Skip to contentSkip to conversation

platform/x86/amd/hsmp: split ACPI, Non-ACPI code

PATCH In review Suma Hegde 2 participants 4 messages Jun 7, 2024 – Jun 10, 2024

Subsystems (4)
lore
Share & tools
lore

Suma Hegde

author
#0 lore raw

cover platform/x86/amd/hsmp: split ACPI, Non-ACPI code

Split hsmp.c into 2 exclusive driver one for ACPI object based probing and one probed as a platform device, provide Kconfig options to select one of them.

Patch1: In preparation for the split. Create hsmp directory and necessary Kconfig and Makefile and move hsmp.c file to hsmp/ directory. There are no logical changes in this patch.

Patch2: Split hsmp.c code into acpi.c, core.c and plat.c files acpi.c + core.c -> compile into ACPI based driver. plat.c + core.c -> compile into plat device based driver.

Also, remove devm_* sysfs calls and uses dev_groups pointer in platform_driver structure.

Suma Hegde (2):
platform/x86/amd/hsmp: Create hsmp/ directory platform/x86/amd/hsmp: Split ACPI and non-ACPI code

 Documentation/arch/x86/amd_hsmp.rst    |  60 +-
 MAINTAINERS                            |   2 +-
 arch/x86/include/asm/amd_hsmp.h        |   2 +-
 drivers/platform/x86/amd/Kconfig       |  14 +-
 drivers/platform/x86/amd/Makefile      |   3 +-
 drivers/platform/x86/amd/hsmp.c        | 988 -------------------------
 drivers/platform/x86/amd/hsmp/Kconfig  |  37 +
 drivers/platform/x86/amd/hsmp/Makefile |  13 +
 drivers/platform/x86/amd/hsmp/acpi.c   | 301 ++++++++
 drivers/platform/x86/amd/hsmp/core.c   | 284 +++++++
 drivers/platform/x86/amd/hsmp/hsmp.h   |  66 ++
 drivers/platform/x86/amd/hsmp/plat.c   | 392 ++++++++++
 12 files changed, 1152 insertions(+), 1010 deletions(-)
 delete mode 100644 drivers/platform/x86/amd/hsmp.c
 create mode 100644 drivers/platform/x86/amd/hsmp/Kconfig
 create mode 100644 drivers/platform/x86/amd/hsmp/Makefile
 create mode 100644 drivers/platform/x86/amd/hsmp/acpi.c
 create mode 100644 drivers/platform/x86/amd/hsmp/core.c
 create mode 100644 drivers/platform/x86/amd/hsmp/hsmp.h
 create mode 100644 drivers/platform/x86/amd/hsmp/plat.c
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 1/2 platform/x86/amd/hsmp: Create hsmp/ directory

This is in preparation for the ACPI and non-ACPI code split. Move hsmp specific code into its own directory, no logical changes.

---
 drivers/platform/x86/amd/Kconfig           | 14 +-------------
 drivers/platform/x86/amd/Makefile          |  3 +--
 drivers/platform/x86/amd/hsmp/Kconfig      | 17 +++++++++++++++++
 drivers/platform/x86/amd/hsmp/Makefile     |  8 ++++++++
 drivers/platform/x86/amd/{ => hsmp}/hsmp.c |  0
 5 files changed, 27 insertions(+), 15 deletions(-)
 create mode 100644 drivers/platform/x86/amd/hsmp/Kconfig
 create mode 100644 drivers/platform/x86/amd/hsmp/Makefile
 rename drivers/platform/x86/amd/{ => hsmp}/hsmp.c (100%)
drivers/platform/x86/amd/Kconfig +1 -13
index f88682d36447..2c671cc17d63 100644
@@ -3,22 +3,10 @@
 # AMD x86 Platform Specific Drivers
 #
 
+source "drivers/platform/x86/amd/hsmp/Kconfig"
 source "drivers/platform/x86/amd/pmf/Kconfig"
 source "drivers/platform/x86/amd/pmc/Kconfig"
 
