4
#include "ioport.h" // inl
6
/* A 32-bit r/o bitmask of the features supported by the host */
7
#define VIRTIO_PCI_HOST_FEATURES 0
9
/* A 32-bit r/w bitmask of features activated by the guest */
10
#define VIRTIO_PCI_GUEST_FEATURES 4
12
/* A 32-bit r/w PFN for the currently selected queue */
13
#define VIRTIO_PCI_QUEUE_PFN 8
15
/* A 16-bit r/o queue size for the currently selected queue */
16
#define VIRTIO_PCI_QUEUE_NUM 12
18
/* A 16-bit r/w queue selector */
19
#define VIRTIO_PCI_QUEUE_SEL 14
21
/* A 16-bit r/w queue notifier */
22
#define VIRTIO_PCI_QUEUE_NOTIFY 16
24
/* An 8-bit device status register. */
25
#define VIRTIO_PCI_STATUS 18
27
/* An 8-bit r/o interrupt status register. Reading the value will return the
28
* current contents of the ISR and will also clear it. This is effectively
29
* a read-and-acknowledge. */
30
#define VIRTIO_PCI_ISR 19
32
/* The bit of the ISR which indicates a device configuration change. */
33
#define VIRTIO_PCI_ISR_CONFIG 0x2
35
/* The remaining space is defined by each driver as the per-driver
36
* configuration space */
37
#define VIRTIO_PCI_CONFIG 20
39
/* Virtio ABI version, this must match exactly */
40
#define VIRTIO_PCI_ABI_VERSION 0
42
static inline u32 vp_get_features(unsigned int ioaddr)
44
return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
47
static inline void vp_set_features(unsigned int ioaddr, u32 features)
49
outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
52
static inline void vp_get(unsigned int ioaddr, unsigned offset,
53
void *buf, unsigned len)
58
for (i = 0; i < len; i++)
59
ptr[i] = inb(ioaddr + VIRTIO_PCI_CONFIG + offset + i);
62
static inline u8 vp_get_status(unsigned int ioaddr)
64
return inb(ioaddr + VIRTIO_PCI_STATUS);
67
static inline void vp_set_status(unsigned int ioaddr, u8 status)
69
if (status == 0) /* reset */
71
outb(status, ioaddr + VIRTIO_PCI_STATUS);
75
static inline void vp_reset(unsigned int ioaddr)
77
outb(0, ioaddr + VIRTIO_PCI_STATUS);
78
(void)inb(ioaddr + VIRTIO_PCI_ISR);
81
static inline void vp_notify(unsigned int ioaddr, int queue_index)
83
outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
86
static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
88
/* select the queue */
90
outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
92
/* deactivate the queue */
94
outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
97
struct vring_virtqueue;
98
int vp_find_vq(unsigned int ioaddr, int queue_index,
99
struct vring_virtqueue *vq);
100
#endif /* _VIRTIO_PCI_H_ */