From patchwork Sun Jul 10 18:14:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 104110 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 007B3B70FF for ; Mon, 11 Jul 2011 06:07:10 +1000 (EST) Received: from localhost ([::1]:41931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qg0HS-0006xM-7p for incoming@patchwork.ozlabs.org; Sun, 10 Jul 2011 16:07:06 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47129) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfyXX-0004IS-Mp for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QfyXL-0007cx-UX for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QfyXE-0007Y3-WB for qemu-devel@nongnu.org; Sun, 10 Jul 2011 14:15:18 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6AIFGPX027543 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 10 Jul 2011 14:15:16 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6AIFDjV032728; Sun, 10 Jul 2011 14:15:15 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 9AB3A250B5C; Sun, 10 Jul 2011 21:15:11 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Sun, 10 Jul 2011 21:14:58 +0300 Message-Id: <1310321709-30770-46-git-send-email-avi@redhat.com> In-Reply-To: <1310321709-30770-1-git-send-email-avi@redhat.com> References: <1310321709-30770-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC v3 45/56] i6300esb: convert to memory API 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 Also add missing destructor. Signed-off-by: Avi Kivity --- hw/wdt_i6300esb.c | 59 ++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 45 insertions(+), 14 deletions(-) diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c index 53786ce..242a8fa 100644 --- a/hw/wdt_i6300esb.c +++ b/hw/wdt_i6300esb.c @@ -66,6 +66,7 @@ /* Device state. */ struct I6300State { PCIDevice dev; + MemoryRegion io_mem; int reboot_enabled; /* "Reboot" on timer expiry. The real action * performed depends on the -watchdog-action @@ -355,6 +356,38 @@ static void i6300esb_mem_writel(void *vp, target_phys_addr_t addr, uint32_t val) } } +static uint64_t i6300esb_mem_read(void *opaque, target_phys_addr_t addr, + unsigned size) +{ + I6300State *s = opaque; + + switch (size) { + case 1: return i6300esb_mem_readb(s, addr); + case 2: return i6300esb_mem_readw(s, addr); + case 4: return i6300esb_mem_readl(s, addr); + default: abort(); + } +} + +static void i6300esb_mem_write(void *opaque, target_phys_addr_t addr, + uint64_t data, unsigned size) +{ + I6300State *s = opaque; + + switch (size) { + case 1: return i6300esb_mem_writeb(s, addr, data); + case 2: return i6300esb_mem_writew(s, addr, data); + case 4: return i6300esb_mem_writel(s, addr, data); + default: abort(); + } +} + +static MemoryRegionOps i6300esb_ops = { + .read = i6300esb_mem_read, + .write = i6300esb_mem_write, + .endianness = DEVICE_NATIVE_ENDIAN, +}; + static const VMStateDescription vmstate_i6300esb = { .name = "i6300esb_wdt", .version_id = sizeof(I6300State), @@ -381,31 +414,28 @@ static const VMStateDescription vmstate_i6300esb = { static int i6300esb_init(PCIDevice *dev) { I6300State *d = DO_UPCAST(I6300State, dev, dev); - int io_mem; - static CPUReadMemoryFunc * const mem_read[3] = { - i6300esb_mem_readb, - i6300esb_mem_readw, - i6300esb_mem_readl, - }; - static CPUWriteMemoryFunc * const mem_write[3] = { - i6300esb_mem_writeb, - i6300esb_mem_writew, - i6300esb_mem_writel, - }; i6300esb_debug("I6300State = %p\n", d); d->timer = qemu_new_timer_ns(vm_clock, i6300esb_timer_expired, d); d->previous_reboot_flag = 0; - io_mem = cpu_register_io_memory(mem_read, mem_write, d, - DEVICE_NATIVE_ENDIAN); - pci_register_bar_simple(&d->dev, 0, 0x10, 0, io_mem); + memory_region_init_io(&d->io_mem, &i6300esb_ops, d, "i6300esb", 0x10); + pci_register_bar_region(&d->dev, 0, 0, &d->io_mem); /* qemu_register_coalesced_mmio (addr, 0x10); ? */ return 0; } +static int i6300esb_exit(PCIDevice *dev) +{ + I6300State *d = DO_UPCAST(I6300State, dev, dev); + + memory_region_destroy(&d->io_mem); + + return 0; +} + static WatchdogTimerModel model = { .wdt_name = "i6300esb", .wdt_description = "Intel 6300ESB", @@ -419,6 +449,7 @@ static PCIDeviceInfo i6300esb_info = { .config_read = i6300esb_config_read, .config_write = i6300esb_config_write, .init = i6300esb_init, + .exit = i6300esb_exit, .vendor_id = PCI_VENDOR_ID_INTEL, .device_id = PCI_DEVICE_ID_INTEL_ESB_9, .class_id = PCI_CLASS_SYSTEM_OTHER,