Home | History | Annotate | Line # | Download | only in qxl
qxl_irq.c revision 1.1.1.1.32.1
      1 /*	$NetBSD: qxl_irq.c,v 1.1.1.1.32.1 2019/06/10 22:08:24 christos 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.1.1.1.32.1 2019/06/10 22:08:24 christos Exp $");
     30 
     31 #include "qxl_drv.h"
     32 
     33 irqreturn_t qxl_irq_handler(int irq, void *arg)
     34 {
     35 	struct drm_device *dev = (struct drm_device *) arg;
     36 	struct qxl_device *qdev = (struct qxl_device *)dev->dev_private;
     37 	uint32_t pending;
     38 
     39 	pending = xchg(&qdev->ram_header->int_pending, 0);
     40 
     41 	if (!pending)
     42 		return IRQ_NONE;
     43 
     44 	atomic_inc(&qdev->irq_received);
     45 
     46 	if (pending & QXL_INTERRUPT_DISPLAY) {
     47 		atomic_inc(&qdev->irq_received_display);
     48 		wake_up_all(&qdev->display_event);
     49 		qxl_queue_garbage_collect(qdev, false);
     50 	}
     51 	if (pending & QXL_INTERRUPT_CURSOR) {
     52 		atomic_inc(&qdev->irq_received_cursor);
     53 		wake_up_all(&qdev->cursor_event);
     54 	}
     55 	if (pending & QXL_INTERRUPT_IO_CMD) {
     56 		atomic_inc(&qdev->irq_received_io_cmd);
     57 		wake_up_all(&qdev->io_cmd_event);
     58 	}
     59 	if (pending & QXL_INTERRUPT_ERROR) {
     60 		/* TODO: log it, reset device (only way to exit this condition)
     61 		 * (do it a certain number of times, afterwards admit defeat,
     62 		 * to avoid endless loops).
     63 		 */
     64 		qdev->irq_received_error++;
     65 		qxl_io_log(qdev, "%s: driver is in bug mode.\n", __func__);
     66 	}
     67 	if (pending & QXL_INTERRUPT_CLIENT_MONITORS_CONFIG) {
     68 		qxl_io_log(qdev, "QXL_INTERRUPT_CLIENT_MONITORS_CONFIG\n");
     69 		schedule_work(&qdev->client_monitors_config_work);
     70 	}
     71 	qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
     72 	outb(0, qdev->io_base + QXL_IO_UPDATE_IRQ);
     73 	return IRQ_HANDLED;
     74 }
     75 
     76 static void qxl_client_monitors_config_work_func(struct work_struct *work)
     77 {
     78 	struct qxl_device *qdev = container_of(work, struct qxl_device,
     79 					       client_monitors_config_work);
     80 
     81 	qxl_display_read_client_monitors_config(qdev);
     82 }
     83 
     84 int qxl_irq_init(struct qxl_device *qdev)
     85 {
     86 	int ret;
     87 
     88 	init_waitqueue_head(&qdev->display_event);
     89 	init_waitqueue_head(&qdev->cursor_event);
     90 	init_waitqueue_head(&qdev->io_cmd_event);
     91 	INIT_WORK(&qdev->client_monitors_config_work,
     92 		  qxl_client_monitors_config_work_func);
     93 	atomic_set(&qdev->irq_received, 0);
     94 	atomic_set(&qdev->irq_received_display, 0);
     95 	atomic_set(&qdev->irq_received_cursor, 0);
     96 	atomic_set(&qdev->irq_received_io_cmd, 0);
     97 	qdev->irq_received_error = 0;
     98 #ifdef __NetBSD__
     99 	ret = drm_irq_install(qdev->ddev);
    100 #else
    101 	ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
    102 #endif
    103 	qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
    104 	if (unlikely(ret != 0)) {
    105 		DRM_ERROR("Failed installing irq: %d\n", ret);
    106 		return 1;
    107 	}
    108 	return 0;
    109 }
    110