]>
Commit | Line | Data |
---|---|---|
fbbdf983 GX |
1 | /* |
2 | * Generic PKUnity SoC machine and board descriptor | |
3 | * | |
4 | * Copyright (C) 2010-2012 Guan Xuetao | |
5 | * | |
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. | |
10 | */ | |
077805fa PB |
11 | |
12 | #include "qemu-common.h" | |
28ecbaee | 13 | #include "ui/console.h" |
fbbdf983 | 14 | #include "elf.h" |
022c62cb | 15 | #include "exec/address-spaces.h" |
83c9f4ca PB |
16 | #include "hw/sysbus.h" |
17 | #include "hw/boards.h" | |
18 | #include "hw/loader.h" | |
0d09e41a | 19 | #include "hw/i386/pc.h" |
f741a26c | 20 | #include "sysemu/qtest.h" |
fbbdf983 GX |
21 | |
22 | #undef DEBUG_PUV3 | |
0d09e41a | 23 | #include "hw/unicore32/puv3.h" |
fbbdf983 GX |
24 | |
25 | #define KERNEL_LOAD_ADDR 0x03000000 | |
26 | #define KERNEL_MAX_SIZE 0x00800000 /* Just a guess */ | |
27 | ||
5c8556a6 GX |
28 | static void puv3_intc_cpu_handler(void *opaque, int irq, int level) |
29 | { | |
d8ed887b | 30 | UniCore32CPU *cpu = opaque; |
d8ed887b | 31 | CPUState *cs = CPU(cpu); |
5c8556a6 GX |
32 | |
33 | assert(irq == 0); | |
34 | if (level) { | |
c3affe56 | 35 | cpu_interrupt(cs, CPU_INTERRUPT_HARD); |
5c8556a6 | 36 | } else { |
d8ed887b | 37 | cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); |
5c8556a6 GX |
38 | } |
39 | } | |
40 | ||
fbbdf983 GX |
41 | static void puv3_soc_init(CPUUniCore32State *env) |
42 | { | |
2c85fad0 | 43 | qemu_irq cpu_intc, irqs[PUV3_IRQS_NR]; |
5c8556a6 | 44 | DeviceState *dev; |
79683f61 | 45 | MemoryRegion *i8042 = g_new(MemoryRegion, 1); |
5c8556a6 GX |
46 | int i; |
47 | ||
48 | /* Initialize interrupt controller */ | |
2c85fad0 SZ |
49 | cpu_intc = qemu_allocate_irq(puv3_intc_cpu_handler, |
50 | uc32_env_get_cpu(env), 0); | |
51 | dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, cpu_intc); | |
5c8556a6 GX |
52 | for (i = 0; i < PUV3_IRQS_NR; i++) { |
53 | irqs[i] = qdev_get_gpio_in(dev, i); | |
54 | } | |
56d07a90 GX |
55 | |
56 | /* Initialize minimal necessary devices for kernel booting */ | |
f716c197 | 57 | sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL); |
1ea34899 | 58 | sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL); |
56d07a90 | 59 | sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]); |
a89d01c1 GX |
60 | sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, |
61 | irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1], | |
62 | irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3], | |
63 | irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5], | |
64 | irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7], | |
65 | irqs[PUV3_IRQS_GPIOHIGH], NULL); | |
79683f61 GX |
66 | |
67 | /* Keyboard (i8042), mouse disabled for nographic */ | |
68 | i8042_mm_init(irqs[PUV3_IRQS_PS2_KBD], NULL, i8042, PUV3_REGS_OFFSET, 4); | |
69 | memory_region_add_subregion(get_system_memory(), PUV3_PS2_BASE, i8042); | |
fbbdf983 GX |
70 | } |
71 | ||
72 | static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size) | |
73 | { | |
74 | MemoryRegion *ram_memory = g_new(MemoryRegion, 1); | |
75 | ||
76 | /* SDRAM at address zero. */ | |
49946538 | 77 | memory_region_init_ram(ram_memory, NULL, "puv3.ram", ram_size, |
f8ed85ac | 78 | &error_fatal); |
fbbdf983 GX |
79 | vmstate_register_ram_global(ram_memory); |
80 | memory_region_add_subregion(get_system_memory(), 0, ram_memory); | |
81 | } | |
82 | ||
380cd056 GH |
83 | static const GraphicHwOps no_ops; |
84 | ||
fbbdf983 GX |
85 | static void puv3_load_kernel(const char *kernel_filename) |
86 | { | |
87 | int size; | |
88 | ||
f741a26c AF |
89 | if (kernel_filename == NULL && qtest_enabled()) { |
90 | return; | |
91 | } | |
fbbdf983 GX |
92 | assert(kernel_filename != NULL); |
93 | ||
94 | /* only zImage format supported */ | |
95 | size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, | |
96 | KERNEL_MAX_SIZE); | |
97 | if (size < 0) { | |
98 | hw_error("Load kernel error: '%s'\n", kernel_filename); | |
99 | } | |
100 | ||
101 | /* cheat curses that we have a graphic console, only under ocd console */ | |
5643706a | 102 | graphic_console_init(NULL, 0, &no_ops, NULL); |
fbbdf983 GX |
103 | } |
104 | ||
3ef96221 | 105 | static void puv3_init(MachineState *machine) |
fbbdf983 | 106 | { |
3ef96221 MA |
107 | ram_addr_t ram_size = machine->ram_size; |
108 | const char *cpu_model = machine->cpu_model; | |
109 | const char *kernel_filename = machine->kernel_filename; | |
110 | const char *initrd_filename = machine->initrd_filename; | |
fbbdf983 | 111 | CPUUniCore32State *env; |
c3898f77 | 112 | UniCore32CPU *cpu; |
fbbdf983 GX |
113 | |
114 | if (initrd_filename) { | |
115 | hw_error("Please use kernel built-in initramdisk.\n"); | |
116 | } | |
117 | ||
118 | if (!cpu_model) { | |
119 | cpu_model = "UniCore-II"; | |
120 | } | |
121 | ||
c3898f77 EH |
122 | cpu = uc32_cpu_init(cpu_model); |
123 | if (!cpu) { | |
fbbdf983 GX |
124 | hw_error("Unable to find CPU definition\n"); |
125 | } | |
c3898f77 | 126 | env = &cpu->env; |
fbbdf983 GX |
127 | |
128 | puv3_soc_init(env); | |
129 | puv3_board_init(env, ram_size); | |
130 | puv3_load_kernel(kernel_filename); | |
131 | } | |
132 | ||
133 | static QEMUMachine puv3_machine = { | |
134 | .name = "puv3", | |
135 | .desc = "PKUnity Version-3 based on UniCore32", | |
136 | .init = puv3_init, | |
220c2147 | 137 | .is_default = 1, |
fbbdf983 GX |
138 | }; |
139 | ||
140 | static void puv3_machine_init(void) | |
141 | { | |
142 | qemu_register_machine(&puv3_machine); | |
143 | } | |
144 | ||
145 | machine_init(puv3_machine_init) |