1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
|