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