]>
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 | */ | |
11 | #include "console.h" | |
12 | #include "elf.h" | |
13 | #include "exec-memory.h" | |
14 | #include "sysbus.h" | |
15 | #include "boards.h" | |
16 | #include "loader.h" | |
17 | #include "pc.h" | |
18 | ||
19 | #undef DEBUG_PUV3 | |
20 | #include "puv3.h" | |
21 | ||
22 | #define KERNEL_LOAD_ADDR 0x03000000 | |
23 | #define KERNEL_MAX_SIZE 0x00800000 /* Just a guess */ | |
24 | ||
5c8556a6 GX |
25 | static void puv3_intc_cpu_handler(void *opaque, int irq, int level) |
26 | { | |
27 | CPUUniCore32State *env = opaque; | |
28 | ||
29 | assert(irq == 0); | |
30 | if (level) { | |
31 | cpu_interrupt(env, CPU_INTERRUPT_HARD); | |
32 | } else { | |
33 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); | |
34 | } | |
35 | } | |
36 | ||
fbbdf983 GX |
37 | static void puv3_soc_init(CPUUniCore32State *env) |
38 | { | |
5c8556a6 GX |
39 | qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR]; |
40 | DeviceState *dev; | |
41 | int i; | |
42 | ||
43 | /* Initialize interrupt controller */ | |
44 | cpu_intc = qemu_allocate_irqs(puv3_intc_cpu_handler, env, 1); | |
45 | dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, *cpu_intc); | |
46 | for (i = 0; i < PUV3_IRQS_NR; i++) { | |
47 | irqs[i] = qdev_get_gpio_in(dev, i); | |
48 | } | |
56d07a90 GX |
49 | |
50 | /* Initialize minimal necessary devices for kernel booting */ | |
f716c197 | 51 | sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL); |
56d07a90 | 52 | sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]); |
a89d01c1 GX |
53 | sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE, |
54 | irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1], | |
55 | irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3], | |
56 | irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5], | |
57 | irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7], | |
58 | irqs[PUV3_IRQS_GPIOHIGH], NULL); | |
fbbdf983 GX |
59 | } |
60 | ||
61 | static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size) | |
62 | { | |
63 | MemoryRegion *ram_memory = g_new(MemoryRegion, 1); | |
64 | ||
65 | /* SDRAM at address zero. */ | |
66 | memory_region_init_ram(ram_memory, "puv3.ram", ram_size); | |
67 | vmstate_register_ram_global(ram_memory); | |
68 | memory_region_add_subregion(get_system_memory(), 0, ram_memory); | |
69 | } | |
70 | ||
71 | static void puv3_load_kernel(const char *kernel_filename) | |
72 | { | |
73 | int size; | |
74 | ||
75 | assert(kernel_filename != NULL); | |
76 | ||
77 | /* only zImage format supported */ | |
78 | size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR, | |
79 | KERNEL_MAX_SIZE); | |
80 | if (size < 0) { | |
81 | hw_error("Load kernel error: '%s'\n", kernel_filename); | |
82 | } | |
83 | ||
84 | /* cheat curses that we have a graphic console, only under ocd console */ | |
85 | graphic_console_init(NULL, NULL, NULL, NULL, NULL); | |
86 | } | |
87 | ||
88 | static void puv3_init(ram_addr_t ram_size, const char *boot_device, | |
89 | const char *kernel_filename, const char *kernel_cmdline, | |
90 | const char *initrd_filename, const char *cpu_model) | |
91 | { | |
92 | CPUUniCore32State *env; | |
93 | ||
94 | if (initrd_filename) { | |
95 | hw_error("Please use kernel built-in initramdisk.\n"); | |
96 | } | |
97 | ||
98 | if (!cpu_model) { | |
99 | cpu_model = "UniCore-II"; | |
100 | } | |
101 | ||
102 | env = cpu_init(cpu_model); | |
103 | if (!env) { | |
104 | hw_error("Unable to find CPU definition\n"); | |
105 | } | |
106 | ||
107 | puv3_soc_init(env); | |
108 | puv3_board_init(env, ram_size); | |
109 | puv3_load_kernel(kernel_filename); | |
110 | } | |
111 | ||
112 | static QEMUMachine puv3_machine = { | |
113 | .name = "puv3", | |
114 | .desc = "PKUnity Version-3 based on UniCore32", | |
115 | .init = puv3_init, | |
116 | .use_scsi = 0, | |
117 | }; | |
118 | ||
119 | static void puv3_machine_init(void) | |
120 | { | |
121 | qemu_register_machine(&puv3_machine); | |
122 | } | |
123 | ||
124 | machine_init(puv3_machine_init) |