153018216SPaolo Bonzini /*
253018216SPaolo Bonzini * KZM Board System emulation.
353018216SPaolo Bonzini *
453018216SPaolo Bonzini * Copyright (c) 2008 OKL and 2011 NICTA
553018216SPaolo Bonzini * Written by Hans at OK-Labs
653018216SPaolo Bonzini * Updated by Peter Chubb.
753018216SPaolo Bonzini *
853018216SPaolo Bonzini * This code is licensed under the GPL, version 2 or later.
953018216SPaolo Bonzini * See the file `COPYING' in the top level directory.
1053018216SPaolo Bonzini *
1153018216SPaolo Bonzini * It (partially) emulates a Kyoto Microcomputer
1253018216SPaolo Bonzini * KZM-ARM11-01 evaluation board, with a Freescale
1353018216SPaolo Bonzini * i.MX31 SoC
1453018216SPaolo Bonzini */
1553018216SPaolo Bonzini
1612b16722SPeter Maydell #include "qemu/osdep.h"
17da34e65cSMarkus Armbruster #include "qapi/error.h"
18f044ac49SJean-Christophe Dubois #include "hw/arm/fsl-imx31.h"
1988e763daSPhilippe Mathieu-Daudé #include "hw/arm/boot.h"
2053018216SPaolo Bonzini #include "hw/boards.h"
21f044ac49SJean-Christophe Dubois #include "qemu/error-report.h"
22f044ac49SJean-Christophe Dubois #include "exec/address-spaces.h"
23f044ac49SJean-Christophe Dubois #include "net/net.h"
2466b03dceSPhilippe Mathieu-Daudé #include "hw/net/lan9118.h"
25*7e6b5497SBernhard Beschow #include "hw/char/serial-mm.h"
26f044ac49SJean-Christophe Dubois #include "sysemu/qtest.h"
2746517dd4SMarkus Armbruster #include "sysemu/sysemu.h"
28462f1f4bSIgor Mammedov #include "qemu/cutils.h"
2953018216SPaolo Bonzini
3053018216SPaolo Bonzini /* Memory map for Kzm Emulation Baseboard:
31f044ac49SJean-Christophe Dubois * 0x00000000-0x7fffffff See i.MX31 SOC for support
32f044ac49SJean-Christophe Dubois * 0x80000000-0x8fffffff RAM EMULATED
33f044ac49SJean-Christophe Dubois * 0x90000000-0x9fffffff RAM EMULATED
34f044ac49SJean-Christophe Dubois * 0xa0000000-0xafffffff Flash IGNORED
3553018216SPaolo Bonzini * 0xb0000000-0xb3ffffff Unavailable IGNORED
3653018216SPaolo Bonzini * 0xb4000000-0xb4000fff 8-bit free space IGNORED
3753018216SPaolo Bonzini * 0xb4001000-0xb400100f Board control IGNORED
3853018216SPaolo Bonzini * 0xb4001003 DIP switch
3953018216SPaolo Bonzini * 0xb4001010-0xb400101f 7-segment LED IGNORED
4053018216SPaolo Bonzini * 0xb4001020-0xb400102f LED IGNORED
4153018216SPaolo Bonzini * 0xb4001030-0xb400103f LED IGNORED
4253018216SPaolo Bonzini * 0xb4001040-0xb400104f FPGA, UART EMULATED
4353018216SPaolo Bonzini * 0xb4001050-0xb400105f FPGA, UART EMULATED
4453018216SPaolo Bonzini * 0xb4001060-0xb40fffff FPGA IGNORED
4553018216SPaolo Bonzini * 0xb6000000-0xb61fffff LAN controller EMULATED
4653018216SPaolo Bonzini * 0xb6200000-0xb62fffff FPGA NAND Controller IGNORED
4753018216SPaolo Bonzini * 0xb6300000-0xb7ffffff Free IGNORED
4853018216SPaolo Bonzini * 0xb8000000-0xb8004fff Memory control registers IGNORED
4953018216SPaolo Bonzini * 0xc0000000-0xc3ffffff PCMCIA/CF IGNORED
5053018216SPaolo Bonzini * 0xc4000000-0xffffffff Reserved IGNORED
5153018216SPaolo Bonzini */
5253018216SPaolo Bonzini
53f044ac49SJean-Christophe Dubois typedef struct IMX31KZM {
54f044ac49SJean-Christophe Dubois FslIMX31State soc;
55f044ac49SJean-Christophe Dubois MemoryRegion ram_alias;
56f044ac49SJean-Christophe Dubois } IMX31KZM;
57f044ac49SJean-Christophe Dubois
58f044ac49SJean-Christophe Dubois #define KZM_RAM_ADDR (FSL_IMX31_SDRAM0_ADDR)
59f044ac49SJean-Christophe Dubois #define KZM_FPGA_ADDR (FSL_IMX31_CS4_ADDR + 0x1040)
60f044ac49SJean-Christophe Dubois #define KZM_LAN9118_ADDR (FSL_IMX31_CS5_ADDR)
6153018216SPaolo Bonzini
6253018216SPaolo Bonzini static struct arm_boot_info kzm_binfo = {
63f044ac49SJean-Christophe Dubois .loader_start = KZM_RAM_ADDR,
6453018216SPaolo Bonzini .board_id = 1722,
6553018216SPaolo Bonzini };
6653018216SPaolo Bonzini
kzm_init(MachineState * machine)673ef96221SMarcel Apfelbaum static void kzm_init(MachineState *machine)
6853018216SPaolo Bonzini {
69f044ac49SJean-Christophe Dubois IMX31KZM *s = g_new0(IMX31KZM, 1);
70f044ac49SJean-Christophe Dubois unsigned int ram_size;
71f044ac49SJean-Christophe Dubois unsigned int alias_offset;
72f044ac49SJean-Christophe Dubois unsigned int i;
7353018216SPaolo Bonzini
749fc7fc4dSMarkus Armbruster object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_FSL_IMX31);
7553018216SPaolo Bonzini
76ce189ab2SMarkus Armbruster qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
7753018216SPaolo Bonzini
78f044ac49SJean-Christophe Dubois /* Check the amount of memory is compatible with the SOC */
79f044ac49SJean-Christophe Dubois if (machine->ram_size > (FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE)) {
80462f1f4bSIgor Mammedov char *sz = size_to_str(FSL_IMX31_SDRAM0_SIZE + FSL_IMX31_SDRAM1_SIZE);
81462f1f4bSIgor Mammedov error_report("RAM size more than %s is not supported", sz);
82462f1f4bSIgor Mammedov g_free(sz);
83462f1f4bSIgor Mammedov exit(EXIT_FAILURE);
84f044ac49SJean-Christophe Dubois }
8553018216SPaolo Bonzini
86f044ac49SJean-Christophe Dubois memory_region_add_subregion(get_system_memory(), FSL_IMX31_SDRAM0_ADDR,
873865cfacSIgor Mammedov machine->ram);
8853018216SPaolo Bonzini
89f044ac49SJean-Christophe Dubois /* initialize the alias memory if any */
90f044ac49SJean-Christophe Dubois for (i = 0, ram_size = machine->ram_size, alias_offset = 0;
91f044ac49SJean-Christophe Dubois (i < 2) && ram_size; i++) {
92f044ac49SJean-Christophe Dubois unsigned int size;
93f044ac49SJean-Christophe Dubois static const struct {
94f044ac49SJean-Christophe Dubois hwaddr addr;
95f044ac49SJean-Christophe Dubois unsigned int size;
96f044ac49SJean-Christophe Dubois } ram[2] = {
97f044ac49SJean-Christophe Dubois { FSL_IMX31_SDRAM0_ADDR, FSL_IMX31_SDRAM0_SIZE },
98f044ac49SJean-Christophe Dubois { FSL_IMX31_SDRAM1_ADDR, FSL_IMX31_SDRAM1_SIZE },
99f044ac49SJean-Christophe Dubois };
10053018216SPaolo Bonzini
101f044ac49SJean-Christophe Dubois size = MIN(ram_size, ram[i].size);
10253018216SPaolo Bonzini
103f044ac49SJean-Christophe Dubois ram_size -= size;
10453018216SPaolo Bonzini
105f044ac49SJean-Christophe Dubois if (size < ram[i].size) {
106f044ac49SJean-Christophe Dubois memory_region_init_alias(&s->ram_alias, NULL, "ram.alias",
1073865cfacSIgor Mammedov machine->ram,
1083865cfacSIgor Mammedov alias_offset, ram[i].size - size);
109f044ac49SJean-Christophe Dubois memory_region_add_subregion(get_system_memory(),
110f044ac49SJean-Christophe Dubois ram[i].addr + size, &s->ram_alias);
111f044ac49SJean-Christophe Dubois }
11253018216SPaolo Bonzini
113f044ac49SJean-Christophe Dubois alias_offset += ram[i].size;
114f044ac49SJean-Christophe Dubois }
11553018216SPaolo Bonzini
116f138ed5eSDavid Woodhouse if (qemu_find_nic_info("lan9118", true, NULL)) {
117f138ed5eSDavid Woodhouse lan9118_init(KZM_LAN9118_ADDR,
118f044ac49SJean-Christophe Dubois qdev_get_gpio_in(DEVICE(&s->soc.avic), 52));
11953018216SPaolo Bonzini }
12053018216SPaolo Bonzini
1219bca0edbSPeter Maydell if (serial_hd(2)) { /* touchscreen */
122f044ac49SJean-Christophe Dubois serial_mm_init(get_system_memory(), KZM_FPGA_ADDR+0x10, 0,
123f044ac49SJean-Christophe Dubois qdev_get_gpio_in(DEVICE(&s->soc.avic), 52),
1249bca0edbSPeter Maydell 14745600, serial_hd(2), DEVICE_NATIVE_ENDIAN);
12553018216SPaolo Bonzini }
12653018216SPaolo Bonzini
127f044ac49SJean-Christophe Dubois kzm_binfo.ram_size = machine->ram_size;
128f044ac49SJean-Christophe Dubois
129f044ac49SJean-Christophe Dubois if (!qtest_enabled()) {
1302744ece8STao Xu arm_load_kernel(&s->soc.cpu, machine, &kzm_binfo);
131f044ac49SJean-Christophe Dubois }
13253018216SPaolo Bonzini }
13353018216SPaolo Bonzini
kzm_machine_init(MachineClass * mc)134e264d29dSEduardo Habkost static void kzm_machine_init(MachineClass *mc)
13553018216SPaolo Bonzini {
136e264d29dSEduardo Habkost mc->desc = "ARM KZM Emulation Baseboard (ARM1136)";
137e264d29dSEduardo Habkost mc->init = kzm_init;
1384672cbd7SPeter Maydell mc->ignore_memory_transaction_failures = true;
1393865cfacSIgor Mammedov mc->default_ram_id = "kzm.ram";
14053018216SPaolo Bonzini }
14153018216SPaolo Bonzini
142e264d29dSEduardo Habkost DEFINE_MACHINE("kzm", kzm_machine_init)
143