3 Usb bus enumeration support.
5 Copyright (c) 2007 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Return the endpoint descriptor in this interface.
22 @param UsbIf The interface to search in.
23 @param EpAddr The address of the endpoint to return.
25 @return The endpoint descriptor or NULL.
30 IN USB_INTERFACE
*UsbIf
,
34 USB_ENDPOINT_DESC
*EpDesc
;
38 NumEndpoints
= UsbIf
->IfSetting
->Desc
.NumEndpoints
;
40 for (Index
= 0; Index
< NumEndpoints
; Index
++) {
41 EpDesc
= UsbIf
->IfSetting
->Endpoints
[Index
];
43 if (EpDesc
->Desc
.EndpointAddress
== EpAddr
) {
53 Free the resource used by USB interface.
55 @param UsbIf The USB interface to free.
60 IN USB_INTERFACE
*UsbIf
63 UsbCloseHostProtoByChild (UsbIf
->Device
->Bus
, UsbIf
->Handle
);
65 gBS
->UninstallMultipleProtocolInterfaces (
67 &gEfiDevicePathProtocolGuid
,
69 &gEfiUsbIoProtocolGuid
,
74 if (UsbIf
->DevicePath
!= NULL
) {
75 FreePool (UsbIf
->DevicePath
);
83 Create an interface for the descriptor IfDesc. Each
84 device's configuration can have several interfaces.
86 @param Device The device has the interface descriptor.
87 @param IfDesc The interface descriptor.
89 @return The created USB interface for the descriptor, or NULL.
94 IN USB_DEVICE
*Device
,
95 IN USB_INTERFACE_DESC
*IfDesc
98 USB_DEVICE_PATH UsbNode
;
100 USB_INTERFACE
*HubIf
;
103 UsbIf
= AllocateZeroPool (sizeof (USB_INTERFACE
));
109 UsbIf
->Signature
= USB_INTERFACE_SIGNATURE
;
110 UsbIf
->Device
= Device
;
111 UsbIf
->IfDesc
= IfDesc
;
112 ASSERT (IfDesc
->ActiveIndex
< USB_MAX_INTERFACE_SETTING
);
113 UsbIf
->IfSetting
= IfDesc
->Settings
[IfDesc
->ActiveIndex
];
118 sizeof (EFI_USB_IO_PROTOCOL
)
122 // Install protocols for USBIO and device path
124 UsbNode
.Header
.Type
= MESSAGING_DEVICE_PATH
;
125 UsbNode
.Header
.SubType
= MSG_USB_DP
;
126 UsbNode
.ParentPortNumber
= Device
->ParentPort
;
127 UsbNode
.InterfaceNumber
= UsbIf
->IfSetting
->Desc
.InterfaceNumber
;
129 SetDevicePathNodeLength (&UsbNode
.Header
, sizeof (UsbNode
));
131 HubIf
= Device
->ParentIf
;
132 ASSERT (HubIf
!= NULL
);
134 UsbIf
->DevicePath
= AppendDevicePathNode (HubIf
->DevicePath
, &UsbNode
.Header
);
136 if (UsbIf
->DevicePath
== NULL
) {
137 DEBUG ((EFI_D_ERROR
, "UsbCreateInterface: failed to create device path\n"));
139 Status
= EFI_OUT_OF_RESOURCES
;
143 Status
= gBS
->InstallMultipleProtocolInterfaces (
145 &gEfiDevicePathProtocolGuid
,
147 &gEfiUsbIoProtocolGuid
,
152 if (EFI_ERROR (Status
)) {
153 DEBUG ((EFI_D_ERROR
, "UsbCreateInterface: failed to install UsbIo - %r\n", Status
));
158 // Open USB Host Controller Protocol by Child
160 Status
= UsbOpenHostProtoByChild (Device
->Bus
, UsbIf
->Handle
);
162 if (EFI_ERROR (Status
)) {
163 gBS
->UninstallMultipleProtocolInterfaces (
165 &gEfiDevicePathProtocolGuid
,
167 &gEfiUsbIoProtocolGuid
,
172 DEBUG ((EFI_D_ERROR
, "UsbCreateInterface: failed to open host for child - %r\n", Status
));
179 if (UsbIf
->DevicePath
!= NULL
) {
180 FreePool (UsbIf
->DevicePath
);
189 Free the resource used by this USB device.
191 @param Device The USB device to free.
196 IN USB_DEVICE
*Device
199 if (Device
->DevDesc
!= NULL
) {
200 UsbFreeDevDesc (Device
->DevDesc
);
203 gBS
->FreePool (Device
);
208 Create a device which is on the parent's ParentPort port.
210 @param ParentIf The parent HUB interface.
211 @param ParentPort The port on the HUB this device is connected to.
213 @return Created USB device, Or NULL.
218 IN USB_INTERFACE
*ParentIf
,
224 ASSERT (ParentIf
!= NULL
);
226 Device
= AllocateZeroPool (sizeof (USB_DEVICE
));
228 if (Device
== NULL
) {
232 Device
->Bus
= ParentIf
->Device
->Bus
;
233 Device
->MaxPacket0
= 8;
234 Device
->ParentAddr
= ParentIf
->Device
->Address
;
235 Device
->ParentIf
= ParentIf
;
236 Device
->ParentPort
= ParentPort
;
242 Connect the USB interface with its driver. EFI USB bus will
243 create a USB interface for each separate interface descriptor.
245 @param UsbIf The interface to connect driver to.
247 @return EFI_SUCCESS Interface is managed by some driver.
248 @return Others Failed to locate a driver for this interface.
253 IN USB_INTERFACE
*UsbIf
259 Status
= EFI_SUCCESS
;
262 // Hub is maintained by the USB bus driver. Otherwise try to
263 // connect drivers with this interface
265 if (UsbIsHubInterface (UsbIf
)) {
266 DEBUG ((EFI_D_INFO
, "UsbConnectDriver: found a hub device\n"));
267 Status
= mUsbHubApi
.Init (UsbIf
);
271 // This function is called in both UsbIoControlTransfer and
272 // the timer callback in hub enumeration. So, at least it is
273 // called at TPL_CALLBACK. Some driver sitting on USB has
274 // twisted TPL used. It should be no problem for us to connect
275 // or disconnect at CALLBACK.
279 // Only recursively wanted usb child device
281 if (UsbBusIsWantedUsbIO (UsbIf
->Device
->Bus
, UsbIf
)) {
282 OldTpl
= UsbGetCurrentTpl ();
283 DEBUG ((EFI_D_INFO
, "UsbConnectDriver: TPL before connect is %d, %p\n", (UINT32
)OldTpl
, UsbIf
->Handle
));
285 gBS
->RestoreTPL (TPL_CALLBACK
);
287 Status
= gBS
->ConnectController (UsbIf
->Handle
, NULL
, NULL
, TRUE
);
288 UsbIf
->IsManaged
= (BOOLEAN
)!EFI_ERROR (Status
);
290 DEBUG ((EFI_D_INFO
, "UsbConnectDriver: TPL after connect is %d\n", (UINT32
)UsbGetCurrentTpl()));
291 ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK
);
293 gBS
->RaiseTPL (OldTpl
);
302 Select an alternate setting for the interface.
303 Each interface can have several mutually exclusive
304 settings. Only one setting is active. It will
305 also reset its endpoints' toggle to zero.
307 @param IfDesc The interface descriptor to set.
308 @param Alternate The alternate setting number to locate.
310 @retval EFI_NOT_FOUND There is no setting with this alternate index.
311 @retval EFI_SUCCESS The interface is set to Alternate setting.
316 IN USB_INTERFACE_DESC
*IfDesc
,
320 USB_INTERFACE_SETTING
*Setting
;
324 // Locate the active alternate setting
328 for (Index
= 0; Index
< IfDesc
->NumOfSetting
; Index
++) {
329 ASSERT (Index
< USB_MAX_INTERFACE_SETTING
);
330 Setting
= IfDesc
->Settings
[Index
];
332 if (Setting
->Desc
.AlternateSetting
== Alternate
) {
337 if (Index
== IfDesc
->NumOfSetting
) {
338 return EFI_NOT_FOUND
;
341 IfDesc
->ActiveIndex
= Index
;
343 ASSERT (Setting
!= NULL
);
344 DEBUG ((EFI_D_INFO
, "UsbSelectSetting: setting %d selected for interface %d\n",
345 Alternate
, Setting
->Desc
.InterfaceNumber
));
348 // Reset the endpoint toggle to zero
350 for (Index
= 0; Index
< Setting
->Desc
.NumEndpoints
; Index
++) {
351 Setting
->Endpoints
[Index
]->Toggle
= 0;
359 Select a new configuration for the device. Each
360 device may support several configurations.
362 @param Device The device to select configuration.
363 @param ConfigValue The index of the configuration ( != 0).
365 @retval EFI_NOT_FOUND There is no configuration with the index.
366 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource.
367 @retval EFI_SUCCESS The configuration is selected.
372 IN USB_DEVICE
*Device
,
376 USB_DEVICE_DESC
*DevDesc
;
377 USB_CONFIG_DESC
*ConfigDesc
;
378 USB_INTERFACE_DESC
*IfDesc
;
379 USB_INTERFACE
*UsbIf
;
384 // Locate the active config, then set the device's pointer
386 DevDesc
= Device
->DevDesc
;
389 for (Index
= 0; Index
< DevDesc
->Desc
.NumConfigurations
; Index
++) {
390 ConfigDesc
= DevDesc
->Configs
[Index
];
392 if (ConfigDesc
->Desc
.ConfigurationValue
== ConfigValue
) {
397 if (Index
== DevDesc
->Desc
.NumConfigurations
) {
398 return EFI_NOT_FOUND
;
401 Device
->ActiveConfig
= ConfigDesc
;
403 DEBUG ((EFI_D_INFO
, "UsbSelectConfig: config %d selected for device %d\n",
404 ConfigValue
, Device
->Address
));
407 // Create interfaces for each USB interface descriptor.
409 for (Index
= 0; Index
< ConfigDesc
->Desc
.NumInterfaces
; Index
++) {
411 // First select the default interface setting, and reset
412 // the endpoint toggles to zero for its endpoints.
414 IfDesc
= ConfigDesc
->Interfaces
[Index
];
415 UsbSelectSetting (IfDesc
, IfDesc
->Settings
[0]->Desc
.AlternateSetting
);
418 // Create a USB_INTERFACE and install USB_IO and other protocols
420 UsbIf
= UsbCreateInterface (Device
, ConfigDesc
->Interfaces
[Index
]);
423 return EFI_OUT_OF_RESOURCES
;
426 ASSERT (Index
< USB_MAX_INTERFACE
);
427 Device
->Interfaces
[Index
] = UsbIf
;
430 // Connect the device to drivers, if it failed, ignore
431 // the error. Don't let the unsupported interfaces to block
432 // the supported interfaces.
434 Status
= UsbConnectDriver (UsbIf
);
436 if (EFI_ERROR (Status
)) {
437 DEBUG ((EFI_D_ERROR
, "UsbSelectConfig: failed to connect driver %r, ignored\n", Status
));
441 Device
->NumOfInterface
= Index
;
448 Disconnect the USB interface with its driver.
450 @param UsbIf The interface to disconnect driver from.
454 UsbDisconnectDriver (
455 IN USB_INTERFACE
*UsbIf
462 // Release the hub if it's a hub controller, otherwise
463 // disconnect the driver if it is managed by other drivers.
466 UsbIf
->HubApi
->Release (UsbIf
);
468 } else if (UsbIf
->IsManaged
) {
470 // This function is called in both UsbIoControlTransfer and
471 // the timer callback in hub enumeration. So, at least it is
472 // called at TPL_CALLBACK. Some driver sitting on USB has
473 // twisted TPL used. It should be no problem for us to connect
474 // or disconnect at CALLBACK.
476 OldTpl
= UsbGetCurrentTpl ();
477 DEBUG ((EFI_D_INFO
, "UsbDisconnectDriver: old TPL is %d, %p\n", (UINT32
)OldTpl
, UsbIf
->Handle
));
479 gBS
->RestoreTPL (TPL_CALLBACK
);
481 Status
= gBS
->DisconnectController (UsbIf
->Handle
, NULL
, NULL
);
482 UsbIf
->IsManaged
= FALSE
;
484 DEBUG (( EFI_D_INFO
, "UsbDisconnectDriver: TPL after disconnect is %d, %d\n", (UINT32
)UsbGetCurrentTpl(), Status
));
485 ASSERT (UsbGetCurrentTpl () == TPL_CALLBACK
);
487 gBS
->RaiseTPL (OldTpl
);
493 Remove the current device configuration.
495 @param Device The USB device to remove configuration from.
500 IN USB_DEVICE
*Device
503 USB_INTERFACE
*UsbIf
;
507 // Remove each interface of the device
509 for (Index
= 0; Index
< Device
->NumOfInterface
; Index
++) {
510 ASSERT (Index
< USB_MAX_INTERFACE
);
511 UsbIf
= Device
->Interfaces
[Index
];
517 UsbDisconnectDriver (UsbIf
);
518 UsbFreeInterface (UsbIf
);
519 Device
->Interfaces
[Index
] = NULL
;
522 Device
->ActiveConfig
= NULL
;
523 Device
->NumOfInterface
= 0;
528 Remove the device and all its children from the bus.
530 @param Device The device to remove.
532 @retval EFI_SUCCESS The device is removed.
537 IN USB_DEVICE
*Device
548 // Remove all the devices on its downstream ports. Search from devices[1].
549 // Devices[0] is the root hub.
551 for (Index
= 1; Index
< USB_MAX_DEVICES
; Index
++) {
552 Child
= Bus
->Devices
[Index
];
554 if ((Child
== NULL
) || (Child
->ParentAddr
!= Device
->Address
)) {
558 Status
= UsbRemoveDevice (Child
);
560 if (EFI_ERROR (Status
)) {
561 DEBUG ((EFI_D_ERROR
, "UsbRemoveDevice: failed to remove child, ignore error\n"));
562 Bus
->Devices
[Index
] = NULL
;
566 UsbRemoveConfig (Device
);
568 DEBUG (( EFI_D_INFO
, "UsbRemoveDevice: device %d removed\n", Device
->Address
));
570 ASSERT (Device
->Address
< USB_MAX_DEVICES
);
571 Bus
->Devices
[Device
->Address
] = NULL
;
572 UsbFreeDevice (Device
);
579 Find the child device on the hub's port.
581 @param HubIf The hub interface.
582 @param Port The port of the hub this child is connected to.
584 @return The device on the hub's port, or NULL if there is none.
589 IN USB_INTERFACE
*HubIf
,
597 Bus
= HubIf
->Device
->Bus
;
600 // Start checking from device 1, device 0 is the root hub
602 for (Index
= 1; Index
< USB_MAX_DEVICES
; Index
++) {
603 Device
= Bus
->Devices
[Index
];
605 if ((Device
!= NULL
) && (Device
->ParentAddr
== HubIf
->Device
->Address
) &&
606 (Device
->ParentPort
== Port
)) {
617 Enumerate and configure the new device on the port of this HUB interface.
619 @param HubIf The HUB that has the device connected.
620 @param Port The port index of the hub (started with zero).
622 @retval EFI_SUCCESS The device is enumerated (added or removed).
623 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device.
624 @retval Others Failed to enumerate the device.
629 IN USB_INTERFACE
*HubIf
,
637 EFI_USB_PORT_STATUS PortState
;
642 Address
= USB_MAX_DEVICES
;
643 Parent
= HubIf
->Device
;
645 HubApi
= HubIf
->HubApi
;
647 gBS
->Stall (USB_WAIT_PORT_STABLE_STALL
);
650 // Hub resets the device for at least 10 milliseconds.
651 // Host learns device speed. If device is of low/full speed
652 // and the hub is a EHCI root hub, ResetPort will release
653 // the device to its companion UHCI and return an error.
655 Status
= HubApi
->ResetPort (HubIf
, Port
);
657 if (EFI_ERROR (Status
)) {
658 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to reset port %d - %r\n", Port
, Status
));
663 DEBUG (( EFI_D_INFO
, "UsbEnumerateNewDev: hub port %d is reset\n", Port
));
665 Child
= UsbCreateDevice (HubIf
, Port
);
668 return EFI_OUT_OF_RESOURCES
;
672 // OK, now identify the device speed. After reset, hub
673 // fully knows the actual device speed.
675 Status
= HubApi
->GetPortStatus (HubIf
, Port
, &PortState
);
677 if (EFI_ERROR (Status
)) {
678 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to get speed of port %d\n", Port
));
682 if (USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_LOW_SPEED
)) {
683 Child
->Speed
= EFI_USB_SPEED_LOW
;
685 } else if (USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_HIGH_SPEED
)) {
686 Child
->Speed
= EFI_USB_SPEED_HIGH
;
689 Child
->Speed
= EFI_USB_SPEED_FULL
;
692 DEBUG (( EFI_D_INFO
, "UsbEnumerateNewDev: device is of %d speed\n", Child
->Speed
));
694 if (Child
->Speed
!= EFI_USB_SPEED_HIGH
) {
696 // If the child isn't a high speed device, it is necessary to
697 // set the transaction translator. Port TT is 1-based.
698 // This is quite simple:
699 // 1. if parent is of high speed, then parent is our translator
700 // 2. otherwise use parent's translator.
702 if (Parent
->Speed
== EFI_USB_SPEED_HIGH
) {
703 Child
->Translator
.TranslatorHubAddress
= Parent
->Address
;
704 Child
->Translator
.TranslatorPortNumber
= (UINT8
) (Port
+ 1);
707 Child
->Translator
= Parent
->Translator
;
710 DEBUG (( EFI_D_INFO
, "UsbEnumerateNewDev: device uses translator (%d, %d)\n",
711 Child
->Translator
.TranslatorHubAddress
,
712 Child
->Translator
.TranslatorPortNumber
));
716 // After port is reset, hub establishes a signal path between
717 // the device and host (DEFALUT state). Device's registers are
718 // reset, use default address 0 (host enumerates one device at
719 // a time) , and ready to respond to control transfer at EP 0.
723 // Host sends a Get_Descriptor request to learn the max packet
724 // size of default pipe (only part of the device's descriptor).
726 Status
= UsbGetMaxPacketSize0 (Child
);
728 if (EFI_ERROR (Status
)) {
729 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to get max packet for EP 0 - %r\n", Status
));
733 DEBUG (( EFI_D_INFO
, "UsbEnumerateNewDev: max packet size for EP 0 is %d\n", Child
->MaxPacket0
));
736 // Host assigns an address to the device. Device completes the
737 // status stage with default address, then switches to new address.
738 // ADDRESS state. Address zero is reserved for root hub.
740 for (Address
= 1; Address
< USB_MAX_DEVICES
; Address
++) {
741 if (Bus
->Devices
[Address
] == NULL
) {
746 if (Address
== USB_MAX_DEVICES
) {
747 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: address pool is full for port %d\n", Port
));
749 Status
= EFI_ACCESS_DENIED
;
753 Bus
->Devices
[Address
] = Child
;
754 Status
= UsbSetAddress (Child
, Address
);
755 Child
->Address
= Address
;
757 if (EFI_ERROR (Status
)) {
758 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to set device address - %r\n", Status
));
762 gBS
->Stall (USB_SET_DEVICE_ADDRESS_STALL
);
764 DEBUG ((EFI_D_INFO
, "UsbEnumerateNewDev: device is now ADDRESSED at %d\n", Address
));
767 // Host learns about the device's abilities by requesting device's
768 // entire descriptions.
770 Status
= UsbBuildDescTable (Child
);
772 if (EFI_ERROR (Status
)) {
773 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to build descriptor table - %r\n", Status
));
778 // Select a default configuration: UEFI must set the configuration
779 // before the driver can connect to the device.
781 Config
= Child
->DevDesc
->Configs
[0]->Desc
.ConfigurationValue
;
782 Status
= UsbSetConfig (Child
, Config
);
784 if (EFI_ERROR (Status
)) {
785 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to set configure %d - %r\n", Config
, Status
));
789 DEBUG (( EFI_D_INFO
, "UsbEnumerateNewDev: device %d is now in CONFIGED state\n", Address
));
792 // Host assigns and loads a device driver.
794 Status
= UsbSelectConfig (Child
, Config
);
796 if (EFI_ERROR (Status
)) {
797 DEBUG ((EFI_D_ERROR
, "UsbEnumerateNewDev: failed to create interfaces - %r\n", Status
));
804 if (Address
!= USB_MAX_DEVICES
) {
805 Bus
->Devices
[Address
] = NULL
;
809 UsbFreeDevice (Child
);
817 Process the events on the port.
819 @param HubIf The HUB that has the device connected.
820 @param Port The port index of the hub (started with zero).
822 @retval EFI_SUCCESS The device is enumerated (added or removed).
823 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the device.
824 @retval Others Failed to enumerate the device.
829 IN USB_INTERFACE
*HubIf
,
835 EFI_USB_PORT_STATUS PortState
;
839 HubApi
= HubIf
->HubApi
;
842 // Host learns of the new device by polling the hub for port changes.
844 Status
= HubApi
->GetPortStatus (HubIf
, Port
, &PortState
);
846 if (EFI_ERROR (Status
)) {
847 DEBUG ((EFI_D_ERROR
, "UsbEnumeratePort: failed to get state of port %d\n", Port
));
851 if (PortState
.PortChangeStatus
== 0) {
855 DEBUG (( EFI_D_INFO
, "UsbEnumeratePort: port %d state - %x, change - %x on %p\n",
856 Port
, PortState
.PortStatus
, PortState
.PortChangeStatus
, HubIf
));
859 // This driver only process two kinds of events now: over current and
860 // connect/disconnect. Other three events are: ENABLE, SUSPEND, RESET.
861 // ENABLE/RESET is used to reset port. SUSPEND isn't supported.
864 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_OVERCURRENT
)) {
866 if (USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_OVERCURRENT
)) {
869 // Both OverCurrent and OverCurrentChange set, means over current occurs,
870 // which probably is caused by short circuit. It has to wait system hardware
871 // to perform recovery.
873 DEBUG (( EFI_D_ERROR
, "UsbEnumeratePort: Critical Over Current\n", Port
));
874 return EFI_DEVICE_ERROR
;
879 // Only OverCurrentChange set, means system has been recoveried from
880 // over current. As a result, all ports are nearly power-off, so
881 // it's necessary to detach and enumerate all ports again.
883 DEBUG (( EFI_D_ERROR
, "UsbEnumeratePort: 2.0 device Recovery Over Current\n", Port
));
886 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_ENABLE
)) {
889 // 1.1 roothub port reg doesn't reflect over-current state, while its counterpart
890 // on 2.0 roothub does. When over-current has influence on 1.1 device, the port
891 // would be disabled, so it's also necessary to detach and enumerate again.
893 DEBUG (( EFI_D_ERROR
, "UsbEnumeratePort: 1.1 device Recovery Over Current\n", Port
));
896 if (USB_BIT_IS_SET (PortState
.PortChangeStatus
, USB_PORT_STAT_C_CONNECTION
)) {
899 // Device connected or disconnected normally.
901 DEBUG ((EFI_D_ERROR
, "UsbEnumeratePort: Device Connect/Discount Normally\n", Port
));
905 // Following as the above cases, it's safety to remove and create again.
907 Child
= UsbFindChild (HubIf
, Port
);
910 DEBUG (( EFI_D_INFO
, "UsbEnumeratePort: device at port %d removed from root hub %p\n", Port
, HubIf
));
911 UsbRemoveDevice (Child
);
914 if (USB_BIT_IS_SET (PortState
.PortStatus
, USB_PORT_STAT_CONNECTION
)) {
916 // Now, new device connected, enumerate and configure the device
918 DEBUG (( EFI_D_INFO
, "UsbEnumeratePort: new device connected at port %d\n", Port
));
919 Status
= UsbEnumerateNewDev (HubIf
, Port
);
922 DEBUG (( EFI_D_INFO
, "UsbEnumeratePort: device disconnected event on port %d\n", Port
));
925 HubApi
->ClearPortChange (HubIf
, Port
);
931 Enumerate all the changed hub ports.
933 @param Event The event that is triggered.
934 @param Context The context to the event.
944 USB_INTERFACE
*HubIf
;
949 ASSERT (Context
!= NULL
);
951 HubIf
= (USB_INTERFACE
*) Context
;
953 if (HubIf
->ChangeMap
== NULL
) {
958 // HUB starts its port index with 1.
963 for (Index
= 0; Index
< HubIf
->NumOfPort
; Index
++) {
964 if (USB_BIT_IS_SET (HubIf
->ChangeMap
[Byte
], USB_BIT (Bit
))) {
965 UsbEnumeratePort (HubIf
, Index
);
968 USB_NEXT_BIT (Byte
, Bit
);
971 UsbHubAckHubStatus (HubIf
->Device
);
973 gBS
->FreePool (HubIf
->ChangeMap
);
974 HubIf
->ChangeMap
= NULL
;
980 Enumerate all the changed hub ports.
982 @param Event The event that is triggered.
983 @param Context The context to the event.
988 UsbRootHubEnumeration (
993 USB_INTERFACE
*RootHub
;
996 RootHub
= (USB_INTERFACE
*) Context
;
998 for (Index
= 0; Index
< RootHub
->NumOfPort
; Index
++) {
999 UsbEnumeratePort (RootHub
, Index
);