44 &gUsbMouseDriverBinding,
46 &gUsbMouseComponentName,
47 &gUsbMouseComponentName2
76 Status =
gBS->OpenProtocol (
78 &gEfiUsbIoProtocolGuid,
80 This->DriverBindingHandle,
82 EFI_OPEN_PROTOCOL_BY_DRIVER
84 if (EFI_ERROR (Status)) {
94 Status = EFI_UNSUPPORTED;
99 &gEfiUsbIoProtocolGuid,
100 This->DriverBindingHandle,
137 UINT8 EndpointNumber;
141 UINT8 PollingInterval;
146 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
150 Status =
gBS->OpenProtocol (
152 &gEfiUsbIoProtocolGuid,
154 This->DriverBindingHandle,
156 EFI_OPEN_PROTOCOL_BY_DRIVER
158 if (EFI_ERROR (Status)) {
163 ASSERT (UsbMouseDevice !=
NULL);
165 UsbMouseDevice->UsbIo = UsbIo;
166 UsbMouseDevice->Signature = USB_MOUSE_DEV_SIGNATURE;
171 Status =
gBS->OpenProtocol (
173 &gEfiDevicePathProtocolGuid,
174 (VOID **)&UsbMouseDevice->DevicePath,
175 This->DriverBindingHandle,
177 EFI_OPEN_PROTOCOL_GET_PROTOCOL
180 if (EFI_ERROR (Status)) {
189 (EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT),
190 UsbMouseDevice->DevicePath
196 UsbIo->UsbGetInterfaceDescriptor (
198 &UsbMouseDevice->InterfaceDescriptor
201 EndpointNumber = UsbMouseDevice->InterfaceDescriptor.NumEndpoints;
207 for (Index = 0; Index < EndpointNumber; Index++) {
208 UsbIo->UsbGetEndpointDescriptor (
214 if (((EndpointDescriptor.Attributes & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT) &&
215 ((EndpointDescriptor.EndpointAddress & USB_ENDPOINT_DIR_IN) != 0))
220 CopyMem (&UsbMouseDevice->IntEndpointDescriptor, &EndpointDescriptor, sizeof (EndpointDescriptor));
232 (EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED)
237 Status = EFI_UNSUPPORTED;
246 (EFI_PERIPHERAL_MOUSE | EFI_P_PC_DETECTED),
247 UsbMouseDevice->DevicePath
251 if (EFI_ERROR (Status)) {
257 (EFI_PERIPHERAL_MOUSE | EFI_P_EC_INTERFACE_ERROR),
258 UsbMouseDevice->DevicePath
267 UsbMouseDevice->SimplePointerProtocol.GetState =
GetMouseState;
269 UsbMouseDevice->SimplePointerProtocol.
Mode = &UsbMouseDevice->Mode;
271 Status =
gBS->CreateEvent (
276 &((UsbMouseDevice->SimplePointerProtocol).WaitForInput)
278 if (EFI_ERROR (Status)) {
282 Status =
gBS->InstallProtocolInterface (
284 &gEfiSimplePointerProtocolGuid,
286 &UsbMouseDevice->SimplePointerProtocol
289 if (EFI_ERROR (Status)) {
300 (EFI_PERIPHERAL_MOUSE | EFI_P_PC_ENABLE),
301 UsbMouseDevice->DevicePath
307 EndpointAddr = UsbMouseDevice->IntEndpointDescriptor.EndpointAddress;
308 PollingInterval = UsbMouseDevice->IntEndpointDescriptor.Interval;
309 PacketSize = (UINT8)(UsbMouseDevice->IntEndpointDescriptor.MaxPacketSize);
311 Status = UsbIo->UsbAsyncInterruptTransfer (
321 if (EFI_ERROR (Status)) {
325 gBS->UninstallProtocolInterface (
327 &gEfiSimplePointerProtocolGuid,
328 &UsbMouseDevice->SimplePointerProtocol
333 UsbMouseDevice->ControllerNameTable =
NULL;
337 &UsbMouseDevice->ControllerNameTable,
338 L
"Generic Usb Mouse",
344 &UsbMouseDevice->ControllerNameTable,
345 L
"Generic Usb Mouse",
349 gBS->RestoreTPL (OldTpl);
357 if (EFI_ERROR (Status)) {
360 &gEfiUsbIoProtocolGuid,
361 This->DriverBindingHandle,
365 if (UsbMouseDevice !=
NULL) {
366 if ((UsbMouseDevice->SimplePointerProtocol).WaitForInput !=
NULL) {
367 gBS->CloseEvent ((UsbMouseDevice->SimplePointerProtocol).WaitForInput);
371 UsbMouseDevice =
NULL;
376 gBS->RestoreTPL (OldTpl);
407 Status =
gBS->OpenProtocol (
409 &gEfiSimplePointerProtocolGuid,
410 (VOID **)&SimplePointerProtocol,
411 This->DriverBindingHandle,
413 EFI_OPEN_PROTOCOL_GET_PROTOCOL
416 if (EFI_ERROR (Status)) {
417 return EFI_UNSUPPORTED;
420 UsbMouseDevice = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (SimplePointerProtocol);
422 UsbIo = UsbMouseDevice->UsbIo;
429 (EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE),
430 UsbMouseDevice->DevicePath
436 UsbIo->UsbAsyncInterruptTransfer (
438 UsbMouseDevice->IntEndpointDescriptor.EndpointAddress,
440 UsbMouseDevice->IntEndpointDescriptor.Interval,
446 Status =
gBS->UninstallProtocolInterface (
448 &gEfiSimplePointerProtocolGuid,
449 &UsbMouseDevice->SimplePointerProtocol
451 if (EFI_ERROR (Status)) {
457 &gEfiUsbIoProtocolGuid,
458 This->DriverBindingHandle,
467 if (UsbMouseDevice->DelayedRecoveryEvent !=
NULL) {
468 gBS->CloseEvent (UsbMouseDevice->DelayedRecoveryEvent);
469 UsbMouseDevice->DelayedRecoveryEvent =
NULL;
472 if (UsbMouseDevice->ControllerNameTable !=
NULL) {
501 Status = UsbIo->UsbGetInterfaceDescriptor (
506 if (EFI_ERROR (Status)) {
510 if ((InterfaceDescriptor.InterfaceClass == CLASS_HID) &&
511 (InterfaceDescriptor.InterfaceSubClass == SUBCLASS_BOOT) &&
512 (InterfaceDescriptor.InterfaceProtocol == PROTOCOL_MOUSE)
548 UINT32 TransferResult;
553 UsbIo = UsbMouseDev->UsbIo;
558 Status = UsbIo->UsbGetConfigDescriptor (
562 if (EFI_ERROR (Status)) {
572 return EFI_OUT_OF_RESOURCES;
577 (UINT16)((USB_DESC_TYPE_CONFIG << 8) | (ConfigDesc.ConfigurationValue - 1)),
579 ConfigDesc.TotalLength,
583 if (EFI_ERROR (Status)) {
598 while (Total < ConfigDesc.TotalLength) {
599 if (Head->Type == USB_DESC_TYPE_INTERFACE) {
607 if (Start && (Head->Type == USB_DESC_TYPE_ENDPOINT)) {
611 if (Start && (Head->Type == USB_DESC_TYPE_HID)) {
616 Total = Total + (UINT16)Head->Len;
620 if (MouseHidDesc ==
NULL) {
622 return EFI_UNSUPPORTED;
628 if (MouseHidDesc->HidClassDesc[0].DescriptorType != USB_DESC_TYPE_REPORT) {
630 return EFI_UNSUPPORTED;
633 ReportDesc =
AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength);
634 ASSERT (ReportDesc !=
NULL);
638 UsbMouseDev->InterfaceDescriptor.InterfaceNumber,
639 MouseHidDesc->HidClassDesc[0].DescriptorLength,
643 if (EFI_ERROR (Status)) {
655 MouseHidDesc->HidClassDesc[0].DescriptorLength
658 if (EFI_ERROR (Status)) {
668 if (UsbMouseDev->NumberOfButtons >= 1) {
669 UsbMouseDev->Mode.LeftButton =
TRUE;
672 if (UsbMouseDev->NumberOfButtons > 1) {
673 UsbMouseDev->Mode.RightButton =
TRUE;
676 UsbMouseDev->Mode.ResolutionX = 8;
677 UsbMouseDev->Mode.ResolutionY = 8;
678 UsbMouseDev->Mode.ResolutionZ = 0;
686 UsbMouseDev->InterfaceDescriptor.InterfaceNumber,
689 if (Protocol != BOOT_PROTOCOL) {
692 UsbMouseDev->InterfaceDescriptor.InterfaceNumber,
696 if (EFI_ERROR (Status)) {
709 if (UsbMouseDev->DelayedRecoveryEvent !=
NULL) {
710 gBS->CloseEvent (UsbMouseDev->DelayedRecoveryEvent);
711 UsbMouseDev->DelayedRecoveryEvent = 0;
715 EVT_TIMER | EVT_NOTIFY_SIGNAL,
719 &UsbMouseDev->DelayedRecoveryEvent
757 UsbIo = UsbMouseDevice->UsbIo;
759 if (Result != EFI_USB_NOERROR) {
765 (EFI_PERIPHERAL_MOUSE | EFI_P_EC_INPUT_ERROR),
766 UsbMouseDevice->DevicePath
769 if ((Result & EFI_USB_ERR_STALL) == EFI_USB_ERR_STALL) {
770 EndpointAddr = UsbMouseDevice->IntEndpointDescriptor.EndpointAddress;
783 UsbIo->UsbAsyncInterruptTransfer (
785 UsbMouseDevice->IntEndpointDescriptor.EndpointAddress,
796 UsbMouseDevice->DelayedRecoveryEvent,
798 EFI_USB_INTERRUPT_DELAY
800 return EFI_DEVICE_ERROR;
806 if ((DataLength == 0) || (Data ==
NULL)) {
822 if (DataLength < 3) {
823 return EFI_DEVICE_ERROR;
826 UsbMouseDevice->StateChanged =
TRUE;
828 UsbMouseDevice->State.
LeftButton = (BOOLEAN)((*(UINT8 *)Data & BIT0) != 0);
829 UsbMouseDevice->State.
RightButton = (BOOLEAN)((*(UINT8 *)Data & BIT1) != 0);
833 if (DataLength > 3) {
863 if (MouseState ==
NULL) {
864 return EFI_INVALID_PARAMETER;
867 MouseDev = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);
869 if (!MouseDev->StateChanged) {
870 return EFI_NOT_READY;
889 MouseDev->StateChanged =
FALSE;
909 IN BOOLEAN ExtendedVerification
914 UsbMouseDevice = USB_MOUSE_DEV_FROM_MOUSE_PROTOCOL (This);
918 (EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET),
919 UsbMouseDevice->DevicePath
926 &UsbMouseDevice->State,
929 UsbMouseDevice->StateChanged =
FALSE;
955 if (UsbMouseDev->StateChanged) {
956 gBS->SignalEvent (Event);
985 UsbIo = UsbMouseDev->UsbIo;
990 UsbIo->UsbAsyncInterruptTransfer (
992 UsbMouseDev->IntEndpointDescriptor.EndpointAddress,
994 UsbMouseDev->IntEndpointDescriptor.Interval,
995 UsbMouseDev->IntEndpointDescriptor.MaxPacketSize,
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define REPORT_STATUS_CODE(Type, Value)
#define REPORT_STATUS_CODE_WITH_DEVICE_PATH(Type, Value, DevicePathParameter)
#define EFI_PROGRESS_CODE
EFI_STATUS EFIAPI AddUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable, IN CONST CHAR16 *UnicodeString, IN BOOLEAN Iso639Language)
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
EFI_STATUS EFIAPI UsbGetReportDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Interface, IN UINT16 DescriptorLength, OUT UINT8 *DescriptorBuffer)
EFI_STATUS EFIAPI UsbSetProtocolRequest(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Interface, IN UINT8 Protocol)
EFI_STATUS EFIAPI UsbGetProtocolRequest(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Interface, OUT UINT8 *Protocol)
EFI_STATUS EFIAPI UsbClearEndpointHalt(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 Endpoint, OUT UINT32 *Status)
EFI_STATUS EFIAPI UsbGetDescriptor(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT16 Value, IN UINT16 Index, IN UINT16 DescriptorLength, OUT VOID *Descriptor, OUT UINT32 *Status)
EFI_STATUS InitializeUsbMouseDevice(IN OUT USB_MOUSE_DEV *UsbMouseDev)
EFI_STATUS EFIAPI USBMouseDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
BOOLEAN IsUsbMouse(IN EFI_USB_IO_PROTOCOL *UsbIo)
EFI_STATUS EFIAPI OnMouseInterruptComplete(IN VOID *Data, IN UINTN DataLength, IN VOID *Context, IN UINT32 Result)
EFI_STATUS EFIAPI USBMouseDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
VOID EFIAPI USBMouseRecoveryHandler(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI UsbMouseReset(IN EFI_SIMPLE_POINTER_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
VOID EFIAPI UsbMouseWaitForInput(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS EFIAPI USBMouseDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
EFI_STATUS EFIAPI GetMouseState(IN EFI_SIMPLE_POINTER_PROTOCOL *This, OUT EFI_SIMPLE_POINTER_STATE *MouseState)
EFI_STATUS EFIAPI USBMouseDriverBindingEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS ParseMouseReportDescriptor(OUT USB_MOUSE_ABSOLUTE_POINTER_DEV *UsbMouseAbsolutePointer, IN UINT8 *ReportDescriptor, IN UINTN ReportSize)
CHAR8 * SupportedLanguages
CHAR8 * SupportedLanguages
EFI_SIMPLE_POINTER_MODE * Mode