From patchwork Wed Nov 27 08:23:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liguang X-Patchwork-Id: 294512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EF66E2C00A4 for ; Wed, 27 Nov 2013 19:26:37 +1100 (EST) Received: from localhost ([::1]:34485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlaS8-0002ZC-RQ for incoming@patchwork.ozlabs.org; Wed, 27 Nov 2013 03:26:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlaRV-0002Ts-4F for qemu-devel@nongnu.org; Wed, 27 Nov 2013 03:25:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlaRO-0008D5-Pv for qemu-devel@nongnu.org; Wed, 27 Nov 2013 03:25:53 -0500 Received: from [222.73.24.84] (port=63124 helo=song.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlaRO-0008Cn-Dh for qemu-devel@nongnu.org; Wed, 27 Nov 2013 03:25:46 -0500 X-IronPort-AV: E=Sophos;i="4.93,780,1378828800"; d="scan'208";a="9136781" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 27 Nov 2013 16:22:12 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id rAR8PbfI032232; Wed, 27 Nov 2013 16:25:38 +0800 Received: from liguang.fnst.cn.fujitsu.com ([10.167.226.22]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013112716254259-457034 ; Wed, 27 Nov 2013 16:25:42 +0800 From: liguang To: qemu-devel@nongnu.org Date: Wed, 27 Nov 2013 16:23:54 +0800 Message-Id: <1385540635-26977-5-git-send-email-lig.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1385540635-26977-1-git-send-email-lig.fnst@cn.fujitsu.com> References: <1385540635-26977-1-git-send-email-lig.fnst@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/11/27 16:25:42, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/11/27 16:25:43, Serialize complete at 2013/11/27 16:25:43 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 222.73.24.84 Cc: Peter Maydell , Peter Crosthwaite , liguang Subject: [Qemu-devel] [PATCH v6 4/5] hw/arm: add sunxi machine type 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: liguang --- hw/arm/Makefile.objs | 1 + hw/arm/sunxi-soc.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 0 deletions(-) create mode 100644 hw/arm/sunxi-soc.c diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs index 3671b42..f9f3071 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -5,3 +5,4 @@ obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o strongarm.o +obj-y += sunxi-soc.o diff --git a/hw/arm/sunxi-soc.c b/hw/arm/sunxi-soc.c new file mode 100644 index 0000000..3c9f204 --- /dev/null +++ b/hw/arm/sunxi-soc.c @@ -0,0 +1,98 @@ +/* + * Allwinner sunxi series SoC emulation + * + * Copyright (C) 2013 Li Guang + * Written by Li Guang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "hw/sysbus.h" +#include "hw/devices.h" +#include "hw/boards.h" +#include "hw/arm/arm.h" +#include "hw/ptimer.h" +#include "hw/char/serial.h" +#include "hw/timer/sunxi-pit.h" +#include "hw/intc/sunxi-pic.h" + +#include "sysemu/sysemu.h" +#include "exec/address-spaces.h" + + +#define SUNXI_PIC_REG_BASE 0x01c20400 +#define SUNXI_PIT_REG_BASE 0x01c20c00 +#define SUNXI_UART0_REG_BASE 0x01c28000 + +static struct arm_boot_info sunxi_binfo = { + .loader_start = 0x40000000, + .board_id = 0x1008, +}; + +static void sunxi_init(QEMUMachineInitArgs *args) +{ + ram_addr_t ram_size = args->ram_size; + const char *cpu_model = args->cpu_model; + const char *kernel_filename = args->kernel_filename; + const char *kernel_cmdline = args->kernel_cmdline; + ARMCPU *cpu; + MemoryRegion *address_space_mem = get_system_memory(); + MemoryRegion *ram = g_new(MemoryRegion, 1); + MemoryRegion *ram_alias = g_new(MemoryRegion, 1); + qemu_irq pic[SUNXI_PIC_INT_NR]; + DeviceState *dev; + uint8_t i; + + /*here we currently support sunxi-4i*/ + cpu_model = "cortex-a8"; + cpu = cpu_arm_init(cpu_model); + if (!cpu) { + fprintf(stderr, "Unable to find CPU definition\n"); + exit(1); + } + + memory_region_init_ram(ram, NULL, "sunxi-soc.ram", ram_size); + memory_region_add_subregion(address_space_mem, 0, ram); + memory_region_init_alias(ram_alias, NULL, "ram.alias", ram, 0, ram_size); + memory_region_add_subregion(address_space_mem, 0x40000000, ram_alias); + + dev = sysbus_create_varargs(TYPE_SUNXI_PIC, SUNXI_PIC_REG_BASE, + qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ), + qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ), + NULL); + for (i = 0; i < SUNXI_PIC_INT_NR; i++) { + pic[i] = qdev_get_gpio_in(dev, i); + } + + sysbus_create_varargs(TYPE_SUNXI_PIT, SUNXI_PIT_REG_BASE, pic[22], pic[23], + pic[24], pic[25], pic[67], pic[68], NULL); + + serial_mm_init(address_space_mem, SUNXI_UART0_REG_BASE, 2, pic[1], 115200, + serial_hds[0], DEVICE_NATIVE_ENDIAN); + + sunxi_binfo.ram_size = ram_size; + sunxi_binfo.kernel_filename = kernel_filename; + sunxi_binfo.kernel_cmdline = kernel_cmdline; + arm_load_kernel(cpu, &sunxi_binfo); +} + +static QEMUMachine sunxi_machine = { + .name = "sunxi", + .desc = "Allwinner's SoC (sunxi series)", + .init = sunxi_init, +}; + +static void sunxi_machine_init(void) +{ + qemu_register_machine(&sunxi_machine); +} + +machine_init(sunxi_machine_init);