diff options
author | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
---|---|---|
committer | raywu <raywu0301@gmail.com> | 2018-06-15 00:00:50 +0800 |
commit | b7c51c9cf4864df6aabb99a1ae843becd577237c (patch) | |
tree | eebe9b0d0ca03062955223097e57da84dd618b9a /ReferenceCode/Haswell/SampleCode/Include | |
download | zprj-master.tar.xz |
Diffstat (limited to 'ReferenceCode/Haswell/SampleCode/Include')
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/AslUpdateLib.h | 178 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/BootGuardRevocationLib.h | 35 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/Cpu.h | 63 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/FlashMap.h | 27 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/KscLib.h | 232 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/PeiKscLib.h | 224 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/SmmIoLib.h | 265 | ||||
-rw-r--r-- | ReferenceCode/Haswell/SampleCode/Include/acpibuild.dsc | 96 |
8 files changed, 1120 insertions, 0 deletions
diff --git a/ReferenceCode/Haswell/SampleCode/Include/AslUpdateLib.h b/ReferenceCode/Haswell/SampleCode/Include/AslUpdateLib.h new file mode 100644 index 0000000..eb9d1cf --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/AslUpdateLib.h @@ -0,0 +1,178 @@ +/** @file + ASL dynamic update library definitions. + + This library provides dymanic update to various ASL structures. + + There may be different libraries for different environments (PEI, BS, RT, SMM). + Make sure you meet the requirements for the library (protocol dependencies, use + restrictions, etc). + +@copyright + Copyright (c) 1999 - 2012 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _ASL_UPDATE_LIB_H_ +#define _ASL_UPDATE_LIB_H_ + +/// +/// Include files +/// +#include "Tiano.h" +#include "Acpi.h" +#include "Acpi3_0.h" + +#include EFI_PROTOCOL_DEPENDENCY (AcpiSupport) +#include EFI_PROTOCOL_DEPENDENCY (AcpiTable) + +/// +/// AML parsing definitions +/// +#define AML_NAME_OP 0x08 +#define AML_BYTE_OP 0x0A +#define AML_WORD_OP 0x0B +#define AML_DWORD_OP 0x0C +#define AML_QWORD_OP 0x0E +#define AML_SCOPE_OP 0x10 +#define AML_BUFFER_OP 0x11 +#define AML_PACKAGE_OP 0x12 +#define AML_METHOD_OP 0x14 +#define AML_EXT_OP 0x5B +#define AML_OPREGION_OP 0x80 +#define AML_DEVICE_OP 0x82 +#define AML_PROCESSOR_OP 0x83 + +/// +/// Magic number definition for values to be updated +/// +#define UINT16_BIT_MAGIC_NUMBER 0xFFFF +#define UINT32_BIT_MAGIC_NUMBER 0xFFFFFFFF + +/// +/// ASL PSS package structure layout +/// +#pragma pack(1) +typedef struct { + UINT8 NameOp; ///< 12h ;First opcode is a NameOp. + UINT8 PackageLead; ///< 20h ;First opcode is a NameOp. + UINT8 NumEntries; ///< 06h ;First opcode is a NameOp. + UINT8 DwordPrefix1; ///< 0Ch + UINT32 CoreFrequency; ///< 00h + UINT8 DwordPrefix2; ///< 0Ch + UINT32 Power; ///< 00h + UINT8 DwordPrefix3; ///< 0Ch + UINT32 TransLatency; ///< 00h + UINT8 DwordPrefix4; ///< 0Ch + UINT32 BMLatency; ///< 00h + UINT8 DwordPrefix5; ///< 0Ch + UINT32 Control; ///< 00h + UINT8 DwordPrefix6; ///< 0Ch + UINT32 Status; ///< 00h +} PSS_PACKAGE_LAYOUT; +#pragma pack() + +/** + Initialize the ASL update library state. + This must be called prior to invoking other library functions. + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +InitializeAslUpdateLib ( + VOID + ); + +/** + This function locates an ACPI structure and updates it. + This function knows how to update operation regions and BUFA/BUFB resource structures. + + This function may not be implemented in all instantiations of this library. + + @param[in] AslSignature - The signature of Operation Region that we want to update. + @param[in] BaseAddress - Base address of IO trap. + @param[in] Length - Length of IO address. + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +UpdateAslCode ( + IN UINT32 AslSignature, + IN UINT16 BaseAddress, + IN UINT8 Length + ); + +/** + This function uses the ACPI support protocol to locate an ACPI table using the . + It is really only useful for finding tables that only have a single instance, + e.g. FADT, FACS, MADT, etc. It is not good for locating SSDT, etc. + Matches are determined by finding the table with ACPI table that has + a matching signature and version. + + @param[in] TableId - Pointer to an ASCII string containing the Signature to match + @param[in] Table - Updated with a pointer to the table + @param[in] Handle - AcpiSupport protocol table handle for the table found + @param[in] Version - On input, the version of the table desired, + on output, the versions the table belongs to + (see AcpiSupport protocol for details) + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableBySignature ( + IN UINT32 Signature, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ); + +/** + This function uses the ACPI support protocol to locate an ACPI SSDT table. + The table is located by searching for a matching OEM Table ID field. + Partial match searches are supported via the TableIdSize parameter. + + @param[in] TableId - Pointer to an ASCII string containing the OEM Table ID from the ACPI table header + @param[in] TableIdSize - Length of the TableId to match. Table ID are 8 bytes long, this function + will consider it a match if the first TableIdSize bytes match + @param[in] Table - Updated with a pointer to the table + @param[in] Handle - AcpiSupport protocol table handle for the table found + @param[in] Version - See AcpiSupport protocol, GetAcpiTable function for use + + @retval EFI_SUCCESS - The function completed successfully. +**/ +EFI_STATUS +LocateAcpiTableByOemTableId ( + IN UINT8 *TableId, + IN UINT8 TableIdSize, + IN OUT EFI_ACPI_DESCRIPTION_HEADER **Table, + IN OUT UINTN *Handle, + IN OUT EFI_ACPI_TABLE_VERSION *Version + ); + +/** + This function calculates and updates an UINT8 checksum. + + @param[in] Buffer Pointer to buffer to checksum + @param[in] Size Number of bytes to checksum + @param[in] ChecksumOffset Offset to place the checksum result in + + @retval EFI_SUCCESS The function completed successfully. +**/ +EFI_STATUS +EFI_BOOTSERVICE +AcpiChecksum ( + IN VOID *Buffer, + IN UINTN Size, + IN UINTN ChecksumOffset + ); + +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/BootGuardRevocationLib.h b/ReferenceCode/Haswell/SampleCode/Include/BootGuardRevocationLib.h new file mode 100644 index 0000000..f7d0fbc --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/BootGuardRevocationLib.h @@ -0,0 +1,35 @@ +/** @file + Header file for Boot Guard revocation notification. + +@copyright + Copyright (c) 2012 - 2013 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _BOOT_GUARD_REVOCATION_LIB_H_ +#define _BOOT_GUARD_REVOCATION_LIB_H_ + +#if !defined(EDK_RELEASE_VERSION) || (EDK_RELEASE_VERSION < 0x00020000) +#include "EdkIIGlueDxe.h" +#endif + +/** + Provide a hook for OEM to deal with Boot Guard revocation flow. +**/ +VOID +EFIAPI +BootGuardOemRevocationHook ( + VOID + ); + +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/Cpu.h b/ReferenceCode/Haswell/SampleCode/Include/Cpu.h new file mode 100644 index 0000000..94b7e56 --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/Cpu.h @@ -0,0 +1,63 @@ +/** @file + Various CPU-specific definitions. + +@copyright + Copyright (c) 1999 - 2012 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _CPU_H_ +#define _CPU_H_ + +#define B_FAMILY_MODEL_STEPPING 0x00000FFF + +#define EFI_MSR_IA32_PERF_STS 0x198 +#define EFI_MSR_IA32_PERF_CTL 0x199 +#define EFI_MSR_IA32_CLOCK_MODULATION 0x19A +#define EFI_MSR_IA32_THERM_STATUS 0x19C + +#define B_BS_VID 0x0000003F +#define N_BS_VID 0 +#define B_BS_RATIO 0x00001F00 +#define N_BS_RATIO 8 + +/// +/// UINT64 workaround +/// +/// The MS compiler doesn't handle QWORDs very well. I'm breaking +/// them into DWORDs to circumvent the problems. Converting back +/// shouldn't be a big deal. +/// +#pragma pack(1) +typedef union _MSR_REGISTER { + UINT64 Qword; + + struct _DWORDS { + UINT32 Low; + UINT32 High; + } Dwords; + + struct _BYTES { + UINT8 FirstByte; + UINT8 SecondByte; + UINT8 ThirdByte; + UINT8 FouthByte; + UINT8 FifthByte; + UINT8 SixthByte; + UINT8 SeventhByte; + UINT8 EighthByte; + } Bytes; + +} MSR_REGISTER; +#pragma pack() +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/FlashMap.h b/ReferenceCode/Haswell/SampleCode/Include/FlashMap.h new file mode 100644 index 0000000..b72df34 --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/FlashMap.h @@ -0,0 +1,27 @@ +/** @file + File content auto-generated by FlashMap utility + +@copyright + Copyright (c) 1999 - 2012 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _FLASH_MAP_H_ +#define _FLASH_MAP_H_ + +/// +/// Please confirm following configuration from your platform setting. +/// +#define FLASH_REGION_MICROCODE_SIZE 0xffd90000 +#define FLASH_REGION_MICROCODE_BASE 0x00040000 +#endif ///< #ifndef _FLASH_MAP_H_ diff --git a/ReferenceCode/Haswell/SampleCode/Include/KscLib.h b/ReferenceCode/Haswell/SampleCode/Include/KscLib.h new file mode 100644 index 0000000..a428f77 --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/KscLib.h @@ -0,0 +1,232 @@ +/** @file + KSC library functions and definitions. + + This library provides basic KSC interface. It is deemed simple enough and uses in + so few cases that there is not currently benefit to implementing a protocol. + If more consumers are added, it may be benefitial to implement as a protocol. + + There may be different libraries for different environments (PEI, BS, RT, SMM). + Make sure you meet the requirements for the library (protocol dependencies, use + restrictions, etc). + +@copyright + Copyright (c) 1999 - 2012 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#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 +/// +/** + This function initializes the KSC library. + It must be called before using any of the other KSC library functions. + + @param[in] None. + + @retval EFI_SUCCESS - KscLib is successfully initialized. +**/ +EFI_STATUS +InitializeKscLib ( + VOID + ); +/** + Send a command to the Keyboard System Controller. + + @param[in] Command - Command byte to send + + @retval EFI_SUCCESS - Command success + @retval EFI_TIMEOUT - Command timeout + @retval Other - Command failed +**/ +EFI_STATUS +SendKscCommand ( + UINT8 Command + ); +/** + Sends data to Keyboard System Controller. + + @param[in] Data - Data byte to send + + @retval EFI_SUCCESS - Success + @retval EFI_TIMEOUT - Timeout + @retval Other - Failed +**/ +EFI_STATUS +SendKscData ( + UINT8 Data + ); +/** + Receives data from Keyboard System Controller. + + @param[in] Data - Data byte received + + @retval EFI_SUCCESS - Read success + @retval EFI_TIMEOUT - Read timeout + @retval Other - Read failed +**/ +EFI_STATUS +ReceiveKscData ( + UINT8 *Data + ); +/** + Receives status from Keyboard System Controller. + + @param[in] KscStatus - Status byte to receive + + @retval EFI_SUCCESS - Success + @retval Other - Failed +**/ +EFI_STATUS +ReceiveKscStatus ( + UINT8 *KscStatus + ); +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/PeiKscLib.h b/ReferenceCode/Haswell/SampleCode/Include/PeiKscLib.h new file mode 100644 index 0000000..76c3dfa --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/PeiKscLib.h @@ -0,0 +1,224 @@ +/** @file + KSC library functions and definitions. + + This library provides basic KSC interface. It is deemed simple enough and uses in + so few cases that there is not currently benefit to implementing a protocol. + If more consumers are added, it may be benefitial to implement as a protocol. + + There may be different libraries for different environments (PEI, BS, RT, SMM). + Make sure you meet the requirements for the library (protocol dependencies, use + restrictions, etc). + +@copyright + Copyright (c) 2012 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. + + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _PEI_KSC_LIB_H_ +#define _PEI_KSC_LIB_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_B_BOARD_ID 0x0F ///< Board ID = [3:0] +#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_DTEMP 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_C_EN_DTEMP 0x5E ///< Commands KSC to begin reading Thermal Diode and comparing to Critical Temperature +#define KSC_C_DIS_DTEMP 0x5F ///< Commands KSC to stop reading Thermal Diode +#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_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 + +/// +/// 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 + +#include EFI_PPI_DEPENDENCY (CpuIo) +#include EFI_PPI_DEPENDENCY (Stall) + +/// +/// Function declarations +/// +EFI_STATUS +SendKscCommand ( + EFI_PEI_SERVICES **PeiServices, + PEI_CPU_IO_PPI *CpuIo, + PEI_STALL_PPI *StallPpi, + UINT8 Command + ); +/** + Sends command to Keyboard System Controller. + + @param[in] PeiServices - PEI Services + @param[in] CpiIo - Pointer to CPU IO protocol + @param[in] StallPpi - Pointer to Stall PPI + @param[in] Command - Command byte to send + + @retval EFI_SUCCESS - Command success + @retval EFI_DEVICE_ERROR - Command error + @retval EFI_TIMEOUT - Command timeout +**/ + +EFI_STATUS +SendKscData ( + EFI_PEI_SERVICES **PeiServices, + PEI_CPU_IO_PPI *CpuIo, + PEI_STALL_PPI *StallPpi, + UINT8 Data + ); +/** + Sends data to Keyboard System Controller. + + @param[in] PeiServices - PEI Services + @param[in] CpiIo - Pointer to CPU IO protocol + @param[in] StallPpi - Pointer to Stall PPI + @param[in] Data - Data byte to send + + @retval EFI_SUCCESS - Success + @retval EFI_DEVICE_ERROR - Error + @retval EFI_TIMEOUT - Command timeout +**/ + +EFI_STATUS +ReceiveKscData ( + EFI_PEI_SERVICES **PeiServices, + PEI_CPU_IO_PPI *CpuIo, + PEI_STALL_PPI *StallPpi, + UINT8 *Data + ); +/** + Receives data from Keyboard System Controller. + + @param[in] PeiServices - PEI Services + @param[in] CpiIo - Pointer to CPU IO protocol + @param[in] StallPpi - Pointer to Stall PPI + @param[in] Data - Data byte received + + @retval EFI_SUCCESS - Read success + @retval EFI_DEVICE_ERROR - Read error + @retval EFI_TIMEOUT - Command timeout +**/ + +EFI_STATUS +ReceiveKscStatus ( + EFI_PEI_SERVICES **PeiServices, + PEI_CPU_IO_PPI *CpuIo, + UINT8 *KscStatus + ); +/** + Receives status from Keyboard System Controller. + + @param[in] PeiServices - PEI Services + @param[in] CpiIo - Pointer to CPU IO protocol + @param[in] KscStatus - Status byte to receive + + @retval EFI_DEVICE_ERROR - Ksc library has not initialized yet or KSC not present + @retval EFI_SUCCESS - Get KSC status successfully +**/ + +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/SmmIoLib.h b/ReferenceCode/Haswell/SampleCode/Include/SmmIoLib.h new file mode 100644 index 0000000..cc9eee9 --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/SmmIoLib.h @@ -0,0 +1,265 @@ +/** @file + This library provides SMM functions for IO and PCI IO access. + These can be used to save size and simplify code. + All contents must be runtime and SMM safe. + +@copyright + Copyright (c) 1999 - 2013 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. + This file contains a 'Sample Driver' and is licensed as such + under the terms of your license agreement with Intel or your + vendor. This file may be modified by the user, subject to + the additional terms of the license agreement +**/ +#ifndef _SMM_IO_LIB_H_ +#define _SMM_IO_LIB_H_ + +#include "EdkIIGlueDxe.h" +#include "Pci22.h" + +/// +/// Utility consumed protocols +/// +#include EFI_PROTOCOL_DEFINITION (SmmBase) + +/// +/// Global variables that must be defined and initialized to use this library +/// +extern EFI_SMM_SYSTEM_TABLE *mSmst; + +/// +/// Definitions +/// +#define ICH_ACPI_TIMER_MAX_VALUE 0x1000000 ///< The timer is 24 bit overflow +/// +/// Pci I/O related data structure deifinition +/// +typedef enum { + SmmPciWidthUint8 = 0, + SmmPciWidthUint16 = 1, + SmmPciWidthUint32 = 2, + SmmPciWidthUint64 = 3, + SmmPciWidthMaximum +} SMM_PCI_IO_WIDTH; + +#define SMM_PCI_ADDRESS(bus, dev, func, reg) \ + ((UINT64) ((((UINT32) bus) << 24) + (((UINT32) dev) << 16) + (((UINT32) func) << 8) + ((UINT32) reg))) + +typedef struct { + UINT8 Register; + UINT8 Function; + UINT8 Device; + UINT8 Bus; + UINT32 ExtendedRegister; +} SMM_PCI_IO_ADDRESS; + +/// +/// CPU I/O Access Functions +/// +/** + Do a one byte IO read + + @param[in] Address - IO address to read + + @retval Data read +**/ +UINT8 +SmmIoRead8 ( + IN UINT16 Address + ); + +/** + Do a one byte IO write + + @param[in] Address - IO address to write + @param[in] Data - Data to write +**/ +VOID +SmmIoWrite8 ( + IN UINT16 Address, + IN UINT8 Data + ); + +/** + Do a two byte IO read + + @param[in] Address - IO address to read + + @retval Data read +**/ +UINT16 +SmmIoRead16 ( + IN UINT16 Address + ); + +/** + Do a two byte IO write + + @param[in] Address - IO address to write + @param[in] Data - Data to write +**/ +VOID +SmmIoWrite16 ( + IN UINT16 Address, + IN UINT16 Data + ); + +/** + Do a four byte IO read + + @param[in] Address - IO address to read + + @retval Data read +**/ +UINT32 +SmmIoRead32 ( + IN UINT16 Address + ); + +/** + Do a four byte IO write + + @param[in] Address - IO address to write + @param[in] Data - Data to write +**/ +VOID +SmmIoWrite32 ( + IN UINT16 Address, + IN UINT32 Data + ); + +/** + Do a one byte Memory write + + @param[in] Dest - Memory address to write + @param[in] Data - Data to write + + @retval None +**/ +VOID +SmmMemWrite8 ( + IN UINT64 Dest, + IN UINT8 Data + ); + +/** + Do a one byte Memory read + + @param[in] Dest - Memory address to read + + @retval Data read +**/ +UINT8 +SmmMemRead8 ( + IN UINT64 Dest + ); + +/** + Do a two bytes Memory write + + @param[in] Dest - Memory address to write + @param[in] Data - Data to write + + @retval None +**/ +VOID +SmmMemWrite16 ( + IN UINT64 Dest, + IN UINT16 Data + ); + +/** + Do a two bytes Memory read + + @param[in] Dest - Memory address to read + + @retval Data read +**/ +UINT16 +SmmMemRead16 ( + IN UINT64 Dest + ); + +/** + Do a four bytes Memory write + + @param[in] Dest - Memory address to write + @param[in] Data - Data to write + + @retval None +**/ +VOID +SmmMemWrite32 ( + IN UINT64 Dest, + IN UINT32 Data + ); + +/** + Do a four bytes Memory read + + @param[in] Dest - Memory address to read + + @retval Data read +**/ +UINT32 +SmmMemRead32 ( + IN UINT64 Dest + ); + +/** + Do a four bytes Memory read, then AND with Data, then write back to the same address + + @param[in] Dest - Memory address to write + @param[in] Data - Data to do AND + + @retval None +**/ +VOID +SmmMemAnd32 ( + IN UINT64 Dest, + IN UINT32 Data + ); +/// +/// Pci Configuration Space access functions definition +/// +/** + Read value from the specified PCI config space register + + @param[in] Width - The width (8, 16 or 32 bits) of accessed pci config space register + @param[in] Address - The address of the accessed pci register (bus, dev, func, offset) + @param[in] Buffer - The returned value + + @retval EFI_SUCCESS - All operations successfully + @retval EFI_INVALID_PARAMETER - Width is not valid or dosn't match register address + @retval Other error code - If any error occured when calling libiary functions +**/ +EFI_STATUS +SmmPciCfgRead ( + IN SMM_PCI_IO_WIDTH Width, + IN SMM_PCI_IO_ADDRESS *Address, + IN OUT VOID *Buffer + ); +/** + Write value into the specified PCI config space register + + @param[in] Width - The width (8, 16 or 32 bits) of accessed pci config space register + @param[in] Address - The address of the accessed pci register (bus, dev, func, offset) + @param[in] Buffer - The returned value + + @retval EFI_SUCCESS - All operations successfully + @retval EFI_INVALID_PARAMETER - Width is not valid or dosn't match register address + @retval Other error code - If any error occured when calling libiary functions +**/ +EFI_STATUS +SmmPciCfgWrite ( + IN SMM_PCI_IO_WIDTH Width, + IN SMM_PCI_IO_ADDRESS *Address, + IN OUT VOID *Buffer + ); +#endif diff --git a/ReferenceCode/Haswell/SampleCode/Include/acpibuild.dsc b/ReferenceCode/Haswell/SampleCode/Include/acpibuild.dsc new file mode 100644 index 0000000..cc3fb3d --- /dev/null +++ b/ReferenceCode/Haswell/SampleCode/Include/acpibuild.dsc @@ -0,0 +1,96 @@ +## @file +# Build description file for building ASL and ACT file types used in ACPI tables +# You should not put platform details, like how to build DSDT, SSDT, or how to +# package the ACPI tables into a data file in this build. This should be platform +# neutral code only. +# +#@copyright +# Copyright (c) 1999 - 2012 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. +# +# This file contains a 'Sample Driver' and is licensed as such +# under the terms of your license agreement with Intel or your +# vendor. This file may be modified by the user, subject to +# the additional terms of the license agreement +# + +[=============================================================================] +[Compile.Ia32.act,Compile.x64.act] +# +# Instructions to create ACPI table sections out of ACPI table C source files. +# + +#/*++ +# +# If it already exists, then include the dependency list file for this +# source file. If it doesn't exist, then this is a clean build and the +# dependency file will get created below and the source file will get +# compiled. Don't do any of this if NO_MAKEDEPS is defined. +# +#--*/ +!IF ("$(NO_MAKEDEPS)" == "") + +!IF EXIST($(DEST_DIR)\$(FILE).dep) +!INCLUDE $(DEST_DIR)\$(FILE).dep +!ENDIF + +# +# This is how to create the dependency file. +# +DEP_FILE = $(DEST_DIR)\$(FILE).dep + +$(DEP_FILE) : $(SOURCE_FILE_NAME) + $(MAKEDEPS) -ignorenotfound -f $(SOURCE_FILE_NAME) -q -target \ + $(DEST_DIR)\$(FILE).obj \ + -o $(DEP_FILE) $(INC) + +!ENDIF + +# +# Compile the file +# +$(DEST_DIR)\$(FILE).obj : $(SOURCE_FILE_NAME) $(INC_DEPS) $(DEP_FILE) + $(CC) $(C_FLAGS) /TC $(SOURCE_FILE_NAME) + +# +# Link it +# +$(DEST_DIR)\$(FILE).exe : $(DEST_DIR)\$(FILE).obj + $(LINK) $(LINK_FLAGS_EXE) $(DEST_DIR)\$(FILE).obj /OUT:$(DEST_DIR)\$(FILE).exe /ENTRY:main + +# +# Strip out the ACPI table +# +$(DEST_DIR)\$(FILE).acpi : $(DEST_DIR)\$(FILE).exe + $(GENACPITABLE) $(DEST_DIR)\$(FILE).exe $(DEST_DIR)\$(FILE).acpi + +# +# Create a section from the ACPI table +# +$(DEST_DIR)\$(FILE).sec : $(DEST_DIR)\$(FILE).acpi + $(GENSECTION) -I $(DEST_DIR)\$(FILE).acpi -O $(DEST_DIR)\$(FILE).sec -S EFI_SECTION_RAW + +# +# Add it to the targets to build +# +SECTIONS = $(SECTIONS) $(DEST_DIR)\$(FILE).sec + +[=============================================================================] +[Compile.Ia32.asl,Compile.x64.asl] +# +# We run the ASL through the C Preprocessor to resolve definitions. +# +$(DEST_DIR)\$(FILE).asl : $(SOURCE_FILE_NAME) + $(CC) $(ASL_CPP_FLAGS) /nologo /C /EP /TC $(INC) -oa $(SOURCE_FILE_NAME) > $(DEST_DIR)\$(FILE).asl + +# +# Add it to the targets to build +# +ASL_FILES = $(ASL_FILES) $(DEST_DIR)\$(FILE).asl + |