Skip to content

Commit 9b7fdef

Browse files
committed
Merge: Update platform/x86/amd/hsmp
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7124 Newer AMD Fam19h and Fam1Ah EPYC 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. Update the driver to support the latest functions. JIRA: https://issues.redhat.com/browse/RHEL-102859 Signed-off-by: David Arcari <darcari@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: Lenny Szubowicz <lszubowi@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Patrick Talbert <ptalbert@redhat.com>
2 parents 72a2be6 + 754a143 commit 9b7fdef

File tree

39 files changed

+2376
-1351
lines changed

39 files changed

+2376
-1351
lines changed

Documentation/arch/x86/amd_hsmp.rst

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,38 @@
44
AMD HSMP interface
55
============================================
66

7-
Newer Fam19h EPYC server line of processors from AMD support system
8-
management functionality via HSMP (Host System Management Port).
7+
Newer Fam19h(model 0x00-0x1f, 0x30-0x3f, 0x90-0x9f, 0xa0-0xaf),
8+
Fam1Ah(model 0x00-0x1f) EPYC server line of processors from AMD support
9+
system management functionality via HSMP (Host System Management Port).
910

1011
The Host System Management Port (HSMP) is an interface to provide
1112
OS-level software with access to system management functions via a
1213
set of mailbox registers.
1314

1415
More details on the interface can be found in chapter
1516
"7 Host System Management Port (HSMP)" of the family/model PPR
16-
Eg: https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip
17+
Eg: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip
1718

18-
HSMP interface is supported on EPYC server CPU models only.
19+
20+
HSMP interface is supported on EPYC line of server CPUs and MI300A (APU).
1921

2022

2123
HSMP device
2224
============================================
2325

24-
amd_hsmp driver under the drivers/platforms/x86/ creates miscdevice
25-
/dev/hsmp to let user space programs run hsmp mailbox commands.
26+
amd_hsmp driver under drivers/platforms/x86/amd/hsmp/ has separate driver files
27+
for ACPI object based probing, platform device based probing and for the common
28+
code for these two drivers.
29+
30+
Kconfig option CONFIG_AMD_HSMP_PLAT compiles plat.c and creates amd_hsmp.ko.
31+
Kconfig option CONFIG_AMD_HSMP_ACPI compiles acpi.c and creates hsmp_acpi.ko.
32+
Selecting any of these two configs automatically selects CONFIG_AMD_HSMP. This
33+
compiles common code hsmp.c and creates hsmp_common.ko module.
34+
35+
Both the ACPI and plat drivers create the miscdevice /dev/hsmp to let
36+
user space programs run hsmp mailbox commands.
37+
38+
The ACPI object format supported by the driver is defined below.
2639

2740
$ ls -al /dev/hsmp
2841
crw-r--r-- 1 root root 10, 123 Jan 21 21:41 /dev/hsmp
@@ -58,6 +71,81 @@ Note: lseek() is not supported as entire metrics table is read.
5871
Metrics table definitions will be documented as part of Public PPR.
5972
The same is defined in the amd_hsmp.h header.
6073

74+
2. HSMP telemetry sysfs files
75+
76+
Following sysfs files are available at /sys/devices/platform/AMDI0097:0X/.
77+
78+
* c0_residency_input: Percentage of cores in C0 state.
79+
* prochot_status: Reports 1 if the processor is at thermal threshold value,
80+
0 otherwise.
81+
* smu_fw_version: SMU firmware version.
82+
* protocol_version: HSMP interface version.
83+
* ddr_max_bw: Theoretical maximum DDR bandwidth in GB/s.
84+
* ddr_utilised_bw_input: Current utilized DDR bandwidth in GB/s.
85+
* ddr_utilised_bw_perc_input(%): Percentage of current utilized DDR bandwidth.
86+
* mclk_input: Memory clock in MHz.
87+
* fclk_input: Fabric clock in MHz.
88+
* clk_fmax: Maximum frequency of socket in MHz.
89+
* clk_fmin: Minimum frequency of socket in MHz.
90+
* cclk_freq_limit_input: Core clock frequency limit per socket in MHz.
91+
* pwr_current_active_freq_limit: Current active frequency limit of socket
92+
in MHz.
93+
* pwr_current_active_freq_limit_source: Source of current active frequency
94+
limit.
95+
96+
ACPI device object format
97+
=========================
98+
The ACPI object format expected from the amd_hsmp driver
99+
for socket with ID00 is given below::
100+
101+
Device(HSMP)
102+
{
103+
Name(_HID, "AMDI0097")
104+
Name(_UID, "ID00")
105+
Name(HSE0, 0x00000001)
106+
Name(RBF0, ResourceTemplate()
107+
{
108+
Memory32Fixed(ReadWrite, 0xxxxxxx, 0x00100000)
109+
})
110+
Method(_CRS, 0, NotSerialized)
111+
{
112+
Return(RBF0)
113+
}
114+
Method(_STA, 0, NotSerialized)
115+
{
116+
If(LEqual(HSE0, One))
117+
{
118+
Return(0x0F)
119+
}
120+
Else
121+
{
122+
Return(Zero)
123+
}
124+
}
125+
Name(_DSD, Package(2)
126+
{
127+
Buffer(0x10)
128+
{
129+
0x9D, 0x61, 0x4D, 0xB7, 0x07, 0x57, 0xBD, 0x48,
130+
0xA6, 0x9F, 0x4E, 0xA2, 0x87, 0x1F, 0xC2, 0xF6
131+
},
132+
Package(3)
133+
{
134+
Package(2) {"MsgIdOffset", 0x00010934},
135+
Package(2) {"MsgRspOffset", 0x00010980},
136+
Package(2) {"MsgArgOffset", 0x000109E0}
137+
}
138+
})
139+
}
140+
141+
HSMP HWMON interface
142+
====================
143+
HSMP power sensors are registered with the hwmon interface. A separate hwmon
144+
directory is created for each socket and the following files are generated
145+
within the hwmon directory.
146+
- power1_input (read only)
147+
- power1_cap_max (read only)
148+
- power1_cap (read, write)
61149

