Skip to content

Commit 79821b9

Browse files
yghannambp3tk0v
authored andcommitted
x86/amd_node: Use defines for SMN register offsets
There are more than one SMN index/data pair available for software use. The register offsets are different, but the protocol is the same. Use defines for the SMN offset values and allow the index/data offsets to be passed to the read/write helper function. This eases code reuse with other SMN users in the kernel. Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20241206161210.163701-14-yazen.ghannam@amd.com
1 parent 77466b7 commit 79821b9

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

arch/x86/kernel/amd_node.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ static struct pci_dev **amd_roots;
9494
/* Protect the PCI config register pairs used for SMN. */
9595
static DEFINE_MUTEX(smn_mutex);
9696

97+
#define SMN_INDEX_OFFSET 0x60
98+
#define SMN_DATA_OFFSET 0x64
99+
97100
/*
98101
* SMN accesses may fail in ways that are difficult to detect here in the called
99102
* functions amd_smn_read() and amd_smn_write(). Therefore, callers must do
@@ -131,7 +134,7 @@ static DEFINE_MUTEX(smn_mutex);
131134
* the operation is considered a success, and the caller does their own
132135
* checking.
133136
*/
134-
static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
137+
static int __amd_smn_rw(u8 i_off, u8 d_off, u16 node, u32 address, u32 *value, bool write)
135138
{
136139
struct pci_dev *root;
137140
int err = -ENODEV;
@@ -145,21 +148,21 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
145148

146149
guard(mutex)(&smn_mutex);
147150

148-
err = pci_write_config_dword(root, 0x60, address);
151+
err = pci_write_config_dword(root, i_off, address);
149152
if (err) {
150153
pr_warn("Error programming SMN address 0x%x.\n", address);
151154
return pcibios_err_to_errno(err);
152155
}
153156

154-
err = (write ? pci_write_config_dword(root, 0x64, *value)
155-
: pci_read_config_dword(root, 0x64, value));
157+
err = (write ? pci_write_config_dword(root, d_off, *value)
158+
: pci_read_config_dword(root, d_off, value));
156159

157160
return pcibios_err_to_errno(err);
158161
}
159162

160163
int __must_check amd_smn_read(u16 node, u32 address, u32 *value)
161164
{
162-
int err = __amd_smn_rw(node, address, value, false);
165+
int err = __amd_smn_rw(SMN_INDEX_OFFSET, SMN_DATA_OFFSET, node, address, value, false);
163166

164167
if (PCI_POSSIBLE_ERROR(*value)) {
165168
err = -ENODEV;
@@ -172,7 +175,7 @@ EXPORT_SYMBOL_GPL(amd_smn_read);
172175

173176
int __must_check amd_smn_write(u16 node, u32 address, u32 value)
174177
{
175-
return __amd_smn_rw(node, address, &value, true);
178+
return __amd_smn_rw(SMN_INDEX_OFFSET, SMN_DATA_OFFSET, node, address, &value, true);
176179
}
177180
EXPORT_SYMBOL_GPL(amd_smn_write);
178181

0 commit comments

Comments
 (0)