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>
7#include "idxd.h"
8
9
10int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,
11 const char *mod_name)
12{
13 struct device_driver *drv = &idxd_drv->drv;
14
15 if (!idxd_drv->type) {
16 pr_debug("driver type not set (%ps)\n", __builtin_return_address(0));
17 return -EINVAL;
18 }
19
20 drv->name = idxd_drv->name;
21 drv->bus = &dsa_bus_type;
22 drv->owner = owner;
23 drv->mod_name = mod_name;
24
25 return driver_register(drv);
26}
27EXPORT_SYMBOL_GPL(__idxd_driver_register);
28
29void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)
30{
31 driver_unregister(drv: &idxd_drv->drv);
32}
33EXPORT_SYMBOL_GPL(idxd_driver_unregister);
34
35static int idxd_config_bus_match(struct device *dev,
36 struct device_driver *drv)
37{
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);
41 int i = 0;
42
43 while (idxd_drv->type[i] != IDXD_DEV_NONE) {
44 if (idxd_dev->type == idxd_drv->type[i])
45 return 1;
46 i++;
47 }
48
49 return 0;
50}
51
52static int idxd_config_bus_probe(struct device *dev)
53{
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);
57
58 return idxd_drv->probe(idxd_dev);
59}
60
61static void idxd_config_bus_remove(struct device *dev)
62{
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);
66
67 idxd_drv->remove(idxd_dev);
68}
69
70static int idxd_bus_uevent(const struct device *dev, struct kobj_uevent_env *env)
71{
72 return add_uevent_var(env, format: "MODALIAS=" IDXD_DEVICES_MODALIAS_FMT, 0);
73}
74
75const struct bus_type dsa_bus_type = {
76 .name = "dsa",
77 .match = idxd_config_bus_match,
78 .probe = idxd_config_bus_probe,
79 .remove = idxd_config_bus_remove,
80 .uevent = idxd_bus_uevent,
81};
82EXPORT_SYMBOL_GPL(dsa_bus_type);
83
84static int __init dsa_bus_init(void)
85{
86 return bus_register(bus: &dsa_bus_type);
87}
88module_init(dsa_bus_init);
89
90static void __exit dsa_bus_exit(void)
91{
92 bus_unregister(bus: &dsa_bus_type);
93}
94module_exit(dsa_bus_exit);
95
96MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
97MODULE_LICENSE("GPL v2");
98

source code of linux/drivers/dma/idxd/bus.c