]> Git Repo - qemu.git/blob - hw/ppc/ppc405_boards.c
ppc405_boards: Delete stale, disabled DEBUG_BOARD_INIT code
[qemu.git] / hw / ppc / ppc405_boards.c
1 /*
2  * QEMU PowerPC 405 evaluation boards emulation
3  *
4  * Copyright (c) 2007 Jocelyn Mayer
5  *
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  */
24 #include "qemu/osdep.h"
25 #include "qemu/units.h"
26 #include "qapi/error.h"
27 #include "qemu-common.h"
28 #include "cpu.h"
29 #include "hw/hw.h"
30 #include "hw/ppc/ppc.h"
31 #include "ppc405.h"
32 #include "hw/timer/m48t59.h"
33 #include "hw/block/flash.h"
34 #include "sysemu/sysemu.h"
35 #include "sysemu/qtest.h"
36 #include "sysemu/block-backend.h"
37 #include "hw/boards.h"
38 #include "qemu/log.h"
39 #include "qemu/error-report.h"
40 #include "hw/loader.h"
41 #include "exec/address-spaces.h"
42
43 #define BIOS_FILENAME "ppc405_rom.bin"
44 #define BIOS_SIZE (2 * MiB)
45
46 #define KERNEL_LOAD_ADDR 0x00000000
47 #define INITRD_LOAD_ADDR 0x01800000
48
49 #define USE_FLASH_BIOS
50
51 /*****************************************************************************/
52 /* PPC405EP reference board (IBM) */
53 /* Standalone board with:
54  * - PowerPC 405EP CPU
55  * - SDRAM (0x00000000)
56  * - Flash (0xFFF80000)
57  * - SRAM  (0xFFF00000)
58  * - NVRAM (0xF0000000)
59  * - FPGA  (0xF0300000)
60  */
61 typedef struct ref405ep_fpga_t ref405ep_fpga_t;
62 struct ref405ep_fpga_t {
63     uint8_t reg0;
64     uint8_t reg1;
65 };
66
67 static uint64_t ref405ep_fpga_readb(void *opaque, hwaddr addr, unsigned size)
68 {
69     ref405ep_fpga_t *fpga;
70     uint32_t ret;
71
72     fpga = opaque;
73     switch (addr) {
74     case 0x0:
75         ret = fpga->reg0;
76         break;
77     case 0x1:
78         ret = fpga->reg1;
79         break;
80     default:
81         ret = 0;
82         break;
83     }
84
85     return ret;
86 }
87
88 static void ref405ep_fpga_writeb(void *opaque, hwaddr addr, uint64_t value,
89                                  unsigned size)
90 {
91     ref405ep_fpga_t *fpga;
92
93     fpga = opaque;
94     switch (addr) {
95     case 0x0:
96         /* Read only */
97         break;
98     case 0x1:
99         fpga->reg1 = value;
100         break;
101     default:
102         break;
103     }
104 }
105
106 static const MemoryRegionOps ref405ep_fpga_ops = {
107     .read = ref405ep_fpga_readb,
108     .write = ref405ep_fpga_writeb,
109     .impl.min_access_size = 1,
110     .impl.max_access_size = 1,
111     .valid.min_access_size = 1,
112     .valid.max_access_size = 4,
113     .endianness = DEVICE_BIG_ENDIAN,
114 };
115
116 static void ref405ep_fpga_reset (void *opaque)
117 {
118     ref405ep_fpga_t *fpga;
119
120     fpga = opaque;
121     fpga->reg0 = 0x00;
122     fpga->reg1 = 0x0F;
123 }
124
125 static void ref405ep_fpga_init(MemoryRegion *sysmem, uint32_t base)
126 {
127     ref405ep_fpga_t *fpga;
128     MemoryRegion *fpga_memory = g_new(MemoryRegion, 1);
129
130     fpga = g_malloc0(sizeof(ref405ep_fpga_t));
131     memory_region_init_io(fpga_memory, NULL, &ref405ep_fpga_ops, fpga,
132                           "fpga", 0x00000100);
133     memory_region_add_subregion(sysmem, base, fpga_memory);
134     qemu_register_reset(&ref405ep_fpga_reset, fpga);
135 }
136
137 static void ref405ep_init(MachineState *machine)
138 {
139     ram_addr_t ram_size = machine->ram_size;
140     const char *kernel_filename = machine->kernel_filename;
141     const char *kernel_cmdline = machine->kernel_cmdline;
142     const char *initrd_filename = machine->initrd_filename;
143     char *filename;
144     ppc4xx_bd_info_t bd;
145     CPUPPCState *env;
146     qemu_irq *pic;
147     MemoryRegion *bios;
148     MemoryRegion *sram = g_new(MemoryRegion, 1);
149     ram_addr_t bdloc;
150     MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
151     hwaddr ram_bases[2], ram_sizes[2];
152     target_ulong sram_size;
153     long bios_size;
154     //int phy_addr = 0;
155     //static int phy_addr = 1;
156     target_ulong kernel_base, initrd_base;
157     long kernel_size, initrd_size;
158     int linux_boot;
159     int fl_idx, fl_sectors, len;
160     DriveInfo *dinfo;
161     MemoryRegion *sysmem = get_system_memory();
162
163     /* XXX: fix this */
164     memory_region_allocate_system_memory(&ram_memories[0], NULL, "ef405ep.ram",
165                                          0x08000000);
166     ram_bases[0] = 0;
167     ram_sizes[0] = 0x08000000;
168     memory_region_init(&ram_memories[1], NULL, "ef405ep.ram1", 0);
169     ram_bases[1] = 0x00000000;
170     ram_sizes[1] = 0x00000000;
171     ram_size = 128 * MiB;
172     env = ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
173                         33333333, &pic, kernel_filename == NULL ? 0 : 1);
174     /* allocate SRAM */
175     sram_size = 512 * KiB;
176     memory_region_init_ram(sram, NULL, "ef405ep.sram", sram_size,
177                            &error_fatal);
178     memory_region_add_subregion(sysmem, 0xFFF00000, sram);
179     /* allocate and load BIOS */
180     fl_idx = 0;
181 #ifdef USE_FLASH_BIOS
182     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
183     if (dinfo) {
184         BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
185
186         bios_size = blk_getlength(blk);
187         fl_sectors = (bios_size + 65535) >> 16;
188         pflash_cfi02_register((uint32_t)(-bios_size),
189                               NULL, "ef405ep.bios", bios_size,
190                               blk, 65536, fl_sectors, 1,
191                               2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
192                               1);
193         fl_idx++;
194     } else
195 #endif
196     {
197         bios = g_new(MemoryRegion, 1);
198         memory_region_init_ram(bios, NULL, "ef405ep.bios", BIOS_SIZE,
199                                &error_fatal);
200
201         if (bios_name == NULL)
202             bios_name = BIOS_FILENAME;
203         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
204         if (filename) {
205             bios_size = load_image_size(filename,
206                                         memory_region_get_ram_ptr(bios),
207                                         BIOS_SIZE);
208             g_free(filename);
209             if (bios_size < 0) {
210                 error_report("Could not load PowerPC BIOS '%s'", bios_name);
211                 exit(1);
212             }
213             bios_size = (bios_size + 0xfff) & ~0xfff;
214             memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
215         } else if (!qtest_enabled() || kernel_filename != NULL) {
216             error_report("Could not load PowerPC BIOS '%s'", bios_name);
217             exit(1);
218         } else {
219             /* Avoid an uninitialized variable warning */
220             bios_size = -1;
221         }
222         memory_region_set_readonly(bios, true);
223     }
224     /* Register FPGA */
225     ref405ep_fpga_init(sysmem, 0xF0300000);
226     /* Register NVRAM */
227     m48t59_init(NULL, 0xF0000000, 0, 8192, 1968, 8);
228     /* Load kernel */
229     linux_boot = (kernel_filename != NULL);
230     if (linux_boot) {
231         memset(&bd, 0, sizeof(bd));
232         bd.bi_memstart = 0x00000000;
233         bd.bi_memsize = ram_size;
234         bd.bi_flashstart = -bios_size;
235         bd.bi_flashsize = -bios_size;
236         bd.bi_flashoffset = 0;
237         bd.bi_sramstart = 0xFFF00000;
238         bd.bi_sramsize = sram_size;
239         bd.bi_bootflags = 0;
240         bd.bi_intfreq = 133333333;
241         bd.bi_busfreq = 33333333;
242         bd.bi_baudrate = 115200;
243         bd.bi_s_version[0] = 'Q';
244         bd.bi_s_version[1] = 'M';
245         bd.bi_s_version[2] = 'U';
246         bd.bi_s_version[3] = '\0';
247         bd.bi_r_version[0] = 'Q';
248         bd.bi_r_version[1] = 'E';
249         bd.bi_r_version[2] = 'M';
250         bd.bi_r_version[3] = 'U';
251         bd.bi_r_version[4] = '\0';
252         bd.bi_procfreq = 133333333;
253         bd.bi_plb_busfreq = 33333333;
254         bd.bi_pci_busfreq = 33333333;
255         bd.bi_opbfreq = 33333333;
256         bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001);
257         env->gpr[3] = bdloc;
258         kernel_base = KERNEL_LOAD_ADDR;
259         /* now we can load the kernel */
260         kernel_size = load_image_targphys(kernel_filename, kernel_base,
261                                           ram_size - kernel_base);
262         if (kernel_size < 0) {
263             error_report("could not load kernel '%s'", kernel_filename);
264             exit(1);
265         }
266         printf("Load kernel size %ld at " TARGET_FMT_lx,
267                kernel_size, kernel_base);
268         /* load initrd */
269         if (initrd_filename) {
270             initrd_base = INITRD_LOAD_ADDR;
271             initrd_size = load_image_targphys(initrd_filename, initrd_base,
272                                               ram_size - initrd_base);
273             if (initrd_size < 0) {
274                 error_report("could not load initial ram disk '%s'",
275                              initrd_filename);
276                 exit(1);
277             }
278         } else {
279             initrd_base = 0;
280             initrd_size = 0;
281         }
282         env->gpr[4] = initrd_base;
283         env->gpr[5] = initrd_size;
284         if (kernel_cmdline != NULL) {
285             len = strlen(kernel_cmdline);
286             bdloc -= ((len + 255) & ~255);
287             cpu_physical_memory_write(bdloc, kernel_cmdline, len + 1);
288             env->gpr[6] = bdloc;
289             env->gpr[7] = bdloc + len;
290         } else {
291             env->gpr[6] = 0;
292             env->gpr[7] = 0;
293         }
294         env->nip = KERNEL_LOAD_ADDR;
295     } else {
296         kernel_base = 0;
297         kernel_size = 0;
298         initrd_base = 0;
299         initrd_size = 0;
300         bdloc = 0;
301     }
302 }
303
304 static void ref405ep_class_init(ObjectClass *oc, void *data)
305 {
306     MachineClass *mc = MACHINE_CLASS(oc);
307
308     mc->desc = "ref405ep";
309     mc->init = ref405ep_init;
310 }
311
312 static const TypeInfo ref405ep_type = {
313     .name = MACHINE_TYPE_NAME("ref405ep"),
314     .parent = TYPE_MACHINE,
315     .class_init = ref405ep_class_init,
316 };
317
318 /*****************************************************************************/
319 /* AMCC Taihu evaluation board */
320 /* - PowerPC 405EP processor
321  * - SDRAM               128 MB at 0x00000000
322  * - Boot flash          2 MB   at 0xFFE00000
323  * - Application flash   32 MB  at 0xFC000000
324  * - 2 serial ports
325  * - 2 ethernet PHY
326  * - 1 USB 1.1 device    0x50000000
327  * - 1 LCD display       0x50100000
328  * - 1 CPLD              0x50100000
329  * - 1 I2C EEPROM
330  * - 1 I2C thermal sensor
331  * - a set of LEDs
332  * - bit-bang SPI port using GPIOs
333  * - 1 EBC interface connector 0 0x50200000
334  * - 1 cardbus controller + expansion slot.
335  * - 1 PCI expansion slot.
336  */
337 typedef struct taihu_cpld_t taihu_cpld_t;
338 struct taihu_cpld_t {
339     uint8_t reg0;
340     uint8_t reg1;
341 };
342
343 static uint64_t taihu_cpld_read(void *opaque, hwaddr addr, unsigned size)
344 {
345     taihu_cpld_t *cpld;
346     uint32_t ret;
347
348     cpld = opaque;
349     switch (addr) {
350     case 0x0:
351         ret = cpld->reg0;
352         break;
353     case 0x1:
354         ret = cpld->reg1;
355         break;
356     default:
357         ret = 0;
358         break;
359     }
360
361     return ret;
362 }
363
364 static void taihu_cpld_write(void *opaque, hwaddr addr,
365                              uint64_t value, unsigned size)
366 {
367     taihu_cpld_t *cpld;
368
369     cpld = opaque;
370     switch (addr) {
371     case 0x0:
372         /* Read only */
373         break;
374     case 0x1:
375         cpld->reg1 = value;
376         break;
377     default:
378         break;
379     }
380 }
381
382 static const MemoryRegionOps taihu_cpld_ops = {
383     .read = taihu_cpld_read,
384     .write = taihu_cpld_write,
385     .impl = {
386         .min_access_size = 1,
387         .max_access_size = 1,
388     },
389     .endianness = DEVICE_NATIVE_ENDIAN,
390 };
391
392 static void taihu_cpld_reset (void *opaque)
393 {
394     taihu_cpld_t *cpld;
395
396     cpld = opaque;
397     cpld->reg0 = 0x01;
398     cpld->reg1 = 0x80;
399 }
400
401 static void taihu_cpld_init(MemoryRegion *sysmem, uint32_t base)
402 {
403     taihu_cpld_t *cpld;
404     MemoryRegion *cpld_memory = g_new(MemoryRegion, 1);
405
406     cpld = g_malloc0(sizeof(taihu_cpld_t));
407     memory_region_init_io(cpld_memory, NULL, &taihu_cpld_ops, cpld, "cpld", 0x100);
408     memory_region_add_subregion(sysmem, base, cpld_memory);
409     qemu_register_reset(&taihu_cpld_reset, cpld);
410 }
411
412 static void taihu_405ep_init(MachineState *machine)
413 {
414     ram_addr_t ram_size = machine->ram_size;
415     const char *kernel_filename = machine->kernel_filename;
416     const char *initrd_filename = machine->initrd_filename;
417     char *filename;
418     qemu_irq *pic;
419     MemoryRegion *sysmem = get_system_memory();
420     MemoryRegion *bios;
421     MemoryRegion *ram_memories = g_new(MemoryRegion, 2);
422     MemoryRegion *ram = g_malloc0(sizeof(*ram));
423     hwaddr ram_bases[2], ram_sizes[2];
424     long bios_size;
425     target_ulong kernel_base, initrd_base;
426     long kernel_size, initrd_size;
427     int linux_boot;
428     int fl_idx, fl_sectors;
429     DriveInfo *dinfo;
430
431     /* RAM is soldered to the board so the size cannot be changed */
432     ram_size = 0x08000000;
433     memory_region_allocate_system_memory(ram, NULL, "taihu_405ep.ram",
434                                          ram_size);
435
436     ram_bases[0] = 0;
437     ram_sizes[0] = 0x04000000;
438     memory_region_init_alias(&ram_memories[0], NULL,
439                              "taihu_405ep.ram-0", ram, ram_bases[0],
440                              ram_sizes[0]);
441     ram_bases[1] = 0x04000000;
442     ram_sizes[1] = 0x04000000;
443     memory_region_init_alias(&ram_memories[1], NULL,
444                              "taihu_405ep.ram-1", ram, ram_bases[1],
445                              ram_sizes[1]);
446     ppc405ep_init(sysmem, ram_memories, ram_bases, ram_sizes,
447                   33333333, &pic, kernel_filename == NULL ? 0 : 1);
448     /* allocate and load BIOS */
449     fl_idx = 0;
450 #if defined(USE_FLASH_BIOS)
451     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
452     if (dinfo) {
453         BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
454
455         bios_size = blk_getlength(blk);
456         /* XXX: should check that size is 2MB */
457         //        bios_size = 2 * 1024 * 1024;
458         fl_sectors = (bios_size + 65535) >> 16;
459         pflash_cfi02_register((uint32_t)(-bios_size),
460                               NULL, "taihu_405ep.bios", bios_size,
461                               blk, 65536, fl_sectors, 1,
462                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
463                               1);
464         fl_idx++;
465     } else
466 #endif
467     {
468         if (bios_name == NULL)
469             bios_name = BIOS_FILENAME;
470         bios = g_new(MemoryRegion, 1);
471         memory_region_init_ram(bios, NULL, "taihu_405ep.bios", BIOS_SIZE,
472                                &error_fatal);
473         filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
474         if (filename) {
475             bios_size = load_image_size(filename,
476                                         memory_region_get_ram_ptr(bios),
477                                         BIOS_SIZE);
478             g_free(filename);
479             if (bios_size < 0) {
480                 error_report("Could not load PowerPC BIOS '%s'", bios_name);
481                 exit(1);
482             }
483             bios_size = (bios_size + 0xfff) & ~0xfff;
484             memory_region_add_subregion(sysmem, (uint32_t)(-bios_size), bios);
485         } else if (!qtest_enabled()) {
486             error_report("Could not load PowerPC BIOS '%s'", bios_name);
487             exit(1);
488         }
489         memory_region_set_readonly(bios, true);
490     }
491     /* Register Linux flash */
492     dinfo = drive_get(IF_PFLASH, 0, fl_idx);
493     if (dinfo) {
494         BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
495
496         bios_size = blk_getlength(blk);
497         /* XXX: should check that size is 32MB */
498         bios_size = 32 * MiB;
499         fl_sectors = (bios_size + 65535) >> 16;
500         pflash_cfi02_register(0xfc000000, NULL, "taihu_405ep.flash", bios_size,
501                               blk, 65536, fl_sectors, 1,
502                               4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA,
503                               1);
504         fl_idx++;
505     }
506     /* Register CLPD & LCD display */
507     taihu_cpld_init(sysmem, 0x50100000);
508     /* Load kernel */
509     linux_boot = (kernel_filename != NULL);
510     if (linux_boot) {
511         kernel_base = KERNEL_LOAD_ADDR;
512         /* now we can load the kernel */
513         kernel_size = load_image_targphys(kernel_filename, kernel_base,
514                                           ram_size - kernel_base);
515         if (kernel_size < 0) {
516             error_report("could not load kernel '%s'", kernel_filename);
517             exit(1);
518         }
519         /* load initrd */
520         if (initrd_filename) {
521             initrd_base = INITRD_LOAD_ADDR;
522             initrd_size = load_image_targphys(initrd_filename, initrd_base,
523                                               ram_size - initrd_base);
524             if (initrd_size < 0) {
525                 error_report("could not load initial ram disk '%s'",
526                              initrd_filename);
527                 exit(1);
528             }
529         } else {
530             initrd_base = 0;
531             initrd_size = 0;
532         }
533     } else {
534         kernel_base = 0;
535         kernel_size = 0;
536         initrd_base = 0;
537         initrd_size = 0;
538     }
539 }
540
541 static void taihu_class_init(ObjectClass *oc, void *data)
542 {
543     MachineClass *mc = MACHINE_CLASS(oc);
544
545     mc->desc = "taihu";
546     mc->init = taihu_405ep_init;
547 }
548
549 static const TypeInfo taihu_type = {
550     .name = MACHINE_TYPE_NAME("taihu"),
551     .parent = TYPE_MACHINE,
552     .class_init = taihu_class_init,
553 };
554
555 static void ppc405_machine_init(void)
556 {
557     type_register_static(&ref405ep_type);
558     type_register_static(&taihu_type);
559 }
560
561 type_init(ppc405_machine_init)
This page took 0.053355 seconds and 4 git commands to generate.