spapr_xive.c 54 KB

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