xref: /linux/arch/powerpc/include/asm/sections.h (revision a257cacc38718c83cee003487e03197f237f5c3f)
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 #include <asm-generic/sections.h>
10 
11 extern char __head_end[];
12 
13 #ifdef __powerpc64__
14 
15 extern char __start_interrupts[];
16 extern char __end_interrupts[];
17 
18 extern char __prom_init_toc_start[];
19 extern char __prom_init_toc_end[];
20 
21 #ifdef CONFIG_PPC_POWERNV
22 extern char start_real_trampolines[];
23 extern char end_real_trampolines[];
24 extern char start_virt_trampolines[];
25 extern char end_virt_trampolines[];
26 #endif
27 
28 /*
29  * This assumes the kernel is never compiled -mcmodel=small or
30  * the total .toc is always less than 64k.
31  */
32 static inline unsigned long kernel_toc_addr(void)
33 {
34 	unsigned long toc_ptr;
35 
36 	asm volatile("mr %0, 2" : "=r" (toc_ptr));
37 	return toc_ptr;
38 }
39 
40 static inline int overlaps_interrupt_vector_text(unsigned long start,
41 							unsigned long end)
42 {
43 	unsigned long real_start, real_end;
44 	real_start = __start_interrupts - _stext;
45 	real_end = __end_interrupts - _stext;
46 
47 	return start < (unsigned long)__va(real_end) &&
48 		(unsigned long)__va(real_start) < end;
49 }
50 
51 static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
52 {
53 	return start < (unsigned long)__init_end &&
54 		(unsigned long)_stext < end;
55 }
56 
57 #ifdef PPC64_ELF_ABI_v1
58 
59 #undef dereference_function_descriptor
60 static inline void *dereference_function_descriptor(void *ptr)
61 {
62 	struct func_desc *desc = ptr;
63 	void *p;
64 
65 	if (!get_kernel_nofault(p, (void *)&desc->addr))
66 		ptr = p;
67 	return ptr;
68 }
69 
70 #undef dereference_kernel_function_descriptor
71 static inline void *dereference_kernel_function_descriptor(void *ptr)
72 {
73 	if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
74 		return ptr;
75 
76 	return dereference_function_descriptor(ptr);
77 }
78 #endif /* PPC64_ELF_ABI_v1 */
79 
80 #endif
81 
82 #endif /* __KERNEL__ */
83 #endif	/* _ASM_POWERPC_SECTIONS_H */
84