scripts/cocci: Patch to let devices own their MemoryRegions

When a device creates a MemoryRegion without setting its ownership,
the MemoryRegion is added to the machine "/unattached" container in
the QOM tree.

Example with the Samsung SMDKC210 board:

  $ arm-softmmu/qemu-system-arm -M smdkc210 -S -monitor stdio
  (qemu) info qom-tree
  /machine (smdkc210-machine)
    /unattached (container)
      /io[0] (qemu:memory-region)
      /exynos4210.dram0[0] (qemu:memory-region)
      /exynos4210.irom[0] (qemu:memory-region)
      /exynos4210.iram[0] (qemu:memory-region)
      /exynos4210.chipid[0] (qemu:memory-region)
      ...
      /device[26] (exynos4210.uart)
        /exynos4210.uart[0] (qemu:memory-region)
    /soc (exynos4210)
      ^
       \__ [*]

The irom/iram/chipid regions should go under 'soc' at [*].

Add a semantic patch to let the device own the memory region.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2020-02-21 16:05:08 +01:00 committed by Paolo Bonzini
parent bb2f4e8d77
commit 84969111e6

View File

@ -101,3 +101,59 @@ expression ERRP;
+memory_region_init_rom_device(MR, NULL, OPS, OPAQUE, NAME, SIZE, ERRP);
...
-vmstate_register_ram_global(MR);
// Device is owner
@@
typedef DeviceState;
identifier device_fn, dev, obj;
expression E1, E2, E3, E4, E5;
@@
static void device_fn(DeviceState *dev, ...)
{
...
Object *obj = OBJECT(dev);
<+...
(
- memory_region_init(E1, NULL, E2, E3);
+ memory_region_init(E1, obj, E2, E3);
|
- memory_region_init_io(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_io(E1, obj, E2, E3, E4, E5);
|
- memory_region_init_alias(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_alias(E1, obj, E2, E3, E4, E5);
|
- memory_region_init_rom(E1, NULL, E2, E3, E4);
+ memory_region_init_rom(E1, obj, E2, E3, E4);
|
- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_ram_shared_nomigrate(E1, obj, E2, E3, E4, E5);
)
...+>
}
@@
identifier device_fn, dev;
expression E1, E2, E3, E4, E5;
@@
static void device_fn(DeviceState *dev, ...)
{
<+...
(
- memory_region_init(E1, NULL, E2, E3);
+ memory_region_init(E1, OBJECT(dev), E2, E3);
|
- memory_region_init_io(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_io(E1, OBJECT(dev), E2, E3, E4, E5);
|
- memory_region_init_alias(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_alias(E1, OBJECT(dev), E2, E3, E4, E5);
|
- memory_region_init_rom(E1, NULL, E2, E3, E4);
+ memory_region_init_rom(E1, OBJECT(dev), E2, E3, E4);
|
- memory_region_init_ram_shared_nomigrate(E1, NULL, E2, E3, E4, E5);
+ memory_region_init_ram_shared_nomigrate(E1, OBJECT(dev), E2, E3, E4, E5);
)
...+>
}