[RFC PATCH-for-6.1 00/10] hw/misc: Add memory_region_add_subregion_aliased() helper

Philippe Mathieu-Daudé posted 10 patches 3 years ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210326002728.1069834-1-f4bug@amsat.org
There is a newer version of this series
include/hw/block/flash.h         |   1 -
include/hw/misc/aliased_region.h |  91 +++++++++++++++
hw/arm/digic_boards.c            |  28 ++++-
hw/arm/musicpal.c                |  29 ++++-
hw/arm/xilinx_zynq.c             |   2 +-
hw/block/pflash_cfi02.c          |  36 +-----
hw/lm32/lm32_boards.c            |   4 +-
hw/m68k/q800.c                   |  61 +++++-----
hw/misc/aliased_region.c         | 185 +++++++++++++++++++++++++++++++
hw/ppc/ppc405_boards.c           |   6 +-
hw/sh4/r2d.c                     |   2 +-
MAINTAINERS                      |   6 +
hw/arm/Kconfig                   |   2 +
hw/m68k/Kconfig                  |   1 +
hw/misc/Kconfig                  |   3 +
hw/misc/meson.build              |   1 +
16 files changed, 375 insertions(+), 83 deletions(-)
create mode 100644 include/hw/misc/aliased_region.h
create mode 100644 hw/misc/aliased_region.c
[RFC PATCH-for-6.1 00/10] hw/misc: Add memory_region_add_subregion_aliased() helper
Posted by Philippe Mathieu-Daudé 3 years ago
Hi,

This series introduce the memory_region_add_subregion_aliased()
helper which basically create a device which maps a subregion
multiple times.

Examples are easier, so having a subregion aliased every @span_size
then mapped onto a container at an offset, you get something like:

          ^-----------^
          |           |
          |           |
          | +-------+ |                 +---------+          <--+
          |           |                 +---------+             |
          |           |                 |         |             |
          |           |   +-----------> | alias#3 |             |
          |           |   |             |         |             |
          |           |   |             +---------+             |
          |           |   |             +---------+             |
          |           |   |             |         |             |
          |           |   |   +-------> | alias#2 |             |
          |           |   |   |         |         |             |region
          | container |   |   |         +---------+             | size
          |           |   |   |         +---------+             |
          |           |   |   |         |         |             |
          |           |   |   |  +----> | alias#1 |             |
          |           |   |   |  |      |         |             |
          |           |   |   |  |      +---------+  <--+       |
          |           | +-+---+--+--+   +---------+     |       |
          |           | |           |   |         |     |span   |
          |           | | subregion +-> | alias#0 |     |size   |
   offset |           | |           |   |         |     |       |
   +----> | +-------+ | +-----------+   +---------+  <--+    <--+
   |      |           |
   |      |           |
   |      |           |
   |      |           |
   |      |           |
   |      ^-----------^

I know it need more documentation and tests, but I prefer to send
as draft RFC for early review before spending more time on it.

Based-on: <20210325120921.858993-1-f4bug@amsat.org>
https://www.mail-archive.com/qemu-devel@nongnu.org/msg795218.html

Philippe Mathieu-Daudé (10):
  hw/misc: Add device to help managing aliased memory regions
  hw/arm/musicpal: Open-code pflash_cfi02_register() call
  hw/arm/musicpal: Map flash using memory_region_add_subregion_aliased()
  hw/arm/digic: Open-code pflash_cfi02_register() call
  hw/arm/digic: Map flash using memory_region_add_subregion_aliased()
  hw/block/pflash_cfi02: Remove pflash_setup_mappings()
  hw/block/pflash_cfi02: Simplify pflash_cfi02_register() prototype
  hw/misc/aliased_region: Simplify aliased I/O regions
  hw/m68k/q800: Add MacIO container
  hw/m68k/q800: Map MacIO using memory_region_add_subregion_aliased()

 include/hw/block/flash.h         |   1 -
 include/hw/misc/aliased_region.h |  91 +++++++++++++++
 hw/arm/digic_boards.c            |  28 ++++-
 hw/arm/musicpal.c                |  29 ++++-
 hw/arm/xilinx_zynq.c             |   2 +-
 hw/block/pflash_cfi02.c          |  36 +-----
 hw/lm32/lm32_boards.c            |   4 +-
 hw/m68k/q800.c                   |  61 +++++-----
 hw/misc/aliased_region.c         | 185 +++++++++++++++++++++++++++++++
 hw/ppc/ppc405_boards.c           |   6 +-
 hw/sh4/r2d.c                     |   2 +-
 MAINTAINERS                      |   6 +
 hw/arm/Kconfig                   |   2 +
 hw/m68k/Kconfig                  |   1 +
 hw/misc/Kconfig                  |   3 +
 hw/misc/meson.build              |   1 +
 16 files changed, 375 insertions(+), 83 deletions(-)
 create mode 100644 include/hw/misc/aliased_region.h
 create mode 100644 hw/misc/aliased_region.c

