pnv_xive.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /*
  2. * QEMU PowerPC XIVE interrupt controller model
  3. *
  4. * Copyright (c) 2017-2019, 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 "sysemu/cpus.h"
  15. #include "sysemu/dma.h"
  16. #include "sysemu/reset.h"
  17. #include "monitor/monitor.h"
  18. #include "hw/ppc/fdt.h"
  19. #include "hw/ppc/pnv.h"
  20. #include "hw/ppc/pnv_core.h"
  21. #include "hw/ppc/pnv_xscom.h"
  22. #include "hw/ppc/pnv_xive.h"
  23. #include "hw/ppc/xive_regs.h"
  24. #include "hw/qdev-properties.h"
  25. #include "hw/ppc/ppc.h"
  26. #include <libfdt.h>
  27. #include "pnv_xive_regs.h"
  28. #define XIVE_DEBUG
  29. /*
  30. * Virtual structures table (VST)
  31. */
  32. #define SBE_PER_BYTE 4
  33. typedef struct XiveVstInfo {
  34. const char *name;
  35. uint32_t size;
  36. uint32_t max_blocks;
  37. } XiveVstInfo;
  38. static const XiveVstInfo vst_infos[] = {
  39. [VST_TSEL_IVT] = { "EAT", sizeof(XiveEAS), 16 },
  40. [VST_TSEL_SBE] = { "SBE", 1, 16 },
  41. [VST_TSEL_EQDT] = { "ENDT", sizeof(XiveEND), 16 },
  42. [VST_TSEL_VPDT] = { "VPDT", sizeof(XiveNVT), 32 },
  43. /*
  44. * Interrupt fifo backing store table (not modeled) :
  45. *
  46. * 0 - IPI,
  47. * 1 - HWD,
  48. * 2 - First escalate,
  49. * 3 - Second escalate,
  50. * 4 - Redistribution,
  51. * 5 - IPI cascaded queue ?
  52. */
  53. [VST_TSEL_IRQ] = { "IRQ", 1, 6 },
  54. };
  55. #define xive_error(xive, fmt, ...) \
  56. qemu_log_mask(LOG_GUEST_ERROR, "XIVE[%x] - " fmt "\n", \
  57. (xive)->chip->chip_id, ## __VA_ARGS__);
  58. /*
  59. * QEMU version of the GETFIELD/SETFIELD macros
  60. *
  61. * TODO: It might be better to use the existing extract64() and
  62. * deposit64() but this means that all the register definitions will
  63. * change and become incompatible with the ones found in skiboot.
  64. *
  65. * Keep it as it is for now until we find a common ground.
  66. */
  67. static inline uint64_t GETFIELD(uint64_t mask, uint64_t word)
  68. {
  69. return (word & mask) >> ctz64(mask);
  70. }
  71. static inline uint64_t SETFIELD(uint64_t mask, uint64_t word,
  72. uint64_t value)
  73. {
  74. return (word & ~mask) | ((value << ctz64(mask)) & mask);
  75. }
  76. /*
  77. * Remote access to controllers. HW uses MMIOs. For now, a simple scan
  78. * of the chips is good enough.
  79. *
  80. * TODO: Block scope support
  81. */
  82. static PnvXive *pnv_xive_get_ic(uint8_t blk)
  83. {
  84. PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
  85. int i;
  86. for (i = 0; i < pnv->num_chips; i++) {
  87. Pnv9Chip *chip9 = PNV9_CHIP(pnv->chips[i]);
  88. PnvXive *xive = &chip9->xive;
  89. if (xive->chip->chip_id == blk) {
  90. return xive;
  91. }
  92. }
  93. return NULL;
  94. }
  95. /*
  96. * VST accessors for SBE, EAT, ENDT, NVT
  97. *
  98. * Indirect VST tables are arrays of VSDs pointing to a page (of same
  99. * size). Each page is a direct VST table.
  100. */
  101. #define XIVE_VSD_SIZE 8
  102. /* Indirect page size can be 4K, 64K, 2M, 16M. */
  103. static uint64_t pnv_xive_vst_page_size_allowed(uint32_t page_shift)
  104. {
  105. return page_shift == 12 || page_shift == 16 ||
  106. page_shift == 21 || page_shift == 24;
  107. }
  108. static uint64_t pnv_xive_vst_size(uint64_t vsd)
  109. {
  110. uint64_t vst_tsize = 1ull << (GETFIELD(VSD_TSIZE, vsd) + 12);
  111. /*
  112. * Read the first descriptor to get the page size of the indirect
  113. * table.
  114. */
  115. if (VSD_INDIRECT & vsd) {
  116. uint32_t nr_pages = vst_tsize / XIVE_VSD_SIZE;
  117. uint32_t page_shift;
  118. vsd = ldq_be_dma(&address_space_memory, vsd & VSD_ADDRESS_MASK);
  119. page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  120. if (!pnv_xive_vst_page_size_allowed(page_shift)) {
  121. return 0;
  122. }
  123. return nr_pages * (1ull << page_shift);
  124. }
  125. return vst_tsize;
  126. }
  127. static uint64_t pnv_xive_vst_addr_direct(PnvXive *xive, uint32_t type,
  128. uint64_t vsd, uint32_t idx)
  129. {
  130. const XiveVstInfo *info = &vst_infos[type];
  131. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  132. return vst_addr + idx * info->size;
  133. }
  134. static uint64_t pnv_xive_vst_addr_indirect(PnvXive *xive, uint32_t type,
  135. uint64_t vsd, uint32_t idx)
  136. {
  137. const XiveVstInfo *info = &vst_infos[type];
  138. uint64_t vsd_addr;
  139. uint32_t vsd_idx;
  140. uint32_t page_shift;
  141. uint32_t vst_per_page;
  142. /* Get the page size of the indirect table. */
  143. vsd_addr = vsd & VSD_ADDRESS_MASK;
  144. vsd = ldq_be_dma(&address_space_memory, vsd_addr);
  145. if (!(vsd & VSD_ADDRESS_MASK)) {
  146. xive_error(xive, "VST: invalid %s entry %x !?", info->name, idx);
  147. return 0;
  148. }
  149. page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  150. if (!pnv_xive_vst_page_size_allowed(page_shift)) {
  151. xive_error(xive, "VST: invalid %s page shift %d", info->name,
  152. page_shift);
  153. return 0;
  154. }
  155. vst_per_page = (1ull << page_shift) / info->size;
  156. vsd_idx = idx / vst_per_page;
  157. /* Load the VSD we are looking for, if not already done */
  158. if (vsd_idx) {
  159. vsd_addr = vsd_addr + vsd_idx * XIVE_VSD_SIZE;
  160. vsd = ldq_be_dma(&address_space_memory, vsd_addr);
  161. if (!(vsd & VSD_ADDRESS_MASK)) {
  162. xive_error(xive, "VST: invalid %s entry %x !?", info->name, idx);
  163. return 0;
  164. }
  165. /*
  166. * Check that the pages have a consistent size across the
  167. * indirect table
  168. */
  169. if (page_shift != GETFIELD(VSD_TSIZE, vsd) + 12) {
  170. xive_error(xive, "VST: %s entry %x indirect page size differ !?",
  171. info->name, idx);
  172. return 0;
  173. }
  174. }
  175. return pnv_xive_vst_addr_direct(xive, type, vsd, (idx % vst_per_page));
  176. }
  177. static uint64_t pnv_xive_vst_addr(PnvXive *xive, uint32_t type, uint8_t blk,
  178. uint32_t idx)
  179. {
  180. const XiveVstInfo *info = &vst_infos[type];
  181. uint64_t vsd;
  182. uint32_t idx_max;
  183. if (blk >= info->max_blocks) {
  184. xive_error(xive, "VST: invalid block id %d for VST %s %d !?",
  185. blk, info->name, idx);
  186. return 0;
  187. }
  188. vsd = xive->vsds[type][blk];
  189. /* Remote VST access */
  190. if (GETFIELD(VSD_MODE, vsd) == VSD_MODE_FORWARD) {
  191. xive = pnv_xive_get_ic(blk);
  192. return xive ? pnv_xive_vst_addr(xive, type, blk, idx) : 0;
  193. }
  194. idx_max = pnv_xive_vst_size(vsd) / info->size - 1;
  195. if (idx > idx_max) {
  196. #ifdef XIVE_DEBUG
  197. xive_error(xive, "VST: %s entry %x/%x out of range [ 0 .. %x ] !?",
  198. info->name, blk, idx, idx_max);
  199. #endif
  200. return 0;
  201. }
  202. if (VSD_INDIRECT & vsd) {
  203. return pnv_xive_vst_addr_indirect(xive, type, vsd, idx);
  204. }
  205. return pnv_xive_vst_addr_direct(xive, type, vsd, idx);
  206. }
  207. static int pnv_xive_vst_read(PnvXive *xive, uint32_t type, uint8_t blk,
  208. uint32_t idx, void *data)
  209. {
  210. const XiveVstInfo *info = &vst_infos[type];
  211. uint64_t addr = pnv_xive_vst_addr(xive, type, blk, idx);
  212. if (!addr) {
  213. return -1;
  214. }
  215. cpu_physical_memory_read(addr, data, info->size);
  216. return 0;
  217. }
  218. #define XIVE_VST_WORD_ALL -1
  219. static int pnv_xive_vst_write(PnvXive *xive, uint32_t type, uint8_t blk,
  220. uint32_t idx, void *data, uint32_t word_number)
  221. {
  222. const XiveVstInfo *info = &vst_infos[type];
  223. uint64_t addr = pnv_xive_vst_addr(xive, type, blk, idx);
  224. if (!addr) {
  225. return -1;
  226. }
  227. if (word_number == XIVE_VST_WORD_ALL) {
  228. cpu_physical_memory_write(addr, data, info->size);
  229. } else {
  230. cpu_physical_memory_write(addr + word_number * 4,
  231. data + word_number * 4, 4);
  232. }
  233. return 0;
  234. }
  235. static int pnv_xive_get_end(XiveRouter *xrtr, uint8_t blk, uint32_t idx,
  236. XiveEND *end)
  237. {
  238. return pnv_xive_vst_read(PNV_XIVE(xrtr), VST_TSEL_EQDT, blk, idx, end);
  239. }
  240. static int pnv_xive_write_end(XiveRouter *xrtr, uint8_t blk, uint32_t idx,
  241. XiveEND *end, uint8_t word_number)
  242. {
  243. return pnv_xive_vst_write(PNV_XIVE(xrtr), VST_TSEL_EQDT, blk, idx, end,
  244. word_number);
  245. }
  246. static int pnv_xive_end_update(PnvXive *xive)
  247. {
  248. uint8_t blk = GETFIELD(VC_EQC_CWATCH_BLOCKID,
  249. xive->regs[(VC_EQC_CWATCH_SPEC >> 3)]);
  250. uint32_t idx = GETFIELD(VC_EQC_CWATCH_OFFSET,
  251. xive->regs[(VC_EQC_CWATCH_SPEC >> 3)]);
  252. int i;
  253. uint64_t eqc_watch[4];
  254. for (i = 0; i < ARRAY_SIZE(eqc_watch); i++) {
  255. eqc_watch[i] = cpu_to_be64(xive->regs[(VC_EQC_CWATCH_DAT0 >> 3) + i]);
  256. }
  257. return pnv_xive_vst_write(xive, VST_TSEL_EQDT, blk, idx, eqc_watch,
  258. XIVE_VST_WORD_ALL);
  259. }
  260. static void pnv_xive_end_cache_load(PnvXive *xive)
  261. {
  262. uint8_t blk = GETFIELD(VC_EQC_CWATCH_BLOCKID,
  263. xive->regs[(VC_EQC_CWATCH_SPEC >> 3)]);
  264. uint32_t idx = GETFIELD(VC_EQC_CWATCH_OFFSET,
  265. xive->regs[(VC_EQC_CWATCH_SPEC >> 3)]);
  266. uint64_t eqc_watch[4] = { 0 };
  267. int i;
  268. if (pnv_xive_vst_read(xive, VST_TSEL_EQDT, blk, idx, eqc_watch)) {
  269. xive_error(xive, "VST: no END entry %x/%x !?", blk, idx);
  270. }
  271. for (i = 0; i < ARRAY_SIZE(eqc_watch); i++) {
  272. xive->regs[(VC_EQC_CWATCH_DAT0 >> 3) + i] = be64_to_cpu(eqc_watch[i]);
  273. }
  274. }
  275. static int pnv_xive_get_nvt(XiveRouter *xrtr, uint8_t blk, uint32_t idx,
  276. XiveNVT *nvt)
  277. {
  278. return pnv_xive_vst_read(PNV_XIVE(xrtr), VST_TSEL_VPDT, blk, idx, nvt);
  279. }
  280. static int pnv_xive_write_nvt(XiveRouter *xrtr, uint8_t blk, uint32_t idx,
  281. XiveNVT *nvt, uint8_t word_number)
  282. {
  283. return pnv_xive_vst_write(PNV_XIVE(xrtr), VST_TSEL_VPDT, blk, idx, nvt,
  284. word_number);
  285. }
  286. static int pnv_xive_nvt_update(PnvXive *xive)
  287. {
  288. uint8_t blk = GETFIELD(PC_VPC_CWATCH_BLOCKID,
  289. xive->regs[(PC_VPC_CWATCH_SPEC >> 3)]);
  290. uint32_t idx = GETFIELD(PC_VPC_CWATCH_OFFSET,
  291. xive->regs[(PC_VPC_CWATCH_SPEC >> 3)]);
  292. int i;
  293. uint64_t vpc_watch[8];
  294. for (i = 0; i < ARRAY_SIZE(vpc_watch); i++) {
  295. vpc_watch[i] = cpu_to_be64(xive->regs[(PC_VPC_CWATCH_DAT0 >> 3) + i]);
  296. }
  297. return pnv_xive_vst_write(xive, VST_TSEL_VPDT, blk, idx, vpc_watch,
  298. XIVE_VST_WORD_ALL);
  299. }
  300. static void pnv_xive_nvt_cache_load(PnvXive *xive)
  301. {
  302. uint8_t blk = GETFIELD(PC_VPC_CWATCH_BLOCKID,
  303. xive->regs[(PC_VPC_CWATCH_SPEC >> 3)]);
  304. uint32_t idx = GETFIELD(PC_VPC_CWATCH_OFFSET,
  305. xive->regs[(PC_VPC_CWATCH_SPEC >> 3)]);
  306. uint64_t vpc_watch[8] = { 0 };
  307. int i;
  308. if (pnv_xive_vst_read(xive, VST_TSEL_VPDT, blk, idx, vpc_watch)) {
  309. xive_error(xive, "VST: no NVT entry %x/%x !?", blk, idx);
  310. }
  311. for (i = 0; i < ARRAY_SIZE(vpc_watch); i++) {
  312. xive->regs[(PC_VPC_CWATCH_DAT0 >> 3) + i] = be64_to_cpu(vpc_watch[i]);
  313. }
  314. }
  315. static int pnv_xive_get_eas(XiveRouter *xrtr, uint8_t blk, uint32_t idx,
  316. XiveEAS *eas)
  317. {
  318. PnvXive *xive = PNV_XIVE(xrtr);
  319. if (pnv_xive_get_ic(blk) != xive) {
  320. xive_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx));
  321. return -1;
  322. }
  323. return pnv_xive_vst_read(xive, VST_TSEL_IVT, blk, idx, eas);
  324. }
  325. static XiveTCTX *pnv_xive_get_tctx(XiveRouter *xrtr, CPUState *cs)
  326. {
  327. PowerPCCPU *cpu = POWERPC_CPU(cs);
  328. XiveTCTX *tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  329. PnvXive *xive = NULL;
  330. CPUPPCState *env = &cpu->env;
  331. int pir = env->spr_cb[SPR_PIR].default_value;
  332. /*
  333. * Perform an extra check on the HW thread enablement.
  334. *
  335. * The TIMA is shared among the chips and to identify the chip
  336. * from which the access is being done, we extract the chip id
  337. * from the PIR.
  338. */
  339. xive = pnv_xive_get_ic((pir >> 8) & 0xf);
  340. if (!xive) {
  341. return NULL;
  342. }
  343. if (!(xive->regs[PC_THREAD_EN_REG0 >> 3] & PPC_BIT(pir & 0x3f))) {
  344. xive_error(PNV_XIVE(xrtr), "IC: CPU %x is not enabled", pir);
  345. }
  346. return tctx;
  347. }
  348. /*
  349. * The internal sources (IPIs) of the interrupt controller have no
  350. * knowledge of the XIVE chip on which they reside. Encode the block
  351. * id in the source interrupt number before forwarding the source
  352. * event notification to the Router. This is required on a multichip
  353. * system.
  354. */
  355. static void pnv_xive_notify(XiveNotifier *xn, uint32_t srcno)
  356. {
  357. PnvXive *xive = PNV_XIVE(xn);
  358. uint8_t blk = xive->chip->chip_id;
  359. xive_router_notify(xn, XIVE_EAS(blk, srcno));
  360. }
  361. /*
  362. * XIVE helpers
  363. */
  364. static uint64_t pnv_xive_vc_size(PnvXive *xive)
  365. {
  366. return (~xive->regs[CQ_VC_BARM >> 3] + 1) & CQ_VC_BARM_MASK;
  367. }
  368. static uint64_t pnv_xive_edt_shift(PnvXive *xive)
  369. {
  370. return ctz64(pnv_xive_vc_size(xive) / XIVE_TABLE_EDT_MAX);
  371. }
  372. static uint64_t pnv_xive_pc_size(PnvXive *xive)
  373. {
  374. return (~xive->regs[CQ_PC_BARM >> 3] + 1) & CQ_PC_BARM_MASK;
  375. }
  376. static uint32_t pnv_xive_nr_ipis(PnvXive *xive)
  377. {
  378. uint8_t blk = xive->chip->chip_id;
  379. return pnv_xive_vst_size(xive->vsds[VST_TSEL_SBE][blk]) * SBE_PER_BYTE;
  380. }
  381. static uint32_t pnv_xive_nr_ends(PnvXive *xive)
  382. {
  383. uint8_t blk = xive->chip->chip_id;
  384. return pnv_xive_vst_size(xive->vsds[VST_TSEL_EQDT][blk])
  385. / vst_infos[VST_TSEL_EQDT].size;
  386. }
  387. /*
  388. * EDT Table
  389. *
  390. * The Virtualization Controller MMIO region containing the IPI ESB
  391. * pages and END ESB pages is sub-divided into "sets" which map
  392. * portions of the VC region to the different ESB pages. It is
  393. * configured at runtime through the EDT "Domain Table" to let the
  394. * firmware decide how to split the VC address space between IPI ESB
  395. * pages and END ESB pages.
  396. */
  397. /*
  398. * Computes the overall size of the IPI or the END ESB pages
  399. */
  400. static uint64_t pnv_xive_edt_size(PnvXive *xive, uint64_t type)
  401. {
  402. uint64_t edt_size = 1ull << pnv_xive_edt_shift(xive);
  403. uint64_t size = 0;
  404. int i;
  405. for (i = 0; i < XIVE_TABLE_EDT_MAX; i++) {
  406. uint64_t edt_type = GETFIELD(CQ_TDR_EDT_TYPE, xive->edt[i]);
  407. if (edt_type == type) {
  408. size += edt_size;
  409. }
  410. }
  411. return size;
  412. }
  413. /*
  414. * Maps an offset of the VC region in the IPI or END region using the
  415. * layout defined by the EDT "Domaine Table"
  416. */
  417. static uint64_t pnv_xive_edt_offset(PnvXive *xive, uint64_t vc_offset,
  418. uint64_t type)
  419. {
  420. int i;
  421. uint64_t edt_size = 1ull << pnv_xive_edt_shift(xive);
  422. uint64_t edt_offset = vc_offset;
  423. for (i = 0; i < XIVE_TABLE_EDT_MAX && (i * edt_size) < vc_offset; i++) {
  424. uint64_t edt_type = GETFIELD(CQ_TDR_EDT_TYPE, xive->edt[i]);
  425. if (edt_type != type) {
  426. edt_offset -= edt_size;
  427. }
  428. }
  429. return edt_offset;
  430. }
  431. static void pnv_xive_edt_resize(PnvXive *xive)
  432. {
  433. uint64_t ipi_edt_size = pnv_xive_edt_size(xive, CQ_TDR_EDT_IPI);
  434. uint64_t end_edt_size = pnv_xive_edt_size(xive, CQ_TDR_EDT_EQ);
  435. memory_region_set_size(&xive->ipi_edt_mmio, ipi_edt_size);
  436. memory_region_add_subregion(&xive->ipi_mmio, 0, &xive->ipi_edt_mmio);
  437. memory_region_set_size(&xive->end_edt_mmio, end_edt_size);
  438. memory_region_add_subregion(&xive->end_mmio, 0, &xive->end_edt_mmio);
  439. }
  440. /*
  441. * XIVE Table configuration. Only EDT is supported.
  442. */
  443. static int pnv_xive_table_set_data(PnvXive *xive, uint64_t val)
  444. {
  445. uint64_t tsel = xive->regs[CQ_TAR >> 3] & CQ_TAR_TSEL;
  446. uint8_t tsel_index = GETFIELD(CQ_TAR_TSEL_INDEX, xive->regs[CQ_TAR >> 3]);
  447. uint64_t *xive_table;
  448. uint8_t max_index;
  449. switch (tsel) {
  450. case CQ_TAR_TSEL_BLK:
  451. max_index = ARRAY_SIZE(xive->blk);
  452. xive_table = xive->blk;
  453. break;
  454. case CQ_TAR_TSEL_MIG:
  455. max_index = ARRAY_SIZE(xive->mig);
  456. xive_table = xive->mig;
  457. break;
  458. case CQ_TAR_TSEL_EDT:
  459. max_index = ARRAY_SIZE(xive->edt);
  460. xive_table = xive->edt;
  461. break;
  462. case CQ_TAR_TSEL_VDT:
  463. max_index = ARRAY_SIZE(xive->vdt);
  464. xive_table = xive->vdt;
  465. break;
  466. default:
  467. xive_error(xive, "IC: invalid table %d", (int) tsel);
  468. return -1;
  469. }
  470. if (tsel_index >= max_index) {
  471. xive_error(xive, "IC: invalid index %d", (int) tsel_index);
  472. return -1;
  473. }
  474. xive_table[tsel_index] = val;
  475. if (xive->regs[CQ_TAR >> 3] & CQ_TAR_TBL_AUTOINC) {
  476. xive->regs[CQ_TAR >> 3] =
  477. SETFIELD(CQ_TAR_TSEL_INDEX, xive->regs[CQ_TAR >> 3], ++tsel_index);
  478. }
  479. /*
  480. * EDT configuration is complete. Resize the MMIO windows exposing
  481. * the IPI and the END ESBs in the VC region.
  482. */
  483. if (tsel == CQ_TAR_TSEL_EDT && tsel_index == ARRAY_SIZE(xive->edt)) {
  484. pnv_xive_edt_resize(xive);
  485. }
  486. return 0;
  487. }
  488. /*
  489. * Virtual Structure Tables (VST) configuration
  490. */
  491. static void pnv_xive_vst_set_exclusive(PnvXive *xive, uint8_t type,
  492. uint8_t blk, uint64_t vsd)
  493. {
  494. XiveENDSource *end_xsrc = &xive->end_source;
  495. XiveSource *xsrc = &xive->ipi_source;
  496. const XiveVstInfo *info = &vst_infos[type];
  497. uint32_t page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  498. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  499. /* Basic checks */
  500. if (VSD_INDIRECT & vsd) {
  501. if (!(xive->regs[VC_GLOBAL_CONFIG >> 3] & VC_GCONF_INDIRECT)) {
  502. xive_error(xive, "VST: %s indirect tables are not enabled",
  503. info->name);
  504. return;
  505. }
  506. if (!pnv_xive_vst_page_size_allowed(page_shift)) {
  507. xive_error(xive, "VST: invalid %s page shift %d", info->name,
  508. page_shift);
  509. return;
  510. }
  511. }
  512. if (!QEMU_IS_ALIGNED(vst_addr, 1ull << page_shift)) {
  513. xive_error(xive, "VST: %s table address 0x%"PRIx64" is not aligned with"
  514. " page shift %d", info->name, vst_addr, page_shift);
  515. return;
  516. }
  517. /* Record the table configuration (in SRAM on HW) */
  518. xive->vsds[type][blk] = vsd;
  519. /* Now tune the models with the configuration provided by the FW */
  520. switch (type) {
  521. case VST_TSEL_IVT: /* Nothing to be done */
  522. break;
  523. case VST_TSEL_EQDT:
  524. /*
  525. * Backing store pages for the END. Compute the number of ENDs
  526. * provisioned by FW and resize the END ESB window accordingly.
  527. */
  528. memory_region_set_size(&end_xsrc->esb_mmio, pnv_xive_nr_ends(xive) *
  529. (1ull << (end_xsrc->esb_shift + 1)));
  530. memory_region_add_subregion(&xive->end_edt_mmio, 0,
  531. &end_xsrc->esb_mmio);
  532. break;
  533. case VST_TSEL_SBE:
  534. /*
  535. * Backing store pages for the source PQ bits. The model does
  536. * not use these PQ bits backed in RAM because the XiveSource
  537. * model has its own. Compute the number of IRQs provisioned
  538. * by FW and resize the IPI ESB window accordingly.
  539. */
  540. memory_region_set_size(&xsrc->esb_mmio, pnv_xive_nr_ipis(xive) *
  541. (1ull << xsrc->esb_shift));
  542. memory_region_add_subregion(&xive->ipi_edt_mmio, 0, &xsrc->esb_mmio);
  543. break;
  544. case VST_TSEL_VPDT: /* Not modeled */
  545. case VST_TSEL_IRQ: /* Not modeled */
  546. /*
  547. * These tables contains the backing store pages for the
  548. * interrupt fifos of the VC sub-engine in case of overflow.
  549. */
  550. break;
  551. default:
  552. g_assert_not_reached();
  553. }
  554. }
  555. /*
  556. * Both PC and VC sub-engines are configured as each use the Virtual
  557. * Structure Tables : SBE, EAS, END and NVT.
  558. */
  559. static void pnv_xive_vst_set_data(PnvXive *xive, uint64_t vsd, bool pc_engine)
  560. {
  561. uint8_t mode = GETFIELD(VSD_MODE, vsd);
  562. uint8_t type = GETFIELD(VST_TABLE_SELECT,
  563. xive->regs[VC_VSD_TABLE_ADDR >> 3]);
  564. uint8_t blk = GETFIELD(VST_TABLE_BLOCK,
  565. xive->regs[VC_VSD_TABLE_ADDR >> 3]);
  566. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  567. if (type > VST_TSEL_IRQ) {
  568. xive_error(xive, "VST: invalid table type %d", type);
  569. return;
  570. }
  571. if (blk >= vst_infos[type].max_blocks) {
  572. xive_error(xive, "VST: invalid block id %d for"
  573. " %s table", blk, vst_infos[type].name);
  574. return;
  575. }
  576. /*
  577. * Only take the VC sub-engine configuration into account because
  578. * the XiveRouter model combines both VC and PC sub-engines
  579. */
  580. if (pc_engine) {
  581. return;
  582. }
  583. if (!vst_addr) {
  584. xive_error(xive, "VST: invalid %s table address", vst_infos[type].name);
  585. return;
  586. }
  587. switch (mode) {
  588. case VSD_MODE_FORWARD:
  589. xive->vsds[type][blk] = vsd;
  590. break;
  591. case VSD_MODE_EXCLUSIVE:
  592. pnv_xive_vst_set_exclusive(xive, type, blk, vsd);
  593. break;
  594. default:
  595. xive_error(xive, "VST: unsupported table mode %d", mode);
  596. return;
  597. }
  598. }
  599. /*
  600. * Interrupt controller MMIO region. The layout is compatible between
  601. * 4K and 64K pages :
  602. *
  603. * Page 0 sub-engine BARs
  604. * 0x000 - 0x3FF IC registers
  605. * 0x400 - 0x7FF PC registers
  606. * 0x800 - 0xFFF VC registers
  607. *
  608. * Page 1 Notify page (writes only)
  609. * 0x000 - 0x7FF HW interrupt triggers (PSI, PHB)
  610. * 0x800 - 0xFFF forwards and syncs
  611. *
  612. * Page 2 LSI Trigger page (writes only) (not modeled)
  613. * Page 3 LSI SB EOI page (reads only) (not modeled)
  614. *
  615. * Page 4-7 indirect TIMA
  616. */
  617. /*
  618. * IC - registers MMIO
  619. */
  620. static void pnv_xive_ic_reg_write(void *opaque, hwaddr offset,
  621. uint64_t val, unsigned size)
  622. {
  623. PnvXive *xive = PNV_XIVE(opaque);
  624. MemoryRegion *sysmem = get_system_memory();
  625. uint32_t reg = offset >> 3;
  626. bool is_chip0 = xive->chip->chip_id == 0;
  627. switch (offset) {
  628. /*
  629. * XIVE CQ (PowerBus bridge) settings
  630. */
  631. case CQ_MSGSND: /* msgsnd for doorbells */
  632. case CQ_FIRMASK_OR: /* FIR error reporting */
  633. break;
  634. case CQ_PBI_CTL:
  635. if (val & CQ_PBI_PC_64K) {
  636. xive->pc_shift = 16;
  637. }
  638. if (val & CQ_PBI_VC_64K) {
  639. xive->vc_shift = 16;
  640. }
  641. break;
  642. case CQ_CFG_PB_GEN: /* PowerBus General Configuration */
  643. /*
  644. * TODO: CQ_INT_ADDR_OPT for 1-block-per-chip mode
  645. */
  646. break;
  647. /*
  648. * XIVE Virtualization Controller settings
  649. */
  650. case VC_GLOBAL_CONFIG:
  651. break;
  652. /*
  653. * XIVE Presenter Controller settings
  654. */
  655. case PC_GLOBAL_CONFIG:
  656. /*
  657. * PC_GCONF_CHIPID_OVR
  658. * Overrides Int command Chip ID with the Chip ID field (DEBUG)
  659. */
  660. break;
  661. case PC_TCTXT_CFG:
  662. /*
  663. * TODO: block group support
  664. *
  665. * PC_TCTXT_CFG_BLKGRP_EN
  666. * PC_TCTXT_CFG_HARD_CHIPID_BLK :
  667. * Moves the chipid into block field for hardwired CAM compares.
  668. * Block offset value is adjusted to 0b0..01 & ThrdId
  669. *
  670. * Will require changes in xive_presenter_tctx_match(). I am
  671. * not sure how to handle that yet.
  672. */
  673. /* Overrides hardwired chip ID with the chip ID field */
  674. if (val & PC_TCTXT_CHIPID_OVERRIDE) {
  675. xive->tctx_chipid = GETFIELD(PC_TCTXT_CHIPID, val);
  676. }
  677. break;
  678. case PC_TCTXT_TRACK:
  679. /*
  680. * PC_TCTXT_TRACK_EN:
  681. * enable block tracking and exchange of block ownership
  682. * information between Interrupt controllers
  683. */
  684. break;
  685. /*
  686. * Misc settings
  687. */
  688. case VC_SBC_CONFIG: /* Store EOI configuration */
  689. /*
  690. * Configure store EOI if required by firwmare (skiboot has removed
  691. * support recently though)
  692. */
  693. if (val & (VC_SBC_CONF_CPLX_CIST | VC_SBC_CONF_CIST_BOTH)) {
  694. xive->ipi_source.esb_flags |= XIVE_SRC_STORE_EOI;
  695. }
  696. break;
  697. case VC_EQC_CONFIG: /* TODO: silent escalation */
  698. case VC_AIB_TX_ORDER_TAG2: /* relax ordering */
  699. break;
  700. /*
  701. * XIVE BAR settings (XSCOM only)
  702. */
  703. case CQ_RST_CTL:
  704. /* bit4: resets all BAR registers */
  705. break;
  706. case CQ_IC_BAR: /* IC BAR. 8 pages */
  707. xive->ic_shift = val & CQ_IC_BAR_64K ? 16 : 12;
  708. if (!(val & CQ_IC_BAR_VALID)) {
  709. xive->ic_base = 0;
  710. if (xive->regs[reg] & CQ_IC_BAR_VALID) {
  711. memory_region_del_subregion(&xive->ic_mmio,
  712. &xive->ic_reg_mmio);
  713. memory_region_del_subregion(&xive->ic_mmio,
  714. &xive->ic_notify_mmio);
  715. memory_region_del_subregion(&xive->ic_mmio,
  716. &xive->ic_lsi_mmio);
  717. memory_region_del_subregion(&xive->ic_mmio,
  718. &xive->tm_indirect_mmio);
  719. memory_region_del_subregion(sysmem, &xive->ic_mmio);
  720. }
  721. } else {
  722. xive->ic_base = val & ~(CQ_IC_BAR_VALID | CQ_IC_BAR_64K);
  723. if (!(xive->regs[reg] & CQ_IC_BAR_VALID)) {
  724. memory_region_add_subregion(sysmem, xive->ic_base,
  725. &xive->ic_mmio);
  726. memory_region_add_subregion(&xive->ic_mmio, 0,
  727. &xive->ic_reg_mmio);
  728. memory_region_add_subregion(&xive->ic_mmio,
  729. 1ul << xive->ic_shift,
  730. &xive->ic_notify_mmio);
  731. memory_region_add_subregion(&xive->ic_mmio,
  732. 2ul << xive->ic_shift,
  733. &xive->ic_lsi_mmio);
  734. memory_region_add_subregion(&xive->ic_mmio,
  735. 4ull << xive->ic_shift,
  736. &xive->tm_indirect_mmio);
  737. }
  738. }
  739. break;
  740. case CQ_TM1_BAR: /* TM BAR. 4 pages. Map only once */
  741. case CQ_TM2_BAR: /* second TM BAR. for hotplug. Not modeled */
  742. xive->tm_shift = val & CQ_TM_BAR_64K ? 16 : 12;
  743. if (!(val & CQ_TM_BAR_VALID)) {
  744. xive->tm_base = 0;
  745. if (xive->regs[reg] & CQ_TM_BAR_VALID && is_chip0) {
  746. memory_region_del_subregion(sysmem, &xive->tm_mmio);
  747. }
  748. } else {
  749. xive->tm_base = val & ~(CQ_TM_BAR_VALID | CQ_TM_BAR_64K);
  750. if (!(xive->regs[reg] & CQ_TM_BAR_VALID) && is_chip0) {
  751. memory_region_add_subregion(sysmem, xive->tm_base,
  752. &xive->tm_mmio);
  753. }
  754. }
  755. break;
  756. case CQ_PC_BARM:
  757. xive->regs[reg] = val;
  758. memory_region_set_size(&xive->pc_mmio, pnv_xive_pc_size(xive));
  759. break;
  760. case CQ_PC_BAR: /* From 32M to 512G */
  761. if (!(val & CQ_PC_BAR_VALID)) {
  762. xive->pc_base = 0;
  763. if (xive->regs[reg] & CQ_PC_BAR_VALID) {
  764. memory_region_del_subregion(sysmem, &xive->pc_mmio);
  765. }
  766. } else {
  767. xive->pc_base = val & ~(CQ_PC_BAR_VALID);
  768. if (!(xive->regs[reg] & CQ_PC_BAR_VALID)) {
  769. memory_region_add_subregion(sysmem, xive->pc_base,
  770. &xive->pc_mmio);
  771. }
  772. }
  773. break;
  774. case CQ_VC_BARM:
  775. xive->regs[reg] = val;
  776. memory_region_set_size(&xive->vc_mmio, pnv_xive_vc_size(xive));
  777. break;
  778. case CQ_VC_BAR: /* From 64M to 4TB */
  779. if (!(val & CQ_VC_BAR_VALID)) {
  780. xive->vc_base = 0;
  781. if (xive->regs[reg] & CQ_VC_BAR_VALID) {
  782. memory_region_del_subregion(sysmem, &xive->vc_mmio);
  783. }
  784. } else {
  785. xive->vc_base = val & ~(CQ_VC_BAR_VALID);
  786. if (!(xive->regs[reg] & CQ_VC_BAR_VALID)) {
  787. memory_region_add_subregion(sysmem, xive->vc_base,
  788. &xive->vc_mmio);
  789. }
  790. }
  791. break;
  792. /*
  793. * XIVE Table settings.
  794. */
  795. case CQ_TAR: /* Table Address */
  796. break;
  797. case CQ_TDR: /* Table Data */
  798. pnv_xive_table_set_data(xive, val);
  799. break;
  800. /*
  801. * XIVE VC & PC Virtual Structure Table settings
  802. */
  803. case VC_VSD_TABLE_ADDR:
  804. case PC_VSD_TABLE_ADDR: /* Virtual table selector */
  805. break;
  806. case VC_VSD_TABLE_DATA: /* Virtual table setting */
  807. case PC_VSD_TABLE_DATA:
  808. pnv_xive_vst_set_data(xive, val, offset == PC_VSD_TABLE_DATA);
  809. break;
  810. /*
  811. * Interrupt fifo overflow in memory backing store (Not modeled)
  812. */
  813. case VC_IRQ_CONFIG_IPI:
  814. case VC_IRQ_CONFIG_HW:
  815. case VC_IRQ_CONFIG_CASCADE1:
  816. case VC_IRQ_CONFIG_CASCADE2:
  817. case VC_IRQ_CONFIG_REDIST:
  818. case VC_IRQ_CONFIG_IPI_CASC:
  819. break;
  820. /*
  821. * XIVE hardware thread enablement
  822. */
  823. case PC_THREAD_EN_REG0: /* Physical Thread Enable */
  824. case PC_THREAD_EN_REG1: /* Physical Thread Enable (fused core) */
  825. break;
  826. case PC_THREAD_EN_REG0_SET:
  827. xive->regs[PC_THREAD_EN_REG0 >> 3] |= val;
  828. break;
  829. case PC_THREAD_EN_REG1_SET:
  830. xive->regs[PC_THREAD_EN_REG1 >> 3] |= val;
  831. break;
  832. case PC_THREAD_EN_REG0_CLR:
  833. xive->regs[PC_THREAD_EN_REG0 >> 3] &= ~val;
  834. break;
  835. case PC_THREAD_EN_REG1_CLR:
  836. xive->regs[PC_THREAD_EN_REG1 >> 3] &= ~val;
  837. break;
  838. /*
  839. * Indirect TIMA access set up. Defines the PIR of the HW thread
  840. * to use.
  841. */
  842. case PC_TCTXT_INDIR0 ... PC_TCTXT_INDIR3:
  843. break;
  844. /*
  845. * XIVE PC & VC cache updates for EAS, NVT and END
  846. */
  847. case VC_IVC_SCRUB_MASK:
  848. case VC_IVC_SCRUB_TRIG:
  849. break;
  850. case VC_EQC_CWATCH_SPEC:
  851. val &= ~VC_EQC_CWATCH_CONFLICT; /* HW resets this bit */
  852. break;
  853. case VC_EQC_CWATCH_DAT1 ... VC_EQC_CWATCH_DAT3:
  854. break;
  855. case VC_EQC_CWATCH_DAT0:
  856. /* writing to DATA0 triggers the cache write */
  857. xive->regs[reg] = val;
  858. pnv_xive_end_update(xive);
  859. break;
  860. case VC_EQC_SCRUB_MASK:
  861. case VC_EQC_SCRUB_TRIG:
  862. /*
  863. * The scrubbing registers flush the cache in RAM and can also
  864. * invalidate.
  865. */
  866. break;
  867. case PC_VPC_CWATCH_SPEC:
  868. val &= ~PC_VPC_CWATCH_CONFLICT; /* HW resets this bit */
  869. break;
  870. case PC_VPC_CWATCH_DAT1 ... PC_VPC_CWATCH_DAT7:
  871. break;
  872. case PC_VPC_CWATCH_DAT0:
  873. /* writing to DATA0 triggers the cache write */
  874. xive->regs[reg] = val;
  875. pnv_xive_nvt_update(xive);
  876. break;
  877. case PC_VPC_SCRUB_MASK:
  878. case PC_VPC_SCRUB_TRIG:
  879. /*
  880. * The scrubbing registers flush the cache in RAM and can also
  881. * invalidate.
  882. */
  883. break;
  884. /*
  885. * XIVE PC & VC cache invalidation
  886. */
  887. case PC_AT_KILL:
  888. break;
  889. case VC_AT_MACRO_KILL:
  890. break;
  891. case PC_AT_KILL_MASK:
  892. case VC_AT_MACRO_KILL_MASK:
  893. break;
  894. default:
  895. xive_error(xive, "IC: invalid write to reg=0x%"HWADDR_PRIx, offset);
  896. return;
  897. }
  898. xive->regs[reg] = val;
  899. }
  900. static uint64_t pnv_xive_ic_reg_read(void *opaque, hwaddr offset, unsigned size)
  901. {
  902. PnvXive *xive = PNV_XIVE(opaque);
  903. uint64_t val = 0;
  904. uint32_t reg = offset >> 3;
  905. switch (offset) {
  906. case CQ_CFG_PB_GEN:
  907. case CQ_IC_BAR:
  908. case CQ_TM1_BAR:
  909. case CQ_TM2_BAR:
  910. case CQ_PC_BAR:
  911. case CQ_PC_BARM:
  912. case CQ_VC_BAR:
  913. case CQ_VC_BARM:
  914. case CQ_TAR:
  915. case CQ_TDR:
  916. case CQ_PBI_CTL:
  917. case PC_TCTXT_CFG:
  918. case PC_TCTXT_TRACK:
  919. case PC_TCTXT_INDIR0:
  920. case PC_TCTXT_INDIR1:
  921. case PC_TCTXT_INDIR2:
  922. case PC_TCTXT_INDIR3:
  923. case PC_GLOBAL_CONFIG:
  924. case PC_VPC_SCRUB_MASK:
  925. case VC_GLOBAL_CONFIG:
  926. case VC_AIB_TX_ORDER_TAG2:
  927. case VC_IRQ_CONFIG_IPI:
  928. case VC_IRQ_CONFIG_HW:
  929. case VC_IRQ_CONFIG_CASCADE1:
  930. case VC_IRQ_CONFIG_CASCADE2:
  931. case VC_IRQ_CONFIG_REDIST:
  932. case VC_IRQ_CONFIG_IPI_CASC:
  933. case VC_EQC_SCRUB_MASK:
  934. case VC_IVC_SCRUB_MASK:
  935. case VC_SBC_CONFIG:
  936. case VC_AT_MACRO_KILL_MASK:
  937. case VC_VSD_TABLE_ADDR:
  938. case PC_VSD_TABLE_ADDR:
  939. case VC_VSD_TABLE_DATA:
  940. case PC_VSD_TABLE_DATA:
  941. case PC_THREAD_EN_REG0:
  942. case PC_THREAD_EN_REG1:
  943. val = xive->regs[reg];
  944. break;
  945. /*
  946. * XIVE hardware thread enablement
  947. */
  948. case PC_THREAD_EN_REG0_SET:
  949. case PC_THREAD_EN_REG0_CLR:
  950. val = xive->regs[PC_THREAD_EN_REG0 >> 3];
  951. break;
  952. case PC_THREAD_EN_REG1_SET:
  953. case PC_THREAD_EN_REG1_CLR:
  954. val = xive->regs[PC_THREAD_EN_REG1 >> 3];
  955. break;
  956. case CQ_MSGSND: /* Identifies which cores have msgsnd enabled. */
  957. val = 0xffffff0000000000;
  958. break;
  959. /*
  960. * XIVE PC & VC cache updates for EAS, NVT and END
  961. */
  962. case VC_EQC_CWATCH_SPEC:
  963. xive->regs[reg] = ~(VC_EQC_CWATCH_FULL | VC_EQC_CWATCH_CONFLICT);
  964. val = xive->regs[reg];
  965. break;
  966. case VC_EQC_CWATCH_DAT0:
  967. /*
  968. * Load DATA registers from cache with data requested by the
  969. * SPEC register
  970. */
  971. pnv_xive_end_cache_load(xive);
  972. val = xive->regs[reg];
  973. break;
  974. case VC_EQC_CWATCH_DAT1 ... VC_EQC_CWATCH_DAT3:
  975. val = xive->regs[reg];
  976. break;
  977. case PC_VPC_CWATCH_SPEC:
  978. xive->regs[reg] = ~(PC_VPC_CWATCH_FULL | PC_VPC_CWATCH_CONFLICT);
  979. val = xive->regs[reg];
  980. break;
  981. case PC_VPC_CWATCH_DAT0:
  982. /*
  983. * Load DATA registers from cache with data requested by the
  984. * SPEC register
  985. */
  986. pnv_xive_nvt_cache_load(xive);
  987. val = xive->regs[reg];
  988. break;
  989. case PC_VPC_CWATCH_DAT1 ... PC_VPC_CWATCH_DAT7:
  990. val = xive->regs[reg];
  991. break;
  992. case PC_VPC_SCRUB_TRIG:
  993. case VC_IVC_SCRUB_TRIG:
  994. case VC_EQC_SCRUB_TRIG:
  995. xive->regs[reg] &= ~VC_SCRUB_VALID;
  996. val = xive->regs[reg];
  997. break;
  998. /*
  999. * XIVE PC & VC cache invalidation
  1000. */
  1001. case PC_AT_KILL:
  1002. xive->regs[reg] &= ~PC_AT_KILL_VALID;
  1003. val = xive->regs[reg];
  1004. break;
  1005. case VC_AT_MACRO_KILL:
  1006. xive->regs[reg] &= ~VC_KILL_VALID;
  1007. val = xive->regs[reg];
  1008. break;
  1009. /*
  1010. * XIVE synchronisation
  1011. */
  1012. case VC_EQC_CONFIG:
  1013. val = VC_EQC_SYNC_MASK;
  1014. break;
  1015. default:
  1016. xive_error(xive, "IC: invalid read reg=0x%"HWADDR_PRIx, offset);
  1017. }
  1018. return val;
  1019. }
  1020. static const MemoryRegionOps pnv_xive_ic_reg_ops = {
  1021. .read = pnv_xive_ic_reg_read,
  1022. .write = pnv_xive_ic_reg_write,
  1023. .endianness = DEVICE_BIG_ENDIAN,
  1024. .valid = {
  1025. .min_access_size = 8,
  1026. .max_access_size = 8,
  1027. },
  1028. .impl = {
  1029. .min_access_size = 8,
  1030. .max_access_size = 8,
  1031. },
  1032. };
  1033. /*
  1034. * IC - Notify MMIO port page (write only)
  1035. */
  1036. #define PNV_XIVE_FORWARD_IPI 0x800 /* Forward IPI */
  1037. #define PNV_XIVE_FORWARD_HW 0x880 /* Forward HW */
  1038. #define PNV_XIVE_FORWARD_OS_ESC 0x900 /* Forward OS escalation */
  1039. #define PNV_XIVE_FORWARD_HW_ESC 0x980 /* Forward Hyp escalation */
  1040. #define PNV_XIVE_FORWARD_REDIS 0xa00 /* Forward Redistribution */
  1041. #define PNV_XIVE_RESERVED5 0xa80 /* Cache line 5 PowerBUS operation */
  1042. #define PNV_XIVE_RESERVED6 0xb00 /* Cache line 6 PowerBUS operation */
  1043. #define PNV_XIVE_RESERVED7 0xb80 /* Cache line 7 PowerBUS operation */
  1044. /* VC synchronisation */
  1045. #define PNV_XIVE_SYNC_IPI 0xc00 /* Sync IPI */
  1046. #define PNV_XIVE_SYNC_HW 0xc80 /* Sync HW */
  1047. #define PNV_XIVE_SYNC_OS_ESC 0xd00 /* Sync OS escalation */
  1048. #define PNV_XIVE_SYNC_HW_ESC 0xd80 /* Sync Hyp escalation */
  1049. #define PNV_XIVE_SYNC_REDIS 0xe00 /* Sync Redistribution */
  1050. /* PC synchronisation */
  1051. #define PNV_XIVE_SYNC_PULL 0xe80 /* Sync pull context */
  1052. #define PNV_XIVE_SYNC_PUSH 0xf00 /* Sync push context */
  1053. #define PNV_XIVE_SYNC_VPC 0xf80 /* Sync remove VPC store */
  1054. static void pnv_xive_ic_hw_trigger(PnvXive *xive, hwaddr addr, uint64_t val)
  1055. {
  1056. uint8_t blk;
  1057. uint32_t idx;
  1058. if (val & XIVE_TRIGGER_END) {
  1059. xive_error(xive, "IC: END trigger at @0x%"HWADDR_PRIx" data 0x%"PRIx64,
  1060. addr, val);
  1061. return;
  1062. }
  1063. /*
  1064. * Forward the source event notification directly to the Router.
  1065. * The source interrupt number should already be correctly encoded
  1066. * with the chip block id by the sending device (PHB, PSI).
  1067. */
  1068. blk = XIVE_EAS_BLOCK(val);
  1069. idx = XIVE_EAS_INDEX(val);
  1070. xive_router_notify(XIVE_NOTIFIER(xive), XIVE_EAS(blk, idx));
  1071. }
  1072. static void pnv_xive_ic_notify_write(void *opaque, hwaddr addr, uint64_t val,
  1073. unsigned size)
  1074. {
  1075. PnvXive *xive = PNV_XIVE(opaque);
  1076. /* VC: HW triggers */
  1077. switch (addr) {
  1078. case 0x000 ... 0x7FF:
  1079. pnv_xive_ic_hw_trigger(opaque, addr, val);
  1080. break;
  1081. /* VC: Forwarded IRQs */
  1082. case PNV_XIVE_FORWARD_IPI:
  1083. case PNV_XIVE_FORWARD_HW:
  1084. case PNV_XIVE_FORWARD_OS_ESC:
  1085. case PNV_XIVE_FORWARD_HW_ESC:
  1086. case PNV_XIVE_FORWARD_REDIS:
  1087. /* TODO: forwarded IRQs. Should be like HW triggers */
  1088. xive_error(xive, "IC: forwarded at @0x%"HWADDR_PRIx" IRQ 0x%"PRIx64,
  1089. addr, val);
  1090. break;
  1091. /* VC syncs */
  1092. case PNV_XIVE_SYNC_IPI:
  1093. case PNV_XIVE_SYNC_HW:
  1094. case PNV_XIVE_SYNC_OS_ESC:
  1095. case PNV_XIVE_SYNC_HW_ESC:
  1096. case PNV_XIVE_SYNC_REDIS:
  1097. break;
  1098. /* PC syncs */
  1099. case PNV_XIVE_SYNC_PULL:
  1100. case PNV_XIVE_SYNC_PUSH:
  1101. case PNV_XIVE_SYNC_VPC:
  1102. break;
  1103. default:
  1104. xive_error(xive, "IC: invalid notify write @%"HWADDR_PRIx, addr);
  1105. }
  1106. }
  1107. static uint64_t pnv_xive_ic_notify_read(void *opaque, hwaddr addr,
  1108. unsigned size)
  1109. {
  1110. PnvXive *xive = PNV_XIVE(opaque);
  1111. /* loads are invalid */
  1112. xive_error(xive, "IC: invalid notify read @%"HWADDR_PRIx, addr);
  1113. return -1;
  1114. }
  1115. static const MemoryRegionOps pnv_xive_ic_notify_ops = {
  1116. .read = pnv_xive_ic_notify_read,
  1117. .write = pnv_xive_ic_notify_write,
  1118. .endianness = DEVICE_BIG_ENDIAN,
  1119. .valid = {
  1120. .min_access_size = 8,
  1121. .max_access_size = 8,
  1122. },
  1123. .impl = {
  1124. .min_access_size = 8,
  1125. .max_access_size = 8,
  1126. },
  1127. };
  1128. /*
  1129. * IC - LSI MMIO handlers (not modeled)
  1130. */
  1131. static void pnv_xive_ic_lsi_write(void *opaque, hwaddr addr,
  1132. uint64_t val, unsigned size)
  1133. {
  1134. PnvXive *xive = PNV_XIVE(opaque);
  1135. xive_error(xive, "IC: LSI invalid write @%"HWADDR_PRIx, addr);
  1136. }
  1137. static uint64_t pnv_xive_ic_lsi_read(void *opaque, hwaddr addr, unsigned size)
  1138. {
  1139. PnvXive *xive = PNV_XIVE(opaque);
  1140. xive_error(xive, "IC: LSI invalid read @%"HWADDR_PRIx, addr);
  1141. return -1;
  1142. }
  1143. static const MemoryRegionOps pnv_xive_ic_lsi_ops = {
  1144. .read = pnv_xive_ic_lsi_read,
  1145. .write = pnv_xive_ic_lsi_write,
  1146. .endianness = DEVICE_BIG_ENDIAN,
  1147. .valid = {
  1148. .min_access_size = 8,
  1149. .max_access_size = 8,
  1150. },
  1151. .impl = {
  1152. .min_access_size = 8,
  1153. .max_access_size = 8,
  1154. },
  1155. };
  1156. /*
  1157. * IC - Indirect TIMA MMIO handlers
  1158. */
  1159. /*
  1160. * When the TIMA is accessed from the indirect page, the thread id
  1161. * (PIR) has to be configured in the IC registers before. This is used
  1162. * for resets and for debug purpose also.
  1163. */
  1164. static XiveTCTX *pnv_xive_get_indirect_tctx(PnvXive *xive)
  1165. {
  1166. uint64_t tctxt_indir = xive->regs[PC_TCTXT_INDIR0 >> 3];
  1167. PowerPCCPU *cpu = NULL;
  1168. int pir;
  1169. if (!(tctxt_indir & PC_TCTXT_INDIR_VALID)) {
  1170. xive_error(xive, "IC: no indirect TIMA access in progress");
  1171. return NULL;
  1172. }
  1173. pir = GETFIELD(PC_TCTXT_INDIR_THRDID, tctxt_indir) & 0xff;
  1174. cpu = ppc_get_vcpu_by_pir(pir);
  1175. if (!cpu) {
  1176. xive_error(xive, "IC: invalid PIR %x for indirect access", pir);
  1177. return NULL;
  1178. }
  1179. /* Check that HW thread is XIVE enabled */
  1180. if (!(xive->regs[PC_THREAD_EN_REG0 >> 3] & PPC_BIT(pir & 0x3f))) {
  1181. xive_error(xive, "IC: CPU %x is not enabled", pir);
  1182. }
  1183. return XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  1184. }
  1185. static void xive_tm_indirect_write(void *opaque, hwaddr offset,
  1186. uint64_t value, unsigned size)
  1187. {
  1188. XiveTCTX *tctx = pnv_xive_get_indirect_tctx(PNV_XIVE(opaque));
  1189. xive_tctx_tm_write(tctx, offset, value, size);
  1190. }
  1191. static uint64_t xive_tm_indirect_read(void *opaque, hwaddr offset,
  1192. unsigned size)
  1193. {
  1194. XiveTCTX *tctx = pnv_xive_get_indirect_tctx(PNV_XIVE(opaque));
  1195. return xive_tctx_tm_read(tctx, offset, size);
  1196. }
  1197. static const MemoryRegionOps xive_tm_indirect_ops = {
  1198. .read = xive_tm_indirect_read,
  1199. .write = xive_tm_indirect_write,
  1200. .endianness = DEVICE_BIG_ENDIAN,
  1201. .valid = {
  1202. .min_access_size = 1,
  1203. .max_access_size = 8,
  1204. },
  1205. .impl = {
  1206. .min_access_size = 1,
  1207. .max_access_size = 8,
  1208. },
  1209. };
  1210. /*
  1211. * Interrupt controller XSCOM region.
  1212. */
  1213. static uint64_t pnv_xive_xscom_read(void *opaque, hwaddr addr, unsigned size)
  1214. {
  1215. switch (addr >> 3) {
  1216. case X_VC_EQC_CONFIG:
  1217. /* FIXME (skiboot): This is the only XSCOM load. Bizarre. */
  1218. return VC_EQC_SYNC_MASK;
  1219. default:
  1220. return pnv_xive_ic_reg_read(opaque, addr, size);
  1221. }
  1222. }
  1223. static void pnv_xive_xscom_write(void *opaque, hwaddr addr,
  1224. uint64_t val, unsigned size)
  1225. {
  1226. pnv_xive_ic_reg_write(opaque, addr, val, size);
  1227. }
  1228. static const MemoryRegionOps pnv_xive_xscom_ops = {
  1229. .read = pnv_xive_xscom_read,
  1230. .write = pnv_xive_xscom_write,
  1231. .endianness = DEVICE_BIG_ENDIAN,
  1232. .valid = {
  1233. .min_access_size = 8,
  1234. .max_access_size = 8,
  1235. },
  1236. .impl = {
  1237. .min_access_size = 8,
  1238. .max_access_size = 8,
  1239. }
  1240. };
  1241. /*
  1242. * Virtualization Controller MMIO region containing the IPI and END ESB pages
  1243. */
  1244. static uint64_t pnv_xive_vc_read(void *opaque, hwaddr offset,
  1245. unsigned size)
  1246. {
  1247. PnvXive *xive = PNV_XIVE(opaque);
  1248. uint64_t edt_index = offset >> pnv_xive_edt_shift(xive);
  1249. uint64_t edt_type = 0;
  1250. uint64_t edt_offset;
  1251. MemTxResult result;
  1252. AddressSpace *edt_as = NULL;
  1253. uint64_t ret = -1;
  1254. if (edt_index < XIVE_TABLE_EDT_MAX) {
  1255. edt_type = GETFIELD(CQ_TDR_EDT_TYPE, xive->edt[edt_index]);
  1256. }
  1257. switch (edt_type) {
  1258. case CQ_TDR_EDT_IPI:
  1259. edt_as = &xive->ipi_as;
  1260. break;
  1261. case CQ_TDR_EDT_EQ:
  1262. edt_as = &xive->end_as;
  1263. break;
  1264. default:
  1265. xive_error(xive, "VC: invalid EDT type for read @%"HWADDR_PRIx, offset);
  1266. return -1;
  1267. }
  1268. /* Remap the offset for the targeted address space */
  1269. edt_offset = pnv_xive_edt_offset(xive, offset, edt_type);
  1270. ret = address_space_ldq(edt_as, edt_offset, MEMTXATTRS_UNSPECIFIED,
  1271. &result);
  1272. if (result != MEMTX_OK) {
  1273. xive_error(xive, "VC: %s read failed at @0x%"HWADDR_PRIx " -> @0x%"
  1274. HWADDR_PRIx, edt_type == CQ_TDR_EDT_IPI ? "IPI" : "END",
  1275. offset, edt_offset);
  1276. return -1;
  1277. }
  1278. return ret;
  1279. }
  1280. static void pnv_xive_vc_write(void *opaque, hwaddr offset,
  1281. uint64_t val, unsigned size)
  1282. {
  1283. PnvXive *xive = PNV_XIVE(opaque);
  1284. uint64_t edt_index = offset >> pnv_xive_edt_shift(xive);
  1285. uint64_t edt_type = 0;
  1286. uint64_t edt_offset;
  1287. MemTxResult result;
  1288. AddressSpace *edt_as = NULL;
  1289. if (edt_index < XIVE_TABLE_EDT_MAX) {
  1290. edt_type = GETFIELD(CQ_TDR_EDT_TYPE, xive->edt[edt_index]);
  1291. }
  1292. switch (edt_type) {
  1293. case CQ_TDR_EDT_IPI:
  1294. edt_as = &xive->ipi_as;
  1295. break;
  1296. case CQ_TDR_EDT_EQ:
  1297. edt_as = &xive->end_as;
  1298. break;
  1299. default:
  1300. xive_error(xive, "VC: invalid EDT type for write @%"HWADDR_PRIx,
  1301. offset);
  1302. return;
  1303. }
  1304. /* Remap the offset for the targeted address space */
  1305. edt_offset = pnv_xive_edt_offset(xive, offset, edt_type);
  1306. address_space_stq(edt_as, edt_offset, val, MEMTXATTRS_UNSPECIFIED, &result);
  1307. if (result != MEMTX_OK) {
  1308. xive_error(xive, "VC: write failed at @0x%"HWADDR_PRIx, edt_offset);
  1309. }
  1310. }
  1311. static const MemoryRegionOps pnv_xive_vc_ops = {
  1312. .read = pnv_xive_vc_read,
  1313. .write = pnv_xive_vc_write,
  1314. .endianness = DEVICE_BIG_ENDIAN,
  1315. .valid = {
  1316. .min_access_size = 8,
  1317. .max_access_size = 8,
  1318. },
  1319. .impl = {
  1320. .min_access_size = 8,
  1321. .max_access_size = 8,
  1322. },
  1323. };
  1324. /*
  1325. * Presenter Controller MMIO region. The Virtualization Controller
  1326. * updates the IPB in the NVT table when required. Not modeled.
  1327. */
  1328. static uint64_t pnv_xive_pc_read(void *opaque, hwaddr addr,
  1329. unsigned size)
  1330. {
  1331. PnvXive *xive = PNV_XIVE(opaque);
  1332. xive_error(xive, "PC: invalid read @%"HWADDR_PRIx, addr);
  1333. return -1;
  1334. }
  1335. static void pnv_xive_pc_write(void *opaque, hwaddr addr,
  1336. uint64_t value, unsigned size)
  1337. {
  1338. PnvXive *xive = PNV_XIVE(opaque);
  1339. xive_error(xive, "PC: invalid write to VC @%"HWADDR_PRIx, addr);
  1340. }
  1341. static const MemoryRegionOps pnv_xive_pc_ops = {
  1342. .read = pnv_xive_pc_read,
  1343. .write = pnv_xive_pc_write,
  1344. .endianness = DEVICE_BIG_ENDIAN,
  1345. .valid = {
  1346. .min_access_size = 8,
  1347. .max_access_size = 8,
  1348. },
  1349. .impl = {
  1350. .min_access_size = 8,
  1351. .max_access_size = 8,
  1352. },
  1353. };
  1354. void pnv_xive_pic_print_info(PnvXive *xive, Monitor *mon)
  1355. {
  1356. XiveRouter *xrtr = XIVE_ROUTER(xive);
  1357. uint8_t blk = xive->chip->chip_id;
  1358. uint32_t srcno0 = XIVE_EAS(blk, 0);
  1359. uint32_t nr_ipis = pnv_xive_nr_ipis(xive);
  1360. uint32_t nr_ends = pnv_xive_nr_ends(xive);
  1361. XiveEAS eas;
  1362. XiveEND end;
  1363. int i;
  1364. monitor_printf(mon, "XIVE[%x] Source %08x .. %08x\n", blk, srcno0,
  1365. srcno0 + nr_ipis - 1);
  1366. xive_source_pic_print_info(&xive->ipi_source, srcno0, mon);
  1367. monitor_printf(mon, "XIVE[%x] EAT %08x .. %08x\n", blk, srcno0,
  1368. srcno0 + nr_ipis - 1);
  1369. for (i = 0; i < nr_ipis; i++) {
  1370. if (xive_router_get_eas(xrtr, blk, i, &eas)) {
  1371. break;
  1372. }
  1373. if (!xive_eas_is_masked(&eas)) {
  1374. xive_eas_pic_print_info(&eas, i, mon);
  1375. }
  1376. }
  1377. monitor_printf(mon, "XIVE[%x] ENDT %08x .. %08x\n", blk, 0, nr_ends - 1);
  1378. for (i = 0; i < nr_ends; i++) {
  1379. if (xive_router_get_end(xrtr, blk, i, &end)) {
  1380. break;
  1381. }
  1382. xive_end_pic_print_info(&end, i, mon);
  1383. }
  1384. monitor_printf(mon, "XIVE[%x] END Escalation %08x .. %08x\n", blk, 0,
  1385. nr_ends - 1);
  1386. for (i = 0; i < nr_ends; i++) {
  1387. if (xive_router_get_end(xrtr, blk, i, &end)) {
  1388. break;
  1389. }
  1390. xive_end_eas_pic_print_info(&end, i, mon);
  1391. }
  1392. }
  1393. static void pnv_xive_reset(void *dev)
  1394. {
  1395. PnvXive *xive = PNV_XIVE(dev);
  1396. XiveSource *xsrc = &xive->ipi_source;
  1397. XiveENDSource *end_xsrc = &xive->end_source;
  1398. /*
  1399. * Use the PnvChip id to identify the XIVE interrupt controller.
  1400. * It can be overriden by configuration at runtime.
  1401. */
  1402. xive->tctx_chipid = xive->chip->chip_id;
  1403. /* Default page size (Should be changed at runtime to 64k) */
  1404. xive->ic_shift = xive->vc_shift = xive->pc_shift = 12;
  1405. /* Clear subregions */
  1406. if (memory_region_is_mapped(&xsrc->esb_mmio)) {
  1407. memory_region_del_subregion(&xive->ipi_edt_mmio, &xsrc->esb_mmio);
  1408. }
  1409. if (memory_region_is_mapped(&xive->ipi_edt_mmio)) {
  1410. memory_region_del_subregion(&xive->ipi_mmio, &xive->ipi_edt_mmio);
  1411. }
  1412. if (memory_region_is_mapped(&end_xsrc->esb_mmio)) {
  1413. memory_region_del_subregion(&xive->end_edt_mmio, &end_xsrc->esb_mmio);
  1414. }
  1415. if (memory_region_is_mapped(&xive->end_edt_mmio)) {
  1416. memory_region_del_subregion(&xive->end_mmio, &xive->end_edt_mmio);
  1417. }
  1418. }
  1419. static void pnv_xive_init(Object *obj)
  1420. {
  1421. PnvXive *xive = PNV_XIVE(obj);
  1422. object_initialize_child(obj, "ipi_source", &xive->ipi_source,
  1423. sizeof(xive->ipi_source), TYPE_XIVE_SOURCE,
  1424. &error_abort, NULL);
  1425. object_initialize_child(obj, "end_source", &xive->end_source,
  1426. sizeof(xive->end_source), TYPE_XIVE_END_SOURCE,
  1427. &error_abort, NULL);
  1428. }
  1429. /*
  1430. * Maximum number of IRQs and ENDs supported by HW
  1431. */
  1432. #define PNV_XIVE_NR_IRQS (PNV9_XIVE_VC_SIZE / (1ull << XIVE_ESB_64K_2PAGE))
  1433. #define PNV_XIVE_NR_ENDS (PNV9_XIVE_VC_SIZE / (1ull << XIVE_ESB_64K_2PAGE))
  1434. static void pnv_xive_realize(DeviceState *dev, Error **errp)
  1435. {
  1436. PnvXive *xive = PNV_XIVE(dev);
  1437. XiveSource *xsrc = &xive->ipi_source;
  1438. XiveENDSource *end_xsrc = &xive->end_source;
  1439. Error *local_err = NULL;
  1440. Object *obj;
  1441. obj = object_property_get_link(OBJECT(dev), "chip", &local_err);
  1442. if (!obj) {
  1443. error_propagate(errp, local_err);
  1444. error_prepend(errp, "required link 'chip' not found: ");
  1445. return;
  1446. }
  1447. /* The PnvChip id identifies the XIVE interrupt controller. */
  1448. xive->chip = PNV_CHIP(obj);
  1449. /*
  1450. * The XiveSource and XiveENDSource objects are realized with the
  1451. * maximum allowed HW configuration. The ESB MMIO regions will be
  1452. * resized dynamically when the controller is configured by the FW
  1453. * to limit accesses to resources not provisioned.
  1454. */
  1455. object_property_set_int(OBJECT(xsrc), PNV_XIVE_NR_IRQS, "nr-irqs",
  1456. &error_fatal);
  1457. object_property_add_const_link(OBJECT(xsrc), "xive", OBJECT(xive),
  1458. &error_fatal);
  1459. object_property_set_bool(OBJECT(xsrc), true, "realized", &local_err);
  1460. if (local_err) {
  1461. error_propagate(errp, local_err);
  1462. return;
  1463. }
  1464. object_property_set_int(OBJECT(end_xsrc), PNV_XIVE_NR_ENDS, "nr-ends",
  1465. &error_fatal);
  1466. object_property_add_const_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
  1467. &error_fatal);
  1468. object_property_set_bool(OBJECT(end_xsrc), true, "realized", &local_err);
  1469. if (local_err) {
  1470. error_propagate(errp, local_err);
  1471. return;
  1472. }
  1473. /* Default page size. Generally changed at runtime to 64k */
  1474. xive->ic_shift = xive->vc_shift = xive->pc_shift = 12;
  1475. /* XSCOM region, used for initial configuration of the BARs */
  1476. memory_region_init_io(&xive->xscom_regs, OBJECT(dev), &pnv_xive_xscom_ops,
  1477. xive, "xscom-xive", PNV9_XSCOM_XIVE_SIZE << 3);
  1478. /* Interrupt controller MMIO regions */
  1479. memory_region_init(&xive->ic_mmio, OBJECT(dev), "xive-ic",
  1480. PNV9_XIVE_IC_SIZE);
  1481. memory_region_init_io(&xive->ic_reg_mmio, OBJECT(dev), &pnv_xive_ic_reg_ops,
  1482. xive, "xive-ic-reg", 1 << xive->ic_shift);
  1483. memory_region_init_io(&xive->ic_notify_mmio, OBJECT(dev),
  1484. &pnv_xive_ic_notify_ops,
  1485. xive, "xive-ic-notify", 1 << xive->ic_shift);
  1486. /* The Pervasive LSI trigger and EOI pages (not modeled) */
  1487. memory_region_init_io(&xive->ic_lsi_mmio, OBJECT(dev), &pnv_xive_ic_lsi_ops,
  1488. xive, "xive-ic-lsi", 2 << xive->ic_shift);
  1489. /* Thread Interrupt Management Area (Indirect) */
  1490. memory_region_init_io(&xive->tm_indirect_mmio, OBJECT(dev),
  1491. &xive_tm_indirect_ops,
  1492. xive, "xive-tima-indirect", PNV9_XIVE_TM_SIZE);
  1493. /*
  1494. * Overall Virtualization Controller MMIO region containing the
  1495. * IPI ESB pages and END ESB pages. The layout is defined by the
  1496. * EDT "Domain table" and the accesses are dispatched using
  1497. * address spaces for each.
  1498. */
  1499. memory_region_init_io(&xive->vc_mmio, OBJECT(xive), &pnv_xive_vc_ops, xive,
  1500. "xive-vc", PNV9_XIVE_VC_SIZE);
  1501. memory_region_init(&xive->ipi_mmio, OBJECT(xive), "xive-vc-ipi",
  1502. PNV9_XIVE_VC_SIZE);
  1503. address_space_init(&xive->ipi_as, &xive->ipi_mmio, "xive-vc-ipi");
  1504. memory_region_init(&xive->end_mmio, OBJECT(xive), "xive-vc-end",
  1505. PNV9_XIVE_VC_SIZE);
  1506. address_space_init(&xive->end_as, &xive->end_mmio, "xive-vc-end");
  1507. /*
  1508. * The MMIO windows exposing the IPI ESBs and the END ESBs in the
  1509. * VC region. Their size is configured by the FW in the EDT table.
  1510. */
  1511. memory_region_init(&xive->ipi_edt_mmio, OBJECT(xive), "xive-vc-ipi-edt", 0);
  1512. memory_region_init(&xive->end_edt_mmio, OBJECT(xive), "xive-vc-end-edt", 0);
  1513. /* Presenter Controller MMIO region (not modeled) */
  1514. memory_region_init_io(&xive->pc_mmio, OBJECT(xive), &pnv_xive_pc_ops, xive,
  1515. "xive-pc", PNV9_XIVE_PC_SIZE);
  1516. /* Thread Interrupt Management Area (Direct) */
  1517. memory_region_init_io(&xive->tm_mmio, OBJECT(xive), &xive_tm_ops,
  1518. xive, "xive-tima", PNV9_XIVE_TM_SIZE);
  1519. qemu_register_reset(pnv_xive_reset, dev);
  1520. }
  1521. static int pnv_xive_dt_xscom(PnvXScomInterface *dev, void *fdt,
  1522. int xscom_offset)
  1523. {
  1524. const char compat[] = "ibm,power9-xive-x";
  1525. char *name;
  1526. int offset;
  1527. uint32_t lpc_pcba = PNV9_XSCOM_XIVE_BASE;
  1528. uint32_t reg[] = {
  1529. cpu_to_be32(lpc_pcba),
  1530. cpu_to_be32(PNV9_XSCOM_XIVE_SIZE)
  1531. };
  1532. name = g_strdup_printf("xive@%x", lpc_pcba);
  1533. offset = fdt_add_subnode(fdt, xscom_offset, name);
  1534. _FDT(offset);
  1535. g_free(name);
  1536. _FDT((fdt_setprop(fdt, offset, "reg", reg, sizeof(reg))));
  1537. _FDT((fdt_setprop(fdt, offset, "compatible", compat,
  1538. sizeof(compat))));
  1539. return 0;
  1540. }
  1541. static Property pnv_xive_properties[] = {
  1542. DEFINE_PROP_UINT64("ic-bar", PnvXive, ic_base, 0),
  1543. DEFINE_PROP_UINT64("vc-bar", PnvXive, vc_base, 0),
  1544. DEFINE_PROP_UINT64("pc-bar", PnvXive, pc_base, 0),
  1545. DEFINE_PROP_UINT64("tm-bar", PnvXive, tm_base, 0),
  1546. DEFINE_PROP_END_OF_LIST(),
  1547. };
  1548. static void pnv_xive_class_init(ObjectClass *klass, void *data)
  1549. {
  1550. DeviceClass *dc = DEVICE_CLASS(klass);
  1551. PnvXScomInterfaceClass *xdc = PNV_XSCOM_INTERFACE_CLASS(klass);
  1552. XiveRouterClass *xrc = XIVE_ROUTER_CLASS(klass);
  1553. XiveNotifierClass *xnc = XIVE_NOTIFIER_CLASS(klass);
  1554. xdc->dt_xscom = pnv_xive_dt_xscom;
  1555. dc->desc = "PowerNV XIVE Interrupt Controller";
  1556. dc->realize = pnv_xive_realize;
  1557. dc->props = pnv_xive_properties;
  1558. xrc->get_eas = pnv_xive_get_eas;
  1559. xrc->get_end = pnv_xive_get_end;
  1560. xrc->write_end = pnv_xive_write_end;
  1561. xrc->get_nvt = pnv_xive_get_nvt;
  1562. xrc->write_nvt = pnv_xive_write_nvt;
  1563. xrc->get_tctx = pnv_xive_get_tctx;
  1564. xnc->notify = pnv_xive_notify;
  1565. };
  1566. static const TypeInfo pnv_xive_info = {
  1567. .name = TYPE_PNV_XIVE,
  1568. .parent = TYPE_XIVE_ROUTER,
  1569. .instance_init = pnv_xive_init,
  1570. .instance_size = sizeof(PnvXive),
  1571. .class_init = pnv_xive_class_init,
  1572. .interfaces = (InterfaceInfo[]) {
  1573. { TYPE_PNV_XSCOM_INTERFACE },
  1574. { }
  1575. }
  1576. };
  1577. static void pnv_xive_register_types(void)
  1578. {
  1579. type_register_static(&pnv_xive_info);
  1580. }
  1581. type_init(pnv_xive_register_types)