\r
Usb bus enumeration support.\r
\r
-Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
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
\r
#include "UsbBus.h"\r
\r
-\r
/**\r
Return the endpoint descriptor in this interface.\r
\r
Device->ParentAddr = ParentIf->Device->Address;\r
Device->ParentIf = ParentIf;\r
Device->ParentPort = ParentPort;\r
+ Device->Tier = ParentIf->Device->Tier + 1;\r
return Device;\r
}\r
\r
USB_BUS *Bus;\r
USB_DEVICE *Child;\r
EFI_STATUS Status;\r
- UINT8 Index;\r
+ UINTN Index;\r
\r
Bus = Device->Bus;\r
\r
// Remove all the devices on its downstream ports. Search from devices[1].\r
// Devices[0] is the root hub.\r
//\r
- for (Index = 1; Index < USB_MAX_DEVICES; Index++) {\r
+ for (Index = 1; Index < mMaxUsbDeviceNum; Index++) {\r
Child = Bus->Devices[Index];\r
\r
if ((Child == NULL) || (Child->ParentAddr != Device->Address)) {\r
\r
DEBUG (( EFI_D_INFO, "UsbRemoveDevice: device %d removed\n", Device->Address));\r
\r
- ASSERT (Device->Address < USB_MAX_DEVICES);\r
+ ASSERT (Device->Address < mMaxUsbDeviceNum);\r
Bus->Devices[Device->Address] = NULL;\r
UsbFreeDevice (Device);\r
\r
//\r
// Start checking from device 1, device 0 is the root hub\r
//\r
- for (Index = 1; Index < USB_MAX_DEVICES; Index++) {\r
+ for (Index = 1; Index < mMaxUsbDeviceNum; Index++) {\r
Device = Bus->Devices[Index];\r
\r
if ((Device != NULL) && (Device->ParentAddr == HubIf->Device->Address) &&\r
USB_DEVICE *Child;\r
USB_DEVICE *Parent;\r
EFI_USB_PORT_STATUS PortState;\r
- UINT8 Address;\r
+ UINTN Address;\r
UINT8 Config;\r
EFI_STATUS Status;\r
\r
- Address = USB_MAX_DEVICES;\r
+ Address = mMaxUsbDeviceNum;\r
Parent = HubIf->Device;\r
Bus = Parent->Bus;\r
HubApi = HubIf->HubApi;\r
goto ON_ERROR;\r
}\r
\r
- if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_LOW_SPEED)) {\r
- Child->Speed = EFI_USB_SPEED_LOW;\r
-\r
+ if (!USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: No device presented at port %d\n", Port));\r
+ goto ON_ERROR;\r
+ } else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_SUPER_SPEED)){\r
+ Child->Speed = EFI_USB_SPEED_SUPER;\r
+ Child->MaxPacket0 = 512;\r
} else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_HIGH_SPEED)) {\r
- Child->Speed = EFI_USB_SPEED_HIGH;\r
-\r
+ Child->Speed = EFI_USB_SPEED_HIGH;\r
+ Child->MaxPacket0 = 64;\r
+ } else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_LOW_SPEED)) {\r
+ Child->Speed = EFI_USB_SPEED_LOW;\r
+ Child->MaxPacket0 = 8;\r
} else {\r
- Child->Speed = EFI_USB_SPEED_FULL;\r
+ Child->Speed = EFI_USB_SPEED_FULL;\r
+ Child->MaxPacket0 = 8;\r
}\r
\r
DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: device is of %d speed\n", Child->Speed));\r
// a time) , and ready to respond to control transfer at EP 0.\r
//\r
\r
- //\r
- // Host sends a Get_Descriptor request to learn the max packet\r
- // size of default pipe (only part of the device's descriptor).\r
- //\r
- Status = UsbGetMaxPacketSize0 (Child);\r
-\r
- if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status));\r
- goto ON_ERROR;\r
- }\r
-\r
- DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0));\r
-\r
//\r
// Host assigns an address to the device. Device completes the\r
// status stage with default address, then switches to new address.\r
// ADDRESS state. Address zero is reserved for root hub.\r
//\r
- for (Address = 1; Address < USB_MAX_DEVICES; Address++) {\r
+ for (Address = 1; Address < mMaxUsbDeviceNum; Address++) {\r
if (Bus->Devices[Address] == NULL) {\r
break;\r
}\r
}\r
\r
- if (Address == USB_MAX_DEVICES) {\r
+ if (Address == mMaxUsbDeviceNum) {\r
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: address pool is full for port %d\n", Port));\r
\r
Status = EFI_ACCESS_DENIED;\r
goto ON_ERROR;\r
}\r
\r
+ Status = UsbSetAddress (Child, (UINT8)Address);\r
+ Child->Address = (UINT8)Address;\r
Bus->Devices[Address] = Child;\r
- Status = UsbSetAddress (Child, Address);\r
- Child->Address = Address;\r
\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to set device address - %r\n", Status));\r
goto ON_ERROR;\r
}\r
- \r
+\r
gBS->Stall (USB_SET_DEVICE_ADDRESS_STALL);\r
\r
DEBUG ((EFI_D_INFO, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address));\r
\r
+ //\r
+ // Host sends a Get_Descriptor request to learn the max packet\r
+ // size of default pipe (only part of the device's descriptor).\r
+ //\r
+ Status = UsbGetMaxPacketSize0 (Child);\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status));\r
+ goto ON_ERROR;\r
+ }\r
+\r
+ DEBUG (( EFI_D_INFO, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child->MaxPacket0));\r
+\r
//\r
// Host learns about the device's abilities by requesting device's\r
// entire descriptions.\r
return EFI_SUCCESS;\r
\r
ON_ERROR:\r
- if (Address != USB_MAX_DEVICES) {\r
+ if (Address != mMaxUsbDeviceNum) {\r
Bus->Devices[Address] = NULL;\r
}\r
\r
return Status;\r
}\r
\r
- if (PortState.PortChangeStatus == 0) {\r
+ //\r
+ // Only handle connection/enable/overcurrent/reset change.\r
+ // Usb super speed hub may report other changes, such as warm reset change. Ignore them.\r
+ //\r
+ if ((PortState.PortChangeStatus & (USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | USB_PORT_STAT_C_OVERCURRENT | USB_PORT_STAT_C_RESET)) == 0) {\r
return EFI_SUCCESS;\r
}\r
\r
- DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %x, change - %x on %p\n",\r
- Port, PortState.PortStatus, PortState.PortChangeStatus, HubIf));\r
+ DEBUG (( EFI_D_INFO, "UsbEnumeratePort: port %d state - %02x, change - %02x on %p\n",\r
+ Port, PortState.PortChangeStatus, PortState.PortStatus, HubIf));\r
\r
//\r
// This driver only process two kinds of events now: over current and\r