|
32 | 32 | #include "exec/address-spaces.h"
|
33 | 33 | #include "trace.h"
|
34 | 34 |
|
35 |
| -typedef struct MemoryRegionPortioList { |
| 35 | +struct MemoryRegionPortioList { |
| 36 | + Object obj; |
| 37 | + |
36 | 38 | MemoryRegion mr;
|
37 | 39 | void *portio_opaque;
|
38 | 40 | MemoryRegionPortio *ports;
|
39 |
| -} MemoryRegionPortioList; |
| 41 | +}; |
| 42 | + |
| 43 | +#define TYPE_MEMORY_REGION_PORTIO_LIST "memory-region-portio-list" |
| 44 | +OBJECT_DECLARE_SIMPLE_TYPE(MemoryRegionPortioList, MEMORY_REGION_PORTIO_LIST) |
40 | 45 |
|
41 | 46 | static uint64_t unassigned_io_read(void *opaque, hwaddr addr, unsigned size)
|
42 | 47 | {
|
@@ -147,8 +152,7 @@ void portio_list_destroy(PortioList *piolist)
|
147 | 152 | for (i = 0; i < piolist->nr; ++i) {
|
148 | 153 | mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
|
149 | 154 | object_unparent(OBJECT(&mrpio->mr));
|
150 |
| - g_free(mrpio->ports); |
151 |
| - g_free(mrpio); |
| 155 | + object_unref(mrpio); |
152 | 156 | }
|
153 | 157 | g_free(piolist->regions);
|
154 | 158 | }
|
@@ -228,7 +232,8 @@ static void portio_list_add_1(PortioList *piolist,
|
228 | 232 | unsigned i;
|
229 | 233 |
|
230 | 234 | /* Copy the sub-list and null-terminate it. */
|
231 |
| - mrpio = g_malloc0(sizeof(MemoryRegionPortioList)); |
| 235 | + mrpio = MEMORY_REGION_PORTIO_LIST( |
| 236 | + object_new(TYPE_MEMORY_REGION_PORTIO_LIST)); |
232 | 237 | mrpio->portio_opaque = piolist->opaque;
|
233 | 238 | mrpio->ports = g_malloc0(sizeof(MemoryRegionPortio) * (count + 1));
|
234 | 239 | memcpy(mrpio->ports, pio_init, sizeof(MemoryRegionPortio) * count);
|
@@ -298,3 +303,24 @@ void portio_list_del(PortioList *piolist)
|
298 | 303 | memory_region_del_subregion(piolist->address_space, &mrpio->mr);
|
299 | 304 | }
|
300 | 305 | }
|
| 306 | + |
| 307 | +static void memory_region_portio_list_finalize(Object *obj) |
| 308 | +{ |
| 309 | + MemoryRegionPortioList *mrpio = MEMORY_REGION_PORTIO_LIST(obj); |
| 310 | + |
| 311 | + g_free(mrpio->ports); |
| 312 | +} |
| 313 | + |
| 314 | +static const TypeInfo memory_region_portio_list_info = { |
| 315 | + .parent = TYPE_OBJECT, |
| 316 | + .name = TYPE_MEMORY_REGION_PORTIO_LIST, |
| 317 | + .instance_size = sizeof(MemoryRegionPortioList), |
| 318 | + .instance_finalize = memory_region_portio_list_finalize, |
| 319 | +}; |
| 320 | + |
| 321 | +static void ioport_register_types(void) |
| 322 | +{ |
| 323 | + type_register_static(&memory_region_portio_list_info); |
| 324 | +} |
| 325 | + |
| 326 | +type_init(ioport_register_types) |
0 commit comments