qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>, qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH v2 31/38] xen-platform: convert to memory API
Date: Wed,  3 Aug 2011 14:56:01 +0300	[thread overview]
Message-ID: <1312372568-5215-32-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1312372568-5215-1-git-send-email-avi@redhat.com>

Since this device bypasses PCI and registers I/O ports directly with
the system bus, it needs further attention.

Reviewed-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 hw/xen_platform.c |   84 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/hw/xen_platform.c b/hw/xen_platform.c
index fb6be6a..239eefe 100644
--- a/hw/xen_platform.c
+++ b/hw/xen_platform.c
@@ -32,7 +32,6 @@
 #include "xen_common.h"
 #include "net.h"
 #include "xen_backend.h"
-#include "rwhandler.h"
 #include "trace.h"
 
 #include <xenguest.h>
@@ -51,6 +50,9 @@
 
 typedef struct PCIXenPlatformState {
     PCIDevice  pci_dev;
+    MemoryRegion fixed_io;
+    MemoryRegion bar;
+    MemoryRegion mmio_bar;
     uint8_t flags; /* used only for version_id == 2 */
     int drivers_blacklisted;
     uint16_t driver_product_version;
@@ -221,21 +223,34 @@ static void platform_fixed_ioport_reset(void *opaque)
     platform_fixed_ioport_writeb(s, XEN_PLATFORM_IOPORT, 0);
 }
 
