2 * QEMU PPC PREP hardware System Emulator
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (c) 2017 Hervé Poussineau
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu/osdep.h"
28 #include "hw/timer/m48t59.h"
29 #include "hw/i386/pc.h"
30 #include "hw/char/serial.h"
31 #include "hw/block/fdc.h"
33 #include "sysemu/sysemu.h"
34 #include "hw/isa/isa.h"
35 #include "hw/pci/pci.h"
36 #include "hw/pci/pci_host.h"
37 #include "hw/ppc/ppc.h"
38 #include "hw/boards.h"
39 #include "qemu/error-report.h"
42 #include "hw/loader.h"
43 #include "hw/timer/mc146818rtc.h"
44 #include "hw/isa/pc87312.h"
45 #include "sysemu/block-backend.h"
46 #include "sysemu/arch_init.h"
47 #include "sysemu/kvm.h"
48 #include "sysemu/qtest.h"
49 #include "exec/address-spaces.h"
52 #include "qemu/cutils.h"
55 /* SMP is not enabled, for now */
60 #define CFG_ADDR 0xf0000510
62 #define BIOS_SIZE (1024 * 1024)
63 #define BIOS_FILENAME "ppc_rom.bin"
64 #define KERNEL_LOAD_ADDR 0x01000000
65 #define INITRD_LOAD_ADDR 0x01800000
67 /* Constants for devices init */
68 static const int ide_iobase
[2] = { 0x1f0, 0x170 };
69 static const int ide_iobase2
[2] = { 0x3f6, 0x376 };
70 static const int ide_irq
[2] = { 13, 13 };
72 #define NE2000_NB_MAX 6
74 static uint32_t ne2000_io
[NE2000_NB_MAX
] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
75 static int ne2000_irq
[NE2000_NB_MAX
] = { 9, 10, 11, 3, 4, 5 };
77 /* ISA IO ports bridge */
78 #define PPC_IO_BASE 0x80000000
80 /* PowerPC control and status registers */
86 /* Control and status */
91 /* General purpose registers */
104 /* Error diagnostic */
107 static void PPC_XCSR_writeb (void *opaque
,
108 hwaddr addr
, uint32_t value
)
110 printf("%s: 0x" TARGET_FMT_plx
" => 0x%08" PRIx32
"\n", __func__
, addr
,
114 static void PPC_XCSR_writew (void *opaque
,
115 hwaddr addr
, uint32_t value
)
117 printf("%s: 0x" TARGET_FMT_plx
" => 0x%08" PRIx32
"\n", __func__
, addr
,
121 static void PPC_XCSR_writel (void *opaque
,
122 hwaddr addr
, uint32_t value
)
124 printf("%s: 0x" TARGET_FMT_plx
" => 0x%08" PRIx32
"\n", __func__
, addr
,
128 static uint32_t PPC_XCSR_readb (void *opaque
, hwaddr addr
)
132 printf("%s: 0x" TARGET_FMT_plx
" <= %08" PRIx32
"\n", __func__
, addr
,
138 static uint32_t PPC_XCSR_readw (void *opaque
, hwaddr addr
)
142 printf("%s: 0x" TARGET_FMT_plx
" <= %08" PRIx32
"\n", __func__
, addr
,
148 static uint32_t PPC_XCSR_readl (void *opaque
, hwaddr addr
)
152 printf("%s: 0x" TARGET_FMT_plx
" <= %08" PRIx32
"\n", __func__
, addr
,
158 static const MemoryRegionOps PPC_XCSR_ops
= {
160 .read
= { PPC_XCSR_readb
, PPC_XCSR_readw
, PPC_XCSR_readl
, },
161 .write
= { PPC_XCSR_writeb
, PPC_XCSR_writew
, PPC_XCSR_writel
, },
163 .endianness
= DEVICE_LITTLE_ENDIAN
,
168 /* Fake super-io ports for PREP platform (Intel 82378ZB) */
169 typedef struct sysctrl_t
{
175 qemu_irq contiguous_map_irq
;
180 STATE_HARDFILE
= 0x01,
183 static sysctrl_t
*sysctrl
;
185 static void PREP_io_800_writeb (void *opaque
, uint32_t addr
, uint32_t val
)
187 sysctrl_t
*sysctrl
= opaque
;
189 trace_prep_io_800_writeb(addr
- PPC_IO_BASE
, val
);
192 /* Special port 92 */
193 /* Check soft reset asked */
195 qemu_irq_raise(sysctrl
->reset_irq
);
197 qemu_irq_lower(sysctrl
->reset_irq
);
207 /* Motorola CPU configuration register : read-only */
210 /* Motorola base module feature register : read-only */
213 /* Motorola base module status register : read-only */
216 /* Hardfile light register */
218 sysctrl
->state
|= STATE_HARDFILE
;
220 sysctrl
->state
&= ~STATE_HARDFILE
;
223 /* Password protect 1 register */
224 if (sysctrl
->nvram
!= NULL
) {
225 NvramClass
*k
= NVRAM_GET_CLASS(sysctrl
->nvram
);
226 (k
->toggle_lock
)(sysctrl
->nvram
, 1);
230 /* Password protect 2 register */
231 if (sysctrl
->nvram
!= NULL
) {
232 NvramClass
*k
= NVRAM_GET_CLASS(sysctrl
->nvram
);
233 (k
->toggle_lock
)(sysctrl
->nvram
, 2);
237 /* L2 invalidate register */
238 // tlb_flush(first_cpu, 1);
241 /* system control register */
242 sysctrl
->syscontrol
= val
& 0x0F;
245 /* I/O map type register */
246 sysctrl
->contiguous_map
= val
& 0x01;
247 qemu_set_irq(sysctrl
->contiguous_map_irq
, sysctrl
->contiguous_map
);
250 printf("ERROR: unaffected IO port write: %04" PRIx32
251 " => %02" PRIx32
"\n", addr
, val
);
256 static uint32_t PREP_io_800_readb (void *opaque
, uint32_t addr
)
258 sysctrl_t
*sysctrl
= opaque
;
259 uint32_t retval
= 0xFF;
263 /* Special port 92 */
264 retval
= sysctrl
->endian
<< 1;
267 /* Motorola CPU configuration register */
268 retval
= 0xEF; /* MPC750 */
271 /* Motorola Base module feature register */
272 retval
= 0xAD; /* No ESCC, PMC slot neither ethernet */
275 /* Motorola base module status register */
276 retval
= 0xE0; /* Standard MPC750 */
279 /* Equipment present register:
281 * no upgrade processor
282 * no cards in PCI slots
288 /* Motorola base module extended feature register */
289 retval
= 0x39; /* No USB, CF and PCI bridge. NVRAM present */
292 /* L2 invalidate: don't care */
299 /* system control register
300 * 7 - 6 / 1 - 0: L2 cache enable
302 retval
= sysctrl
->syscontrol
;
306 retval
= 0x03; /* no L2 cache */
309 /* I/O map type register */
310 retval
= sysctrl
->contiguous_map
;
313 printf("ERROR: unaffected IO port: %04" PRIx32
" read\n", addr
);
316 trace_prep_io_800_readb(addr
- PPC_IO_BASE
, retval
);
322 #define NVRAM_SIZE 0x2000
324 static void fw_cfg_boot_set(void *opaque
, const char *boot_device
,
327 fw_cfg_modify_i16(opaque
, FW_CFG_BOOT_DEVICE
, boot_device
[0]);
330 static void ppc_prep_reset(void *opaque
)
332 PowerPCCPU
*cpu
= opaque
;
337 static const MemoryRegionPortio prep_portio_list
[] = {
338 /* System control ports */
339 { 0x0092, 1, 1, .read
= PREP_io_800_readb
, .write
= PREP_io_800_writeb
, },
341 .read
= PREP_io_800_readb
, .write
= PREP_io_800_writeb
, },
342 /* Special port to get debug messages from Open-Firmware */
343 { 0x0F00, 4, 1, .write
= PPC_debug_write
, },
344 PORTIO_END_OF_LIST(),
347 static PortioList prep_port_list
;
349 /*****************************************************************************/
351 static inline uint32_t nvram_read(Nvram
*nvram
, uint32_t addr
)
353 NvramClass
*k
= NVRAM_GET_CLASS(nvram
);
354 return (k
->read
)(nvram
, addr
);
357 static inline void nvram_write(Nvram
*nvram
, uint32_t addr
, uint32_t val
)
359 NvramClass
*k
= NVRAM_GET_CLASS(nvram
);
360 (k
->write
)(nvram
, addr
, val
);
363 static void NVRAM_set_byte(Nvram
*nvram
, uint32_t addr
, uint8_t value
)
365 nvram_write(nvram
, addr
, value
);
368 static uint8_t NVRAM_get_byte(Nvram
*nvram
, uint32_t addr
)
370 return nvram_read(nvram
, addr
);
373 static void NVRAM_set_word(Nvram
*nvram
, uint32_t addr
, uint16_t value
)
375 nvram_write(nvram
, addr
, value
>> 8);
376 nvram_write(nvram
, addr
+ 1, value
& 0xFF);
379 static uint16_t NVRAM_get_word(Nvram
*nvram
, uint32_t addr
)
383 tmp
= nvram_read(nvram
, addr
) << 8;
384 tmp
|= nvram_read(nvram
, addr
+ 1);
389 static void NVRAM_set_lword(Nvram
*nvram
, uint32_t addr
, uint32_t value
)
391 nvram_write(nvram
, addr
, value
>> 24);
392 nvram_write(nvram
, addr
+ 1, (value
>> 16) & 0xFF);
393 nvram_write(nvram
, addr
+ 2, (value
>> 8) & 0xFF);
394 nvram_write(nvram
, addr
+ 3, value
& 0xFF);
397 static void NVRAM_set_string(Nvram
*nvram
, uint32_t addr
, const char *str
,
402 for (i
= 0; i
< max
&& str
[i
] != '\0'; i
++) {
403 nvram_write(nvram
, addr
+ i
, str
[i
]);
405 nvram_write(nvram
, addr
+ i
, str
[i
]);
406 nvram_write(nvram
, addr
+ max
- 1, '\0');
409 static uint16_t NVRAM_crc_update (uint16_t prev
, uint16_t value
)
412 uint16_t pd
, pd1
, pd2
;
417 pd2
= ((pd
>> 4) & 0x000F) ^ pd1
;
418 tmp
^= (pd1
<< 3) | (pd1
<< 8);
419 tmp
^= pd2
| (pd2
<< 7) | (pd2
<< 12);
424 static uint16_t NVRAM_compute_crc (Nvram
*nvram
, uint32_t start
, uint32_t count
)
427 uint16_t crc
= 0xFFFF;
432 for (i
= 0; i
!= count
; i
++) {
433 crc
= NVRAM_crc_update(crc
, NVRAM_get_word(nvram
, start
+ i
));
436 crc
= NVRAM_crc_update(crc
, NVRAM_get_byte(nvram
, start
+ i
) << 8);
442 #define CMDLINE_ADDR 0x017ff000
444 static int PPC_NVRAM_set_params (Nvram
*nvram
, uint16_t NVRAM_size
,
446 uint32_t RAM_size
, int boot_device
,
447 uint32_t kernel_image
, uint32_t kernel_size
,
449 uint32_t initrd_image
, uint32_t initrd_size
,
450 uint32_t NVRAM_image
,
451 int width
, int height
, int depth
)
455 /* Set parameters for Open Hack'Ware BIOS */
456 NVRAM_set_string(nvram
, 0x00, "QEMU_BIOS", 16);
457 NVRAM_set_lword(nvram
, 0x10, 0x00000002); /* structure v2 */
458 NVRAM_set_word(nvram
, 0x14, NVRAM_size
);
459 NVRAM_set_string(nvram
, 0x20, arch
, 16);
460 NVRAM_set_lword(nvram
, 0x30, RAM_size
);
461 NVRAM_set_byte(nvram
, 0x34, boot_device
);
462 NVRAM_set_lword(nvram
, 0x38, kernel_image
);
463 NVRAM_set_lword(nvram
, 0x3C, kernel_size
);
465 /* XXX: put the cmdline in NVRAM too ? */
466 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, RAM_size
- CMDLINE_ADDR
,
468 NVRAM_set_lword(nvram
, 0x40, CMDLINE_ADDR
);
469 NVRAM_set_lword(nvram
, 0x44, strlen(cmdline
));
471 NVRAM_set_lword(nvram
, 0x40, 0);
472 NVRAM_set_lword(nvram
, 0x44, 0);
474 NVRAM_set_lword(nvram
, 0x48, initrd_image
);
475 NVRAM_set_lword(nvram
, 0x4C, initrd_size
);
476 NVRAM_set_lword(nvram
, 0x50, NVRAM_image
);
478 NVRAM_set_word(nvram
, 0x54, width
);
479 NVRAM_set_word(nvram
, 0x56, height
);
480 NVRAM_set_word(nvram
, 0x58, depth
);
481 crc
= NVRAM_compute_crc(nvram
, 0x00, 0xF8);
482 NVRAM_set_word(nvram
, 0xFC, crc
);
487 /* PowerPC PREP hardware initialisation */
488 static void ppc_prep_init(MachineState
*machine
)
490 ram_addr_t ram_size
= machine
->ram_size
;
491 const char *kernel_filename
= machine
->kernel_filename
;
492 const char *kernel_cmdline
= machine
->kernel_cmdline
;
493 const char *initrd_filename
= machine
->initrd_filename
;
494 const char *boot_device
= machine
->boot_order
;
495 MemoryRegion
*sysmem
= get_system_memory();
496 PowerPCCPU
*cpu
= NULL
;
497 CPUPPCState
*env
= NULL
;
500 MemoryRegion
*xcsr
= g_new(MemoryRegion
, 1);
502 int linux_boot
, i
, nb_nics1
;
503 MemoryRegion
*ram
= g_new(MemoryRegion
, 1);
504 uint32_t kernel_base
, initrd_base
;
505 long kernel_size
, initrd_size
;
507 PCIHostState
*pcihost
;
513 DriveInfo
*hd
[MAX_IDE_BUS
* MAX_IDE_DEVS
];
515 sysctrl
= g_malloc0(sizeof(sysctrl_t
));
517 linux_boot
= (kernel_filename
!= NULL
);
520 if (machine
->cpu_model
== NULL
)
521 machine
->cpu_model
= "602";
522 for (i
= 0; i
< smp_cpus
; i
++) {
523 cpu
= cpu_ppc_init(machine
->cpu_model
);
525 fprintf(stderr
, "Unable to find PowerPC CPU definition\n");
530 if (env
->flags
& POWERPC_FLAG_RTC_CLK
) {
531 /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
532 cpu_ppc_tb_init(env
, 7812500UL);
534 /* Set time-base frequency to 100 Mhz */
535 cpu_ppc_tb_init(env
, 100UL * 1000UL * 1000UL);
537 qemu_register_reset(ppc_prep_reset
, cpu
);
541 memory_region_allocate_system_memory(ram
, NULL
, "ppc_prep.ram", ram_size
);
542 memory_region_add_subregion(sysmem
, 0, ram
);
545 kernel_base
= KERNEL_LOAD_ADDR
;
546 /* now we can load the kernel */
547 kernel_size
= load_image_targphys(kernel_filename
, kernel_base
,
548 ram_size
- kernel_base
);
549 if (kernel_size
< 0) {
550 error_report("could not load kernel '%s'", kernel_filename
);
554 if (initrd_filename
) {
555 initrd_base
= INITRD_LOAD_ADDR
;
556 initrd_size
= load_image_targphys(initrd_filename
, initrd_base
,
557 ram_size
- initrd_base
);
558 if (initrd_size
< 0) {
559 error_report("could not load initial ram disk '%s'",
567 ppc_boot_device
= 'm';
573 ppc_boot_device
= '\0';
574 /* For now, OHW cannot boot from the network. */
575 for (i
= 0; boot_device
[i
] != '\0'; i
++) {
576 if (boot_device
[i
] >= 'a' && boot_device
[i
] <= 'f') {
577 ppc_boot_device
= boot_device
[i
];
581 if (ppc_boot_device
== '\0') {
582 fprintf(stderr
, "No valid boot device for Mac99 machine\n");
587 if (PPC_INPUT(env
) != PPC_FLAGS_INPUT_6xx
) {
588 error_report("Only 6xx bus is supported on PREP machine");
592 dev
= qdev_create(NULL
, "raven-pcihost");
593 if (bios_name
== NULL
) {
594 bios_name
= BIOS_FILENAME
;
596 qdev_prop_set_string(dev
, "bios-name", bios_name
);
597 qdev_prop_set_uint32(dev
, "elf-machine", PPC_ELF_MACHINE
);
598 pcihost
= PCI_HOST_BRIDGE(dev
);
599 object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev
), NULL
);
600 qdev_init_nofail(dev
);
601 pci_bus
= (PCIBus
*)qdev_get_child_bus(dev
, "pci.0");
602 if (pci_bus
== NULL
) {
603 fprintf(stderr
, "Couldn't create PCI host controller.\n");
606 sysctrl
->contiguous_map_irq
= qdev_get_gpio_in(dev
, 0);
608 /* PCI -> ISA bridge */
609 pci
= pci_create_simple(pci_bus
, PCI_DEVFN(1, 0), "i82378");
610 cpu
= POWERPC_CPU(first_cpu
);
611 qdev_connect_gpio_out(&pci
->qdev
, 0,
612 cpu
->env
.irq_inputs
[PPC6xx_INPUT_INT
]);
613 sysbus_connect_irq(&pcihost
->busdev
, 0, qdev_get_gpio_in(&pci
->qdev
, 9));
614 sysbus_connect_irq(&pcihost
->busdev
, 1, qdev_get_gpio_in(&pci
->qdev
, 11));
615 sysbus_connect_irq(&pcihost
->busdev
, 2, qdev_get_gpio_in(&pci
->qdev
, 9));
616 sysbus_connect_irq(&pcihost
->busdev
, 3, qdev_get_gpio_in(&pci
->qdev
, 11));
617 isa_bus
= ISA_BUS(qdev_get_child_bus(DEVICE(pci
), "isa.0"));
619 /* Super I/O (parallel + serial ports) */
620 isa
= isa_create(isa_bus
, TYPE_PC87312
);
622 qdev_prop_set_uint8(dev
, "config", 13); /* fdc, ser0, ser1, par0 */
623 qdev_init_nofail(dev
);
625 /* init basic PC hardware */
626 pci_vga_init(pci_bus
);
629 if (nb_nics1
> NE2000_NB_MAX
)
630 nb_nics1
= NE2000_NB_MAX
;
631 for(i
= 0; i
< nb_nics1
; i
++) {
632 if (nd_table
[i
].model
== NULL
) {
633 nd_table
[i
].model
= g_strdup("ne2k_isa");
635 if (strcmp(nd_table
[i
].model
, "ne2k_isa") == 0) {
636 isa_ne2000_init(isa_bus
, ne2000_io
[i
], ne2000_irq
[i
],
639 pci_nic_init_nofail(&nd_table
[i
], pci_bus
, "ne2k_pci", NULL
);
643 ide_drive_get(hd
, ARRAY_SIZE(hd
));
644 for(i
= 0; i
< MAX_IDE_BUS
; i
++) {
645 isa_ide_init(isa_bus
, ide_iobase
[i
], ide_iobase2
[i
], ide_irq
[i
],
649 isa_create_simple(isa_bus
, "i8042");
651 cpu
= POWERPC_CPU(first_cpu
);
652 sysctrl
->reset_irq
= cpu
->env
.irq_inputs
[PPC6xx_INPUT_HRESET
];
654 portio_list_init(&prep_port_list
, NULL
, prep_portio_list
, sysctrl
, "prep");
655 portio_list_add(&prep_port_list
, isa_address_space_io(isa
), 0x0);
657 /* PowerPC control and status register group */
659 memory_region_init_io(xcsr
, NULL
, &PPC_XCSR_ops
, NULL
, "ppc-xcsr", 0x1000);
660 memory_region_add_subregion(sysmem
, 0xFEFF0000, xcsr
);
663 if (machine_usb(machine
)) {
664 pci_create_simple(pci_bus
, -1, "pci-ohci");
667 m48t59
= m48t59_init_isa(isa_bus
, 0x0074, NVRAM_SIZE
, 2000, 59);
670 sysctrl
->nvram
= m48t59
;
672 /* Initialise NVRAM */
673 PPC_NVRAM_set_params(m48t59
, NVRAM_SIZE
, "PREP", ram_size
,
675 kernel_base
, kernel_size
,
677 initrd_base
, initrd_size
,
678 /* XXX: need an option to load a NVRAM image */
680 graphic_width
, graphic_height
, graphic_depth
);
683 static void prep_machine_init(MachineClass
*mc
)
685 mc
->desc
= "PowerPC PREP platform";
686 mc
->init
= ppc_prep_init
;
687 mc
->block_default_type
= IF_IDE
;
688 mc
->max_cpus
= MAX_CPUS
;
689 mc
->default_boot_order
= "cad";
692 static int prep_set_cmos_checksum(DeviceState
*dev
, void *opaque
)
694 uint16_t checksum
= *(uint16_t *)opaque
;
697 if (object_dynamic_cast(OBJECT(dev
), "mc146818rtc")) {
698 rtc
= ISA_DEVICE(dev
);
699 rtc_set_memory(rtc
, 0x2e, checksum
& 0xff);
700 rtc_set_memory(rtc
, 0x3e, checksum
& 0xff);
701 rtc_set_memory(rtc
, 0x2f, checksum
>> 8);
702 rtc_set_memory(rtc
, 0x3f, checksum
>> 8);
707 static void ibm_40p_init(MachineState
*machine
)
709 CPUPPCState
*env
= NULL
;
710 uint16_t cmos_checksum
;
713 SysBusDevice
*pcihost
;
714 Nvram
*m48t59
= NULL
;
719 uint32_t kernel_base
= 0, initrd_base
= 0;
720 long kernel_size
= 0, initrd_size
= 0;
724 if (!machine
->cpu_model
) {
725 machine
->cpu_model
= "604";
727 cpu
= cpu_ppc_init(machine
->cpu_model
);
729 error_report("could not initialize CPU '%s'",
734 if (PPC_INPUT(env
) != PPC_FLAGS_INPUT_6xx
) {
735 error_report("only 6xx bus is supported on this machine");
739 if (env
->flags
& POWERPC_FLAG_RTC_CLK
) {
740 /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
741 cpu_ppc_tb_init(env
, 7812500UL);
743 /* Set time-base frequency to 100 Mhz */
744 cpu_ppc_tb_init(env
, 100UL * 1000UL * 1000UL);
746 qemu_register_reset(ppc_prep_reset
, cpu
);
749 dev
= qdev_create(NULL
, "raven-pcihost");
751 bios_name
= BIOS_FILENAME
;
753 qdev_prop_set_string(dev
, "bios-name", bios_name
);
754 qdev_prop_set_uint32(dev
, "elf-machine", PPC_ELF_MACHINE
);
755 pcihost
= SYS_BUS_DEVICE(dev
);
756 object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev
), NULL
);
757 qdev_init_nofail(dev
);
758 pci_bus
= PCI_BUS(qdev_get_child_bus(dev
, "pci.0"));
760 error_report("could not create PCI host controller");
764 /* PCI -> ISA bridge */
765 dev
= DEVICE(pci_create_simple(pci_bus
, PCI_DEVFN(11, 0), "i82378"));
766 qdev_connect_gpio_out(dev
, 0,
767 cpu
->env
.irq_inputs
[PPC6xx_INPUT_INT
]);
768 sysbus_connect_irq(pcihost
, 0, qdev_get_gpio_in(dev
, 15));
769 sysbus_connect_irq(pcihost
, 1, qdev_get_gpio_in(dev
, 13));
770 sysbus_connect_irq(pcihost
, 2, qdev_get_gpio_in(dev
, 15));
771 sysbus_connect_irq(pcihost
, 3, qdev_get_gpio_in(dev
, 13));
772 isa_bus
= ISA_BUS(qdev_get_child_bus(dev
, "isa.0"));
774 /* Memory controller */
775 dev
= DEVICE(isa_create(isa_bus
, "rs6000-mc"));
776 qdev_prop_set_uint32(dev
, "ram-size", machine
->ram_size
);
777 qdev_init_nofail(dev
);
779 /* initialize CMOS checksums */
780 cmos_checksum
= 0x6aa9;
781 qbus_walk_children(BUS(isa_bus
), prep_set_cmos_checksum
, NULL
, NULL
, NULL
,
784 /* add some more devices */
785 if (defaults_enabled()) {
786 isa_create_simple(isa_bus
, "i8042");
787 m48t59
= NVRAM(isa_create_simple(isa_bus
, "isa-m48t59"));
789 dev
= DEVICE(isa_create(isa_bus
, "cs4231a"));
790 qdev_prop_set_uint32(dev
, "iobase", 0x830);
791 qdev_prop_set_uint32(dev
, "irq", 10);
792 qdev_init_nofail(dev
);
794 dev
= DEVICE(isa_create(isa_bus
, "pc87312"));
795 qdev_prop_set_uint32(dev
, "config", 12);
796 qdev_init_nofail(dev
);
798 dev
= DEVICE(isa_create(isa_bus
, "prep-systemio"));
799 qdev_prop_set_uint32(dev
, "ibm-planar-id", 0xfc);
800 qdev_prop_set_uint32(dev
, "equipment", 0xc0);
801 qdev_init_nofail(dev
);
803 pci_create_simple(pci_bus
, PCI_DEVFN(1, 0), "lsi53c810");
805 /* XXX: s3-trio at PCI_DEVFN(2, 0) */
806 pci_vga_init(pci_bus
);
808 for (i
= 0; i
< nb_nics
; i
++) {
809 pci_nic_init_nofail(&nd_table
[i
], pci_bus
, "pcnet",
810 i
== 0 ? "3" : NULL
);
814 /* Prepare firmware configuration for OpenBIOS */
815 fw_cfg
= fw_cfg_init_mem(CFG_ADDR
, CFG_ADDR
+ 2);
817 if (machine
->kernel_filename
) {
819 kernel_base
= KERNEL_LOAD_ADDR
;
820 kernel_size
= load_image_targphys(machine
->kernel_filename
,
822 machine
->ram_size
- kernel_base
);
823 if (kernel_size
< 0) {
824 error_report("could not load kernel '%s'",
825 machine
->kernel_filename
);
828 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_ADDR
, kernel_base
);
829 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_SIZE
, kernel_size
);
831 if (machine
->initrd_filename
) {
832 initrd_base
= INITRD_LOAD_ADDR
;
833 initrd_size
= load_image_targphys(machine
->initrd_filename
,
835 machine
->ram_size
- initrd_base
);
836 if (initrd_size
< 0) {
837 error_report("could not load initial ram disk '%s'",
838 machine
->initrd_filename
);
841 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_ADDR
, initrd_base
);
842 fw_cfg_add_i32(fw_cfg
, FW_CFG_INITRD_SIZE
, initrd_size
);
844 if (machine
->kernel_cmdline
&& *machine
->kernel_cmdline
) {
845 fw_cfg_add_i32(fw_cfg
, FW_CFG_KERNEL_CMDLINE
, CMDLINE_ADDR
);
846 pstrcpy_targphys("cmdline", CMDLINE_ADDR
, TARGET_PAGE_SIZE
,
847 machine
->kernel_cmdline
);
848 fw_cfg_add_string(fw_cfg
, FW_CFG_CMDLINE_DATA
,
849 machine
->kernel_cmdline
);
850 fw_cfg_add_i32(fw_cfg
, FW_CFG_CMDLINE_SIZE
,
851 strlen(machine
->kernel_cmdline
) + 1);
855 boot_device
= machine
->boot_order
[0];
858 fw_cfg_add_i16(fw_cfg
, FW_CFG_MAX_CPUS
, (uint16_t)max_cpus
);
859 fw_cfg_add_i64(fw_cfg
, FW_CFG_RAM_SIZE
, (uint64_t)machine
->ram_size
);
860 fw_cfg_add_i16(fw_cfg
, FW_CFG_MACHINE_ID
, ARCH_PREP
);
862 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_WIDTH
, graphic_width
);
863 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_HEIGHT
, graphic_height
);
864 fw_cfg_add_i16(fw_cfg
, FW_CFG_PPC_DEPTH
, graphic_depth
);
866 fw_cfg_add_i32(fw_cfg
, FW_CFG_PPC_IS_KVM
, kvm_enabled());
871 fw_cfg_add_i32(fw_cfg
, FW_CFG_PPC_TBFREQ
, kvmppc_get_tbfreq());
872 hypercall
= g_malloc(16);
873 kvmppc_get_hypercall(env
, hypercall
, 16);
874 fw_cfg_add_bytes(fw_cfg
, FW_CFG_PPC_KVM_HC
, hypercall
, 16);
875 fw_cfg_add_i32(fw_cfg
, FW_CFG_PPC_KVM_PID
, getpid());
878 fw_cfg_add_i32(fw_cfg
, FW_CFG_PPC_TBFREQ
, NANOSECONDS_PER_SECOND
);
880 fw_cfg_add_i16(fw_cfg
, FW_CFG_BOOT_DEVICE
, boot_device
);
881 qemu_register_boot_set(fw_cfg_boot_set
, fw_cfg
);
883 /* Prepare firmware configuration for Open Hack'Ware */
885 PPC_NVRAM_set_params(m48t59
, NVRAM_SIZE
, "PREP", ram_size
,
887 kernel_base
, kernel_size
,
888 machine
->kernel_cmdline
,
889 initrd_base
, initrd_size
,
890 /* XXX: need an option to load a NVRAM image */
892 graphic_width
, graphic_height
, graphic_depth
);
896 static void ibm_40p_machine_init(MachineClass
*mc
)
898 mc
->desc
= "IBM RS/6000 7020 (40p)",
899 mc
->init
= ibm_40p_init
;
901 mc
->pci_allow_0_address
= true;
902 mc
->default_ram_size
= 128 * M_BYTE
;
903 mc
->block_default_type
= IF_SCSI
;
904 mc
->default_boot_order
= "c";
907 DEFINE_MACHINE("40p", ibm_40p_machine_init
)
908 DEFINE_MACHINE("prep", prep_machine_init
)