mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-29 08:47:24 +00:00
DM USB: add usb_dev_path_cmp function for convenience
Comparing two USB devices' path is frequently used operation, abstract it as an seperated function for convenience. Tracked-On: #1893 Signed-off-by: Xiaoguang Wu <xiaoguang.wu@intel.com> Reviewed-by: Liang Yang <liang3.yang@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
parent
6c1ca13767
commit
e5c98e6d9a
@ -542,23 +542,13 @@ pci_xhci_get_native_port_index_by_path(struct pci_xhci_vdev *xdev,
|
||||
struct usb_devpath *path)
|
||||
{
|
||||
int i;
|
||||
struct usb_devpath *p;
|
||||
|
||||
assert(xdev);
|
||||
assert(path);
|
||||
|
||||
for (i = 0; i < XHCI_MAX_VIRT_PORTS; i++) {
|
||||
p = &xdev->native_ports[i].info.path;
|
||||
|
||||
if (p->bus != path->bus)
|
||||
continue;
|
||||
|
||||
if (p->depth != path->depth)
|
||||
continue;
|
||||
|
||||
if (memcmp(p->path, path->path, path->depth) == 0)
|
||||
for (i = 0; i < XHCI_MAX_VIRT_PORTS; i++)
|
||||
if (usb_dev_path_cmp(&xdev->native_ports[i].info.path, path))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -272,6 +272,16 @@ usb_dev_path(struct usb_devpath *path)
|
||||
return output;
|
||||
}
|
||||
|
||||
bool
|
||||
usb_dev_path_cmp(struct usb_devpath *p1, struct usb_devpath *p2)
|
||||
{
|
||||
if (!p1 || !p2)
|
||||
return false;
|
||||
|
||||
return (p1->bus == p2->bus && p1->depth == p2->depth &&
|
||||
memcmp(p1->path, p2->path, p1->depth) == 0);
|
||||
}
|
||||
|
||||
int
|
||||
usb_get_hub_port_num(struct usb_devpath *path)
|
||||
{
|
||||
|
@ -257,4 +257,5 @@ struct usb_data_xfer_block *usb_data_xfer_append(struct usb_data_xfer *xfer,
|
||||
int ccs);
|
||||
int usb_get_hub_port_num(struct usb_devpath *path);
|
||||
char *usb_dev_path(struct usb_devpath *path);
|
||||
bool usb_dev_path_cmp(struct usb_devpath *p1, struct usb_devpath *p2);
|
||||
#endif /* _USB_CORE_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user