qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: qemu-devel@nongnu.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Subject: [Qemu-devel] [patch 12/18] qemu: add pci_unregister_device
Date: Wed, 04 Feb 2009 11:33:15 -0200	[thread overview]
Message-ID: <20090204133924.314509077@localhost.localdomain> (raw)
In-Reply-To: 20090204133303.113145633@localhost.localdomain

[-- Attachment #1: pci-unregister --]
[-- Type: text/plain, Size: 3221 bytes --]

Unregister the pci device, unassign its IO and memory regions, and free
associated data.

Add a callback so drivers can free device state.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

Index: trunk/hw/pci.c
===================================================================
--- trunk.orig/hw/pci.c
+++ trunk/hw/pci.c
@@ -198,6 +198,48 @@ PCIDevice *pci_register_device(PCIBus *b
     return pci_dev;
 }
 
+static target_phys_addr_t pci_to_cpu_addr(target_phys_addr_t addr)
+{
+    return addr + pci_mem_base;
+}
+
+static void pci_unregister_io_regions(PCIDevice *pci_dev)
+{
+    PCIIORegion *r;
+    int i;
+
+    for(i = 0; i < PCI_NUM_REGIONS; i++) {
+        r = &pci_dev->io_regions[i];
+        if (!r->size || r->addr == -1)
+            continue;
+        if (r->type == PCI_ADDRESS_SPACE_IO) {
+            isa_unassign_ioport(r->addr, r->size);
+        } else {
+            cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+                                                     r->size,
+                                                     IO_MEM_UNASSIGNED);
+        }
+    }
+}
+
+int pci_unregister_device(PCIDevice *pci_dev)
+{
+    int ret = 0;
+
+    if (pci_dev->unregister)
+        ret = pci_dev->unregister(pci_dev);
+    if (ret)
+        return ret;
+
+    pci_unregister_io_regions(pci_dev);
+
+    qemu_free_irqs(pci_dev->irq);
+    pci_irq_index--;
+    pci_dev->bus->devices[pci_dev->devfn] = NULL;
+    qemu_free(pci_dev);
+    return 0;
+}
+
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,
                             PCIMapIORegionFunc *map_func)
@@ -220,11 +262,6 @@ void pci_register_io_region(PCIDevice *p
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
 }
 
-static target_phys_addr_t pci_to_cpu_addr(target_phys_addr_t addr)
-{
-    return addr + pci_mem_base;
-}
-
 static void pci_update_mappings(PCIDevice *d)
 {
     PCIIORegion *r;
Index: trunk/hw/pci.h
===================================================================
--- trunk.orig/hw/pci.h
+++ trunk/hw/pci.h
@@ -125,6 +125,7 @@ typedef uint32_t PCIConfigReadFunc(PCIDe
                                    uint32_t address, int len);
 typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num,
                                 uint32_t addr, uint32_t size, int type);
+typedef int PCIUnregisterFunc(PCIDevice *pci_dev);
 
 #define PCI_ADDRESS_SPACE_MEM		0x00
 #define PCI_ADDRESS_SPACE_IO		0x01
@@ -189,6 +190,7 @@ struct PCIDevice {
     /* do not access the following fields */
     PCIConfigReadFunc *config_read;
     PCIConfigWriteFunc *config_write;
+    PCIUnregisterFunc *unregister;
     /* ??? This is a PC-specific hack, and should be removed.  */
     int irq_index;
 
@@ -203,6 +205,7 @@ PCIDevice *pci_register_device(PCIBus *b
                                int instance_size, int devfn,
                                PCIConfigReadFunc *config_read,
                                PCIConfigWriteFunc *config_write);
+int pci_unregister_device(PCIDevice *pci_dev);
 
 void pci_register_io_region(PCIDevice *pci_dev, int region_num,
                             uint32_t size, int type,

-- 

  parent reply	other threads:[~2009-02-04 13:46 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-04 13:33 [Qemu-devel] [patch 00/18] acpi pci hotplug support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 01/18] qemu: add pci helper functions Marcelo Tosatti
2009-02-04 14:56   ` Paul Brook
2009-02-04 19:15     ` Anthony Liguori
2009-02-06 17:35       ` Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 02/18] qemu: return PCIDevice on net device init and record devfn Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 03/18] qemu: dynamic drive/drive_opt index allocation Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 04/18] qemu: dynamic nic info " Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 05/18] qemu: drive removal support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 06/18] qemu: record devfn on block driver instance Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 07/18] qemu: move drives_opt for external use Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 08/18] qemu: net/drive add/remove tweaks Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 09/18] qemu: add net_client_uninit / qemu_find_vlan_client Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 10/18] qemu: add cpu_unregister_io_memory and make io mem table index dynamic Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 11/18] qemu: add qemu_free_irqs Marcelo Tosatti
2009-02-04 13:33 ` Marcelo Tosatti [this message]
2009-02-04 13:33 ` [Qemu-devel] [patch 13/18] qemu: warn if PCI region is not power of two Marcelo Tosatti
2009-02-04 14:38   ` Paul Brook
2009-02-06 17:34     ` Marcelo Tosatti
2009-02-08  6:08       ` malc
2009-02-08 17:20         ` Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 14/18] qemu: LSI SCSI and e1000 unregister callbacks Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 15/18] qemu: zero ioport_opaque on isa_unassign_ioport Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 16/18] qemu: initialize hot add system / acpi gpe Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 17/18] qemu: pci hotplug GPE support Marcelo Tosatti
2009-02-04 13:33 ` [Qemu-devel] [patch 18/18] qemu: PCI device, disk and host network hot-add / hot-remove Marcelo Tosatti
2009-02-04 14:38   ` Daniel P. Berrange
2009-02-04 15:21     ` Anthony Liguori
2009-02-04 15:37       ` Daniel P. Berrange
2009-02-04 15:59       ` Avi Kivity
2009-02-04 16:46         ` Anthony Liguori
2009-02-04 14:59   ` Paul Brook
2009-02-04 16:17   ` Markus Armbruster
2009-02-04 17:47   ` Blue Swirl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090204133924.314509077@localhost.localdomain \
    --to=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).