Add AMD system management interface driver
Subsystems (4)
cover Add AMD system management interface driver
Newer Fam19h EPYC server line of processors from AMD support system management functionality via HSMP (Host System Management Port).
The Host System Management Port (HSMP) is an interface to provide OS-level software with access to system management functions via a set of mailbox registers.
This patchset adds a driver and documentation for the device interface.
Naveen Krishna Chatradhi (1):
Documentation: Add x86/amd_hsmp driver
Suma Hegde (1):
platforms/x86: Add AMD system management interface driver
.../userspace-api/ioctl/ioctl-number.rst | 2 + Documentation/x86/amd_hsmp.rst | 93 ++++ arch/x86/include/asm/amd_hsmp.h | 16 + arch/x86/include/uapi/asm/amd_hsmp.h | 56 +++ drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/amd_hsmp.c | 426 ++++++++++++++++++ 7 files changed, 607 insertions(+) create mode 100644 Documentation/x86/amd_hsmp.rst create mode 100644 arch/x86/include/asm/amd_hsmp.h create mode 100644 arch/x86/include/uapi/asm/amd_hsmp.h create mode 100644 drivers/platform/x86/amd_hsmp.c
Signature · 1 line
2.17.1
PATCH 1/2 platforms/x86: Add AMD system management interface driver
From: Suma Hegde <[email protected]>
Recent Fam19h EPYC server line of processors from AMD support system management functionality via HSMP (Host System Management Port) interface.
The Host System Management Port (HSMP) is an interface to provide OS-level software with access to system management functions via a set of mailbox registers.
More details on the interface can be found in chapter "7 Host System Management Port (HSMP)" of the following PPR
https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip
This patch adds new amd_hsmp module under the drivers/platforms/x86/ which creates miscdevice with an IOCTL interface to the user space. /dev/hsmp is for running the hsmp mailbox commands.
Major features support by the interface include monitor and/or control of a. boostlimit
b. current power, power limit, max power limit
c. c0 residency
d. prochot status
e. clocks
f. ddr bandwidth, utilization
g. data fabric P-state
--- .../userspace-api/ioctl/ioctl-number.rst | 2 + arch/x86/include/asm/amd_hsmp.h | 16 + arch/x86/include/uapi/asm/amd_hsmp.h | 56 +++ drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/amd_hsmp.c | 426 ++++++++++++++++++ 6 files changed, 514 insertions(+) create mode 100644 arch/x86/include/asm/amd_hsmp.h create mode 100644 arch/x86/include/uapi/asm/amd_hsmp.h create mode 100644 drivers/platform/x86/amd_hsmp.c
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -372,6 +372,8 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xF6 all LTTng Linux Trace Toolkit Next Generation <mailto:[email protected]> +0xF8 all arch/x86/include/uapi/asm/amd_hsmp.h AMD HSMP EPYC system management interface driver + <mailto:[email protected]> 0xFD all linux/dm-ioctl.h 0xFE all linux/isst_if.h ==== ===== ======================================================= ================================================================
arch/x86/include/asm/amd_hsmp.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef _ASM_X86_AMD_HSMP_H_ +#define _ASM_X86_AMD_HSMP_H_ + +#include <uapi/asm/amd_hsmp.h> + +#if (defined(CONFIG_AMD_HSMP ) || defined(CONFIG_AMD_HSMP_MODULE )) +int hsmp_send_message (struct hsmp_message *msg); +#else +int hsmp_send_message (struct hsmp_message *msg) +{ +return -ENODEV ; +} +#endif +#endif /*_ASM_X86_AMD_HSMP_H_*/
arch/x86/include/uapi/asm/amd_hsmp.h new file +56 -0
56 lines not on this page · raw message
drivers/platform/x86/Kconfig +13 -0
@@ -210,6 +210,19 @@ config AMD_PMC If you choose to compile this driver as a module the module will be called amd-pmc. +config AMD_HSMP + tristate "AMD HSMP Driver" + depends on AMD_NB && X86_64 + help + The driver provides a way for user space tools to monitor and manage + system management functionality on EPYC server CPUs from AMD. + + Host System Management Port (HSMP) interface is a mailbox interface + between the x86 core and the System Management Unit (SMU) firmware. + + If you choose to compile this driver as a module the module will be + called amd_hsmp. + config ADV_SWBUTTON tristate "Advantech ACPI Software Button Driver" depends on ACPI && INPUT
drivers/platform/x86/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_ACER_WMI) += acer-wmi.o # AMD obj-$(CONFIG_AMD_PMC) += amd-pmc.o +obj-$(CONFIG_AMD_HSMP) += amd_hsmp.o # Advantech obj-$(CONFIG_ADV_SWBUTTON) += adv_swbutton.o
drivers/platform/x86/amd_hsmp.c new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 1/2] platforms/x86: Add AMD system management interface driver
Hello folks,
It's great to see this patch on the mailing list, this is useful stuff! I have some small suggestions to improve things a little more. Besides that the driver is in great shape I think.
Feel free to add Reviewed-by: Carlos Bilbao <[email protected]>.
Quoted 29 lines · Naveen Krishna Chatradhi
From: Suma Hegde <[email protected]>
(...)drivers/platform/x86/amd_hsmp.c new file +27
-0+ +int hsmp_send_message (struct hsmp_message *msg) +{ +struct amd_northbridge *nb; +int ret; + +if (!msg) +return -EINVAL ; + + nb =node_to_amd_nb (msg->sock_ind); +if (!nb || !nb->root) +return -ENODEV ; + +if (msg->msg_id <HSMP_TEST || msg->msg_id >=HSMP_MSG_ID_MAX ) +return -EINVAL ; + +if (msg->num_args >HSMP_MAX_MSG_LEN || msg->response_sz >HSMP_MAX_MSG_LEN ) +return -EINVAL ; + +/* +* The time taken by smu operation to complete is between +* 10us to 1ms. Sometime it may take more time. +* In SMP system timeout of 100 millisecs should +* be enough for the previous thread to finish the operation +*/ + ret =down_timeout (&hsmp_sem[msg->sock_ind], +msecs_to_jiffies (HSMP_MSG_TIMEOUT ));
drivers/platform/x86/amd_hsmp.c line 228
Quoted 10 lines
drivers/platform/x86/amd_hsmp.c new file +10
-0+if (ret <0 ) +return ret; + + ret =__hsmp_send_message (nb->root, msg); + +up (&hsmp_sem[msg->sock_ind]); + +return ret; +} +EXPORT_SYMBOL_GPL (hsmp_send_message);
In this function it would be nice to check for a msg_id of HSMP_RESERVED and return -EINVAL if so. The function hsmp_ioctl() could do the same, but it's better here since third-parties can call this directly.
drivers/platform/x86/amd_hsmp.c line 372
Quoted 4 lines
+ (...)
drivers/platform/x86/amd_hsmp.c new file +3
-0+ +static int __init hsmp_plt_init (void ) +{
Perhaps instead of __init/__exit let's do __devinit/__devexit?
Quoted 31 lines
drivers/platform/x86/amd_hsmp.c new file +31
-0+int ret = -ENODEV ; +u16 num_sockets; +int i; + +/* +* amd_nb_num() returns number of SMN/DF interfaces present in the system +* if we have N SMN/DF interfaces that ideally means N sockets +*/ + num_sockets =amd_nb_num (); +if (num_sockets ==0 ) +return ret; + +/* Test the hsmp interface on each socket */ +for (i =0 ; i < num_sockets; i++) { + ret =hsmp_test (i); +if (ret) +return ret; + } + + ret =platform_driver_register (&amd_hsmp_driver); +if (ret) +return ret; + + amd_hsmp_platdev =platform_device_alloc (DRIVER_NAME ,-1 ); +if (!amd_hsmp_platdev) { + ret = -ENOMEM ; + goto drv_unregister; + } + + ret =platform_device_add (amd_hsmp_platdev); +if (ret) {
drivers/platform/x86/amd_hsmp.c line 413
Quoted 10 lines
drivers/platform/x86/amd_hsmp.c new file +10
-0+platform_device_put (amd_hsmp_platdev); + goto drv_unregister; + } + +return 0 ; + +drv_unregister: +platform_driver_unregister (&amd_hsmp_driver); +return ret; +}
I think we really need to do some checking for family and model (>=0x19) here.
drivers/platform/x86/amd_hsmp.c line 426
Quoted 13 lines
drivers/platform/x86/amd_hsmp.c new file +13
-0+ +static void __exit hsmp_plt_exit(void) +{ +platform_device_unregister (amd_hsmp_platdev); +platform_driver_unregister (&amd_hsmp_driver); +} + +device_initcall (hsmp_plt_init); +module_exit (hsmp_plt_exit); + +MODULE_DESCRIPTION ("AMD HSMP Platform Interface Driver" ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL v2" );
Thanks,
Carlos
Re: [PATCH 1/2] platforms/x86: Add AMD system management interface driver
Quoted 96 lines · Carlos Bilbao
Hello folks,
It's great to see this patch on the mailing list, this is useful stuff! I have some small suggestions to improve things a little more. Besides that the driver is in great shape I think.
Feel free to add Reviewed-by: Carlos Bilbao <[email protected]>.
Quoted 29 lines · Naveen Krishna Chatradhi
From: Suma Hegde <[email protected]>
(...)drivers/platform/x86/amd_hsmp.c new file +27
-0+ +int hsmp_send_message (struct hsmp_message *msg) +{ +struct amd_northbridge *nb; +int ret; + +if (!msg) +return -EINVAL ; + + nb =node_to_amd_nb (msg->sock_ind); +if (!nb || !nb->root) +return -ENODEV ; + +if (msg->msg_id <HSMP_TEST || msg->msg_id >=HSMP_MSG_ID_MAX ) +return -EINVAL ; + +if (msg->num_args >HSMP_MAX_MSG_LEN || msg->response_sz >HSMP_MAX_MSG_LEN ) +return -EINVAL ; + +/* +* The time taken by smu operation to complete is between +* 10us to 1ms. Sometime it may take more time. +* In SMP system timeout of 100 millisecs should +* be enough for the previous thread to finish the operation +*/ + ret =down_timeout (&hsmp_sem[msg->sock_ind], +msecs_to_jiffies (HSMP_MSG_TIMEOUT ));drivers/platform/x86/amd_hsmp.c line 228
Quoted 10 lines
drivers/platform/x86/amd_hsmp.c new file +10
-0+if (ret <0 ) +return ret; + + ret =__hsmp_send_message (nb->root, msg); + +up (&hsmp_sem[msg->sock_ind]); + +return ret; +} +EXPORT_SYMBOL_GPL (hsmp_send_message);In this function it would be nice to check for a
msg_idofHSMP_RESERVEDand return-EINVALif so. The functionhsmp_ioctl()could do the same, but it's better here since third-parties can call this directly.drivers/platform/x86/amd_hsmp.c line 372
Quoted 4 lines
+ (...)
drivers/platform/x86/amd_hsmp.c new file +3
-0+ +static int __init hsmp_plt_init (void ) +{Perhaps instead of __init/__exit let's do __devinit/__devexit?
Quoted 36 lines
drivers/platform/x86/amd_hsmp.c new file +36
-0+int ret = -ENODEV ; +u16 num_sockets; +int i; + +/* +* amd_nb_num() returns number of SMN/DF interfaces present in the system +* if we have N SMN/DF interfaces that ideally means N sockets +*/ + num_sockets =amd_nb_num (); +if (num_sockets ==0 ) +return ret; + +/* Test the hsmp interface on each socket */ +for (i =0 ; i < num_sockets; i++) { + ret =hsmp_test (i); +if (ret) +return ret; + } + + ret =platform_driver_register (&amd_hsmp_driver); +if (ret) +return ret; + + amd_hsmp_platdev =platform_device_alloc (DRIVER_NAME ,-1 ); +if (!amd_hsmp_platdev) { + ret = -ENOMEM ; + goto drv_unregister; + } + + ret =platform_device_add (amd_hsmp_platdev); +if (ret) { +platform_device_put (amd_hsmp_platdev); + goto drv_unregister; + } + +return 0 ;
Quoted 9 lines
drivers/platform/x86/amd_hsmp.c line 413
Quoted 5 lines
drivers/platform/x86/amd_hsmp.c new file +5
-0+ +drv_unregister: +platform_driver_unregister (&amd_hsmp_driver); +return ret; +}I think we really need to do some checking for family and model (>=0x19) here.
We should only need to do a family check, HSMP is only supported on family 19h.
-Nathan
Quoted 16 lines
drivers/platform/x86/amd_hsmp.c line 426
Quoted 13 lines
drivers/platform/x86/amd_hsmp.c new file +13
-0+ +static void __exit hsmp_plt_exit(void) +{ +platform_device_unregister (amd_hsmp_platdev); +platform_driver_unregister (&amd_hsmp_driver); +} + +device_initcall (hsmp_plt_init); +module_exit (hsmp_plt_exit); + +MODULE_DESCRIPTION ("AMD HSMP Platform Interface Driver" ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL v2" );Thanks,
Carlos
Re: [PATCH 1/2] platforms/x86: Add AMD system management interface driver
Hi Everyone,
Quoted 103 lines · Nathan Fontenot
Quoted 93 lines · Carlos Bilbao
Hello folks,
It's great to see this patch on the mailing list, this is useful stuff! I have some small suggestions to improve things a little more. Besides that the driver is in great shape I think.
Feel free to add Reviewed-by: Carlos Bilbao <[email protected]>.
Quoted 29 lines · Naveen Krishna Chatradhi
From: Suma Hegde <[email protected]>
(...)drivers/platform/x86/amd_hsmp.c new file +27
-0+ +int hsmp_send_message (struct hsmp_message *msg) +{ +struct amd_northbridge *nb; +int ret; + +if (!msg) +return -EINVAL ; + + nb =node_to_amd_nb (msg->sock_ind); +if (!nb || !nb->root) +return -ENODEV ; + +if (msg->msg_id <HSMP_TEST || msg->msg_id >=HSMP_MSG_ID_MAX ) +return -EINVAL ; + +if (msg->num_args >HSMP_MAX_MSG_LEN || msg->response_sz >HSMP_MAX_MSG_LEN ) +return -EINVAL ; + +/* +* The time taken by smu operation to complete is between +* 10us to 1ms. Sometime it may take more time. +* In SMP system timeout of 100 millisecs should +* be enough for the previous thread to finish the operation +*/ + ret =down_timeout (&hsmp_sem[msg->sock_ind], +msecs_to_jiffies (HSMP_MSG_TIMEOUT ));drivers/platform/x86/amd_hsmp.c line 228
Quoted 10 lines
drivers/platform/x86/amd_hsmp.c new file +10
-0+if (ret <0 ) +return ret; + + ret =__hsmp_send_message (nb->root, msg); + +up (&hsmp_sem[msg->sock_ind]); + +return ret; +} +EXPORT_SYMBOL_GPL (hsmp_send_message);In this function it would be nice to check for a
msg_idofHSMP_RESERVEDand return-EINVALif so. The functionhsmp_ioctl()could do the same, but it's better here since third-parties can call this directly.drivers/platform/x86/amd_hsmp.c line 372
Quoted 4 lines
+ (...)
drivers/platform/x86/amd_hsmp.c new file +3
-0+ +static int __init hsmp_plt_init (void ) +{Perhaps instead of __init/__exit let's do __devinit/__devexit?
Quoted 35 lines
drivers/platform/x86/amd_hsmp.c new file +35
-0+int ret = -ENODEV ; +u16 num_sockets; +int i; + +/* +* amd_nb_num() returns number of SMN/DF interfaces present in the system +* if we have N SMN/DF interfaces that ideally means N sockets +*/ + num_sockets =amd_nb_num (); +if (num_sockets ==0 ) +return ret; + +/* Test the hsmp interface on each socket */ +for (i =0 ; i < num_sockets; i++) { + ret =hsmp_test (i); +if (ret) +return ret; + } + + ret =platform_driver_register (&amd_hsmp_driver); +if (ret) +return ret; + + amd_hsmp_platdev =platform_device_alloc (DRIVER_NAME ,-1 ); +if (!amd_hsmp_platdev) { + ret = -ENOMEM ; + goto drv_unregister; + } + + ret =platform_device_add (amd_hsmp_platdev); +if (ret) { +platform_device_put (amd_hsmp_platdev); + goto drv_unregister; + } +Quoted 9 lines
drivers/platform/x86/amd_hsmp.c line 413
Quoted 6 lines
drivers/platform/x86/amd_hsmp.c new file +6
-0+return 0 ; + +drv_unregister: +platform_driver_unregister (&amd_hsmp_driver); +return ret; +}I think we really need to do some checking for family and model (>=0x19) here.
Quoted 3 lines
We should only need to do a family check, HSMP is only supported on family 19h.
-Nathan
Thank you for the comments, will wait for some more feedback before submitting the next version addressing these comments along.
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
drivers/platform/x86/amd_hsmp.c new file +3
-0+ +static void __exit hsmp_plt_exit(void) +{drivers/platform/x86/amd_hsmp.c line 426
Quoted 10 lines
drivers/platform/x86/amd_hsmp.c new file +10
-0+platform_device_unregister (amd_hsmp_platdev); +platform_driver_unregister (&amd_hsmp_driver); +} + +device_initcall (hsmp_plt_init); +module_exit (hsmp_plt_exit); + +MODULE_DESCRIPTION ("AMD HSMP Platform Interface Driver" ); +MODULE_VERSION (DRIVER_VERSION ); +MODULE_LICENSE ("GPL v2" );Thanks,
Carlos
PATCH 2/2 Documentation: Add x86/amd_hsmp driver
In reply to Naveen Krishna ChatradhiThis documentation for amd_hsmp driver explains how to use the device interface.
--- Documentation/x86/amd_hsmp.rst | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Documentation/x86/amd_hsmp.rst
Documentation/x86/amd_hsmp.rst new file +93 -0
@@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================================ +AMD HSMP interface +============================================ + +Newer Fam19h EPYC server line of processors from AMD support system +management functionality via HSMP (Host System Management Port). + +The Host System Management Port (HSMP) is an interface to provide +OS-level software with access to system management functions via a +set of mailbox registers. + +More details on the interface can be found in chapter +"7 Host System Management Port (HSMP)" of the following PPR +https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip + + +HSMP device +============================================ + +amd_hsmp driver under the drivers/platforms/x86/ creates miscdevice +/dev/hsmp to let user space programs run hsmp mailbox commands. + +$ ls -al /dev/hsmp +crw-r--r-- 1 root root 10, 123 Jan 21 21:41 /dev/hsmp + +Characteristics of the dev node: + * Write mode is used for running set/configure commands + * Read mode is used for running get/status monitor commands + +Access restrictions: + * Only root user is allowed to open the file in write mode. + * The file can be opened in read mode by all the users. + +In-kernel integration: + * Other subsystems in the kernel can use the exported transport + function hsmp_send_message(). + * Locking across callers is taken care by the driver. + +Features support by the interface include monitor and/or control of +a. boostlimit +b. current power, power limit, max power limit +c. c0 residency +d. prochot status +e. clocks (fclk, mclk and cclk) +f. ddr bandwidth, utilization +g. data fabric P-state + + +An example +========== + +To access hsmp device from a C program. +First, you need to include the headers:: + + #include <linux/amd_hsmp.h> +Which defines the supported messages/message IDs. + +Next thing, open the device file, as follows:: + + int file; + + file = open("/dev/hsmp", O_RDWR); + if (file < 0) { + /* ERROR HANDLING; you can check errno to see what went wrong */ + exit(1); + } + +The following IOCTL is defined: + +``ioctl(file, HSMP_IOCTL_CMD, struct hsmp_message *msg)`` + The argument is a pointer to a:: + + struct hsmp_message { + __u32 msg_id; /* Message ID */ + __u16 num_args; /* Number of arguments in message */ + __u16 response_sz; /* Number of expected response words */ + __u32 args[HSMP_MAX_MSG_LEN]; /* Argument(s) */ + __u32 response[HSMP_MAX_MSG_LEN]; /* Response word(s) */ + __u16 sock_ind; /* socket number */ + }; + +The ioctl would return a non-zero on failure; you can read errno to see +what happened. The transaction returns 0 on success. + +More details on the interface can be found in chapter +"7 Host System Management Port (HSMP)" of the following PPR +https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip + +User space C-APIs are made available by linking against the esmi library, +which is provided by the E-SMS project https://developer.amd.com/e-sms/. +See: https://github.com/amd/esmi_ib_library
Signature · 1 line
2.17.1