diff mbox

[RFC,v2,6/8] hw: platform-bus: enable to map any memory region onto the platform-bus

Message ID 1454086429-4373-7-git-send-email-eric.auger@linaro.org
State New
Headers show

Commit Message

Auger Eric Jan. 29, 2016, 4:53 p.m. UTC
The platform bus currently is used to map dynamically instantiable
platform device MMIO regions. The platform bus also can be seen as a
pool of free guest physical addresses. We would like to use that pool
to allocate a contiguous reserved IOVA region usable for MSI message
address IOMMU mapping.

This patch introduces platform_bus_map_region which enables to map any
memory region onto the platform bus.

Signed-off-by: Eric Auger <eric.auger@linaro.org>

---
 hw/core/platform-bus.c    | 26 ++++++++++++++++----------
 include/hw/platform-bus.h |  7 +++++++
 2 files changed, 23 insertions(+), 10 deletions(-)

-- 
1.9.1

Comments

Peter Maydell Feb. 16, 2016, 6:16 p.m. UTC | #1
On 29 January 2016 at 16:53, Eric Auger <eric.auger@linaro.org> wrote:
> The platform bus currently is used to map dynamically instantiable

> platform device MMIO regions. The platform bus also can be seen as a

> pool of free guest physical addresses. We would like to use that pool

> to allocate a contiguous reserved IOVA region usable for MSI message

> address IOMMU mapping.

>

> This patch introduces platform_bus_map_region which enables to map any

> memory region onto the platform bus.

>

> Signed-off-by: Eric Auger <eric.auger@linaro.org>

> ---

>  hw/core/platform-bus.c    | 26 ++++++++++++++++----------

>  include/hw/platform-bus.h |  7 +++++++

>  2 files changed, 23 insertions(+), 10 deletions(-)

>

> diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c

> index aa55d01..7d0f5e0 100644

> --- a/hw/core/platform-bus.c

> +++ b/hw/core/platform-bus.c

> @@ -128,16 +128,14 @@ static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,

>      sysbus_connect_irq(sbdev, n, pbus->irqs[irqn]);

>  }

>

> -static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,

> -                                  int n)

> +void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr)

>  {

> -    MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n);

> -    uint64_t size = memory_region_size(sbdev_mr);

> +    uint64_t size = memory_region_size(mr);

>      uint64_t alignment = (1ULL << (63 - clz64(size + size - 1)));

>      uint64_t off;

>      bool found_region = false;

>

> -    if (memory_region_is_mapped(sbdev_mr)) {

> +    if (memory_region_is_mapped(mr)) {

>          /* Region is already mapped, nothing to do */

>          return;

>      }

> @@ -154,13 +152,21 @@ static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,

>      }

>

>      if (!found_region) {

> -        error_report("Platform Bus: Can not fit MMIO region of size %"PRIx64,

> -                     size);

> -        exit(1);

> +        error_setg(&error_fatal,

> +                   "Platform Bus: Can not fit region %s of size %"PRIx64,

> +                   mr->name, size);

>      }

>

> -    /* Map the device's region into our Platform Bus MMIO space */

> -    memory_region_add_subregion(&pbus->mmio, off, sbdev_mr);

> +    /* Map the region into our Platform Bus MMIO space */

> +    memory_region_add_subregion(&pbus->mmio, off, mr);

> +}

> +

> +static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,

> +                                  int n)

> +{

> +    MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n);

> +

> +    platform_bus_map_region(pbus, sbdev_mr);

>  }

>

>  /*

> diff --git a/include/hw/platform-bus.h b/include/hw/platform-bus.h

> index bd42b83..ee19674 100644

> --- a/include/hw/platform-bus.h

> +++ b/include/hw/platform-bus.h

> @@ -54,4 +54,11 @@ int platform_bus_get_irqn(PlatformBusDevice *platform_bus, SysBusDevice *sbdev,

>  hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus, SysBusDevice *sbdev,

>                                    int n);

>

> +/**

> + * platform_bus_map_region: map a region into the platform bus


s/region/MemoryRegion/

> + * @pbus: platform bus handle

> + * @mr: memory region handle

> + */

> +void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr);

> +

>  #endif /* !HW_PLATFORM_BUS_H */

> --

> 1.9.1


otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>


thanks
-- PMM
diff mbox

Patch

diff --git a/hw/core/platform-bus.c b/hw/core/platform-bus.c
index aa55d01..7d0f5e0 100644
--- a/hw/core/platform-bus.c
+++ b/hw/core/platform-bus.c
@@ -128,16 +128,14 @@  static void platform_bus_map_irq(PlatformBusDevice *pbus, SysBusDevice *sbdev,
     sysbus_connect_irq(sbdev, n, pbus->irqs[irqn]);
 }
 
-static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
-                                  int n)
+void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr)
 {
-    MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n);
-    uint64_t size = memory_region_size(sbdev_mr);
+    uint64_t size = memory_region_size(mr);
     uint64_t alignment = (1ULL << (63 - clz64(size + size - 1)));
     uint64_t off;
     bool found_region = false;
 
-    if (memory_region_is_mapped(sbdev_mr)) {
+    if (memory_region_is_mapped(mr)) {
         /* Region is already mapped, nothing to do */
         return;
     }
@@ -154,13 +152,21 @@  static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
     }
 
     if (!found_region) {
-        error_report("Platform Bus: Can not fit MMIO region of size %"PRIx64,
-                     size);
-        exit(1);
+        error_setg(&error_fatal,
+                   "Platform Bus: Can not fit region %s of size %"PRIx64,
+                   mr->name, size);
     }
 
-    /* Map the device's region into our Platform Bus MMIO space */
-    memory_region_add_subregion(&pbus->mmio, off, sbdev_mr);
+    /* Map the region into our Platform Bus MMIO space */
+    memory_region_add_subregion(&pbus->mmio, off, mr);
+}
+
+static void platform_bus_map_mmio(PlatformBusDevice *pbus, SysBusDevice *sbdev,
+                                  int n)
+{
+    MemoryRegion *sbdev_mr = sysbus_mmio_get_region(sbdev, n);
+
+    platform_bus_map_region(pbus, sbdev_mr);
 }
 
 /*
diff --git a/include/hw/platform-bus.h b/include/hw/platform-bus.h
index bd42b83..ee19674 100644
--- a/include/hw/platform-bus.h
+++ b/include/hw/platform-bus.h
@@ -54,4 +54,11 @@  int platform_bus_get_irqn(PlatformBusDevice *platform_bus, SysBusDevice *sbdev,
 hwaddr platform_bus_get_mmio_addr(PlatformBusDevice *pbus, SysBusDevice *sbdev,
                                   int n);
 
+/**
+ * platform_bus_map_region: map a region into the platform bus
+ * @pbus: platform bus handle
+ * @mr: memory region handle
+ */
+void platform_bus_map_region(PlatformBusDevice *pbus, MemoryRegion *mr);
+
 #endif /* !HW_PLATFORM_BUS_H */