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