x86/amd_nb: Unexport amd_cache_northbridges()
authorMuralidhara M K <muralimk@amd.com>
Thu, 24 Mar 2022 12:27:29 +0000 (17:57 +0530)
committerBorislav Petkov <bp@suse.de>
Tue, 5 Apr 2022 17:22:27 +0000 (19:22 +0200)
amd_cache_northbridges() is exported by amd_nb.c and is called by
amd64-agp.c and amd64_edac.c modules at module_init() time so that NB
descriptors are properly cached before those drivers can use them.

However, the init_amd_nbs() initcall already does call
amd_cache_northbridges() unconditionally and thus makes sure the NB
descriptors are enumerated.

That initcall is a fs_initcall type which is on the 5th group (starting
from 0) of initcalls that gets run in increasing numerical order by the
init code.

The module_init() call is turned into an __initcall() in the MODULE=n
case and those are device-level initcalls, i.e., group 6.

Therefore, the northbridges caching is already finished by the time
module initialization starts and thus the correct initialization order
is retained.

Unexport amd_cache_northbridges(), update dependent modules to
call amd_nb_num() instead. While at it, simplify the checks in
amd_cache_northbridges().

  [ bp: Heavily massage and *actually* explain why the change is ok. ]

Signed-off-by: Muralidhara M K <muralimk@amd.com>
Signed-off-by: Naveen Krishna Chatradhi <nchatrad@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20220324122729.221765-1-nchatrad@amd.com
arch/x86/include/asm/amd_nb.h
arch/x86/kernel/amd_nb.c
drivers/char/agp/amd64-agp.c
drivers/edac/amd64_edac.c

index 00d1a400b7a17a272f2cbbf796682b8a18aa3665..ed0eaf65c43721ebfcf4f4ee74f827c6d91ec5d1 100644 (file)
@@ -16,7 +16,6 @@ extern const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[];
 
 extern bool early_is_amd_nb(u32 value);
 extern struct resource *amd_get_mmconfig_range(struct resource *res);
-extern int amd_cache_northbridges(void);
 extern void amd_flush_garts(void);
 extern int amd_numa_init(void);
 extern int amd_get_subcaches(int);
index 020c906f79349548d1d1ed5ddf101e1c83293c85..190e0f76337559f27e3b42f246f4b06f12a23ddc 100644 (file)
@@ -188,7 +188,7 @@ int amd_smn_write(u16 node, u32 address, u32 value)
 EXPORT_SYMBOL_GPL(amd_smn_write);
 
 
-int amd_cache_northbridges(void)
+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;
@@ -210,14 +210,14 @@ int amd_cache_northbridges(void)
        }
 
        misc = NULL;
-       while ((misc = next_northbridge(misc, misc_ids)) != NULL)
+       while ((misc = next_northbridge(misc, misc_ids)))
                misc_count++;
 
        if (!misc_count)
                return -ENODEV;
 
        root = NULL;
-       while ((root = next_northbridge(root, root_ids)) != NULL)
+       while ((root = next_northbridge(root, root_ids)))
                root_count++;
 
        if (root_count) {
@@ -290,7 +290,6 @@ int amd_cache_northbridges(void)
 
        return 0;
 }
-EXPORT_SYMBOL_GPL(amd_cache_northbridges);
 
 /*
  * Ignores subdevice/subvendor but as far as I can figure out
index dc78a4fb879eb6a0fea8d17c880156567c398105..84a4aa9312cf8d845990f7b06ebc328b41064c7f 100644 (file)
@@ -327,7 +327,7 @@ static int cache_nbs(struct pci_dev *pdev, u32 cap_ptr)
 {
        int i;
 
-       if (amd_cache_northbridges() < 0)
+       if (!amd_nb_num())
                return -ENODEV;
 
        if (!amd_nb_has_feature(AMD_NB_GART))
index 812baa48b29065d322e822a04dc5fca02be8b082..2f854feeeb237af1059bcd4ab8b541ce0c25e4a9 100644 (file)
@@ -4336,7 +4336,7 @@ static int __init amd64_edac_init(void)
        if (!x86_match_cpu(amd64_cpuids))
                return -ENODEV;
 
-       if (amd_cache_northbridges() < 0)
+       if (!amd_nb_num())
                return -ENODEV;
 
        opstate_init();