+const MemoryRegionPortio xen_platform_ioport[] = {
+    { 0, 16, 4, .write = platform_fixed_ioport_writel, },
+    { 0, 16, 2, .write = platform_fixed_ioport_writew, },
+    { 0, 16, 1, .write = platform_fixed_ioport_writeb, },
+    { 0, 16, 2, .read = platform_fixed_ioport_readw, },
+    { 0, 16, 1, .read = platform_fixed_ioport_readb, },
+    PORTIO_END
+};
+
+static const MemoryRegionOps platform_fixed_io_ops = {
+    .old_portio = xen_platform_ioport,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+#include "exec-memory.h"
+
 static void platform_fixed_ioport_init(PCIXenPlatformState* s)
 {
-    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 4, platform_fixed_ioport_writel, s);
-    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 2, platform_fixed_ioport_writew, s);
-    register_ioport_write(XEN_PLATFORM_IOPORT, 16, 1, platform_fixed_ioport_writeb, s);
-    register_ioport_read(XEN_PLATFORM_IOPORT, 16, 2, platform_fixed_ioport_readw, s);
-    register_ioport_read(XEN_PLATFORM_IOPORT, 16, 1, platform_fixed_ioport_readb, s);
+    memory_region_init_io(&s->fixed_io, &platform_fixed_io_ops, s,
+                          "xen-fixed", 16);
+    memory_region_add_subregion(get_system_io(), XEN_PLATFORM_IOPORT,
+                                &s->fixed_io);
 }
 
 /* Xen Platform PCI Device */
 
 static uint32_t xen_platform_ioport_readb(void *opaque, uint32_t addr)
 {
-    addr &= 0xff;
-
     if (addr == 0) {
         return platform_fixed_ioport_readb(opaque, XEN_PLATFORM_IOPORT);
     } else {
@@ -247,9 +262,6 @@ static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val
 {
     PCIXenPlatformState *s = opaque;
 
-    addr &= 0xff;
-    val  &= 0xff;
-
     switch (addr) {
     case 0: /* Platform flags */
         platform_fixed_ioport_writeb(opaque, XEN_PLATFORM_IOPORT, val);
@@ -262,15 +274,23 @@ static void xen_platform_ioport_writeb(void *opaque, uint32_t addr, uint32_t val
     }
 }
 
-static void platform_ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, pcibus_t size, int type)
-{
-    PCIXenPlatformState *d = DO_UPCAST(PCIXenPlatformState, pci_dev, pci_dev);
+static MemoryRegionPortio xen_pci_portio[] = {
+    { 0, 0x100, 1, .read = xen_platform_ioport_readb, },
+    { 0, 0x100, 1, .write = xen_platform_ioport_writeb, },
+    PORTIO_END
+};
+
+static const MemoryRegionOps xen_pci_io_ops = {
+    .old_portio = xen_pci_portio,
+};
 
-    register_ioport_write(addr, size, 1, xen_platform_ioport_writeb, d);
-    register_ioport_read(addr, size, 1, xen_platform_ioport_readb, d);
+static void platform_ioport_bar_setup(PCIXenPlatformState *d)
+{
+    memory_region_init_io(&d->bar, &xen_pci_io_ops, d, "xen-pci", 0x100);
 }
 
-static uint32_t platform_mmio_read(ReadWriteHandler *handler, pcibus_t addr, int len)
+static uint64_t platform_mmio_read(void *opaque, target_phys_addr_t addr,
+                                   unsigned size)
 {
     DPRINTF("Warning: attempted read from physical address "
             "0x" TARGET_FMT_plx " in xen platform mmio space\n", addr);
@@ -278,28 +298,24 @@ static uint32_t platform_mmio_read(ReadWriteHandler *handler, pcibus_t addr, int
     return 0;
 }
 
-static void platform_mmio_write(ReadWriteHandler *handler, pcibus_t addr,
-                                uint32_t val, int len)
+static void platform_mmio_write(void *opaque, target_phys_addr_t addr,
+                                uint64_t val, unsigned size)
 {
-    DPRINTF("Warning: attempted write of 0x%x to physical "
+    DPRINTF("Warning: attempted write of 0x%"PRIx64" to physical "
             "address 0x" TARGET_FMT_plx " in xen platform mmio space\n",
             val, addr);
 }
 
-static ReadWriteHandler platform_mmio_handler = {
+static const MemoryRegionOps platform_mmio_handler = {
     .read = &platform_mmio_read,
     .write = &platform_mmio_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
-static void platform_mmio_map(PCIDevice *d, int region_num,
-                              pcibus_t addr, pcibus_t size, int type)
+static void platform_mmio_setup(PCIXenPlatformState *d)
 {
-    int mmio_io_addr;
-
-    mmio_io_addr = cpu_register_io_memory_simple(&platform_mmio_handler,
-                                                 DEVICE_NATIVE_ENDIAN);
-
-    cpu_register_physical_memory(addr, size, mmio_io_addr);
+    memory_region_init_io(&d->mmio_bar, &platform_mmio_handler, d,
+                          "xen-mmio", 0x1000000);
 }
 
 static int xen_platform_post_load(void *opaque, int version_id)
@@ -337,12 +353,14 @@ static int xen_platform_initfn(PCIDevice *dev)
 
     pci_conf[PCI_INTERRUPT_PIN] = 1;
 
-    pci_register_bar(&d->pci_dev, 0, 0x100,
-            PCI_BASE_ADDRESS_SPACE_IO, platform_ioport_map);
+    platform_ioport_bar_setup(d);
+    pci_register_bar_region(&d->pci_dev, 0,
+                            PCI_BASE_ADDRESS_SPACE_IO, &d->bar);
 
     /* reserve 16MB mmio address for share memory*/
-    pci_register_bar(&d->pci_dev, 1, 0x1000000,
-            PCI_BASE_ADDRESS_MEM_PREFETCH, platform_mmio_map);
+    platform_mmio_setup(d);
+    pci_register_bar_region(&d->pci_dev, 1,
+                            PCI_BASE_ADDRESS_MEM_PREFETCH, &d->mmio_bar);
 
     platform_fixed_ioport_init(d);
 
-- 
1.7.5.3

  parent reply	other threads:[~2011-08-03 11:56 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-03 11:55 [Qemu-devel] [PATCH v2 00/38] Memory API, batch 2: PCI devices Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 01/38] pci: add API to get a BAR's mapped address Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 02/38] vmsvga: don't remember pci BAR address in callback any more Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 03/38] vga: convert vga and its derivatives to the memory API Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 04/38] cirrus: simplify mmio BAR access functions Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 05/38] cirrus: simplify bitblt " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 06/38] cirrus: simplify vga window mmio " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 07/38] vga: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 08/38] cirrus: simplify linear framebuffer " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 09/38] Integrate I/O memory regions into qemu Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 10/38] pci: pass I/O address space to new PCI bus Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 11/38] pci: allow I/O BARs to be registered with pci_register_bar_region() Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 12/38] rtl8139: convert to memory API Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 13/38] ac97: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 14/38] e1000: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 15/38] eepro100: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 16/38] es1370: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 17/38] ide: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 18/38] ivshmem: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 19/38] virtio-pci: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 20/38] ahci: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 21/38] intel-hda: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 22/38] lsi53c895a: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 23/38] ppc: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 24/38] ne2000: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 25/38] pcnet: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 26/38] i6300esb: " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 27/38] isa-mmio: concert " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 28/38] sun4u: convert " Avi Kivity
2011-08-03 11:55 ` [Qemu-devel] [PATCH v2 29/38] ehci: " Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 30/38] uhci: " Avi Kivity
2011-08-03 11:56 ` Avi Kivity [this message]
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 32/38] msix: " Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 33/38] pci: remove pci_register_bar_simple() Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 34/38] pci: convert pci rom to memory API Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 35/38] pci: remove pci_register_bar() Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 36/38] pci: fold BAR mapping function into its caller Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 37/38] pci: rename pci_register_bar_region() to pci_register_bar() Avi Kivity
2011-08-03 11:56 ` [Qemu-devel] [PATCH v2 38/38] pci: remove support for pre memory API BARs Avi Kivity

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=1312372568-5215-32-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).