diff mbox series

[v4,6/6] hw/ppc: Add emulation of Genesi/bPlan Pegasos II

Message ID 848089b1c91e0c28eb7c52ccdc55dc870eb49dc0.1614282457.git.balaton@eik.bme.hu (mailing list archive)
State New, archived
Headers show
Series Pegasos2 emulation | expand

Commit Message

BALATON Zoltan Feb. 25, 2021, 7:47 p.m. UTC
Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
a PowerPC board based on the Marvell MV64361 system controller and the
VIA VT8231 integrated south bridge/superio chips. It can run Linux,
AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
image is needed to boot and only MorphOS has a video driver to produce
graphics output. Linux could work too but distros that supported this
machine don't include usual video drivers so those only run with
serial console for now.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 MAINTAINERS                             |  10 ++
 default-configs/devices/ppc-softmmu.mak |   2 +
 hw/ppc/Kconfig                          |  10 ++
 hw/ppc/meson.build                      |   2 +
 hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
 5 files changed, 168 insertions(+)
 create mode 100644 hw/ppc/pegasos2.c

Comments

Philippe Mathieu-Daudé March 2, 2021, 7:59 a.m. UTC | #1
On 2/25/21 8:47 PM, BALATON Zoltan wrote:
> Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
> a PowerPC board based on the Marvell MV64361 system controller and the
> VIA VT8231 integrated south bridge/superio chips. It can run Linux,
> AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
> image is needed to boot and only MorphOS has a video driver to produce
> graphics output. Linux could work too but distros that supported this
> machine don't include usual video drivers so those only run with
> serial console for now.
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>  MAINTAINERS                             |  10 ++
>  default-configs/devices/ppc-softmmu.mak |   2 +
>  hw/ppc/Kconfig                          |  10 ++
>  hw/ppc/meson.build                      |   2 +
>  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
>  5 files changed, 168 insertions(+)
>  create mode 100644 hw/ppc/pegasos2.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 9b2aa18e1f..a023217702 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
>  F: pc-bios/u-boot-sam460ex-20100605.bin
>  F: roms/u-boot-sam460ex
>  
> +pegasos2
> +M: BALATON Zoltan <balaton@eik.bme.hu>
> +R: David Gibson <david@gibson.dropbear.id.au>

:)

> +L: qemu-ppc@nongnu.org
> +S: Maintained
> +F: hw/ppc/pegasos2.c
> +F: hw/pci-host/mv64361.c
> +F: hw/pci-host/mv643xx.h
> +F: include/hw/pci-host/mv64361.h
> +
>  RISC-V Machines
>  ---------------
>  OpenTitan
> diff --git a/default-configs/devices/ppc-softmmu.mak b/default-configs/devices/ppc-softmmu.mak
> index 61b78b844d..4535993d8d 100644
> --- a/default-configs/devices/ppc-softmmu.mak
> +++ b/default-configs/devices/ppc-softmmu.mak
> @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
>  CONFIG_MAC_OLDWORLD=y
>  CONFIG_MAC_NEWWORLD=y
>  
> +CONFIG_PEGASOS2=y
> +
>  # For PReP
>  CONFIG_PREP=y
> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
> index d11dc30509..98d8dd1a84 100644
> --- a/hw/ppc/Kconfig
> +++ b/hw/ppc/Kconfig
> @@ -68,6 +68,16 @@ config SAM460EX
>      select USB_OHCI
>      select FDT_PPC
>  
> +config PEGASOS2
> +    bool
> +    select MV64361
> +    select VT82C686
> +    select IDE_VIA
> +    select SMBUS_EEPROM
> +# These should come with VT82C686
> +    select APM
> +    select ACPI_X86
> +
>  config PREP
>      bool
>      imply PCI_DEVICES
> diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
> index 218631c883..86d6f379d1 100644
> --- a/hw/ppc/meson.build
> +++ b/hw/ppc/meson.build
> @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
>  ))
>  # PowerPC 440 Xilinx ML507 reference board.
>  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
> +# Pegasos2
> +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
>  
>  hw_arch += {'ppc': ppc_ss}
> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
> new file mode 100644
> index 0000000000..427e884fbf
> --- /dev/null
> +++ b/hw/ppc/pegasos2.c
> @@ -0,0 +1,144 @@
> +/*
> + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
> + *
> + * Copyright (c) 2018-2020 BALATON Zoltan

2018-2021

> + *
> + * This work is licensed under the GNU GPL license version 2 or later.
> + *
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "qemu/units.h"
> +#include "qapi/error.h"
> +#include "hw/hw.h"
> +#include "hw/ppc/ppc.h"
> +#include "hw/sysbus.h"
> +#include "hw/pci/pci_host.h"
> +#include "hw/irq.h"
> +#include "hw/pci-host/mv64361.h"
> +#include "hw/isa/vt82c686.h"
> +#include "hw/ide/pci.h"
> +#include "hw/i2c/smbus_eeprom.h"
> +#include "hw/qdev-properties.h"
> +#include "sysemu/reset.h"
> +#include "hw/boards.h"
> +#include "hw/loader.h"
> +#include "hw/fw-path-provider.h"
> +#include "elf.h"
> +#include "qemu/log.h"
> +#include "qemu/error-report.h"
> +#include "sysemu/kvm.h"
> +#include "kvm_ppc.h"
> +#include "exec/address-spaces.h"
> +#include "trace.h"
> +#include "qemu/datadir.h"
> +#include "sysemu/device_tree.h"
> +
> +#define PROM_FILENAME "pegasos2.rom"
> +#define PROM_ADDR     0xfff00000
> +#define PROM_SIZE     0x80000
> +
> +#define BUS_FREQ 133333333

Can you rename as BUS_FREQ_HZ?

> +
> +static void pegasos2_cpu_reset(void *opaque)
> +{
> +    PowerPCCPU *cpu = opaque;
> +
> +    cpu_reset(CPU(cpu));
> +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
> +}
> +
> +static void pegasos2_init(MachineState *machine)
> +{
> +    PowerPCCPU *cpu = NULL;
> +    MemoryRegion *rom = g_new(MemoryRegion, 1);
> +    DeviceState *mv;
> +    PCIBus *pci_bus;
> +    PCIDevice *dev;
> +    I2CBus *i2c_bus;
> +    const char *fwname = machine->firmware ?: PROM_FILENAME;
> +    char *filename;
> +    int sz;
> +    uint8_t *spd_data;
> +
> +    /* init CPU */
> +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
> +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
> +        error_report("Incompatible CPU, only 6xx bus supported");
> +        exit(1);
> +    }
> +
> +    /* Set time-base frequency */
> +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
> +    qemu_register_reset(pegasos2_cpu_reset, cpu);
> +
> +    /* RAM */
> +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
> +
> +    /* allocate and load firmware */
> +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
> +    if (!filename) {
> +        error_report("Could not find firmware '%s'", fwname);
> +        exit(1);
> +    }
> +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
> +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
> +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
> +                  PPC_ELF_MACHINE, 0, 0);
> +    if (sz <= 0) {
> +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
> +    }
> +    if (sz <= 0 || sz > PROM_SIZE) {
> +        error_report("Could not load firmware '%s'", filename);
> +        exit(1);
> +    }
> +    g_free(filename);
> +
> +    /* Marvell Discovery II system controller */
> +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
> +                        ((qemu_irq *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));

Indent off.

