|
8 | 8 | * Author: Yazen Ghannam <[email protected]>
|
9 | 9 | */
|
10 | 10 |
|
11 |
| -#include <asm/amd_nb.h> |
12 | 11 | #include <asm/amd_node.h>
|
13 | 12 |
|
14 | 13 | /*
|
@@ -90,6 +89,8 @@ struct pci_dev *amd_node_get_root(u16 node)
|
90 | 89 | return root;
|
91 | 90 | }
|
92 | 91 |
|
| 92 | +static struct pci_dev **amd_roots; |
| 93 | + |
93 | 94 | /* Protect the PCI config register pairs used for SMN. */
|
94 | 95 | static DEFINE_MUTEX(smn_mutex);
|
95 | 96 |
|
@@ -135,10 +136,10 @@ static int __amd_smn_rw(u16 node, u32 address, u32 *value, bool write)
|
135 | 136 | struct pci_dev *root;
|
136 | 137 | int err = -ENODEV;
|
137 | 138 |
|
138 |
| - if (node >= amd_nb_num()) |
| 139 | + if (node >= amd_num_nodes()) |
139 | 140 | return err;
|
140 | 141 |
|
141 |
| - root = node_to_amd_nb(node)->root; |
| 142 | + root = amd_roots[node]; |
142 | 143 | if (!root)
|
143 | 144 | return err;
|
144 | 145 |
|
@@ -174,3 +175,38 @@ int __must_check amd_smn_write(u16 node, u32 address, u32 value)
|
174 | 175 | return __amd_smn_rw(node, address, &value, true);
|
175 | 176 | }
|
176 | 177 | 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