powerpc/machdep: Define 'compatibles' property in ppc_md and use it
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 14 Dec 2023 10:31:51 +0000 (21:31 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Sun, 3 Mar 2024 11:20:29 +0000 (22:20 +1100)
Most probe functions that do not use the 'compatible' string do
nothing else than checking whether the machine is compatible with
one of the strings in a NULL terminated table of strings.

Define that table of strings in ppc_md structure and check it directly
from probe_machine() instead of using ppc_md.probe() for that.

Keep checking in ppc_md.probe() only for more complex probing.

All .compatible could be replaced with a single element NULL
terminated list but that's not worth the churn. Can be do incrementaly
in follow-up patches.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20231214103152.12269-4-mpe@ellerman.id.au
arch/powerpc/include/asm/machdep.h
arch/powerpc/kernel/setup-common.c
arch/powerpc/platforms/40x/ppc40x_simple.c
arch/powerpc/platforms/512x/mpc512x_generic.c
arch/powerpc/platforms/52xx/lite5200.c
arch/powerpc/platforms/52xx/mpc5200_simple.c
arch/powerpc/platforms/83xx/mpc830x_rdb.c
arch/powerpc/platforms/83xx/mpc831x_rdb.c
arch/powerpc/platforms/83xx/mpc837x_rdb.c
arch/powerpc/platforms/85xx/corenet_generic.c
arch/powerpc/platforms/85xx/tqm85xx.c

index d31a5ec1550d4b051dfce4c1680b3d62f43af3a7..1862f94335ee89c7c6bff8758b81ac380f506630 100644 (file)
@@ -22,6 +22,7 @@ struct pci_host_bridge;
 struct machdep_calls {
        const char      *name;
        const char      *compatible;
+       const char * const *compatibles;
 #ifdef CONFIG_PPC64
 #ifdef CONFIG_PM
        void            (*iommu_restore)(void);
index 6fe68aa932684a1371415679c005462f82e25b7c..0c41098bdc35df771b1bce24292e594c1b4ccc73 100644 (file)
@@ -640,6 +640,8 @@ static __init void probe_machine(void)
                DBG("  %s ...\n", machine_id->name);
                if (machine_id->compatible && !of_machine_is_compatible(machine_id->compatible))
                        continue;
+               if (machine_id->compatibles && !of_machine_compatible_match(machine_id->compatibles))
+                       continue;
                memcpy(&ppc_md, machine_id, sizeof(struct machdep_calls));
                if (ppc_md.probe && !ppc_md.probe())
                        continue;
index e454e9d2eff17b575a113e8422494a9e4e17230f..294ab27285889adf42c5206ba0fb5560c195f98b 100644 (file)
@@ -59,16 +59,13 @@ static const char * const board[] __initconst = {
 
 static int __init ppc40x_probe(void)
 {
-       if (of_device_compatible_match(of_root, board)) {
-               pci_set_flags(PCI_REASSIGN_ALL_RSRC);
-               return 1;
-       }
-
-       return 0;
+       pci_set_flags(PCI_REASSIGN_ALL_RSRC);
+       return 1;
 }
 
 define_machine(ppc40x_simple) {
        .name = "PowerPC 40x Platform",
+       .compatibles = board,
        .probe = ppc40x_probe,
        .progress = udbg_progress,
        .init_IRQ = uic_init_tree,
index 0d58ab257cd93acf22c7a548d67b2258e1d2fddc..d4fa6c302ccfb0ae77ed9b222878f049cc29d9e3 100644 (file)
@@ -32,9 +32,6 @@ static const char * const board[] __initconst = {
  */
 static int __init mpc512x_generic_probe(void)
 {
-       if (!of_device_compatible_match(of_root, board))
-               return 0;
-
        mpc512x_init_early();
 
        return 1;
@@ -42,6 +39,7 @@ static int __init mpc512x_generic_probe(void)
 
 define_machine(mpc512x_generic) {
        .name                   = "MPC512x generic",
+       .compatibles            = board,
        .probe                  = mpc512x_generic_probe,
        .init                   = mpc512x_init,
        .setup_arch             = mpc512x_setup_arch,
index 0fd67b3ffc3e83999cfc46387a0d7aed5513d3e9..0a161d82a3a8772f26fedc1fef183f811d53f13a 100644 (file)
@@ -172,17 +172,9 @@ static const char * const board[] __initconst = {
        NULL,
 };
 
-/*
- * Called very early, MMU is off, device-tree isn't unflattened
- */
-static int __init lite5200_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 define_machine(lite5200) {
        .name           = "lite5200",
-       .probe          = lite5200_probe,
+       .compatibles    = board,
        .setup_arch     = lite5200_setup_arch,
        .discover_phbs  = mpc52xx_setup_pci,
        .init           = mpc52xx_declare_of_platform_devices,
index f1e85e86f5e57620621db9b81e9b0f793649e77b..7e0e4c34a40be17e8cf4061faaab001c293c04f1 100644 (file)
@@ -59,17 +59,9 @@ static const char *board[] __initdata = {
        NULL
 };
 
-/*
- * Called very early, MMU is off, device-tree isn't unflattened
- */
-static int __init mpc5200_simple_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 define_machine(mpc5200_simple_platform) {
        .name           = "mpc5200-simple-platform",
-       .probe          = mpc5200_simple_probe,
+       .compatibles    = board,
        .setup_arch     = mpc5200_simple_setup_arch,
        .discover_phbs  = mpc52xx_setup_pci,
        .init           = mpc52xx_declare_of_platform_devices,
index 534bb227480d25dd09a81166a818467db6db1ba2..63b6d213726a6d6ee7ca0589dcadad8de1866f93 100644 (file)
@@ -34,19 +34,11 @@ static const char *board[] __initdata = {
        NULL
 };
 
-/*
- * Called very early, MMU is off, device-tree isn't unflattened
- */
-static int __init mpc830x_rdb_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 machine_device_initcall(mpc830x_rdb, mpc83xx_declare_of_platform_devices);
 
 define_machine(mpc830x_rdb) {
        .name                   = "MPC830x RDB",
-       .probe                  = mpc830x_rdb_probe,
+       .compatibles            = board,
        .setup_arch             = mpc830x_rdb_setup_arch,
        .discover_phbs          = mpc83xx_setup_pci,
        .init_IRQ               = mpc83xx_ipic_init_IRQ,
index 7b901ab3b864632b79e2185d6d0f40f7fa923cec..5c39966762e4264d2ef91b2c4ef75fdf2c2c5d65 100644 (file)
@@ -34,19 +34,11 @@ static const char *board[] __initdata = {
        NULL
 };
 
-/*
- * Called very early, MMU is off, device-tree isn't unflattened
- */
-static int __init mpc831x_rdb_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 machine_device_initcall(mpc831x_rdb, mpc83xx_declare_of_platform_devices);
 
 define_machine(mpc831x_rdb) {
        .name                   = "MPC831x RDB",
-       .probe                  = mpc831x_rdb_probe,
+       .compatibles            = board,
        .setup_arch             = mpc831x_rdb_setup_arch,
        .discover_phbs          = mpc83xx_setup_pci,
        .init_IRQ               = mpc83xx_ipic_init_IRQ,
index 39e78018dd0b7fe993b5e91f61f40a9187c1673f..45823e14793311d679530ce72d93b6e204c70992 100644 (file)
@@ -61,17 +61,9 @@ static const char * const board[] __initconst = {
        NULL
 };
 
-/*
- * Called very early, MMU is off, device-tree isn't unflattened
- */
-static int __init mpc837x_rdb_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 define_machine(mpc837x_rdb) {
        .name                   = "MPC837x RDB/WLAN",
-       .probe                  = mpc837x_rdb_probe,
+       .compatibles            = board,
        .setup_arch             = mpc837x_rdb_setup_arch,
        .discover_phbs          = mpc83xx_setup_pci,
        .init_IRQ               = mpc83xx_ipic_init_IRQ,
index 645fcca77cde56c3773175dbd947c0c2f635f0ab..c44400e95f5514a9307ce4d00f3663e241215bec 100644 (file)
@@ -149,7 +149,7 @@ static int __init corenet_generic_probe(void)
        extern struct smp_ops_t smp_85xx_ops;
 #endif
 
-       if (of_device_compatible_match(of_root, boards))
+       if (of_machine_compatible_match(boards))
                return 1;
 
        /* Check if we're running under the Freescale hypervisor */
index 6be1b9809db6b5c47aa68da49263ae7c4deac13c..f74d446c53f085c6521ecef889a24935ae55f09d 100644 (file)
@@ -112,17 +112,9 @@ static const char * const board[] __initconst = {
        NULL
 };
 
-/*
- * Called very early, device-tree isn't unflattened
- */
-static int __init tqm85xx_probe(void)
-{
-       return of_device_compatible_match(of_root, board);
-}
-
 define_machine(tqm85xx) {
        .name                   = "TQM85xx",
-       .probe                  = tqm85xx_probe,
+       .compatibles            = board,
        .setup_arch             = tqm85xx_setup_arch,
        .init_IRQ               = tqm85xx_pic_init,
        .show_cpuinfo           = tqm85xx_show_cpuinfo,