Page MenuHomeFreeBSD

bhyve: Refactor initial PCI BAR setup
ClosedPublic

Authored by jhb on Mon, Aug 17, 5:55 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Sep 8, 2:32 AM
Unknown Object (File)
Mon, Sep 7, 7:18 PM
Unknown Object (File)
Mon, Sep 7, 7:17 PM
Unknown Object (File)
Mon, Sep 7, 7:15 PM
Unknown Object (File)
Sat, Sep 5, 6:06 AM
Unknown Object (File)
Sat, Sep 5, 4:31 AM
Unknown Object (File)
Fri, Sep 4, 10:35 PM
Unknown Object (File)
Fri, Sep 4, 8:40 PM
Subscribers

Details

Summary

Fully initialize BARs with an address of 0 in pci_emul_alloc_bar()
instead of deferring some of that initialization to
pci_emul_assign_bar(). Now, the latter is only used to allocate an
initial address range for PCI BARs.

Note that this means that the pci_passthru model now overrides the
initial lobits after they are set removing the need for a workaround
in pci_emul_assign_bar().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Mon, Aug 17, 5:55 PM
jhb added inline comments.
usr.sbin/bhyve/pci_emul.c
869

@bnovkov I think once this change is in place, all you would need to do here for the HotPlug case is return here before adding the BAR to the linked list or enabling decoding in the command register.

usr.sbin/bhyve/pci_emul.c
921

I can't find the PCIM_BAR_MEM_PREFETCH flag in the reworked code, is this intentional?

usr.sbin/bhyve/pci_emul.c
921

Bleh, I think this is a bug in the old code. If a device model needs this, it should request it explicitly (and we should update the API of pci_emul_alloc_bar() to take a bool or flag to request prefetch, or maybe define a new PCI_MEM64_PREFETCH BAR type or some such).

However, I don't think any of the software device models request a large enough BAR. Only nvme(4) allocates a MEM64 BAR, and the size of that BAR is capped to (0x1008 + (8 * (16 + 1)) which is far less than 128 MB.

The PCI pass through device model overwrites the lobits value with the "real" value (precisely to preserve the PREFETCH flag), so it would never use the flag set here.

bnovkov added inline comments.
usr.sbin/bhyve/pci_emul.c
921

Bleh, I think this is a bug in the old code. If a device model needs this, it should request it explicitly (and we should update the API of pci_emul_alloc_bar() to take a bool or flag to request prefetch, or maybe define a new PCI_MEM64_PREFETCH BAR type or some such).

However, I don't think any of the software device models request a large enough BAR. Only nvme(4) allocates a MEM64 BAR, and the size of that BAR is capped to (0x1008 + (8 * (16 + 1)) which is far less than 128 MB.

That makes sense, I just wanted to make sure that it's safe to remove this.

This revision is now accepted and ready to land.Sun, Aug 23, 1:07 PM
usr.sbin/bhyve/pci_emul.c
921

I think I will split it out into a separate commit in fact.

This revision was automatically updated to reflect the committed changes.