/** Check keyboard for given key value. @param This Point to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL @retval EFI_SUCCESS success check keyboard value @retval !EFI_SUCCESS Fail to get char from keyboard **/ EFI_STATUS KeyboardCheckForKey ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This ) { KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This); // // If ready to read next key, check it // if (ConsoleIn->Key.ScanCode == SCAN_NULL && ConsoleIn->Key.UnicodeChar == 0x00) { return KeyGetchar (ConsoleIn); } return EFI_SUCCESS; }
/** Retrieve key values for driver user which implement SIMPLE_TEXT_IN.ReadKeyStroke(). @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL @param Key The output buffer for key value @retval EFI_SUCCESS success to read key stroke **/ EFI_STATUS EFIAPI KeyboardReadKeyStroke ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key ) { EFI_STATUS Status; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; EFI_KEY_DATA KeyData; ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This); Status = KeyboardReadKeyStrokeWorker (ConsoleIn, &KeyData); if (EFI_ERROR (Status)) { return Status; } CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY)); return EFI_SUCCESS; }
/** Event notification function for SIMPLE_TEXT_IN.WaitForKey event Signal the event if there is key available @param Event the event object @param Context waitting context **/ VOID EFIAPI KeyboardWaitForKey ( IN EFI_EVENT Event, IN VOID *Context ) { EFI_TPL OldTpl; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (Context); // // Enter critical section // OldTpl = gBS->RaiseTPL (TPL_NOTIFY); if (ConsoleIn->KeyboardErr) { // // Leave critical section and return // gBS->RestoreTPL (OldTpl); return ; } // // Someone is waiting on the keyboard event, if there's // a key pending, signal the event // if (!EFI_ERROR (KeyboardCheckForKey (Context))) { gBS->SignalEvent (Event); } // // Leave critical section and return // gBS->RestoreTPL (OldTpl); return ; }
/** 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 KbdControllerDriverStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ) { EFI_STATUS Status; EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; UINT8 Data; // // Disable Keyboard // Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInProtocolGuid, (VOID **) &ConIn, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInputExProtocolGuid, NULL, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn); // // Report that the keyboard is being disabled // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE, ConsoleIn->DevicePath ); if (ConsoleIn->TimerEvent != NULL) { gBS->CloseEvent (ConsoleIn->TimerEvent); ConsoleIn->TimerEvent = NULL; } // // Since there will be no timer handler for keyboard input any more, // exhaust input data just in case there is still keyboard data left // Status = EFI_SUCCESS; while (!EFI_ERROR (Status)) { Status = KeyboardRead (ConsoleIn, &Data);; } // // Uninstall the SimpleTextIn and SimpleTextInEx protocols // Status = gBS->UninstallMultipleProtocolInterfaces ( Controller, &gEfiSimpleTextInProtocolGuid, &ConsoleIn->ConIn, &gEfiSimpleTextInputExProtocolGuid, &ConsoleIn->ConInEx, NULL ); if (EFI_ERROR (Status)) { return Status; } gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, Controller ); gBS->CloseProtocol ( Controller, &gEfiIsaIoProtocolGuid, This->DriverBindingHandle, Controller ); // // Free other resources // if ((ConsoleIn->ConIn).WaitForKey != NULL) { gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey); (ConsoleIn->ConIn).WaitForKey = NULL; } if (ConsoleIn->ConInEx.WaitForKeyEx != NULL) { gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); ConsoleIn->ConInEx.WaitForKeyEx = NULL; } KbdFreeNotifyList (&ConsoleIn->NotifyList); FreeUnicodeStringTable (ConsoleIn->ControllerNameTable); gBS->FreePool (ConsoleIn); 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 Ps2KeyboardComponentNameGetControllerName ( 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_TEXT_INPUT_PROTOCOL *ConIn; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; EFI_ISA_IO_PROTOCOL *IsaIoProtocol; // // This is a device driver, so ChildHandle must be NULL. // if (ChildHandle != NULL) { return EFI_UNSUPPORTED; } // // Check Controller's handle // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiIsaIoProtocolGuid, (VOID **) &IsaIoProtocol, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (!EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, &gEfiIsaIoProtocolGuid, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle ); return EFI_UNSUPPORTED; } if (Status != EFI_ALREADY_STARTED) { return EFI_UNSUPPORTED; } // // Get the device context // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSimpleTextInProtocolGuid, (VOID **) &ConIn, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn); return LookupUnicodeString2 ( Language, This->SupportedLanguages, ConsoleIn->ControllerNameTable, ControllerName, (BOOLEAN)(This == &gPs2KeyboardComponentName) ); }
/** Perform 8042 controller and keyboard initialization which implement SIMPLE_TEXT_IN.Reset() @param This Pointer to instance of EFI_SIMPLE_TEXT_INPUT_PROTOCOL @param ExtendedVerification Indicate that the driver may perform a more exhaustive verification operation of the device during reset, now this par is ignored in this driver **/ EFI_STATUS EFIAPI KeyboardEfiReset ( IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, IN BOOLEAN ExtendedVerification ) { EFI_STATUS Status; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; EFI_TPL OldTpl; ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This); if (ConsoleIn->KeyboardErr) { return EFI_DEVICE_ERROR; } REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_RESET, ConsoleIn->DevicePath ); // // Enter critical section // OldTpl = gBS->RaiseTPL (TPL_NOTIFY); // // Call InitKeyboard to initialize the keyboard // Status = InitKeyboard (ConsoleIn, ExtendedVerification); if (EFI_ERROR (Status)) { // // Leave critical section and return // gBS->RestoreTPL (OldTpl); return EFI_DEVICE_ERROR; } // // Clear the status of ConsoleIn.Key // ConsoleIn->Key.ScanCode = SCAN_NULL; ConsoleIn->Key.UnicodeChar = 0x0000; // // Leave critical section and return // gBS->RestoreTPL (OldTpl); // // Report the status If a stuck key was detected // if (KeyReadStatusRegister (ConsoleIn) & 0x01) { REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_STUCK_KEY, ConsoleIn->DevicePath ); } // // Report the status If keyboard is locked // if ((KeyReadStatusRegister (ConsoleIn) & 0x10) == 0) { REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE | EFI_ERROR_MINOR, EFI_PERIPHERAL_KEYBOARD | EFI_P_KEYBOARD_EC_LOCKED, ConsoleIn->DevicePath ); } return EFI_SUCCESS; }
EFI_STATUS EFIAPI KbdControllerDriverStop ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer ) /*++ Routine Description: Arguments: Returns: --*/ // GC_TODO: This - add argument and description to function comment // GC_TODO: Controller - add argument and description to function comment // GC_TODO: NumberOfChildren - add argument and description to function comment // GC_TODO: ChildHandleBuffer - add argument and description to function comment // GC_TODO: EFI_SUCCESS - add return value to function comment { EFI_STATUS Status; EFI_SIMPLE_TEXT_IN_PROTOCOL *ConIn; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; UINT8 Data; // // Disable Keyboard // Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInProtocolGuid, (VOID **) &ConIn, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } #if (EFI_SPECIFICATION_VERSION >= 0x0002000A) #ifndef DISABLE_CONSOLE_EX Status = gBS->OpenProtocol ( Controller, &gEfiSimpleTextInputExProtocolGuid, NULL, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_TEST_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } #endif // DISABLE_CONSOLE_EX #endif ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn); // // Report that the keyboard is being disabled // ReportStatusCodeWithDevicePath ( EFI_PROGRESS_CODE, EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_DISABLE, 0, &gEfiCallerIdGuid, ConsoleIn->DevicePath ); if (ConsoleIn->TimerEvent) { gBS->CloseEvent (ConsoleIn->TimerEvent); ConsoleIn->TimerEvent = NULL; } // // Disable the keyboard interface // Status = DisableKeyboard (ConsoleIn); // // Since there will be no timer handler for keyboard input any more, // exhaust input data just in case there is still keyboard data left // Status = EFI_SUCCESS; while (!EFI_ERROR (Status)) { Status = KeyboardRead (ConsoleIn, &Data);; } // // Uninstall the SimpleTextIn and SimpleTextInEx protocols // Status = gBS->UninstallMultipleProtocolInterfaces ( Controller, &gEfiSimpleTextInProtocolGuid, &ConsoleIn->ConIn, #if (EFI_SPECIFICATION_VERSION >= 0x0002000A) #ifndef DISABLE_CONSOLE_EX &gEfiSimpleTextInputExProtocolGuid, &ConsoleIn->ConInEx, #endif // DISABLE_CONSOLE_EX #endif NULL ); if (EFI_ERROR (Status)) { return Status; } gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, This->DriverBindingHandle, Controller ); gBS->CloseProtocol ( Controller, EFI_ISA_IO_PROTOCOL_VERSION, This->DriverBindingHandle, Controller ); // // Free other resources // if ((ConsoleIn->ConIn).WaitForKey) { gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey); (ConsoleIn->ConIn).WaitForKey = NULL; } #if (EFI_SPECIFICATION_VERSION >= 0x0002000A) #ifndef DISABLE_CONSOLE_EX if (ConsoleIn->ConInEx.WaitForKeyEx != NULL) { gBS->CloseEvent (ConsoleIn->ConInEx.WaitForKeyEx); ConsoleIn->ConInEx.WaitForKeyEx = NULL; } KbdFreeNotifyList (&ConsoleIn->NotifyList); #endif // DISABLE_CONSOLE_EX #endif EfiLibFreeUnicodeStringTable (ConsoleIn->ControllerNameTable); gBS->FreePool (ConsoleIn); return EFI_SUCCESS; }
EFI_STATUS EFIAPI Ps2KeyboardComponentNameGetControllerName ( #if (EFI_SPECIFICATION_VERSION >= 0x00020000) IN EFI_COMPONENT_NAME2_PROTOCOL *This, #else IN EFI_COMPONENT_NAME_PROTOCOL *This, #endif IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName ) /*++ Routine Description: Retrieves a Unicode string that is the user readable name of the controller that is being managed by an EFI Driver. Arguments: This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. ControllerHandle - The handle of a controller that the driver specified by This is managing. This handle specifies the controller whose name is to be returned. ChildHandle - 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. Language - A pointer to a three character ISO 639-2 language identifier. This is the language of the controller name that 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. ControllerName - 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. Returns: 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. EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE. EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE. EFI_INVALID_PARAMETER - Language is NULL. EFI_INVALID_PARAMETER - ControllerName is NULL. EFI_UNSUPPORTED - The driver specified by This is not currently managing the controller specified by ControllerHandle and ChildHandle. EFI_UNSUPPORTED - The driver specified by This does not support the language specified by Language. --*/ { EFI_STATUS Status; EFI_SIMPLE_TEXT_IN_PROTOCOL *ConIn; KEYBOARD_CONSOLE_IN_DEV *ConsoleIn; EFI_INTERFACE_DEFINITION_FOR_ISA_IO *IsaIoProtocol; // // This is a device driver, so ChildHandle must be NULL. // if (ChildHandle != NULL) { return EFI_UNSUPPORTED; } // // Check Controller's handle // Status = gBS->OpenProtocol ( ControllerHandle, EFI_ISA_IO_PROTOCOL_VERSION, (VOID **) &IsaIoProtocol, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER ); if (!EFI_ERROR (Status)) { gBS->CloseProtocol ( ControllerHandle, EFI_ISA_IO_PROTOCOL_VERSION, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle ); return EFI_UNSUPPORTED; } if (Status != EFI_ALREADY_STARTED) { return EFI_UNSUPPORTED; } // // Get the device context // Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSimpleTextInProtocolGuid, (VOID **) &ConIn, gKeyboardControllerDriver.DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if (EFI_ERROR (Status)) { return Status; } ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (ConIn); return EfiLibLookupUnicodeString ( Language, gPs2KeyboardComponentName.SupportedLanguages, ConsoleIn->ControllerNameTable, ControllerName ); }