From patchwork Fri May 30 12:22:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 354119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 67BB51400CF for ; Fri, 30 May 2014 22:23:43 +1000 (EST) Received: from localhost ([::1]:53882 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqLqX-000211-9j for incoming@patchwork.ozlabs.org; Fri, 30 May 2014 08:23:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqLpw-0000pD-88 for qemu-devel@nongnu.org; Fri, 30 May 2014 08:23:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WqLpn-0000cs-Uy for qemu-devel@nongnu.org; Fri, 30 May 2014 08:23:04 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:47595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WqLpn-0000bz-6R for qemu-devel@nongnu.org; Fri, 30 May 2014 08:22:55 -0400 Received: from 172.24.2.119 (EHLO szxeml211-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BUM31119; Fri, 30 May 2014 20:22:41 +0800 (CST) Received: from SZXEML422-HUB.china.huawei.com (10.82.67.161) by szxeml211-edg.china.huawei.com (172.24.2.182) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 30 May 2014 20:22:40 +0800 Received: from localhost (10.177.19.102) by szxeml422-hub.china.huawei.com (10.82.67.161) with Microsoft SMTP Server id 14.3.158.1; Fri, 30 May 2014 20:22:31 +0800 From: To: Date: Fri, 30 May 2014 20:22:21 +0800 Message-ID: <1401452542-11080-6-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1401452542-11080-1-git-send-email-arei.gonglei@huawei.com> References: <1401452542-11080-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Cc: weidong.huang@huawei.com, Gonglei , luonengjun@huawei.com, kraxel@redhat.com, peter.huangpeng@huawei.com Subject: [Qemu-devel] [PATCH 5/6] usb-xhci: add exit function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei clean up xhci resource when xhci pci device exit Signed-off-by: Gonglei --- hw/usb/hcd-xhci.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 54dea16..4c266e7 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3617,6 +3617,41 @@ static int usb_xhci_initfn(struct PCIDevice *dev) return 0; } +static void usb_xhci_exit(PCIDevice *dev) +{ + int i; + XHCIState *xhci = XHCI(dev); + + 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 +3841,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;