/* @udev: the transport device @cfg_type: the VIRTIO_PCI_CAP_* value we seek */
static int virtio_pci_find_capability(struct udevice *udev, u8 cfg_type)
/* @udev: the transport device @cfg_type: the VIRTIO_PCI_CAP_* value we seek */
static int virtio_pci_find_capability(struct udevice *udev, u8 cfg_type)
{
	int pos;
	int offset;
	u8 type, bar;
	for (pos = dm_pci_find_capability(udev, PCI_CAP_ID_VNDR);
	     pos > 0;
	     pos = dm_pci_find_next_capability(udev, pos, PCI_CAP_ID_VNDR)) {
		offset = pos + offsetof(struct virtio_pci_cap, cfg_type);
		dm_pci_read_config8(udev, offset, &type);
		offset = pos + offsetof(struct virtio_pci_cap, bar);
		dm_pci_read_config8(udev, offset, &bar);
		if (bar > 0x5)
			continue;
		if (type == cfg_type)
			return pos;
	}
	return 0;
}