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