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 #ifdef CONFIG_HAVE_FUNCTION_DESCRIPTORS
10 typedef struct func_desc func_desc_t;
11 #endif
12 
13 #include <asm-generic/sections.h>
14 
15 extern char __head_end[];
16 extern char __srwx_boundary[];
17 extern char __exittext_begin[], __exittext_end[];
18 
19 /* Patch sites */
20 extern s32 patch__call_flush_branch_caches1;
21 extern s32 patch__call_flush_branch_caches2;
22 extern s32 patch__call_flush_branch_caches3;
23 extern s32 patch__flush_count_cache_return;
24 extern s32 patch__flush_link_stack_return;
25 extern s32 patch__call_kvm_flush_link_stack;
26 extern s32 patch__call_kvm_flush_link_stack_p9;
27 extern s32 patch__memset_nocache, patch__memcpy_nocache;
28 
29 extern long flush_branch_caches;
30 extern long kvm_flush_link_stack;
31 
32 #ifdef __powerpc64__
33 
34 extern char __start_interrupts[];
35 extern char __end_interrupts[];
36 
37 #ifdef CONFIG_PPC_POWERNV
38 extern char start_real_trampolines[];
39 extern char end_real_trampolines[];
40 extern char start_virt_trampolines[];
41 extern char end_virt_trampolines[];
42 #endif
43 
44 /*
45  * This assumes the kernel is never compiled -mcmodel=small or
46  * the total .toc is always less than 64k.
47  */
kernel_toc_addr(void)48 static inline unsigned long kernel_toc_addr(void)
49 {
50 #ifdef CONFIG_PPC_KERNEL_PCREL
51 	BUILD_BUG();
52 	return -1UL;
53 #else
54 	unsigned long toc_ptr;
55 
56 	asm volatile("mr %0, 2" : "=r" (toc_ptr));
57 	return toc_ptr;
58 #endif
59 }
60 
overlaps_interrupt_vector_text(unsigned long start,unsigned long end)61 static inline int overlaps_interrupt_vector_text(unsigned long start,
62 							unsigned long end)
63 {
64 	unsigned long real_start, real_end;
65 	real_start = __start_interrupts - _stext;
66 	real_end = __end_interrupts - _stext;
67 
68 	return start < (unsigned long)__va(real_end) &&
69 		(unsigned long)__va(real_start) < end;
70 }
71 
overlaps_kernel_text(unsigned long start,unsigned long end)72 static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
73 {
74 	return start < (unsigned long)__init_end &&
75 		(unsigned long)_stext < end;
76 }
77 
78 #else
kernel_toc_addr(void)79 static inline unsigned long kernel_toc_addr(void) { BUILD_BUG(); return -1UL; }
80 #endif
81 
82 #endif /* __KERNEL__ */
83 #endif	/* _ASM_POWERPC_SECTIONS_H */
84