From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web09.16640.1628731360062511526 for ; Wed, 11 Aug 2021 18:22:40 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.20, mailfrom: nathaniel.l.desimone@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10073"; a="202441805" X-IronPort-AV: E=Sophos;i="5.84,314,1620716400"; d="scan'208";a="202441805" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 18:22:39 -0700 X-IronPort-AV: E=Sophos;i="5.84,314,1620716400"; d="scan'208";a="507310892" Received: from nldesimo-desk1.amr.corp.intel.com ([10.212.189.134]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2021 18:22:38 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: nathaniel.l.desimone@intel.com, Michael Kubacki , Chasel Chiu , Sai Chaganty , Benjamin Doron Subject: [edk2-platforms][PATCH v1] KabylakeSiliconPkg/PchPmcLib: Add GetSleepTypeAfterWakeup() Date: Wed, 11 Aug 2021 18:22:25 -0700 Message-Id: <20210812012225.28357-1-nathaniel.l.desimone@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Michael Kubacki 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 Cc: Sai Chaganty Cc: Nate DeSimone Cc: Benjamin Doron Signed-off-by: Michael Kubacki --- 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