io: cope with websock 'Connection' header having multiple values
[qemu/ar7.git] / hw / lm32 / lm32_boards.c
blobb0bb3ef58af4af8234799c099d0a160fc4638e57
1 /*
2 * QEMU models for LatticeMico32 uclinux and evr32 boards.
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu-common.h"
22 #include "cpu.h"
23 #include "hw/sysbus.h"
24 #include "hw/hw.h"
25 #include "hw/block/flash.h"
26 #include "hw/devices.h"
27 #include "hw/boards.h"
28 #include "hw/loader.h"
29 #include "sysemu/block-backend.h"
30 #include "elf.h"
31 #include "lm32_hwsetup.h"
32 #include "lm32.h"
33 #include "exec/address-spaces.h"
34 #include "sysemu/sysemu.h"
36 typedef struct {
37 LM32CPU *cpu;
38 hwaddr bootstrap_pc;
39 hwaddr flash_base;
40 hwaddr hwsetup_base;
41 hwaddr initrd_base;
42 size_t initrd_size;
43 hwaddr cmdline_base;
44 } ResetInfo;
46 static void cpu_irq_handler(void *opaque, int irq, int level)
48 LM32CPU *cpu = opaque;
49 CPUState *cs = CPU(cpu);
51 if (level) {
52 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
53 } else {
54 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
58 static void main_cpu_reset(void *opaque)
60 ResetInfo *reset_info = opaque;
61 CPULM32State *env = &reset_info->cpu->env;
63 cpu_reset(CPU(reset_info->cpu));
65 /* init defaults */
66 env->pc = (uint32_t)reset_info->bootstrap_pc;
67 env->regs[R_R1] = (uint32_t)reset_info->hwsetup_base;
68 env->regs[R_R2] = (uint32_t)reset_info->cmdline_base;
69 env->regs[R_R3] = (uint32_t)reset_info->initrd_base;
70 env->regs[R_R4] = (uint32_t)(reset_info->initrd_base +
71 reset_info->initrd_size);
72 env->eba = reset_info->flash_base;
73 env->deba = reset_info->flash_base;
76 static void lm32_evr_init(MachineState *machine)
78 const char *cpu_model = machine->cpu_model;
79 const char *kernel_filename = machine->kernel_filename;
80 LM32CPU *cpu;
81 CPULM32State *env;
82 DriveInfo *dinfo;
83 MemoryRegion *address_space_mem = get_system_memory();
84 MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
85 qemu_irq irq[32];
86 ResetInfo *reset_info;
87 int i;
89 /* memory map */
90 hwaddr flash_base = 0x04000000;
91 size_t flash_sector_size = 256 * 1024;
92 size_t flash_size = 32 * 1024 * 1024;
93 hwaddr ram_base = 0x08000000;
94 size_t ram_size = 64 * 1024 * 1024;
95 hwaddr timer0_base = 0x80002000;
96 hwaddr uart0_base = 0x80006000;
97 hwaddr timer1_base = 0x8000a000;
98 int uart0_irq = 0;
99 int timer0_irq = 1;
100 int timer1_irq = 3;
102 reset_info = g_malloc0(sizeof(ResetInfo));
104 if (cpu_model == NULL) {
105 cpu_model = "lm32-full";
107 cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
109 env = &cpu->env;
110 reset_info->cpu = cpu;
112 reset_info->flash_base = flash_base;
114 memory_region_allocate_system_memory(phys_ram, NULL, "lm32_evr.sdram",
115 ram_size);
116 memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
118 dinfo = drive_get(IF_PFLASH, 0, 0);
119 /* Spansion S29NS128P */
120 pflash_cfi02_register(flash_base, NULL, "lm32_evr.flash", flash_size,
121 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
122 flash_sector_size, flash_size / flash_sector_size,
123 1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
125 /* create irq lines */
126 env->pic_state = lm32_pic_init(qemu_allocate_irq(cpu_irq_handler, cpu, 0));
127 for (i = 0; i < 32; i++) {
128 irq[i] = qdev_get_gpio_in(env->pic_state, i);
131 lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
132 sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
133 sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
135 /* make sure juart isn't the first chardev */
136 env->juart_state = lm32_juart_init(serial_hds[1]);
138 reset_info->bootstrap_pc = flash_base;
140 if (kernel_filename) {
141 uint64_t entry;
142 int kernel_size;
144 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
145 1, EM_LATTICEMICO32, 0, 0);
146 reset_info->bootstrap_pc = entry;
148 if (kernel_size < 0) {
149 kernel_size = load_image_targphys(kernel_filename, ram_base,
150 ram_size);
151 reset_info->bootstrap_pc = ram_base;
154 if (kernel_size < 0) {
155 fprintf(stderr, "qemu: could not load kernel '%s'\n",
156 kernel_filename);
157 exit(1);
161 qemu_register_reset(main_cpu_reset, reset_info);
164 static void lm32_uclinux_init(MachineState *machine)
166 const char *cpu_model = machine->cpu_model;
167 const char *kernel_filename = machine->kernel_filename;
168 const char *kernel_cmdline = machine->kernel_cmdline;
169 const char *initrd_filename = machine->initrd_filename;
170 LM32CPU *cpu;
171 CPULM32State *env;
172 DriveInfo *dinfo;
173 MemoryRegion *address_space_mem = get_system_memory();
174 MemoryRegion *phys_ram = g_new(MemoryRegion, 1);
175 qemu_irq irq[32];
176 HWSetup *hw;
177 ResetInfo *reset_info;
178 int i;
180 /* memory map */
181 hwaddr flash_base = 0x04000000;
182 size_t flash_sector_size = 256 * 1024;
183 size_t flash_size = 32 * 1024 * 1024;
184 hwaddr ram_base = 0x08000000;
185 size_t ram_size = 64 * 1024 * 1024;
186 hwaddr uart0_base = 0x80000000;
187 hwaddr timer0_base = 0x80002000;
188 hwaddr timer1_base = 0x80010000;
189 hwaddr timer2_base = 0x80012000;
190 int uart0_irq = 0;
191 int timer0_irq = 1;
192 int timer1_irq = 20;
193 int timer2_irq = 21;
194 hwaddr hwsetup_base = 0x0bffe000;
195 hwaddr cmdline_base = 0x0bfff000;
196 hwaddr initrd_base = 0x08400000;
197 size_t initrd_max = 0x01000000;
199 reset_info = g_malloc0(sizeof(ResetInfo));
201 if (cpu_model == NULL) {
202 cpu_model = "lm32-full";
204 cpu = LM32_CPU(cpu_generic_init(TYPE_LM32_CPU, cpu_model));
206 env = &cpu->env;
207 reset_info->cpu = cpu;
209 reset_info->flash_base = flash_base;
211 memory_region_allocate_system_memory(phys_ram, NULL,
212 "lm32_uclinux.sdram", ram_size);
213 memory_region_add_subregion(address_space_mem, ram_base, phys_ram);
215 dinfo = drive_get(IF_PFLASH, 0, 0);
216 /* Spansion S29NS128P */
217 pflash_cfi02_register(flash_base, NULL, "lm32_uclinux.flash", flash_size,
218 dinfo ? blk_by_legacy_dinfo(dinfo) : NULL,
219 flash_sector_size, flash_size / flash_sector_size,
220 1, 2, 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1);
222 /* create irq lines */
223 env->pic_state = lm32_pic_init(qemu_allocate_irq(cpu_irq_handler, env, 0));
224 for (i = 0; i < 32; i++) {
225 irq[i] = qdev_get_gpio_in(env->pic_state, i);
228 lm32_uart_create(uart0_base, irq[uart0_irq], serial_hds[0]);
229 sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
230 sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
231 sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
233 /* make sure juart isn't the first chardev */
234 env->juart_state = lm32_juart_init(serial_hds[1]);
236 reset_info->bootstrap_pc = flash_base;
238 if (kernel_filename) {
239 uint64_t entry;
240 int kernel_size;
242 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
243 1, EM_LATTICEMICO32, 0, 0);
244 reset_info->bootstrap_pc = entry;
246 if (kernel_size < 0) {
247 kernel_size = load_image_targphys(kernel_filename, ram_base,
248 ram_size);
249 reset_info->bootstrap_pc = ram_base;
252 if (kernel_size < 0) {
253 fprintf(stderr, "qemu: could not load kernel '%s'\n",
254 kernel_filename);
255 exit(1);
259 /* generate a rom with the hardware description */
260 hw = hwsetup_init();
261 hwsetup_add_cpu(hw, "LM32", 75000000);
262 hwsetup_add_flash(hw, "flash", flash_base, flash_size);
263 hwsetup_add_ddr_sdram(hw, "ddr_sdram", ram_base, ram_size);
264 hwsetup_add_timer(hw, "timer0", timer0_base, timer0_irq);
265 hwsetup_add_timer(hw, "timer1_dev_only", timer1_base, timer1_irq);
266 hwsetup_add_timer(hw, "timer2_dev_only", timer2_base, timer2_irq);
267 hwsetup_add_uart(hw, "uart", uart0_base, uart0_irq);
268 hwsetup_add_trailer(hw);
269 hwsetup_create_rom(hw, hwsetup_base);
270 hwsetup_free(hw);
272 reset_info->hwsetup_base = hwsetup_base;
274 if (kernel_cmdline && strlen(kernel_cmdline)) {
275 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
276 kernel_cmdline);
277 reset_info->cmdline_base = cmdline_base;
280 if (initrd_filename) {
281 size_t initrd_size;
282 initrd_size = load_image_targphys(initrd_filename, initrd_base,
283 initrd_max);
284 reset_info->initrd_base = initrd_base;
285 reset_info->initrd_size = initrd_size;
288 qemu_register_reset(main_cpu_reset, reset_info);
291 static void lm32_evr_class_init(ObjectClass *oc, void *data)
293 MachineClass *mc = MACHINE_CLASS(oc);
295 mc->desc = "LatticeMico32 EVR32 eval system";
296 mc->init = lm32_evr_init;
297 mc->is_default = 1;
300 static const TypeInfo lm32_evr_type = {
301 .name = MACHINE_TYPE_NAME("lm32-evr"),
302 .parent = TYPE_MACHINE,
303 .class_init = lm32_evr_class_init,
306 static void lm32_uclinux_class_init(ObjectClass *oc, void *data)
308 MachineClass *mc = MACHINE_CLASS(oc);
310 mc->desc = "lm32 platform for uClinux and u-boot by Theobroma Systems";
311 mc->init = lm32_uclinux_init;
312 mc->is_default = 0;
315 static const TypeInfo lm32_uclinux_type = {
316 .name = MACHINE_TYPE_NAME("lm32-uclinux"),
317 .parent = TYPE_MACHINE,
318 .class_init = lm32_uclinux_class_init,
321 static void lm32_machine_init(void)
323 type_register_static(&lm32_evr_type);
324 type_register_static(&lm32_uclinux_type);
327 type_init(lm32_machine_init)