This subproject is about implementing emulation of Pegasos2 board which can run Linux and several Amiga like and other OSes.
While QEMU already has sam460ex board that can run Amiga like OSes, that is based on an embedded PPC440 (BookE) core SoC which cannot use KVM on PPC hosts and lacks some advanced PPC features such as AltiVec/VMX which could be used by some programs to run faster via exploiting QEMU's ability to translate these to corresponding host vector instructions where possible. MorphOS runs on the QEMU mac99 emulation but AmigaOS doesn't so having a board with a BookS CPU that can run all Amiga like OSes could be useful for KVM acceleration on BookS PPC hosts and allowing AltiVec/VMX under AmigaOS. The Pegasos2 is a good target for that.
So let's explore what's needed to implement it in QEMU. First step is to gather all information about the board so we get to know it.
Know the hardware
The bPlan/Genesi Pegasos II is built around the Marvell Discovery II MV64360 family PowerPC system controller chip, specifically the MV64361 version and a VIA VT8231 integrated SuperIO/South Bridge. These two chips provide almost all of its functions (except Firewire which is not needed to boot so it will be ignored for now). The CPU is on a separate card and can be a passive cooled G3 (750CXe) or a G4 (7447) with active cooling. For reference here are the specifications in short:
The schematics of the board was also published by Genesi and is freely available. Documentation of the MV64361 and VT8231 chips are not freely available (so cannot be uploaded or linked here) but it may be possible to find these on-line by searching for MV64360/1/2 and VT8231 respectively. The VT8231 is also very similar to the VT82C686B so information about that chip could also be useful. (QEMU already has some implementation of the VT82C686B which is used by the mips_fulong2e board.)
Know the firmware
The board has an Open Firmware implementation that is based on CodeGen's SmartFirmware but it is not identical to the open source version as it has modifications from bPlan that were not open sourced. Apart from board specific initialisation it also integrates a BIOS emulator which is used to run option ROM of PC video cards. The device tree can be seen in PegasosII_OFW-Tree.txt and all other info about the open firmware implementation in PegasosII_OFW-Dump.txt. As the board's firmware is not open source it cannot be redistributed and it also cannot be included in QEMU or uploaded here which is a problem that eventually will need to be solved. Either by reimplementing it from the open source parts it consists of (the BIOS emulator is likely based on x86emu similar to what is described here or how it's implemented in Pmon 2000) or replacing it with one of the existing open firmware implementations in QEMU (OpenBIOS or SLOF) but those will need to be modified to provide the info as guests running on Pegasos 2 expect. Which way we choose will be decided later, fixing OpenBIOS to be usable would help to make it more generic and also fix problem with MorphOS on mac99 while reimplementing SmartFirmware based firmware may be more compatible to real hardware but would add yet another firmware to QEMU which may not be desirable. Both ways would probably need same amount of work so not decided yet. I've made some experiments to port OpenFirmware to Pegasos2 but it does not work yet and would need similar modifications to emulate the different device tree. Also there are plans to emulate minimal OF within QEMU for spapr so maybe that could be used to replace firmware once it lands upstream. Easiest would be if bPlan open sourced the firmware but so far they haven't replied to any queries about that. Until then, a ROM image is needed to test this emulation which can be obtained by dumping it from your Pegasos II or maybe finding the firmware update called up050404 that was once downloadable from bPlan but not there any more. The ROM image can be extracted from that update with extract_rom_from_updater.
Implementing emulation in QEMU
To emulate this board we can use existing PPC CPU emulation. The VT8231 can be based on and reuse similar parts of VT82C686B that already exist in QEMU but these may need to be enhanced or fixed for differences between these chips and also adding missing pieces. (The mips_fulong2e board that uses VT82C686B emulation seems to be only partially implemented and the 686B is also missing a lot of details such as AC97 sound so this is not a finished emulation and may need to be finished and not only modified for differences between 686B and VT8231. While it's a good starting point, expect missing pieces when using it.) The biggest missing part is the MV64361 which is quite a complex chip and it needs to be implemented from scratch as no emulation of it is present in QEMU yet so this will probably be the hardest task. (Another MIPS board the mips_malta which is emulated by QEMU is based on a chip named GT64120 which may be similar to the MV64361 because Marvell apparently bought Galileo Tech which produced that chip and may have based the Discovery II on that. So maybe hw/mips/gt64xxx_pci.c could be used for some inspiration but I'm not sure how similar these are.)
Current status and outstanding issues
The work in progress pegasos2 emulation is in the pegasos2 branch of git. Currently most of the missing parts are being worked on in a single file (hw/ppc/pegasos2.c) because I find it simpler to see everything in one place than working with files scattered around in different dirs, but later before upstreaming this will need to be split into device emulation of MV64361, VT8231, actual board code and their headers. I've put markers where the split will approximately happen, keep this in mind when changing code in this file and keep it organised. Other changes for already implemented VIA parts are in their respective files.
In its current state the board firmware ROM runs and also can boot operating systems but only MorphOS >=2.6 can usefully boot yet. Linux (I've tested with Debian 8.11.0 powerpc netinst image) also boots but it does not seem to have driver for the VGA card (expects Radeon VGA) so can only be used over serial console. Similar to Linux, AmigaOS4.1 PegasosII version also boots but can't be seen due to no graphics driver. Maybe the driver from Sam460EX version could be used somehow but I did not attempt that. A lot of MV64361 might still be missing and there are also missing pieces of VT8231 but not sure how much of these are needed. The QEMU command line is something like:
qemu-system-ppc -M pegasos2 -bios path/to/pegrom.bin \ -vga none -device ati-vga,romfile=VGABIOS-lgpl-latest.bin \ -cdrom some.iso -d guest_errors,unimp
Look for output in the serial window (try Ctrl+Alt+2) or use -serial stdio QEMU option to redirect to terminal but that mixes up debug messages also printed there.
Below is a summary of known (solved or have a work around) and unknown (outstanding) issues with links to tickets where they are tracked: