Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_SECTIONS_H |
| 2 | #define _ASM_POWERPC_SECTIONS_H |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 3 | #ifdef __KERNEL__ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 4 | |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 5 | #include <linux/elf.h> |
| 6 | #include <linux/uaccess.h> |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 7 | #include <asm-generic/sections.h> |
| 8 | |
Naveen N. Rao | 7aa5b01 | 2017-04-19 20:59:51 +0530 | [diff] [blame^] | 9 | extern char __head_end[]; |
| 10 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 11 | #ifdef __powerpc64__ |
| 12 | |
Mahesh Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 13 | extern char __start_interrupts[]; |
Anton Blanchard | d715e43 | 2011-11-14 12:54:47 +0000 | [diff] [blame] | 14 | extern char __end_interrupts[]; |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 15 | |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 16 | extern char __prom_init_toc_start[]; |
| 17 | extern char __prom_init_toc_end[]; |
| 18 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 19 | static inline int in_kernel_text(unsigned long addr) |
| 20 | { |
| 21 | if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end) |
| 22 | return 1; |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Michael Ellerman | a5cab83 | 2016-03-03 15:26:53 +1100 | [diff] [blame] | 27 | static inline unsigned long kernel_toc_addr(void) |
| 28 | { |
| 29 | /* Defined by the linker, see vmlinux.lds.S */ |
| 30 | extern unsigned long __toc_start; |
| 31 | |
| 32 | /* |
| 33 | * The TOC register (r2) points 32kB into the TOC, so that 64kB of |
| 34 | * the TOC can be addressed using a single machine instruction. |
| 35 | */ |
| 36 | return (unsigned long)(&__toc_start) + 0x8000UL; |
| 37 | } |
| 38 | |
Mahesh Salgaonkar | 429d2e8 | 2014-01-31 00:31:04 +0530 | [diff] [blame] | 39 | static inline int overlaps_interrupt_vector_text(unsigned long start, |
| 40 | unsigned long end) |
| 41 | { |
| 42 | unsigned long real_start, real_end; |
| 43 | real_start = __start_interrupts - _stext; |
| 44 | real_end = __end_interrupts - _stext; |
| 45 | |
| 46 | return start < (unsigned long)__va(real_end) && |
| 47 | (unsigned long)__va(real_start) < end; |
| 48 | } |
| 49 | |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 50 | static inline int overlaps_kernel_text(unsigned long start, unsigned long end) |
| 51 | { |
| 52 | return start < (unsigned long)__init_end && |
| 53 | (unsigned long)_stext < end; |
| 54 | } |
| 55 | |
Alexander Graf | b18db0b | 2014-04-29 12:17:26 +0200 | [diff] [blame] | 56 | static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end) |
| 57 | { |
| 58 | #ifdef CONFIG_KVM_GUEST |
| 59 | extern char kvm_tmp[]; |
| 60 | return start < (unsigned long)kvm_tmp && |
| 61 | (unsigned long)&kvm_tmp[1024 * 1024] < end; |
| 62 | #else |
| 63 | return 0; |
| 64 | #endif |
| 65 | } |
| 66 | |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 67 | #ifdef PPC64_ELF_ABI_v1 |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 68 | #undef dereference_function_descriptor |
James Bottomley | 2d291e9 | 2008-09-09 14:04:18 +0000 | [diff] [blame] | 69 | static inline void *dereference_function_descriptor(void *ptr) |
| 70 | { |
| 71 | struct ppc64_opd_entry *desc = ptr; |
| 72 | void *p; |
| 73 | |
| 74 | if (!probe_kernel_address(&desc->funcaddr, p)) |
| 75 | ptr = p; |
| 76 | return ptr; |
| 77 | } |
Michael Ellerman | f55d966 | 2016-06-06 22:26:10 +0530 | [diff] [blame] | 78 | #endif /* PPC64_ELF_ABI_v1 */ |
James Bottomley | deac93d | 2008-09-03 20:43:36 -0500 | [diff] [blame] | 79 | |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 80 | #endif |
| 81 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 82 | #endif /* __KERNEL__ */ |
Jon Loeliger | fbcd54b | 2005-09-17 10:39:46 -0500 | [diff] [blame] | 83 | #endif /* _ASM_POWERPC_SECTIONS_H */ |