]> git.proxmox.com Git - mirror_qemu.git/blame - hw/lm32/milkymist.c
virtio-blk: Rename VirtIOBlkConf variables to conf
[mirror_qemu.git] / hw / lm32 / 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
83c9f4ca
PB
20#include "hw/sysbus.h"
21#include "hw/hw.h"
0d09e41a 22#include "hw/block/flash.h"
9c17d615 23#include "sysemu/sysemu.h"
c00eb5ce 24#include "sysemu/qtest.h"
bd2be150 25#include "hw/devices.h"
83c9f4ca
PB
26#include "hw/boards.h"
27#include "hw/loader.h"
5052d227 28#include "elf.h"
fa1d36df 29#include "sysemu/block-backend.h"
9c17d615 30#include "sysemu/blockdev.h"
47b43a1f
PB
31#include "milkymist-hw.h"
32#include "lm32.h"
022c62cb 33#include "exec/address-spaces.h"
5052d227
MW
34
35#define BIOS_FILENAME "mmone-bios.bin"
36#define BIOS_OFFSET 0x00860000
37#define BIOS_SIZE (512*1024)
38#define KERNEL_LOAD_ADDR 0x40000000
39
40typedef struct {
f6932a86 41 LM32CPU *cpu;
a8170e5e
AK
42 hwaddr bootstrap_pc;
43 hwaddr flash_base;
44 hwaddr initrd_base;
5052d227 45 size_t initrd_size;
a8170e5e 46 hwaddr cmdline_base;
5052d227
MW
47} ResetInfo;
48
49static void cpu_irq_handler(void *opaque, int irq, int level)
50{
d8ed887b 51 LM32CPU *cpu = opaque;
d8ed887b 52 CPUState *cs = CPU(cpu);
5052d227
MW
53
54 if (level) {
c3affe56 55 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
5052d227 56 } else {
d8ed887b 57 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
5052d227
MW
58 }
59}
60
61static void main_cpu_reset(void *opaque)
62{
63 ResetInfo *reset_info = opaque;
f6932a86 64 CPULM32State *env = &reset_info->cpu->env;
5052d227 65
f6932a86 66 cpu_reset(CPU(reset_info->cpu));
5052d227
MW
67
68 /* init defaults */
69 env->pc = reset_info->bootstrap_pc;
70 env->regs[R_R1] = reset_info->cmdline_base;
71 env->regs[R_R2] = reset_info->initrd_base;
72 env->regs[R_R3] = reset_info->initrd_base + reset_info->initrd_size;
73 env->eba = reset_info->flash_base;
74 env->deba = reset_info->flash_base;
75}
76
77static void
3ef96221 78milkymist_init(MachineState *machine)
5052d227 79{
3ef96221
MA
80 const char *cpu_model = machine->cpu_model;
81 const char *kernel_filename = machine->kernel_filename;
82 const char *kernel_cmdline = machine->kernel_cmdline;
83 const char *initrd_filename = machine->initrd_filename;
1328cc01 84 LM32CPU *cpu;
93a67402 85 CPULM32State *env;
5052d227
MW
86 int kernel_size;
87 DriveInfo *dinfo;
c50a6def
AK
88 MemoryRegion *address_space_mem = get_system_memory();
89 MemoryRegion *phys_sdram = g_new(MemoryRegion, 1);
5052d227
MW
90 qemu_irq irq[32], *cpu_irq;
91 int i;
92 char *bios_filename;
93 ResetInfo *reset_info;
94
95 /* memory map */
a8170e5e 96 hwaddr flash_base = 0x00000000;
5052d227
MW
97 size_t flash_sector_size = 128 * 1024;
98 size_t flash_size = 32 * 1024 * 1024;
a8170e5e 99 hwaddr sdram_base = 0x40000000;
5052d227
MW
100 size_t sdram_size = 128 * 1024 * 1024;
101
a8170e5e
AK
102 hwaddr initrd_base = sdram_base + 0x1002000;
103 hwaddr cmdline_base = sdram_base + 0x1000000;
5052d227
MW
104 size_t initrd_max = sdram_size - 0x1002000;
105
7267c094 106 reset_info = g_malloc0(sizeof(ResetInfo));
5052d227
MW
107
108 if (cpu_model == NULL) {
109 cpu_model = "lm32-full";
110 }
1328cc01 111 cpu = cpu_lm32_init(cpu_model);
f41152bd
MW
112 if (cpu == NULL) {
113 fprintf(stderr, "qemu: unable to find CPU '%s'\n", cpu_model);
114 exit(1);
115 }
116
1328cc01 117 env = &cpu->env;
f6932a86 118 reset_info->cpu = cpu;
5052d227
MW
119
120 cpu_lm32_set_phys_msb_ignore(env, 1);
121
49946538
HT
122 memory_region_init_ram(phys_sdram, NULL, "milkymist.sdram", sdram_size,
123 &error_abort);
c5705a77 124 vmstate_register_ram_global(phys_sdram);
c50a6def 125 memory_region_add_subregion(address_space_mem, sdram_base, phys_sdram);
5052d227 126
5052d227
MW
127 dinfo = drive_get(IF_PFLASH, 0, 0);
128 /* Numonyx JS28F256J3F105 */
cfe5f011 129 pflash_cfi01_register(flash_base, NULL, "milkymist.flash", flash_size,
fa1d36df
MA
130 dinfo ? blk_bs(blk_by_legacy_dinfo(dinfo)) : NULL,
131 flash_sector_size, flash_size / flash_sector_size,
132 2, 0x00, 0x89, 0x00, 0x1d, 1);
5052d227
MW
133
134 /* create irq lines */
d8ed887b 135 cpu_irq = qemu_allocate_irqs(cpu_irq_handler, cpu, 1);
5052d227
MW
136 env->pic_state = lm32_pic_init(*cpu_irq);
137 for (i = 0; i < 32; i++) {
138 irq[i] = qdev_get_gpio_in(env->pic_state, i);
139 }
140
141 /* load bios rom */
142 if (bios_name == NULL) {
143 bios_name = BIOS_FILENAME;
144 }
145 bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
146
147 if (bios_filename) {
148 load_image_targphys(bios_filename, BIOS_OFFSET, BIOS_SIZE);
149 }
150
151 reset_info->bootstrap_pc = BIOS_OFFSET;
152
153 /* if no kernel is given no valid bios rom is a fatal error */
c00eb5ce 154 if (!kernel_filename && !dinfo && !bios_filename && !qtest_enabled()) {
5052d227
MW
155 fprintf(stderr, "qemu: could not load Milkymist One bios '%s'\n",
156 bios_name);
157 exit(1);
158 }
159
fcfa3397 160 milkymist_uart_create(0x60000000, irq[0]);
779277ca 161 milkymist_sysctl_create(0x60001000, irq[1], irq[2], irq[3],
5052d227
MW
162 80000000, 0x10014d31, 0x0000041f, 0x00000001);
163 milkymist_hpdmc_create(0x60002000);
164 milkymist_vgafb_create(0x60003000, 0x40000000, 0x0fffffff);
165 milkymist_memcard_create(0x60004000);
779277ca
MW
166 milkymist_ac97_create(0x60005000, irq[4], irq[5], irq[6], irq[7]);
167 milkymist_pfpu_create(0x60006000, irq[8]);
168 milkymist_tmu2_create(0x60007000, irq[9]);
169 milkymist_minimac2_create(0x60008000, 0x30000000, irq[10], irq[11]);
170 milkymist_softusb_create(0x6000f000, irq[15],
5052d227
MW
171 0x20000000, 0x1000, 0x20020000, 0x2000);
172
173 /* make sure juart isn't the first chardev */
174 env->juart_state = lm32_juart_init();
175
176 if (kernel_filename) {
177 uint64_t entry;
178
179 /* Boots a kernel elf binary. */
180 kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL,
181 1, ELF_MACHINE, 0);
182 reset_info->bootstrap_pc = entry;
183
184 if (kernel_size < 0) {
185 kernel_size = load_image_targphys(kernel_filename, sdram_base,
186 sdram_size);
187 reset_info->bootstrap_pc = sdram_base;
188 }
189
190 if (kernel_size < 0) {
191 fprintf(stderr, "qemu: could not load kernel '%s'\n",
192 kernel_filename);
193 exit(1);
194 }
195 }
196
197 if (kernel_cmdline && strlen(kernel_cmdline)) {
198 pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
199 kernel_cmdline);
200 reset_info->cmdline_base = (uint32_t)cmdline_base;
201 }
202
203 if (initrd_filename) {
204 size_t initrd_size;
205 initrd_size = load_image_targphys(initrd_filename, initrd_base,
206 initrd_max);
207 reset_info->initrd_base = (uint32_t)initrd_base;
208 reset_info->initrd_size = (uint32_t)initrd_size;
209 }
210
211 qemu_register_reset(main_cpu_reset, reset_info);
212}
213
214static QEMUMachine milkymist_machine = {
215 .name = "milkymist",
216 .desc = "Milkymist One",
217 .init = milkymist_init,
e4ada29e 218 .is_default = 0,
5052d227
MW
219};
220
221static void milkymist_machine_init(void)
222{
223 qemu_register_machine(&milkymist_machine);
224}
225
226machine_init(milkymist_machine_init);