firmware: coreboot: Replace tag with id table in driver struct

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>
This commit is contained in:
Nícolas F. R. A. Prado 2024-02-12 09:50:07 -05:00 committed by Tzung-Bi Shih
parent f1cebae1db
commit 8a0a62941a
6 changed files with 40 additions and 6 deletions

View 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);

View 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)

View 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. */

View 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);

View 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);

View 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);