Otherwise:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
BALATON Zoltan March 2, 2021, 9:13 a.m. UTC | #2
On Tue, 2 Mar 2021, Philippe Mathieu-Daudé wrote:
> On 2/25/21 8:47 PM, BALATON Zoltan wrote:
>> Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
>> a PowerPC board based on the Marvell MV64361 system controller and the
>> VIA VT8231 integrated south bridge/superio chips. It can run Linux,
>> AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
>> image is needed to boot and only MorphOS has a video driver to produce
>> graphics output. Linux could work too but distros that supported this
>> machine don't include usual video drivers so those only run with
>> serial console for now.
>>
>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>> ---
>>  MAINTAINERS                             |  10 ++
>>  default-configs/devices/ppc-softmmu.mak |   2 +
>>  hw/ppc/Kconfig                          |  10 ++
>>  hw/ppc/meson.build                      |   2 +
>>  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
>>  5 files changed, 168 insertions(+)
>>  create mode 100644 hw/ppc/pegasos2.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 9b2aa18e1f..a023217702 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
>>  F: pc-bios/u-boot-sam460ex-20100605.bin
>>  F: roms/u-boot-sam460ex
>>
>> +pegasos2
>> +M: BALATON Zoltan <balaton@eik.bme.hu>
>> +R: David Gibson <david@gibson.dropbear.id.au>
>
> :)

He's also listed as reviewer for the sam460ex and I think as the PPC 
maintainer probably should be notified about changes that's why this is 
here. I guess he can complain or submit a patch later if he wants to be 
removed.

