pciback.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. struct pci_saved_state *pci_saved_state;
  39. unsigned int permissive:1;
  40. unsigned int warned_on_write:1;
  41. unsigned int enable_intx:1;
  42. unsigned int isr_on:1; /* Whether the IRQ handler is installed. */
  43. unsigned int ack_intr:1; /* .. and ACK-ing */
  44. unsigned long handled;
  45. unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */
  46. char irq_name[0]; /* xen-pcibk[000:04:00.0] */
  47. };
  48. /* Used by XenBus and xen_pcibk_ops.c */
  49. extern wait_queue_head_t xen_pcibk_aer_wait_queue;
  50. extern struct workqueue_struct *xen_pcibk_wq;
  51. /* Used by pcistub.c and conf_space_quirks.c */
  52. extern struct list_head xen_pcibk_quirks;
  53. /* Get/Put PCI Devices that are hidden from the PCI Backend Domain */
  54. struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
  55. int domain, int bus,
  56. int slot, int func);
  57. struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
  58. struct pci_dev *dev);
  59. void pcistub_put_pci_dev(struct pci_dev *dev);
  60. /* Ensure a device is turned off or reset */
  61. void xen_pcibk_reset_device(struct pci_dev *pdev);
  62. /* Access a virtual configuration space for a PCI device */
  63. int xen_pcibk_config_init(void);
  64. int xen_pcibk_config_init_dev(struct pci_dev *dev);
  65. void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev);
  66. void xen_pcibk_config_reset_dev(struct pci_dev *dev);
  67. void xen_pcibk_config_free_dev(struct pci_dev *dev);
  68. int xen_pcibk_config_read(struct pci_dev *dev, int offset, int size,
  69. u32 *ret_val);
  70. int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size,
  71. u32 value);
  72. /* Handle requests for specific devices from the frontend */
  73. typedef int (*publish_pci_dev_cb) (struct xen_pcibk_device *pdev,
  74. unsigned int domain, unsigned int bus,
  75. unsigned int devfn, unsigned int devid);
  76. typedef int (*publish_pci_root_cb) (struct xen_pcibk_device *pdev,
  77. unsigned int domain, unsigned int bus);
  78. /* Backend registration for the two types of BDF representation:
  79. * vpci - BDFs start at 00
  80. * passthrough - BDFs are exactly like in the host.
  81. */
  82. struct xen_pcibk_backend {
  83. const char *name;
  84. int (*init)(struct xen_pcibk_device *pdev);
  85. void (*free)(struct xen_pcibk_device *pdev);
  86. int (*find)(struct pci_dev *pcidev, struct xen_pcibk_device *pdev,
  87. unsigned int *domain, unsigned int *bus,
  88. unsigned int *devfn);
  89. int (*publish)(struct xen_pcibk_device *pdev, publish_pci_root_cb cb);
  90. void (*release)(struct xen_pcibk_device *pdev, struct pci_dev *dev);
  91. int (*add)(struct xen_pcibk_device *pdev, struct pci_dev *dev,
  92. int devid, publish_pci_dev_cb publish_cb);
  93. struct pci_dev *(*get)(struct xen_pcibk_device *pdev,
  94. unsigned int domain, unsigned int bus,
  95. unsigned int devfn);
  96. };
  97. extern const struct xen_pcibk_backend xen_pcibk_vpci_backend;
  98. extern const struct xen_pcibk_backend xen_pcibk_passthrough_backend;
  99. extern const struct xen_pcibk_backend *xen_pcibk_backend;
  100. static inline int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
  101. struct pci_dev *dev,
  102. int devid,
  103. publish_pci_dev_cb publish_cb)
  104. {
  105. if (xen_pcibk_backend && xen_pcibk_backend->add)
  106. return xen_pcibk_backend->add(pdev, dev, devid, publish_cb);
  107. return -1;
  108. }
  109. static inline void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
  110. struct pci_dev *dev)
  111. {
  112. if (xen_pcibk_backend && xen_pcibk_backend->release)
  113. return xen_pcibk_backend->release(pdev, dev);
  114. }
  115. static inline struct pci_dev *
  116. xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev, unsigned int domain,
  117. unsigned int bus, unsigned int devfn)
  118. {
  119. if (xen_pcibk_backend && xen_pcibk_backend->get)
  120. return xen_pcibk_backend->get(pdev, domain, bus, devfn);
  121. return NULL;
  122. }
  123. /**
  124. * Add for domain0 PCIE-AER handling. Get guest domain/bus/devfn in xen_pcibk
  125. * before sending aer request to pcifront, so that guest could identify
  126. * device, coopearte with xen_pcibk to finish aer recovery job if device driver
  127. * has the capability
  128. */
  129. static inline int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
  130. struct xen_pcibk_device *pdev,
  131. unsigned int *domain,
  132. unsigned int *bus,
  133. unsigned int *devfn)
  134. {
  135. if (xen_pcibk_backend && xen_pcibk_backend->find)
  136. return xen_pcibk_backend->find(pcidev, pdev, domain, bus,
  137. devfn);
  138. return -1;
  139. }
  140. static inline int xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
  141. {
  142. if (xen_pcibk_backend && xen_pcibk_backend->init)
  143. return xen_pcibk_backend->init(pdev);
  144. return -1;
  145. }
  146. static inline int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
  147. publish_pci_root_cb cb)
  148. {
  149. if (xen_pcibk_backend && xen_pcibk_backend->publish)
  150. return xen_pcibk_backend->publish(pdev, cb);
  151. return -1;
  152. }
  153. static inline void xen_pcibk_release_devices(struct xen_pcibk_device *pdev)
  154. {
  155. if (xen_pcibk_backend && xen_pcibk_backend->free)
  156. return xen_pcibk_backend->free(pdev);
  157. }
  158. /* Handles events from front-end */
  159. irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id);
  160. void xen_pcibk_do_op(struct work_struct *data);
  161. int xen_pcibk_xenbus_register(void);
  162. void xen_pcibk_xenbus_unregister(void);
  163. extern int verbose_request;
  164. void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev);
  165. #endif
  166. /* Handles shared IRQs that can to device domain and control domain. */
  167. void xen_pcibk_irq_handler(struct pci_dev *dev, int reset);