All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/32] hw: Sanitize various MemoryRegion uses
@ 2020-02-24 20:47 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

This series simplifies various memory API calls when creating
memory regions.

Most of the patches are generated with Coccinelle semantic
patches (provided).
Few more cleanups added while writting the patches have been
added.

v1 was 'Let devices own the MemoryRegion they create':
https://www.mail-archive.com/qemu-devel@nongnu.org/msg681960.html

Since v1:
- understood a bit more Peter Maydell comments regarding
  how memory devices are migrated.

Supersedes: <20200221173049.18134-1-philmd@redhat.com>

Philippe Mathieu-Daudé (32):
  memory: Correctly return alias region type
  memory: Simplify memory_region_init_rom_nomigrate() to ease review
  scripts/cocci: Rename memory-region-{init-ram -> housekeeping}
  scripts/cocci: Patch to replace memory_region_init_{ram,readonly ->
    rom}
  hw/arm: Use memory_region_init_rom() with read-only regions
  hw/display: Use memory_region_init_rom() with read-only regions
  hw/mips: Use memory_region_init_rom() with read-only regions
  hw/m68k: Use memory_region_init_rom() with read-only regions
  hw/net: Use memory_region_init_rom() with read-only regions
  hw/pci-host: Use memory_region_init_rom() with read-only regions
  hw/ppc: Use memory_region_init_rom() with read-only regions
  hw/riscv: Use memory_region_init_rom() with read-only regions
  hw/sh4: Use memory_region_init_rom() with read-only regions
  hw/sparc: Use memory_region_init_rom() with read-only regions
  scripts/cocci: Patch to detect potential use of memory_region_init_rom
  hw/arm/stm32: Use memory_region_init_rom() with read-only regions
  hw/ppc/ppc405: Use memory_region_init_rom() with read-only regions
  hw/i386/pc_sysfw: Simplify using memory_region_init_alias()
  hw/i386/pc_sysfw: Remove unused 'ram_size' argument
  scripts/cocci: Patch to remove unnecessary
    memory_region_set_readonly()
  hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias
  scripts/cocci: Patch to let devices own their MemoryRegions
  hw/arm: Let devices own the MemoryRegion they create
  hw/char: Let devices own the MemoryRegion they create
  hw/core: Let devices own the MemoryRegion they create
  hw/display: Let devices own the MemoryRegion they create
  hw/dma: Let devices own the MemoryRegion they create
  hw/riscv: Let devices own the MemoryRegion they create
  hw/input/milkymist-softusb: Remove unused 'pmem_ptr' field
  hw/input/milkymist-softusb: Let devices own the MemoryRegion they
    create
  hw/net/milkymist-minimac2: Let devices own the MemoryRegion they
    create
  hw/block/onenand: Let devices own the MemoryRegion they create

 .../memory-region-housekeeping.cocci          | 159 ++++++++++++++++++
 .../coccinelle/memory-region-init-ram.cocci   |  38 -----
 hw/arm/exynos4210.c                           |  14 +-
 hw/arm/fsl-imx25.c                            |  10 +-
 hw/arm/fsl-imx31.c                            |   6 +-
 hw/arm/fsl-imx6.c                             |   6 +-
 hw/arm/fsl-imx6ul.c                           |   9 +-
 hw/arm/mainstone.c                            |   3 +-
 hw/arm/msf2-soc.c                             |   6 +-
 hw/arm/nrf51_soc.c                            |   2 +-
 hw/arm/omap_sx1.c                             |   6 +-
 hw/arm/palm.c                                 |   3 +-
 hw/arm/spitz.c                                |   3 +-
 hw/arm/stellaris.c                            |   3 +-
 hw/arm/stm32f205_soc.c                        |  11 +-
 hw/arm/stm32f405_soc.c                        |  12 +-
 hw/arm/tosa.c                                 |   3 +-
 hw/arm/xlnx-zynqmp.c                          |  11 +-
 hw/block/onenand.c                            |   7 +-
 hw/char/serial.c                              |   7 +-
 hw/core/platform-bus.c                        |   3 +-
 hw/display/cg3.c                              |   5 +-
 hw/display/g364fb.c                           |   3 +-
 hw/display/macfb.c                            |   4 +-
 hw/display/tcx.c                              |   5 +-
 hw/dma/i8257.c                                |   2 +-
 hw/dma/rc4030.c                               |   4 +-
 hw/i386/pc_sysfw.c                            |  29 +---
 hw/input/milkymist-softusb.c                  |  12 +-
 hw/m68k/q800.c                                |   3 +-
 hw/mips/mips_fulong2e.c                       |   3 +-
 hw/mips/mips_jazz.c                           |   6 +-
 hw/mips/mips_mipssim.c                        |   3 +-
 hw/mips/mips_r4k.c                            |   3 +-
 hw/net/dp8393x.c                              |   5 +-
 hw/net/milkymist-minimac2.c                   |   8 +-
 hw/pci-host/prep.c                            |   5 +-
 hw/ppc/mac_newworld.c                         |   3 +-
 hw/ppc/mac_oldworld.c                         |   3 +-
 hw/ppc/ppc405_boards.c                        |   6 +-
 hw/riscv/sifive_e.c                           |   9 +-
 hw/riscv/sifive_u.c                           |   2 +-
 hw/sh4/shix.c                                 |   3 +-
 hw/sparc/leon3.c                              |   3 +-
 memory.c                                      |  16 +-
 MAINTAINERS                                   |   1 +
 46 files changed, 268 insertions(+), 200 deletions(-)
 create mode 100644 scripts/coccinelle/memory-region-housekeeping.cocci
 delete mode 100644 scripts/coccinelle/memory-region-init-ram.cocci

-- 
2.21.1



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v2 00/32] hw: Sanitize various MemoryRegion uses
@ 2020-02-24 20:47 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

This series simplifies various memory API calls when creating
memory regions.

Most of the patches are generated with Coccinelle semantic
patches (provided).
Few more cleanups added while writting the patches have been
added.

v1 was 'Let devices own the MemoryRegion they create':
https://www.mail-archive.com/qemu-devel@nongnu.org/msg681960.html

Since v1:
- understood a bit more Peter Maydell comments regarding
  how memory devices are migrated.

Supersedes: <20200221173049.18134-1-philmd@redhat.com>

Philippe Mathieu-Daudé (32):
  memory: Correctly return alias region type
  memory: Simplify memory_region_init_rom_nomigrate() to ease review
  scripts/cocci: Rename memory-region-{init-ram -> housekeeping}
  scripts/cocci: Patch to replace memory_region_init_{ram,readonly ->
    rom}
  hw/arm: Use memory_region_init_rom() with read-only regions
  hw/display: Use memory_region_init_rom() with read-only regions
  hw/mips: Use memory_region_init_rom() with read-only regions
  hw/m68k: Use memory_region_init_rom() with read-only regions
  hw/net: Use memory_region_init_rom() with read-only regions
  hw/pci-host: Use memory_region_init_rom() with read-only regions
  hw/ppc: Use memory_region_init_rom() with read-only regions
  hw/riscv: Use memory_region_init_rom() with read-only regions
  hw/sh4: Use memory_region_init_rom() with read-only regions
  hw/sparc: Use memory_region_init_rom() with read-only regions
  scripts/cocci: Patch to detect potential use of memory_region_init_rom
  hw/arm/stm32: Use memory_region_init_rom() with read-only regions
  hw/ppc/ppc405: Use memory_region_init_rom() with read-only regions
  hw/i386/pc_sysfw: Simplify using memory_region_init_alias()
  hw/i386/pc_sysfw: Remove unused 'ram_size' argument
  scripts/cocci: Patch to remove unnecessary
    memory_region_set_readonly()
  hw/arm: Remove unnecessary memory_region_set_readonly() on ROM alias
  scripts/cocci: Patch to let devices own their MemoryRegions
  hw/arm: Let devices own the MemoryRegion they create
  hw/char: Let devices own the MemoryRegion they create
  hw/core: Let devices own the MemoryRegion they create
  hw/display: Let devices own the MemoryRegion they create
  hw/dma: Let devices own the MemoryRegion they create
  hw/riscv: Let devices own the MemoryRegion they create
  hw/input/milkymist-softusb: Remove unused 'pmem_ptr' field
  hw/input/milkymist-softusb: Let devices own the MemoryRegion they
    create
  hw/net/milkymist-minimac2: Let devices own the MemoryRegion they
    create
  hw/block/onenand: Let devices own the MemoryRegion they create

 .../memory-region-housekeeping.cocci          | 159 ++++++++++++++++++
 .../coccinelle/memory-region-init-ram.cocci   |  38 -----
 hw/arm/exynos4210.c                           |  14 +-
 hw/arm/fsl-imx25.c                            |  10 +-
 hw/arm/fsl-imx31.c                            |   6 +-
 hw/arm/fsl-imx6.c                             |   6 +-
 hw/arm/fsl-imx6ul.c                           |   9 +-
 hw/arm/mainstone.c                            |   3 +-
 hw/arm/msf2-soc.c                             |   6 +-
 hw/arm/nrf51_soc.c                            |   2 +-
 hw/arm/omap_sx1.c                             |   6 +-
 hw/arm/palm.c                                 |   3 +-
 hw/arm/spitz.c                                |   3 +-
 hw/arm/stellaris.c                            |   3 +-
 hw/arm/stm32f205_soc.c                        |  11 +-
 hw/arm/stm32f405_soc.c                        |  12 +-
 hw/arm/tosa.c                                 |   3 +-
 hw/arm/xlnx-zynqmp.c                          |  11 +-
 hw/block/onenand.c                            |   7 +-
 hw/char/serial.c                              |   7 +-
 hw/core/platform-bus.c                        |   3 +-
 hw/display/cg3.c                              |   5 +-
 hw/display/g364fb.c                           |   3 +-
 hw/display/macfb.c                            |   4 +-
 hw/display/tcx.c                              |   5 +-
 hw/dma/i8257.c                                |   2 +-
 hw/dma/rc4030.c                               |   4 +-
 hw/i386/pc_sysfw.c                            |  29 +---
 hw/input/milkymist-softusb.c                  |  12 +-
 hw/m68k/q800.c                                |   3 +-
 hw/mips/mips_fulong2e.c                       |   3 +-
 hw/mips/mips_jazz.c                           |   6 +-
 hw/mips/mips_mipssim.c                        |   3 +-
 hw/mips/mips_r4k.c                            |   3 +-
 hw/net/dp8393x.c                              |   5 +-
 hw/net/milkymist-minimac2.c                   |   8 +-
 hw/pci-host/prep.c                            |   5 +-
 hw/ppc/mac_newworld.c                         |   3 +-
 hw/ppc/mac_oldworld.c                         |   3 +-
 hw/ppc/ppc405_boards.c                        |   6 +-
 hw/riscv/sifive_e.c                           |   9 +-
 hw/riscv/sifive_u.c                           |   2 +-
 hw/sh4/shix.c                                 |   3 +-
 hw/sparc/leon3.c                              |   3 +-
 memory.c                                      |  16 +-
 MAINTAINERS                                   |   1 +
 46 files changed, 268 insertions(+), 200 deletions(-)
 create mode 100644 scripts/coccinelle/memory-region-housekeeping.cocci
 delete mode 100644 scripts/coccinelle/memory-region-init-ram.cocci

