Re: [PATCH v2 5/7] hw/arm/digic: Map flash using memory_region_add_subregion_aliased()

2021-04-21 Thread Richard Henderson

On 4/19/21 2:43 AM, Philippe Mathieu-Daudé wrote:

Instead of using a device specific feature for mapping the
flash memory multiple times over a wider region, use the
generic memory_region_add_subregion_aliased() helper.

There is no change in the memory layout.

* before:

   $ qemu-system-arm -M canon-a1100 -S -monitor stdio
   QEMU 5.2.90 monitor - type 'help' for more information
   (qemu) info mtree
   address-space: memory
 - (prio 0, i/o): system
   -03ff (prio 0, ram): ram
   c021-c02100ff (prio 0, i/o): digic-timer
   c0210100-c02101ff (prio 0, i/o): digic-timer
   c0210200-c02102ff (prio 0, i/o): digic-timer
   c080-c0800017 (prio 0, i/o): digic-uart
   f800- (prio 0, i/o): pflash
 f800-f83f (prio 0, romd): alias pflash-alias 
@pflash -003f
 f840-f87f (prio 0, romd): alias pflash-alias 
@pflash -003f
 f880-f8bf (prio 0, romd): alias pflash-alias 
@pflash -003f
 ...
 ff40-ff7f (prio 0, romd): alias pflash-alias 
@pflash -003f
 ff80-ffbf (prio 0, romd): alias pflash-alias 
@pflash -003f
 ffc0- (prio 0, romd): alias pflash-alias 
@pflash -003f

* after:

   (qemu) info mtree
   address-space: memory
 - (prio 0, i/o): system
   -03ff (prio 0, ram): ram
   c021-c02100ff (prio 0, i/o): digic-timer
   c0210100-c02101ff (prio 0, i/o): digic-timer
   c0210200-c02102ff (prio 0, i/o): digic-timer
   c080-c0800017 (prio 0, i/o): digic-uart
   f800- (prio 0, i/o): masked pflash [span of 
4 MiB]
 f800-f83f (prio 0, romd): alias pflash [#0/32] 
@pflash -003f
 f840-f87f (prio 0, romd): alias pflash [#1/32] 
@pflash -003f
 f880-f8bf (prio 0, romd): alias pflash [#2/32] 
@pflash -003f
 ...
 ff40-ff7f (prio 0, romd): alias pflash 
[#29/32] @pflash -003f
 ff80-ffbf (prio 0, romd): alias pflash 
[#30/32] @pflash -003f
 ffc0- (prio 0, romd): alias pflash 
[#31/32] @pflash -003f

Signed-off-by: Philippe Mathieu-Daudé 
---
  hw/arm/digic_boards.c | 8 +---
  hw/arm/Kconfig| 1 +
  2 files changed, 6 insertions(+), 3 deletions(-)


Reviewed-by: Richard Henderson 

r~



[PATCH v2 5/7] hw/arm/digic: Map flash using memory_region_add_subregion_aliased()

2021-04-19 Thread Philippe Mathieu-Daudé
Instead of using a device specific feature for mapping the
flash memory multiple times over a wider region, use the
generic memory_region_add_subregion_aliased() helper.

There is no change in the memory layout.

* before:

  $ qemu-system-arm -M canon-a1100 -S -monitor stdio
  QEMU 5.2.90 monitor - type 'help' for more information
  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -03ff (prio 0, ram): ram
  c021-c02100ff (prio 0, i/o): digic-timer
  c0210100-c02101ff (prio 0, i/o): digic-timer
  c0210200-c02102ff (prio 0, i/o): digic-timer
  c080-c0800017 (prio 0, i/o): digic-uart
  f800- (prio 0, i/o): pflash
f800-f83f (prio 0, romd): alias pflash-alias 
@pflash -003f
f840-f87f (prio 0, romd): alias pflash-alias 
@pflash -003f
f880-f8bf (prio 0, romd): alias pflash-alias 
@pflash -003f
...
ff40-ff7f (prio 0, romd): alias pflash-alias 
@pflash -003f
ff80-ffbf (prio 0, romd): alias pflash-alias 
@pflash -003f
ffc0- (prio 0, romd): alias pflash-alias 
@pflash -003f

* after:

  (qemu) info mtree
  address-space: memory
- (prio 0, i/o): system
  -03ff (prio 0, ram): ram
  c021-c02100ff (prio 0, i/o): digic-timer
  c0210100-c02101ff (prio 0, i/o): digic-timer
  c0210200-c02102ff (prio 0, i/o): digic-timer
  c080-c0800017 (prio 0, i/o): digic-uart
  f800- (prio 0, i/o): masked pflash [span of 4 
MiB]
f800-f83f (prio 0, romd): alias pflash [#0/32] 
@pflash -003f
f840-f87f (prio 0, romd): alias pflash [#1/32] 
@pflash -003f
f880-f8bf (prio 0, romd): alias pflash [#2/32] 
@pflash -003f
...
ff40-ff7f (prio 0, romd): alias pflash [#29/32] 
@pflash -003f
ff80-ffbf (prio 0, romd): alias pflash [#30/32] 
@pflash -003f
ffc0- (prio 0, romd): alias pflash [#31/32] 
@pflash -003f

Signed-off-by: Philippe Mathieu-Daudé 
---
 hw/arm/digic_boards.c | 8 +---
 hw/arm/Kconfig| 1 +
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/hw/arm/digic_boards.c b/hw/arm/digic_boards.c
index fc4a671b2e1..293402b1240 100644
--- a/hw/arm/digic_boards.c
+++ b/hw/arm/digic_boards.c
@@ -128,8 +128,7 @@ static void digic4_add_k8p3215uqb_rom(DigicState *s, hwaddr 
addr,
  FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE);
 qdev_prop_set_uint32(dev, "sector-length", FLASH_K8P3215UQB_SECTOR_SIZE);
 qdev_prop_set_uint8(dev, "width", 4); /* 32-bit */
-qdev_prop_set_uint8(dev, "mappings",
-DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE);
+qdev_prop_set_uint8(dev, "mappings", 0);
 qdev_prop_set_uint8(dev, "big-endian", 0);
 qdev_prop_set_uint16(dev, "id0", 0x00ec);
 qdev_prop_set_uint16(dev, "id1", 0x007e);
@@ -140,7 +139,10 @@ static void digic4_add_k8p3215uqb_rom(DigicState *s, 
hwaddr addr,
 qdev_prop_set_string(dev, "name", "pflash");
 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), _fatal);
 
-sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr);
+memory_region_add_subregion_aliased(get_system_memory(),
+addr, DIGIC4_ROM_MAX_SIZE,
+sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0),
+FLASH_K8P3215UQB_SIZE);
 
 digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, filename);
 }
diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig
index aa8553b3cd3..1a7b9724d6c 100644
--- a/hw/arm/Kconfig
+++ b/hw/arm/Kconfig
@@ -42,6 +42,7 @@ config DIGIC
 bool
 select PTIMER
 select PFLASH_CFI02
+select ALIASED_REGION
 
 config EXYNOS4
 bool
-- 
2.26.3