firmware: coreboot: Replace tag with id table in driver struct
authorNícolas F. R. A. Prado <nfraprado@collabora.com>
Mon, 12 Feb 2024 14:50:07 +0000 (09:50 -0500)
committerTzung-Bi Shih <tzungbi@kernel.org>
Sat, 17 Feb 2024 00:53:06 +0000 (08:53 +0800)
Switch the plain 'tag' field in struct coreboot_driver for the newly
created coreboot_device_id struct, which also contains a tag field and
has the benefit of allowing modalias generation, and update all coreboot
drivers accordingly.

While at it, also add the id table for each driver to the module device
table to allow automatically loading the module.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Link: https://lore.kernel.org/r/20240212-coreboot-mod-defconfig-v4-3-d14172676f6d@collabora.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/firmware/google/cbmem.c
drivers/firmware/google/coreboot_table.c
drivers/firmware/google/coreboot_table.h
drivers/firmware/google/framebuffer-coreboot.c
drivers/firmware/google/memconsole-coreboot.c
drivers/firmware/google/vpd.c

index 88e587ba1e0da3f5e9287c3ac42c7a0f4fb82809..c2bffdc352a3a9b194e17496602ac919f9717c0a 100644 (file)
@@ -114,6 +114,12 @@ static int cbmem_entry_probe(struct coreboot_device *dev)
        return 0;
 }
 
+static const struct coreboot_device_id cbmem_ids[] = {
+       { .tag = LB_TAG_CBMEM_ENTRY },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(coreboot, cbmem_ids);
+
 static struct coreboot_driver cbmem_entry_driver = {
        .probe = cbmem_entry_probe,
        .drv = {
@@ -121,7 +127,7 @@ static struct coreboot_driver cbmem_entry_driver = {
                .owner = THIS_MODULE,
                .dev_groups = dev_groups,
        },
-       .tag = LB_TAG_CBMEM_ENTRY,
+       .id_table = cbmem_ids,
 };
 module_coreboot_driver(cbmem_entry_driver);
 
index 234cebf376d97f950964178355e70c80273320ed..d4b6e581a6c6b1d83146595b2419e943df984672 100644 (file)
@@ -28,8 +28,17 @@ static int coreboot_bus_match(struct device *dev, struct device_driver *drv)
 {
        struct coreboot_device *device = CB_DEV(dev);
        struct coreboot_driver *driver = CB_DRV(drv);
+       const struct coreboot_device_id *id;
 
-       return device->entry.tag == driver->tag;
+       if (!driver->id_table)
+               return 0;
+
+       for (id = driver->id_table; id->tag; id++) {
+               if (device->entry.tag == id->tag)
+                       return 1;
+       }
+
+       return 0;
 }
 
 static int coreboot_bus_probe(struct device *dev)
index d814dca33a084cfd526d54fadf2c4353a292362c..86427989c57fb535f57bfe84c9c7610c916426f7 100644 (file)
@@ -13,6 +13,7 @@
 #define __COREBOOT_TABLE_H
 
 #include <linux/device.h>
+#include <linux/mod_devicetable.h>
 
 /* Coreboot table header structure */
 struct coreboot_table_header {
@@ -93,7 +94,7 @@ struct coreboot_driver {
        int (*probe)(struct coreboot_device *);
        void (*remove)(struct coreboot_device *);
        struct device_driver drv;
-       u32 tag;
+       const struct coreboot_device_id *id_table;
 };
 
 /* Register a driver that uses the data from a coreboot table. */
index 5c84bbebfef85668459e49fcf9cf40c8cfa22b38..07c458bf64ec38458e47cb2b1fa733c3fd9b4b07 100644 (file)
@@ -80,13 +80,19 @@ static void framebuffer_remove(struct coreboot_device *dev)
        platform_device_unregister(pdev);
 }
 
+static const struct coreboot_device_id framebuffer_ids[] = {
+       { .tag = CB_TAG_FRAMEBUFFER },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(coreboot, framebuffer_ids);
+
 static struct coreboot_driver framebuffer_driver = {
        .probe = framebuffer_probe,
        .remove = framebuffer_remove,
        .drv = {
                .name = "framebuffer",
        },
-       .tag = CB_TAG_FRAMEBUFFER,
+       .id_table = framebuffer_ids,
 };
 module_coreboot_driver(framebuffer_driver);
 
index 74b5286518eefbc2df08baffc62f150f4329ffd0..24c97a70aa809338aa1a914a4b04ce22e3de43ca 100644 (file)
@@ -96,13 +96,19 @@ static void memconsole_remove(struct coreboot_device *dev)
        memconsole_exit();
 }
 
+static const struct coreboot_device_id memconsole_ids[] = {
+       { .tag = CB_TAG_CBMEM_CONSOLE },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(coreboot, memconsole_ids);
+
 static struct coreboot_driver memconsole_driver = {
        .probe = memconsole_probe,
        .remove = memconsole_remove,
        .drv = {
                .name = "memconsole",
        },
-       .tag = CB_TAG_CBMEM_CONSOLE,
+       .id_table = memconsole_ids,
 };
 module_coreboot_driver(memconsole_driver);
 
index ee6e08c0592b5492d208829191a4321bd29f6f5e..8e4216714b299dbdffee96744116fb0673fd2426 100644 (file)
@@ -306,13 +306,19 @@ static void vpd_remove(struct coreboot_device *dev)
        kobject_put(vpd_kobj);
 }
 
+static const struct coreboot_device_id vpd_ids[] = {
+       { .tag = CB_TAG_VPD },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(coreboot, vpd_ids);
+
 static struct coreboot_driver vpd_driver = {
        .probe = vpd_probe,
        .remove = vpd_remove,
        .drv = {
                .name = "vpd",
        },
-       .tag = CB_TAG_VPD,
+       .id_table = vpd_ids,
 };
 module_coreboot_driver(vpd_driver);