On 10/23/2025 10:31 AM, Farhan Ali wrote:
+ * Find the position of the capability config within PCI configuration
+ * space for a given cfg type. Return the position if found,
otherwise 0.
+ */
+uint8_t find_cap_pos(uint32_t fhandle, uint64_t cfg_type) {
+ uint64_t req, next, cfg;
+ uint8_t status;
+ int rc;
+
+ req = ZPCI_CREATE_REQ(fhandle, 0xf, 1);
+ rc = pcilg(&next, req, PCI_CAPABILITY_LIST, &status);
+ rc = pcilg(&cfg, req, next + 3, &status);
Why are we reading next + 3 into cfg? If I understand this correctly
next will be the address of the first capability in the linked list,
and so we should just read the first byte from next to get the
capability id? I think we should have helper function like
qpci_find_capability to find the capabilities?
+
+ while (!rc && (cfg != cfg_type) && next) {
+ rc = pcilg(&next, req, next + 1, &status);
+ rc = pcilg(&cfg, req, next + 3, &status);
Same question here?
+ }
+
+ return rc ? 0 : next;
+}
+
[..snip..]
Ah I see in patch 5 we are using this function to get virtio config
type, which is a vendor specific capability and according to spec the
virtio config type is defined in the 4th byte. Maybe we could just move
the function to virtio-pci.c? I would expect a function defined here
will try to find a specific PCI capability by searching through the PCI
capability list.
Thanks
Farhan