Add in Ps2keyboard.inf and Ps2Mouse.inf to IntelFrameworkModuelPkg

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3112 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12
2007-07-06 09:09:42 +00:00
parent 911cad134a
commit 05fbd06d91
18 changed files with 6799 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/**@file
Common header file shared by all source files.
This file includes package header files, library classes and protocol, PPI & GUID definitions.
Copyright (c) 2006 - 2007, Intel Corporation.
All rights reserved.
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
**/
#ifndef __COMMON_HEADER_H_
#define __COMMON_HEADER_H_
//
// The package level header files this module uses
//
#include <PiDxe.h>
#include <Framework/StatusCode.h>
//
// The protocols, PPI and GUID defintions for this module
//
#include <Protocol/SimpleTextIn.h>
#include <Protocol/IsaIo.h>
#include <Protocol/DevicePath.h>
#include <Protocol/Ps2Policy.h>
//
// The Library classes this module consumes
//
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
//
// Driver Binding Externs
//
extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
#endif

View File

@ -0,0 +1,230 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
ComponentName.c
Abstract:
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
#include "Ps2Keyboard.h"
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
Ps2KeyboardComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
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 Component Name Protocol
//
EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName = {
Ps2KeyboardComponentNameGetDriverName,
Ps2KeyboardComponentNameGetControllerName,
"eng"
};
static EFI_UNICODE_STRING_TABLE mPs2KeyboardDriverNameTable[] = {
{
"eng",
L"PS/2 Keyboard Driver"
},
{
NULL,
NULL
}
};
EFI_STATUS
EFIAPI
Ps2KeyboardComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
/*++
Routine Description:
Retrieves a Unicode string that is the user readable name of the EFI Driver.
Arguments:
This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
Language - A pointer to a three character ISO 639-2 language identifier.
This is the language of the driver 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.
DriverName - A pointer to the Unicode string to return. This Unicode string
is the name of the driver specified by This in the language
specified by Language.
Returns:
EFI_SUCCESS - The Unicode string for the Driver specified by This
and the language specified by Language was returned
in DriverName.
EFI_INVALID_PARAMETER - Language is NULL.
EFI_INVALID_PARAMETER - DriverName is NULL.
EFI_UNSUPPORTED - The driver specified by This does not support the
language specified by Language.
--*/
{
return LookupUnicodeString (
Language,
gPs2KeyboardComponentName.SupportedLanguages,
mPs2KeyboardDriverNameTable,
DriverName
);
}
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
)
/*++
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_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 LookupUnicodeString (
Language,
gPs2KeyboardComponentName.SupportedLanguages,
ConsoleIn->ControllerNameTable,
ControllerName
);
}

View File

@ -0,0 +1,58 @@
/**@file
Entry Point Source file.
This file contains the user entry point
Copyright (c) 2006 - 2007, Intel Corporation.
All rights reserved.
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
**/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
/**
The user Entry Point for module Ps2Keyboard. The user code starts with this function.
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval other Some error occurs when executing this entry point.
**/
EFI_STATUS
EFIAPI
InitializePs2Keyboard(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Install driver model protocol(s).
//
Status = EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gKeyboardControllerDriver,
ImageHandle,
&gPs2KeyboardComponentName,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,306 @@
/*++
Copyright (c) 2006, Intel Corporation. All rights reserved. <BR>
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
Ps2KbdTextIn.c
Abstract:
PS/2 Keyboard driver
Routines that support SIMPLE_TEXT_IN protocol
Revision History
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
#include "Ps2Keyboard.h"
//
// function declarations
//
EFI_STATUS
EFIAPI
KeyboardEfiReset (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
EFI_STATUS
EFIAPI
KeyboardReadKeyStroke (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
);
VOID
EFIAPI
KeyboardWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
KeyboardCheckForKey (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This
);
EFI_STATUS
EFIAPI
KeyboardEfiReset (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Implement SIMPLE_TEXT_IN.Reset()
Perform 8042 controller and keyboard initialization
Arguments:
Returns:
--*/
// GC_TODO: This - add argument and description to function comment
// GC_TODO: ExtendedVerification - add argument and description to function comment
// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
// GC_TODO: EFI_SUCCESS - add return value to function comment
{
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)) {
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
KeyboardReadKeyStroke (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
Implement SIMPLE_TEXT_IN.ReadKeyStroke().
Retrieve key values for driver user.
Arguments:
Returns:
--*/
// GC_TODO: This - add argument and description to function comment
// GC_TODO: Key - add argument and description to function comment
// GC_TODO: EFI_DEVICE_ERROR - add return value to function comment
// GC_TODO: EFI_NOT_READY - add return value to function comment
// GC_TODO: EFI_SUCCESS - add return value to function comment
{
EFI_STATUS Status;
KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
EFI_TPL OldTpl;
ConsoleIn = KEYBOARD_CONSOLE_IN_DEV_FROM_THIS (This);
//
// Enter critical section
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
if (ConsoleIn->KeyboardErr) {
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return EFI_DEVICE_ERROR;
}
//
// If there's no key, just return
//
Status = KeyboardCheckForKey (This);
if (EFI_ERROR (Status)) {
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return EFI_NOT_READY;
}
Key->ScanCode = ConsoleIn->Key.ScanCode;
Key->UnicodeChar = ConsoleIn->Key.UnicodeChar;
ConsoleIn->Key.ScanCode = SCAN_NULL;
ConsoleIn->Key.UnicodeChar = 0x0000;
//
// Leave critical section and return
//
gBS->RestoreTPL (OldTpl);
return EFI_SUCCESS;
}
VOID
EFIAPI
KeyboardWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Event notification function for SIMPLE_TEXT_IN.WaitForKey event
Signal the event if there is key available
Arguments:
Returns:
--*/
// GC_TODO: Event - add argument and description to function comment
// GC_TODO: Context - add argument and description to function comment
{
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 ;
}
EFI_STATUS
KeyboardCheckForKey (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
This - GC_TODO: add argument description
Returns:
EFI_SUCCESS - GC_TODO: Add description for return value
--*/
{
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;
}

View File

@ -0,0 +1,474 @@
/*++
Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved. <BR>
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
Module Name:
Ps2Keyboard.c
Abstract:
PS/2 Keyboard driver. Routines that interacts with callers,
conforming to EFI driver model
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
#include "Ps2Keyboard.h"
//
// Function prototypes
//
EFI_STATUS
EFIAPI
KbdControllerDriverSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
KbdControllerDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
KbdControllerDriverStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// Global variables
//
//
// DriverBinding Protocol Instance
//
EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver = {
KbdControllerDriverSupported,
KbdControllerDriverStart,
KbdControllerDriverStop,
0xa,
NULL,
NULL
};
EFI_STATUS
EFIAPI
KbdControllerDriverSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
ControllerDriver Protocol Method
Arguments:
Returns:
--*/
// GC_TODO: This - add argument and description to function comment
// GC_TODO: Controller - add argument and description to function comment
// GC_TODO: RemainingDevicePath - add argument and description to function comment
{
EFI_STATUS Status;
EFI_ISA_IO_PROTOCOL *IsaIo;
//
// Open the IO Abstraction(s) needed to perform the supported test
//
Status = gBS->OpenProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
(VOID **) &IsaIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Use the ISA I/O Protocol to see if Controller is the Keyboard controller
//
if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x303) || IsaIo->ResourceList->Device.UID != 0) {
Status = EFI_UNSUPPORTED;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
EFI_STATUS
EFIAPI
KbdControllerDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
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: RemainingDevicePath - add argument and description to function comment
// GC_TODO: EFI_INVALID_PARAMETER - add return value to function comment
{
EFI_STATUS Status;
EFI_STATUS Status1;
EFI_ISA_IO_PROTOCOL *IsaIo;
KEYBOARD_CONSOLE_IN_DEV *ConsoleIn;
UINT8 Data;
EFI_STATUS_CODE_VALUE StatusCode;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
StatusCode = 0;
Status = gBS->OpenProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
(VOID **) &ParentDevicePath,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Report that the keyboard is being enabled
//
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_PROGRESS_CODE,
EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_ENABLE,
ParentDevicePath
);
//
// Get the ISA I/O Protocol on Controller's handle
//
Status = gBS->OpenProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
(VOID **) &IsaIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_INVALID_PARAMETER;
}
//
// Allocate private data
//
ConsoleIn = AllocateZeroPool (sizeof (KEYBOARD_CONSOLE_IN_DEV));
if (ConsoleIn == NULL) {
Status = EFI_OUT_OF_RESOURCES;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
//
// Setup the device instance
//
ConsoleIn->Signature = KEYBOARD_CONSOLE_IN_DEV_SIGNATURE;
ConsoleIn->Handle = Controller;
(ConsoleIn->ConIn).Reset = KeyboardEfiReset;
(ConsoleIn->ConIn).ReadKeyStroke = KeyboardReadKeyStroke;
ConsoleIn->DataRegisterAddress = KEYBOARD_8042_DATA_REGISTER;
ConsoleIn->StatusRegisterAddress = KEYBOARD_8042_STATUS_REGISTER;
ConsoleIn->CommandRegisterAddress = KEYBOARD_8042_COMMAND_REGISTER;
ConsoleIn->IsaIo = IsaIo;
ConsoleIn->ScancodeBufStartPos = 0;
ConsoleIn->ScancodeBufEndPos = KEYBOARD_BUFFER_MAX_COUNT - 1;
ConsoleIn->ScancodeBufCount = 0;
ConsoleIn->Ctrled = FALSE;
ConsoleIn->Alted = FALSE;
ConsoleIn->DevicePath = ParentDevicePath;
//
// Setup the WaitForKey event
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
KeyboardWaitForKey,
&(ConsoleIn->ConIn),
&((ConsoleIn->ConIn).WaitForKey)
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
//
// Setup a periodic timer, used for reading keystrokes at a fixed interval
//
Status = gBS->CreateEvent (
EVT_TIMER | EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
KeyboardTimerHandler,
ConsoleIn,
&ConsoleIn->TimerEvent
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
Status = gBS->SetTimer (
ConsoleIn->TimerEvent,
TimerPeriodic,
KEYBOARD_TIMER_INTERVAL
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_PROGRESS_CODE,
EFI_PERIPHERAL_KEYBOARD | EFI_P_PC_PRESENCE_DETECT,
ParentDevicePath
);
//
// Reset the keyboard device
//
Status = ConsoleIn->ConIn.Reset (&ConsoleIn->ConIn, TRUE);
if (EFI_ERROR (Status)) {
Status = EFI_DEVICE_ERROR;
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_NOT_DETECTED;
goto ErrorExit;
}
ConsoleIn->ControllerNameTable = NULL;
AddUnicodeString (
"eng",
gPs2KeyboardComponentName.SupportedLanguages,
&ConsoleIn->ControllerNameTable,
L"PS/2 Keyboard Device"
);
//
// Install protocol interfaces for the keyboard device.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Controller,
&gEfiSimpleTextInProtocolGuid,
&ConsoleIn->ConIn,
NULL
);
if (EFI_ERROR (Status)) {
StatusCode = EFI_PERIPHERAL_KEYBOARD | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
return Status;
ErrorExit:
//
// Report error code
//
if (StatusCode != 0) {
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_ERROR_CODE | EFI_ERROR_MINOR,
StatusCode,
ParentDevicePath
);
}
if ((ConsoleIn != NULL) && (ConsoleIn->ConIn.WaitForKey != NULL)) {
gBS->CloseEvent (ConsoleIn->ConIn.WaitForKey);
}
if ((ConsoleIn != NULL) && (ConsoleIn->TimerEvent != NULL)) {
gBS->CloseEvent (ConsoleIn->TimerEvent);
}
if ((ConsoleIn != NULL) && (ConsoleIn->ControllerNameTable != NULL)) {
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
}
//
// Since there will be no timer handler for keyboard input any more,
// exhaust input data just in case there is still keyboard data left
//
Status1 = EFI_SUCCESS;
while (!EFI_ERROR (Status1)) {
Status1 = KeyboardRead (ConsoleIn, &Data);;
}
if (ConsoleIn != NULL) {
gBS->FreePool (ConsoleIn);
}
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->CloseProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
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_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;
}
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) {
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 Simple TextIn Protocol
//
Status = gBS->UninstallProtocolInterface (
Controller,
&gEfiSimpleTextInProtocolGuid,
&ConsoleIn->ConIn
);
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) {
gBS->CloseEvent ((ConsoleIn->ConIn).WaitForKey);
(ConsoleIn->ConIn).WaitForKey = NULL;
}
FreeUnicodeStringTable (ConsoleIn->ControllerNameTable);
gBS->FreePool (ConsoleIn);
return EFI_SUCCESS;
}