>> +L: qemu-ppc@nongnu.org
>> +S: Maintained
>> +F: hw/ppc/pegasos2.c
>> +F: hw/pci-host/mv64361.c
>> +F: hw/pci-host/mv643xx.h
>> +F: include/hw/pci-host/mv64361.h
>> +
>>  RISC-V Machines
>>  ---------------
>>  OpenTitan
>> diff --git a/default-configs/devices/ppc-softmmu.mak b/default-configs/devices/ppc-softmmu.mak
>> index 61b78b844d..4535993d8d 100644
>> --- a/default-configs/devices/ppc-softmmu.mak
>> +++ b/default-configs/devices/ppc-softmmu.mak
>> @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
>>  CONFIG_MAC_OLDWORLD=y
>>  CONFIG_MAC_NEWWORLD=y
>>
>> +CONFIG_PEGASOS2=y
>> +
>>  # For PReP
>>  CONFIG_PREP=y
>> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
>> index d11dc30509..98d8dd1a84 100644
>> --- a/hw/ppc/Kconfig
>> +++ b/hw/ppc/Kconfig
>> @@ -68,6 +68,16 @@ config SAM460EX
>>      select USB_OHCI
>>      select FDT_PPC
>>
>> +config PEGASOS2
>> +    bool
>> +    select MV64361
>> +    select VT82C686
>> +    select IDE_VIA
>> +    select SMBUS_EEPROM
>> +# These should come with VT82C686
>> +    select APM
>> +    select ACPI_X86
>> +
>>  config PREP
>>      bool
>>      imply PCI_DEVICES
>> diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
>> index 218631c883..86d6f379d1 100644
>> --- a/hw/ppc/meson.build
>> +++ b/hw/ppc/meson.build
>> @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
>>  ))
>>  # PowerPC 440 Xilinx ML507 reference board.
>>  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
>> +# Pegasos2
>> +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
>>
>>  hw_arch += {'ppc': ppc_ss}
>> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
>> new file mode 100644
>> index 0000000000..427e884fbf
>> --- /dev/null
>> +++ b/hw/ppc/pegasos2.c
>> @@ -0,0 +1,144 @@
>> +/*
>> + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
>> + *
>> + * Copyright (c) 2018-2020 BALATON Zoltan
>
> 2018-2021

Not really. I've done this between Christmas of 2018 and 2020. This year 
were only changes for upstreaming and review comments so I preserved the 
dates to record when the actual code was written.

>> + *
>> + * This work is licensed under the GNU GPL license version 2 or later.
>> + *
>> + */
>> +
>> +#include "qemu/osdep.h"
>> +#include "qemu-common.h"
>> +#include "qemu/units.h"
>> +#include "qapi/error.h"
>> +#include "hw/hw.h"
>> +#include "hw/ppc/ppc.h"
>> +#include "hw/sysbus.h"
>> +#include "hw/pci/pci_host.h"
>> +#include "hw/irq.h"
>> +#include "hw/pci-host/mv64361.h"
>> +#include "hw/isa/vt82c686.h"
>> +#include "hw/ide/pci.h"
>> +#include "hw/i2c/smbus_eeprom.h"
>> +#include "hw/qdev-properties.h"
>> +#include "sysemu/reset.h"
>> +#include "hw/boards.h"
>> +#include "hw/loader.h"
>> +#include "hw/fw-path-provider.h"
>> +#include "elf.h"
>> +#include "qemu/log.h"
>> +#include "qemu/error-report.h"
>> +#include "sysemu/kvm.h"
>> +#include "kvm_ppc.h"
>> +#include "exec/address-spaces.h"
>> +#include "trace.h"
>> +#include "qemu/datadir.h"
>> +#include "sysemu/device_tree.h"
>> +
>> +#define PROM_FILENAME "pegasos2.rom"
>> +#define PROM_ADDR     0xfff00000
>> +#define PROM_SIZE     0x80000
>> +
>> +#define BUS_FREQ 133333333
>
> Can you rename as BUS_FREQ_HZ?
>
>> +
>> +static void pegasos2_cpu_reset(void *opaque)
>> +{
>> +    PowerPCCPU *cpu = opaque;
>> +
>> +    cpu_reset(CPU(cpu));
>> +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
>> +}
>> +
>> +static void pegasos2_init(MachineState *machine)
>> +{
>> +    PowerPCCPU *cpu = NULL;
>> +    MemoryRegion *rom = g_new(MemoryRegion, 1);
>> +    DeviceState *mv;
>> +    PCIBus *pci_bus;
>> +    PCIDevice *dev;
>> +    I2CBus *i2c_bus;
>> +    const char *fwname = machine->firmware ?: PROM_FILENAME;
>> +    char *filename;
>> +    int sz;
>> +    uint8_t *spd_data;
>> +
>> +    /* init CPU */
>> +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
>> +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
>> +        error_report("Incompatible CPU, only 6xx bus supported");
>> +        exit(1);
>> +    }
>> +
>> +    /* Set time-base frequency */
>> +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
>> +    qemu_register_reset(pegasos2_cpu_reset, cpu);
>> +
>> +    /* RAM */
>> +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>> +
>> +    /* allocate and load firmware */
>> +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
>> +    if (!filename) {
>> +        error_report("Could not find firmware '%s'", fwname);
>> +        exit(1);
>> +    }
>> +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
>> +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
>> +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
>> +                  PPC_ELF_MACHINE, 0, 0);
>> +    if (sz <= 0) {
>> +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
>> +    }
>> +    if (sz <= 0 || sz > PROM_SIZE) {
>> +        error_report("Could not load firmware '%s'", filename);
>> +        exit(1);
>> +    }
>> +    g_free(filename);
>> +
>> +    /* Marvell Discovery II system controller */
>> +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
>> +                        ((qemu_irq *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
>
> Indent off.

There's no other way to fit in the 80 chars line length limit in a 
sensible way. (Aligning to DEVICE( would be confusing as last arg belongs 
to sysbus_create_simple().)

> Otherwise:
> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Thanks, I'll do the other changes you've recommended.

Regards,
BALATON Zoltan
Philippe Mathieu-Daudé March 2, 2021, 10:05 a.m. UTC | #3
On 3/2/21 10:13 AM, BALATON Zoltan wrote:
> On Tue, 2 Mar 2021, Philippe Mathieu-Daudé wrote:
>> On 2/25/21 8:47 PM, BALATON Zoltan wrote:
>>> Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
>>> a PowerPC board based on the Marvell MV64361 system controller and the
>>> VIA VT8231 integrated south bridge/superio chips. It can run Linux,
>>> AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
>>> image is needed to boot and only MorphOS has a video driver to produce
>>> graphics output. Linux could work too but distros that supported this
>>> machine don't include usual video drivers so those only run with
>>> serial console for now.
>>>
>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>> ---
>>>  MAINTAINERS                             |  10 ++
>>>  default-configs/devices/ppc-softmmu.mak |   2 +
>>>  hw/ppc/Kconfig                          |  10 ++
>>>  hw/ppc/meson.build                      |   2 +
>>>  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
>>>  5 files changed, 168 insertions(+)
>>>  create mode 100644 hw/ppc/pegasos2.c
>>>
>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>> index 9b2aa18e1f..a023217702 100644
>>> --- a/MAINTAINERS
>>> +++ b/MAINTAINERS
>>> @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
>>>  F: pc-bios/u-boot-sam460ex-20100605.bin
>>>  F: roms/u-boot-sam460ex
>>>
>>> +pegasos2
>>> +M: BALATON Zoltan <balaton@eik.bme.hu>
>>> +R: David Gibson <david@gibson.dropbear.id.au>
>>
>> :)
> 
> He's also listed as reviewer for the sam460ex and I think as the PPC
> maintainer probably should be notified about changes that's why this is
> here. I guess he can complain or submit a patch later if he wants to be
> removed.

To clarify the confusion with this simple smiley, I meant I'm glad
you found someone interested in being reviewer with your board, it
was not a mockery...

> 
>>> +L: qemu-ppc@nongnu.org
>>> +S: Maintained
>>> +F: hw/ppc/pegasos2.c
>>> +F: hw/pci-host/mv64361.c
>>> +F: hw/pci-host/mv643xx.h
>>> +F: include/hw/pci-host/mv64361.h
>>> +
>>>  RISC-V Machines
>>>  ---------------
>>>  OpenTitan
>>> diff --git a/default-configs/devices/ppc-softmmu.mak
>>> b/default-configs/devices/ppc-softmmu.mak
>>> index 61b78b844d..4535993d8d 100644
>>> --- a/default-configs/devices/ppc-softmmu.mak
>>> +++ b/default-configs/devices/ppc-softmmu.mak
>>> @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
>>>  CONFIG_MAC_OLDWORLD=y
>>>  CONFIG_MAC_NEWWORLD=y
>>>
>>> +CONFIG_PEGASOS2=y
>>> +
>>>  # For PReP
>>>  CONFIG_PREP=y
>>> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
>>> index d11dc30509..98d8dd1a84 100644
>>> --- a/hw/ppc/Kconfig
>>> +++ b/hw/ppc/Kconfig
>>> @@ -68,6 +68,16 @@ config SAM460EX
>>>      select USB_OHCI
>>>      select FDT_PPC
>>>
>>> +config PEGASOS2
>>> +    bool
>>> +    select MV64361
>>> +    select VT82C686
>>> +    select IDE_VIA
>>> +    select SMBUS_EEPROM
>>> +# These should come with VT82C686
>>> +    select APM

You might get ride of this one by rebasing/including
https://www.mail-archive.com/qemu-devel@nongnu.org/msg786878.html

>>> +    select ACPI_X86
>>> +
>>>  config PREP
>>>      bool
>>>      imply PCI_DEVICES
>>> diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
>>> index 218631c883..86d6f379d1 100644
>>> --- a/hw/ppc/meson.build
>>> +++ b/hw/ppc/meson.build
>>> @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
>>>  ))
>>>  # PowerPC 440 Xilinx ML507 reference board.
>>>  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
>>> +# Pegasos2
>>> +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
>>>
>>>  hw_arch += {'ppc': ppc_ss}
>>> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
>>> new file mode 100644
>>> index 0000000000..427e884fbf
>>> --- /dev/null
>>> +++ b/hw/ppc/pegasos2.c
>>> @@ -0,0 +1,144 @@
>>> +/*
>>> + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
>>> + *
>>> + * Copyright (c) 2018-2020 BALATON Zoltan
>>
>> 2018-2021
> 
> Not really. I've done this between Christmas of 2018 and 2020. This year
> were only changes for upstreaming and review comments so I preserved the
> dates to record when the actual code was written.
> 
>>> + *
>>> + * This work is licensed under the GNU GPL license version 2 or later.
>>> + *
>>> + */
>>> +
>>> +#include "qemu/osdep.h"
>>> +#include "qemu-common.h"
>>> +#include "qemu/units.h"
>>> +#include "qapi/error.h"
>>> +#include "hw/hw.h"
>>> +#include "hw/ppc/ppc.h"
>>> +#include "hw/sysbus.h"
>>> +#include "hw/pci/pci_host.h"
>>> +#include "hw/irq.h"
>>> +#include "hw/pci-host/mv64361.h"
>>> +#include "hw/isa/vt82c686.h"
>>> +#include "hw/ide/pci.h"
>>> +#include "hw/i2c/smbus_eeprom.h"
>>> +#include "hw/qdev-properties.h"
>>> +#include "sysemu/reset.h"
>>> +#include "hw/boards.h"
>>> +#include "hw/loader.h"
>>> +#include "hw/fw-path-provider.h"
>>> +#include "elf.h"
>>> +#include "qemu/log.h"
>>> +#include "qemu/error-report.h"
>>> +#include "sysemu/kvm.h"
>>> +#include "kvm_ppc.h"
>>> +#include "exec/address-spaces.h"
>>> +#include "trace.h"
>>> +#include "qemu/datadir.h"
>>> +#include "sysemu/device_tree.h"
>>> +
>>> +#define PROM_FILENAME "pegasos2.rom"
>>> +#define PROM_ADDR     0xfff00000
>>> +#define PROM_SIZE     0x80000
>>> +
>>> +#define BUS_FREQ 133333333
>>
>> Can you rename as BUS_FREQ_HZ?
>>
>>> +
>>> +static void pegasos2_cpu_reset(void *opaque)
>>> +{
>>> +    PowerPCCPU *cpu = opaque;
>>> +
>>> +    cpu_reset(CPU(cpu));
>>> +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
>>> +}
>>> +
>>> +static void pegasos2_init(MachineState *machine)
>>> +{
>>> +    PowerPCCPU *cpu = NULL;
>>> +    MemoryRegion *rom = g_new(MemoryRegion, 1);
>>> +    DeviceState *mv;
>>> +    PCIBus *pci_bus;
>>> +    PCIDevice *dev;
>>> +    I2CBus *i2c_bus;
>>> +    const char *fwname = machine->firmware ?: PROM_FILENAME;
>>> +    char *filename;
>>> +    int sz;
>>> +    uint8_t *spd_data;
>>> +
>>> +    /* init CPU */
>>> +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
>>> +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
>>> +        error_report("Incompatible CPU, only 6xx bus supported");
>>> +        exit(1);
>>> +    }
>>> +
>>> +    /* Set time-base frequency */
>>> +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
>>> +    qemu_register_reset(pegasos2_cpu_reset, cpu);
>>> +
>>> +    /* RAM */
>>> +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>>> +
>>> +    /* allocate and load firmware */
>>> +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
>>> +    if (!filename) {
>>> +        error_report("Could not find firmware '%s'", fwname);
>>> +        exit(1);
>>> +    }
>>> +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE,
>>> &error_fatal);
>>> +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
>>> +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL,
>>> NULL, 1,
>>> +                  PPC_ELF_MACHINE, 0, 0);
>>> +    if (sz <= 0) {
>>> +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
>>> +    }
>>> +    if (sz <= 0 || sz > PROM_SIZE) {
>>> +        error_report("Could not load firmware '%s'", filename);
>>> +        exit(1);
>>> +    }
>>> +    g_free(filename);
>>> +
>>> +    /* Marvell Discovery II system controller */
>>> +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
>>> +                        ((qemu_irq
>>> *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
>>
>> Indent off.
> 
> There's no other way to fit in the 80 chars line length limit in a
> sensible way. (Aligning to DEVICE( would be confusing as last arg
> belongs to sysbus_create_simple().)

You are right, I got confused by sysbus_create_simple() indeed.

> 
>> Otherwise:
>> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> Thanks, I'll do the other changes you've recommended.
> 
> Regards,
> BALATON Zoltan
David Gibson March 3, 2021, 12:21 a.m. UTC | #4
On Tue, Mar 02, 2021 at 10:13:19AM +0100, BALATON Zoltan wrote:
> On Tue, 2 Mar 2021, Philippe Mathieu-Daudé wrote:
> > On 2/25/21 8:47 PM, BALATON Zoltan wrote:
> > > Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
> > > a PowerPC board based on the Marvell MV64361 system controller and the
> > > VIA VT8231 integrated south bridge/superio chips. It can run Linux,
> > > AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
> > > image is needed to boot and only MorphOS has a video driver to produce
> > > graphics output. Linux could work too but distros that supported this
> > > machine don't include usual video drivers so those only run with
> > > serial console for now.
> > > 
> > > Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> > > ---
> > >  MAINTAINERS                             |  10 ++
> > >  default-configs/devices/ppc-softmmu.mak |   2 +
> > >  hw/ppc/Kconfig                          |  10 ++
> > >  hw/ppc/meson.build                      |   2 +
> > >  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
> > >  5 files changed, 168 insertions(+)
> > >  create mode 100644 hw/ppc/pegasos2.c
> > > 
> > > diff --git a/MAINTAINERS b/MAINTAINERS
> > > index 9b2aa18e1f..a023217702 100644
> > > --- a/MAINTAINERS
> > > +++ b/MAINTAINERS
> > > @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
> > >  F: pc-bios/u-boot-sam460ex-20100605.bin
> > >  F: roms/u-boot-sam460ex
> > > 
> > > +pegasos2
> > > +M: BALATON Zoltan <balaton@eik.bme.hu>
> > > +R: David Gibson <david@gibson.dropbear.id.au>
> > 
> > :)
> 
> He's also listed as reviewer for the sam460ex and I think as the PPC
> maintainer probably should be notified about changes that's why this is
> here. I guess he can complain or submit a patch later if he wants to be
> removed.

Including me as reviewer is fine for now.

> 
> > > +L: qemu-ppc@nongnu.org
> > > +S: Maintained
> > > +F: hw/ppc/pegasos2.c
> > > +F: hw/pci-host/mv64361.c
> > > +F: hw/pci-host/mv643xx.h
> > > +F: include/hw/pci-host/mv64361.h
> > > +
> > >  RISC-V Machines
> > >  ---------------
> > >  OpenTitan
> > > diff --git a/default-configs/devices/ppc-softmmu.mak b/default-configs/devices/ppc-softmmu.mak
> > > index 61b78b844d..4535993d8d 100644
> > > --- a/default-configs/devices/ppc-softmmu.mak
> > > +++ b/default-configs/devices/ppc-softmmu.mak
> > > @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
> > >  CONFIG_MAC_OLDWORLD=y
> > >  CONFIG_MAC_NEWWORLD=y
> > > 
> > > +CONFIG_PEGASOS2=y
> > > +
> > >  # For PReP
> > >  CONFIG_PREP=y
> > > diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
> > > index d11dc30509..98d8dd1a84 100644
> > > --- a/hw/ppc/Kconfig
> > > +++ b/hw/ppc/Kconfig
> > > @@ -68,6 +68,16 @@ config SAM460EX
> > >      select USB_OHCI
> > >      select FDT_PPC
> > > 
> > > +config PEGASOS2
> > > +    bool
> > > +    select MV64361
> > > +    select VT82C686
> > > +    select IDE_VIA
> > > +    select SMBUS_EEPROM
> > > +# These should come with VT82C686
> > > +    select APM
> > > +    select ACPI_X86
> > > +
> > >  config PREP
> > >      bool
> > >      imply PCI_DEVICES
> > > diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
> > > index 218631c883..86d6f379d1 100644
> > > --- a/hw/ppc/meson.build
> > > +++ b/hw/ppc/meson.build
> > > @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
> > >  ))
> > >  # PowerPC 440 Xilinx ML507 reference board.
> > >  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
> > > +# Pegasos2
> > > +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
> > > 
> > >  hw_arch += {'ppc': ppc_ss}
> > > diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
> > > new file mode 100644
> > > index 0000000000..427e884fbf
> > > --- /dev/null
> > > +++ b/hw/ppc/pegasos2.c
> > > @@ -0,0 +1,144 @@
> > > +/*
> > > + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
> > > + *
> > > + * Copyright (c) 2018-2020 BALATON Zoltan
> > 
> > 2018-2021
> 
> Not really. I've done this between Christmas of 2018 and 2020. This year
> were only changes for upstreaming and review comments so I preserved the
> dates to record when the actual code was written.

Fwiw, Red Hat's internal guidelines have the opinion that the years
don't matter that much and are usually out of date, so they suggest
simply "Copyright Red Hat." for contributions from us. IANAL.

> > > + *
> > > + * This work is licensed under the GNU GPL license version 2 or later.
> > > + *
> > > + */
> > > +
> > > +#include "qemu/osdep.h"
> > > +#include "qemu-common.h"
> > > +#include "qemu/units.h"
> > > +#include "qapi/error.h"
> > > +#include "hw/hw.h"
> > > +#include "hw/ppc/ppc.h"
> > > +#include "hw/sysbus.h"
> > > +#include "hw/pci/pci_host.h"
> > > +#include "hw/irq.h"
> > > +#include "hw/pci-host/mv64361.h"
> > > +#include "hw/isa/vt82c686.h"
> > > +#include "hw/ide/pci.h"
> > > +#include "hw/i2c/smbus_eeprom.h"
> > > +#include "hw/qdev-properties.h"
> > > +#include "sysemu/reset.h"
> > > +#include "hw/boards.h"
> > > +#include "hw/loader.h"
> > > +#include "hw/fw-path-provider.h"
> > > +#include "elf.h"
> > > +#include "qemu/log.h"
> > > +#include "qemu/error-report.h"
> > > +#include "sysemu/kvm.h"
> > > +#include "kvm_ppc.h"
> > > +#include "exec/address-spaces.h"
> > > +#include "trace.h"
> > > +#include "qemu/datadir.h"
> > > +#include "sysemu/device_tree.h"
> > > +
> > > +#define PROM_FILENAME "pegasos2.rom"
> > > +#define PROM_ADDR     0xfff00000
> > > +#define PROM_SIZE     0x80000
> > > +
> > > +#define BUS_FREQ 133333333
> > 
> > Can you rename as BUS_FREQ_HZ?
> > 
> > > +
> > > +static void pegasos2_cpu_reset(void *opaque)
> > > +{
> > > +    PowerPCCPU *cpu = opaque;
> > > +
> > > +    cpu_reset(CPU(cpu));
> > > +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
> > > +}
> > > +
> > > +static void pegasos2_init(MachineState *machine)
> > > +{
> > > +    PowerPCCPU *cpu = NULL;
> > > +    MemoryRegion *rom = g_new(MemoryRegion, 1);
> > > +    DeviceState *mv;
> > > +    PCIBus *pci_bus;
> > > +    PCIDevice *dev;
> > > +    I2CBus *i2c_bus;
> > > +    const char *fwname = machine->firmware ?: PROM_FILENAME;
> > > +    char *filename;
> > > +    int sz;
> > > +    uint8_t *spd_data;
> > > +
> > > +    /* init CPU */
> > > +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
> > > +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
> > > +        error_report("Incompatible CPU, only 6xx bus supported");
> > > +        exit(1);
> > > +    }
> > > +
> > > +    /* Set time-base frequency */
> > > +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
> > > +    qemu_register_reset(pegasos2_cpu_reset, cpu);
> > > +
> > > +    /* RAM */
> > > +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
> > > +
> > > +    /* allocate and load firmware */
> > > +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
> > > +    if (!filename) {
> > > +        error_report("Could not find firmware '%s'", fwname);
> > > +        exit(1);
> > > +    }
> > > +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
> > > +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
> > > +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
> > > +                  PPC_ELF_MACHINE, 0, 0);
> > > +    if (sz <= 0) {
> > > +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
> > > +    }
> > > +    if (sz <= 0 || sz > PROM_SIZE) {
> > > +        error_report("Could not load firmware '%s'", filename);
> > > +        exit(1);
> > > +    }
> > > +    g_free(filename);
> > > +
> > > +    /* Marvell Discovery II system controller */
> > > +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
> > > +                        ((qemu_irq *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
> > 
> > Indent off.
> 
> There's no other way to fit in the 80 chars line length limit in a sensible
> way. (Aligning to DEVICE( would be confusing as last arg belongs to
> sysbus_create_simple().)

You could declare a temporary variable with the complex irq_inputs expression.

> 
> > Otherwise:
> > Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> 
> Thanks, I'll do the other changes you've recommended.
> 
> Regards,
> BALATON Zoltan
BALATON Zoltan March 4, 2021, 8:31 p.m. UTC | #5
On Wed, 3 Mar 2021, David Gibson wrote:
> On Tue, Mar 02, 2021 at 10:13:19AM +0100, BALATON Zoltan wrote:
>> On Tue, 2 Mar 2021, Philippe Mathieu-Daudé wrote:
>>> On 2/25/21 8:47 PM, BALATON Zoltan wrote:
>>>> Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
>>>> a PowerPC board based on the Marvell MV64361 system controller and the
>>>> VIA VT8231 integrated south bridge/superio chips. It can run Linux,
>>>> AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
>>>> image is needed to boot and only MorphOS has a video driver to produce
>>>> graphics output. Linux could work too but distros that supported this
>>>> machine don't include usual video drivers so those only run with
>>>> serial console for now.
>>>>
>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>> ---
>>>>  MAINTAINERS                             |  10 ++
>>>>  default-configs/devices/ppc-softmmu.mak |   2 +
>>>>  hw/ppc/Kconfig                          |  10 ++
>>>>  hw/ppc/meson.build                      |   2 +
>>>>  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
>>>>  5 files changed, 168 insertions(+)
>>>>  create mode 100644 hw/ppc/pegasos2.c
>>>>
>>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>>> index 9b2aa18e1f..a023217702 100644
>>>> --- a/MAINTAINERS
>>>> +++ b/MAINTAINERS
>>>> @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
>>>>  F: pc-bios/u-boot-sam460ex-20100605.bin
>>>>  F: roms/u-boot-sam460ex
>>>>
>>>> +pegasos2
>>>> +M: BALATON Zoltan <balaton@eik.bme.hu>
>>>> +R: David Gibson <david@gibson.dropbear.id.au>
>>>
>>> :)
>>
>> He's also listed as reviewer for the sam460ex and I think as the PPC
>> maintainer probably should be notified about changes that's why this is
>> here. I guess he can complain or submit a patch later if he wants to be
>> removed.
>
> Including me as reviewer is fine for now.
>
>>
>>>> +L: qemu-ppc@nongnu.org
>>>> +S: Maintained
>>>> +F: hw/ppc/pegasos2.c
>>>> +F: hw/pci-host/mv64361.c
>>>> +F: hw/pci-host/mv643xx.h
>>>> +F: include/hw/pci-host/mv64361.h
>>>> +
>>>>  RISC-V Machines
>>>>  ---------------
>>>>  OpenTitan
>>>> diff --git a/default-configs/devices/ppc-softmmu.mak b/default-configs/devices/ppc-softmmu.mak
>>>> index 61b78b844d..4535993d8d 100644
>>>> --- a/default-configs/devices/ppc-softmmu.mak
>>>> +++ b/default-configs/devices/ppc-softmmu.mak
>>>> @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
>>>>  CONFIG_MAC_OLDWORLD=y
>>>>  CONFIG_MAC_NEWWORLD=y
>>>>
>>>> +CONFIG_PEGASOS2=y
>>>> +
>>>>  # For PReP
>>>>  CONFIG_PREP=y
>>>> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
>>>> index d11dc30509..98d8dd1a84 100644
>>>> --- a/hw/ppc/Kconfig
>>>> +++ b/hw/ppc/Kconfig
>>>> @@ -68,6 +68,16 @@ config SAM460EX
>>>>      select USB_OHCI
>>>>      select FDT_PPC
>>>>
>>>> +config PEGASOS2
>>>> +    bool
>>>> +    select MV64361
>>>> +    select VT82C686
>>>> +    select IDE_VIA
>>>> +    select SMBUS_EEPROM
>>>> +# These should come with VT82C686
>>>> +    select APM
>>>> +    select ACPI_X86
>>>> +
>>>>  config PREP
>>>>      bool
>>>>      imply PCI_DEVICES
>>>> diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
>>>> index 218631c883..86d6f379d1 100644
>>>> --- a/hw/ppc/meson.build
>>>> +++ b/hw/ppc/meson.build
>>>> @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
>>>>  ))
>>>>  # PowerPC 440 Xilinx ML507 reference board.
>>>>  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
>>>> +# Pegasos2
>>>> +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
>>>>
>>>>  hw_arch += {'ppc': ppc_ss}
>>>> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
>>>> new file mode 100644
>>>> index 0000000000..427e884fbf
>>>> --- /dev/null
>>>> +++ b/hw/ppc/pegasos2.c
>>>> @@ -0,0 +1,144 @@
>>>> +/*
>>>> + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
>>>> + *
>>>> + * Copyright (c) 2018-2020 BALATON Zoltan
>>>
>>> 2018-2021
>>
>> Not really. I've done this between Christmas of 2018 and 2020. This year
>> were only changes for upstreaming and review comments so I preserved the
>> dates to record when the actual code was written.
>
> Fwiw, Red Hat's internal guidelines have the opinion that the years
> don't matter that much and are usually out of date, so they suggest
> simply "Copyright Red Hat." for contributions from us. IANAL.

I think including the year originally comes from that in some 
jurisdictions there is or was a limit for how long copyright is reserved 
starting from this date and then each modification may restart that period 
but I read somewhere that it's not any more relevant. Anyway, I've just 
added the year to record when did I do it and the whole copyright message 
is mostly to state who's to blame for this as it's under GPL anyway so 
copyright does not matter much and the commit log also has this info it's 
just easier to find in the header comment.

>>>> + *
>>>> + * This work is licensed under the GNU GPL license version 2 or later.
>>>> + *
>>>> + */
>>>> +
>>>> +#include "qemu/osdep.h"
>>>> +#include "qemu-common.h"
>>>> +#include "qemu/units.h"
>>>> +#include "qapi/error.h"
>>>> +#include "hw/hw.h"
>>>> +#include "hw/ppc/ppc.h"
>>>> +#include "hw/sysbus.h"
>>>> +#include "hw/pci/pci_host.h"
>>>> +#include "hw/irq.h"
>>>> +#include "hw/pci-host/mv64361.h"
>>>> +#include "hw/isa/vt82c686.h"
>>>> +#include "hw/ide/pci.h"
>>>> +#include "hw/i2c/smbus_eeprom.h"
>>>> +#include "hw/qdev-properties.h"
>>>> +#include "sysemu/reset.h"
>>>> +#include "hw/boards.h"
>>>> +#include "hw/loader.h"
>>>> +#include "hw/fw-path-provider.h"
>>>> +#include "elf.h"
>>>> +#include "qemu/log.h"
>>>> +#include "qemu/error-report.h"
>>>> +#include "sysemu/kvm.h"
>>>> +#include "kvm_ppc.h"
>>>> +#include "exec/address-spaces.h"
>>>> +#include "trace.h"
>>>> +#include "qemu/datadir.h"
>>>> +#include "sysemu/device_tree.h"
>>>> +
>>>> +#define PROM_FILENAME "pegasos2.rom"
>>>> +#define PROM_ADDR     0xfff00000
>>>> +#define PROM_SIZE     0x80000
>>>> +
>>>> +#define BUS_FREQ 133333333
>>>
>>> Can you rename as BUS_FREQ_HZ?
>>>
>>>> +
>>>> +static void pegasos2_cpu_reset(void *opaque)
>>>> +{
>>>> +    PowerPCCPU *cpu = opaque;
>>>> +
>>>> +    cpu_reset(CPU(cpu));
>>>> +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
>>>> +}
>>>> +
>>>> +static void pegasos2_init(MachineState *machine)
>>>> +{
>>>> +    PowerPCCPU *cpu = NULL;
>>>> +    MemoryRegion *rom = g_new(MemoryRegion, 1);
>>>> +    DeviceState *mv;
>>>> +    PCIBus *pci_bus;
>>>> +    PCIDevice *dev;
>>>> +    I2CBus *i2c_bus;
>>>> +    const char *fwname = machine->firmware ?: PROM_FILENAME;
>>>> +    char *filename;
>>>> +    int sz;
>>>> +    uint8_t *spd_data;
>>>> +
>>>> +    /* init CPU */
>>>> +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
>>>> +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
>>>> +        error_report("Incompatible CPU, only 6xx bus supported");
>>>> +        exit(1);
>>>> +    }
>>>> +
>>>> +    /* Set time-base frequency */
>>>> +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
>>>> +    qemu_register_reset(pegasos2_cpu_reset, cpu);
>>>> +
>>>> +    /* RAM */
>>>> +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>>>> +
>>>> +    /* allocate and load firmware */
>>>> +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
>>>> +    if (!filename) {
>>>> +        error_report("Could not find firmware '%s'", fwname);
>>>> +        exit(1);
>>>> +    }
>>>> +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
>>>> +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
>>>> +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
>>>> +                  PPC_ELF_MACHINE, 0, 0);
>>>> +    if (sz <= 0) {
>>>> +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
>>>> +    }
>>>> +    if (sz <= 0 || sz > PROM_SIZE) {
>>>> +        error_report("Could not load firmware '%s'", filename);
>>>> +        exit(1);
>>>> +    }
>>>> +    g_free(filename);
>>>> +
>>>> +    /* Marvell Discovery II system controller */
>>>> +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
>>>> +                        ((qemu_irq *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
>>>
>>> Indent off.
>>
>> There's no other way to fit in the 80 chars line length limit in a sensible
>> way. (Aligning to DEVICE( would be confusing as last arg belongs to
>> sysbus_create_simple().)
>
> You could declare a temporary variable with the complex irq_inputs expression.

Should I submit a new version with that change or you just noted it as a 
possibility? I've also thought about that but I think it's not worth it if 
it's only used at this one place. This may also be simplified in the 
future if PPC interrupts are converted to gpios as Peter suggested.

Regards,
BALATON Zoltan
BALATON Zoltan March 8, 2021, 11:45 a.m. UTC | #6
On Thu, 4 Mar 2021, BALATON Zoltan wrote:
> On Wed, 3 Mar 2021, David Gibson wrote:
>> On Tue, Mar 02, 2021 at 10:13:19AM +0100, BALATON Zoltan wrote:
>>> On Tue, 2 Mar 2021, Philippe Mathieu-Daudé wrote:
>>>> On 2/25/21 8:47 PM, BALATON Zoltan wrote:
>>>>> Add new machine called pegasos2 emulating the Genesi/bPlan Pegasos II,
>>>>> a PowerPC board based on the Marvell MV64361 system controller and the
>>>>> VIA VT8231 integrated south bridge/superio chips. It can run Linux,
>>>>> AmigaOS and a wide range of MorphOS versions. Currently a firmware ROM
>>>>> image is needed to boot and only MorphOS has a video driver to produce
>>>>> graphics output. Linux could work too but distros that supported this
>>>>> machine don't include usual video drivers so those only run with
>>>>> serial console for now.
>>>>> 
>>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>>> ---
>>>>>  MAINTAINERS                             |  10 ++
>>>>>  default-configs/devices/ppc-softmmu.mak |   2 +
>>>>>  hw/ppc/Kconfig                          |  10 ++
>>>>>  hw/ppc/meson.build                      |   2 +
>>>>>  hw/ppc/pegasos2.c                       | 144 ++++++++++++++++++++++++
>>>>>  5 files changed, 168 insertions(+)
>>>>>  create mode 100644 hw/ppc/pegasos2.c
>>>>> 
>>>>> diff --git a/MAINTAINERS b/MAINTAINERS
>>>>> index 9b2aa18e1f..a023217702 100644
>>>>> --- a/MAINTAINERS
>>>>> +++ b/MAINTAINERS
>>>>> @@ -1345,6 +1345,16 @@ F: pc-bios/canyonlands.dt[sb]
>>>>>  F: pc-bios/u-boot-sam460ex-20100605.bin
>>>>>  F: roms/u-boot-sam460ex
>>>>> 
>>>>> +pegasos2
>>>>> +M: BALATON Zoltan <balaton@eik.bme.hu>
>>>>> +R: David Gibson <david@gibson.dropbear.id.au>
>>>> 
>>>> :)
>>> 
>>> He's also listed as reviewer for the sam460ex and I think as the PPC
>>> maintainer probably should be notified about changes that's why this is
>>> here. I guess he can complain or submit a patch later if he wants to be
>>> removed.
>> 
>> Including me as reviewer is fine for now.
>> 
>>> 
>>>>> +L: qemu-ppc@nongnu.org
>>>>> +S: Maintained
>>>>> +F: hw/ppc/pegasos2.c
>>>>> +F: hw/pci-host/mv64361.c
>>>>> +F: hw/pci-host/mv643xx.h
>>>>> +F: include/hw/pci-host/mv64361.h
>>>>> +
>>>>>  RISC-V Machines
>>>>>  ---------------
>>>>>  OpenTitan
>>>>> diff --git a/default-configs/devices/ppc-softmmu.mak 
>>>>> b/default-configs/devices/ppc-softmmu.mak
>>>>> index 61b78b844d..4535993d8d 100644
>>>>> --- a/default-configs/devices/ppc-softmmu.mak
>>>>> +++ b/default-configs/devices/ppc-softmmu.mak
>>>>> @@ -14,5 +14,7 @@ CONFIG_SAM460EX=y
>>>>>  CONFIG_MAC_OLDWORLD=y
>>>>>  CONFIG_MAC_NEWWORLD=y
>>>>> 
>>>>> +CONFIG_PEGASOS2=y
>>>>> +
>>>>>  # For PReP
>>>>>  CONFIG_PREP=y
>>>>> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
>>>>> index d11dc30509..98d8dd1a84 100644
>>>>> --- a/hw/ppc/Kconfig
>>>>> +++ b/hw/ppc/Kconfig
>>>>> @@ -68,6 +68,16 @@ config SAM460EX
>>>>>      select USB_OHCI
>>>>>      select FDT_PPC
>>>>> 
>>>>> +config PEGASOS2
>>>>> +    bool
>>>>> +    select MV64361
>>>>> +    select VT82C686
>>>>> +    select IDE_VIA
>>>>> +    select SMBUS_EEPROM
>>>>> +# These should come with VT82C686
>>>>> +    select APM
>>>>> +    select ACPI_X86
>>>>> +
>>>>>  config PREP
>>>>>      bool
>>>>>      imply PCI_DEVICES
>>>>> diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
>>>>> index 218631c883..86d6f379d1 100644
>>>>> --- a/hw/ppc/meson.build
>>>>> +++ b/hw/ppc/meson.build
>>>>> @@ -78,5 +78,7 @@ ppc_ss.add(when: 'CONFIG_E500', if_true: files(
>>>>>  ))
>>>>>  # PowerPC 440 Xilinx ML507 reference board.
>>>>>  ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
>>>>> +# Pegasos2
>>>>> +ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
>>>>>
>>>>>  hw_arch += {'ppc': ppc_ss}
>>>>> diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
>>>>> new file mode 100644
>>>>> index 0000000000..427e884fbf
>>>>> --- /dev/null
>>>>> +++ b/hw/ppc/pegasos2.c
>>>>> @@ -0,0 +1,144 @@
>>>>> +/*
>>>>> + * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
>>>>> + *
>>>>> + * Copyright (c) 2018-2020 BALATON Zoltan
>>>> 
>>>> 2018-2021
>>> 
>>> Not really. I've done this between Christmas of 2018 and 2020. This year
>>> were only changes for upstreaming and review comments so I preserved the
>>> dates to record when the actual code was written.
>> 
>> Fwiw, Red Hat's internal guidelines have the opinion that the years
>> don't matter that much and are usually out of date, so they suggest
>> simply "Copyright Red Hat." for contributions from us. IANAL.
>
> I think including the year originally comes from that in some jurisdictions 
> there is or was a limit for how long copyright is reserved starting from this 
> date and then each modification may restart that period but I read somewhere 
> that it's not any more relevant. Anyway, I've just added the year to record 
> when did I do it and the whole copyright message is mostly to state who's to 
> blame for this as it's under GPL anyway so copyright does not matter much and 
> the commit log also has this info it's just easier to find in the header 
> comment.
>
>>>>> + *
>>>>> + * This work is licensed under the GNU GPL license version 2 or later.
>>>>> + *
>>>>> + */
>>>>> +
>>>>> +#include "qemu/osdep.h"
>>>>> +#include "qemu-common.h"
>>>>> +#include "qemu/units.h"
>>>>> +#include "qapi/error.h"
>>>>> +#include "hw/hw.h"
>>>>> +#include "hw/ppc/ppc.h"
>>>>> +#include "hw/sysbus.h"
>>>>> +#include "hw/pci/pci_host.h"
>>>>> +#include "hw/irq.h"
>>>>> +#include "hw/pci-host/mv64361.h"
>>>>> +#include "hw/isa/vt82c686.h"
>>>>> +#include "hw/ide/pci.h"
>>>>> +#include "hw/i2c/smbus_eeprom.h"
>>>>> +#include "hw/qdev-properties.h"
>>>>> +#include "sysemu/reset.h"
>>>>> +#include "hw/boards.h"
>>>>> +#include "hw/loader.h"
>>>>> +#include "hw/fw-path-provider.h"
>>>>> +#include "elf.h"
>>>>> +#include "qemu/log.h"
>>>>> +#include "qemu/error-report.h"
>>>>> +#include "sysemu/kvm.h"
>>>>> +#include "kvm_ppc.h"
>>>>> +#include "exec/address-spaces.h"
>>>>> +#include "trace.h"
>>>>> +#include "qemu/datadir.h"
>>>>> +#include "sysemu/device_tree.h"
>>>>> +
>>>>> +#define PROM_FILENAME "pegasos2.rom"
>>>>> +#define PROM_ADDR     0xfff00000
>>>>> +#define PROM_SIZE     0x80000
>>>>> +
>>>>> +#define BUS_FREQ 133333333
>>>> 
>>>> Can you rename as BUS_FREQ_HZ?
>>>> 
>>>>> +
>>>>> +static void pegasos2_cpu_reset(void *opaque)
>>>>> +{
>>>>> +    PowerPCCPU *cpu = opaque;
>>>>> +
>>>>> +    cpu_reset(CPU(cpu));
>>>>> +    cpu->env.spr[SPR_HID1] = 7ULL << 28;
>>>>> +}
>>>>> +
>>>>> +static void pegasos2_init(MachineState *machine)
>>>>> +{
>>>>> +    PowerPCCPU *cpu = NULL;
>>>>> +    MemoryRegion *rom = g_new(MemoryRegion, 1);
>>>>> +    DeviceState *mv;
>>>>> +    PCIBus *pci_bus;
>>>>> +    PCIDevice *dev;
>>>>> +    I2CBus *i2c_bus;
>>>>> +    const char *fwname = machine->firmware ?: PROM_FILENAME;
>>>>> +    char *filename;
>>>>> +    int sz;
>>>>> +    uint8_t *spd_data;
>>>>> +
>>>>> +    /* init CPU */
>>>>> +    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
>>>>> +    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
>>>>> +        error_report("Incompatible CPU, only 6xx bus supported");
>>>>> +        exit(1);
>>>>> +    }
>>>>> +
>>>>> +    /* Set time-base frequency */
>>>>> +    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
>>>>> +    qemu_register_reset(pegasos2_cpu_reset, cpu);
>>>>> +
>>>>> +    /* RAM */
>>>>> +    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
>>>>> +
>>>>> +    /* allocate and load firmware */
>>>>> +    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
>>>>> +    if (!filename) {
>>>>> +        error_report("Could not find firmware '%s'", fwname);
>>>>> +        exit(1);
>>>>> +    }
>>>>> +    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, 
>>>>> &error_fatal);
>>>>> +    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
>>>>> +    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
>>>>> 1,
>>>>> +                  PPC_ELF_MACHINE, 0, 0);
>>>>> +    if (sz <= 0) {
>>>>> +        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
>>>>> +    }
>>>>> +    if (sz <= 0 || sz > PROM_SIZE) {
>>>>> +        error_report("Could not load firmware '%s'", filename);
>>>>> +        exit(1);
>>>>> +    }
>>>>> +    g_free(filename);
>>>>> +
>>>>> +    /* Marvell Discovery II system controller */
>>>>> +    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
>>>>> +                        ((qemu_irq 
>>>>> *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
>>>> 
>>>> Indent off.
>>> 
>>> There's no other way to fit in the 80 chars line length limit in a 
>>> sensible
>>> way. (Aligning to DEVICE( would be confusing as last arg belongs to
>>> sysbus_create_simple().)
>> 
>> You could declare a temporary variable with the complex irq_inputs 
>> expression.
>
> Should I submit a new version with that change or you just noted it as a 
> possibility? I've also thought about that but I think it's not worth it if 
> it's only used at this one place. This may also be simplified in the future 
> if PPC interrupts are converted to gpios as Peter suggested.

Ping? Is there anything that needs a respin that you're waiting for or you 
just did not yet have the time yet to merge this series?

Regards,
BALATON Zoltan
Philippe Mathieu-Daudé March 8, 2021, 1:43 p.m. UTC | #7
On 3/8/21 12:45 PM, BALATON Zoltan wrote:
> Ping? Is there anything that needs a respin that you're waiting for or
> you just did not yet have the time yet to merge this series?

I asked you to split patch 4:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg786871.html

If you can get Paolo to Ack patch #1 and split patch 4, I'm
OK to queue the VIA patches via the MIPS tree, letting this
single one for the PPC tree.

Regards,

Phil.
BALATON Zoltan March 8, 2021, 4:06 p.m. UTC | #8
On Mon, 8 Mar 2021, Philippe Mathieu-Daudé wrote:
> On 3/8/21 12:45 PM, BALATON Zoltan wrote:
>> Ping? Is there anything that needs a respin that you're waiting for or
>> you just did not yet have the time yet to merge this series?
>
> I asked you to split patch 4:
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg786871.html

I did that in v5 and you've reviewed it I think, (Just replied to the ping 
message sent for v4 but I've also sent a v5 meanwhile and this ping was 
meant for that, sorry for the confusion).

> If you can get Paolo to Ack patch #1 and split patch 4, I'm

He was cc'd on all this and haven't answered so far so I guess he doesn't 
care about it.

> OK to queue the VIA patches via the MIPS tree, letting this
> single one for the PPC tree.

There's also the MV64361 patch that's only used by pegasos2 so may be PPC 
specific and the other VT8231 patches are useless without these last two. 
I hope David will be able to take the series so I'd wait a bit for his 
answer on what he prefers.

Thank you,
BALATON Zoltan
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 9b2aa18e1f..a023217702 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1345,6 +1345,16 @@  F: pc-bios/canyonlands.dt[sb]
 F: pc-bios/u-boot-sam460ex-20100605.bin
 F: roms/u-boot-sam460ex
 
+pegasos2
+M: BALATON Zoltan <balaton@eik.bme.hu>
+R: David Gibson <david@gibson.dropbear.id.au>
+L: qemu-ppc@nongnu.org
+S: Maintained
+F: hw/ppc/pegasos2.c
+F: hw/pci-host/mv64361.c
+F: hw/pci-host/mv643xx.h
+F: include/hw/pci-host/mv64361.h
+
 RISC-V Machines
 ---------------
 OpenTitan
diff --git a/default-configs/devices/ppc-softmmu.mak b/default-configs/devices/ppc-softmmu.mak
index 61b78b844d..4535993d8d 100644
--- a/default-configs/devices/ppc-softmmu.mak
+++ b/default-configs/devices/ppc-softmmu.mak
@@ -14,5 +14,7 @@  CONFIG_SAM460EX=y
 CONFIG_MAC_OLDWORLD=y
 CONFIG_MAC_NEWWORLD=y
 
+CONFIG_PEGASOS2=y
+
 # For PReP
 CONFIG_PREP=y
diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig
index d11dc30509..98d8dd1a84 100644
--- a/hw/ppc/Kconfig
+++ b/hw/ppc/Kconfig
@@ -68,6 +68,16 @@  config SAM460EX
     select USB_OHCI
     select FDT_PPC
 
+config PEGASOS2
+    bool
+    select MV64361
+    select VT82C686
+    select IDE_VIA
+    select SMBUS_EEPROM
+# These should come with VT82C686
+    select APM
+    select ACPI_X86
+
 config PREP
     bool
     imply PCI_DEVICES
diff --git a/hw/ppc/meson.build b/hw/ppc/meson.build
index 218631c883..86d6f379d1 100644
--- a/hw/ppc/meson.build
+++ b/hw/ppc/meson.build
@@ -78,5 +78,7 @@  ppc_ss.add(when: 'CONFIG_E500', if_true: files(
 ))
 # PowerPC 440 Xilinx ML507 reference board.
 ppc_ss.add(when: 'CONFIG_VIRTEX', if_true: files('virtex_ml507.c'))
+# Pegasos2
+ppc_ss.add(when: 'CONFIG_PEGASOS2', if_true: files('pegasos2.c'))
 
 hw_arch += {'ppc': ppc_ss}
diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c
new file mode 100644
index 0000000000..427e884fbf
--- /dev/null
+++ b/hw/ppc/pegasos2.c
@@ -0,0 +1,144 @@ 
+/*
+ * QEMU PowerPC CHRP (Genesi/bPlan Pegasos II) hardware System Emulator
+ *
+ * Copyright (c) 2018-2020 BALATON Zoltan
+ *
+ * This work is licensed under the GNU GPL license version 2 or later.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "qemu/units.h"
+#include "qapi/error.h"
+#include "hw/hw.h"
+#include "hw/ppc/ppc.h"
+#include "hw/sysbus.h"
+#include "hw/pci/pci_host.h"
+#include "hw/irq.h"
+#include "hw/pci-host/mv64361.h"
+#include "hw/isa/vt82c686.h"
+#include "hw/ide/pci.h"
+#include "hw/i2c/smbus_eeprom.h"
+#include "hw/qdev-properties.h"
+#include "sysemu/reset.h"
+#include "hw/boards.h"
+#include "hw/loader.h"
+#include "hw/fw-path-provider.h"
+#include "elf.h"
+#include "qemu/log.h"
+#include "qemu/error-report.h"
+#include "sysemu/kvm.h"
+#include "kvm_ppc.h"
+#include "exec/address-spaces.h"
+#include "trace.h"
+#include "qemu/datadir.h"
+#include "sysemu/device_tree.h"
+
+#define PROM_FILENAME "pegasos2.rom"
+#define PROM_ADDR     0xfff00000
+#define PROM_SIZE     0x80000
+
+#define BUS_FREQ 133333333
+
+static void pegasos2_cpu_reset(void *opaque)
+{
+    PowerPCCPU *cpu = opaque;
+
+    cpu_reset(CPU(cpu));
+    cpu->env.spr[SPR_HID1] = 7ULL << 28;
+}
+
+static void pegasos2_init(MachineState *machine)
+{
+    PowerPCCPU *cpu = NULL;
+    MemoryRegion *rom = g_new(MemoryRegion, 1);
+    DeviceState *mv;
+    PCIBus *pci_bus;
+    PCIDevice *dev;
+    I2CBus *i2c_bus;
+    const char *fwname = machine->firmware ?: PROM_FILENAME;
+    char *filename;
+    int sz;
+    uint8_t *spd_data;
+
+    /* init CPU */
+    cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
+    if (PPC_INPUT(&cpu->env) != PPC_FLAGS_INPUT_6xx) {
+        error_report("Incompatible CPU, only 6xx bus supported");
+        exit(1);
+    }
+
+    /* Set time-base frequency */
+    cpu_ppc_tb_init(&cpu->env, BUS_FREQ / 4);
+    qemu_register_reset(pegasos2_cpu_reset, cpu);
+
+    /* RAM */
+    memory_region_add_subregion(get_system_memory(), 0, machine->ram);
+
+    /* allocate and load firmware */
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, fwname);
+    if (!filename) {
+        error_report("Could not find firmware '%s'", fwname);
+        exit(1);
+    }
+    memory_region_init_rom(rom, NULL, "pegasos2.rom", PROM_SIZE, &error_fatal);
+    memory_region_add_subregion(get_system_memory(), PROM_ADDR, rom);
+    sz = load_elf(filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1,
+                  PPC_ELF_MACHINE, 0, 0);
+    if (sz <= 0) {
+        sz = load_image_targphys(filename, PROM_ADDR, PROM_SIZE);
+    }
+    if (sz <= 0 || sz > PROM_SIZE) {
+        error_report("Could not load firmware '%s'", filename);
+        exit(1);
+    }
+    g_free(filename);
+
+    /* Marvell Discovery II system controller */
+    mv = DEVICE(sysbus_create_simple(TYPE_MV64361, -1,
+                        ((qemu_irq *)cpu->env.irq_inputs)[PPC6xx_INPUT_INT]));
+    pci_bus = mv64361_get_pci_bus(mv, 1);
+
+    /* VIA VT8231 South Bridge (multifunction PCI device) */
+    /* VT8231 function 0: PCI-to-ISA Bridge */
+    dev = pci_create_simple_multifunction(pci_bus, PCI_DEVFN(12, 0), true,
+                                          TYPE_VT8231_ISA);
+    qdev_connect_gpio_out(DEVICE(dev), 0,
+                          qdev_get_gpio_in_named(mv, "gpp", 31));
+
+    /* VT8231 function 1: IDE Controller */
+    dev = pci_create_simple(pci_bus, PCI_DEVFN(12, 1), "via-ide");
+    pci_ide_create_devs(dev);
+
+    /* VT8231 function 2-3: USB Ports */
+    pci_create_simple(pci_bus, PCI_DEVFN(12, 2), "vt82c686b-usb-uhci");
+    pci_create_simple(pci_bus, PCI_DEVFN(12, 3), "vt82c686b-usb-uhci");
+
+    /* VT8231 function 4: Power Management Controller */
+    dev = pci_create_simple(pci_bus, PCI_DEVFN(12, 4), TYPE_VT8231_PM);
+    i2c_bus = I2C_BUS(qdev_get_child_bus(DEVICE(dev), "i2c"));
+    spd_data = spd_data_generate(DDR, machine->ram_size);
+    smbus_eeprom_init_one(i2c_bus, 0x57, spd_data);
+
+    /* VT8231 function 5-6: AC97 Audio & Modem */
+    pci_create_simple(pci_bus, PCI_DEVFN(12, 5), TYPE_VIA_AC97);
+    pci_create_simple(pci_bus, PCI_DEVFN(12, 6), TYPE_VIA_MC97);
+
+    /* other PC hardware */
+    pci_vga_init(pci_bus);
+}
+
+static void pegasos2_machine(MachineClass *mc)
+{
+    mc->desc = "Genesi/bPlan Pegasos II";
+    mc->init = pegasos2_init;
+    mc->block_default_type = IF_IDE;
+    mc->default_boot_order = "cd";
+    mc->default_display = "std";
+    mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("7400_v2.9");
+    mc->default_ram_id = "pegasos2.ram";
+    mc->default_ram_size = 512 * MiB;
+}
+
+DEFINE_MACHINE("pegasos2", pegasos2_machine)