62150
An example
63151
==========
@@ -97,8 +185,8 @@ what happened. The transaction returns 0 on success.
97185

98186
More details on the interface and message definitions can be found in chapter
99187
"7 Host System Management Port (HSMP)" of the respective family/model PPR
100-
eg: https://www.amd.com/system/files/TechDocs/55898_B1_pub_0.50.zip
188+
eg: https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/programmer-references/55898_B1_pub_0_50.zip
101189

102190
User space C-APIs are made available by linking against the esmi library,
103-
which is provided by the E-SMS project https://developer.amd.com/e-sms/.
191+
which is provided by the E-SMS project https://www.amd.com/en/developer/e-sms.html.
104192
See: https://github.com/amd/esmi_ib_library

MAINTAINERS

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,14 @@ L: linux-i2c@vger.kernel.org
10341034
S: Maintained
10351035
F: drivers/i2c/busses/i2c-amd-mp2*
10361036

1037+
AMD NODE DRIVER
1038+
M: Mario Limonciello <mario.limonciello@amd.com>
1039+
M: Yazen Ghannam <yazen.ghannam@amd.com>
1040+
L: linux-kernel@vger.kernel.org
1041+
S: Supported
1042+
F: arch/x86/include/asm/amd/node.h
1043+
F: arch/x86/kernel/amd_node.c
1044+
10371045
AMD PMC DRIVER
10381046
M: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
10391047
L: platform-driver-x86@vger.kernel.org
@@ -1046,9 +1054,9 @@ R: Carlos Bilbao <carlos.bilbao@amd.com>
10461054
L: platform-driver-x86@vger.kernel.org
10471055
S: Maintained
10481056
F: Documentation/arch/x86/amd_hsmp.rst
1049-
F: arch/x86/include/asm/amd_hsmp.h
1057+
F: arch/x86/include/asm/amd/hsmp.h
10501058
F: arch/x86/include/uapi/asm/amd_hsmp.h
1051-
F: drivers/platform/x86/amd/hsmp.c
1059+
F: drivers/platform/x86/amd/hsmp/
10521060

10531061
AMD POWERPLAY
10541062
M: Evan Quan <evan.quan@amd.com>

arch/x86/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,6 +3122,10 @@ config TS5500
31223122
endif # X86_32
31233123

31243124
config AMD_NB
3125+
def_bool y
3126+
depends on AMD_NODE
3127+
3128+
config AMD_NODE
31253129
def_bool y
31263130
depends on CPU_SUP_AMD && PCI
31273131

arch/x86/include/asm/amd_hsmp.h renamed to arch/x86/include/asm/amd/hsmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2-
32
#ifndef _ASM_X86_AMD_HSMP_H_
43
#define _ASM_X86_AMD_HSMP_H_
54

@@ -13,4 +12,5 @@ static inline int hsmp_send_message(struct hsmp_message *msg)
1312
return -ENODEV;
1413
}
1514
#endif
15+
1616
#endif /*_ASM_X86_AMD_HSMP_H_*/

