dfl.h 2.4 KB

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