pciback.h 6.1 KB

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