arch/x86/include/asm/amd/node.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* AMD Node helper functions and common defines
4+
*
5+
* Copyright (c) 2024, Advanced Micro Devices, Inc.
6+
* All Rights Reserved.
7+
*
8+
* Author: Yazen Ghannam <Yazen.Ghannam@amd.com>
9+
*
10+
* Note:
11+
* Items in this file may only be used in a single place.
12+
* However, it's prudent to keep all AMD Node functionality
13+
* in a unified place rather than spreading throughout the
14+
* kernel.
15+
*/
16+
17+
#ifndef _ASM_X86_AMD_NODE_H_
18+
#define _ASM_X86_AMD_NODE_H_
19+
20+
#include <linux/pci.h>
21+
22+
#define MAX_AMD_NUM_NODES 8
23+
#define AMD_NODE0_PCI_SLOT 0x18
24+
25+
struct pci_dev *amd_node_get_func(u16 node, u8 func);
26+
struct pci_dev *amd_node_get_root(u16 node);
27+
28+
static inline u16 amd_num_nodes(void)
29+
{
30+
return topology_amd_nodes_per_pkg() * topology_max_packages();
31+
}
32+
33+
#ifdef CONFIG_AMD_NODE
34+
int __must_check amd_smn_read(u16 node, u32 address, u32 *value);
35+
int __must_check amd_smn_write(u16 node, u32 address, u32 value);
36+
37+
/* Should only be used by the HSMP driver. */
38+
int __must_check amd_smn_hsmp_rdwr(u16 node, u32 address, u32 *value, bool write);
39+
#else
40+
static inline int __must_check amd_smn_read(u16 node, u32 address, u32 *value) { return -ENODEV; }
41+
static inline int __must_check amd_smn_write(u16 node, u32 address, u32 value) { return -ENODEV; }
42+
43+
static inline int __must_check amd_smn_hsmp_rdwr(u16 node, u32 address, u32 *value, bool write)
44+
{
45+
return -ENODEV;
46+
}
47+
#endif /* CONFIG_AMD_NODE */
48+
49+
#endif /*_ASM_X86_AMD_NODE_H_*/

arch/x86/include/asm/amd_nb.h

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <linux/ioport.h>
66
#include <linux/pci.h>
7-
#include <linux/refcount.h>
7+
#include <asm/amd/node.h>
88

