Received: from eggs.gnu.org ([2001:4830:134:3::10]:54597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrmNw-0000gk-7y for qemu-devel@nongnu.org; Tue, 03 Jun 2014 06:56:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrmNr-0005yR-Ao for qemu-devel@nongnu.org; Tue, 03 Jun 2014 06:56:04 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:8302) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrmNq-0005ur-Lo for qemu-devel@nongnu.org; Tue, 03 Jun 2014 06:55:59 -0400 From: Date: Tue, 3 Jun 2014 18:54:23 +0800 Message-ID: <1401792864-4656-9-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1401792864-4656-1-git-send-email-arei.gonglei@huawei.com> References: <1401792864-4656-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 8/9] usb-xhci: add exit function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: weidong.huang@huawei.com, Gonglei , luonengjun@huawei.com, kraxel@redhat.com, peter.huangpeng@huawei.com From: Gonglei clean up xhci resource when xhci pci device exit. Signed-off-by: Gonglei --- hw/usb/hcd-xhci.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 54dea16..da8a1fb 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3617,6 +3617,51 @@ static int usb_xhci_initfn(struct PCIDevice *dev) return 0; } +static void usb_xhci_exit(PCIDevice *dev) +{ + int i; + XHCIState *xhci = XHCI(dev); + + for (i = 0; i < xhci->numslots; i++) { + xhci_disable_slot(xhci, i + 1); + } + + if (xhci->mfwrap_timer) { + timer_del(xhci->mfwrap_timer); + timer_free(xhci->mfwrap_timer); + xhci->mfwrap_timer = NULL; + } + + memory_region_del_subregion(&xhci->mem, &xhci->mem_cap); + memory_region_del_subregion(&xhci->mem, &xhci->mem_oper); + memory_region_del_subregion(&xhci->mem, &xhci->mem_runtime); + memory_region_del_subregion(&xhci->mem, &xhci->mem_doorbell); + + memory_region_destroy(&xhci->mem_cap); + memory_region_destroy(&xhci->mem_oper); + memory_region_destroy(&xhci->mem_runtime); + memory_region_destroy(&xhci->mem_doorbell); + + for (i = 0; i < xhci->numports; i++) { + XHCIPort *port = &xhci->ports[i]; + memory_region_del_subregion(&xhci->mem, &port->mem); + memory_region_destroy(&port->mem); + } + + /* destroy msix memory region */ + if (dev->msix_table && dev->msix_pba + && dev->msix_entry_used) { + memory_region_del_subregion(&xhci->mem, &dev->msix_table_mmio); + memory_region_destroy(&dev->msix_table_mmio); + memory_region_del_subregion(&xhci->mem, &dev->msix_pba_mmio); + memory_region_destroy(&dev->msix_pba_mmio); + } + + memory_region_destroy(&xhci->mem); + + usb_bus_release(&xhci->bus); +} + static int usb_xhci_post_load(void *opaque, int version_id) { XHCIState *xhci = opaque; @@ -3806,6 +3851,7 @@ static void xhci_class_init(ObjectClass *klass, void *data) dc->hotpluggable = false; set_bit(DEVICE_CATEGORY_USB, dc->categories); k->init = usb_xhci_initfn; + k->exit = usb_xhci_exit; k->vendor_id = PCI_VENDOR_ID_NEC; k->device_id = PCI_DEVICE_ID_NEC_UPD720200; k->class_id = PCI_CLASS_SERIAL_USB; -- 1.7.12.4