]> git.proxmox.com Git - qemu.git/blame - hw/milkymist.c
softmmu: move include files to include/sysemu/
[qemu.git] / hw / milkymist.c
CommitLineData
5052d227
MW
1/*
2 * QEMU model for the Milkymist board.
3 *
4 * Copyright (c) 2010 Michael Walle <michael@walle.cc>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "sysbus.h"
21#include "hw.h"
5052d227 22#include "flash.h"
9c17d615 23#include "sysemu/sysemu.h"
5052d227
MW
24#include "devices.h"
25#include "boards.h"
26#include "loader.h"
27#include "elf.h"
9c17d615 28#include "sysemu/blockdev.h"
5052d227
MW
29#include "milkymist-hw.h"
30#include "lm32.h"
022c62cb 31#include "exec/address-spaces.h"
5052d227
MW
32
33#define BIOS_FILENAME "mmone-bios.bin"
34#define BIOS_OFFSET 0x00860000
35#define BIOS_SIZE (512*1024)
36#define KERNEL_LOAD_ADDR 0x40000000
37
38typedef struct {
f6932a86 39 LM32CPU *cpu;
a8170e5e
AK
40 hwaddr bootstrap_pc;
41 hwaddr flash_base;
42 hwaddr initrd_base;
5052d227 43 size_t initrd_size;
a8170e5e 44 hwaddr cmdline_base;
5052d227
MW
45} ResetInfo;
46
47static void cpu_irq_handler(void *opaque, int irq, int level)
48{
93a67402 49 CPULM32State *env = opaque;
5052d227
MW
50
51 if (level) {
52 cpu_interrupt(env, CPU_INTERRUPT_HARD);
53 } else {
54 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
55 }
56}
57
58static void main_cpu_reset(void *opaque)
59{
60 ResetInfo *reset_info = opaque;
f6932a86 61 CPULM32State *env = &reset_info->cpu->env;
5052d227 62
f6932a86 63 cpu_reset(CPU(reset_info->cpu));
5052d227
MW
64
65 /* init defaults */
66 env->pc = reset_info->bootstrap_pc;
67 env->regs[R_R1] = reset_info->cmdline_base;
68 env->regs[R_R2] = reset_info->initrd_base;
69 env->regs[R_R3] = reset_info->initrd_base + reset_info->initrd_size;
70 env->eba = reset_info->flash_base;
71 env->deba = reset_info->flash_base;
72}
73
74static void
5f072e1f 75milkymist_init(QEMUMachineInitArgs *args)
5052d227 76{
5f072e1f
EH
77 const char *cpu_model = args->cpu_model;
78 const char *kernel_filename = args->kernel_filename;
79 const char *kernel_cmdline = args->kernel_cmdline;
80 const char *initrd_filename = args->initrd_filename;
1328cc01 81 LM32CPU *cpu;
93a67402 82 CPULM32State *env;
5052d227
MW
83 int kernel_size;
84 DriveInfo *dinfo;
c50a6def
AK
85 MemoryRegion *address_space_mem = get_system_memory();
86 MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
5052d227
MW
87 qemu_irq irq[32], *cpu_irq;
88 int i;
89 char *bios_filename;
90 ResetInfo *reset_info;
91
92 /* memory map */
a8170e5e 93 hwaddr flash_base = 0x00000000;
5052d227
MW
94 size_t flash_sector_size = 128 * 1024;
95 size_t flash_size = 32 * 1024 * 1024;
a8170e5e 96 hwaddr sdram_base = 0x40000000;
5052d227
MW
97 size_t sdram_size = 128 * 1024 * 1024;
98
a8170e5e
AK
99 hwaddr initrd_base = sdram_base + 0x1002000;
100 hwaddr cmdline_base = sdram_base + 0x1000000;
5052d227
MW
101 size_t initrd_max = sdram_size - 0x1002000;
102
7267c094 103 reset_info = g_malloc0(sizeof(ResetInfo));
5052d227
MW
104
105 if (cpu_model == NULL) {
106 cpu_model = "lm32-full";
107 }
1328cc01
AF
108 cpu = cpu_lm32_init(cpu_model);
109 env = &cpu->env;
f6932a86 110 reset_info->cpu = cpu;
5052d227
MW
111
112 cpu_lm32_set_phys_msb_ignore(env, 1);
113
c5705a77
AK
114 memory_region_init_ram(phys_sdram, "milkymist.sdram", sdram_size);
115 vmstate_register_ram_global(phys_sdram);
c50a6def 116 memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram);
5052d227 117
5052d227
MW
118 dinfo = drive_get(IF_PFLASH, 0, 0);
119 /* Numonyx JS28F256J3F105 */
cfe5f011 120 pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
5052d227
MW
121 dinfo ? dinfo->bdrv : NULL, flash_sector_size,
122 flash_size / flash_sector_size, 2,
01e0451a 123 0x00, 0x89, 0x00, 0x1d, 1);
5052d227
MW
124
125 /* create irq lines */
126 cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
127 env->pic_state = lm32_pic_init(*cpu_irq);
128 for (i = 0; i < 32; i++) {
129 irq[i] = qdev_get_gpio_in(env->pic_state, i);
130 }
131
132 /* load bios rom */
133 if (bios_name == NULL) {
134 bios_name = BIOS_FILENAME;
135 }
136 bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
137
138 if (bios_filename) {
139 load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE);
140 }
141
142 reset_info->bootstrap_pc = BIOS_OFFSET;
143
144 /* if no kernel is given no valid bios rom is a fatal error */
145 if (!kernel_filename && !dinfo && !bios_filename) {
146 fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n",
147 bios_name);
148 exit(1);
149 }
150
fcfa3397 151 milkymist_uart_create(0x60000000, irq[0]);
779277ca 152 milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
5052d227
MW
153 80000000, 0x10014d31, 0x0000041f, 0x00000001);
154 milkymist_hpdmc_create(0x60002000);
155 milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff);
156 milkymist_memcard_create(0x60004000);
779277ca
MW
157 milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]);
158 milkymist_pfpu_create(0x60006000, irq[8]);
159 milkymist_tmu2_create(0x60007000, irq[9]);
160 milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]);
161 milkymist_softusb_create(0x6000f000, irq[15],
5052d227
MW
162 0x20000000, 0x1000, 0x20020000, 0x2000);
163
164 /* make sure juart isn't the first chardev */
165 env->juart_state = lm32_juart_init();
166
167 if (kernel_filename) {
168 uint64_t entry;
169
170 /* Boots a kernel elf binary. */
171 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
172 1, ELF_MACHINE, 0);
173 reset_info->bootstrap_pc = entry;
174
175 if (kernel_size < 0) {
176 kernel_size = load_image_targphys(kernel_filename, sdram_base,
177 sdram_size);
178 reset_info->bootstrap_pc = sdram_base;
179 }
180
181 if (kernel_size < 0) {
182 fprintf(stderr, "qemu: could not load kernel '%s'\n",
183 kernel_filename);
184 exit(1);
185 }
186 }
187
188 if (kernel_cmdline && strlen(kernel_cmdline)) {
189 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
190 kernel_cmdline);
191 reset_info->cmdline_base = (uint32_t)cmdline_base;
192 }
193
194 if (initrd_filename) {
195 size_t initrd_size;
196 initrd_size = load_image_targphys(initrd_filename, initrd_base,
197 initrd_max);
198 reset_info->initrd_base = (uint32_t)initrd_base;
199 reset_info->initrd_size = (uint32_t)initrd_size;
200 }
201
202 qemu_register_reset(main_cpu_reset, reset_info);
203}
204
205static QEMUMachine milkymist_machine = {
206 .name = "milkymist",
207 .desc = "Milkymist One",
208 .init = milkymist_init,
209 .is_default = 0
210};
211
212static void milkymist_machine_init(void)
213{
214 qemu_register_machine(&milkymist_machine);
215}
216
217machine_init(milkymist_machine_init);