-config AMD_HSMP
-	tristate "AMD HSMP Driver"
-	depends on AMD_NB && X86_64 && ACPI
-	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 AMD_WBRF
 	bool "AMD Wifi RF Band mitigations (WBRF)"
 	depends on ACPI
drivers/platform/x86/amd/Makefile +1 -2
index dcec0a46f8af..f0b2fe81c685 100644
@@ -5,7 +5,6 @@
 #
 
 obj-$(CONFIG_AMD_PMC)		+= pmc/
-amd_hsmp-y			:= hsmp.o
-obj-$(CONFIG_AMD_HSMP)		+= amd_hsmp.o
+obj-$(CONFIG_AMD_HSMP)		+= hsmp/
 obj-$(CONFIG_AMD_PMF)		+= pmf/
 obj-$(CONFIG_AMD_WBRF)		+= wbrf.o
drivers/platform/x86/amd/hsmp/Kconfig new file +17 -0
new file mode 100644
index 000000000000..b55d4ed9bceb
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# AMD HSMP Driver
+#
+
+config AMD_HSMP
+	tristate "AMD HSMP Driver"
+	depends on AMD_NB && X86_64 && ACPI
+	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.
drivers/platform/x86/amd/hsmp/Makefile new file +8 -0
new file mode 100644
index 000000000000..fda64906a5e8
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for drivers/platform/x86/amd/hsmp
+# AMD HSMP Driver
+#
+
+obj-$(CONFIG_AMD_HSMP)		+= amd_hsmp.o
+amd_hsmp-objs			:= hsmp.o
drivers/platform/x86/amd/hsmp/hsmp.c renamed from drivers/platform/x86/amd/hsmp.c +0 -0
similarity index 100%
rename from drivers/platform/x86/amd/hsmp.c
rename to drivers/platform/x86/amd/hsmp/hsmp.c
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH 2/2 platform/x86/amd/hsmp: Split ACPI and non-ACPI code

In reply to Suma Hegde

Separate the probes for ACPI and non-ACPI supported platforms. Provide a Kconfig option to select either the
ACPI or the non-ACPI (platform device based driver).

This change is done to
- Keep the probes clean of the if else ladder
- Use dev_groups in platform driver structure, instead of using devm_device_add_group()
+ use is_visible() to enable the sysfs entries

---
 Documentation/arch/x86/amd_hsmp.rst    |  60 +-
 MAINTAINERS                            |   2 +-
 arch/x86/include/asm/amd_hsmp.h        |   2 +-
 drivers/platform/x86/amd/Makefile      |   2 +-
 drivers/platform/x86/amd/hsmp/Kconfig  |  22 +-
 drivers/platform/x86/amd/hsmp/Makefile |   9 +-
 drivers/platform/x86/amd/hsmp/acpi.c   | 301 ++++++++
 drivers/platform/x86/amd/hsmp/core.c   | 284 +++++++
 drivers/platform/x86/amd/hsmp/hsmp.c   | 988 -------------------------
 drivers/platform/x86/amd/hsmp/hsmp.h   |  66 ++
 drivers/platform/x86/amd/hsmp/plat.c   | 392 ++++++++++
 11 files changed, 1129 insertions(+), 999 deletions(-)
 create mode 100644 drivers/platform/x86/amd/hsmp/acpi.c
 create mode 100644 drivers/platform/x86/amd/hsmp/core.c
 delete mode 100644 drivers/platform/x86/amd/hsmp/hsmp.c
 create mode 100644 drivers/platform/x86/amd/hsmp/hsmp.h
 create mode 100644 drivers/platform/x86/amd/hsmp/plat.c
Documentation/arch/x86/amd_hsmp.rst +55 -5
index 1e499ecf5f4e..431fb6b6ea57 100644
@@ -4,8 +4,8 @@
 AMD HSMP interface
 ============================================
 
