virtio-pci.h

Go to the documentation of this file.
00001 #ifndef _VIRTIO_PCI_H_
00002 # define _VIRTIO_PCI_H_
00003 
00004 /* A 32-bit r/o bitmask of the features supported by the host */
00005 #define VIRTIO_PCI_HOST_FEATURES        0
00006 
00007 /* A 32-bit r/w bitmask of features activated by the guest */
00008 #define VIRTIO_PCI_GUEST_FEATURES       4
00009 
00010 /* A 32-bit r/w PFN for the currently selected queue */
00011 #define VIRTIO_PCI_QUEUE_PFN            8
00012 
00013 /* A 16-bit r/o queue size for the currently selected queue */
00014 #define VIRTIO_PCI_QUEUE_NUM            12
00015 
00016 /* A 16-bit r/w queue selector */
00017 #define VIRTIO_PCI_QUEUE_SEL            14
00018 
00019 /* A 16-bit r/w queue notifier */
00020 #define VIRTIO_PCI_QUEUE_NOTIFY         16
00021 
00022 /* An 8-bit device status register.  */
00023 #define VIRTIO_PCI_STATUS               18
00024 
00025 /* An 8-bit r/o interrupt status register.  Reading the value will return the
00026  * current contents of the ISR and will also clear it.  This is effectively
00027  * a read-and-acknowledge. */
00028 #define VIRTIO_PCI_ISR                  19
00029 
00030 /* The bit of the ISR which indicates a device configuration change. */
00031 #define VIRTIO_PCI_ISR_CONFIG           0x2
00032 
00033 /* The remaining space is defined by each driver as the per-driver
00034  * configuration space */
00035 #define VIRTIO_PCI_CONFIG               20
00036 
00037 /* Virtio ABI version, this must match exactly */
00038 #define VIRTIO_PCI_ABI_VERSION          0
00039 
00040 static inline u32 vp_get_features(unsigned int ioaddr)
00041 {
00042    return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
00043 }
00044 
00045 static inline void vp_set_features(unsigned int ioaddr, u32 features)
00046 {
00047         outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
00048 }
00049 
00050 static inline void vp_get(unsigned int ioaddr, unsigned offset,
00051                      void *buf, unsigned len)
00052 {
00053    u8 *ptr = buf;
00054    unsigned i;
00055 
00056    for (i = 0; i < len; i++)
00057            ptr[i] = inb(ioaddr + VIRTIO_PCI_CONFIG + offset + i);
00058 }
00059 
00060 static inline u8 vp_get_status(unsigned int ioaddr)
00061 {
00062    return inb(ioaddr + VIRTIO_PCI_STATUS);
00063 }
00064 
00065 static inline void vp_set_status(unsigned int ioaddr, u8 status)
00066 {
00067    if (status == 0)        /* reset */
00068            return;
00069    outb(status, ioaddr + VIRTIO_PCI_STATUS);
00070 }
00071 
00072 
00073 static inline void vp_reset(unsigned int ioaddr)
00074 {
00075    outb(0, ioaddr + VIRTIO_PCI_STATUS);
00076    (void)inb(ioaddr + VIRTIO_PCI_ISR);
00077 }
00078 
00079 static inline void vp_notify(unsigned int ioaddr, int queue_index)
00080 {
00081    outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
00082 }
00083 
00084 static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
00085 {
00086    /* select the queue */
00087 
00088    outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
00089 
00090    /* deactivate the queue */
00091 
00092    outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
00093 }
00094 
00095 int vp_find_vq(unsigned int ioaddr, int queue_index,
00096                struct vring_virtqueue *vq);
00097 #endif /* _VIRTIO_PCI_H_ */

Generated on Tue Apr 6 20:01:09 2010 for gPXE by  doxygen 1.5.7.1