]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/amd_nb: Simplify function 4 search
authorYazen Ghannam <yazen.ghannam@amd.com>
Fri, 6 Dec 2024 16:11:58 +0000 (16:11 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Wed, 8 Jan 2025 09:47:50 +0000 (10:47 +0100)
Use the newly added helper function to look up a CPU/Node function to
find "function 4" devices.

Thus, avoid the need to regularly add new PCI IDs for basic discovery.
The unique PCI IDs are still useful in case of quirks or functional
changes. And they should be used only in such a manner.

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-6-yazen.ghannam@amd.com
arch/x86/include/asm/amd_nb.h
arch/x86/kernel/amd_nb.c

index d0caac26533f22e78c4776b4921102df5edd423b..b48dc6975da27b9fbd09015ce61f7d62080b9729 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <linux/ioport.h>
 #include <linux/pci.h>
-#include <linux/refcount.h>
+#include <asm/amd_node.h>
 
 struct amd_nb_bus_dev_range {
        u8 bus;
index ee20071ced997ba4183ed1c0ff2888de5c25a487..7a62c5af253122e8e66bd744b0c23f48efe7feb7 100644 (file)
 #define PCI_DEVICE_ID_AMD_MI200_ROOT           0x14bb
 #define PCI_DEVICE_ID_AMD_MI300_ROOT           0x14f8
 
-#define PCI_DEVICE_ID_AMD_17H_DF_F4            0x1464
-#define PCI_DEVICE_ID_AMD_17H_M10H_DF_F4       0x15ec
-#define PCI_DEVICE_ID_AMD_17H_M30H_DF_F4       0x1494
-#define PCI_DEVICE_ID_AMD_17H_M60H_DF_F4       0x144c
-#define PCI_DEVICE_ID_AMD_17H_M70H_DF_F4       0x1444
-#define PCI_DEVICE_ID_AMD_17H_MA0H_DF_F4       0x1728
-#define PCI_DEVICE_ID_AMD_19H_DF_F4            0x1654
-#define PCI_DEVICE_ID_AMD_19H_M10H_DF_F4       0x14b1
-#define PCI_DEVICE_ID_AMD_19H_M40H_DF_F4       0x167d
-#define PCI_DEVICE_ID_AMD_19H_M50H_DF_F4       0x166e
-#define PCI_DEVICE_ID_AMD_19H_M60H_DF_F4       0x14e4
-#define PCI_DEVICE_ID_AMD_19H_M70H_DF_F4       0x14f4
-#define PCI_DEVICE_ID_AMD_19H_M78H_DF_F4       0x12fc
-#define PCI_DEVICE_ID_AMD_1AH_M00H_DF_F4       0x12c4
-#define PCI_DEVICE_ID_AMD_1AH_M20H_DF_F4       0x16fc
-#define PCI_DEVICE_ID_AMD_1AH_M60H_DF_F4       0x124c
-#define PCI_DEVICE_ID_AMD_1AH_M70H_DF_F4       0x12bc
-#define PCI_DEVICE_ID_AMD_MI200_DF_F4          0x14d4
-#define PCI_DEVICE_ID_AMD_MI300_DF_F4          0x152c
-
 /* Protect the PCI config register pairs used for SMN. */
 static DEFINE_MUTEX(smn_mutex);
 
@@ -73,8 +53,6 @@ static const struct pci_device_id amd_root_ids[] = {
        {}
 };
 
-#define PCI_DEVICE_ID_AMD_CNB17H_F4     0x1704
-
 static const struct pci_device_id amd_nb_misc_ids[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
        { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
@@ -107,35 +85,6 @@ static const struct pci_device_id amd_nb_misc_ids[] = {
        {}
 };
 
-static const struct pci_device_id amd_nb_link_ids[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M10H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M30H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M60H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_M70H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_MA0H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M10H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M40H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M50H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M60H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M70H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_19H_M78H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CNB17H_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_1AH_M00H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_1AH_M20H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_1AH_M60H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_1AH_M70H_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_MI200_DF_F4) },
-       { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_MI300_DF_F4) },
-       {}
-};
-
 static const struct pci_device_id hygon_root_ids[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_17H_ROOT) },
        {}
@@ -146,11 +95,6 @@ static const struct pci_device_id hygon_nb_misc_ids[] = {
        {}
 };
 
-static const struct pci_device_id hygon_nb_link_ids[] = {
-       { PCI_DEVICE(PCI_VENDOR_ID_HYGON, PCI_DEVICE_ID_AMD_17H_DF_F4) },
-       {}
-};
-
 const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[] __initconst = {
        { 0x00, 0x18, 0x20 },
        { 0xff, 0x00, 0x20 },
@@ -275,13 +219,11 @@ int __must_check amd_smn_write(u16 node, u32 address, u32 value)
 }
 EXPORT_SYMBOL_GPL(amd_smn_write);
 
-
 static int amd_cache_northbridges(void)
 {
        const struct pci_device_id *misc_ids = amd_nb_misc_ids;
-       const struct pci_device_id *link_ids = amd_nb_link_ids;
        const struct pci_device_id *root_ids = amd_root_ids;
-       struct pci_dev *root, *misc, *link;
+       struct pci_dev *root, *misc;
        struct amd_northbridge *nb;
        u16 roots_per_misc = 0;
        u16 misc_count = 0;
@@ -294,7 +236,6 @@ static int amd_cache_northbridges(void)
        if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) {
                root_ids = hygon_root_ids;
                misc_ids = hygon_nb_misc_ids;
-               link_ids = hygon_nb_link_ids;
        }
 
        misc = NULL;
@@ -328,14 +269,13 @@ static int amd_cache_northbridges(void)
        amd_northbridges.nb = nb;
        amd_northbridges.num = misc_count;
 
-       link = misc = root = NULL;
+       misc = root = NULL;
        for (i = 0; i < amd_northbridges.num; i++) {
                node_to_amd_nb(i)->root = root =
                        next_northbridge(root, root_ids);
                node_to_amd_nb(i)->misc = misc =
                        next_northbridge(misc, misc_ids);
-               node_to_amd_nb(i)->link = link =
-                       next_northbridge(link, link_ids);
+               node_to_amd_nb(i)->link = amd_node_get_func(i, 4);
 
                /*
                 * If there are more PCI root devices than data fabric/