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