xref: /openbmc/linux/include/linux/dfl.h (revision 6b342707)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Header file for DFL driver and device API
4  *
5  * Copyright (C) 2020 Intel Corporation, Inc.
6  */
7 
8 #ifndef __LINUX_DFL_H
9 #define __LINUX_DFL_H
10 
11 #include <linux/device.h>
12 #include <linux/mod_devicetable.h>
13 
14 /**
15  * enum dfl_id_type - define the DFL FIU types
16  */
17 enum dfl_id_type {
18 	FME_ID = 0,
19 	PORT_ID = 1,
20 	DFL_ID_MAX,
21 };
22 
23 /**
24  * struct dfl_device - represent an dfl device on dfl bus
25  *
26  * @dev: generic device interface.
27  * @id: id of the dfl device.
28  * @type: type of DFL FIU of the device. See enum dfl_id_type.
29  * @feature_id: feature identifier local to its DFL FIU type.
30  * @mmio_res: mmio resource of this dfl device.
31  * @irqs: list of Linux IRQ numbers of this dfl device.
32  * @num_irqs: number of IRQs supported by this dfl device.
33  * @cdev: pointer to DFL FPGA container device this dfl device belongs to.
34  * @id_entry: matched id entry in dfl driver's id table.
35  */
36 struct dfl_device {
37 	struct device dev;
38 	int id;
39 	u16 type;
40 	u16 feature_id;
41 	u8 revision;
42 	struct resource mmio_res;
43 	int *irqs;
44 	unsigned int num_irqs;
45 	struct dfl_fpga_cdev *cdev;
46 	const struct dfl_device_id *id_entry;
47 };
48 
49 /**
50  * struct dfl_driver - represent an dfl device driver
51  *
52  * @drv: driver model structure.
53  * @id_table: pointer to table of device IDs the driver is interested in.
54  *	      { } member terminated.
55  * @probe: mandatory callback for device binding.
56  * @remove: callback for device unbinding.
57  */
58 struct dfl_driver {
59 	struct device_driver drv;
60 	const struct dfl_device_id *id_table;
61 
62 	int (*probe)(struct dfl_device *dfl_dev);
63 	void (*remove)(struct dfl_device *dfl_dev);
64 };
65 
66 #define to_dfl_dev(d) container_of(d, struct dfl_device, dev)
67 #define to_dfl_drv(d) container_of(d, struct dfl_driver, drv)
68 
69 /*
70  * use a macro to avoid include chaining to get THIS_MODULE.
71  */
72 #define dfl_driver_register(drv) \
73 	__dfl_driver_register(drv, THIS_MODULE)
74 int __dfl_driver_register(struct dfl_driver *dfl_drv, struct module *owner);
75 void dfl_driver_unregister(struct dfl_driver *dfl_drv);
76 
77 /*
78  * module_dfl_driver() - Helper macro for drivers that don't do
79  * anything special in module init/exit.  This eliminates a lot of
80  * boilerplate.  Each module may only use this macro once, and
81  * calling it replaces module_init() and module_exit().
82  */
83 #define module_dfl_driver(__dfl_driver) \
84 	module_driver(__dfl_driver, dfl_driver_register, \
85 		      dfl_driver_unregister)
86 
87 #endif /* __LINUX_DFL_H */
88