xive.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236
  1. /*
  2. * QEMU PowerPC XIVE interrupt controller model
  3. *
  4. * Copyright (c) 2017-2018, IBM Corporation.
  5. *
  6. * This code is licensed under the GPL version 2 or later. See the
  7. * COPYING file in the top-level directory.
  8. */
  9. #include "qemu/osdep.h"
  10. #include "qemu/log.h"
  11. #include "qemu/module.h"
  12. #include "qapi/error.h"
  13. #include "target/ppc/cpu.h"
  14. #include "system/cpus.h"
  15. #include "system/dma.h"
  16. #include "system/reset.h"
  17. #include "hw/qdev-properties.h"
  18. #include "migration/vmstate.h"
  19. #include "hw/irq.h"
  20. #include "hw/ppc/xive.h"
  21. #include "hw/ppc/xive2.h"
  22. #include "hw/ppc/xive_regs.h"
  23. #include "trace.h"
  24. /*
  25. * XIVE Thread Interrupt Management context
  26. */
  27. /*
  28. * Convert an Interrupt Pending Buffer (IPB) register to a Pending
  29. * Interrupt Priority Register (PIPR), which contains the priority of
  30. * the most favored pending notification.
  31. */
  32. static uint8_t ipb_to_pipr(uint8_t ibp)
  33. {
  34. return ibp ? clz32((uint32_t)ibp << 24) : 0xff;
  35. }
  36. static uint8_t exception_mask(uint8_t ring)
  37. {
  38. switch (ring) {
  39. case TM_QW1_OS:
  40. return TM_QW1_NSR_EO;
  41. case TM_QW3_HV_PHYS:
  42. return TM_QW3_NSR_HE;
  43. default:
  44. g_assert_not_reached();
  45. }
  46. }
  47. static qemu_irq xive_tctx_output(XiveTCTX *tctx, uint8_t ring)
  48. {
  49. switch (ring) {
  50. case TM_QW0_USER:
  51. return 0; /* Not supported */
  52. case TM_QW1_OS:
  53. return tctx->os_output;
  54. case TM_QW2_HV_POOL:
  55. case TM_QW3_HV_PHYS:
  56. return tctx->hv_output;
  57. default:
  58. return 0;
  59. }
  60. }
  61. static uint64_t xive_tctx_accept(XiveTCTX *tctx, uint8_t ring)
  62. {
  63. uint8_t *regs = &tctx->regs[ring];
  64. uint8_t nsr = regs[TM_NSR];
  65. uint8_t mask = exception_mask(ring);
  66. qemu_irq_lower(xive_tctx_output(tctx, ring));
  67. if (regs[TM_NSR] & mask) {
  68. uint8_t cppr = regs[TM_PIPR];
  69. uint8_t alt_ring;
  70. uint8_t *alt_regs;
  71. /* POOL interrupt uses IPB in QW2, POOL ring */
  72. if ((ring == TM_QW3_HV_PHYS) && (nsr & (TM_QW3_NSR_HE_POOL << 6))) {
  73. alt_ring = TM_QW2_HV_POOL;
  74. } else {
  75. alt_ring = ring;
  76. }
  77. alt_regs = &tctx->regs[alt_ring];
  78. regs[TM_CPPR] = cppr;
  79. /* Reset the pending buffer bit */
  80. alt_regs[TM_IPB] &= ~xive_priority_to_ipb(cppr);
  81. /* Drop Exception bit */
  82. regs[TM_NSR] &= ~mask;
  83. trace_xive_tctx_accept(tctx->cs->cpu_index, alt_ring,
  84. alt_regs[TM_IPB], regs[TM_PIPR],
  85. regs[TM_CPPR], regs[TM_NSR]);
  86. }
  87. return ((uint64_t)nsr << 8) | regs[TM_CPPR];
  88. }
  89. static void xive_tctx_notify(XiveTCTX *tctx, uint8_t ring)
  90. {
  91. /* HV_POOL ring uses HV_PHYS NSR, CPPR and PIPR registers */
  92. uint8_t alt_ring = (ring == TM_QW2_HV_POOL) ? TM_QW3_HV_PHYS : ring;
  93. uint8_t *alt_regs = &tctx->regs[alt_ring];
  94. uint8_t *regs = &tctx->regs[ring];
  95. if (alt_regs[TM_PIPR] < alt_regs[TM_CPPR]) {
  96. switch (ring) {
  97. case TM_QW1_OS:
  98. regs[TM_NSR] |= TM_QW1_NSR_EO;
  99. break;
  100. case TM_QW2_HV_POOL:
  101. alt_regs[TM_NSR] = (TM_QW3_NSR_HE_POOL << 6);
  102. break;
  103. case TM_QW3_HV_PHYS:
  104. regs[TM_NSR] |= (TM_QW3_NSR_HE_PHYS << 6);
  105. break;
  106. default:
  107. g_assert_not_reached();
  108. }
  109. trace_xive_tctx_notify(tctx->cs->cpu_index, ring,
  110. regs[TM_IPB], alt_regs[TM_PIPR],
  111. alt_regs[TM_CPPR], alt_regs[TM_NSR]);
  112. qemu_irq_raise(xive_tctx_output(tctx, ring));
  113. }
  114. }
  115. void xive_tctx_reset_signal(XiveTCTX *tctx, uint8_t ring)
  116. {
  117. /*
  118. * Lower the External interrupt. Used when pulling a context. It is
  119. * necessary to avoid catching it in the higher privilege context. It
  120. * should be raised again when re-pushing the lower privilege context.
  121. */
  122. qemu_irq_lower(xive_tctx_output(tctx, ring));
  123. }
  124. static void xive_tctx_set_cppr(XiveTCTX *tctx, uint8_t ring, uint8_t cppr)
  125. {
  126. uint8_t *regs = &tctx->regs[ring];
  127. uint8_t pipr_min;
  128. uint8_t ring_min;
  129. trace_xive_tctx_set_cppr(tctx->cs->cpu_index, ring,
  130. regs[TM_IPB], regs[TM_PIPR],
  131. cppr, regs[TM_NSR]);
  132. if (cppr > XIVE_PRIORITY_MAX) {
  133. cppr = 0xff;
  134. }
  135. tctx->regs[ring + TM_CPPR] = cppr;
  136. /*
  137. * Recompute the PIPR based on local pending interrupts. The PHYS
  138. * ring must take the minimum of both the PHYS and POOL PIPR values.
  139. */
  140. pipr_min = ipb_to_pipr(regs[TM_IPB]);
  141. ring_min = ring;
  142. /* PHYS updates also depend on POOL values */
  143. if (ring == TM_QW3_HV_PHYS) {
  144. uint8_t *pool_regs = &tctx->regs[TM_QW2_HV_POOL];
  145. /* POOL values only matter if POOL ctx is valid */
  146. if (pool_regs[TM_WORD2] & 0x80) {
  147. uint8_t pool_pipr = ipb_to_pipr(pool_regs[TM_IPB]);
  148. /*
  149. * Determine highest priority interrupt and
  150. * remember which ring has it.
  151. */
  152. if (pool_pipr < pipr_min) {
  153. pipr_min = pool_pipr;
  154. ring_min = TM_QW2_HV_POOL;
  155. }
  156. }
  157. }
  158. regs[TM_PIPR] = pipr_min;
  159. /* CPPR has changed, check if we need to raise a pending exception */
  160. xive_tctx_notify(tctx, ring_min);
  161. }
  162. void xive_tctx_ipb_update(XiveTCTX *tctx, uint8_t ring, uint8_t ipb)
  163. {
  164. uint8_t *regs = &tctx->regs[ring];
  165. regs[TM_IPB] |= ipb;
  166. regs[TM_PIPR] = ipb_to_pipr(regs[TM_IPB]);
  167. xive_tctx_notify(tctx, ring);
  168. }
  169. /*
  170. * XIVE Thread Interrupt Management Area (TIMA)
  171. */
  172. static void xive_tm_set_hv_cppr(XivePresenter *xptr, XiveTCTX *tctx,
  173. hwaddr offset, uint64_t value, unsigned size)
  174. {
  175. xive_tctx_set_cppr(tctx, TM_QW3_HV_PHYS, value & 0xff);
  176. }
  177. static uint64_t xive_tm_ack_hv_reg(XivePresenter *xptr, XiveTCTX *tctx,
  178. hwaddr offset, unsigned size)
  179. {
  180. return xive_tctx_accept(tctx, TM_QW3_HV_PHYS);
  181. }
  182. static uint64_t xive_tm_pull_pool_ctx(XivePresenter *xptr, XiveTCTX *tctx,
  183. hwaddr offset, unsigned size)
  184. {
  185. uint32_t qw2w2_prev = xive_tctx_word2(&tctx->regs[TM_QW2_HV_POOL]);
  186. uint32_t qw2w2;
  187. qw2w2 = xive_set_field32(TM_QW2W2_VP, qw2w2_prev, 0);
  188. memcpy(&tctx->regs[TM_QW2_HV_POOL + TM_WORD2], &qw2w2, 4);
  189. return qw2w2;
  190. }
  191. static uint64_t xive_tm_pull_phys_ctx(XivePresenter *xptr, XiveTCTX *tctx,
  192. hwaddr offset, unsigned size)
  193. {
  194. uint8_t qw3b8_prev = tctx->regs[TM_QW3_HV_PHYS + TM_WORD2];
  195. uint8_t qw3b8;
  196. qw3b8 = qw3b8_prev & ~TM_QW3B8_VT;
  197. tctx->regs[TM_QW3_HV_PHYS + TM_WORD2] = qw3b8;
  198. return qw3b8;
  199. }
  200. static void xive_tm_vt_push(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
  201. uint64_t value, unsigned size)
  202. {
  203. tctx->regs[TM_QW3_HV_PHYS + TM_WORD2] = value & 0xff;
  204. }
  205. static uint64_t xive_tm_vt_poll(XivePresenter *xptr, XiveTCTX *tctx,
  206. hwaddr offset, unsigned size)
  207. {
  208. return tctx->regs[TM_QW3_HV_PHYS + TM_WORD2] & 0xff;
  209. }
  210. /*
  211. * Define an access map for each page of the TIMA that we will use in
  212. * the memory region ops to filter values when doing loads and stores
  213. * of raw registers values
  214. *
  215. * Registers accessibility bits :
  216. *
  217. * 0x0 - no access
  218. * 0x1 - write only
  219. * 0x2 - read only
  220. * 0x3 - read/write
  221. */
  222. static const uint8_t xive_tm_hw_view[] = {
  223. 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-0 User */
  224. 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-1 OS */
  225. 0, 0, 3, 3, 0, 3, 3, 0, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-2 POOL */
  226. 3, 3, 3, 3, 0, 3, 0, 2, 3, 0, 0, 3, 3, 3, 3, 0, /* QW-3 PHYS */
  227. };
  228. static const uint8_t xive_tm_hv_view[] = {
  229. 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-0 User */
  230. 3, 3, 3, 3, 3, 3, 0, 2, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-1 OS */
  231. 0, 0, 3, 3, 0, 3, 3, 0, 0, 3, 3, 3, 0, 0, 0, 0, /* QW-2 POOL */
  232. 3, 3, 3, 3, 0, 3, 0, 2, 3, 0, 0, 3, 0, 0, 0, 0, /* QW-3 PHYS */
  233. };
  234. static const uint8_t xive_tm_os_view[] = {
  235. 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 0, /* QW-0 User */
  236. 2, 3, 2, 2, 2, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-1 OS */
  237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-2 POOL */
  238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-3 PHYS */
  239. };
  240. static const uint8_t xive_tm_user_view[] = {
  241. 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-0 User */
  242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-1 OS */
  243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-2 POOL */
  244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* QW-3 PHYS */
  245. };
  246. /*
  247. * Overall TIMA access map for the thread interrupt management context
  248. * registers
  249. */
  250. static const uint8_t *xive_tm_views[] = {
  251. [XIVE_TM_HW_PAGE] = xive_tm_hw_view,
  252. [XIVE_TM_HV_PAGE] = xive_tm_hv_view,
  253. [XIVE_TM_OS_PAGE] = xive_tm_os_view,
  254. [XIVE_TM_USER_PAGE] = xive_tm_user_view,
  255. };
  256. /*
  257. * Computes a register access mask for a given offset in the TIMA
  258. */
  259. static uint64_t xive_tm_mask(hwaddr offset, unsigned size, bool write)
  260. {
  261. uint8_t page_offset = (offset >> TM_SHIFT) & 0x3;
  262. uint8_t reg_offset = offset & TM_REG_OFFSET;
  263. uint8_t reg_mask = write ? 0x1 : 0x2;
  264. uint64_t mask = 0x0;
  265. int i;
  266. for (i = 0; i < size; i++) {
  267. if (xive_tm_views[page_offset][reg_offset + i] & reg_mask) {
  268. mask |= (uint64_t) 0xff << (8 * (size - i - 1));
  269. }
  270. }
  271. return mask;
  272. }
  273. static void xive_tm_raw_write(XiveTCTX *tctx, hwaddr offset, uint64_t value,
  274. unsigned size)
  275. {
  276. uint8_t ring_offset = offset & TM_RING_OFFSET;
  277. uint8_t reg_offset = offset & TM_REG_OFFSET;
  278. uint64_t mask = xive_tm_mask(offset, size, true);
  279. int i;
  280. /*
  281. * Only 4 or 8 bytes stores are allowed and the User ring is
  282. * excluded
  283. */
  284. if (size < 4 || !mask || ring_offset == TM_QW0_USER) {
  285. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid write access at TIMA @%"
  286. HWADDR_PRIx"\n", offset);
  287. return;
  288. }
  289. /*
  290. * Use the register offset for the raw values and filter out
  291. * reserved values
  292. */
  293. for (i = 0; i < size; i++) {
  294. uint8_t byte_mask = (mask >> (8 * (size - i - 1)));
  295. if (byte_mask) {
  296. tctx->regs[reg_offset + i] = (value >> (8 * (size - i - 1))) &
  297. byte_mask;
  298. }
  299. }
  300. }
  301. static uint64_t xive_tm_raw_read(XiveTCTX *tctx, hwaddr offset, unsigned size)
  302. {
  303. uint8_t ring_offset = offset & TM_RING_OFFSET;
  304. uint8_t reg_offset = offset & TM_REG_OFFSET;
  305. uint64_t mask = xive_tm_mask(offset, size, false);
  306. uint64_t ret;
  307. int i;
  308. /*
  309. * Only 4 or 8 bytes loads are allowed and the User ring is
  310. * excluded
  311. */
  312. if (size < 4 || !mask || ring_offset == TM_QW0_USER) {
  313. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid read access at TIMA @%"
  314. HWADDR_PRIx"\n", offset);
  315. return -1;
  316. }
  317. /* Use the register offset for the raw values */
  318. ret = 0;
  319. for (i = 0; i < size; i++) {
  320. ret |= (uint64_t) tctx->regs[reg_offset + i] << (8 * (size - i - 1));
  321. }
  322. /* filter out reserved values */
  323. return ret & mask;
  324. }
  325. /*
  326. * The TM context is mapped twice within each page. Stores and loads
  327. * to the first mapping below 2K write and read the specified values
  328. * without modification. The second mapping above 2K performs specific
  329. * state changes (side effects) in addition to setting/returning the
  330. * interrupt management area context of the processor thread.
  331. */
  332. static uint64_t xive_tm_ack_os_reg(XivePresenter *xptr, XiveTCTX *tctx,
  333. hwaddr offset, unsigned size)
  334. {
  335. return xive_tctx_accept(tctx, TM_QW1_OS);
  336. }
  337. static void xive_tm_set_os_cppr(XivePresenter *xptr, XiveTCTX *tctx,
  338. hwaddr offset, uint64_t value, unsigned size)
  339. {
  340. xive_tctx_set_cppr(tctx, TM_QW1_OS, value & 0xff);
  341. }
  342. static void xive_tctx_set_lgs(XiveTCTX *tctx, uint8_t ring, uint8_t lgs)
  343. {
  344. uint8_t *regs = &tctx->regs[ring];
  345. regs[TM_LGS] = lgs;
  346. }
  347. static void xive_tm_set_os_lgs(XivePresenter *xptr, XiveTCTX *tctx,
  348. hwaddr offset, uint64_t value, unsigned size)
  349. {
  350. xive_tctx_set_lgs(tctx, TM_QW1_OS, value & 0xff);
  351. }
  352. /*
  353. * Adjust the IPB to allow a CPU to process event queues of other
  354. * priorities during one physical interrupt cycle.
  355. */
  356. static void xive_tm_set_os_pending(XivePresenter *xptr, XiveTCTX *tctx,
  357. hwaddr offset, uint64_t value, unsigned size)
  358. {
  359. xive_tctx_ipb_update(tctx, TM_QW1_OS, xive_priority_to_ipb(value & 0xff));
  360. }
  361. static void xive_os_cam_decode(uint32_t cam, uint8_t *nvt_blk,
  362. uint32_t *nvt_idx, bool *vo)
  363. {
  364. if (nvt_blk) {
  365. *nvt_blk = xive_nvt_blk(cam);
  366. }
  367. if (nvt_idx) {
  368. *nvt_idx = xive_nvt_idx(cam);
  369. }
  370. if (vo) {
  371. *vo = !!(cam & TM_QW1W2_VO);
  372. }
  373. }
  374. static uint32_t xive_tctx_get_os_cam(XiveTCTX *tctx, uint8_t *nvt_blk,
  375. uint32_t *nvt_idx, bool *vo)
  376. {
  377. uint32_t qw1w2 = xive_tctx_word2(&tctx->regs[TM_QW1_OS]);
  378. uint32_t cam = be32_to_cpu(qw1w2);
  379. xive_os_cam_decode(cam, nvt_blk, nvt_idx, vo);
  380. return qw1w2;
  381. }
  382. static void xive_tctx_set_os_cam(XiveTCTX *tctx, uint32_t qw1w2)
  383. {
  384. memcpy(&tctx->regs[TM_QW1_OS + TM_WORD2], &qw1w2, 4);
  385. }
  386. static uint64_t xive_tm_pull_os_ctx(XivePresenter *xptr, XiveTCTX *tctx,
  387. hwaddr offset, unsigned size)
  388. {
  389. uint32_t qw1w2;
  390. uint32_t qw1w2_new;
  391. uint8_t nvt_blk;
  392. uint32_t nvt_idx;
  393. bool vo;
  394. qw1w2 = xive_tctx_get_os_cam(tctx, &nvt_blk, &nvt_idx, &vo);
  395. if (!vo) {
  396. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: pulling invalid NVT %x/%x !?\n",
  397. nvt_blk, nvt_idx);
  398. }
  399. /* Invalidate CAM line */
  400. qw1w2_new = xive_set_field32(TM_QW1W2_VO, qw1w2, 0);
  401. xive_tctx_set_os_cam(tctx, qw1w2_new);
  402. xive_tctx_reset_signal(tctx, TM_QW1_OS);
  403. return qw1w2;
  404. }
  405. static void xive_tctx_need_resend(XiveRouter *xrtr, XiveTCTX *tctx,
  406. uint8_t nvt_blk, uint32_t nvt_idx)
  407. {
  408. XiveNVT nvt;
  409. uint8_t ipb;
  410. /*
  411. * Grab the associated NVT to pull the pending bits, and merge
  412. * them with the IPB of the thread interrupt context registers
  413. */
  414. if (xive_router_get_nvt(xrtr, nvt_blk, nvt_idx, &nvt)) {
  415. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid NVT %x/%x\n",
  416. nvt_blk, nvt_idx);
  417. return;
  418. }
  419. ipb = xive_get_field32(NVT_W4_IPB, nvt.w4);
  420. if (ipb) {
  421. /* Reset the NVT value */
  422. nvt.w4 = xive_set_field32(NVT_W4_IPB, nvt.w4, 0);
  423. xive_router_write_nvt(xrtr, nvt_blk, nvt_idx, &nvt, 4);
  424. }
  425. /*
  426. * Always call xive_tctx_ipb_update(). Even if there were no
  427. * escalation triggered, there could be a pending interrupt which
  428. * was saved when the context was pulled and that we need to take
  429. * into account by recalculating the PIPR (which is not
  430. * saved/restored).
  431. * It will also raise the External interrupt signal if needed.
  432. */
  433. xive_tctx_ipb_update(tctx, TM_QW1_OS, ipb);
  434. }
  435. /*
  436. * Updating the OS CAM line can trigger a resend of interrupt
  437. */
  438. static void xive_tm_push_os_ctx(XivePresenter *xptr, XiveTCTX *tctx,
  439. hwaddr offset, uint64_t value, unsigned size)
  440. {
  441. uint32_t cam = value;
  442. uint32_t qw1w2 = cpu_to_be32(cam);
  443. uint8_t nvt_blk;
  444. uint32_t nvt_idx;
  445. bool vo;
  446. xive_os_cam_decode(cam, &nvt_blk, &nvt_idx, &vo);
  447. /* First update the registers */
  448. xive_tctx_set_os_cam(tctx, qw1w2);
  449. /* Check the interrupt pending bits */
  450. if (vo) {
  451. xive_tctx_need_resend(XIVE_ROUTER(xptr), tctx, nvt_blk, nvt_idx);
  452. }
  453. }
  454. static uint32_t xive_presenter_get_config(XivePresenter *xptr)
  455. {
  456. XivePresenterClass *xpc = XIVE_PRESENTER_GET_CLASS(xptr);
  457. return xpc->get_config(xptr);
  458. }
  459. /*
  460. * Define a mapping of "special" operations depending on the TIMA page
  461. * offset and the size of the operation.
  462. */
  463. typedef struct XiveTmOp {
  464. uint8_t page_offset;
  465. uint32_t op_offset;
  466. unsigned size;
  467. void (*write_handler)(XivePresenter *xptr, XiveTCTX *tctx,
  468. hwaddr offset,
  469. uint64_t value, unsigned size);
  470. uint64_t (*read_handler)(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
  471. unsigned size);
  472. } XiveTmOp;
  473. static const XiveTmOp xive_tm_operations[] = {
  474. /*
  475. * MMIOs below 2K : raw values and special operations without side
  476. * effects
  477. */
  478. { XIVE_TM_OS_PAGE, TM_QW1_OS + TM_CPPR, 1, xive_tm_set_os_cppr,
  479. NULL },
  480. { XIVE_TM_HV_PAGE, TM_QW1_OS + TM_WORD2, 4, xive_tm_push_os_ctx,
  481. NULL },
  482. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_CPPR, 1, xive_tm_set_hv_cppr,
  483. NULL },
  484. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_WORD2, 1, xive_tm_vt_push,
  485. NULL },
  486. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_WORD2, 1, NULL,
  487. xive_tm_vt_poll },
  488. /* MMIOs above 2K : special operations with side effects */
  489. { XIVE_TM_OS_PAGE, TM_SPC_ACK_OS_REG, 2, NULL,
  490. xive_tm_ack_os_reg },
  491. { XIVE_TM_OS_PAGE, TM_SPC_SET_OS_PENDING, 1, xive_tm_set_os_pending,
  492. NULL },
  493. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX, 4, NULL,
  494. xive_tm_pull_os_ctx },
  495. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX, 8, NULL,
  496. xive_tm_pull_os_ctx },
  497. { XIVE_TM_HV_PAGE, TM_SPC_ACK_HV_REG, 2, NULL,
  498. xive_tm_ack_hv_reg },
  499. { XIVE_TM_HV_PAGE, TM_SPC_PULL_POOL_CTX, 4, NULL,
  500. xive_tm_pull_pool_ctx },
  501. { XIVE_TM_HV_PAGE, TM_SPC_PULL_POOL_CTX, 8, NULL,
  502. xive_tm_pull_pool_ctx },
  503. { XIVE_TM_HV_PAGE, TM_SPC_PULL_PHYS_CTX, 1, NULL,
  504. xive_tm_pull_phys_ctx },
  505. };
  506. static const XiveTmOp xive2_tm_operations[] = {
  507. /*
  508. * MMIOs below 2K : raw values and special operations without side
  509. * effects
  510. */
  511. { XIVE_TM_OS_PAGE, TM_QW1_OS + TM_CPPR, 1, xive_tm_set_os_cppr,
  512. NULL },
  513. { XIVE_TM_HV_PAGE, TM_QW1_OS + TM_WORD2, 4, xive2_tm_push_os_ctx,
  514. NULL },
  515. { XIVE_TM_HV_PAGE, TM_QW1_OS + TM_WORD2, 8, xive2_tm_push_os_ctx,
  516. NULL },
  517. { XIVE_TM_OS_PAGE, TM_QW1_OS + TM_LGS, 1, xive_tm_set_os_lgs,
  518. NULL },
  519. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_CPPR, 1, xive_tm_set_hv_cppr,
  520. NULL },
  521. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_WORD2, 1, xive_tm_vt_push,
  522. NULL },
  523. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_WORD2, 1, NULL,
  524. xive_tm_vt_poll },
  525. { XIVE_TM_HV_PAGE, TM_QW3_HV_PHYS + TM_T, 1, xive2_tm_set_hv_target,
  526. NULL },
  527. /* MMIOs above 2K : special operations with side effects */
  528. { XIVE_TM_OS_PAGE, TM_SPC_ACK_OS_REG, 2, NULL,
  529. xive_tm_ack_os_reg },
  530. { XIVE_TM_OS_PAGE, TM_SPC_SET_OS_PENDING, 1, xive_tm_set_os_pending,
  531. NULL },
  532. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX_G2, 4, NULL,
  533. xive2_tm_pull_os_ctx },
  534. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX, 4, NULL,
  535. xive2_tm_pull_os_ctx },
  536. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX, 8, NULL,
  537. xive2_tm_pull_os_ctx },
  538. { XIVE_TM_HV_PAGE, TM_SPC_ACK_HV_REG, 2, NULL,
  539. xive_tm_ack_hv_reg },
  540. { XIVE_TM_HV_PAGE, TM_SPC_PULL_POOL_CTX_G2, 4, NULL,
  541. xive_tm_pull_pool_ctx },
  542. { XIVE_TM_HV_PAGE, TM_SPC_PULL_POOL_CTX, 4, NULL,
  543. xive_tm_pull_pool_ctx },
  544. { XIVE_TM_HV_PAGE, TM_SPC_PULL_POOL_CTX, 8, NULL,
  545. xive_tm_pull_pool_ctx },
  546. { XIVE_TM_HV_PAGE, TM_SPC_PULL_OS_CTX_OL, 1, xive2_tm_pull_os_ctx_ol,
  547. NULL },
  548. { XIVE_TM_HV_PAGE, TM_SPC_PULL_PHYS_CTX_G2, 4, NULL,
  549. xive_tm_pull_phys_ctx },
  550. { XIVE_TM_HV_PAGE, TM_SPC_PULL_PHYS_CTX, 1, NULL,
  551. xive_tm_pull_phys_ctx },
  552. { XIVE_TM_HV_PAGE, TM_SPC_PULL_PHYS_CTX_OL, 1, xive2_tm_pull_phys_ctx_ol,
  553. NULL },
  554. };
  555. static const XiveTmOp *xive_tm_find_op(XivePresenter *xptr, hwaddr offset,
  556. unsigned size, bool write)
  557. {
  558. uint8_t page_offset = (offset >> TM_SHIFT) & 0x3;
  559. uint32_t op_offset = offset & TM_ADDRESS_MASK;
  560. const XiveTmOp *tm_ops;
  561. int i, tm_ops_count;
  562. uint32_t cfg;
  563. cfg = xive_presenter_get_config(xptr);
  564. if (cfg & XIVE_PRESENTER_GEN1_TIMA_OS) {
  565. tm_ops = xive_tm_operations;
  566. tm_ops_count = ARRAY_SIZE(xive_tm_operations);
  567. } else {
  568. tm_ops = xive2_tm_operations;
  569. tm_ops_count = ARRAY_SIZE(xive2_tm_operations);
  570. }
  571. for (i = 0; i < tm_ops_count; i++) {
  572. const XiveTmOp *xto = &tm_ops[i];
  573. /* Accesses done from a more privileged TIMA page is allowed */
  574. if (xto->page_offset >= page_offset &&
  575. xto->op_offset == op_offset &&
  576. xto->size == size &&
  577. ((write && xto->write_handler) || (!write && xto->read_handler))) {
  578. return xto;
  579. }
  580. }
  581. return NULL;
  582. }
  583. /*
  584. * TIMA MMIO handlers
  585. */
  586. void xive_tctx_tm_write(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
  587. uint64_t value, unsigned size)
  588. {
  589. const XiveTmOp *xto;
  590. trace_xive_tctx_tm_write(tctx->cs->cpu_index, offset, size, value);
  591. /*
  592. * TODO: check V bit in Q[0-3]W2
  593. */
  594. /*
  595. * First, check for special operations in the 2K region
  596. */
  597. if (offset & TM_SPECIAL_OP) {
  598. xto = xive_tm_find_op(tctx->xptr, offset, size, true);
  599. if (!xto) {
  600. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid write access at TIMA "
  601. "@%"HWADDR_PRIx"\n", offset);
  602. } else {
  603. xto->write_handler(xptr, tctx, offset, value, size);
  604. }
  605. return;
  606. }
  607. /*
  608. * Then, for special operations in the region below 2K.
  609. */
  610. xto = xive_tm_find_op(tctx->xptr, offset, size, true);
  611. if (xto) {
  612. xto->write_handler(xptr, tctx, offset, value, size);
  613. return;
  614. }
  615. /*
  616. * Finish with raw access to the register values
  617. */
  618. xive_tm_raw_write(tctx, offset, value, size);
  619. }
  620. uint64_t xive_tctx_tm_read(XivePresenter *xptr, XiveTCTX *tctx, hwaddr offset,
  621. unsigned size)
  622. {
  623. const XiveTmOp *xto;
  624. uint64_t ret;
  625. /*
  626. * TODO: check V bit in Q[0-3]W2
  627. */
  628. /*
  629. * First, check for special operations in the 2K region
  630. */
  631. if (offset & TM_SPECIAL_OP) {
  632. xto = xive_tm_find_op(tctx->xptr, offset, size, false);
  633. if (!xto) {
  634. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid read access to TIMA"
  635. "@%"HWADDR_PRIx"\n", offset);
  636. return -1;
  637. }
  638. ret = xto->read_handler(xptr, tctx, offset, size);
  639. goto out;
  640. }
  641. /*
  642. * Then, for special operations in the region below 2K.
  643. */
  644. xto = xive_tm_find_op(tctx->xptr, offset, size, false);
  645. if (xto) {
  646. ret = xto->read_handler(xptr, tctx, offset, size);
  647. goto out;
  648. }
  649. /*
  650. * Finish with raw access to the register values
  651. */
  652. ret = xive_tm_raw_read(tctx, offset, size);
  653. out:
  654. trace_xive_tctx_tm_read(tctx->cs->cpu_index, offset, size, ret);
  655. return ret;
  656. }
  657. static char *xive_tctx_ring_print(uint8_t *ring)
  658. {
  659. uint32_t w2 = xive_tctx_word2(ring);
  660. return g_strdup_printf("%02x %02x %02x %02x %02x "
  661. "%02x %02x %02x %08x",
  662. ring[TM_NSR], ring[TM_CPPR], ring[TM_IPB], ring[TM_LSMFB],
  663. ring[TM_ACK_CNT], ring[TM_INC], ring[TM_AGE], ring[TM_PIPR],
  664. be32_to_cpu(w2));
  665. }
  666. static const char * const xive_tctx_ring_names[] = {
  667. "USER", "OS", "POOL", "PHYS",
  668. };
  669. /*
  670. * kvm_irqchip_in_kernel() will cause the compiler to turn this
  671. * info a nop if CONFIG_KVM isn't defined.
  672. */
  673. #define xive_in_kernel(xptr) \
  674. (kvm_irqchip_in_kernel() && \
  675. ({ \
  676. XivePresenterClass *xpc = XIVE_PRESENTER_GET_CLASS(xptr); \
  677. xpc->in_kernel ? xpc->in_kernel(xptr) : false; \
  678. }))
  679. void xive_tctx_pic_print_info(XiveTCTX *tctx, GString *buf)
  680. {
  681. int cpu_index;
  682. int i;
  683. /* Skip partially initialized vCPUs. This can happen on sPAPR when vCPUs
  684. * are hot plugged or unplugged.
  685. */
  686. if (!tctx) {
  687. return;
  688. }
  689. cpu_index = tctx->cs ? tctx->cs->cpu_index : -1;
  690. if (xive_in_kernel(tctx->xptr)) {
  691. Error *local_err = NULL;
  692. kvmppc_xive_cpu_synchronize_state(tctx, &local_err);
  693. if (local_err) {
  694. error_report_err(local_err);
  695. return;
  696. }
  697. }
  698. if (xive_presenter_get_config(tctx->xptr) & XIVE_PRESENTER_GEN1_TIMA_OS) {
  699. g_string_append_printf(buf, "CPU[%04x]: "
  700. "QW NSR CPPR IPB LSMFB ACK# INC AGE PIPR"
  701. " W2\n", cpu_index);
  702. } else {
  703. g_string_append_printf(buf, "CPU[%04x]: "
  704. "QW NSR CPPR IPB LSMFB - LGS T PIPR"
  705. " W2\n", cpu_index);
  706. }
  707. for (i = 0; i < XIVE_TM_RING_COUNT; i++) {
  708. char *s = xive_tctx_ring_print(&tctx->regs[i * XIVE_TM_RING_SIZE]);
  709. g_string_append_printf(buf, "CPU[%04x]: %4s %s\n",
  710. cpu_index, xive_tctx_ring_names[i], s);
  711. g_free(s);
  712. }
  713. }
  714. void xive_tctx_reset(XiveTCTX *tctx)
  715. {
  716. memset(tctx->regs, 0, sizeof(tctx->regs));
  717. /* Set some defaults */
  718. tctx->regs[TM_QW1_OS + TM_LSMFB] = 0xFF;
  719. tctx->regs[TM_QW1_OS + TM_ACK_CNT] = 0xFF;
  720. tctx->regs[TM_QW1_OS + TM_AGE] = 0xFF;
  721. if (!(xive_presenter_get_config(tctx->xptr) &
  722. XIVE_PRESENTER_GEN1_TIMA_OS)) {
  723. tctx->regs[TM_QW1_OS + TM_OGEN] = 2;
  724. }
  725. /*
  726. * Initialize PIPR to 0xFF to avoid phantom interrupts when the
  727. * CPPR is first set.
  728. */
  729. tctx->regs[TM_QW1_OS + TM_PIPR] =
  730. ipb_to_pipr(tctx->regs[TM_QW1_OS + TM_IPB]);
  731. tctx->regs[TM_QW3_HV_PHYS + TM_PIPR] =
  732. ipb_to_pipr(tctx->regs[TM_QW3_HV_PHYS + TM_IPB]);
  733. }
  734. static void xive_tctx_realize(DeviceState *dev, Error **errp)
  735. {
  736. XiveTCTX *tctx = XIVE_TCTX(dev);
  737. PowerPCCPU *cpu;
  738. CPUPPCState *env;
  739. assert(tctx->cs);
  740. assert(tctx->xptr);
  741. cpu = POWERPC_CPU(tctx->cs);
  742. env = &cpu->env;
  743. switch (PPC_INPUT(env)) {
  744. case PPC_FLAGS_INPUT_POWER9:
  745. tctx->hv_output = qdev_get_gpio_in(DEVICE(cpu), POWER9_INPUT_HINT);
  746. tctx->os_output = qdev_get_gpio_in(DEVICE(cpu), POWER9_INPUT_INT);
  747. break;
  748. default:
  749. error_setg(errp, "XIVE interrupt controller does not support "
  750. "this CPU bus model");
  751. return;
  752. }
  753. /* Connect the presenter to the VCPU (required for CPU hotplug) */
  754. if (xive_in_kernel(tctx->xptr)) {
  755. if (kvmppc_xive_cpu_connect(tctx, errp) < 0) {
  756. return;
  757. }
  758. }
  759. }
  760. static int vmstate_xive_tctx_pre_save(void *opaque)
  761. {
  762. XiveTCTX *tctx = XIVE_TCTX(opaque);
  763. Error *local_err = NULL;
  764. int ret;
  765. if (xive_in_kernel(tctx->xptr)) {
  766. ret = kvmppc_xive_cpu_get_state(tctx, &local_err);
  767. if (ret < 0) {
  768. error_report_err(local_err);
  769. return ret;
  770. }
  771. }
  772. return 0;
  773. }
  774. static int vmstate_xive_tctx_post_load(void *opaque, int version_id)
  775. {
  776. XiveTCTX *tctx = XIVE_TCTX(opaque);
  777. Error *local_err = NULL;
  778. int ret;
  779. if (xive_in_kernel(tctx->xptr)) {
  780. /*
  781. * Required for hotplugged CPU, for which the state comes
  782. * after all states of the machine.
  783. */
  784. ret = kvmppc_xive_cpu_set_state(tctx, &local_err);
  785. if (ret < 0) {
  786. error_report_err(local_err);
  787. return ret;
  788. }
  789. }
  790. return 0;
  791. }
  792. static const VMStateDescription vmstate_xive_tctx = {
  793. .name = TYPE_XIVE_TCTX,
  794. .version_id = 1,
  795. .minimum_version_id = 1,
  796. .pre_save = vmstate_xive_tctx_pre_save,
  797. .post_load = vmstate_xive_tctx_post_load,
  798. .fields = (const VMStateField[]) {
  799. VMSTATE_BUFFER(regs, XiveTCTX),
  800. VMSTATE_END_OF_LIST()
  801. },
  802. };
  803. static const Property xive_tctx_properties[] = {
  804. DEFINE_PROP_LINK("cpu", XiveTCTX, cs, TYPE_CPU, CPUState *),
  805. DEFINE_PROP_LINK("presenter", XiveTCTX, xptr, TYPE_XIVE_PRESENTER,
  806. XivePresenter *),
  807. };
  808. static void xive_tctx_class_init(ObjectClass *klass, void *data)
  809. {
  810. DeviceClass *dc = DEVICE_CLASS(klass);
  811. dc->desc = "XIVE Interrupt Thread Context";
  812. dc->realize = xive_tctx_realize;
  813. dc->vmsd = &vmstate_xive_tctx;
  814. device_class_set_props(dc, xive_tctx_properties);
  815. /*
  816. * Reason: part of XIVE interrupt controller, needs to be wired up
  817. * by xive_tctx_create().
  818. */
  819. dc->user_creatable = false;
  820. }
  821. static const TypeInfo xive_tctx_info = {
  822. .name = TYPE_XIVE_TCTX,
  823. .parent = TYPE_DEVICE,
  824. .instance_size = sizeof(XiveTCTX),
  825. .class_init = xive_tctx_class_init,
  826. };
  827. Object *xive_tctx_create(Object *cpu, XivePresenter *xptr, Error **errp)
  828. {
  829. Object *obj;
  830. obj = object_new(TYPE_XIVE_TCTX);
  831. object_property_add_child(cpu, TYPE_XIVE_TCTX, obj);
  832. object_unref(obj);
  833. object_property_set_link(obj, "cpu", cpu, &error_abort);
  834. object_property_set_link(obj, "presenter", OBJECT(xptr), &error_abort);
  835. if (!qdev_realize(DEVICE(obj), NULL, errp)) {
  836. object_unparent(obj);
  837. return NULL;
  838. }
  839. return obj;
  840. }
  841. void xive_tctx_destroy(XiveTCTX *tctx)
  842. {
  843. Object *obj = OBJECT(tctx);
  844. object_unparent(obj);
  845. }
  846. /*
  847. * XIVE ESB helpers
  848. */
  849. uint8_t xive_esb_set(uint8_t *pq, uint8_t value)
  850. {
  851. uint8_t old_pq = *pq & 0x3;
  852. *pq &= ~0x3;
  853. *pq |= value & 0x3;
  854. return old_pq;
  855. }
  856. bool xive_esb_trigger(uint8_t *pq)
  857. {
  858. uint8_t old_pq = *pq & 0x3;
  859. switch (old_pq) {
  860. case XIVE_ESB_RESET:
  861. xive_esb_set(pq, XIVE_ESB_PENDING);
  862. return true;
  863. case XIVE_ESB_PENDING:
  864. case XIVE_ESB_QUEUED:
  865. xive_esb_set(pq, XIVE_ESB_QUEUED);
  866. return false;
  867. case XIVE_ESB_OFF:
  868. xive_esb_set(pq, XIVE_ESB_OFF);
  869. return false;
  870. default:
  871. g_assert_not_reached();
  872. }
  873. }
  874. bool xive_esb_eoi(uint8_t *pq)
  875. {
  876. uint8_t old_pq = *pq & 0x3;
  877. switch (old_pq) {
  878. case XIVE_ESB_RESET:
  879. case XIVE_ESB_PENDING:
  880. xive_esb_set(pq, XIVE_ESB_RESET);
  881. return false;
  882. case XIVE_ESB_QUEUED:
  883. xive_esb_set(pq, XIVE_ESB_PENDING);
  884. return true;
  885. case XIVE_ESB_OFF:
  886. xive_esb_set(pq, XIVE_ESB_OFF);
  887. return false;
  888. default:
  889. g_assert_not_reached();
  890. }
  891. }
  892. /*
  893. * XIVE Interrupt Source (or IVSE)
  894. */
  895. uint8_t xive_source_esb_get(XiveSource *xsrc, uint32_t srcno)
  896. {
  897. assert(srcno < xsrc->nr_irqs);
  898. return xsrc->status[srcno] & 0x3;
  899. }
  900. uint8_t xive_source_esb_set(XiveSource *xsrc, uint32_t srcno, uint8_t pq)
  901. {
  902. assert(srcno < xsrc->nr_irqs);
  903. return xive_esb_set(&xsrc->status[srcno], pq);
  904. }
  905. /*
  906. * Returns whether the event notification should be forwarded.
  907. */
  908. static bool xive_source_lsi_trigger(XiveSource *xsrc, uint32_t srcno)
  909. {
  910. uint8_t old_pq = xive_source_esb_get(xsrc, srcno);
  911. xive_source_set_asserted(xsrc, srcno, true);
  912. switch (old_pq) {
  913. case XIVE_ESB_RESET:
  914. xive_source_esb_set(xsrc, srcno, XIVE_ESB_PENDING);
  915. return true;
  916. default:
  917. return false;
  918. }
  919. }
  920. /*
  921. * Sources can be configured with PQ offloading in which case the check
  922. * on the PQ state bits of MSIs is disabled
  923. */
  924. static bool xive_source_esb_disabled(XiveSource *xsrc, uint32_t srcno)
  925. {
  926. return (xsrc->esb_flags & XIVE_SRC_PQ_DISABLE) &&
  927. !xive_source_irq_is_lsi(xsrc, srcno);
  928. }
  929. /*
  930. * Returns whether the event notification should be forwarded.
  931. */
  932. static bool xive_source_esb_trigger(XiveSource *xsrc, uint32_t srcno)
  933. {
  934. bool ret;
  935. assert(srcno < xsrc->nr_irqs);
  936. if (xive_source_esb_disabled(xsrc, srcno)) {
  937. return true;
  938. }
  939. ret = xive_esb_trigger(&xsrc->status[srcno]);
  940. if (xive_source_irq_is_lsi(xsrc, srcno) &&
  941. xive_source_esb_get(xsrc, srcno) == XIVE_ESB_QUEUED) {
  942. qemu_log_mask(LOG_GUEST_ERROR,
  943. "XIVE: queued an event on LSI IRQ %d\n", srcno);
  944. }
  945. return ret;
  946. }
  947. /*
  948. * Returns whether the event notification should be forwarded.
  949. */
  950. static bool xive_source_esb_eoi(XiveSource *xsrc, uint32_t srcno)
  951. {
  952. bool ret;
  953. assert(srcno < xsrc->nr_irqs);
  954. if (xive_source_esb_disabled(xsrc, srcno)) {
  955. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid EOI for IRQ %d\n", srcno);
  956. return false;
  957. }
  958. ret = xive_esb_eoi(&xsrc->status[srcno]);
  959. /*
  960. * LSI sources do not set the Q bit but they can still be
  961. * asserted, in which case we should forward a new event
  962. * notification
  963. */
  964. if (xive_source_irq_is_lsi(xsrc, srcno) &&
  965. xive_source_is_asserted(xsrc, srcno)) {
  966. ret = xive_source_lsi_trigger(xsrc, srcno);
  967. }
  968. return ret;
  969. }
  970. /*
  971. * Forward the source event notification to the Router
  972. */
  973. static void xive_source_notify(XiveSource *xsrc, int srcno)
  974. {
  975. XiveNotifierClass *xnc = XIVE_NOTIFIER_GET_CLASS(xsrc->xive);
  976. bool pq_checked = !xive_source_esb_disabled(xsrc, srcno);
  977. if (xnc->notify) {
  978. xnc->notify(xsrc->xive, srcno, pq_checked);
  979. }
  980. }
  981. /*
  982. * In a two pages ESB MMIO setting, even page is the trigger page, odd
  983. * page is for management
  984. */
  985. static inline bool addr_is_even(hwaddr addr, uint32_t shift)
  986. {
  987. return !((addr >> shift) & 1);
  988. }
  989. static inline bool xive_source_is_trigger_page(XiveSource *xsrc, hwaddr addr)
  990. {
  991. return xive_source_esb_has_2page(xsrc) &&
  992. addr_is_even(addr, xsrc->esb_shift - 1);
  993. }
  994. /*
  995. * ESB MMIO loads
  996. * Trigger page Management/EOI page
  997. *
  998. * ESB MMIO setting 2 pages 1 or 2 pages
  999. *
  1000. * 0x000 .. 0x3FF -1 EOI and return 0|1
  1001. * 0x400 .. 0x7FF -1 EOI and return 0|1
  1002. * 0x800 .. 0xBFF -1 return PQ
  1003. * 0xC00 .. 0xCFF -1 return PQ and atomically PQ=00
  1004. * 0xD00 .. 0xDFF -1 return PQ and atomically PQ=01
  1005. * 0xE00 .. 0xDFF -1 return PQ and atomically PQ=10
  1006. * 0xF00 .. 0xDFF -1 return PQ and atomically PQ=11
  1007. */
  1008. static uint64_t xive_source_esb_read(void *opaque, hwaddr addr, unsigned size)
  1009. {
  1010. XiveSource *xsrc = XIVE_SOURCE(opaque);
  1011. uint32_t offset = addr & 0xFFF;
  1012. uint32_t srcno = addr >> xsrc->esb_shift;
  1013. uint64_t ret = -1;
  1014. /* In a two pages ESB MMIO setting, trigger page should not be read */
  1015. if (xive_source_is_trigger_page(xsrc, addr)) {
  1016. qemu_log_mask(LOG_GUEST_ERROR,
  1017. "XIVE: invalid load on IRQ %d trigger page at "
  1018. "0x%"HWADDR_PRIx"\n", srcno, addr);
  1019. return -1;
  1020. }
  1021. switch (offset) {
  1022. case XIVE_ESB_LOAD_EOI ... XIVE_ESB_LOAD_EOI + 0x7FF:
  1023. ret = xive_source_esb_eoi(xsrc, srcno);
  1024. /* Forward the source event notification for routing */
  1025. if (ret) {
  1026. xive_source_notify(xsrc, srcno);
  1027. }
  1028. break;
  1029. case XIVE_ESB_GET ... XIVE_ESB_GET + 0x3FF:
  1030. ret = xive_source_esb_get(xsrc, srcno);
  1031. break;
  1032. case XIVE_ESB_SET_PQ_00 ... XIVE_ESB_SET_PQ_00 + 0x0FF:
  1033. case XIVE_ESB_SET_PQ_01 ... XIVE_ESB_SET_PQ_01 + 0x0FF:
  1034. case XIVE_ESB_SET_PQ_10 ... XIVE_ESB_SET_PQ_10 + 0x0FF:
  1035. case XIVE_ESB_SET_PQ_11 ... XIVE_ESB_SET_PQ_11 + 0x0FF:
  1036. ret = xive_source_esb_set(xsrc, srcno, (offset >> 8) & 0x3);
  1037. break;
  1038. default:
  1039. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB load addr %x\n",
  1040. offset);
  1041. }
  1042. trace_xive_source_esb_read(addr, srcno, ret);
  1043. return ret;
  1044. }
  1045. /*
  1046. * ESB MMIO stores
  1047. * Trigger page Management/EOI page
  1048. *
  1049. * ESB MMIO setting 2 pages 1 or 2 pages
  1050. *
  1051. * 0x000 .. 0x3FF Trigger Trigger
  1052. * 0x400 .. 0x7FF Trigger EOI
  1053. * 0x800 .. 0xBFF Trigger undefined
  1054. * 0xC00 .. 0xCFF Trigger PQ=00
  1055. * 0xD00 .. 0xDFF Trigger PQ=01
  1056. * 0xE00 .. 0xDFF Trigger PQ=10
  1057. * 0xF00 .. 0xDFF Trigger PQ=11
  1058. */
  1059. static void xive_source_esb_write(void *opaque, hwaddr addr,
  1060. uint64_t value, unsigned size)
  1061. {
  1062. XiveSource *xsrc = XIVE_SOURCE(opaque);
  1063. uint32_t offset = addr & 0xFFF;
  1064. uint32_t srcno = addr >> xsrc->esb_shift;
  1065. bool notify = false;
  1066. trace_xive_source_esb_write(addr, srcno, value);
  1067. /* In a two pages ESB MMIO setting, trigger page only triggers */
  1068. if (xive_source_is_trigger_page(xsrc, addr)) {
  1069. notify = xive_source_esb_trigger(xsrc, srcno);
  1070. goto out;
  1071. }
  1072. switch (offset) {
  1073. case 0 ... 0x3FF:
  1074. notify = xive_source_esb_trigger(xsrc, srcno);
  1075. break;
  1076. case XIVE_ESB_STORE_EOI ... XIVE_ESB_STORE_EOI + 0x3FF:
  1077. if (!(xsrc->esb_flags & XIVE_SRC_STORE_EOI)) {
  1078. qemu_log_mask(LOG_GUEST_ERROR,
  1079. "XIVE: invalid Store EOI for IRQ %d\n", srcno);
  1080. return;
  1081. }
  1082. notify = xive_source_esb_eoi(xsrc, srcno);
  1083. break;
  1084. /*
  1085. * This is an internal offset used to inject triggers when the PQ
  1086. * state bits are not controlled locally. Such as for LSIs when
  1087. * under ABT mode.
  1088. */
  1089. case XIVE_ESB_INJECT ... XIVE_ESB_INJECT + 0x3FF:
  1090. notify = true;
  1091. break;
  1092. case XIVE_ESB_SET_PQ_00 ... XIVE_ESB_SET_PQ_00 + 0x0FF:
  1093. case XIVE_ESB_SET_PQ_01 ... XIVE_ESB_SET_PQ_01 + 0x0FF:
  1094. case XIVE_ESB_SET_PQ_10 ... XIVE_ESB_SET_PQ_10 + 0x0FF:
  1095. case XIVE_ESB_SET_PQ_11 ... XIVE_ESB_SET_PQ_11 + 0x0FF:
  1096. xive_source_esb_set(xsrc, srcno, (offset >> 8) & 0x3);
  1097. break;
  1098. default:
  1099. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB write addr %x\n",
  1100. offset);
  1101. return;
  1102. }
  1103. out:
  1104. /* Forward the source event notification for routing */
  1105. if (notify) {
  1106. xive_source_notify(xsrc, srcno);
  1107. }
  1108. }
  1109. static const MemoryRegionOps xive_source_esb_ops = {
  1110. .read = xive_source_esb_read,
  1111. .write = xive_source_esb_write,
  1112. .endianness = DEVICE_BIG_ENDIAN,
  1113. .valid = {
  1114. .min_access_size = 1,
  1115. .max_access_size = 8,
  1116. },
  1117. .impl = {
  1118. .min_access_size = 1,
  1119. .max_access_size = 8,
  1120. },
  1121. };
  1122. void xive_source_set_irq(void *opaque, int srcno, int val)
  1123. {
  1124. XiveSource *xsrc = XIVE_SOURCE(opaque);
  1125. bool notify = false;
  1126. if (xive_source_irq_is_lsi(xsrc, srcno)) {
  1127. if (val) {
  1128. notify = xive_source_lsi_trigger(xsrc, srcno);
  1129. } else {
  1130. xive_source_set_asserted(xsrc, srcno, false);
  1131. }
  1132. } else {
  1133. if (val) {
  1134. notify = xive_source_esb_trigger(xsrc, srcno);
  1135. }
  1136. }
  1137. /* Forward the source event notification for routing */
  1138. if (notify) {
  1139. xive_source_notify(xsrc, srcno);
  1140. }
  1141. }
  1142. void xive_source_pic_print_info(XiveSource *xsrc, uint32_t offset, GString *buf)
  1143. {
  1144. for (unsigned i = 0; i < xsrc->nr_irqs; i++) {
  1145. uint8_t pq = xive_source_esb_get(xsrc, i);
  1146. if (pq == XIVE_ESB_OFF) {
  1147. continue;
  1148. }
  1149. g_string_append_printf(buf, " %08x %s %c%c%c\n", i + offset,
  1150. xive_source_irq_is_lsi(xsrc, i) ? "LSI" : "MSI",
  1151. pq & XIVE_ESB_VAL_P ? 'P' : '-',
  1152. pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
  1153. xive_source_is_asserted(xsrc, i) ? 'A' : ' ');
  1154. }
  1155. }
  1156. static void xive_source_reset(void *dev)
  1157. {
  1158. XiveSource *xsrc = XIVE_SOURCE(dev);
  1159. /* Do not clear the LSI bitmap */
  1160. memset(xsrc->status, xsrc->reset_pq, xsrc->nr_irqs);
  1161. }
  1162. static void xive_source_realize(DeviceState *dev, Error **errp)
  1163. {
  1164. XiveSource *xsrc = XIVE_SOURCE(dev);
  1165. uint64_t esb_len = xive_source_esb_len(xsrc);
  1166. assert(xsrc->xive);
  1167. if (!xsrc->nr_irqs) {
  1168. error_setg(errp, "Number of interrupt needs to be greater than 0");
  1169. return;
  1170. }
  1171. if (xsrc->esb_shift != XIVE_ESB_4K &&
  1172. xsrc->esb_shift != XIVE_ESB_4K_2PAGE &&
  1173. xsrc->esb_shift != XIVE_ESB_64K &&
  1174. xsrc->esb_shift != XIVE_ESB_64K_2PAGE) {
  1175. error_setg(errp, "Invalid ESB shift setting");
  1176. return;
  1177. }
  1178. xsrc->status = g_malloc0(xsrc->nr_irqs);
  1179. xsrc->lsi_map = bitmap_new(xsrc->nr_irqs);
  1180. memory_region_init(&xsrc->esb_mmio, OBJECT(xsrc), "xive.esb", esb_len);
  1181. memory_region_init_io(&xsrc->esb_mmio_emulated, OBJECT(xsrc),
  1182. &xive_source_esb_ops, xsrc, "xive.esb-emulated",
  1183. esb_len);
  1184. memory_region_add_subregion(&xsrc->esb_mmio, 0, &xsrc->esb_mmio_emulated);
  1185. qemu_register_reset(xive_source_reset, dev);
  1186. }
  1187. static const VMStateDescription vmstate_xive_source = {
  1188. .name = TYPE_XIVE_SOURCE,
  1189. .version_id = 1,
  1190. .minimum_version_id = 1,
  1191. .fields = (const VMStateField[]) {
  1192. VMSTATE_UINT32_EQUAL(nr_irqs, XiveSource, NULL),
  1193. VMSTATE_VBUFFER_UINT32(status, XiveSource, 1, NULL, nr_irqs),
  1194. VMSTATE_END_OF_LIST()
  1195. },
  1196. };
  1197. /*
  1198. * The default XIVE interrupt source setting for the ESB MMIOs is two
  1199. * 64k pages without Store EOI, to be in sync with KVM.
  1200. */
  1201. static const Property xive_source_properties[] = {
  1202. DEFINE_PROP_UINT64("flags", XiveSource, esb_flags, 0),
  1203. DEFINE_PROP_UINT32("nr-irqs", XiveSource, nr_irqs, 0),
  1204. DEFINE_PROP_UINT32("shift", XiveSource, esb_shift, XIVE_ESB_64K_2PAGE),
  1205. /*
  1206. * By default, PQs are initialized to 0b01 (Q=1) which corresponds
  1207. * to "ints off"
  1208. */
  1209. DEFINE_PROP_UINT8("reset-pq", XiveSource, reset_pq, XIVE_ESB_OFF),
  1210. DEFINE_PROP_LINK("xive", XiveSource, xive, TYPE_XIVE_NOTIFIER,
  1211. XiveNotifier *),
  1212. };
  1213. static void xive_source_class_init(ObjectClass *klass, void *data)
  1214. {
  1215. DeviceClass *dc = DEVICE_CLASS(klass);
  1216. dc->desc = "XIVE Interrupt Source";
  1217. device_class_set_props(dc, xive_source_properties);
  1218. dc->realize = xive_source_realize;
  1219. dc->vmsd = &vmstate_xive_source;
  1220. /*
  1221. * Reason: part of XIVE interrupt controller, needs to be wired up,
  1222. * e.g. by spapr_xive_instance_init().
  1223. */
  1224. dc->user_creatable = false;
  1225. }
  1226. static const TypeInfo xive_source_info = {
  1227. .name = TYPE_XIVE_SOURCE,
  1228. .parent = TYPE_DEVICE,
  1229. .instance_size = sizeof(XiveSource),
  1230. .class_init = xive_source_class_init,
  1231. };
  1232. /*
  1233. * XiveEND helpers
  1234. */
  1235. void xive_end_queue_pic_print_info(XiveEND *end, uint32_t width, GString *buf)
  1236. {
  1237. uint64_t qaddr_base = xive_end_qaddr(end);
  1238. uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
  1239. uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
  1240. uint32_t qentries = 1 << (qsize + 10);
  1241. int i;
  1242. /*
  1243. * print out the [ (qindex - (width - 1)) .. (qindex + 1)] window
  1244. */
  1245. g_string_append_printf(buf, " [ ");
  1246. qindex = (qindex - (width - 1)) & (qentries - 1);
  1247. for (i = 0; i < width; i++) {
  1248. uint64_t qaddr = qaddr_base + (qindex << 2);
  1249. uint32_t qdata = -1;
  1250. if (dma_memory_read(&address_space_memory, qaddr,
  1251. &qdata, sizeof(qdata), MEMTXATTRS_UNSPECIFIED)) {
  1252. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to read EQ @0x%"
  1253. HWADDR_PRIx "\n", qaddr);
  1254. return;
  1255. }
  1256. g_string_append_printf(buf, "%s%08x ", i == width - 1 ? "^" : "",
  1257. be32_to_cpu(qdata));
  1258. qindex = (qindex + 1) & (qentries - 1);
  1259. }
  1260. g_string_append_c(buf, ']');
  1261. }
  1262. void xive_end_pic_print_info(XiveEND *end, uint32_t end_idx, GString *buf)
  1263. {
  1264. uint64_t qaddr_base = xive_end_qaddr(end);
  1265. uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
  1266. uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
  1267. uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
  1268. uint32_t qentries = 1 << (qsize + 10);
  1269. uint32_t nvt_blk = xive_get_field32(END_W6_NVT_BLOCK, end->w6);
  1270. uint32_t nvt_idx = xive_get_field32(END_W6_NVT_INDEX, end->w6);
  1271. uint8_t priority = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
  1272. uint8_t pq;
  1273. if (!xive_end_is_valid(end)) {
  1274. return;
  1275. }
  1276. pq = xive_get_field32(END_W1_ESn, end->w1);
  1277. g_string_append_printf(buf,
  1278. " %08x %c%c %c%c%c%c%c%c%c%c prio:%d nvt:%02x/%04x",
  1279. end_idx,
  1280. pq & XIVE_ESB_VAL_P ? 'P' : '-',
  1281. pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
  1282. xive_end_is_valid(end) ? 'v' : '-',
  1283. xive_end_is_enqueue(end) ? 'q' : '-',
  1284. xive_end_is_notify(end) ? 'n' : '-',
  1285. xive_end_is_backlog(end) ? 'b' : '-',
  1286. xive_end_is_escalate(end) ? 'e' : '-',
  1287. xive_end_is_uncond_escalation(end) ? 'u' : '-',
  1288. xive_end_is_silent_escalation(end) ? 's' : '-',
  1289. xive_end_is_firmware(end) ? 'f' : '-',
  1290. priority, nvt_blk, nvt_idx);
  1291. if (qaddr_base) {
  1292. g_string_append_printf(buf, " eq:@%08"PRIx64"% 6d/%5d ^%d",
  1293. qaddr_base, qindex, qentries, qgen);
  1294. xive_end_queue_pic_print_info(end, 6, buf);
  1295. }
  1296. g_string_append_c(buf, '\n');
  1297. }
  1298. static void xive_end_enqueue(XiveEND *end, uint32_t data)
  1299. {
  1300. uint64_t qaddr_base = xive_end_qaddr(end);
  1301. uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
  1302. uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
  1303. uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
  1304. uint64_t qaddr = qaddr_base + (qindex << 2);
  1305. uint32_t qdata = cpu_to_be32((qgen << 31) | (data & 0x7fffffff));
  1306. uint32_t qentries = 1 << (qsize + 10);
  1307. if (dma_memory_write(&address_space_memory, qaddr,
  1308. &qdata, sizeof(qdata), MEMTXATTRS_UNSPECIFIED)) {
  1309. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to write END data @0x%"
  1310. HWADDR_PRIx "\n", qaddr);
  1311. return;
  1312. }
  1313. qindex = (qindex + 1) & (qentries - 1);
  1314. if (qindex == 0) {
  1315. qgen ^= 1;
  1316. end->w1 = xive_set_field32(END_W1_GENERATION, end->w1, qgen);
  1317. }
  1318. end->w1 = xive_set_field32(END_W1_PAGE_OFF, end->w1, qindex);
  1319. }
  1320. void xive_end_eas_pic_print_info(XiveEND *end, uint32_t end_idx, GString *buf)
  1321. {
  1322. XiveEAS *eas = (XiveEAS *) &end->w4;
  1323. uint8_t pq;
  1324. if (!xive_end_is_escalate(end)) {
  1325. return;
  1326. }
  1327. pq = xive_get_field32(END_W1_ESe, end->w1);
  1328. g_string_append_printf(buf, " %08x %c%c %c%c end:%02x/%04x data:%08x\n",
  1329. end_idx,
  1330. pq & XIVE_ESB_VAL_P ? 'P' : '-',
  1331. pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
  1332. xive_eas_is_valid(eas) ? 'V' : ' ',
  1333. xive_eas_is_masked(eas) ? 'M' : ' ',
  1334. (uint8_t) xive_get_field64(EAS_END_BLOCK, eas->w),
  1335. (uint32_t) xive_get_field64(EAS_END_INDEX, eas->w),
  1336. (uint32_t) xive_get_field64(EAS_END_DATA, eas->w));
  1337. }
  1338. /*
  1339. * XIVE Router (aka. Virtualization Controller or IVRE)
  1340. */
  1341. int xive_router_get_eas(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
  1342. XiveEAS *eas)
  1343. {
  1344. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1345. return xrc->get_eas(xrtr, eas_blk, eas_idx, eas);
  1346. }
  1347. static
  1348. int xive_router_get_pq(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
  1349. uint8_t *pq)
  1350. {
  1351. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1352. return xrc->get_pq(xrtr, eas_blk, eas_idx, pq);
  1353. }
  1354. static
  1355. int xive_router_set_pq(XiveRouter *xrtr, uint8_t eas_blk, uint32_t eas_idx,
  1356. uint8_t *pq)
  1357. {
  1358. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1359. return xrc->set_pq(xrtr, eas_blk, eas_idx, pq);
  1360. }
  1361. int xive_router_get_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
  1362. XiveEND *end)
  1363. {
  1364. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1365. return xrc->get_end(xrtr, end_blk, end_idx, end);
  1366. }
  1367. int xive_router_write_end(XiveRouter *xrtr, uint8_t end_blk, uint32_t end_idx,
  1368. XiveEND *end, uint8_t word_number)
  1369. {
  1370. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1371. return xrc->write_end(xrtr, end_blk, end_idx, end, word_number);
  1372. }
  1373. int xive_router_get_nvt(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
  1374. XiveNVT *nvt)
  1375. {
  1376. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1377. return xrc->get_nvt(xrtr, nvt_blk, nvt_idx, nvt);
  1378. }
  1379. int xive_router_write_nvt(XiveRouter *xrtr, uint8_t nvt_blk, uint32_t nvt_idx,
  1380. XiveNVT *nvt, uint8_t word_number)
  1381. {
  1382. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1383. return xrc->write_nvt(xrtr, nvt_blk, nvt_idx, nvt, word_number);
  1384. }
  1385. static int xive_router_get_block_id(XiveRouter *xrtr)
  1386. {
  1387. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1388. return xrc->get_block_id(xrtr);
  1389. }
  1390. static void xive_router_realize(DeviceState *dev, Error **errp)
  1391. {
  1392. XiveRouter *xrtr = XIVE_ROUTER(dev);
  1393. assert(xrtr->xfb);
  1394. }
  1395. static void xive_router_end_notify_handler(XiveRouter *xrtr, XiveEAS *eas)
  1396. {
  1397. XiveRouterClass *xrc = XIVE_ROUTER_GET_CLASS(xrtr);
  1398. return xrc->end_notify(xrtr, eas);
  1399. }
  1400. /*
  1401. * Encode the HW CAM line in the block group mode format :
  1402. *
  1403. * chip << 19 | 0000000 0 0001 thread (7Bit)
  1404. */
  1405. static uint32_t xive_tctx_hw_cam_line(XivePresenter *xptr, XiveTCTX *tctx)
  1406. {
  1407. CPUPPCState *env = &POWERPC_CPU(tctx->cs)->env;
  1408. uint32_t pir = env->spr_cb[SPR_PIR].default_value;
  1409. uint8_t blk = xive_router_get_block_id(XIVE_ROUTER(xptr));
  1410. return xive_nvt_cam_line(blk, 1 << 7 | (pir & 0x7f));
  1411. }
  1412. /*
  1413. * The thread context register words are in big-endian format.
  1414. */
  1415. int xive_presenter_tctx_match(XivePresenter *xptr, XiveTCTX *tctx,
  1416. uint8_t format,
  1417. uint8_t nvt_blk, uint32_t nvt_idx,
  1418. bool cam_ignore, uint32_t logic_serv)
  1419. {
  1420. uint32_t cam = xive_nvt_cam_line(nvt_blk, nvt_idx);
  1421. uint32_t qw3w2 = xive_tctx_word2(&tctx->regs[TM_QW3_HV_PHYS]);
  1422. uint32_t qw2w2 = xive_tctx_word2(&tctx->regs[TM_QW2_HV_POOL]);
  1423. uint32_t qw1w2 = xive_tctx_word2(&tctx->regs[TM_QW1_OS]);
  1424. uint32_t qw0w2 = xive_tctx_word2(&tctx->regs[TM_QW0_USER]);
  1425. /*
  1426. * TODO (PowerNV): ignore mode. The low order bits of the NVT
  1427. * identifier are ignored in the "CAM" match.
  1428. */
  1429. if (format == 0) {
  1430. if (cam_ignore == true) {
  1431. /*
  1432. * F=0 & i=1: Logical server notification (bits ignored at
  1433. * the end of the NVT identifier)
  1434. */
  1435. qemu_log_mask(LOG_UNIMP, "XIVE: no support for LS NVT %x/%x\n",
  1436. nvt_blk, nvt_idx);
  1437. return -1;
  1438. }
  1439. /* F=0 & i=0: Specific NVT notification */
  1440. /* PHYS ring */
  1441. if ((be32_to_cpu(qw3w2) & TM_QW3W2_VT) &&
  1442. cam == xive_tctx_hw_cam_line(xptr, tctx)) {
  1443. return TM_QW3_HV_PHYS;
  1444. }
  1445. /* HV POOL ring */
  1446. if ((be32_to_cpu(qw2w2) & TM_QW2W2_VP) &&
  1447. cam == xive_get_field32(TM_QW2W2_POOL_CAM, qw2w2)) {
  1448. return TM_QW2_HV_POOL;
  1449. }
  1450. /* OS ring */
  1451. if ((be32_to_cpu(qw1w2) & TM_QW1W2_VO) &&
  1452. cam == xive_get_field32(TM_QW1W2_OS_CAM, qw1w2)) {
  1453. return TM_QW1_OS;
  1454. }
  1455. } else {
  1456. /* F=1 : User level Event-Based Branch (EBB) notification */
  1457. /* USER ring */
  1458. if ((be32_to_cpu(qw1w2) & TM_QW1W2_VO) &&
  1459. (cam == xive_get_field32(TM_QW1W2_OS_CAM, qw1w2)) &&
  1460. (be32_to_cpu(qw0w2) & TM_QW0W2_VU) &&
  1461. (logic_serv == xive_get_field32(TM_QW0W2_LOGIC_SERV, qw0w2))) {
  1462. return TM_QW0_USER;
  1463. }
  1464. }
  1465. return -1;
  1466. }
  1467. /*
  1468. * This is our simple Xive Presenter Engine model. It is merged in the
  1469. * Router as it does not require an extra object.
  1470. *
  1471. * It receives notification requests sent by the IVRE to find one
  1472. * matching NVT (or more) dispatched on the processor threads. In case
  1473. * of a single NVT notification, the process is abbreviated and the
  1474. * thread is signaled if a match is found. In case of a logical server
  1475. * notification (bits ignored at the end of the NVT identifier), the
  1476. * IVPE and IVRE select a winning thread using different filters. This
  1477. * involves 2 or 3 exchanges on the PowerBus that the model does not
  1478. * support.
  1479. *
  1480. * The parameters represent what is sent on the PowerBus
  1481. */
  1482. bool xive_presenter_notify(XiveFabric *xfb, uint8_t format,
  1483. uint8_t nvt_blk, uint32_t nvt_idx,
  1484. bool cam_ignore, uint8_t priority,
  1485. uint32_t logic_serv)
  1486. {
  1487. XiveFabricClass *xfc = XIVE_FABRIC_GET_CLASS(xfb);
  1488. XiveTCTXMatch match = { .tctx = NULL, .ring = 0 };
  1489. int count;
  1490. /*
  1491. * Ask the machine to scan the interrupt controllers for a match
  1492. */
  1493. count = xfc->match_nvt(xfb, format, nvt_blk, nvt_idx, cam_ignore,
  1494. priority, logic_serv, &match);
  1495. if (count < 0) {
  1496. return false;
  1497. }
  1498. /* handle CPU exception delivery */
  1499. if (count) {
  1500. trace_xive_presenter_notify(nvt_blk, nvt_idx, match.ring);
  1501. xive_tctx_ipb_update(match.tctx, match.ring,
  1502. xive_priority_to_ipb(priority));
  1503. }
  1504. return !!count;
  1505. }
  1506. /*
  1507. * Notification using the END ESe/ESn bit (Event State Buffer for
  1508. * escalation and notification). Provide further coalescing in the
  1509. * Router.
  1510. */
  1511. static bool xive_router_end_es_notify(XiveRouter *xrtr, uint8_t end_blk,
  1512. uint32_t end_idx, XiveEND *end,
  1513. uint32_t end_esmask)
  1514. {
  1515. uint8_t pq = xive_get_field32(end_esmask, end->w1);
  1516. bool notify = xive_esb_trigger(&pq);
  1517. if (pq != xive_get_field32(end_esmask, end->w1)) {
  1518. end->w1 = xive_set_field32(end_esmask, end->w1, pq);
  1519. xive_router_write_end(xrtr, end_blk, end_idx, end, 1);
  1520. }
  1521. /* ESe/n[Q]=1 : end of notification */
  1522. return notify;
  1523. }
  1524. /*
  1525. * An END trigger can come from an event trigger (IPI or HW) or from
  1526. * another chip. We don't model the PowerBus but the END trigger
  1527. * message has the same parameters than in the function below.
  1528. */
  1529. void xive_router_end_notify(XiveRouter *xrtr, XiveEAS *eas)
  1530. {
  1531. XiveEND end;
  1532. uint8_t priority;
  1533. uint8_t format;
  1534. uint8_t nvt_blk;
  1535. uint32_t nvt_idx;
  1536. XiveNVT nvt;
  1537. bool found;
  1538. uint8_t end_blk = xive_get_field64(EAS_END_BLOCK, eas->w);
  1539. uint32_t end_idx = xive_get_field64(EAS_END_INDEX, eas->w);
  1540. uint32_t end_data = xive_get_field64(EAS_END_DATA, eas->w);
  1541. /* END cache lookup */
  1542. if (xive_router_get_end(xrtr, end_blk, end_idx, &end)) {
  1543. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: No END %x/%x\n", end_blk,
  1544. end_idx);
  1545. return;
  1546. }
  1547. if (!xive_end_is_valid(&end)) {
  1548. trace_xive_router_end_notify(end_blk, end_idx, end_data);
  1549. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: END %x/%x is invalid\n",
  1550. end_blk, end_idx);
  1551. return;
  1552. }
  1553. if (xive_end_is_enqueue(&end)) {
  1554. xive_end_enqueue(&end, end_data);
  1555. /* Enqueuing event data modifies the EQ toggle and index */
  1556. xive_router_write_end(xrtr, end_blk, end_idx, &end, 1);
  1557. }
  1558. /*
  1559. * When the END is silent, we skip the notification part.
  1560. */
  1561. if (xive_end_is_silent_escalation(&end)) {
  1562. goto do_escalation;
  1563. }
  1564. /*
  1565. * The W7 format depends on the F bit in W6. It defines the type
  1566. * of the notification :
  1567. *
  1568. * F=0 : single or multiple NVT notification
  1569. * F=1 : User level Event-Based Branch (EBB) notification, no
  1570. * priority
  1571. */
  1572. format = xive_get_field32(END_W6_FORMAT_BIT, end.w6);
  1573. priority = xive_get_field32(END_W7_F0_PRIORITY, end.w7);
  1574. /* The END is masked */
  1575. if (format == 0 && priority == 0xff) {
  1576. return;
  1577. }
  1578. /*
  1579. * Check the END ESn (Event State Buffer for notification) for
  1580. * even further coalescing in the Router
  1581. */
  1582. if (!xive_end_is_notify(&end)) {
  1583. /* ESn[Q]=1 : end of notification */
  1584. if (!xive_router_end_es_notify(xrtr, end_blk, end_idx,
  1585. &end, END_W1_ESn)) {
  1586. return;
  1587. }
  1588. }
  1589. /*
  1590. * Follows IVPE notification
  1591. */
  1592. nvt_blk = xive_get_field32(END_W6_NVT_BLOCK, end.w6);
  1593. nvt_idx = xive_get_field32(END_W6_NVT_INDEX, end.w6);
  1594. /* NVT cache lookup */
  1595. if (xive_router_get_nvt(xrtr, nvt_blk, nvt_idx, &nvt)) {
  1596. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: no NVT %x/%x\n",
  1597. nvt_blk, nvt_idx);
  1598. return;
  1599. }
  1600. if (!xive_nvt_is_valid(&nvt)) {
  1601. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: NVT %x/%x is invalid\n",
  1602. nvt_blk, nvt_idx);
  1603. return;
  1604. }
  1605. found = xive_presenter_notify(xrtr->xfb, format, nvt_blk, nvt_idx,
  1606. xive_get_field32(END_W7_F0_IGNORE, end.w7),
  1607. priority,
  1608. xive_get_field32(END_W7_F1_LOG_SERVER_ID, end.w7));
  1609. /* TODO: Auto EOI. */
  1610. if (found) {
  1611. return;
  1612. }
  1613. /*
  1614. * If no matching NVT is dispatched on a HW thread :
  1615. * - specific VP: update the NVT structure if backlog is activated
  1616. * - logical server : forward request to IVPE (not supported)
  1617. */
  1618. if (xive_end_is_backlog(&end)) {
  1619. uint8_t ipb;
  1620. if (format == 1) {
  1621. qemu_log_mask(LOG_GUEST_ERROR,
  1622. "XIVE: END %x/%x invalid config: F1 & backlog\n",
  1623. end_blk, end_idx);
  1624. return;
  1625. }
  1626. /*
  1627. * Record the IPB in the associated NVT structure for later
  1628. * use. The presenter will resend the interrupt when the vCPU
  1629. * is dispatched again on a HW thread.
  1630. */
  1631. ipb = xive_get_field32(NVT_W4_IPB, nvt.w4) |
  1632. xive_priority_to_ipb(priority);
  1633. nvt.w4 = xive_set_field32(NVT_W4_IPB, nvt.w4, ipb);
  1634. xive_router_write_nvt(xrtr, nvt_blk, nvt_idx, &nvt, 4);
  1635. /*
  1636. * On HW, follows a "Broadcast Backlog" to IVPEs
  1637. */
  1638. }
  1639. do_escalation:
  1640. /*
  1641. * If activated, escalate notification using the ESe PQ bits and
  1642. * the EAS in w4-5
  1643. */
  1644. if (!xive_end_is_escalate(&end)) {
  1645. return;
  1646. }
  1647. /*
  1648. * Check the END ESe (Event State Buffer for escalation) for even
  1649. * further coalescing in the Router
  1650. */
  1651. if (!xive_end_is_uncond_escalation(&end)) {
  1652. /* ESe[Q]=1 : end of notification */
  1653. if (!xive_router_end_es_notify(xrtr, end_blk, end_idx,
  1654. &end, END_W1_ESe)) {
  1655. return;
  1656. }
  1657. }
  1658. trace_xive_router_end_escalate(end_blk, end_idx,
  1659. (uint8_t) xive_get_field32(END_W4_ESC_END_BLOCK, end.w4),
  1660. (uint32_t) xive_get_field32(END_W4_ESC_END_INDEX, end.w4),
  1661. (uint32_t) xive_get_field32(END_W5_ESC_END_DATA, end.w5));
  1662. /*
  1663. * The END trigger becomes an Escalation trigger
  1664. */
  1665. xive_router_end_notify_handler(xrtr, (XiveEAS *) &end.w4);
  1666. }
  1667. void xive_router_notify(XiveNotifier *xn, uint32_t lisn, bool pq_checked)
  1668. {
  1669. XiveRouter *xrtr = XIVE_ROUTER(xn);
  1670. uint8_t eas_blk = XIVE_EAS_BLOCK(lisn);
  1671. uint32_t eas_idx = XIVE_EAS_INDEX(lisn);
  1672. XiveEAS eas;
  1673. /* EAS cache lookup */
  1674. if (xive_router_get_eas(xrtr, eas_blk, eas_idx, &eas)) {
  1675. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN %x\n", lisn);
  1676. return;
  1677. }
  1678. if (!pq_checked) {
  1679. bool notify;
  1680. uint8_t pq;
  1681. /* PQ cache lookup */
  1682. if (xive_router_get_pq(xrtr, eas_blk, eas_idx, &pq)) {
  1683. /* Set FIR */
  1684. g_assert_not_reached();
  1685. }
  1686. notify = xive_esb_trigger(&pq);
  1687. if (xive_router_set_pq(xrtr, eas_blk, eas_idx, &pq)) {
  1688. /* Set FIR */
  1689. g_assert_not_reached();
  1690. }
  1691. if (!notify) {
  1692. return;
  1693. }
  1694. }
  1695. if (!xive_eas_is_valid(&eas)) {
  1696. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid LISN %x\n", lisn);
  1697. return;
  1698. }
  1699. if (xive_eas_is_masked(&eas)) {
  1700. /* Notification completed */
  1701. return;
  1702. }
  1703. /*
  1704. * The event trigger becomes an END trigger
  1705. */
  1706. xive_router_end_notify_handler(xrtr, &eas);
  1707. }
  1708. static const Property xive_router_properties[] = {
  1709. DEFINE_PROP_LINK("xive-fabric", XiveRouter, xfb,
  1710. TYPE_XIVE_FABRIC, XiveFabric *),
  1711. };
  1712. static void xive_router_class_init(ObjectClass *klass, void *data)
  1713. {
  1714. DeviceClass *dc = DEVICE_CLASS(klass);
  1715. XiveNotifierClass *xnc = XIVE_NOTIFIER_CLASS(klass);
  1716. XiveRouterClass *xrc = XIVE_ROUTER_CLASS(klass);
  1717. dc->desc = "XIVE Router Engine";
  1718. device_class_set_props(dc, xive_router_properties);
  1719. /* Parent is SysBusDeviceClass. No need to call its realize hook */
  1720. dc->realize = xive_router_realize;
  1721. xnc->notify = xive_router_notify;
  1722. /* By default, the router handles END triggers locally */
  1723. xrc->end_notify = xive_router_end_notify;
  1724. }
  1725. static const TypeInfo xive_router_info = {
  1726. .name = TYPE_XIVE_ROUTER,
  1727. .parent = TYPE_SYS_BUS_DEVICE,
  1728. .abstract = true,
  1729. .instance_size = sizeof(XiveRouter),
  1730. .class_size = sizeof(XiveRouterClass),
  1731. .class_init = xive_router_class_init,
  1732. .interfaces = (InterfaceInfo[]) {
  1733. { TYPE_XIVE_NOTIFIER },
  1734. { TYPE_XIVE_PRESENTER },
  1735. { }
  1736. }
  1737. };
  1738. void xive_eas_pic_print_info(XiveEAS *eas, uint32_t lisn, GString *buf)
  1739. {
  1740. if (!xive_eas_is_valid(eas)) {
  1741. return;
  1742. }
  1743. g_string_append_printf(buf, " %08x %s end:%02x/%04x data:%08x\n",
  1744. lisn, xive_eas_is_masked(eas) ? "M" : " ",
  1745. (uint8_t) xive_get_field64(EAS_END_BLOCK, eas->w),
  1746. (uint32_t) xive_get_field64(EAS_END_INDEX, eas->w),
  1747. (uint32_t) xive_get_field64(EAS_END_DATA, eas->w));
  1748. }
  1749. /*
  1750. * END ESB MMIO loads
  1751. */
  1752. static uint64_t xive_end_source_read(void *opaque, hwaddr addr, unsigned size)
  1753. {
  1754. XiveENDSource *xsrc = XIVE_END_SOURCE(opaque);
  1755. uint32_t offset = addr & 0xFFF;
  1756. uint8_t end_blk;
  1757. uint32_t end_idx;
  1758. XiveEND end;
  1759. uint32_t end_esmask;
  1760. uint8_t pq;
  1761. uint64_t ret = -1;
  1762. /*
  1763. * The block id should be deduced from the load address on the END
  1764. * ESB MMIO but our model only supports a single block per XIVE chip.
  1765. */
  1766. end_blk = xive_router_get_block_id(xsrc->xrtr);
  1767. end_idx = addr >> (xsrc->esb_shift + 1);
  1768. trace_xive_end_source_read(end_blk, end_idx, addr);
  1769. if (xive_router_get_end(xsrc->xrtr, end_blk, end_idx, &end)) {
  1770. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: No END %x/%x\n", end_blk,
  1771. end_idx);
  1772. return -1;
  1773. }
  1774. if (!xive_end_is_valid(&end)) {
  1775. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: END %x/%x is invalid\n",
  1776. end_blk, end_idx);
  1777. return -1;
  1778. }
  1779. end_esmask = addr_is_even(addr, xsrc->esb_shift) ? END_W1_ESn : END_W1_ESe;
  1780. pq = xive_get_field32(end_esmask, end.w1);
  1781. switch (offset) {
  1782. case XIVE_ESB_LOAD_EOI ... XIVE_ESB_LOAD_EOI + 0x7FF:
  1783. ret = xive_esb_eoi(&pq);
  1784. /* Forward the source event notification for routing ?? */
  1785. break;
  1786. case XIVE_ESB_GET ... XIVE_ESB_GET + 0x3FF:
  1787. ret = pq;
  1788. break;
  1789. case XIVE_ESB_SET_PQ_00 ... XIVE_ESB_SET_PQ_00 + 0x0FF:
  1790. case XIVE_ESB_SET_PQ_01 ... XIVE_ESB_SET_PQ_01 + 0x0FF:
  1791. case XIVE_ESB_SET_PQ_10 ... XIVE_ESB_SET_PQ_10 + 0x0FF:
  1792. case XIVE_ESB_SET_PQ_11 ... XIVE_ESB_SET_PQ_11 + 0x0FF:
  1793. ret = xive_esb_set(&pq, (offset >> 8) & 0x3);
  1794. break;
  1795. default:
  1796. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid END ESB load addr %d\n",
  1797. offset);
  1798. return -1;
  1799. }
  1800. if (pq != xive_get_field32(end_esmask, end.w1)) {
  1801. end.w1 = xive_set_field32(end_esmask, end.w1, pq);
  1802. xive_router_write_end(xsrc->xrtr, end_blk, end_idx, &end, 1);
  1803. }
  1804. return ret;
  1805. }
  1806. /*
  1807. * END ESB MMIO stores are invalid
  1808. */
  1809. static void xive_end_source_write(void *opaque, hwaddr addr,
  1810. uint64_t value, unsigned size)
  1811. {
  1812. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB write addr 0x%"
  1813. HWADDR_PRIx"\n", addr);
  1814. }
  1815. static const MemoryRegionOps xive_end_source_ops = {
  1816. .read = xive_end_source_read,
  1817. .write = xive_end_source_write,
  1818. .endianness = DEVICE_BIG_ENDIAN,
  1819. .valid = {
  1820. .min_access_size = 1,
  1821. .max_access_size = 8,
  1822. },
  1823. .impl = {
  1824. .min_access_size = 1,
  1825. .max_access_size = 8,
  1826. },
  1827. };
  1828. static void xive_end_source_realize(DeviceState *dev, Error **errp)
  1829. {
  1830. XiveENDSource *xsrc = XIVE_END_SOURCE(dev);
  1831. assert(xsrc->xrtr);
  1832. if (!xsrc->nr_ends) {
  1833. error_setg(errp, "Number of interrupt needs to be greater than 0");
  1834. return;
  1835. }
  1836. if (xsrc->esb_shift != XIVE_ESB_4K &&
  1837. xsrc->esb_shift != XIVE_ESB_64K) {
  1838. error_setg(errp, "Invalid ESB shift setting");
  1839. return;
  1840. }
  1841. /*
  1842. * Each END is assigned an even/odd pair of MMIO pages, the even page
  1843. * manages the ESn field while the odd page manages the ESe field.
  1844. */
  1845. memory_region_init_io(&xsrc->esb_mmio, OBJECT(xsrc),
  1846. &xive_end_source_ops, xsrc, "xive.end",
  1847. (1ull << (xsrc->esb_shift + 1)) * xsrc->nr_ends);
  1848. }
  1849. static const Property xive_end_source_properties[] = {
  1850. DEFINE_PROP_UINT32("nr-ends", XiveENDSource, nr_ends, 0),
  1851. DEFINE_PROP_UINT32("shift", XiveENDSource, esb_shift, XIVE_ESB_64K),
  1852. DEFINE_PROP_LINK("xive", XiveENDSource, xrtr, TYPE_XIVE_ROUTER,
  1853. XiveRouter *),
  1854. };
  1855. static void xive_end_source_class_init(ObjectClass *klass, void *data)
  1856. {
  1857. DeviceClass *dc = DEVICE_CLASS(klass);
  1858. dc->desc = "XIVE END Source";
  1859. device_class_set_props(dc, xive_end_source_properties);
  1860. dc->realize = xive_end_source_realize;
  1861. /*
  1862. * Reason: part of XIVE interrupt controller, needs to be wired up,
  1863. * e.g. by spapr_xive_instance_init().
  1864. */
  1865. dc->user_creatable = false;
  1866. }
  1867. static const TypeInfo xive_end_source_info = {
  1868. .name = TYPE_XIVE_END_SOURCE,
  1869. .parent = TYPE_DEVICE,
  1870. .instance_size = sizeof(XiveENDSource),
  1871. .class_init = xive_end_source_class_init,
  1872. };
  1873. /*
  1874. * XIVE Notifier
  1875. */
  1876. static const TypeInfo xive_notifier_info = {
  1877. .name = TYPE_XIVE_NOTIFIER,
  1878. .parent = TYPE_INTERFACE,
  1879. .class_size = sizeof(XiveNotifierClass),
  1880. };
  1881. /*
  1882. * XIVE Presenter
  1883. */
  1884. static const TypeInfo xive_presenter_info = {
  1885. .name = TYPE_XIVE_PRESENTER,
  1886. .parent = TYPE_INTERFACE,
  1887. .class_size = sizeof(XivePresenterClass),
  1888. };
  1889. /*
  1890. * XIVE Fabric
  1891. */
  1892. static const TypeInfo xive_fabric_info = {
  1893. .name = TYPE_XIVE_FABRIC,
  1894. .parent = TYPE_INTERFACE,
  1895. .class_size = sizeof(XiveFabricClass),
  1896. };
  1897. static void xive_register_types(void)
  1898. {
  1899. type_register_static(&xive_fabric_info);
  1900. type_register_static(&xive_source_info);
  1901. type_register_static(&xive_notifier_info);
  1902. type_register_static(&xive_presenter_info);
  1903. type_register_static(&xive_router_info);
  1904. type_register_static(&xive_end_source_info);
  1905. type_register_static(&xive_tctx_info);
  1906. }
  1907. type_init(xive_register_types)