blob: e335a8f846afdd0d8388e782b02c5dba563bf206 [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>
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05008#include <asm-generic/sections.h>
9
Naveen N. Rao7aa5b012017-04-19 20:59:51 +053010extern char __head_end[];
11
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050012#ifdef __powerpc64__
13
Mahesh Salgaonkar429d2e82014-01-31 00:31:04 +053014extern char __start_interrupts[];
Anton Blanchardd715e432011-11-14 12:54:47 +000015extern char __end_interrupts[];
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050016
Anton Blanchard5ac47f72012-11-26 17:39:03 +000017extern char __prom_init_toc_start[];
18extern char __prom_init_toc_end[];
19
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050020static 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
Michael Ellermana5cab832016-03-03 15:26:53 +110028static 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
Mahesh Salgaonkar429d2e82014-01-31 00:31:04 +053040static 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 Mackerras549e8152008-08-30 11:43:47 +100051static 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
Alexander Grafb18db0b2014-04-29 12:17:26 +020057static 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
Michael Ellermanf55d9662016-06-06 22:26:10 +053068#ifdef PPC64_ELF_ABI_v1
Sergey Senozhatsky5633e852017-11-10 08:48:27 +090069
70#define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
71
James Bottomleydeac93d2008-09-03 20:43:36 -050072#undef dereference_function_descriptor
James Bottomley2d291e92008-09-09 14:04:18 +000073static 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}
Sergey Senozhatsky5633e852017-11-10 08:48:27 +090082
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}
Michael Ellermanf55d9662016-06-06 22:26:10 +053091#endif /* PPC64_ELF_ABI_v1 */
James Bottomleydeac93d2008-09-03 20:43:36 -050092
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050093#endif
94
Arnd Bergmann88ced032005-12-16 22:43:46 +010095#endif /* __KERNEL__ */
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050096#endif /* _ASM_POWERPC_SECTIONS_H */