virtio-pci.c File Reference

#include "etherboot.h"
#include "gpxe/io.h"
#include "gpxe/virtio-ring.h"
#include "gpxe/virtio-pci.h"

Go to the source code of this file.

Functions

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


Function Documentation

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:16 2010 for gPXE by  doxygen 1.5.7.1