{"id":27450787,"url":"https://github.com/shymega/ryzen_smu","last_synced_at":"2025-04-15T09:30:53.902Z","repository":{"id":283175782,"uuid":"845260090","full_name":"shymega/ryzen_smu","owner":"shymega","description":"A fork of the now-unmaintained https://gitlab.com/leogx9r/ryzen_smu with merge requests and my own updates applied.","archived":false,"fork":false,"pushed_at":"2023-12-29T21:35:25.000Z","size":934,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-15T01:45:31.089Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shymega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-20T22:50:34.000Z","updated_at":"2025-03-15T20:55:15.000Z","dependencies_parsed_at":"2025-03-18T23:44:23.365Z","dependency_job_id":"1ed6801b-ae96-445c-b38f-a11b4d076dbd","html_url":"https://github.com/shymega/ryzen_smu","commit_stats":null,"previous_names":["shymega/ryzen_smu"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shymega%2Fryzen_smu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shymega%2Fryzen_smu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shymega%2Fryzen_smu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shymega%2Fryzen_smu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shymega","download_url":"https://codeload.github.com/shymega/ryzen_smu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249042765,"owners_count":21203349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-15T09:30:48.784Z","updated_at":"2025-04-15T09:30:53.890Z","avatar_url":"https://github.com/shymega.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ryzen SMU\n\n\u003cimg src=\"pics/preview1.jpg\" width=\"400\" height=\"650\"\u003e \u003cimg src=\"pics/preview2.jpg\" width=\"400\" height=\"650\"\u003e\n\n\u003csmall\u003e*N.B. Images above shows the potential capabilities of this driver, retrieved using the\n[monitor_cpu](userspace/monitor_cpu.c)* utility. Other processors will require tweaking on the\nuser's part or additional tools.\u003c/small\u003e\n\n**Ryzen SMU** is a Linux kernel driver that exposes access to the SMU (System Management Unit) for\ncertain AMD Ryzen Processors. ***Use at your own risk, the author takes no responsibility over\npotential damages that may result from the misuse of this driver or programs dependent upon it.***\n\nThe following processor code names are supported:\n\n- [Colfax](https://en.wikichip.org/wiki/amd/cores/colfax)\n- [Renoir](https://en.wikichip.org/wiki/amd/cores/renoir)\n- [Picasso](https://en.wikichip.org/wiki/amd/cores/picasso)\n- [Matisse](https://en.wikichip.org/wiki/amd/cores/matisse)\n- [Castle Peak](https://en.wikichip.org/wiki/amd/cores/castle_peak)\n- [Raven Ridge](https://en.wikichip.org/wiki/amd/cores/raven_ridge)\n- [Raven Ridge 2](https://www.techpowerup.com/gpu-specs/amd-raven-2.g888)\n- [Summit Ridge](https://en.wikichip.org/wiki/amd/cores/summit_ridge)\n- [Pinnacle Ridge](https://en.wikichip.org/wiki/amd/cores/pinnacle_ridge)\n- [Raphael](https://en.wikichip.org/wiki/amd/cores/raphael)\n- [Rembrandt](https://en.wikichip.org/wiki/amd/cores/rembrandt)\n- [Vermeer](https://en.wikichip.org/wiki/amd/cores/vermeer)\n- [Vangogh](https://en.wikichip.org/wiki/amd/cores/vangogh)\n- [Cezanne](https://en.wikichip.org/wiki/amd/cores/cezanne)\n- [Milan](https://en.wikichip.org/wiki/amd/cores/milan)\n- [Dali](https://en.wikichip.org/wiki/amd/cores/dali)\n- [Chagall](https://en.wikichip.org/wiki/amd/cores/chagall)\n- [Naples](https://en.wikichip.org/wiki/amd/cores/naples)\n- [Lucienne](https://en.wikichip.org/wiki/amd/cores/lucienne)\n\nIn addition, for the following models, the power metrics/monitoring (PM) table (seen in screenshot)\ncan also be accessed:\n\n- Raphael ( Ryzen 7000 Desktop Series )\n- Vermeer ( Ryzen 5000 Desktop Series )\n- Matisse ( Ryzen 3000 Desktop Series )\n- Cezanne ( Ryzen 5000[GE] APU Series )\n- Renoir ( Ryzen 4000[UGHS] APU Series )\n- Picasso ( Ryzen 3000[UGHS] APU Series )\n- Raven Ridge ( Ryzen 2000[GEU] APU Series )\n- Raven Ridge 2\n\nWhen loaded, the driver exposes several files under sysfs which can only be read with root\npermissions (for obvious reasons) at the root path `/sys/kernel/ryzen_smu_drv`:\n\n- `drv_version`\n- `version`\n- `mp1_if_version`\n- `codename`\n- `smu_args`\n- `mp1_smu_cmd`\n- `hsmp_smu_cmd`\n- `smn`\n- `rsmu_cmd` (Not present on `Rembrandt`, `Vangogh`)\n\nFor supported PM table models where RSMU is also supported, the following files are additionally\nexposed:\n\n- `pm_table_version`\n- `pm_table_size`\n- `pm_table`\n\n\n\n## Installation\n\nThe kernel module may be installed either by DKMS or manually building and inserting the module.\n\nBe sure kernel headers, dev utilities such as `gcc` and `make` are installed beforehand.\n\n### Ubuntu / Debian\n\n```sh\nsudo apt install dkms git build-essential linux-headers-$(uname -r)\ngit clone https://gitlab.com/leogx9r/ryzen_smu.git\ncd ryzen_smu\n\nsudo make dkms-install\n```\n\n### Arch Linux\n\nAvailable on the [AUR](https://aur.archlinux.org/packages/ryzen_smu-dkms-git/).\n\nInstall it using your AUR helper of choice, example:\n\n```sh\nyay -S ryzen_smu-dkms-git\n```\n\n### Stand-alone Installation\n\nThe module may be built and inserted into the running kernel manually as follows:\n\n```sh\ngit clone https://gitlab.com/leogx9r/ryzen_smu.git\ncd ryzen_smu\n\nmake\nsudo insmod ryzen_smu.ko\n```\n\n## Auto-Loading On System Startup\n\nAssuming you are using `systemd`, the kernel module may be loaded automatically upon system startup\nusing [`modules-load.d`](https://www.freedesktop.org/software/systemd/man/modules-load.d.html) by\nadding the module name to `/etc/modules-load.d/\u003cname\u003e.conf`\n\nExample:\n\n```sh\n# /etc/modules-load.d/ryzen_smu.conf\n# Load ryzen_smu driver upon startup\nryzen_smu\n```\n\n## Confirming Module Works\n\nUpon loading the module, you should see output in your `dmesg` window listing the SMU version:\n\n```sh\n# dmesg\n\n...\n[1091.154018] ryzen_smu: CPUID: family 0x17, model 0x71, stepping 0x0, package 0x2\n[1091.154385] ryzen_smu: SMU v46.54.0\n...\n```\n\nAfter which you can verify the existence of the sysfs files and attempt to read them:\n\n```\n# ls -lah /sys/kernel/ryzen_smu_drv\ntotal 0\ndrwxr-xr-x  2 root root    0 May  7 03:01 ./\ndrwxr-xr-x 14 root root    0 May  7 03:01 ../\n-r--------  1 root root 4.0K May  7 03:12 codename\n-r--------  1 root root 4.0K May  7 03:12 drv_version\n-rw-------  1 root root 4.0K May  7 03:10 hsmp_smu_cmd\n-r--------  1 root root 4.0K May  7 03:10 mp1_if_version\n-rw-------  1 root root 4.0K May  7 03:10 mp1_smu_cmd\n-r--------  1 root root 4.0K May  7 03:12 pm_table\n-r--------  1 root root 4.0K May  7 03:12 pm_table_size\n-r--------  1 root root 4.0K May  7 03:12 pm_table_version\n-rw-------  1 root root 4.0K May  7 03:10 rsmu_cmd\n-rw-------  1 root root 4.0K May  7 03:10 smn\n-rw-------  1 root root 4.0K May  7 03:10 smu_args\n-r--------  1 root root 4.0K May  7 03:01 version\n\n# cat /sys/kernel/ryzen_smu_drv/version          \nSMU v46.54.0\n\n# cat /sys/kernel/ryzen_smu_drv/mp1_if_version\n2\n\n# cat /sys/kernel/ryzen_smu_drv/codename\n4\n\n# cat /sys/kernel/ryzen_smu_drv/drv_version\n0.1.5\n\n```\n\nFollowing which, you can run the [test.py script](scripts/test.py) to verify that SMU and SMN\nfunctionality is working:\n\n```\n# python3 scripts/test.py\nRetrieved SMU Version: v46.54.0\nProcessor Code Name: Matisse\nPM Table: [Supported/Unsupported]\nSMN Offset[0x50200]: 0x00001539\n\nEverything seems to be working properly!\n\n```\n\n## Explaining Sysfs Files\n\n#### `/sys/kernel/ryzen_smu_drv/drv_version`\n\nLists the string-representation of the driver (and thus interface) version. For userspace\napplications, they should make sure this version is within the expected range.\n\n#### `/sys/kernel/ryzen_smu_drv/version`\n\nLists the current SMU firmware version in relation to the currently installed\n[AGESA](https://en.wikipedia.org/wiki/AGESA).\n\nThe following are several lists of SMU to AGESA versions:\n\n\u003cimg src=\"pics/smu_versions.jpg\" width=\"1000\" height=\"825\"\u003e\n\nNote: This file returns a string encoded version represented by the \"SMU Version\" above.\n\n#### `/sys/kernel/ryzen_smu_drv/mp1_if_version`\n\nLists the interface version for the MP1 mailbox.\n\nThis can range from v9 to v13 and is indicated by the following table:\n\n| Value | Interface Version |\n|:-----:|:-----------------:|\n| 0     | v9                |\n| 1     | v10               |\n| 2     | v11               |\n| 3     | v12               |\n| 4     | v13               |\n| 5     | Undefined         |\n\nNote: This file returns a string representation of the \"Value\" field above.\n\n#### `/sys/kernel/ryzen_smu_drv/codename`\n\nReturns a numeric index containing the running processor's codename based on the following\nenumeration:\n\n| Hex | Decimal | Code Name      |\n|:---:|:-------:|:--------------:|\n| 00h | 0       | Unknown        |\n| 01h | 1       | Colfax         |\n| 02h | 2       | Renoir         |\n| 03h | 3       | Picasso        |\n| 04h | 4       | Matisse        |\n| 05h | 5       | Threadripper   |\n| 06h | 6       | Castle Peak    |\n| 07h | 7       | Raven Ridge    |\n| 08h | 8       | Raven Ridge 2  |\n| 09h | 9       | Summit Ridge   |\n| 0Ah | 10      | Pinnacle Ridge |\n| 0Bh | 11      | Rembrandt      |\n| 0Ch | 12      | Vermeer        |\n| 0Dh | 13      | Vangogh        |\n| 0Eh | 14      | Cezanne        |\n| 0Fh | 15      | Milan          |\n| 10h | 16      | Dali           |\n\nNote: This file returns 2 characters of the 'Decimal' encoded index.\n\n#### `/sys/kernel/ryzen_smu_drv/rsmu_cmd` or `/sys/kernel/ryzen_smu_drv/mp1_smu_cmd` or `/sys/kernel/ryzen_smu_drv/hsmp_smu_cmd`\n\nThis file allows the user to initiate an RSMU or MP1 SMU request. It accepts either an 8-bit or\n32-bit command ID that is platform-dependent.\n\nWhen this file is read, it produces the result on the status of the operation, as a 32 bit\nlittle-endian encoded value.\n\nThe SMU returns the following possible values which indicate the result of a command execution:\n\n| Hex | Decimal | Explanation                   |\n|:---:|:-------:|:-----------------------------:|\n| 00h | 0       | WAITING                       |\n| 01h | 1       | OK                            |\n| FFh | 255     | FAILED                        |\n| FEh | 254     | UNKNOWN COMMAND               |\n| FDh | 253     | REJECTED - PREREQUISITE UNMET |\n| FCh | 252     | REJECTED - BUSY               |\n\nIn addition to this, several custom error codes are also implemented by the driver:\n\n| Hex | Decimal | Explanation                   |\n|:---:|:-------:|:-----------------------------:|\n| FBh | 251     | COMMAND TIMEOUT               |\n| FAh | 250     | INVALID ARGUMENT              |\n| F9h | 249     | UNSUPPORTED PLATFORM          |\n| F8h | 248     | INSUFFICIENT BUFFER SIZE      |\n| F7h | 247     | MEMORY MAP ERROR              |\n| F6h | 246     | PCI PROGRAMMING ERROR         |\n\n\n#### `/sys/kernel/ryzen_smu_drv/smu_args`\n\nWhen written to, this file accepts 6x 32-bit words (a total of 192 bits) that specify the arguments\nused when executing an SMU command.\n\nWhen read from, it lists either:\n\n- The last values that were written to it before an SMU request was initiated\n- The responses from the SMU after a request was completed\n\nNote: All values sent to and read from this file must be in 6x 32-bit words encoded in little-endian\norder, arguments numbered from 1 to 6.\n\n#### `/sys/kernel/ryzen_smu_drv/smn`\n\nAllows reading and writing 32 bit values from the SMN address space. To perform an operation, write\na value then read the file for the result.\n\nThe amount of bytes written indicates the operation performed:\n\n| Bits Written | Operation | Action Taken                                                                 |\n|:------------:|:---------:| ---------------------------------------------------------------------------- |\n| 32           | Read      | Reads 32 bit address and returns the result                                  |\n| 64           | Write     | Writes the second 32-bit value to the address specified by the first 32 bits |\n\nNote: All values sent to and read from the device must are in little-endian binary format.\n\n#### `/sys/kernel/ryzen_smu_drv/pm_table_size`\n\nOn supported platforms, this lists the maximum size of the `/sys/kernel/ryzen_smu_drv/pm_table`\nfile, in bytes.\n\nNote: File is a 64 bit word encoded in little-endian binary order.\n\n#### `/sys/kernel/ryzen_smu_drv/pm_table_version`\n\nOn supported platforms, listed in the table below, this indicates the version of the metrics table.\n\nEach version corresponds to a specific table size and layout that differs across processors.\n\nThe following table lists the known characteristics per version:\n\n| Hex      | Platform    | Table Size (Hex) |\n|:--------:|:-----------:|:----------------:|\n| 0x1E0004 | Raven Ridge | 0x6AC            |\n| 0x1E0005 | Raven Ridge | 0x6AC            |\n| 0x1E0101 | Raven Ridge | 0x6AC            |\n|          |             |                  |\n| 0x240802 | Matisse     | 0x7E0            |\n| 0x240803 | Matisse     | 0x7E4            |\n| 0x240902 | Matisse     | 0x514            |\n| 0x240903 | Matisse     | 0x518            |\n|          |             |                  |\n| 0x2D0803 | Vermeer     | 0x894            |\n| 0x380804 | Vermeer     | 0x8A4            |\n| 0x380805 | Vermeer     | 0x8F0            |\n| 0x2D0903 | Vermeer     | 0x594            |\n| 0x380904 | Vermeer     | 0x5A4            |\n| 0x380905 | Vermeer     | 0x5D0            |\n|          |             |                  |\n| 0x370000 | Renoir      | 0x794            |\n| 0x370001 | Renoir      | 0x884            |\n| 0x370002 | Renoir      | 0x88C            |\n| 0x370004 | Renoir      | 0x8AC            |\n| 0x370005 | Renoir      | 0x8C8            |\n|          |             |                  |\n| 0x400005 | Cezanne     | 0x944            |\n|          |             |                  |\n| 0x2D0008 | Milan       | 0x1AB0           |\n\nNote: File is a 32 bit word encoded in little-endian binary order.\n\n#### `/sys/kernel/ryzen_smu_drv/pm_table`\n\nOn supported platforms, this file contains the PM table for the processor, as updated by the SMU.\n\nNote: This file is encoded directly by the SMU and contains an array of 32-bit floating point values\nwhose structure is determined by the version of the table.\n\n## Module Parameters\n\nThe driver supports the following module parameter(s):\n\n#### `smu_timeout_attempts`\n\nWhen executing an SMU command, either by reading `pm_table` or manually, via `smu_args` and\n`smu_cmd`, the driver will retry this many times before considering the command to have timed out.\n\nFor example, on slower or busy systems, the SMU may be tied up resulting in commands taking longer\nto execute than normal. Allowed range is from `500` to `32768`, defaulting to `8192`.\n\n## Userspace Library\n\nIncluded in this project is a userspace library, located at [/lib](lib) to allow easy interaction\nwith the driver. More details of the methods provided may be found in [libsmu.h](lib/libsmu.h).\n\nExample usage of the library is detailed below:\n\n```cpp\n#include \u003cstdlib.h\u003e\n#include \u003cunistd.h\u003e\n\n#include \u003clibsmu.h\u003e\n\n#define TEST_SMN_ADDR 0x50200\n\nint main(int argc, char** argv) {\n    smu_obj_t obj;\n    unsigned int result;\n\n    // Userspace library requires root permissions to access driver.\n    if (getuid() != 0 \u0026\u0026 geteuid() != 0) {\n        fprintf(stderr, \"Program must be run as root.\\n\");\n        exit(-1);\n    }\n\n    // Initialize the library for use with the program.\n    if (smu_init(\u0026obj) != SMU_Return_OK) {\n        fprintf(stderr, \"Error initializing userspace library.\\n\");\n        exit(-2);\n    }\n\n    printf(\"Processor Codename: %s\\n\", smu_codename_to_str(\u0026obj));\n    printf(\"SMU FW: %s\\n\", smu_get_fw_version(\u0026obj));\n\n    if (smu_read_smn_addr(\u0026obj, TEST_SMN_ADDR, \u0026result) != SMU_Return_OK) {\n        fprintf(stderr, \"Error reading SMN address: 0x%08x\\n\", TEST_SMN_ADDR);\n        exit(-3);\n    }\n    printf(\"SMN [0x%08x]: 0x%08x\\n\", TEST_SMN_ADDR, result);\n\n    // Cleanup after library use has ended.\n    smu_free(\u0026obj);\n\n    return 0;\n}\n```\n\nN.B. This header file must be compatible with the version of the driver installed.\n\n\n## Example Usage\n\nFor Matisse \u0026 Vermeer processors, there are several commands that are known to work. See\n[rsmu_commands.md](docs/rsmu_commands.md) for more information.\n\nCommands may be executed either programatically using the library or under a shell by writing to the\ndesignated files.\n\nExample usage via shell:\n\n```sh\n# Note: Does not persist across reboots\n\n# Set the running PPT to 142 W (argument in milliwatts)\nprintf '%0*x' 48 142000 | fold -w 2 | tac | tr -d '\\n' | xxd -r -p | sudo tee /sys/kernel/ryzen_smu_drv/smu_args \u0026\u0026 printf '\\x53' | sudo tee /sys/kernel/ryzen_smu_drv/rsmu_cmd\n\n# Set the running TDC to 90 A (argument in milliamps)\nprintf '%0*x' 48 90000 | fold -w 2 | tac | tr -d '\\n' | xxd -r -p | sudo tee /sys/kernel/ryzen_smu_drv/smu_args \u0026\u0026 printf '\\x54' | sudo tee /sys/kernel/ryzen_smu_drv/rsmu_cmd\n\n# Set the running EDC to 140 A (argument in milliamps)\nprintf '%0*x' 48 140000 | fold -w 2 | tac | tr -d '\\n' | xxd -r -p | sudo tee /sys/kernel/ryzen_smu_drv/smu_args \u0026\u0026 printf '\\x55' | sudo tee /sys/kernel/ryzen_smu_drv/rsmu_cmd\n\n# Set the PBO Scalar to 2x\n# Calculation: 100 * scalar\nprintf '%0*x' 48 200 | fold -w 2 | tac | tr -d '\\n' | xxd -r -p | sudo tee /sys/kernel/ryzen_smu_drv/smu_args \u0026\u0026 printf '\\x58' | sudo tee /sys/kernel/ryzen_smu_drv/rsmu_cmd\n```\n\nAs to the rest of the commands, we leave that as an exercise up to the user. :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshymega%2Fryzen_smu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshymega%2Fryzen_smu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshymega%2Fryzen_smu/lists"}