View File

@ -0,0 +1,361 @@
/**@file
PS/2 keyboard driver header file
Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved. <BR>
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
**/
#ifndef _PS2KEYBOARD_H
#define _PS2KEYBOARD_H
//
// Include common header file for this module.
//
#include "CommonHeader.h"
//
// Driver Private Data
//
#define KEYBOARD_BUFFER_MAX_COUNT 32
#define KEYBOARD_CONSOLE_IN_DEV_SIGNATURE EFI_SIGNATURE_32 ('k', 'k', 'e', 'y')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_SIMPLE_TEXT_INPUT_PROTOCOL ConIn;
EFI_ISA_IO_PROTOCOL *IsaIo;
EFI_EVENT TimerEvent;
UINT32 DataRegisterAddress;
UINT32 StatusRegisterAddress;
UINT32 CommandRegisterAddress;
EFI_INPUT_KEY Key;
BOOLEAN Ctrl;
BOOLEAN Alt;
BOOLEAN Shift;
BOOLEAN CapsLock;
BOOLEAN NumLock;
BOOLEAN ScrollLock;
//
// Buffer storing key scancodes
//
UINT8 ScancodeBuf[KEYBOARD_BUFFER_MAX_COUNT];
UINT32 ScancodeBufStartPos;
UINT32 ScancodeBufEndPos;
UINT32 ScancodeBufCount;
//
// Indicators of the key pressing state, used in detecting Alt+Ctrl+Del
//
BOOLEAN Ctrled;
BOOLEAN Alted;
//
// Error state
//
BOOLEAN KeyboardErr;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
} KEYBOARD_CONSOLE_IN_DEV;
#define KEYBOARD_CONSOLE_IN_DEV_FROM_THIS(a) CR (a, KEYBOARD_CONSOLE_IN_DEV, ConIn, KEYBOARD_CONSOLE_IN_DEV_SIGNATURE)
#define TABLE_END 0x0
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gKeyboardControllerDriver;
extern EFI_COMPONENT_NAME_PROTOCOL gPs2KeyboardComponentName;
//
// Driver entry point
//
EFI_STATUS
InstallPs2KeyboardDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ImageHandle - GC_TODO: add argument description
SystemTable - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
#define KEYBOARD_8042_DATA_REGISTER 0x60
#define KEYBOARD_8042_STATUS_REGISTER 0x64
#define KEYBOARD_8042_COMMAND_REGISTER 0x64
#define KEYBOARD_KBEN 0xF4
#define KEYBOARD_CMDECHO_ACK 0xFA
#define KEYBOARD_TIMEOUT 65536 // 0.07s
#define KEYBOARD_WAITFORVALUE_TIMEOUT 1000000 // 1s
#define KEYBOARD_BAT_TIMEOUT 4000000 // 4s
#define KEYBOARD_TIMER_INTERVAL 200000 // 0.02s
#define SCANCODE_EXTENDED 0xE0
#define SCANCODE_EXTENDED1 0xE1
#define SCANCODE_CTRL_MAKE 0x1D
#define SCANCODE_CTRL_BREAK 0x9D
#define SCANCODE_ALT_MAKE 0x38
#define SCANCODE_ALT_BREAK 0xB8
#define SCANCODE_LEFT_SHIFT_MAKE 0x2A
#define SCANCODE_LEFT_SHIFT_BREAK 0xAA
#define SCANCODE_RIGHT_SHIFT_MAKE 0x36
#define SCANCODE_RIGHT_SHIFT_BREAK 0xB6
#define SCANCODE_CAPS_LOCK_MAKE 0x3A
#define SCANCODE_NUM_LOCK_MAKE 0x45
#define SCANCODE_SCROLL_LOCK_MAKE 0x46
#define SCANCODE_MAX_MAKE 0x59
//
// Other functions that are used among .c files
//
EFI_STATUS
KeyboardRead (
IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
OUT UINT8 *Data
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ConsoleIn - GC_TODO: add argument description
Data - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
KeyGetchar (
IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ConsoleIn - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
InitKeyboard (
IN OUT KEYBOARD_CONSOLE_IN_DEV *ConsoleIn,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ConsoleIn - GC_TODO: add argument description
ExtendedVerification - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
DisableKeyboard (
IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ConsoleIn - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
VOID
EFIAPI
KeyboardTimerHandler (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
Event - GC_TODO: add argument description
Context - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
KeyboardEfiReset (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
This - GC_TODO: add argument description
ExtendedVerification - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
EFIAPI
KeyboardReadKeyStroke (
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
OUT EFI_INPUT_KEY *Key
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
This - GC_TODO: add argument description
Key - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
VOID
EFIAPI
KeyboardWaitForKey (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
Event - GC_TODO: add argument description
Context - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
UINT8
KeyReadStatusRegister (
IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
ConsoleIn - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
/**
Check whether there is Ps/2 Keyboard device in system by 0xF4 Keyboard Command
If Keyboard receives 0xF4, it will respond with 'ACK'. If it doesn't respond, the device
should not be in system.
@param[in] BiosKeyboardPrivate Keyboard Private Data Structure
@retval TRUE Keyboard in System.
@retval FALSE Keyboard not in System.
**/
BOOLEAN
EFIAPI
CheckKeyboardConnect (
IN KEYBOARD_CONSOLE_IN_DEV *ConsoleIn
)
;
#endif

View File

@ -0,0 +1,108 @@
#/** @file
# Ps2 Keyboard Driver
#
# This dirver directly uses IsaIo protocol service to support KeyBoard work.
# Copyright (c) 2006 - 2007, Intel Corporation.
#
# All rights reserved.
# This software and associated documentation (if any) is furnished
# under a license and may only be used or copied in accordance
# with the terms of the license. Except as permitted by such
# license, no part of this software or documentation may be
# reproduced, stored in a retrieval system, or transmitted in any
# form or by any means without the express written consent of
# Intel Corporation.
#
#
#**/
################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = Ps2Keyboard
FILE_GUID = 3DC82376-637B-40a6-A8FC-A565417F2C38
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
ENTRY_POINT = InitializePs2Keyboard
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gKeyboardControllerDriver
# COMPONENT_NAME = gPs2KeyboardComponentName
# Create Event Guid C Name: Event Type: EVENT_TYPE_RELATIVE_TIMER
# Create Event Guid C Name: Event Type: EVENT_TYPE_PERIODIC_TIMER
#
# Signal Event Guid C Name: Event Type: EVENT_TYPE_PERIODIC_TIMER
#
#
################################################################################
#
# Sources Section - list of files that are required for the build to succeed.
#
################################################################################
[Sources.common]
ComponentName.c
Ps2Keyboard.h
Ps2KbdCtrller.c
Ps2KbdTextIn.c
Ps2Keyboard.c
CommonHeader.h
EntryPoint.c
################################################################################
#
# Package Dependency Section - list of Package files that are required for
# this module.
#
################################################################################
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
################################################################################
#
# Library Class Section - list of Library Classes that are required for
# this module.
#
################################################################################
[LibraryClasses]
MemoryAllocationLib
UefiRuntimeServicesTableLib
DebugLib
ReportStatusCodeLib
UefiBootServicesTableLib
UefiLib
UefiDriverEntryPoint
################################################################################
#
# Protocol C Name Section - list of Protocol and Protocol Notify C Names
# that this module uses or produces.
#
################################################################################
[Protocols]
gEfiPs2PolicyProtocolGuid # PROTOCOL TO_START
gEfiIsaIoProtocolGuid # PROTOCOL TO_START
gEfiSimpleTextInProtocolGuid # PROTOCOL BY_START
gEfiDevicePathProtocolGuid # PROTOCOL TO_START

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ModuleSurfaceArea xsi:schemaLocation="http://www.TianoCore.org/2006/Edk2.0 http://www.TianoCore.org/2006/Edk2.0/SurfaceArea.xsd" xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MsaHeader>
<ModuleName>Ps2Keyboard</ModuleName>
<ModuleType>DXE_DRIVER</ModuleType>
<GuidValue>3DC82376-637B-40a6-A8FC-A565417F2C38</GuidValue>
<Version>1.0</Version>
<Abstract>Ps2 Keyboard Driver</Abstract>
<Description>This dirver directly uses IsaIo protocol service to support KeyBoard work.</Description>
<Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>
<License>All rights reserved.
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.</License>
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
</MsaHeader>
<ModuleDefinitions>
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
<BinaryModule>false</BinaryModule>
<OutputFileBasename>Ps2Keyboard</OutputFileBasename>
</ModuleDefinitions>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiDriverModelLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiDriverEntryPoint</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>ReportStatusCodeLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DebugLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiRuntimeServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>MemoryAllocationLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>Ps2Keyboard.c</Filename>
<Filename>Ps2KbdTextIn.c</Filename>
<Filename>Ps2KbdCtrller.c</Filename>
<Filename>Ps2Keyboard.h</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
<Package PackageGuid="bea835f9-fd62-464a-81ff-f3a806360c6b"/>
</PackageDependencies>
<Protocols>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="BY_START">
<ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiIsaIoProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiPs2PolicyProtocolGuid</ProtocolCName>
</Protocol>
</Protocols>
<Events>
<CreateEvents>
<EventTypes Usage="ALWAYS_PRODUCED">
<EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>
<HelpText>Set up event in order to wait for key stroke</HelpText>
</EventTypes>
<EventTypes Usage="ALWAYS_PRODUCED">
<EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>
<HelpText>Set up a periodic timer to read key strokes at a fixed interval</HelpText>
</EventTypes>
</CreateEvents>
<SignalEvents>
<EventTypes Usage="SOMETIMES_PRODUCED">
<EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>
<HelpText>Signal an event wheneven there is a key pending</HelpText>
</EventTypes>
</SignalEvents>
</Events>
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<DriverBinding>gKeyboardControllerDriver</DriverBinding>
<ComponentName>gPs2KeyboardComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>