From patchwork Mon Sep 12 10:50:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 114311 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 A3786B70DC for ; Mon, 12 Sep 2011 20:56:54 +1000 (EST) Received: from localhost ([::1]:35606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R347I-0003Nc-JP for incoming@patchwork.ozlabs.org; Mon, 12 Sep 2011 06:51:56 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R346d-0001YB-LG for qemu-devel@nongnu.org; Mon, 12 Sep 2011 06:51:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R346a-0006kv-5q for qemu-devel@nongnu.org; Mon, 12 Sep 2011 06:51:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22919) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R346Z-0006kJ-Q0 for qemu-devel@nongnu.org; Mon, 12 Sep 2011 06:51:12 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8CApB0O006632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 12 Sep 2011 06:51:11 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8CAp9pM000800 for ; Mon, 12 Sep 2011 06:51:09 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 9A4C1250B5B; Mon, 12 Sep 2011 13:51:08 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Mon, 12 Sep 2011 13:50:40 +0300 Message-Id: <1315824666-4214-3-git-send-email-avi@redhat.com> In-Reply-To: <1315824666-4214-1-git-send-email-avi@redhat.com> References: <1315824666-4214-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/28] mips_malta: 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 Signed-off-by: Avi Kivity --- hw/mips_malta.c | 53 ++++++++++++++++++++++++++--------------------------- 1 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hw/mips_malta.c b/hw/mips_malta.c index e7cdf20..0110daa 100644 --- a/hw/mips_malta.c +++ b/hw/mips_malta.c @@ -57,6 +57,9 @@ #define MAX_IDE_BUS 2 typedef struct { + MemoryRegion iomem; + MemoryRegion iomem_lo; /* 0 - 0x900 */ + MemoryRegion iomem_hi; /* 0xa00 - 0x100000 */ uint32_t leds; uint32_t brk; uint32_t gpout; @@ -215,7 +218,8 @@ static void eeprom24c0x_write(int scl, int sda) eeprom.sda = sda; } -static uint32_t malta_fpga_readl(void *opaque, target_phys_addr_t addr) +static uint64_t malta_fpga_read(void *opaque, target_phys_addr_t addr, + unsigned size) { MaltaFPGAState *s = opaque; uint32_t val = 0; @@ -302,8 +306,8 @@ static uint32_t malta_fpga_readl(void *opaque, target_phys_addr_t addr) return val; } -static void malta_fpga_writel(void *opaque, target_phys_addr_t addr, - uint32_t val) +static void malta_fpga_write(void *opaque, target_phys_addr_t addr, + uint64_t val, unsigned size) { MaltaFPGAState *s = opaque; uint32_t saddr; @@ -328,7 +332,7 @@ static void malta_fpga_writel(void *opaque, target_phys_addr_t addr, /* ASCIIWORD Register */ case 0x00410: - snprintf(s->display_text, 9, "%08X", val); + snprintf(s->display_text, 9, "%08X", (uint32_t)val); malta_fpga_update_display(s); break; @@ -388,16 +392,10 @@ static void malta_fpga_writel(void *opaque, target_phys_addr_t addr, } } -static CPUReadMemoryFunc * const malta_fpga_read[] = { - malta_fpga_readl, - malta_fpga_readl, - malta_fpga_readl -}; - -static CPUWriteMemoryFunc * const malta_fpga_write[] = { - malta_fpga_writel, - malta_fpga_writel, - malta_fpga_writel +static const MemoryRegionOps malta_fpga_ops = { + .read = malta_fpga_read, + .write = malta_fpga_write, + .endianness = DEVICE_NATIVE_ENDIAN, }; static void malta_fpga_reset(void *opaque) @@ -429,20 +427,22 @@ static void malta_fpga_led_init(CharDriverState *chr) qemu_chr_fe_printf(chr, "+--------+\r\n"); } -static MaltaFPGAState *malta_fpga_init(target_phys_addr_t base, qemu_irq uart_irq, CharDriverState *uart_chr) +static MaltaFPGAState *malta_fpga_init(MemoryRegion *address_space, + target_phys_addr_t base, qemu_irq uart_irq, CharDriverState *uart_chr) { MaltaFPGAState *s; - int malta; s = (MaltaFPGAState *)g_malloc0(sizeof(MaltaFPGAState)); - malta = cpu_register_io_memory(malta_fpga_read, - malta_fpga_write, s, - DEVICE_NATIVE_ENDIAN); + memory_region_init_io(&s->iomem, &malta_fpga_ops, s, + "malta-fpga", 0x100000); + memory_region_init_alias(&s->iomem_lo, "malta-fpga", + &s->iomem, 0, 0x900); + memory_region_init_alias(&s->iomem_hi, "malta-fpga", + &s->iomem, 0xa00, 0x10000-0xa00); - cpu_register_physical_memory(base, 0x900, malta); - /* 0xa00 is less than a page, so will still get the right offsets. */ - cpu_register_physical_memory(base + 0xa00, 0x100000 - 0xa00, malta); + memory_region_add_subregion(address_space, base, &s->iomem_lo); + memory_region_add_subregion(address_space, base + 0xa00, &s->iomem_hi); s->display = qemu_chr_new("fpga", "vc:320x200", malta_fpga_led_init); @@ -771,8 +771,8 @@ void mips_malta_init (ram_addr_t ram_size, { char *filename; pflash_t *fl; - ram_addr_t ram_offset; MemoryRegion *system_memory = get_system_memory(); + MemoryRegion *ram = g_new(MemoryRegion, 1); MemoryRegion *bios, *bios_alias = g_new(MemoryRegion, 1); target_long bios_size; int64_t kernel_entry; @@ -828,9 +828,8 @@ void mips_malta_init (ram_addr_t ram_size, ((unsigned int)ram_size / (1 << 20))); exit(1); } - ram_offset = qemu_ram_alloc(NULL, "mips_malta.ram", ram_size); - - cpu_register_physical_memory(0, ram_size, ram_offset | IO_MEM_RAM); + memory_region_init_ram(ram, NULL, "mips_malta.ram", ram_size); + memory_region_add_subregion(system_memory, 0, ram); #ifdef TARGET_WORDS_BIGENDIAN be = 1; @@ -838,7 +837,7 @@ void mips_malta_init (ram_addr_t ram_size, be = 0; #endif /* FPGA */ - malta_fpga_init(0x1f000000LL, env->irq[2], serial_hds[2]); + malta_fpga_init(system_memory, 0x1f000000LL, env->irq[2], serial_hds[2]); /* Load firmware in flash / BIOS unless we boot directly into a kernel. */ if (kernel_filename) {