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/arm.h" 20 #include "hw/devices.h" 21 #include "net/net.h" 22 #include "sysemu/sysemu.h" 23 #include "hw/boards.h" 24 #include "hw/char/serial.h" 25 #include "hw/arm/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 DeviceState *dev; 86 DeviceState *ccm; 87 88 if (!cpu_model) { 89 cpu_model = "arm1136"; 90 } 91 92 cpu = cpu_arm_init(cpu_model); 93 if (!cpu) { 94 fprintf(stderr, "Unable to find CPU definition\n"); 95 exit(1); 96 } 97 98 /* On a real system, the first 16k is a `secure boot rom' */ 99 100 memory_region_init_ram(ram, NULL, "kzm.ram", ram_size); 101 vmstate_register_ram_global(ram); 102 memory_region_add_subregion(address_space_mem, KZM_RAMADDRESS, ram); 103 104 memory_region_init_alias(ram_alias, NULL, "ram.alias", ram, 0, ram_size); 105 memory_region_add_subregion(address_space_mem, 0x88000000, ram_alias); 106 107 memory_region_init_ram(sram, NULL, "kzm.sram", 0x4000); 108 memory_region_add_subregion(address_space_mem, 0x1FFFC000, sram); 109 110 dev = sysbus_create_varargs("imx_avic", 0x68000000, 111 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ), 112 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ), 113 NULL); 114 115 imx_serial_create(0, 0x43f90000, qdev_get_gpio_in(dev, 45)); 116 imx_serial_create(1, 0x43f94000, qdev_get_gpio_in(dev, 32)); 117 118 ccm = sysbus_create_simple("imx_ccm", 0x53f80000, NULL); 119 120 imx_timerp_create(0x53f94000, qdev_get_gpio_in(dev, 28), ccm); 121 imx_timerp_create(0x53f98000, qdev_get_gpio_in(dev, 27), ccm); 122 imx_timerg_create(0x53f90000, qdev_get_gpio_in(dev, 29), ccm); 123 124 if (nd_table[0].used) { 125 lan9118_init(&nd_table[0], 0xb6000000, qdev_get_gpio_in(dev, 52)); 126 } 127 128 if (serial_hds[2]) { /* touchscreen */ 129 serial_mm_init(address_space_mem, KZM_FPGA+0x10, 0, 130 qdev_get_gpio_in(dev, 52), 131 14745600, serial_hds[2], 132 DEVICE_NATIVE_ENDIAN); 133 } 134 135 kzm_binfo.ram_size = ram_size; 136 kzm_binfo.kernel_filename = kernel_filename; 137 kzm_binfo.kernel_cmdline = kernel_cmdline; 138 kzm_binfo.initrd_filename = initrd_filename; 139 kzm_binfo.nb_cpus = 1; 140 arm_load_kernel(cpu, &kzm_binfo); 141 } 142 143 static QEMUMachine kzm_machine = { 144 .name = "kzm", 145 .desc = "ARM KZM Emulation Baseboard (ARM1136)", 146 .init = kzm_init, 147 DEFAULT_MACHINE_OPTIONS, 148 }; 149 150 static void kzm_machine_init(void) 151 { 152 qemu_register_machine(&kzm_machine); 153 } 154 155 machine_init(kzm_machine_init) 156