proc-fns.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * arch/arm/include/asm/proc-fns.h
  3. *
  4. * Copyright (C) 1997-1999 Russell King
  5. * Copyright (C) 2000 Deep Blue Solutions Ltd
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef __ASM_PROCFNS_H
  12. #define __ASM_PROCFNS_H
  13. #ifdef __KERNEL__
  14. #include <asm/glue-proc.h>
  15. #include <asm/page.h>
  16. #ifndef __ASSEMBLY__
  17. struct mm_struct;
  18. /*
  19. * Don't change this structure - ASM code relies on it.
  20. */
  21. struct processor {
  22. /* MISC
  23. * get data abort address/flags
  24. */
  25. void (*_data_abort)(unsigned long pc);
  26. /*
  27. * Retrieve prefetch fault address
  28. */
  29. unsigned long (*_prefetch_abort)(unsigned long lr);
  30. /*
  31. * Set up any processor specifics
  32. */
  33. void (*_proc_init)(void);
  34. /*
  35. * Check for processor bugs
  36. */
  37. void (*check_bugs)(void);
  38. /*
  39. * Disable any processor specifics
  40. */
  41. void (*_proc_fin)(void);
  42. /*
  43. * Special stuff for a reset
  44. */
  45. void (*reset)(unsigned long addr, bool hvc) __attribute__((noreturn));
  46. /*
  47. * Idle the processor
  48. */
  49. int (*_do_idle)(void);
  50. /*
  51. * Processor architecture specific
  52. */
  53. /*
  54. * clean a virtual address range from the
  55. * D-cache without flushing the cache.
  56. */
  57. void (*dcache_clean_area)(void *addr, int size);
  58. /*
  59. * Set the page table
  60. */
  61. void (*switch_mm)(phys_addr_t pgd_phys, struct mm_struct *mm);
  62. /*
  63. * Set a possibly extended PTE. Non-extended PTEs should
  64. * ignore 'ext'.
  65. */
  66. #ifdef CONFIG_ARM_LPAE
  67. void (*set_pte_ext)(pte_t *ptep, pte_t pte);
  68. #else
  69. void (*set_pte_ext)(pte_t *ptep, pte_t pte, unsigned int ext);
  70. #endif
  71. /* Suspend/resume */
  72. unsigned int suspend_size;
  73. void (*do_suspend)(void *);
  74. void (*do_resume)(void *);
  75. };
  76. #ifndef MULTI_CPU
  77. static inline void init_proc_vtable(const struct processor *p)
  78. {
  79. }
  80. extern void cpu_proc_init(void);
  81. extern void cpu_proc_fin(void);
  82. extern int cpu_do_idle(void);
  83. extern void cpu_dcache_clean_area(void *, int);
  84. extern void cpu_do_switch_mm(phys_addr_t pgd_phys, struct mm_struct *mm);
  85. #ifdef CONFIG_ARM_LPAE
  86. extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte);
  87. #else
  88. extern void cpu_set_pte_ext(pte_t *ptep, pte_t pte, unsigned int ext);
  89. #endif
  90. extern void cpu_reset(unsigned long addr, bool hvc) __attribute__((noreturn));
  91. /* These three are private to arch/arm/kernel/suspend.c */
  92. extern void cpu_do_suspend(void *);
  93. extern void cpu_do_resume(void *);
  94. #else
  95. extern struct processor processor;
  96. #if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR)
  97. #include <linux/smp.h>
  98. /*
  99. * This can't be a per-cpu variable because we need to access it before
  100. * per-cpu has been initialised. We have a couple of functions that are
  101. * called in a pre-emptible context, and so can't use smp_processor_id()
  102. * there, hence PROC_TABLE(). We insist in init_proc_vtable() that the
  103. * function pointers for these are identical across all CPUs.
  104. */
  105. extern struct processor *cpu_vtable[];
  106. #define PROC_VTABLE(f) cpu_vtable[smp_processor_id()]->f
  107. #define PROC_TABLE(f) cpu_vtable[0]->f
  108. static inline void init_proc_vtable(const struct processor *p)
  109. {
  110. unsigned int cpu = smp_processor_id();
  111. *cpu_vtable[cpu] = *p;
  112. WARN_ON_ONCE(cpu_vtable[cpu]->dcache_clean_area !=
  113. cpu_vtable[0]->dcache_clean_area);
  114. WARN_ON_ONCE(cpu_vtable[cpu]->set_pte_ext !=
  115. cpu_vtable[0]->set_pte_ext);
  116. }
  117. #else
  118. #define PROC_VTABLE(f) processor.f
  119. #define PROC_TABLE(f) processor.f
  120. static inline void init_proc_vtable(const struct processor *p)
  121. {
  122. processor = *p;
  123. }
  124. #endif
  125. #define cpu_proc_init PROC_VTABLE(_proc_init)
  126. #define cpu_check_bugs PROC_VTABLE(check_bugs)
  127. #define cpu_proc_fin PROC_VTABLE(_proc_fin)
  128. #define cpu_reset PROC_VTABLE(reset)
  129. #define cpu_do_idle PROC_VTABLE(_do_idle)
  130. #define cpu_dcache_clean_area PROC_TABLE(dcache_clean_area)
  131. #define cpu_set_pte_ext PROC_TABLE(set_pte_ext)
  132. #define cpu_do_switch_mm PROC_VTABLE(switch_mm)
  133. /* These two are private to arch/arm/kernel/suspend.c */
  134. #define cpu_do_suspend PROC_VTABLE(do_suspend)
  135. #define cpu_do_resume PROC_VTABLE(do_resume)
  136. #endif
  137. extern void cpu_resume(void);
  138. #include <asm/memory.h>
  139. #ifdef CONFIG_MMU
  140. #define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)
  141. #ifdef CONFIG_ARM_LPAE
  142. #define cpu_get_ttbr(nr) \
  143. ({ \
  144. u64 ttbr; \
  145. __asm__("mrrc p15, " #nr ", %Q0, %R0, c2" \
  146. : "=r" (ttbr)); \
  147. ttbr; \
  148. })
  149. #define cpu_get_pgd() \
  150. ({ \
  151. u64 pg = cpu_get_ttbr(0); \
  152. pg &= ~(PTRS_PER_PGD*sizeof(pgd_t)-1); \
  153. (pgd_t *)phys_to_virt(pg); \
  154. })
  155. #else
  156. #define cpu_get_pgd() \
  157. ({ \
  158. unsigned long pg; \
  159. __asm__("mrc p15, 0, %0, c2, c0, 0" \
  160. : "=r" (pg) : : "cc"); \
  161. pg &= ~0x3fff; \
  162. (pgd_t *)phys_to_virt(pg); \
  163. })
  164. #endif
  165. #else /*!CONFIG_MMU */
  166. #define cpu_switch_mm(pgd,mm) { }
  167. #endif
  168. #endif /* __ASSEMBLY__ */
  169. #endif /* __KERNEL__ */
  170. #endif /* __ASM_PROCFNS_H */