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>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,445 @@
/*++
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.
Module Name:
CommPs2.h
Abstract:
PS2 Mouse Communication Interface
Revision History
--*/
#ifndef _COMMPS2_H_
#define _COMMPS2_H_
//
// Include common header file for this module.
//
#include "CommonHeader.h"
#define PS2_PACKET_LENGTH 3
#define PS2_SYNC_MASK 0xc
#define PS2_SYNC_BYTE 0x8
#define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)
#define PS2_READ_BYTE_ONE 0
#define PS2_READ_DATA_BYTE 1
#define PS2_PROCESS_PACKET 2
#define TIMEOUT 50000
#define BAT_TIMEOUT 500000
//
// 8042 I/O Port
//
#define KBC_DATA_PORT 0x60
#define KBC_CMD_STS_PORT 0x64
//
// 8042 Command
//
#define READ_CMD_BYTE 0x20
#define WRITE_CMD_BYTE 0x60
#define DISABLE_AUX 0xa7
#define ENABLE_AUX 0xa8
#define SELF_TEST 0xaa
#define DISABLE_KB 0xad
#define ENABLE_KB 0xae
#define WRITE_AUX_DEV 0xd4
#define CMD_SYS_FLAG 0x04
#define CMD_KB_STS 0x10
#define CMD_KB_DIS 0x10
#define CMD_KB_EN 0x0
//
// 8042 Auxiliary Device Command
//
#define SETSF1_CMD 0xe6
#define SETSF2_CMD 0xe7
#define SETRE_CMD 0xe8
#define READ_CMD 0xeb
#define SETRM_CMD 0xf0
#define SETSR_CMD 0xf3
#define ENABLE_CMD 0xf4
#define DISABLE_CMD 0xf5
#define RESET_CMD 0xff
//
// return code
//
#define PS2_ACK 0xfa
#define PS2_RESEND 0xfe
#define PS2MOUSE_BAT1 0xaa
#define PS2MOUSE_BAT2 0x0
//
// Keyboard Controller Status
//
#define KBC_PARE 0x80 // Parity Error
#define KBC_TIM 0x40 // General Time Out
#define KBC_AUXB 0x20 // Output buffer for auxiliary device (PS/2):
// 0 - Holds keyboard data
// 1 - Holds data for auxiliary device
//
#define KBC_KEYL 0x10 // Keyboard lock status:
// 0 - keyboard locked
// 1 - keyboard free
//
#define KBC_CD 0x08 // Command/Data:
// 0 - data byte written via port 60h
// 1 - command byte written via port 64h
//
#define KBC_SYSF 0x04 // System Flag:
// 0 - power-on reset
// 1 - self-test successful
//
#define KBC_INPB 0x02 // Input Buffer Status :
// 0 - input buffer empty
// 1 - CPU data in input buffer
//
#define KBC_OUTB 0x01 // Output Buffer Status :
// 0 - output buffer empty
// 1 - keyboard controller data in output buffer
//
EFI_STATUS
KbcSelfTest (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
KbcEnableAux (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
KbcDisableAux (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
KbcEnableKb (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
KbcDisableKb (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
CheckKbStatus (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
OUT BOOLEAN *KeyboardEnable
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
KeyboardEnable - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseReset (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseSetSampleRate (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN MOUSE_SR SampleRate
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
SampleRate - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseSetResolution (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN MOUSE_RE Resolution
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Resolution - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseSetScaling (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN MOUSE_SF Scaling
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Scaling - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseEnable (
IN EFI_ISA_IO_PROTOCOL *IsaIo
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
IsaIo - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseGetPacket (
PS2_MOUSE_DEV *MouseDev
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
MouseDev - GC_TODO: add argument description
Returns:
GC_TODO: add return values
--*/
;
EFI_STATUS
PS2MouseRead (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
OUT VOID *Buffer,
IN OUT UINTN *BufSize,
IN UINTN State
);
//
// 8042 I/O function
//
EFI_STATUS
Out8042Command (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINT8 Command
);
EFI_STATUS
In8042Data (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN OUT UINT8 *Data
);
EFI_STATUS
Out8042Data (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINT8 Data
);
EFI_STATUS
Out8042AuxCommand (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINT8 Command,
IN BOOLEAN Resend
);
EFI_STATUS
In8042AuxData (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN OUT UINT8 *Data
);
EFI_STATUS
Out8042AuxData (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINT8 Data
);
EFI_STATUS
CheckForInput (
IN EFI_ISA_IO_PROTOCOL *IsaIo
);
EFI_STATUS
WaitInputEmpty (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINTN Timeout
);
EFI_STATUS
WaitOutputFull (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN UINTN Timeout
);
#endif // _COMMPS2_H_

View File

@ -0,0 +1,48 @@
/**@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/SimplePointer.h>
#include <Protocol/IsaIo.h>
#include <Protocol/DevicePath.h>
//
// The Library classes this module consumes
//
#include <Library/DebugLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/ReportStatusCodeLib.h>
//
// Driver Binding Externs
//
extern EFI_DRIVER_BINDING_PROTOCOL gPS2MouseDriver;
extern EFI_COMPONENT_NAME_PROTOCOL gPs2MouseComponentName;
#endif

View File

@ -0,0 +1,209 @@
/*++
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 "Ps2Mouse.h"
//
// EFI Component Name Protocol
//
EFI_COMPONENT_NAME_PROTOCOL gPs2MouseComponentName = {
Ps2MouseComponentNameGetDriverName,
Ps2MouseComponentNameGetControllerName,
"eng"
};
static EFI_UNICODE_STRING_TABLE mPs2MouseDriverNameTable[] = {
{
"eng",
L"PS/2 Mouse Driver"
},
{
NULL,
NULL
}
};
EFI_STATUS
EFIAPI
Ps2MouseComponentNameGetDriverName (
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,
gPs2MouseComponentName.SupportedLanguages,
mPs2MouseDriverNameTable,
DriverName
);
}
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
)
/*++
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_POINTER_PROTOCOL *SimplePointerProtocol;
PS2_MOUSE_DEV *MouseDev;
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,
gPS2MouseDriver.DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
&gEfiIsaIoProtocolGuid,
gPS2MouseDriver.DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status != EFI_ALREADY_STARTED) {
return EFI_UNSUPPORTED;
}
//
// 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 LookupUnicodeString (
Language,
gPs2MouseComponentName.SupportedLanguages,
MouseDev->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 Ps2Mouse. 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
InitializePs2Mouse(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
//
// Install driver model protocol(s).
//
Status = EfiLibInstallAllDriverProtocols (
ImageHandle,
SystemTable,
&gPS2MouseDriver,
ImageHandle,
&gPs2MouseComponentName,
NULL,
NULL
);
ASSERT_EFI_ERROR (Status);
return Status;
}

View File

@ -0,0 +1,763 @@
/*++
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:
Ps2Mouse.c
Abstract:
PS/2 Mouse driver. Routines that interacts with callers,
conforming to EFI driver model
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
#include "Ps2Mouse.h"
#include "CommPs2.h"
//
// DriverBinding Protocol Instance
//
EFI_DRIVER_BINDING_PROTOCOL gPS2MouseDriver = {
PS2MouseDriverSupported,
PS2MouseDriverStart,
PS2MouseDriverStop,
0xa,
NULL,
NULL
};
EFI_STATUS
EFIAPI
PS2MouseDriverSupported (
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;
Status = EFI_SUCCESS;
//
// 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
//
switch (IsaIo->ResourceList->Device.HID) {
case EISA_PNP_ID (0xF03):
//
// Microsoft PS/2 style mouse
//
case EISA_PNP_ID (0xF13):
//
// PS/2 Port for PS/2-style Mice
//
break;
case EISA_PNP_ID (0x303):
//
// IBM Enhanced (101/102-key, PS/2 mouse support)
//
if (IsaIo->ResourceList->Device.UID == 1) {
break;
}
default:
Status = EFI_UNSUPPORTED;
break;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
gBS->CloseProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
EFI_STATUS
EFIAPI
PS2MouseDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
/*++
Routine Description:
Start protocol interfaces for the mouse device handles.
Arguments:
This - Protocol instance pointer.
Controller - Handle of device to bind driver to.
RemainingDevicePath - Not used.
Returns:
EFI_SUCCESS - This driver is added to DeviceHandle.
other - Errors occurred.
--*/
{
EFI_STATUS Status;
EFI_STATUS EmptyStatus;
EFI_ISA_IO_PROTOCOL *IsaIo;
PS2_MOUSE_DEV *MouseDev;
UINT8 Data;
EFI_TPL OldTpl;
EFI_STATUS_CODE_VALUE StatusCode;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
StatusCode = 0;
MouseDev = NULL;
IsaIo = NULL;
//
// Open the device path protocol
//
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_MOUSE | 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;
}
//
// Raise TPL to avoid keyboard operation impact
//
OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
//
// Allocate private data
//
MouseDev = AllocateZeroPool (sizeof (PS2_MOUSE_DEV));
if (MouseDev == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
//
// Setup the device instance
//
MouseDev->Signature = PS2_MOUSE_DEV_SIGNATURE;
MouseDev->Handle = Controller;
MouseDev->SampleRate = SSR_20;
MouseDev->Resolution = CMR4;
MouseDev->Scaling = SF1;
MouseDev->DataPackageSize = 3;
MouseDev->IsaIo = IsaIo;
MouseDev->DevicePath = ParentDevicePath;
//
// Resolution = 4 counts/mm
//
MouseDev->Mode.ResolutionX = 4;
MouseDev->Mode.ResolutionY = 4;
MouseDev->Mode.LeftButton = TRUE;
MouseDev->Mode.RightButton = TRUE;
MouseDev->SimplePointerProtocol.Reset = MouseReset;
MouseDev->SimplePointerProtocol.GetState = MouseGetState;
MouseDev->SimplePointerProtocol.Mode = &(MouseDev->Mode);
//
// Initialize keyboard controller if necessary
//
IsaIo->Io.Read (IsaIo, EfiIsaIoWidthUint8, KBC_CMD_STS_PORT, 1, &Data);
if ((Data & KBC_SYSF) != KBC_SYSF) {
Status = KbcSelfTest (IsaIo);
if (EFI_ERROR (Status)) {
StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_CONTROLLER_ERROR;
goto ErrorExit;
}
}
KbcEnableAux (IsaIo);
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_PROGRESS_CODE,
EFI_PERIPHERAL_MOUSE | EFI_P_PC_PRESENCE_DETECT,
ParentDevicePath
);
//
// Reset the mouse
//
Status = MouseDev->SimplePointerProtocol.Reset (&MouseDev->SimplePointerProtocol, TRUE);
if (EFI_ERROR (Status)) {
//
// mouse not connected
//
Status = EFI_SUCCESS;
StatusCode = EFI_PERIPHERAL_MOUSE | EFI_P_EC_NOT_DETECTED;
goto ErrorExit;
}
//
// Setup the WaitForKey event
//
Status = gBS->CreateEvent (
EVT_NOTIFY_WAIT,
TPL_NOTIFY,
MouseWaitForInput,
MouseDev,
&((MouseDev->SimplePointerProtocol).WaitForInput)
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
//
// Setup a periodic timer, used to poll mouse state
//
Status = gBS->CreateEvent (
EVT_TIMER | EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
PollMouse,
MouseDev,
&MouseDev->TimerEvent
);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
//
// Start timer to poll mouse (100 samples per second)
//
Status = gBS->SetTimer (MouseDev->TimerEvent, TimerPeriodic, 100000);
if (EFI_ERROR (Status)) {
Status = EFI_OUT_OF_RESOURCES;
goto ErrorExit;
}
MouseDev->ControllerNameTable = NULL;
AddUnicodeString (
"eng",
gPs2MouseComponentName.SupportedLanguages,
&MouseDev->ControllerNameTable,
L"PS/2 Mouse Device"
);
//
// Install protocol interfaces for the mouse device.
//
Status = gBS->InstallMultipleProtocolInterfaces (
&Controller,
&gEfiSimplePointerProtocolGuid,
&MouseDev->SimplePointerProtocol,
NULL
);
if (EFI_ERROR (Status)) {
goto ErrorExit;
}
gBS->RestoreTPL (OldTpl);
return Status;
ErrorExit:
KbcDisableAux (IsaIo);
if (StatusCode != 0) {
REPORT_STATUS_CODE_WITH_DEVICE_PATH (
EFI_ERROR_CODE | EFI_ERROR_MINOR,
StatusCode,
ParentDevicePath
);
}
if ((MouseDev != NULL) && (MouseDev->SimplePointerProtocol.WaitForInput != NULL)) {
gBS->CloseEvent (MouseDev->SimplePointerProtocol.WaitForInput);
}
if ((MouseDev != NULL) && (MouseDev->TimerEvent != NULL)) {
gBS->CloseEvent (MouseDev->TimerEvent);
}
if ((MouseDev != NULL) && (MouseDev->ControllerNameTable != NULL)) {
FreeUnicodeStringTable (MouseDev->ControllerNameTable);
}
//
// Since there will be no timer handler for mouse input any more,
// exhaust input data just in case there is still mouse data left
//
EmptyStatus = EFI_SUCCESS;
while (!EFI_ERROR (EmptyStatus)) {
EmptyStatus = In8042Data (IsaIo, &Data);
}
if (MouseDev != NULL) {
gBS->FreePool (MouseDev);
}
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->CloseProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->RestoreTPL (OldTpl);
return Status;
}
EFI_STATUS
EFIAPI
PS2MouseDriverStop (
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
// GC_TODO: EFI_SUCCESS - add return value to function comment
{
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;
}
//
// Disable mouse on keyboard controller
//
KbcDisableAux (MouseDev->IsaIo);
//
// 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);
gBS->FreePool (MouseDev);
gBS->CloseProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
This->DriverBindingHandle,
Controller
);
gBS->CloseProtocol (
Controller,
&gEfiIsaIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
MouseReset (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
/*++
Routine Description:
Reset the Mouse and do BAT test for it, if ExtendedVerification isTRUE and there is a mouse device connectted to system
Arguments:
This - Pointer of simple pointer Protocol.
ExtendedVerification - Whether configure mouse parameters. True: do; FALSE: skip.
Returns:
EFI_SUCCESS - The command byte is written successfully.
EFI_DEVICE_ERROR - Errors occurred during reseting keyboard.
--*/
{
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;
}
BOOLEAN
CheckMouseConnect (
IN PS2_MOUSE_DEV *MouseDev
)
/*++
Routine Description:
Check whether there is Ps/2 mouse device in system
Arguments:
PS2_MOUSE_DEV - Mouse Private Data Structure
Returns:
TRUE - Keyboard in System.
FALSE - Keyboard not in System.
--*/
{
EFI_STATUS Status;
Status = PS2MouseEnable (MouseDev->IsaIo);
if (!EFI_ERROR (Status)) {
return TRUE;
}
return FALSE;
}
EFI_STATUS
EFIAPI
MouseGetState (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN OUT EFI_SIMPLE_POINTER_STATE *State
)
/*++
Routine Description:
GC_TODO: Add function description
Arguments:
This - GC_TODO: add argument description
State - GC_TODO: add argument description
Returns:
EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
EFI_NOT_READY - GC_TODO: Add description for return value
EFI_SUCCESS - GC_TODO: Add description for return value
--*/
{
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;
}
VOID
EFIAPI
MouseWaitForInput (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Event notification function for SIMPLE_POINTER.WaitForInput event
Signal the event if there is input from mouse
Arguments:
Returns:
--*/
// GC_TODO: Event - add argument and description to function comment
// GC_TODO: Context - add argument and description to function comment
{
PS2_MOUSE_DEV *MouseDev;
MouseDev = (PS2_MOUSE_DEV *) Context;
//
// Someone is waiting on the mouse event, if there's
// input from mouse, signal the event
//
if (MouseDev->StateChanged) {
gBS->SignalEvent (Event);
}
}
VOID
EFIAPI
PollMouse (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Event notification function for TimerEvent event
If mouse device is connected to system, try to get the mouse packet data
Arguments:
Event - TimerEvent in PS2_MOUSE_DEV
Context - Pointer to PS2_MOUSE_DEV structure
Returns:
None
--*/
{
PS2_MOUSE_DEV *MouseDev;
MouseDev = (PS2_MOUSE_DEV *) Context;
//
// Polling mouse packet data
//
PS2MouseGetPacket (MouseDev);
}

View File

@ -0,0 +1,191 @@
/*++
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.
Module Name:
Ps2Mouse.h
Abstract:
PS/2 Mouse driver header file
Revision History
--*/
#ifndef _PS2MOUSE_H
#define _PS2MOUSE_H
//
// Include common header file for this module.
//
#include "CommonHeader.h"
//
// PS/2 mouse sample rate
//
typedef enum {
SSR_10,
SSR_20,
SSR_40,
SSR_60,
SSR_80,
SSR_100,
SSR_200,
MAX_SR
} MOUSE_SR;
//
// PS/2 mouse resolution
//
typedef enum {
CMR1,
CMR2,
CMR4,
CMR8,
MAX_CMR
} MOUSE_RE;
//
// PS/2 mouse scaling
//
typedef enum {
SF1,
SF2
} MOUSE_SF;
//
// Driver Private Data
//
#define PS2_MOUSE_DEV_SIGNATURE EFI_SIGNATURE_32 ('p', 's', '2', 'm')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_SIMPLE_POINTER_PROTOCOL SimplePointerProtocol;
EFI_SIMPLE_POINTER_STATE State;
EFI_SIMPLE_POINTER_MODE Mode;
BOOLEAN StateChanged;
//
// PS2 Mouse device specific information
//
MOUSE_SR SampleRate;
MOUSE_RE Resolution;
MOUSE_SF Scaling;
UINT8 DataPackageSize;
EFI_ISA_IO_PROTOCOL *IsaIo;
EFI_EVENT TimerEvent;
EFI_UNICODE_STRING_TABLE *ControllerNameTable;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
} PS2_MOUSE_DEV;
#define PS2_MOUSE_DEV_FROM_THIS(a) CR (a, PS2_MOUSE_DEV, SimplePointerProtocol, PS2_MOUSE_DEV_SIGNATURE)
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gPS2MouseDriver;
extern EFI_COMPONENT_NAME_PROTOCOL gPs2MouseComponentName;
//
// Function prototypes
//
EFI_STATUS
EFIAPI
PS2MouseDriverSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
PS2MouseDriverStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
);
EFI_STATUS
EFIAPI
PS2MouseDriverStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
);
//
// EFI Component Name Functions
//
EFI_STATUS
EFIAPI
Ps2MouseComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
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
EFIAPI
MouseReset (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
);
EFI_STATUS
EFIAPI
MouseGetState (
IN EFI_SIMPLE_POINTER_PROTOCOL *This,
IN OUT EFI_SIMPLE_POINTER_STATE *State
);
VOID
EFIAPI
MouseWaitForInput (
IN EFI_EVENT Event,
IN VOID *Context
);
VOID
EFIAPI
PollMouse (
IN EFI_EVENT Event,
IN VOID *Context
);
EFI_STATUS
In8042Data (
IN EFI_ISA_IO_PROTOCOL *IsaIo,
IN OUT UINT8 *Data
);
BOOLEAN
CheckMouseConnect (
IN PS2_MOUSE_DEV *MouseDev
);
#endif

View File

@ -0,0 +1,107 @@
#/** @file
# Ps2 Mouse Driver
#
# This dirver directly uses IsaIo protocol service to support Ps2 mouse 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 = Ps2Mouse
FILE_GUID = 202A2B0E-9A31-4812-B291-8747DF152439
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
ENTRY_POINT = InitializePs2Mouse
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# DRIVER_BINDING = gPS2MouseDriver
# COMPONENT_NAME = gPs2MouseComponentName
# 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_RELATIVE_TIMER
#
#
################################################################################
#
# Sources Section - list of files that are required for the build to succeed.
#
################################################################################
[Sources.common]
ComponentName.c
CommPs2.h
CommPs2.c
Ps2Mouse.h
Ps2Mouse.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]
ReportStatusCodeLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
UefiLib
UefiDriverEntryPoint
DebugLib
################################################################################
#
# Protocol C Name Section - list of Protocol and Protocol Notify C Names
# that this module uses or produces.
#
################################################################################
[Protocols]
gEfiIsaIoProtocolGuid # PROTOCOL TO_START
gEfiSimplePointerProtocolGuid # PROTOCOL BY_START
gEfiDevicePathProtocolGuid # PROTOCOL TO_START

View File

@ -0,0 +1,100 @@
<?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>Ps2Mouse</ModuleName>
<ModuleType>DXE_DRIVER</ModuleType>
<GuidValue>202A2B0E-9A31-4812-B291-8747DF152439</GuidValue>
<Version>1.0</Version>
<Abstract>Ps2 Mouse Driver</Abstract>
<Description>This dirver directly uses IsaIo protocol service to support Ps2 mouse 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>Ps2Mouse</OutputFileBasename>
</ModuleDefinitions>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DebugLib</Keyword>
</LibraryClass>
<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>BaseMemoryLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>MemoryAllocationLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>ReportStatusCodeLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>Ps2Mouse.c</Filename>
<Filename>Ps2Mouse.h</Filename>
<Filename>CommPs2.c</Filename>
<Filename>CommPs2.h</Filename>
<Filename>ComponentName.c</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
</PackageDependencies>
<Protocols>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="BY_START">
<ProtocolCName>gEfiSimplePointerProtocolGuid</ProtocolCName>
</Protocol>
<Protocol Usage="TO_START">
<ProtocolCName>gEfiIsaIoProtocolGuid</ProtocolCName>
</Protocol>
</Protocols>
<Events>
<CreateEvents>
<EventTypes Usage="ALWAYS_PRODUCED">
<EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>
<HelpText>Set up a time event to wait for the mouse input</HelpText>
</EventTypes>
<EventTypes Usage="ALWAYS_PRODUCED">
<EventType>EVENT_TYPE_PERIODIC_TIMER</EventType>
<HelpText>Set up a periodic timer to poll mouse state at a fixed interval</HelpText>
</EventTypes>
</CreateEvents>
<SignalEvents>
<EventTypes Usage="SOMETIMES_PRODUCED">
<EventType>EVENT_TYPE_RELATIVE_TIMER</EventType>
<HelpText>Signal an event whenever these is a pending event from mouse input</HelpText>
</EventTypes>
</SignalEvents>
</Events>
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<DriverBinding>gPS2MouseDriver</DriverBinding>
<ComponentName>gPs2MouseComponentName</ComponentName>
</Extern>
</Externs>
</ModuleSurfaceArea>