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