Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright(c) 2021 Intel Corporation. All rights rsvd. */
0003 #include <linux/init.h>
0004 #include <linux/kernel.h>
0005 #include <linux/module.h>
0006 #include <linux/device.h>
0007 #include "idxd.h"
0008 
0009 
0010 int __idxd_driver_register(struct idxd_device_driver *idxd_drv, struct module *owner,
0011                const char *mod_name)
0012 {
0013     struct device_driver *drv = &idxd_drv->drv;
0014 
0015     if (!idxd_drv->type) {
0016         pr_debug("driver type not set (%ps)\n", __builtin_return_address(0));
0017         return -EINVAL;
0018     }
0019 
0020     drv->name = idxd_drv->name;
0021     drv->bus = &dsa_bus_type;
0022     drv->owner = owner;
0023     drv->mod_name = mod_name;
0024 
0025     return driver_register(drv);
0026 }
0027 EXPORT_SYMBOL_GPL(__idxd_driver_register);
0028 
0029 void idxd_driver_unregister(struct idxd_device_driver *idxd_drv)
0030 {
0031     driver_unregister(&idxd_drv->drv);
0032 }
0033 EXPORT_SYMBOL_GPL(idxd_driver_unregister);
0034 
0035 static int idxd_config_bus_match(struct device *dev,
0036                  struct device_driver *drv)
0037 {
0038     struct idxd_device_driver *idxd_drv =
0039         container_of(drv, struct idxd_device_driver, drv);
0040     struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
0041     int i = 0;
0042 
0043     while (idxd_drv->type[i] != IDXD_DEV_NONE) {
0044         if (idxd_dev->type == idxd_drv->type[i])
0045             return 1;
0046         i++;
0047     }
0048 
0049     return 0;
0050 }
0051 
0052 static int idxd_config_bus_probe(struct device *dev)
0053 {
0054     struct idxd_device_driver *idxd_drv =
0055         container_of(dev->driver, struct idxd_device_driver, drv);
0056     struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
0057 
0058     return idxd_drv->probe(idxd_dev);
0059 }
0060 
0061 static void idxd_config_bus_remove(struct device *dev)
0062 {
0063     struct idxd_device_driver *idxd_drv =
0064         container_of(dev->driver, struct idxd_device_driver, drv);
0065     struct idxd_dev *idxd_dev = confdev_to_idxd_dev(dev);
0066 
0067     idxd_drv->remove(idxd_dev);
0068 }
0069 
0070 struct bus_type dsa_bus_type = {
0071     .name = "dsa",
0072     .match = idxd_config_bus_match,
0073     .probe = idxd_config_bus_probe,
0074     .remove = idxd_config_bus_remove,
0075 };
0076 EXPORT_SYMBOL_GPL(dsa_bus_type);
0077 
0078 static int __init dsa_bus_init(void)
0079 {
0080     return bus_register(&dsa_bus_type);
0081 }
0082 module_init(dsa_bus_init);
0083 
0084 static void __exit dsa_bus_exit(void)
0085 {
0086     bus_unregister(&dsa_bus_type);
0087 }
0088 module_exit(dsa_bus_exit);
0089 
0090 MODULE_DESCRIPTION("IDXD driver dsa_bus_type driver");
0091 MODULE_LICENSE("GPL v2");