sections.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_POWERPC_SECTIONS_H
  3. #define _ASM_POWERPC_SECTIONS_H
  4. #ifdef __KERNEL__
  5. #include <linux/elf.h>
  6. #include <linux/uaccess.h>
  7. #include <asm-generic/sections.h>
  8. extern char __head_end[];
  9. #ifdef __powerpc64__
  10. extern char __start_interrupts[];
  11. extern char __end_interrupts[];
  12. extern char __prom_init_toc_start[];
  13. extern char __prom_init_toc_end[];
  14. static inline int in_kernel_text(unsigned long addr)
  15. {
  16. if (addr >= (unsigned long)_stext && addr < (unsigned long)__init_end)
  17. return 1;
  18. return 0;
  19. }
  20. static inline unsigned long kernel_toc_addr(void)
  21. {
  22. /* Defined by the linker, see vmlinux.lds.S */
  23. extern unsigned long __toc_start;
  24. /*
  25. * The TOC register (r2) points 32kB into the TOC, so that 64kB of
  26. * the TOC can be addressed using a single machine instruction.
  27. */
  28. return (unsigned long)(&__toc_start) + 0x8000UL;
  29. }
  30. static inline int overlaps_interrupt_vector_text(unsigned long start,
  31. unsigned long end)
  32. {
  33. unsigned long real_start, real_end;
  34. real_start = __start_interrupts - _stext;
  35. real_end = __end_interrupts - _stext;
  36. return start < (unsigned long)__va(real_end) &&
  37. (unsigned long)__va(real_start) < end;
  38. }
  39. static inline int overlaps_kernel_text(unsigned long start, unsigned long end)
  40. {
  41. return start < (unsigned long)__init_end &&
  42. (unsigned long)_stext < end;
  43. }
  44. static inline int overlaps_kvm_tmp(unsigned long start, unsigned long end)
  45. {
  46. #ifdef CONFIG_KVM_GUEST
  47. extern char kvm_tmp[];
  48. return start < (unsigned long)kvm_tmp &&
  49. (unsigned long)&kvm_tmp[1024 * 1024] < end;
  50. #else
  51. return 0;
  52. #endif
  53. }
  54. #ifdef PPC64_ELF_ABI_v1
  55. #define HAVE_DEREFERENCE_FUNCTION_DESCRIPTOR 1
  56. #undef dereference_function_descriptor
  57. static inline void *dereference_function_descriptor(void *ptr)
  58. {
  59. struct ppc64_opd_entry *desc = ptr;
  60. void *p;
  61. if (!probe_kernel_address(&desc->funcaddr, p))
  62. ptr = p;
  63. return ptr;
  64. }
  65. #undef dereference_kernel_function_descriptor
  66. static inline void *dereference_kernel_function_descriptor(void *ptr)
  67. {
  68. if (ptr < (void *)__start_opd || ptr >= (void *)__end_opd)
  69. return ptr;
  70. return dereference_function_descriptor(ptr);
  71. }
  72. #endif /* PPC64_ELF_ABI_v1 */
  73. #endif
  74. #endif /* __KERNEL__ */
  75. #endif /* _ASM_POWERPC_SECTIONS_H */