blob: 7902d63588548a0cca22e7875d21f75264df49e3 [file] [log] [blame]
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05001#ifndef _ASM_POWERPC_SECTIONS_H
2#define _ASM_POWERPC_SECTIONS_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05004
James Bottomley2d291e92008-09-09 14:04:18 +00005#include <linux/elf.h>
6#include <linux/uaccess.h>
Jon Loeligerfbcd54b2005-09-17 10:39:46 -05007#include <asm-generic/sections.h>
8
Naveen N. Rao7aa5b012017-04-19 20:59:51 +05309extern char __head_end[];
10
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050011#ifdef __powerpc64__
12
Mahesh Salgaonkar429d2e82014-01-31 00:31:04 +053013extern char __start_interrupts[];
Anton Blanchardd715e432011-11-14 12:54:47 +000014extern char __end_interrupts[];
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050015
Anton Blanchard5ac47f72012-11-26 17:39:03 +000016extern char __prom_init_toc_start[];
17extern char __prom_init_toc_end[];
18
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050019static 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 Ellermana5cab832016-03-03 15:26:53 +110027static 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 Salgaonkar429d2e82014-01-31 00:31:04 +053039static 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 Mackerras549e8152008-08-30 11:43:47 +100050static 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 Grafb18db0b2014-04-29 12:17:26 +020056static 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 Ellermanf55d9662016-06-06 22:26:10 +053067#ifdef PPC64_ELF_ABI_v1
James Bottomleydeac93d2008-09-03 20:43:36 -050068#undef dereference_function_descriptor
James Bottomley2d291e92008-09-09 14:04:18 +000069static 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 Ellermanf55d9662016-06-06 22:26:10 +053078#endif /* PPC64_ELF_ABI_v1 */
James Bottomleydeac93d2008-09-03 20:43:36 -050079
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050080#endif
81
Arnd Bergmann88ced032005-12-16 22:43:46 +010082#endif /* __KERNEL__ */
Jon Loeligerfbcd54b2005-09-17 10:39:46 -050083#endif /* _ASM_POWERPC_SECTIONS_H */