mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-29 08:01:08 +00:00
5ae5aa9310
U-Boot sets up the real mode interrupt handler stubs starting from address 0x1000. In most cases, the first 640K (0x00000 - 0x9ffff) system memory is reported as system RAM in E820 table to the OS. (see install_e820_map() implementation for each platform). So OS can use these memories whatever it wants. If U-Boot is in an S3 resume path, care must be taken not to corrupt these memorie otherwise OS data gets lost. Testing shows that, on Microsoft Windows 10 on Intel Baytrail its wake up vector happens to be installed at the same address 0x1000. While on Linux its wake up vector does not overlap this memory range, but after resume kernel checks low memory range per config option CONFIG_X86_RESERVE_LOW which is 64K by default to see whether a memory corruption occurs during the suspend/resume (it's harmless, but warnings are shown in the kernel dmesg logs). We cannot simply mark the these memory as reserved in E820 table because such configuration makes GRUB complain: unable to allocate real mode page. Hence we choose to back up these memories to the place where we reserved on our stack for our S3 resume work. Before jumping to OS wake up vector, we need restore the original content there. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Stefan Roese <sr@denx.de>
131 lines
2.9 KiB
C
131 lines
2.9 KiB
C
/*
|
|
* 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__
|
|
|
|
#define WAKEUP_BASE 0x600
|
|
|
|
/* 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
|
|
|
|
/* Memory size reserved for S3 resume */
|
|
#define S3_RESERVE_SIZE 0x1000
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
extern char __wakeup[];
|
|
extern int __wakeup_size;
|
|
|
|
enum acpi_sleep_state {
|
|
ACPI_S0,
|
|
ACPI_S1,
|
|
ACPI_S2,
|
|
ACPI_S3,
|
|
ACPI_S4,
|
|
ACPI_S5,
|
|
};
|
|
|
|
/**
|
|
* acpi_ss_string() - get ACPI-defined sleep state string
|
|
*
|
|
* @pm1_cnt: ACPI-defined sleep state
|
|
* @return: a pointer to the sleep state string.
|
|
*/
|
|
static inline char *acpi_ss_string(enum acpi_sleep_state state)
|
|
{
|
|
char *ss_string[] = { "S0", "S1", "S2", "S3", "S4", "S5"};
|
|
|
|
return ss_string[state];
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* chipset_prev_sleep_state() - Get chipset previous sleep state
|
|
*
|
|
* This returns chipset previous sleep state from ACPI registers.
|
|
* Platform codes must supply this routine in order to support ACPI S3.
|
|
*
|
|
* @return ACPI_S0/S1/S2/S3/S4/S5.
|
|
*/
|
|
enum acpi_sleep_state chipset_prev_sleep_state(void);
|
|
|
|
/**
|
|
* chipset_clear_sleep_state() - Clear chipset sleep state
|
|
*
|
|
* This clears chipset sleep state in ACPI registers.
|
|
* Platform codes must supply this routine in order to support ACPI S3.
|
|
*/
|
|
void chipset_clear_sleep_state(void);
|
|
|
|
struct acpi_fadt;
|
|
/**
|
|
* acpi_resume() - Do ACPI S3 resume
|
|
*
|
|
* This calls U-Boot wake up assembly stub and jumps to OS's wake up vector.
|
|
*
|
|
* @fadt: FADT table pointer in the ACPI table
|
|
* @return: Never returns
|
|
*/
|
|
void acpi_resume(struct acpi_fadt *fadt);
|
|
|
|
/**
|
|
* acpi_s3_reserve() - Reserve memory for ACPI S3 resume
|
|
*
|
|
* This copies memory where real mode interrupt handler stubs reside to the
|
|
* reserved place on the stack.
|
|
*
|
|
* This routine should be called by reserve_arch() before U-Boot is relocated
|
|
* when ACPI S3 resume is enabled.
|
|
*
|
|
* @return: 0 always
|
|
*/
|
|
int acpi_s3_reserve(void);
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __ASM_ACPI_S3_H__ */
|