Skip to content

Commit bc7b2e6

Browse files
yghannambp3tk0v
authored andcommitted
x86/amd_nb: Use topology info to get AMD node count
Currently, the total AMD node count is determined by searching and counting CPU/node devices using PCI IDs. However, AMD node information is already available through topology CPUID/MSRs. The recent topology rework has made this info easier to access. Replace the node counting code with a simple product of topology info. Every node/northbridge is expected to have a 'misc' device. Clear everything out if a 'misc' device isn't found on a node. 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 40a5f6f commit bc7b2e6

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

arch/x86/include/asm/amd_node.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
struct pci_dev *amd_node_get_func(u16 node, u8 func);
2626
struct pci_dev *amd_node_get_root(u16 node);
2727

28+
static inline u16 amd_num_nodes(void)
29+
{
30+
return topology_amd_nodes_per_pkg() * topology_max_packages();
31+
}
32+
2833
#endif /*_ASM_X86_AMD_NODE_H_*/

arch/x86/kernel/amd_nb.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ static int amd_cache_northbridges(void)
186186
const struct pci_device_id *misc_ids = amd_nb_misc_ids;
187187
struct pci_dev *misc;
188188
struct amd_northbridge *nb;
189-
u16 misc_count = 0;
190189
u16 i;
191190

192191
if (amd_northbridges.num)
@@ -196,25 +195,30 @@ static int amd_cache_northbridges(void)
196195
misc_ids = hygon_nb_misc_ids;
197196
}
198197

199-
misc = NULL;
200-
while ((misc = next_northbridge(misc, misc_ids)))
201-
misc_count++;
202-
203-
if (!misc_count)
204-
return -ENODEV;
198+
amd_northbridges.num = amd_num_nodes();
205199

206-
nb = kcalloc(misc_count, sizeof(struct amd_northbridge), GFP_KERNEL);
200+
nb = kcalloc(amd_northbridges.num, sizeof(struct amd_northbridge), GFP_KERNEL);
207201
if (!nb)
208202
return -ENOMEM;
209203

210204
amd_northbridges.nb = nb;
211-
amd_northbridges.num = misc_count;
212205

213206
misc = NULL;
214207
for (i = 0; i < amd_northbridges.num; i++) {
215208
node_to_amd_nb(i)->root = amd_node_get_root(i);
216209
node_to_amd_nb(i)->misc = misc =
217210
next_northbridge(misc, misc_ids);
211+
212+
/*
213+
* Each Northbridge must have a 'misc' device.
214+
* If not, then uninitialize everything.
215+
*/
216+
if (!node_to_amd_nb(i)->misc) {
217+
amd_northbridges.num = 0;
218+
kfree(nb);
219+
return -ENODEV;
220+
}
221+
218222
node_to_amd_nb(i)->link = amd_node_get_func(i, 4);
219223
}
220224

0 commit comments

Comments
 (0)