usbdxelib.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 702 行 · 第 1/2 页
C
702 行
}
//
// Set Device Feature
//
EFI_STATUS
UsbSetDeviceFeature (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN EFI_USB_RECIPIENT Recipient,
IN UINT16 Value,
IN UINT16 Target,
OUT UINT32 *Status
)
/*++
Routine Description:
Usb Set Device Feature
Arguments:
UsbIo - EFI_USB_IO_PROTOCOL
Recipient - Interface/Device/Endpoint
Value - Request value
Target - Request Index
Status - Transfer status
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_TIMEOUT - Device has no response
--*/
{
EFI_USB_DEVICE_REQUEST DevReq;
if (UsbIo == NULL) {
return EFI_INVALID_PARAMETER;
}
EfiZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
switch (Recipient) {
case EfiUsbDevice:
DevReq.RequestType = 0x00;
break;
case EfiUsbInterface:
DevReq.RequestType = 0x01;
break;
case EfiUsbEndpoint:
DevReq.RequestType = 0x02;
break;
}
//
// Fill device request, see USB1.1 spec
//
DevReq.Request = USB_DEV_SET_FEATURE;
DevReq.Value = Value;
DevReq.Index = Target;
return UsbIo->UsbControlTransfer (
UsbIo,
&DevReq,
EfiUsbNoData,
TIMEOUT_VALUE,
NULL,
0,
Status
);
}
//
// Clear Device Feature
//
EFI_STATUS
UsbClearDeviceFeature (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN EFI_USB_RECIPIENT Recipient,
IN UINT16 Value,
IN UINT16 Target,
OUT UINT32 *Status
)
/*++
Routine Description:
Usb Clear Device Feature
Arguments:
UsbIo - EFI_USB_IO_PROTOCOL
Recipient - Interface/Device/Endpoint
Value - Request value
Target - Request Index
Status - Transfer status
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_TIMEOUT - Device has no response
--*/
{
EFI_USB_DEVICE_REQUEST DevReq;
if (UsbIo == NULL) {
return EFI_INVALID_PARAMETER;
}
EfiZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
switch (Recipient) {
case EfiUsbDevice:
DevReq.RequestType = 0x00;
break;
case EfiUsbInterface:
DevReq.RequestType = 0x01;
break;
case EfiUsbEndpoint:
DevReq.RequestType = 0x02;
break;
}
//
// Fill device request, see USB1.1 spec
//
DevReq.Request = USB_DEV_CLEAR_FEATURE;
DevReq.Value = Value;
DevReq.Index = Target;
return UsbIo->UsbControlTransfer (
UsbIo,
&DevReq,
EfiUsbNoData,
TIMEOUT_VALUE,
NULL,
0,
Status
);
}
//
// Get Device Status
//
EFI_STATUS
UsbGetDeviceStatus (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN EFI_USB_RECIPIENT Recipient,
IN UINT16 Target,
OUT UINT16 *DevStatus,
OUT UINT32 *Status
)
/*++
Routine Description:
Usb Get Device Status
Arguments:
UsbIo - EFI_USB_IO_PROTOCOL
Recipient - Interface/Device/Endpoint
Target - Request index
DevStatus - Device status
Status - Transfer status
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_TIMEOUT - Device has no response
--*/
{
EFI_USB_DEVICE_REQUEST DevReq;
if (UsbIo == NULL) {
return EFI_INVALID_PARAMETER;
}
EfiZeroMem (&DevReq, sizeof (EFI_USB_DEVICE_REQUEST));
switch (Recipient) {
case EfiUsbDevice:
DevReq.RequestType = 0x80;
break;
case EfiUsbInterface:
DevReq.RequestType = 0x81;
break;
case EfiUsbEndpoint:
DevReq.RequestType = 0x82;
break;
}
//
// Fill device request, see USB1.1 spec
//
DevReq.Request = USB_DEV_GET_STATUS;
DevReq.Value = 0;
DevReq.Index = Target;
DevReq.Length = 2;
return UsbIo->UsbControlTransfer (
UsbIo,
&DevReq,
EfiUsbDataIn,
TIMEOUT_VALUE,
DevStatus,
2,
Status
);
}
//
// Usb Get String
//
EFI_STATUS
UsbGetString (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT16 LangID,
IN UINT8 Index,
IN VOID *Buf,
IN UINTN BufSize,
OUT UINT32 *Status
)
/*++
Routine Description:
Usb Get String
Arguments:
UsbIo - EFI_USB_IO_PROTOCOL
LangID - Language ID
Index - Request index
Buf - Buffer to store string
BufSize - Buffer size
Status - Transfer status
Returns:
EFI_INVALID_PARAMETER - Parameter is error
EFI_SUCCESS - Success
EFI_TIMEOUT - Device has no response
--*/
{
UINT16 Value;
if (UsbIo == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Fill value, see USB1.1 spec
//
Value = (UINT16) ((USB_DT_STRING << 8) | Index);
return UsbGetDescriptor (
UsbIo,
Value,
LangID,
(UINT16) BufSize,
Buf,
Status
);
}
EFI_STATUS
UsbClearEndpointHalt (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointNo,
OUT UINT32 *Status
)
/*++
Routine Description:
Clear endpoint stall
Arguments:
UsbIo - EFI_USB_IO_PROTOCOL
EndpointNo - Endpoint Number
Status - Transfer Status
Returns:
EFI_NOT_FOUND - Can't find the Endpoint
EFI_DEVICE_ERROR - Hardware error
EFI_SUCCESS - Success
--*/
{
EFI_STATUS Result;
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
UINT8 Index;
EfiZeroMem (&EndpointDescriptor, sizeof (EFI_USB_ENDPOINT_DESCRIPTOR));
//
// First seach the endpoint descriptor for that endpoint addr
//
Result = UsbIo->UsbGetInterfaceDescriptor (
UsbIo,
&InterfaceDescriptor
);
if (EFI_ERROR (Result)) {
return Result;
}
for (Index = 0; Index < InterfaceDescriptor.NumEndpoints; Index++) {
Result = UsbIo->UsbGetEndpointDescriptor (
UsbIo,
Index,
&EndpointDescriptor
);
if (EFI_ERROR (Result)) {
continue;
}
if (EndpointDescriptor.EndpointAddress == EndpointNo) {
break;
}
}
if (Index == InterfaceDescriptor.NumEndpoints) {
//
// No such endpoint
//
return EFI_NOT_FOUND;
}
Result = UsbClearDeviceFeature (
UsbIo,
EfiUsbEndpoint,
EfiUsbEndpointHalt,
EndpointDescriptor.EndpointAddress,
Status
);
return Result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?