2 File to contain all the hardware specific stuff for the Smm Sx dispatch protocol.
4 Copyright (c) 2013-2015 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
12 // Include common header file for this module.
14 #include "CommonHeader.h"
16 #include "QNCSmmHelpers.h"
18 CONST QNC_SMM_SOURCE_DESC SX_SOURCE_DESC
= {
22 {GPE_ADDR_TYPE
, {R_QNC_GPE0BLK_SMIE
}}, S_QNC_GPE0BLK_SMIE
, N_QNC_GPE0BLK_SMIE_SLP
24 NULL_BIT_DESC_INITIALIZER
28 {GPE_ADDR_TYPE
, {R_QNC_GPE0BLK_SMIS
}}, S_QNC_GPE0BLK_SMIS
, N_QNC_GPE0BLK_SMIS_SLP
35 IN DATABASE_RECORD
*Record
,
36 OUT QNC_SMM_CONTEXT
*Context
41 Pm1Cnt
= IoRead32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
);
44 // By design, the context phase will always be ENTRY
46 Context
->Sx
.Phase
= SxEntry
;
49 // Map the PM1_CNT register's SLP_TYP bits to the context type
51 switch (Pm1Cnt
& B_QNC_PM1BLK_PM1C_SLPTP
) {
54 Context
->Sx
.Type
= SxS0
;
58 Context
->Sx
.Type
= SxS3
;
62 Context
->Sx
.Type
= SxS4
;
66 Context
->Sx
.Type
= SxS5
;
77 IN QNC_SMM_CONTEXT
*Context1
,
78 IN QNC_SMM_CONTEXT
*Context2
81 return (BOOLEAN
)(Context1
->Sx
.Type
== Context2
->Sx
.Type
);
92 When we get an SMI that indicates that we are transitioning to a sleep state,
93 we need to actually transition to that state. We do this by disabling the
94 "SMI on sleep enable" feature, which generates an SMI when the operating system
95 tries to put the system to sleep, and then physically putting the system to sleep.
106 // Flush cache into memory before we go to sleep. It is necessary for S3 sleep
107 // because we may update memory in SMM Sx sleep handlers -- the updates are in cache now
114 QNCSmmClearSource (&SX_SOURCE_DESC
);
115 QNCSmmDisableSource (&SX_SOURCE_DESC
);
118 // Clear Sleep Type Enable
120 IoAnd16 ((UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF) + R_QNC_GPE0BLK_SMIE
, (UINT16
)(~B_QNC_GPE0BLK_SMIE_SLP
));
122 // clear sleep SMI status
123 IoAnd16 ((UINT16
)(LpcPciCfg32 (R_QNC_LPC_GPE0BLK
) & 0xFFFF) + R_QNC_GPE0BLK_SMIS
, (UINT16
)(S_QNC_GPE0BLK_SMIS
));
126 // Now that SMIs are disabled, write to the SLP_EN bit again to trigger the sleep
128 Pm1Cnt
= IoOr32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
, B_QNC_PM1BLK_PM1C_SLPEN
);
131 // The system just went to sleep. If the sleep state was S1, then code execution will resume
132 // here when the system wakes up.
134 Pm1Cnt
= IoRead32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
);
135 if ((Pm1Cnt
& B_QNC_PM1BLK_PM1C_SCIEN
) == 0) {
137 // An ACPI OS isn't present, clear the sleep information
139 Pm1Cnt
&= ~B_QNC_PM1BLK_PM1C_SLPTP
;
142 IoWrite32 (PcdGet16 (PcdPm1blkIoBaseAddress
) + R_QNC_PM1BLK_PM1C
, Pm1Cnt
);
145 QNCSmmClearSource (&SX_SOURCE_DESC
);
146 QNCSmmEnableSource (&SX_SOURCE_DESC
);