Browse Source

memory: convert memory_region_destroy to object_unparent

Explicitly call object_unparent in the few places where we
will re-create the memory region.  If the memory region is
simply being destroyed as part of device teardown, let QOM
handle it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini 11 years ago
parent
commit
d8d9581460
9 changed files with 18 additions and 14 deletions
  1. 10 5
      docs/memory.txt
  2. 1 1
      hw/display/vga.c
  3. 1 1
      hw/i386/kvmvapic.c
  4. 1 1
      hw/mips/gt64xxx_pci.c
  5. 1 1
      hw/misc/omap_gpmc.c
  6. 2 2
      hw/misc/vfio.c
  7. 1 1
      hw/ppc/ppc4xx_devs.c
  8. 1 1
      ioport.c
  9. 0 1
      memory.c

+ 10 - 5
docs/memory.txt

@@ -74,11 +74,16 @@ Region lifecycle
 ----------------
 ----------------
 
 
 A region is created by one of the constructor functions (memory_region_init*())
 A region is created by one of the constructor functions (memory_region_init*())
-and destroyed by the destructor (memory_region_destroy()).  In between,
-a region can be added to an address space by using memory_region_add_subregion()
-and removed using memory_region_del_subregion().  Region attributes may be
-changed at any point; they take effect once the region becomes exposed to the
-guest.
+and attached to an object.  It is then destroyed by object_unparent() or simply
+when the parent object dies.
+
+In between, a region can be added to an address space
+by using memory_region_add_subregion() and removed using
+memory_region_del_subregion().  Destroying the region implicitly
+removes the region from the address space.
+
+Region attributes may be changed at any point; they take effect once
+the region becomes exposed to the guest.
 
 
 Overlapping regions and priority
 Overlapping regions and priority
 --------------------------------
 --------------------------------

+ 1 - 1
hw/display/vga.c

@@ -176,7 +176,7 @@ static void vga_update_memory_access(VGACommonState *s)
 
 
     if (s->has_chain4_alias) {
     if (s->has_chain4_alias) {
         memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
         memory_region_del_subregion(s->legacy_address_space, &s->chain4_alias);
-        memory_region_destroy(&s->chain4_alias);
+        object_unparent(OBJECT(&s->chain4_alias));
         s->has_chain4_alias = false;
         s->has_chain4_alias = false;
         s->plane_updated = 0xf;
         s->plane_updated = 0xf;
     }
     }

+ 1 - 1
hw/i386/kvmvapic.c

@@ -584,7 +584,7 @@ static int vapic_map_rom_writable(VAPICROMState *s)
 
 
     if (s->rom_mapped_writable) {
     if (s->rom_mapped_writable) {
         memory_region_del_subregion(as, &s->rom);
         memory_region_del_subregion(as, &s->rom);
-        memory_region_destroy(&s->rom);
+        object_unparent(OBJECT(&s->rom));
     }
     }
 
 
     /* grab RAM memory region (region @rom_paddr may still be pc.rom) */
     /* grab RAM memory region (region @rom_paddr may still be pc.rom) */

+ 1 - 1
hw/mips/gt64xxx_pci.c

@@ -297,7 +297,7 @@ static void gt64120_pci_mapping(GT64120State *s)
       if (s->PCI0IO_length)
       if (s->PCI0IO_length)
       {
       {
           memory_region_del_subregion(get_system_memory(), &s->PCI0IO_mem);
           memory_region_del_subregion(get_system_memory(), &s->PCI0IO_mem);
-          memory_region_destroy(&s->PCI0IO_mem);
+          object_unparent(OBJECT(&s->PCI0IO_mem));
       }
       }
       /* Map new IO address */
       /* Map new IO address */
       s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
       s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;

+ 1 - 1
hw/misc/omap_gpmc.c

@@ -436,7 +436,7 @@ static void omap_gpmc_cs_unmap(struct omap_gpmc_s *s, int cs)
     }
     }
     memory_region_del_subregion(get_system_memory(), &f->container);
     memory_region_del_subregion(get_system_memory(), &f->container);
     memory_region_del_subregion(&f->container, omap_gpmc_cs_memregion(s, cs));
     memory_region_del_subregion(&f->container, omap_gpmc_cs_memregion(s, cs));
