xref: /openbmc/qemu/scripts/coccinelle/memory-region-housekeeping.cocci (revision cf949cbb7079d3856ba61ceab44880ac88f0d7eb)
1/*
2  Usage:
3
4    spatch \
5        --macro-file scripts/cocci-macro-file.h \
6        --sp-file scripts/coccinelle/memory-region-housekeeping.cocci \
7        --keep-comments \
8        --in-place \
9        --dir .
10
11*/
12
13
14// Replace memory_region_init_ram(readonly) by memory_region_init_rom()
15@@
16expression E1, E2, E3, E4, E5;
17symbol true;
18@@
19(
20- memory_region_init_ram(E1, E2, E3, E4, E5);
21+ memory_region_init_rom(E1, E2, E3, E4, E5);
22  ... WHEN != E1
23- memory_region_set_readonly(E1, true);
24|
25- memory_region_init_ram_nomigrate(E1, E2, E3, E4, E5);
26+ memory_region_init_rom_nomigrate(E1, E2, E3, E4, E5);
27  ... WHEN != E1
28- memory_region_set_readonly(E1, true);
29)
30
31
32@possible_memory_region_init_rom@
33expression E1, E2, E3, E4, E5;
34position p;
35@@
36(
37  memory_region_init_ram@p(E1, E2, E3, E4, E5);
38  ...
39  memory_region_set_readonly(E1, true);
40|
41  memory_region_init_ram_nomigrate@p(E1, E2, E3, E4, E5);
42  ...
43  memory_region_set_readonly(E1, true);
44)
45@script:python@
46p << possible_memory_region_init_rom.p;
47@@
48cocci.print_main("potential use of memory_region_init_rom*() in ", p)
49
50
51// Replace by-hand memory_region_init_ram_nomigrate/vmstate_register_ram
52// code sequences with use of the new memory_region_init_ram function.
53// Similarly for the _rom and _rom_device functions.
54// We don't try to replace sequences with a non-NULL owner, because
55// there are none in the tree that can be automatically converted
56// (and only a handful that can be manually converted).
57@@
58expression MR;
59expression NAME;
60expression SIZE;
61expression ERRP;
62@@
63-memory_region_init_ram_nomigrate(MR, NULL, NAME, SIZE, ERRP);
64+memory_region_init_ram(MR, NULL, NAME, SIZE, ERRP);
65 ...
66-vmstate_register_ram_global(MR);
67@@
68expression MR;
69expression NAME;
70expression SIZE;
71expression ERRP;
72@@
73-memory_region_init_rom_nomigrate(MR, NULL, NAME, SIZE, ERRP);
74+memory_region_init_rom(MR, NULL, NAME, SIZE, ERRP);
75 ...
76-vmstate_register_ram_global(MR);
77@@
78expression MR;
79expression OPS;
80expression OPAQUE;
81expression NAME;
82expression SIZE;
83expression ERRP;
84@@
85-memory_region_init_rom_device_nomigrate(MR, NULL, OPS, OPAQUE, NAME, SIZE, ERRP);
86+memory_region_init_rom_device(MR, NULL, OPS, OPAQUE, NAME, SIZE, ERRP);
87 ...
88-vmstate_register_ram_global(MR);
89