-- 
2.21.1



^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v2 01/32] memory: Correctly return alias region type
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, qemu-trivial,
	Magnus Damm, Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

Since memory region aliases are neither rom nor ram, they are
described as i/o, which is often incorrect. Return instead the
type of the original region we are aliasing.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Cc: qemu-trivial@nongnu.org

 memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/memory.c b/memory.c
index aeaa8dcc9e..ce1179874e 100644
--- a/memory.c
+++ b/memory.c
@@ -2818,6 +2818,9 @@ void address_space_destroy(AddressSpace *as)
 
 static const char *memory_region_type(MemoryRegion *mr)
 {
+    if (mr->alias) {
+        return memory_region_type(mr->alias);
+    }
     if (memory_region_is_ram_device(mr)) {
         return "ramd";
     } else if (memory_region_is_romd(mr)) {
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 01/32] memory: Correctly return alias region type
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko,
	qemu-trivial

Since memory region aliases are neither rom nor ram, they are
described as i/o, which is often incorrect. Return instead the
type of the original region we are aliasing.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
Cc: qemu-trivial@nongnu.org

 memory.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/memory.c b/memory.c
index aeaa8dcc9e..ce1179874e 100644
--- a/memory.c
+++ b/memory.c
@@ -2818,6 +2818,9 @@ void address_space_destroy(AddressSpace *as)
 
 static const char *memory_region_type(MemoryRegion *mr)
 {
+    if (mr->alias) {
+        return memory_region_type(mr->alias);
+    }
     if (memory_region_is_ram_device(mr)) {
         return "ramd";
     } else if (memory_region_is_romd(mr)) {
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 02/32] memory: Simplify memory_region_init_rom_nomigrate() to ease review
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

memory_region_init_rom_nomigrate() has the same content than
memory_region_init_ram_shared_nomigrate(), with setting the
readonly mode. The code is easier to review as creating a
readonly ram/shared/nomigrate region.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 memory.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/memory.c b/memory.c
index ce1179874e..6a327a54ed 100644
--- a/memory.c
+++ b/memory.c
@@ -1659,19 +1659,8 @@ void memory_region_init_rom_nomigrate(MemoryRegion *mr,
                                       uint64_t size,
                                       Error **errp)
 {
-    Error *err = NULL;
-    memory_region_init(mr, owner, name, size);
-    mr->ram = true;
+    memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, errp);
     mr->readonly = true;
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc(size, false, mr, &err);
-    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
-    }
 }
 
 void memory_region_init_rom_device_nomigrate(MemoryRegion *mr,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 02/32] memory: Simplify memory_region_init_rom_nomigrate() to ease review
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

memory_region_init_rom_nomigrate() has the same content than
memory_region_init_ram_shared_nomigrate(), with setting the
readonly mode. The code is easier to review as creating a
readonly ram/shared/nomigrate region.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 memory.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/memory.c b/memory.c
index ce1179874e..6a327a54ed 100644
--- a/memory.c
+++ b/memory.c
@@ -1659,19 +1659,8 @@ void memory_region_init_rom_nomigrate(MemoryRegion *mr,
                                       uint64_t size,
                                       Error **errp)
 {
-    Error *err = NULL;
-    memory_region_init(mr, owner, name, size);
-    mr->ram = true;
+    memory_region_init_ram_shared_nomigrate(mr, owner, name, size, false, errp);
     mr->readonly = true;
-    mr->terminates = true;
-    mr->destructor = memory_region_destructor_ram;
-    mr->ram_block = qemu_ram_alloc(size, false, mr, &err);
-    mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0;
-    if (err) {
-        mr->size = int128_zero();
-        object_unparent(OBJECT(mr));
-        error_propagate(errp, err);
-    }
 }
 
 void memory_region_init_rom_device_nomigrate(MemoryRegion *mr,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 03/32] scripts/cocci: Rename memory-region-{init-ram -> housekeeping}
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

As we are going to add various semantic changes related to the memory
region API, rename this script to be more generic.
Add a 'usage' header, and an entry in MAINTAINERS to avoid checkpatch
warning.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 ...t-ram.cocci => memory-region-housekeeping.cocci} | 13 +++++++++++++
 MAINTAINERS                                         |  1 +
 2 files changed, 14 insertions(+)
 rename scripts/coccinelle/{memory-region-init-ram.cocci => memory-region-housekeeping.cocci} (84%)

diff --git a/scripts/coccinelle/memory-region-init-ram.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
similarity index 84%
rename from scripts/coccinelle/memory-region-init-ram.cocci
rename to scripts/coccinelle/memory-region-housekeeping.cocci
index d290150872..3699c1017e 100644
--- a/scripts/coccinelle/memory-region-init-ram.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -1,3 +1,16 @@
+/*
+  Usage:
+
+    spatch \
+        --macro-file scripts/cocci-macro-file.h \
+        --sp-file scripts/coccinelle/memory-region-housekeeping.cocci \
+        --keep-comments \
+        --in-place \
+        --dir .
+
+*/
+
+
 // Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
 // code sequences with use of the new memory_region_init_ram function.
 // Similarly for the _rom and _rom_device functions.
diff --git a/MAINTAINERS b/MAINTAINERS
index 195dd58cac..316a8edbb6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1998,6 +1998,7 @@ F: include/exec/ramblock.h
 F: memory.c
 F: include/exec/memory-internal.h
 F: exec.c
+F: scripts/coccinelle/memory-region-housekeeping.cocci
 
 SPICE
 M: Gerd Hoffmann <kraxel@redhat.com>
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 03/32] scripts/cocci: Rename memory-region-{init-ram -> housekeeping}
@ 2020-02-24 20:47   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:47 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

As we are going to add various semantic changes related to the memory
region API, rename this script to be more generic.
Add a 'usage' header, and an entry in MAINTAINERS to avoid checkpatch
warning.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 ...t-ram.cocci => memory-region-housekeeping.cocci} | 13 +++++++++++++
 MAINTAINERS                                         |  1 +
 2 files changed, 14 insertions(+)
 rename scripts/coccinelle/{memory-region-init-ram.cocci => memory-region-housekeeping.cocci} (84%)

diff --git a/scripts/coccinelle/memory-region-init-ram.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
similarity index 84%
rename from scripts/coccinelle/memory-region-init-ram.cocci
rename to scripts/coccinelle/memory-region-housekeeping.cocci
index d290150872..3699c1017e 100644
--- a/scripts/coccinelle/memory-region-init-ram.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -1,3 +1,16 @@
+/*
+  Usage:
+
+    spatch \
+        --macro-file scripts/cocci-macro-file.h \
+        --sp-file scripts/coccinelle/memory-region-housekeeping.cocci \
+        --keep-comments \
+        --in-place \
+        --dir .
+
+*/
+
+
 // Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
 // code sequences with use of the new memory_region_init_ram function.
 // Similarly for the _rom and _rom_device functions.
diff --git a/MAINTAINERS b/MAINTAINERS
index 195dd58cac..316a8edbb6 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1998,6 +1998,7 @@ F: include/exec/ramblock.h
 F: memory.c
 F: include/exec/memory-internal.h
 F: exec.c
+F: scripts/coccinelle/memory-region-housekeeping.cocci
 
 SPICE
 M: Gerd Hoffmann <kraxel@redhat.com>
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 04/32] scripts/cocci: Patch to replace memory_region_init_{ram, readonly -> rom}
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

Add a semantic patch to replace memory_region_init_ram(readonly)
by memory_region_init_rom().

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 .../memory-region-housekeeping.cocci           | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
index 3699c1017e..ee3923d369 100644
--- a/scripts/coccinelle/memory-region-housekeeping.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -11,6 +11,24 @@
 */
 
 
