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