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 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 9 | #include <asm-generic/sections.h> |
| 10 | |
Naveen N. Rao | 7aa5b01 | 2017-04-19 20:59:51 +0530 | [diff] [blame] | 11 | extern char __head_end[]; |
| 12 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 13 | #ifdef __powerpc64__ |
| 14 | |
Mahesh Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 15 | extern char __start_interrupts[]; |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 16 | extern char __end_interrupts[]; |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 17 | |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 18 | extern char __prom_init_toc_start[]; |
| 19 | extern char __prom_init_toc_end[]; |
| 20 | |
Nicholas Piggin | bd3524f | 2019-03-01 22:56:36 +1000 | [diff] [blame] | 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 | |
Alan Modra | a3ad84d | 2021-12-21 16:58:59 +1100 | [diff] [blame] | 28 | /* |
| 29 | * This assumes the kernel is never compiled -mcmodel=small or |
| 30 | * the total .toc is always less than 64k. |
| 31 | */ |
Michael Ellerman | a5cab83 | 2016-03-03 15:26:53 +1100 | [diff] [blame] | 32 | static inline unsigned long kernel_toc_addr(void) |
| 33 | { |
Alan Modra | a3ad84d | 2021-12-21 16:58:59 +1100 | [diff] [blame] | 34 | unsigned long toc_ptr; |
Michael Ellerman | a5cab83 | 2016-03-03 15:26:53 +1100 | [diff] [blame] | 35 | |
Alan Modra | a3ad84d | 2021-12-21 16:58:59 +1100 | [diff] [blame] | 36 | asm volatile("mr %0, 2" : "=r" (toc_ptr)); |
| 37 | return toc_ptr; |
Michael Ellerman | a5cab83 | 2016-03-03 15:26:53 +1100 | [diff] [blame] | 38 | } |
| 39 | |
Mahesh Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 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 | |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 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 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 57 | #ifdef PPC64_ELF_ABI_v1 |
Sergey Senozhatsky | 5633e85 | 2017-11-10 08:48:27 +0900 | [diff] [blame] | 58 | |
| 59 | #define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1 |
| 60 | |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 61 | #undef dereference_function_descriptor |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 62 | static inline void *dereference_function_descriptor(void *ptr) |
| 63 | { |
| 64 | struct ppc64_opd_entry *desc = ptr; |
| 65 | void *p; |
| 66 | |
Linus Torvalds | 0c389d89 | 2020-06-18 12:10:37 -0700 | [diff] [blame] | 67 | if (!get_kernel_nofault(p, (void *)&desc->funcaddr)) |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 68 | ptr = p; |
| 69 | return ptr; |
| 70 | } |
Sergey Senozhatsky | 5633e85 | 2017-11-10 08:48:27 +0900 | [diff] [blame] | 71 | |
| 72 | #undef dereference_kernel_function_descriptor |
| 73 | static inline void *dereference_kernel_function_descriptor(void *ptr) |
| 74 | { |
| 75 | if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd) |
| 76 | return ptr; |
| 77 | |
| 78 | return dereference_function_descriptor(ptr); |
| 79 | } |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 80 | #endif /* PPC64_ELF_ABI_v1 */ |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 81 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 82 | #endif |
| 83 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 84 | #endif /* __KERNEL__ */ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 85 | #endif /* _ASM_POWERPC_SECTIONS_H */ |