blob: a0e131a815030d5ed95536b1ea89f9ec5ef93b3a [file] [log] [blame]
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -04001/*
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
9#include <linux/pci.h>
10#include <linux/interrupt.h>
11#include <xen/xenbus.h>
12#include <linux/list.h>
13#include <linux/spinlock.h>
14#include <linux/workqueue.h>
Konrad Rzeszutek Wilk8bfd4e02011-07-19 20:09:43 -040015#include <linux/atomic.h>
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040016#include <xen/interface/io/pciif.h>
17
18struct pci_dev_entry {
19 struct list_head list;
20 struct pci_dev *dev;
21};
22
Konrad Rzeszutek Wilk8bfd4e02011-07-19 20:09:43 -040023#define _PDEVF_op_active (0)
24#define PDEVF_op_active (1<<(_PDEVF_op_active))
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040025#define _PCIB_op_pending (1)
26#define PCIB_op_pending (1<<(_PCIB_op_pending))
27
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040028struct xen_pcibk_device {
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040029 void *pci_dev_data;
30 spinlock_t dev_lock;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040031 struct xenbus_device *xdev;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040032 struct xenbus_watch be_watch;
33 u8 be_watching;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040034 int evtchn_irq;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040035 struct xen_pci_sharedinfo *sh_info;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040036 unsigned long flags;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040037 struct work_struct op_work;
38};
39
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040040struct xen_pcibk_dev_data {
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040041 struct list_head config_fields;
Konrad Rzeszutek Wilk0513fe92011-07-19 18:56:39 -040042 unsigned int permissive:1;
43 unsigned int warned_on_write:1;
44 unsigned int enable_intx:1;
45 unsigned int isr_on:1; /* Whether the IRQ handler is installed. */
46 unsigned int ack_intr:1; /* .. and ACK-ing */
47 unsigned long handled;
48 unsigned int irq; /* Saved in case device transitions to MSI/MSI-X */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040049 char irq_name[0]; /* xen-pcibk[000:04:00.0] */
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040050};
51
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040052/* Used by XenBus and xen_pcibk_ops.c */
53extern wait_queue_head_t xen_pcibk_aer_wait_queue;
54extern struct workqueue_struct *xen_pcibk_wq;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040055/* Used by pcistub.c and conf_space_quirks.c */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040056extern struct list_head xen_pcibk_quirks;
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040057
58/* Get/Put PCI Devices that are hidden from the PCI Backend Domain */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040059struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040060 int domain, int bus,
61 int slot, int func);
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040062struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040063 struct pci_dev *dev);
64void pcistub_put_pci_dev(struct pci_dev *dev);
65
66/* Ensure a device is turned off or reset */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040067void xen_pcibk_reset_device(struct pci_dev *pdev);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040068
69/* Access a virtual configuration space for a PCI device */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040070int xen_pcibk_config_init(void);
71int xen_pcibk_config_init_dev(struct pci_dev *dev);
72void xen_pcibk_config_free_dyn_fields(struct pci_dev *dev);
73void xen_pcibk_config_reset_dev(struct pci_dev *dev);
74void xen_pcibk_config_free_dev(struct pci_dev *dev);
75int xen_pcibk_config_read(struct pci_dev *dev, int offset, int size,
76 u32 *ret_val);
77int xen_pcibk_config_write(struct pci_dev *dev, int offset, int size,
78 u32 value);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040079
80/* Handle requests for specific devices from the frontend */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040081typedef int (*publish_pci_dev_cb) (struct xen_pcibk_device *pdev,
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040082 unsigned int domain, unsigned int bus,
83 unsigned int devfn, unsigned int devid);
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -040084typedef int (*publish_pci_root_cb) (struct xen_pcibk_device *pdev,
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040085 unsigned int domain, unsigned int bus);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040086
Konrad Rzeszutek Wilk2ebdc422011-07-11 16:49:41 -040087/* Backend registration for the two types of BDF representation:
88 * vpci - BDFs start at 00
89 * passthrough - BDFs are exactly like in the host.
90 */
91struct xen_pcibk_backend {
92 char *name;
93 int (*init)(struct xen_pcibk_device *pdev);
94 void (*free)(struct xen_pcibk_device *pdev);
95 int (*find)(struct pci_dev *pcidev, struct xen_pcibk_device *pdev,
96 unsigned int *domain, unsigned int *bus,
97 unsigned int *devfn);
98 int (*publish)(struct xen_pcibk_device *pdev, publish_pci_root_cb cb);
99 void (*release)(struct xen_pcibk_device *pdev, struct pci_dev *dev);
100 int (*add)(struct xen_pcibk_device *pdev, struct pci_dev *dev,
101 int devid, publish_pci_dev_cb publish_cb);
102 struct pci_dev *(*get)(struct xen_pcibk_device *pdev,
103 unsigned int domain, unsigned int bus,
104 unsigned int devfn);
105};
106
107extern struct xen_pcibk_backend xen_pcibk_vpci_backend;
108extern struct xen_pcibk_backend xen_pcibk_passthrough_backend;
109extern struct xen_pcibk_backend *xen_pcibk_backend;
110
111static inline int xen_pcibk_add_pci_dev(struct xen_pcibk_device *pdev,
112 struct pci_dev *dev,
113 int devid,
114 publish_pci_dev_cb publish_cb)
115{
116 if (xen_pcibk_backend && xen_pcibk_backend->add)
117 return xen_pcibk_backend->add(pdev, dev, devid, publish_cb);
118 return -1;
119};
120static inline void xen_pcibk_release_pci_dev(struct xen_pcibk_device *pdev,
121 struct pci_dev *dev)
122{
123 if (xen_pcibk_backend && xen_pcibk_backend->free)
124 return xen_pcibk_backend->release(pdev, dev);
125};
126
127static inline struct pci_dev *
128xen_pcibk_get_pci_dev(struct xen_pcibk_device *pdev, unsigned int domain,
129 unsigned int bus, unsigned int devfn)
130{
131 if (xen_pcibk_backend && xen_pcibk_backend->get)
132 return xen_pcibk_backend->get(pdev, domain, bus, devfn);
133 return NULL;
134};
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400135/**
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400136* Add for domain0 PCIE-AER handling. Get guest domain/bus/devfn in xen_pcibk
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400137* before sending aer request to pcifront, so that guest could identify
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400138* device, coopearte with xen_pcibk to finish aer recovery job if device driver
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400139* has the capability
140*/
Konrad Rzeszutek Wilk2ebdc422011-07-11 16:49:41 -0400141static inline int xen_pcibk_get_pcifront_dev(struct pci_dev *pcidev,
142 struct xen_pcibk_device *pdev,
143 unsigned int *domain,
144 unsigned int *bus,
145 unsigned int *devfn)
146{
147 if (xen_pcibk_backend && xen_pcibk_backend->find)
148 return xen_pcibk_backend->find(pcidev, pdev, domain, bus,
149 devfn);
150 return -1;
151};
152static inline int xen_pcibk_init_devices(struct xen_pcibk_device *pdev)
153{
154 if (xen_pcibk_backend && xen_pcibk_backend->init)
155 return xen_pcibk_backend->init(pdev);
156 return -1;
157};
158static inline int xen_pcibk_publish_pci_roots(struct xen_pcibk_device *pdev,
159 publish_pci_root_cb cb)
160{
161 if (xen_pcibk_backend && xen_pcibk_backend->publish)
162 return xen_pcibk_backend->publish(pdev, cb);
163 return -1;
164};
165static inline void xen_pcibk_release_devices(struct xen_pcibk_device *pdev)
166{
167 if (xen_pcibk_backend && xen_pcibk_backend->free)
168 return xen_pcibk_backend->free(pdev);
169};
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400170/* Handles events from front-end */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400171irqreturn_t xen_pcibk_handle_event(int irq, void *dev_id);
172void xen_pcibk_do_op(struct work_struct *data);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400173
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400174int xen_pcibk_xenbus_register(void);
175void xen_pcibk_xenbus_unregister(void);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400176
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400177extern int verbose_request;
178
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400179void xen_pcibk_test_and_schedule_op(struct xen_pcibk_device *pdev);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400180#endif
181
Konrad Rzeszutek Wilk0513fe92011-07-19 18:56:39 -0400182/* Handles shared IRQs that can to device domain and control domain. */
Konrad Rzeszutek Wilka92336a2011-07-19 19:40:51 -0400183void xen_pcibk_irq_handler(struct pci_dev *dev, int reset);