commit
ae1b939930
@ -1,20 +0,0 @@ |
||||
/*
|
||||
* Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <mmc.h> |
||||
#include <pci_ids.h> |
||||
|
||||
static struct pci_device_id mmc_supported[] = { |
||||
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_SDIO_0 }, |
||||
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TCF_SDIO_1 }, |
||||
{}, |
||||
}; |
||||
|
||||
int cpu_mmc_init(bd_t *bis) |
||||
{ |
||||
return pci_mmc_init("Topcliff SDHCI", mmc_supported); |
||||
} |
@ -0,0 +1,78 @@ |
||||
/* |
||||
* Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com>
|
||||
* |
||||
* From coreboot src/arch/x86/wakeup.S |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <asm/acpi_s3.h> |
||||
#include <asm/processor.h> |
||||
#include <asm/processor-flags.h> |
||||
|
||||
#define RELOCATED(x) ((x) - __wakeup + WAKEUP_BASE) |
||||
|
||||
#define CODE_SEG (X86_GDT_ENTRY_16BIT_CS * X86_GDT_ENTRY_SIZE) |
||||
#define DATA_SEG (X86_GDT_ENTRY_16BIT_DS * X86_GDT_ENTRY_SIZE) |
||||
|
||||
.code32 |
||||
.globl __wakeup
|
||||
__wakeup: |
||||
/* First prepare the jmp to the resume vector */ |
||||
mov 0x4(%esp), %eax /* vector */ |
||||
/* last 4 bits of linear addr are taken as offset */ |
||||
andw $0x0f, %ax |
||||
movw %ax, (__wakeup_offset) |
||||
mov 0x4(%esp), %eax |
||||
/* the rest is taken as segment */ |
||||
shr $4, %eax |
||||
movw %ax, (__wakeup_segment) |
||||
|
||||
/* Activate the right segment descriptor real mode */ |
||||
ljmp $CODE_SEG, $RELOCATED(1f) |
||||
1: |
||||
/* 16 bit code from here on... */ |
||||
.code16 |
||||
|
||||
/* |
||||
* Load the segment registers w/ properly configured segment |
||||
* descriptors. They will retain these configurations (limits, |
||||
* writability, etc.) once protected mode is turned off. |
||||
*/ |
||||
mov $DATA_SEG, %ax |
||||
mov %ax, %ds |
||||
mov %ax, %es |
||||
mov %ax, %fs |
||||
mov %ax, %gs |
||||
mov %ax, %ss |
||||
|
||||
/* Turn off protection */ |
||||
movl %cr0, %eax |
||||
andl $~X86_CR0_PE, %eax |
||||
movl %eax, %cr0 |
||||
|
||||
/* Now really going into real mode */ |
||||
ljmp $0, $RELOCATED(1f) |
||||
1: |
||||
movw $0x0, %ax |
||||
movw %ax, %ds |
||||
movw %ax, %es |
||||
movw %ax, %ss |
||||
movw %ax, %fs |
||||
movw %ax, %gs |
||||
|
||||
/* |
||||
* This is a FAR JMP to the OS waking vector. |
||||
* The C code changes the address to be correct. |
||||
*/ |
||||
.byte 0xea
|
||||
|
||||
__wakeup_offset = RELOCATED(.) |
||||
.word 0x0000
|
||||
|
||||
__wakeup_segment = RELOCATED(.) |
||||
.word 0x0000
|
||||
|
||||
.globl __wakeup_size
|
||||
__wakeup_size: |
||||
.long . - __wakeup |
@ -0,0 +1,131 @@ |
||||
/*
|
||||
* 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__ */ |
@ -0,0 +1,31 @@ |
||||
/*
|
||||
* Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef __CMOS_LAYOUT_H |
||||
#define __CMOS_LAYOUT_H |
||||
|
||||
/*
|
||||
* The RTC internal registers and RAM is organized as two banks of 128 bytes |
||||
* each, called the standard and extended banks. The first 14 bytes of the |
||||
* standard bank contain the RTC time and date information along with four |
||||
* registers, A - D, that are used for configuration of the RTC. The extended |
||||
* bank contains a full 128 bytes of battery backed SRAM. |
||||
* |
||||
* For simplicity in U-Boot we only support CMOS in the standard bank, and |
||||
* its base address starts from offset 0x10, which leaves us 112 bytes space. |
||||
*/ |
||||
#define CMOS_BASE 0x10 |
||||
|
||||
/*
|
||||
* The file records all offsets off CMOS_BASE that is currently used by |
||||
* U-Boot for various reasons. It is put in such a unified place in order |
||||
* to be consistent across platforms. |
||||
*/ |
||||
|
||||
/* stack address for S3 boot in a FSP configuration, 4 bytes */ |
||||
#define CMOS_FSP_STACK_ADDR CMOS_BASE |
||||
|
||||
#endif /* __CMOS_LAYOUT_H */ |
@ -0,0 +1,43 @@ |
||||
/*
|
||||
* Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#ifndef __EARLY_CMOS_H |
||||
#define __EARLY_CMOS_H |
||||
|
||||
/* CMOS actually resides in the RTC SRAM */ |
||||
#define CMOS_IO_PORT 0x70 |
||||
|
||||
/**
|
||||
* cmos_read8() - Get 8-bit data stored at the given address |
||||
* |
||||
* This reads from CMOS for the 8-bit data stored at the given address. |
||||
* |
||||
* @addr: RTC SRAM address |
||||
* @return: 8-bit data stored at the given address |
||||
*/ |
||||
u8 cmos_read8(u8 addr); |
||||
|
||||
/**
|
||||
* cmos_read16() - Get 16-bit data stored at the given address |
||||
* |
||||
* This reads from CMOS for the 16-bit data stored at the given address. |
||||
* |
||||
* @addr: RTC SRAM address |
||||
* @return: 16-bit data stored at the given address |
||||
*/ |
||||
u16 cmos_read16(u8 addr); |
||||
|
||||
/**
|
||||
* cmos_read32() - Get 32-bit data stored at the given address |
||||
* |
||||
* This reads from CMOS for the 32-bit data stored at the given address. |
||||
* |
||||
* @addr: RTC SRAM address |
||||
* @return: 32-bit data stored at the given address |
||||
*/ |
||||
u32 cmos_read32(u8 addr); |
||||
|
||||
#endif /* __EARLY_CMOS_H */ |
@ -0,0 +1,82 @@ |
||||
/*
|
||||
* Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/acpi_s3.h> |
||||
#include <asm/acpi_table.h> |
||||
#include <asm/post.h> |
||||
|
||||
DECLARE_GLOBAL_DATA_PTR; |
||||
|
||||
static void asmlinkage (*acpi_do_wakeup)(void *vector) = (void *)WAKEUP_BASE; |
||||
|
||||
static void acpi_jump_to_wakeup(void *vector) |
||||
{ |
||||
/* Copy wakeup trampoline in place */ |
||||
memcpy((void *)WAKEUP_BASE, __wakeup, __wakeup_size); |
||||
|
||||
printf("Jumping to OS waking vector %p\n", vector); |
||||
acpi_do_wakeup(vector); |
||||
} |
||||
|
||||
void acpi_resume(struct acpi_fadt *fadt) |
||||
{ |
||||
void *wake_vec; |
||||
|
||||
/* Turn on ACPI mode for S3 */ |
||||
enter_acpi_mode(fadt->pm1a_cnt_blk); |
||||
|
||||
wake_vec = acpi_find_wakeup_vector(fadt); |
||||
|
||||
/*
|
||||
* Restore the memory content starting from address 0x1000 which is |
||||
* used for the real mode interrupt handler stubs. |
||||
*/ |
||||
memcpy((void *)0x1000, (const void *)gd->arch.backup_mem, |
||||
S3_RESERVE_SIZE); |
||||
|
||||
post_code(POST_OS_RESUME); |
||||
acpi_jump_to_wakeup(wake_vec); |
||||
} |
||||
|
||||
int acpi_s3_reserve(void) |
||||
{ |
||||
/* adjust stack pointer for ACPI S3 resume backup memory */ |
||||
gd->start_addr_sp -= S3_RESERVE_SIZE; |
||||
gd->arch.backup_mem = gd->start_addr_sp; |
||||
|
||||
gd->start_addr_sp &= ~0xf; |
||||
|
||||
/*
|
||||
* 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 (see acpi_resume() above). |
||||
*/ |
||||
if (gd->arch.prev_sleep_state == ACPI_S3) |
||||
memcpy((void *)gd->arch.backup_mem, (const void *)0x1000, |
||||
S3_RESERVE_SIZE); |
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,51 @@ |
||||
/*
|
||||
* Copyright (C) 2017, Bin Meng <bmeng.cn@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-2.0+ |
||||
*/ |
||||
|
||||
/*
|
||||
* This library provides CMOS (inside RTC SRAM) access routines at a very |
||||
* early stage when driver model is not available yet. Only read access is |
||||
* provided. The 16-bit/32-bit read are compatible with driver model RTC |
||||
* uclass write ops, that data is stored in little-endian mode. |
||||
*/ |
||||
|
||||
#include <common.h> |
||||
#include <asm/early_cmos.h> |
||||
#include <asm/io.h> |
||||
|
||||
u8 cmos_read8(u8 addr) |
||||
{ |
||||
outb(addr, CMOS_IO_PORT); |
||||
|
||||
return inb(CMOS_IO_PORT + 1); |
||||
} |
||||
|
||||
u16 cmos_read16(u8 addr) |
||||
{ |
||||
u16 value = 0; |
||||
u16 data; |
||||
int i; |
||||
|
||||
for (i = 0; i < sizeof(value); i++) { |
||||
data = cmos_read8(addr + i); |
||||
value |= data << (i << 3); |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
|
||||
u32 cmos_read32(u8 addr) |
||||
{ |
||||
u32 value = 0; |
||||
u32 data; |
||||
int i; |
||||
|
||||
for (i = 0; i < sizeof(value); i++) { |
||||
data = cmos_read8(addr + i); |
||||
value |= data << (i << 3); |
||||
} |
||||
|
||||
return value; |
||||
} |
Loading…
Reference in new issue