]> git.proxmox.com Git - mirror_qemu.git/blame - hw/milkymist.c
milkymist-softusb: convert to memory API
[mirror_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"
22#include "net.h"
23#include "flash.h"
24#include "sysemu.h"
25#include "devices.h"
26#include "boards.h"
27#include "loader.h"
28#include "elf.h"
29#include "blockdev.h"
30#include "milkymist-hw.h"
31#include "lm32.h"
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 {
39 CPUState *env;
40 target_phys_addr_t bootstrap_pc;
41 target_phys_addr_t flash_base;
42 target_phys_addr_t initrd_base;
43 size_t initrd_size;
44 target_phys_addr_t cmdline_base;
45} ResetInfo;
46
47static void cpu_irq_handler(void *opaque, int irq, int level)
48{
49 CPUState *env = opaque;
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;
61 CPUState *env = reset_info->env;
62
63 cpu_reset(env);
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
75milkymist_init(ram_addr_t ram_size_not_used,
76 const char *boot_device,
77 const char *kernel_filename,
78 const char *kernel_cmdline,
79 const char *initrd_filename, const char *cpu_model)
80{
81 CPUState *env;
82 int kernel_size;
83 DriveInfo *dinfo;
01e0451a 84 ram_addr_t phys_sdram;
5052d227
MW
85 qemu_irq irq[32], *cpu_irq;
86 int i;
87 char *bios_filename;
88 ResetInfo *reset_info;
89
90 /* memory map */
91 target_phys_addr_t flash_base = 0x00000000;
92 size_t flash_sector_size = 128 * 1024;
93 size_t flash_size = 32 * 1024 * 1024;
94 target_phys_addr_t sdram_base = 0x40000000;
95 size_t sdram_size = 128 * 1024 * 1024;
96
97 target_phys_addr_t initrd_base = sdram_base + 0x1002000;
98 target_phys_addr_t cmdline_base = sdram_base + 0x1000000;
99 size_t initrd_max = sdram_size - 0x1002000;
100
7267c094 101 reset_info = g_malloc0(sizeof(ResetInfo));
5052d227
MW
102
103 if (cpu_model == NULL) {
104 cpu_model = "lm32-full";
105 }
106 env = cpu_init(cpu_model);
107 reset_info->env = env;
108
109 cpu_lm32_set_phys_msb_ignore(env, 1);
110
01e0451a
AL
111 phys_sdram = qemu_ram_alloc(NULL, "milkymist.sdram", sdram_size);
112 cpu_register_physical_memory(sdram_base, sdram_size,
113 phys_sdram | IO_MEM_RAM);
5052d227 114
5052d227
MW
115 dinfo = drive_get(IF_PFLASH, 0, 0);
116 /* Numonyx JS28F256J3F105 */
cfe5f011 117 pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
5052d227
MW
118 dinfo ? dinfo->bdrv : NULL, flash_sector_size,
119 flash_size / flash_sector_size, 2,
01e0451a 120 0x00, 0x89, 0x00, 0x1d, 1);
5052d227
MW
121
122 /* create irq lines */
123 cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
124 env->pic_state = lm32_pic_init(*cpu_irq);
125 for (i = 0; i < 32; i++) {
126 irq[i] = qdev_get_gpio_in(env->pic_state, i);
127 }
128
129 /* load bios rom */
130 if (bios_name == NULL) {
131 bios_name = BIOS_FILENAME;
132 }
133 bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
134
135 if (bios_filename) {
136 load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE);
137 }
138
139 reset_info->bootstrap_pc = BIOS_OFFSET;
140
141 /* if no kernel is given no valid bios rom is a fatal error */
142 if (!kernel_filename && !dinfo && !bios_filename) {
143 fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n",
144 bios_name);
145 exit(1);
146 }
147
148 milkymist_uart_create(0x60000000, irq[0], irq[1]);
149 milkymist_sysctl_create(0x60001000, irq[2], irq[3], irq[4],
150 80000000, 0x10014d31, 0x0000041f, 0x00000001);
151 milkymist_hpdmc_create(0x60002000);
152 milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff);
153 milkymist_memcard_create(0x60004000);
154 milkymist_ac97_create(0x60005000, irq[5], irq[6], irq[7], irq[8]);
155 milkymist_pfpu_create(0x60006000, irq[9]);
156 milkymist_tmu2_create(0x60007000, irq[10]);
57aa265d 157 milkymist_minimac2_create(0x60008000, 0x30000000, irq[11], irq[12]);
5052d227
MW
158 milkymist_softusb_create(0x6000f000, irq[17],
159 0x20000000, 0x1000, 0x20020000, 0x2000);
160
161 /* make sure juart isn't the first chardev */
162 env->juart_state = lm32_juart_init();
163
164 if (kernel_filename) {
165 uint64_t entry;
166
167 /* Boots a kernel elf binary. */
168 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
169 1, ELF_MACHINE, 0);
170 reset_info->bootstrap_pc = entry;
171
172 if (kernel_size < 0) {
173 kernel_size = load_image_targphys(kernel_filename, sdram_base,
174 sdram_size);
175 reset_info->bootstrap_pc = sdram_base;
176 }
177
178 if (kernel_size < 0) {
179 fprintf(stderr, "qemu: could not load kernel '%s'\n",
180 kernel_filename);
181 exit(1);
182 }
183 }
184
185 if (kernel_cmdline && strlen(kernel_cmdline)) {
186 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
187 kernel_cmdline);
188 reset_info->cmdline_base = (uint32_t)cmdline_base;
189 }
190
191 if (initrd_filename) {
192 size_t initrd_size;
193 initrd_size = load_image_targphys(initrd_filename, initrd_base,
194 initrd_max);
195 reset_info->initrd_base = (uint32_t)initrd_base;
196 reset_info->initrd_size = (uint32_t)initrd_size;
197 }
198
199 qemu_register_reset(main_cpu_reset, reset_info);
200}
201
202static QEMUMachine milkymist_machine = {
203 .name = "milkymist",
204 .desc = "Milkymist One",
205 .init = milkymist_init,
206 .is_default = 0
207};
208
209static void milkymist_machine_init(void)
210{
211 qemu_register_machine(&milkymist_machine);
212}
213
214machine_init(milkymist_machine_init);