pciback.h 6.2 KB

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