Skip to content

Conversation

@seijikun
Copy link
Contributor

@seijikun seijikun commented Nov 22, 2025

Initial implementation for device path generation of discovered pci devices in a PciTree instance.
Unfortunately, it's a bit clunky to use, since you have to query the DevicePath corresponding to your PciRootBridgeIo instance yourself and pass that in:

let mut pci_proto = get_open_protocol::<PciRootBridgeIo>(pci_handle);
let root_device_path = get_open_protocol::<DevicePath>(pci_handle);

let pci_tree = pci_proto.enumerate().unwrap();
for addr in pci_tree {
    // v Would be nicer, if I didn't have to pass root DevicePath in manually here v
    let device_path = pci_tree.device_path(&root_device_path, addr).unwrap();
}

I tried getting the DevicePath of the PciRootBridgeIo instance within PciRootBridgeIo::enumerate() and pass that on to the PciTree, but I couldn't find a way to get the DevicePath instance - other than ugly workarounds.

Best consumed Commit-By-Commit. Contains #1830..

Steps to Undraft

Checklist

  • Sensible git history (for example, squash "typo" or "fix" commits). See the Rewriting History guide for help.
  • Update the changelog (if necessary)

@seijikun seijikun force-pushed the mr-pci-device_paths branch from ab46f2d to 582714a Compare November 22, 2025 02:34
@phip1611 phip1611 marked this pull request as draft November 22, 2025 09:27
@seijikun seijikun force-pushed the mr-pci-device_paths branch 2 times, most recently from 6f6f35b to 8a4ab00 Compare November 24, 2025 10:44
@seijikun seijikun force-pushed the mr-pci-device_paths branch from 8a4ab00 to c31575d Compare December 14, 2025 20:08
@seijikun seijikun marked this pull request as ready for review December 14, 2025 20:13
@phip1611 phip1611 self-requested a review December 14, 2025 22:24
Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with two nits!

PS: You do not have to fix it here but do you have an opinion on #1817? I'd like to hear a direction that we should go for (Box<DevicePath> vs PoolDevicePath)

@seijikun seijikun force-pushed the mr-pci-device_paths branch 4 times, most recently from 3e6b322 to 9770e69 Compare December 15, 2025 13:29
@seijikun
Copy link
Contributor Author

You do not have to fix it here but do you have an opinion on #1817? I'd like to hear a direction that we should go for (Box vs PoolDevicePath)

To be completely honest with you, I don't really understand the difference. I was under the impression, that PoolDevicePath is just a typedef of Box<DevicePath>. Is that not correct?

@phip1611
Copy link
Member

You do not have to fix it here but do you have an opinion on #1817? I'd like to hear a direction that we should go for (Box vs PoolDevicePath)

To be completely honest with you, I don't really understand the difference. I was under the impression, that PoolDevicePath is just a typedef of Box<DevicePath>. Is that not correct?

Nope, it is a wrapper for PoolAllocation. https://docs.rs/uefi/latest/src/uefi/proto/device_path/mod.rs.html#137

@seijikun seijikun requested a review from phip1611 December 15, 2025 14:02
@seijikun
Copy link
Contributor Author

Nope, it is a wrapper for PoolAllocation. https://docs.rs/uefi/latest/src/uefi/proto/device_path/mod.rs.html#137

Yes. But isn't alloc in uefi also just using pool allocations under the hood, conceptually?

@phip1611 phip1611 force-pushed the mr-pci-device_paths branch from 9770e69 to b643d1a Compare January 25, 2026 10:12
Copy link
Member

@phip1611 phip1611 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution!

We are currently inconsistent with Box<[u8]> and PoolDevicePath - no need to clean that up.

One final question: When I execute the integration test, it prints

...
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@069:  \- Bus: 01
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [00, 1f, 00]: vendor=8086, device=2918, class=06, subclass=01 - PciRoot(0x0)/Pci(0x1F,0x0)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [00, 1f, 02]: vendor=8086, device=2922, class=01, subclass=06 - PciRoot(0x0)/Pci(0x1F,0x2)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [00, 1f, 03]: vendor=8086, device=2930, class=0C, subclass=05 - PciRoot(0x0)/Pci(0x1F,0x3)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [01, 00, 00]: vendor=104C, device=8232, class=06, subclass=04 - PciRoot(0x0)/Pci(0x7,0x0)/Pci(0x0,0x0)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@069:  \- Bus: 02
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [02, 00, 00]: vendor=104C, device=8233, class=06, subclass=04 - PciRoot(0x0)/Pci(0x7,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@069:  \- Bus: 03
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [02, 01, 00]: vendor=104C, device=8233, class=06, subclass=04 - PciRoot(0x0)/Pci(0x7,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@069:  \- Bus: 04
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [03, 00, 00]: vendor=1AF4, device=1048, class=01, subclass=00 - PciRoot(0x0)/Pci(0x7,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)/Pci(0x0,0x0)
[ INFO]: uefi-test-runner/src/proto/pci/root_bridge.rs@064: PCI Device: [04, 00, 00]: vendor=1AF4, device=1048, class=01, subclass=00 - PciRoot(0x0)/Pci(0x7,0x0)/Pci(0x0,0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)
[ INFO]: uefi-test-runner/src/proto/pi/mod.rs@004: Testing Platform Initialization protocols

I don't understand the output. When you are about to enumerate bus 3, the device says it is at bus 2? And if you enumerate Bus 4, the first device says it is as bus 3? Please explain - or is therea bug?

Image

Not sure about the random Windows CI failure, tho.

@seijikun
Copy link
Contributor Author

seijikun commented Jan 26, 2026

Ah yes, the logging may be a bit confusing.

        let pci_tree = pci_proto.enumerate().unwrap();
        for addr in pci_tree.iter().cloned() {
                // ...
        }

basically performs a breadth-first-search. Meaning that you will first get all devices in bus 0 before going to bus 1.
At the bottom of the loop, I print the subsequent bus numbers (if any) for every iterated device with this:

            for child_bus in pci_tree.child_bus_of_iter(addr) {
                log::info!(" \\- Bus: {child_bus:02x}");
            }

So the log line \- Bus: 03 is basically only saying: "The bus 03 that will come sometime later is connected to me"

@seijikun seijikun force-pushed the mr-pci-device_paths branch from b643d1a to f8444fd Compare January 26, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants