diff options
Diffstat (limited to 'Board/EM/Platform/Library/Dxe')
-rw-r--r-- | Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.c | 288 | ||||
-rw-r--r-- | Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.cif | 11 | ||||
-rw-r--r-- | Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.mak | 65 | ||||
-rw-r--r-- | Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.sdl | 40 | ||||
-rw-r--r-- | Board/EM/Platform/Library/Dxe/DxeKscLib/KscLib.h | 260 |
5 files changed, 664 insertions, 0 deletions
diff --git a/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.c b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.c new file mode 100644 index 0000000..f48c576 --- /dev/null +++ b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.c @@ -0,0 +1,288 @@ + +#include <Protocol\CpuIo.h> +#include <AmiDxeLib.h> +#include "KscLib.h" + +EFI_CPU_IO_PROTOCOL *mDxeKscLibCpuIo; + +BOOLEAN mDxeKscLibInitialized = FALSE; +extern EFI_BOOT_SERVICES *pBS; + +// +// Function implemenations +// +EFI_STATUS +InitializeKscLib ( + VOID + ) +/*++ + +Routine Description: + + Initialize the library. + The DXE library only requires CPU IO protocol, so this will locate CPU IO protocol + and save it for future use. + +Arguments: + + None. + +Returns: + + EFI_SUCCESS - KscLib is successfully initialized. + +--*/ +{ + EFI_STATUS Status; + UINT8 Data; + + // + // Locate CpuIo protocol + // + + Status = pBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mDxeKscLibCpuIo); + ASSERT_EFI_ERROR (Status); + + // + // Fail if EC doesn't exist. + // + mDxeKscLibCpuIo->Io.Read (mDxeKscLibCpuIo, EfiCpuIoWidthUint8, KSC_C_PORT, 1, &Data); + if(Data == 0xff){ + mDxeKscLibInitialized = FALSE; + Status = EFI_DEVICE_ERROR; + } else { + mDxeKscLibInitialized = TRUE; + Status = EFI_SUCCESS; + } + return Status; +} + +EFI_STATUS +SendKscCommand ( + UINT8 Command + ) +/*++ + +Routine Description: + + Sends command to Keyboard System Controller. + +Arguments: + + Command - Command byte to send + +Returns: + + EFI_SUCCESS - Command success + EFI_DEVICE_ERROR - Command error + +--*/ +{ + UINTN Index; + UINT8 KscStatus; + EFI_STATUS Status; + + KscStatus = 0; + Index = 0; + + // + // Locate CpuIo protocol + // + + Status = pBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mDxeKscLibCpuIo); + ASSERT_EFI_ERROR (Status); + + // + // Wait for KSC to be ready (with a timeout) + // + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_IBF) != 0) && (Index < KSC_TIME_OUT)) { + pBS->Stall (15); + ReceiveKscStatus (&KscStatus); + Index++; + } + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + + // + // Send the KSC command + // + Status = mDxeKscLibCpuIo->Io.Write ( + mDxeKscLibCpuIo, + EfiCpuIoWidthUint8, + KSC_C_PORT, + 1, + &Command + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +EFI_STATUS +ReceiveKscStatus ( + UINT8 *KscStatus + ) +/*++ + +Routine Description: + + Receives status from Keyboard System Controller. + +Arguments: + + Status - Status byte to receive + +Returns: + + EFI_SUCCESS - Always success + +--*/ +{ + EFI_STATUS Status = EFI_SUCCESS; + + // + // Locate CpuIo protocol + // + + Status = pBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mDxeKscLibCpuIo); + ASSERT_EFI_ERROR (Status); + + // + // Read and return the status + // + Status = mDxeKscLibCpuIo->Io.Read ( + mDxeKscLibCpuIo, + EfiCpuIoWidthUint8, + KSC_C_PORT, + 1, + KscStatus + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +EFI_STATUS +SendKscData ( + UINT8 Data + ) +/*++ + +Routine Description: + + Sends data to Keyboard System Controller. + +Arguments: + + Data - Data byte to send + +Returns: + + EFI_SUCCESS - Success + EFI_TIMEOUT - Timeout + Other - Failed + +--*/ +{ + UINTN Index; + UINT8 KscStatus; + EFI_STATUS Status = EFI_SUCCESS; + + Index = 0; + + // + // Locate CpuIo protocol + // + Status = pBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mDxeKscLibCpuIo); + ASSERT_EFI_ERROR (Status); + + // + // Wait for KSC to be ready (with a timeout) + // + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_IBF) != 0) && (Index < KSC_TIME_OUT)) { + pBS->Stall (15); + ReceiveKscStatus (&KscStatus); + Index++; + } + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + + // + // Send the data and return + // + Status = mDxeKscLibCpuIo->Io.Write ( + mDxeKscLibCpuIo, + EfiCpuIoWidthUint8, + KSC_D_PORT, + 1, + &Data + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +EFI_STATUS +ReceiveKscData ( + UINT8 *Data + ) +/*++ + +Routine Description: + + Receives data from Keyboard System Controller. + +Arguments: + + Data - Data byte received + +Returns: + + EFI_SUCCESS - Read success + EFI_DEVICE_ERROR - Read error + +--*/ +{ + UINTN Index; + UINT8 KscStatus; + EFI_STATUS Status = EFI_SUCCESS; + + Index = 0; + + // + // Locate CpuIo protocol + // + + Status = pBS->LocateProtocol (&gEfiCpuIoProtocolGuid, NULL, &mDxeKscLibCpuIo); + ASSERT_EFI_ERROR (Status); + // + // Wait for KSC to be ready (with a timeout) + // + ReceiveKscStatus (&KscStatus); + while (((KscStatus & KSC_S_OBF) == 0) && (Index < KSC_TIME_OUT)) { + pBS->Stall (15); + ReceiveKscStatus (&KscStatus); + Index++; + } + if (Index >= KSC_TIME_OUT) { + return EFI_DEVICE_ERROR; + } + + // + // Read KSC data and return + // + Status = mDxeKscLibCpuIo->Io.Read ( + mDxeKscLibCpuIo, + EfiCpuIoWidthUint8, + KSC_D_PORT, + 1, + Data + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} diff --git a/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.cif b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.cif new file mode 100644 index 0000000..887e0f7 --- /dev/null +++ b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.cif @@ -0,0 +1,11 @@ +<component> + name = "DxeKscLib" + category = ModulePart + LocalRoot = "Board\EM\Platform\Library\Dxe\DxeKscLib" + RefName = "DxeKscLib" +[files] +"DxeKscLib.sdl" +"DxeKscLib.mak" +"DxeKscLib.c" +"KscLib.h" +<endComponent> diff --git a/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.mak b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.mak new file mode 100644 index 0000000..d60b49e --- /dev/null +++ b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.mak @@ -0,0 +1,65 @@ +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#************************************************************************* + +#************************************************************************* +# $Header: /Alaska/SOURCE/Modules/SharkBayRefCodes/Platform/IntelPlatformProtocolLib/DxeKscLib/DxeKscLib.mak 1 2/09/12 12:39a Yurenlai $ +# +# $Revision: 1 $ +# +# $Date: 2/09/12 12:39a $ +#************************************************************************* +# Revision History +# ---------------- +# $Log: /Alaska/SOURCE/Modules/SharkBayRefCodes/Platform/IntelPlatformProtocolLib/DxeKscLib/DxeKscLib.mak $ +# +# 1 2/09/12 12:39a Yurenlai +# Initial check in. +# +#************************************************************************* +#<AMI_FHDR_START> +# +# Name: <ComponentName>.mak +# +# Description: +# +#<AMI_FHDR_END> +#********************************************************************** +all : DxeKscLib + +$(BUILD_DIR)\DxeKscLib.lib : DxeKscLib + +DxeKscLib : $(BUILD_DIR)\DxeKscLib.mak DxeKscLibBin + +$(BUILD_DIR)\DxeKscLib.mak : $(DxeKscLib_DIR)\$(@B).cif $(DxeKscLib_DIR)\$(@B).mak $(BUILD_RULES) + $(CIF2MAK) $(DxeKscLib_DIR)\$(@B).cif $(CIF2MAK_DEFAULTS) + +DxeKscLibBin : $(EFIDRIVERLIB) + $(MAKE) /$(MAKEFLAGS) $(BUILD_DEFAULTS)\ + /f $(BUILD_DIR)\DxeKscLib.mak all\ + "CFLAGS=$(CFLAGS) "\ + TYPE=LIBRARY \ + +#************************************************************************* +#************************************************************************* +#** ** +#** (C)Copyright 1985-2011, American Megatrends, Inc. ** +#** ** +#** All Rights Reserved. ** +#** ** +#** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 ** +#** ** +#** Phone: (770)-246-8600 ** +#** ** +#************************************************************************* +#*************************************************************************
\ No newline at end of file diff --git a/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.sdl b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.sdl new file mode 100644 index 0000000..677ad94 --- /dev/null +++ b/Board/EM/Platform/Library/Dxe/DxeKscLib/DxeKscLib.sdl @@ -0,0 +1,40 @@ +TOKEN + Name = "INTEL_CRB_DXE_KSC_LIB_SUPPORT" + Value = "1" + Help = "Main switch to enable INTEL_CRB_DXE_KSC_LIB(EC:H8)support in Project" + TokenType = Boolean + TargetEQU = Yes + TargetMAK = Yes + Master = Yes +End + +PATH + Name = "DxeKscLib_DIR" +End + +MODULE + Help = "Includes DxeKscLib.mak to Project" + File = "DxeKscLib.mak" +End + +ELINK + Name = "DxeKscLib_LIB" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "$(BUILD_DIR)\DxeKscLib.lib" + Parent = "DxeKscLib_LIB" + InvokeOrder = AfterParent +End + +ELINK + Name = "DxeKscLib_INCLUDES" + InvokeOrder = ReplaceParent +End + +ELINK + Name = "/I $(DxeKscLib_DIR)" + Parent = "DxeKscLib_INCLUDES" + InvokeOrder = AfterParent +End diff --git a/Board/EM/Platform/Library/Dxe/DxeKscLib/KscLib.h b/Board/EM/Platform/Library/Dxe/DxeKscLib/KscLib.h new file mode 100644 index 0000000..2aee1c7 --- /dev/null +++ b/Board/EM/Platform/Library/Dxe/DxeKscLib/KscLib.h @@ -0,0 +1,260 @@ + +#ifndef _KSC_LIB_H_ +#define _KSC_LIB_H_ + +// +// Include files +// +///#include "Tiano.h" + +// +// Timeout if KSC command/data fails +// +#define KSC_TIME_OUT 0x20000 + +// +// The Keyboard and System management Controller (KSC) implements a standard 8042 keyboard +// controller interface at ports 0x60/0x64 and a ACPI compliant system management controller +// at ports 0x62/0x66. Port 0x66 is the command and status port, port 0x62 is the data port. +// +#define KSC_D_PORT 0x62 +#define KSC_C_PORT 0x66 + +// +// Status Port 0x62 +// +#define KSC_S_OVR_TMP 0x80 // Current CPU temperature exceeds the threshold +#define KSC_S_SMI_EVT 0x40 // SMI event is pending +#define KSC_S_SCI_EVT 0x20 // SCI event is pending +#define KSC_S_BURST 0x10 // KSC is in burst mode or normal mode +#define KSC_S_CMD 0x08 // Byte in data register is command/data +#define KSC_S_IGN 0x04 // Ignored +#define KSC_S_IBF 0x02 // Input buffer is full/empty +#define KSC_S_OBF 0x01 // Output buffer is full/empty + +// +// KSC commands that are issued to the KSC through the command port (0x66). +// New commands and command parameters should only be written by the host when IBF=0. +// Data read from the KSC data port is valid only when OBF=1. +// +#define KSC_C_SMI_NOTIFY_ENABLE 0x04 // Enable SMI notifications to the host +#define KSC_C_SMI_NOTIFY_DISABLE 0x05 // SMI notifications are disabled and pending notifications cleared +#define KSC_C_QUERY_SYS_STATUS 0x06 // Returns 1 byte of information about the system status +#define KSC_B_SYS_STATUS_FAN 0x40 // Fan status (1 = ON) +#define KSC_B_SYS_STATUS_DOCK 0x20 // Dock status (1 = Docked) +#define KSC_B_SYS_STATUS_AC 0x10 // AC power (1 = AC powered) +#define KSC_B_SYS_STATUS_THERMAL 0x0F // CPU thermal state (0 ~ 9) +#define KSC_C_FAB_ID 0x0D // Get the board fab ID in the lower 3 bits +#define KSC_C_SYSTEM_POWER_OFF 0x22 // Turn off the system power +#define KSC_C_LAN_ON 0x46 // Turn on the power to LAN through EC/KSC +#define KSC_C_LAN_OFF 0x47 // Turn off the power to LAN through EC/KSC +#define KSC_C_GET_TEMP 0x50 // Returns the CPU temperature as read from the SMBus thermal sensor. +#define KSC_C_SET_CTEMP 0x58 // The next byte written to the data port will be the shutdown temperature +#define KSC_EC_PCH_SMBUS_EN 0x60 // EC PCH SMBus thermal monitoring Enable cmd +#define KSC_EC_PCH_SMBUS_DIS 0x61 // EC PCH SMBus thermal monitoring Disable cmd +#define KSC_TS_ON_DIMM_EN 0x6B // TS-on-DIMM thermal monitoring enable command +#define KSC_TS_ON_DIMM_DIS 0x6C // TS-on-DIMM thermal monitoring disable command +#define KSC_C_PCH_SMBUS_MSG_LENGTH 0x6D // PCH SMBus block read buffer length +#define KSC_C_PCH_SMBUS_PEC_EN 0x6E // PCH SMBus Packet Error Checking (PEC) Enable command. +#define KSC_C_PCH_SMBUS_PEC_DIS 0x76 // PCH SMBus Packet Error Checking (PEC) Disable command. +#define KSC_C_EC_SMBUS_HIGH_SPEED 0x75 // EC SMBus high speed mode command +#define KSC_EC_PCH_SMBUS_WRITE_EN 0x68 // EC PCH SMBus Write Enable cmd +#define KSC_EC_PCH_SMBUS_WRITE_DIS 0x69 // EC PCH SMBus Write Disable cmd +#define KSC_C_SMI_QUERY 0x70 // The host reads the data port to retrieve the notifications +#define KSC_C_SMI_TIMER 0x71 // Commands the KSC to generate a periodic SMI to the host +#define KSC_C_SMI_HOTKEY 0x72 // Get the scan code of hotkey pressed (CTRL + ALT + SHIFT + key) +#define KSC_C_READ_MEM 0x80 // Read the KSC memory +#define KSC_C_WRITE_MEM 0x81 // Write the KSC memory +#define KSC_C_DOCK_STATUS 0x8A // Get the dock status +#define KSC_B_DOCK_STATUS_ATTACH 0x01 // Dock status (1 = Attach) +#define KSC_C_KSC_REVISION 0x90 // Get the revision for the KSC +#define KSC_C_SMI_INJECT 0xBA // The next byte written to the data port will generate an immediate SMI +#define KSC_C_SMI_DISABLE 0xBC // SMI generation by the KSC is disabled +#define KSC_C_SMI_ENABLE 0xBD // SMI generation by the KSC is enabled +#define KSC_C_ACPI_ENABLE 0xAA // Enable ACPI mode +#define KSC_C_ACPI_DISABLE 0xAB // Disable ACPI mode + +// +// KSC commands that are only valid if the EC has ACPI mode enabled. +// Note that capacity and voltage are 16 bit values, thus you need to read them from +// ACPI space with two reads (little Endian). +// +#define KSC_VIRTUAL_BAT_STATUS 48 // Status of the virtual battery (present) +#define KSC_VIRTUAL_BAT_PRESENT_MASK 0x10 // Bit 4 is the indicator + +#define KSC_REAL_BAT1_STATUS 50 // Status of the first real battery (present, charging) +#define KSC_REAL_BAT1_REMAINING_CAPACITY 89 // Remaining capacity in mWh +#define KSC_REAL_BAT1_RESOLUTION_VOLTAGE 93 // Full resolution voltage in mV + +#define KSC_REAL_BAT2_STATUS 54 // Status of the second real battery (present, charging) +#define KSC_REAL_BAT2_REMAINING_CAPACITY 99 // Remaining capacity in mWh +#define KSC_REAL_BAT2_RESOLUTION_VOLTAGE 103 // Full resolution voltage in mV + +#define KSC_REAL_BAT_PRESENT_MASK 0x8 // Bit 3 is the indicator +#define KSC_REAL_BAT_CHARGING_MASK 0x1 // Bit 1 is the indicator + +// +// SMI notification code table, read through command KSC_C_SMI_QUERY +// +#define KSC_N_SMI_NULL 0x00 // Null marks the end of the SMI notification queue +#define KSC_N_SMI_HOTKEY 0x20 // Hotkey pressed SMI +#define KSC_N_SMI_ACINSERTION 0x30 // AC insertion SMI +#define KSC_N_SMI_ACREMOVAL 0x31 // AC removal SMI +#define KSC_N_SMI_PWRSW 0x32 // Power switch press SMI +#define KSC_N_SMI_LID 0x33 // Lid switch change SMI +#define KSC_N_SMI_VB 0x34 // Virtual battery switch change SMI +#define KSC_N_SMI_THERM_0 0x60 // Thermal state 0 SMI +#define KSC_N_SMI_THERM_1 0x61 // Thermal state 1 SMI +#define KSC_N_SMI_THERM_2 0x62 // Thermal state 2 SMI +#define KSC_N_SMI_THERM_3 0x63 // Thermal state 3 SMI +#define KSC_N_SMI_THERM_4 0x64 // Thermal state 4 SMI +#define KSC_N_SMI_THERM_5 0x65 // Thermal state 5 SMI +#define KSC_N_SMI_THERM_6 0x66 // Thermal state 6 SMI +#define KSC_N_SMI_THERM_7 0x67 // Thermal state 7 SMI +#define KSC_N_SMI_THERM_8 0x68 // Thermal state 8 SMI +#define KSC_N_SMI_DOCKED 0x70 // Dock complete SMI +#define KSC_N_SMI_UNDOCKED 0x71 // Undock complete SMI +#define KSC_N_SMI_UNDOCKREQUEST 0x72 // Undocking request SMI +#define KSC_N_SMI_TIMER 0x80 // Timer wakeup SMI + +// +// Hotkey scan code (CTRL + ALT + SHIFT + key) +// +#define KSC_HK_ESC 0x01 // ESC +#define KSC_HK_1 0x02 // 1 ! +#define KSC_HK_2 0x03 // 2 @ +#define KSC_HK_3 0x04 // 3 # +#define KSC_HK_4 0x05 // 4 $ +#define KSC_HK_5 0x06 // 5 % +#define KSC_HK_6 0x07 // 6 ^ +#define KSC_HK_7 0x08 // 7 & +#define KSC_HK_8 0x09 // 8 * +#define KSC_HK_9 0x0A // 9 ( +#define KSC_HK_0 0x0B // 0 ) +#define KSC_HK_MINUS 0x0C // - _ +#define KSC_HK_ADD 0x0D // = + +#define KSC_HK_F1 0x3B // F1 +#define KSC_HK_F2 0x3C // F2 +#define KSC_HK_F3 0x3D // F3 +#define KSC_HK_F4 0x3E // F4 +#define KSC_HK_F5 0x3F // F5 +#define KSC_HK_F6 0x40 // F6 +#define KSC_HK_F7 0x41 // F7 +#define KSC_HK_F8 0x42 // F8 +#define KSC_HK_F9 0x43 // F9 +#define KSC_HK_F10 0x44 // F10 +#define KSC_HK_F11 0x57 // F11 +#define KSC_HK_F12 0x58 // F12 + +// +// Function declarations +// +EFI_STATUS +InitializeKscLib ( + VOID + ); +/*++ + +Routine Description: + + This function initializes the KSC library. + It must be called before using any of the other KSC library functions. + +Arguments: + + None. + +Returns: + + EFI_SUCCESS - KscLib is successfully initialized. + +--*/ + +EFI_STATUS +SendKscCommand ( + UINT8 Command + ); +/*++ + +Routine Description: + + Send a command to the Keyboard System Controller. + +Arguments: + + Command - Command byte to send + +Returns: + + EFI_SUCCESS - Command success + EFI_TIMEOUT - Command timeout + Other - Command failed + +--*/ + +EFI_STATUS +SendKscData ( + UINT8 Data + ); +/*++ + +Routine Description: + + Sends data to Keyboard System Controller. + +Arguments: + + Data - Data byte to send + +Returns: + + EFI_SUCCESS - Success + EFI_TIMEOUT - Timeout + Other - Failed + +--*/ + +EFI_STATUS +ReceiveKscData ( + UINT8 *Data + ); +/*++ + +Routine Description: + + Receives data from Keyboard System Controller. + +Arguments: + + Data - Data byte received + +Returns: + + EFI_SUCCESS - Read success + EFI_TIMEOUT - Read timeout + Other - Read failed + +--*/ + +EFI_STATUS +ReceiveKscStatus ( + UINT8 *KscStatus + ); +/*++ + +Routine Description: + + Receives status from Keyboard System Controller. + +Arguments: + + Status - Status byte to receive + +Returns: + + EFI_SUCCESS - Success + Other - Failed + +--*/ + +#endif |