From patchwork Wed Jun 4 08:31:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 355766 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 4599314009E for ; Wed, 4 Jun 2014 18:33:17 +1000 (EST) Received: from localhost ([::1]:58290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ws6dG-0002cx-Vr for incoming@patchwork.ozlabs.org; Wed, 04 Jun 2014 04:33:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ws6ch-0001hZ-Mu for qemu-devel@nongnu.org; Wed, 04 Jun 2014 04:32:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ws6ca-0008TZ-G4 for qemu-devel@nongnu.org; Wed, 04 Jun 2014 04:32:39 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:52132) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ws6cZ-0008PY-Np for qemu-devel@nongnu.org; Wed, 04 Jun 2014 04:32:32 -0400 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BUQ74940; Wed, 04 Jun 2014 16:32:16 +0800 (CST) Received: from SZXEML404-HUB.china.huawei.com (10.82.67.59) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.3.158.1; Wed, 4 Jun 2014 16:32:15 +0800 Received: from localhost (10.177.19.102) by szxeml404-hub.china.huawei.com (10.82.67.59) with Microsoft SMTP Server id 14.3.158.1; Wed, 4 Jun 2014 16:32:05 +0800 From: To: Date: Wed, 4 Jun 2014 16:31:51 +0800 Message-ID: <1401870715-9952-7-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1401870715-9952-1-git-send-email-arei.gonglei@huawei.com> References: <1401870715-9952-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 v3 06/10] usb-ehci: add ehci unrealize funciton 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 cleanup ehci controller resource, both pci and sysbus if they're necessary. Signed-off-by: Gonglei --- hw/usb/hcd-ehci.c | 29 +++++++++++++++++++++++++++++ hw/usb/hcd-ehci.h | 1 + 2 files changed, 30 insertions(+) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 76e939d..172ca04 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2471,6 +2471,35 @@ void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp) s->vmstate = qemu_add_vm_change_state_handler(usb_ehci_vm_state_change, s); } +void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp) +{ + if (s->frame_timer) { + timer_del(s->frame_timer); + timer_free(s->frame_timer); + s->frame_timer = NULL; + } + if (s->async_bh) { + qemu_bh_delete(s->async_bh); + } + + ehci_queues_rip_all(s, 0); + ehci_queues_rip_all(s, 1); + + memory_region_del_subregion(&s->mem, &s->mem_caps); + memory_region_del_subregion(&s->mem, &s->mem_opreg); + memory_region_del_subregion(&s->mem, &s->mem_ports); + memory_region_destroy(&s->mem_caps); + memory_region_destroy(&s->mem_opreg); + memory_region_destroy(&s->mem_ports); + memory_region_destroy(&s->mem); + + usb_bus_release(&s->bus); + + if (s->vmstate) { + qemu_del_vm_change_state_handler(s->vmstate); + } +} + void usb_ehci_init(EHCIState *s, DeviceState *dev) { /* 2.2 host controller interface version */ diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index 594d9d3..4858b7e 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -323,6 +323,7 @@ extern const VMStateDescription vmstate_ehci; void usb_ehci_init(EHCIState *s, DeviceState *dev); void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp); +void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp); #define TYPE_PCI_EHCI "pci-ehci-usb" #define PCI_EHCI(obj) OBJECT_CHECK(EHCIPCIState, (obj), TYPE_PCI_EHCI)