Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 2 | #ifndef _ASM_POWERPC_SECTIONS_H |
| 3 | #define _ASM_POWERPC_SECTIONS_H |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 4 | #ifdef __KERNEL__ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 5 | |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 6 | #include <linux/elf.h> |
| 7 | #include <linux/uaccess.h> |
Michael Ellerman | 6f07048 | 2019-11-27 18:41:26 +1100 | [diff] [blame^] | 8 | |
| 9 | #define arch_is_kernel_initmem_freed arch_is_kernel_initmem_freed |
| 10 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 11 | #include <asm-generic/sections.h> |
| 12 | |
Michael Ellerman | 6f07048 | 2019-11-27 18:41:26 +1100 | [diff] [blame^] | 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 | |
Naveen N. Rao | 7aa5b01 | 2017-04-19 20:59:51 +0530 | [diff] [blame] | 24 | extern char __head_end[]; |
| 25 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 26 | #ifdef __powerpc64__ |
| 27 | |
Mahesh Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 28 | extern char __start_interrupts[]; |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 29 | extern char __end_interrupts[]; |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 30 | |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 31 | extern char __prom_init_toc_start[]; |
| 32 | extern char __prom_init_toc_end[]; |
| 33 | |
Nicholas Piggin | bd3524f | 2019-03-01 22:56:36 +1000 | [diff] [blame] | 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 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 41 | static 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 Ellerman | a5cab83 | 2016-03-03 15:26:53 +1100 | [diff] [blame] | 49 | static 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 Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 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 | |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 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 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 78 | #ifdef PPC64_ELF_ABI_v1 |
Sergey Senozhatsky | 5633e85 | 2017-11-10 08:48:27 +0900 | [diff] [blame] | 79 | |
| 80 | #define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1 |
| 81 | |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 82 | #undef dereference_function_descriptor |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 83 | static 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 Senozhatsky | 5633e85 | 2017-11-10 08:48:27 +0900 | [diff] [blame] | 92 | |
| 93 | #undef dereference_kernel_function_descriptor |
| 94 | static 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 Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 101 | #endif /* PPC64_ELF_ABI_v1 */ |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 102 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 103 | #endif |
| 104 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 105 | #endif /* __KERNEL__ */ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 106 | #endif /* _ASM_POWERPC_SECTIONS_H */ |