-    memory_region_destroy(&f->container);
+    object_unparent(OBJECT(&f->container));
 }
 }
 
 
 void omap_gpmc_reset(struct omap_gpmc_s *s)
 void omap_gpmc_reset(struct omap_gpmc_s *s)

+ 2 - 2
hw/misc/vfio.c

@@ -2266,7 +2266,7 @@ static void vfio_vga_quirk_teardown(VFIODevice *vdev)
         while (!QLIST_EMPTY(&vdev->vga.region[i].quirks)) {
         while (!QLIST_EMPTY(&vdev->vga.region[i].quirks)) {
             VFIOQuirk *quirk = QLIST_FIRST(&vdev->vga.region[i].quirks);
             VFIOQuirk *quirk = QLIST_FIRST(&vdev->vga.region[i].quirks);
             memory_region_del_subregion(&vdev->vga.region[i].mem, &quirk->mem);
             memory_region_del_subregion(&vdev->vga.region[i].mem, &quirk->mem);
-            memory_region_destroy(&quirk->mem);
+            object_unparent(OBJECT(&quirk->mem));
             QLIST_REMOVE(quirk, next);
             QLIST_REMOVE(quirk, next);
             g_free(quirk);
             g_free(quirk);
         }
         }
@@ -2290,7 +2290,7 @@ static void vfio_bar_quirk_teardown(VFIODevice *vdev, int nr)
     while (!QLIST_EMPTY(&bar->quirks)) {
     while (!QLIST_EMPTY(&bar->quirks)) {
         VFIOQuirk *quirk = QLIST_FIRST(&bar->quirks);
         VFIOQuirk *quirk = QLIST_FIRST(&bar->quirks);
         memory_region_del_subregion(&bar->mem, &quirk->mem);
         memory_region_del_subregion(&bar->mem, &quirk->mem);
-        memory_region_destroy(&quirk->mem);
+        object_unparent(OBJECT(&quirk->mem));
         QLIST_REMOVE(quirk, next);
         QLIST_REMOVE(quirk, next);
         g_free(quirk);
         g_free(quirk);
     }
     }

+ 1 - 1
hw/ppc/ppc4xx_devs.c

@@ -422,7 +422,7 @@ static void sdram_set_bcr(ppc4xx_sdram_t *sdram,
                                     &sdram->containers[n]);
                                     &sdram->containers[n]);
         memory_region_del_subregion(&sdram->containers[n],
         memory_region_del_subregion(&sdram->containers[n],
                                     &sdram->ram_memories[n]);
                                     &sdram->ram_memories[n]);
-        memory_region_destroy(&sdram->containers[n]);
+        object_unparent(OBJECT(&sdram->containers[n]));
     }
     }
     *bcrp = bcr & 0xFFDEE001;
     *bcrp = bcr & 0xFFDEE001;
     if (enabled && (bcr & 0x00000001)) {
     if (enabled && (bcr & 0x00000001)) {

+ 1 - 1
ioport.c

@@ -154,7 +154,7 @@ void portio_list_destroy(PortioList *piolist)
 
 
     for (i = 0; i < piolist->nr; ++i) {
     for (i = 0; i < piolist->nr; ++i) {
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
         mrpio = container_of(piolist->regions[i], MemoryRegionPortioList, mr);
-        memory_region_destroy(&mrpio->mr);
+        object_unparent(OBJECT(&mrpio->mr));
         g_free(mrpio);
         g_free(mrpio);
     }
     }
     g_free(piolist->regions);
     g_free(piolist->regions);

+ 0 - 1
memory.c

@@ -1266,7 +1266,6 @@ static void memory_region_finalize(Object *obj)
 
 
 void memory_region_destroy(MemoryRegion *mr)
 void memory_region_destroy(MemoryRegion *mr)
 {
 {
-    object_unparent(OBJECT(mr));
 }
 }