processor.h 6.6 KB
Newer Older
C
Catalin Marinas 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Based on arch/arm/include/asm/processor.h
 *
 * Copyright (C) 1995-1999 Russell King
 * Copyright (C) 2012 ARM Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef __ASM_PROCESSOR_H
#define __ASM_PROCESSOR_H

22 23
#define TASK_SIZE_64		(UL(1) << VA_BITS)

24 25 26
#define KERNEL_DS	UL(-1)
#define USER_DS		(TASK_SIZE_64 - 1)

27 28
#ifndef __ASSEMBLY__

C
Catalin Marinas 已提交
29 30 31 32 33 34 35 36
/*
 * Default implementation of macro that returns current
 * instruction pointer ("program counter").
 */
#define current_text_addr() ({ __label__ _l; _l: &&_l;})

#ifdef __KERNEL__

37 38
#include <linux/build_bug.h>
#include <linux/stddef.h>
C
Catalin Marinas 已提交
39 40
#include <linux/string.h>

41
#include <asm/alternative.h>
42
#include <asm/cpufeature.h>
C
Catalin Marinas 已提交
43
#include <asm/hw_breakpoint.h>
44
#include <asm/lse.h>
45
#include <asm/pgtable-hwdef.h>
C
Catalin Marinas 已提交
46 47 48
#include <asm/ptrace.h>
#include <asm/types.h>

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*
 * TASK_SIZE - the maximum size of a user space task.
 * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
 */
#ifdef CONFIG_COMPAT
#define TASK_SIZE_32		UL(0x100000000)
#define TASK_SIZE		(test_thread_flag(TIF_32BIT) ? \
				TASK_SIZE_32 : TASK_SIZE_64)
#define TASK_SIZE_OF(tsk)	(test_tsk_thread_flag(tsk, TIF_32BIT) ? \
				TASK_SIZE_32 : TASK_SIZE_64)
#else
#define TASK_SIZE		TASK_SIZE_64
#endif /* CONFIG_COMPAT */

#define TASK_UNMAPPED_BASE	(PAGE_ALIGN(TASK_SIZE / 4))

C
Catalin Marinas 已提交
65 66 67 68 69 70 71 72
#define STACK_TOP_MAX		TASK_SIZE_64
#ifdef CONFIG_COMPAT
#define AARCH32_VECTORS_BASE	0xffff0000
#define STACK_TOP		(test_thread_flag(TIF_32BIT) ? \
				AARCH32_VECTORS_BASE : STACK_TOP_MAX)
#else
#define STACK_TOP		STACK_TOP_MAX
#endif /* CONFIG_COMPAT */
73

74 75
extern phys_addr_t arm64_dma_phys_limit;
#define ARCH_LOW_ADDRESS_LIMIT	(arm64_dma_phys_limit - 1)
C
Catalin Marinas 已提交
76 77

struct debug_info {
78
#ifdef CONFIG_HAVE_HW_BREAKPOINT
C
Catalin Marinas 已提交
79 80 81 82 83 84 85 86
	/* Have we suspended stepping by a debugger? */
	int			suspended_step;
	/* Allow breakpoints and watchpoints to be disabled for this thread. */
	int			bps_disabled;
	int			wps_disabled;
	/* Hardware breakpoints pinned to this task. */
	struct perf_event	*hbp_break[ARM_MAX_BRP];
	struct perf_event	*hbp_watch[ARM_MAX_WRP];
87
#endif
C
Catalin Marinas 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
};

struct cpu_context {
	unsigned long x19;
	unsigned long x20;
	unsigned long x21;
	unsigned long x22;
	unsigned long x23;
	unsigned long x24;
	unsigned long x25;
	unsigned long x26;
	unsigned long x27;
	unsigned long x28;
	unsigned long fp;
	unsigned long sp;
	unsigned long pc;
};

struct thread_struct {
	struct cpu_context	cpu_context;	/* cpu context */
108 109 110 111 112 113 114 115 116 117 118 119

	/*
	 * Whitelisted fields for hardened usercopy:
	 * Maintainers must ensure manually that this contains no
	 * implicit padding.
	 */
	struct {
		unsigned long	tp_value;	/* TLS register */
		unsigned long	tp2_value;
		struct user_fpsimd_state fpsimd_state;
	} uw;

120
	unsigned int		fpsimd_cpu;
121 122
	void			*sve_state;	/* SVE registers, if any */
	unsigned int		sve_vl;		/* SVE vector length */
123
	unsigned int		sve_vl_onexec;	/* SVE vl after next exec */
C
Catalin Marinas 已提交
124
	unsigned long		fault_address;	/* fault info */
125
	unsigned long		fault_code;	/* ESR_EL1 value */
C
Catalin Marinas 已提交
126 127 128
	struct debug_info	debug;		/* debugging */
};

