1 /* 2 * KZM Board System emulation. 3 * 4 * Copyright (c) 2008 OKL and 2011 NICTA 5 * Written by Hans at OK-Labs 6 * Updated by Peter Chubb. 7 * 8 * This code is licensed under the GPL, version 2 or later. 9 * See the file `COPYING' in the top level directory. 10 * 11 * It (partially) emulates a Kyoto Microcomputer 12 * KZM-ARM11-01 evaluation board, with a Freescale 13 * i.MX31 SoC 14 */ 15 16 #include "hw/sysbus.h" 17 #include "exec/address-spaces.h" 18 #include "hw/hw.h" 19 #include "hw/arm-misc.h" 20 #include "hw/devices.h" 21 #include "net/net.h" 22 #include "sysemu/sysemu.h" 23 #include "hw/boards.h" 24 #include "hw/serial.h" 25 #include "hw/imx.h" 26 27 /* Memory map for Kzm Emulation Baseboard: 28 * 0x00000000-0x00003fff 16k secure ROM IGNORED 29 * 0x00004000-0x00407fff Reserved IGNORED 30 * 0x00404000-0x00407fff ROM IGNORED 31 * 0x00408000-0x0fffffff Reserved IGNORED 32 * 0x10000000-0x1fffbfff RAM aliasing IGNORED 33 * 0x1fffc000-0x1fffffff RAM EMULATED 34 * 0x20000000-0x2fffffff Reserved IGNORED 35 * 0x30000000-0x7fffffff I.MX31 Internal Register Space 36 * 0x43f00000 IO_AREA0 37 * 0x43f90000 UART1 EMULATED 38 * 0x43f94000 UART2 EMULATED 39 * 0x68000000 AVIC EMULATED 40 * 0x53f80000 CCM EMULATED 41 * 0x53f94000 PIT 1 EMULATED 42 * 0x53f98000 PIT 2 EMULATED 43 * 0x53f90000 GPT EMULATED 44 * 0x80000000-0x87ffffff RAM EMULATED 45 * 0x88000000-0x8fffffff RAM Aliasing EMULATED 46 * 0xa0000000-0xafffffff NAND Flash IGNORED 47 * 0xb0000000-0xb3ffffff Unavailable IGNORED 48 * 0xb4000000-0xb4000fff 8-bit free space IGNORED 49 * 0xb4001000-0xb400100f Board control IGNORED 50 * 0xb4001003 DIP switch 51 * 0xb4001010-0xb400101f 7-segment LED IGNORED 52 * 0xb4001020-0xb400102f LED IGNORED 53 * 0xb4001030-0xb400103f LED IGNORED 54 * 0xb4001040-0xb400104f FPGA, UART EMULATED 55 * 0xb4001050-0xb400105f FPGA, UART EMULATED 56 * 0xb4001060-0xb40fffff FPGA IGNORED 57 * 0xb6000000-0xb61fffff LAN controller EMULATED 58 * 0xb6200000-0xb62fffff FPGA NAND Controller IGNORED 59 * 0xb6300000-0xb7ffffff Free IGNORED 60 * 0xb8000000-0xb8004fff Memory control registers IGNORED 61 * 0xc0000000-0xc3ffffff PCMCIA/CF IGNORED 62 * 0xc4000000-0xffffffff Reserved IGNORED 63 */ 64 65 #define KZM_RAMADDRESS (0x80000000) 66 #define KZM_FPGA (0xb4001040) 67 68 static struct arm_boot_info kzm_binfo = { 69 .loader_start = KZM_RAMADDRESS, 70 .board_id = 1722, 71 }; 72 73 static void kzm_init(QEMUMachineInitArgs *args) 74 { 75 ram_addr_t ram_size = args->ram_size; 76 const char *cpu_model = args->cpu_model; 77 const char *kernel_filename = args->kernel_filename; 78 const char *kernel_cmdline = args->kernel_cmdline; 79 const char *initrd_filename = args->initrd_filename; 80 ARMCPU *cpu; 81 MemoryRegion *address_space_mem = get_system_memory(); 82 MemoryRegion *ram = g_new(MemoryRegion, 1); 83 MemoryRegion *sram = g_new(MemoryRegion, 1); 84 MemoryRegion *ram_alias = g_new(MemoryRegion, 1); 85 qemu_irq *cpu_pic; 86 DeviceState *dev; 87 DeviceState *ccm; 88 89 if (!cpu_model) { 90 cpu_model = "arm1136"; 91 } 92 93 cpu = cpu_arm_init(cpu_model); 94 if (!cpu) { 95 fprintf(stderr, "Unable to find CPU definition\n"); 96 exit(1); 97 } 98 99 /* On a real system, the first 16k is a `secure boot rom' */ 100 101 memory_region_init_ram(ram, "kzm.ram", ram_size); 102 vmstate_register_ram_global(ram); 103 memory_region_add_subregion(address_space_mem, KZM_RAMADDRESS, ram); 104 105 memory_region_init_alias(ram_alias, "ram.alias", ram, 0, ram_size); 106 memory_region_add_subregion(address_space_mem, 0x88000000, ram_alias); 107 108 memory_region_init_ram(sram, "kzm.sram", 0x4000); 109 memory_region_add_subregion(address_space_mem, 0x1FFFC000, sram); 110 111 cpu_pic = arm_pic_init_cpu(cpu); 112 dev = sysbus_create_varargs("imx_avic", 0x68000000, 113 cpu_pic[ARM_PIC_CPU_IRQ], 114 cpu_pic[ARM_PIC_CPU_FIQ], NULL); 115 116 117 imx_serial_create(0, 0x43f90000, qdev_get_gpio_in(dev, 45)); 118 imx_serial_create(1, 0x43f94000, qdev_get_gpio_in(dev, 32)); 119 120 ccm = sysbus_create_simple("imx_ccm", 0x53f80000, NULL); 121 122 imx_timerp_create(0x53f94000, qdev_get_gpio_in(dev, 28), ccm); 123 imx_timerp_create(0x53f98000, qdev_get_gpio_in(dev, 27), ccm); 124 imx_timerg_create(0x53f90000, qdev_get_gpio_in(dev, 29), ccm); 125 126 if (nd_table[0].used) { 127 lan9118_init(&nd_table[0], 0xb6000000, qdev_get_gpio_in(dev, 52)); 128 } 129 130 if (serial_hds[2]) { /* touchscreen */ 131 serial_mm_init(address_space_mem, KZM_FPGA+0x10, 0, 132 qdev_get_gpio_in(dev, 52), 133 14745600, serial_hds[2], 134 DEVICE_NATIVE_ENDIAN); 135 } 136 137 kzm_binfo.ram_size = ram_size; 138 kzm_binfo.kernel_filename = kernel_filename; 139 kzm_binfo.kernel_cmdline = kernel_cmdline; 140 kzm_binfo.initrd_filename = initrd_filename; 141 kzm_binfo.nb_cpus = 1; 142 arm_load_kernel(cpu, &kzm_binfo); 143 } 144 145 static QEMUMachine kzm_machine = { 146 .name = "kzm", 147 .desc = "ARM KZM Emulation Baseboard (ARM1136)", 148 .init = kzm_init, 149 DEFAULT_MACHINE_OPTIONS, 150 }; 151 152 static void kzm_machine_init(void) 153 { 154 qemu_register_machine(&kzm_machine); 155 } 156 157 machine_init(kzm_machine_init) 158