1 | /* $Id: vbox_irq.c 59598 2016-02-05 14:47:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Additions Linux kernel video driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | * --------------------------------------------------------------------
|
---|
17 | *
|
---|
18 | * This code is based on
|
---|
19 | * qxl_irq.c
|
---|
20 | * with the following copyright and permission notice:
|
---|
21 | *
|
---|
22 | * Copyright 2013 Red Hat Inc.
|
---|
23 | *
|
---|
24 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
25 | * copy of this software and associated documentation files (the "Software"),
|
---|
26 | * to deal in the Software without restriction, including without limitation
|
---|
27 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
28 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
29 | * Software is furnished to do so, subject to the following conditions:
|
---|
30 | *
|
---|
31 | * The above copyright notice and this permission notice shall be included in
|
---|
32 | * all copies or substantial portions of the Software.
|
---|
33 | *
|
---|
34 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
35 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
36 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
37 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
---|
38 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
---|
39 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
---|
40 | * OTHER DEALINGS IN THE SOFTWARE.
|
---|
41 | *
|
---|
42 | * Authors: Dave Airlie
|
---|
43 | * Alon Levy
|
---|
44 | */
|
---|
45 |
|
---|
46 | #include "vbox_drv.h"
|
---|
47 |
|
---|
48 | #include <drm/drm_crtc_helper.h>
|
---|
49 |
|
---|
50 | static void vbox_clear_irq(void)
|
---|
51 | {
|
---|
52 | outl((uint32_t)~0, VGA_PORT_HGSMI_HOST);
|
---|
53 | }
|
---|
54 |
|
---|
55 | static uint32_t vbox_get_flags(struct vbox_private *vbox)
|
---|
56 | {
|
---|
57 | return (uint32_t)readl(vbox->vram + vbox->host_flags_offset);
|
---|
58 | }
|
---|
59 |
|
---|
60 | irqreturn_t vbox_irq_handler(int irq, void *arg)
|
---|
61 | {
|
---|
62 | struct drm_device *dev = (struct drm_device *) arg;
|
---|
63 | struct vbox_private *vbox = (struct vbox_private *)dev->dev_private;
|
---|
64 | uint32_t host_flags = vbox_get_flags(vbox);
|
---|
65 |
|
---|
66 | if (!(host_flags & HGSMIHOSTFLAGS_IRQ))
|
---|
67 | return IRQ_NONE;
|
---|
68 |
|
---|
69 | /* Due to a bug in the initial host implementation of hot-plug interrupts,
|
---|
70 | * the hot-plug and cursor capability flags were never cleared. Fortunately
|
---|
71 | * we can tell when they would have been set by checking that the VSYNC flag
|
---|
72 | * is not set. */
|
---|
73 | if ( host_flags & (HGSMIHOSTFLAGS_HOTPLUG | HGSMIHOSTFLAGS_CURSOR_CAPABILITIES)
|
---|
74 | && !(host_flags & HGSMIHOSTFLAGS_VSYNC))
|
---|
75 | schedule_work(&vbox->hotplug_work);
|
---|
76 | vbox_clear_irq();
|
---|
77 | return IRQ_HANDLED;
|
---|
78 | }
|
---|
79 |
|
---|
80 | static void vbox_hotplug_worker(struct work_struct *work)
|
---|
81 | {
|
---|
82 | struct vbox_private *vbox = container_of(work, struct vbox_private,
|
---|
83 | hotplug_work);
|
---|
84 |
|
---|
85 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
86 | drm_kms_helper_hotplug_event(vbox->dev);
|
---|
87 | if (vbox->fbdev)
|
---|
88 | drm_fb_helper_hotplug_event(&vbox->fbdev->helper);
|
---|
89 | }
|
---|
90 |
|
---|
91 | int vbox_irq_init(struct vbox_private *vbox)
|
---|
92 | {
|
---|
93 | int ret;
|
---|
94 |
|
---|
95 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
96 | ret = drm_irq_install(vbox->dev, vbox->dev->pdev->irq);
|
---|
97 | if (unlikely(ret != 0)) {
|
---|
98 | vbox_irq_fini(vbox);
|
---|
99 | DRM_ERROR("Failed installing irq: %d\n", ret);
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 | INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
|
---|
103 | vbox->isr_installed = true;
|
---|
104 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
105 | return 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | void vbox_irq_fini(struct vbox_private *vbox)
|
---|
109 | {
|
---|
110 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
111 | if (vbox->isr_installed) {
|
---|
112 | drm_irq_uninstall(vbox->dev);
|
---|
113 | flush_work(&vbox->hotplug_work);
|
---|
114 | vbox->isr_installed = false;
|
---|
115 | }
|
---|
116 | }
|
---|