pci-epf.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /**
  3. * PCI Endpoint *Function* (EPF) header file
  4. *
  5. * Copyright (C) 2017 Texas Instruments
  6. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  7. */
  8. #ifndef __LINUX_PCI_EPF_H
  9. #define __LINUX_PCI_EPF_H
  10. #include <linux/device.h>
  11. #include <linux/mod_devicetable.h>
  12. #include <linux/pci.h>
  13. struct pci_epf;
  14. enum pci_barno {
  15. BAR_0,
  16. BAR_1,
  17. BAR_2,
  18. BAR_3,
  19. BAR_4,
  20. BAR_5,
  21. };
  22. /**
  23. * struct pci_epf_header - represents standard configuration header
  24. * @vendorid: identifies device manufacturer
  25. * @deviceid: identifies a particular device
  26. * @revid: specifies a device-specific revision identifier
  27. * @progif_code: identifies a specific register-level programming interface
  28. * @subclass_code: identifies more specifically the function of the device
  29. * @baseclass_code: broadly classifies the type of function the device performs
  30. * @cache_line_size: specifies the system cacheline size in units of DWORDs
  31. * @subsys_vendor_id: vendor of the add-in card or subsystem
  32. * @subsys_id: id specific to vendor
  33. * @interrupt_pin: interrupt pin the device (or device function) uses
  34. */
  35. struct pci_epf_header {
  36. u16 vendorid;
  37. u16 deviceid;
  38. u8 revid;
  39. u8 progif_code;
  40. u8 subclass_code;
  41. u8 baseclass_code;
  42. u8 cache_line_size;
  43. u16 subsys_vendor_id;
  44. u16 subsys_id;
  45. enum pci_interrupt_pin interrupt_pin;
  46. };
  47. /**
  48. * struct pci_epf_ops - set of function pointers for performing EPF operations
  49. * @bind: ops to perform when a EPC device has been bound to EPF device
  50. * @unbind: ops to perform when a binding has been lost between a EPC device
  51. * and EPF device
  52. * @linkup: ops to perform when the EPC device has established a connection with
  53. * a host system
  54. */
  55. struct pci_epf_ops {
  56. int (*bind)(struct pci_epf *epf);
  57. void (*unbind)(struct pci_epf *epf);
  58. void (*linkup)(struct pci_epf *epf);
  59. };
  60. /**
  61. * struct pci_epf_driver - represents the PCI EPF driver
  62. * @probe: ops to perform when a new EPF device has been bound to the EPF driver
  63. * @remove: ops to perform when the binding between the EPF device and EPF
  64. * driver is broken
  65. * @driver: PCI EPF driver
  66. * @ops: set of function pointers for performing EPF operations
  67. * @owner: the owner of the module that registers the PCI EPF driver
  68. * @epf_group: list of configfs group corresponding to the PCI EPF driver
  69. * @id_table: identifies EPF devices for probing
  70. */
  71. struct pci_epf_driver {
  72. int (*probe)(struct pci_epf *epf);
  73. int (*remove)(struct pci_epf *epf);
  74. struct device_driver driver;
  75. struct pci_epf_ops *ops;
  76. struct module *owner;
  77. struct list_head epf_group;
  78. const struct pci_epf_device_id *id_table;
  79. };
  80. #define to_pci_epf_driver(drv) (container_of((drv), struct pci_epf_driver, \
  81. driver))
  82. /**
  83. * struct pci_epf_bar - represents the BAR of EPF device
  84. * @phys_addr: physical address that should be mapped to the BAR
  85. * @size: the size of the address space present in BAR
  86. */
  87. struct pci_epf_bar {
  88. dma_addr_t phys_addr;
  89. size_t size;
  90. enum pci_barno barno;
  91. int flags;
  92. };
  93. /**
  94. * struct pci_epf - represents the PCI EPF device
  95. * @dev: the PCI EPF device
  96. * @name: the name of the PCI EPF device
  97. * @header: represents standard configuration header
  98. * @bar: represents the BAR of EPF device
  99. * @msi_interrupts: number of MSI interrupts required by this function
  100. * @func_no: unique function number within this endpoint device
  101. * @epc: the EPC device to which this EPF device is bound
  102. * @driver: the EPF driver to which this EPF device is bound
  103. * @list: to add pci_epf as a list of PCI endpoint functions to pci_epc
  104. */
  105. struct pci_epf {
  106. struct device dev;
  107. const char *name;
  108. struct pci_epf_header *header;
  109. struct pci_epf_bar bar[6];
  110. u8 msi_interrupts;
  111. u16 msix_interrupts;
  112. u8 func_no;
  113. struct pci_epc *epc;
  114. struct pci_epf_driver *driver;
  115. struct list_head list;
  116. };
  117. #define to_pci_epf(epf_dev) container_of((epf_dev), struct pci_epf, dev)
  118. #define pci_epf_register_driver(driver) \
  119. __pci_epf_register_driver((driver), THIS_MODULE)
  120. static inline void epf_set_drvdata(struct pci_epf *epf, void *data)
  121. {
  122. dev_set_drvdata(&epf->dev, data);
  123. }
  124. static inline void *epf_get_drvdata(struct pci_epf *epf)
  125. {
  126. return dev_get_drvdata(&epf->dev);
  127. }
  128. const struct pci_epf_device_id *
  129. pci_epf_match_device(const struct pci_epf_device_id *id, struct pci_epf *epf);
  130. struct pci_epf *pci_epf_create(const char *name);
  131. void pci_epf_destroy(struct pci_epf *epf);
  132. int __pci_epf_register_driver(struct pci_epf_driver *driver,
  133. struct module *owner);
  134. void pci_epf_unregister_driver(struct pci_epf_driver *driver);
  135. void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar);
  136. void pci_epf_free_space(struct pci_epf *epf, void *addr, enum pci_barno bar);
  137. int pci_epf_bind(struct pci_epf *epf);
  138. void pci_epf_unbind(struct pci_epf *epf);
  139. void pci_epf_linkup(struct pci_epf *epf);
  140. #endif /* __LINUX_PCI_EPF_H */