3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
30 OUT UINT32
*PortStatus
35 Get a given hub port status
38 UsbIo - EFI_USB_IO_PROTOCOL instance
39 Port - Usb hub port number (starting from 1).
40 PortStatus - Current Hub port status and change status.
50 EFI_USB_DEVICE_REQUEST DevReq
;
55 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
58 // Fill Device request packet
60 DevReq
.RequestType
= HUB_GET_PORT_STATUS_REQ_TYPE
;
61 DevReq
.Request
= HUB_GET_PORT_STATUS
;
64 DevReq
.Length
= sizeof (UINT32
);
68 EfiStatus
= UsbIo
->UsbControlTransfer (
83 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
90 Set specified feature to a give hub port
93 UsbIo - EFI_USB_IO_PROTOCOL instance
94 Port - Usb hub port number (starting from 1).
95 Value - New feature value.
101 EFI_INVALID_PARAMETER
105 EFI_USB_DEVICE_REQUEST DevReq
;
106 EFI_STATUS EfiStatus
;
110 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
113 // Fill Device request packet
115 DevReq
.RequestType
= HUB_SET_PORT_FEATURE_REQ_TYPE
;
116 DevReq
.Request
= HUB_SET_PORT_FEATURE
;
117 DevReq
.Value
= Value
;
122 EfiStatus
= UsbIo
->UsbControlTransfer (
136 HubClearPortFeature (
137 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
144 Clear a specified feature of a given hub port
147 UsbIo - EFI_USB_IO_PROTOCOL instance
148 Port - Usb hub port number (starting from 1).
149 Value - Feature value that will be cleared from
156 EFI_INVALID_PARAMETER
160 EFI_USB_DEVICE_REQUEST DevReq
;
161 EFI_STATUS EfiStatus
;
165 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
168 // Fill Device request packet
170 DevReq
.RequestType
= HUB_CLEAR_FEATURE_PORT_REQ_TYPE
;
171 DevReq
.Request
= HUB_CLEAR_FEATURE_PORT
;
172 DevReq
.Value
= Value
;
177 EfiStatus
= UsbIo
->UsbControlTransfer (
192 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
193 OUT UINT32
*HubStatus
201 UsbIo - EFI_USB_IO_PROTOCOL instance
202 HubStatus - Current Hub status and change status.
211 EFI_USB_DEVICE_REQUEST DevReq
;
212 EFI_STATUS EfiStatus
;
216 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
219 // Fill Device request packet
221 DevReq
.RequestType
= HUB_GET_HUB_STATUS_REQ_TYPE
;
222 DevReq
.Request
= HUB_GET_HUB_STATUS
;
225 DevReq
.Length
= sizeof (UINT32
);
228 EfiStatus
= UsbIo
->UsbControlTransfer (
243 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
249 Set a specified feature to the hub
252 UsbIo - EFI_USB_IO_PROTOCOL instance
253 Value - Feature value that will be set to the hub.
262 EFI_USB_DEVICE_REQUEST DevReq
;
263 EFI_STATUS EfiStatus
;
267 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
270 // Fill Device request packet
272 DevReq
.RequestType
= HUB_SET_HUB_FEATURE_REQ_TYPE
;
273 DevReq
.Request
= HUB_SET_HUB_FEATURE
;
274 DevReq
.Value
= Value
;
279 EfiStatus
= UsbIo
->UsbControlTransfer (
294 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
300 Set a specified feature to the hub
303 UsbIo - EFI_USB_IO_PROTOCOL instance
304 Value - Feature value that will be cleared from the hub.
313 EFI_USB_DEVICE_REQUEST DevReq
;
314 EFI_STATUS EfiStatus
;
318 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
321 // Fill Device request packet
323 DevReq
.RequestType
= HUB_CLEAR_FEATURE_REQ_TYPE
;
324 DevReq
.Request
= HUB_CLEAR_FEATURE
;
325 DevReq
.Value
= Value
;
330 EfiStatus
= UsbIo
->UsbControlTransfer (
346 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
347 IN UINTN DescriptorSize
,
348 OUT EFI_USB_HUB_DESCRIPTOR
*HubDescriptor
353 Get the hub descriptor
356 UsbIo - EFI_USB_IO_PROTOCOL instance
357 DescriptorSize - The length of Hub Descriptor buffer.
358 HubDescriptor - Caller allocated buffer to store the hub descriptor
359 if successfully returned.
368 EFI_USB_DEVICE_REQUEST DevReq
;
369 EFI_STATUS EfiStatus
;
373 ZeroMem (&DevReq
, sizeof (EFI_USB_DEVICE_REQUEST
));
376 // Fill Device request packet
378 DevReq
.RequestType
= USB_RT_HUB
| 0x80;
379 DevReq
.Request
= HUB_GET_DESCRIPTOR
;
380 DevReq
.Value
= USB_DT_HUB
<< 8;
382 DevReq
.Length
= (UINT16
) DescriptorSize
;
385 EfiStatus
= UsbIo
->UsbControlTransfer (
391 (UINT16
) DescriptorSize
,
401 IN USB_IO_CONTROLLER_DEVICE
*HubController
409 HubController - Indicating the hub controller device that
418 EFI_USB_IO_PROTOCOL
*UsbIo
;
419 EFI_USB_HUB_DESCRIPTOR HubDescriptor
;
421 EFI_USB_HUB_STATUS HubStatus
;
425 UsbIo
= &HubController
->UsbIo
;
427 ZeroMem (&HubDescriptor
, sizeof (HubDescriptor
));
430 // First get the hub descriptor length
432 Status
= GetHubDescriptor (UsbIo
, 2, &HubDescriptor
);
433 if (EFI_ERROR (Status
)) {
434 return EFI_DEVICE_ERROR
;
438 // First get the whole descriptor, then
439 // get the number of hub ports
441 Status
= GetHubDescriptor (
443 HubDescriptor
.Length
,
446 if (EFI_ERROR (Status
)) {
447 DEBUG ((gUSBErrorLevel
, "Get hub descriptor fail\n"));
448 return EFI_DEVICE_ERROR
;
451 HubController
->DownstreamPorts
= HubDescriptor
.NbrPorts
;
453 Status
= HubGetHubStatus (UsbIo
, (UINT32
*) &HubStatus
);
454 if (EFI_ERROR (Status
)) {
455 DEBUG ((gUSBErrorLevel
, "Get hub status fail when configure\n"));
456 return EFI_DEVICE_ERROR
;
460 // Get all hub ports status
462 for (Index
= 0; Index
< HubController
->DownstreamPorts
; Index
++) {
464 Status
= HubGetPortStatus (UsbIo
, (UINT8
) (Index
+ 1), &PortStatus
);
465 if (EFI_ERROR (Status
)) {
470 // Power all the hub ports
472 for (Index
= 0; Index
< HubController
->DownstreamPorts
; Index
++) {
473 Status
= HubSetPortFeature (
478 if (EFI_ERROR (Status
)) {
484 // Clear Hub Status Change
486 Status
= HubGetHubStatus (UsbIo
, (UINT32
*) &HubStatus
);
487 if (EFI_ERROR (Status
)) {
488 DEBUG ((gUSBErrorLevel
, "Get hub status fail\n"));
489 return EFI_DEVICE_ERROR
;
492 // Hub power supply change happens
494 if (HubStatus
.HubChange
& HUB_CHANGE_LOCAL_POWER
) {
495 HubClearHubFeature (UsbIo
, C_HUB_LOCAL_POWER
);
498 // Hub change overcurrent happens
500 if (HubStatus
.HubChange
& HUB_CHANGE_OVERCURRENT
) {
501 HubClearHubFeature (UsbIo
, C_HUB_OVER_CURRENT
);