Patchwork [v1,4/7] sysbus/sysbus_mmio_map: parameterise mapped region

login
register
mail settings
Submitter Peter Crosthwaite
Date Oct. 19, 2012, 6:40 a.m.
Message ID <ab7ffb2f80ecae0e28215f0bde0680769616ee08.1350619775.git.peter.crosthwaite@xilinx.com>
Download mbox | patch
Permalink /patch/192573/
State New
Headers show

Comments

Peter Crosthwaite - Oct. 19, 2012, 6:40 a.m.
Add a variant to sysbus_mmio_map that allow specifying a target memory region.
The requested device memory region is mapped within the argument target memory
region rather than the default (get_system_memory()). Behaviour of original
sysbus_mmio_map remains unchanged.

The will probably go away or morph into something else with Anthony sysbus purge
so its intended to be a bridging patch until those refactorings go live.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
---

 hw/sysbus.c |   11 ++++++++---
 hw/sysbus.h |    2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)
Peter Maydell - Oct. 19, 2012, 8:06 a.m.
On 19 October 2012 07:40, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> Add a variant to sysbus_mmio_map that allow specifying a target memory region.
> The requested device memory region is mapped within the argument target memory
> region rather than the default (get_system_memory()). Behaviour of original
> sysbus_mmio_map remains unchanged.

If you want to take a sysbus device and map one of its mmio regions into
something other than the system memory space, the usual approach is to
use sysbus_mmio_get_region() to get the MemoryRegion* and then you can
do what you want with it.

-- PMM
Peter Crosthwaite - Oct. 19, 2012, 9:01 a.m.
On Fri, Oct 19, 2012 at 6:06 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 19 October 2012 07:40, Peter Crosthwaite
> <peter.crosthwaite@xilinx.com> wrote:
>> Add a variant to sysbus_mmio_map that allow specifying a target memory region.
>> The requested device memory region is mapped within the argument target memory
>> region rather than the default (get_system_memory()). Behaviour of original
>> sysbus_mmio_map remains unchanged.
>
> If you want to take a sysbus device and map one of its mmio regions into
> something other than the system memory space, the usual approach is to
> use sysbus_mmio_get_region() to get the MemoryRegion* and then you can
> do what you want with it.
>

Fixed in v2. This patch will be removed from the series.

Regards,
Peter

> -- PMM
>

Patch

diff --git a/hw/sysbus.c b/hw/sysbus.c
index c173840..bd45183 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -48,7 +48,8 @@  void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
     }
 }
 
-void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
+void sysbus_mmio_map_to_region(SysBusDevice *dev, int n,
+                               target_phys_addr_t addr, MemoryRegion *region)
 {
     assert(n >= 0 && n < dev->num_mmio);
 
@@ -58,14 +59,18 @@  void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
     }
     if (dev->mmio[n].addr != (target_phys_addr_t)-1) {
         /* Unregister previous mapping.  */
-        memory_region_del_subregion(get_system_memory(), dev->mmio[n].memory);
+        memory_region_del_subregion(region, dev->mmio[n].memory);
     }
     dev->mmio[n].addr = addr;
-    memory_region_add_subregion(get_system_memory(),
+    memory_region_add_subregion(region,
                                 addr,
                                 dev->mmio[n].memory);
 }
 
+void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr)
+{
+    sysbus_mmio_map_to_region(dev, n, addr, get_system_memory());
+}
 
 /* Request an IRQ source.  The actual IRQ object may be populated later.  */
 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p)
diff --git a/hw/sysbus.h b/hw/sysbus.h
index acfbcfb..9cdb2b4 100644
--- a/hw/sysbus.h
+++ b/hw/sysbus.h
@@ -56,6 +56,8 @@  void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);
 
 
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
+void sysbus_mmio_map_to_region(SysBusDevice *dev, int n,
+                               target_phys_addr_t addr, MemoryRegion *region);
 void sysbus_mmio_map(SysBusDevice *dev, int n, target_phys_addr_t addr);
 void sysbus_add_memory(SysBusDevice *dev, target_phys_addr_t addr,
                        MemoryRegion *mem);