From a66fd8920df1e0a534d0a8ed68adb6143a304a66 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 8 May 2015 16:50:47 +0100 Subject: [PATCH] [usb] Add find_usb_bus_by_location() helper function Signed-off-by: Michael Brown --- src/drivers/bus/usb.c | 20 ++++++++++++++++++++ src/include/ipxe/usb.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/drivers/bus/usb.c b/src/drivers/bus/usb.c index 16f18259..0fe6da20 100644 --- a/src/drivers/bus/usb.c +++ b/src/drivers/bus/usb.c @@ -1976,6 +1976,26 @@ void free_usb_bus ( struct usb_bus *bus ) { free ( bus ); } +/** + * Find USB bus by device location + * + * @v bus_type Bus type + * @v location Bus location + * @ret bus USB bus, or NULL + */ +struct usb_bus * find_usb_bus_by_location ( unsigned int bus_type, + unsigned int location ) { + struct usb_bus *bus; + + for_each_usb_bus ( bus ) { + if ( ( bus->dev->desc.bus_type == bus_type ) && + ( bus->dev->desc.location == location ) ) + return bus; + } + + return NULL; +} + /****************************************************************************** * * USB address assignment diff --git a/src/include/ipxe/usb.h b/src/include/ipxe/usb.h index ee826bc1..eb5b99f8 100644 --- a/src/include/ipxe/usb.h +++ b/src/include/ipxe/usb.h @@ -1211,6 +1211,8 @@ extern struct usb_bus * alloc_usb_bus ( struct device *dev, extern int register_usb_bus ( struct usb_bus *bus ); extern void unregister_usb_bus ( struct usb_bus *bus ); extern void free_usb_bus ( struct usb_bus *bus ); +extern struct usb_bus * find_usb_bus_by_location ( unsigned int bus_type, + unsigned int location ); extern int usb_alloc_address ( struct usb_bus *bus ); extern void usb_free_address ( struct usb_bus *bus, unsigned int address );