129 130 131
static inline void arch_thread_struct_whitelist(unsigned long *offset,
						unsigned long *size)
{
132 133 134 135 136 137 138 139
	/* Verify that there is no padding among the whitelisted fields: */
	BUILD_BUG_ON(sizeof_field(struct thread_struct, uw) !=
		     sizeof_field(struct thread_struct, uw.tp_value) +
		     sizeof_field(struct thread_struct, uw.tp2_value) +
		     sizeof_field(struct thread_struct, uw.fpsimd_state));

	*offset = offsetof(struct thread_struct, uw);
	*size = sizeof_field(struct thread_struct, uw);
140 141
}

142 143 144 145 146
#ifdef CONFIG_COMPAT
#define task_user_tls(t)						\
({									\
	unsigned long *__tls;						\
	if (is_compat_thread(task_thread_info(t)))			\
147
		__tls = &(t)->thread.uw.tp2_value;			\
148
	else								\
149
		__tls = &(t)->thread.uw.tp_value;			\
150 151 152
	__tls;								\
 })
#else
153
#define task_user_tls(t)	(&(t)->thread.uw.tp_value)
154 155
#endif

156 157 158
/* Sync TPIDR_EL0 back to thread_struct for current */
void tls_preserve_current_state(void);

159 160 161
#define INIT_THREAD {				\
	.fpsimd_cpu = NR_CPUS,			\
}
C
Catalin Marinas 已提交
162 163 164 165

static inline void start_thread_common(struct pt_regs *regs, unsigned long pc)
{
	memset(regs, 0, sizeof(*regs));
166
	forget_syscall(regs);
C
Catalin Marinas 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
	regs->pc = pc;
}

static inline void start_thread(struct pt_regs *regs, unsigned long pc,
				unsigned long sp)
{
	start_thread_common(regs, pc);
	regs->pstate = PSR_MODE_EL0t;
	regs->sp = sp;
}

#ifdef CONFIG_COMPAT
static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc,
				       unsigned long sp)
{
	start_thread_common(regs, pc);
	regs->pstate = COMPAT_PSR_MODE_USR;
	if (pc & 1)
		regs->pstate |= COMPAT_PSR_T_BIT;
186 187 188 189 190

#ifdef __AARCH64EB__
	regs->pstate |= COMPAT_PSR_E_BIT;
#endif

C
Catalin Marinas 已提交
191 192 193 194 195 196 197 198 199 200 201 202
	regs->compat_sp = sp;
}
#endif

/* Forward declaration, a strange C thing */
struct task_struct;

/* Free all resources held by a thread. */
extern void release_thread(struct task_struct *);

unsigned long get_wchan(struct task_struct *p);

203 204 205 206 207
static inline void cpu_relax(void)
{
	asm volatile("yield" ::: "memory");
}

C
Catalin Marinas 已提交
208 209 210 211 212
/* Thread switching */
extern struct task_struct *cpu_switch_to(struct task_struct *prev,
					 struct task_struct *next);

#define task_pt_regs(p) \
213
	((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)
C
Catalin Marinas 已提交
214

215
#define KSTK_EIP(tsk)	((unsigned long)task_pt_regs(tsk)->pc)
216
#define KSTK_ESP(tsk)	user_stack_pointer(task_pt_regs(tsk))
C
Catalin Marinas 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

/*
 * Prefetching support
 */
#define ARCH_HAS_PREFETCH
static inline void prefetch(const void *ptr)
{
	asm volatile("prfm pldl1keep, %a0\n" : : "p" (ptr));
}

#define ARCH_HAS_PREFETCHW
static inline void prefetchw(const void *ptr)
{
	asm volatile("prfm pstl1keep, %a0\n" : : "p" (ptr));
}

#define ARCH_HAS_SPINLOCK_PREFETCH
234
static inline void spin_lock_prefetch(const void *ptr)
C
Catalin Marinas 已提交
235
{
236 237 238
	asm volatile(ARM64_LSE_ATOMIC_INSN(
		     "prfm pstl1strm, %a0",
		     "nop") : : "p" (ptr));
C
Catalin Marinas 已提交
239 240 241 242 243 244
}

#define HAVE_ARCH_PICK_MMAP_LAYOUT

#endif

245 246 247
void cpu_enable_pan(const struct arm64_cpu_capabilities *__unused);
void cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused);
void cpu_clear_disr(const struct arm64_cpu_capabilities *__unused);
248

249 250 251 252
/* Userspace interface for PR_SVE_{SET,GET}_VL prctl()s: */
#define SVE_SET_VL(arg)	sve_set_current_vl(arg)
#define SVE_GET_VL()	sve_get_current_vl()

253
#endif /* __ASSEMBLY__ */
C
Catalin Marinas 已提交
254
#endif /* __ASM_PROCESSOR_H */