]>
Commit | Line | Data |
---|---|---|
1a6c0886 JM |
1 | /* |
2 | * QEMU PowerPC 405 evaluation boards emulation | |
5fafdf24 | 3 | * |
1a6c0886 | 4 | * Copyright (c) 2007 Jocelyn Mayer |
5fafdf24 | 5 | * |
1a6c0886 JM |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
22 | * THE SOFTWARE. | |
23 | */ | |
87ecb68b PB |
24 | #include "hw.h" |
25 | #include "ppc.h" | |
1a6c0886 | 26 | #include "ppc405.h" |
87ecb68b PB |
27 | #include "nvram.h" |
28 | #include "flash.h" | |
29 | #include "sysemu.h" | |
30 | #include "block.h" | |
31 | #include "boards.h" | |
3b3fb322 | 32 | #include "qemu-log.h" |
ca20cf32 | 33 | #include "loader.h" |
1a6c0886 JM |
34 | |
35 | #define BIOS_FILENAME "ppc405_rom.bin" | |
1a6c0886 JM |
36 | #define BIOS_SIZE (2048 * 1024) |
37 | ||
38 | #define KERNEL_LOAD_ADDR 0x00000000 | |
39 | #define INITRD_LOAD_ADDR 0x01800000 | |
40 | ||
41 | #define USE_FLASH_BIOS | |
42 | ||
43 | #define DEBUG_BOARD_INIT | |
44 | ||
45 | /*****************************************************************************/ | |
46 | /* PPC405EP reference board (IBM) */ | |
47 | /* Standalone board with: | |
48 | * - PowerPC 405EP CPU | |
49 | * - SDRAM (0x00000000) | |
50 | * - Flash (0xFFF80000) | |
51 | * - SRAM (0xFFF00000) | |
52 | * - NVRAM (0xF0000000) | |
53 | * - FPGA (0xF0300000) | |
54 | */ | |
c227f099 AL |
55 | typedef struct ref405ep_fpga_t ref405ep_fpga_t; |
56 | struct ref405ep_fpga_t { | |
1a6c0886 JM |
57 | uint8_t reg0; |
58 | uint8_t reg1; | |
59 | }; | |
60 | ||
c227f099 | 61 | static uint32_t ref405ep_fpga_readb (void *opaque, target_phys_addr_t addr) |
1a6c0886 | 62 | { |
c227f099 | 63 | ref405ep_fpga_t *fpga; |
1a6c0886 JM |
64 | uint32_t ret; |
65 | ||
66 | fpga = opaque; | |
1a6c0886 JM |
67 | switch (addr) { |
68 | case 0x0: | |
69 | ret = fpga->reg0; | |
70 | break; | |
71 | case 0x1: | |
72 | ret = fpga->reg1; | |
73 | break; | |
74 | default: | |
75 | ret = 0; | |
76 | break; | |
77 | } | |
78 | ||
79 | return ret; | |
80 | } | |
81 | ||
82 | static void ref405ep_fpga_writeb (void *opaque, | |
c227f099 | 83 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 | 84 | { |
c227f099 | 85 | ref405ep_fpga_t *fpga; |
1a6c0886 JM |
86 | |
87 | fpga = opaque; | |
1a6c0886 JM |
88 | switch (addr) { |
89 | case 0x0: | |
90 | /* Read only */ | |
91 | break; | |
92 | case 0x1: | |
93 | fpga->reg1 = value; | |
94 | break; | |
95 | default: | |
96 | break; | |
97 | } | |
98 | } | |
99 | ||
c227f099 | 100 | static uint32_t ref405ep_fpga_readw (void *opaque, target_phys_addr_t addr) |
1a6c0886 JM |
101 | { |
102 | uint32_t ret; | |
103 | ||
104 | ret = ref405ep_fpga_readb(opaque, addr) << 8; | |
105 | ret |= ref405ep_fpga_readb(opaque, addr + 1); | |
106 | ||
107 | return ret; | |
108 | } | |
109 | ||
110 | static void ref405ep_fpga_writew (void *opaque, | |
c227f099 | 111 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 JM |
112 | { |
113 | ref405ep_fpga_writeb(opaque, addr, (value >> 8) & 0xFF); | |
114 | ref405ep_fpga_writeb(opaque, addr + 1, value & 0xFF); | |
115 | } | |
116 | ||
c227f099 | 117 | static uint32_t ref405ep_fpga_readl (void *opaque, target_phys_addr_t addr) |
1a6c0886 JM |
118 | { |
119 | uint32_t ret; | |
120 | ||
121 | ret = ref405ep_fpga_readb(opaque, addr) << 24; | |
122 | ret |= ref405ep_fpga_readb(opaque, addr + 1) << 16; | |
123 | ret |= ref405ep_fpga_readb(opaque, addr + 2) << 8; | |
124 | ret |= ref405ep_fpga_readb(opaque, addr + 3); | |
125 | ||
126 | return ret; | |
127 | } | |
128 | ||
129 | static void ref405ep_fpga_writel (void *opaque, | |
c227f099 | 130 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 | 131 | { |
8de24106 AJ |
132 | ref405ep_fpga_writeb(opaque, addr, (value >> 24) & 0xFF); |
133 | ref405ep_fpga_writeb(opaque, addr + 1, (value >> 16) & 0xFF); | |
134 | ref405ep_fpga_writeb(opaque, addr + 2, (value >> 8) & 0xFF); | |
1a6c0886 JM |
135 | ref405ep_fpga_writeb(opaque, addr + 3, value & 0xFF); |
136 | } | |
137 | ||
d60efc6b | 138 | static CPUReadMemoryFunc * const ref405ep_fpga_read[] = { |
1a6c0886 JM |
139 | &ref405ep_fpga_readb, |
140 | &ref405ep_fpga_readw, | |
141 | &ref405ep_fpga_readl, | |
142 | }; | |
143 | ||
d60efc6b | 144 | static CPUWriteMemoryFunc * const ref405ep_fpga_write[] = { |
1a6c0886 JM |
145 | &ref405ep_fpga_writeb, |
146 | &ref405ep_fpga_writew, | |
147 | &ref405ep_fpga_writel, | |
148 | }; | |
149 | ||
150 | static void ref405ep_fpga_reset (void *opaque) | |
151 | { | |
c227f099 | 152 | ref405ep_fpga_t *fpga; |
1a6c0886 JM |
153 | |
154 | fpga = opaque; | |
155 | fpga->reg0 = 0x00; | |
156 | fpga->reg1 = 0x0F; | |
157 | } | |
158 | ||
159 | static void ref405ep_fpga_init (uint32_t base) | |
160 | { | |
c227f099 | 161 | ref405ep_fpga_t *fpga; |
1a6c0886 JM |
162 | int fpga_memory; |
163 | ||
c227f099 | 164 | fpga = qemu_mallocz(sizeof(ref405ep_fpga_t)); |
1eed09cb | 165 | fpga_memory = cpu_register_io_memory(ref405ep_fpga_read, |
487414f1 AL |
166 | ref405ep_fpga_write, fpga); |
167 | cpu_register_physical_memory(base, 0x00000100, fpga_memory); | |
a08d4367 | 168 | qemu_register_reset(&ref405ep_fpga_reset, fpga); |
1a6c0886 JM |
169 | } |
170 | ||
c227f099 | 171 | static void ref405ep_init (ram_addr_t ram_size, |
3023f332 | 172 | const char *boot_device, |
5fafdf24 | 173 | const char *kernel_filename, |
1a6c0886 JM |
174 | const char *kernel_cmdline, |
175 | const char *initrd_filename, | |
176 | const char *cpu_model) | |
177 | { | |
5cea8590 | 178 | char *filename; |
c227f099 | 179 | ppc4xx_bd_info_t bd; |
1a6c0886 JM |
180 | CPUPPCState *env; |
181 | qemu_irq *pic; | |
c227f099 AL |
182 | ram_addr_t sram_offset, bios_offset, bdloc; |
183 | target_phys_addr_t ram_bases[2], ram_sizes[2]; | |
1a6c0886 JM |
184 | target_ulong sram_size, bios_size; |
185 | //int phy_addr = 0; | |
186 | //static int phy_addr = 1; | |
187 | target_ulong kernel_base, kernel_size, initrd_base, initrd_size; | |
188 | int linux_boot; | |
189 | int fl_idx, fl_sectors, len; | |
6ac0e82d | 190 | int ppc_boot_device = boot_device[0]; |
751c6a17 | 191 | DriveInfo *dinfo; |
1a6c0886 JM |
192 | |
193 | /* XXX: fix this */ | |
5c130f65 | 194 | ram_bases[0] = qemu_ram_alloc(0x08000000); |
1a6c0886 JM |
195 | ram_sizes[0] = 0x08000000; |
196 | ram_bases[1] = 0x00000000; | |
197 | ram_sizes[1] = 0x00000000; | |
198 | ram_size = 128 * 1024 * 1024; | |
199 | #ifdef DEBUG_BOARD_INIT | |
200 | printf("%s: register cpu\n", __func__); | |
201 | #endif | |
5c130f65 | 202 | env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, |
1a6c0886 JM |
203 | kernel_filename == NULL ? 0 : 1); |
204 | /* allocate SRAM */ | |
5c130f65 PB |
205 | sram_size = 512 * 1024; |
206 | sram_offset = qemu_ram_alloc(sram_size); | |
1a6c0886 JM |
207 | #ifdef DEBUG_BOARD_INIT |
208 | printf("%s: register SRAM at offset %08lx\n", __func__, sram_offset); | |
209 | #endif | |
1a6c0886 JM |
210 | cpu_register_physical_memory(0xFFF00000, sram_size, |
211 | sram_offset | IO_MEM_RAM); | |
212 | /* allocate and load BIOS */ | |
213 | #ifdef DEBUG_BOARD_INIT | |
214 | printf("%s: register BIOS\n", __func__); | |
215 | #endif | |
1a6c0886 JM |
216 | fl_idx = 0; |
217 | #ifdef USE_FLASH_BIOS | |
751c6a17 GH |
218 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
219 | if (dinfo) { | |
220 | bios_size = bdrv_getlength(dinfo->bdrv); | |
5c130f65 | 221 | bios_offset = qemu_ram_alloc(bios_size); |
1a6c0886 JM |
222 | fl_sectors = (bios_size + 65535) >> 16; |
223 | #ifdef DEBUG_BOARD_INIT | |
90e189ec BS |
224 | printf("Register parallel flash %d size " TARGET_FMT_lx |
225 | " at offset %08lx addr " TARGET_FMT_lx " '%s' %d\n", | |
1a6c0886 | 226 | fl_idx, bios_size, bios_offset, -bios_size, |
751c6a17 | 227 | bdrv_get_device_name(dinfo->bdrv), fl_sectors); |
1a6c0886 | 228 | #endif |
88eeee0a | 229 | pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, |
751c6a17 | 230 | dinfo->bdrv, 65536, fl_sectors, 1, |
4fbd24ba | 231 | 2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
1a6c0886 JM |
232 | fl_idx++; |
233 | } else | |
234 | #endif | |
235 | { | |
236 | #ifdef DEBUG_BOARD_INIT | |
237 | printf("Load BIOS from file\n"); | |
238 | #endif | |
5cea8590 | 239 | bios_offset = qemu_ram_alloc(BIOS_SIZE); |
1192dad8 JM |
240 | if (bios_name == NULL) |
241 | bios_name = BIOS_FILENAME; | |
5cea8590 PB |
242 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); |
243 | if (filename) { | |
244 | bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset)); | |
245 | qemu_free(filename); | |
246 | } else { | |
247 | bios_size = -1; | |
248 | } | |
1a6c0886 | 249 | if (bios_size < 0 || bios_size > BIOS_SIZE) { |
5cea8590 PB |
250 | fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", |
251 | bios_name); | |
1a6c0886 JM |
252 | exit(1); |
253 | } | |
254 | bios_size = (bios_size + 0xfff) & ~0xfff; | |
5fafdf24 | 255 | cpu_register_physical_memory((uint32_t)(-bios_size), |
1a6c0886 JM |
256 | bios_size, bios_offset | IO_MEM_ROM); |
257 | } | |
1a6c0886 JM |
258 | /* Register FPGA */ |
259 | #ifdef DEBUG_BOARD_INIT | |
260 | printf("%s: register FPGA\n", __func__); | |
261 | #endif | |
262 | ref405ep_fpga_init(0xF0300000); | |
263 | /* Register NVRAM */ | |
264 | #ifdef DEBUG_BOARD_INIT | |
265 | printf("%s: register NVRAM\n", __func__); | |
266 | #endif | |
267 | m48t59_init(NULL, 0xF0000000, 0, 8192, 8); | |
268 | /* Load kernel */ | |
269 | linux_boot = (kernel_filename != NULL); | |
270 | if (linux_boot) { | |
271 | #ifdef DEBUG_BOARD_INIT | |
272 | printf("%s: load kernel\n", __func__); | |
273 | #endif | |
274 | memset(&bd, 0, sizeof(bd)); | |
275 | bd.bi_memstart = 0x00000000; | |
276 | bd.bi_memsize = ram_size; | |
217fae2d | 277 | bd.bi_flashstart = -bios_size; |
1a6c0886 JM |
278 | bd.bi_flashsize = -bios_size; |
279 | bd.bi_flashoffset = 0; | |
280 | bd.bi_sramstart = 0xFFF00000; | |
281 | bd.bi_sramsize = sram_size; | |
282 | bd.bi_bootflags = 0; | |
283 | bd.bi_intfreq = 133333333; | |
284 | bd.bi_busfreq = 33333333; | |
285 | bd.bi_baudrate = 115200; | |
286 | bd.bi_s_version[0] = 'Q'; | |
287 | bd.bi_s_version[1] = 'M'; | |
288 | bd.bi_s_version[2] = 'U'; | |
289 | bd.bi_s_version[3] = '\0'; | |
290 | bd.bi_r_version[0] = 'Q'; | |
291 | bd.bi_r_version[1] = 'E'; | |
292 | bd.bi_r_version[2] = 'M'; | |
293 | bd.bi_r_version[3] = 'U'; | |
294 | bd.bi_r_version[4] = '\0'; | |
295 | bd.bi_procfreq = 133333333; | |
296 | bd.bi_plb_busfreq = 33333333; | |
297 | bd.bi_pci_busfreq = 33333333; | |
298 | bd.bi_opbfreq = 33333333; | |
b8d3f5d1 | 299 | bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001); |
1a6c0886 JM |
300 | env->gpr[3] = bdloc; |
301 | kernel_base = KERNEL_LOAD_ADDR; | |
302 | /* now we can load the kernel */ | |
5c130f65 PB |
303 | kernel_size = load_image_targphys(kernel_filename, kernel_base, |
304 | ram_size - kernel_base); | |
1a6c0886 | 305 | if (kernel_size < 0) { |
5fafdf24 | 306 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
1a6c0886 JM |
307 | kernel_filename); |
308 | exit(1); | |
309 | } | |
5c130f65 PB |
310 | printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx, |
311 | kernel_size, kernel_base); | |
1a6c0886 JM |
312 | /* load initrd */ |
313 | if (initrd_filename) { | |
314 | initrd_base = INITRD_LOAD_ADDR; | |
5c130f65 PB |
315 | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
316 | ram_size - initrd_base); | |
1a6c0886 | 317 | if (initrd_size < 0) { |
5fafdf24 | 318 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
1a6c0886 JM |
319 | initrd_filename); |
320 | exit(1); | |
321 | } | |
322 | } else { | |
323 | initrd_base = 0; | |
324 | initrd_size = 0; | |
325 | } | |
326 | env->gpr[4] = initrd_base; | |
327 | env->gpr[5] = initrd_size; | |
6ac0e82d | 328 | ppc_boot_device = 'm'; |
1a6c0886 JM |
329 | if (kernel_cmdline != NULL) { |
330 | len = strlen(kernel_cmdline); | |
331 | bdloc -= ((len + 255) & ~255); | |
5c130f65 | 332 | cpu_physical_memory_write(bdloc, (void *)kernel_cmdline, len + 1); |
1a6c0886 JM |
333 | env->gpr[6] = bdloc; |
334 | env->gpr[7] = bdloc + len; | |
335 | } else { | |
336 | env->gpr[6] = 0; | |
337 | env->gpr[7] = 0; | |
338 | } | |
339 | env->nip = KERNEL_LOAD_ADDR; | |
340 | } else { | |
341 | kernel_base = 0; | |
342 | kernel_size = 0; | |
343 | initrd_base = 0; | |
344 | initrd_size = 0; | |
345 | bdloc = 0; | |
346 | } | |
347 | #ifdef DEBUG_BOARD_INIT | |
348 | printf("%s: Done\n", __func__); | |
349 | #endif | |
5c130f65 | 350 | printf("bdloc %016lx\n", (unsigned long)bdloc); |
1a6c0886 JM |
351 | } |
352 | ||
f80f9ec9 | 353 | static QEMUMachine ref405ep_machine = { |
4b32e168 AL |
354 | .name = "ref405ep", |
355 | .desc = "ref405ep", | |
356 | .init = ref405ep_init, | |
1a6c0886 JM |
357 | }; |
358 | ||
359 | /*****************************************************************************/ | |
360 | /* AMCC Taihu evaluation board */ | |
361 | /* - PowerPC 405EP processor | |
362 | * - SDRAM 128 MB at 0x00000000 | |
363 | * - Boot flash 2 MB at 0xFFE00000 | |
364 | * - Application flash 32 MB at 0xFC000000 | |
365 | * - 2 serial ports | |
366 | * - 2 ethernet PHY | |
367 | * - 1 USB 1.1 device 0x50000000 | |
368 | * - 1 LCD display 0x50100000 | |
369 | * - 1 CPLD 0x50100000 | |
370 | * - 1 I2C EEPROM | |
371 | * - 1 I2C thermal sensor | |
372 | * - a set of LEDs | |
373 | * - bit-bang SPI port using GPIOs | |
374 | * - 1 EBC interface connector 0 0x50200000 | |
375 | * - 1 cardbus controller + expansion slot. | |
376 | * - 1 PCI expansion slot. | |
377 | */ | |
378 | typedef struct taihu_cpld_t taihu_cpld_t; | |
379 | struct taihu_cpld_t { | |
1a6c0886 JM |
380 | uint8_t reg0; |
381 | uint8_t reg1; | |
382 | }; | |
383 | ||
c227f099 | 384 | static uint32_t taihu_cpld_readb (void *opaque, target_phys_addr_t addr) |
1a6c0886 JM |
385 | { |
386 | taihu_cpld_t *cpld; | |
387 | uint32_t ret; | |
388 | ||
389 | cpld = opaque; | |
1a6c0886 JM |
390 | switch (addr) { |
391 | case 0x0: | |
392 | ret = cpld->reg0; | |
393 | break; | |
394 | case 0x1: | |
395 | ret = cpld->reg1; | |
396 | break; | |
397 | default: | |
398 | ret = 0; | |
399 | break; | |
400 | } | |
401 | ||
402 | return ret; | |
403 | } | |
404 | ||
405 | static void taihu_cpld_writeb (void *opaque, | |
c227f099 | 406 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 JM |
407 | { |
408 | taihu_cpld_t *cpld; | |
409 | ||
410 | cpld = opaque; | |
1a6c0886 JM |
411 | switch (addr) { |
412 | case 0x0: | |
413 | /* Read only */ | |
414 | break; | |
415 | case 0x1: | |
416 | cpld->reg1 = value; | |
417 | break; | |
418 | default: | |
419 | break; | |
420 | } | |
421 | } | |
422 | ||
c227f099 | 423 | static uint32_t taihu_cpld_readw (void *opaque, target_phys_addr_t addr) |
1a6c0886 JM |
424 | { |
425 | uint32_t ret; | |
426 | ||
427 | ret = taihu_cpld_readb(opaque, addr) << 8; | |
428 | ret |= taihu_cpld_readb(opaque, addr + 1); | |
429 | ||
430 | return ret; | |
431 | } | |
432 | ||
433 | static void taihu_cpld_writew (void *opaque, | |
c227f099 | 434 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 JM |
435 | { |
436 | taihu_cpld_writeb(opaque, addr, (value >> 8) & 0xFF); | |
437 | taihu_cpld_writeb(opaque, addr + 1, value & 0xFF); | |
438 | } | |
439 | ||
c227f099 | 440 | static uint32_t taihu_cpld_readl (void *opaque, target_phys_addr_t addr) |
1a6c0886 JM |
441 | { |
442 | uint32_t ret; | |
443 | ||
444 | ret = taihu_cpld_readb(opaque, addr) << 24; | |
445 | ret |= taihu_cpld_readb(opaque, addr + 1) << 16; | |
446 | ret |= taihu_cpld_readb(opaque, addr + 2) << 8; | |
447 | ret |= taihu_cpld_readb(opaque, addr + 3); | |
448 | ||
449 | return ret; | |
450 | } | |
451 | ||
452 | static void taihu_cpld_writel (void *opaque, | |
c227f099 | 453 | target_phys_addr_t addr, uint32_t value) |
1a6c0886 JM |
454 | { |
455 | taihu_cpld_writel(opaque, addr, (value >> 24) & 0xFF); | |
456 | taihu_cpld_writel(opaque, addr + 1, (value >> 16) & 0xFF); | |
457 | taihu_cpld_writel(opaque, addr + 2, (value >> 8) & 0xFF); | |
458 | taihu_cpld_writeb(opaque, addr + 3, value & 0xFF); | |
459 | } | |
460 | ||
d60efc6b | 461 | static CPUReadMemoryFunc * const taihu_cpld_read[] = { |
1a6c0886 JM |
462 | &taihu_cpld_readb, |
463 | &taihu_cpld_readw, | |
464 | &taihu_cpld_readl, | |
465 | }; | |
466 | ||
d60efc6b | 467 | static CPUWriteMemoryFunc * const taihu_cpld_write[] = { |
1a6c0886 JM |
468 | &taihu_cpld_writeb, |
469 | &taihu_cpld_writew, | |
470 | &taihu_cpld_writel, | |
471 | }; | |
472 | ||
473 | static void taihu_cpld_reset (void *opaque) | |
474 | { | |
475 | taihu_cpld_t *cpld; | |
476 | ||
477 | cpld = opaque; | |
478 | cpld->reg0 = 0x01; | |
479 | cpld->reg1 = 0x80; | |
480 | } | |
481 | ||
482 | static void taihu_cpld_init (uint32_t base) | |
483 | { | |
484 | taihu_cpld_t *cpld; | |
485 | int cpld_memory; | |
486 | ||
487 | cpld = qemu_mallocz(sizeof(taihu_cpld_t)); | |
1eed09cb | 488 | cpld_memory = cpu_register_io_memory(taihu_cpld_read, |
487414f1 AL |
489 | taihu_cpld_write, cpld); |
490 | cpu_register_physical_memory(base, 0x00000100, cpld_memory); | |
a08d4367 | 491 | qemu_register_reset(&taihu_cpld_reset, cpld); |
1a6c0886 JM |
492 | } |
493 | ||
c227f099 | 494 | static void taihu_405ep_init(ram_addr_t ram_size, |
3023f332 | 495 | const char *boot_device, |
5fafdf24 | 496 | const char *kernel_filename, |
1a6c0886 JM |
497 | const char *kernel_cmdline, |
498 | const char *initrd_filename, | |
499 | const char *cpu_model) | |
500 | { | |
5cea8590 | 501 | char *filename; |
1a6c0886 JM |
502 | CPUPPCState *env; |
503 | qemu_irq *pic; | |
c227f099 AL |
504 | ram_addr_t bios_offset; |
505 | target_phys_addr_t ram_bases[2], ram_sizes[2]; | |
1a6c0886 JM |
506 | target_ulong bios_size; |
507 | target_ulong kernel_base, kernel_size, initrd_base, initrd_size; | |
508 | int linux_boot; | |
509 | int fl_idx, fl_sectors; | |
6ac0e82d | 510 | int ppc_boot_device = boot_device[0]; |
751c6a17 | 511 | DriveInfo *dinfo; |
3b46e624 | 512 | |
1a6c0886 | 513 | /* RAM is soldered to the board so the size cannot be changed */ |
5c130f65 | 514 | ram_bases[0] = qemu_ram_alloc(0x04000000); |
1a6c0886 | 515 | ram_sizes[0] = 0x04000000; |
5c130f65 | 516 | ram_bases[1] = qemu_ram_alloc(0x04000000); |
1a6c0886 | 517 | ram_sizes[1] = 0x04000000; |
a0b753df | 518 | ram_size = 0x08000000; |
1a6c0886 JM |
519 | #ifdef DEBUG_BOARD_INIT |
520 | printf("%s: register cpu\n", __func__); | |
521 | #endif | |
5c130f65 | 522 | env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic, |
1a6c0886 JM |
523 | kernel_filename == NULL ? 0 : 1); |
524 | /* allocate and load BIOS */ | |
525 | #ifdef DEBUG_BOARD_INIT | |
526 | printf("%s: register BIOS\n", __func__); | |
527 | #endif | |
528 | fl_idx = 0; | |
529 | #if defined(USE_FLASH_BIOS) | |
751c6a17 GH |
530 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
531 | if (dinfo) { | |
532 | bios_size = bdrv_getlength(dinfo->bdrv); | |
1a6c0886 JM |
533 | /* XXX: should check that size is 2MB */ |
534 | // bios_size = 2 * 1024 * 1024; | |
535 | fl_sectors = (bios_size + 65535) >> 16; | |
5c130f65 | 536 | bios_offset = qemu_ram_alloc(bios_size); |
1a6c0886 | 537 | #ifdef DEBUG_BOARD_INIT |
90e189ec BS |
538 | printf("Register parallel flash %d size " TARGET_FMT_lx |
539 | " at offset %08lx addr " TARGET_FMT_lx " '%s' %d\n", | |
1a6c0886 | 540 | fl_idx, bios_size, bios_offset, -bios_size, |
751c6a17 | 541 | bdrv_get_device_name(dinfo->bdrv), fl_sectors); |
1a6c0886 | 542 | #endif |
88eeee0a | 543 | pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, |
751c6a17 | 544 | dinfo->bdrv, 65536, fl_sectors, 1, |
4fbd24ba | 545 | 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
1a6c0886 JM |
546 | fl_idx++; |
547 | } else | |
548 | #endif | |
549 | { | |
550 | #ifdef DEBUG_BOARD_INIT | |
551 | printf("Load BIOS from file\n"); | |
552 | #endif | |
1192dad8 JM |
553 | if (bios_name == NULL) |
554 | bios_name = BIOS_FILENAME; | |
5c130f65 | 555 | bios_offset = qemu_ram_alloc(BIOS_SIZE); |
5cea8590 PB |
556 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); |
557 | if (filename) { | |
558 | bios_size = load_image(filename, qemu_get_ram_ptr(bios_offset)); | |
559 | } else { | |
560 | bios_size = -1; | |
561 | } | |
1a6c0886 | 562 | if (bios_size < 0 || bios_size > BIOS_SIZE) { |
5cea8590 PB |
563 | fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", |
564 | bios_name); | |
1a6c0886 JM |
565 | exit(1); |
566 | } | |
567 | bios_size = (bios_size + 0xfff) & ~0xfff; | |
5fafdf24 | 568 | cpu_register_physical_memory((uint32_t)(-bios_size), |
1a6c0886 JM |
569 | bios_size, bios_offset | IO_MEM_ROM); |
570 | } | |
1a6c0886 | 571 | /* Register Linux flash */ |
751c6a17 GH |
572 | dinfo = drive_get(IF_PFLASH, 0, fl_idx); |
573 | if (dinfo) { | |
574 | bios_size = bdrv_getlength(dinfo->bdrv); | |
1a6c0886 JM |
575 | /* XXX: should check that size is 32MB */ |
576 | bios_size = 32 * 1024 * 1024; | |
577 | fl_sectors = (bios_size + 65535) >> 16; | |
578 | #ifdef DEBUG_BOARD_INIT | |
90e189ec BS |
579 | printf("Register parallel flash %d size " TARGET_FMT_lx |
580 | " at offset %08lx addr " TARGET_FMT_lx " '%s'\n", | |
1a6c0886 | 581 | fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000, |
751c6a17 | 582 | bdrv_get_device_name(dinfo->bdrv)); |
1a6c0886 | 583 | #endif |
5c130f65 | 584 | bios_offset = qemu_ram_alloc(bios_size); |
88eeee0a | 585 | pflash_cfi02_register(0xfc000000, bios_offset, |
751c6a17 | 586 | dinfo->bdrv, 65536, fl_sectors, 1, |
4fbd24ba | 587 | 4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
1a6c0886 JM |
588 | fl_idx++; |
589 | } | |
590 | /* Register CLPD & LCD display */ | |
591 | #ifdef DEBUG_BOARD_INIT | |
592 | printf("%s: register CPLD\n", __func__); | |
593 | #endif | |
594 | taihu_cpld_init(0x50100000); | |
595 | /* Load kernel */ | |
596 | linux_boot = (kernel_filename != NULL); | |
597 | if (linux_boot) { | |
598 | #ifdef DEBUG_BOARD_INIT | |
599 | printf("%s: load kernel\n", __func__); | |
600 | #endif | |
601 | kernel_base = KERNEL_LOAD_ADDR; | |
602 | /* now we can load the kernel */ | |
5c130f65 PB |
603 | kernel_size = load_image_targphys(kernel_filename, kernel_base, |
604 | ram_size - kernel_base); | |
1a6c0886 | 605 | if (kernel_size < 0) { |
5fafdf24 | 606 | fprintf(stderr, "qemu: could not load kernel '%s'\n", |
1a6c0886 JM |
607 | kernel_filename); |
608 | exit(1); | |
609 | } | |
610 | /* load initrd */ | |
611 | if (initrd_filename) { | |
612 | initrd_base = INITRD_LOAD_ADDR; | |
5c130f65 PB |
613 | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
614 | ram_size - initrd_base); | |
1a6c0886 JM |
615 | if (initrd_size < 0) { |
616 | fprintf(stderr, | |
5fafdf24 | 617 | "qemu: could not load initial ram disk '%s'\n", |
1a6c0886 JM |
618 | initrd_filename); |
619 | exit(1); | |
620 | } | |
621 | } else { | |
622 | initrd_base = 0; | |
623 | initrd_size = 0; | |
624 | } | |
6ac0e82d | 625 | ppc_boot_device = 'm'; |
1a6c0886 JM |
626 | } else { |
627 | kernel_base = 0; | |
628 | kernel_size = 0; | |
629 | initrd_base = 0; | |
630 | initrd_size = 0; | |
631 | } | |
632 | #ifdef DEBUG_BOARD_INIT | |
633 | printf("%s: Done\n", __func__); | |
634 | #endif | |
635 | } | |
636 | ||
f80f9ec9 | 637 | static QEMUMachine taihu_machine = { |
b2ee0ce2 PB |
638 | .name = "taihu", |
639 | .desc = "taihu", | |
640 | .init = taihu_405ep_init, | |
1a6c0886 | 641 | }; |
f80f9ec9 AL |
642 | |
643 | static void ppc405_machine_init(void) | |
644 | { | |
645 | qemu_register_machine(&ref405ep_machine); | |
646 | qemu_register_machine(&taihu_machine); | |
647 | } | |
648 | ||
649 | machine_init(ppc405_machine_init); |