[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/7] scripts/coccinelle: Add a script to let devices own their Me
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 1/7] scripts/coccinelle: Add a script to let devices own their MemoryRegions |
Date: |
Fri, 21 Feb 2020 18:30:43 +0100 |
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 coccinelle script to do automatic semantic patching.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
.../memory_region_owner_nonnull.cocci | 80 +++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100644 scripts/coccinelle/memory_region_owner_nonnull.cocci
diff --git a/scripts/coccinelle/memory_region_owner_nonnull.cocci
b/scripts/coccinelle/memory_region_owner_nonnull.cocci
new file mode 100644
index 0000000000..6748a200b2
--- /dev/null
+++ b/scripts/coccinelle/memory_region_owner_nonnull.cocci
@@ -0,0 +1,80 @@
+/*
+ Usage:
+
+ spatch \
+ --macro-file scripts/cocci-macro-file.h \
+ --sp-file scripts/coccinelle/memory_region_owner_nonnull.cocci \
+ --keep-comments \
+ --in-place \
+ --dir .
+
+*/
+
+// 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(E1, NULL, E2, E3, E4);
++ memory_region_init_ram(E1, obj, E2, E3, E4);
+|
+- memory_region_init_ram_ptr(E1, NULL, E2, E3, E4);
++ memory_region_init_ram_ptr(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);
+)
+ ...+>
+}
+
+// Device is owner
+@@
+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(E1, NULL, E2, E3, E4);
++ memory_region_init_ram(E1, OBJECT(dev), E2, E3, E4);
+|
+- memory_region_init_ram_ptr(E1, NULL, E2, E3, E4);
++ memory_region_init_ram_ptr(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);
+)
+ ...+>
+}
--
2.21.1
- [PATCH 0/7] hw: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 1/7] scripts/coccinelle: Add a script to let devices own their MemoryRegions,
Philippe Mathieu-Daudé <=
- [PATCH 3/7] hw/char: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 2/7] hw/arm: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 4/7] hw/core: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 5/7] hw/display: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 6/7] hw/dma: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21
- [PATCH 7/7] hw/riscv: Let devices own the MemoryRegion they create, Philippe Mathieu-Daudé, 2020/02/21