-Newer Fam19h EPYC server line of processors from AMD support system
-management functionality via HSMP (Host System Management Port).
+Newer Fam19h(model 0x00-0x1f, 0x30-0x3f, 0x90-0x9f, 0xa0-0xaf), Fam1Ah(model 0x00-0x1f) 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
@@ -16,14 +16,21 @@ More details on the interface can be found in chapter
 Eg: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip
 
 
-HSMP interface is supported on EPYC server CPU models only.
+HSMP interface is supported on EPYC line of server CPUs and MI300A (APU).
 
 
 HSMP device
 ============================================
 
-amd_hsmp driver under the drivers/platforms/x86/ creates miscdevice
-/dev/hsmp to let user space programs run hsmp mailbox commands.
+amd_hsmp driver under the drivers/platforms/x86/hsmp/ is now split into separate driver files
+with mutually exclusive compile time Kconfig options to choose between ACPI object based probing
+or as a platform device which continues to create the miscdevice /dev/hsmp to let user
+space programs run hsmp mailbox commands.
+
+The ACPI object format supported by the driver is defined below.
+
+Kconfig option CONFIG_AMD_HSMP compiles plat.c + core.c for platform probing.
+Kconfig option CONFIG_AMD_HSMP_ACPI compiles acpi.c + core.c for ACPI probing.
 
 $ ls -al /dev/hsmp
 crw-r--r-- 1 root root 10, 123 Jan 21 21:41 /dev/hsmp
@@ -59,6 +66,49 @@ Note: lseek() is not supported as entire metrics table is read.
 Metrics table definitions will be documented as part of Public PPR.
 The same is defined in the amd_hsmp.h header.
 
+ACPI device object format
+=========================
+The ACPI object format expected from the amd_hsmp driver
+for socket with ID00 is given below.
+Device(HSMP)
+		{
+			Name(_HID, "AMDI0097")
+			Name(_UID, "ID00")
+			Name(HSE0, 0x00000001)
+			Name(RBF0, ResourceTemplate()
+			{
+				Memory32Fixed(ReadWrite, 0xxxxxxx, 0x00100000)
+			})
+			Method(_CRS, 0, NotSerialized)
+			{
+				Return(RBF0)
+			}
+			Method(_STA, 0, NotSerialized)
+			{
+				If(LEqual(HSE0, One))
+				{
+					Return(0x0F)
+				}
+				Else
+				{
+					Return(Zero)
+				}
+			}
+			Name(_DSD, Package(2)
+			{
+				Buffer(0x10)
+				{
+					0x9D, 0x61, 0x4D, 0xB7, 0x07, 0x57, 0xBD, 0x48,
+					0xA6, 0x9F, 0x4E, 0xA2, 0x87, 0x1F, 0xC2, 0xF6
+				},
+				Package(3)
+				{
+					Package(2) {"MsgIdOffset", 0x00010934},
+					Package(2) {"MsgRspOffset", 0x00010980},
+					Package(2) {"MsgArgOffset", 0x000109E0}
+				}
+			})
+		}
 
 An example
 ==========
MAINTAINERS +1 -1
index d6c90161c7bf..a7d79d1f7ec1 100644
@@ -1037,7 +1037,7 @@ S:	Maintained
 F:	Documentation/arch/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
+F:	drivers/platform/x86/amd/hsmp/
 
 AMD IOMMU (AMD-VI)
 M:	Joerg Roedel <[email protected]>
arch/x86/include/asm/amd_hsmp.h +1 -1
index 03c2ce3edaf5..ada14e55f9f4 100644
@@ -5,7 +5,7 @@
 
 #include <uapi/asm/amd_hsmp.h>
 
-#if IS_ENABLED(CONFIG_AMD_HSMP)
+#if IS_ENABLED(CONFIG_AMD_HSMP) || IS_ENABLED(CONFIG_AMD_HSMP_ACPI)
 int hsmp_send_message(struct hsmp_message *msg);
 #else
 static inline int hsmp_send_message(struct hsmp_message *msg)
