// twisted TPL used. It should be no problem for us to connect\r
// or disconnect at CALLBACK.\r
//\r
- OldTpl = UsbGetCurrentTpl ();\r
- DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", OldTpl));\r
+ \r
+ //\r
+ // Only recursively wanted usb child device\r
+ //\r
+ if (UsbBusIsWantedUsbIO (UsbIf->Device->Bus, UsbIf)) {\r
+ OldTpl = UsbGetCurrentTpl ();\r
+ DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", OldTpl));\r
\r
- gBS->RestoreTPL (TPL_CALLBACK);\r
+ gBS->RestoreTPL (TPL_CALLBACK);\r
\r
- Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE);\r
- UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status);\r
+ Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE);\r
+ UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status);\r
\r
- DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl()));\r
- ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);\r
+ DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl()));\r
+ ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK);\r
\r
- gBS->RaiseTPL (OldTpl);\r
+ gBS->RaiseTPL (OldTpl);\r
+ }\r
}\r
\r
return Status;\r
);\r
\r
VOID\r
+EFIAPI\r
UsbHubEnumeration (\r
IN EFI_EVENT Event,\r
IN VOID *Context\r
\r
#include "UsbBus.h"\r
\r
+//\r
+// if RemainingDevicePath== NULL, then all Usb child devices in this bus are wanted.\r
+// Use a shor form Usb class Device Path, which could match any usb device, in WantedUsbIoDPList to indicate all Usb devices\r
+// are wanted Usb devices\r
+//\r
+STATIC USB_CLASS_FORMAT_DEVICE_PATH mAllUsbClassDevicePath = {\r
+ {\r
+ {\r
+ MESSAGING_DEVICE_PATH,\r
+ MSG_USB_CLASS_DP,\r
+ (UINT8) (sizeof (USB_CLASS_DEVICE_PATH)),\r
+ (UINT8) ((sizeof (USB_CLASS_DEVICE_PATH)) >> 8)\r
+ },\r
+ 0xffff, // VendorId\r
+ 0xffff, // ProductId\r
+ 0xff, // DeviceClass\r
+ 0xff, // DeviceSubClass\r
+ 0xff // DeviceProtocol\r
+ },\r
+\r
+ {\r
+ END_DEVICE_PATH_TYPE,\r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+ END_DEVICE_PATH_LENGTH,\r
+ 0\r
+ }\r
+};\r
+\r
\r
/**\r
Get the capability of the host controller\r
return Tpl;\r
}\r
\r
+/**\r
+ Create a new device path which only contain the first Usb part of the DevicePath\r
+\r
+ @param DevicePath A full device path which contain the usb nodes\r
+\r
+ @return A new device path which only contain the Usb part of the DevicePath\r
+\r
+**/\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+EFIAPI\r
+GetUsbDPFromFullDP (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
+ )\r
+{\r
+ EFI_DEVICE_PATH_PROTOCOL *UsbDevicePathPtr;\r
+ EFI_DEVICE_PATH_PROTOCOL *UsbDevicePathBeginPtr;\r
+ EFI_DEVICE_PATH_PROTOCOL *UsbDevicePathEndPtr;\r
+ UINTN Size;\r
+\r
+ //\r
+ // Get the Usb part first Begin node in full device path\r
+ //\r
+ UsbDevicePathBeginPtr = DevicePath;\r
+ while ( (!EfiIsDevicePathEnd (UsbDevicePathBeginPtr))&&\r
+ ((UsbDevicePathBeginPtr->Type != MESSAGING_DEVICE_PATH) ||\r
+ (UsbDevicePathBeginPtr->SubType != MSG_USB_DP &&\r
+ UsbDevicePathBeginPtr->SubType != MSG_USB_CLASS_DP\r
+ && UsbDevicePathBeginPtr->SubType != MSG_USB_WWID_DP\r
+ ))) {\r
+\r
+ UsbDevicePathBeginPtr = NextDevicePathNode(UsbDevicePathBeginPtr);\r
+ }\r
+\r
+ //\r
+ // Get the Usb part first End node in full device path\r
+ //\r
+ UsbDevicePathEndPtr = UsbDevicePathBeginPtr;\r
+ while ((!EfiIsDevicePathEnd (UsbDevicePathEndPtr))&&\r
+ (UsbDevicePathEndPtr->Type == MESSAGING_DEVICE_PATH) &&\r
+ (UsbDevicePathEndPtr->SubType == MSG_USB_DP ||\r
+ UsbDevicePathEndPtr->SubType == MSG_USB_CLASS_DP\r
+ || UsbDevicePathEndPtr->SubType == MSG_USB_WWID_DP\r
+ )) {\r
+\r
+ UsbDevicePathEndPtr = NextDevicePathNode(UsbDevicePathEndPtr);\r
+ }\r
+\r
+ Size = GetDevicePathSize (UsbDevicePathBeginPtr);\r
+ Size -= GetDevicePathSize (UsbDevicePathEndPtr);\r
+ if (Size ==0){\r
+ //\r
+ // The passed in DevicePath does not contain the usb nodes\r
+ //\r
+ return NULL;\r
+ }\r
+\r
+ //\r
+ // Create a new device path which only contain the above Usb part\r
+ //\r
+ UsbDevicePathPtr = AllocateZeroPool (Size + sizeof (EFI_DEVICE_PATH_PROTOCOL));\r
+ ASSERT (UsbDevicePathPtr != NULL);\r
+ CopyMem (UsbDevicePathPtr, UsbDevicePathBeginPtr, Size);\r
+ //\r
+ // Append end device path node\r
+ //\r
+ UsbDevicePathEndPtr = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) UsbDevicePathPtr + Size);\r
+ SetDevicePathEndNode (UsbDevicePathEndPtr);\r
+ return UsbDevicePathPtr;\r
+}\r
+\r
+/**\r
+ Check whether a usb device path is in a DEVICE_PATH_LIST_ITEM list.\r
+\r
+ @param UsbDP a usb device path of DEVICE_PATH_LIST_ITEM\r
+ @parem UsbIoDPList a DEVICE_PATH_LIST_ITEM list\r
+\r
+ @retval TRUE there is a DEVICE_PATH_LIST_ITEM in UsbIoDPList which contains the passed in UsbDP\r
+ @retval FALSE there is no DEVICE_PATH_LIST_ITEM in UsbIoDPList which contains the passed in UsbDP\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+SearchUsbDPInList (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *UsbDP,\r
+ IN LIST_ENTRY *UsbIoDPList\r
+ )\r
+{\r
+ LIST_ENTRY *ListIndex;\r
+ DEVICE_PATH_LIST_ITEM *ListItem;\r
+ BOOLEAN Found;\r
+ UINTN UsbDpDevicePathSize;\r
+\r
+ //\r
+ // Check that UsbDP and UsbIoDPList are valid\r
+ //\r
+ if ((UsbIoDPList == NULL) || (UsbDP == NULL)) {\r
+ return FALSE;\r
+ }\r
+\r
+ Found = FALSE;\r
+ ListIndex = UsbIoDPList->ForwardLink;\r
+ while (ListIndex != UsbIoDPList){\r
+ ListItem = CR(ListIndex, DEVICE_PATH_LIST_ITEM, Link, DEVICE_PATH_LIST_ITEM_SIGNATURE);\r
+ //\r
+ // Compare DEVICE_PATH_LIST_ITEM.DevicePath[]\r
+ //\r
+ ASSERT (ListItem->DevicePath != NULL);\r
+\r
+ UsbDpDevicePathSize = GetDevicePathSize (UsbDP);\r
+ if (UsbDpDevicePathSize == GetDevicePathSize (ListItem->DevicePath)) {\r
+ if ((CompareMem (UsbDP, ListItem->DevicePath, UsbDpDevicePathSize)) == 0) {\r
+ Found = TRUE;\r
+ break;\r
+ }\r
+ }\r
+ ListIndex = ListIndex->ForwardLink;\r
+ }\r
+\r
+ return Found;\r
+}\r
+\r
+/**\r
+ Add a usb device path into the DEVICE_PATH_LIST_ITEM list.\r
+\r
+ @param UsbDP a usb device path of DEVICE_PATH_LIST_ITEM\r
+ @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list\r
+\r
+ @retval EFI_INVALID_PARAMETER\r
+ @retval EFI_SUCCESS\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AddUsbDPToList (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *UsbDP,\r
+ IN LIST_ENTRY *UsbIoDPList\r
+ )\r
+{\r
+ DEVICE_PATH_LIST_ITEM *ListItem;\r
+\r
+ //\r
+ // Check that UsbDP and UsbIoDPList are valid\r
+ //\r
+ if ((UsbIoDPList == NULL) || (UsbDP == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ if (SearchUsbDPInList (UsbDP, UsbIoDPList)){\r
+ return EFI_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Prepare the usbio device path DEVICE_PATH_LIST_ITEM structure.\r
+ //\r
+ ListItem = AllocateZeroPool (sizeof (DEVICE_PATH_LIST_ITEM));\r
+ ASSERT (ListItem != NULL);\r
+ ListItem->Signature = DEVICE_PATH_LIST_ITEM_SIGNATURE;\r
+ ListItem->DevicePath = DuplicateDevicePath (UsbDP);\r
+\r
+ InsertTailList (UsbIoDPList, &ListItem->Link);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Check whether usb device, whose interface is UsbIf, matches the usb class which indicated by\r
+ UsbClassDevicePathPtr whose is a short form usb class device path\r
+\r
+ @param UsbClassDevicePathPtr a short form usb class device path\r
+ @param UsbIf a usb device interface\r
+\r
+ @retval TRUE the usb device match the usb class\r
+ @retval FALSE the usb device does not match the usb class\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+MatchUsbClass (\r
+ IN USB_CLASS_DEVICE_PATH *UsbClassDevicePathPtr,\r
+ IN USB_INTERFACE *UsbIf\r
+ )\r
+{\r
+ USB_INTERFACE_DESC *IfDesc;\r
+ EFI_USB_INTERFACE_DESCRIPTOR *ActIfDesc;\r
+ EFI_USB_DEVICE_DESCRIPTOR *DevDesc;\r
+\r
+\r
+ if ((UsbClassDevicePathPtr->Header.Type != MESSAGING_DEVICE_PATH) ||\r
+ (UsbClassDevicePathPtr->Header.SubType != MSG_USB_CLASS_DP)){\r
+ ASSERT (0);\r
+ return FALSE;\r
+ }\r
+\r
+ IfDesc = UsbIf->IfDesc;\r
+ ActIfDesc = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc);\r
+ DevDesc = &(UsbIf->Device->DevDesc->Desc);\r
+\r
+ //\r
+ // If connect class policy, determine whether to create device handle by the five fields\r
+ // in class device path node.\r
+ //\r
+ // In addtion, hub interface is always matched for this policy.\r
+ //\r
+ if ((ActIfDesc->InterfaceClass == USB_HUB_CLASS_CODE) &&\r
+ (ActIfDesc->InterfaceSubClass == USB_HUB_SUBCLASS_CODE)) {\r
+ return TRUE;\r
+ }\r
+\r
+ //\r
+ // If vendor id or product id is 0xffff, they will be ignored.\r
+ //\r
+ if ((UsbClassDevicePathPtr->VendorId == 0xffff || UsbClassDevicePathPtr->VendorId == DevDesc->IdVendor) &&\r
+ (UsbClassDevicePathPtr->ProductId == 0xffff || UsbClassDevicePathPtr->ProductId == DevDesc->IdProduct)) {\r
+\r
+ //\r
+ // If class or subclass or protocol is 0, the counterparts in interface should be checked.\r
+ //\r
+ if (DevDesc->DeviceClass == 0 &&\r
+ DevDesc->DeviceSubClass == 0 &&\r
+ DevDesc->DeviceProtocol == 0) {\r
+\r
+ if ((UsbClassDevicePathPtr->DeviceClass == ActIfDesc->InterfaceClass ||\r
+ UsbClassDevicePathPtr->DeviceClass == 0xff) &&\r
+ (UsbClassDevicePathPtr->DeviceSubClass == ActIfDesc->InterfaceSubClass ||\r
+ UsbClassDevicePathPtr->DeviceSubClass == 0xff) &&\r
+ (UsbClassDevicePathPtr->DeviceProtocol == ActIfDesc->InterfaceProtocol) ||\r
+ UsbClassDevicePathPtr->DeviceProtocol == 0xff) {\r
+ return TRUE;\r
+ }\r
+\r
+ } else if ((UsbClassDevicePathPtr->DeviceClass != DevDesc->DeviceClass ||\r
+ UsbClassDevicePathPtr->DeviceClass == 0xff) &&\r
+ (UsbClassDevicePathPtr->DeviceSubClass == DevDesc->DeviceSubClass ||\r
+ UsbClassDevicePathPtr->DeviceSubClass == 0xff) &&\r
+ (UsbClassDevicePathPtr->DeviceProtocol == DevDesc->DeviceProtocol) ||\r
+ UsbClassDevicePathPtr->DeviceProtocol == 0xff) {\r
+\r
+ return TRUE;\r
+ }\r
+ }\r
+\r
+ return FALSE;\r
+}\r
+\r
+/**\r
+ Check whether usb device, whose interface is UsbIf, matches the usb WWID requirement which indicated by\r
+ UsbWWIDDevicePathPtr whose is a short form usb WWID device path\r
+\r
+ @param UsbClassDevicePathPtr a short form usb WWID device path\r
+ @param UsbIf a usb device interface\r
+\r
+ @retval TRUE the usb device match the usb WWID requirement\r
+ @retval FALSE the usb device does not match the usb WWID requirement\r
+\r
+**/\r
+STATIC\r
+BOOLEAN\r
+MatchUsbWwid (\r
+ IN USB_WWID_DEVICE_PATH *UsbWWIDDevicePathPtr,\r
+ IN USB_INTERFACE *UsbIf\r
+ )\r
+{\r
+ USB_INTERFACE_DESC *IfDesc;\r
+ EFI_USB_INTERFACE_DESCRIPTOR *ActIfDesc;\r
+ EFI_USB_DEVICE_DESCRIPTOR *DevDesc;\r
+ EFI_USB_STRING_DESCRIPTOR *StrDesc;\r
+ UINT16 *SnString;\r
+\r
+ if ((UsbWWIDDevicePathPtr->Header.Type != MESSAGING_DEVICE_PATH) ||\r
+ (UsbWWIDDevicePathPtr->Header.SubType != MSG_USB_WWID_DP )){\r
+ ASSERT (0);\r
+ return FALSE;\r
+ }\r
+\r
+ IfDesc = UsbIf->IfDesc;\r
+ ActIfDesc = &(IfDesc->Settings[IfDesc->ActiveIndex]->Desc);\r
+ DevDesc = &(UsbIf->Device->DevDesc->Desc);\r
+ StrDesc = UsbGetOneString (UsbIf->Device, DevDesc->StrSerialNumber, USB_US_LAND_ID);\r
+ SnString = (UINT16 *) ((UINT8 *)UsbWWIDDevicePathPtr + 10);\r
+\r
+ //\r
+ //In addtion, hub interface is always matched for this policy.\r
+ //\r
+ if ((ActIfDesc->InterfaceClass == USB_HUB_CLASS_CODE) &&\r
+ (ActIfDesc->InterfaceSubClass == USB_HUB_SUBCLASS_CODE)) {\r
+ return TRUE;\r
+ }\r
+ //\r
+ // If connect wwid policy, determine the objective device by the serial number of\r
+ // device descriptor.\r
+ // Get serial number index from device descriptor, then get serial number by index\r
+ // and land id, compare the serial number with wwid device path node at last\r
+ //\r
+ // BugBug: only check serial number here, should check Interface Number, Device Vendor Id, Device Product Id in later version\r
+ //\r
+ if (StrDesc != NULL && !StrnCmp (StrDesc->String, SnString, StrDesc->Length)) {\r
+\r
+ return TRUE;\r
+ }\r
+\r
+ return FALSE;\r
+}\r
+\r
+/**\r
+ Free a DEVICE_PATH_LIST_ITEM list\r
+\r
+ @param UsbIoDPList a DEVICE_PATH_LIST_ITEM list pointer\r
+\r
+ @retval EFI_INVALID_PARAMETER\r
+ @retval EFI_SUCCESS\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusFreeUsbDPList (\r
+ IN LIST_ENTRY *UsbIoDPList\r
+ )\r
+{\r
+ LIST_ENTRY *ListIndex;\r
+ DEVICE_PATH_LIST_ITEM *ListItem;\r
+\r
+ //\r
+ // Check that ControllerHandle is a valid handle\r
+ //\r
+ if (UsbIoDPList == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ ListIndex = UsbIoDPList->ForwardLink;\r
+ while (ListIndex != UsbIoDPList){\r
+ ListItem = CR(ListIndex, DEVICE_PATH_LIST_ITEM, Link, DEVICE_PATH_LIST_ITEM_SIGNATURE);\r
+ //\r
+ // Free DEVICE_PATH_LIST_ITEM.DevicePath[]\r
+ //\r
+ if (ListItem->DevicePath != NULL){\r
+ FreePool(ListItem->DevicePath);\r
+ }\r
+ //\r
+ // Free DEVICE_PATH_LIST_ITEM itself\r
+ //\r
+ ListIndex = ListIndex->ForwardLink;\r
+ RemoveEntryList (&ListItem->Link);\r
+ FreePool (ListItem);\r
+ }\r
+\r
+ InitializeListHead (UsbIoDPList);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Store a wanted usb child device info (its Usb part of device path) which is indicated by\r
+ RemainingDevicePath in a Usb bus which is indicated by UsbBusId\r
+\r
+ @param UsbBusId Point to EFI_USB_BUS_PROTOCOL interface\r
+ @param RemainingDevicePath The remaining device patch\r
+\r
+ @retval EFI_SUCCESS\r
+ @retval EFI_INVALID_PARAMETER\r
+ @retval EFI_OUT_OF_RESOURCES\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusAddWantedUsbIoDP (\r
+ IN EFI_USB_BUS_PROTOCOL *UsbBusId,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ USB_BUS *Bus;\r
+ EFI_STATUS Status;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathPtr;\r
+\r
+ //\r
+ // Check whether remaining device path is valid\r
+ //\r
+ if (RemainingDevicePath != NULL) {\r
+ if ((RemainingDevicePath->Type != MESSAGING_DEVICE_PATH) ||\r
+ (RemainingDevicePath->SubType != MSG_USB_DP &&\r
+ RemainingDevicePath->SubType != MSG_USB_CLASS_DP\r
+ && RemainingDevicePath->SubType != MSG_USB_WWID_DP\r
+ )) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ }\r
+\r
+ if (UsbBusId == NULL){\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Bus = USB_BUS_FROM_THIS (UsbBusId);\r
+\r
+ if (RemainingDevicePath == NULL) {\r
+ //\r
+ // RemainingDevicePath== NULL means all Usb devices in this bus are wanted.\r
+ // Here use a Usb class Device Path in WantedUsbIoDPList to indicate all Usb devices\r
+ // are wanted Usb devices\r
+ //\r
+ Status = UsbBusFreeUsbDPList (&Bus->WantedUsbIoDPList);\r
+ ASSERT (!EFI_ERROR (Status));\r
+ DevicePathPtr = DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) &mAllUsbClassDevicePath);\r
+ } else {\r
+ //\r
+ // Create new Usb device path according to the usb part in remaining device path\r
+ //\r
+ DevicePathPtr = GetUsbDPFromFullDP (RemainingDevicePath);\r
+ }\r
+\r
+ ASSERT (DevicePathPtr != NULL);\r
+ Status = AddUsbDPToList (DevicePathPtr, &Bus->WantedUsbIoDPList);\r
+ ASSERT (!EFI_ERROR (Status));\r
+ gBS->FreePool (DevicePathPtr);\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Check whether a usb child device is the wanted device in a bus\r
+\r
+ @param Bus The Usb bus's private data pointer\r
+ @param UsbIf The usb child device inferface\r
+\r
+ @retval EFI_SUCCESS\r
+ @retval EFI_INVALID_PARAMETER\r
+ @retval EFI_OUT_OF_RESOURCES\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+UsbBusIsWantedUsbIO (\r
+ IN USB_BUS *Bus,\r
+ IN USB_INTERFACE *UsbIf\r
+ )\r
+{\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathPtr;\r
+ LIST_ENTRY *WantedUsbIoDPListPtr;\r
+ LIST_ENTRY *WantedListIndex;\r
+ DEVICE_PATH_LIST_ITEM *WantedListItem;\r
+ BOOLEAN DoConvert;\r
+ UINTN FirstDevicePathSize;\r
+\r
+ //\r
+ // Check whether passed in parameters are valid\r
+ //\r
+ if ((UsbIf == NULL) || (Bus == NULL)) {\r
+ return FALSE;\r
+ }\r
+ //\r
+ // Check whether UsbIf is Hub\r
+ //\r
+ if (UsbIf->IsHub) {\r
+ return TRUE;\r
+ }\r
+\r
+ //\r
+ // Check whether all Usb devices in this bus are wanted\r
+ //\r
+ if (SearchUsbDPInList ((EFI_DEVICE_PATH_PROTOCOL *)&mAllUsbClassDevicePath, &Bus->WantedUsbIoDPList)){\r
+ return TRUE;\r
+ }\r
+\r
+ //\r
+ // Check whether the Usb device match any item in WantedUsbIoDPList\r
+ //\r
+ WantedUsbIoDPListPtr = &Bus->WantedUsbIoDPList;\r
+ //\r
+ // Create new Usb device path according to the usb part in UsbIo full device path\r
+ //\r
+ DevicePathPtr = GetUsbDPFromFullDP (UsbIf->DevicePath);\r
+ ASSERT (DevicePathPtr != NULL);\r
+\r
+ DoConvert = FALSE;\r
+ WantedListIndex = WantedUsbIoDPListPtr->ForwardLink;\r
+ while (WantedListIndex != WantedUsbIoDPListPtr){\r
+ WantedListItem = CR(WantedListIndex, DEVICE_PATH_LIST_ITEM, Link, DEVICE_PATH_LIST_ITEM_SIGNATURE);\r
+ ASSERT (WantedListItem->DevicePath->Type == MESSAGING_DEVICE_PATH);\r
+ switch (WantedListItem->DevicePath->SubType) {\r
+ case MSG_USB_DP:\r
+ FirstDevicePathSize = GetDevicePathSize (WantedListItem->DevicePath);\r
+ if (FirstDevicePathSize == GetDevicePathSize (DevicePathPtr)) {\r
+ if (CompareMem (\r
+ WantedListItem->DevicePath,\r
+ DevicePathPtr,\r
+ GetDevicePathSize (DevicePathPtr)) == 0\r
+ ) {\r
+ DoConvert = TRUE;\r
+ }\r
+ }\r
+ break;\r
+ case MSG_USB_CLASS_DP:\r
+ if (MatchUsbClass((USB_CLASS_DEVICE_PATH *)WantedListItem->DevicePath, UsbIf)) {\r
+ DoConvert = TRUE;\r
+ }\r
+ break;\r
+ case MSG_USB_WWID_DP:\r
+ if (MatchUsbWwid((USB_WWID_DEVICE_PATH *)WantedListItem->DevicePath, UsbIf)) {\r
+ DoConvert = TRUE;\r
+ }\r
+ break;\r
+ default:\r
+ ASSERT (0);\r
+ break;\r
+ }\r
+\r
+ if (DoConvert) {\r
+ break;\r
+ }\r
+\r
+ WantedListIndex = WantedListIndex->ForwardLink;\r
+ }\r
+ gBS->FreePool (DevicePathPtr);\r
+\r
+ //\r
+ // Check whether the new Usb device path is wanted\r
+ //\r
+ if (DoConvert){\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r
+\r
+/**\r
+ Recursively connnect every wanted usb child device to ensure they all fully connected.\r
+ Check all the child Usb IO handles in this bus, recursively connecte if it is wanted usb child device\r
+\r
+ @param UsbBusId point to EFI_USB_BUS_PROTOCOL interface\r
+\r
+ @retval EFI_SUCCESS\r
+ @retval EFI_INVALID_PARAMETER\r
+ @retval EFI_OUT_OF_RESOURCES\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusRecursivelyConnectWantedUsbIo (\r
+ IN EFI_USB_BUS_PROTOCOL *UsbBusId\r
+ )\r
+{\r
+ USB_BUS *Bus;\r
+ EFI_STATUS Status;\r
+ UINTN Index;\r
+ EFI_USB_IO_PROTOCOL *UsbIo;\r
+ USB_INTERFACE *UsbIf;\r
+ UINTN UsbIoHandleCount;\r
+ EFI_HANDLE *UsbIoBuffer;\r
+ EFI_DEVICE_PATH_PROTOCOL *UsbIoDevicePath;\r
+\r
+ if (UsbBusId == NULL){\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ Bus = USB_BUS_FROM_THIS (UsbBusId);\r
+\r
+ //\r
+ // Get all Usb IO handles in system\r
+ //\r
+ UsbIoHandleCount = 0;\r
+ Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiUsbIoProtocolGuid, NULL, &UsbIoHandleCount, &UsbIoBuffer);\r
+ if (Status == EFI_NOT_FOUND || UsbIoHandleCount == 0) {\r
+ return EFI_SUCCESS;\r
+ }\r
+ ASSERT (!EFI_ERROR (Status));\r
+\r
+ for (Index = 0; Index < UsbIoHandleCount; Index++) {\r
+ //\r
+ // Check whether the USB IO handle is a child of this bus\r
+ // Note: The usb child handle maybe invalid because of hot plugged out during the loop\r
+ //\r
+ UsbIoDevicePath = NULL;\r
+ Status = gBS->HandleProtocol (UsbIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &UsbIoDevicePath);\r
+ if (EFI_ERROR (Status) || UsbIoDevicePath == NULL) {\r
+ continue;\r
+ }\r
+ if (CompareMem (\r
+ UsbIoDevicePath,\r
+ Bus->DevicePath,\r
+ (GetDevicePathSize (Bus->DevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
+ ) != 0) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Get the child Usb IO interface\r
+ //\r
+ Status = gBS->HandleProtocol(\r
+ UsbIoBuffer[Index],\r
+ &gEfiUsbIoProtocolGuid,\r
+ (VOID **) &UsbIo\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ continue;\r
+ }\r
+ UsbIf = USB_INTERFACE_FROM_USBIO (UsbIo);\r
+\r
+ if (UsbBusIsWantedUsbIO (Bus, UsbIf)) {\r
+ if (!UsbIf->IsManaged) {\r
+ //\r
+ // Recursively connect the wanted Usb Io handle\r
+ //\r
+ DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL before connect is %d\n", UsbGetCurrentTpl ()));\r
+ Status = gBS->ConnectController (UsbIf->Handle, NULL, NULL, TRUE);\r
+ UsbIf->IsManaged = (BOOLEAN)!EFI_ERROR (Status);\r
+ DEBUG ((EFI_D_INFO, "UsbConnectDriver: TPL after connect is %d\n", UsbGetCurrentTpl()));\r
+ }\r
+ }\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
return Status;\r
}\r
\r
+\r
+/**\r
+ Install Usb Bus Protocol on host controller, and start the Usb bus\r
+\r
+ @param This The USB bus driver binding instance\r
+ @param Controller The controller to check\r
+ @param RemainingDevicePath The remaining device patch\r
+\r
+ @retval EFI_SUCCESS The controller is controlled by the usb bus\r
+ @retval EFI_ALREADY_STARTED The controller is already controlled by the usb bus\r
+ @retval EFI_OUT_OF_RESOURCES Failed to allocate resources\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusBuildProtocol (\r
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+ IN EFI_HANDLE Controller,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ )\r
+{\r
+ USB_BUS *UsbBus;\r
+ USB_DEVICE *RootHub;\r
+ USB_INTERFACE *RootIf;\r
+ EFI_STATUS Status;\r
+ EFI_STATUS Status2;\r
+\r
+ UsbBus = AllocateZeroPool (sizeof (USB_BUS));\r
+\r
+ if (UsbBus == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ UsbBus->Signature = USB_BUS_SIGNATURE;\r
+ UsbBus->HostHandle = Controller;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ (VOID **) &UsbBus->DevicePath,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to open device path %r\n", Status));\r
+\r
+ gBS->FreePool (UsbBus);\r
+ return Status;\r
+ }\r
+\r
+ //\r
+ // Get USB_HC2/USB_HC host controller protocol (EHCI/UHCI).\r
+ // This is for backward compatbility with EFI 1.x. In UEFI\r
+ // 2.x, USB_HC2 replaces USB_HC. We will open both USB_HC2\r
+ // and USB_HC because EHCI driver will install both protocols\r
+ // (for the same reason). If we don't consume both of them,\r
+ // the unconsumed one may be opened by others.\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiUsb2HcProtocolGuid,\r
+ (VOID **) &(UsbBus->Usb2Hc),\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+\r
+ Status2 = gBS->OpenProtocol (\r
+ Controller,\r
+ &gEfiUsbHcProtocolGuid,\r
+ (VOID **) &(UsbBus->UsbHc),\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_BY_DRIVER\r
+ );\r
+\r
+ if (EFI_ERROR (Status) && EFI_ERROR (Status2)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to open USB_HC/USB2_HC %r\n", Status));\r
+\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto CLOSE_HC;\r
+ }\r
+\r
+ UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
+ UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
+\r
+ //\r
+ // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
+ //\r
+ Status = gBS->InstallProtocolInterface (\r
+ &Controller,\r
+ &mUsbBusProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
+ &UsbBus->BusId\r
+ );\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
+ goto CLOSE_HC;\r
+ }\r
+\r
+ //\r
+ // Initial the wanted child device path list, and add first RemainingDevicePath\r
+ //\r
+ InitializeListHead (&UsbBus->WantedUsbIoDPList);\r
+ Status = UsbBusAddWantedUsbIoDP (&UsbBus->BusId, RemainingDevicePath);\r
+ ASSERT (!EFI_ERROR (Status));\r
+ //\r
+ // Create a fake usb device for root hub\r
+ //\r
+ RootHub = AllocateZeroPool (sizeof (USB_DEVICE));\r
+\r
+ if (RootHub == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto UNINSTALL_USBBUS;\r
+ }\r
+\r
+ RootIf = AllocateZeroPool (sizeof (USB_INTERFACE));\r
+\r
+ if (RootIf == NULL) {\r
+ gBS->FreePool (RootHub);\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto FREE_ROOTHUB;\r
+ }\r
+\r
+ RootHub->Bus = UsbBus;\r
+ RootHub->NumOfInterface = 1;\r
+ RootHub->Interfaces[0] = RootIf;\r
+ RootIf->Signature = USB_INTERFACE_SIGNATURE;\r
+ RootIf->Device = RootHub;\r
+ RootIf->DevicePath = UsbBus->DevicePath;\r
+\r
+ Status = mUsbRootHubApi.Init (RootIf);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to init root hub %r\n", Status));\r
+ goto FREE_ROOTHUB;\r
+ }\r
+\r
+ UsbBus->Devices[0] = RootHub;\r
+\r
+ DEBUG ((EFI_D_INFO, "UsbBusStart: usb bus started on %x, root hub %x\n", Controller, RootIf));\r
+ return EFI_SUCCESS;\r
+\r
+FREE_ROOTHUB:\r
+ if (RootIf != NULL) {\r
+ gBS->FreePool (RootIf);\r
+ }\r
+ if (RootHub != NULL) {\r
+ gBS->FreePool (RootHub);\r
+ }\r
+\r
+UNINSTALL_USBBUS:\r
+ gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &UsbBus->BusId);\r
+\r
+CLOSE_HC:\r
+ if (UsbBus->Usb2Hc != NULL) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiUsb2HcProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ }\r
+ if (UsbBus->UsbHc != NULL) {\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiUsbHcProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ }\r
+ gBS->CloseProtocol (\r
+ Controller,\r
+ &gEfiDevicePathProtocolGuid,\r
+ This->DriverBindingHandle,\r
+ Controller\r
+ );\r
+ gBS->FreePool (UsbBus);\r
+\r
+ DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to start bus driver %r\n", Status));\r
+ return Status;\r
+}\r
+\r
EFI_USB_IO_PROTOCOL mUsbIoProtocol = {\r
UsbIoControlTransfer,\r
UsbIoBulkTransfer,\r
DevicePathNode.DevPath = RemainingDevicePath;\r
\r
if ((DevicePathNode.DevPath->Type != MESSAGING_DEVICE_PATH) ||\r
- (DevicePathNode.DevPath->SubType != MSG_USB_DP) ||\r
- (DevicePathNodeLength (DevicePathNode.DevPath) != sizeof (USB_DEVICE_PATH))) {\r
+ (DevicePathNode.DevPath->SubType != MSG_USB_DP &&\r
+ DevicePathNode.DevPath->SubType != MSG_USB_CLASS_DP\r
+ && DevicePathNode.DevPath->SubType != MSG_USB_WWID_DP\r
+ )) {\r
\r
return EFI_UNSUPPORTED;\r
}\r
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
)\r
{\r
- USB_BUS *UsbBus;\r
- USB_DEVICE *RootHub;\r
- USB_INTERFACE *RootIf;\r
- EFI_USB_BUS_PROTOCOL *UsbBusId;\r
- EFI_STATUS Status;\r
- EFI_STATUS Status2;\r
+ EFI_USB_BUS_PROTOCOL *UsbBusId;\r
+ EFI_STATUS Status;\r
\r
//\r
// Locate the USB bus protocol, if it is found, USB bus\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
\r
- if (!EFI_ERROR (Status)) {\r
- return EFI_ALREADY_STARTED;\r
- }\r
-\r
- UsbBus = AllocateZeroPool (sizeof (USB_BUS));\r
-\r
- if (UsbBus == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- UsbBus->Signature = USB_BUS_SIGNATURE;\r
- UsbBus->HostHandle = Controller;\r
-\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiDevicePathProtocolGuid,\r
- (VOID **) &UsbBus->DevicePath,\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
-\r
if (EFI_ERROR (Status)) {\r
- DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to open device path %r\n", Status));\r
-\r
- gBS->FreePool (UsbBus);\r
- return Status;\r
- }\r
-\r
- //\r
- // Get USB_HC2/USB_HC host controller protocol (EHCI/UHCI).\r
- // This is for backward compatbility with EFI 1.x. In UEFI\r
- // 2.x, USB_HC2 replaces USB_HC. We will open both USB_HC2\r
- // and USB_HC because EHCI driver will install both protocols\r
- // (for the same reason). If we don't consume both of them,\r
- // the unconsumed one may be opened by others.\r
- //\r
- Status = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiUsb2HcProtocolGuid,\r
- (VOID **) &(UsbBus->Usb2Hc),\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
-\r
- Status2 = gBS->OpenProtocol (\r
- Controller,\r
- &gEfiUsbHcProtocolGuid,\r
- (VOID **) &(UsbBus->UsbHc),\r
- This->DriverBindingHandle,\r
- Controller,\r
- EFI_OPEN_PROTOCOL_BY_DRIVER\r
- );\r
-\r
- if (EFI_ERROR (Status) && EFI_ERROR (Status2)) {\r
- DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to open USB_HC/USB2_HC %r\n", Status));\r
-\r
- Status = EFI_DEVICE_ERROR;\r
- goto CLOSE_HC;\r
- }\r
-\r
- UsbHcReset (UsbBus, EFI_USB_HC_RESET_GLOBAL);\r
- UsbHcSetState (UsbBus, EfiUsbHcStateOperational);\r
-\r
- //\r
- // Install an EFI_USB_BUS_PROTOCOL to host controler to identify it.\r
- //\r
- Status = gBS->InstallProtocolInterface (\r
- &Controller,\r
- &mUsbBusProtocolGuid,\r
- EFI_NATIVE_INTERFACE,\r
- &UsbBus->BusId\r
- );\r
-\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "UsbBusStart: Failed to install bus protocol %r\n", Status));\r
- goto CLOSE_HC;\r
- }\r
-\r
- //\r
- // Create a fake usb device for root hub\r
- //\r
- RootHub = AllocateZeroPool (sizeof (USB_DEVICE));\r
-\r
- if (RootHub == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto UNINSTALL_USBBUS;\r
- }\r
-\r
- RootIf = AllocateZeroPool (sizeof (USB_INTERFACE));\r
-\r
- if (RootIf == NULL) {\r
- gBS->FreePool (RootHub);\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto FREE_ROOTHUB;\r
- }\r
-\r
- RootHub->Bus = UsbBus;\r
- RootHub->NumOfInterface = 1;\r
- RootHub->Interfaces[0] = RootIf;\r
- RootIf->Signature = USB_INTERFACE_SIGNATURE;\r
- RootIf->Device = RootHub;\r
- RootIf->DevicePath = UsbBus->DevicePath;\r
- \r
- Status = mUsbRootHubApi.Init (RootIf);\r
-\r
- if (EFI_ERROR (Status)) {\r
- DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to init root hub %r\n", Status));\r
- goto FREE_ROOTHUB;\r
+ //\r
+ // If first start, build the bus execute enviorment and install bus protocol\r
+ //\r
+ Status = UsbBusBuildProtocol (This, Controller, RemainingDevicePath);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+ //\r
+ // Try get the Usb Bus protocol interface again\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Controller,\r
+ &mUsbBusProtocolGuid,\r
+ (VOID **) &UsbBusId,\r
+ This->DriverBindingHandle,\r
+ Controller,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ ASSERT (!EFI_ERROR (Status));\r
+ } else {\r
+ //\r
+ // USB Bus driver need to control the recursive connect policy of the bus, only those wanted\r
+ // usb child device will be recursively connected.\r
+ // The RemainingDevicePath indicate the child usb device which user want to fully recursively connecte this time.\r
+ // All wanted usb child devices will be remembered by the usb bus driver itself.\r
+ // If RemainingDevicePath == NULL, all the usb child devices in the usb bus are wanted devices.\r
+ //\r
+ // Save the passed in RemainingDevicePath this time\r
+ //\r
+ Status = UsbBusAddWantedUsbIoDP (UsbBusId, RemainingDevicePath);\r
+ ASSERT (!EFI_ERROR (Status));\r
+ //\r
+ // Ensure all wanted child usb devices are fully recursively connected\r
+ //\r
+ Status = UsbBusRecursivelyConnectWantedUsbIo (UsbBusId);\r
+ ASSERT (!EFI_ERROR (Status));\r
}\r
\r
- UsbBus->Devices[0] = RootHub;\r
\r
- DEBUG (( EFI_D_INFO, "UsbBusStart: usb bus started on %x, root hub %x\n", Controller, RootIf));\r
return EFI_SUCCESS;\r
- \r
-FREE_ROOTHUB:\r
- if (RootIf != NULL) {\r
- gBS->FreePool (RootIf);\r
- }\r
- if (RootHub != NULL) {\r
- gBS->FreePool (RootHub);\r
- }\r
- \r
-UNINSTALL_USBBUS:\r
- gBS->UninstallProtocolInterface (Controller, &mUsbBusProtocolGuid, &UsbBus->BusId);\r
- \r
-CLOSE_HC:\r
- if (UsbBus->Usb2Hc != NULL) {\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiUsb2HcProtocolGuid,\r
- This->DriverBindingHandle,\r
- Controller\r
- );\r
- }\r
- if (UsbBus->UsbHc != NULL) {\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiUsbHcProtocolGuid,\r
- This->DriverBindingHandle,\r
- Controller\r
- );\r
- }\r
- gBS->CloseProtocol (\r
- Controller,\r
- &gEfiDevicePathProtocolGuid,\r
- This->DriverBindingHandle,\r
- Controller\r
- );\r
- gBS->FreePool (UsbBus);\r
-\r
- DEBUG (( EFI_D_ERROR, "UsbBusStart: Failed to start bus driver %r\n", Status));\r
- return Status;\r
}\r
\r
\r
Status = EFI_SUCCESS;\r
\r
if (NumberOfChildren > 0) {\r
- OldTpl = gBS->RaiseTPL (USB_BUS_TPL);\r
+ //\r
+ // BugBug: Raise TPL to callback level instead of USB_BUS_TPL to avoid TPL conflict\r
+ //\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
\r
for (Index = 0; Index < NumberOfChildren; Index++) {\r
Status = gBS->OpenProtocol (\r
//\r
// Stop the root hub, then free all the devices\r
//\r
- OldTpl = gBS->RaiseTPL (USB_BUS_TPL);\r
+ // BugBug: Raise TPL to callback level instead of USB_BUS_TPL to avoid TPL conflict\r
+ //\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
UsbHcSetState (Bus, EfiUsbHcStateHalt);\r
\r
RootHub = Bus->Devices[0];\r
\r
gBS->FreePool (RootIf);\r
gBS->FreePool (RootHub);\r
+ Status = UsbBusFreeUsbDPList (&Bus->WantedUsbIoDPList);\r
+ ASSERT (!EFI_ERROR (Status));\r
\r
//\r
// Uninstall the bus identifier and close USB_HC/USB2_HC protocols\r
#include <Protocol/UsbIo.h>\r
#include <Protocol/DevicePath.h>\r
\r
+#include <library/BaseLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/UefiDriverEntryPoint.h>\r
//\r
USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
\r
- // \r
+ //\r
// Wait for port statue reg change, set by experience\r
//\r
USB_WAIT_PORT_STS_CHANGE_STALL = 5 * USB_BUS_1_MILLISECOND,\r
USB_SET_PORT_POWER_STALL = 2 * USB_BUS_1_MILLISECOND,\r
\r
//\r
- // Wait for port reset, refers to specification \r
- // [USB20-7.1.7.5, it says 10ms for hub and 50ms for \r
+ // Wait for port reset, refers to specification\r
+ // [USB20-7.1.7.5, it says 10ms for hub and 50ms for\r
// root hub]\r
//\r
USB_SET_PORT_RESET_STALL = 20 * USB_BUS_1_MILLISECOND,\r
\r
//\r
// Wait for set roothub port enable, set by experience\r
- // \r
+ //\r
USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,\r
\r
//\r
- // Send general device request timeout, refers to \r
+ // Send general device request timeout, refers to\r
// specification[USB20-11.24.1]\r
//\r
USB_GENERAL_DEVICE_REQUEST_TIMEOUT = 50 * USB_BUS_1_MILLISECOND,\r
// Send clear feature request timeout, set by experience\r
//\r
USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND,\r
- \r
+\r
//\r
// Bus raises TPL to TPL_NOTIFY to serialize all its operations\r
// to protect shared data structures.\r
// for root hub. Device with address i is at Devices[i].\r
//\r
USB_DEVICE *Devices[USB_MAX_DEVICES];\r
+\r
+ //\r
+ // USB Bus driver need to control the recursive connect policy of the bus, only those wanted\r
+ // usb child device will be recursively connected.\r
+ //\r
+ // WantedUsbIoDPList tracks the Usb child devices which user want to recursivly fully connecte,\r
+ // every wanted child device is stored in a item of the WantedUsbIoDPList, whose structrure is\r
+ // DEVICE_PATH_LIST_ITEM\r
+ //\r
+ LIST_ENTRY WantedUsbIoDPList;\r
+\r
};\r
\r
+#define USB_US_LAND_ID 0x0409\r
+\r
+#define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')\r
+typedef struct _DEVICE_PATH_LIST_ITEM{\r
+ UINTN Signature;\r
+ LIST_ENTRY Link;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+} DEVICE_PATH_LIST_ITEM;\r
+\r
+typedef struct {\r
+ USB_CLASS_DEVICE_PATH UsbClass;\r
+ EFI_DEVICE_PATH_PROTOCOL End;\r
+} USB_CLASS_FORMAT_DEVICE_PATH;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusFreeUsbDPList (\r
+ IN LIST_ENTRY *UsbIoDPList\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusAddWantedUsbIoDP (\r
+ IN EFI_USB_BUS_PROTOCOL *UsbBusId,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
+ );\r
+\r
+BOOLEAN\r
+EFIAPI\r
+UsbBusIsWantedUsbIO (\r
+ IN USB_BUS *Bus,\r
+ IN USB_INTERFACE *UsbIf\r
+ );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UsbBusRecursivelyConnectWantedUsbIo (\r
+ IN EFI_USB_BUS_PROTOCOL *UsbBusId\r
+ );\r
+\r
extern EFI_USB_IO_PROTOCOL mUsbIoProtocol;\r
extern EFI_DRIVER_BINDING_PROTOCOL mUsbBusDriverBinding;\r
extern EFI_COMPONENT_NAME_PROTOCOL mUsbBusComponentName;\r