forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'riscv-for-linus-6.4-mw2' of git://git.kernel.org/pub/scm/l…
…inux/kernel/git/riscv/linux Pull more RISC-V updates from Palmer Dabbelt: - Support for hibernation - The .rela.dyn section has been moved to the init area - A fix for the SBI probing to allow for implementation-defined behavior - Various other fixes and cleanups throughout the tree * tag 'riscv-for-linus-6.4-mw2' of git://git.kernel.org/pub/scm/linux/kernel/git/riscv/linux: RISC-V: include cpufeature.h in cpufeature.c riscv: Move .rela.dyn to the init sections dt-bindings: riscv: explicitly mention assumption of Zicsr & Zifencei support riscv: compat_syscall_table: Fixup compile warning RISC-V: fixup in-flight collision with ARCH_WANT_OPTIMIZE_VMEMMAP rename RISC-V: fix sifive and thead section mismatches in errata RISC-V: Align SBI probe implementation with spec riscv: mm: remove redundant parameter of create_fdt_early_page_table riscv: Adjust dependencies of HAVE_DYNAMIC_FTRACE selection RISC-V: Add arch functions to support hibernation/suspend-to-disk RISC-V: mm: Enable huge page support to kernel_page_present() function RISC-V: Factor out common code of __cpu_resume_enter() RISC-V: Change suspend_save_csrs and suspend_restore_csrs to public function
- Loading branch information
Showing
22 changed files
with
682 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright (C) 2023 StarFive Technology Co., Ltd. | ||
* | ||
* Author: Jee Heng Sia <[email protected]> | ||
*/ | ||
|
||
#ifndef __ASSEMBLY__ | ||
#error "Only include this from assembly code" | ||
#endif | ||
|
||
#ifndef __ASM_ASSEMBLER_H | ||
#define __ASM_ASSEMBLER_H | ||
|
||
#include <asm/asm.h> | ||
#include <asm/asm-offsets.h> | ||
#include <asm/csr.h> | ||
|
||
/* | ||
* suspend_restore_csrs - restore CSRs | ||
*/ | ||
.macro suspend_restore_csrs | ||
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_EPC)(a0) | ||
csrw CSR_EPC, t0 | ||
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_STATUS)(a0) | ||
csrw CSR_STATUS, t0 | ||
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_BADADDR)(a0) | ||
csrw CSR_TVAL, t0 | ||
REG_L t0, (SUSPEND_CONTEXT_REGS + PT_CAUSE)(a0) | ||
csrw CSR_CAUSE, t0 | ||
.endm | ||
|
||
/* | ||
* suspend_restore_regs - Restore registers (except A0 and T0-T6) | ||
*/ | ||
.macro suspend_restore_regs | ||
REG_L ra, (SUSPEND_CONTEXT_REGS + PT_RA)(a0) | ||
REG_L sp, (SUSPEND_CONTEXT_REGS + PT_SP)(a0) | ||
REG_L gp, (SUSPEND_CONTEXT_REGS + PT_GP)(a0) | ||
REG_L tp, (SUSPEND_CONTEXT_REGS + PT_TP)(a0) | ||
REG_L s0, (SUSPEND_CONTEXT_REGS + PT_S0)(a0) | ||
REG_L s1, (SUSPEND_CONTEXT_REGS + PT_S1)(a0) | ||
REG_L a1, (SUSPEND_CONTEXT_REGS + PT_A1)(a0) | ||
REG_L a2, (SUSPEND_CONTEXT_REGS + PT_A2)(a0) | ||
REG_L a3, (SUSPEND_CONTEXT_REGS + PT_A3)(a0) | ||
REG_L a4, (SUSPEND_CONTEXT_REGS + PT_A4)(a0) | ||
REG_L a5, (SUSPEND_CONTEXT_REGS + PT_A5)(a0) | ||
REG_L a6, (SUSPEND_CONTEXT_REGS + PT_A6)(a0) | ||
REG_L a7, (SUSPEND_CONTEXT_REGS + PT_A7)(a0) | ||
REG_L s2, (SUSPEND_CONTEXT_REGS + PT_S2)(a0) | ||
REG_L s3, (SUSPEND_CONTEXT_REGS + PT_S3)(a0) | ||
REG_L s4, (SUSPEND_CONTEXT_REGS + PT_S4)(a0) | ||
REG_L s5, (SUSPEND_CONTEXT_REGS + PT_S5)(a0) | ||
REG_L s6, (SUSPEND_CONTEXT_REGS + PT_S6)(a0) | ||
REG_L s7, (SUSPEND_CONTEXT_REGS + PT_S7)(a0) | ||
REG_L s8, (SUSPEND_CONTEXT_REGS + PT_S8)(a0) | ||
REG_L s9, (SUSPEND_CONTEXT_REGS + PT_S9)(a0) | ||
REG_L s10, (SUSPEND_CONTEXT_REGS + PT_S10)(a0) | ||
REG_L s11, (SUSPEND_CONTEXT_REGS + PT_S11)(a0) | ||
.endm | ||
|
||
/* | ||
* copy_page - copy 1 page (4KB) of data from source to destination | ||
* @a0 - destination | ||
* @a1 - source | ||
*/ | ||
.macro copy_page a0, a1 | ||
lui a2, 0x1 | ||
add a2, a2, a0 | ||
1 : | ||
REG_L t0, 0(a1) | ||
REG_L t1, SZREG(a1) | ||
|
||
REG_S t0, 0(a0) | ||
REG_S t1, SZREG(a0) | ||
|
||
addi a0, a0, 2 * SZREG | ||
addi a1, a1, 2 * SZREG | ||
bne a2, a0, 1b | ||
.endm | ||
|
||
#endif /* __ASM_ASSEMBLER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Hibernation low level support for RISCV. | ||
* | ||
* Copyright (C) 2023 StarFive Technology Co., Ltd. | ||
* | ||
* Author: Jee Heng Sia <[email protected]> | ||
*/ | ||
|
||
#include <asm/asm.h> | ||
#include <asm/asm-offsets.h> | ||
#include <asm/assembler.h> | ||
#include <asm/csr.h> | ||
|
||
#include <linux/linkage.h> | ||
|
||
/* | ||
* int __hibernate_cpu_resume(void) | ||
* Switch back to the hibernated image's page table prior to restoring the CPU | ||
* context. | ||
* | ||
* Always returns 0 | ||
*/ | ||
ENTRY(__hibernate_cpu_resume) | ||
/* switch to hibernated image's page table. */ | ||
csrw CSR_SATP, s0 | ||
sfence.vma | ||
|
||
REG_L a0, hibernate_cpu_context | ||
|
||
suspend_restore_csrs | ||
suspend_restore_regs | ||
|
||
/* Return zero value. */ | ||
mv a0, zero | ||
|
||
ret | ||
END(__hibernate_cpu_resume) | ||
|
||
/* | ||
* Prepare to restore the image. | ||
* a0: satp of saved page tables. | ||
* a1: satp of temporary page tables. | ||
* a2: cpu_resume. | ||
*/ | ||
ENTRY(hibernate_restore_image) | ||
mv s0, a0 | ||
mv s1, a1 | ||
mv s2, a2 | ||
REG_L s4, restore_pblist | ||
REG_L a1, relocated_restore_code | ||
|
||
jalr a1 | ||
END(hibernate_restore_image) | ||
|
||
/* | ||
* The below code will be executed from a 'safe' page. | ||
* It first switches to the temporary page table, then starts to copy the pages | ||
* back to the original memory location. Finally, it jumps to __hibernate_cpu_resume() | ||
* to restore the CPU context. | ||
*/ | ||
ENTRY(hibernate_core_restore_code) | ||
/* switch to temp page table. */ | ||
csrw satp, s1 | ||
sfence.vma | ||
.Lcopy: | ||
/* The below code will restore the hibernated image. */ | ||
REG_L a1, HIBERN_PBE_ADDR(s4) | ||
REG_L a0, HIBERN_PBE_ORIG(s4) | ||
|
||
copy_page a0, a1 | ||
|
||
REG_L s4, HIBERN_PBE_NEXT(s4) | ||
bnez s4, .Lcopy | ||
|
||
jalr s2 | ||
END(hibernate_core_restore_code) |
Oops, something went wrong.