2 QNC Smm Library Services that implements SMM Region access, S/W SMI generation and detection.
4 Copyright (c) 2013-2015 Intel Corporation.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <IntelQNCRegs.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/IoLib.h>
22 #include <Uefi/UefiBaseType.h>
23 #include <Library/QNCAccessLib.h>
25 #define BOOT_SERVICE_SOFTWARE_SMI_DATA 0
26 #define RUNTIME_SOFTWARE_SMI_DATA 1
29 Triggers a run time or boot time SMI.
31 This function triggers a software SMM interrupt and set the APMC status with an 8-bit Data.
33 @param Data The value to set the APMC status.
46 // Get PM1BLK_Base & GPE0BLK_Base
48 PM1BLK_Base
= PcdGet16 (PcdPm1blkIoBaseAddress
);
49 GPE0BLK_Base
= (UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF);
55 IoOr32 ((GPE0BLK_Base
+ R_QNC_GPE0BLK_SMIE
), B_QNC_GPE0BLK_SMIE_APM
);
58 // Enable SMI globally
60 NewValue
= QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
);
62 QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID
, QNC_MSG_FSBIC_REG_HMISC
, NewValue
);
67 IoWrite8 (PcdGet16 (PcdSmmDataPort
), Data
);
70 // Generate the APM SMI
72 IoWrite8 (PcdGet16 (PcdSmmActivationPort
), PcdGet8 (PcdSmmActivationData
));
75 // Clear the APM SMI Status Bit
77 IoWrite32 ((GPE0BLK_Base
+ R_QNC_GPE0BLK_SMIS
), B_QNC_GPE0BLK_SMIS_APM
);
82 IoOr32 ((GPE0BLK_Base
+ R_QNC_GPE0BLK_SMIS
), B_QNC_GPE0BLK_SMIS_EOS
);
87 Triggers an SMI at boot time.
89 This function triggers a software SMM interrupt at boot time.
94 TriggerBootServiceSoftwareSmi (
98 InternalTriggerSmi (BOOT_SERVICE_SOFTWARE_SMI_DATA
);
103 Triggers an SMI at run time.
105 This function triggers a software SMM interrupt at run time.
110 TriggerRuntimeSoftwareSmi (
114 InternalTriggerSmi (RUNTIME_SOFTWARE_SMI_DATA
);
119 Gets the software SMI data.
121 This function tests if a software SMM interrupt happens. If a software SMI happens,
122 it retrieves the SMM data and returns it as a non-negative value; otherwise a negative
125 @return Data The data retrieved from SMM data port in case of a software SMI;
126 otherwise a negative value.
130 InternalGetSwSmiData (
137 SmiStatus
= IoRead8 ((UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF) + R_QNC_GPE0BLK_SMIS
);
138 if (((SmiStatus
& B_QNC_GPE0BLK_SMIS_APM
) != 0) &&
139 (IoRead8 (PcdGet16 (PcdSmmActivationPort
)) == PcdGet8 (PcdSmmActivationData
))) {
140 Data
= IoRead8 (PcdGet16 (PcdSmmDataPort
));
141 return (INTN
)(UINTN
)Data
;
149 Test if a boot time software SMI happened.
151 This function tests if a software SMM interrupt happened. If a software SMM interrupt happened and
152 it was triggered at boot time, it returns TRUE. Otherwise, it returns FALSE.
154 @retval TRUE A software SMI triggered at boot time happened.
155 @retval FLASE No software SMI happened or the software SMI was triggered at run time.
160 IsBootServiceSoftwareSmi (
164 return (BOOLEAN
) (InternalGetSwSmiData () == BOOT_SERVICE_SOFTWARE_SMI_DATA
);
169 Test if a run time software SMI happened.
171 This function tests if a software SMM interrupt happened. If a software SMM interrupt happened and
172 it was triggered at run time, it returns TRUE. Otherwise, it returns FALSE.
174 @retval TRUE A software SMI triggered at run time happened.
175 @retval FLASE No software SMI happened or the software SMI was triggered at boot time.
180 IsRuntimeSoftwareSmi (
184 return (BOOLEAN
) (InternalGetSwSmiData () == RUNTIME_SOFTWARE_SMI_DATA
);
191 Clear APM SMI Status Bit; Set the EOS bit.
206 GPE0BLK_Base
= (UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF);
209 // Clear the APM SMI Status Bit
211 IoOr16 (GPE0BLK_Base
+ R_QNC_GPE0BLK_SMIS
, B_QNC_GPE0BLK_SMIS_APM
);
216 IoOr32 (GPE0BLK_Base
+ R_QNC_GPE0BLK_SMIS
, B_QNC_GPE0BLK_SMIS_EOS
);
220 This routine is the chipset code that accepts a request to "open" a region of SMRAM.
221 The region could be legacy ABSEG, HSEG, or TSEG near top of physical memory.
222 The use of "open" means that the memory is visible from all boot-service
225 @retval FALSE Cannot open a locked SMRAM region
226 @retval TRUE Success to open SMRAM region.
236 // Read the SMRAM register
237 Smram
= QncHsmmcRead ();
240 // Is the platform locked?
242 if (Smram
& SMM_LOCKED
) {
243 // Cannot Open a locked region
244 DEBUG ((EFI_D_WARN
, "Cannot open a locked SMRAM region\n"));
249 // Open all SMRAM regions for Host access only
251 Smram
|= (SMM_WRITE_OPEN
| SMM_READ_OPEN
); // Open for Host.
252 Smram
&= ~(NON_HOST_SMM_WR_OPEN
| NON_HOST_SMM_RD_OPEN
); // Not for others.
255 // Write the SMRAM register
257 QncHsmmcWrite (Smram
);
263 This routine is the chipset code that accepts a request to "close" a region of SMRAM.
264 The region could be legacy AB or TSEG near top of physical memory.
265 The use of "close" means that the memory is only visible from SMM agents,
266 not from BS or RT code.
268 @retval FALSE Cannot open a locked SMRAM region
269 @retval TRUE Success to open SMRAM region.
273 QNCCloseSmramRegion (
279 // Read the SMRAM register.
280 Smram
= QncHsmmcRead ();
283 // Is the platform locked?
285 if(Smram
& SMM_LOCKED
) {
286 // Cannot Open a locked region
287 DEBUG ((EFI_D_WARN
, "Cannot close a locked SMRAM region\n"));
291 Smram
&= (~(SMM_WRITE_OPEN
| SMM_READ_OPEN
| NON_HOST_SMM_WR_OPEN
| NON_HOST_SMM_RD_OPEN
));
293 QncHsmmcWrite (Smram
);
299 This routine is the chipset code that accepts a request to "lock" SMRAM.
300 The region could be legacy AB or TSEG near top of physical memory.
301 The use of "lock" means that the memory can no longer be opened
312 // Read the SMRAM register.
313 Smram
= QncHsmmcRead ();
314 if(Smram
& SMM_LOCKED
) {
315 DEBUG ((EFI_D_WARN
, "SMRAM region already locked!\n"));
319 QncHsmmcWrite (Smram
);