On Wed, 16 Jun 2021, Alexey Kardashevskiy wrote: > On 6/15/21 19:44, BALATON Zoltan wrote: >> On Tue, 15 Jun 2021, Alexey Kardashevskiy wrote: >>> On 6/7/21 01:46, BALATON Zoltan wrote: >>>> The pegasos2 board comes with an Open Firmware compliant ROM based on >>>> SmartFirmware but it has some changes that are not open source >>>> therefore the ROM binary cannot be included in QEMU. Guests running on >>>> the board however depend on services provided by the firmware. The >>>> Virtual Open Firmware recently added to QEMU imlements a minimal set >>>> of these services to allow some guests to boot without the original >>>> firmware. This patch adds VOF as the default firmware for pegasos2 >>>> which allows booting Linux and MorphOS via -kernel option while a ROM >>>> image can still be used with -bios for guests that don't run with VOF. >>>> >>>> Signed-off-by: BALATON Zoltan >>>> --- >>>>   hw/ppc/Kconfig    |   1 + >>>>   hw/ppc/pegasos2.c | 622 +++++++++++++++++++++++++++++++++++++++++++++- >>>>   2 files changed, 621 insertions(+), 2 deletions(-) >>>> >>>> diff --git a/hw/ppc/Kconfig b/hw/ppc/Kconfig >>>> index b895720b28..0eb48128fe 100644 >>>> --- a/hw/ppc/Kconfig >>>> +++ b/hw/ppc/Kconfig >>>> @@ -75,6 +75,7 @@ config PEGASOS2 >>>>       select VT82C686 >>>>       select IDE_VIA >>>>       select SMBUS_EEPROM >>>> +    select VOF >>>>   # This should come with VT82C686 >>>>       select ACPI_X86 >>>>   diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c >>>> index 07971175c9..91e5fa8fbe 100644 >>>> --- a/hw/ppc/pegasos2.c >>>> +++ b/hw/ppc/pegasos2.c >> [...] >>>> +static void add_pci_device(PCIBus *bus, PCIDevice *d, void *opaque) >>>> +{ >>>> +    FDTInfo *fi = opaque; >>>> +    GString *node = g_string_new(NULL); >>>> +    uint32_t cells[(PCI_NUM_REGIONS + 1) * 5]; >>>> +    int i, j; >>>> +    const char *name = NULL; >>>> +    g_autofree const gchar *pn = g_strdup_printf("pci%x,%x", >>>> + pci_get_word(&d->config[PCI_VENDOR_ID]), >>>> + pci_get_word(&d->config[PCI_DEVICE_ID])); >>>> + >>>> +    for (i = 0; device_map[i].id; i++) { >>>> +        if (!strcmp(pn, device_map[i].id)) { >>>> +            name = device_map[i].name; >>>> +            break; >>>> +        } >>>> +    } >>>> +    g_string_printf(node, "%s/%s@%x", fi->path, (name ?: pn), >>>> +                    PCI_SLOT(d->devfn)); >>>> +    if (PCI_FUNC(d->devfn)) { >>>> +        g_string_append_printf(node, ",%x", PCI_FUNC(d->devfn)); >>>> +    } >>>> + >>>> +    qemu_fdt_add_subnode(fi->fdt, node->str); >>>> +    if (device_map[i].dtf) { >>>> +        FDTInfo cfi = { fi->fdt, node->str }; >>>> +        device_map[i].dtf(bus, d, &cfi); >>>> +    } >>>> +    cells[0] = cpu_to_be32(d->devfn << 8); >>>> +    cells[1] = 0; >>>> +    cells[2] = 0; >>>> +    cells[3] = 0; >>>> +    cells[4] = 0; >>>> +    j = 5; >>>> +    for (i = 0; i < PCI_NUM_REGIONS; i++) { >>>> +        if (!d->io_regions[i].size) { >>>> +            continue; >>>> +        } >>>> +        cells[j] = cpu_to_be32(d->devfn << 8 | (PCI_BASE_ADDRESS_0 + i * >>>> 4)); >>>> +        if (d->io_regions[i].type & PCI_BASE_ADDRESS_SPACE_IO) { >>>> +            cells[j] |= cpu_to_be32(1 << 24); >>>> +        } else { >>>> +            cells[j] |= cpu_to_be32(2 << 24); >>>> +            if (d->io_regions[i].type & PCI_BASE_ADDRESS_MEM_PREFETCH) { >>>> +                cells[j] |= cpu_to_be32(4 << 28); >>>> +            } >>>> +        } >>>> +        cells[j + 1] = 0; >>>> +        cells[j + 2] = 0; >>>> +        cells[j + 3] = cpu_to_be32(d->io_regions[i].size >> 32); >>>> +        cells[j + 4] = cpu_to_be32(d->io_regions[i].size); >>>> +        j += 5; >>>> +    } >>> >>> >>> btw I was wondering if Linux on pegasos2 could assign resources when >>> /chosen/linux,pci-probe-only is in the FDT, could not it? Or the serial >>> device does not probe and Linux does not boot? >> >> Linux probes PCI devices by itself but MorphOS relies on the device tree >> entries so I need at least the reg properties for that then it will map the >> BARs but I think it won't scan the bus otherwise. You still seem to add PCI >> devices in spapr too, at least I think I've got the idea for this function >> above from there. > > > Linux does not scan, this is why we are adding devices in the FDT for pseries > (and likely so should you) but Linux does reassign resources if something is > wrong. > > Does MorphOS boot with this patchset? If it does not, and Linux reassigns > resources, we are probably better off with a minimalist approach and skip > resource assignment. MorphOS and Linux boot with this and I don't understand what you mean by resource assingment. I'm not setting BARs just adding info about them in the reg property but the address is 0, it's still the guest OS (Linux or MorphOS) that maps these where it wants. (The board firmware does map some devices such as USB or IDE it uses itself but fortunately no guest depends on that and they enable devices if they aren't yet enabled.) Regards, BALATON Zoltan