Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c | 54 ++++++++++++++++++++ Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h | 15 ++++++ Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf | 4 ++ 3 files changed, 73 insertions(+)
From: Michael Kubacki <michael.kubacki@microsoft.com>
Adds the capability to get the system sleep type after wakeup to
PchPmcLib in KabylakeSiliconPkg.
This is needed by platforms to determine the Sx resume state.
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Benjamin Doron <benjamin.doron00@gmail.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
---
Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c | 54 ++++++++++++++++++++
Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h | 15 ++++++
Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf | 4 ++
3 files changed, 73 insertions(+)
diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c
index 790af0a7a1..3c9c4c2a2d 100644
--- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c
+++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c
@@ -128,3 +128,57 @@ PchIsRtcBatteryGood (
}
return FALSE;
}
+
+/**
+ Returns the sleep type after system wakeup.
+
+ @param[out] SleepType Sleep type to be returned.
+
+ @retval TRUE A wake event occurred without power failure.
+ @retval FALSE Power failure occurred or not a wakeup.
+
+**/
+BOOLEAN
+EFIAPI
+GetSleepTypeAfterWakeup (
+ OUT UINT32 *SleepType
+ )
+{
+ UINT16 Pm1Sts;
+ UINT32 Pm1Cnt;
+ UINTN PmcBaseAddress;
+
+ PmcBaseAddress = MmPciBase (
+ DEFAULT_PCI_BUS_NUMBER_PCH,
+ PCI_DEVICE_NUMBER_PCH_PMC,
+ PCI_FUNCTION_NUMBER_PCH_PMC
+ );
+
+ ///
+ /// Read the ACPI registers
+ ///
+ Pm1Sts = IoRead16 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_STS);
+ Pm1Cnt = IoRead32 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT);
+
+ ///
+ /// Get sleep type if a wake event occurred and there is no power failure and reset
+ ///
+ if ((Pm1Sts & B_PCH_ACPI_PM1_STS_WAK) != 0) {
+ if ((MmioRead16 (PmcBaseAddress + R_PCH_PMC_GEN_PMCON_B) & (B_PCH_PMC_GEN_PMCON_B_RTC_PWR_STS | B_PCH_PMC_GEN_PMCON_B_PWR_FLR)) == 0) {
+ *SleepType = Pm1Cnt & B_PCH_ACPI_PM1_CNT_SLP_TYP;
+
+ return TRUE;
+ } else {
+ ///
+ /// Clear Wake Status (WAK_STS) and Sleep Type (SLP_TYP)
+ ///
+ IoWrite16 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_STS, B_PCH_ACPI_PM1_STS_WAK);
+ Pm1Cnt &= ~B_PCH_ACPI_PM1_CNT_SLP_TYP;
+ IoWrite32 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT, Pm1Cnt);
+
+ return FALSE;
+ }
+ }
+
+ return FALSE;
+}
diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h
index ec98e07100..f84606d31c 100644
--- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h
+++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h
@@ -41,4 +41,19 @@ PchIsRtcBatteryGood (
VOID
);
+/**
+ Returns the sleep type after system wakeup.
+
+ @param[out] SleepType Sleep type to be returned.
+
+ @retval TRUE A wake event occurred without power failure.
+ @retval FALSE Power failure occurred or not a wakeup.
+
+**/
+BOOLEAN
+EFIAPI
+GetSleepTypeAfterWakeup (
+ OUT UINT32 *SleepType
+ );
+
#endif // _PCH_PMC_LIB_H_
diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf
index 8b46a59b67..1e6103f4ca 100644
--- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf
+++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf
@@ -33,5 +33,9 @@ MdePkg/MdePkg.dec
KabylakeSiliconPkg/SiPkg.dec
+[Pcd]
+gSiPkgTokenSpaceGuid.PcdAcpiBaseAddress
+
+
[Sources]
PchPmcLib.c
--
2.29.2.windows.2
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79132): https://edk2.groups.io/g/devel/message/79132
Mute This Topic: https://groups.io/mt/84831387/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com> > -----Original Message----- > From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> > Sent: Thursday, August 12, 2021 9:22 AM > To: devel@edk2.groups.io > Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Michael > Kubacki <michael.kubacki@microsoft.com>; Chiu, Chasel > <chasel.chiu@intel.com>; Chaganty, Rangasai V > <rangasai.v.chaganty@intel.com>; Benjamin Doron > <benjamin.doron00@gmail.com> > Subject: [edk2-platforms][PATCH v1] KabylakeSiliconPkg/PchPmcLib: Add > GetSleepTypeAfterWakeup() > > From: Michael Kubacki <michael.kubacki@microsoft.com> > > Adds the capability to get the system sleep type after wakeup to PchPmcLib > in KabylakeSiliconPkg. > > This is needed by platforms to determine the Sx resume state. > > Cc: Chasel Chiu <chasel.chiu@intel.com> > Cc: Sai Chaganty <rangasai.v.chaganty@intel.com> > Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> > Cc: Benjamin Doron <benjamin.doron00@gmail.com> > Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> > --- > > Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmc > Lib.c | 54 ++++++++++++++++++++ > Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h > | 15 ++++++ > > Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeS > mmPchPmcLib.inf | 4 ++ > 3 files changed, 73 insertions(+) > > diff --git > a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchP > mcLib.c > b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchP > mcLib.c > index 790af0a7a1..3c9c4c2a2d 100644 > --- > a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchP > mcLib.c > +++ > b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/Pc > +++ hPmcLib.c > @@ -128,3 +128,57 @@ PchIsRtcBatteryGood ( > } > return FALSE; > } > + > +/** > + Returns the sleep type after system wakeup. > + > + @param[out] SleepType Sleep type to be returned. > + > + @retval TRUE A wake event occurred without power failure. > + @retval FALSE Power failure occurred or not a wakeup. > + > +**/ > +BOOLEAN > +EFIAPI > +GetSleepTypeAfterWakeup ( > + OUT UINT32 *SleepType > + ) > +{ > + UINT16 Pm1Sts; > + UINT32 Pm1Cnt; > + UINTN PmcBaseAddress; > + > + PmcBaseAddress = MmPciBase ( > + DEFAULT_PCI_BUS_NUMBER_PCH, > + PCI_DEVICE_NUMBER_PCH_PMC, > + PCI_FUNCTION_NUMBER_PCH_PMC > + ); > + > + /// > + /// Read the ACPI registers > + /// > + Pm1Sts = IoRead16 (PcdGet16 (PcdAcpiBaseAddress) + > + R_PCH_ACPI_PM1_STS); Pm1Cnt = IoRead32 (PcdGet16 > + (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT); > + > + /// > + /// Get sleep type if a wake event occurred and there is no power > + failure and reset /// if ((Pm1Sts & B_PCH_ACPI_PM1_STS_WAK) != 0) { > + if ((MmioRead16 (PmcBaseAddress + R_PCH_PMC_GEN_PMCON_B) & > (B_PCH_PMC_GEN_PMCON_B_RTC_PWR_STS | > B_PCH_PMC_GEN_PMCON_B_PWR_FLR)) == 0) { > + *SleepType = Pm1Cnt & B_PCH_ACPI_PM1_CNT_SLP_TYP; > + > + return TRUE; > + } else { > + /// > + /// Clear Wake Status (WAK_STS) and Sleep Type (SLP_TYP) > + /// > + IoWrite16 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_STS, > B_PCH_ACPI_PM1_STS_WAK); > + Pm1Cnt &= ~B_PCH_ACPI_PM1_CNT_SLP_TYP; > + IoWrite32 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT, > + Pm1Cnt); > + > + return FALSE; > + } > + } > + > + return FALSE; > +} > diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h > b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h > index ec98e07100..f84606d31c 100644 > --- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h > +++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h > @@ -41,4 +41,19 @@ PchIsRtcBatteryGood ( > VOID > ); > > +/** > + Returns the sleep type after system wakeup. > + > + @param[out] SleepType Sleep type to be returned. > + > + @retval TRUE A wake event occurred without power failure. > + @retval FALSE Power failure occurred or not a wakeup. > + > +**/ > +BOOLEAN > +EFIAPI > +GetSleepTypeAfterWakeup ( > + OUT UINT32 *SleepType > + ); > + > #endif // _PCH_PMC_LIB_H_ > diff --git > a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDx > eSmmPchPmcLib.inf > b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDx > eSmmPchPmcLib.inf > index 8b46a59b67..1e6103f4ca 100644 > --- > a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDx > eSmmPchPmcLib.inf > +++ > b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/Pe > +++ iDxeSmmPchPmcLib.inf > @@ -33,5 +33,9 @@ MdePkg/MdePkg.dec > KabylakeSiliconPkg/SiPkg.dec > > > +[Pcd] > +gSiPkgTokenSpaceGuid.PcdAcpiBaseAddress > + > + > [Sources] > PchPmcLib.c > -- > 2.29.2.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79147): https://edk2.groups.io/g/devel/message/79147 Mute This Topic: https://groups.io/mt/84831387/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com> -----Original Message----- From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> Sent: Wednesday, August 11, 2021 6:22 PM To: devel@edk2.groups.io Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Michael Kubacki <michael.kubacki@microsoft.com>; Chiu, Chasel <chasel.chiu@intel.com>; Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Benjamin Doron <benjamin.doron00@gmail.com> Subject: [edk2-platforms][PATCH v1] KabylakeSiliconPkg/PchPmcLib: Add GetSleepTypeAfterWakeup() From: Michael Kubacki <michael.kubacki@microsoft.com> Adds the capability to get the system sleep type after wakeup to PchPmcLib in KabylakeSiliconPkg. This is needed by platforms to determine the Sx resume state. Cc: Chasel Chiu <chasel.chiu@intel.com> Cc: Sai Chaganty <rangasai.v.chaganty@intel.com> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> Cc: Benjamin Doron <benjamin.doron00@gmail.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> --- Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c | 54 ++++++++++++++++++++ Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h | 15 ++++++ Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf | 4 ++ 3 files changed, 73 insertions(+) diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c index 790af0a7a1..3c9c4c2a2d 100644 --- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PchPmcLib.c +++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/Pc +++ hPmcLib.c @@ -128,3 +128,57 @@ PchIsRtcBatteryGood ( } return FALSE; } + +/** + Returns the sleep type after system wakeup. + + @param[out] SleepType Sleep type to be returned. + + @retval TRUE A wake event occurred without power failure. + @retval FALSE Power failure occurred or not a wakeup. + +**/ +BOOLEAN +EFIAPI +GetSleepTypeAfterWakeup ( + OUT UINT32 *SleepType + ) +{ + UINT16 Pm1Sts; + UINT32 Pm1Cnt; + UINTN PmcBaseAddress; + + PmcBaseAddress = MmPciBase ( + DEFAULT_PCI_BUS_NUMBER_PCH, + PCI_DEVICE_NUMBER_PCH_PMC, + PCI_FUNCTION_NUMBER_PCH_PMC + ); + + /// + /// Read the ACPI registers + /// + Pm1Sts = IoRead16 (PcdGet16 (PcdAcpiBaseAddress) + + R_PCH_ACPI_PM1_STS); Pm1Cnt = IoRead32 (PcdGet16 + (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT); + + /// + /// Get sleep type if a wake event occurred and there is no power + failure and reset /// if ((Pm1Sts & B_PCH_ACPI_PM1_STS_WAK) != 0) { + if ((MmioRead16 (PmcBaseAddress + R_PCH_PMC_GEN_PMCON_B) & (B_PCH_PMC_GEN_PMCON_B_RTC_PWR_STS | B_PCH_PMC_GEN_PMCON_B_PWR_FLR)) == 0) { + *SleepType = Pm1Cnt & B_PCH_ACPI_PM1_CNT_SLP_TYP; + + return TRUE; + } else { + /// + /// Clear Wake Status (WAK_STS) and Sleep Type (SLP_TYP) + /// + IoWrite16 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_STS, B_PCH_ACPI_PM1_STS_WAK); + Pm1Cnt &= ~B_PCH_ACPI_PM1_CNT_SLP_TYP; + IoWrite32 (PcdGet16 (PcdAcpiBaseAddress) + R_PCH_ACPI_PM1_CNT, + Pm1Cnt); + + return FALSE; + } + } + + return FALSE; +} diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h index ec98e07100..f84606d31c 100644 --- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h +++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Include/Library/PchPmcLib.h @@ -41,4 +41,19 @@ PchIsRtcBatteryGood ( VOID ); +/** + Returns the sleep type after system wakeup. + + @param[out] SleepType Sleep type to be returned. + + @retval TRUE A wake event occurred without power failure. + @retval FALSE Power failure occurred or not a wakeup. + +**/ +BOOLEAN +EFIAPI +GetSleepTypeAfterWakeup ( + OUT UINT32 *SleepType + ); + #endif // _PCH_PMC_LIB_H_ diff --git a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf index 8b46a59b67..1e6103f4ca 100644 --- a/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/PeiDxeSmmPchPmcLib.inf +++ b/Silicon/Intel/KabylakeSiliconPkg/Pch/Library/PeiDxeSmmPchPmcLib/Pe +++ iDxeSmmPchPmcLib.inf @@ -33,5 +33,9 @@ MdePkg/MdePkg.dec KabylakeSiliconPkg/SiPkg.dec +[Pcd] +gSiPkgTokenSpaceGuid.PcdAcpiBaseAddress + + [Sources] PchPmcLib.c -- 2.29.2.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79151): https://edk2.groups.io/g/devel/message/79151 Mute This Topic: https://groups.io/mt/84831387/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.