qxl_irq.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Dave Airlie
  23. * Alon Levy
  24. */
  25. #include <linux/pci.h>
  26. #include <drm/drm_drv.h>
  27. #include "qxl_drv.h"
  28. static irqreturn_t qxl_irq_handler(int irq, void *arg)
  29. {
  30. struct drm_device *dev = (struct drm_device *) arg;
  31. struct qxl_device *qdev = to_qxl(dev);
  32. uint32_t pending;
  33. pending = xchg(&qdev->ram_header->int_pending, 0);
  34. if (!pending)
  35. return IRQ_NONE;
  36. atomic_inc(&qdev->irq_received);
  37. if (pending & QXL_INTERRUPT_DISPLAY) {
  38. atomic_inc(&qdev->irq_received_display);
  39. wake_up_all(&qdev->display_event);
  40. qxl_queue_garbage_collect(qdev, false);
  41. }
  42. if (pending & QXL_INTERRUPT_CURSOR) {
  43. atomic_inc(&qdev->irq_received_cursor);
  44. wake_up_all(&qdev->cursor_event);
  45. }
  46. if (pending & QXL_INTERRUPT_IO_CMD) {
  47. atomic_inc(&qdev->irq_received_io_cmd);
  48. wake_up_all(&qdev->io_cmd_event);
  49. }
  50. if (pending & QXL_INTERRUPT_ERROR) {
  51. /* TODO: log it, reset device (only way to exit this condition)
  52. * (do it a certain number of times, afterwards admit defeat,
  53. * to avoid endless loops).
  54. */
  55. qdev->irq_received_error++;
  56. DRM_WARN("driver is in bug mode\n");
  57. }
  58. if (pending & QXL_INTERRUPT_CLIENT_MONITORS_CONFIG) {
  59. schedule_work(&qdev->client_monitors_config_work);
  60. }
  61. qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
  62. outb(0, qdev->io_base + QXL_IO_UPDATE_IRQ);
  63. return IRQ_HANDLED;
  64. }
  65. static void qxl_client_monitors_config_work_func(struct work_struct *work)
  66. {
  67. struct qxl_device *qdev = container_of(work, struct qxl_device,
  68. client_monitors_config_work);
  69. qxl_display_read_client_monitors_config(qdev);
  70. }
  71. int qxl_irq_init(struct qxl_device *qdev)
  72. {
  73. struct drm_device *ddev = &qdev->ddev;
  74. struct pci_dev *pdev = to_pci_dev(ddev->dev);
  75. int ret;
  76. init_waitqueue_head(&qdev->display_event);
  77. init_waitqueue_head(&qdev->cursor_event);
  78. init_waitqueue_head(&qdev->io_cmd_event);
  79. init_waitqueue_head(&qdev->release_event);
  80. INIT_WORK(&qdev->client_monitors_config_work,
  81. qxl_client_monitors_config_work_func);
  82. atomic_set(&qdev->irq_received, 0);
  83. atomic_set(&qdev->irq_received_display, 0);
  84. atomic_set(&qdev->irq_received_cursor, 0);
  85. atomic_set(&qdev->irq_received_io_cmd, 0);
  86. qdev->irq_received_error = 0;
  87. ret = request_irq(pdev->irq, qxl_irq_handler, IRQF_SHARED, ddev->driver->name, ddev);
  88. qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
  89. if (unlikely(ret != 0)) {
  90. DRM_ERROR("Failed installing irq: %d\n", ret);
  91. return 1;
  92. }
  93. return 0;
  94. }