From patchwork Thu Feb 9 07:04:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9564127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1602460236 for ; Thu, 9 Feb 2017 07:05:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFC57284E7 for ; Thu, 9 Feb 2017 07:05:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C4A3B2850D; Thu, 9 Feb 2017 07:05:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3E2CB284E7 for ; Thu, 9 Feb 2017 07:05:00 +0000 (UTC) Received: from localhost ([::1]:35963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbimq-0003Ly-1N for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Feb 2017 02:05:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbimI-0003Ie-JY for qemu-devel@nongnu.org; Thu, 09 Feb 2017 02:04:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbimE-000274-Ih for qemu-devel@nongnu.org; Thu, 09 Feb 2017 02:04:24 -0500 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:33002) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbimE-00026p-EP for qemu-devel@nongnu.org; Thu, 09 Feb 2017 02:04:22 -0500 Received: by mail-io0-x241.google.com with SMTP id 101so1295613iom.0 for ; Wed, 08 Feb 2017 23:04:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q39s0X/m0ZMQA4uzZvtxEmuHhDDXoTYZYOQCKus2Ww4=; b=k9EVk4OF6vwuSJXk4pS/v+s7M/poPf2nPUHsll+iQAqmZ9gLH3kVWqLWqiXaxm+GA8 VvVoocLAodo49xb7K/tq3mTSKcMqSSE6jYCxc0ALePHD9gQq+AMHkTb4jla7Z27YmJin U9qWGINJJqgup6vVI0PTVrFYgaDr/WmJwMxL/fcl5+sF4tW3uoj5MkUfCMaTQgB8q0Jw s8KvbdtLrmoB5xGWjXtZU6hyNDUqrqMgeF8MkA5Uuh9+K62chO1rTKvk2iuZoxQVod7d WZSrvq8XtfUE4amjaBBDK88fGpRnCgK4BLuifrxdMfAXQFIaiyzjWinqhGZEWdSGaDTO Rq8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q39s0X/m0ZMQA4uzZvtxEmuHhDDXoTYZYOQCKus2Ww4=; b=BFQbY81MHP+2nOwEixkIWERdjBwJklZvJmK8Mzw3rPYQkfnFKuu21xyQDErROf3Do6 IfZ2cdRQPs8BoHekJtcu47TaSrjS514SXxyL3BU/A6XHpvLCCtmp9LV2wJ8n0f76+67E CLmaDXV+avh8imlft23RJvcaX7F++P9pChVInv3dNS/d9CW/RzQ2iMLNLeJNQY4RUkFp Xk/wdYaxQDZd5vGdsQtTYOUTMOavyijZQEqQ+PLiziUZxCDj6soLR/iAPNYcii+rX+u9 +zjtO9Tq0uVTTifLfu2GziNd2hBH+8Eq1CRnxuXr/K6K7WFxBvcF3FU12sihQuC6ORjx Dxzg== X-Gm-Message-State: AMke39nOpGfklekmfZ6pS1BXLmsFjmR6768dhAqQ7CdGPb2uefZYS892TGbEhXEDRPxnAQ== X-Received: by 10.107.9.149 with SMTP id 21mr1815922ioj.106.1486623859558; Wed, 08 Feb 2017 23:04:19 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id e11sm2483474ita.10.2017.02.08.23.04.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Feb 2017 23:04:19 -0800 (PST) From: Li Qiang X-Google-Original-From: Li Qiang To: jsnow@redhat.com, qemu-devel@nongnu.org Date: Wed, 8 Feb 2017 23:04:03 -0800 Message-Id: <1486623844-13140-2-git-send-email-liqiang6-s@360.cn> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1486623844-13140-1-git-send-email-liqiang6-s@360.cn> References: <1486623844-13140-1-git-send-email-liqiang6-s@360.cn> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::241 Subject: [Qemu-devel] [PATCH 1/2] ide: core: add cleanup function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP As the pci ahci can be hotplug and unplug, in the ahci unrealize function it should free all the resource once allocated in the realized function. This patch adds two cleanup function. Signed-off-by: Li Qiang --- hw/ide/core.c | 21 +++++++++++++++++++++ include/hw/ide/internal.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index 43709e5..8fe5896 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2586,6 +2586,13 @@ void ide_register_restart_cb(IDEBus *bus) } } +void ide_unregister_restart_cb(IDEBus *bus) +{ + if (bus->dma->ops->restart_dma) { + qemu_del_vm_change_state_handler(bus->vmstate); + } +} + static IDEDMA ide_dma_nop = { .ops = &ide_dma_nop_ops, .aiocb = NULL, @@ -2603,6 +2610,20 @@ void ide_init2(IDEBus *bus, qemu_irq irq) bus->dma = &ide_dma_nop; } +void ide_exit(IDEBus *bus) +{ + int i; + + for (i = 0; i < 2; i++) { + IDEState *s = &bus->ifs[i]; + + timer_del(s->sector_write_timer); + timer_free(s->sector_write_timer); + qemu_vfree(s->smart_selftest_data); + qemu_vfree(s->io_buffer); + } +} + static const MemoryRegionPortio ide_portio_list[] = { { 0, 8, 1, .read = ide_ioport_read, .write = ide_ioport_write }, { 0, 1, 2, .read = ide_data_readw, .write = ide_data_writew }, diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h index 88dc118..09b0404 100644 --- a/include/hw/ide/internal.h +++ b/include/hw/ide/internal.h @@ -607,8 +607,10 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind, uint32_t cylinders, uint32_t heads, uint32_t secs, int chs_trans); void ide_init2(IDEBus *bus, qemu_irq irq); +void ide_exit(IDEBus *bus); void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2); void ide_register_restart_cb(IDEBus *bus); +void ide_unregister_restart_cb(IDEBus *bus); void ide_exec_cmd(IDEBus *bus, uint32_t val);