\r
Usb Bus Driver Binding and Bus IO Protocol.\r
\r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include <Library/UefiLib.h>\r
#include <Library/DevicePathLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
\r
\r
#include <IndustryStandard/Usb.h>\r
#include "UsbHub.h"\r
#include "UsbEnumer.h"\r
\r
-typedef enum {\r
- USB_MAX_LANG_ID = 16,\r
- USB_MAX_INTERFACE = 16,\r
- USB_MAX_DEVICES = 128,\r
+//\r
+// USB bus timeout experience values\r
+//\r
\r
- USB_BUS_1_MILLISECOND = 1000,\r
+#define USB_MAX_LANG_ID 16\r
+#define USB_MAX_INTERFACE 16\r
+#define USB_MAX_DEVICES 128\r
\r
- //\r
- // Roothub and hub's polling interval, set by experience,\r
- // The unit of roothub is 100us, means 1s as interval, and\r
- // the unit of hub is 1ms, means 64ms as interval.\r
- //\r
- USB_ROOTHUB_POLL_INTERVAL = 1000 * 10000U,\r
- USB_HUB_POLL_INTERVAL = 64,\r
+#define USB_BUS_1_MILLISECOND 1000\r
\r
- //\r
- // Wait for port stable to work, refers to specification\r
- // [USB20-9.1.2]\r
- //\r
- USB_WAIT_PORT_STABLE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Roothub and hub's polling interval, set by experience,\r
+// The unit of roothub is 100us, means 100ms as interval, and\r
+// the unit of hub is 1ms, means 64ms as interval.\r
+//\r
+#define USB_ROOTHUB_POLL_INTERVAL (100 * 10000U)\r
+#define USB_HUB_POLL_INTERVAL 64\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
+//\r
+// Wait for port stable to work, refers to specification\r
+// [USB20-9.1.2]\r
+//\r
+#define USB_WAIT_PORT_STABLE_STALL (100 * USB_BUS_1_MILLISECOND)\r
\r
- //\r
- // Wait for set device address, refers to specification\r
- // [USB20-9.2.6.3, it says 2ms]\r
- //\r
- USB_SET_DEVICE_ADDRESS_STALL = 20 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Wait for port statue reg change, set by experience\r
+//\r
+#define USB_WAIT_PORT_STS_CHANGE_STALL (100)\r
\r
- //\r
- // Wait for retry max packet size, set by experience\r
- //\r
- USB_RETRY_MAX_PACK_SIZE_STALL = 100 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Wait for set device address, refers to specification\r
+// [USB20-9.2.6.3, it says 2ms]\r
+//\r
+#define USB_SET_DEVICE_ADDRESS_STALL (2 * USB_BUS_1_MILLISECOND)\r
\r
- //\r
- // Wait for hub port power-on, refers to specification\r
- // [USB20-11.23.2]\r
- //\r
- USB_SET_PORT_POWER_STALL = 2 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Wait for retry max packet size, set by experience\r
+//\r
+#define USB_RETRY_MAX_PACK_SIZE_STALL (100 * 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
- // root hub]\r
- //\r
- USB_SET_PORT_RESET_STALL = 20 * USB_BUS_1_MILLISECOND,\r
- USB_SET_ROOT_PORT_RESET_STALL = 50 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Wait for hub port power-on, refers to specification\r
+// [USB20-11.23.2]\r
+//\r
+#define USB_SET_PORT_POWER_STALL (2 * USB_BUS_1_MILLISECOND)\r
\r
- //\r
- // Wait for clear roothub port reset, set by experience\r
- //\r
- USB_CLR_ROOT_PORT_RESET_STALL = 1 * USB_BUS_1_MILLISECOND,\r
+//\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
+// According to USB2.0, Chapter 11.5.1.5 Resetting,\r
+// the worst case for TDRST is 20ms\r
+//\r
+#define USB_SET_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)\r
+#define USB_SET_ROOT_PORT_RESET_STALL (50 * USB_BUS_1_MILLISECOND)\r
\r
- //\r
- // Wait for set roothub port enable, set by experience\r
- //\r
- USB_SET_ROOT_PORT_ENABLE_STALL = 20 * USB_BUS_1_MILLISECOND,\r
+//\r
+// Wait for port recovery to accept SetAddress, refers to specification\r
+// [USB20-7.1.7.5, it says 10 ms for TRSTRCY]\r
+//\r
+#define USB_SET_PORT_RECOVERY_STALL (10 * USB_BUS_1_MILLISECOND)\r
\r
- //\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
+//\r
+// Wait for clear roothub port reset, set by experience\r
+//\r
+#define USB_CLR_ROOT_PORT_RESET_STALL (20 * USB_BUS_1_MILLISECOND)\r
\r
- //\r
- // Send clear feature request timeout, set by experience\r
- //\r
- USB_CLEAR_FEATURE_REQUEST_TIMEOUT = 10 * USB_BUS_1_MILLISECOND\r
-}USB_BUS_TIMEOUT_EXPERIENCE_VALUE;\r
+//\r
+// Wait for set roothub port enable, set by experience\r
+//\r
+#define USB_SET_ROOT_PORT_ENABLE_STALL (20 * USB_BUS_1_MILLISECOND)\r
+\r
+//\r
+// Send general device request timeout.\r
+//\r
+// The USB Specification 2.0, section 11.24.1 recommends a value of\r
+// 50 milliseconds. We use a value of 500 milliseconds to work\r
+// around slower hubs and devices.\r
+//\r
+#define USB_GENERAL_DEVICE_REQUEST_TIMEOUT 500\r
+\r
+//\r
+// Send clear feature request timeout, set by experience\r
+//\r
+#define USB_CLEAR_FEATURE_REQUEST_TIMEOUT 10\r
\r
//\r
// Bus raises TPL to TPL_NOTIFY to serialize all its operations\r
//\r
#define USB_BUS_TPL TPL_NOTIFY\r
\r
-#define USB_INTERFACE_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'I')\r
-#define USB_BUS_SIGNATURE EFI_SIGNATURE_32 ('U', 'S', 'B', 'B')\r
+#define USB_INTERFACE_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'I')\r
+#define USB_BUS_SIGNATURE SIGNATURE_32 ('U', 'S', 'B', 'B')\r
\r
#define USB_BIT(a) ((UINTN)(1 << (a)))\r
#define USB_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))\r
\r
-#define EFI_USB_BUS_PROTOCOL_GUID \\r
- {0x2B2F68CC, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75}}\r
-\r
#define USB_INTERFACE_FROM_USBIO(a) \\r
CR(a, USB_INTERFACE, UsbIo, USB_INTERFACE_SIGNATURE)\r
\r
\r
//\r
// Used to locate USB_BUS\r
+// UsbBusProtocol is the private protocol.\r
+// gEfiCallerIdGuid will be used as its protocol guid.\r
//\r
typedef struct _EFI_USB_BUS_PROTOCOL {\r
UINT64 Reserved;\r
//\r
UINT8 Speed;\r
UINT8 Address;\r
- UINT8 MaxPacket0;\r
+ UINT32 MaxPacket0;\r
\r
//\r
// The device's descriptors and its configuration\r
UINT8 ParentAddr;\r
USB_INTERFACE *ParentIf;\r
UINT8 ParentPort; // Start at 0\r
+ UINT8 Tier;\r
+ BOOLEAN DisconnectFail;\r
};\r
\r
//\r
EFI_USB2_HC_PROTOCOL *Usb2Hc;\r
EFI_USB_HC_PROTOCOL *UsbHc;\r
\r
+ //\r
+ // Recorded the max supported usb devices.\r
+ // XHCI can support up to 255 devices.\r
+ // EHCI/UHCI/OHCI supports up to 127 devices.\r
+ //\r
+ UINT32 MaxDevices;\r
//\r
// An array of device that is on the bus. Devices[0] is\r
// for root hub. Device with address i is at Devices[i].\r
//\r
- USB_DEVICE *Devices[USB_MAX_DEVICES];\r
+ USB_DEVICE *Devices[256];\r
\r
//\r
// USB Bus driver need to control the recursive connect policy of the bus, only those wanted\r
\r
#define USB_US_LAND_ID 0x0409\r
\r
-#define DEVICE_PATH_LIST_ITEM_SIGNATURE EFI_SIGNATURE_32('d','p','l','i')\r
+#define DEVICE_PATH_LIST_ITEM_SIGNATURE SIGNATURE_32('d','p','l','i')\r
typedef struct _DEVICE_PATH_LIST_ITEM{\r
UINTN Signature;\r
LIST_ENTRY Link;\r
\r
@param This The USB IO instance.\r
@param LangIDTable The table to return the language IDs.\r
- @param TableSize The number of supported languanges.\r
+ @param TableSize The size, in bytes, of the table LangIDTable.\r
\r
@retval EFI_SUCCESS The language ID is return.\r
\r