]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkNorthCluster/Smm/Pei/SmmControlPei/SmmControlPei.c
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Smm / Pei / SmmControlPei / SmmControlPei.c
1 /** @file
2 This module provides an implementation of the SMM Control PPI for use with
3 the QNC.
4
5 Copyright (c) 2013-2015 Intel Corporation.
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <PiPei.h>
12
13 #include <Ppi/SmmControl.h>
14
15 #include <Library/DebugLib.h>
16 #include <Library/HobLib.h>
17 #include <Library/PeiServicesLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/PciLib.h>
21
22 #include <IntelQNCPeim.h>
23 #include <Library/QNCAccessLib.h>
24 #include <Uefi/UefiBaseType.h>
25
26 /**
27 Generates an SMI using the parameters passed in.
28
29 @param PeiServices Describes the list of possible PEI Services.
30 @param This A pointer to an instance of
31 EFI_SMM_CONTROL_PPI
32 @param ArgumentBuffer The argument buffer
33 @param ArgumentBufferSize The size of the argument buffer
34 @param Periodic TRUE to indicate a periodical SMI
35 @param ActivationInterval Interval of the periodical SMI
36
37 @retval EFI_INVALID_PARAMETER Periodic is TRUE or ArgumentBufferSize > 1
38 @retval EFI_SUCCESS SMI generated
39
40 **/
41 EFI_STATUS
42 EFIAPI
43 PeiActivate (
44 IN EFI_PEI_SERVICES **PeiServices,
45 IN PEI_SMM_CONTROL_PPI *This,
46 IN OUT INT8 *ArgumentBuffer OPTIONAL,
47 IN OUT UINTN *ArgumentBufferSize OPTIONAL,
48 IN BOOLEAN Periodic OPTIONAL,
49 IN UINTN ActivationInterval OPTIONAL
50 );
51
52 /**
53 Clears an SMI.
54
55 @param PeiServices Describes the list of possible PEI Services.
56 @param This Pointer to an instance of EFI_SMM_CONTROL_PPI
57 @param Periodic TRUE to indicate a periodical SMI
58
59 @return Return value from SmmClear()
60
61 **/
62 EFI_STATUS
63 EFIAPI
64 PeiDeactivate (
65 IN EFI_PEI_SERVICES **PeiServices,
66 IN PEI_SMM_CONTROL_PPI *This,
67 IN BOOLEAN Periodic OPTIONAL
68 );
69
70 PEI_SMM_CONTROL_PPI mSmmControlPpi = {
71 PeiActivate,
72 PeiDeactivate
73 };
74
75 EFI_PEI_PPI_DESCRIPTOR mPpiList = {
76 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
77 &gPeiSmmControlPpiGuid,
78 &mSmmControlPpi
79 };
80
81 /**
82 Clear SMI related chipset status and re-enable SMI by setting the EOS bit.
83
84 @retval EFI_SUCCESS The requested operation has been carried out successfully
85 @retval EFI_DEVICE_ERROR The EOS bit could not be set.
86
87 **/
88 EFI_STATUS
89 SmmClear (
90 VOID
91 )
92 {
93 UINT16 GPE0BLK_Base;
94
95 //
96 // Get GPE0BLK_Base
97 //
98 GPE0BLK_Base = PcdGet16 (PcdGpe0blkIoBaseAddress);
99
100 //
101 // Clear the Power Button Override Status Bit, it gates EOS from being set.
102 // In QuarkNcSocId - Bit is read only. Handled by external SMC, do nothing.
103 //
104
105 //
106 // Clear the APM SMI Status Bit
107 //
108 IoWrite32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIS), B_QNC_GPE0BLK_SMIS_APM);
109
110 //
111 // Set the EOS Bit
112 //
113 IoOr32 ((GPE0BLK_Base + R_QNC_GPE0BLK_SMIS), B_QNC_GPE0BLK_SMIS_EOS);
114
115 return EFI_SUCCESS;
116 }
117
118
119 EFI_STATUS
120 EFIAPI
121 SmmTrigger (
122 IN UINT8 Data
123 )
124 /*++
125
126 Routine Description:
127
128 Trigger the software SMI
129
130 Arguments:
131
132 Data The value to be set on the software SMI data port
133
134 Returns:
135
136 EFI_SUCCESS Function completes successfully
137
138 --*/
139 {
140 UINT16 GPE0BLK_Base;
141 UINT32 NewValue;
142
143 //
144 // Get GPE0BLK_Base
145 //
146 GPE0BLK_Base = PcdGet16 (PcdGpe0blkIoBaseAddress);
147
148 //
149 // Enable the APMC SMI
150 //
151 IoOr32 (GPE0BLK_Base + R_QNC_GPE0BLK_SMIE, B_QNC_GPE0BLK_SMIE_APM);
152
153 //
154 // Enable SMI globally
155 //
156 NewValue = QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC);
157 NewValue |= SMI_EN;
158 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, NewValue);
159
160
161 //
162 // Generate the APMC SMI
163 //
164 IoWrite8 (PcdGet16 (PcdSmmActivationPort), Data);
165
166 return EFI_SUCCESS;
167 }
168
169 /**
170 Generates an SMI using the parameters passed in.
171
172 @param PeiServices Describes the list of possible PEI Services.
173 @param This A pointer to an instance of
174 EFI_SMM_CONTROL_PPI
175 @param ArgumentBuffer The argument buffer
176 @param ArgumentBufferSize The size of the argument buffer
177 @param Periodic TRUE to indicate a periodical SMI
178 @param ActivationInterval Interval of the periodical SMI
179
180 @retval EFI_INVALID_PARAMETER Periodic is TRUE or ArgumentBufferSize > 1
181 @retval EFI_SUCCESS SMI generated
182
183 **/
184 EFI_STATUS
185 EFIAPI
186 PeiActivate (
187 IN EFI_PEI_SERVICES **PeiServices,
188 IN PEI_SMM_CONTROL_PPI *This,
189 IN OUT INT8 *ArgumentBuffer OPTIONAL,
190 IN OUT UINTN *ArgumentBufferSize OPTIONAL,
191 IN BOOLEAN Periodic OPTIONAL,
192 IN UINTN ActivationInterval OPTIONAL
193 )
194 {
195 INT8 Data;
196 EFI_STATUS Status;
197 //
198 // Periodic SMI not supported.
199 //
200 if (Periodic) {
201 DEBUG ((DEBUG_WARN, "Invalid parameter\n"));
202 return EFI_INVALID_PARAMETER;
203 }
204
205 if (ArgumentBuffer == NULL) {
206 Data = 0xFF;
207 } else {
208 if (ArgumentBufferSize == NULL || *ArgumentBufferSize != 1) {
209 return EFI_INVALID_PARAMETER;
210 }
211
212 Data = *ArgumentBuffer;
213 }
214 //
215 // Clear any pending the APM SMI
216 //
217 Status = SmmClear ();
218 if (EFI_ERROR (Status)) {
219 return Status;
220 }
221
222 return SmmTrigger (Data);
223 }
224
225 /**
226 Clears an SMI.
227
228 @param PeiServices Describes the list of possible PEI Services.
229 @param This Pointer to an instance of EFI_SMM_CONTROL_PPI
230 @param Periodic TRUE to indicate a periodical SMI
231
232 @return Return value from SmmClear()
233
234 **/
235 EFI_STATUS
236 EFIAPI
237 PeiDeactivate (
238 IN EFI_PEI_SERVICES **PeiServices,
239 IN PEI_SMM_CONTROL_PPI *This,
240 IN BOOLEAN Periodic OPTIONAL
241 )
242 {
243 if (Periodic) {
244 return EFI_INVALID_PARAMETER;
245 }
246 return SmmClear ();
247 }
248
249 /**
250 This is the constructor for the SMM Control Ppi.
251
252 This function installs EFI_SMM_CONTROL_PPI.
253
254 @param FileHandle Handle of the file being invoked.
255 @param PeiServices Describes the list of possible PEI Services.
256
257 @retval EFI_UNSUPPORTED There's no Intel ICH on this platform
258 @return The status returned from InstallPpi().
259
260 --*/
261 EFI_STATUS
262 EFIAPI
263 SmmControlPeiEntry (
264 IN EFI_PEI_FILE_HANDLE FileHandle,
265 IN CONST EFI_PEI_SERVICES **PeiServices
266 )
267 {
268 EFI_STATUS Status;
269
270 Status = (**PeiServices).InstallPpi (PeiServices, &mPpiList);
271 ASSERT_EFI_ERROR (Status);
272
273 return Status;
274 }