1 /* 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 
9 #define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
10 
11 #include <asm-generic/sections.h>
12 
13 extern bool init_mem_is_free;
14 
15 static inline int arch_is_kernel_initmem_freed(unsigned long addr)
16 {
17 	if (!init_mem_is_free)
18 		return 0;
19 
20 	return addr >= (unsigned long)__init_begin &&
21 		addr < (unsigned long)__init_end;
22 }
23 
24 extern char __head_end[];
25 
26 #ifdef __powerpc64__
27 
28 extern char __start_interrupts[];
29 extern char __end_interrupts[];
30 
31 extern char __prom_init_toc_start[];
32 extern char __prom_init_toc_end[];
33 
34 #ifdef CONFIG_PPC_POWERNV
35 extern char start_real_trampolines[];
36 extern char end_real_trampolines[];
37 extern char start_virt_trampolines[];
38 extern char end_virt_trampolines[];
39 #endif
40 
41 static inline unsigned long kernel_toc_addr(void)
42 {
43 	/* Defined by the linker, see vmlinux.lds.S */
44 	extern unsigned long __toc_start;
45 
46 	/*
47 	 * The TOC register (r2) points 32kB into the TOC, so that 64kB of
48 	 * the TOC can be addressed using a single machine instruction.
49 	 */
50 	return (unsigned long)(&__toc_start) + 0x8000UL;
51 }
52 
53 static inline int overlaps_interrupt_vector_text(unsigned long start,
54 							unsigned long end)
55 {
56 	unsigned long real_start, real_end;
57 	real_start = __start_interrupts - _stext;
58 	real_end = __end_interrupts - _stext;
59 
60 	return start < (unsigned long)__va(real_end) &&
61 		(unsigned long)__va(real_start) < end;
62 }
63 
64 static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
65 {
66 	return start < (unsigned long)__init_end &&
67 		(unsigned long)_stext < end;
68 }
69 
70 #ifdef PPC64_ELF_ABI_v1
71 
72 #define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
73 
74 #undef dereference_function_descriptor
75 static inline void *dereference_function_descriptor(void *ptr)
76 {
77 	struct ppc64_opd_entry *desc = ptr;
78 	void *p;
79 
80 	if (!get_kernel_nofault(p, (void *)&desc->funcaddr))
81 		ptr = p;
82 	return ptr;
83 }
84 
85 #undef dereference_kernel_function_descriptor
86 static inline void *dereference_kernel_function_descriptor(void *ptr)
87 {
88 	if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
89 		return ptr;
90 
91 	return dereference_function_descriptor(ptr);
92 }
93 #endif /* PPC64_ELF_ABI_v1 */
94 
95 #endif
96 
97 #endif /* __KERNEL__ */
98 #endif	/* _ASM_POWERPC_SECTIONS_H */
99