2
0

pnv_xive2.c 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682
  1. /*
  2. * QEMU PowerPC XIVE2 interrupt controller model (POWER10)
  3. *
  4. * Copyright (c) 2019-2024, IBM Corporation.
  5. *
  6. * SPDX-License-Identifier: GPL-2.0-or-later
  7. */
  8. #include "qemu/osdep.h"
  9. #include "qemu/log.h"
  10. #include "qapi/error.h"
  11. #include "target/ppc/cpu.h"
  12. #include "system/cpus.h"
  13. #include "system/dma.h"
  14. #include "hw/ppc/fdt.h"
  15. #include "hw/ppc/pnv.h"
  16. #include "hw/ppc/pnv_chip.h"
  17. #include "hw/ppc/pnv_core.h"
  18. #include "hw/ppc/pnv_xscom.h"
  19. #include "hw/ppc/xive2.h"
  20. #include "hw/ppc/pnv_xive.h"
  21. #include "hw/ppc/xive_regs.h"
  22. #include "hw/ppc/xive2_regs.h"
  23. #include "hw/ppc/ppc.h"
  24. #include "hw/qdev-properties.h"
  25. #include "system/reset.h"
  26. #include "system/qtest.h"
  27. #include <libfdt.h>
  28. #include "pnv_xive2_regs.h"
  29. #undef XIVE2_DEBUG
  30. /* XIVE Sync or Flush Notification Block */
  31. typedef struct XiveSfnBlock {
  32. uint8_t bytes[32];
  33. } XiveSfnBlock;
  34. /* XIVE Thread Sync or Flush Notification Area */
  35. typedef struct XiveThreadNA {
  36. XiveSfnBlock topo[16];
  37. } XiveThreadNA;
  38. /*
  39. * Virtual structures table (VST)
  40. */
  41. #define SBE_PER_BYTE 4
  42. typedef struct XiveVstInfo {
  43. const char *name;
  44. uint32_t size;
  45. uint32_t max_blocks;
  46. } XiveVstInfo;
  47. static const XiveVstInfo vst_infos[] = {
  48. [VST_EAS] = { "EAT", sizeof(Xive2Eas), 16 },
  49. [VST_ESB] = { "ESB", 1, 16 },
  50. [VST_END] = { "ENDT", sizeof(Xive2End), 16 },
  51. [VST_NVP] = { "NVPT", sizeof(Xive2Nvp), 16 },
  52. [VST_NVG] = { "NVGT", sizeof(Xive2Nvgc), 16 },
  53. [VST_NVC] = { "NVCT", sizeof(Xive2Nvgc), 16 },
  54. [VST_IC] = { "IC", 1, /* ? */ 16 }, /* Topology # */
  55. [VST_SYNC] = { "SYNC", sizeof(XiveThreadNA), 16 }, /* Topology # */
  56. /*
  57. * This table contains the backing store pages for the interrupt
  58. * fifos of the VC sub-engine in case of overflow.
  59. *
  60. * 0 - IPI,
  61. * 1 - HWD,
  62. * 2 - NxC,
  63. * 3 - INT,
  64. * 4 - OS-Queue,
  65. * 5 - Pool-Queue,
  66. * 6 - Hard-Queue
  67. */
  68. [VST_ERQ] = { "ERQ", 1, VC_QUEUE_COUNT },
  69. };
  70. #define xive2_error(xive, fmt, ...) \
  71. qemu_log_mask(LOG_GUEST_ERROR, "XIVE[%x] - " fmt "\n", \
  72. (xive)->chip->chip_id, ## __VA_ARGS__);
  73. /*
  74. * TODO: Document block id override
  75. */
  76. static uint32_t pnv_xive2_block_id(PnvXive2 *xive)
  77. {
  78. uint8_t blk = xive->chip->chip_id;
  79. uint64_t cfg_val = xive->cq_regs[CQ_XIVE_CFG >> 3];
  80. if (cfg_val & CQ_XIVE_CFG_HYP_HARD_BLKID_OVERRIDE) {
  81. blk = GETFIELD(CQ_XIVE_CFG_HYP_HARD_BLOCK_ID, cfg_val);
  82. }
  83. return blk;
  84. }
  85. /*
  86. * Remote access to controllers. HW uses MMIOs. For now, a simple scan
  87. * of the chips is good enough.
  88. *
  89. * TODO: Block scope support
  90. */
  91. static PnvXive2 *pnv_xive2_get_remote(uint8_t blk)
  92. {
  93. PnvMachineState *pnv = PNV_MACHINE(qdev_get_machine());
  94. int i;
  95. for (i = 0; i < pnv->num_chips; i++) {
  96. Pnv10Chip *chip10 = PNV10_CHIP(pnv->chips[i]);
  97. PnvXive2 *xive = &chip10->xive;
  98. if (pnv_xive2_block_id(xive) == blk) {
  99. return xive;
  100. }
  101. }
  102. return NULL;
  103. }
  104. /*
  105. * VST accessors for ESB, EAT, ENDT, NVP
  106. *
  107. * Indirect VST tables are arrays of VSDs pointing to a page (of same
  108. * size). Each page is a direct VST table.
  109. */
  110. #define XIVE_VSD_SIZE 8
  111. /* Indirect page size can be 4K, 64K, 2M, 16M. */
  112. static uint64_t pnv_xive2_vst_page_size_allowed(uint32_t page_shift)
  113. {
  114. return page_shift == 12 || page_shift == 16 ||
  115. page_shift == 21 || page_shift == 24;
  116. }
  117. static uint64_t pnv_xive2_vst_addr_direct(PnvXive2 *xive, uint32_t type,
  118. uint64_t vsd, uint32_t idx)
  119. {
  120. const XiveVstInfo *info = &vst_infos[type];
  121. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  122. uint64_t vst_tsize = 1ull << (GETFIELD(VSD_TSIZE, vsd) + 12);
  123. uint32_t idx_max;
  124. idx_max = vst_tsize / info->size - 1;
  125. if (idx > idx_max) {
  126. #ifdef XIVE2_DEBUG
  127. xive2_error(xive, "VST: %s entry %x out of range [ 0 .. %x ] !?",
  128. info->name, idx, idx_max);
  129. #endif
  130. return 0;
  131. }
  132. return vst_addr + idx * info->size;
  133. }
  134. static uint64_t pnv_xive2_vst_addr_indirect(PnvXive2 *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. ldq_be_dma(&address_space_memory, vsd_addr, &vsd, MEMTXATTRS_UNSPECIFIED);
  145. if (!(vsd & VSD_ADDRESS_MASK)) {
  146. #ifdef XIVE2_DEBUG
  147. xive2_error(xive, "VST: invalid %s entry %x !?", info->name, idx);
  148. #endif
  149. return 0;
  150. }
  151. page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  152. if (!pnv_xive2_vst_page_size_allowed(page_shift)) {
  153. xive2_error(xive, "VST: invalid %s page shift %d", info->name,
  154. page_shift);
  155. return 0;
  156. }
  157. vst_per_page = (1ull << page_shift) / info->size;
  158. vsd_idx = idx / vst_per_page;
  159. /* Load the VSD we are looking for, if not already done */
  160. if (vsd_idx) {
  161. vsd_addr = vsd_addr + vsd_idx * XIVE_VSD_SIZE;
  162. ldq_be_dma(&address_space_memory, vsd_addr, &vsd,
  163. MEMTXATTRS_UNSPECIFIED);
  164. if (!(vsd & VSD_ADDRESS_MASK)) {
  165. #ifdef XIVE2_DEBUG
  166. xive2_error(xive, "VST: invalid %s entry %x !?", info->name, idx);
  167. #endif
  168. return 0;
  169. }
  170. /*
  171. * Check that the pages have a consistent size across the
  172. * indirect table
  173. */
  174. if (page_shift != GETFIELD(VSD_TSIZE, vsd) + 12) {
  175. xive2_error(xive, "VST: %s entry %x indirect page size differ !?",
  176. info->name, idx);
  177. return 0;
  178. }
  179. }
  180. return pnv_xive2_vst_addr_direct(xive, type, vsd, (idx % vst_per_page));
  181. }
  182. static uint8_t pnv_xive2_nvc_table_compress_shift(PnvXive2 *xive)
  183. {
  184. uint8_t shift = GETFIELD(PC_NXC_PROC_CONFIG_NVC_TABLE_COMPRESS,
  185. xive->pc_regs[PC_NXC_PROC_CONFIG >> 3]);
  186. return shift > 8 ? 0 : shift;
  187. }
  188. static uint8_t pnv_xive2_nvg_table_compress_shift(PnvXive2 *xive)
  189. {
  190. uint8_t shift = GETFIELD(PC_NXC_PROC_CONFIG_NVG_TABLE_COMPRESS,
  191. xive->pc_regs[PC_NXC_PROC_CONFIG >> 3]);
  192. return shift > 8 ? 0 : shift;
  193. }
  194. static uint64_t pnv_xive2_vst_addr(PnvXive2 *xive, uint32_t type, uint8_t blk,
  195. uint32_t idx)
  196. {
  197. const XiveVstInfo *info = &vst_infos[type];
  198. uint64_t vsd;
  199. if (blk >= info->max_blocks) {
  200. xive2_error(xive, "VST: invalid block id %d for VST %s %d !?",
  201. blk, info->name, idx);
  202. return 0;
  203. }
  204. vsd = xive->vsds[type][blk];
  205. if (vsd == 0) {
  206. xive2_error(xive, "VST: vsd == 0 block id %d for VST %s %d !?",
  207. blk, info->name, idx);
  208. return 0;
  209. }
  210. /* Remote VST access */
  211. if (GETFIELD(VSD_MODE, vsd) == VSD_MODE_FORWARD) {
  212. xive = pnv_xive2_get_remote(blk);
  213. return xive ? pnv_xive2_vst_addr(xive, type, blk, idx) : 0;
  214. }
  215. if (type == VST_NVG) {
  216. idx >>= pnv_xive2_nvg_table_compress_shift(xive);
  217. } else if (type == VST_NVC) {
  218. idx >>= pnv_xive2_nvc_table_compress_shift(xive);
  219. }
  220. if (VSD_INDIRECT & vsd) {
  221. return pnv_xive2_vst_addr_indirect(xive, type, vsd, idx);
  222. }
  223. return pnv_xive2_vst_addr_direct(xive, type, vsd, idx);
  224. }
  225. static int pnv_xive2_vst_read(PnvXive2 *xive, uint32_t type, uint8_t blk,
  226. uint32_t idx, void *data)
  227. {
  228. const XiveVstInfo *info = &vst_infos[type];
  229. uint64_t addr = pnv_xive2_vst_addr(xive, type, blk, idx);
  230. MemTxResult result;
  231. if (!addr) {
  232. return -1;
  233. }
  234. result = address_space_read(&address_space_memory, addr,
  235. MEMTXATTRS_UNSPECIFIED, data,
  236. info->size);
  237. if (result != MEMTX_OK) {
  238. xive2_error(xive, "VST: read failed at @0x%" HWADDR_PRIx
  239. " for VST %s %x/%x\n", addr, info->name, blk, idx);
  240. return -1;
  241. }
  242. return 0;
  243. }
  244. #define XIVE_VST_WORD_ALL -1
  245. static int pnv_xive2_vst_write(PnvXive2 *xive, uint32_t type, uint8_t blk,
  246. uint32_t idx, void *data, uint32_t word_number)
  247. {
  248. const XiveVstInfo *info = &vst_infos[type];
  249. uint64_t addr = pnv_xive2_vst_addr(xive, type, blk, idx);
  250. MemTxResult result;
  251. if (!addr) {
  252. return -1;
  253. }
  254. if (word_number == XIVE_VST_WORD_ALL) {
  255. result = address_space_write(&address_space_memory, addr,
  256. MEMTXATTRS_UNSPECIFIED, data,
  257. info->size);
  258. } else {
  259. result = address_space_write(&address_space_memory,
  260. addr + word_number * 4,
  261. MEMTXATTRS_UNSPECIFIED,
  262. data + word_number * 4, 4);
  263. }
  264. if (result != MEMTX_OK) {
  265. xive2_error(xive, "VST: write failed at @0x%" HWADDR_PRIx
  266. "for VST %s %x/%x\n", addr, info->name, blk, idx);
  267. return -1;
  268. }
  269. return 0;
  270. }
  271. static int pnv_xive2_get_pq(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  272. uint8_t *pq)
  273. {
  274. PnvXive2 *xive = PNV_XIVE2(xrtr);
  275. if (pnv_xive2_block_id(xive) != blk) {
  276. xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx));
  277. return -1;
  278. }
  279. *pq = xive_source_esb_get(&xive->ipi_source, idx);
  280. return 0;
  281. }
  282. static int pnv_xive2_set_pq(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  283. uint8_t *pq)
  284. {
  285. PnvXive2 *xive = PNV_XIVE2(xrtr);
  286. if (pnv_xive2_block_id(xive) != blk) {
  287. xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx));
  288. return -1;
  289. }
  290. *pq = xive_source_esb_set(&xive->ipi_source, idx, *pq);
  291. return 0;
  292. }
  293. static int pnv_xive2_get_end(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  294. Xive2End *end)
  295. {
  296. return pnv_xive2_vst_read(PNV_XIVE2(xrtr), VST_END, blk, idx, end);
  297. }
  298. static int pnv_xive2_write_end(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  299. Xive2End *end, uint8_t word_number)
  300. {
  301. return pnv_xive2_vst_write(PNV_XIVE2(xrtr), VST_END, blk, idx, end,
  302. word_number);
  303. }
  304. static inline int pnv_xive2_get_current_pir(PnvXive2 *xive)
  305. {
  306. if (!qtest_enabled()) {
  307. PowerPCCPU *cpu = POWERPC_CPU(current_cpu);
  308. return ppc_cpu_pir(cpu);
  309. }
  310. return 0;
  311. }
  312. /*
  313. * After SW injects a Queue Sync or Cache Flush operation, HW will notify
  314. * SW of the completion of the operation by writing a byte of all 1's (0xff)
  315. * to a specific memory location. The memory location is calculated by first
  316. * looking up a base address in the SYNC VSD using the Topology ID of the
  317. * originating thread as the "block" number. This points to a
  318. * 64k block of memory that is further divided into 128 512 byte chunks of
  319. * memory, which is indexed by the thread id of the requesting thread.
  320. * Finally, this 512 byte chunk of memory is divided into 16 32 byte
  321. * chunks which are indexed by the topology id of the targeted IC's chip.
  322. * The values below are the offsets into that 32 byte chunk of memory for
  323. * each type of cache flush or queue sync operation.
  324. */
  325. #define PNV_XIVE2_QUEUE_IPI 0x00
  326. #define PNV_XIVE2_QUEUE_HW 0x01
  327. #define PNV_XIVE2_QUEUE_NXC 0x02
  328. #define PNV_XIVE2_QUEUE_INT 0x03
  329. #define PNV_XIVE2_QUEUE_OS 0x04
  330. #define PNV_XIVE2_QUEUE_POOL 0x05
  331. #define PNV_XIVE2_QUEUE_HARD 0x06
  332. #define PNV_XIVE2_CACHE_ENDC 0x08
  333. #define PNV_XIVE2_CACHE_ESBC 0x09
  334. #define PNV_XIVE2_CACHE_EASC 0x0a
  335. #define PNV_XIVE2_QUEUE_NXC_LD_LCL_NCO 0x10
  336. #define PNV_XIVE2_QUEUE_NXC_LD_LCL_CO 0x11
  337. #define PNV_XIVE2_QUEUE_NXC_ST_LCL_NCI 0x12
  338. #define PNV_XIVE2_QUEUE_NXC_ST_LCL_CI 0x13
  339. #define PNV_XIVE2_QUEUE_NXC_ST_RMT_NCI 0x14
  340. #define PNV_XIVE2_QUEUE_NXC_ST_RMT_CI 0x15
  341. #define PNV_XIVE2_CACHE_NXC 0x18
  342. static int pnv_xive2_inject_notify(PnvXive2 *xive, int type)
  343. {
  344. uint64_t addr;
  345. int pir = pnv_xive2_get_current_pir(xive);
  346. int thread_nr = PNV10_PIR2THREAD(pir);
  347. int thread_topo_id = PNV10_PIR2CHIP(pir);
  348. int ic_topo_id = xive->chip->chip_id;
  349. uint64_t offset = ic_topo_id * sizeof(XiveSfnBlock);
  350. uint8_t byte = 0xff;
  351. MemTxResult result;
  352. /* Retrieve the address of requesting thread's notification area */
  353. addr = pnv_xive2_vst_addr(xive, VST_SYNC, thread_topo_id, thread_nr);
  354. if (!addr) {
  355. xive2_error(xive, "VST: no SYNC entry %x/%x !?",
  356. thread_topo_id, thread_nr);
  357. return -1;
  358. }
  359. address_space_stb(&address_space_memory, addr + offset + type, byte,
  360. MEMTXATTRS_UNSPECIFIED, &result);
  361. assert(result == MEMTX_OK);
  362. return 0;
  363. }
  364. static int pnv_xive2_end_update(PnvXive2 *xive, uint8_t watch_engine)
  365. {
  366. uint8_t blk;
  367. uint32_t idx;
  368. int i, spec_reg, data_reg;
  369. uint64_t endc_watch[4];
  370. assert(watch_engine < ARRAY_SIZE(endc_watch));
  371. spec_reg = (VC_ENDC_WATCH0_SPEC + watch_engine * 0x40) >> 3;
  372. data_reg = (VC_ENDC_WATCH0_DATA0 + watch_engine * 0x40) >> 3;
  373. blk = GETFIELD(VC_ENDC_WATCH_BLOCK_ID, xive->vc_regs[spec_reg]);
  374. idx = GETFIELD(VC_ENDC_WATCH_INDEX, xive->vc_regs[spec_reg]);
  375. for (i = 0; i < ARRAY_SIZE(endc_watch); i++) {
  376. endc_watch[i] = cpu_to_be64(xive->vc_regs[data_reg + i]);
  377. }
  378. return pnv_xive2_vst_write(xive, VST_END, blk, idx, endc_watch,
  379. XIVE_VST_WORD_ALL);
  380. }
  381. static void pnv_xive2_end_cache_load(PnvXive2 *xive, uint8_t watch_engine)
  382. {
  383. uint8_t blk;
  384. uint32_t idx;
  385. uint64_t endc_watch[4] = { 0 };
  386. int i, spec_reg, data_reg;
  387. assert(watch_engine < ARRAY_SIZE(endc_watch));
  388. spec_reg = (VC_ENDC_WATCH0_SPEC + watch_engine * 0x40) >> 3;
  389. data_reg = (VC_ENDC_WATCH0_DATA0 + watch_engine * 0x40) >> 3;
  390. blk = GETFIELD(VC_ENDC_WATCH_BLOCK_ID, xive->vc_regs[spec_reg]);
  391. idx = GETFIELD(VC_ENDC_WATCH_INDEX, xive->vc_regs[spec_reg]);
  392. if (pnv_xive2_vst_read(xive, VST_END, blk, idx, endc_watch)) {
  393. xive2_error(xive, "VST: no END entry %x/%x !?", blk, idx);
  394. }
  395. for (i = 0; i < ARRAY_SIZE(endc_watch); i++) {
  396. xive->vc_regs[data_reg + i] = be64_to_cpu(endc_watch[i]);
  397. }
  398. }
  399. static int pnv_xive2_get_nvp(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  400. Xive2Nvp *nvp)
  401. {
  402. return pnv_xive2_vst_read(PNV_XIVE2(xrtr), VST_NVP, blk, idx, nvp);
  403. }
  404. static int pnv_xive2_write_nvp(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  405. Xive2Nvp *nvp, uint8_t word_number)
  406. {
  407. return pnv_xive2_vst_write(PNV_XIVE2(xrtr), VST_NVP, blk, idx, nvp,
  408. word_number);
  409. }
  410. static int pnv_xive2_get_nvgc(Xive2Router *xrtr, bool crowd,
  411. uint8_t blk, uint32_t idx,
  412. Xive2Nvgc *nvgc)
  413. {
  414. return pnv_xive2_vst_read(PNV_XIVE2(xrtr), crowd ? VST_NVC : VST_NVG,
  415. blk, idx, nvgc);
  416. }
  417. static int pnv_xive2_write_nvgc(Xive2Router *xrtr, bool crowd,
  418. uint8_t blk, uint32_t idx,
  419. Xive2Nvgc *nvgc)
  420. {
  421. return pnv_xive2_vst_write(PNV_XIVE2(xrtr), crowd ? VST_NVC : VST_NVG,
  422. blk, idx, nvgc,
  423. XIVE_VST_WORD_ALL);
  424. }
  425. static int pnv_xive2_nxc_to_table_type(uint8_t nxc_type, uint32_t *table_type)
  426. {
  427. switch (nxc_type) {
  428. case PC_NXC_WATCH_NXC_NVP:
  429. *table_type = VST_NVP;
  430. break;
  431. case PC_NXC_WATCH_NXC_NVG:
  432. *table_type = VST_NVG;
  433. break;
  434. case PC_NXC_WATCH_NXC_NVC:
  435. *table_type = VST_NVC;
  436. break;
  437. default:
  438. qemu_log_mask(LOG_GUEST_ERROR,
  439. "XIVE: invalid table type for nxc operation\n");
  440. return -1;
  441. }
  442. return 0;
  443. }
  444. static int pnv_xive2_nxc_update(PnvXive2 *xive, uint8_t watch_engine)
  445. {
  446. uint8_t blk, nxc_type;
  447. uint32_t idx, table_type = -1;
  448. int i, spec_reg, data_reg;
  449. uint64_t nxc_watch[4];
  450. assert(watch_engine < ARRAY_SIZE(nxc_watch));
  451. spec_reg = (PC_NXC_WATCH0_SPEC + watch_engine * 0x40) >> 3;
  452. data_reg = (PC_NXC_WATCH0_DATA0 + watch_engine * 0x40) >> 3;
  453. nxc_type = GETFIELD(PC_NXC_WATCH_NXC_TYPE, xive->pc_regs[spec_reg]);
  454. blk = GETFIELD(PC_NXC_WATCH_BLOCK_ID, xive->pc_regs[spec_reg]);
  455. idx = GETFIELD(PC_NXC_WATCH_INDEX, xive->pc_regs[spec_reg]);
  456. assert(!pnv_xive2_nxc_to_table_type(nxc_type, &table_type));
  457. for (i = 0; i < ARRAY_SIZE(nxc_watch); i++) {
  458. nxc_watch[i] = cpu_to_be64(xive->pc_regs[data_reg + i]);
  459. }
  460. return pnv_xive2_vst_write(xive, table_type, blk, idx, nxc_watch,
  461. XIVE_VST_WORD_ALL);
  462. }
  463. static void pnv_xive2_nxc_cache_load(PnvXive2 *xive, uint8_t watch_engine)
  464. {
  465. uint8_t blk, nxc_type;
  466. uint32_t idx, table_type = -1;
  467. uint64_t nxc_watch[4] = { 0 };
  468. int i, spec_reg, data_reg;
  469. assert(watch_engine < ARRAY_SIZE(nxc_watch));
  470. spec_reg = (PC_NXC_WATCH0_SPEC + watch_engine * 0x40) >> 3;
  471. data_reg = (PC_NXC_WATCH0_DATA0 + watch_engine * 0x40) >> 3;
  472. nxc_type = GETFIELD(PC_NXC_WATCH_NXC_TYPE, xive->pc_regs[spec_reg]);
  473. blk = GETFIELD(PC_NXC_WATCH_BLOCK_ID, xive->pc_regs[spec_reg]);
  474. idx = GETFIELD(PC_NXC_WATCH_INDEX, xive->pc_regs[spec_reg]);
  475. assert(!pnv_xive2_nxc_to_table_type(nxc_type, &table_type));
  476. if (pnv_xive2_vst_read(xive, table_type, blk, idx, nxc_watch)) {
  477. xive2_error(xive, "VST: no NXC entry %x/%x in %s table!?",
  478. blk, idx, vst_infos[table_type].name);
  479. }
  480. for (i = 0; i < ARRAY_SIZE(nxc_watch); i++) {
  481. xive->pc_regs[data_reg + i] = be64_to_cpu(nxc_watch[i]);
  482. }
  483. }
  484. static int pnv_xive2_get_eas(Xive2Router *xrtr, uint8_t blk, uint32_t idx,
  485. Xive2Eas *eas)
  486. {
  487. PnvXive2 *xive = PNV_XIVE2(xrtr);
  488. if (pnv_xive2_block_id(xive) != blk) {
  489. xive2_error(xive, "VST: EAS %x is remote !?", XIVE_EAS(blk, idx));
  490. return -1;
  491. }
  492. return pnv_xive2_vst_read(xive, VST_EAS, blk, idx, eas);
  493. }
  494. static uint32_t pnv_xive2_get_config(Xive2Router *xrtr)
  495. {
  496. PnvXive2 *xive = PNV_XIVE2(xrtr);
  497. uint32_t cfg = 0;
  498. if (xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS) {
  499. cfg |= XIVE2_GEN1_TIMA_OS;
  500. }
  501. if (xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_EN_VP_SAVE_RESTORE) {
  502. cfg |= XIVE2_VP_SAVE_RESTORE;
  503. }
  504. if (GETFIELD(CQ_XIVE_CFG_HYP_HARD_RANGE,
  505. xive->cq_regs[CQ_XIVE_CFG >> 3]) == CQ_XIVE_CFG_THREADID_8BITS) {
  506. cfg |= XIVE2_THREADID_8BITS;
  507. }
  508. return cfg;
  509. }
  510. static bool pnv_xive2_is_cpu_enabled(PnvXive2 *xive, PowerPCCPU *cpu)
  511. {
  512. int pir = ppc_cpu_pir(cpu);
  513. uint32_t fc = PNV10_PIR2FUSEDCORE(pir);
  514. uint64_t reg = fc < 8 ? TCTXT_EN0 : TCTXT_EN1;
  515. uint32_t bit = pir & 0x3f;
  516. return xive->tctxt_regs[reg >> 3] & PPC_BIT(bit);
  517. }
  518. static int pnv_xive2_match_nvt(XivePresenter *xptr, uint8_t format,
  519. uint8_t nvt_blk, uint32_t nvt_idx,
  520. bool crowd, bool cam_ignore, uint8_t priority,
  521. uint32_t logic_serv, XiveTCTXMatch *match)
  522. {
  523. PnvXive2 *xive = PNV_XIVE2(xptr);
  524. PnvChip *chip = xive->chip;
  525. int count = 0;
  526. int i, j;
  527. bool gen1_tima_os =
  528. xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS;
  529. for (i = 0; i < chip->nr_cores; i++) {
  530. PnvCore *pc = chip->cores[i];
  531. CPUCore *cc = CPU_CORE(pc);
  532. for (j = 0; j < cc->nr_threads; j++) {
  533. PowerPCCPU *cpu = pc->threads[j];
  534. XiveTCTX *tctx;
  535. int ring;
  536. if (!pnv_xive2_is_cpu_enabled(xive, cpu)) {
  537. continue;
  538. }
  539. tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  540. if (gen1_tima_os) {
  541. ring = xive_presenter_tctx_match(xptr, tctx, format, nvt_blk,
  542. nvt_idx, cam_ignore,
  543. logic_serv);
  544. } else {
  545. ring = xive2_presenter_tctx_match(xptr, tctx, format, nvt_blk,
  546. nvt_idx, crowd, cam_ignore,
  547. logic_serv);
  548. }
  549. if (ring != -1) {
  550. /*
  551. * For VP-specific match, finding more than one is a
  552. * problem. For group notification, it's possible.
  553. */
  554. if (!cam_ignore && match->tctx) {
  555. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: already found a "
  556. "thread context NVT %x/%x\n",
  557. nvt_blk, nvt_idx);
  558. /* Should set a FIR if we ever model it */
  559. return -1;
  560. }
  561. /*
  562. * For a group notification, we need to know if the
  563. * match is precluded first by checking the current
  564. * thread priority. If the interrupt can be delivered,
  565. * we always notify the first match (for now).
  566. */
  567. if (cam_ignore &&
  568. xive2_tm_irq_precluded(tctx, ring, priority)) {
  569. match->precluded = true;
  570. } else {
  571. if (!match->tctx) {
  572. match->ring = ring;
  573. match->tctx = tctx;
  574. }
  575. count++;
  576. }
  577. }
  578. }
  579. }
  580. return count;
  581. }
  582. static uint32_t pnv_xive2_presenter_get_config(XivePresenter *xptr)
  583. {
  584. PnvXive2 *xive = PNV_XIVE2(xptr);
  585. uint32_t cfg = 0;
  586. if (xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS) {
  587. cfg |= XIVE_PRESENTER_GEN1_TIMA_OS;
  588. }
  589. return cfg;
  590. }
  591. static int pnv_xive2_broadcast(XivePresenter *xptr,
  592. uint8_t nvt_blk, uint32_t nvt_idx,
  593. bool crowd, bool ignore, uint8_t priority)
  594. {
  595. PnvXive2 *xive = PNV_XIVE2(xptr);
  596. PnvChip *chip = xive->chip;
  597. int i, j;
  598. bool gen1_tima_os =
  599. xive->cq_regs[CQ_XIVE_CFG >> 3] & CQ_XIVE_CFG_GEN1_TIMA_OS;
  600. for (i = 0; i < chip->nr_cores; i++) {
  601. PnvCore *pc = chip->cores[i];
  602. CPUCore *cc = CPU_CORE(pc);
  603. for (j = 0; j < cc->nr_threads; j++) {
  604. PowerPCCPU *cpu = pc->threads[j];
  605. XiveTCTX *tctx;
  606. int ring;
  607. if (!pnv_xive2_is_cpu_enabled(xive, cpu)) {
  608. continue;
  609. }
  610. tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  611. if (gen1_tima_os) {
  612. ring = xive_presenter_tctx_match(xptr, tctx, 0, nvt_blk,
  613. nvt_idx, ignore, 0);
  614. } else {
  615. ring = xive2_presenter_tctx_match(xptr, tctx, 0, nvt_blk,
  616. nvt_idx, crowd, ignore, 0);
  617. }
  618. if (ring != -1) {
  619. xive2_tm_set_lsmfb(tctx, ring, priority);
  620. }
  621. }
  622. }
  623. return 0;
  624. }
  625. static uint8_t pnv_xive2_get_block_id(Xive2Router *xrtr)
  626. {
  627. return pnv_xive2_block_id(PNV_XIVE2(xrtr));
  628. }
  629. /*
  630. * The TIMA MMIO space is shared among the chips and to identify the
  631. * chip from which the access is being done, we extract the chip id
  632. * from the PIR.
  633. */
  634. static PnvXive2 *pnv_xive2_tm_get_xive(PowerPCCPU *cpu)
  635. {
  636. int pir = ppc_cpu_pir(cpu);
  637. XivePresenter *xptr = XIVE_TCTX(pnv_cpu_state(cpu)->intc)->xptr;
  638. PnvXive2 *xive = PNV_XIVE2(xptr);
  639. if (!pnv_xive2_is_cpu_enabled(xive, cpu)) {
  640. xive2_error(xive, "IC: CPU %x is not enabled", pir);
  641. }
  642. return xive;
  643. }
  644. /*
  645. * The internal sources of the interrupt controller have no knowledge
  646. * of the XIVE2 chip on which they reside. Encode the block id in the
  647. * source interrupt number before forwarding the source event
  648. * notification to the Router. This is required on a multichip system.
  649. */
  650. static void pnv_xive2_notify(XiveNotifier *xn, uint32_t srcno, bool pq_checked)
  651. {
  652. PnvXive2 *xive = PNV_XIVE2(xn);
  653. uint8_t blk = pnv_xive2_block_id(xive);
  654. xive2_router_notify(xn, XIVE_EAS(blk, srcno), pq_checked);
  655. }
  656. /*
  657. * Set Translation Tables
  658. *
  659. * TODO add support for multiple sets
  660. */
  661. static int pnv_xive2_stt_set_data(PnvXive2 *xive, uint64_t val)
  662. {
  663. uint8_t tsel = GETFIELD(CQ_TAR_SELECT, xive->cq_regs[CQ_TAR >> 3]);
  664. uint8_t entry = GETFIELD(CQ_TAR_ENTRY_SELECT,
  665. xive->cq_regs[CQ_TAR >> 3]);
  666. switch (tsel) {
  667. case CQ_TAR_NVPG:
  668. case CQ_TAR_ESB:
  669. case CQ_TAR_END:
  670. case CQ_TAR_NVC:
  671. xive->tables[tsel][entry] = val;
  672. break;
  673. default:
  674. xive2_error(xive, "IC: unsupported table %d", tsel);
  675. return -1;
  676. }
  677. if (xive->cq_regs[CQ_TAR >> 3] & CQ_TAR_AUTOINC) {
  678. xive->cq_regs[CQ_TAR >> 3] = SETFIELD(CQ_TAR_ENTRY_SELECT,
  679. xive->cq_regs[CQ_TAR >> 3], ++entry);
  680. }
  681. return 0;
  682. }
  683. /*
  684. * Virtual Structure Tables (VST) configuration
  685. */
  686. static void pnv_xive2_vst_set_exclusive(PnvXive2 *xive, uint8_t type,
  687. uint8_t blk, uint64_t vsd)
  688. {
  689. Xive2EndSource *end_xsrc = &xive->end_source;
  690. XiveSource *xsrc = &xive->ipi_source;
  691. const XiveVstInfo *info = &vst_infos[type];
  692. uint32_t page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  693. uint64_t vst_tsize = 1ull << page_shift;
  694. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  695. /* Basic checks */
  696. if (VSD_INDIRECT & vsd) {
  697. if (!pnv_xive2_vst_page_size_allowed(page_shift)) {
  698. xive2_error(xive, "VST: invalid %s page shift %d", info->name,
  699. page_shift);
  700. return;
  701. }
  702. }
  703. if (!QEMU_IS_ALIGNED(vst_addr, 1ull << page_shift)) {
  704. xive2_error(xive, "VST: %s table address 0x%"PRIx64
  705. " is not aligned with page shift %d",
  706. info->name, vst_addr, page_shift);
  707. return;
  708. }
  709. /* Record the table configuration (in SRAM on HW) */
  710. xive->vsds[type][blk] = vsd;
  711. /* Now tune the models with the configuration provided by the FW */
  712. switch (type) {
  713. case VST_ESB:
  714. /*
  715. * Backing store pages for the source PQ bits. The model does
  716. * not use these PQ bits backed in RAM because the XiveSource
  717. * model has its own.
  718. *
  719. * If the table is direct, we can compute the number of PQ
  720. * entries provisioned by FW (such as skiboot) and resize the
  721. * ESB window accordingly.
  722. */
  723. if (memory_region_is_mapped(&xsrc->esb_mmio)) {
  724. memory_region_del_subregion(&xive->esb_mmio, &xsrc->esb_mmio);
  725. }
  726. if (!(VSD_INDIRECT & vsd)) {
  727. memory_region_set_size(&xsrc->esb_mmio, vst_tsize * SBE_PER_BYTE
  728. * (1ull << xsrc->esb_shift));
  729. }
  730. memory_region_add_subregion(&xive->esb_mmio, 0, &xsrc->esb_mmio);
  731. break;
  732. case VST_EAS: /* Nothing to be done */
  733. break;
  734. case VST_END:
  735. /*
  736. * Backing store pages for the END.
  737. */
  738. if (memory_region_is_mapped(&end_xsrc->esb_mmio)) {
  739. memory_region_del_subregion(&xive->end_mmio, &end_xsrc->esb_mmio);
  740. }
  741. if (!(VSD_INDIRECT & vsd)) {
  742. memory_region_set_size(&end_xsrc->esb_mmio, (vst_tsize / info->size)
  743. * (1ull << end_xsrc->esb_shift));
  744. }
  745. memory_region_add_subregion(&xive->end_mmio, 0, &end_xsrc->esb_mmio);
  746. break;
  747. case VST_NVP: /* Not modeled */
  748. case VST_NVG: /* Not modeled */
  749. case VST_NVC: /* Not modeled */
  750. case VST_IC: /* Not modeled */
  751. case VST_SYNC: /* Not modeled */
  752. case VST_ERQ: /* Not modeled */
  753. break;
  754. default:
  755. g_assert_not_reached();
  756. }
  757. }
  758. /*
  759. * Both PC and VC sub-engines are configured as each use the Virtual
  760. * Structure Tables
  761. */
  762. static void pnv_xive2_vst_set_data(PnvXive2 *xive, uint64_t vsd,
  763. uint8_t type, uint8_t blk)
  764. {
  765. uint8_t mode = GETFIELD(VSD_MODE, vsd);
  766. uint64_t vst_addr = vsd & VSD_ADDRESS_MASK;
  767. if (type > VST_ERQ) {
  768. xive2_error(xive, "VST: invalid table type %d", type);
  769. return;
  770. }
  771. if (blk >= vst_infos[type].max_blocks) {
  772. xive2_error(xive, "VST: invalid block id %d for"
  773. " %s table", blk, vst_infos[type].name);
  774. return;
  775. }
  776. if (!vst_addr) {
  777. xive2_error(xive, "VST: invalid %s table address",
  778. vst_infos[type].name);
  779. return;
  780. }
  781. switch (mode) {
  782. case VSD_MODE_FORWARD:
  783. xive->vsds[type][blk] = vsd;
  784. break;
  785. case VSD_MODE_EXCLUSIVE:
  786. pnv_xive2_vst_set_exclusive(xive, type, blk, vsd);
  787. break;
  788. default:
  789. xive2_error(xive, "VST: unsupported table mode %d", mode);
  790. return;
  791. }
  792. }
  793. static void pnv_xive2_vc_vst_set_data(PnvXive2 *xive, uint64_t vsd)
  794. {
  795. uint8_t type = GETFIELD(VC_VSD_TABLE_SELECT,
  796. xive->vc_regs[VC_VSD_TABLE_ADDR >> 3]);
  797. uint8_t blk = GETFIELD(VC_VSD_TABLE_ADDRESS,
  798. xive->vc_regs[VC_VSD_TABLE_ADDR >> 3]);
  799. pnv_xive2_vst_set_data(xive, vsd, type, blk);
  800. }
  801. /*
  802. * MMIO handlers
  803. */
  804. /*
  805. * IC BAR layout
  806. *
  807. * Page 0: Internal CQ register accesses (reads & writes)
  808. * Page 1: Internal PC register accesses (reads & writes)
  809. * Page 2: Internal VC register accesses (reads & writes)
  810. * Page 3: Internal TCTXT (TIMA) reg accesses (read & writes)
  811. * Page 4: Notify Port page (writes only, w/data),
  812. * Page 5: Reserved
  813. * Page 6: Sync Poll page (writes only, dataless)
  814. * Page 7: Sync Inject page (writes only, dataless)
  815. * Page 8: LSI Trigger page (writes only, dataless)
  816. * Page 9: LSI SB Management page (reads & writes dataless)
  817. * Pages 10-255: Reserved
  818. * Pages 256-383: Direct mapped Thread Context Area (reads & writes)
  819. * covering the 128 threads in P10.
  820. * Pages 384-511: Reserved
  821. */
  822. typedef struct PnvXive2Region {
  823. const char *name;
  824. uint32_t pgoff;
  825. uint32_t pgsize;
  826. const MemoryRegionOps *ops;
  827. } PnvXive2Region;
  828. static const MemoryRegionOps pnv_xive2_ic_cq_ops;
  829. static const MemoryRegionOps pnv_xive2_ic_pc_ops;
  830. static const MemoryRegionOps pnv_xive2_ic_vc_ops;
  831. static const MemoryRegionOps pnv_xive2_ic_tctxt_ops;
  832. static const MemoryRegionOps pnv_xive2_ic_notify_ops;
  833. static const MemoryRegionOps pnv_xive2_ic_sync_ops;
  834. static const MemoryRegionOps pnv_xive2_ic_lsi_ops;
  835. static const MemoryRegionOps pnv_xive2_ic_tm_indirect_ops;
  836. /* 512 pages. 4K: 2M range, 64K: 32M range */
  837. static const PnvXive2Region pnv_xive2_ic_regions[] = {
  838. { "xive-ic-cq", 0, 1, &pnv_xive2_ic_cq_ops },
  839. { "xive-ic-vc", 1, 1, &pnv_xive2_ic_vc_ops },
  840. { "xive-ic-pc", 2, 1, &pnv_xive2_ic_pc_ops },
  841. { "xive-ic-tctxt", 3, 1, &pnv_xive2_ic_tctxt_ops },
  842. { "xive-ic-notify", 4, 1, &pnv_xive2_ic_notify_ops },
  843. /* page 5 reserved */
  844. { "xive-ic-sync", 6, 2, &pnv_xive2_ic_sync_ops },
  845. { "xive-ic-lsi", 8, 2, &pnv_xive2_ic_lsi_ops },
  846. /* pages 10-255 reserved */
  847. { "xive-ic-tm-indirect", 256, 128, &pnv_xive2_ic_tm_indirect_ops },
  848. /* pages 384-511 reserved */
  849. };
  850. /*
  851. * CQ operations
  852. */
  853. static uint64_t pnv_xive2_ic_cq_read(void *opaque, hwaddr offset,
  854. unsigned size)
  855. {
  856. PnvXive2 *xive = PNV_XIVE2(opaque);
  857. uint32_t reg = offset >> 3;
  858. uint64_t val = 0;
  859. switch (offset) {
  860. case CQ_XIVE_CAP: /* Set at reset */
  861. case CQ_XIVE_CFG:
  862. val = xive->cq_regs[reg];
  863. break;
  864. case CQ_MSGSND: /* TODO check the #cores of the machine */
  865. val = 0xffffffff00000000;
  866. break;
  867. case CQ_CFG_PB_GEN:
  868. val = CQ_CFG_PB_GEN_PB_INIT; /* TODO: fix CQ_CFG_PB_GEN default value */
  869. break;
  870. default:
  871. xive2_error(xive, "CQ: invalid read @%"HWADDR_PRIx, offset);
  872. }
  873. return val;
  874. }
  875. static uint64_t pnv_xive2_bar_size(uint64_t val)
  876. {
  877. return 1ull << (GETFIELD(CQ_BAR_RANGE, val) + 24);
  878. }
  879. static void pnv_xive2_ic_cq_write(void *opaque, hwaddr offset,
  880. uint64_t val, unsigned size)
  881. {
  882. PnvXive2 *xive = PNV_XIVE2(opaque);
  883. MemoryRegion *sysmem = get_system_memory();
  884. uint32_t reg = offset >> 3;
  885. int i;
  886. switch (offset) {
  887. case CQ_XIVE_CFG:
  888. case CQ_RST_CTL: /* TODO: reset all BARs */
  889. break;
  890. case CQ_IC_BAR:
  891. xive->ic_shift = val & CQ_IC_BAR_64K ? 16 : 12;
  892. if (!(val & CQ_IC_BAR_VALID)) {
  893. xive->ic_base = 0;
  894. if (xive->cq_regs[reg] & CQ_IC_BAR_VALID) {
  895. for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) {
  896. memory_region_del_subregion(&xive->ic_mmio,
  897. &xive->ic_mmios[i]);
  898. }
  899. memory_region_del_subregion(sysmem, &xive->ic_mmio);
  900. }
  901. } else {
  902. xive->ic_base = val & ~(CQ_IC_BAR_VALID | CQ_IC_BAR_64K);
  903. if (!(xive->cq_regs[reg] & CQ_IC_BAR_VALID)) {
  904. for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) {
  905. memory_region_add_subregion(&xive->ic_mmio,
  906. pnv_xive2_ic_regions[i].pgoff << xive->ic_shift,
  907. &xive->ic_mmios[i]);
  908. }
  909. memory_region_add_subregion(sysmem, xive->ic_base,
  910. &xive->ic_mmio);
  911. }
  912. }
  913. break;
  914. case CQ_TM_BAR:
  915. xive->tm_shift = val & CQ_TM_BAR_64K ? 16 : 12;
  916. if (!(val & CQ_TM_BAR_VALID)) {
  917. xive->tm_base = 0;
  918. if (xive->cq_regs[reg] & CQ_TM_BAR_VALID) {
  919. memory_region_del_subregion(sysmem, &xive->tm_mmio);
  920. }
  921. } else {
  922. xive->tm_base = val & ~(CQ_TM_BAR_VALID | CQ_TM_BAR_64K);
  923. if (!(xive->cq_regs[reg] & CQ_TM_BAR_VALID)) {
  924. memory_region_add_subregion(sysmem, xive->tm_base,
  925. &xive->tm_mmio);
  926. }
  927. }
  928. break;
  929. case CQ_ESB_BAR:
  930. xive->esb_shift = val & CQ_BAR_64K ? 16 : 12;
  931. if (!(val & CQ_BAR_VALID)) {
  932. xive->esb_base = 0;
  933. if (xive->cq_regs[reg] & CQ_BAR_VALID) {
  934. memory_region_del_subregion(sysmem, &xive->esb_mmio);
  935. }
  936. } else {
  937. xive->esb_base = val & CQ_BAR_ADDR;
  938. if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) {
  939. memory_region_set_size(&xive->esb_mmio,
  940. pnv_xive2_bar_size(val));
  941. memory_region_add_subregion(sysmem, xive->esb_base,
  942. &xive->esb_mmio);
  943. }
  944. }
  945. break;
  946. case CQ_END_BAR:
  947. xive->end_shift = val & CQ_BAR_64K ? 16 : 12;
  948. if (!(val & CQ_BAR_VALID)) {
  949. xive->end_base = 0;
  950. if (xive->cq_regs[reg] & CQ_BAR_VALID) {
  951. memory_region_del_subregion(sysmem, &xive->end_mmio);
  952. }
  953. } else {
  954. xive->end_base = val & CQ_BAR_ADDR;
  955. if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) {
  956. memory_region_set_size(&xive->end_mmio,
  957. pnv_xive2_bar_size(val));
  958. memory_region_add_subregion(sysmem, xive->end_base,
  959. &xive->end_mmio);
  960. }
  961. }
  962. break;
  963. case CQ_NVC_BAR:
  964. xive->nvc_shift = val & CQ_BAR_64K ? 16 : 12;
  965. if (!(val & CQ_BAR_VALID)) {
  966. xive->nvc_base = 0;
  967. if (xive->cq_regs[reg] & CQ_BAR_VALID) {
  968. memory_region_del_subregion(sysmem, &xive->nvc_mmio);
  969. }
  970. } else {
  971. xive->nvc_base = val & CQ_BAR_ADDR;
  972. if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) {
  973. memory_region_set_size(&xive->nvc_mmio,
  974. pnv_xive2_bar_size(val));
  975. memory_region_add_subregion(sysmem, xive->nvc_base,
  976. &xive->nvc_mmio);
  977. }
  978. }
  979. break;
  980. case CQ_NVPG_BAR:
  981. xive->nvpg_shift = val & CQ_BAR_64K ? 16 : 12;
  982. if (!(val & CQ_BAR_VALID)) {
  983. xive->nvpg_base = 0;
  984. if (xive->cq_regs[reg] & CQ_BAR_VALID) {
  985. memory_region_del_subregion(sysmem, &xive->nvpg_mmio);
  986. }
  987. } else {
  988. xive->nvpg_base = val & CQ_BAR_ADDR;
  989. if (!(xive->cq_regs[reg] & CQ_BAR_VALID)) {
  990. memory_region_set_size(&xive->nvpg_mmio,
  991. pnv_xive2_bar_size(val));
  992. memory_region_add_subregion(sysmem, xive->nvpg_base,
  993. &xive->nvpg_mmio);
  994. }
  995. }
  996. break;
  997. case CQ_TAR: /* Set Translation Table Address */
  998. break;
  999. case CQ_TDR: /* Set Translation Table Data */
  1000. pnv_xive2_stt_set_data(xive, val);
  1001. break;
  1002. case CQ_FIRMASK_OR: /* FIR error reporting */
  1003. break;
  1004. default:
  1005. xive2_error(xive, "CQ: invalid write 0x%"HWADDR_PRIx, offset);
  1006. return;
  1007. }
  1008. xive->cq_regs[reg] = val;
  1009. }
  1010. static const MemoryRegionOps pnv_xive2_ic_cq_ops = {
  1011. .read = pnv_xive2_ic_cq_read,
  1012. .write = pnv_xive2_ic_cq_write,
  1013. .endianness = DEVICE_BIG_ENDIAN,
  1014. .valid = {
  1015. .min_access_size = 8,
  1016. .max_access_size = 8,
  1017. },
  1018. .impl = {
  1019. .min_access_size = 8,
  1020. .max_access_size = 8,
  1021. },
  1022. };
  1023. static uint8_t pnv_xive2_cache_watch_assign(uint64_t engine_mask,
  1024. uint64_t *state)
  1025. {
  1026. uint8_t val = 0xFF;
  1027. int i;
  1028. for (i = 3; i >= 0; i--) {
  1029. if (BIT(i) & engine_mask) {
  1030. if (!(BIT(i) & *state)) {
  1031. *state |= BIT(i);
  1032. val = 3 - i;
  1033. break;
  1034. }
  1035. }
  1036. }
  1037. return val;
  1038. }
  1039. static void pnv_xive2_cache_watch_release(uint64_t *state, uint8_t watch_engine)
  1040. {
  1041. uint8_t engine_bit = 3 - watch_engine;
  1042. if (*state & BIT(engine_bit)) {
  1043. *state &= ~BIT(engine_bit);
  1044. }
  1045. }
  1046. static uint8_t pnv_xive2_endc_cache_watch_assign(PnvXive2 *xive)
  1047. {
  1048. uint64_t engine_mask = GETFIELD(VC_ENDC_CFG_CACHE_WATCH_ASSIGN,
  1049. xive->vc_regs[VC_ENDC_CFG >> 3]);
  1050. uint64_t state = xive->vc_regs[VC_ENDC_WATCH_ASSIGN >> 3];
  1051. uint8_t val;
  1052. /*
  1053. * We keep track of which engines are currently busy in the
  1054. * VC_ENDC_WATCH_ASSIGN register directly. When the firmware reads
  1055. * the register, we don't return its value but the ID of an engine
  1056. * it can use.
  1057. * There are 4 engines. 0xFF means no engine is available.
  1058. */
  1059. val = pnv_xive2_cache_watch_assign(engine_mask, &state);
  1060. if (val != 0xFF) {
  1061. xive->vc_regs[VC_ENDC_WATCH_ASSIGN >> 3] = state;
  1062. }
  1063. return val;
  1064. }
  1065. static void pnv_xive2_endc_cache_watch_release(PnvXive2 *xive,
  1066. uint8_t watch_engine)
  1067. {
  1068. uint64_t state = xive->vc_regs[VC_ENDC_WATCH_ASSIGN >> 3];
  1069. pnv_xive2_cache_watch_release(&state, watch_engine);
  1070. xive->vc_regs[VC_ENDC_WATCH_ASSIGN >> 3] = state;
  1071. }
  1072. static uint64_t pnv_xive2_ic_vc_read(void *opaque, hwaddr offset,
  1073. unsigned size)
  1074. {
  1075. PnvXive2 *xive = PNV_XIVE2(opaque);
  1076. uint64_t val = 0;
  1077. uint32_t reg = offset >> 3;
  1078. uint8_t watch_engine;
  1079. switch (offset) {
  1080. /*
  1081. * VSD table settings.
  1082. */
  1083. case VC_VSD_TABLE_ADDR:
  1084. case VC_VSD_TABLE_DATA:
  1085. val = xive->vc_regs[reg];
  1086. break;
  1087. /*
  1088. * ESB cache updates (not modeled)
  1089. */
  1090. case VC_ESBC_FLUSH_CTRL:
  1091. xive->vc_regs[reg] &= ~VC_ESBC_FLUSH_CTRL_POLL_VALID;
  1092. val = xive->vc_regs[reg];
  1093. break;
  1094. case VC_ESBC_CFG:
  1095. val = xive->vc_regs[reg];
  1096. break;
  1097. /*
  1098. * EAS cache updates (not modeled)
  1099. */
  1100. case VC_EASC_FLUSH_CTRL:
  1101. xive->vc_regs[reg] &= ~VC_EASC_FLUSH_CTRL_POLL_VALID;
  1102. val = xive->vc_regs[reg];
  1103. break;
  1104. case VC_ENDC_WATCH_ASSIGN:
  1105. val = pnv_xive2_endc_cache_watch_assign(xive);
  1106. break;
  1107. case VC_ENDC_CFG:
  1108. val = xive->vc_regs[reg];
  1109. break;
  1110. /*
  1111. * END cache updates
  1112. */
  1113. case VC_ENDC_WATCH0_SPEC:
  1114. case VC_ENDC_WATCH1_SPEC:
  1115. case VC_ENDC_WATCH2_SPEC:
  1116. case VC_ENDC_WATCH3_SPEC:
  1117. watch_engine = (offset - VC_ENDC_WATCH0_SPEC) >> 6;
  1118. xive->vc_regs[reg] &= ~(VC_ENDC_WATCH_FULL | VC_ENDC_WATCH_CONFLICT);
  1119. pnv_xive2_endc_cache_watch_release(xive, watch_engine);
  1120. val = xive->vc_regs[reg];
  1121. break;
  1122. case VC_ENDC_WATCH0_DATA0:
  1123. case VC_ENDC_WATCH1_DATA0:
  1124. case VC_ENDC_WATCH2_DATA0:
  1125. case VC_ENDC_WATCH3_DATA0:
  1126. /*
  1127. * Load DATA registers from cache with data requested by the
  1128. * SPEC register
  1129. */
  1130. watch_engine = (offset - VC_ENDC_WATCH0_DATA0) >> 6;
  1131. pnv_xive2_end_cache_load(xive, watch_engine);
  1132. val = xive->vc_regs[reg];
  1133. break;
  1134. case VC_ENDC_WATCH0_DATA1 ... VC_ENDC_WATCH0_DATA3:
  1135. case VC_ENDC_WATCH1_DATA1 ... VC_ENDC_WATCH1_DATA3:
  1136. case VC_ENDC_WATCH2_DATA1 ... VC_ENDC_WATCH2_DATA3:
  1137. case VC_ENDC_WATCH3_DATA1 ... VC_ENDC_WATCH3_DATA3:
  1138. val = xive->vc_regs[reg];
  1139. break;
  1140. case VC_ENDC_FLUSH_CTRL:
  1141. xive->vc_regs[reg] &= ~VC_ENDC_FLUSH_CTRL_POLL_VALID;
  1142. val = xive->vc_regs[reg];
  1143. break;
  1144. /*
  1145. * Indirect invalidation
  1146. */
  1147. case VC_AT_MACRO_KILL_MASK:
  1148. val = xive->vc_regs[reg];
  1149. break;
  1150. case VC_AT_MACRO_KILL:
  1151. xive->vc_regs[reg] &= ~VC_AT_MACRO_KILL_VALID;
  1152. val = xive->vc_regs[reg];
  1153. break;
  1154. /*
  1155. * Interrupt fifo overflow in memory backing store (Not modeled)
  1156. */
  1157. case VC_QUEUES_CFG_REM0 ... VC_QUEUES_CFG_REM6:
  1158. val = xive->vc_regs[reg];
  1159. break;
  1160. /*
  1161. * Synchronisation
  1162. */
  1163. case VC_ENDC_SYNC_DONE:
  1164. val = VC_ENDC_SYNC_POLL_DONE;
  1165. break;
  1166. default:
  1167. xive2_error(xive, "VC: invalid read @%"HWADDR_PRIx, offset);
  1168. }
  1169. return val;
  1170. }
  1171. static void pnv_xive2_ic_vc_write(void *opaque, hwaddr offset,
  1172. uint64_t val, unsigned size)
  1173. {
  1174. PnvXive2 *xive = PNV_XIVE2(opaque);
  1175. uint32_t reg = offset >> 3;
  1176. uint8_t watch_engine;
  1177. switch (offset) {
  1178. /*
  1179. * VSD table settings.
  1180. */
  1181. case VC_VSD_TABLE_ADDR:
  1182. break;
  1183. case VC_VSD_TABLE_DATA:
  1184. pnv_xive2_vc_vst_set_data(xive, val);
  1185. break;
  1186. /*
  1187. * ESB cache updates (not modeled)
  1188. */
  1189. /* case VC_ESBC_FLUSH_CTRL: */
  1190. case VC_ESBC_FLUSH_POLL:
  1191. xive->vc_regs[VC_ESBC_FLUSH_CTRL >> 3] |= VC_ESBC_FLUSH_CTRL_POLL_VALID;
  1192. /* ESB update */
  1193. break;
  1194. case VC_ESBC_FLUSH_INJECT:
  1195. pnv_xive2_inject_notify(xive, PNV_XIVE2_CACHE_ESBC);
  1196. break;
  1197. case VC_ESBC_CFG:
  1198. break;
  1199. /*
  1200. * EAS cache updates (not modeled)
  1201. */
  1202. /* case VC_EASC_FLUSH_CTRL: */
  1203. case VC_EASC_FLUSH_POLL:
  1204. xive->vc_regs[VC_EASC_FLUSH_CTRL >> 3] |= VC_EASC_FLUSH_CTRL_POLL_VALID;
  1205. /* EAS update */
  1206. break;
  1207. case VC_EASC_FLUSH_INJECT:
  1208. pnv_xive2_inject_notify(xive, PNV_XIVE2_CACHE_EASC);
  1209. break;
  1210. case VC_ENDC_CFG:
  1211. break;
  1212. /*
  1213. * END cache updates
  1214. */
  1215. case VC_ENDC_WATCH0_SPEC:
  1216. case VC_ENDC_WATCH1_SPEC:
  1217. case VC_ENDC_WATCH2_SPEC:
  1218. case VC_ENDC_WATCH3_SPEC:
  1219. val &= ~VC_ENDC_WATCH_CONFLICT; /* HW will set this bit */
  1220. break;
  1221. case VC_ENDC_WATCH0_DATA1 ... VC_ENDC_WATCH0_DATA3:
  1222. case VC_ENDC_WATCH1_DATA1 ... VC_ENDC_WATCH1_DATA3:
  1223. case VC_ENDC_WATCH2_DATA1 ... VC_ENDC_WATCH2_DATA3:
  1224. case VC_ENDC_WATCH3_DATA1 ... VC_ENDC_WATCH3_DATA3:
  1225. break;
  1226. case VC_ENDC_WATCH0_DATA0:
  1227. case VC_ENDC_WATCH1_DATA0:
  1228. case VC_ENDC_WATCH2_DATA0:
  1229. case VC_ENDC_WATCH3_DATA0:
  1230. /* writing to DATA0 triggers the cache write */
  1231. watch_engine = (offset - VC_ENDC_WATCH0_DATA0) >> 6;
  1232. xive->vc_regs[reg] = val;
  1233. pnv_xive2_end_update(xive, watch_engine);
  1234. break;
  1235. /* case VC_ENDC_FLUSH_CTRL: */
  1236. case VC_ENDC_FLUSH_POLL:
  1237. xive->vc_regs[VC_ENDC_FLUSH_CTRL >> 3] |= VC_ENDC_FLUSH_CTRL_POLL_VALID;
  1238. break;
  1239. case VC_ENDC_FLUSH_INJECT:
  1240. pnv_xive2_inject_notify(xive, PNV_XIVE2_CACHE_ENDC);
  1241. break;
  1242. /*
  1243. * Indirect invalidation
  1244. */
  1245. case VC_AT_MACRO_KILL:
  1246. case VC_AT_MACRO_KILL_MASK:
  1247. break;
  1248. /*
  1249. * Interrupt fifo overflow in memory backing store (Not modeled)
  1250. */
  1251. case VC_QUEUES_CFG_REM0 ... VC_QUEUES_CFG_REM6:
  1252. break;
  1253. /*
  1254. * Synchronisation
  1255. */
  1256. case VC_ENDC_SYNC_DONE:
  1257. break;
  1258. default:
  1259. xive2_error(xive, "VC: invalid write @%"HWADDR_PRIx, offset);
  1260. return;
  1261. }
  1262. xive->vc_regs[reg] = val;
  1263. }
  1264. static const MemoryRegionOps pnv_xive2_ic_vc_ops = {
  1265. .read = pnv_xive2_ic_vc_read,
  1266. .write = pnv_xive2_ic_vc_write,
  1267. .endianness = DEVICE_BIG_ENDIAN,
  1268. .valid = {
  1269. .min_access_size = 8,
  1270. .max_access_size = 8,
  1271. },
  1272. .impl = {
  1273. .min_access_size = 8,
  1274. .max_access_size = 8,
  1275. },
  1276. };
  1277. static uint8_t pnv_xive2_nxc_cache_watch_assign(PnvXive2 *xive)
  1278. {
  1279. uint64_t engine_mask = GETFIELD(PC_NXC_PROC_CONFIG_WATCH_ASSIGN,
  1280. xive->pc_regs[PC_NXC_PROC_CONFIG >> 3]);
  1281. uint64_t state = xive->pc_regs[PC_NXC_WATCH_ASSIGN >> 3];
  1282. uint8_t val;
  1283. /*
  1284. * We keep track of which engines are currently busy in the
  1285. * PC_NXC_WATCH_ASSIGN register directly. When the firmware reads
  1286. * the register, we don't return its value but the ID of an engine
  1287. * it can use.
  1288. * There are 4 engines. 0xFF means no engine is available.
  1289. */
  1290. val = pnv_xive2_cache_watch_assign(engine_mask, &state);
  1291. if (val != 0xFF) {
  1292. xive->pc_regs[PC_NXC_WATCH_ASSIGN >> 3] = state;
  1293. }
  1294. return val;
  1295. }
  1296. static void pnv_xive2_nxc_cache_watch_release(PnvXive2 *xive,
  1297. uint8_t watch_engine)
  1298. {
  1299. uint64_t state = xive->pc_regs[PC_NXC_WATCH_ASSIGN >> 3];
  1300. pnv_xive2_cache_watch_release(&state, watch_engine);
  1301. xive->pc_regs[PC_NXC_WATCH_ASSIGN >> 3] = state;
  1302. }
  1303. static uint64_t pnv_xive2_ic_pc_read(void *opaque, hwaddr offset,
  1304. unsigned size)
  1305. {
  1306. PnvXive2 *xive = PNV_XIVE2(opaque);
  1307. uint64_t val = -1;
  1308. uint32_t reg = offset >> 3;
  1309. uint8_t watch_engine;
  1310. switch (offset) {
  1311. /*
  1312. * VSD table settings.
  1313. */
  1314. case PC_VSD_TABLE_ADDR:
  1315. case PC_VSD_TABLE_DATA:
  1316. val = xive->pc_regs[reg];
  1317. break;
  1318. case PC_NXC_WATCH_ASSIGN:
  1319. val = pnv_xive2_nxc_cache_watch_assign(xive);
  1320. break;
  1321. case PC_NXC_PROC_CONFIG:
  1322. val = xive->pc_regs[reg];
  1323. break;
  1324. /*
  1325. * cache updates
  1326. */
  1327. case PC_NXC_WATCH0_SPEC:
  1328. case PC_NXC_WATCH1_SPEC:
  1329. case PC_NXC_WATCH2_SPEC:
  1330. case PC_NXC_WATCH3_SPEC:
  1331. watch_engine = (offset - PC_NXC_WATCH0_SPEC) >> 6;
  1332. xive->pc_regs[reg] &= ~(PC_NXC_WATCH_FULL | PC_NXC_WATCH_CONFLICT);
  1333. pnv_xive2_nxc_cache_watch_release(xive, watch_engine);
  1334. val = xive->pc_regs[reg];
  1335. break;
  1336. case PC_NXC_WATCH0_DATA0:
  1337. case PC_NXC_WATCH1_DATA0:
  1338. case PC_NXC_WATCH2_DATA0:
  1339. case PC_NXC_WATCH3_DATA0:
  1340. /*
  1341. * Load DATA registers from cache with data requested by the
  1342. * SPEC register
  1343. */
  1344. watch_engine = (offset - PC_NXC_WATCH0_DATA0) >> 6;
  1345. pnv_xive2_nxc_cache_load(xive, watch_engine);
  1346. val = xive->pc_regs[reg];
  1347. break;
  1348. case PC_NXC_WATCH0_DATA1 ... PC_NXC_WATCH0_DATA3:
  1349. case PC_NXC_WATCH1_DATA1 ... PC_NXC_WATCH1_DATA3:
  1350. case PC_NXC_WATCH2_DATA1 ... PC_NXC_WATCH2_DATA3:
  1351. case PC_NXC_WATCH3_DATA1 ... PC_NXC_WATCH3_DATA3:
  1352. val = xive->pc_regs[reg];
  1353. break;
  1354. case PC_NXC_FLUSH_CTRL:
  1355. xive->pc_regs[reg] &= ~PC_NXC_FLUSH_CTRL_POLL_VALID;
  1356. val = xive->pc_regs[reg];
  1357. break;
  1358. /*
  1359. * Indirect invalidation
  1360. */
  1361. case PC_AT_KILL:
  1362. xive->pc_regs[reg] &= ~PC_AT_KILL_VALID;
  1363. val = xive->pc_regs[reg];
  1364. break;
  1365. default:
  1366. xive2_error(xive, "PC: invalid read @%"HWADDR_PRIx, offset);
  1367. }
  1368. return val;
  1369. }
  1370. static void pnv_xive2_pc_vst_set_data(PnvXive2 *xive, uint64_t vsd)
  1371. {
  1372. uint8_t type = GETFIELD(PC_VSD_TABLE_SELECT,
  1373. xive->pc_regs[PC_VSD_TABLE_ADDR >> 3]);
  1374. uint8_t blk = GETFIELD(PC_VSD_TABLE_ADDRESS,
  1375. xive->pc_regs[PC_VSD_TABLE_ADDR >> 3]);
  1376. pnv_xive2_vst_set_data(xive, vsd, type, blk);
  1377. }
  1378. static void pnv_xive2_ic_pc_write(void *opaque, hwaddr offset,
  1379. uint64_t val, unsigned size)
  1380. {
  1381. PnvXive2 *xive = PNV_XIVE2(opaque);
  1382. uint32_t reg = offset >> 3;
  1383. uint8_t watch_engine;
  1384. switch (offset) {
  1385. /*
  1386. * VSD table settings.
  1387. * The Xive2Router model combines both VC and PC sub-engines. We
  1388. * allow to configure the tables through both, for the rare cases
  1389. * where a table only really needs to be configured for one of
  1390. * them (e.g. the NVG table for the presenter). It assumes that
  1391. * firmware passes the same address to the VC and PC when tables
  1392. * are defined for both, which seems acceptable.
  1393. */
  1394. case PC_VSD_TABLE_ADDR:
  1395. break;
  1396. case PC_VSD_TABLE_DATA:
  1397. pnv_xive2_pc_vst_set_data(xive, val);
  1398. break;
  1399. case PC_NXC_PROC_CONFIG:
  1400. break;
  1401. /*
  1402. * cache updates
  1403. */
  1404. case PC_NXC_WATCH0_SPEC:
  1405. case PC_NXC_WATCH1_SPEC:
  1406. case PC_NXC_WATCH2_SPEC:
  1407. case PC_NXC_WATCH3_SPEC:
  1408. val &= ~PC_NXC_WATCH_CONFLICT; /* HW will set this bit */
  1409. break;
  1410. case PC_NXC_WATCH0_DATA1 ... PC_NXC_WATCH0_DATA3:
  1411. case PC_NXC_WATCH1_DATA1 ... PC_NXC_WATCH1_DATA3:
  1412. case PC_NXC_WATCH2_DATA1 ... PC_NXC_WATCH2_DATA3:
  1413. case PC_NXC_WATCH3_DATA1 ... PC_NXC_WATCH3_DATA3:
  1414. break;
  1415. case PC_NXC_WATCH0_DATA0:
  1416. case PC_NXC_WATCH1_DATA0:
  1417. case PC_NXC_WATCH2_DATA0:
  1418. case PC_NXC_WATCH3_DATA0:
  1419. /* writing to DATA0 triggers the cache write */
  1420. watch_engine = (offset - PC_NXC_WATCH0_DATA0) >> 6;
  1421. xive->pc_regs[reg] = val;
  1422. pnv_xive2_nxc_update(xive, watch_engine);
  1423. break;
  1424. /* case PC_NXC_FLUSH_CTRL: */
  1425. case PC_NXC_FLUSH_POLL:
  1426. xive->pc_regs[PC_NXC_FLUSH_CTRL >> 3] |= PC_NXC_FLUSH_CTRL_POLL_VALID;
  1427. break;
  1428. case PC_NXC_FLUSH_INJECT:
  1429. pnv_xive2_inject_notify(xive, PNV_XIVE2_CACHE_NXC);
  1430. break;
  1431. /*
  1432. * Indirect invalidation
  1433. */
  1434. case PC_AT_KILL:
  1435. case PC_AT_KILL_MASK:
  1436. break;
  1437. default:
  1438. xive2_error(xive, "PC: invalid write @%"HWADDR_PRIx, offset);
  1439. return;
  1440. }
  1441. xive->pc_regs[reg] = val;
  1442. }
  1443. static const MemoryRegionOps pnv_xive2_ic_pc_ops = {
  1444. .read = pnv_xive2_ic_pc_read,
  1445. .write = pnv_xive2_ic_pc_write,
  1446. .endianness = DEVICE_BIG_ENDIAN,
  1447. .valid = {
  1448. .min_access_size = 8,
  1449. .max_access_size = 8,
  1450. },
  1451. .impl = {
  1452. .min_access_size = 8,
  1453. .max_access_size = 8,
  1454. },
  1455. };
  1456. static uint64_t pnv_xive2_ic_tctxt_read(void *opaque, hwaddr offset,
  1457. unsigned size)
  1458. {
  1459. PnvXive2 *xive = PNV_XIVE2(opaque);
  1460. uint64_t val = -1;
  1461. uint32_t reg = offset >> 3;
  1462. switch (offset) {
  1463. /*
  1464. * XIVE2 hardware thread enablement
  1465. */
  1466. case TCTXT_EN0:
  1467. case TCTXT_EN1:
  1468. val = xive->tctxt_regs[reg];
  1469. break;
  1470. case TCTXT_EN0_SET:
  1471. case TCTXT_EN0_RESET:
  1472. val = xive->tctxt_regs[TCTXT_EN0 >> 3];
  1473. break;
  1474. case TCTXT_EN1_SET:
  1475. case TCTXT_EN1_RESET:
  1476. val = xive->tctxt_regs[TCTXT_EN1 >> 3];
  1477. break;
  1478. case TCTXT_CFG:
  1479. val = xive->tctxt_regs[reg];
  1480. break;
  1481. default:
  1482. xive2_error(xive, "TCTXT: invalid read @%"HWADDR_PRIx, offset);
  1483. }
  1484. return val;
  1485. }
  1486. static void pnv_xive2_ic_tctxt_write(void *opaque, hwaddr offset,
  1487. uint64_t val, unsigned size)
  1488. {
  1489. PnvXive2 *xive = PNV_XIVE2(opaque);
  1490. uint32_t reg = offset >> 3;
  1491. switch (offset) {
  1492. /*
  1493. * XIVE2 hardware thread enablement
  1494. */
  1495. case TCTXT_EN0: /* Physical Thread Enable */
  1496. case TCTXT_EN1: /* Physical Thread Enable (fused core) */
  1497. xive->tctxt_regs[reg] = val;
  1498. break;
  1499. case TCTXT_EN0_SET:
  1500. xive->tctxt_regs[TCTXT_EN0 >> 3] |= val;
  1501. break;
  1502. case TCTXT_EN1_SET:
  1503. xive->tctxt_regs[TCTXT_EN1 >> 3] |= val;
  1504. break;
  1505. case TCTXT_EN0_RESET:
  1506. xive->tctxt_regs[TCTXT_EN0 >> 3] &= ~val;
  1507. break;
  1508. case TCTXT_EN1_RESET:
  1509. xive->tctxt_regs[TCTXT_EN1 >> 3] &= ~val;
  1510. break;
  1511. case TCTXT_CFG:
  1512. xive->tctxt_regs[reg] = val;
  1513. break;
  1514. default:
  1515. xive2_error(xive, "TCTXT: invalid write @%"HWADDR_PRIx, offset);
  1516. return;
  1517. }
  1518. }
  1519. static const MemoryRegionOps pnv_xive2_ic_tctxt_ops = {
  1520. .read = pnv_xive2_ic_tctxt_read,
  1521. .write = pnv_xive2_ic_tctxt_write,
  1522. .endianness = DEVICE_BIG_ENDIAN,
  1523. .valid = {
  1524. .min_access_size = 8,
  1525. .max_access_size = 8,
  1526. },
  1527. .impl = {
  1528. .min_access_size = 8,
  1529. .max_access_size = 8,
  1530. },
  1531. };
  1532. /*
  1533. * Redirect XSCOM to MMIO handlers
  1534. */
  1535. static uint64_t pnv_xive2_xscom_read(void *opaque, hwaddr offset,
  1536. unsigned size)
  1537. {
  1538. PnvXive2 *xive = PNV_XIVE2(opaque);
  1539. uint64_t val = -1;
  1540. uint32_t xscom_reg = offset >> 3;
  1541. uint32_t mmio_offset = (xscom_reg & 0xFF) << 3;
  1542. switch (xscom_reg) {
  1543. case 0x000 ... 0x0FF:
  1544. val = pnv_xive2_ic_cq_read(opaque, mmio_offset, size);
  1545. break;
  1546. case 0x100 ... 0x1FF:
  1547. val = pnv_xive2_ic_vc_read(opaque, mmio_offset, size);
  1548. break;
  1549. case 0x200 ... 0x2FF:
  1550. val = pnv_xive2_ic_pc_read(opaque, mmio_offset, size);
  1551. break;
  1552. case 0x300 ... 0x3FF:
  1553. val = pnv_xive2_ic_tctxt_read(opaque, mmio_offset, size);
  1554. break;
  1555. default:
  1556. xive2_error(xive, "XSCOM: invalid read @%"HWADDR_PRIx, offset);
  1557. }
  1558. return val;
  1559. }
  1560. static void pnv_xive2_xscom_write(void *opaque, hwaddr offset,
  1561. uint64_t val, unsigned size)
  1562. {
  1563. PnvXive2 *xive = PNV_XIVE2(opaque);
  1564. uint32_t xscom_reg = offset >> 3;
  1565. uint32_t mmio_offset = (xscom_reg & 0xFF) << 3;
  1566. switch (xscom_reg) {
  1567. case 0x000 ... 0x0FF:
  1568. pnv_xive2_ic_cq_write(opaque, mmio_offset, val, size);
  1569. break;
  1570. case 0x100 ... 0x1FF:
  1571. pnv_xive2_ic_vc_write(opaque, mmio_offset, val, size);
  1572. break;
  1573. case 0x200 ... 0x2FF:
  1574. pnv_xive2_ic_pc_write(opaque, mmio_offset, val, size);
  1575. break;
  1576. case 0x300 ... 0x3FF:
  1577. pnv_xive2_ic_tctxt_write(opaque, mmio_offset, val, size);
  1578. break;
  1579. default:
  1580. xive2_error(xive, "XSCOM: invalid write @%"HWADDR_PRIx, offset);
  1581. }
  1582. }
  1583. static const MemoryRegionOps pnv_xive2_xscom_ops = {
  1584. .read = pnv_xive2_xscom_read,
  1585. .write = pnv_xive2_xscom_write,
  1586. .endianness = DEVICE_BIG_ENDIAN,
  1587. .valid = {
  1588. .min_access_size = 8,
  1589. .max_access_size = 8,
  1590. },
  1591. .impl = {
  1592. .min_access_size = 8,
  1593. .max_access_size = 8,
  1594. },
  1595. };
  1596. /*
  1597. * Notify port page. The layout is compatible between 4K and 64K pages :
  1598. *
  1599. * Page 1 Notify page (writes only)
  1600. * 0x000 - 0x7FF IPI interrupt (NPU)
  1601. * 0x800 - 0xFFF HW interrupt triggers (PSI, PHB)
  1602. */
  1603. static void pnv_xive2_ic_hw_trigger(PnvXive2 *xive, hwaddr addr,
  1604. uint64_t val)
  1605. {
  1606. uint8_t blk;
  1607. uint32_t idx;
  1608. if (val & XIVE_TRIGGER_END) {
  1609. xive2_error(xive, "IC: END trigger at @0x%"HWADDR_PRIx" data 0x%"PRIx64,
  1610. addr, val);
  1611. return;
  1612. }
  1613. /*
  1614. * Forward the source event notification directly to the Router.
  1615. * The source interrupt number should already be correctly encoded
  1616. * with the chip block id by the sending device (PHB, PSI).
  1617. */
  1618. blk = XIVE_EAS_BLOCK(val);
  1619. idx = XIVE_EAS_INDEX(val);
  1620. xive2_router_notify(XIVE_NOTIFIER(xive), XIVE_EAS(blk, idx),
  1621. !!(val & XIVE_TRIGGER_PQ));
  1622. }
  1623. static void pnv_xive2_ic_notify_write(void *opaque, hwaddr offset,
  1624. uint64_t val, unsigned size)
  1625. {
  1626. PnvXive2 *xive = PNV_XIVE2(opaque);
  1627. /* VC: IPI triggers */
  1628. switch (offset) {
  1629. case 0x000 ... 0x7FF:
  1630. /* TODO: check IPI notify sub-page routing */
  1631. pnv_xive2_ic_hw_trigger(opaque, offset, val);
  1632. break;
  1633. /* VC: HW triggers */
  1634. case 0x800 ... 0xFFF:
  1635. pnv_xive2_ic_hw_trigger(opaque, offset, val);
  1636. break;
  1637. default:
  1638. xive2_error(xive, "NOTIFY: invalid write @%"HWADDR_PRIx, offset);
  1639. }
  1640. }
  1641. static uint64_t pnv_xive2_ic_notify_read(void *opaque, hwaddr offset,
  1642. unsigned size)
  1643. {
  1644. PnvXive2 *xive = PNV_XIVE2(opaque);
  1645. /* loads are invalid */
  1646. xive2_error(xive, "NOTIFY: invalid read @%"HWADDR_PRIx, offset);
  1647. return -1;
  1648. }
  1649. static const MemoryRegionOps pnv_xive2_ic_notify_ops = {
  1650. .read = pnv_xive2_ic_notify_read,
  1651. .write = pnv_xive2_ic_notify_write,
  1652. .endianness = DEVICE_BIG_ENDIAN,
  1653. .valid = {
  1654. .min_access_size = 8,
  1655. .max_access_size = 8,
  1656. },
  1657. .impl = {
  1658. .min_access_size = 8,
  1659. .max_access_size = 8,
  1660. },
  1661. };
  1662. static uint64_t pnv_xive2_ic_lsi_read(void *opaque, hwaddr offset,
  1663. unsigned size)
  1664. {
  1665. PnvXive2 *xive = PNV_XIVE2(opaque);
  1666. xive2_error(xive, "LSI: invalid read @%"HWADDR_PRIx, offset);
  1667. return -1;
  1668. }
  1669. static void pnv_xive2_ic_lsi_write(void *opaque, hwaddr offset,
  1670. uint64_t val, unsigned size)
  1671. {
  1672. PnvXive2 *xive = PNV_XIVE2(opaque);
  1673. xive2_error(xive, "LSI: invalid write @%"HWADDR_PRIx, offset);
  1674. }
  1675. static const MemoryRegionOps pnv_xive2_ic_lsi_ops = {
  1676. .read = pnv_xive2_ic_lsi_read,
  1677. .write = pnv_xive2_ic_lsi_write,
  1678. .endianness = DEVICE_BIG_ENDIAN,
  1679. .valid = {
  1680. .min_access_size = 8,
  1681. .max_access_size = 8,
  1682. },
  1683. .impl = {
  1684. .min_access_size = 8,
  1685. .max_access_size = 8,
  1686. },
  1687. };
  1688. /*
  1689. * Sync MMIO page (write only)
  1690. */
  1691. #define PNV_XIVE2_SYNC_IPI 0x000
  1692. #define PNV_XIVE2_SYNC_HW 0x080
  1693. #define PNV_XIVE2_SYNC_NxC 0x100
  1694. #define PNV_XIVE2_SYNC_INT 0x180
  1695. #define PNV_XIVE2_SYNC_OS_ESC 0x200
  1696. #define PNV_XIVE2_SYNC_POOL_ESC 0x280
  1697. #define PNV_XIVE2_SYNC_HARD_ESC 0x300
  1698. #define PNV_XIVE2_SYNC_NXC_LD_LCL_NCO 0x800
  1699. #define PNV_XIVE2_SYNC_NXC_LD_LCL_CO 0x880
  1700. #define PNV_XIVE2_SYNC_NXC_ST_LCL_NCI 0x900
  1701. #define PNV_XIVE2_SYNC_NXC_ST_LCL_CI 0x980
  1702. #define PNV_XIVE2_SYNC_NXC_ST_RMT_NCI 0xA00
  1703. #define PNV_XIVE2_SYNC_NXC_ST_RMT_CI 0xA80
  1704. static uint64_t pnv_xive2_ic_sync_read(void *opaque, hwaddr offset,
  1705. unsigned size)
  1706. {
  1707. PnvXive2 *xive = PNV_XIVE2(opaque);
  1708. /* loads are invalid */
  1709. xive2_error(xive, "SYNC: invalid read @%"HWADDR_PRIx, offset);
  1710. return -1;
  1711. }
  1712. /*
  1713. * The sync MMIO space spans two pages. The lower page is use for
  1714. * queue sync "poll" requests while the upper page is used for queue
  1715. * sync "inject" requests. Inject requests require the HW to write
  1716. * a byte of all 1's to a predetermined location in memory in order
  1717. * to signal completion of the request. Both pages have the same
  1718. * layout, so it is easiest to handle both with a single function.
  1719. */
  1720. static void pnv_xive2_ic_sync_write(void *opaque, hwaddr offset,
  1721. uint64_t val, unsigned size)
  1722. {
  1723. PnvXive2 *xive = PNV_XIVE2(opaque);
  1724. int inject_type;
  1725. hwaddr pg_offset_mask = (1ull << xive->ic_shift) - 1;
  1726. /* adjust offset for inject page */
  1727. hwaddr adj_offset = offset & pg_offset_mask;
  1728. switch (adj_offset) {
  1729. case PNV_XIVE2_SYNC_IPI:
  1730. inject_type = PNV_XIVE2_QUEUE_IPI;
  1731. break;
  1732. case PNV_XIVE2_SYNC_HW:
  1733. inject_type = PNV_XIVE2_QUEUE_HW;
  1734. break;
  1735. case PNV_XIVE2_SYNC_NxC:
  1736. inject_type = PNV_XIVE2_QUEUE_NXC;
  1737. break;
  1738. case PNV_XIVE2_SYNC_INT:
  1739. inject_type = PNV_XIVE2_QUEUE_INT;
  1740. break;
  1741. case PNV_XIVE2_SYNC_OS_ESC:
  1742. inject_type = PNV_XIVE2_QUEUE_OS;
  1743. break;
  1744. case PNV_XIVE2_SYNC_POOL_ESC:
  1745. inject_type = PNV_XIVE2_QUEUE_POOL;
  1746. break;
  1747. case PNV_XIVE2_SYNC_HARD_ESC:
  1748. inject_type = PNV_XIVE2_QUEUE_HARD;
  1749. break;
  1750. case PNV_XIVE2_SYNC_NXC_LD_LCL_NCO:
  1751. inject_type = PNV_XIVE2_QUEUE_NXC_LD_LCL_NCO;
  1752. break;
  1753. case PNV_XIVE2_SYNC_NXC_LD_LCL_CO:
  1754. inject_type = PNV_XIVE2_QUEUE_NXC_LD_LCL_CO;
  1755. break;
  1756. case PNV_XIVE2_SYNC_NXC_ST_LCL_NCI:
  1757. inject_type = PNV_XIVE2_QUEUE_NXC_ST_LCL_NCI;
  1758. break;
  1759. case PNV_XIVE2_SYNC_NXC_ST_LCL_CI:
  1760. inject_type = PNV_XIVE2_QUEUE_NXC_ST_LCL_CI;
  1761. break;
  1762. case PNV_XIVE2_SYNC_NXC_ST_RMT_NCI:
  1763. inject_type = PNV_XIVE2_QUEUE_NXC_ST_RMT_NCI;
  1764. break;
  1765. case PNV_XIVE2_SYNC_NXC_ST_RMT_CI:
  1766. inject_type = PNV_XIVE2_QUEUE_NXC_ST_RMT_CI;
  1767. break;
  1768. default:
  1769. xive2_error(xive, "SYNC: invalid write @%"HWADDR_PRIx, offset);
  1770. return;
  1771. }
  1772. /* Write Queue Sync notification byte if writing to sync inject page */
  1773. if ((offset & ~pg_offset_mask) != 0) {
  1774. pnv_xive2_inject_notify(xive, inject_type);
  1775. }
  1776. }
  1777. static const MemoryRegionOps pnv_xive2_ic_sync_ops = {
  1778. .read = pnv_xive2_ic_sync_read,
  1779. .write = pnv_xive2_ic_sync_write,
  1780. .endianness = DEVICE_BIG_ENDIAN,
  1781. .valid = {
  1782. .min_access_size = 8,
  1783. .max_access_size = 8,
  1784. },
  1785. .impl = {
  1786. .min_access_size = 8,
  1787. .max_access_size = 8,
  1788. },
  1789. };
  1790. /*
  1791. * When the TM direct pages of the IC controller are accessed, the
  1792. * target HW thread is deduced from the page offset.
  1793. */
  1794. static uint32_t pnv_xive2_ic_tm_get_pir(PnvXive2 *xive, hwaddr offset)
  1795. {
  1796. /* On P10, the node ID shift in the PIR register is 8 bits */
  1797. return xive->chip->chip_id << 8 | offset >> xive->ic_shift;
  1798. }
  1799. static uint32_t pnv_xive2_ic_tm_get_hw_page_offset(PnvXive2 *xive,
  1800. hwaddr offset)
  1801. {
  1802. /*
  1803. * Indirect TIMA accesses are similar to direct accesses for
  1804. * privilege ring 0. So remove any traces of the hw thread ID from
  1805. * the offset in the IC BAR as it could be interpreted as the ring
  1806. * privilege when calling the underlying direct access functions.
  1807. */
  1808. return offset & ((1ull << xive->ic_shift) - 1);
  1809. }
  1810. static XiveTCTX *pnv_xive2_get_indirect_tctx(PnvXive2 *xive, uint32_t pir)
  1811. {
  1812. PnvChip *chip = xive->chip;
  1813. PowerPCCPU *cpu = NULL;
  1814. cpu = pnv_chip_find_cpu(chip, pir);
  1815. if (!cpu) {
  1816. xive2_error(xive, "IC: invalid PIR %x for indirect access", pir);
  1817. return NULL;
  1818. }
  1819. if (!pnv_xive2_is_cpu_enabled(xive, cpu)) {
  1820. xive2_error(xive, "IC: CPU %x is not enabled", pir);
  1821. }
  1822. return XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  1823. }
  1824. static uint64_t pnv_xive2_ic_tm_indirect_read(void *opaque, hwaddr offset,
  1825. unsigned size)
  1826. {
  1827. PnvXive2 *xive = PNV_XIVE2(opaque);
  1828. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1829. hwaddr hw_page_offset;
  1830. uint32_t pir;
  1831. XiveTCTX *tctx;
  1832. uint64_t val = -1;
  1833. pir = pnv_xive2_ic_tm_get_pir(xive, offset);
  1834. hw_page_offset = pnv_xive2_ic_tm_get_hw_page_offset(xive, offset);
  1835. tctx = pnv_xive2_get_indirect_tctx(xive, pir);
  1836. if (tctx) {
  1837. val = xive_tctx_tm_read(xptr, tctx, hw_page_offset, size);
  1838. }
  1839. return val;
  1840. }
  1841. static void pnv_xive2_ic_tm_indirect_write(void *opaque, hwaddr offset,
  1842. uint64_t val, unsigned size)
  1843. {
  1844. PnvXive2 *xive = PNV_XIVE2(opaque);
  1845. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1846. hwaddr hw_page_offset;
  1847. uint32_t pir;
  1848. XiveTCTX *tctx;
  1849. pir = pnv_xive2_ic_tm_get_pir(xive, offset);
  1850. hw_page_offset = pnv_xive2_ic_tm_get_hw_page_offset(xive, offset);
  1851. tctx = pnv_xive2_get_indirect_tctx(xive, pir);
  1852. if (tctx) {
  1853. xive_tctx_tm_write(xptr, tctx, hw_page_offset, val, size);
  1854. }
  1855. }
  1856. static const MemoryRegionOps pnv_xive2_ic_tm_indirect_ops = {
  1857. .read = pnv_xive2_ic_tm_indirect_read,
  1858. .write = pnv_xive2_ic_tm_indirect_write,
  1859. .endianness = DEVICE_BIG_ENDIAN,
  1860. .valid = {
  1861. .min_access_size = 1,
  1862. .max_access_size = 8,
  1863. },
  1864. .impl = {
  1865. .min_access_size = 1,
  1866. .max_access_size = 8,
  1867. },
  1868. };
  1869. /*
  1870. * TIMA ops
  1871. */
  1872. static void pnv_xive2_tm_write(void *opaque, hwaddr offset,
  1873. uint64_t value, unsigned size)
  1874. {
  1875. PowerPCCPU *cpu = POWERPC_CPU(current_cpu);
  1876. PnvXive2 *xive = pnv_xive2_tm_get_xive(cpu);
  1877. XiveTCTX *tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  1878. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1879. xive_tctx_tm_write(xptr, tctx, offset, value, size);
  1880. }
  1881. static uint64_t pnv_xive2_tm_read(void *opaque, hwaddr offset, unsigned size)
  1882. {
  1883. PowerPCCPU *cpu = POWERPC_CPU(current_cpu);
  1884. PnvXive2 *xive = pnv_xive2_tm_get_xive(cpu);
  1885. XiveTCTX *tctx = XIVE_TCTX(pnv_cpu_state(cpu)->intc);
  1886. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1887. return xive_tctx_tm_read(xptr, tctx, offset, size);
  1888. }
  1889. static const MemoryRegionOps pnv_xive2_tm_ops = {
  1890. .read = pnv_xive2_tm_read,
  1891. .write = pnv_xive2_tm_write,
  1892. .endianness = DEVICE_BIG_ENDIAN,
  1893. .valid = {
  1894. .min_access_size = 1,
  1895. .max_access_size = 8,
  1896. },
  1897. .impl = {
  1898. .min_access_size = 1,
  1899. .max_access_size = 8,
  1900. },
  1901. };
  1902. static uint64_t pnv_xive2_nvc_read(void *opaque, hwaddr addr,
  1903. unsigned size)
  1904. {
  1905. PnvXive2 *xive = PNV_XIVE2(opaque);
  1906. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1907. uint32_t page = addr >> xive->nvpg_shift;
  1908. uint16_t op = addr & 0xFFF;
  1909. uint8_t blk = pnv_xive2_block_id(xive);
  1910. if (size != 2) {
  1911. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid nvc load size %d\n",
  1912. size);
  1913. return -1;
  1914. }
  1915. return xive2_presenter_nvgc_backlog_op(xptr, true, blk, page, op, 1);
  1916. }
  1917. static void pnv_xive2_nvc_write(void *opaque, hwaddr addr,
  1918. uint64_t val, unsigned size)
  1919. {
  1920. PnvXive2 *xive = PNV_XIVE2(opaque);
  1921. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1922. uint32_t page = addr >> xive->nvc_shift;
  1923. uint16_t op = addr & 0xFFF;
  1924. uint8_t blk = pnv_xive2_block_id(xive);
  1925. if (size != 1) {
  1926. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid nvc write size %d\n",
  1927. size);
  1928. return;
  1929. }
  1930. (void)xive2_presenter_nvgc_backlog_op(xptr, true, blk, page, op, val);
  1931. }
  1932. static const MemoryRegionOps pnv_xive2_nvc_ops = {
  1933. .read = pnv_xive2_nvc_read,
  1934. .write = pnv_xive2_nvc_write,
  1935. .endianness = DEVICE_BIG_ENDIAN,
  1936. .valid = {
  1937. .min_access_size = 1,
  1938. .max_access_size = 8,
  1939. },
  1940. .impl = {
  1941. .min_access_size = 1,
  1942. .max_access_size = 8,
  1943. },
  1944. };
  1945. static uint64_t pnv_xive2_nvpg_read(void *opaque, hwaddr addr,
  1946. unsigned size)
  1947. {
  1948. PnvXive2 *xive = PNV_XIVE2(opaque);
  1949. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1950. uint32_t page = addr >> xive->nvpg_shift;
  1951. uint16_t op = addr & 0xFFF;
  1952. uint32_t index = page >> 1;
  1953. uint8_t blk = pnv_xive2_block_id(xive);
  1954. if (size != 2) {
  1955. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid nvpg load size %d\n",
  1956. size);
  1957. return -1;
  1958. }
  1959. if (page % 2) {
  1960. /* odd page - NVG */
  1961. return xive2_presenter_nvgc_backlog_op(xptr, false, blk, index, op, 1);
  1962. } else {
  1963. /* even page - NVP */
  1964. return xive2_presenter_nvp_backlog_op(xptr, blk, index, op);
  1965. }
  1966. }
  1967. static void pnv_xive2_nvpg_write(void *opaque, hwaddr addr,
  1968. uint64_t val, unsigned size)
  1969. {
  1970. PnvXive2 *xive = PNV_XIVE2(opaque);
  1971. XivePresenter *xptr = XIVE_PRESENTER(xive);
  1972. uint32_t page = addr >> xive->nvpg_shift;
  1973. uint16_t op = addr & 0xFFF;
  1974. uint32_t index = page >> 1;
  1975. uint8_t blk = pnv_xive2_block_id(xive);
  1976. if (size != 1) {
  1977. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid nvpg write size %d\n",
  1978. size);
  1979. return;
  1980. }
  1981. if (page % 2) {
  1982. /* odd page - NVG */
  1983. (void)xive2_presenter_nvgc_backlog_op(xptr, false, blk, index, op, val);
  1984. } else {
  1985. /* even page - NVP */
  1986. (void)xive2_presenter_nvp_backlog_op(xptr, blk, index, op);
  1987. }
  1988. }
  1989. static const MemoryRegionOps pnv_xive2_nvpg_ops = {
  1990. .read = pnv_xive2_nvpg_read,
  1991. .write = pnv_xive2_nvpg_write,
  1992. .endianness = DEVICE_BIG_ENDIAN,
  1993. .valid = {
  1994. .min_access_size = 1,
  1995. .max_access_size = 8,
  1996. },
  1997. .impl = {
  1998. .min_access_size = 1,
  1999. .max_access_size = 8,
  2000. },
  2001. };
  2002. /*
  2003. * POWER10 default capabilities: 0x2000120076f000FC
  2004. */
  2005. #define PNV_XIVE2_CAPABILITIES 0x2000120076f000FC
  2006. /*
  2007. * POWER10 default configuration: 0x0030000033000000
  2008. *
  2009. * 8bits thread id was dropped for P10
  2010. */
  2011. #define PNV_XIVE2_CONFIGURATION 0x0030000033000000
  2012. static void pnv_xive2_reset(void *dev)
  2013. {
  2014. PnvXive2 *xive = PNV_XIVE2(dev);
  2015. XiveSource *xsrc = &xive->ipi_source;
  2016. Xive2EndSource *end_xsrc = &xive->end_source;
  2017. xive->cq_regs[CQ_XIVE_CAP >> 3] = xive->capabilities;
  2018. xive->cq_regs[CQ_XIVE_CFG >> 3] = xive->config;
  2019. /* HW hardwires the #Topology of the chip in the block field */
  2020. xive->cq_regs[CQ_XIVE_CFG >> 3] |=
  2021. SETFIELD(CQ_XIVE_CFG_HYP_HARD_BLOCK_ID, 0ull, xive->chip->chip_id);
  2022. /* VC and PC cache watch assign mechanism */
  2023. xive->vc_regs[VC_ENDC_CFG >> 3] =
  2024. SETFIELD(VC_ENDC_CFG_CACHE_WATCH_ASSIGN, 0ull, 0b0111);
  2025. xive->pc_regs[PC_NXC_PROC_CONFIG >> 3] =
  2026. SETFIELD(PC_NXC_PROC_CONFIG_WATCH_ASSIGN, 0ull, 0b0111);
  2027. /* Set default page size to 64k */
  2028. xive->ic_shift = xive->esb_shift = xive->end_shift = 16;
  2029. xive->nvc_shift = xive->nvpg_shift = xive->tm_shift = 16;
  2030. /* Clear source MMIOs */
  2031. if (memory_region_is_mapped(&xsrc->esb_mmio)) {
  2032. memory_region_del_subregion(&xive->esb_mmio, &xsrc->esb_mmio);
  2033. }
  2034. if (memory_region_is_mapped(&end_xsrc->esb_mmio)) {
  2035. memory_region_del_subregion(&xive->end_mmio, &end_xsrc->esb_mmio);
  2036. }
  2037. }
  2038. /*
  2039. * Maximum number of IRQs and ENDs supported by HW. Will be tuned by
  2040. * software.
  2041. */
  2042. #define PNV_XIVE2_NR_IRQS (PNV10_XIVE2_ESB_SIZE / (1ull << XIVE_ESB_64K_2PAGE))
  2043. #define PNV_XIVE2_NR_ENDS (PNV10_XIVE2_END_SIZE / (1ull << XIVE_ESB_64K_2PAGE))
  2044. static void pnv_xive2_realize(DeviceState *dev, Error **errp)
  2045. {
  2046. PnvXive2 *xive = PNV_XIVE2(dev);
  2047. PnvXive2Class *pxc = PNV_XIVE2_GET_CLASS(dev);
  2048. XiveSource *xsrc = &xive->ipi_source;
  2049. Xive2EndSource *end_xsrc = &xive->end_source;
  2050. Error *local_err = NULL;
  2051. int i;
  2052. pxc->parent_realize(dev, &local_err);
  2053. if (local_err) {
  2054. error_propagate(errp, local_err);
  2055. return;
  2056. }
  2057. assert(xive->chip);
  2058. /*
  2059. * The XiveSource and Xive2EndSource objects are realized with the
  2060. * maximum allowed HW configuration. The ESB MMIO regions will be
  2061. * resized dynamically when the controller is configured by the FW
  2062. * to limit accesses to resources not provisioned.
  2063. */
  2064. object_property_set_int(OBJECT(xsrc), "flags", XIVE_SRC_STORE_EOI,
  2065. &error_fatal);
  2066. object_property_set_int(OBJECT(xsrc), "nr-irqs", PNV_XIVE2_NR_IRQS,
  2067. &error_fatal);
  2068. object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive),
  2069. &error_fatal);
  2070. qdev_realize(DEVICE(xsrc), NULL, &local_err);
  2071. if (local_err) {
  2072. error_propagate(errp, local_err);
  2073. return;
  2074. }
  2075. object_property_set_int(OBJECT(end_xsrc), "nr-ends", PNV_XIVE2_NR_ENDS,
  2076. &error_fatal);
  2077. object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
  2078. &error_abort);
  2079. qdev_realize(DEVICE(end_xsrc), NULL, &local_err);
  2080. if (local_err) {
  2081. error_propagate(errp, local_err);
  2082. return;
  2083. }
  2084. /* XSCOM region, used for initial configuration of the BARs */
  2085. memory_region_init_io(&xive->xscom_regs, OBJECT(dev),
  2086. &pnv_xive2_xscom_ops, xive, "xscom-xive",
  2087. PNV10_XSCOM_XIVE2_SIZE << 3);
  2088. /* Interrupt controller MMIO regions */
  2089. xive->ic_shift = 16;
  2090. memory_region_init(&xive->ic_mmio, OBJECT(dev), "xive-ic",
  2091. PNV10_XIVE2_IC_SIZE);
  2092. for (i = 0; i < ARRAY_SIZE(xive->ic_mmios); i++) {
  2093. memory_region_init_io(&xive->ic_mmios[i], OBJECT(dev),
  2094. pnv_xive2_ic_regions[i].ops, xive,
  2095. pnv_xive2_ic_regions[i].name,
  2096. pnv_xive2_ic_regions[i].pgsize << xive->ic_shift);
  2097. }
  2098. /*
  2099. * VC MMIO regions.
  2100. */
  2101. xive->esb_shift = 16;
  2102. xive->end_shift = 16;
  2103. memory_region_init(&xive->esb_mmio, OBJECT(xive), "xive-esb",
  2104. PNV10_XIVE2_ESB_SIZE);
  2105. memory_region_init(&xive->end_mmio, OBJECT(xive), "xive-end",
  2106. PNV10_XIVE2_END_SIZE);
  2107. /* Presenter Controller MMIO region (not modeled) */
  2108. xive->nvc_shift = 16;
  2109. xive->nvpg_shift = 16;
  2110. memory_region_init_io(&xive->nvc_mmio, OBJECT(dev),
  2111. &pnv_xive2_nvc_ops, xive,
  2112. "xive-nvc", PNV10_XIVE2_NVC_SIZE);
  2113. memory_region_init_io(&xive->nvpg_mmio, OBJECT(dev),
  2114. &pnv_xive2_nvpg_ops, xive,
  2115. "xive-nvpg", PNV10_XIVE2_NVPG_SIZE);
  2116. /* Thread Interrupt Management Area (Direct) */
  2117. xive->tm_shift = 16;
  2118. memory_region_init_io(&xive->tm_mmio, OBJECT(dev), &pnv_xive2_tm_ops,
  2119. xive, "xive-tima", PNV10_XIVE2_TM_SIZE);
  2120. qemu_register_reset(pnv_xive2_reset, dev);
  2121. }
  2122. static const Property pnv_xive2_properties[] = {
  2123. DEFINE_PROP_UINT64("ic-bar", PnvXive2, ic_base, 0),
  2124. DEFINE_PROP_UINT64("esb-bar", PnvXive2, esb_base, 0),
  2125. DEFINE_PROP_UINT64("end-bar", PnvXive2, end_base, 0),
  2126. DEFINE_PROP_UINT64("nvc-bar", PnvXive2, nvc_base, 0),
  2127. DEFINE_PROP_UINT64("nvpg-bar", PnvXive2, nvpg_base, 0),
  2128. DEFINE_PROP_UINT64("tm-bar", PnvXive2, tm_base, 0),
  2129. DEFINE_PROP_UINT64("capabilities", PnvXive2, capabilities,
  2130. PNV_XIVE2_CAPABILITIES),
  2131. DEFINE_PROP_UINT64("config", PnvXive2, config,
  2132. PNV_XIVE2_CONFIGURATION),
  2133. DEFINE_PROP_LINK("chip", PnvXive2, chip, TYPE_PNV_CHIP, PnvChip *),
  2134. };
  2135. static void pnv_xive2_instance_init(Object *obj)
  2136. {
  2137. PnvXive2 *xive = PNV_XIVE2(obj);
  2138. object_initialize_child(obj, "ipi_source", &xive->ipi_source,
  2139. TYPE_XIVE_SOURCE);
  2140. object_initialize_child(obj, "end_source", &xive->end_source,
  2141. TYPE_XIVE2_END_SOURCE);
  2142. }
  2143. static int pnv_xive2_dt_xscom(PnvXScomInterface *dev, void *fdt,
  2144. int xscom_offset)
  2145. {
  2146. const char compat_p10[] = "ibm,power10-xive-x";
  2147. char *name;
  2148. int offset;
  2149. uint32_t reg[] = {
  2150. cpu_to_be32(PNV10_XSCOM_XIVE2_BASE),
  2151. cpu_to_be32(PNV10_XSCOM_XIVE2_SIZE)
  2152. };
  2153. name = g_strdup_printf("xive@%x", PNV10_XSCOM_XIVE2_BASE);
  2154. offset = fdt_add_subnode(fdt, xscom_offset, name);
  2155. _FDT(offset);
  2156. g_free(name);
  2157. _FDT((fdt_setprop(fdt, offset, "reg", reg, sizeof(reg))));
  2158. _FDT(fdt_setprop(fdt, offset, "compatible", compat_p10,
  2159. sizeof(compat_p10)));
  2160. return 0;
  2161. }
  2162. static void pnv_xive2_class_init(ObjectClass *klass, void *data)
  2163. {
  2164. DeviceClass *dc = DEVICE_CLASS(klass);
  2165. PnvXScomInterfaceClass *xdc = PNV_XSCOM_INTERFACE_CLASS(klass);
  2166. Xive2RouterClass *xrc = XIVE2_ROUTER_CLASS(klass);
  2167. XiveNotifierClass *xnc = XIVE_NOTIFIER_CLASS(klass);
  2168. XivePresenterClass *xpc = XIVE_PRESENTER_CLASS(klass);
  2169. PnvXive2Class *pxc = PNV_XIVE2_CLASS(klass);
  2170. xdc->dt_xscom = pnv_xive2_dt_xscom;
  2171. dc->desc = "PowerNV XIVE2 Interrupt Controller (POWER10)";
  2172. device_class_set_parent_realize(dc, pnv_xive2_realize,
  2173. &pxc->parent_realize);
  2174. device_class_set_props(dc, pnv_xive2_properties);
  2175. xrc->get_eas = pnv_xive2_get_eas;
  2176. xrc->get_pq = pnv_xive2_get_pq;
  2177. xrc->set_pq = pnv_xive2_set_pq;
  2178. xrc->get_end = pnv_xive2_get_end;
  2179. xrc->write_end = pnv_xive2_write_end;
  2180. xrc->get_nvp = pnv_xive2_get_nvp;
  2181. xrc->write_nvp = pnv_xive2_write_nvp;
  2182. xrc->get_nvgc = pnv_xive2_get_nvgc;
  2183. xrc->write_nvgc = pnv_xive2_write_nvgc;
  2184. xrc->get_config = pnv_xive2_get_config;
  2185. xrc->get_block_id = pnv_xive2_get_block_id;
  2186. xnc->notify = pnv_xive2_notify;
  2187. xpc->match_nvt = pnv_xive2_match_nvt;
  2188. xpc->get_config = pnv_xive2_presenter_get_config;
  2189. xpc->broadcast = pnv_xive2_broadcast;
  2190. };
  2191. static const TypeInfo pnv_xive2_info = {
  2192. .name = TYPE_PNV_XIVE2,
  2193. .parent = TYPE_XIVE2_ROUTER,
  2194. .instance_init = pnv_xive2_instance_init,
  2195. .instance_size = sizeof(PnvXive2),
  2196. .class_init = pnv_xive2_class_init,
  2197. .class_size = sizeof(PnvXive2Class),
  2198. .interfaces = (InterfaceInfo[]) {
  2199. { TYPE_PNV_XSCOM_INTERFACE },
  2200. { }
  2201. }
  2202. };
  2203. static void pnv_xive2_register_types(void)
  2204. {
  2205. type_register_static(&pnv_xive2_info);
  2206. }
  2207. type_init(pnv_xive2_register_types)
  2208. /*
  2209. * If the table is direct, we can compute the number of PQ entries
  2210. * provisioned by FW.
  2211. */
  2212. static uint32_t pnv_xive2_nr_esbs(PnvXive2 *xive)
  2213. {
  2214. uint8_t blk = pnv_xive2_block_id(xive);
  2215. uint64_t vsd = xive->vsds[VST_ESB][blk];
  2216. uint64_t vst_tsize = 1ull << (GETFIELD(VSD_TSIZE, vsd) + 12);
  2217. return VSD_INDIRECT & vsd ? 0 : vst_tsize * SBE_PER_BYTE;
  2218. }
  2219. /*
  2220. * Compute the number of entries per indirect subpage.
  2221. */
  2222. static uint64_t pnv_xive2_vst_per_subpage(PnvXive2 *xive, uint32_t type)
  2223. {
  2224. uint8_t blk = pnv_xive2_block_id(xive);
  2225. uint64_t vsd = xive->vsds[type][blk];
  2226. const XiveVstInfo *info = &vst_infos[type];
  2227. uint64_t vsd_addr;
  2228. uint32_t page_shift;
  2229. /* For direct tables, fake a valid value */
  2230. if (!(VSD_INDIRECT & vsd)) {
  2231. return 1;
  2232. }
  2233. /* Get the page size of the indirect table. */
  2234. vsd_addr = vsd & VSD_ADDRESS_MASK;
  2235. ldq_be_dma(&address_space_memory, vsd_addr, &vsd, MEMTXATTRS_UNSPECIFIED);
  2236. if (!(vsd & VSD_ADDRESS_MASK)) {
  2237. #ifdef XIVE2_DEBUG
  2238. xive2_error(xive, "VST: invalid %s entry!?", info->name);
  2239. #endif
  2240. return 0;
  2241. }
  2242. page_shift = GETFIELD(VSD_TSIZE, vsd) + 12;
  2243. if (!pnv_xive2_vst_page_size_allowed(page_shift)) {
  2244. xive2_error(xive, "VST: invalid %s page shift %d", info->name,
  2245. page_shift);
  2246. return 0;
  2247. }
  2248. return (1ull << page_shift) / info->size;
  2249. }
  2250. void pnv_xive2_pic_print_info(PnvXive2 *xive, GString *buf)
  2251. {
  2252. Xive2Router *xrtr = XIVE2_ROUTER(xive);
  2253. uint8_t blk = pnv_xive2_block_id(xive);
  2254. uint8_t chip_id = xive->chip->chip_id;
  2255. uint32_t srcno0 = XIVE_EAS(blk, 0);
  2256. uint32_t nr_esbs = pnv_xive2_nr_esbs(xive);
  2257. Xive2Eas eas;
  2258. Xive2End end;
  2259. Xive2Nvp nvp;
  2260. Xive2Nvgc nvgc;
  2261. int i;
  2262. uint64_t entries_per_subpage;
  2263. g_string_append_printf(buf, "XIVE[%x] Source %08x .. %08x\n",
  2264. blk, srcno0, srcno0 + nr_esbs - 1);
  2265. xive_source_pic_print_info(&xive->ipi_source, srcno0, buf);
  2266. g_string_append_printf(buf, "XIVE[%x] EAT %08x .. %08x\n",
  2267. blk, srcno0, srcno0 + nr_esbs - 1);
  2268. for (i = 0; i < nr_esbs; i++) {
  2269. if (xive2_router_get_eas(xrtr, blk, i, &eas)) {
  2270. break;
  2271. }
  2272. if (!xive2_eas_is_masked(&eas)) {
  2273. xive2_eas_pic_print_info(&eas, i, buf);
  2274. }
  2275. }
  2276. g_string_append_printf(buf, "XIVE[%x] #%d END Escalation EAT\n",
  2277. chip_id, blk);
  2278. i = 0;
  2279. while (!xive2_router_get_end(xrtr, blk, i, &end)) {
  2280. xive2_end_eas_pic_print_info(&end, i++, buf);
  2281. }
  2282. g_string_append_printf(buf, "XIVE[%x] #%d ENDT\n", chip_id, blk);
  2283. i = 0;
  2284. while (!xive2_router_get_end(xrtr, blk, i, &end)) {
  2285. xive2_end_pic_print_info(&end, i++, buf);
  2286. }
  2287. g_string_append_printf(buf, "XIVE[%x] #%d NVPT %08x .. %08x\n",
  2288. chip_id, blk, 0, XIVE2_NVP_COUNT - 1);
  2289. entries_per_subpage = pnv_xive2_vst_per_subpage(xive, VST_NVP);
  2290. for (i = 0; i < XIVE2_NVP_COUNT; i += entries_per_subpage) {
  2291. while (!xive2_router_get_nvp(xrtr, blk, i, &nvp)) {
  2292. xive2_nvp_pic_print_info(&nvp, i++, buf);
  2293. }
  2294. }
  2295. g_string_append_printf(buf, "XIVE[%x] #%d NVGT %08x .. %08x\n",
  2296. chip_id, blk, 0, XIVE2_NVP_COUNT - 1);
  2297. entries_per_subpage = pnv_xive2_vst_per_subpage(xive, VST_NVG);
  2298. for (i = 0; i < XIVE2_NVP_COUNT; i += entries_per_subpage) {
  2299. while (!xive2_router_get_nvgc(xrtr, false, blk, i, &nvgc)) {
  2300. xive2_nvgc_pic_print_info(&nvgc, i++, buf);
  2301. }
  2302. }
  2303. g_string_append_printf(buf, "XIVE[%x] #%d NVCT %08x .. %08x\n",
  2304. chip_id, blk, 0, XIVE2_NVP_COUNT - 1);
  2305. entries_per_subpage = pnv_xive2_vst_per_subpage(xive, VST_NVC);
  2306. for (i = 0; i < XIVE2_NVP_COUNT; i += entries_per_subpage) {
  2307. while (!xive2_router_get_nvgc(xrtr, true, blk, i, &nvgc)) {
  2308. xive2_nvgc_pic_print_info(&nvgc, i++, buf);
  2309. }
  2310. }
  2311. }