[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 06/10] hw/arm/bcm2836: Create VideoCore address space in the S
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 06/10] hw/arm/bcm2836: Create VideoCore address space in the SoC |
Date: |
Fri, 18 Oct 2019 00:57:56 +0200 |
Currently the VideoCore is created in the Peripheral container
as the 'GPU bus'. It is created there because the peripherals
using DMA use physical addresses from the VideoCore bus.
However the VideoCore is a GPU core placed at the same
hierarchical level than the ARM cores.
To match the datasheet design, create the VideoCore container
in the SoC, and link it to the peripheral container.
The VideoCore bus is 1GiB wide, accessible at 4 regions in
different cache configurations. Add the full mapping.
Before this commit the memory tree is:
(qemu) info mtree
address-space: bcm2835-dma-memory
0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu
0000000000000000-000000003fffffff (prio 0, i/o): alias
bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
0000000040000000-000000007fffffff (prio 0, i/o): alias
bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
000000007e000000-000000007effffff (prio 1, i/o): alias
bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff
0000000080000000-00000000bfffffff (prio 0, i/o): alias
bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
00000000c0000000-00000000ffffffff (prio 0, i/o): alias
bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff
After:
address-space: bcm2835-dma-memory
0000000000000000-000000003fffffff (prio 0, i/o): videocore-bus
0000000000000000-000000003fffffff (prio 1, i/o): alias vc-ram-alias @ram
0000000000000000-000000003fffffff
000000003e000000-000000003effffff (prio 2, i/o): alias
vc-peripherals-alias @bcm2835-peripherals 0000000000000000-0000000000ffffff
0000000040000000-000000007fffffff (prio 0, i/o): alias cached-coherent
@videocore-bus 0000000000000000-000000003fffffff
0000000080000000-00000000bfffffff (prio 0, i/o): alias cached
@videocore-bus 0000000000000000-000000003fffffff
00000000c0000000-00000000ffffffff (prio 0, i/o): alias uncached
@videocore-bus 0000000000000000-000000003fffffff
Now the periferals are accessible from the uncached region too.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/arm/bcm2835_peripherals.c | 45 +++++++++-------------------
hw/arm/bcm2836.c | 43 ++++++++++++++++++++++++--
include/hw/arm/bcm2835_peripherals.h | 4 +--
include/hw/arm/bcm2836.h | 5 ++++
4 files changed, 62 insertions(+), 35 deletions(-)
diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
index 17207ae07e..059e44a620 100644
--- a/hw/arm/bcm2835_peripherals.c
+++ b/hw/arm/bcm2835_peripherals.c
@@ -9,6 +9,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/units.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "hw/arm/bcm2835_peripherals.h"
@@ -16,9 +17,6 @@
#include "hw/arm/raspi_platform.h"
#include "sysemu/sysemu.h"
-/* Peripheral base address on the VC (GPU) system bus */
-#define BCM2835_VC_PERI_BASE 0x7e000000
-
/* Capabilities for SD controller: no DMA, high-speed, default clocks etc. */
#define BCM2835_SDHC_CAPAREG 0x52134b4
@@ -45,10 +43,6 @@ static void bcm2835_peripherals_init(Object *obj)
object_property_add_child(obj, "peripheral-io", OBJECT(&s->peri_mr), NULL);
sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_mr);
- /* Internal memory region for peripheral bus addresses (not exported) */
- memory_region_init(&s->gpu_bus_mr, obj, "bcm2835-gpu", (uint64_t)1 << 32);
- object_property_add_child(obj, "gpu-bus", OBJECT(&s->gpu_bus_mr), NULL);
-
/* Internal memory region for request/response communication with
* mailbox-addressable peripherals (not exported)
*/
@@ -82,9 +76,6 @@ static void bcm2835_peripherals_init(Object *obj)
object_property_add_alias(obj, "vcram-size", OBJECT(&s->fb), "vcram-size",
&error_abort);
- object_property_add_const_link(OBJECT(&s->fb), "dma-mr",
- OBJECT(&s->gpu_bus_mr), &error_abort);
-
/* Property channel */
sysbus_init_child_obj(obj, "property", &s->property, sizeof(s->property),
TYPE_BCM2835_PROPERTY);
@@ -93,8 +84,6 @@ static void bcm2835_peripherals_init(Object *obj)
object_property_add_const_link(OBJECT(&s->property), "fb",
OBJECT(&s->fb), &error_abort);
- object_property_add_const_link(OBJECT(&s->property), "dma-mr",
- OBJECT(&s->gpu_bus_mr), &error_abort);
/* Random Number Generator */
sysbus_init_child_obj(obj, "rng", &s->rng, sizeof(s->rng),
@@ -112,9 +101,6 @@ static void bcm2835_peripherals_init(Object *obj)
sysbus_init_child_obj(obj, "dma", &s->dma, sizeof(s->dma),
TYPE_BCM2835_DMA);
- object_property_add_const_link(OBJECT(&s->dma), "dma-mr",
- OBJECT(&s->gpu_bus_mr), &error_abort);
-
/* Thermal */
sysbus_init_child_obj(obj, "thermal", &s->thermal, sizeof(s->thermal),
TYPE_BCM2835_THERMAL);
@@ -133,7 +119,7 @@ static void bcm2835_peripherals_realize(DeviceState *dev,
Error **errp)
{
BCM2835PeripheralState *s = BCM2835_PERIPHERALS(dev);
Object *obj;
- MemoryRegion *ram;
+ MemoryRegion *ram, *vc;
Error *err = NULL;
uint64_t ram_size, vcram_size;
int n;
@@ -144,25 +130,16 @@ static void bcm2835_peripherals_realize(DeviceState *dev,
Error **errp)
__func__, error_get_pretty(err));
return;
}
-
ram = MEMORY_REGION(obj);
ram_size = memory_region_size(ram);
- /* Map peripherals and RAM into the GPU address space. */
- memory_region_init_alias(&s->peri_mr_alias, OBJECT(s),
- "bcm2835-peripherals", &s->peri_mr, 0,
- memory_region_size(&s->peri_mr));
-
- memory_region_add_subregion_overlap(&s->gpu_bus_mr, BCM2835_VC_PERI_BASE,
- &s->peri_mr_alias, 1);
-
- /* RAM is aliased four times (different cache configurations) on the GPU */
- for (n = 0; n < 4; n++) {
- memory_region_init_alias(&s->ram_alias[n], OBJECT(s),
- "bcm2835-gpu-ram-alias[*]", ram, 0, ram_size);
- memory_region_add_subregion_overlap(&s->gpu_bus_mr, (hwaddr)n << 30,
- &s->ram_alias[n], 0);
+ obj = object_property_get_link(OBJECT(dev), "videocore", &err);
+ if (obj == NULL) {
+ error_setg(errp, "%s: required videocore link not found: %s",
+ __func__, error_get_pretty(err));
+ return;
}
+ vc = MEMORY_REGION(obj);
/* Interrupt Controller */
object_property_set_bool(OBJECT(&s->ic), true, "realized", &err);
@@ -243,6 +220,8 @@ static void bcm2835_peripherals_realize(DeviceState *dev,
Error **errp)
return;
}
+ object_property_add_const_link(OBJECT(&s->fb), "dma-mr",
+ OBJECT(vc), &error_abort);
object_property_set_bool(OBJECT(&s->fb), true, "realized", &err);
if (err) {
error_propagate(errp, err);
@@ -255,6 +234,8 @@ static void bcm2835_peripherals_realize(DeviceState *dev,
Error **errp)
qdev_get_gpio_in(DEVICE(&s->mboxes), MBOX_CHAN_FB));
/* Property channel */
+ object_property_add_const_link(OBJECT(&s->property), "dma-mr",
+ OBJECT(vc), &error_abort);
object_property_set_bool(OBJECT(&s->property), true, "realized", &err);
if (err) {
error_propagate(errp, err);
@@ -323,6 +304,8 @@ static void bcm2835_peripherals_realize(DeviceState *dev,
Error **errp)
INTERRUPT_SDIO));
/* DMA Channels */
+ object_property_add_const_link(OBJECT(&s->dma), "dma-mr",
+ OBJECT(vc), &error_abort);
object_property_set_bool(OBJECT(&s->dma), true, "realized", &err);
if (err) {
error_propagate(errp, err);
diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 019e67b906..d712f36052 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -9,6 +9,7 @@
*/
#include "qemu/osdep.h"
+#include "qemu/units.h"
#include "qapi/error.h"
#include "qemu/module.h"
#include "cpu.h"
@@ -16,6 +17,9 @@
#include "hw/arm/raspi_platform.h"
#include "hw/sysbus.h"
+/* Peripheral base address on the VC (GPU) system bus */
+#define BCM2835_VC_PERI_BASE 0x3e000000
+
struct BCM283XInfo {
const char *name;
const char *cpu_type;
@@ -50,6 +54,21 @@ static void bcm2836_init(Object *obj)
const BCM283XInfo *info = bc->info;
int n;
+ /* VideoCore memory region */
+ memory_region_init(&s->videocore.mr[0], obj, "videocore-bus", 1 * GiB);
+ object_property_add_child(obj, "videocore",
+ OBJECT(&s->videocore.mr[0]), NULL);
+ for (n = 1; n < BCM283X_NCPUS; n++) {
+ static const char *alias_name[] = {
+ NULL, "cached-coherent", "cached", "uncached"
+ };
+ memory_region_init_alias(&s->videocore.mr[n], obj,
+ alias_name[n], &s->videocore.mr[0],
+ 0, 1 * GiB);
+ memory_region_add_subregion_overlap(&s->videocore.mr[0], n * GiB,
+ &s->videocore.mr[n], 0);
+ }
+
for (n = 0; n < BCM283X_NCPUS; n++) {
object_initialize_child(obj, "cpu[*]", &s->cpus[n], sizeof(s->cpus[n]),
info->cpu_type, &error_abort, NULL);
@@ -71,6 +90,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
BCM283XState *s = BCM283X(dev);
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
const BCM283XInfo *info = bc->info;
+ MemoryRegion *ram_mr, *peri_mr;
Object *obj;
Error *err = NULL;
int n;
@@ -83,26 +103,45 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
__func__, error_get_pretty(err));
return;
}
-
+ ram_mr = MEMORY_REGION(obj);
object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj, &err);
if (err) {
error_propagate(errp, err);
return;
}
+ object_property_add_const_link(OBJECT(&s->peripherals), "videocore",
+ OBJECT(&s->videocore), &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
object_property_set_bool(OBJECT(&s->peripherals), true, "realized", &err);
if (err) {
error_propagate(errp, err);
return;
}
+ /* Map peripherals and RAM into the GPU address space. */
+ memory_region_init_alias(&s->videocore.ram_mr_alias, OBJECT(s),
+ "vc-ram-alias", ram_mr, 0,
+ memory_region_size(ram_mr));
+ memory_region_add_subregion_overlap(&s->videocore.mr[0], 0,
+ &s->videocore.ram_mr_alias, 1);
+ peri_mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->peripherals), 0);
+ memory_region_init_alias(&s->videocore.peri_mr_alias, OBJECT(s),
+ "vc-peripherals-alias",
+ peri_mr, 0, 16 * MiB);
+ memory_region_add_subregion_overlap(&s->videocore.mr[0],
+ BCM2835_VC_PERI_BASE,
+ &s->videocore.peri_mr_alias, 2);
+
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
"sd-bus", &err);
if (err) {
error_propagate(errp, err);
return;
}
-
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
info->peri_base, 1);
diff --git a/include/hw/arm/bcm2835_peripherals.h
b/include/hw/arm/bcm2835_peripherals.h
index 7859281e11..f485f20aae 100644
--- a/include/hw/arm/bcm2835_peripherals.h
+++ b/include/hw/arm/bcm2835_peripherals.h
@@ -36,8 +36,8 @@ typedef struct BCM2835PeripheralState {
SysBusDevice parent_obj;
/*< public >*/
- MemoryRegion peri_mr, peri_mr_alias, gpu_bus_mr, mbox_mr;
- MemoryRegion ram_alias[4];
+ MemoryRegion peri_mr;
+ MemoryRegion mbox_mr;
qemu_irq irq, fiq;
BCM2835SystemTimerState systmr;
diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h
index 97187f72be..a26bf895a4 100644
--- a/include/hw/arm/bcm2836.h
+++ b/include/hw/arm/bcm2836.h
@@ -35,6 +35,11 @@ typedef struct BCM283XState {
char *cpu_type;
uint32_t enabled_cpus;
+ struct {
+ MemoryRegion mr[4];
+ MemoryRegion peri_mr_alias;
+ MemoryRegion ram_mr_alias;
+ } videocore;
ARMCPU cpus[BCM283X_NCPUS];
BCM2836ControlState control;
BCM2835PeripheralState peripherals;
--
2.21.0
- [PATCH v2 00/10] hw/arm/raspi: Add thermal/timer, improve multicore address space, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 01/10] hw/misc/bcm2835_thermal: Add a dummy BCM2835 thermal sensor, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 02/10] hw/arm/bcm2835_peripherals: Use the thermal sensor block, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 03/10] hw/timer/bcm2835: Add the BCM2835 SYS_timer, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 04/10] hw/arm/bcm2835_peripherals: Use the SYS_timer, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 05/10] hw/arm/bcm2836: Make the SoC code modular, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 06/10] hw/arm/bcm2836: Create VideoCore address space in the SoC,
Philippe Mathieu-Daudé <=
- [PATCH v2 08/10] hw/arm/raspi: Use AddressSpace when using arm_boot::write_secondary_boot, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 07/10] hw/arm/bcm2836: Use per CPU address spaces, Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 10/10] hw/arm/highbank: Use AddressSpace when using write_secondary_boot(), Philippe Mathieu-Daudé, 2019/10/17
- [PATCH v2 09/10] hw/arm/raspi: Make the board code modular, Philippe Mathieu-Daudé, 2019/10/17
- Re: [PATCH v2 00/10] hw/arm/raspi: Add thermal/timer, improve multicore address space, no-reply, 2019/10/18