+// Replace memory_region_init_ram(readonly) by memory_region_init_rom()
+@@
+expression E1, E2, E3, E4, E5;
+symbol true;
+@@
+(
+- memory_region_init_ram(E1, E2, E3, E4, E5);
++ memory_region_init_rom(E1, E2, E3, E4, E5);
+  ... WHEN != E1
+- memory_region_set_readonly(E1, true);
+|
+- memory_region_init_ram_nomigrate(E1, E2, E3, E4, E5);
++ memory_region_init_rom_nomigrate(E1, E2, E3, E4, E5);
+  ... WHEN != E1
+- memory_region_set_readonly(E1, true);
+)
+
+
 // Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
 // code sequences with use of the new memory_region_init_ram function.
 // Similarly for the _rom and _rom_device functions.
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 04/32] scripts/cocci: Patch to replace memory_region_init_{ram, readonly -> rom}
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

Add a semantic patch to replace memory_region_init_ram(readonly)
by memory_region_init_rom().

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 .../memory-region-housekeeping.cocci           | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/scripts/coccinelle/memory-region-housekeeping.cocci b/scripts/coccinelle/memory-region-housekeeping.cocci
index 3699c1017e..ee3923d369 100644
--- a/scripts/coccinelle/memory-region-housekeeping.cocci
+++ b/scripts/coccinelle/memory-region-housekeeping.cocci
@@ -11,6 +11,24 @@
 */
 
 
+// Replace memory_region_init_ram(readonly) by memory_region_init_rom()
+@@
+expression E1, E2, E3, E4, E5;
+symbol true;
+@@
+(
+- memory_region_init_ram(E1, E2, E3, E4, E5);
++ memory_region_init_rom(E1, E2, E3, E4, E5);
+  ... WHEN != E1
+- memory_region_set_readonly(E1, true);
+|
+- memory_region_init_ram_nomigrate(E1, E2, E3, E4, E5);
++ memory_region_init_rom_nomigrate(E1, E2, E3, E4, E5);
+  ... WHEN != E1
+- memory_region_set_readonly(E1, true);
+)
+
+
 // Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
 // code sequences with use of the new memory_region_init_ram function.
 // Similarly for the _rom and _rom_device functions.
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/arm/exynos4210.c | 3 +--
 hw/arm/mainstone.c  | 3 +--
 hw/arm/omap_sx1.c   | 6 ++----
 hw/arm/palm.c       | 3 +--
 hw/arm/spitz.c      | 3 +--
 hw/arm/stellaris.c  | 3 +--
 hw/arm/tosa.c       | 3 +--
 7 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 59a27bdd68..3af6502a5e 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
                                 &s->chipid_mem);
 
     /* Internal ROM */
-    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
+    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
                            EXYNOS4210_IROM_SIZE, &error_fatal);
-    memory_region_set_readonly(&s->irom_mem, true);
     memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
                                 &s->irom_mem);
     /* mirror of iROM */
diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
index 6e64dfab50..05a806b422 100644
--- a/hw/arm/mainstone.c
+++ b/hw/arm/mainstone.c
@@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
     /* Setup CPU & memory */
     mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
                       machine->cpu_type);
-    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
+    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
                            &error_fatal);
-    memory_region_set_readonly(rom, true);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
 #ifdef TARGET_WORDS_BIGENDIAN
diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
index be245714db..6c3fd1b271 100644
--- a/hw/arm/omap_sx1.c
+++ b/hw/arm/omap_sx1.c
@@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
     mpu = omap310_mpu_init(dram, machine->cpu_type);
 
     /* External Flash (EMIFS) */
-    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
+    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
 
     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
@@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
     if ((version == 1) &&
             (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
         MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
-        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
+        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
                                flash1_size, &error_fatal);
-        memory_region_set_readonly(flash_1, true);
         memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
 
         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
diff --git a/hw/arm/palm.c b/hw/arm/palm.c
index 72eca8cc55..265d5891a6 100644
--- a/hw/arm/palm.c
+++ b/hw/arm/palm.c
@@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
     mpu = omap310_mpu_init(dram, machine->cpu_type);
 
     /* External Flash (EMIFS) */
-    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
+    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
 
     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index e001088103..1d27399721 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
 
     sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
 
-    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
-    memory_region_set_readonly(rom, true);
+    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
     /* Setup peripherals */
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 221a78674e..d136ba1a92 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sram_size = ((board->dc0 >> 18) + 1) * 1024;
 
     /* Flash programming is done via the SCU, so pretend it is ROM.  */
-    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
+    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(system_memory, 0, flash);
 
     memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
index 4d95a1f3e2..5dee2d76c6 100644
--- a/hw/arm/tosa.c
+++ b/hw/arm/tosa.c
@@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
 
     mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
 
-    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
-    memory_region_set_readonly(rom, true);
+    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
     tmio = tc6393xb_init(address_space_mem, 0x10000000,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/arm/exynos4210.c | 3 +--
 hw/arm/mainstone.c  | 3 +--
 hw/arm/omap_sx1.c   | 6 ++----
 hw/arm/palm.c       | 3 +--
 hw/arm/spitz.c      | 3 +--
 hw/arm/stellaris.c  | 3 +--
 hw/arm/tosa.c       | 3 +--
 7 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
index 59a27bdd68..3af6502a5e 100644
--- a/hw/arm/exynos4210.c
+++ b/hw/arm/exynos4210.c
@@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
                                 &s->chipid_mem);
 
     /* Internal ROM */
-    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
+    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
                            EXYNOS4210_IROM_SIZE, &error_fatal);
-    memory_region_set_readonly(&s->irom_mem, true);
     memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
                                 &s->irom_mem);
     /* mirror of iROM */
diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
index 6e64dfab50..05a806b422 100644
--- a/hw/arm/mainstone.c
+++ b/hw/arm/mainstone.c
@@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
     /* Setup CPU & memory */
     mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
                       machine->cpu_type);
-    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
+    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
                            &error_fatal);
-    memory_region_set_readonly(rom, true);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
 #ifdef TARGET_WORDS_BIGENDIAN
diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
index be245714db..6c3fd1b271 100644
--- a/hw/arm/omap_sx1.c
+++ b/hw/arm/omap_sx1.c
@@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
     mpu = omap310_mpu_init(dram, machine->cpu_type);
 
     /* External Flash (EMIFS) */
-    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
+    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
 
     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
@@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
     if ((version == 1) &&
             (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
         MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
-        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
+        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
                                flash1_size, &error_fatal);
-        memory_region_set_readonly(flash_1, true);
         memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
 
         memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
diff --git a/hw/arm/palm.c b/hw/arm/palm.c
index 72eca8cc55..265d5891a6 100644
--- a/hw/arm/palm.c
+++ b/hw/arm/palm.c
@@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
     mpu = omap310_mpu_init(dram, machine->cpu_type);
 
     /* External Flash (EMIFS) */
-    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
+    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
 
     memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
index e001088103..1d27399721 100644
--- a/hw/arm/spitz.c
+++ b/hw/arm/spitz.c
@@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
 
     sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
 
-    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
-    memory_region_set_readonly(rom, true);
+    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
     /* Setup peripherals */
diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
index 221a78674e..d136ba1a92 100644
--- a/hw/arm/stellaris.c
+++ b/hw/arm/stellaris.c
@@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
     sram_size = ((board->dc0 >> 18) + 1) * 1024;
 
     /* Flash programming is done via the SCU, so pretend it is ROM.  */
-    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
+    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
                            &error_fatal);
-    memory_region_set_readonly(flash, true);
     memory_region_add_subregion(system_memory, 0, flash);
 
     memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
index 4d95a1f3e2..5dee2d76c6 100644
--- a/hw/arm/tosa.c
+++ b/hw/arm/tosa.c
@@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
 
     mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
 
-    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
-    memory_region_set_readonly(rom, true);
+    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
     memory_region_add_subregion(address_space_mem, 0, rom);
 
     tmio = tc6393xb_init(address_space_mem, 0x10000000,
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 06/32] hw/display: Use memory_region_init_rom() with read-only regions
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/display/cg3.c | 5 ++---
 hw/display/tcx.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/display/cg3.c b/hw/display/cg3.c
index 4fb67c6b1c..a1ede10394 100644
--- a/hw/display/cg3.c
+++ b/hw/display/cg3.c
@@ -287,9 +287,8 @@ static void cg3_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     CG3State *s = CG3(obj);
 
