platforms/x86: Add AMD system management interface
Subsystems (4)
PATCH v6 1/2 platforms/x86: Add AMD system management interface
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.
---
Changes since v5:
1. change variable name msg.buf to msg.args
2. correct spellings and adjust comments
3. do not call validate_message() in 2 places use the necessary checks alone.
4. return misc_register() directly
5. Added reviewed-by and acked-by, thanks for the review
Changes since v4:
1. Add description of the messages in the header
2. use one set of buf[] array for both arguments and response data
3. renamed struct msg_desc_table to hsmp_msg_desc_table
4. Correct the names in MAINTAINER to first name last name basis
Changes since v3:
remove change ids
Changes since v2:
1. Updated MAINTAINERS page
2. Added message description table with num_args, response_sz and type fields. This will be useful for user space applications and the driver to validate the inputs.
3. removed the model check and added a statement in the documentation.
Changes since v1:
1. Add supported model check
. This interface is supported only on server line of CPUs.
2. Handle Reserved messages
3. Add brief descriptions of the Messages
4. Add Carlos Bilbao's reviewed-by
.../userspace-api/ioctl/ioctl-number.rst | 2 + MAINTAINERS | 10 + arch/x86/include/asm/amd_hsmp.h | 16 + arch/x86/include/uapi/asm/amd_hsmp.h | 203 +++++++++ drivers/platform/x86/Kconfig | 13 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/amd_hsmp.c | 425 ++++++++++++++++++ 7 files changed, 670 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
@@ -375,6 +375,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 ==== ===== ======================================================= ================================================================
MAINTAINERS +10 -0
@@ -989,6 +989,16 @@ L: [email protected] S: Maintained F: drivers/platform/x86/amd-pmc.* +AMD HSMP DRIVER +M: Naveen Krishna Chatradhi <[email protected]> +R: Carlos Bilbao <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/x86/amd_hsmp.rst +F: arch/x86/include/asm/amd_hsmp.h +F: arch/x86/include/uapi/asm/amd_hsmp.h +F: drivers/platform/x86/amd_hsmp.c + AMD POWERPLAY AND SWSMU M: Evan Quan <[email protected]> L: [email protected]
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 +203 -0
203 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 +425 -0
425 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v6 2/2 Documentation: Add x86/amd_hsmp driver
This documentation for amd_hsmp driver explains how to use the device interface.
---
Changes since v5:
variable name changed from buf to args
Changes since v4:
struct hsmp_message is updated
Changes since v3:
remove change ids
Changes since v2:
Add statement saying the HSMP interface is supported only on server cpu models from AMD.
Changes since v1:
None
Documentation/x86/amd_hsmp.rst | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/x86/amd_hsmp.rst
Documentation/x86/amd_hsmp.rst new file +85 -0
@@ -0,0 +1,85 @@ +.. 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 family/model PPR +Eg: https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip + +HSMP interface is supported on EPYC server CPU models only. + + +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. + + +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 input argument words in message */ + __u16 response_sz; /* Number of expected output/response words */ + __u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */ + __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 and message definitions can be found in chapter +"7 Host System Management Port (HSMP)" of the respective family/model PPR +eg: 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
Re: [PATCH v6 2/2] Documentation: Add x86/amd_hsmp driver
Quoted 5 lines · Naveen Krishna Chatradhi
This documentation for
amd_hsmpdriver explains how to use the device interface.Signed-off-by Naveen Krishna Chatradhi <[email protected]>
Quoted 111 lines
---
Changes since v5:
variable name changed from buf to args
Changes since v4:
structhsmp_messageis updated
Changes since v3:
remove change ids
Changes since v2:
Add statement saying the HSMP interface is supported only on server cpu models from AMD.
Changes since v1:
NoneDocumentation/x86/amd_hsmp.rst | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/x86/amd_hsmp.rstDocumentation/x86/amd_hsmp.rst new file +85
-1@@ -0,0 +1,85 @@ +.. 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 family/model PPR +Eg: https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip + +HSMP interface is supported on EPYC server CPU models only. + + +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. + + +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 input argument words in message */ + __u16 response_sz; /* Number of expected output/response words */ + __u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */ + __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 and message definitions can be found in chapter +"7 Host System Management Port (HSMP)" of the respective family/model PPR +eg: 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 --2.17.1