1 /* virtio-pci.c - pci interface for virtio interface
3 * (c) Copyright 2008 Bull S.A.S.
5 * Author: Laurent Vivier <Laurent.Vivier@bull.net>
7 * some parts from Linux Virtio PCI driver
9 * Copyright IBM Corp. 2007
10 * Authors: Anthony Liguori <aliguori@us.ibm.com>
12 * Adopted for Seabios: Gleb Natapov <gleb@redhat.com>
14 * This work is licensed under the terms of the GNU LGPLv3
15 * See the COPYING file in the top-level directory.
18 #include "virtio-ring.h"
19 #include "virtio-pci.h"
21 int vp_find_vq(unsigned int ioaddr, int queue_index,
22 struct vring_virtqueue *vq)
24 struct vring * vr = &vq->vring;
28 /* select the queue */
30 outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
32 /* check if the queue is available */
34 num = inw(ioaddr + VIRTIO_PCI_QUEUE_NUM);
36 dprintf(1, "ERROR: queue size is 0\n");
40 if (num > MAX_QUEUE_NUM) {
41 dprintf(1, "ERROR: queue size %d > %d\n", num, MAX_QUEUE_NUM);
45 /* check if the queue is already active */
47 if (inl(ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
48 dprintf(1, "ERROR: queue already active\n");
52 vq->queue_index = queue_index;
54 /* initialize the queue */
56 vring_init(vr, num, (unsigned char*)&vq->queue);
60 * NOTE: vr->desc is initialized by vring_init()
63 outl((unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT,
64 ioaddr + VIRTIO_PCI_QUEUE_PFN);