gicv3_internal.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /*
  2. * ARM GICv3 support - internal interfaces
  3. *
  4. * Copyright (c) 2012 Linaro Limited
  5. * Copyright (c) 2015 Huawei.
  6. * Copyright (c) 2015 Samsung Electronics Co., Ltd.
  7. * Written by Peter Maydell
  8. * Reworked for GICv3 by Shlomo Pongratz and Pavel Fedin
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #ifndef QEMU_ARM_GICV3_INTERNAL_H
  24. #define QEMU_ARM_GICV3_INTERNAL_H
  25. #include "hw/registerfields.h"
  26. #include "hw/intc/arm_gicv3_common.h"
  27. /* Distributor registers, as offsets from the distributor base address */
  28. #define GICD_CTLR 0x0000
  29. #define GICD_TYPER 0x0004
  30. #define GICD_IIDR 0x0008
  31. #define GICD_STATUSR 0x0010
  32. #define GICD_SETSPI_NSR 0x0040
  33. #define GICD_CLRSPI_NSR 0x0048
  34. #define GICD_SETSPI_SR 0x0050
  35. #define GICD_CLRSPI_SR 0x0058
  36. #define GICD_SEIR 0x0068
  37. #define GICD_IGROUPR 0x0080
  38. #define GICD_ISENABLER 0x0100
  39. #define GICD_ICENABLER 0x0180
  40. #define GICD_ISPENDR 0x0200
  41. #define GICD_ICPENDR 0x0280
  42. #define GICD_ISACTIVER 0x0300
  43. #define GICD_ICACTIVER 0x0380
  44. #define GICD_IPRIORITYR 0x0400
  45. #define GICD_ITARGETSR 0x0800
  46. #define GICD_ICFGR 0x0C00
  47. #define GICD_IGRPMODR 0x0D00
  48. #define GICD_NSACR 0x0E00
  49. #define GICD_SGIR 0x0F00
  50. #define GICD_CPENDSGIR 0x0F10
  51. #define GICD_SPENDSGIR 0x0F20
  52. #define GICD_INMIR 0x0F80
  53. #define GICD_INMIRnE 0x3B00
  54. #define GICD_IROUTER 0x6000
  55. #define GICD_IDREGS 0xFFD0
  56. /* GICD_CTLR fields */
  57. #define GICD_CTLR_EN_GRP0 (1U << 0)
  58. #define GICD_CTLR_EN_GRP1NS (1U << 1) /* GICv3 5.3.20 */
  59. #define GICD_CTLR_EN_GRP1S (1U << 2)
  60. #define GICD_CTLR_EN_GRP1_ALL (GICD_CTLR_EN_GRP1NS | GICD_CTLR_EN_GRP1S)
  61. /* Bit 4 is ARE if the system doesn't support TrustZone, ARE_S otherwise */
  62. #define GICD_CTLR_ARE (1U << 4)
  63. #define GICD_CTLR_ARE_S (1U << 4)
  64. #define GICD_CTLR_ARE_NS (1U << 5)
  65. #define GICD_CTLR_DS (1U << 6)
  66. #define GICD_CTLR_E1NWF (1U << 7)
  67. #define GICD_CTLR_RWP (1U << 31)
  68. #define GICD_TYPER_NMI_SHIFT 9
  69. #define GICD_TYPER_LPIS_SHIFT 17
  70. /* 16 bits EventId */
  71. #define GICD_TYPER_IDBITS 0xf
  72. /*
  73. * Redistributor frame offsets from RD_base
  74. */
  75. #define GICR_SGI_OFFSET 0x10000
  76. #define GICR_VLPI_OFFSET 0x20000
  77. /*
  78. * Redistributor registers, offsets from RD_base
  79. */
  80. #define GICR_CTLR 0x0000
  81. #define GICR_IIDR 0x0004
  82. #define GICR_TYPER 0x0008
  83. #define GICR_STATUSR 0x0010
  84. #define GICR_WAKER 0x0014
  85. #define GICR_SETLPIR 0x0040
  86. #define GICR_CLRLPIR 0x0048
  87. #define GICR_PROPBASER 0x0070
  88. #define GICR_PENDBASER 0x0078
  89. #define GICR_INVLPIR 0x00A0
  90. #define GICR_INVALLR 0x00B0
  91. #define GICR_SYNCR 0x00C0
  92. #define GICR_IDREGS 0xFFD0
  93. /* SGI and PPI Redistributor registers, offsets from RD_base */
  94. #define GICR_IGROUPR0 (GICR_SGI_OFFSET + 0x0080)
  95. #define GICR_ISENABLER0 (GICR_SGI_OFFSET + 0x0100)
  96. #define GICR_ICENABLER0 (GICR_SGI_OFFSET + 0x0180)
  97. #define GICR_ISPENDR0 (GICR_SGI_OFFSET + 0x0200)
  98. #define GICR_ICPENDR0 (GICR_SGI_OFFSET + 0x0280)
  99. #define GICR_ISACTIVER0 (GICR_SGI_OFFSET + 0x0300)
  100. #define GICR_ICACTIVER0 (GICR_SGI_OFFSET + 0x0380)
  101. #define GICR_IPRIORITYR (GICR_SGI_OFFSET + 0x0400)
  102. #define GICR_ICFGR0 (GICR_SGI_OFFSET + 0x0C00)
  103. #define GICR_ICFGR1 (GICR_SGI_OFFSET + 0x0C04)
  104. #define GICR_IGRPMODR0 (GICR_SGI_OFFSET + 0x0D00)
  105. #define GICR_NSACR (GICR_SGI_OFFSET + 0x0E00)
  106. #define GICR_INMIR0 (GICR_SGI_OFFSET + 0x0F80)
  107. /* VLPI redistributor registers, offsets from VLPI_base */
  108. #define GICR_VPROPBASER (GICR_VLPI_OFFSET + 0x70)
  109. #define GICR_VPENDBASER (GICR_VLPI_OFFSET + 0x78)
  110. #define GICR_CTLR_ENABLE_LPIS (1U << 0)
  111. #define GICR_CTLR_CES (1U << 1)
  112. #define GICR_CTLR_RWP (1U << 3)
  113. #define GICR_CTLR_DPG0 (1U << 24)
  114. #define GICR_CTLR_DPG1NS (1U << 25)
  115. #define GICR_CTLR_DPG1S (1U << 26)
  116. #define GICR_CTLR_UWP (1U << 31)
  117. #define GICR_TYPER_PLPIS (1U << 0)
  118. #define GICR_TYPER_VLPIS (1U << 1)
  119. #define GICR_TYPER_DIRECTLPI (1U << 3)
  120. #define GICR_TYPER_LAST (1U << 4)
  121. #define GICR_TYPER_DPGS (1U << 5)
  122. #define GICR_TYPER_PROCNUM (0xFFFFU << 8)
  123. #define GICR_TYPER_COMMONLPIAFF (0x3 << 24)
  124. #define GICR_TYPER_AFFINITYVALUE (0xFFFFFFFFULL << 32)
  125. #define GICR_WAKER_ProcessorSleep (1U << 1)
  126. #define GICR_WAKER_ChildrenAsleep (1U << 2)
  127. FIELD(GICR_PROPBASER, IDBITS, 0, 5)
  128. FIELD(GICR_PROPBASER, INNERCACHE, 7, 3)
  129. FIELD(GICR_PROPBASER, SHAREABILITY, 10, 2)
  130. FIELD(GICR_PROPBASER, PHYADDR, 12, 40)
  131. FIELD(GICR_PROPBASER, OUTERCACHE, 56, 3)
  132. FIELD(GICR_PENDBASER, INNERCACHE, 7, 3)
  133. FIELD(GICR_PENDBASER, SHAREABILITY, 10, 2)
  134. FIELD(GICR_PENDBASER, PHYADDR, 16, 36)
  135. FIELD(GICR_PENDBASER, OUTERCACHE, 56, 3)
  136. FIELD(GICR_PENDBASER, PTZ, 62, 1)
  137. #define GICR_PROPBASER_IDBITS_THRESHOLD 0xd
  138. /* These are the GICv4 VPROPBASER and VPENDBASER layouts; v4.1 is different */
  139. FIELD(GICR_VPROPBASER, IDBITS, 0, 5)
  140. FIELD(GICR_VPROPBASER, INNERCACHE, 7, 3)
  141. FIELD(GICR_VPROPBASER, SHAREABILITY, 10, 2)
  142. FIELD(GICR_VPROPBASER, PHYADDR, 12, 40)
  143. FIELD(GICR_VPROPBASER, OUTERCACHE, 56, 3)
  144. FIELD(GICR_VPENDBASER, INNERCACHE, 7, 3)
  145. FIELD(GICR_VPENDBASER, SHAREABILITY, 10, 2)
  146. FIELD(GICR_VPENDBASER, PHYADDR, 16, 36)
  147. FIELD(GICR_VPENDBASER, OUTERCACHE, 56, 3)
  148. FIELD(GICR_VPENDBASER, DIRTY, 60, 1)
  149. FIELD(GICR_VPENDBASER, PENDINGLAST, 61, 1)
  150. FIELD(GICR_VPENDBASER, IDAI, 62, 1)
  151. FIELD(GICR_VPENDBASER, VALID, 63, 1)
  152. #define ICC_CTLR_EL1_CBPR (1U << 0)
  153. #define ICC_CTLR_EL1_EOIMODE (1U << 1)
  154. #define ICC_CTLR_EL1_PMHE (1U << 6)
  155. #define ICC_CTLR_EL1_PRIBITS_SHIFT 8
  156. #define ICC_CTLR_EL1_PRIBITS_MASK (7U << ICC_CTLR_EL1_PRIBITS_SHIFT)
  157. #define ICC_CTLR_EL1_IDBITS_SHIFT 11
  158. #define ICC_CTLR_EL1_SEIS (1U << 14)
  159. #define ICC_CTLR_EL1_A3V (1U << 15)
  160. #define ICC_PMR_PRIORITY_MASK 0xff
  161. #define ICC_BPR_BINARYPOINT_MASK 0x07
  162. #define ICC_IGRPEN_ENABLE 0x01
  163. #define ICC_CTLR_EL3_CBPR_EL1S (1U << 0)
  164. #define ICC_CTLR_EL3_CBPR_EL1NS (1U << 1)
  165. #define ICC_CTLR_EL3_EOIMODE_EL3 (1U << 2)
  166. #define ICC_CTLR_EL3_EOIMODE_EL1S (1U << 3)
  167. #define ICC_CTLR_EL3_EOIMODE_EL1NS (1U << 4)
  168. #define ICC_CTLR_EL3_RM (1U << 5)
  169. #define ICC_CTLR_EL3_PMHE (1U << 6)
  170. #define ICC_CTLR_EL3_PRIBITS_SHIFT 8
  171. #define ICC_CTLR_EL3_IDBITS_SHIFT 11
  172. #define ICC_CTLR_EL3_SEIS (1U << 14)
  173. #define ICC_CTLR_EL3_A3V (1U << 15)
  174. #define ICC_CTLR_EL3_NDS (1U << 17)
  175. #define ICC_AP1R_EL1_NMI (1ULL << 63)
  176. #define ICC_RPR_EL1_NSNMI (1ULL << 62)
  177. #define ICC_RPR_EL1_NMI (1ULL << 63)
  178. #define ICH_VMCR_EL2_VENG0_SHIFT 0
  179. #define ICH_VMCR_EL2_VENG0 (1U << ICH_VMCR_EL2_VENG0_SHIFT)
  180. #define ICH_VMCR_EL2_VENG1_SHIFT 1
  181. #define ICH_VMCR_EL2_VENG1 (1U << ICH_VMCR_EL2_VENG1_SHIFT)
  182. #define ICH_VMCR_EL2_VACKCTL (1U << 2)
  183. #define ICH_VMCR_EL2_VFIQEN (1U << 3)
  184. #define ICH_VMCR_EL2_VCBPR_SHIFT 4
  185. #define ICH_VMCR_EL2_VCBPR (1U << ICH_VMCR_EL2_VCBPR_SHIFT)
  186. #define ICH_VMCR_EL2_VEOIM_SHIFT 9
  187. #define ICH_VMCR_EL2_VEOIM (1U << ICH_VMCR_EL2_VEOIM_SHIFT)
  188. #define ICH_VMCR_EL2_VBPR1_SHIFT 18
  189. #define ICH_VMCR_EL2_VBPR1_LENGTH 3
  190. #define ICH_VMCR_EL2_VBPR1_MASK (0x7U << ICH_VMCR_EL2_VBPR1_SHIFT)
  191. #define ICH_VMCR_EL2_VBPR0_SHIFT 21
  192. #define ICH_VMCR_EL2_VBPR0_LENGTH 3
  193. #define ICH_VMCR_EL2_VBPR0_MASK (0x7U << ICH_VMCR_EL2_VBPR0_SHIFT)
  194. #define ICH_VMCR_EL2_VPMR_SHIFT 24
  195. #define ICH_VMCR_EL2_VPMR_LENGTH 8
  196. #define ICH_VMCR_EL2_VPMR_MASK (0xffU << ICH_VMCR_EL2_VPMR_SHIFT)
  197. #define ICH_HCR_EL2_EN (1U << 0)
  198. #define ICH_HCR_EL2_UIE (1U << 1)
  199. #define ICH_HCR_EL2_LRENPIE (1U << 2)
  200. #define ICH_HCR_EL2_NPIE (1U << 3)
  201. #define ICH_HCR_EL2_VGRP0EIE (1U << 4)
  202. #define ICH_HCR_EL2_VGRP0DIE (1U << 5)
  203. #define ICH_HCR_EL2_VGRP1EIE (1U << 6)
  204. #define ICH_HCR_EL2_VGRP1DIE (1U << 7)
  205. #define ICH_HCR_EL2_TC (1U << 10)
  206. #define ICH_HCR_EL2_TALL0 (1U << 11)
  207. #define ICH_HCR_EL2_TALL1 (1U << 12)
  208. #define ICH_HCR_EL2_TSEI (1U << 13)
  209. #define ICH_HCR_EL2_TDIR (1U << 14)
  210. #define ICH_HCR_EL2_EOICOUNT_SHIFT 27
  211. #define ICH_HCR_EL2_EOICOUNT_LENGTH 5
  212. #define ICH_HCR_EL2_EOICOUNT_MASK (0x1fU << ICH_HCR_EL2_EOICOUNT_SHIFT)
  213. #define ICH_LR_EL2_VINTID_SHIFT 0
  214. #define ICH_LR_EL2_VINTID_LENGTH 32
  215. #define ICH_LR_EL2_VINTID_MASK (0xffffffffULL << ICH_LR_EL2_VINTID_SHIFT)
  216. #define ICH_LR_EL2_PINTID_SHIFT 32
  217. #define ICH_LR_EL2_PINTID_LENGTH 10
  218. #define ICH_LR_EL2_PINTID_MASK (0x3ffULL << ICH_LR_EL2_PINTID_SHIFT)
  219. /* Note that EOI shares with the top bit of the pINTID field */
  220. #define ICH_LR_EL2_EOI (1ULL << 41)
  221. #define ICH_LR_EL2_PRIORITY_SHIFT 48
  222. #define ICH_LR_EL2_PRIORITY_LENGTH 8
  223. #define ICH_LR_EL2_PRIORITY_MASK (0xffULL << ICH_LR_EL2_PRIORITY_SHIFT)
  224. #define ICH_LR_EL2_NMI (1ULL << 59)
  225. #define ICH_LR_EL2_GROUP (1ULL << 60)
  226. #define ICH_LR_EL2_HW (1ULL << 61)
  227. #define ICH_LR_EL2_STATE_SHIFT 62
  228. #define ICH_LR_EL2_STATE_LENGTH 2
  229. #define ICH_LR_EL2_STATE_MASK (3ULL << ICH_LR_EL2_STATE_SHIFT)
  230. /* values for the state field: */
  231. #define ICH_LR_EL2_STATE_INVALID 0
  232. #define ICH_LR_EL2_STATE_PENDING 1
  233. #define ICH_LR_EL2_STATE_ACTIVE 2
  234. #define ICH_LR_EL2_STATE_ACTIVE_PENDING 3
  235. #define ICH_LR_EL2_STATE_PENDING_BIT (1ULL << ICH_LR_EL2_STATE_SHIFT)
  236. #define ICH_LR_EL2_STATE_ACTIVE_BIT (2ULL << ICH_LR_EL2_STATE_SHIFT)
  237. #define ICH_MISR_EL2_EOI (1U << 0)
  238. #define ICH_MISR_EL2_U (1U << 1)
  239. #define ICH_MISR_EL2_LRENP (1U << 2)
  240. #define ICH_MISR_EL2_NP (1U << 3)
  241. #define ICH_MISR_EL2_VGRP0E (1U << 4)
  242. #define ICH_MISR_EL2_VGRP0D (1U << 5)
  243. #define ICH_MISR_EL2_VGRP1E (1U << 6)
  244. #define ICH_MISR_EL2_VGRP1D (1U << 7)
  245. #define ICH_VTR_EL2_LISTREGS_SHIFT 0
  246. #define ICH_VTR_EL2_TDS (1U << 19)
  247. #define ICH_VTR_EL2_NV4 (1U << 20)
  248. #define ICH_VTR_EL2_A3V (1U << 21)
  249. #define ICH_VTR_EL2_SEIS (1U << 22)
  250. #define ICH_VTR_EL2_IDBITS_SHIFT 23
  251. #define ICH_VTR_EL2_PREBITS_SHIFT 26
  252. #define ICH_VTR_EL2_PRIBITS_SHIFT 29
  253. #define ICV_AP1R_EL1_NMI (1ULL << 63)
  254. #define ICV_RPR_EL1_NMI (1ULL << 63)
  255. /* ITS Registers */
  256. FIELD(GITS_BASER, SIZE, 0, 8)
  257. FIELD(GITS_BASER, PAGESIZE, 8, 2)
  258. FIELD(GITS_BASER, SHAREABILITY, 10, 2)
  259. FIELD(GITS_BASER, PHYADDR, 12, 36)
  260. FIELD(GITS_BASER, PHYADDRL_64K, 16, 32)
  261. FIELD(GITS_BASER, PHYADDRH_64K, 12, 4)
  262. FIELD(GITS_BASER, ENTRYSIZE, 48, 5)
  263. FIELD(GITS_BASER, OUTERCACHE, 53, 3)
  264. FIELD(GITS_BASER, TYPE, 56, 3)
  265. FIELD(GITS_BASER, INNERCACHE, 59, 3)
  266. FIELD(GITS_BASER, INDIRECT, 62, 1)
  267. FIELD(GITS_BASER, VALID, 63, 1)
  268. FIELD(GITS_CBASER, SIZE, 0, 8)
  269. FIELD(GITS_CBASER, SHAREABILITY, 10, 2)
  270. FIELD(GITS_CBASER, PHYADDR, 12, 40)
  271. FIELD(GITS_CBASER, OUTERCACHE, 53, 3)
  272. FIELD(GITS_CBASER, INNERCACHE, 59, 3)
  273. FIELD(GITS_CBASER, VALID, 63, 1)
  274. FIELD(GITS_CREADR, STALLED, 0, 1)
  275. FIELD(GITS_CREADR, OFFSET, 5, 15)
  276. FIELD(GITS_CWRITER, RETRY, 0, 1)
  277. FIELD(GITS_CWRITER, OFFSET, 5, 15)
  278. FIELD(GITS_CTLR, ENABLED, 0, 1)
  279. FIELD(GITS_CTLR, QUIESCENT, 31, 1)
  280. FIELD(GITS_TYPER, PHYSICAL, 0, 1)
  281. FIELD(GITS_TYPER, VIRTUAL, 1, 1)
  282. FIELD(GITS_TYPER, ITT_ENTRY_SIZE, 4, 4)
  283. FIELD(GITS_TYPER, IDBITS, 8, 5)
  284. FIELD(GITS_TYPER, DEVBITS, 13, 5)
  285. FIELD(GITS_TYPER, SEIS, 18, 1)
  286. FIELD(GITS_TYPER, PTA, 19, 1)
  287. FIELD(GITS_TYPER, CIDBITS, 32, 4)
  288. FIELD(GITS_TYPER, CIL, 36, 1)
  289. FIELD(GITS_TYPER, VMOVP, 37, 1)
  290. #define GITS_IDREGS 0xFFD0
  291. #define GITS_BASER_RO_MASK (R_GITS_BASER_ENTRYSIZE_MASK | \
  292. R_GITS_BASER_TYPE_MASK)
  293. #define GITS_BASER_PAGESIZE_4K 0
  294. #define GITS_BASER_PAGESIZE_16K 1
  295. #define GITS_BASER_PAGESIZE_64K 2
  296. #define GITS_BASER_TYPE_DEVICE 1ULL
  297. #define GITS_BASER_TYPE_VPE 2ULL
  298. #define GITS_BASER_TYPE_COLLECTION 4ULL
  299. #define GITS_PAGE_SIZE_4K 0x1000
  300. #define GITS_PAGE_SIZE_16K 0x4000
  301. #define GITS_PAGE_SIZE_64K 0x10000
  302. #define L1TABLE_ENTRY_SIZE 8
  303. #define LPI_CTE_ENABLED TABLE_ENTRY_VALID_MASK
  304. #define LPI_PRIORITY_MASK 0xfc
  305. #define GITS_CMDQ_ENTRY_WORDS 4
  306. #define GITS_CMDQ_ENTRY_SIZE (GITS_CMDQ_ENTRY_WORDS * sizeof(uint64_t))
  307. #define CMD_MASK 0xff
  308. /* ITS Commands */
  309. #define GITS_CMD_MOVI 0x01
  310. #define GITS_CMD_INT 0x03
  311. #define GITS_CMD_CLEAR 0x04
  312. #define GITS_CMD_SYNC 0x05
  313. #define GITS_CMD_MAPD 0x08
  314. #define GITS_CMD_MAPC 0x09
  315. #define GITS_CMD_MAPTI 0x0A
  316. #define GITS_CMD_MAPI 0x0B
  317. #define GITS_CMD_INV 0x0C
  318. #define GITS_CMD_INVALL 0x0D
  319. #define GITS_CMD_MOVALL 0x0E
  320. #define GITS_CMD_DISCARD 0x0F
  321. #define GITS_CMD_VMOVI 0x21
  322. #define GITS_CMD_VMOVP 0x22
  323. #define GITS_CMD_VSYNC 0x25
  324. #define GITS_CMD_VMAPP 0x29
  325. #define GITS_CMD_VMAPTI 0x2A
  326. #define GITS_CMD_VMAPI 0x2B
  327. #define GITS_CMD_VINVALL 0x2D
  328. /* MAPC command fields */
  329. #define ICID_LENGTH 16
  330. #define ICID_MASK ((1U << ICID_LENGTH) - 1)
  331. FIELD(MAPC, RDBASE, 16, 32)
  332. #define RDBASE_PROCNUM_LENGTH 16
  333. #define RDBASE_PROCNUM_MASK ((1ULL << RDBASE_PROCNUM_LENGTH) - 1)
  334. /* MAPD command fields */
  335. #define ITTADDR_LENGTH 44
  336. #define ITTADDR_SHIFT 8
  337. #define ITTADDR_MASK MAKE_64BIT_MASK(ITTADDR_SHIFT, ITTADDR_LENGTH)
  338. #define SIZE_MASK 0x1f
  339. /* MAPI command fields */
  340. #define EVENTID_MASK ((1ULL << 32) - 1)
  341. /* MAPTI command fields */
  342. #define pINTID_SHIFT 32
  343. #define pINTID_MASK MAKE_64BIT_MASK(32, 32)
  344. #define DEVID_SHIFT 32
  345. #define DEVID_MASK MAKE_64BIT_MASK(32, 32)
  346. #define VALID_SHIFT 63
  347. #define CMD_FIELD_VALID_MASK (1ULL << VALID_SHIFT)
  348. #define L2_TABLE_VALID_MASK CMD_FIELD_VALID_MASK
  349. #define TABLE_ENTRY_VALID_MASK (1ULL << 0)
  350. /* MOVALL command fields */
  351. FIELD(MOVALL_2, RDBASE1, 16, 36)
  352. FIELD(MOVALL_3, RDBASE2, 16, 36)
  353. /* MOVI command fields */
  354. FIELD(MOVI_0, DEVICEID, 32, 32)
  355. FIELD(MOVI_1, EVENTID, 0, 32)
  356. FIELD(MOVI_2, ICID, 0, 16)
  357. /* INV command fields */
  358. FIELD(INV_0, DEVICEID, 32, 32)
  359. FIELD(INV_1, EVENTID, 0, 32)
  360. /* VMAPI, VMAPTI command fields */
  361. FIELD(VMAPTI_0, DEVICEID, 32, 32)
  362. FIELD(VMAPTI_1, EVENTID, 0, 32)
  363. FIELD(VMAPTI_1, VPEID, 32, 16)
  364. FIELD(VMAPTI_2, VINTID, 0, 32) /* VMAPTI only */
  365. FIELD(VMAPTI_2, DOORBELL, 32, 32)
  366. /* VMAPP command fields */
  367. FIELD(VMAPP_0, ALLOC, 8, 1) /* GICv4.1 only */
  368. FIELD(VMAPP_0, PTZ, 9, 1) /* GICv4.1 only */
  369. FIELD(VMAPP_0, VCONFADDR, 16, 36) /* GICv4.1 only */
  370. FIELD(VMAPP_1, DEFAULT_DOORBELL, 0, 32) /* GICv4.1 only */
  371. FIELD(VMAPP_1, VPEID, 32, 16)
  372. FIELD(VMAPP_2, RDBASE, 16, 36)
  373. FIELD(VMAPP_2, V, 63, 1)
  374. FIELD(VMAPP_3, VPTSIZE, 0, 8) /* For GICv4.0, bits [7:6] are RES0 */
  375. FIELD(VMAPP_3, VPTADDR, 16, 36)
  376. /* VMOVP command fields */
  377. FIELD(VMOVP_0, SEQNUM, 32, 16) /* not used for GITS_TYPER.VMOVP == 1 */
  378. FIELD(VMOVP_1, ITSLIST, 0, 16) /* not used for GITS_TYPER.VMOVP == 1 */
  379. FIELD(VMOVP_1, VPEID, 32, 16)
  380. FIELD(VMOVP_2, RDBASE, 16, 36)
  381. FIELD(VMOVP_2, DB, 63, 1) /* GICv4.1 only */
  382. FIELD(VMOVP_3, DEFAULT_DOORBELL, 0, 32) /* GICv4.1 only */
  383. /* VMOVI command fields */
  384. FIELD(VMOVI_0, DEVICEID, 32, 32)
  385. FIELD(VMOVI_1, EVENTID, 0, 32)
  386. FIELD(VMOVI_1, VPEID, 32, 16)
  387. FIELD(VMOVI_2, D, 0, 1)
  388. FIELD(VMOVI_2, DOORBELL, 32, 32)
  389. /* VINVALL command fields */
  390. FIELD(VINVALL_1, VPEID, 32, 16)
  391. /*
  392. * 12 bytes Interrupt translation Table Entry size
  393. * as per Table 5.3 in GICv3 spec
  394. * ITE Lower 8 Bytes
  395. * Bits: | 63 ... 48 | 47 ... 32 | 31 ... 26 | 25 ... 2 | 1 | 0 |
  396. * Values: | vPEID | ICID | unused | IntNum | IntType | Valid |
  397. * ITE Higher 4 Bytes
  398. * Bits: | 31 ... 25 | 24 ... 0 |
  399. * Values: | unused | Doorbell |
  400. * (When Doorbell is unused, as it always is for INTYPE_PHYSICAL,
  401. * the value of that field in memory cannot be relied upon -- older
  402. * versions of QEMU did not correctly write to that memory.)
  403. */
  404. #define MIN_ITS_ITT_ENTRY_SIZE 0xC
  405. FIELD(ITE_L, VALID, 0, 1)
  406. FIELD(ITE_L, INTTYPE, 1, 1)
  407. FIELD(ITE_L, INTID, 2, 24)
  408. FIELD(ITE_L, ICID, 32, 16)
  409. FIELD(ITE_L, VPEID, 48, 16)
  410. FIELD(ITE_H, DOORBELL, 0, 24)
  411. /* Possible values for ITE_L INTTYPE */
  412. #define ITE_INTTYPE_VIRTUAL 0
  413. #define ITE_INTTYPE_PHYSICAL 1
  414. /* 16 bits EventId */
  415. #define ITS_IDBITS GICD_TYPER_IDBITS
  416. /* 16 bits DeviceId */
  417. #define ITS_DEVBITS 0xF
  418. /* 16 bits CollectionId */
  419. #define ITS_CIDBITS 0xF
  420. /*
  421. * 8 bytes Device Table Entry size
  422. * Valid = 1 bit,ITTAddr = 44 bits,Size = 5 bits
  423. */
  424. #define GITS_DTE_SIZE (0x8ULL)
  425. FIELD(DTE, VALID, 0, 1)
  426. FIELD(DTE, SIZE, 1, 5)
  427. FIELD(DTE, ITTADDR, 6, 44)
  428. /*
  429. * 8 bytes Collection Table Entry size
  430. * Valid = 1 bit, RDBase = 16 bits
  431. */
  432. #define GITS_CTE_SIZE (0x8ULL)
  433. FIELD(CTE, VALID, 0, 1)
  434. FIELD(CTE, RDBASE, 1, RDBASE_PROCNUM_LENGTH)
  435. /*
  436. * 8 bytes VPE table entry size:
  437. * Valid = 1 bit, VPTsize = 5 bits, VPTaddr = 36 bits, RDbase = 16 bits
  438. *
  439. * Field sizes for Valid and size are mandated; field sizes for RDbase
  440. * and VPT_addr are IMPDEF.
  441. */
  442. #define GITS_VPE_SIZE 0x8ULL
  443. FIELD(VTE, VALID, 0, 1)
  444. FIELD(VTE, VPTSIZE, 1, 5)
  445. FIELD(VTE, VPTADDR, 6, 36)
  446. FIELD(VTE, RDBASE, 42, RDBASE_PROCNUM_LENGTH)
  447. /* Special interrupt IDs */
  448. #define INTID_SECURE 1020
  449. #define INTID_NONSECURE 1021
  450. #define INTID_NMI 1022
  451. #define INTID_SPURIOUS 1023
  452. /* Functions internal to the emulated GICv3 */
  453. /**
  454. * gicv3_redist_size:
  455. * @s: GICv3State
  456. *
  457. * Return the size of the redistributor register frame in bytes
  458. * (which depends on what GIC version this is)
  459. */
  460. static inline int gicv3_redist_size(GICv3State *s)
  461. {
  462. /*
  463. * Redistributor size is controlled by the redistributor GICR_TYPER.VLPIS.
  464. * It's the same for every redistributor in the GIC, so arbitrarily
  465. * use the register field in the first one.
  466. */
  467. if (s->cpu[0].gicr_typer & GICR_TYPER_VLPIS) {
  468. return GICV4_REDIST_SIZE;
  469. } else {
  470. return GICV3_REDIST_SIZE;
  471. }
  472. }
  473. /**
  474. * gicv3_intid_is_special:
  475. * @intid: interrupt ID
  476. *
  477. * Return true if @intid is a special interrupt ID (1020 to
  478. * 1023 inclusive). This corresponds to the GIC spec pseudocode
  479. * IsSpecial() function.
  480. */
  481. static inline bool gicv3_intid_is_special(int intid)
  482. {
  483. return intid >= INTID_SECURE && intid <= INTID_SPURIOUS;
  484. }
  485. /**
  486. * gicv3_redist_update:
  487. * @cs: GICv3CPUState for this redistributor
  488. *
  489. * Recalculate the highest priority pending interrupt after a
  490. * change to redistributor state, and inform the CPU accordingly.
  491. */
  492. void gicv3_redist_update(GICv3CPUState *cs);
  493. /**
  494. * gicv3_update:
  495. * @s: GICv3State
  496. * @start: first interrupt whose state changed
  497. * @len: length of the range of interrupts whose state changed
  498. *
  499. * Recalculate the highest priority pending interrupts after a
  500. * change to the distributor state affecting @len interrupts
  501. * starting at @start, and inform the CPUs accordingly.
  502. */
  503. void gicv3_update(GICv3State *s, int start, int len);
  504. /**
  505. * gicv3_full_update_noirqset:
  506. * @s: GICv3State
  507. *
  508. * Recalculate the cached information about highest priority
  509. * pending interrupts, but don't inform the CPUs. This should be
  510. * called after an incoming migration has loaded new state.
  511. */
  512. void gicv3_full_update_noirqset(GICv3State *s);
  513. /**
  514. * gicv3_full_update:
  515. * @s: GICv3State
  516. *
  517. * Recalculate the highest priority pending interrupts after
  518. * a change that could affect the status of all interrupts,
  519. * and inform the CPUs accordingly.
  520. */
  521. void gicv3_full_update(GICv3State *s);
  522. MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data,
  523. unsigned size, MemTxAttrs attrs);
  524. MemTxResult gicv3_dist_write(void *opaque, hwaddr addr, uint64_t data,
  525. unsigned size, MemTxAttrs attrs);
  526. MemTxResult gicv3_redist_read(void *opaque, hwaddr offset, uint64_t *data,
  527. unsigned size, MemTxAttrs attrs);
  528. MemTxResult gicv3_redist_write(void *opaque, hwaddr offset, uint64_t data,
  529. unsigned size, MemTxAttrs attrs);
  530. void gicv3_dist_set_irq(GICv3State *s, int irq, int level);
  531. void gicv3_redist_set_irq(GICv3CPUState *cs, int irq, int level);
  532. void gicv3_redist_process_lpi(GICv3CPUState *cs, int irq, int level);
  533. /**
  534. * gicv3_redist_process_vlpi:
  535. * @cs: GICv3CPUState
  536. * @irq: (virtual) interrupt number
  537. * @vptaddr: (guest) address of VLPI table
  538. * @doorbell: doorbell (physical) interrupt number (1023 for "no doorbell")
  539. * @level: level to set @irq to
  540. *
  541. * Process a virtual LPI being directly injected by the ITS. This function
  542. * will update the VLPI table specified by @vptaddr and @vptsize. If the
  543. * vCPU corresponding to that VLPI table is currently running on
  544. * the CPU associated with this redistributor, directly inject the VLPI
  545. * @irq. If the vCPU is not running on this CPU, raise the doorbell
  546. * interrupt instead.
  547. */
  548. void gicv3_redist_process_vlpi(GICv3CPUState *cs, int irq, uint64_t vptaddr,
  549. int doorbell, int level);
  550. /**
  551. * gicv3_redist_vlpi_pending:
  552. * @cs: GICv3CPUState
  553. * @irq: (virtual) interrupt number
  554. * @level: level to set @irq to
  555. *
  556. * Set/clear the pending status of a virtual LPI in the vLPI table
  557. * that this redistributor is currently using. (The difference between
  558. * this and gicv3_redist_process_vlpi() is that this is called from
  559. * the cpuif and does not need to do the not-running-on-this-vcpu checks.)
  560. */
  561. void gicv3_redist_vlpi_pending(GICv3CPUState *cs, int irq, int level);
  562. void gicv3_redist_lpi_pending(GICv3CPUState *cs, int irq, int level);
  563. /**
  564. * gicv3_redist_update_lpi:
  565. * @cs: GICv3CPUState
  566. *
  567. * Scan the LPI pending table and recalculate the highest priority
  568. * pending LPI and also the overall highest priority pending interrupt.
  569. */
  570. void gicv3_redist_update_lpi(GICv3CPUState *cs);
  571. /**
  572. * gicv3_redist_update_lpi_only:
  573. * @cs: GICv3CPUState
  574. *
  575. * Scan the LPI pending table and recalculate cs->hpplpi only,
  576. * without calling gicv3_redist_update() to recalculate the overall
  577. * highest priority pending interrupt. This should be called after
  578. * an incoming migration has loaded new state.
  579. */
  580. void gicv3_redist_update_lpi_only(GICv3CPUState *cs);
  581. /**
  582. * gicv3_redist_inv_lpi:
  583. * @cs: GICv3CPUState
  584. * @irq: LPI to invalidate cached information for
  585. *
  586. * Forget or update any cached information associated with this LPI.
  587. */
  588. void gicv3_redist_inv_lpi(GICv3CPUState *cs, int irq);
  589. /**
  590. * gicv3_redist_inv_vlpi:
  591. * @cs: GICv3CPUState
  592. * @irq: vLPI to invalidate cached information for
  593. * @vptaddr: (guest) address of vLPI table
  594. *
  595. * Forget or update any cached information associated with this vLPI.
  596. */
  597. void gicv3_redist_inv_vlpi(GICv3CPUState *cs, int irq, uint64_t vptaddr);
  598. /**
  599. * gicv3_redist_mov_lpi:
  600. * @src: source redistributor
  601. * @dest: destination redistributor
  602. * @irq: LPI to update
  603. *
  604. * Move the pending state of the specified LPI from @src to @dest,
  605. * as required by the ITS MOVI command.
  606. */
  607. void gicv3_redist_mov_lpi(GICv3CPUState *src, GICv3CPUState *dest, int irq);
  608. /**
  609. * gicv3_redist_movall_lpis:
  610. * @src: source redistributor
  611. * @dest: destination redistributor
  612. *
  613. * Scan the LPI pending table for @src, and for each pending LPI there
  614. * mark it as not-pending for @src and pending for @dest, as required
  615. * by the ITS MOVALL command.
  616. */
  617. void gicv3_redist_movall_lpis(GICv3CPUState *src, GICv3CPUState *dest);
  618. /**
  619. * gicv3_redist_mov_vlpi:
  620. * @src: source redistributor
  621. * @src_vptaddr: (guest) address of source VLPI table
  622. * @dest: destination redistributor
  623. * @dest_vptaddr: (guest) address of destination VLPI table
  624. * @irq: VLPI to update
  625. * @doorbell: doorbell for destination (1023 for "no doorbell")
  626. *
  627. * Move the pending state of the specified VLPI from @src to @dest,
  628. * as required by the ITS VMOVI command.
  629. */
  630. void gicv3_redist_mov_vlpi(GICv3CPUState *src, uint64_t src_vptaddr,
  631. GICv3CPUState *dest, uint64_t dest_vptaddr,
  632. int irq, int doorbell);
  633. /**
  634. * gicv3_redist_vinvall:
  635. * @cs: GICv3CPUState
  636. * @vptaddr: address of VLPI pending table
  637. *
  638. * On redistributor @cs, invalidate all cached information associated
  639. * with the vCPU defined by @vptaddr.
  640. */
  641. void gicv3_redist_vinvall(GICv3CPUState *cs, uint64_t vptaddr);
  642. void gicv3_redist_send_sgi(GICv3CPUState *cs, int grp, int irq, bool ns);
  643. void gicv3_init_cpuif(GICv3State *s);
  644. /**
  645. * gicv3_cpuif_update:
  646. * @cs: GICv3CPUState for the CPU to update
  647. *
  648. * Recalculate whether to assert the IRQ or FIQ lines after a change
  649. * to the current highest priority pending interrupt, the CPU's
  650. * current running priority or the CPU's current exception level or
  651. * security state.
  652. */
  653. void gicv3_cpuif_update(GICv3CPUState *cs);
  654. /*
  655. * gicv3_cpuif_virt_irq_fiq_update:
  656. * @cs: GICv3CPUState for the CPU to update
  657. *
  658. * Recalculate whether to assert the virtual IRQ or FIQ lines after
  659. * a change to the current highest priority pending virtual interrupt.
  660. * Note that this does not recalculate and change the maintenance
  661. * interrupt status (for that, see gicv3_cpuif_virt_update()).
  662. */
  663. void gicv3_cpuif_virt_irq_fiq_update(GICv3CPUState *cs);
  664. static inline uint32_t gicv3_iidr(void)
  665. {
  666. /* Return the Implementer Identification Register value
  667. * for the emulated GICv3, as reported in GICD_IIDR and GICR_IIDR.
  668. *
  669. * We claim to be an ARM r0p0 with a zero ProductID.
  670. * This is the same as an r0p0 GIC-500.
  671. */
  672. return 0x43b;
  673. }
  674. /* CoreSight PIDR0 values for ARM GICv3 implementations */
  675. #define GICV3_PIDR0_DIST 0x92
  676. #define GICV3_PIDR0_REDIST 0x93
  677. #define GICV3_PIDR0_ITS 0x94
  678. static inline uint32_t gicv3_idreg(GICv3State *s, int regoffset, uint8_t pidr0)
  679. {
  680. /* Return the value of the CoreSight ID register at the specified
  681. * offset from the first ID register (as found in the distributor
  682. * and redistributor register banks).
  683. * These values indicate an ARM implementation of a GICv3 or v4.
  684. */
  685. static const uint8_t gicd_ids[] = {
  686. 0x44, 0x00, 0x00, 0x00, 0x92, 0xB4, 0x0B, 0x00, 0x0D, 0xF0, 0x05, 0xB1
  687. };
  688. uint32_t id;
  689. regoffset /= 4;
  690. if (regoffset == 4) {
  691. return pidr0;
  692. }
  693. id = gicd_ids[regoffset];
  694. if (regoffset == 6) {
  695. /* PIDR2 bits [7:4] are the GIC architecture revision */
  696. id |= s->revision << 4;
  697. }
  698. return id;
  699. }
  700. /**
  701. * gicv3_irq_group:
  702. *
  703. * Return the group which this interrupt is configured as (GICV3_G0,
  704. * GICV3_G1 or GICV3_G1NS).
  705. */
  706. static inline int gicv3_irq_group(GICv3State *s, GICv3CPUState *cs, int irq)
  707. {
  708. bool grpbit, grpmodbit;
  709. if (irq < GIC_INTERNAL) {
  710. grpbit = extract32(cs->gicr_igroupr0, irq, 1);
  711. grpmodbit = extract32(cs->gicr_igrpmodr0, irq, 1);
  712. } else {
  713. grpbit = gicv3_gicd_group_test(s, irq);
  714. grpmodbit = gicv3_gicd_grpmod_test(s, irq);
  715. }
  716. if (grpbit) {
  717. return GICV3_G1NS;
  718. }
  719. if (s->gicd_ctlr & GICD_CTLR_DS) {
  720. return GICV3_G0;
  721. }
  722. return grpmodbit ? GICV3_G1 : GICV3_G0;
  723. }
  724. /**
  725. * gicv3_redist_affid:
  726. *
  727. * Return the 32-bit affinity ID of the CPU connected to this redistributor
  728. */
  729. static inline uint32_t gicv3_redist_affid(GICv3CPUState *cs)
  730. {
  731. return cs->gicr_typer >> 32;
  732. }
  733. /**
  734. * gicv3_cache_target_cpustate:
  735. *
  736. * Update the cached CPU state corresponding to the target for this interrupt
  737. * (which is kept in s->gicd_irouter_target[]).
  738. */
  739. static inline void gicv3_cache_target_cpustate(GICv3State *s, int irq)
  740. {
  741. GICv3CPUState *cs = NULL;
  742. int i;
  743. uint32_t tgtaff = extract64(s->gicd_irouter[irq], 0, 24) |
  744. extract64(s->gicd_irouter[irq], 32, 8) << 24;
  745. for (i = 0; i < s->num_cpu; i++) {
  746. if (s->cpu[i].gicr_typer >> 32 == tgtaff) {
  747. cs = &s->cpu[i];
  748. break;
  749. }
  750. }
  751. s->gicd_irouter_target[irq] = cs;
  752. }
  753. /**
  754. * gicv3_cache_all_target_cpustates:
  755. *
  756. * Populate the entire cache of CPU state pointers for interrupt targets
  757. * (eg after inbound migration or CPU reset)
  758. */
  759. static inline void gicv3_cache_all_target_cpustates(GICv3State *s)
  760. {
  761. int irq;
  762. for (irq = GIC_INTERNAL; irq < GICV3_MAXIRQ; irq++) {
  763. gicv3_cache_target_cpustate(s, irq);
  764. }
  765. }
  766. void gicv3_set_gicv3state(CPUState *cpu, GICv3CPUState *s);
  767. #endif /* QEMU_ARM_GICV3_INTERNAL_H */