From patchwork Wed Feb 24 14:23:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 81753 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1OENnhn022956 for ; Wed, 24 Feb 2010 14:23:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754855Ab0BXOXr (ORCPT ); Wed, 24 Feb 2010 09:23:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12280 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754330Ab0BXOXq (ORCPT ); Wed, 24 Feb 2010 09:23:46 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1OENjVY010552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 24 Feb 2010 09:23:45 -0500 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o1OENiVw007185; Wed, 24 Feb 2010 09:23:45 -0500 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 8D4B918D450; Wed, 24 Feb 2010 16:23:44 +0200 (IST) Date: Wed, 24 Feb 2010 16:23:44 +0200 From: Gleb Natapov To: avi@redhat.com, mtosatti@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH] Add io memory to test device Message-ID: <20100224142344.GQ29041@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 24 Feb 2010 14:23:49 +0000 (UTC) diff --git a/hw/testdev.c b/hw/testdev.c index ac5b9cd..ad34e43 100644 --- a/hw/testdev.c +++ b/hw/testdev.c @@ -34,14 +34,62 @@ static void test_device_irq_line(void *opaque, uint32_t addr, uint32_t data) qemu_set_irq(ioapic_irq_hack[addr - 0x2000], !!data); } +static char *iomem_buf; + +static uint32_t test_iomem_readb(void *opaque, target_phys_addr_t addr) +{ + return iomem_buf[addr]; +} + +static uint32_t test_iomem_readw(void *opaque, target_phys_addr_t addr) +{ + return *(uint16_t*)(iomem_buf + addr); +} + +static uint32_t test_iomem_readl(void *opaque, target_phys_addr_t addr) +{ + return *(uint32_t*)(iomem_buf + addr); +} + +static void test_iomem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) +{ + iomem_buf[addr] = val; +} + +static void test_iomem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) +{ + *(uint16_t*)(iomem_buf + addr) = val; +} + +static void test_iomem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) +{ + *(uint32_t*)(iomem_buf + addr) = val; +} + +static CPUReadMemoryFunc * const test_iomem_read[3] = { + test_iomem_readb, + test_iomem_readw, + test_iomem_readl, +}; + +static CPUWriteMemoryFunc * const test_iomem_write[3] = { + test_iomem_writeb, + test_iomem_writew, + test_iomem_writel, +}; + static int init_test_device(ISADevice *isa) { struct testdev *dev = DO_UPCAST(struct testdev, dev, isa); + int iomem; register_ioport_write(0xf1, 1, 1, test_device_serial_write, dev); register_ioport_write(0xf4, 1, 4, test_device_exit, dev); register_ioport_read(0xd1, 1, 4, test_device_memsize_read, dev); register_ioport_write(0x2000, 24, 1, test_device_irq_line, NULL); + iomem_buf = qemu_mallocz(0x10000); + iomem = cpu_register_io_memory(test_iomem_read, test_iomem_write, NULL); + cpu_register_physical_memory(0xff000000, 0x10000, iomem); return 0; }