2
0

spapr_xive.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. /*
  2. * QEMU PowerPC sPAPR XIVE interrupt controller model
  3. *
  4. * Copyright (c) 2017-2018, IBM Corporation.
  5. *
  6. * This code is licensed under the GPL version 2 or later. See the
  7. * COPYING file in the top-level directory.
  8. */
  9. #include "qemu/osdep.h"
  10. #include "qemu/log.h"
  11. #include "qemu/module.h"
  12. #include "qapi/error.h"
  13. #include "qemu/error-report.h"
  14. #include "target/ppc/cpu.h"
  15. #include "sysemu/cpus.h"
  16. #include "sysemu/reset.h"
  17. #include "migration/vmstate.h"
  18. #include "monitor/monitor.h"
  19. #include "hw/ppc/fdt.h"
  20. #include "hw/ppc/spapr.h"
  21. #include "hw/ppc/spapr_cpu_core.h"
  22. #include "hw/ppc/spapr_xive.h"
  23. #include "hw/ppc/xive.h"
  24. #include "hw/ppc/xive_regs.h"
  25. #include "hw/qdev-properties.h"
  26. /*
  27. * XIVE Virtualization Controller BAR and Thread Managment BAR that we
  28. * use for the ESB pages and the TIMA pages
  29. */
  30. #define SPAPR_XIVE_VC_BASE 0x0006010000000000ull
  31. #define SPAPR_XIVE_TM_BASE 0x0006030203180000ull
  32. /*
  33. * The allocation of VP blocks is a complex operation in OPAL and the
  34. * VP identifiers have a relation with the number of HW chips, the
  35. * size of the VP blocks, VP grouping, etc. The QEMU sPAPR XIVE
  36. * controller model does not have the same constraints and can use a
  37. * simple mapping scheme of the CPU vcpu_id
  38. *
  39. * These identifiers are never returned to the OS.
  40. */
  41. #define SPAPR_XIVE_NVT_BASE 0x400
  42. /*
  43. * sPAPR NVT and END indexing helpers
  44. */
  45. static uint32_t spapr_xive_nvt_to_target(uint8_t nvt_blk, uint32_t nvt_idx)
  46. {
  47. return nvt_idx - SPAPR_XIVE_NVT_BASE;
  48. }
  49. static void spapr_xive_cpu_to_nvt(PowerPCCPU *cpu,
  50. uint8_t *out_nvt_blk, uint32_t *out_nvt_idx)
  51. {
  52. assert(cpu);
  53. if (out_nvt_blk) {
  54. *out_nvt_blk = SPAPR_XIVE_BLOCK_ID;
  55. }
  56. if (out_nvt_blk) {
  57. *out_nvt_idx = SPAPR_XIVE_NVT_BASE + cpu->vcpu_id;
  58. }
  59. }
  60. static int spapr_xive_target_to_nvt(uint32_t target,
  61. uint8_t *out_nvt_blk, uint32_t *out_nvt_idx)
  62. {
  63. PowerPCCPU *cpu = spapr_find_cpu(target);
  64. if (!cpu) {
  65. return -1;
  66. }
  67. spapr_xive_cpu_to_nvt(cpu, out_nvt_blk, out_nvt_idx);
  68. return 0;
  69. }
  70. /*
  71. * sPAPR END indexing uses a simple mapping of the CPU vcpu_id, 8
  72. * priorities per CPU
  73. */
  74. int spapr_xive_end_to_target(uint8_t end_blk, uint32_t end_idx,
  75. uint32_t *out_server, uint8_t *out_prio)
  76. {
  77. assert(end_blk == SPAPR_XIVE_BLOCK_ID);
  78. if (out_server) {
  79. *out_server = end_idx >> 3;
  80. }
  81. if (out_prio) {
  82. *out_prio = end_idx & 0x7;
  83. }
  84. return 0;
  85. }
  86. static void spapr_xive_cpu_to_end(PowerPCCPU *cpu, uint8_t prio,
  87. uint8_t *out_end_blk, uint32_t *out_end_idx)
  88. {
  89. assert(cpu);
  90. if (out_end_blk) {
  91. *out_end_blk = SPAPR_XIVE_BLOCK_ID;
  92. }
  93. if (out_end_idx) {
  94. *out_end_idx = (cpu->vcpu_id << 3) + prio;
  95. }
  96. }
  97. static int spapr_xive_target_to_end(uint32_t target, uint8_t prio,
  98. uint8_t *out_end_blk, uint32_t *out_end_idx)
  99. {
  100. PowerPCCPU *cpu = spapr_find_cpu(target);
  101. if (!cpu) {
  102. return -1;
  103. }
  104. spapr_xive_cpu_to_end(cpu, prio, out_end_blk, out_end_idx);
  105. return 0;
  106. }
  107. /*
  108. * On sPAPR machines, use a simplified output for the XIVE END
  109. * structure dumping only the information related to the OS EQ.
  110. */
  111. static void spapr_xive_end_pic_print_info(SpaprXive *xive, XiveEND *end,
  112. Monitor *mon)
  113. {
  114. uint64_t qaddr_base = xive_end_qaddr(end);
  115. uint32_t qindex = xive_get_field32(END_W1_PAGE_OFF, end->w1);
  116. uint32_t qgen = xive_get_field32(END_W1_GENERATION, end->w1);
  117. uint32_t qsize = xive_get_field32(END_W0_QSIZE, end->w0);
  118. uint32_t qentries = 1 << (qsize + 10);
  119. uint32_t nvt = xive_get_field32(END_W6_NVT_INDEX, end->w6);
  120. uint8_t priority = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
  121. monitor_printf(mon, "%3d/%d % 6d/%5d @%"PRIx64" ^%d",
  122. spapr_xive_nvt_to_target(0, nvt),
  123. priority, qindex, qentries, qaddr_base, qgen);
  124. xive_end_queue_pic_print_info(end, 6, mon);
  125. }
  126. void spapr_xive_pic_print_info(SpaprXive *xive, Monitor *mon)
  127. {
  128. XiveSource *xsrc = &xive->source;
  129. int i;
  130. if (kvm_irqchip_in_kernel()) {
  131. Error *local_err = NULL;
  132. kvmppc_xive_synchronize_state(xive, &local_err);
  133. if (local_err) {
  134. error_report_err(local_err);
  135. return;
  136. }
  137. }
  138. monitor_printf(mon, " LISN PQ EISN CPU/PRIO EQ\n");
  139. for (i = 0; i < xive->nr_irqs; i++) {
  140. uint8_t pq = xive_source_esb_get(xsrc, i);
  141. XiveEAS *eas = &xive->eat[i];
  142. if (!xive_eas_is_valid(eas)) {
  143. continue;
  144. }
  145. monitor_printf(mon, " %08x %s %c%c%c %s %08x ", i,
  146. xive_source_irq_is_lsi(xsrc, i) ? "LSI" : "MSI",
  147. pq & XIVE_ESB_VAL_P ? 'P' : '-',
  148. pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
  149. xsrc->status[i] & XIVE_STATUS_ASSERTED ? 'A' : ' ',
  150. xive_eas_is_masked(eas) ? "M" : " ",
  151. (int) xive_get_field64(EAS_END_DATA, eas->w));
  152. if (!xive_eas_is_masked(eas)) {
  153. uint32_t end_idx = xive_get_field64(EAS_END_INDEX, eas->w);
  154. XiveEND *end;
  155. assert(end_idx < xive->nr_ends);
  156. end = &xive->endt[end_idx];
  157. if (xive_end_is_valid(end)) {
  158. spapr_xive_end_pic_print_info(xive, end, mon);
  159. }
  160. }
  161. monitor_printf(mon, "\n");
  162. }
  163. }
  164. void spapr_xive_mmio_set_enabled(SpaprXive *xive, bool enable)
  165. {
  166. memory_region_set_enabled(&xive->source.esb_mmio, enable);
  167. memory_region_set_enabled(&xive->tm_mmio, enable);
  168. /* Disable the END ESBs until a guest OS makes use of them */
  169. memory_region_set_enabled(&xive->end_source.esb_mmio, false);
  170. }
  171. static void spapr_xive_tm_write(void *opaque, hwaddr offset,
  172. uint64_t value, unsigned size)
  173. {
  174. XiveTCTX *tctx = spapr_cpu_state(POWERPC_CPU(current_cpu))->tctx;
  175. xive_tctx_tm_write(XIVE_PRESENTER(opaque), tctx, offset, value, size);
  176. }
  177. static uint64_t spapr_xive_tm_read(void *opaque, hwaddr offset, unsigned size)
  178. {
  179. XiveTCTX *tctx = spapr_cpu_state(POWERPC_CPU(current_cpu))->tctx;
  180. return xive_tctx_tm_read(XIVE_PRESENTER(opaque), tctx, offset, size);
  181. }
  182. const MemoryRegionOps spapr_xive_tm_ops = {
  183. .read = spapr_xive_tm_read,
  184. .write = spapr_xive_tm_write,
  185. .endianness = DEVICE_BIG_ENDIAN,
  186. .valid = {
  187. .min_access_size = 1,
  188. .max_access_size = 8,
  189. },
  190. .impl = {
  191. .min_access_size = 1,
  192. .max_access_size = 8,
  193. },
  194. };
  195. static void spapr_xive_end_reset(XiveEND *end)
  196. {
  197. memset(end, 0, sizeof(*end));
  198. /* switch off the escalation and notification ESBs */
  199. end->w1 = cpu_to_be32(END_W1_ESe_Q | END_W1_ESn_Q);
  200. }
  201. static void spapr_xive_reset(void *dev)
  202. {
  203. SpaprXive *xive = SPAPR_XIVE(dev);
  204. int i;
  205. /*
  206. * The XiveSource has its own reset handler, which mask off all
  207. * IRQs (!P|Q)
  208. */
  209. /* Mask all valid EASs in the IRQ number space. */
  210. for (i = 0; i < xive->nr_irqs; i++) {
  211. XiveEAS *eas = &xive->eat[i];
  212. if (xive_eas_is_valid(eas)) {
  213. eas->w = cpu_to_be64(EAS_VALID | EAS_MASKED);
  214. } else {
  215. eas->w = 0;
  216. }
  217. }
  218. /* Clear all ENDs */
  219. for (i = 0; i < xive->nr_ends; i++) {
  220. spapr_xive_end_reset(&xive->endt[i]);
  221. }
  222. }
  223. static void spapr_xive_instance_init(Object *obj)
  224. {
  225. SpaprXive *xive = SPAPR_XIVE(obj);
  226. object_initialize_child(obj, "source", &xive->source, TYPE_XIVE_SOURCE);
  227. object_initialize_child(obj, "end_source", &xive->end_source,
  228. TYPE_XIVE_END_SOURCE);
  229. /* Not connected to the KVM XIVE device */
  230. xive->fd = -1;
  231. }
  232. static void spapr_xive_realize(DeviceState *dev, Error **errp)
  233. {
  234. SpaprXive *xive = SPAPR_XIVE(dev);
  235. SpaprXiveClass *sxc = SPAPR_XIVE_GET_CLASS(xive);
  236. XiveSource *xsrc = &xive->source;
  237. XiveENDSource *end_xsrc = &xive->end_source;
  238. Error *local_err = NULL;
  239. sxc->parent_realize(dev, &local_err);
  240. if (local_err) {
  241. error_propagate(errp, local_err);
  242. return;
  243. }
  244. if (!xive->nr_irqs) {
  245. error_setg(errp, "Number of interrupt needs to be greater 0");
  246. return;
  247. }
  248. if (!xive->nr_ends) {
  249. error_setg(errp, "Number of interrupt needs to be greater 0");
  250. return;
  251. }
  252. /*
  253. * Initialize the internal sources, for IPIs and virtual devices.
  254. */
  255. object_property_set_int(OBJECT(xsrc), "nr-irqs", xive->nr_irqs,
  256. &error_fatal);
  257. object_property_set_link(OBJECT(xsrc), "xive", OBJECT(xive), &error_abort);
  258. if (!qdev_realize(DEVICE(xsrc), NULL, errp)) {
  259. return;
  260. }
  261. sysbus_init_mmio(SYS_BUS_DEVICE(xive), &xsrc->esb_mmio);
  262. /*
  263. * Initialize the END ESB source
  264. */
  265. object_property_set_int(OBJECT(end_xsrc), "nr-ends", xive->nr_irqs,
  266. &error_fatal);
  267. object_property_set_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
  268. &error_abort);
  269. if (!qdev_realize(DEVICE(end_xsrc), NULL, errp)) {
  270. return;
  271. }
  272. sysbus_init_mmio(SYS_BUS_DEVICE(xive), &end_xsrc->esb_mmio);
  273. /* Set the mapping address of the END ESB pages after the source ESBs */
  274. xive->end_base = xive->vc_base + (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
  275. /*
  276. * Allocate the routing tables
  277. */
  278. xive->eat = g_new0(XiveEAS, xive->nr_irqs);
  279. xive->endt = g_new0(XiveEND, xive->nr_ends);
  280. xive->nodename = g_strdup_printf("interrupt-controller@%" PRIx64,
  281. xive->tm_base + XIVE_TM_USER_PAGE * (1 << TM_SHIFT));
  282. qemu_register_reset(spapr_xive_reset, dev);
  283. /* TIMA initialization */
  284. memory_region_init_io(&xive->tm_mmio, OBJECT(xive), &spapr_xive_tm_ops,
  285. xive, "xive.tima", 4ull << TM_SHIFT);
  286. sysbus_init_mmio(SYS_BUS_DEVICE(xive), &xive->tm_mmio);
  287. /*
  288. * Map all regions. These will be enabled or disabled at reset and
  289. * can also be overridden by KVM memory regions if active
  290. */
  291. sysbus_mmio_map(SYS_BUS_DEVICE(xive), 0, xive->vc_base);
  292. sysbus_mmio_map(SYS_BUS_DEVICE(xive), 1, xive->end_base);
  293. sysbus_mmio_map(SYS_BUS_DEVICE(xive), 2, xive->tm_base);
  294. }
  295. static int spapr_xive_get_eas(XiveRouter *xrtr, uint8_t eas_blk,
  296. uint32_t eas_idx, XiveEAS *eas)
  297. {
  298. SpaprXive *xive = SPAPR_XIVE(xrtr);
  299. if (eas_idx >= xive->nr_irqs) {
  300. return -1;
  301. }
  302. *eas = xive->eat[eas_idx];
  303. return 0;
  304. }
  305. static int spapr_xive_get_end(XiveRouter *xrtr,
  306. uint8_t end_blk, uint32_t end_idx, XiveEND *end)
  307. {
  308. SpaprXive *xive = SPAPR_XIVE(xrtr);
  309. if (end_idx >= xive->nr_ends) {
  310. return -1;
  311. }
  312. memcpy(end, &xive->endt[end_idx], sizeof(XiveEND));
  313. return 0;
  314. }
  315. static int spapr_xive_write_end(XiveRouter *xrtr, uint8_t end_blk,
  316. uint32_t end_idx, XiveEND *end,
  317. uint8_t word_number)
  318. {
  319. SpaprXive *xive = SPAPR_XIVE(xrtr);
  320. if (end_idx >= xive->nr_ends) {
  321. return -1;
  322. }
  323. memcpy(&xive->endt[end_idx], end, sizeof(XiveEND));
  324. return 0;
  325. }
  326. static int spapr_xive_get_nvt(XiveRouter *xrtr,
  327. uint8_t nvt_blk, uint32_t nvt_idx, XiveNVT *nvt)
  328. {
  329. uint32_t vcpu_id = spapr_xive_nvt_to_target(nvt_blk, nvt_idx);
  330. PowerPCCPU *cpu = spapr_find_cpu(vcpu_id);
  331. if (!cpu) {
  332. /* TODO: should we assert() if we can find a NVT ? */
  333. return -1;
  334. }
  335. /*
  336. * sPAPR does not maintain a NVT table. Return that the NVT is
  337. * valid if we have found a matching CPU
  338. */
  339. nvt->w0 = cpu_to_be32(NVT_W0_VALID);
  340. return 0;
  341. }
  342. static int spapr_xive_write_nvt(XiveRouter *xrtr, uint8_t nvt_blk,
  343. uint32_t nvt_idx, XiveNVT *nvt,
  344. uint8_t word_number)
  345. {
  346. /*
  347. * We don't need to write back to the NVTs because the sPAPR
  348. * machine should never hit a non-scheduled NVT. It should never
  349. * get called.
  350. */
  351. g_assert_not_reached();
  352. }
  353. static int spapr_xive_match_nvt(XivePresenter *xptr, uint8_t format,
  354. uint8_t nvt_blk, uint32_t nvt_idx,
  355. bool cam_ignore, uint8_t priority,
  356. uint32_t logic_serv, XiveTCTXMatch *match)
  357. {
  358. CPUState *cs;
  359. int count = 0;
  360. CPU_FOREACH(cs) {
  361. PowerPCCPU *cpu = POWERPC_CPU(cs);
  362. XiveTCTX *tctx = spapr_cpu_state(cpu)->tctx;
  363. int ring;
  364. /*
  365. * Skip partially initialized vCPUs. This can happen when
  366. * vCPUs are hotplugged.
  367. */
  368. if (!tctx) {
  369. continue;
  370. }
  371. /*
  372. * Check the thread context CAM lines and record matches.
  373. */
  374. ring = xive_presenter_tctx_match(xptr, tctx, format, nvt_blk, nvt_idx,
  375. cam_ignore, logic_serv);
  376. /*
  377. * Save the matching thread interrupt context and follow on to
  378. * check for duplicates which are invalid.
  379. */
  380. if (ring != -1) {
  381. if (match->tctx) {
  382. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: already found a thread "
  383. "context NVT %x/%x\n", nvt_blk, nvt_idx);
  384. return -1;
  385. }
  386. match->ring = ring;
  387. match->tctx = tctx;
  388. count++;
  389. }
  390. }
  391. return count;
  392. }
  393. static uint8_t spapr_xive_get_block_id(XiveRouter *xrtr)
  394. {
  395. return SPAPR_XIVE_BLOCK_ID;
  396. }
  397. static const VMStateDescription vmstate_spapr_xive_end = {
  398. .name = TYPE_SPAPR_XIVE "/end",
  399. .version_id = 1,
  400. .minimum_version_id = 1,
  401. .fields = (VMStateField []) {
  402. VMSTATE_UINT32(w0, XiveEND),
  403. VMSTATE_UINT32(w1, XiveEND),
  404. VMSTATE_UINT32(w2, XiveEND),
  405. VMSTATE_UINT32(w3, XiveEND),
  406. VMSTATE_UINT32(w4, XiveEND),
  407. VMSTATE_UINT32(w5, XiveEND),
  408. VMSTATE_UINT32(w6, XiveEND),
  409. VMSTATE_UINT32(w7, XiveEND),
  410. VMSTATE_END_OF_LIST()
  411. },
  412. };
  413. static const VMStateDescription vmstate_spapr_xive_eas = {
  414. .name = TYPE_SPAPR_XIVE "/eas",
  415. .version_id = 1,
  416. .minimum_version_id = 1,
  417. .fields = (VMStateField []) {
  418. VMSTATE_UINT64(w, XiveEAS),
  419. VMSTATE_END_OF_LIST()
  420. },
  421. };
  422. static int vmstate_spapr_xive_pre_save(void *opaque)
  423. {
  424. if (kvm_irqchip_in_kernel()) {
  425. return kvmppc_xive_pre_save(SPAPR_XIVE(opaque));
  426. }
  427. return 0;
  428. }
  429. /*
  430. * Called by the sPAPR IRQ backend 'post_load' method at the machine
  431. * level.
  432. */
  433. static int spapr_xive_post_load(SpaprInterruptController *intc, int version_id)
  434. {
  435. if (kvm_irqchip_in_kernel()) {
  436. return kvmppc_xive_post_load(SPAPR_XIVE(intc), version_id);
  437. }
  438. return 0;
  439. }
  440. static const VMStateDescription vmstate_spapr_xive = {
  441. .name = TYPE_SPAPR_XIVE,
  442. .version_id = 1,
  443. .minimum_version_id = 1,
  444. .pre_save = vmstate_spapr_xive_pre_save,
  445. .post_load = NULL, /* handled at the machine level */
  446. .fields = (VMStateField[]) {
  447. VMSTATE_UINT32_EQUAL(nr_irqs, SpaprXive, NULL),
  448. VMSTATE_STRUCT_VARRAY_POINTER_UINT32(eat, SpaprXive, nr_irqs,
  449. vmstate_spapr_xive_eas, XiveEAS),
  450. VMSTATE_STRUCT_VARRAY_POINTER_UINT32(endt, SpaprXive, nr_ends,
  451. vmstate_spapr_xive_end, XiveEND),
  452. VMSTATE_END_OF_LIST()
  453. },
  454. };
  455. static int spapr_xive_claim_irq(SpaprInterruptController *intc, int lisn,
  456. bool lsi, Error **errp)
  457. {
  458. SpaprXive *xive = SPAPR_XIVE(intc);
  459. XiveSource *xsrc = &xive->source;
  460. assert(lisn < xive->nr_irqs);
  461. if (xive_eas_is_valid(&xive->eat[lisn])) {
  462. error_setg(errp, "IRQ %d is not free", lisn);
  463. return -EBUSY;
  464. }
  465. /*
  466. * Set default values when allocating an IRQ number
  467. */
  468. xive->eat[lisn].w |= cpu_to_be64(EAS_VALID | EAS_MASKED);
  469. if (lsi) {
  470. xive_source_irq_set_lsi(xsrc, lisn);
  471. }
  472. if (kvm_irqchip_in_kernel()) {
  473. return kvmppc_xive_source_reset_one(xsrc, lisn, errp);
  474. }
  475. return 0;
  476. }
  477. static void spapr_xive_free_irq(SpaprInterruptController *intc, int lisn)
  478. {
  479. SpaprXive *xive = SPAPR_XIVE(intc);
  480. assert(lisn < xive->nr_irqs);
  481. xive->eat[lisn].w &= cpu_to_be64(~EAS_VALID);
  482. }
  483. static Property spapr_xive_properties[] = {
  484. DEFINE_PROP_UINT32("nr-irqs", SpaprXive, nr_irqs, 0),
  485. DEFINE_PROP_UINT32("nr-ends", SpaprXive, nr_ends, 0),
  486. DEFINE_PROP_UINT64("vc-base", SpaprXive, vc_base, SPAPR_XIVE_VC_BASE),
  487. DEFINE_PROP_UINT64("tm-base", SpaprXive, tm_base, SPAPR_XIVE_TM_BASE),
  488. DEFINE_PROP_END_OF_LIST(),
  489. };
  490. static int spapr_xive_cpu_intc_create(SpaprInterruptController *intc,
  491. PowerPCCPU *cpu, Error **errp)
  492. {
  493. SpaprXive *xive = SPAPR_XIVE(intc);
  494. Object *obj;
  495. SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
  496. obj = xive_tctx_create(OBJECT(cpu), XIVE_PRESENTER(xive), errp);
  497. if (!obj) {
  498. return -1;
  499. }
  500. spapr_cpu->tctx = XIVE_TCTX(obj);
  501. return 0;
  502. }
  503. static void xive_tctx_set_os_cam(XiveTCTX *tctx, uint32_t os_cam)
  504. {
  505. uint32_t qw1w2 = cpu_to_be32(TM_QW1W2_VO | os_cam);
  506. memcpy(&tctx->regs[TM_QW1_OS + TM_WORD2], &qw1w2, 4);
  507. }
  508. static void spapr_xive_cpu_intc_reset(SpaprInterruptController *intc,
  509. PowerPCCPU *cpu)
  510. {
  511. XiveTCTX *tctx = spapr_cpu_state(cpu)->tctx;
  512. uint8_t nvt_blk;
  513. uint32_t nvt_idx;
  514. xive_tctx_reset(tctx);
  515. /*
  516. * When a Virtual Processor is scheduled to run on a HW thread,
  517. * the hypervisor pushes its identifier in the OS CAM line.
  518. * Emulate the same behavior under QEMU.
  519. */
  520. spapr_xive_cpu_to_nvt(cpu, &nvt_blk, &nvt_idx);
  521. xive_tctx_set_os_cam(tctx, xive_nvt_cam_line(nvt_blk, nvt_idx));
  522. }
  523. static void spapr_xive_cpu_intc_destroy(SpaprInterruptController *intc,
  524. PowerPCCPU *cpu)
  525. {
  526. SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
  527. xive_tctx_destroy(spapr_cpu->tctx);
  528. spapr_cpu->tctx = NULL;
  529. }
  530. static void spapr_xive_set_irq(SpaprInterruptController *intc, int irq, int val)
  531. {
  532. SpaprXive *xive = SPAPR_XIVE(intc);
  533. if (kvm_irqchip_in_kernel()) {
  534. kvmppc_xive_source_set_irq(&xive->source, irq, val);
  535. } else {
  536. xive_source_set_irq(&xive->source, irq, val);
  537. }
  538. }
  539. static void spapr_xive_print_info(SpaprInterruptController *intc, Monitor *mon)
  540. {
  541. SpaprXive *xive = SPAPR_XIVE(intc);
  542. CPUState *cs;
  543. CPU_FOREACH(cs) {
  544. PowerPCCPU *cpu = POWERPC_CPU(cs);
  545. xive_tctx_pic_print_info(spapr_cpu_state(cpu)->tctx, mon);
  546. }
  547. spapr_xive_pic_print_info(xive, mon);
  548. }
  549. static void spapr_xive_dt(SpaprInterruptController *intc, uint32_t nr_servers,
  550. void *fdt, uint32_t phandle)
  551. {
  552. SpaprXive *xive = SPAPR_XIVE(intc);
  553. int node;
  554. uint64_t timas[2 * 2];
  555. /* Interrupt number ranges for the IPIs */
  556. uint32_t lisn_ranges[] = {
  557. cpu_to_be32(SPAPR_IRQ_IPI),
  558. cpu_to_be32(SPAPR_IRQ_IPI + nr_servers),
  559. };
  560. /*
  561. * EQ size - the sizes of pages supported by the system 4K, 64K,
  562. * 2M, 16M. We only advertise 64K for the moment.
  563. */
  564. uint32_t eq_sizes[] = {
  565. cpu_to_be32(16), /* 64K */
  566. };
  567. /*
  568. * The following array is in sync with the reserved priorities
  569. * defined by the 'spapr_xive_priority_is_reserved' routine.
  570. */
  571. uint32_t plat_res_int_priorities[] = {
  572. cpu_to_be32(7), /* start */
  573. cpu_to_be32(0xf8), /* count */
  574. };
  575. /* Thread Interrupt Management Area : User (ring 3) and OS (ring 2) */
  576. timas[0] = cpu_to_be64(xive->tm_base +
  577. XIVE_TM_USER_PAGE * (1ull << TM_SHIFT));
  578. timas[1] = cpu_to_be64(1ull << TM_SHIFT);
  579. timas[2] = cpu_to_be64(xive->tm_base +
  580. XIVE_TM_OS_PAGE * (1ull << TM_SHIFT));
  581. timas[3] = cpu_to_be64(1ull << TM_SHIFT);
  582. _FDT(node = fdt_add_subnode(fdt, 0, xive->nodename));
  583. _FDT(fdt_setprop_string(fdt, node, "device_type", "power-ivpe"));
  584. _FDT(fdt_setprop(fdt, node, "reg", timas, sizeof(timas)));
  585. _FDT(fdt_setprop_string(fdt, node, "compatible", "ibm,power-ivpe"));
  586. _FDT(fdt_setprop(fdt, node, "ibm,xive-eq-sizes", eq_sizes,
  587. sizeof(eq_sizes)));
  588. _FDT(fdt_setprop(fdt, node, "ibm,xive-lisn-ranges", lisn_ranges,
  589. sizeof(lisn_ranges)));
  590. /* For Linux to link the LSIs to the interrupt controller. */
  591. _FDT(fdt_setprop(fdt, node, "interrupt-controller", NULL, 0));
  592. _FDT(fdt_setprop_cell(fdt, node, "#interrupt-cells", 2));
  593. /* For SLOF */
  594. _FDT(fdt_setprop_cell(fdt, node, "linux,phandle", phandle));
  595. _FDT(fdt_setprop_cell(fdt, node, "phandle", phandle));
  596. /*
  597. * The "ibm,plat-res-int-priorities" property defines the priority
  598. * ranges reserved by the hypervisor
  599. */
  600. _FDT(fdt_setprop(fdt, 0, "ibm,plat-res-int-priorities",
  601. plat_res_int_priorities, sizeof(plat_res_int_priorities)));
  602. }
  603. static int spapr_xive_activate(SpaprInterruptController *intc,
  604. uint32_t nr_servers, Error **errp)
  605. {
  606. SpaprXive *xive = SPAPR_XIVE(intc);
  607. if (kvm_enabled()) {
  608. int rc = spapr_irq_init_kvm(kvmppc_xive_connect, intc, nr_servers,
  609. errp);
  610. if (rc < 0) {
  611. return rc;
  612. }
  613. }
  614. /* Activate the XIVE MMIOs */
  615. spapr_xive_mmio_set_enabled(xive, true);
  616. return 0;
  617. }
  618. static void spapr_xive_deactivate(SpaprInterruptController *intc)
  619. {
  620. SpaprXive *xive = SPAPR_XIVE(intc);
  621. spapr_xive_mmio_set_enabled(xive, false);
  622. if (kvm_irqchip_in_kernel()) {
  623. kvmppc_xive_disconnect(intc);
  624. }
  625. }
  626. static void spapr_xive_class_init(ObjectClass *klass, void *data)
  627. {
  628. DeviceClass *dc = DEVICE_CLASS(klass);
  629. XiveRouterClass *xrc = XIVE_ROUTER_CLASS(klass);
  630. SpaprInterruptControllerClass *sicc = SPAPR_INTC_CLASS(klass);
  631. XivePresenterClass *xpc = XIVE_PRESENTER_CLASS(klass);
  632. SpaprXiveClass *sxc = SPAPR_XIVE_CLASS(klass);
  633. dc->desc = "sPAPR XIVE Interrupt Controller";
  634. device_class_set_props(dc, spapr_xive_properties);
  635. device_class_set_parent_realize(dc, spapr_xive_realize,
  636. &sxc->parent_realize);
  637. dc->vmsd = &vmstate_spapr_xive;
  638. xrc->get_eas = spapr_xive_get_eas;
  639. xrc->get_end = spapr_xive_get_end;
  640. xrc->write_end = spapr_xive_write_end;
  641. xrc->get_nvt = spapr_xive_get_nvt;
  642. xrc->write_nvt = spapr_xive_write_nvt;
  643. xrc->get_block_id = spapr_xive_get_block_id;
  644. sicc->activate = spapr_xive_activate;
  645. sicc->deactivate = spapr_xive_deactivate;
  646. sicc->cpu_intc_create = spapr_xive_cpu_intc_create;
  647. sicc->cpu_intc_reset = spapr_xive_cpu_intc_reset;
  648. sicc->cpu_intc_destroy = spapr_xive_cpu_intc_destroy;
  649. sicc->claim_irq = spapr_xive_claim_irq;
  650. sicc->free_irq = spapr_xive_free_irq;
  651. sicc->set_irq = spapr_xive_set_irq;
  652. sicc->print_info = spapr_xive_print_info;
  653. sicc->dt = spapr_xive_dt;
  654. sicc->post_load = spapr_xive_post_load;
  655. xpc->match_nvt = spapr_xive_match_nvt;
  656. }
  657. static const TypeInfo spapr_xive_info = {
  658. .name = TYPE_SPAPR_XIVE,
  659. .parent = TYPE_XIVE_ROUTER,
  660. .instance_init = spapr_xive_instance_init,
  661. .instance_size = sizeof(SpaprXive),
  662. .class_init = spapr_xive_class_init,
  663. .class_size = sizeof(SpaprXiveClass),
  664. .interfaces = (InterfaceInfo[]) {
  665. { TYPE_SPAPR_INTC },
  666. { }
  667. },
  668. };
  669. static void spapr_xive_register_types(void)
  670. {
  671. type_register_static(&spapr_xive_info);
  672. }
  673. type_init(spapr_xive_register_types)
  674. /*
  675. * XIVE hcalls
  676. *
  677. * The terminology used by the XIVE hcalls is the following :
  678. *
  679. * TARGET vCPU number
  680. * EQ Event Queue assigned by OS to receive event data
  681. * ESB page for source interrupt management
  682. * LISN Logical Interrupt Source Number identifying a source in the
  683. * machine
  684. * EISN Effective Interrupt Source Number used by guest OS to
  685. * identify source in the guest
  686. *
  687. * The EAS, END, NVT structures are not exposed.
  688. */
  689. /*
  690. * Linux hosts under OPAL reserve priority 7 for their own escalation
  691. * interrupts (DD2.X POWER9). So we only allow the guest to use
  692. * priorities [0..6].
  693. */
  694. static bool spapr_xive_priority_is_reserved(uint8_t priority)
  695. {
  696. switch (priority) {
  697. case 0 ... 6:
  698. return false;
  699. case 7: /* OPAL escalation queue */
  700. default:
  701. return true;
  702. }
  703. }
  704. /*
  705. * The H_INT_GET_SOURCE_INFO hcall() is used to obtain the logical
  706. * real address of the MMIO page through which the Event State Buffer
  707. * entry associated with the value of the "lisn" parameter is managed.
  708. *
  709. * Parameters:
  710. * Input
  711. * - R4: "flags"
  712. * Bits 0-63 reserved
  713. * - R5: "lisn" is per "interrupts", "interrupt-map", or
  714. * "ibm,xive-lisn-ranges" properties, or as returned by the
  715. * ibm,query-interrupt-source-number RTAS call, or as returned
  716. * by the H_ALLOCATE_VAS_WINDOW hcall
  717. *
  718. * Output
  719. * - R4: "flags"
  720. * Bits 0-59: Reserved
  721. * Bit 60: H_INT_ESB must be used for Event State Buffer
  722. * management
  723. * Bit 61: 1 == LSI 0 == MSI
  724. * Bit 62: the full function page supports trigger
  725. * Bit 63: Store EOI Supported
  726. * - R5: Logical Real address of full function Event State Buffer
  727. * management page, -1 if H_INT_ESB hcall flag is set to 1.
  728. * - R6: Logical Real Address of trigger only Event State Buffer
  729. * management page or -1.
  730. * - R7: Power of 2 page size for the ESB management pages returned in
  731. * R5 and R6.
  732. */
  733. #define SPAPR_XIVE_SRC_H_INT_ESB PPC_BIT(60) /* ESB manage with H_INT_ESB */
  734. #define SPAPR_XIVE_SRC_LSI PPC_BIT(61) /* Virtual LSI type */
  735. #define SPAPR_XIVE_SRC_TRIGGER PPC_BIT(62) /* Trigger and management
  736. on same page */
  737. #define SPAPR_XIVE_SRC_STORE_EOI PPC_BIT(63) /* Store EOI support */
  738. static target_ulong h_int_get_source_info(PowerPCCPU *cpu,
  739. SpaprMachineState *spapr,
  740. target_ulong opcode,
  741. target_ulong *args)
  742. {
  743. SpaprXive *xive = spapr->xive;
  744. XiveSource *xsrc = &xive->source;
  745. target_ulong flags = args[0];
  746. target_ulong lisn = args[1];
  747. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  748. return H_FUNCTION;
  749. }
  750. if (flags) {
  751. return H_PARAMETER;
  752. }
  753. if (lisn >= xive->nr_irqs) {
  754. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
  755. lisn);
  756. return H_P2;
  757. }
  758. if (!xive_eas_is_valid(&xive->eat[lisn])) {
  759. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
  760. lisn);
  761. return H_P2;
  762. }
  763. /*
  764. * All sources are emulated under the main XIVE object and share
  765. * the same characteristics.
  766. */
  767. args[0] = 0;
  768. if (!xive_source_esb_has_2page(xsrc)) {
  769. args[0] |= SPAPR_XIVE_SRC_TRIGGER;
  770. }
  771. if (xsrc->esb_flags & XIVE_SRC_STORE_EOI) {
  772. args[0] |= SPAPR_XIVE_SRC_STORE_EOI;
  773. }
  774. /*
  775. * Force the use of the H_INT_ESB hcall in case of an LSI
  776. * interrupt. This is necessary under KVM to re-trigger the
  777. * interrupt if the level is still asserted
  778. */
  779. if (xive_source_irq_is_lsi(xsrc, lisn)) {
  780. args[0] |= SPAPR_XIVE_SRC_H_INT_ESB | SPAPR_XIVE_SRC_LSI;
  781. }
  782. if (!(args[0] & SPAPR_XIVE_SRC_H_INT_ESB)) {
  783. args[1] = xive->vc_base + xive_source_esb_mgmt(xsrc, lisn);
  784. } else {
  785. args[1] = -1;
  786. }
  787. if (xive_source_esb_has_2page(xsrc) &&
  788. !(args[0] & SPAPR_XIVE_SRC_H_INT_ESB)) {
  789. args[2] = xive->vc_base + xive_source_esb_page(xsrc, lisn);
  790. } else {
  791. args[2] = -1;
  792. }
  793. if (xive_source_esb_has_2page(xsrc)) {
  794. args[3] = xsrc->esb_shift - 1;
  795. } else {
  796. args[3] = xsrc->esb_shift;
  797. }
  798. return H_SUCCESS;
  799. }
  800. /*
  801. * The H_INT_SET_SOURCE_CONFIG hcall() is used to assign a Logical
  802. * Interrupt Source to a target. The Logical Interrupt Source is
  803. * designated with the "lisn" parameter and the target is designated
  804. * with the "target" and "priority" parameters. Upon return from the
  805. * hcall(), no additional interrupts will be directed to the old EQ.
  806. *
  807. * Parameters:
  808. * Input:
  809. * - R4: "flags"
  810. * Bits 0-61: Reserved
  811. * Bit 62: set the "eisn" in the EAS
  812. * Bit 63: masks the interrupt source in the hardware interrupt
  813. * control structure. An interrupt masked by this mechanism will
  814. * be dropped, but it's source state bits will still be
  815. * set. There is no race-free way of unmasking and restoring the
  816. * source. Thus this should only be used in interrupts that are
  817. * also masked at the source, and only in cases where the
  818. * interrupt is not meant to be used for a large amount of time
  819. * because no valid target exists for it for example
  820. * - R5: "lisn" is per "interrupts", "interrupt-map", or
  821. * "ibm,xive-lisn-ranges" properties, or as returned by the
  822. * ibm,query-interrupt-source-number RTAS call, or as returned by
  823. * the H_ALLOCATE_VAS_WINDOW hcall
  824. * - R6: "target" is per "ibm,ppc-interrupt-server#s" or
  825. * "ibm,ppc-interrupt-gserver#s"
  826. * - R7: "priority" is a valid priority not in
  827. * "ibm,plat-res-int-priorities"
  828. * - R8: "eisn" is the guest EISN associated with the "lisn"
  829. *
  830. * Output:
  831. * - None
  832. */
  833. #define SPAPR_XIVE_SRC_SET_EISN PPC_BIT(62)
  834. #define SPAPR_XIVE_SRC_MASK PPC_BIT(63)
  835. static target_ulong h_int_set_source_config(PowerPCCPU *cpu,
  836. SpaprMachineState *spapr,
  837. target_ulong opcode,
  838. target_ulong *args)
  839. {
  840. SpaprXive *xive = spapr->xive;
  841. XiveEAS eas, new_eas;
  842. target_ulong flags = args[0];
  843. target_ulong lisn = args[1];
  844. target_ulong target = args[2];
  845. target_ulong priority = args[3];
  846. target_ulong eisn = args[4];
  847. uint8_t end_blk;
  848. uint32_t end_idx;
  849. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  850. return H_FUNCTION;
  851. }
  852. if (flags & ~(SPAPR_XIVE_SRC_SET_EISN | SPAPR_XIVE_SRC_MASK)) {
  853. return H_PARAMETER;
  854. }
  855. if (lisn >= xive->nr_irqs) {
  856. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
  857. lisn);
  858. return H_P2;
  859. }
  860. eas = xive->eat[lisn];
  861. if (!xive_eas_is_valid(&eas)) {
  862. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
  863. lisn);
  864. return H_P2;
  865. }
  866. /* priority 0xff is used to reset the EAS */
  867. if (priority == 0xff) {
  868. new_eas.w = cpu_to_be64(EAS_VALID | EAS_MASKED);
  869. goto out;
  870. }
  871. if (flags & SPAPR_XIVE_SRC_MASK) {
  872. new_eas.w = eas.w | cpu_to_be64(EAS_MASKED);
  873. } else {
  874. new_eas.w = eas.w & cpu_to_be64(~EAS_MASKED);
  875. }
  876. if (spapr_xive_priority_is_reserved(priority)) {
  877. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
  878. " is reserved\n", priority);
  879. return H_P4;
  880. }
  881. /*
  882. * Validate that "target" is part of the list of threads allocated
  883. * to the partition. For that, find the END corresponding to the
  884. * target.
  885. */
  886. if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
  887. return H_P3;
  888. }
  889. new_eas.w = xive_set_field64(EAS_END_BLOCK, new_eas.w, end_blk);
  890. new_eas.w = xive_set_field64(EAS_END_INDEX, new_eas.w, end_idx);
  891. if (flags & SPAPR_XIVE_SRC_SET_EISN) {
  892. new_eas.w = xive_set_field64(EAS_END_DATA, new_eas.w, eisn);
  893. }
  894. if (kvm_irqchip_in_kernel()) {
  895. Error *local_err = NULL;
  896. kvmppc_xive_set_source_config(xive, lisn, &new_eas, &local_err);
  897. if (local_err) {
  898. error_report_err(local_err);
  899. return H_HARDWARE;
  900. }
  901. }
  902. out:
  903. xive->eat[lisn] = new_eas;
  904. return H_SUCCESS;
  905. }
  906. /*
  907. * The H_INT_GET_SOURCE_CONFIG hcall() is used to determine to which
  908. * target/priority pair is assigned to the specified Logical Interrupt
  909. * Source.
  910. *
  911. * Parameters:
  912. * Input:
  913. * - R4: "flags"
  914. * Bits 0-63 Reserved
  915. * - R5: "lisn" is per "interrupts", "interrupt-map", or
  916. * "ibm,xive-lisn-ranges" properties, or as returned by the
  917. * ibm,query-interrupt-source-number RTAS call, or as
  918. * returned by the H_ALLOCATE_VAS_WINDOW hcall
  919. *
  920. * Output:
  921. * - R4: Target to which the specified Logical Interrupt Source is
  922. * assigned
  923. * - R5: Priority to which the specified Logical Interrupt Source is
  924. * assigned
  925. * - R6: EISN for the specified Logical Interrupt Source (this will be
  926. * equivalent to the LISN if not changed by H_INT_SET_SOURCE_CONFIG)
  927. */
  928. static target_ulong h_int_get_source_config(PowerPCCPU *cpu,
  929. SpaprMachineState *spapr,
  930. target_ulong opcode,
  931. target_ulong *args)
  932. {
  933. SpaprXive *xive = spapr->xive;
  934. target_ulong flags = args[0];
  935. target_ulong lisn = args[1];
  936. XiveEAS eas;
  937. XiveEND *end;
  938. uint8_t nvt_blk;
  939. uint32_t end_idx, nvt_idx;
  940. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  941. return H_FUNCTION;
  942. }
  943. if (flags) {
  944. return H_PARAMETER;
  945. }
  946. if (lisn >= xive->nr_irqs) {
  947. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
  948. lisn);
  949. return H_P2;
  950. }
  951. eas = xive->eat[lisn];
  952. if (!xive_eas_is_valid(&eas)) {
  953. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
  954. lisn);
  955. return H_P2;
  956. }
  957. /* EAS_END_BLOCK is unused on sPAPR */
  958. end_idx = xive_get_field64(EAS_END_INDEX, eas.w);
  959. assert(end_idx < xive->nr_ends);
  960. end = &xive->endt[end_idx];
  961. nvt_blk = xive_get_field32(END_W6_NVT_BLOCK, end->w6);
  962. nvt_idx = xive_get_field32(END_W6_NVT_INDEX, end->w6);
  963. args[0] = spapr_xive_nvt_to_target(nvt_blk, nvt_idx);
  964. if (xive_eas_is_masked(&eas)) {
  965. args[1] = 0xff;
  966. } else {
  967. args[1] = xive_get_field32(END_W7_F0_PRIORITY, end->w7);
  968. }
  969. args[2] = xive_get_field64(EAS_END_DATA, eas.w);
  970. return H_SUCCESS;
  971. }
  972. /*
  973. * The H_INT_GET_QUEUE_INFO hcall() is used to get the logical real
  974. * address of the notification management page associated with the
  975. * specified target and priority.
  976. *
  977. * Parameters:
  978. * Input:
  979. * - R4: "flags"
  980. * Bits 0-63 Reserved
  981. * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
  982. * "ibm,ppc-interrupt-gserver#s"
  983. * - R6: "priority" is a valid priority not in
  984. * "ibm,plat-res-int-priorities"
  985. *
  986. * Output:
  987. * - R4: Logical real address of notification page
  988. * - R5: Power of 2 page size of the notification page
  989. */
  990. static target_ulong h_int_get_queue_info(PowerPCCPU *cpu,
  991. SpaprMachineState *spapr,
  992. target_ulong opcode,
  993. target_ulong *args)
  994. {
  995. SpaprXive *xive = spapr->xive;
  996. XiveENDSource *end_xsrc = &xive->end_source;
  997. target_ulong flags = args[0];
  998. target_ulong target = args[1];
  999. target_ulong priority = args[2];
  1000. XiveEND *end;
  1001. uint8_t end_blk;
  1002. uint32_t end_idx;
  1003. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1004. return H_FUNCTION;
  1005. }
  1006. if (flags) {
  1007. return H_PARAMETER;
  1008. }
  1009. /*
  1010. * H_STATE should be returned if a H_INT_RESET is in progress.
  1011. * This is not needed when running the emulation under QEMU
  1012. */
  1013. if (spapr_xive_priority_is_reserved(priority)) {
  1014. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
  1015. " is reserved\n", priority);
  1016. return H_P3;
  1017. }
  1018. /*
  1019. * Validate that "target" is part of the list of threads allocated
  1020. * to the partition. For that, find the END corresponding to the
  1021. * target.
  1022. */
  1023. if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
  1024. return H_P2;
  1025. }
  1026. assert(end_idx < xive->nr_ends);
  1027. end = &xive->endt[end_idx];
  1028. args[0] = xive->end_base + (1ull << (end_xsrc->esb_shift + 1)) * end_idx;
  1029. if (xive_end_is_enqueue(end)) {
  1030. args[1] = xive_get_field32(END_W0_QSIZE, end->w0) + 12;
  1031. } else {
  1032. args[1] = 0;
  1033. }
  1034. return H_SUCCESS;
  1035. }
  1036. /*
  1037. * The H_INT_SET_QUEUE_CONFIG hcall() is used to set or reset a EQ for
  1038. * a given "target" and "priority". It is also used to set the
  1039. * notification config associated with the EQ. An EQ size of 0 is
  1040. * used to reset the EQ config for a given target and priority. If
  1041. * resetting the EQ config, the END associated with the given "target"
  1042. * and "priority" will be changed to disable queueing.
  1043. *
  1044. * Upon return from the hcall(), no additional interrupts will be
  1045. * directed to the old EQ (if one was set). The old EQ (if one was
  1046. * set) should be investigated for interrupts that occurred prior to
  1047. * or during the hcall().
  1048. *
  1049. * Parameters:
  1050. * Input:
  1051. * - R4: "flags"
  1052. * Bits 0-62: Reserved
  1053. * Bit 63: Unconditional Notify (n) per the XIVE spec
  1054. * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
  1055. * "ibm,ppc-interrupt-gserver#s"
  1056. * - R6: "priority" is a valid priority not in
  1057. * "ibm,plat-res-int-priorities"
  1058. * - R7: "eventQueue": The logical real address of the start of the EQ
  1059. * - R8: "eventQueueSize": The power of 2 EQ size per "ibm,xive-eq-sizes"
  1060. *
  1061. * Output:
  1062. * - None
  1063. */
  1064. #define SPAPR_XIVE_END_ALWAYS_NOTIFY PPC_BIT(63)
  1065. static target_ulong h_int_set_queue_config(PowerPCCPU *cpu,
  1066. SpaprMachineState *spapr,
  1067. target_ulong opcode,
  1068. target_ulong *args)
  1069. {
  1070. SpaprXive *xive = spapr->xive;
  1071. target_ulong flags = args[0];
  1072. target_ulong target = args[1];
  1073. target_ulong priority = args[2];
  1074. target_ulong qpage = args[3];
  1075. target_ulong qsize = args[4];
  1076. XiveEND end;
  1077. uint8_t end_blk, nvt_blk;
  1078. uint32_t end_idx, nvt_idx;
  1079. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1080. return H_FUNCTION;
  1081. }
  1082. if (flags & ~SPAPR_XIVE_END_ALWAYS_NOTIFY) {
  1083. return H_PARAMETER;
  1084. }
  1085. /*
  1086. * H_STATE should be returned if a H_INT_RESET is in progress.
  1087. * This is not needed when running the emulation under QEMU
  1088. */
  1089. if (spapr_xive_priority_is_reserved(priority)) {
  1090. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
  1091. " is reserved\n", priority);
  1092. return H_P3;
  1093. }
  1094. /*
  1095. * Validate that "target" is part of the list of threads allocated
  1096. * to the partition. For that, find the END corresponding to the
  1097. * target.
  1098. */
  1099. if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
  1100. return H_P2;
  1101. }
  1102. assert(end_idx < xive->nr_ends);
  1103. memcpy(&end, &xive->endt[end_idx], sizeof(XiveEND));
  1104. switch (qsize) {
  1105. case 12:
  1106. case 16:
  1107. case 21:
  1108. case 24:
  1109. if (!QEMU_IS_ALIGNED(qpage, 1ul << qsize)) {
  1110. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: EQ @0x%" HWADDR_PRIx
  1111. " is not naturally aligned with %" HWADDR_PRIx "\n",
  1112. qpage, (hwaddr)1 << qsize);
  1113. return H_P4;
  1114. }
  1115. end.w2 = cpu_to_be32((qpage >> 32) & 0x0fffffff);
  1116. end.w3 = cpu_to_be32(qpage & 0xffffffff);
  1117. end.w0 |= cpu_to_be32(END_W0_ENQUEUE);
  1118. end.w0 = xive_set_field32(END_W0_QSIZE, end.w0, qsize - 12);
  1119. break;
  1120. case 0:
  1121. /* reset queue and disable queueing */
  1122. spapr_xive_end_reset(&end);
  1123. goto out;
  1124. default:
  1125. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid EQ size %"PRIx64"\n",
  1126. qsize);
  1127. return H_P5;
  1128. }
  1129. if (qsize) {
  1130. hwaddr plen = 1 << qsize;
  1131. void *eq;
  1132. /*
  1133. * Validate the guest EQ. We should also check that the queue
  1134. * has been zeroed by the OS.
  1135. */
  1136. eq = address_space_map(CPU(cpu)->as, qpage, &plen, true,
  1137. MEMTXATTRS_UNSPECIFIED);
  1138. if (plen != 1 << qsize) {
  1139. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to map EQ @0x%"
  1140. HWADDR_PRIx "\n", qpage);
  1141. return H_P4;
  1142. }
  1143. address_space_unmap(CPU(cpu)->as, eq, plen, true, plen);
  1144. }
  1145. /* "target" should have been validated above */
  1146. if (spapr_xive_target_to_nvt(target, &nvt_blk, &nvt_idx)) {
  1147. g_assert_not_reached();
  1148. }
  1149. /*
  1150. * Ensure the priority and target are correctly set (they will not
  1151. * be right after allocation)
  1152. */
  1153. end.w6 = xive_set_field32(END_W6_NVT_BLOCK, 0ul, nvt_blk) |
  1154. xive_set_field32(END_W6_NVT_INDEX, 0ul, nvt_idx);
  1155. end.w7 = xive_set_field32(END_W7_F0_PRIORITY, 0ul, priority);
  1156. if (flags & SPAPR_XIVE_END_ALWAYS_NOTIFY) {
  1157. end.w0 |= cpu_to_be32(END_W0_UCOND_NOTIFY);
  1158. } else {
  1159. end.w0 &= cpu_to_be32((uint32_t)~END_W0_UCOND_NOTIFY);
  1160. }
  1161. /*
  1162. * The generation bit for the END starts at 1 and The END page
  1163. * offset counter starts at 0.
  1164. */
  1165. end.w1 = cpu_to_be32(END_W1_GENERATION) |
  1166. xive_set_field32(END_W1_PAGE_OFF, 0ul, 0ul);
  1167. end.w0 |= cpu_to_be32(END_W0_VALID);
  1168. /*
  1169. * TODO: issue syncs required to ensure all in-flight interrupts
  1170. * are complete on the old END
  1171. */
  1172. out:
  1173. if (kvm_irqchip_in_kernel()) {
  1174. Error *local_err = NULL;
  1175. kvmppc_xive_set_queue_config(xive, end_blk, end_idx, &end, &local_err);
  1176. if (local_err) {
  1177. error_report_err(local_err);
  1178. return H_HARDWARE;
  1179. }
  1180. }
  1181. /* Update END */
  1182. memcpy(&xive->endt[end_idx], &end, sizeof(XiveEND));
  1183. return H_SUCCESS;
  1184. }
  1185. /*
  1186. * The H_INT_GET_QUEUE_CONFIG hcall() is used to get a EQ for a given
  1187. * target and priority.
  1188. *
  1189. * Parameters:
  1190. * Input:
  1191. * - R4: "flags"
  1192. * Bits 0-62: Reserved
  1193. * Bit 63: Debug: Return debug data
  1194. * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
  1195. * "ibm,ppc-interrupt-gserver#s"
  1196. * - R6: "priority" is a valid priority not in
  1197. * "ibm,plat-res-int-priorities"
  1198. *
  1199. * Output:
  1200. * - R4: "flags":
  1201. * Bits 0-61: Reserved
  1202. * Bit 62: The value of Event Queue Generation Number (g) per
  1203. * the XIVE spec if "Debug" = 1
  1204. * Bit 63: The value of Unconditional Notify (n) per the XIVE spec
  1205. * - R5: The logical real address of the start of the EQ
  1206. * - R6: The power of 2 EQ size per "ibm,xive-eq-sizes"
  1207. * - R7: The value of Event Queue Offset Counter per XIVE spec
  1208. * if "Debug" = 1, else 0
  1209. *
  1210. */
  1211. #define SPAPR_XIVE_END_DEBUG PPC_BIT(63)
  1212. static target_ulong h_int_get_queue_config(PowerPCCPU *cpu,
  1213. SpaprMachineState *spapr,
  1214. target_ulong opcode,
  1215. target_ulong *args)
  1216. {
  1217. SpaprXive *xive = spapr->xive;
  1218. target_ulong flags = args[0];
  1219. target_ulong target = args[1];
  1220. target_ulong priority = args[2];
  1221. XiveEND *end;
  1222. uint8_t end_blk;
  1223. uint32_t end_idx;
  1224. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1225. return H_FUNCTION;
  1226. }
  1227. if (flags & ~SPAPR_XIVE_END_DEBUG) {
  1228. return H_PARAMETER;
  1229. }
  1230. /*
  1231. * H_STATE should be returned if a H_INT_RESET is in progress.
  1232. * This is not needed when running the emulation under QEMU
  1233. */
  1234. if (spapr_xive_priority_is_reserved(priority)) {
  1235. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: priority " TARGET_FMT_ld
  1236. " is reserved\n", priority);
  1237. return H_P3;
  1238. }
  1239. /*
  1240. * Validate that "target" is part of the list of threads allocated
  1241. * to the partition. For that, find the END corresponding to the
  1242. * target.
  1243. */
  1244. if (spapr_xive_target_to_end(target, priority, &end_blk, &end_idx)) {
  1245. return H_P2;
  1246. }
  1247. assert(end_idx < xive->nr_ends);
  1248. end = &xive->endt[end_idx];
  1249. args[0] = 0;
  1250. if (xive_end_is_notify(end)) {
  1251. args[0] |= SPAPR_XIVE_END_ALWAYS_NOTIFY;
  1252. }
  1253. if (xive_end_is_enqueue(end)) {
  1254. args[1] = xive_end_qaddr(end);
  1255. args[2] = xive_get_field32(END_W0_QSIZE, end->w0) + 12;
  1256. } else {
  1257. args[1] = 0;
  1258. args[2] = 0;
  1259. }
  1260. if (kvm_irqchip_in_kernel()) {
  1261. Error *local_err = NULL;
  1262. kvmppc_xive_get_queue_config(xive, end_blk, end_idx, end, &local_err);
  1263. if (local_err) {
  1264. error_report_err(local_err);
  1265. return H_HARDWARE;
  1266. }
  1267. }
  1268. /* TODO: do we need any locking on the END ? */
  1269. if (flags & SPAPR_XIVE_END_DEBUG) {
  1270. /* Load the event queue generation number into the return flags */
  1271. args[0] |= (uint64_t)xive_get_field32(END_W1_GENERATION, end->w1) << 62;
  1272. /* Load R7 with the event queue offset counter */
  1273. args[3] = xive_get_field32(END_W1_PAGE_OFF, end->w1);
  1274. } else {
  1275. args[3] = 0;
  1276. }
  1277. return H_SUCCESS;
  1278. }
  1279. /*
  1280. * The H_INT_SET_OS_REPORTING_LINE hcall() is used to set the
  1281. * reporting cache line pair for the calling thread. The reporting
  1282. * cache lines will contain the OS interrupt context when the OS
  1283. * issues a CI store byte to @TIMA+0xC10 to acknowledge the OS
  1284. * interrupt. The reporting cache lines can be reset by inputting -1
  1285. * in "reportingLine". Issuing the CI store byte without reporting
  1286. * cache lines registered will result in the data not being accessible
  1287. * to the OS.
  1288. *
  1289. * Parameters:
  1290. * Input:
  1291. * - R4: "flags"
  1292. * Bits 0-63: Reserved
  1293. * - R5: "reportingLine": The logical real address of the reporting cache
  1294. * line pair
  1295. *
  1296. * Output:
  1297. * - None
  1298. */
  1299. static target_ulong h_int_set_os_reporting_line(PowerPCCPU *cpu,
  1300. SpaprMachineState *spapr,
  1301. target_ulong opcode,
  1302. target_ulong *args)
  1303. {
  1304. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1305. return H_FUNCTION;
  1306. }
  1307. /*
  1308. * H_STATE should be returned if a H_INT_RESET is in progress.
  1309. * This is not needed when running the emulation under QEMU
  1310. */
  1311. /* TODO: H_INT_SET_OS_REPORTING_LINE */
  1312. return H_FUNCTION;
  1313. }
  1314. /*
  1315. * The H_INT_GET_OS_REPORTING_LINE hcall() is used to get the logical
  1316. * real address of the reporting cache line pair set for the input
  1317. * "target". If no reporting cache line pair has been set, -1 is
  1318. * returned.
  1319. *
  1320. * Parameters:
  1321. * Input:
  1322. * - R4: "flags"
  1323. * Bits 0-63: Reserved
  1324. * - R5: "target" is per "ibm,ppc-interrupt-server#s" or
  1325. * "ibm,ppc-interrupt-gserver#s"
  1326. * - R6: "reportingLine": The logical real address of the reporting
  1327. * cache line pair
  1328. *
  1329. * Output:
  1330. * - R4: The logical real address of the reporting line if set, else -1
  1331. */
  1332. static target_ulong h_int_get_os_reporting_line(PowerPCCPU *cpu,
  1333. SpaprMachineState *spapr,
  1334. target_ulong opcode,
  1335. target_ulong *args)
  1336. {
  1337. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1338. return H_FUNCTION;
  1339. }
  1340. /*
  1341. * H_STATE should be returned if a H_INT_RESET is in progress.
  1342. * This is not needed when running the emulation under QEMU
  1343. */
  1344. /* TODO: H_INT_GET_OS_REPORTING_LINE */
  1345. return H_FUNCTION;
  1346. }
  1347. /*
  1348. * The H_INT_ESB hcall() is used to issue a load or store to the ESB
  1349. * page for the input "lisn". This hcall is only supported for LISNs
  1350. * that have the ESB hcall flag set to 1 when returned from hcall()
  1351. * H_INT_GET_SOURCE_INFO.
  1352. *
  1353. * Parameters:
  1354. * Input:
  1355. * - R4: "flags"
  1356. * Bits 0-62: Reserved
  1357. * bit 63: Store: Store=1, store operation, else load operation
  1358. * - R5: "lisn" is per "interrupts", "interrupt-map", or
  1359. * "ibm,xive-lisn-ranges" properties, or as returned by the
  1360. * ibm,query-interrupt-source-number RTAS call, or as
  1361. * returned by the H_ALLOCATE_VAS_WINDOW hcall
  1362. * - R6: "esbOffset" is the offset into the ESB page for the load or
  1363. * store operation
  1364. * - R7: "storeData" is the data to write for a store operation
  1365. *
  1366. * Output:
  1367. * - R4: The value of the load if load operation, else -1
  1368. */
  1369. #define SPAPR_XIVE_ESB_STORE PPC_BIT(63)
  1370. static target_ulong h_int_esb(PowerPCCPU *cpu,
  1371. SpaprMachineState *spapr,
  1372. target_ulong opcode,
  1373. target_ulong *args)
  1374. {
  1375. SpaprXive *xive = spapr->xive;
  1376. XiveEAS eas;
  1377. target_ulong flags = args[0];
  1378. target_ulong lisn = args[1];
  1379. target_ulong offset = args[2];
  1380. target_ulong data = args[3];
  1381. hwaddr mmio_addr;
  1382. XiveSource *xsrc = &xive->source;
  1383. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1384. return H_FUNCTION;
  1385. }
  1386. if (flags & ~SPAPR_XIVE_ESB_STORE) {
  1387. return H_PARAMETER;
  1388. }
  1389. if (lisn >= xive->nr_irqs) {
  1390. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
  1391. lisn);
  1392. return H_P2;
  1393. }
  1394. eas = xive->eat[lisn];
  1395. if (!xive_eas_is_valid(&eas)) {
  1396. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
  1397. lisn);
  1398. return H_P2;
  1399. }
  1400. if (offset > (1ull << xsrc->esb_shift)) {
  1401. return H_P3;
  1402. }
  1403. if (kvm_irqchip_in_kernel()) {
  1404. args[0] = kvmppc_xive_esb_rw(xsrc, lisn, offset, data,
  1405. flags & SPAPR_XIVE_ESB_STORE);
  1406. } else {
  1407. mmio_addr = xive->vc_base + xive_source_esb_mgmt(xsrc, lisn) + offset;
  1408. if (dma_memory_rw(&address_space_memory, mmio_addr, &data, 8,
  1409. (flags & SPAPR_XIVE_ESB_STORE))) {
  1410. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: failed to access ESB @0x%"
  1411. HWADDR_PRIx "\n", mmio_addr);
  1412. return H_HARDWARE;
  1413. }
  1414. args[0] = (flags & SPAPR_XIVE_ESB_STORE) ? -1 : data;
  1415. }
  1416. return H_SUCCESS;
  1417. }
  1418. /*
  1419. * The H_INT_SYNC hcall() is used to issue hardware syncs that will
  1420. * ensure any in flight events for the input lisn are in the event
  1421. * queue.
  1422. *
  1423. * Parameters:
  1424. * Input:
  1425. * - R4: "flags"
  1426. * Bits 0-63: Reserved
  1427. * - R5: "lisn" is per "interrupts", "interrupt-map", or
  1428. * "ibm,xive-lisn-ranges" properties, or as returned by the
  1429. * ibm,query-interrupt-source-number RTAS call, or as
  1430. * returned by the H_ALLOCATE_VAS_WINDOW hcall
  1431. *
  1432. * Output:
  1433. * - None
  1434. */
  1435. static target_ulong h_int_sync(PowerPCCPU *cpu,
  1436. SpaprMachineState *spapr,
  1437. target_ulong opcode,
  1438. target_ulong *args)
  1439. {
  1440. SpaprXive *xive = spapr->xive;
  1441. XiveEAS eas;
  1442. target_ulong flags = args[0];
  1443. target_ulong lisn = args[1];
  1444. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1445. return H_FUNCTION;
  1446. }
  1447. if (flags) {
  1448. return H_PARAMETER;
  1449. }
  1450. if (lisn >= xive->nr_irqs) {
  1451. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Unknown LISN " TARGET_FMT_lx "\n",
  1452. lisn);
  1453. return H_P2;
  1454. }
  1455. eas = xive->eat[lisn];
  1456. if (!xive_eas_is_valid(&eas)) {
  1457. qemu_log_mask(LOG_GUEST_ERROR, "XIVE: Invalid LISN " TARGET_FMT_lx "\n",
  1458. lisn);
  1459. return H_P2;
  1460. }
  1461. /*
  1462. * H_STATE should be returned if a H_INT_RESET is in progress.
  1463. * This is not needed when running the emulation under QEMU
  1464. */
  1465. /*
  1466. * This is not real hardware. Nothing to be done unless when
  1467. * under KVM
  1468. */
  1469. if (kvm_irqchip_in_kernel()) {
  1470. Error *local_err = NULL;
  1471. kvmppc_xive_sync_source(xive, lisn, &local_err);
  1472. if (local_err) {
  1473. error_report_err(local_err);
  1474. return H_HARDWARE;
  1475. }
  1476. }
  1477. return H_SUCCESS;
  1478. }
  1479. /*
  1480. * The H_INT_RESET hcall() is used to reset all of the partition's
  1481. * interrupt exploitation structures to their initial state. This
  1482. * means losing all previously set interrupt state set via
  1483. * H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
  1484. *
  1485. * Parameters:
  1486. * Input:
  1487. * - R4: "flags"
  1488. * Bits 0-63: Reserved
  1489. *
  1490. * Output:
  1491. * - None
  1492. */
  1493. static target_ulong h_int_reset(PowerPCCPU *cpu,
  1494. SpaprMachineState *spapr,
  1495. target_ulong opcode,
  1496. target_ulong *args)
  1497. {
  1498. SpaprXive *xive = spapr->xive;
  1499. target_ulong flags = args[0];
  1500. if (!spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
  1501. return H_FUNCTION;
  1502. }
  1503. if (flags) {
  1504. return H_PARAMETER;
  1505. }
  1506. device_legacy_reset(DEVICE(xive));
  1507. if (kvm_irqchip_in_kernel()) {
  1508. Error *local_err = NULL;
  1509. kvmppc_xive_reset(xive, &local_err);
  1510. if (local_err) {
  1511. error_report_err(local_err);
  1512. return H_HARDWARE;
  1513. }
  1514. }
  1515. return H_SUCCESS;
  1516. }
  1517. void spapr_xive_hcall_init(SpaprMachineState *spapr)
  1518. {
  1519. spapr_register_hypercall(H_INT_GET_SOURCE_INFO, h_int_get_source_info);
  1520. spapr_register_hypercall(H_INT_SET_SOURCE_CONFIG, h_int_set_source_config);
  1521. spapr_register_hypercall(H_INT_GET_SOURCE_CONFIG, h_int_get_source_config);
  1522. spapr_register_hypercall(H_INT_GET_QUEUE_INFO, h_int_get_queue_info);
  1523. spapr_register_hypercall(H_INT_SET_QUEUE_CONFIG, h_int_set_queue_config);
  1524. spapr_register_hypercall(H_INT_GET_QUEUE_CONFIG, h_int_get_queue_config);
  1525. spapr_register_hypercall(H_INT_SET_OS_REPORTING_LINE,
  1526. h_int_set_os_reporting_line);
  1527. spapr_register_hypercall(H_INT_GET_OS_REPORTING_LINE,
  1528. h_int_get_os_reporting_line);
  1529. spapr_register_hypercall(H_INT_ESB, h_int_esb);
  1530. spapr_register_hypercall(H_INT_SYNC, h_int_sync);
  1531. spapr_register_hypercall(H_INT_RESET, h_int_reset);
  1532. }