[U-Boot,v2,01/22] x86: acpi: Add Kconfig option and header file for ACPI resume

Message ID 1492784689-15701-2-git-send-email-bmeng.cn@gmail.com
State Accepted
Commit 4372c111d49f1fa0fec0c8645c23a6266617e69d
Delegated to: Bin Meng
Headers show

Commit Message

Bin Meng April 21, 2017, 2:24 p.m.
This introduces a Kconfig option for ACPI S3 resume, as well as a
header file to include anything related to ACPI S3 resume.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

---

Changes in v2:
- fixed several nits in CONFIG_HAVE_ACPI_RESUME Kconfig help text
- return -EINVAL instead of -1 in acpi_sleep_from_pm1()
- add a function comment block for acpi_sleep_from_pm1()

 arch/x86/Kconfig               | 12 ++++++++
 arch/x86/include/asm/acpi_s3.h | 64 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi_s3.h

Comments

Bin Meng April 26, 2017, 7:33 a.m. | #1
On Fri, Apr 21, 2017 at 10:24 PM, Bin Meng <bmeng.cn@gmail.com> wrote:
> This introduces a Kconfig option for ACPI S3 resume, as well as a
> header file to include anything related to ACPI S3 resume.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> ---
>
> Changes in v2:
> - fixed several nits in CONFIG_HAVE_ACPI_RESUME Kconfig help text
> - return -EINVAL instead of -1 in acpi_sleep_from_pm1()
> - add a function comment block for acpi_sleep_from_pm1()
>
>  arch/x86/Kconfig               | 12 ++++++++
>  arch/x86/include/asm/acpi_s3.h | 64 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 76 insertions(+)
>  create mode 100644 arch/x86/include/asm/acpi_s3.h
>

applied to u-boot-x86/next, thanks!

Patch

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 9ead3eb..b568852 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -589,6 +589,18 @@  config GENERATE_ACPI_TABLE
 
 endmenu
 
+config HAVE_ACPI_RESUME
+	bool "Enable ACPI S3 resume"
+	help
+	  Select this to enable ACPI S3 resume. S3 is an ACPI-defined sleeping
+	  state where all system context is lost except system memory. U-Boot
+	  is responsible for restoring the machine state as it was before sleep.
+	  It needs restore the memory controller, without overwriting memory
+	  which is not marked as reserved. For the peripherals which lose their
+	  registers, U-Boot needs to write the original value. When everything
+	  is done, U-Boot needs to find out the wakeup vector provided by OSes
+	  and jump there.
+
 config MAX_PIRQ_LINKS
 	int
 	default 8
diff --git a/arch/x86/include/asm/acpi_s3.h b/arch/x86/include/asm/acpi_s3.h
new file mode 100644
index 0000000..78c53ea
--- /dev/null
+++ b/arch/x86/include/asm/acpi_s3.h
@@ -0,0 +1,64 @@ 
+/*
+ * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __ASM_ACPI_S3_H__
+#define __ASM_ACPI_S3_H__
+
+/* PM1_STATUS register */
+#define WAK_STS		(1 << 15)
+#define PCIEXPWAK_STS	(1 << 14)
+#define RTC_STS		(1 << 10)
+#define SLPBTN_STS	(1 << 9)
+#define PWRBTN_STS	(1 << 8)
+#define GBL_STS		(1 << 5)
+#define BM_STS		(1 << 4)
+#define TMR_STS		(1 << 0)
+
+/* PM1_CNT register */
+#define SLP_EN		(1 << 13)
+#define SLP_TYP_SHIFT	10
+#define SLP_TYP		(7 << SLP_TYP_SHIFT)
+#define SLP_TYP_S0	0
+#define SLP_TYP_S1	1
+#define SLP_TYP_S3	5
+#define SLP_TYP_S4	6
+#define SLP_TYP_S5	7
+
+enum acpi_sleep_state {
+	ACPI_S0,
+	ACPI_S1,
+	ACPI_S2,
+	ACPI_S3,
+	ACPI_S4,
+	ACPI_S5,
+};
+
+/**
+ * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register
+ *
+ * @pm1_cnt:	PM1_CNT register value
+ * @return:	ACPI-defined sleep state if given valid PM1_CNT register value,
+ *		-EINVAL otherwise.
+ */
+static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt)
+{
+	switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
+	case SLP_TYP_S0:
+		return ACPI_S0;
+	case SLP_TYP_S1:
+		return ACPI_S1;
+	case SLP_TYP_S3:
+		return ACPI_S3;
+	case SLP_TYP_S4:
+		return ACPI_S4;
+	case SLP_TYP_S5:
+		return ACPI_S5;
+	}
+
+	return -EINVAL;
+}
+
+#endif /* __ASM_ACPI_S3_H__ */