pciback.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * PCI Backend Common Data Structures & Function Declarations
  3. *
  4. * Author: Ryan Wilson <hap9@epoch.ncsc.mil>
  5. */
  6. #ifndef __XEN_PCIBACK_H__
  7. #define __XEN_PCIBACK_H__
  8. #include <linux/pci.h>
  9. #include <linux/interrupt.h>
  10. #include <xen/xenbus.h>
  11. #include <linux/list.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/atomic.h>
  15. #include <xen/interface/io/pciif.h>
  16. #define DRV_NAME "xen-pciback"
  17. struct pci_dev_entry {
  18. struct list_head list;
  19. struct pci_dev *dev;
  20. };
  21. #define _PDEVF_op_active (0)
  22. #define PDEVF_op_active (1<<(_PDEVF_op_active))
  23. #define _PCIB_op_pending (1)
  24. #define PCIB_op_pending (1<<(_PCIB_op_pending))
  25. struct xen_pcibk_device {
  26. void *pci_dev_data;
  27. struct mutex dev_lock;
  28. struct xenbus_device *xdev;
  29. struct xenbus_watch be_watch;
  30. u8 be_watching;
  31. int evtchn_irq;
  32. struct xen_pci_sharedinfo *sh_info;
  33. unsigned long flags;
  34. struct work_struct op_work;
  35. };
  36. struct xen_pcibk_dev_data {
  37. struct list_head config_fields;
  38. unsigned int permissive:1;
  39. unsigned int warned_on_write:1;
  40. unsigned int enable_intx:1;
  41. unsigned int isr_on:1; /* Whether the IRQ handler is installed. */
  42. unsigned int ack_intr:1; /* .. and ACK-ing */
  43. unsigned long handled;
  44. unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */
  45. char irq_name[0]; /* xen-pcibk[000:04:00.0] */
  46. };
  47. /* Used by XenBus and xen_pcibk_ops.c */
  48. extern wait_queue_head_t xen_pcibk_aer_wait_queue;
  49. extern struct workqueue_struct *xen_pcibk_wq;
  50. /* Used by pcistub.c and conf_space_quirks.c */
  51. extern struct list_head xen_pcibk_quirks;
  52. /* Get/Put PCI Devices that are hidden from the PCI Backend Domain */
  53. struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
  54. int domain, int bus,
  55. int slot, int func);
  56. struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
  57. struct pci_dev *dev);
  58. void pcistub_put_pci_dev(struct pci_dev *dev);
  59. /* Ensure a device is turned off or reset */
  60. void xen_pcibk_reset_device(struct pci_dev *pdev);
  61. /* Access a virtual configuration space for a PCI device */
  62. int xen_pcibk_config_init(void);
  63. int xen_pcibk_config_init_dev(struct pci_dev *dev);
  64. void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev);
  65. void xen_pcibk_config_reset_dev(struct pci_dev *dev);
  66. void xen_pcibk_config_free_dev(struct pci_dev *dev);
  67. int xen_pcibk_config_read(struct pci_dev *dev, int offset, int size,
  68. u32 *ret_val);
  69. int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size,
  70. u32 value);
  71. /* Handle requests for specific devices from the frontend */
  72. typedef int (*publish_pci_dev_cb) (struct xen_pcibk_device *pdev,
  73. unsigned int domain, unsigned int bus,
  74. unsigned int devfn, unsigned int devid);
  75. typedef int (*publish_pci_root_cb) (struct xen_pcibk_device *pdev,
  76. unsigned int domain, unsigned int bus);
  77. /* Backend registration for the two types of BDF representation:
  78. * vpci - BDFs start at 00
  79. * passthrough - BDFs are exactly like in the host.
  80. */
  81. struct xen_pcibk_backend {
  82. const char *name;
  83. int (*init)(struct xen_pcibk_device *pdev);
  84. void (*free)(struct xen_pcibk_device *pdev);
  85. int (*find)(struct pci_dev *pcidev, struct xen_pcibk_device *pdev,
  86. unsigned int *domain, unsigned int *bus,
  87. unsigned int *devfn);
  88. int (*publish)(struct xen_pcibk_device *pdev, publish_pci_root_cb cb);
  89. void (*release)(struct xen_pcibk_device *pdev, struct pci_dev *dev);
  90. int (*add)(struct xen_pcibk_device *pdev, struct pci_dev *dev,
  91. int devid, publish_pci_dev_cb publish_cb);
  92. struct pci_dev *(*get)(struct xen_pcibk_device *pdev,
  93. unsigned int domain, unsigned int bus,
  94. unsigned int devfn);
  95. };
  96. extern const struct xen_pcibk_backend xen_pcibk_vpci_backend;
  97. extern const struct xen_pcibk_backend xen_pcibk_passthrough_backend;
  98. extern const struct xen_pcibk_backend *xen_pcibk_backend;
  99. static inline int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
  100. struct pci_dev *dev,
  101. int devid,
  102. publish_pci_dev_cb publish_cb)
  103. {
  104. if (xen_pcibk_backend && xen_pcibk_backend->add)
  105. return xen_pcibk_backend->add(pdev, dev, devid, publish_cb);
  106. return -1;
  107. }
  108. static inline void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
  109. struct pci_dev *dev)
  110. {
  111. if (xen_pcibk_backend && xen_pcibk_backend->free)
  112. return xen_pcibk_backend->release(pdev, dev);
  113. }
  114. static inline struct pci_dev *
  115. xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev, unsigned int domain,
  116. unsigned int bus, unsigned int devfn)
  117. {
  118. if (xen_pcibk_backend && xen_pcibk_backend->get)
  119. return xen_pcibk_backend->get(pdev, domain, bus, devfn);
  120. return NULL;
  121. }
  122. /**
  123. * Add for domain0 PCIE-AER handling. Get guest domain/bus/devfn in xen_pcibk
  124. * before sending aer request to pcifront, so that guest could identify
  125. * device, coopearte with xen_pcibk to finish aer recovery job if device driver
  126. * has the capability
  127. */
  128. static inline int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
  129. struct xen_pcibk_device *pdev,
  130. unsigned int *domain,
  131. unsigned int *bus,
  132. unsigned int *devfn)
  133. {
  134. if (xen_pcibk_backend && xen_pcibk_backend->find)
  135. return xen_pcibk_backend->find(pcidev, pdev, domain, bus,
  136. devfn);
  137. return -1;
  138. }
  139. static inline int xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
  140. {
  141. if (xen_pcibk_backend && xen_pcibk_backend->init)
  142. return xen_pcibk_backend->init(pdev);
  143. return -1;
  144. }
  145. static inline int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
  146. publish_pci_root_cb cb)
  147. {
  148. if (xen_pcibk_backend && xen_pcibk_backend->publish)
  149. return xen_pcibk_backend->publish(pdev, cb);
  150. return -1;
  151. }
  152. static inline void xen_pcibk_release_devices(struct xen_pcibk_device *pdev)
  153. {
  154. if (xen_pcibk_backend && xen_pcibk_backend->free)
  155. return xen_pcibk_backend->free(pdev);
  156. }
  157. /* Handles events from front-end */
  158. irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id);
  159. void xen_pcibk_do_op(struct work_struct *data);
  160. int xen_pcibk_xenbus_register(void);
  161. void xen_pcibk_xenbus_unregister(void);
  162. extern int verbose_request;
  163. void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev);
  164. #endif
  165. /* Handles shared IRQs that can to device domain and control domain. */
  166. void xen_pcibk_irq_handler(struct pci_dev *dev, int reset);