From patchwork Thu Mar 16 14:26:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 739869 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vkWFj6HYxz9rvt for ; Fri, 17 Mar 2017 01:34:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RQLwXKXs"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 80534C21C8C; Thu, 16 Mar 2017 14:25:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 51197C21C57; Thu, 16 Mar 2017 14:23:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1677DC21C6A; Thu, 16 Mar 2017 14:22:33 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by lists.denx.de (Postfix) with ESMTPS id 09DE2C21C64 for ; Thu, 16 Mar 2017 14:22:30 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id g2so6272518pge.2 for ; Thu, 16 Mar 2017 07:22:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=7ds0llrGaGz8ZYNVJc8ZaHx6nUKL0y/7mzSlE1st2fc=; b=RQLwXKXsi9hPqrwNlLpMfe/ZAZVVEqr18rZ/wLP+N+Aeu3Q3TPp9APhSmsFe+zheCE 6AUDQxot0ZDppJr7fgZEjr2NTIWEdGZNvQRWiEyzKSifpHOb/Aerx0HjYPNWepegad8g ichdUeqgbBPZsX7kN0qHb2rGCAN3ocodhFBYzycPcGd0hRHc/lR87YLaSwEciHE6Rs4k mcKexoDPuCam6x/XS5niXDLIs4iZKH7NYHI7eej+bKkEYQB7psOZsRlfMwnL38Lm/WjY zUtPwBiJ0Qh7Y/NMSiRFcJ5n0/prQYjwUjWJ/XQkANJE12pCpGX8465yAUSkybff+z1A p8eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=7ds0llrGaGz8ZYNVJc8ZaHx6nUKL0y/7mzSlE1st2fc=; b=o5d2wSpi4oiiswECrlTk9Nd6+fl/9HwDOyFhSfda55h6vL7l2BjyYYAJRimNNrbiTz 8AcL+qC1hS3x5DJluSdpMGzN7LJPli174LGLaHF/Bdyen8w3G0zRMrbeEMavvCWZYhEN YInMaQvgLfNazW7g3EI7Bt12CZSU66usJVtZG5CVBBoem2GU3dtXk5gpqadcGFFZeVkj NB7AN1SRb1hmx2ZXs2eOS506QKBhD82p5KVoqpygq2FIy24/kaUGL3NB+80qtTwW8dE4 AVOo/tp07dYrJF8oxAUA8Lw0PC/4w4Ryho/S6qzDC/uwLXPpNhf6DTsoFMsA+/IaxdPX ESMA== X-Gm-Message-State: AFeK/H0EVgTg+AcaqzrJ09AQSn/k0OqhcofYgipAGkZo49mmawZ1hgBRrWGKvAe9aFYsEw== X-Received: by 10.84.206.37 with SMTP id f34mr12884718ple.175.1489674148689; Thu, 16 Mar 2017 07:22:28 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-157-139.windriver.com. [147.11.157.139]) by smtp.gmail.com with ESMTPSA id c64sm11039959pfa.45.2017.03.16.07.22.27 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Mar 2017 07:22:27 -0700 (PDT) From: Bin Meng To: Simon Glass , Stefan Roese , U-Boot Mailing List Date: Thu, 16 Mar 2017 07:26:35 -0700 Message-Id: <1489674408-17498-10-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1489674408-17498-1-git-send-email-bmeng.cn@gmail.com> References: <1489674408-17498-1-git-send-email-bmeng.cn@gmail.com> Subject: [U-Boot] [PATCH 09/22] x86: acpi: Add wake up assembly stub X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This adds a wake up stub before jumping to OS wake up vector. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- arch/x86/cpu/Makefile | 1 + arch/x86/cpu/wakeup.S | 79 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/acpi_s3.h | 9 +++++ 3 files changed, 89 insertions(+) create mode 100644 arch/x86/cpu/wakeup.S diff --git a/arch/x86/cpu/Makefile b/arch/x86/cpu/Makefile index 92a9023..e1c84ce 100644 --- a/arch/x86/cpu/Makefile +++ b/arch/x86/cpu/Makefile @@ -45,6 +45,7 @@ ifndef CONFIG_$(SPL_)X86_64 obj-$(CONFIG_SMP) += sipi_vector.o endif obj-y += turbo.o +obj-$(CONFIG_HAVE_ACPI_RESUME) += wakeup.o ifeq ($(CONFIG_$(SPL_)X86_64),y) obj-y += x86_64/ diff --git a/arch/x86/cpu/wakeup.S b/arch/x86/cpu/wakeup.S new file mode 100644 index 0000000..97b1c21 --- /dev/null +++ b/arch/x86/cpu/wakeup.S @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2017, Bin Meng + * + * From coreboot src/arch/x86/wakeup.S + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +#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 changed the address to be correct. + */ + .byte 0xea + +__wakeup_offset = RELOCATED(.) + .word 0x0000 + +__wakeup_segment = RELOCATED(.) + .word 0x0000 + + .globl __wakeup_size +__wakeup_size: + .long . - __wakeup diff --git a/arch/x86/include/asm/acpi_s3.h b/arch/x86/include/asm/acpi_s3.h index c1cdbd0..f9d4739 100644 --- a/arch/x86/include/asm/acpi_s3.h +++ b/arch/x86/include/asm/acpi_s3.h @@ -7,6 +7,8 @@ #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) @@ -27,6 +29,11 @@ #define SLP_TYP_S4 6 #define SLP_TYP_S5 7 +#ifndef __ASSEMBLY__ + +extern char __wakeup[]; +extern int __wakeup_size; + enum acpi_sleep_state { ACPI_S0, ACPI_S1, @@ -93,4 +100,6 @@ enum acpi_sleep_state chipset_prev_sleep_state(void); */ void chipset_clear_sleep_state(void); +#endif /* __ASSEMBLY__ */ + #endif /* __ASM_ACPI_S3_H__ */