vfio_pci_intrs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * VFIO PCI interrupt handling
  3. *
  4. * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
  5. * Author: Alex Williamson <alex.williamson@redhat.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Derived from original vfio:
  12. * Copyright 2010 Cisco Systems, Inc. All rights reserved.
  13. * Author: Tom Lyon, pugs@cisco.com
  14. */
  15. #include <linux/device.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/eventfd.h>
  18. #include <linux/msi.h>
  19. #include <linux/pci.h>
  20. #include <linux/file.h>
  21. #include <linux/vfio.h>
  22. #include <linux/wait.h>
  23. #include <linux/slab.h>
  24. #include "vfio_pci_private.h"
  25. /*
  26. * INTx
  27. */
  28. static void vfio_send_intx_eventfd(void *opaque, void *unused)
  29. {
  30. struct vfio_pci_device *vdev = opaque;
  31. if (likely(is_intx(vdev) && !vdev->virq_disabled))
  32. eventfd_signal(vdev->ctx[0].trigger, 1);
  33. }
  34. void vfio_pci_intx_mask(struct vfio_pci_device *vdev)
  35. {
  36. struct pci_dev *pdev = vdev->pdev;
  37. unsigned long flags;
  38. spin_lock_irqsave(&vdev->irqlock, flags);
  39. /*
  40. * Masking can come from interrupt, ioctl, or config space
  41. * via INTx disable. The latter means this can get called
  42. * even when not using intx delivery. In this case, just
  43. * try to have the physical bit follow the virtual bit.
  44. */
  45. if (unlikely(!is_intx(vdev))) {
  46. if (vdev->pci_2_3)
  47. pci_intx(pdev, 0);
  48. } else if (!vdev->ctx[0].masked) {
  49. /*
  50. * Can't use check_and_mask here because we always want to
  51. * mask, not just when something is pending.
  52. */
  53. if (vdev->pci_2_3)
  54. pci_intx(pdev, 0);
  55. else
  56. disable_irq_nosync(pdev->irq);
  57. vdev->ctx[0].masked = true;
  58. }
  59. spin_unlock_irqrestore(&vdev->irqlock, flags);
  60. }
  61. /*
  62. * If this is triggered by an eventfd, we can't call eventfd_signal
  63. * or else we'll deadlock on the eventfd wait queue. Return >0 when
  64. * a signal is necessary, which can then be handled via a work queue
  65. * or directly depending on the caller.
  66. */
  67. static int vfio_pci_intx_unmask_handler(void *opaque, void *unused)
  68. {
  69. struct vfio_pci_device *vdev = opaque;
  70. struct pci_dev *pdev = vdev->pdev;
  71. unsigned long flags;
  72. int ret = 0;
  73. spin_lock_irqsave(&vdev->irqlock, flags);
  74. /*
  75. * Unmasking comes from ioctl or config, so again, have the
  76. * physical bit follow the virtual even when not using INTx.
  77. */
  78. if (unlikely(!is_intx(vdev))) {
  79. if (vdev->pci_2_3)
  80. pci_intx(pdev, 1);
  81. } else if (vdev->ctx[0].masked && !vdev->virq_disabled) {
  82. /*
  83. * A pending interrupt here would immediately trigger,
  84. * but we can avoid that overhead by just re-sending
  85. * the interrupt to the user.
  86. */
  87. if (vdev->pci_2_3) {
  88. if (!pci_check_and_unmask_intx(pdev))
  89. ret = 1;
  90. } else
  91. enable_irq(pdev->irq);
  92. vdev->ctx[0].masked = (ret > 0);
  93. }
  94. spin_unlock_irqrestore(&vdev->irqlock, flags);
  95. return ret;
  96. }
  97. void vfio_pci_intx_unmask(struct vfio_pci_device *vdev)
  98. {
  99. if (vfio_pci_intx_unmask_handler(vdev, NULL) > 0)
  100. vfio_send_intx_eventfd(vdev, NULL);
  101. }
  102. static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
  103. {
  104. struct vfio_pci_device *vdev = dev_id;
  105. unsigned long flags;
  106. int ret = IRQ_NONE;
  107. spin_lock_irqsave(&vdev->irqlock, flags);
  108. if (!vdev->pci_2_3) {
  109. disable_irq_nosync(vdev->pdev->irq);
  110. vdev->ctx[0].masked = true;
  111. ret = IRQ_HANDLED;
  112. } else if (!vdev->ctx[0].masked && /* may be shared */
  113. pci_check_and_mask_intx(vdev->pdev)) {
  114. vdev->ctx[0].masked = true;
  115. ret = IRQ_HANDLED;
  116. }
  117. spin_unlock_irqrestore(&vdev->irqlock, flags);
  118. if (ret == IRQ_HANDLED)
  119. vfio_send_intx_eventfd(vdev, NULL);
  120. return ret;
  121. }
  122. static int vfio_intx_enable(struct vfio_pci_device *vdev)
  123. {
  124. if (!is_irq_none(vdev))
  125. return -EINVAL;
  126. if (!vdev->pdev->irq)
  127. return -ENODEV;
  128. vdev->ctx = kzalloc(sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL);
  129. if (!vdev->ctx)
  130. return -ENOMEM;
  131. vdev->num_ctx = 1;
  132. /*
  133. * If the virtual interrupt is masked, restore it. Devices
  134. * supporting DisINTx can be masked at the hardware level
  135. * here, non-PCI-2.3 devices will have to wait until the
  136. * interrupt is enabled.
  137. */
  138. vdev->ctx[0].masked = vdev->virq_disabled;
  139. if (vdev->pci_2_3)
  140. pci_intx(vdev->pdev, !vdev->ctx[0].masked);
  141. vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX;
  142. return 0;
  143. }
  144. static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd)
  145. {
  146. struct pci_dev *pdev = vdev->pdev;
  147. unsigned long irqflags = IRQF_SHARED;
  148. struct eventfd_ctx *trigger;
  149. unsigned long flags;
  150. int ret;
  151. if (vdev->ctx[0].trigger) {
  152. free_irq(pdev->irq, vdev);
  153. kfree(vdev->ctx[0].name);
  154. eventfd_ctx_put(vdev->ctx[0].trigger);
  155. vdev->ctx[0].trigger = NULL;
  156. }
  157. if (fd < 0) /* Disable only */
  158. return 0;
  159. vdev->ctx[0].name = kasprintf(GFP_KERNEL, "vfio-intx(%s)",
  160. pci_name(pdev));
  161. if (!vdev->ctx[0].name)
  162. return -ENOMEM;
  163. trigger = eventfd_ctx_fdget(fd);
  164. if (IS_ERR(trigger)) {
  165. kfree(vdev->ctx[0].name);
  166. return PTR_ERR(trigger);
  167. }
  168. vdev->ctx[0].trigger = trigger;
  169. if (!vdev->pci_2_3)
  170. irqflags = 0;
  171. ret = request_irq(pdev->irq, vfio_intx_handler,
  172. irqflags, vdev->ctx[0].name, vdev);
  173. if (ret) {
  174. vdev->ctx[0].trigger = NULL;
  175. kfree(vdev->ctx[0].name);
  176. eventfd_ctx_put(trigger);
  177. return ret;
  178. }
  179. /*
  180. * INTx disable will stick across the new irq setup,
  181. * disable_irq won't.
  182. */
  183. spin_lock_irqsave(&vdev->irqlock, flags);
  184. if (!vdev->pci_2_3 && vdev->ctx[0].masked)
  185. disable_irq_nosync(pdev->irq);
  186. spin_unlock_irqrestore(&vdev->irqlock, flags);
  187. return 0;
  188. }
  189. static void vfio_intx_disable(struct vfio_pci_device *vdev)
  190. {
  191. vfio_virqfd_disable(&vdev->ctx[0].unmask);
  192. vfio_virqfd_disable(&vdev->ctx[0].mask);
  193. vfio_intx_set_signal(vdev, -1);
  194. vdev->irq_type = VFIO_PCI_NUM_IRQS;
  195. vdev->num_ctx = 0;
  196. kfree(vdev->ctx);
  197. }
  198. /*
  199. * MSI/MSI-X
  200. */
  201. static irqreturn_t vfio_msihandler(int irq, void *arg)
  202. {
  203. struct eventfd_ctx *trigger = arg;
  204. eventfd_signal(trigger, 1);
  205. return IRQ_HANDLED;
  206. }
  207. static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
  208. {
  209. struct pci_dev *pdev = vdev->pdev;
  210. unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI;
  211. int ret;
  212. if (!is_irq_none(vdev))
  213. return -EINVAL;
  214. vdev->ctx = kcalloc(nvec, sizeof(struct vfio_pci_irq_ctx), GFP_KERNEL);
  215. if (!vdev->ctx)
  216. return -ENOMEM;
  217. /* return the number of supported vectors if we can't get all: */
  218. ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag);
  219. if (ret < nvec) {
  220. if (ret > 0)
  221. pci_free_irq_vectors(pdev);
  222. kfree(vdev->ctx);
  223. return ret;
  224. }
  225. vdev->num_ctx = nvec;
  226. vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
  227. VFIO_PCI_MSI_IRQ_INDEX;
  228. if (!msix) {
  229. /*
  230. * Compute the virtual hardware field for max msi vectors -
  231. * it is the log base 2 of the number of vectors.
  232. */
  233. vdev->msi_qmax = fls(nvec * 2 - 1) - 1;
  234. }
  235. return 0;
  236. }
  237. static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
  238. int vector, int fd, bool msix)
  239. {
  240. struct pci_dev *pdev = vdev->pdev;
  241. struct eventfd_ctx *trigger;
  242. int irq, ret;
  243. if (vector < 0 || vector >= vdev->num_ctx)
  244. return -EINVAL;
  245. irq = pci_irq_vector(pdev, vector);
  246. if (vdev->ctx[vector].trigger) {
  247. free_irq(irq, vdev->ctx[vector].trigger);
  248. irq_bypass_unregister_producer(&vdev->ctx[vector].producer);
  249. kfree(vdev->ctx[vector].name);
  250. eventfd_ctx_put(vdev->ctx[vector].trigger);
  251. vdev->ctx[vector].trigger = NULL;
  252. }
  253. if (fd < 0)
  254. return 0;
  255. vdev->ctx[vector].name = kasprintf(GFP_KERNEL, "vfio-msi%s[%d](%s)",
  256. msix ? "x" : "", vector,
  257. pci_name(pdev));
  258. if (!vdev->ctx[vector].name)
  259. return -ENOMEM;
  260. trigger = eventfd_ctx_fdget(fd);
  261. if (IS_ERR(trigger)) {
  262. kfree(vdev->ctx[vector].name);
  263. return PTR_ERR(trigger);
  264. }
  265. /*
  266. * The MSIx vector table resides in device memory which may be cleared
  267. * via backdoor resets. We don't allow direct access to the vector
  268. * table so even if a userspace driver attempts to save/restore around
  269. * such a reset it would be unsuccessful. To avoid this, restore the
  270. * cached value of the message prior to enabling.
  271. */
  272. if (msix) {
  273. struct msi_msg msg;
  274. get_cached_msi_msg(irq, &msg);
  275. pci_write_msi_msg(irq, &msg);
  276. }
  277. ret = request_irq(irq, vfio_msihandler, 0,
  278. vdev->ctx[vector].name, trigger);
  279. if (ret) {
  280. kfree(vdev->ctx[vector].name);
  281. eventfd_ctx_put(trigger);
  282. return ret;
  283. }
  284. vdev->ctx[vector].producer.token = trigger;
  285. vdev->ctx[vector].producer.irq = irq;
  286. ret = irq_bypass_register_producer(&vdev->ctx[vector].producer);
  287. if (unlikely(ret))
  288. dev_info(&pdev->dev,
  289. "irq bypass producer (token %p) registration fails: %d\n",
  290. vdev->ctx[vector].producer.token, ret);
  291. vdev->ctx[vector].trigger = trigger;
  292. return 0;
  293. }
  294. static int vfio_msi_set_block(struct vfio_pci_device *vdev, unsigned start,
  295. unsigned count, int32_t *fds, bool msix)
  296. {
  297. int i, j, ret = 0;
  298. if (start >= vdev->num_ctx || start + count > vdev->num_ctx)
  299. return -EINVAL;
  300. for (i = 0, j = start; i < count && !ret; i++, j++) {
  301. int fd = fds ? fds[i] : -1;
  302. ret = vfio_msi_set_vector_signal(vdev, j, fd, msix);
  303. }
  304. if (ret) {
  305. for (--j; j >= (int)start; j--)
  306. vfio_msi_set_vector_signal(vdev, j, -1, msix);
  307. }
  308. return ret;
  309. }
  310. static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
  311. {
  312. struct pci_dev *pdev = vdev->pdev;
  313. int i;
  314. for (i = 0; i < vdev->num_ctx; i++) {
  315. vfio_virqfd_disable(&vdev->ctx[i].unmask);
  316. vfio_virqfd_disable(&vdev->ctx[i].mask);
  317. }
  318. vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
  319. pci_free_irq_vectors(pdev);
  320. /*
  321. * Both disable paths above use pci_intx_for_msi() to clear DisINTx
  322. * via their shutdown paths. Restore for NoINTx devices.
  323. */
  324. if (vdev->nointx)
  325. pci_intx(pdev, 0);
  326. vdev->irq_type = VFIO_PCI_NUM_IRQS;
  327. vdev->num_ctx = 0;
  328. kfree(vdev->ctx);
  329. }
  330. /*
  331. * IOCTL support
  332. */
  333. static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev,
  334. unsigned index, unsigned start,
  335. unsigned count, uint32_t flags, void *data)
  336. {
  337. if (!is_intx(vdev) || start != 0 || count != 1)
  338. return -EINVAL;
  339. if (flags & VFIO_IRQ_SET_DATA_NONE) {
  340. vfio_pci_intx_unmask(vdev);
  341. } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
  342. uint8_t unmask = *(uint8_t *)data;
  343. if (unmask)
  344. vfio_pci_intx_unmask(vdev);
  345. } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
  346. int32_t fd = *(int32_t *)data;
  347. if (fd >= 0)
  348. return vfio_virqfd_enable((void *) vdev,
  349. vfio_pci_intx_unmask_handler,
  350. vfio_send_intx_eventfd, NULL,
  351. &vdev->ctx[0].unmask, fd);
  352. vfio_virqfd_disable(&vdev->ctx[0].unmask);
  353. }
  354. return 0;
  355. }
  356. static int vfio_pci_set_intx_mask(struct vfio_pci_device *vdev,
  357. unsigned index, unsigned start,
  358. unsigned count, uint32_t flags, void *data)
  359. {
  360. if (!is_intx(vdev) || start != 0 || count != 1)
  361. return -EINVAL;
  362. if (flags & VFIO_IRQ_SET_DATA_NONE) {
  363. vfio_pci_intx_mask(vdev);
  364. } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
  365. uint8_t mask = *(uint8_t *)data;
  366. if (mask)
  367. vfio_pci_intx_mask(vdev);
  368. } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
  369. return -ENOTTY; /* XXX implement me */
  370. }
  371. return 0;
  372. }
  373. static int vfio_pci_set_intx_trigger(struct vfio_pci_device *vdev,
  374. unsigned index, unsigned start,
  375. unsigned count, uint32_t flags, void *data)
  376. {
  377. if (is_intx(vdev) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
  378. vfio_intx_disable(vdev);
  379. return 0;
  380. }
  381. if (!(is_intx(vdev) || is_irq_none(vdev)) || start != 0 || count != 1)
  382. return -EINVAL;
  383. if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
  384. int32_t fd = *(int32_t *)data;
  385. int ret;
  386. if (is_intx(vdev))
  387. return vfio_intx_set_signal(vdev, fd);
  388. ret = vfio_intx_enable(vdev);
  389. if (ret)
  390. return ret;
  391. ret = vfio_intx_set_signal(vdev, fd);
  392. if (ret)
  393. vfio_intx_disable(vdev);
  394. return ret;
  395. }
  396. if (!is_intx(vdev))
  397. return -EINVAL;
  398. if (flags & VFIO_IRQ_SET_DATA_NONE) {
  399. vfio_send_intx_eventfd(vdev, NULL);
  400. } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
  401. uint8_t trigger = *(uint8_t *)data;
  402. if (trigger)
  403. vfio_send_intx_eventfd(vdev, NULL);
  404. }
  405. return 0;
  406. }
  407. static int vfio_pci_set_msi_trigger(struct vfio_pci_device *vdev,
  408. unsigned index, unsigned start,
  409. unsigned count, uint32_t flags, void *data)
  410. {
  411. int i;
  412. bool msix = (index == VFIO_PCI_MSIX_IRQ_INDEX) ? true : false;
  413. if (irq_is(vdev, index) && !count && (flags & VFIO_IRQ_SET_DATA_NONE)) {
  414. vfio_msi_disable(vdev, msix);
  415. return 0;
  416. }
  417. if (!(irq_is(vdev, index) || is_irq_none(vdev)))
  418. return -EINVAL;
  419. if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
  420. int32_t *fds = data;
  421. int ret;
  422. if (vdev->irq_type == index)
  423. return vfio_msi_set_block(vdev, start, count,
  424. fds, msix);
  425. ret = vfio_msi_enable(vdev, start + count, msix);
  426. if (ret)
  427. return ret;
  428. ret = vfio_msi_set_block(vdev, start, count, fds, msix);
  429. if (ret)
  430. vfio_msi_disable(vdev, msix);
  431. return ret;
  432. }
  433. if (!irq_is(vdev, index) || start + count > vdev->num_ctx)
  434. return -EINVAL;
  435. for (i = start; i < start + count; i++) {
  436. if (!vdev->ctx[i].trigger)
  437. continue;
  438. if (flags & VFIO_IRQ_SET_DATA_NONE) {
  439. eventfd_signal(vdev->ctx[i].trigger, 1);
  440. } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
  441. uint8_t *bools = data;
  442. if (bools[i - start])
  443. eventfd_signal(vdev->ctx[i].trigger, 1);
  444. }
  445. }
  446. return 0;
  447. }
  448. static int vfio_pci_set_ctx_trigger_single(struct eventfd_ctx **ctx,
  449. unsigned int count, uint32_t flags,
  450. void *data)
  451. {
  452. /* DATA_NONE/DATA_BOOL enables loopback testing */
  453. if (flags & VFIO_IRQ_SET_DATA_NONE) {
  454. if (*ctx) {
  455. if (count) {
  456. eventfd_signal(*ctx, 1);
  457. } else {
  458. eventfd_ctx_put(*ctx);
  459. *ctx = NULL;
  460. }
  461. return 0;
  462. }
  463. } else if (flags & VFIO_IRQ_SET_DATA_BOOL) {
  464. uint8_t trigger;
  465. if (!count)
  466. return -EINVAL;
  467. trigger = *(uint8_t *)data;
  468. if (trigger && *ctx)
  469. eventfd_signal(*ctx, 1);
  470. return 0;
  471. } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) {
  472. int32_t fd;
  473. if (!count)
  474. return -EINVAL;
  475. fd = *(int32_t *)data;
  476. if (fd == -1) {
  477. if (*ctx)
  478. eventfd_ctx_put(*ctx);
  479. *ctx = NULL;
  480. } else if (fd >= 0) {
  481. struct eventfd_ctx *efdctx;
  482. efdctx = eventfd_ctx_fdget(fd);
  483. if (IS_ERR(efdctx))
  484. return PTR_ERR(efdctx);
  485. if (*ctx)
  486. eventfd_ctx_put(*ctx);
  487. *ctx = efdctx;
  488. }
  489. return 0;
  490. }
  491. return -EINVAL;
  492. }
  493. static int vfio_pci_set_err_trigger(struct vfio_pci_device *vdev,
  494. unsigned index, unsigned start,
  495. unsigned count, uint32_t flags, void *data)
  496. {
  497. if (index != VFIO_PCI_ERR_IRQ_INDEX || start != 0 || count > 1)
  498. return -EINVAL;
  499. return vfio_pci_set_ctx_trigger_single(&vdev->err_trigger,
  500. count, flags, data);
  501. }
  502. static int vfio_pci_set_req_trigger(struct vfio_pci_device *vdev,
  503. unsigned index, unsigned start,
  504. unsigned count, uint32_t flags, void *data)
  505. {
  506. if (index != VFIO_PCI_REQ_IRQ_INDEX || start != 0 || count > 1)
  507. return -EINVAL;
  508. return vfio_pci_set_ctx_trigger_single(&vdev->req_trigger,
  509. count, flags, data);
  510. }
  511. int vfio_pci_set_irqs_ioctl(struct vfio_pci_device *vdev, uint32_t flags,
  512. unsigned index, unsigned start, unsigned count,
  513. void *data)
  514. {
  515. int (*func)(struct vfio_pci_device *vdev, unsigned index,
  516. unsigned start, unsigned count, uint32_t flags,
  517. void *data) = NULL;
  518. switch (index) {
  519. case VFIO_PCI_INTX_IRQ_INDEX:
  520. switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
  521. case VFIO_IRQ_SET_ACTION_MASK:
  522. func = vfio_pci_set_intx_mask;
  523. break;
  524. case VFIO_IRQ_SET_ACTION_UNMASK:
  525. func = vfio_pci_set_intx_unmask;
  526. break;
  527. case VFIO_IRQ_SET_ACTION_TRIGGER:
  528. func = vfio_pci_set_intx_trigger;
  529. break;
  530. }
  531. break;
  532. case VFIO_PCI_MSI_IRQ_INDEX:
  533. case VFIO_PCI_MSIX_IRQ_INDEX:
  534. switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
  535. case VFIO_IRQ_SET_ACTION_MASK:
  536. case VFIO_IRQ_SET_ACTION_UNMASK:
  537. /* XXX Need masking support exported */
  538. break;
  539. case VFIO_IRQ_SET_ACTION_TRIGGER:
  540. func = vfio_pci_set_msi_trigger;
  541. break;
  542. }
  543. break;
  544. case VFIO_PCI_ERR_IRQ_INDEX:
  545. switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
  546. case VFIO_IRQ_SET_ACTION_TRIGGER:
  547. if (pci_is_pcie(vdev->pdev))
  548. func = vfio_pci_set_err_trigger;
  549. break;
  550. }
  551. break;
  552. case VFIO_PCI_REQ_IRQ_INDEX:
  553. switch (flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {
  554. case VFIO_IRQ_SET_ACTION_TRIGGER:
  555. func = vfio_pci_set_req_trigger;
  556. break;
  557. }
  558. break;
  559. }
  560. if (!func)
  561. return -ENOTTY;
  562. return func(vdev, index, start, count, flags, data);
  563. }