xref: /openbmc/u-boot/arch/x86/include/asm/acpi_s3.h (revision a22bbfda)
1 /*
2  * Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #ifndef __ASM_ACPI_S3_H__
8 #define __ASM_ACPI_S3_H__
9 
10 #define WAKEUP_BASE	0x600
11 
12 /* PM1_STATUS register */
13 #define WAK_STS		(1 << 15)
14 #define PCIEXPWAK_STS	(1 << 14)
15 #define RTC_STS		(1 << 10)
16 #define SLPBTN_STS	(1 << 9)
17 #define PWRBTN_STS	(1 << 8)
18 #define GBL_STS		(1 << 5)
19 #define BM_STS		(1 << 4)
20 #define TMR_STS		(1 << 0)
21 
22 /* PM1_CNT register */
23 #define SLP_EN		(1 << 13)
24 #define SLP_TYP_SHIFT	10
25 #define SLP_TYP		(7 << SLP_TYP_SHIFT)
26 #define SLP_TYP_S0	0
27 #define SLP_TYP_S1	1
28 #define SLP_TYP_S3	5
29 #define SLP_TYP_S4	6
30 #define SLP_TYP_S5	7
31 
32 /* Memory size reserved for S3 resume */
33 #define S3_RESERVE_SIZE	0x1000
34 
35 #ifndef __ASSEMBLY__
36 
37 extern char __wakeup[];
38 extern int __wakeup_size;
39 
40 enum acpi_sleep_state {
41 	ACPI_S0,
42 	ACPI_S1,
43 	ACPI_S2,
44 	ACPI_S3,
45 	ACPI_S4,
46 	ACPI_S5,
47 };
48 
49 /**
50  * acpi_ss_string() - get ACPI-defined sleep state string
51  *
52  * @pm1_cnt:	ACPI-defined sleep state
53  * @return:	a pointer to the sleep state string.
54  */
55 static inline char *acpi_ss_string(enum acpi_sleep_state state)
56 {
57 	char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"};
58 
59 	return ss_string[state];
60 }
61 
62 /**
63  * acpi_sleep_from_pm1() - get ACPI-defined sleep state from PM1_CNT register
64  *
65  * @pm1_cnt:	PM1_CNT register value
66  * @return:	ACPI-defined sleep state if given valid PM1_CNT register value,
67  *		-EINVAL otherwise.
68  */
69 static inline enum acpi_sleep_state acpi_sleep_from_pm1(u32 pm1_cnt)
70 {
71 	switch ((pm1_cnt & SLP_TYP) >> SLP_TYP_SHIFT) {
72 	case SLP_TYP_S0:
73 		return ACPI_S0;
74 	case SLP_TYP_S1:
75 		return ACPI_S1;
76 	case SLP_TYP_S3:
77 		return ACPI_S3;
78 	case SLP_TYP_S4:
79 		return ACPI_S4;
80 	case SLP_TYP_S5:
81 		return ACPI_S5;
82 	}
83 
84 	return -EINVAL;
85 }
86 
87 /**
88  * chipset_prev_sleep_state() - Get chipset previous sleep state
89  *
90  * This returns chipset previous sleep state from ACPI registers.
91  * Platform codes must supply this routine in order to support ACPI S3.
92  *
93  * @return ACPI_S0/S1/S2/S3/S4/S5.
94  */
95 enum acpi_sleep_state chipset_prev_sleep_state(void);
96 
97 /**
98  * chipset_clear_sleep_state() - Clear chipset sleep state
99  *
100  * This clears chipset sleep state in ACPI registers.
101  * Platform codes must supply this routine in order to support ACPI S3.
102  */
103 void chipset_clear_sleep_state(void);
104 
105 struct acpi_fadt;
106 /**
107  * acpi_resume() - Do ACPI S3 resume
108  *
109  * This calls U-Boot wake up assembly stub and jumps to OS's wake up vector.
110  *
111  * @fadt:	FADT table pointer in the ACPI table
112  * @return:	Never returns
113  */
114 void acpi_resume(struct acpi_fadt *fadt);
115 
116 /**
117  * acpi_s3_reserve() - Reserve memory for ACPI S3 resume
118  *
119  * This copies memory where real mode interrupt handler stubs reside to the
120  * reserved place on the stack.
121  *
122  * This routine should be called by reserve_arch() before U-Boot is relocated
123  * when ACPI S3 resume is enabled.
124  *
125  * @return:	0 always
126  */
127 int acpi_s3_reserve(void);
128 
129 #endif /* __ASSEMBLY__ */
130 
131 #endif /* __ASM_ACPI_S3_H__ */
132