xref: /openbmc/qemu/hw/arm/kzm.c (revision 489653b5)
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(MachineState *machine)
74 {
75     ram_addr_t ram_size = machine->ram_size;
76     const char *cpu_model = machine->cpu_model;
77     const char *kernel_filename = machine->kernel_filename;
78     const char *kernel_cmdline = machine->kernel_cmdline;
79     const char *initrd_filename = machine->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_allocate_system_memory(ram, NULL, "kzm.ram", ram_size);
101     memory_region_add_subregion(address_space_mem, KZM_RAMADDRESS, ram);
102 
103     memory_region_init_alias(ram_alias, NULL, "ram.alias", ram, 0, ram_size);
104     memory_region_add_subregion(address_space_mem, 0x88000000, ram_alias);
105 
106     memory_region_init_ram(sram, NULL, "kzm.sram", 0x4000, &error_abort);
107     memory_region_add_subregion(address_space_mem, 0x1FFFC000, sram);
108 
109     dev = sysbus_create_varargs("imx_avic", 0x68000000,
110                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ),
111                                 qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_FIQ),
112                                 NULL);
113 
114     imx_serial_create(0, 0x43f90000, qdev_get_gpio_in(dev, 45));
115     imx_serial_create(1, 0x43f94000, qdev_get_gpio_in(dev, 32));
116 
117     ccm = sysbus_create_simple("imx_ccm", 0x53f80000, NULL);
118 
119     imx_timerp_create(0x53f94000, qdev_get_gpio_in(dev, 28), ccm);
120     imx_timerp_create(0x53f98000, qdev_get_gpio_in(dev, 27), ccm);
121     imx_timerg_create(0x53f90000, qdev_get_gpio_in(dev, 29), ccm);
122 
123     if (nd_table[0].used) {
124         lan9118_init(&nd_table[0], 0xb6000000, qdev_get_gpio_in(dev, 52));
125     }
126 
127     if (serial_hds[2]) { /* touchscreen */
128         serial_mm_init(address_space_mem, KZM_FPGA+0x10, 0,
129                        qdev_get_gpio_in(dev, 52),
130                        14745600, serial_hds[2],
131                        DEVICE_NATIVE_ENDIAN);
132     }
133 
134     kzm_binfo.ram_size = ram_size;
135     kzm_binfo.kernel_filename = kernel_filename;
136     kzm_binfo.kernel_cmdline = kernel_cmdline;
137     kzm_binfo.initrd_filename = initrd_filename;
138     kzm_binfo.nb_cpus = 1;
139     arm_load_kernel(cpu, &kzm_binfo);
140 }
141 
142 static QEMUMachine kzm_machine = {
143     .name = "kzm",
144     .desc = "ARM KZM Emulation Baseboard (ARM1136)",
145     .init = kzm_init,
146 };
147 
148 static void kzm_machine_init(void)
149 {
150     qemu_register_machine(&kzm_machine);
151 }
152 
153 machine_init(kzm_machine_init)
154