-    memory_region_init_ram_nomigrate(&s->rom, obj, "cg3.prom", FCODE_MAX_ROM_SIZE,
-                           &error_fatal);
-    memory_region_set_readonly(&s->rom, true);
+    memory_region_init_rom_nomigrate(&s->rom, obj, "cg3.prom",
+                                     FCODE_MAX_ROM_SIZE, &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     memory_region_init_io(&s->reg, obj, &cg3_reg_ops, s, "cg3.reg",
diff --git a/hw/display/tcx.c b/hw/display/tcx.c
index ca458f94fe..76de16e8ea 100644
--- a/hw/display/tcx.c
+++ b/hw/display/tcx.c
@@ -755,9 +755,8 @@ static void tcx_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     TCXState *s = TCX(obj);
 
-    memory_region_init_ram_nomigrate(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE,
-                           &error_fatal);
-    memory_region_set_readonly(&s->rom, true);
+    memory_region_init_rom_nomigrate(&s->rom, obj, "tcx.prom",
+                                     FCODE_MAX_ROM_SIZE, &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     /* 2/STIP : Stippler */
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 06/32] hw/display: Use memory_region_init_rom() with read-only regions
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/display/cg3.c | 5 ++---
 hw/display/tcx.c | 5 ++---
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/display/cg3.c b/hw/display/cg3.c
index 4fb67c6b1c..a1ede10394 100644
--- a/hw/display/cg3.c
+++ b/hw/display/cg3.c
@@ -287,9 +287,8 @@ static void cg3_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     CG3State *s = CG3(obj);
 
-    memory_region_init_ram_nomigrate(&s->rom, obj, "cg3.prom", FCODE_MAX_ROM_SIZE,
-                           &error_fatal);
-    memory_region_set_readonly(&s->rom, true);
+    memory_region_init_rom_nomigrate(&s->rom, obj, "cg3.prom",
+                                     FCODE_MAX_ROM_SIZE, &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     memory_region_init_io(&s->reg, obj, &cg3_reg_ops, s, "cg3.reg",
diff --git a/hw/display/tcx.c b/hw/display/tcx.c
index ca458f94fe..76de16e8ea 100644
--- a/hw/display/tcx.c
+++ b/hw/display/tcx.c
@@ -755,9 +755,8 @@ static void tcx_initfn(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     TCXState *s = TCX(obj);
 
-    memory_region_init_ram_nomigrate(&s->rom, obj, "tcx.prom", FCODE_MAX_ROM_SIZE,
-                           &error_fatal);
-    memory_region_set_readonly(&s->rom, true);
+    memory_region_init_rom_nomigrate(&s->rom, obj, "tcx.prom",
+                                     FCODE_MAX_ROM_SIZE, &error_fatal);
     sysbus_init_mmio(sbd, &s->rom);
 
     /* 2/STIP : Stippler */
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 07/32] hw/mips: Use memory_region_init_rom() with read-only regions
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/mips/mips_fulong2e.c | 3 +--
 hw/mips/mips_jazz.c     | 6 ++----
 hw/mips/mips_mipssim.c  | 3 +--
 hw/mips/mips_r4k.c      | 3 +--
 4 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 2e043cbb98..547a7d3a45 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -319,9 +319,8 @@ static void mips_fulong2e_init(MachineState *machine)
 
     /* allocate RAM */
     memory_region_allocate_system_memory(ram, NULL, "fulong2e.ram", ram_size);
-    memory_region_init_ram(bios, NULL, "fulong2e.bios", BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "fulong2e.bios", BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
 
     memory_region_add_subregion(address_space_mem, 0, ram);
     memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c
index 66fd4d867d..cf47335ea5 100644
--- a/hw/mips/mips_jazz.c
+++ b/hw/mips/mips_jazz.c
@@ -195,9 +195,8 @@ static void mips_jazz_init(MachineState *machine,
                                          machine->ram_size);
     memory_region_add_subregion(address_space, 0, ram);
 
-    memory_region_init_ram(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
     memory_region_init_alias(bios2, NULL, "mips_jazz.bios", bios,
                              0, MAGNUM_BIOS_SIZE);
     memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
@@ -263,9 +262,8 @@ static void mips_jazz_init(MachineState *machine,
         {
             /* Simple ROM, so user doesn't have to provide one */
             MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
-            memory_region_init_ram(rom_mr, NULL, "g364fb.rom", 0x80000,
+            memory_region_init_rom(rom_mr, NULL, "g364fb.rom", 0x80000,
                                    &error_fatal);
-            memory_region_set_readonly(rom_mr, true);
             uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
             memory_region_add_subregion(address_space, 0x60000000, rom_mr);
             rom[0] = 0x10; /* Mips G364 */
diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
index b934ca9d51..3fdbb21680 100644
--- a/hw/mips/mips_mipssim.c
+++ b/hw/mips/mips_mipssim.c
@@ -169,9 +169,8 @@ mips_mipssim_init(MachineState *machine)
     /* Allocate RAM. */
     memory_region_allocate_system_memory(ram, NULL, "mips_mipssim.ram",
                                          ram_size);
-    memory_region_init_ram(bios, NULL, "mips_mipssim.bios", BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "mips_mipssim.bios", BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
 
     memory_region_add_subregion(address_space_mem, 0, ram);
 
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index b2aec434c3..54b286ceee 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -241,9 +241,8 @@ void mips_r4k_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) {
         bios = g_new(MemoryRegion, 1);
-        memory_region_init_ram(bios, NULL, "mips_r4k.bios", BIOS_SIZE,
+        memory_region_init_rom(bios, NULL, "mips_r4k.bios", BIOS_SIZE,
                                &error_fatal);
-        memory_region_set_readonly(bios, true);
         memory_region_add_subregion(get_system_memory(), 0x1fc00000, bios);
 
         load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 07/32] hw/mips: Use memory_region_init_rom() with read-only regions
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/mips/mips_fulong2e.c | 3 +--
 hw/mips/mips_jazz.c     | 6 ++----
 hw/mips/mips_mipssim.c  | 3 +--
 hw/mips/mips_r4k.c      | 3 +--
 4 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c
index 2e043cbb98..547a7d3a45 100644
--- a/hw/mips/mips_fulong2e.c
+++ b/hw/mips/mips_fulong2e.c
@@ -319,9 +319,8 @@ static void mips_fulong2e_init(MachineState *machine)
 
     /* allocate RAM */
     memory_region_allocate_system_memory(ram, NULL, "fulong2e.ram", ram_size);
-    memory_region_init_ram(bios, NULL, "fulong2e.bios", BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "fulong2e.bios", BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
 
     memory_region_add_subregion(address_space_mem, 0, ram);
     memory_region_add_subregion(address_space_mem, 0x1fc00000LL, bios);
diff --git a/hw/mips/mips_jazz.c b/hw/mips/mips_jazz.c
index 66fd4d867d..cf47335ea5 100644
--- a/hw/mips/mips_jazz.c
+++ b/hw/mips/mips_jazz.c
@@ -195,9 +195,8 @@ static void mips_jazz_init(MachineState *machine,
                                          machine->ram_size);
     memory_region_add_subregion(address_space, 0, ram);
 
-    memory_region_init_ram(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "mips_jazz.bios", MAGNUM_BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
     memory_region_init_alias(bios2, NULL, "mips_jazz.bios", bios,
                              0, MAGNUM_BIOS_SIZE);
     memory_region_add_subregion(address_space, 0x1fc00000LL, bios);
@@ -263,9 +262,8 @@ static void mips_jazz_init(MachineState *machine,
         {
             /* Simple ROM, so user doesn't have to provide one */
             MemoryRegion *rom_mr = g_new(MemoryRegion, 1);
-            memory_region_init_ram(rom_mr, NULL, "g364fb.rom", 0x80000,
+            memory_region_init_rom(rom_mr, NULL, "g364fb.rom", 0x80000,
                                    &error_fatal);
-            memory_region_set_readonly(rom_mr, true);
             uint8_t *rom = memory_region_get_ram_ptr(rom_mr);
             memory_region_add_subregion(address_space, 0x60000000, rom_mr);
             rom[0] = 0x10; /* Mips G364 */
diff --git a/hw/mips/mips_mipssim.c b/hw/mips/mips_mipssim.c
index b934ca9d51..3fdbb21680 100644
--- a/hw/mips/mips_mipssim.c
+++ b/hw/mips/mips_mipssim.c
@@ -169,9 +169,8 @@ mips_mipssim_init(MachineState *machine)
     /* Allocate RAM. */
     memory_region_allocate_system_memory(ram, NULL, "mips_mipssim.ram",
                                          ram_size);
-    memory_region_init_ram(bios, NULL, "mips_mipssim.bios", BIOS_SIZE,
+    memory_region_init_rom(bios, NULL, "mips_mipssim.bios", BIOS_SIZE,
                            &error_fatal);
-    memory_region_set_readonly(bios, true);
 
     memory_region_add_subregion(address_space_mem, 0, ram);
 
diff --git a/hw/mips/mips_r4k.c b/hw/mips/mips_r4k.c
index b2aec434c3..54b286ceee 100644
--- a/hw/mips/mips_r4k.c
+++ b/hw/mips/mips_r4k.c
@@ -241,9 +241,8 @@ void mips_r4k_init(MachineState *machine)
     dinfo = drive_get(IF_PFLASH, 0, 0);
     if ((bios_size > 0) && (bios_size <= BIOS_SIZE)) {
         bios = g_new(MemoryRegion, 1);
-        memory_region_init_ram(bios, NULL, "mips_r4k.bios", BIOS_SIZE,
+        memory_region_init_rom(bios, NULL, "mips_r4k.bios", BIOS_SIZE,
                                &error_fatal);
-        memory_region_set_readonly(bios, true);
         memory_region_add_subregion(get_system_memory(), 0x1fc00000, bios);
 
         load_image_targphys(filename, 0x1fc00000, BIOS_SIZE);
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 08/32] hw/m68k: Use memory_region_init_rom() with read-only regions
  2020-02-24 20:47 ` Philippe Mathieu-Daudé
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, qemu-riscv, Igor Mitsyanko,
	Philippe Mathieu-Daudé,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle, qemu-ppc,
	Aleksandar Markovic, Bastian Koppelmann, Aurelien Jarno

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/m68k/q800.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 1e32363688..8083326d37 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -402,13 +402,12 @@ static void q800_init(MachineState *machine)
         uint8_t *ptr;
         /* allocate and load BIOS */
         rom = g_malloc(sizeof(*rom));
-        memory_region_init_ram(rom, NULL, "m68k_mac.rom", MACROM_SIZE,
+        memory_region_init_rom(rom, NULL, "m68k_mac.rom", MACROM_SIZE,
                                &error_abort);
         if (bios_name == NULL) {
             bios_name = MACROM_FILENAME;
         }
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-        memory_region_set_readonly(rom, true);
         memory_region_add_subregion(get_system_memory(), MACROM_ADDR, rom);
 
         /* Load MacROM binary */
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 08/32] hw/m68k: Use memory_region_init_rom() with read-only regions
@ 2020-02-24 20:48   ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-24 20:48 UTC (permalink / raw)
  To: Peter Maydell, Paolo Bonzini, qemu-devel
  Cc: Joel Stanley, Laurent Vivier, Aleksandar Markovic,
	Richard Henderson, Andrzej Zaborowski, KONRAD Frederic,
	Peter Chubb, Palmer Dabbelt, Michael Walle, Max Reitz,
	Edgar E. Iglesias, Marcel Apfelbaum, Hervé Poussineau,
	qemu-arm, Magnus Damm, Subbaraya Sundeep, David Gibson,
	Eduardo Habkost, Jean-Christophe Dubois, Sagar Karandikar,
	Igor Mitsyanko, qemu-ppc, qemu-riscv, Mark Cave-Ayland,
	Aurelien Jarno, Jason Wang, Philippe Mathieu-Daudé,
	Alistair Francis, Bastian Koppelmann, Fabien Chouteau,
	Alistair Francis, Kevin Wolf, Aleksandar Rikalo, qemu-block,
	Marc-André Lureau, Michael S. Tsirkin, Artyom Tarasenko

This commit was produced with the Coccinelle script
scripts/coccinelle/memory-region-housekeeping.cocci.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 hw/m68k/q800.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 1e32363688..8083326d37 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -402,13 +402,12 @@ static void q800_init(MachineState *machine)
         uint8_t *ptr;
         /* allocate and load BIOS */
         rom = g_malloc(sizeof(*rom));
-        memory_region_init_ram(rom, NULL, "m68k_mac.rom", MACROM_SIZE,
+        memory_region_init_rom(rom, NULL, "m68k_mac.rom", MACROM_SIZE,
                                &error_abort);
         if (bios_name == NULL) {
             bios_name = MACROM_FILENAME;
         }
         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-        memory_region_set_readonly(rom, true);
         memory_region_add_subregion(get_system_memory(), MACROM_ADDR, rom);
 
         /* Load MacROM binary */
-- 
2.21.1



^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 01/32] memory: Correctly return alias region type
  2020-02-24 20:47   ` Philippe Mathieu-Daudé
@ 2020-02-24 21:14     ` Alistair Francis
  -1 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-24 21:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, qemu-devel@nongnu.org Developers,
	KONRAD Frederic, Alistair Francis, Edgar E. Iglesias,
	Subbaraya Sundeep, Qemu-block, QEMU Trivial, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Marc-André Lureau,
	Aleksandar Rikalo, David Gibson, Artyom Tarasenko,
	Eduardo Habkost, Jean-Christophe Dubois, Alistair Francis,
	Fabien Chouteau, qemu-arm, Peter Chubb, open list:New World,
	Richard Henderson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Bastian Koppelmann, Laurent Vivier, Max Reitz, Michael Walle,
	Palmer Dabbelt, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno

On Mon, Feb 24, 2020 at 12:49 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Since memory region aliases are neither rom nor ram, they are
> described as i/o, which is often incorrect. Return instead the
> type of the original region we are aliasing.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
> Cc: qemu-trivial@nongnu.org
>
>  memory.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/memory.c b/memory.c
> index aeaa8dcc9e..ce1179874e 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2818,6 +2818,9 @@ void address_space_destroy(AddressSpace *as)
>
>  static const char *memory_region_type(MemoryRegion *mr)
>  {
> +    if (mr->alias) {
> +        return memory_region_type(mr->alias);
> +    }
>      if (memory_region_is_ram_device(mr)) {
>          return "ramd";
>      } else if (memory_region_is_romd(mr)) {
> --
> 2.21.1
>
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 01/32] memory: Correctly return alias region type
@ 2020-02-24 21:14     ` Alistair Francis
  0 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-24 21:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel@nongnu.org Developers,
	Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, Qemu-block, QEMU Trivial,
	Magnus Damm, Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle,
	open list:New World, Aleksandar Markovic, Bastian Koppelmann,
	Aurelien Jarno

On Mon, Feb 24, 2020 at 12:49 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Since memory region aliases are neither rom nor ram, they are
> described as i/o, which is often incorrect. Return instead the
> type of the original region we are aliasing.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
> Cc: qemu-trivial@nongnu.org
>
>  memory.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/memory.c b/memory.c
> index aeaa8dcc9e..ce1179874e 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2818,6 +2818,9 @@ void address_space_destroy(AddressSpace *as)
>
>  static const char *memory_region_type(MemoryRegion *mr)
>  {
> +    if (mr->alias) {
> +        return memory_region_type(mr->alias);
> +    }
>      if (memory_region_is_ram_device(mr)) {
>          return "ramd";
>      } else if (memory_region_is_romd(mr)) {
> --
> 2.21.1
>
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
  2020-02-24 20:48   ` Philippe Mathieu-Daudé
@ 2020-02-24 21:20     ` Alistair Francis
  -1 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-24 21:20 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, qemu-devel@nongnu.org Developers,
	KONRAD Frederic, Alistair Francis, Edgar E. Iglesias,
	Subbaraya Sundeep, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Marc-André Lureau,
	Aleksandar Rikalo, David Gibson, Artyom Tarasenko,
	Eduardo Habkost, Jean-Christophe Dubois, Alistair Francis,
	Fabien Chouteau, qemu-arm, Peter Chubb, open list:New World,
	Richard Henderson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Bastian Koppelmann, Laurent Vivier, Max Reitz, Michael Walle,
	Palmer Dabbelt, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno

On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> This commit was produced with the Coccinelle script
> scripts/coccinelle/memory-region-housekeeping.cocci.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

This looks good for the ROM regions, for the flash regions this
doesn't change the current functionality but I'm not sure it's any
clearer.

Either way though:

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/arm/exynos4210.c | 3 +--
>  hw/arm/mainstone.c  | 3 +--
>  hw/arm/omap_sx1.c   | 6 ++----
>  hw/arm/palm.c       | 3 +--
>  hw/arm/spitz.c      | 3 +--
>  hw/arm/stellaris.c  | 3 +--
>  hw/arm/tosa.c       | 3 +--
>  7 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
> index 59a27bdd68..3af6502a5e 100644
> --- a/hw/arm/exynos4210.c
> +++ b/hw/arm/exynos4210.c
> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
>                                  &s->chipid_mem);
>
>      /* Internal ROM */
> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
>                             EXYNOS4210_IROM_SIZE, &error_fatal);
> -    memory_region_set_readonly(&s->irom_mem, true);
>      memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
>                                  &s->irom_mem);
>      /* mirror of iROM */
> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> index 6e64dfab50..05a806b422 100644
> --- a/hw/arm/mainstone.c
> +++ b/hw/arm/mainstone.c
> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>      /* Setup CPU & memory */
>      mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
>                        machine->cpu_type);
> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>                             &error_fatal);
> -    memory_region_set_readonly(rom, true);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>  #ifdef TARGET_WORDS_BIGENDIAN
> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> index be245714db..6c3fd1b271 100644
> --- a/hw/arm/omap_sx1.c
> +++ b/hw/arm/omap_sx1.c
> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
>      mpu = omap310_mpu_init(dram, machine->cpu_type);
>
>      /* External Flash (EMIFS) */
> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
>
>      memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
>      if ((version == 1) &&
>              (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
>          MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
>                                 flash1_size, &error_fatal);
> -        memory_region_set_readonly(flash_1, true);
>          memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
>
>          memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
> index 72eca8cc55..265d5891a6 100644
> --- a/hw/arm/palm.c
> +++ b/hw/arm/palm.c
> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
>      mpu = omap310_mpu_init(dram, machine->cpu_type);
>
>      /* External Flash (EMIFS) */
> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
>
>      memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
> index e001088103..1d27399721 100644
> --- a/hw/arm/spitz.c
> +++ b/hw/arm/spitz.c
> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
>
>      sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
>
> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> -    memory_region_set_readonly(rom, true);
> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>      /* Setup peripherals */
> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> index 221a78674e..d136ba1a92 100644
> --- a/hw/arm/stellaris.c
> +++ b/hw/arm/stellaris.c
> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
>      sram_size = ((board->dc0 >> 18) + 1) * 1024;
>
>      /* Flash programming is done via the SCU, so pretend it is ROM.  */
> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(system_memory, 0, flash);
>
>      memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
> index 4d95a1f3e2..5dee2d76c6 100644
> --- a/hw/arm/tosa.c
> +++ b/hw/arm/tosa.c
> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
>
>      mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
>
> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> -    memory_region_set_readonly(rom, true);
> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>      tmio = tc6393xb_init(address_space_mem, 0x10000000,
> --
> 2.21.1
>
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
@ 2020-02-24 21:20     ` Alistair Francis
  0 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-24 21:20 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel@nongnu.org Developers,
	Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle,
	open list:New World, Aleksandar Markovic, Bastian Koppelmann,
	Aurelien Jarno

On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> This commit was produced with the Coccinelle script
> scripts/coccinelle/memory-region-housekeeping.cocci.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

This looks good for the ROM regions, for the flash regions this
doesn't change the current functionality but I'm not sure it's any
clearer.

Either way though:

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  hw/arm/exynos4210.c | 3 +--
>  hw/arm/mainstone.c  | 3 +--
>  hw/arm/omap_sx1.c   | 6 ++----
>  hw/arm/palm.c       | 3 +--
>  hw/arm/spitz.c      | 3 +--
>  hw/arm/stellaris.c  | 3 +--
>  hw/arm/tosa.c       | 3 +--
>  7 files changed, 8 insertions(+), 16 deletions(-)
>
> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
> index 59a27bdd68..3af6502a5e 100644
> --- a/hw/arm/exynos4210.c
> +++ b/hw/arm/exynos4210.c
> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
>                                  &s->chipid_mem);
>
>      /* Internal ROM */
> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
>                             EXYNOS4210_IROM_SIZE, &error_fatal);
> -    memory_region_set_readonly(&s->irom_mem, true);
>      memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
>                                  &s->irom_mem);
>      /* mirror of iROM */
> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> index 6e64dfab50..05a806b422 100644
> --- a/hw/arm/mainstone.c
> +++ b/hw/arm/mainstone.c
> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>      /* Setup CPU & memory */
>      mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
>                        machine->cpu_type);
> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>                             &error_fatal);
> -    memory_region_set_readonly(rom, true);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>  #ifdef TARGET_WORDS_BIGENDIAN
> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> index be245714db..6c3fd1b271 100644
> --- a/hw/arm/omap_sx1.c
> +++ b/hw/arm/omap_sx1.c
> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
>      mpu = omap310_mpu_init(dram, machine->cpu_type);
>
>      /* External Flash (EMIFS) */
> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
>
>      memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
>      if ((version == 1) &&
>              (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
>          MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
>                                 flash1_size, &error_fatal);
> -        memory_region_set_readonly(flash_1, true);
>          memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
>
>          memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
> index 72eca8cc55..265d5891a6 100644
> --- a/hw/arm/palm.c
> +++ b/hw/arm/palm.c
> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
>      mpu = omap310_mpu_init(dram, machine->cpu_type);
>
>      /* External Flash (EMIFS) */
> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
>
>      memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
> index e001088103..1d27399721 100644
> --- a/hw/arm/spitz.c
> +++ b/hw/arm/spitz.c
> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
>
>      sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
>
> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> -    memory_region_set_readonly(rom, true);
> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>      /* Setup peripherals */
> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> index 221a78674e..d136ba1a92 100644
> --- a/hw/arm/stellaris.c
> +++ b/hw/arm/stellaris.c
> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
>      sram_size = ((board->dc0 >> 18) + 1) * 1024;
>
>      /* Flash programming is done via the SCU, so pretend it is ROM.  */
> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
>                             &error_fatal);
> -    memory_region_set_readonly(flash, true);
>      memory_region_add_subregion(system_memory, 0, flash);
>
>      memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
> index 4d95a1f3e2..5dee2d76c6 100644
> --- a/hw/arm/tosa.c
> +++ b/hw/arm/tosa.c
> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
>
>      mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
>
> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> -    memory_region_set_readonly(rom, true);
> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>      memory_region_add_subregion(address_space_mem, 0, rom);
>
>      tmio = tc6393xb_init(address_space_mem, 0x10000000,
> --
> 2.21.1
>
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
  2020-02-24 21:20     ` Alistair Francis
@ 2020-02-25 10:02       ` Philippe Mathieu-Daudé
  -1 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-25 10:02 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Peter Maydell, Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, qemu-devel@nongnu.org Developers,
	KONRAD Frederic, Alistair Francis, Edgar E. Iglesias,
	Subbaraya Sundeep, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Marc-André Lureau,
	Aleksandar Rikalo, David Gibson, Artyom Tarasenko,
	Eduardo Habkost, Jean-Christophe Dubois, Alistair Francis,
	Fabien Chouteau, qemu-arm, Peter Chubb, open list:New World,
	Richard Henderson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Bastian Koppelmann, Laurent Vivier, Max Reitz, Michael Walle,
	Palmer Dabbelt, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno

On 2/24/20 10:20 PM, Alistair Francis wrote:
> On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
> <philmd@redhat.com> wrote:
>>
>> This commit was produced with the Coccinelle script
>> scripts/coccinelle/memory-region-housekeeping.cocci.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> This looks good for the ROM regions, for the flash regions this
> doesn't change the current functionality but I'm not sure it's any
> clearer.

Less code makes easier review.

These regions behave as ROM on the bus, any write to the address space 
is illegal (they are programmable via I/O registers in another address 
space).

> 
> Either way though:
> 
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Thanks, do you want me to improve the commit description?

> 
> Alistair
> 
>> ---
>>   hw/arm/exynos4210.c | 3 +--
>>   hw/arm/mainstone.c  | 3 +--
>>   hw/arm/omap_sx1.c   | 6 ++----
>>   hw/arm/palm.c       | 3 +--
>>   hw/arm/spitz.c      | 3 +--
>>   hw/arm/stellaris.c  | 3 +--
>>   hw/arm/tosa.c       | 3 +--
>>   7 files changed, 8 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
>> index 59a27bdd68..3af6502a5e 100644
>> --- a/hw/arm/exynos4210.c
>> +++ b/hw/arm/exynos4210.c
>> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
>>                                   &s->chipid_mem);
>>
>>       /* Internal ROM */
>> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
>> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
>>                              EXYNOS4210_IROM_SIZE, &error_fatal);
>> -    memory_region_set_readonly(&s->irom_mem, true);
>>       memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
>>                                   &s->irom_mem);
>>       /* mirror of iROM */
>> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
>> index 6e64dfab50..05a806b422 100644
>> --- a/hw/arm/mainstone.c
>> +++ b/hw/arm/mainstone.c
>> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>>       /* Setup CPU & memory */
>>       mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
>>                         machine->cpu_type);
>> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>>                              &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>   #ifdef TARGET_WORDS_BIGENDIAN
>> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
>> index be245714db..6c3fd1b271 100644
>> --- a/hw/arm/omap_sx1.c
>> +++ b/hw/arm/omap_sx1.c
>> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
>>       mpu = omap310_mpu_init(dram, machine->cpu_type);
>>
>>       /* External Flash (EMIFS) */
>> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
>> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
>>
>>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
>> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
>>       if ((version == 1) &&
>>               (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
>>           MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
>> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
>> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
>>                                  flash1_size, &error_fatal);
>> -        memory_region_set_readonly(flash_1, true);
>>           memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
>>
>>           memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
>> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
>> index 72eca8cc55..265d5891a6 100644
>> --- a/hw/arm/palm.c
>> +++ b/hw/arm/palm.c
>> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
>>       mpu = omap310_mpu_init(dram, machine->cpu_type);
>>
>>       /* External Flash (EMIFS) */
>> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
>> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
>>
>>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
>> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
>> index e001088103..1d27399721 100644
>> --- a/hw/arm/spitz.c
>> +++ b/hw/arm/spitz.c
>> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
>>
>>       sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
>>
>> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>       /* Setup peripherals */
>> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
>> index 221a78674e..d136ba1a92 100644
>> --- a/hw/arm/stellaris.c
>> +++ b/hw/arm/stellaris.c
>> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
>>       sram_size = ((board->dc0 >> 18) + 1) * 1024;
>>
>>       /* Flash programming is done via the SCU, so pretend it is ROM.  */
>> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
>> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(system_memory, 0, flash);
>>
>>       memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
>> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
>> index 4d95a1f3e2..5dee2d76c6 100644
>> --- a/hw/arm/tosa.c
>> +++ b/hw/arm/tosa.c
>> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
>>
>>       mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
>>
>> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>       tmio = tc6393xb_init(address_space_mem, 0x10000000,
>> --
>> 2.21.1
>>
>>
> 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
@ 2020-02-25 10:02       ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 26+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-02-25 10:02 UTC (permalink / raw)
  To: Alistair Francis
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel@nongnu.org Developers,
	Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle,
	open list:New World, Aleksandar Markovic, Bastian Koppelmann,
	Aurelien Jarno

On 2/24/20 10:20 PM, Alistair Francis wrote:
> On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
> <philmd@redhat.com> wrote:
>>
>> This commit was produced with the Coccinelle script
>> scripts/coccinelle/memory-region-housekeeping.cocci.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
> This looks good for the ROM regions, for the flash regions this
> doesn't change the current functionality but I'm not sure it's any
> clearer.

Less code makes easier review.

These regions behave as ROM on the bus, any write to the address space 
is illegal (they are programmable via I/O registers in another address 
space).

> 
> Either way though:
> 
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Thanks, do you want me to improve the commit description?

> 
> Alistair
> 
>> ---
>>   hw/arm/exynos4210.c | 3 +--
>>   hw/arm/mainstone.c  | 3 +--
>>   hw/arm/omap_sx1.c   | 6 ++----
>>   hw/arm/palm.c       | 3 +--
>>   hw/arm/spitz.c      | 3 +--
>>   hw/arm/stellaris.c  | 3 +--
>>   hw/arm/tosa.c       | 3 +--
>>   7 files changed, 8 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
>> index 59a27bdd68..3af6502a5e 100644
>> --- a/hw/arm/exynos4210.c
>> +++ b/hw/arm/exynos4210.c
>> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
>>                                   &s->chipid_mem);
>>
>>       /* Internal ROM */
>> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
>> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
>>                              EXYNOS4210_IROM_SIZE, &error_fatal);
>> -    memory_region_set_readonly(&s->irom_mem, true);
>>       memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
>>                                   &s->irom_mem);
>>       /* mirror of iROM */
>> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
>> index 6e64dfab50..05a806b422 100644
>> --- a/hw/arm/mainstone.c
>> +++ b/hw/arm/mainstone.c
>> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
>>       /* Setup CPU & memory */
>>       mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
>>                         machine->cpu_type);
>> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
>>                              &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>   #ifdef TARGET_WORDS_BIGENDIAN
>> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
>> index be245714db..6c3fd1b271 100644
>> --- a/hw/arm/omap_sx1.c
>> +++ b/hw/arm/omap_sx1.c
>> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
>>       mpu = omap310_mpu_init(dram, machine->cpu_type);
>>
>>       /* External Flash (EMIFS) */
>> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
>> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
>>
>>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
>> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
>>       if ((version == 1) &&
>>               (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
>>           MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
>> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
>> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
>>                                  flash1_size, &error_fatal);
>> -        memory_region_set_readonly(flash_1, true);
>>           memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
>>
>>           memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
>> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
>> index 72eca8cc55..265d5891a6 100644
>> --- a/hw/arm/palm.c
>> +++ b/hw/arm/palm.c
>> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
>>       mpu = omap310_mpu_init(dram, machine->cpu_type);
>>
>>       /* External Flash (EMIFS) */
>> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
>> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
>>
>>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
>> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
>> index e001088103..1d27399721 100644
>> --- a/hw/arm/spitz.c
>> +++ b/hw/arm/spitz.c
>> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
>>
>>       sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
>>
>> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>       /* Setup peripherals */
>> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
>> index 221a78674e..d136ba1a92 100644
>> --- a/hw/arm/stellaris.c
>> +++ b/hw/arm/stellaris.c
>> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
>>       sram_size = ((board->dc0 >> 18) + 1) * 1024;
>>
>>       /* Flash programming is done via the SCU, so pretend it is ROM.  */
>> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
>> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
>>                              &error_fatal);
>> -    memory_region_set_readonly(flash, true);
>>       memory_region_add_subregion(system_memory, 0, flash);
>>
>>       memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
>> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
>> index 4d95a1f3e2..5dee2d76c6 100644
>> --- a/hw/arm/tosa.c
>> +++ b/hw/arm/tosa.c
>> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
>>
>>       mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
>>
>> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>> -    memory_region_set_readonly(rom, true);
>> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
>>       memory_region_add_subregion(address_space_mem, 0, rom);
>>
>>       tmio = tc6393xb_init(address_space_mem, 0x10000000,
>> --
>> 2.21.1
>>
>>
> 



^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
  2020-02-25 10:02       ` Philippe Mathieu-Daudé
@ 2020-02-25 16:15         ` Alistair Francis
  -1 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-25 16:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, qemu-devel@nongnu.org Developers,
	KONRAD Frederic, Alistair Francis, Edgar E. Iglesias,
	Subbaraya Sundeep, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Marc-André Lureau,
	Aleksandar Rikalo, David Gibson, Artyom Tarasenko,
	Eduardo Habkost, Jean-Christophe Dubois, Alistair Francis,
	Fabien Chouteau, qemu-arm, Peter Chubb, open list:New World,
	Richard Henderson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Bastian Koppelmann, Laurent Vivier, Max Reitz, Michael Walle,
	Palmer Dabbelt, Aleksandar Markovic, Paolo Bonzini,
	Aurelien Jarno

On Tue, Feb 25, 2020 at 2:02 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 2/24/20 10:20 PM, Alistair Francis wrote:
> > On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
> > <philmd@redhat.com> wrote:
> >>
> >> This commit was produced with the Coccinelle script
> >> scripts/coccinelle/memory-region-housekeeping.cocci.
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >
> > This looks good for the ROM regions, for the flash regions this
> > doesn't change the current functionality but I'm not sure it's any
> > clearer.
>
> Less code makes easier review.
>
> These regions behave as ROM on the bus, any write to the address space
> is illegal (they are programmable via I/O registers in another address
> space).

Good point.

>
> >
> > Either way though:
> >
> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>
> Thanks, do you want me to improve the commit description?

Nope, it's fine :)

Alistair

>
> >
> > Alistair
> >
> >> ---
> >>   hw/arm/exynos4210.c | 3 +--
> >>   hw/arm/mainstone.c  | 3 +--
> >>   hw/arm/omap_sx1.c   | 6 ++----
> >>   hw/arm/palm.c       | 3 +--
> >>   hw/arm/spitz.c      | 3 +--
> >>   hw/arm/stellaris.c  | 3 +--
> >>   hw/arm/tosa.c       | 3 +--
> >>   7 files changed, 8 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
> >> index 59a27bdd68..3af6502a5e 100644
> >> --- a/hw/arm/exynos4210.c
> >> +++ b/hw/arm/exynos4210.c
> >> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
> >>                                   &s->chipid_mem);
> >>
> >>       /* Internal ROM */
> >> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
> >> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
> >>                              EXYNOS4210_IROM_SIZE, &error_fatal);
> >> -    memory_region_set_readonly(&s->irom_mem, true);
> >>       memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
> >>                                   &s->irom_mem);
> >>       /* mirror of iROM */
> >> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> >> index 6e64dfab50..05a806b422 100644
> >> --- a/hw/arm/mainstone.c
> >> +++ b/hw/arm/mainstone.c
> >> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
> >>       /* Setup CPU & memory */
> >>       mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
> >>                         machine->cpu_type);
> >> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> >> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>   #ifdef TARGET_WORDS_BIGENDIAN
> >> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> >> index be245714db..6c3fd1b271 100644
> >> --- a/hw/arm/omap_sx1.c
> >> +++ b/hw/arm/omap_sx1.c
> >> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
> >>       mpu = omap310_mpu_init(dram, machine->cpu_type);
> >>
> >>       /* External Flash (EMIFS) */
> >> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
> >>
> >>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
> >> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
> >>       if ((version == 1) &&
> >>               (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
> >>           MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
> >> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
> >> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
> >>                                  flash1_size, &error_fatal);
> >> -        memory_region_set_readonly(flash_1, true);
> >>           memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
> >>
> >>           memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
> >> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
> >> index 72eca8cc55..265d5891a6 100644
> >> --- a/hw/arm/palm.c
> >> +++ b/hw/arm/palm.c
> >> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
> >>       mpu = omap310_mpu_init(dram, machine->cpu_type);
> >>
> >>       /* External Flash (EMIFS) */
> >> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
> >>
> >>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
> >> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
> >> index e001088103..1d27399721 100644
> >> --- a/hw/arm/spitz.c
> >> +++ b/hw/arm/spitz.c
> >> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
> >>
> >>       sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
> >>
> >> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>       /* Setup peripherals */
> >> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> >> index 221a78674e..d136ba1a92 100644
> >> --- a/hw/arm/stellaris.c
> >> +++ b/hw/arm/stellaris.c
> >> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
> >>       sram_size = ((board->dc0 >> 18) + 1) * 1024;
> >>
> >>       /* Flash programming is done via the SCU, so pretend it is ROM.  */
> >> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(system_memory, 0, flash);
> >>
> >>       memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
> >> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
> >> index 4d95a1f3e2..5dee2d76c6 100644
> >> --- a/hw/arm/tosa.c
> >> +++ b/hw/arm/tosa.c
> >> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
> >>
> >>       mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
> >>
> >> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>       tmio = tc6393xb_init(address_space_mem, 0x10000000,
> >> --
> >> 2.21.1
> >>
> >>
> >
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions
@ 2020-02-25 16:15         ` Alistair Francis
  0 siblings, 0 replies; 26+ messages in thread
From: Alistair Francis @ 2020-02-25 16:15 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel@nongnu.org Developers,
	Sagar Karandikar, Michael S. Tsirkin, Jason Wang,
	Mark Cave-Ayland, KONRAD Frederic, Alistair Francis,
	Edgar E. Iglesias, Max Reitz, Qemu-block, Magnus Damm,
	Hervé Poussineau, Joel Stanley, Palmer Dabbelt,
	Aleksandar Rikalo, Richard Henderson, Artyom Tarasenko,
	Eduardo Habkost, Alistair Francis, Fabien Chouteau, qemu-arm,
	Peter Chubb, Marc-André Lureau, Subbaraya Sundeep,
	David Gibson, Kevin Wolf, open list:RISC-V, Igor Mitsyanko,
	Laurent Vivier, Jean-Christophe Dubois, Michael Walle,
	open list:New World, Aleksandar Markovic, Bastian Koppelmann,
	Aurelien Jarno

On Tue, Feb 25, 2020 at 2:02 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 2/24/20 10:20 PM, Alistair Francis wrote:
> > On Mon, Feb 24, 2020 at 12:51 PM Philippe Mathieu-Daudé
> > <philmd@redhat.com> wrote:
> >>
> >> This commit was produced with the Coccinelle script
> >> scripts/coccinelle/memory-region-housekeeping.cocci.
> >>
> >> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> >
> > This looks good for the ROM regions, for the flash regions this
> > doesn't change the current functionality but I'm not sure it's any
> > clearer.
>
> Less code makes easier review.
>
> These regions behave as ROM on the bus, any write to the address space
> is illegal (they are programmable via I/O registers in another address
> space).

Good point.

>
> >
> > Either way though:
> >
> > Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
>
> Thanks, do you want me to improve the commit description?

Nope, it's fine :)

Alistair

>
> >
> > Alistair
> >
> >> ---
> >>   hw/arm/exynos4210.c | 3 +--
> >>   hw/arm/mainstone.c  | 3 +--
> >>   hw/arm/omap_sx1.c   | 6 ++----
> >>   hw/arm/palm.c       | 3 +--
> >>   hw/arm/spitz.c      | 3 +--
> >>   hw/arm/stellaris.c  | 3 +--
> >>   hw/arm/tosa.c       | 3 +--
> >>   7 files changed, 8 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c
> >> index 59a27bdd68..3af6502a5e 100644
> >> --- a/hw/arm/exynos4210.c
> >> +++ b/hw/arm/exynos4210.c
> >> @@ -311,9 +311,8 @@ static void exynos4210_realize(DeviceState *socdev, Error **errp)
> >>                                   &s->chipid_mem);
> >>
> >>       /* Internal ROM */
> >> -    memory_region_init_ram(&s->irom_mem, NULL, "exynos4210.irom",
> >> +    memory_region_init_rom(&s->irom_mem, NULL, "exynos4210.irom",
> >>                              EXYNOS4210_IROM_SIZE, &error_fatal);
> >> -    memory_region_set_readonly(&s->irom_mem, true);
> >>       memory_region_add_subregion(system_mem, EXYNOS4210_IROM_BASE_ADDR,
> >>                                   &s->irom_mem);
> >>       /* mirror of iROM */
> >> diff --git a/hw/arm/mainstone.c b/hw/arm/mainstone.c
> >> index 6e64dfab50..05a806b422 100644
> >> --- a/hw/arm/mainstone.c
> >> +++ b/hw/arm/mainstone.c
> >> @@ -125,9 +125,8 @@ static void mainstone_common_init(MemoryRegion *address_space_mem,
> >>       /* Setup CPU & memory */
> >>       mpu = pxa270_init(address_space_mem, mainstone_binfo.ram_size,
> >>                         machine->cpu_type);
> >> -    memory_region_init_ram(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> >> +    memory_region_init_rom(rom, NULL, "mainstone.rom", MAINSTONE_ROM,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>   #ifdef TARGET_WORDS_BIGENDIAN
> >> diff --git a/hw/arm/omap_sx1.c b/hw/arm/omap_sx1.c
> >> index be245714db..6c3fd1b271 100644
> >> --- a/hw/arm/omap_sx1.c
> >> +++ b/hw/arm/omap_sx1.c
> >> @@ -126,9 +126,8 @@ static void sx1_init(MachineState *machine, const int version)
> >>       mpu = omap310_mpu_init(dram, machine->cpu_type);
> >>
> >>       /* External Flash (EMIFS) */
> >> -    memory_region_init_ram(flash, NULL, "omap_sx1.flash0-0", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "omap_sx1.flash0-0", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(address_space, OMAP_CS0_BASE, flash);
> >>
> >>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val,
> >> @@ -168,9 +167,8 @@ static void sx1_init(MachineState *machine, const int version)
> >>       if ((version == 1) &&
> >>               (dinfo = drive_get(IF_PFLASH, 0, fl_idx)) != NULL) {
> >>           MemoryRegion *flash_1 = g_new(MemoryRegion, 1);
> >> -        memory_region_init_ram(flash_1, NULL, "omap_sx1.flash1-0",
> >> +        memory_region_init_rom(flash_1, NULL, "omap_sx1.flash1-0",
> >>                                  flash1_size, &error_fatal);
> >> -        memory_region_set_readonly(flash_1, true);
> >>           memory_region_add_subregion(address_space, OMAP_CS1_BASE, flash_1);
> >>
> >>           memory_region_init_io(&cs[1], NULL, &static_ops, &cs1val,
> >> diff --git a/hw/arm/palm.c b/hw/arm/palm.c
> >> index 72eca8cc55..265d5891a6 100644
> >> --- a/hw/arm/palm.c
> >> +++ b/hw/arm/palm.c
> >> @@ -206,9 +206,8 @@ static void palmte_init(MachineState *machine)
> >>       mpu = omap310_mpu_init(dram, machine->cpu_type);
> >>
> >>       /* External Flash (EMIFS) */
> >> -    memory_region_init_ram(flash, NULL, "palmte.flash", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "palmte.flash", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(address_space_mem, OMAP_CS0_BASE, flash);
> >>
> >>       memory_region_init_io(&cs[0], NULL, &static_ops, &cs0val, "palmte-cs0",
> >> diff --git a/hw/arm/spitz.c b/hw/arm/spitz.c
> >> index e001088103..1d27399721 100644
> >> --- a/hw/arm/spitz.c
> >> +++ b/hw/arm/spitz.c
> >> @@ -924,8 +924,7 @@ static void spitz_common_init(MachineState *machine,
> >>
> >>       sl_flash_register(mpu, (model == spitz) ? FLASH_128M : FLASH_1024M);
> >>
> >> -    memory_region_init_ram(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >> +    memory_region_init_rom(rom, NULL, "spitz.rom", SPITZ_ROM, &error_fatal);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>       /* Setup peripherals */
> >> diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c
> >> index 221a78674e..d136ba1a92 100644
> >> --- a/hw/arm/stellaris.c
> >> +++ b/hw/arm/stellaris.c
> >> @@ -1300,9 +1300,8 @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board)
> >>       sram_size = ((board->dc0 >> 18) + 1) * 1024;
> >>
> >>       /* Flash programming is done via the SCU, so pretend it is ROM.  */
> >> -    memory_region_init_ram(flash, NULL, "stellaris.flash", flash_size,
> >> +    memory_region_init_rom(flash, NULL, "stellaris.flash", flash_size,
> >>                              &error_fatal);
> >> -    memory_region_set_readonly(flash, true);
> >>       memory_region_add_subregion(system_memory, 0, flash);
> >>
> >>       memory_region_init_ram(sram, NULL, "stellaris.sram", sram_size,
> >> diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c
> >> index 4d95a1f3e2..5dee2d76c6 100644
> >> --- a/hw/arm/tosa.c
> >> +++ b/hw/arm/tosa.c
> >> @@ -226,8 +226,7 @@ static void tosa_init(MachineState *machine)
> >>
> >>       mpu = pxa255_init(address_space_mem, tosa_binfo.ram_size);
> >>
> >> -    memory_region_init_ram(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> >> -    memory_region_set_readonly(rom, true);
> >> +    memory_region_init_rom(rom, NULL, "tosa.rom", TOSA_ROM, &error_fatal);
> >>       memory_region_add_subregion(address_space_mem, 0, rom);
> >>
> >>       tmio = tc6393xb_init(address_space_mem, 0x10000000,
> >> --
> >> 2.21.1
> >>
> >>
> >
>


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-02-25 16:17 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24 20:47 [PATCH v2 00/32] hw: Sanitize various MemoryRegion uses Philippe Mathieu-Daudé
2020-02-24 20:47 ` Philippe Mathieu-Daudé
2020-02-24 20:47 ` [PATCH v2 01/32] memory: Correctly return alias region type Philippe Mathieu-Daudé
2020-02-24 20:47   ` Philippe Mathieu-Daudé
2020-02-24 21:14   ` Alistair Francis
2020-02-24 21:14     ` Alistair Francis
2020-02-24 20:47 ` [PATCH v2 02/32] memory: Simplify memory_region_init_rom_nomigrate() to ease review Philippe Mathieu-Daudé
2020-02-24 20:47   ` Philippe Mathieu-Daudé
2020-02-24 20:47 ` [PATCH v2 03/32] scripts/cocci: Rename memory-region-{init-ram -> housekeeping} Philippe Mathieu-Daudé
2020-02-24 20:47   ` Philippe Mathieu-Daudé
2020-02-24 20:48 ` [PATCH v2 04/32] scripts/cocci: Patch to replace memory_region_init_{ram, readonly -> rom} Philippe Mathieu-Daudé
2020-02-24 20:48   ` Philippe Mathieu-Daudé
2020-02-24 20:48 ` [PATCH v2 05/32] hw/arm: Use memory_region_init_rom() with read-only regions Philippe Mathieu-Daudé
2020-02-24 20:48   ` Philippe Mathieu-Daudé
2020-02-24 21:20   ` Alistair Francis
2020-02-24 21:20     ` Alistair Francis
2020-02-25 10:02     ` Philippe Mathieu-Daudé
2020-02-25 10:02       ` Philippe Mathieu-Daudé
2020-02-25 16:15       ` Alistair Francis
2020-02-25 16:15         ` Alistair Francis
2020-02-24 20:48 ` [PATCH v2 06/32] hw/display: " Philippe Mathieu-Daudé
2020-02-24 20:48   ` Philippe Mathieu-Daudé
2020-02-24 20:48 ` [PATCH v2 07/32] hw/mips: " Philippe Mathieu-Daudé
2020-02-24 20:48   ` Philippe Mathieu-Daudé
2020-02-24 20:48 ` [PATCH v2 08/32] hw/m68k: " Philippe Mathieu-Daudé
2020-02-24 20:48   ` Philippe Mathieu-Daudé

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.