tests: Test blockjob IDs
[qemu/ar7.git] / hw / unicore32 / puv3.c
blob31cd171016a8ab11db9a780204469366d357f427
1 /*
2 * Generic PKUnity SoC machine and board descriptor
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu-common.h"
15 #include "cpu.h"
16 #include "qemu-common.h"
17 #include "ui/console.h"
18 #include "elf.h"
19 #include "exec/address-spaces.h"
20 #include "hw/sysbus.h"
21 #include "hw/boards.h"
22 #include "hw/loader.h"
23 #include "hw/i386/pc.h"
24 #include "qemu/error-report.h"
25 #include "sysemu/qtest.h"
27 #undef DEBUG_PUV3
28 #include "hw/unicore32/puv3.h"
30 #define KERNEL_LOAD_ADDR 0x03000000
31 #define KERNEL_MAX_SIZE 0x00800000 /* Just a guess */
33 static void puv3_intc_cpu_handler(void *opaque, int irq, int level)
35 UniCore32CPU *cpu = opaque;
36 CPUState *cs = CPU(cpu);
38 assert(irq == 0);
39 if (level) {
40 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
41 } else {
42 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
46 static void puv3_soc_init(CPUUniCore32State *env)
48 qemu_irq cpu_intc, irqs[PUV3_IRQS_NR];
49 DeviceState *dev;
50 MemoryRegion *i8042 = g_new(MemoryRegion, 1);
51 int i;
53 /* Initialize interrupt controller */
54 cpu_intc = qemu_allocate_irq(puv3_intc_cpu_handler,
55 uc32_env_get_cpu(env), 0);
56 dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, cpu_intc);
57 for (i = 0; i < PUV3_IRQS_NR; i++) {
58 irqs[i] = qdev_get_gpio_in(dev, i);
61 /* Initialize minimal necessary devices for kernel booting */
62 sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL);
63 sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL);
64 sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
65 sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
66 irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
67 irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3],
68 irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5],
69 irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7],
70 irqs[PUV3_IRQS_GPIOHIGH], NULL);
72 /* Keyboard (i8042), mouse disabled for nographic */
73 i8042_mm_init(irqs[PUV3_IRQS_PS2_KBD], NULL, i8042, PUV3_REGS_OFFSET, 4);
74 memory_region_add_subregion(get_system_memory(), PUV3_PS2_BASE, i8042);
77 static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
79 MemoryRegion *ram_memory = g_new(MemoryRegion, 1);
81 /* SDRAM at address zero. */
82 memory_region_init_ram(ram_memory, NULL, "puv3.ram", ram_size,
83 &error_fatal);
84 vmstate_register_ram_global(ram_memory);
85 memory_region_add_subregion(get_system_memory(), 0, ram_memory);
88 static const GraphicHwOps no_ops;
90 static void puv3_load_kernel(const char *kernel_filename)
92 int size;
94 if (kernel_filename == NULL && qtest_enabled()) {
95 return;
97 assert(kernel_filename != NULL);
99 /* only zImage format supported */
100 size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
101 KERNEL_MAX_SIZE);
102 if (size < 0) {
103 error_report("Load kernel error: '%s'", kernel_filename);
104 exit(1);
107 /* cheat curses that we have a graphic console, only under ocd console */
108 graphic_console_init(NULL, 0, &no_ops, NULL);
111 static void puv3_init(MachineState *machine)
113 ram_addr_t ram_size = machine->ram_size;
114 const char *cpu_model = machine->cpu_model;
115 const char *kernel_filename = machine->kernel_filename;
116 const char *initrd_filename = machine->initrd_filename;
117 CPUUniCore32State *env;
118 UniCore32CPU *cpu;
120 if (initrd_filename) {
121 error_report("Please use kernel built-in initramdisk");
122 exit(1);
125 if (!cpu_model) {
126 cpu_model = "UniCore-II";
129 cpu = uc32_cpu_init(cpu_model);
130 if (!cpu) {
131 error_report("Unable to find CPU definition");
132 exit(1);
134 env = &cpu->env;
136 puv3_soc_init(env);
137 puv3_board_init(env, ram_size);
138 puv3_load_kernel(kernel_filename);
141 static void puv3_machine_init(MachineClass *mc)
143 mc->desc = "PKUnity Version-3 based on UniCore32";
144 mc->init = puv3_init;
145 mc->is_default = 1;
148 DEFINE_MACHINE("puv3", puv3_machine_init)