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 const struct device_driver
*drv
)
38 const struct idxd_device_driver
*idxd_drv
=
39 container_of_const(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 static int idxd_bus_uevent(const struct device
*dev
, struct kobj_uevent_env
*env
)
72 return add_uevent_var(env
, "MODALIAS=" IDXD_DEVICES_MODALIAS_FMT
, 0);
75 const struct bus_type dsa_bus_type
= {
77 .match
= idxd_config_bus_match
,
78 .probe
= idxd_config_bus_probe
,
79 .remove
= idxd_config_bus_remove
,
80 .uevent
= idxd_bus_uevent
,
82 EXPORT_SYMBOL_GPL(dsa_bus_type
);
84 static int __init
dsa_bus_init(void)
86 return bus_register(&dsa_bus_type
);
88 module_init(dsa_bus_init
);
90 static void __exit
dsa_bus_exit(void)
92 bus_unregister(&dsa_bus_type
);
94 module_exit(dsa_bus_exit
);
96 MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
97 MODULE_LICENSE("GPL v2");