forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/arch/x86/kernel/amd_nb.c
....@@ -1,6 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Shared support code for AMD K8 northbridges and derivates.
3
- * Copyright 2006 Andi Kleen, SUSE Labs. Subject to GPLv2.
4
+ * Copyright 2006 Andi Kleen, SUSE Labs.
45 */
56
67 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -17,9 +18,11 @@
1718 #define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450
1819 #define PCI_DEVICE_ID_AMD_17H_M10H_ROOT 0x15d0
1920 #define PCI_DEVICE_ID_AMD_17H_M30H_ROOT 0x1480
21
+#define PCI_DEVICE_ID_AMD_17H_M60H_ROOT 0x1630
2022 #define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464
2123 #define PCI_DEVICE_ID_AMD_17H_M10H_DF_F4 0x15ec
2224 #define PCI_DEVICE_ID_AMD_17H_M30H_DF_F4 0x1494
25
+#define PCI_DEVICE_ID_AMD_17H_M60H_DF_F4 0x144c
2326 #define PCI_DEVICE_ID_AMD_17H_M70H_DF_F4 0x1444
2427 #define PCI_DEVICE_ID_AMD_19H_DF_F4 0x1654
2528
....@@ -32,13 +35,13 @@
3235 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_ROOT) },
3336 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_ROOT) },
3437 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_ROOT) },
38
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M60H_ROOT) },
3539 {}
3640 };
3741
38
-
3942 #define PCI_DEVICE_ID_AMD_CNB17H_F4 0x1704
4043
41
-const struct pci_device_id amd_nb_misc_ids[] = {
44
+static const struct pci_device_id amd_nb_misc_ids[] = {
4245 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
4346 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
4447 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
....@@ -50,12 +53,12 @@
5053 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) },
5154 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F3) },
5255 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F3) },
56
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M60H_DF_F3) },
5357 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
5458 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F3) },
5559 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_DF_F3) },
5660 {}
5761 };
58
-EXPORT_SYMBOL_GPL(amd_nb_misc_ids);
5962
6063 static const struct pci_device_id amd_nb_link_ids[] = {
6164 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
....@@ -66,9 +69,25 @@
6669 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) },
6770 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F4) },
6871 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F4) },
72
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M60H_DF_F4) },
6973 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F4) },
7074 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_DF_F4) },
7175 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) },
76
+ {}
77
+};
78
+
79
+static const struct pci_device_id hygon_root_ids[] = {
80
+ { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_17H_ROOT) },
81
+ {}
82
+};
83
+
84
+static const struct pci_device_id hygon_nb_misc_ids[] = {
85
+ { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_17H_DF_F3) },
86
+ {}
87
+};
88
+
89
+static const struct pci_device_id hygon_nb_link_ids[] = {
90
+ { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_17H_DF_F4) },
7291 {}
7392 };
7493
....@@ -205,35 +224,76 @@
205224
206225 int amd_cache_northbridges(void)
207226 {
208
- u16 i = 0;
209
- struct amd_northbridge *nb;
227
+ const struct pci_device_id *misc_ids = amd_nb_misc_ids;
228
+ const struct pci_device_id *link_ids = amd_nb_link_ids;
229
+ const struct pci_device_id *root_ids = amd_root_ids;
210230 struct pci_dev *root, *misc, *link;
231
+ struct amd_northbridge *nb;
232
+ u16 roots_per_misc = 0;
233
+ u16 misc_count = 0;
234
+ u16 root_count = 0;
235
+ u16 i, j;
211236
212237 if (amd_northbridges.num)
213238 return 0;
214239
215
- misc = NULL;
216
- while ((misc = next_northbridge(misc, amd_nb_misc_ids)) != NULL)
217
- i++;
240
+ if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
241
+ root_ids = hygon_root_ids;
242
+ misc_ids = hygon_nb_misc_ids;
243
+ link_ids = hygon_nb_link_ids;
244
+ }
218245
219
- if (!i)
246
+ misc = NULL;
247
+ while ((misc = next_northbridge(misc, misc_ids)) != NULL)
248
+ misc_count++;
249
+
250
+ if (!misc_count)
220251 return -ENODEV;
221252
222
- nb = kcalloc(i, sizeof(struct amd_northbridge), GFP_KERNEL);
253
+ root = NULL;
254
+ while ((root = next_northbridge(root, root_ids)) != NULL)
255
+ root_count++;
256
+
257
+ if (root_count) {
258
+ roots_per_misc = root_count / misc_count;
259
+
260
+ /*
261
+ * There should be _exactly_ N roots for each DF/SMN
262
+ * interface.
263
+ */
264
+ if (!roots_per_misc || (root_count % roots_per_misc)) {
265
+ pr_info("Unsupported AMD DF/PCI configuration found\n");
266
+ return -ENODEV;
267
+ }
268
+ }
269
+
270
+ nb = kcalloc(misc_count, sizeof(struct amd_northbridge), GFP_KERNEL);
223271 if (!nb)
224272 return -ENOMEM;
225273
226274 amd_northbridges.nb = nb;
227
- amd_northbridges.num = i;
275
+ amd_northbridges.num = misc_count;
228276
229277 link = misc = root = NULL;
230
- for (i = 0; i != amd_northbridges.num; i++) {
278
+ for (i = 0; i < amd_northbridges.num; i++) {
231279 node_to_amd_nb(i)->root = root =
232
- next_northbridge(root, amd_root_ids);
280
+ next_northbridge(root, root_ids);
233281 node_to_amd_nb(i)->misc = misc =
234
- next_northbridge(misc, amd_nb_misc_ids);
282
+ next_northbridge(misc, misc_ids);
235283 node_to_amd_nb(i)->link = link =
236
- next_northbridge(link, amd_nb_link_ids);
284
+ next_northbridge(link, link_ids);
285
+
286
+ /*
287
+ * If there are more PCI root devices than data fabric/
288
+ * system management network interfaces, then the (N)
289
+ * PCI roots per DF/SMN interface are functionally the
290
+ * same (for DF/SMN access) and N-1 are redundant. N-1
291
+ * PCI roots should be skipped per DF/SMN interface so
292
+ * the following DF/SMN interfaces get mapped to
293
+ * correct PCI roots.
294
+ */
295
+ for (j = 1; j < roots_per_misc; j++)
296
+ root = next_northbridge(root, root_ids);
237297 }
238298
239299 if (amd_gart_present())
....@@ -272,11 +332,19 @@
272332 */
273333 bool __init early_is_amd_nb(u32 device)
274334 {
335
+ const struct pci_device_id *misc_ids = amd_nb_misc_ids;
275336 const struct pci_device_id *id;
276337 u32 vendor = device & 0xffff;
277338
339
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
340
+ boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
341
+ return false;
342
+
343
+ if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)
344
+ misc_ids = hygon_nb_misc_ids;
345
+
278346 device >>= 16;
279
- for (id = amd_nb_misc_ids; id->vendor; id++)
347
+ for (id = misc_ids; id->vendor; id++)
280348 if (vendor == id->vendor && device == id->device)
281349 return true;
282350 return false;
....@@ -288,7 +356,8 @@
288356 u64 base, msr;
289357 unsigned int segn_busn_bits;
290358
291
- if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
359
+ if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
360
+ boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
292361 return NULL;
293362
294363 /* assume all cpus from fam10h have mmconfig */