pcpu.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
  5. * Copyright (c) Peter Wemm <peter@netplex.com.au>
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * $FreeBSD$
  30. */
  31. #ifndef _MACHINE_PCPU_H_
  32. #define _MACHINE_PCPU_H_
  33. #include <machine/cpufunc.h>
  34. #include <machine/slb.h>
  35. #include <machine/tlb.h>
  36. struct pmap;
  37. struct pvo_entry;
  38. #define CPUSAVE_LEN 9
  39. #define PCPU_MD_COMMON_FIELDS \
  40. int pc_inside_intr; \
  41. struct pmap *pc_curpmap; /* current pmap */ \
  42. struct thread *pc_fputhread; /* current fpu user */ \
  43. struct thread *pc_vecthread; /* current vec user */ \
  44. struct thread *pc_htmthread; /* current htm user */ \
  45. uintptr_t pc_hwref; \
  46. int pc_bsp; \
  47. volatile int pc_awake; \
  48. uint32_t pc_ipimask; \
  49. uint32_t pc_flags; /* cpu feature flags */ \
  50. register_t pc_tempsave[CPUSAVE_LEN]; \
  51. register_t pc_disisave[CPUSAVE_LEN]; \
  52. register_t pc_dbsave[CPUSAVE_LEN]; \
  53. void *pc_restore; \
  54. vm_offset_t pc_qmap_addr;
  55. #define PCPU_MD_AIM32_FIELDS \
  56. struct pvo_entry *qmap_pvo; \
  57. struct mtx qmap_lock; \
  58. char __pad[128];
  59. #define PCPU_MD_AIM64_FIELDS \
  60. struct slb slb[64]; \
  61. struct slb **userslb; \
  62. register_t slbsave[18]; \
  63. uint8_t slbstack[1024]; \
  64. struct pvo_entry *qmap_pvo; \
  65. struct mtx qmap_lock; \
  66. uint64_t opal_hmi_flags; \
  67. char __pad[1337];
  68. #ifdef __powerpc64__
  69. #define PCPU_MD_AIM_FIELDS PCPU_MD_AIM64_FIELDS
  70. #else
  71. #define PCPU_MD_AIM_FIELDS PCPU_MD_AIM32_FIELDS
  72. #endif
  73. /* CPU feature flags, can be used for cached flow control. */
  74. #define PC_FLAG_NOSRS 0x80000000
  75. #define BOOKE_CRITSAVE_LEN (CPUSAVE_LEN + 2)
  76. #define BOOKE_TLB_MAXNEST 4
  77. #define BOOKE_TLB_SAVELEN 16
  78. #define BOOKE_TLBSAVE_LEN (BOOKE_TLB_SAVELEN * BOOKE_TLB_MAXNEST)
  79. #ifdef __powerpc64__
  80. #define BOOKE_PCPU_PAD 901
  81. #else
  82. #define BOOKE_PCPU_PAD 365
  83. #endif
  84. #define PCPU_MD_BOOKE_FIELDS \
  85. register_t critsave[BOOKE_CRITSAVE_LEN]; \
  86. register_t mchksave[CPUSAVE_LEN]; \
  87. register_t tlbsave[BOOKE_TLBSAVE_LEN]; \
  88. register_t tlb_level; \
  89. uintptr_t *tlb_lock; \
  90. int tid_next; \
  91. char __pad[BOOKE_PCPU_PAD];
  92. /* Definitions for register offsets within the exception tmp save areas */
  93. #define CPUSAVE_R27 0 /* where r27 gets saved */
  94. #define CPUSAVE_R28 1 /* where r28 gets saved */
  95. #define CPUSAVE_R29 2 /* where r29 gets saved */
  96. #define CPUSAVE_R30 3 /* where r30 gets saved */
  97. #define CPUSAVE_R31 4 /* where r31 gets saved */
  98. #define CPUSAVE_AIM_DAR 5 /* where SPR_DAR gets saved */
  99. #define CPUSAVE_AIM_DSISR 6 /* where SPR_DSISR gets saved */
  100. #define CPUSAVE_BOOKE_DEAR 5 /* where SPR_DEAR gets saved */
  101. #define CPUSAVE_BOOKE_ESR 6 /* where SPR_ESR gets saved */
  102. #define CPUSAVE_SRR0 7 /* where SRR0 gets saved */
  103. #define CPUSAVE_SRR1 8 /* where SRR1 gets saved */
  104. #define BOOKE_CRITSAVE_SRR0 9 /* where real SRR0 gets saved (critical) */
  105. #define BOOKE_CRITSAVE_SRR1 10 /* where real SRR0 gets saved (critical) */
  106. /* Book-E TLBSAVE is more elaborate */
  107. #define TLBSAVE_BOOKE_LR 0
  108. #define TLBSAVE_BOOKE_CR 1
  109. #define TLBSAVE_BOOKE_SRR0 2
  110. #define TLBSAVE_BOOKE_SRR1 3
  111. #define TLBSAVE_BOOKE_R20 4
  112. #define TLBSAVE_BOOKE_R21 5
  113. #define TLBSAVE_BOOKE_R22 6
  114. #define TLBSAVE_BOOKE_R23 7
  115. #define TLBSAVE_BOOKE_R24 8
  116. #define TLBSAVE_BOOKE_R25 9
  117. #define TLBSAVE_BOOKE_R26 10
  118. #define TLBSAVE_BOOKE_R27 11
  119. #define TLBSAVE_BOOKE_R28 12
  120. #define TLBSAVE_BOOKE_R29 13
  121. #define TLBSAVE_BOOKE_R30 14
  122. #define TLBSAVE_BOOKE_R31 15
  123. #define PCPU_MD_FIELDS \
  124. PCPU_MD_COMMON_FIELDS \
  125. union { \
  126. struct { \
  127. PCPU_MD_AIM_FIELDS \
  128. } pc_aim; \
  129. struct { \
  130. PCPU_MD_BOOKE_FIELDS \
  131. } pc_booke; \
  132. }
  133. #ifdef _KERNEL
  134. #define pcpup (get_pcpu())
  135. static __inline __pure2 struct thread *
  136. __curthread(void)
  137. {
  138. struct thread *td;
  139. #ifdef __powerpc64__
  140. __asm __volatile("mr %0,13" : "=r"(td));
  141. #else
  142. __asm __volatile("mr %0,2" : "=r"(td));
  143. #endif
  144. return (td);
  145. }
  146. #define curthread (__curthread())
  147. #define PCPU_GET(member) (pcpup->pc_ ## member)
  148. /*
  149. * XXX The implementation of this operation should be made atomic
  150. * with respect to preemption.
  151. */
  152. #define PCPU_ADD(member, value) (pcpup->pc_ ## member += (value))
  153. #define PCPU_INC(member) PCPU_ADD(member, 1)
  154. #define PCPU_PTR(member) (&pcpup->pc_ ## member)
  155. #define PCPU_SET(member,value) (pcpup->pc_ ## member = (value))
  156. #endif /* _KERNEL */
  157. #endif /* !_MACHINE_PCPU_H_ */