blob: 12a561a54128ced49c7c8686c4d6c045fa684c13 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Geoff Levandd28f6df2016-06-23 17:54:48 +00002/*
3 * kexec for arm64
4 *
5 * Copyright (C) Linaro.
6 * Copyright (C) Huawei Futurewei Technologies.
Geoff Levandd28f6df2016-06-23 17:54:48 +00007 */
8
9#ifndef _ARM64_KEXEC_H
10#define _ARM64_KEXEC_H
11
12/* Maximum physical address we can use pages from */
13
14#define KEXEC_SOURCE_MEMORY_LIMIT (-1UL)
15
16/* Maximum address we can reach in physical address mode */
17
18#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
19
20/* Maximum address we can use for the control code buffer */
21
22#define KEXEC_CONTROL_MEMORY_LIMIT (-1UL)
23
24#define KEXEC_CONTROL_PAGE_SIZE 4096
25
26#define KEXEC_ARCH KEXEC_ARCH_AARCH64
27
28#ifndef __ASSEMBLY__
29
30/**
31 * crash_setup_regs() - save registers for the panic kernel
32 *
33 * @newregs: registers are saved here
34 * @oldregs: registers to be saved (may be %NULL)
35 */
36
37static inline void crash_setup_regs(struct pt_regs *newregs,
38 struct pt_regs *oldregs)
39{
AKASHI Takahiro78fd5842017-04-03 11:24:36 +090040 if (oldregs) {
41 memcpy(newregs, oldregs, sizeof(*newregs));
42 } else {
43 u64 tmp1, tmp2;
44
45 __asm__ __volatile__ (
46 "stp x0, x1, [%2, #16 * 0]\n"
47 "stp x2, x3, [%2, #16 * 1]\n"
48 "stp x4, x5, [%2, #16 * 2]\n"
49 "stp x6, x7, [%2, #16 * 3]\n"
50 "stp x8, x9, [%2, #16 * 4]\n"
51 "stp x10, x11, [%2, #16 * 5]\n"
52 "stp x12, x13, [%2, #16 * 6]\n"
53 "stp x14, x15, [%2, #16 * 7]\n"
54 "stp x16, x17, [%2, #16 * 8]\n"
55 "stp x18, x19, [%2, #16 * 9]\n"
56 "stp x20, x21, [%2, #16 * 10]\n"
57 "stp x22, x23, [%2, #16 * 11]\n"
58 "stp x24, x25, [%2, #16 * 12]\n"
59 "stp x26, x27, [%2, #16 * 13]\n"
60 "stp x28, x29, [%2, #16 * 14]\n"
61 "mov %0, sp\n"
62 "stp x30, %0, [%2, #16 * 15]\n"
63
64 "/* faked current PSTATE */\n"
65 "mrs %0, CurrentEL\n"
66 "mrs %1, SPSEL\n"
67 "orr %0, %0, %1\n"
68 "mrs %1, DAIF\n"
69 "orr %0, %0, %1\n"
70 "mrs %1, NZCV\n"
71 "orr %0, %0, %1\n"
72 /* pc */
73 "adr %1, 1f\n"
74 "1:\n"
75 "stp %1, %0, [%2, #16 * 16]\n"
76 : "=&r" (tmp1), "=&r" (tmp2)
77 : "r" (newregs)
78 : "memory"
79 );
80 }
Geoff Levandd28f6df2016-06-23 17:54:48 +000081}
82
AKASHI Takahiro254a41c2017-04-03 11:24:35 +090083#if defined(CONFIG_KEXEC_CORE) && defined(CONFIG_HIBERNATION)
84extern bool crash_is_nosave(unsigned long pfn);
85extern void crash_prepare_suspend(void);
86extern void crash_post_resume(void);
87#else
88static inline bool crash_is_nosave(unsigned long pfn) {return false; }
89static inline void crash_prepare_suspend(void) {}
90static inline void crash_post_resume(void) {}
91#endif
92
AKASHI Takahiro52b2a8a2018-11-15 14:52:49 +090093#ifdef CONFIG_KEXEC_FILE
94#define ARCH_HAS_KIMAGE_ARCH
95
96struct kimage_arch {
97 void *dtb;
98 unsigned long dtb_mem;
99};
100
AKASHI Takahirof3b70e52018-11-15 14:52:50 +0900101extern const struct kexec_file_ops kexec_image_ops;
102
AKASHI Takahiro52b2a8a2018-11-15 14:52:49 +0900103struct kimage;
104
105extern int arch_kimage_file_post_load_cleanup(struct kimage *image);
106extern int load_other_segments(struct kimage *image,
107 unsigned long kernel_load_addr, unsigned long kernel_size,
108 char *initrd, unsigned long initrd_len,
109 char *cmdline);
110#endif
111
Geoff Levandd28f6df2016-06-23 17:54:48 +0000112#endif /* __ASSEMBLY__ */
113
114#endif