blob: d19871763ed4aab6ada51716f385d7978c241b76 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05002#ifndef _ASM_POWERPC_SECTIONS_H
3#define _ASM_POWERPC_SECTIONS_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01004#ifdef __KERNEL__
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05005
James Bottomley2d291e92008-09-09 14:04:18 +00006#include <linux/elf.h>
7#include <linux/uaccess.h>
Michael Ellerman6f070482019-11-27 18:41:26 +11008
9#define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed
10
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050011#include <asm-generic/sections.h>
12
Michael Ellerman6f070482019-11-27 18:41:26 +110013extern bool init_mem_is_free;
14
15static 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
Naveen N. Rao7aa5b012017-04-19 20:59:51 +053024extern char __head_end[];
25
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050026#ifdef __powerpc64__
27
Mahesh Salgaonkar429d2e82014-01-31 00:31:04 +053028extern char __start_interrupts[];
Anton Blanchardd715e432011-11-14 12:54:47 +000029extern char __end_interrupts[];
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050030
Anton Blanchard5ac47f72012-11-26 17:39:03 +000031extern char __prom_init_toc_start[];
32extern char __prom_init_toc_end[];
33
Nicholas Pigginbd3524f2019-03-01 22:56:36 +100034#ifdef CONFIG_PPC_POWERNV
35extern char start_real_trampolines[];
36extern char end_real_trampolines[];
37extern char start_virt_trampolines[];
38extern char end_virt_trampolines[];
39#endif
40
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050041static inline int in_kernel_text(unsigned long addr)
42{
43 if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
44 return 1;
45
46 return 0;
47}
48
Michael Ellermana5cab832016-03-03 15:26:53 +110049static inline unsigned long kernel_toc_addr(void)
50{
51 /* Defined by the linker, see vmlinux.lds.S */
52 extern unsigned long __toc_start;
53
54 /*
55 * The TOC register (r2) points 32kB into the TOC, so that 64kB of
56 * the TOC can be addressed using a single machine instruction.
57 */
58 return (unsigned long)(&__toc_start) + 0x8000UL;
59}
60
Mahesh Salgaonkar429d2e82014-01-31 00:31:04 +053061static 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
Paul Mackerras549e8152008-08-30 11:43:47 +100072static 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
Michael Ellermanf55d9662016-06-06 22:26:10 +053078#ifdef PPC64_ELF_ABI_v1
Sergey Senozhatsky5633e852017-11-10 08:48:27 +090079
80#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
81
James Bottomleydeac93d2008-09-03 20:43:36 -050082#undef dereference_function_descriptor
James Bottomley2d291e92008-09-09 14:04:18 +000083static inline void *dereference_function_descriptor(void *ptr)
84{
85 struct ppc64_opd_entry *desc = ptr;
86 void *p;
87
88 if (!probe_kernel_address(&desc->funcaddr, p))
89 ptr = p;
90 return ptr;
91}
Sergey Senozhatsky5633e852017-11-10 08:48:27 +090092
93#undef dereference_kernel_function_descriptor
94static inline void *dereference_kernel_function_descriptor(void *ptr)
95{
96 if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
97 return ptr;
98
99 return dereference_function_descriptor(ptr);
100}
Michael Ellermanf55d9662016-06-06 22:26:10 +0530101#endif /* PPC64_ELF_ABI_v1 */
James Bottomleydeac93d2008-09-03 20:43:36 -0500102
Jon Loeligerfbcd54b2005-09-17 10:39:46 -0500103#endif
104
Arnd Bergmann88ced032005-12-16 22:43:46 +0100105#endif /* __KERNEL__ */
Jon Loeligerfbcd54b2005-09-17 10:39:46 -0500106#endif /* _ASM_POWERPC_SECTIONS_H */