Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Header file for DFL driver and device API
0004  *
0005  * Copyright (C) 2020 Intel Corporation, Inc.
0006  */
0007 
0008 #ifndef __LINUX_DFL_H
0009 #define __LINUX_DFL_H
0010 
0011 #include <linux/device.h>
0012 #include <linux/mod_devicetable.h>
0013 
0014 /**
0015  * enum dfl_id_type - define the DFL FIU types
0016  */
0017 enum dfl_id_type {
0018     FME_ID = 0,
0019     PORT_ID = 1,
0020     DFL_ID_MAX,
0021 };
0022 
0023 /**
0024  * struct dfl_device - represent an dfl device on dfl bus
0025  *
0026  * @dev: generic device interface.
0027  * @id: id of the dfl device.
0028  * @type: type of DFL FIU of the device. See enum dfl_id_type.
0029  * @feature_id: feature identifier local to its DFL FIU type.
0030  * @mmio_res: mmio resource of this dfl device.
0031  * @irqs: list of Linux IRQ numbers of this dfl device.
0032  * @num_irqs: number of IRQs supported by this dfl device.
0033  * @cdev: pointer to DFL FPGA container device this dfl device belongs to.
0034  * @id_entry: matched id entry in dfl driver's id table.
0035  */
0036 struct dfl_device {
0037     struct device dev;
0038     int id;
0039     u16 type;
0040     u16 feature_id;
0041     u8 revision;
0042     struct resource mmio_res;
0043     int *irqs;
0044     unsigned int num_irqs;
0045     struct dfl_fpga_cdev *cdev;
0046     const struct dfl_device_id *id_entry;
0047 };
0048 
0049 /**
0050  * struct dfl_driver - represent an dfl device driver
0051  *
0052  * @drv: driver model structure.
0053  * @id_table: pointer to table of device IDs the driver is interested in.
0054  *        { } member terminated.
0055  * @probe: mandatory callback for device binding.
0056  * @remove: callback for device unbinding.
0057  */
0058 struct dfl_driver {
0059     struct device_driver drv;
0060     const struct dfl_device_id *id_table;
0061 
0062     int (*probe)(struct dfl_device *dfl_dev);
0063     void (*remove)(struct dfl_device *dfl_dev);
0064 };
0065 
0066 #define to_dfl_dev(d) container_of(d, struct dfl_device, dev)
0067 #define to_dfl_drv(d) container_of(d, struct dfl_driver, drv)
0068 
0069 /*
0070  * use a macro to avoid include chaining to get THIS_MODULE.
0071  */
0072 #define dfl_driver_register(drv) \
0073     __dfl_driver_register(drv, THIS_MODULE)
0074 int __dfl_driver_register(struct dfl_driver *dfl_drv, struct module *owner);
0075 void dfl_driver_unregister(struct dfl_driver *dfl_drv);
0076 
0077 /*
0078  * module_dfl_driver() - Helper macro for drivers that don't do
0079  * anything special in module init/exit.  This eliminates a lot of
0080  * boilerplate.  Each module may only use this macro once, and
0081  * calling it replaces module_init() and module_exit().
0082  */
0083 #define module_dfl_driver(__dfl_driver) \
0084     module_driver(__dfl_driver, dfl_driver_register, \
0085               dfl_driver_unregister)
0086 
0087 #endif /* __LINUX_DFL_H */