Skip to content

Commit 77466b7

Browse files
yghannambp3tk0v
authored andcommitted
x86/amd_node: Remove dependency on AMD_NB
Cache the root devices locally so that there are no more dependencies on AMD_NB. Signed-off-by: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 35df797 commit 77466b7

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

arch/x86/kernel/amd_node.c

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Author: Yazen Ghannam <[email protected]>
99
*/
1010

11-
#include <asm/amd_nb.h>
1211
#include <asm/amd_node.h>
1312

1413
/*
@@ -90,6 +89,8 @@ struct pci_dev *amd_node_get_root(u16 node)
9089
return root;
9190
}
9291

92+
static struct pci_dev **amd_roots;
93+
9394
/* Protect the PCI config register pairs used for SMN. */
9495
static DEFINE_MUTEX(smn_mutex);
9596

@@ -135,10 +136,10 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
135136
struct pci_dev *root;
136137
int err = -ENODEV;
137138

138-
if (node >= amd_nb_num())
139+
if (node >= amd_num_nodes())
139140
return err;
140141

141-
root = node_to_amd_nb(node)->root;
142+
root = amd_roots[node];
142143
if (!root)
143144
return err;
144145

@@ -174,3 +175,38 @@ int __must_check amd_smn_write(u16 node, u32 address, u32 value)
174175
return __amd_smn_rw(node, address, &value, true);
175176
}
176177
EXPORT_SYMBOL_GPL(amd_smn_write);
178+
179+
static int amd_cache_roots(void)
180+
{
181+
u16 node, num_nodes = amd_num_nodes();
182+
183+
amd_roots = kcalloc(num_nodes, sizeof(*amd_roots), GFP_KERNEL);
184+
if (!amd_roots)
185+
return -ENOMEM;
186+
187+
for (node = 0; node < num_nodes; node++)
188+
amd_roots[node] = amd_node_get_root(node);
189+
190+
return 0;
191+
}
192+
193+
static int __init amd_smn_init(void)
194+
{
195+
int err;
196+
197+
if (!cpu_feature_enabled(X86_FEATURE_ZEN))
198+
return 0;
199+
200+
guard(mutex)(&smn_mutex);
201+
202+
if (amd_roots)
203+
return 0;
204+
205+
err = amd_cache_roots();
206+
if (err)
207+
return err;
208+
209+
return 0;
210+
}
211+
212+
fs_initcall(amd_smn_init);

0 commit comments

Comments
 (0)