b4ba67d9a7
The usual use model for the libqos PCI functions is to map a specific PCI BAR using qpci_iomap() then pass the returned token into IO accessor functions. This, and the fact that iomap() returns a (void *) which actually contains a PCI space address, kind of suggests that the return value from iomap is supposed to be an opaque token. ..except that the callers expect to be able to add offsets to it. Which also assumes the compiler will support pointer arithmetic on a (void *), and treat it as working with byte offsets. To clarify this situation change iomap() and the IO accessors to take a definitely opaque BAR handle (enforced with a wrapper struct) along with an offset within the BAR. This changes both the functions and all the callers. There were a number of places that checked if iomap() returned non-NULL, and or initialized it to NULL before hand. Since iomap() already assert()s if it fails to map the BAR, these tests were mostly pointless and are removed. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Greg Kurz <groug@kaod.org>
45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
/*
|
|
* libqos virtio PCI definitions
|
|
*
|
|
* Copyright (c) 2014 Marc Marí
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
|
|
#ifndef LIBQOS_VIRTIO_PCI_H
|
|
#define LIBQOS_VIRTIO_PCI_H
|
|
|
|
#include "libqos/virtio.h"
|
|
#include "libqos/pci.h"
|
|
|
|
typedef struct QVirtioPCIDevice {
|
|
QVirtioDevice vdev;
|
|
QPCIDevice *pdev;
|
|
QPCIBar bar;
|
|
uint16_t config_msix_entry;
|
|
uint64_t config_msix_addr;
|
|
uint32_t config_msix_data;
|
|
} QVirtioPCIDevice;
|
|
|
|
typedef struct QVirtQueuePCI {
|
|
QVirtQueue vq;
|
|
uint16_t msix_entry;
|
|
uint64_t msix_addr;
|
|
uint32_t msix_data;
|
|
} QVirtQueuePCI;
|
|
|
|
extern const QVirtioBus qvirtio_pci;
|
|
|
|
void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type,
|
|
void (*func)(QVirtioDevice *d, void *data), void *data);
|
|
QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type);
|
|
void qvirtio_pci_device_enable(QVirtioPCIDevice *d);
|
|
void qvirtio_pci_device_disable(QVirtioPCIDevice *d);
|
|
|
|
void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,
|
|
QGuestAllocator *alloc, uint16_t entry);
|
|
void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci,
|
|
QGuestAllocator *alloc, uint16_t entry);
|
|
#endif
|