pci-epf.h 4.9 KB

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