From patchwork Tue Feb 9 22:01:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 44969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B22C9B7CFD for ; Wed, 10 Feb 2010 09:14:19 +1100 (EST) Received: from localhost ([127.0.0.1]:41385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NeyKY-0007WS-9u for incoming@patchwork.ozlabs.org; Tue, 09 Feb 2010 17:13:14 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ney9h-0002EH-3G for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:02:01 -0500 Received: from [199.232.76.173] (port=52479 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ney9f-0002CU-Kn for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:01:59 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Ney9d-0005nM-4M for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:01:58 -0500 Received: from e7.ny.us.ibm.com ([32.97.182.137]:40021) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ney9c-0005mx-PL for qemu-devel@nongnu.org; Tue, 09 Feb 2010 17:01:56 -0500 Received: from d01relay07.pok.ibm.com (d01relay07.pok.ibm.com [9.56.227.147]) by e7.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id o19LskGv014748 for ; Tue, 9 Feb 2010 16:54:46 -0500 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay07.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o19M1pO82056214 for ; Tue, 9 Feb 2010 17:01:51 -0500 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o19M1oA5014040 for ; Tue, 9 Feb 2010 17:01:50 -0500 Received: from localhost.localdomain (sig-9-65-47-242.mts.ibm.com [9.65.47.242]) by d01av01.pok.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o19M1eiG013399; Tue, 9 Feb 2010 17:01:49 -0500 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Tue, 9 Feb 2010 16:01:30 -0600 Message-Id: <1265752899-26980-7-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1265752899-26980-1-git-send-email-aliguori@us.ibm.com> References: <1265752899-26980-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Michael Tsirkin , Anthony Liguori , Alex Graf Subject: [Qemu-devel] [PATCH 06/15] wdt_i6300esb: convert to new pci inteface X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org - kept same semantics for writes, probably can be simplified - fixes an iotype leak for hot unplug Signed-off-by: Anthony Liguori --- hw/wdt_i6300esb.c | 122 ++++++++++++----------------------------------------- 1 files changed, 27 insertions(+), 95 deletions(-) diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c index 6c08c32..6de5866 100644 --- a/hw/wdt_i6300esb.c +++ b/hw/wdt_i6300esb.c @@ -98,8 +98,6 @@ struct I6300State { int previous_reboot_flag; /* If the watchdog caused the previous * reboot, this flag will be set. */ - - int io_mem; }; typedef struct I6300State I6300State; @@ -245,21 +243,14 @@ static uint32_t i6300esb_config_read(PCIDevice *dev, uint32_t addr, int len) } } -static uint32_t i6300esb_mem_readb(void *vp, target_phys_addr_t addr) -{ - i6300esb_debug ("addr = %x\n", (int) addr); - - return 0; -} - -static uint32_t i6300esb_mem_readw(void *vp, target_phys_addr_t addr) +static uint32_t i6300esb_mem_read(PCIDevice *dev, pcibus_t addr, int size) { + I6300State *d = DO_UPCAST(I6300State, dev, dev); uint32_t data = 0; - I6300State *d = vp; i6300esb_debug("addr = %x\n", (int) addr); - if (addr == 0xc) { + if (size == 2 && addr == 0xc) { /* The previous reboot flag is really bit 9, but there is * a bug in the Linux driver where it thinks it's bit 12. * Set both. @@ -270,28 +261,10 @@ static uint32_t i6300esb_mem_readw(void *vp, target_phys_addr_t addr) return data; } -static uint32_t i6300esb_mem_readl(void *vp, target_phys_addr_t addr) -{ - i6300esb_debug("addr = %x\n", (int) addr); - - return 0; -} - -static void i6300esb_mem_writeb(void *vp, target_phys_addr_t addr, uint32_t val) +static void i6300esb_mem_write(PCIDevice *dev, pcibus_t addr, int size, + uint32_t val) { - I6300State *d = vp; - - i6300esb_debug("addr = %x, val = %x\n", (int) addr, val); - - if (addr == 0xc && val == 0x80) - d->unlock_state = 1; - else if (addr == 0xc && val == 0x86 && d->unlock_state == 1) - d->unlock_state = 2; -} - -static void i6300esb_mem_writew(void *vp, target_phys_addr_t addr, uint32_t val) -{ - I6300State *d = vp; + I6300State *d = DO_UPCAST(I6300State, dev, dev); i6300esb_debug("addr = %x, val = %x\n", (int) addr, val); @@ -301,20 +274,27 @@ static void i6300esb_mem_writew(void *vp, target_phys_addr_t addr, uint32_t val) d->unlock_state = 2; else { if (d->unlock_state == 2) { - if (addr == 0xc) { - if ((val & 0x100) != 0) - /* This is the "ping" from the userspace watchdog in - * the guest ... + if (size == 2) { + if (addr == 0xc) { + if ((val & 0x100) != 0) + /* This is the "ping" from the userspace watchdog in + * the guest ... + */ + i6300esb_restart_timer(d, 1); + + /* Setting bit 9 resets the previous reboot flag. + * There's a bug in the Linux driver where it sets + * bit 12 instead. */ - i6300esb_restart_timer(d, 1); - - /* Setting bit 9 resets the previous reboot flag. - * There's a bug in the Linux driver where it sets - * bit 12 instead. - */ - if ((val & 0x200) != 0 || (val & 0x1000) != 0) { - d->previous_reboot_flag = 0; + if ((val & 0x200) != 0 || (val & 0x1000) != 0) { + d->previous_reboot_flag = 0; + } } + } else if (size == 4) { + if (addr == 0) + d->timer1_preload = val & 0xfffff; + else if (addr == 4) + d->timer2_preload = val & 0xfffff; } d->unlock_state = 0; @@ -322,52 +302,6 @@ static void i6300esb_mem_writew(void *vp, target_phys_addr_t addr, uint32_t val) } } -static void i6300esb_mem_writel(void *vp, target_phys_addr_t addr, uint32_t val) -{ - I6300State *d = vp; - - i6300esb_debug ("addr = %x, val = %x\n", (int) addr, val); - - if (addr == 0xc && val == 0x80) - d->unlock_state = 1; - else if (addr == 0xc && val == 0x86 && d->unlock_state == 1) - d->unlock_state = 2; - else { - if (d->unlock_state == 2) { - if (addr == 0) - d->timer1_preload = val & 0xfffff; - else if (addr == 4) - d->timer2_preload = val & 0xfffff; - - d->unlock_state = 0; - } - } -} - -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, -}; - -static void i6300esb_map(PCIDevice *dev, int region_num, - pcibus_t addr, pcibus_t size, int type) -{ - I6300State *d = DO_UPCAST(I6300State, dev, dev); - - i6300esb_debug("addr = %"FMT_PCIBUS", size = %"FMT_PCIBUS", type = %d\n", - addr, size, type); - - cpu_register_physical_memory (addr, 0x10, d->io_mem); - /* qemu_register_coalesced_mmio (addr, 0x10); ? */ -} - static const VMStateDescription vmstate_i6300esb = { .name = "i6300esb_wdt", .version_id = sizeof(I6300State), @@ -408,8 +342,6 @@ static int i6300esb_init(PCIDevice *dev) d->stage = 1; d->unlock_state = 0; d->previous_reboot_flag = 0; - d->io_mem = cpu_register_io_memory(mem_read, mem_write, d); - pci_conf = d->dev.config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL); @@ -417,8 +349,8 @@ static int i6300esb_init(PCIDevice *dev) pci_config_set_class(pci_conf, PCI_CLASS_SYSTEM_OTHER); pci_conf[PCI_HEADER_TYPE] = 0x00; - pci_register_bar(&d->dev, 0, 0x10, - PCI_BASE_ADDRESS_SPACE_MEMORY, i6300esb_map); + pci_register_io_region(&d->dev, 0, 0x10, PCI_BASE_ADDRESS_SPACE_MEMORY, + i6300esb_mem_read, i6300esb_mem_write); return 0; }