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