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 88e587b..c2bffdc 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 234cebf..d4b6e58 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 d814dca..8642798 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 5c84bbe..07c458b 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 74b5286..24c97a7 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 ee6e08c..8e42167 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);