1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
3 #include <linux/init.h>
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/device.h>
10 int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,
13 struct device_driver *drv = &idxd_drv->drv;
15 if (!idxd_drv->type) {
16 pr_debug("driver type not set (%ps)\n", __builtin_return_address(0));
20 drv->name = idxd_drv->name;
21 drv->bus = &dsa_bus_type;
23 drv->mod_name = mod_name;
25 return driver_register(drv);
27 EXPORT_SYMBOL_GPL(__idxd_driver_register);
29 void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)
31 driver_unregister(&idxd_drv->drv);
33 EXPORT_SYMBOL_GPL(idxd_driver_unregister);
35 static int idxd_config_bus_match(struct device *dev,
36 struct device_driver *drv)
38 struct idxd_device_driver *idxd_drv =
39 container_of(drv, struct idxd_device_driver, drv);
40 struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
43 while (idxd_drv->type[i] != IDXD_DEV_NONE) {
44 if (idxd_dev->type == idxd_drv->type[i])
52 static int idxd_config_bus_probe(struct device *dev)
54 struct idxd_device_driver *idxd_drv =
55 container_of(dev->driver, struct idxd_device_driver, drv);
56 struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
58 return idxd_drv->probe(idxd_dev);
61 static void idxd_config_bus_remove(struct device *dev)
63 struct idxd_device_driver *idxd_drv =
64 container_of(dev->driver, struct idxd_device_driver, drv);
65 struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
67 idxd_drv->remove(idxd_dev);
70 struct bus_type dsa_bus_type = {
72 .match = idxd_config_bus_match,
73 .probe = idxd_config_bus_probe,
74 .remove = idxd_config_bus_remove,
76 EXPORT_SYMBOL_GPL(dsa_bus_type);
78 static int __init dsa_bus_init(void)
80 return bus_register(&dsa_bus_type);
82 module_init(dsa_bus_init);
84 static void __exit dsa_bus_exit(void)
86 bus_unregister(&dsa_bus_type);
88 module_exit(dsa_bus_exit);
90 MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
91 MODULE_LICENSE("GPL v2");