From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [RFC v5 42/86] virtio-pci: convert to memory API
Date: Wed, 20 Jul 2011 19:49:52 +0300 [thread overview]
Message-ID: <1311180636-17012-43-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1311180636-17012-1-git-send-email-avi@redhat.com>
except msix.
[jan: fix build]
Signed-off-by: Avi Kivity <avi@redhat.com>
---
hw/virtio-pci.c | 74 ++++++++++++++++++++++--------------------------------
hw/virtio-pci.h | 2 +-
2 files changed, 31 insertions(+), 45 deletions(-)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index d685243..c114e1a 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -161,7 +161,8 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
{
VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
- int r;
+ int r = 0;
+
if (assign) {
r = event_notifier_init(notifier, 1);
if (r < 0) {
@@ -169,24 +170,11 @@ static int virtio_pci_set_host_notifier_internal(VirtIOPCIProxy *proxy,
__func__, r);
return r;
}
- r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
- proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
- n, assign);
- if (r < 0) {
- error_report("%s: unable to map ioeventfd: %d",
- __func__, r);
- event_notifier_cleanup(notifier);
- }
+ memory_region_add_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
+ true, n, event_notifier_get_fd(notifier));
} else {
- r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
- proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
- n, assign);
- if (r < 0) {
- error_report("%s: unable to unmap ioeventfd: %d",
- __func__, r);
- return r;
- }
-
+ memory_region_del_eventfd(&proxy->bar, VIRTIO_PCI_QUEUE_NOTIFY, 2,
+ true, n, event_notifier_get_fd(notifier));
/* Handle the race condition where the guest kicked and we deassigned
* before we got around to handling the kick.
*/
@@ -423,7 +411,6 @@ static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config)
return virtio_ioport_read(proxy, addr);
addr -= config;
@@ -434,7 +421,6 @@ static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config)
return virtio_ioport_read(proxy, addr);
addr -= config;
@@ -445,7 +431,6 @@ static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config)
return virtio_ioport_read(proxy, addr);
addr -= config;
@@ -456,7 +441,6 @@ static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config) {
virtio_ioport_write(proxy, addr, val);
return;
@@ -469,7 +453,6 @@ static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config) {
virtio_ioport_write(proxy, addr, val);
return;
@@ -482,7 +465,6 @@ static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
{
VirtIOPCIProxy *proxy = opaque;
uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
- addr -= proxy->addr;
if (addr < config) {
virtio_ioport_write(proxy, addr, val);
return;
@@ -491,30 +473,26 @@ static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
virtio_config_writel(proxy->vdev, addr, val);
}
-static void virtio_map(PCIDevice *pci_dev, int region_num,
- pcibus_t addr, pcibus_t size, int type)
-{
- VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
- VirtIODevice *vdev = proxy->vdev;
- unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
-
- proxy->addr = addr;
-
- register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
- register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
- register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
- register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
- register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
- register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
+const MemoryRegionPortio virtio_portio[] = {
+ { 0, 0x10000, 1, .write = virtio_pci_config_writeb, },
+ { 0, 0x10000, 2, .write = virtio_pci_config_writew, },
+ { 0, 0x10000, 4, .write = virtio_pci_config_writel, },
+ { 0, 0x10000, 1, .read = virtio_pci_config_readb, },
+ { 0, 0x10000, 2, .read = virtio_pci_config_readw, },
+ { 0, 0x10000, 4, .read = virtio_pci_config_readl, },
+ PORTIO_END
+};
- if (vdev->config_len)
- vdev->get_config(vdev, vdev->config);
-}
+static const MemoryRegionOps virtio_pci_config_ops = {
+ .old_portio = virtio_portio,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+};
static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
uint32_t val, int len)
{
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+ VirtIODevice *vdev = proxy->vdev;
if (PCI_COMMAND == address) {
if (!(val & PCI_COMMAND_MASTER)) {
@@ -525,6 +503,9 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
}
}
}
+ if (address == PCI_BASE_ADDRESS_0 && vdev->config_len) {
+ vdev->get_config(vdev, vdev->config);
+ }
pci_default_write_config(pci_dev, address, val, len);
msix_write_config(pci_dev, address, val, len);
@@ -678,8 +659,10 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
if (size & (size-1))
size = 1 << qemu_fls(size);
- pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
- virtio_map);
+ memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
+ "virtio-pci", size);
+ pci_register_bar_region(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
+ &proxy->bar);
if (!kvm_has_many_ioeventfds()) {
proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
@@ -714,6 +697,9 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
static int virtio_exit_pci(PCIDevice *pci_dev)
{
+ VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+
+ memory_region_destroy(&proxy->bar);
return msix_uninit(pci_dev);
}
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 1f0de56..5af1c8c 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -21,8 +21,8 @@
typedef struct {
PCIDevice pci_dev;
VirtIODevice *vdev;
+ MemoryRegion bar;
uint32_t flags;
- uint32_t addr;
uint32_t class_code;
uint32_t nvectors;
BlockConf block;
--
1.7.5.3
next prev parent reply other threads:[~2011-07-20 17:02 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-20 16:49 [Qemu-devel] [RFC v5 00/86] Memory API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 01/86] xen: fix xen-mapcache build on non-Xen capable targets Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 02/86] Hierarchical memory region API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 03/86] memory: implement dirty tracking Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 04/86] memory: merge adjacent segments of a single memory region Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 05/86] Internal interfaces for memory API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 06/86] memory: abstract address space operations Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 07/86] memory: rename MemoryRegion::has_ram_addr to ::terminates Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 08/86] memory: late initialization of ram_addr Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 09/86] memory: I/O address space support Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 10/86] memory: add backward compatibility for old portio registration Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 11/86] memory: add backward compatibility for old mmio registration Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 12/86] memory: add ioeventfd support Avi Kivity
2011-07-21 19:55 ` Blue Swirl
2011-07-22 7:05 ` Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 13/86] memory: separate building the final memory map into two steps Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 14/86] exec.c: initialize memory map Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 15/86] ioport: register ranges by byte aligned addresses always Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 16/86] pc: grab system_memory Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 17/86] pc: convert pc_memory_init() to memory API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 18/86] pc: move global memory map out of pc_init1() and into its callers Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 19/86] pci: pass address space to pci bus when created Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 20/86] pci: add MemoryRegion based BAR management API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 21/86] sysbus: add MemoryRegion based memory " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 22/86] usb-ohci: convert to MemoryRegion Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 23/86] pci: add API to get a BAR's mapped address Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 24/86] vmsvga: don't remember pci BAR address in callback any more Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 25/86] vga: convert vga and its derivatives to the memory API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 26/86] cirrus: simplify mmio BAR access functions Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 27/86] cirrus: simplify bitblt " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 28/86] cirrus: simplify vga window mmio " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 29/86] vga: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 30/86] cirrus: simplify linear framebuffer " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 31/86] Integrate I/O memory regions into qemu Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 32/86] exec.c: fix initialization of system I/O memory region Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 33/86] pci: pass I/O address space to new PCI bus Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 34/86] pci: allow I/O BARs to be registered with pci_register_bar_region() Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 35/86] rtl8139: convert to memory API Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 36/86] ac97: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 37/86] e1000: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 38/86] eepro100: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 39/86] es1370: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 40/86] ide: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 41/86] ivshmem: " Avi Kivity
2011-07-20 16:49 ` Avi Kivity [this message]
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 43/86] ahci: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 44/86] intel-hda: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 45/86] lsi53c895a: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 46/86] ppc: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 47/86] ne2000: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 48/86] pcnet: " Avi Kivity
2011-07-20 16:49 ` [Qemu-devel] [RFC v5 49/86] i6300esb: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 50/86] isa-mmio: concert " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 51/86] sun4u: convert " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 52/86] ehci: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 53/86] uhci: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 54/86] xen-platform: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 55/86] msix: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 56/86] pci: remove pci_register_bar_simple() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 57/86] pci: convert pci rom to memory API Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 58/86] pci: remove pci_register_bar() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 59/86] pci: fold BAR mapping function into its caller Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 60/86] pci: rename pci_register_bar_region() to pci_register_bar() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 61/86] pci: remove support for pre memory API BARs Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 62/86] Introduce QEMU_NEW() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 63/86] apb_pci: convert to memory API Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 64/86] apic: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 65/86] arm_gic: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 66/86] arm_sysctl: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 67/86] arm_timer: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 68/86] armv7m: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 69/86] gt64xxx.c: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 70/86] tusb6010: move declarations to new file tusb6010.h Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 71/86] omap_gpmc/nseries/tusb6010: convert to memory API Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 72/86] onenand: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 73/86] pcie_host: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 74/86] ppc405_uc: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 75/86] ppc4xx_sdram: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 76/86] stellaris_enet: " Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 77/86] sysbus: add a variant of sysbus_init_mmio_cb with an unmap callback Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 78/86] sh_pci: convert to memory API Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 79/86] arm11mpcore: use sysbus_init_mmio_cb2 Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 80/86] versatile_pci: convert to memory API Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 81/86] ppce500_pci: convert to sysbus_init_mmio_cb2() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 82/86] sysbus: remove sysbus_init_mmio_cb() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 83/86] isa: add isa_address_space() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 84/86] pci: add pci_address_space() Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 85/86] vga: drop get_system_memory() from vga devices and derivatives Avi Kivity
2011-07-20 16:50 ` [Qemu-devel] [RFC v5 86/86] 440fx: fix PAM, PCI holes Avi Kivity
2011-07-25 13:07 ` Anthony Liguori
2011-07-25 13:14 ` Avi Kivity
2011-07-25 13:17 ` Gleb Natapov
2011-07-25 13:28 ` Avi Kivity
2011-07-25 13:31 ` Gleb Natapov
2011-07-25 13:31 ` Avi Kivity
2011-07-25 13:35 ` Gleb Natapov
2011-07-25 13:38 ` Avi Kivity
2011-07-25 13:47 ` Anthony Liguori
2011-07-25 13:50 ` Gleb Natapov
2011-07-25 14:05 ` Avi Kivity
2011-07-25 14:08 ` Anthony Liguori
2011-07-25 14:10 ` Avi Kivity
2011-07-25 13:32 ` Anthony Liguori
2011-07-25 21:34 ` Eric Northup
2011-07-26 8:01 ` Avi Kivity
2011-07-20 17:41 ` [Qemu-devel] [RFC v5 00/86] Memory API Jan Kiszka
2011-07-20 17:43 ` Avi Kivity
2011-07-20 21:43 ` Jan Kiszka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1311180636-17012-43-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).