Loading...
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
10typedef struct func_desc func_desc_t;
11#endif
12
13#include <asm-generic/sections.h>
14
15extern char __head_end[];
16extern char __srwx_boundary[];
17extern char __exittext_begin[], __exittext_end[];
18
19/* Patch sites */
20extern s32 patch__call_flush_branch_caches1;
21extern s32 patch__call_flush_branch_caches2;
22extern s32 patch__call_flush_branch_caches3;
23extern s32 patch__flush_count_cache_return;
24extern s32 patch__flush_link_stack_return;
25extern s32 patch__call_kvm_flush_link_stack;
26extern s32 patch__call_kvm_flush_link_stack_p9;
27extern s32 patch__memset_nocache, patch__memcpy_nocache;
28
29extern long flush_branch_caches;
30extern long kvm_flush_link_stack;
31
32#ifdef __powerpc64__
33
34extern char __start_interrupts[];
35extern char __end_interrupts[];
36
37#ifdef CONFIG_PPC_POWERNV
38extern char start_real_trampolines[];
39extern char end_real_trampolines[];
40extern char start_virt_trampolines[];
41extern 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 */
48static 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
61static 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
72static 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
79static inline unsigned long kernel_toc_addr(void) { BUILD_BUG(); return -1UL; }
80#endif
81
82#endif /* __KERNEL__ */
83#endif /* _ASM_POWERPC_SECTIONS_H */
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#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
20static inline int in_kernel_text(unsigned long addr)
21{
22 if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
23 return 1;
24
25 return 0;
26}
27
28static inline unsigned long kernel_toc_addr(void)
29{
30 /* Defined by the linker, see vmlinux.lds.S */
31 extern unsigned long __toc_start;
32
33 /*
34 * The TOC register (r2) points 32kB into the TOC, so that 64kB of
35 * the TOC can be addressed using a single machine instruction.
36 */
37 return (unsigned long)(&__toc_start) + 0x8000UL;
38}
39
40static 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
51static 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
57static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end)
58{
59#ifdef CONFIG_KVM_GUEST
60 extern char kvm_tmp[];
61 return start < (unsigned long)kvm_tmp &&
62 (unsigned long)&kvm_tmp[1024 * 1024] < end;
63#else
64 return 0;
65#endif
66}
67
68#ifdef PPC64_ELF_ABI_v1
69
70#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
71
72#undef dereference_function_descriptor
73static inline void *dereference_function_descriptor(void *ptr)
74{
75 struct ppc64_opd_entry *desc = ptr;
76 void *p;
77
78 if (!probe_kernel_address(&desc->funcaddr, p))
79 ptr = p;
80 return ptr;
81}
82
83#undef dereference_kernel_function_descriptor
84static inline void *dereference_kernel_function_descriptor(void *ptr)
85{
86 if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
87 return ptr;
88
89 return dereference_function_descriptor(ptr);
90}
91#endif /* PPC64_ELF_ABI_v1 */
92
93#endif
94
95#endif /* __KERNEL__ */
96#endif /* _ASM_POWERPC_SECTIONS_H */