From: Avi Kivity <avi@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>, qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH 19/39] ivshmem: convert to memory API
Date: Sun, 31 Jul 2011 20:57:42 +0300 [thread overview]
Message-ID: <1312135082-31985-20-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1312135082-31985-1-git-send-email-avi@redhat.com>
excluding msix.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
hw/ivshmem.c | 148 ++++++++++++++++++++--------------------------------------
1 files changed, 50 insertions(+), 98 deletions(-)
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 3055dd2..f80e7b6 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -56,11 +56,15 @@ typedef struct IVShmemState {
CharDriverState **eventfd_chr;
CharDriverState *server_chr;
- int ivshmem_mmio_io_addr;
+ MemoryRegion ivshmem_mmio;
pcibus_t mmio_addr;
- pcibus_t shm_pci_addr;
- uint64_t ivshmem_offset;
+ /* We might need to register the BAR before we actually have the memory.
+ * So prepare a container MemoryRegion for the BAR immediately and
+ * add a subregion when we have the memory.
+ */
+ MemoryRegion bar;
+ MemoryRegion ivshmem;
uint64_t ivshmem_size; /* size of shared memory region */
int shm_fd; /* shared memory file descriptor */
@@ -96,23 +100,6 @@ static inline bool is_power_of_two(uint64_t x) {
return (x & (x - 1)) == 0;
}
-static void ivshmem_map(PCIDevice *pci_dev, int region_num,
- pcibus_t addr, pcibus_t size, int type)
-{
- IVShmemState *s = DO_UPCAST(IVShmemState, dev, pci_dev);
-
- s->shm_pci_addr = addr;
-
- if (s->ivshmem_offset > 0) {
- cpu_register_physical_memory(s->shm_pci_addr, s->ivshmem_size,
- s->ivshmem_offset);
- }
-
- IVSHMEM_DPRINTF("guest pci addr = %" FMT_PCIBUS ", guest h/w addr = %"
- PRIu64 ", size = %" FMT_PCIBUS "\n", addr, s->ivshmem_offset, size);
-
-}
-
/* accessing registers - based on rtl8139 */
static void ivshmem_update_irq(IVShmemState *s, int val)
{
@@ -168,15 +155,8 @@ static uint32_t ivshmem_IntrStatus_read(IVShmemState *s)
return ret;
}
-static void ivshmem_io_writew(void *opaque, target_phys_addr_t addr,
- uint32_t val)
-{
-
- IVSHMEM_DPRINTF("We shouldn't be writing words\n");
-}
-
-static void ivshmem_io_writel(void *opaque, target_phys_addr_t addr,
- uint32_t val)
+static void ivshmem_io_write(void *opaque, target_phys_addr_t addr,
+ uint64_t val, unsigned size)
{
IVShmemState *s = opaque;
@@ -219,20 +199,8 @@ static void ivshmem_io_writel(void *opaque, target_phys_addr_t addr,
}
}
-static void ivshmem_io_writeb(void *opaque, target_phys_addr_t addr,
- uint32_t val)
-{
- IVSHMEM_DPRINTF("We shouldn't be writing bytes\n");
-}
-
-static uint32_t ivshmem_io_readw(void *opaque, target_phys_addr_t addr)
-{
-
- IVSHMEM_DPRINTF("We shouldn't be reading words\n");
- return 0;
-}
-
-static uint32_t ivshmem_io_readl(void *opaque, target_phys_addr_t addr)
+static uint64_t ivshmem_io_read(void *opaque, target_phys_addr_t addr,
+ unsigned size)
{
IVShmemState *s = opaque;
@@ -265,23 +233,14 @@ static uint32_t ivshmem_io_readl(void *opaque, target_phys_addr_t addr)
return ret;
}
-static uint32_t ivshmem_io_readb(void *opaque, target_phys_addr_t addr)
-{
- IVSHMEM_DPRINTF("We shouldn't be reading bytes\n");
-
- return 0;
-}
-
-static CPUReadMemoryFunc * const ivshmem_mmio_read[3] = {
- ivshmem_io_readb,
- ivshmem_io_readw,
- ivshmem_io_readl,
-};
-
-static CPUWriteMemoryFunc * const ivshmem_mmio_write[3] = {
- ivshmem_io_writeb,
- ivshmem_io_writew,
- ivshmem_io_writel,
+static const MemoryRegionOps ivshmem_mmio_ops = {
+ .read = ivshmem_io_read,
+ .write = ivshmem_io_write,
+ .endianness = DEVICE_NATIVE_ENDIAN,
+ .impl = {
+ .min_access_size = 4,
+ .max_access_size = 4,
+ },
};
static void ivshmem_receive(void *opaque, const uint8_t *buf, int size)
@@ -371,12 +330,12 @@ static void create_shared_memory_BAR(IVShmemState *s, int fd) {
ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
- s->ivshmem_offset = qemu_ram_alloc_from_ptr(&s->dev.qdev, "ivshmem.bar2",
- s->ivshmem_size, ptr);
+ memory_region_init_ram_ptr(&s->ivshmem, &s->dev.qdev, "ivshmem.bar2",
+ s->ivshmem_size, ptr);
+ memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
/* region for shared memory */
- pci_register_bar(&s->dev, 2, s->ivshmem_size,
- PCI_BASE_ADDRESS_SPACE_MEMORY, ivshmem_map);
+ pci_register_bar_region(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar);
}
static void close_guest_eventfds(IVShmemState *s, int posn)
@@ -401,8 +360,12 @@ static void setup_ioeventfds(IVShmemState *s) {
for (i = 0; i <= s->max_peer; i++) {
for (j = 0; j < s->peers[i].nb_eventfds; j++) {
- kvm_set_ioeventfd_mmio_long(s->peers[i].eventfds[j],
- s->mmio_addr + DOORBELL, (i << 16) | j, 1);
+ memory_region_add_eventfd(&s->ivshmem_mmio,
+ DOORBELL,
+ 4,
+ true,
+ (i << 16) | j,
+ s->peers[i].eventfds[j]);
}
}
}
@@ -483,18 +446,13 @@ static void ivshmem_read(void *opaque, const uint8_t * buf, int flags)
/* mmap the region and map into the BAR2 */
map_ptr = mmap(0, s->ivshmem_size, PROT_READ|PROT_WRITE, MAP_SHARED,
incoming_fd, 0);
- s->ivshmem_offset = qemu_ram_alloc_from_ptr(&s->dev.qdev,
- "ivshmem.bar2", s->ivshmem_size, map_ptr);
+ memory_region_init_ram_ptr(&s->ivshmem, &s->dev.qdev,
+ "ivshmem.bar2", s->ivshmem_size, map_ptr);
- IVSHMEM_DPRINTF("guest pci addr = %" FMT_PCIBUS ", guest h/w addr = %"
- PRIu64 ", size = %" PRIu64 "\n", s->shm_pci_addr,
+ IVSHMEM_DPRINTF("guest h/w addr = %" PRIu64 ", size = %" PRIu64 "\n",
s->ivshmem_offset, s->ivshmem_size);
- if (s->shm_pci_addr > 0) {
- /* map memory into BAR2 */
- cpu_register_physical_memory(s->shm_pci_addr, s->ivshmem_size,
- s->ivshmem_offset);
- }
+ memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
/* only store the fd if it is successfully mapped */
s->shm_fd = incoming_fd;
@@ -549,20 +507,6 @@ static void ivshmem_reset(DeviceState *d)
return;
}
-static void ivshmem_mmio_map(PCIDevice *pci_dev, int region_num,
- pcibus_t addr, pcibus_t size, int type)
-{
- IVShmemState *s = DO_UPCAST(IVShmemState, dev, pci_dev);
-
- s->mmio_addr = addr;
- cpu_register_physical_memory(addr + 0, IVSHMEM_REG_BAR_SIZE,
- s->ivshmem_mmio_io_addr);
-
- if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
- setup_ioeventfds(s);
- }
-}
-
static uint64_t ivshmem_get_size(IVShmemState * s) {
uint64_t value;
@@ -710,15 +654,20 @@ static int pci_ivshmem_init(PCIDevice *dev)
pci_config_set_interrupt_pin(pci_conf, 1);
- s->shm_pci_addr = 0;
- s->ivshmem_offset = 0;
s->shm_fd = 0;
- s->ivshmem_mmio_io_addr = cpu_register_io_memory(ivshmem_mmio_read,
- ivshmem_mmio_write, s, DEVICE_NATIVE_ENDIAN);
+ memory_region_init_io(&s->ivshmem_mmio, &ivshmem_mmio_ops, s,
+ "ivshmem-mmio", IVSHMEM_REG_BAR_SIZE);
+
+ if (ivshmem_has_feature(s, IVSHMEM_IOEVENTFD)) {
+ setup_ioeventfds(s);
+ }
+
/* region for registers*/
- pci_register_bar(&s->dev, 0, IVSHMEM_REG_BAR_SIZE,
- PCI_BASE_ADDRESS_SPACE_MEMORY, ivshmem_mmio_map);
+ pci_register_bar_region(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY,
+ &s->ivshmem_mmio);
+
+ memory_region_init(&s->bar, "ivshmem-bar2-container", s->ivshmem_size);
if ((s->server_chr != NULL) &&
(strncmp(s->server_chr->filename, "unix:", 5) == 0)) {
@@ -744,8 +693,8 @@ static int pci_ivshmem_init(PCIDevice *dev)
/* allocate/initialize space for interrupt handling */
s->peers = qemu_mallocz(s->nb_peers * sizeof(Peer));
- pci_register_bar(&s->dev, 2, s->ivshmem_size,
- PCI_BASE_ADDRESS_SPACE_MEMORY, ivshmem_map);
+ pci_register_bar_region(&s->dev, 2,
+ PCI_BASE_ADDRESS_SPACE_MEMORY, &s->ivshmem);
s->eventfd_chr = qemu_mallocz(s->vectors * sizeof(CharDriverState *));
@@ -792,7 +741,10 @@ static int pci_ivshmem_uninit(PCIDevice *dev)
{
IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
- cpu_unregister_io_memory(s->ivshmem_mmio_io_addr);
+ memory_region_destroy(&s->ivshmem_mmio);
+ memory_region_del_subregion(&s->bar, &s->ivshmem);
+ memory_region_destroy(&s->ivshmem);
+ memory_region_destroy(&s->bar);
unregister_savevm(&dev->qdev, "ivshmem", s);
return 0;
--
1.7.5.3
next prev parent reply other threads:[~2011-07-31 17:58 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-31 17:57 [Qemu-devel] [PATCH 00/39] Memory API, batch 2: PCI devices Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 01/39] pci: add API to get a BAR's mapped address Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 02/39] vmsvga: don't remember pci BAR address in callback any more Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 03/39] vga: convert vga and its derivatives to the memory API Avi Kivity
2011-07-31 18:42 ` Jan Kiszka
2011-07-31 18:46 ` Avi Kivity
2011-07-31 18:48 ` Jan Kiszka
2011-07-31 19:06 ` Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 04/39] cirrus: simplify mmio BAR access functions Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 05/39] cirrus: simplify bitblt " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 06/39] cirrus: simplify vga window mmio " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 07/39] vga: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 08/39] cirrus: simplify linear framebuffer " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 09/39] Integrate I/O memory regions into qemu Avi Kivity
2011-08-01 0:19 ` Richard Henderson
2011-08-01 6:05 ` Avi Kivity
2011-08-01 7:42 ` [Qemu-devel] [PATCH v2 " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 10/39] exec.c: fix initialization of system I/O memory region Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 11/39] pci: pass I/O address space to new PCI bus Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 12/39] pci: allow I/O BARs to be registered with pci_register_bar_region() Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 13/39] rtl8139: convert to memory API Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 14/39] ac97: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 15/39] e1000: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 16/39] eepro100: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 17/39] es1370: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 18/39] ide: " Avi Kivity
2011-08-01 19:22 ` Richard Henderson
2011-08-02 12:48 ` Avi Kivity
2011-07-31 17:57 ` Avi Kivity [this message]
2011-07-31 17:57 ` [Qemu-devel] [PATCH 20/39] virtio-pci: " Avi Kivity
2011-08-01 8:26 ` Michael S. Tsirkin
2011-08-01 9:35 ` Avi Kivity
2011-08-01 10:23 ` Michael S. Tsirkin
2011-08-01 20:24 ` Anthony Liguori
2011-08-03 15:16 ` Michael S. Tsirkin
2011-08-03 15:23 ` Avi Kivity
2011-08-03 15:38 ` Michael S. Tsirkin
2011-08-01 19:53 ` Michael S. Tsirkin
2011-08-02 9:17 ` Avi Kivity
2011-08-02 9:34 ` Michael S. Tsirkin
2011-08-02 12:39 ` Avi Kivity
2011-08-02 16:28 ` Gerd Hoffmann
2011-08-01 20:23 ` Anthony Liguori
2011-07-31 17:57 ` [Qemu-devel] [PATCH 21/39] ahci: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 22/39] intel-hda: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 23/39] lsi53c895a: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 24/39] ppc: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 25/39] ne2000: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 26/39] pcnet: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 27/39] i6300esb: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 28/39] isa-mmio: concert " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 29/39] sun4u: convert " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 30/39] ehci: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 31/39] uhci: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 32/39] xen-platform: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 33/39] msix: " Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 34/39] pci: remove pci_register_bar_simple() Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 35/39] pci: convert pci rom to memory API Avi Kivity
2011-07-31 17:57 ` [Qemu-devel] [PATCH 36/39] pci: remove pci_register_bar() Avi Kivity
2011-07-31 17:58 ` [Qemu-devel] [PATCH 37/39] pci: fold BAR mapping function into its caller Avi Kivity
2011-07-31 17:58 ` [Qemu-devel] [PATCH 38/39] pci: rename pci_register_bar_region() to pci_register_bar() Avi Kivity
2011-07-31 17:58 ` [Qemu-devel] [PATCH 39/39] pci: remove support for pre memory API BARs Avi Kivity
2011-07-31 18:02 ` [Qemu-devel] [PATCH 00/39] Memory API, batch 2: PCI devices Avi Kivity
2011-07-31 21:03 ` Anthony Liguori
2011-08-01 17:32 ` Richard Henderson
2011-08-01 21:23 ` [Qemu-devel] [RFC] Alpha system patchset updated for " Richard Henderson
2011-08-02 9:23 ` Avi Kivity
2011-08-02 15:42 ` Richard Henderson
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=1312135082-31985-20-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=anthony@codemonkey.ws \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--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).