-- 
2.26.2

Re: [RFC PATCH-for-6.1 00/10] hw/misc: Add memory_region_add_subregion_aliased() helper
Posted by Mark Cave-Ayland 3 years ago
On 26/03/2021 00:27, Philippe Mathieu-Daudé wrote:

> Hi,
> 
> This series introduce the memory_region_add_subregion_aliased()
> helper which basically create a device which maps a subregion
> multiple times.
> 
> Examples are easier, so having a subregion aliased every @span_size
> then mapped onto a container at an offset, you get something like:
> 
>            ^-----------^
>            |           |
>            |           |
>            | +-------+ |                 +---------+          <--+
>            |           |                 +---------+             |
>            |           |                 |         |             |
>            |           |   +-----------> | alias#3 |             |
>            |           |   |             |         |             |
>            |           |   |             +---------+             |
>            |           |   |             +---------+             |
>            |           |   |             |         |             |
>            |           |   |   +-------> | alias#2 |             |
>            |           |   |   |         |         |             |region
>            | container |   |   |         +---------+             | size
>            |           |   |   |         +---------+             |
>            |           |   |   |         |         |             |
>            |           |   |   |  +----> | alias#1 |             |
>            |           |   |   |  |      |         |             |
>            |           |   |   |  |      +---------+  <--+       |
>            |           | +-+---+--+--+   +---------+     |       |
>            |           | |           |   |         |     |span   |
>            |           | | subregion +-> | alias#0 |     |size   |
>     offset |           | |           |   |         |     |       |
>     +----> | +-------+ | +-----------+   +---------+  <--+    <--+
>     |      |           |
>     |      |           |
>     |      |           |
>     |      |           |
>     |      |           |
>     |      ^-----------^
> 
> I know it need more documentation and tests, but I prefer to send
> as draft RFC for early review before spending more time on it.
> 
> Based-on: <20210325120921.858993-1-f4bug@amsat.org>
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg795218.html
> 
> Philippe Mathieu-Daudé (10):
>    hw/misc: Add device to help managing aliased memory regions
>    hw/arm/musicpal: Open-code pflash_cfi02_register() call
>    hw/arm/musicpal: Map flash using memory_region_add_subregion_aliased()
>    hw/arm/digic: Open-code pflash_cfi02_register() call
>    hw/arm/digic: Map flash using memory_region_add_subregion_aliased()
>    hw/block/pflash_cfi02: Remove pflash_setup_mappings()
>    hw/block/pflash_cfi02: Simplify pflash_cfi02_register() prototype
>    hw/misc/aliased_region: Simplify aliased I/O regions
>    hw/m68k/q800: Add MacIO container
>    hw/m68k/q800: Map MacIO using memory_region_add_subregion_aliased()
> 
>   include/hw/block/flash.h         |   1 -
>   include/hw/misc/aliased_region.h |  91 +++++++++++++++
>   hw/arm/digic_boards.c            |  28 ++++-
>   hw/arm/musicpal.c                |  29 ++++-
>   hw/arm/xilinx_zynq.c             |   2 +-
>   hw/block/pflash_cfi02.c          |  36 +-----
>   hw/lm32/lm32_boards.c            |   4 +-
>   hw/m68k/q800.c                   |  61 +++++-----
>   hw/misc/aliased_region.c         | 185 +++++++++++++++++++++++++++++++
>   hw/ppc/ppc405_boards.c           |   6 +-
>   hw/sh4/r2d.c                     |   2 +-
>   MAINTAINERS                      |   6 +
>   hw/arm/Kconfig                   |   2 +
>   hw/m68k/Kconfig                  |   1 +
>   hw/misc/Kconfig                  |   3 +
>   hw/misc/meson.build              |   1 +
>   16 files changed, 375 insertions(+), 83 deletions(-)
>   create mode 100644 include/hw/misc/aliased_region.h
>   create mode 100644 hw/misc/aliased_region.c

Now this is interesting. Are there any limits to the number of aliased memory regions 
supported? In my q800 dev branch I have the following commit: 
https://github.com/mcayland/qemu/commit/272547abbca69906dab5d94af32c5117691a1050 
("q800: reimplement mac-io region aliasing using IO memory region") to implement 
similar functionality because adding just one more device into the aliased region is 
enough to cause QEMU to assert with "phys_section_add: Assertion `map->sections_nb < 
TARGET_PAGE_SIZE'
failed" on startup.


ATB,

Mark.

Re: [RFC PATCH-for-6.1 00/10] hw/misc: Add memory_region_add_subregion_aliased() helper
Posted by Richard Henderson 3 years ago
On 3/25/21 6:27 PM, Philippe Mathieu-Daudé wrote:
> This series introduce the memory_region_add_subregion_aliased()
> helper which basically create a device which maps a subregion
> multiple times.

I must say, the example mtree changes are persuasive.
I'll look in more detail later.


r~