gicv3_internal.h 28 KB

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