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