2 File to contain all the hardware specific stuff for the Smm Sx dispatch protocol.
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 common header file for this module.
20 #include "CommonHeader.h"
22 #include "QNCSmmHelpers.h"
24 CONST QNC_SMM_SOURCE_DESC SX_SOURCE_DESC
= {
28 {GPE_ADDR_TYPE
, {R_QNC_GPE0BLK_SMIE
}}, S_QNC_GPE0BLK_SMIE
, N_QNC_GPE0BLK_SMIE_SLP
30 NULL_BIT_DESC_INITIALIZER
34 {GPE_ADDR_TYPE
, {R_QNC_GPE0BLK_SMIS
}}, S_QNC_GPE0BLK_SMIS
, N_QNC_GPE0BLK_SMIS_SLP
41 IN DATABASE_RECORD
*Record
,
42 OUT QNC_SMM_CONTEXT
*Context
47 Pm1Cnt
= IoRead32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
);
50 // By design, the context phase will always be ENTRY
52 Context
->Sx
.Phase
= SxEntry
;
55 // Map the PM1_CNT register's SLP_TYP bits to the context type
57 switch (Pm1Cnt
& B_QNC_PM1BLK_PM1C_SLPTP
) {
60 Context
->Sx
.Type
= SxS0
;
64 Context
->Sx
.Type
= SxS3
;
68 Context
->Sx
.Type
= SxS4
;
72 Context
->Sx
.Type
= SxS5
;
83 IN QNC_SMM_CONTEXT
*Context1
,
84 IN QNC_SMM_CONTEXT
*Context2
87 return (BOOLEAN
)(Context1
->Sx
.Type
== Context2
->Sx
.Type
);
98 When we get an SMI that indicates that we are transitioning to a sleep state,
99 we need to actually transition to that state. We do this by disabling the
100 "SMI on sleep enable" feature, which generates an SMI when the operating system
101 tries to put the system to sleep, and then physically putting the system to sleep.
112 // Flush cache into memory before we go to sleep. It is necessary for S3 sleep
113 // because we may update memory in SMM Sx sleep handlers -- the updates are in cache now
120 QNCSmmClearSource (&SX_SOURCE_DESC
);
121 QNCSmmDisableSource (&SX_SOURCE_DESC
);
124 // Clear Sleep Type Enable
126 IoAnd16 ((UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF) + R_QNC_GPE0BLK_SMIE
, (UINT16
)(~B_QNC_GPE0BLK_SMIE_SLP
));
128 // clear sleep SMI status
129 IoAnd16 ((UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF) + R_QNC_GPE0BLK_SMIS
, (UINT16
)(S_QNC_GPE0BLK_SMIS
));
132 // Now that SMIs are disabled, write to the SLP_EN bit again to trigger the sleep
134 Pm1Cnt
= IoOr32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
, B_QNC_PM1BLK_PM1C_SLPEN
);
137 // The system just went to sleep. If the sleep state was S1, then code execution will resume
138 // here when the system wakes up.
140 Pm1Cnt
= IoRead32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
);
141 if ((Pm1Cnt
& B_QNC_PM1BLK_PM1C_SCIEN
) == 0) {
143 // An ACPI OS isn't present, clear the sleep information
145 Pm1Cnt
&= ~B_QNC_PM1BLK_PM1C_SLPTP
;
148 IoWrite32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
, Pm1Cnt
);
151 QNCSmmClearSource (&SX_SOURCE_DESC
);
152 QNCSmmEnableSource (&SX_SOURCE_DESC
);