/** Get and Clear mouse status. @param This - Pointer of simple pointer Protocol. @param State - Output buffer holding status. @retval EFI_INVALID_PARAMETER Output buffer is invalid. @retval EFI_NOT_READY Mouse is not changed status yet. @retval EFI_SUCCESS Mouse status is changed and get successful. **/ EFI_STATUS EFIAPI MouseGetState ( IN EFI_SIMPLE_POINTER_PROTOCOL *This, IN OUT EFI_SIMPLE_POINTER_STATE *State ) { PS2_MOUSE_DEV *MouseDev; EFI_TPL OldTpl; MouseDev = PS2_MOUSE_DEV_FROM_THIS (This); if (State == NULL) { return EFI_INVALID_PARAMETER; } if (!MouseDev->StateChanged) { return EFI_NOT_READY; } OldTpl = gBS->RaiseTPL (TPL_NOTIFY); CopyMem (State, &(MouseDev->State), sizeof (EFI_SIMPLE_POINTER_STATE)); // // clear mouse state // MouseDev->State.RelativeMovementX = 0; MouseDev->State.RelativeMovementY = 0; MouseDev->State.RelativeMovementZ = 0; MouseDev->StateChanged = FALSE; gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; }
/** Retrieves a Unicode string that is the user readable name of the controller that is being managed by a driver. This function retrieves the user readable name of the controller specified by ControllerHandle and ChildHandle in the form of a Unicode string. If the driver specified by This has a user readable name in the language specified by Language, then a pointer to the controller name is returned in ControllerName, and EFI_SUCCESS is returned. If the driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle, then EFI_UNSUPPORTED is returned. If the driver specified by This does not support the language specified by Language, then EFI_UNSUPPORTED is returned. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or EFI_COMPONENT_NAME_PROTOCOL instance. @param ControllerHandle[in] The handle of a controller that the driver specified by This is managing. This handle specifies the controller whose name is to be returned. @param ChildHandle[in] The handle of the child controller to retrieve the name of. This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to retrieve the name of the bus controller. It will not be NULL for a bus driver that wishes to retrieve the name of a child controller. @param Language[in] A pointer to a Null-terminated ASCII string array indicating the language. This is the language of the driver name that the caller is requesting, and it must match one of the languages specified in SupportedLanguages. The number of languages supported by a driver is up to the driver writer. Language is specified in RFC 4646 or ISO 639-2 language code format. @param ControllerName[out] A pointer to the Unicode string to return. This Unicode string is the name of the controller specified by ControllerHandle and ChildHandle in the language specified by Language from the point of view of the driver specified by This. @retval EFI_SUCCESS The Unicode string for the user readable name in the language specified by Language for the driver specified by This was returned in DriverName. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE. @retval EFI_INVALID_PARAMETER Language is NULL. @retval EFI_INVALID_PARAMETER ControllerName is NULL. @retval EFI_UNSUPPORTED The driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle. @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language. **/ EFI_STATUS EFIAPI Ps2MouseComponentNameGetControllerName ( IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName ) { EFI_STATUS Status; EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol; PS2_MOUSE_DEV *MouseDev; // // This is a device driver, so ChildHandle must be NULL. // if (ChildHandle != NULL) { return EFI_UNSUPPORTED; } // // Check Controller's handle // Status = EfiTestManagedDevice (ControllerHandle, gPS2MouseDriver.DriverBindingHandle, &gEfiSioProtocolGuid); if (EFI_ERROR (Status)) { return Status; } // // Get the device context // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSimplePointerProtocolGuid, (VOID **) &SimplePointerProtocol, gPS2MouseDriver.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol); return LookupUnicodeString2 ( Language, This->SupportedLanguages, MouseDev->ControllerNameTable, ControllerName, (BOOLEAN)(This == &gPs2MouseComponentName) ); }
/** Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system @param This - Pointer of simple pointer Protocol. @param ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip. @retval EFI_SUCCESS - The command byte is written successfully. @retval EFI_DEVICE_ERROR - Errors occurred during reseting keyboard. **/ EFI_STATUS EFIAPI MouseReset ( IN EFI_SIMPLE_POINTER_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { EFI_STATUS Status; PS2_MOUSE_DEV *MouseDev; EFI_TPL OldTpl; BOOLEAN KeyboardEnable; UINT8 Data; MouseDev = PS2_MOUSE_DEV_FROM_THIS (This); // // Report reset progress code // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_MOUSE | EFI_P_PC_RESET, MouseDev->DevicePath ); KeyboardEnable = FALSE; // // Raise TPL to avoid keyboard operation impact // OldTpl = gBS->RaiseTPL (TPL_NOTIFY); ZeroMem (&MouseDev->State, sizeof (EFI_SIMPLE_POINTER_STATE)); MouseDev->StateChanged = FALSE; // // Exhaust input data // Status = EFI_SUCCESS; while (!EFI_ERROR (Status)) { Status = In8042Data (MouseDev->IsaIo, &Data); } CheckKbStatus (MouseDev->IsaIo, &KeyboardEnable); KbcDisableKb (MouseDev->IsaIo); MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data); // // if there's data block on KBC data port, read it out // if ((Data & KBC_OUTB) == KBC_OUTB) { MouseDev->IsaIo->Io.Read (MouseDev->IsaIo, EfiIsaIoWidthUint8, KBC_DATA_PORT, 1, &Data); } Status = EFI_SUCCESS; // // The PS2 mouse driver reset behavior is always successfully return no matter wheater or not there is mouse connected to system. // This behavior is needed by performance speed. The following mouse command only succeessfully finish when mouse device is // connected to system, so if PS2 mouse device not connect to system or user not ask for, we skip the mouse configuration and enabling // if (ExtendedVerification && CheckMouseConnect (MouseDev)) { // // Send mouse reset command and set mouse default configure // Status = PS2MouseReset (MouseDev->IsaIo); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } Status = PS2MouseSetSampleRate (MouseDev->IsaIo, MouseDev->SampleRate); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } Status = PS2MouseSetResolution (MouseDev->IsaIo, MouseDev->Resolution); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } Status = PS2MouseSetScaling (MouseDev->IsaIo, MouseDev->Scaling); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } Status = PS2MouseEnable (MouseDev->IsaIo); if (EFI_ERROR (Status)) { Status = EFI_DEVICE_ERROR; goto Exit; } } Exit: gBS->RestoreTPL (OldTpl); if (KeyboardEnable) { KbcEnableKb (MouseDev->IsaIo); } return Status; }
/** Stop this driver on ControllerHandle. Support stoping any child handles created by this driver. @param This Protocol instance pointer. @param ControllerHandle Handle of device to stop driver on @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of children is zero stop the entire bus driver. @param ChildHandleBuffer List of Child Handles to Stop. @retval EFI_SUCCESS This driver is removed ControllerHandle @retval other This driver was not removed from this device **/ EFI_STATUS EFIAPI PS2MouseDriverStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ) { EFI_STATUS Status; EFI_SIMPLE_POINTER_PROTOCOL *SimplePointerProtocol; PS2_MOUSE_DEV *MouseDev; UINT8 Data; Status = gBS->OpenProtocol ( Controller, &gEfiSimplePointerProtocolGuid, (VOID **) &SimplePointerProtocol, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return EFI_SUCCESS; } MouseDev = PS2_MOUSE_DEV_FROM_THIS (SimplePointerProtocol); // // Report that the keyboard is being disabled // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_MOUSE | EFI_P_PC_DISABLE, MouseDev->DevicePath ); Status = gBS->UninstallProtocolInterface ( Controller, &gEfiSimplePointerProtocolGuid, &MouseDev->SimplePointerProtocol ); if (EFI_ERROR (Status)) { return Status; } // // Cancel mouse data polling timer, close timer event // gBS->SetTimer (MouseDev->TimerEvent, TimerCancel, 0); gBS->CloseEvent (MouseDev->TimerEvent); // // Since there will be no timer handler for mouse input any more, // exhaust input data just in case there is still mouse data left // Status = EFI_SUCCESS; while (!EFI_ERROR (Status)) { Status = In8042Data (MouseDev->IsaIo, &Data); } gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput); FreeUnicodeStringTable (MouseDev->ControllerNameTable); FreePool (MouseDev); gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, Controller ); gBS->CloseProtocol ( Controller, &gEfiIsaIoProtocolGuid, This->DriverBindingHandle, Controller ); return EFI_SUCCESS; }