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