drivers/platform/x86/amd/Makefile +1 -1
index f0b2fe81c685..96ec24c8701b 100644
@@ -5,6 +5,6 @@
 #
 
 obj-$(CONFIG_AMD_PMC)		+= pmc/
-obj-$(CONFIG_AMD_HSMP)		+= hsmp/
+obj-y				+= hsmp/
 obj-$(CONFIG_AMD_PMF)		+= pmf/
 obj-$(CONFIG_AMD_WBRF)		+= wbrf.o
drivers/platform/x86/amd/hsmp/Kconfig +21 -1
index b55d4ed9bceb..2e54615a09a6 100644
@@ -3,9 +3,27 @@
 # AMD HSMP Driver
 #
 
+menu "AMD Host System Management Port driver"
+	depends on AMD_NB
+
+config AMD_HSMP_ACPI
+	tristate "AMD HSMP ACPI driver"
+	depends on ACPI
+	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.
+
+	  This driver supports ACPI based probing.
+
+	  If you choose to compile this driver as a module the module will be
+	  called amd_hsmp.
+
 config AMD_HSMP
 	tristate "AMD HSMP Driver"
-	depends on AMD_NB && X86_64 && ACPI
+	depends on !(AMD_HSMP_ACPI || AMD_HSMP_ACPI=m)
 	help
 	  The driver provides a way for user space tools to monitor and manage
 	  system management functionality on EPYC server CPUs from AMD.
@@ -15,3 +33,5 @@ config AMD_HSMP
 
 	  If you choose to compile this driver as a module the module will be
 	  called amd_hsmp.
+
+endmenu
drivers/platform/x86/amd/hsmp/Makefile +7 -2
index fda64906a5e8..a2c63de8c93c 100644
@@ -3,6 +3,11 @@
 # Makefile for drivers/platform/x86/amd/hsmp
 # AMD HSMP Driver
 #
-
 obj-$(CONFIG_AMD_HSMP)		+= amd_hsmp.o
-amd_hsmp-objs			:= hsmp.o
+obj-$(CONFIG_AMD_HSMP_ACPI)	+= amd_hsmp.o
+ifneq ($(CONFIG_AMD_HSMP), )
+amd_hsmp-objs = core.o plat.o
+endif
+ifneq ($(CONFIG_AMD_HSMP_ACPI), )
+amd_hsmp-objs = core.o acpi.o
+endif
drivers/platform/x86/amd/hsmp/acpi.c new file +301 -0

301 lines not on this page · raw message

drivers/platform/x86/amd/hsmp/core.c new file +284 -0

284 lines not on this page · raw message

drivers/platform/x86/amd/hsmp/hsmp.c deleted +0 -988

988 lines not on this page · raw message

drivers/platform/x86/amd/hsmp/hsmp.h new file +66 -0

66 lines not on this page · raw message

drivers/platform/x86/amd/hsmp/plat.c new file +392 -0

392 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH 2/2] platform/x86/amd/hsmp: Split ACPI and non-ACPI code

Quoted 4 lines · Suma Hegde

Separate the probes for ACPI and non-ACPI supported platforms. Provide a Kconfig option to select either the
ACPI or the non-ACPI (platform device based driver).

Quoted 8 lines

This change is done to
- Keep the probes clean of the if else ladder
- Use dev_groups in platform driver structure, instead of using devm_device_add_group()
+ use is_visible() to enable the sysfs entries

This will be quite tedious to review in the current form because it combines mass-moving of code with non-move changes. I'd expect it to be significantly easier to review if the existing functions would be copied 1:1 to the respective files first and then another change does the actual separation.

You might need to add a few extra function prototypes into the header in the intermediate state but I believe it's still going to be huge win even if you'll need to remove some of those prototypes when the actual split commences in the second change.

A few general comments:

- EXPORTs should be namespaced.

- Directly include <> headers in the individual files .c, don't mass include them through "hsmp.h" as clearly they'll be different for ACPI/non-ACPI to some extent.

Signature · 1 line
 i.