blob: 5a9b6eb651b6c0dccda755a51c83baba5e008070 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_POWERPC_SECTIONS_H
3#define _ASM_POWERPC_SECTIONS_H
4#ifdef __KERNEL__
5
6#include <linux/elf.h>
7#include <linux/uaccess.h>
8#include <asm-generic/sections.h>
9
10extern char __head_end[];
11
12#ifdef __powerpc64__
13
14extern char __start_interrupts[];
15extern char __end_interrupts[];
16
17extern char __prom_init_toc_start[];
18extern char __prom_init_toc_end[];
19
David Brazdil0f672f62019-12-10 10:32:29 +000020#ifdef CONFIG_PPC_POWERNV
21extern char start_real_trampolines[];
22extern char end_real_trampolines[];
23extern char start_virt_trampolines[];
24extern char end_virt_trampolines[];
25#endif
26
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027static inline int in_kernel_text(unsigned long addr)
28{
29 if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
30 return 1;
31
32 return 0;
33}
34
35static inline unsigned long kernel_toc_addr(void)
36{
37 /* Defined by the linker, see vmlinux.lds.S */
38 extern unsigned long __toc_start;
39
40 /*
41 * The TOC register (r2) points 32kB into the TOC, so that 64kB of
42 * the TOC can be addressed using a single machine instruction.
43 */
44 return (unsigned long)(&__toc_start) + 0x8000UL;
45}
46
47static inline int overlaps_interrupt_vector_text(unsigned long start,
48 unsigned long end)
49{
50 unsigned long real_start, real_end;
51 real_start = __start_interrupts - _stext;
52 real_end = __end_interrupts - _stext;
53
54 return start < (unsigned long)__va(real_end) &&
55 (unsigned long)__va(real_start) < end;
56}
57
58static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
59{
60 return start < (unsigned long)__init_end &&
61 (unsigned long)_stext < end;
62}
63
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064#ifdef PPC64_ELF_ABI_v1
65
66#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
67
68#undef dereference_function_descriptor
69static inline void *dereference_function_descriptor(void *ptr)
70{
71 struct ppc64_opd_entry *desc = ptr;
72 void *p;
73
74 if (!probe_kernel_address(&desc->funcaddr, p))
75 ptr = p;
76 return ptr;
77}
78
79#undef dereference_kernel_function_descriptor
80static inline void *dereference_kernel_function_descriptor(void *ptr)
81{
82 if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
83 return ptr;
84
85 return dereference_function_descriptor(ptr);
86}
87#endif /* PPC64_ELF_ABI_v1 */
88
89#endif
90
91#endif /* __KERNEL__ */
92#endif /* _ASM_POWERPC_SECTIONS_H */