99
struct amd_nb_bus_dev_range {
1010
u8 bus;
@@ -21,9 +21,6 @@ extern int amd_numa_init(void);
2121
extern int amd_get_subcaches(int);
2222
extern int amd_set_subcaches(int, unsigned long);
2323

24-
extern int amd_smn_read(u16 node, u32 address, u32 *value);
25-
extern int amd_smn_write(u16 node, u32 address, u32 value);
26-
2724
struct amd_l3_cache {
2825
unsigned indices;
2926
u8 subcaches[4];
@@ -59,7 +56,6 @@ struct threshold_bank {
5956
};
6057

6158
struct amd_northbridge {
62-
struct pci_dev *root;
6359
struct pci_dev *misc;
6460
struct pci_dev *link;
6561
struct amd_l3_cache l3_cache;
@@ -82,23 +78,6 @@ u16 amd_nb_num(void);
8278
bool amd_nb_has_feature(unsigned int feature);
8379
struct amd_northbridge *node_to_amd_nb(int node);
8480

85-
static inline u16 amd_pci_dev_to_node_id(struct pci_dev *pdev)
86-
{
87-
struct pci_dev *misc;
88-
int i;
89-
90-
for (i = 0; i != amd_nb_num(); i++) {
91-
misc = node_to_amd_nb(i)->misc;
92-
93-
if (pci_domain_nr(misc->bus) == pci_domain_nr(pdev->bus) &&
94-
PCI_SLOT(misc->devfn) == PCI_SLOT(pdev->devfn))
95-
return i;
96-
}
97-
98-
WARN(1, "Unable to find AMD Northbridge id for %s\n", pci_name(pdev));
99-
return 0;
100-
}
101-
10281
static inline bool amd_gart_present(void)
10382
{
10483
if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)

arch/x86/include/uapi/asm/amd_hsmp.h

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ enum hsmp_message_ids {
5050
HSMP_GET_METRIC_TABLE_VER, /* 23h Get metrics table version */
5151
HSMP_GET_METRIC_TABLE, /* 24h Get metrics table */
5252
HSMP_GET_METRIC_TABLE_DRAM_ADDR,/* 25h Get metrics table dram address */
53+
HSMP_SET_XGMI_PSTATE_RANGE, /* 26h Set xGMI P-state range */
54+
HSMP_CPU_RAIL_ISO_FREQ_POLICY, /* 27h Get/Set Cpu Iso frequency policy */
55+
HSMP_DFC_ENABLE_CTRL, /* 28h Enable/Disable DF C-state */
56+
HSMP_GET_RAPL_UNITS = 0x30, /* 30h Get scaling factor for energy */
57+
HSMP_GET_RAPL_CORE_COUNTER, /* 31h Get core energy counter value */
58+
HSMP_GET_RAPL_PACKAGE_COUNTER, /* 32h Get package energy counter value */
5359
HSMP_MSG_ID_MAX,
5460
};
5561

@@ -65,14 +71,16 @@ enum hsmp_msg_type {
6571
HSMP_RSVD = -1,
6672
HSMP_SET = 0,
6773
HSMP_GET = 1,
74+
HSMP_SET_GET = 2,
6875
};
6976

7077
enum hsmp_proto_versions {
7178
HSMP_PROTO_VER2 = 2,
7279
HSMP_PROTO_VER3,
7380
HSMP_PROTO_VER4,
7481
HSMP_PROTO_VER5,
75-
HSMP_PROTO_VER6
82+
HSMP_PROTO_VER6,
83+
HSMP_PROTO_VER7
7684
};
7785

7886
struct hsmp_msg_desc {
@@ -88,7 +96,8 @@ struct hsmp_msg_desc {
8896
*
8997
* Not supported messages would return -ENOMSG.
9098
*/
91-
static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
99+
static const struct hsmp_msg_desc hsmp_msg_desc_table[]
100+
__attribute__((unused)) = {
92101
/* RESERVED */
93102
{0, 0, HSMP_RSVD},
94103

@@ -299,7 +308,7 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
299308
* HSMP_SET_POWER_MODE, num_args = 1, response_sz = 0
300309
* input: args[0] = power efficiency mode[2:0]
301310
*/
302-
{1, 0, HSMP_SET},
311+
{1, 1, HSMP_SET_GET},
303312

304313
/*
305314
* HSMP_SET_PSTATE_MAX_MIN, num_args = 1, response_sz = 0
@@ -324,6 +333,58 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
324333
* output: args[1] = upper 32 bits of the address
325334
*/
326335
{0, 2, HSMP_GET},
336+
337+
/*
338+
* HSMP_SET_XGMI_PSTATE_RANGE, num_args = 1, response_sz = 0
339+
* input: args[0] = min xGMI p-state[15:8] + max xGMI p-state[7:0]
340+
*/
341+
{1, 0, HSMP_SET},
342+
343+
/*
344+
* HSMP_CPU_RAIL_ISO_FREQ_POLICY, num_args = 1, response_sz = 1
345+
* input: args[0] = set/get policy[31] +
346+
* disable/enable independent control[0]
347+
* output: args[0] = current policy[0]
348+
*/
349+
{1, 1, HSMP_SET_GET},
350+
351+
/*
352+
* HSMP_DFC_ENABLE_CTRL, num_args = 1, response_sz = 1
353+
* input: args[0] = set/get policy[31] + enable/disable DFC[0]
354+
* output: args[0] = current policy[0]
355+
*/
356+
{1, 1, HSMP_SET_GET},
357+
358+
/* RESERVED(0x29-0x2f) */
359+
{0, 0, HSMP_RSVD},
360+
{0, 0, HSMP_RSVD},
361+
{0, 0, HSMP_RSVD},
362+
{0, 0, HSMP_RSVD},
363+
{0, 0, HSMP_RSVD},
364+
{0, 0, HSMP_RSVD},
365+
{0, 0, HSMP_RSVD},
366+
367+
/*
368+
* HSMP_GET_RAPL_UNITS, response_sz = 1
369+
* output: args[0] = tu value[19:16] + esu value[12:8]
370+
*/
371+
{0, 1, HSMP_GET},
372+
373+
/*
374+
* HSMP_GET_RAPL_CORE_COUNTER, num_args = 1, response_sz = 1
375+
* input: args[0] = apic id[15:0]
376+
* output: args[0] = lower 32 bits of energy
377+
* output: args[1] = upper 32 bits of energy
378+
*/
379+
{1, 2, HSMP_GET},
380+
381+
/*
382+
* HSMP_GET_RAPL_PACKAGE_COUNTER, num_args = 0, response_sz = 1
383+
* output: args[0] = lower 32 bits of energy
384+
* output: args[1] = upper 32 bits of energy
385+
*/
386+
{0, 2, HSMP_GET},
387+
327388
};
328389

329390
/* Metrics table (supported only with proto version 6) */

0 commit comments

Comments
 (0)