[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/2] hw/usb/hcd-xhci-pci: Make PCI device more configurabl
From: |
Nicholas Piggin |
Subject: |
Re: [PATCH v2 1/2] hw/usb/hcd-xhci-pci: Make PCI device more configurable |
Date: |
Thu, 19 Dec 2024 10:50:20 +1000 |
On Thu Dec 19, 2024 at 7:06 AM AEST, Phil Dennis-Jordan wrote:
> On Wed, 18 Dec 2024 at 02:19, Nicholas Piggin <npiggin@gmail.com> wrote:
>
> > On Thu Dec 12, 2024 at 8:41 PM AEST, Phil Dennis-Jordan wrote:
[...]
> > > > @@ -143,22 +177,37 @@ static void usb_xhci_pci_realize(struct PCIDevice
> > > > *dev, Error **errp)
> > > > /* With msi=auto, we fall back to MSI off silently */
> > > > error_free(err);
> > > > }
> > > > +
> > > > pci_register_bar(dev, 0,
> > > > PCI_BASE_ADDRESS_SPACE_MEMORY |
> > > > PCI_BASE_ADDRESS_MEM_TYPE_64,
> > > > &s->xhci.mem);
> > > >
> > > > if (pci_bus_is_express(pci_get_bus(dev))) {
> > > > - ret = pcie_endpoint_cap_init(dev, 0xa0);
> > > > + ret = pcie_endpoint_cap_init(dev, s->pcie_cap_off);
> > > > assert(ret > 0);
> > > > }
> > > >
> > > > if (s->msix != ON_OFF_AUTO_OFF) {
> > > > - /* TODO check for errors, and should fail when msix=on */
> > > > - msix_init(dev, s->xhci.numintrs,
> > > > - &s->xhci.mem, 0, OFF_MSIX_TABLE,
> > > > - &s->xhci.mem, 0, OFF_MSIX_PBA,
> > > > - 0x90, NULL);
> > > > + MemoryRegion *msix_bar = &s->xhci.mem;
> > > > + if (s->msix_bar_nr != 0) {
> > > > + memory_region_init(&dev->msix_exclusive_bar, OBJECT(dev),
> > > > + "xhci-msix", s->msix_bar_size);
> > > > + msix_bar = &dev->msix_exclusive_bar;
> > > > + }
> > > > +
> > > > + ret = msix_init(dev, s->xhci.numintrs,
> > > > + msix_bar, s->msix_bar_nr, s->msix_table_off,
> > > > + msix_bar, s->msix_bar_nr, s->msix_pba_off,
> > > > + s->msix_cap_off, errp);
> > > > + if (ret) {
> > > > + return;
> > > > + }
> > > >
> > >
> > > Surely we should only propagate the error and fail realize() iff s->msix
> > is
> > > ON_OFF_AUTO_ON?
> > >
> > > For ON_OFF_AUTO_AUTO, msix_init returning failure isn't a critical error.
> >
> > Yep you're right... you had been testing with msix disabled. I wonder if
> > there is a good way to force fail this in qtests?
> >
>
> I'm really the wrong person to ask about qtest, I'm only just beginning to
> get to grips with it.
I'm not an expert in it, for the most part it can set up a machine as
usual, but the test case itself pokes at the machine directly by
talking to an interface on the host that can run memory access, qmp
commands, etc.
Can just make things easier and faster to set up and orchestrate than
doing it from within the target machine code.
> It seems the only real reason msix_init fails other
> than misconfiguration of the device/BAR is when msi_nonbroken = false.
>
> At least on x86(-64), msi_nonbroken=true is unconditionally set in
> apic_realize(). (I think real hardware would not support MSI(-X) on the
> i440FX chipset - I was fairly certain it was the PCI root/southbridge
> catching the writes to the reserved memory region, and I didn't think the
> PIIX did this; but at least in QEMU it doesn't seem to be implemented in a
> chipset-dependent way.) I'm not sure it's possible to run QEMU without an
> APIC?
>
> On aarch64, the GICv3 needs to explicitly enable support (via the ITS), so
> perhaps it's possible to set up an aarch64 qtest with ITS disabled? It
> looks like the 'virt' machine type only supports the ITS from version 6.2,
> so older versions will disable it.
>
> Sorry, clutching at straws here.
No that's okay, thanks for the input. Finding a platform with
broken msi could be an interesting test. I'll check it out.
> > > > +
> > > > + pci_register_bar(dev, s->msix_bar_nr,
> > > > + PCI_BASE_ADDRESS_SPACE_MEMORY |
> > > > + PCI_BASE_ADDRESS_MEM_TYPE_64,
> > > > + msix_bar);
> > > >
> > >
> > > Is it safe to call pci_register_bar() again for the msix_bar_nr = 0 case?
> > > Even if it is safe, is it sensible? If we're calling it twice for the
> > same
> > > BAR, and the arguments of either of the calls changes in future, the
> > other
> > > needs to change too. Doesn't seem ideal.
> >
> > Good catch. It looks like it "works" so long as the bar wasn't mapped,
> > but I'm sure bad practice... Interesting there is no assertion in
> > there though. I'll fix it though.
> >
>
> I notice there's a msix_init_exclusive_bar()… I wonder if it'd be simpler
> to use that and modify it so it allows you to choose a size and layout for
> the BAR, rather than adding all that extra code to deal with the extra BAR
> in the XHCI?
> (It already calls pci_register_bar() and msix_init() internally, but seems
> to set the BAR's size to 4096 and places the PBA at halfway through the
> BAR. Perhaps rename it to something like
> msix_init_exclusive_bar_with_layout and pass the bar_size and
> bar_pba_offset in as parameters; then make msix_init_exclusive_bar() a
> wrapper for that function with the existing defaults for those variables?)
>
> Just kicking around some ideas here, I have no idea if that actually ends
> up making things simpler…
Yeah, I ended up beginning with that, but ended up running into some of
these issues and ended up being more code due to duplicating the non
exclusive case.
I'll stick with open-coding it for now, but it almost seems like there
could be an API call that could encompass exclusive and non-exclusive
cases in one. Would probably be good to have more than one caller before
trying to refactor it though.
Thanks,
Nick
[PATCH v2 2/2] hw/usb/hcd-xhci-pci: Add TI TUSB73X0 XHCI controller model, Nicholas Piggin, 2024/12/12