virtio-pci.h File Reference

Go to the source code of this file.

Defines

#define VIRTIO_PCI_HOST_FEATURES   0
#define VIRTIO_PCI_GUEST_FEATURES   4
#define VIRTIO_PCI_QUEUE_PFN   8
#define VIRTIO_PCI_QUEUE_NUM   12
#define VIRTIO_PCI_QUEUE_SEL   14
#define VIRTIO_PCI_QUEUE_NOTIFY   16
#define VIRTIO_PCI_STATUS   18
#define VIRTIO_PCI_ISR   19
#define VIRTIO_PCI_ISR_CONFIG   0x2
#define VIRTIO_PCI_CONFIG   20
#define VIRTIO_PCI_ABI_VERSION   0

Functions

static u32 vp_get_features (unsigned int ioaddr)
static void vp_set_features (unsigned int ioaddr, u32 features)
static void vp_get (unsigned int ioaddr, unsigned offset, void *buf, unsigned len)
static u8 vp_get_status (unsigned int ioaddr)
static void vp_set_status (unsigned int ioaddr, u8 status)
static void vp_reset (unsigned int ioaddr)
static void vp_notify (unsigned int ioaddr, int queue_index)
static void vp_del_vq (unsigned int ioaddr, int queue_index)
int vp_find_vq (unsigned int ioaddr, int queue_index, struct vring_virtqueue *vq)


Define Documentation

#define VIRTIO_PCI_HOST_FEATURES   0

Definition at line 5 of file virtio-pci.h.

Referenced by vp_get_features().

#define VIRTIO_PCI_GUEST_FEATURES   4

Definition at line 8 of file virtio-pci.h.

Referenced by vp_set_features().

#define VIRTIO_PCI_QUEUE_PFN   8

Definition at line 11 of file virtio-pci.h.

Referenced by vp_del_vq(), and vp_find_vq().

#define VIRTIO_PCI_QUEUE_NUM   12

Definition at line 14 of file virtio-pci.h.

Referenced by vp_find_vq().

#define VIRTIO_PCI_QUEUE_SEL   14

Definition at line 17 of file virtio-pci.h.

Referenced by vp_del_vq(), and vp_find_vq().

#define VIRTIO_PCI_QUEUE_NOTIFY   16

Definition at line 20 of file virtio-pci.h.

Referenced by vp_notify().

#define VIRTIO_PCI_STATUS   18

Definition at line 23 of file virtio-pci.h.

Referenced by vp_get_status(), vp_reset(), and vp_set_status().

#define VIRTIO_PCI_ISR   19

Definition at line 28 of file virtio-pci.h.

Referenced by vp_reset().

#define VIRTIO_PCI_ISR_CONFIG   0x2

Definition at line 31 of file virtio-pci.h.

#define VIRTIO_PCI_CONFIG   20

Definition at line 35 of file virtio-pci.h.

Referenced by vp_get().

#define VIRTIO_PCI_ABI_VERSION   0

Definition at line 38 of file virtio-pci.h.


Function Documentation

static u32 vp_get_features ( unsigned int  ioaddr  )  [inline, static]

Definition at line 40 of file virtio-pci.h.

References inl, and VIRTIO_PCI_HOST_FEATURES.

Referenced by virtnet_probe().

00041 {
00042    return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
00043 }

static void vp_set_features ( unsigned int  ioaddr,
u32  features 
) [inline, static]

Definition at line 45 of file virtio-pci.h.

References outl, and VIRTIO_PCI_GUEST_FEATURES.

Referenced by virtnet_probe().

00046 {
00047         outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
00048 }

static void vp_get ( unsigned int  ioaddr,
unsigned  offset,
void *  buf,
unsigned  len 
) [inline, static]

Definition at line 50 of file virtio-pci.h.

References inb, u8, and VIRTIO_PCI_CONFIG.

Referenced by virtnet_probe().

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 }

static u8 vp_get_status ( unsigned int  ioaddr  )  [inline, static]

Definition at line 60 of file virtio-pci.h.

References inb, and VIRTIO_PCI_STATUS.

00061 {
00062    return inb(ioaddr + VIRTIO_PCI_STATUS);
00063 }

static void vp_set_status ( unsigned int  ioaddr,
u8  status 
) [inline, static]

Definition at line 65 of file virtio-pci.h.

References outb, and VIRTIO_PCI_STATUS.

Referenced by virtnet_probe().

00066 {
00067    if (status == 0)        /* reset */
00068            return;
00069    outb(status, ioaddr + VIRTIO_PCI_STATUS);
00070 }

static void vp_reset ( unsigned int  ioaddr  )  [inline, static]

Definition at line 73 of file virtio-pci.h.

References inb, outb, VIRTIO_PCI_ISR, and VIRTIO_PCI_STATUS.

Referenced by virtnet_disable(), and virtnet_probe().

00074 {
00075    outb(0, ioaddr + VIRTIO_PCI_STATUS);
00076    (void)inb(ioaddr + VIRTIO_PCI_ISR);
00077 }

static void vp_notify ( unsigned int  ioaddr,
int  queue_index 
) [inline, static]

Definition at line 79 of file virtio-pci.h.

References outw, and VIRTIO_PCI_QUEUE_NOTIFY.

Referenced by vring_kick().

00080 {
00081    outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
00082 }

static void vp_del_vq ( unsigned int  ioaddr,
int  queue_index 
) [inline, static]

Definition at line 84 of file virtio-pci.h.

References outl, outw, VIRTIO_PCI_QUEUE_PFN, and VIRTIO_PCI_QUEUE_SEL.

Referenced by virtnet_disable().

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 }

int vp_find_vq ( unsigned int  ioaddr,
int  queue_index,
struct vring_virtqueue vq 
)

Definition at line 19 of file virtio-pci.c.

References vring::desc, inl, inw, MAX_QUEUE_NUM, vring::num, outl, outw, PAGE_SHIFT, printf(), vring_virtqueue::queue, vring_virtqueue::queue_index, u16, virt_to_phys(), VIRTIO_PCI_QUEUE_NUM, VIRTIO_PCI_QUEUE_PFN, VIRTIO_PCI_QUEUE_SEL, vring_virtqueue::vring, and vring_init().

Referenced by virtnet_probe().

00021 {
00022    struct vring * vr = &vq->vring;
00023    u16 num;
00024 
00025    /* select the queue */
00026 
00027    outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
00028 
00029    /* check if the queue is available */
00030 
00031    num = inw(ioaddr + VIRTIO_PCI_QUEUE_NUM);
00032    if (!num) {
00033            printf("ERROR: queue size is 0\n");
00034            return -1;
00035    }
00036 
00037    if (num > MAX_QUEUE_NUM) {
00038            printf("ERROR: queue size %d > %d\n", num, MAX_QUEUE_NUM);
00039            return -1;
00040    }
00041 
00042    /* check if the queue is already active */
00043 
00044    if (inl(ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
00045            printf("ERROR: queue already active\n");
00046            return -1;
00047    }
00048 
00049    vq->queue_index = queue_index;
00050 
00051    /* initialize the queue */
00052 
00053    vring_init(vr, num, (unsigned char*)&vq->queue);
00054 
00055    /* activate the queue
00056     *
00057     * NOTE: vr->desc is initialized by vring_init()
00058     */
00059 
00060    outl((unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT,
00061         ioaddr + VIRTIO_PCI_QUEUE_PFN);
00062 
00063    return num;
00064 }


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