1 | /* $Id: vbox_irq.c 59794 2016-02-24 09:06:26Z 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 <VBox/VBoxVideo.h>
|
---|
49 |
|
---|
50 | #include <drm/drm_crtc_helper.h>
|
---|
51 |
|
---|
52 | static void vbox_clear_irq(void)
|
---|
53 | {
|
---|
54 | outl((uint32_t)~0, VGA_PORT_HGSMI_HOST);
|
---|
55 | }
|
---|
56 |
|
---|
57 | static uint32_t vbox_get_flags(struct vbox_private *vbox)
|
---|
58 | {
|
---|
59 | return (uint32_t)readl(vbox->vram + vbox->host_flags_offset);
|
---|
60 | }
|
---|
61 |
|
---|
62 | irqreturn_t vbox_irq_handler(int irq, void *arg)
|
---|
63 | {
|
---|
64 | struct drm_device *dev = (struct drm_device *) arg;
|
---|
65 | struct vbox_private *vbox = (struct vbox_private *)dev->dev_private;
|
---|
66 | uint32_t host_flags = vbox_get_flags(vbox);
|
---|
67 |
|
---|
68 | if (!(host_flags & HGSMIHOSTFLAGS_IRQ))
|
---|
69 | return IRQ_NONE;
|
---|
70 |
|
---|
71 | /* Due to a bug in the initial host implementation of hot-plug interrupts,
|
---|
72 | * the hot-plug and cursor capability flags were never cleared. Fortunately
|
---|
73 | * we can tell when they would have been set by checking that the VSYNC flag
|
---|
74 | * is not set. */
|
---|
75 | if ( host_flags & (HGSMIHOSTFLAGS_HOTPLUG | HGSMIHOSTFLAGS_CURSOR_CAPABILITIES)
|
---|
76 | && !(host_flags & HGSMIHOSTFLAGS_VSYNC))
|
---|
77 | schedule_work(&vbox->hotplug_work);
|
---|
78 | vbox_clear_irq();
|
---|
79 | return IRQ_HANDLED;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Query the host for
|
---|
84 | */
|
---|
85 | static void vbox_update_mode_hints(struct vbox_private *vbox)
|
---|
86 | {
|
---|
87 | struct drm_device *dev = vbox->dev;
|
---|
88 | struct drm_connector *connector;
|
---|
89 | struct vbox_connector *vbox_connector;
|
---|
90 | struct VBVAMODEHINT *hints;
|
---|
91 | int rc;
|
---|
92 |
|
---|
93 | rc = VBoxHGSMIGetModeHints(&vbox->submit_info, vbox->num_crtcs,
|
---|
94 | vbox->last_mode_hints);
|
---|
95 | AssertMsgRCReturnVoid(rc, ("VBoxHGSMIGetModeHints failed, rc=%Rrc.\n", rc));
|
---|
96 | drm_modeset_lock_all(dev);
|
---|
97 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
|
---|
98 | vbox_connector = to_vbox_connector(connector);
|
---|
99 | hints = &vbox->last_mode_hints[vbox_connector->crtc_id];
|
---|
100 | if (hints->magic == VBVAMODEHINT_MAGIC) {
|
---|
101 | LogFunc(("vboxvideo: %d: crtc_id=%u, mode %hdx%hd(enabled:%d),%hdx%hd\n",
|
---|
102 | __LINE__, (unsigned)vbox_connector->crtc_id,
|
---|
103 | (short)hints->cx, (short)hints->cy, (int)hints->fEnabled,
|
---|
104 | (short)hints->dx, (short)hints->dy));
|
---|
105 | vbox_connector->mode_hint.width = hints->cx & 0x8fff;
|
---|
106 | vbox_connector->mode_hint.height = hints->cy & 0x8fff;
|
---|
107 | vbox_connector->mode_hint.disconnected = !(hints->fEnabled);
|
---|
108 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
|
---|
109 | if ((hints->dx < 0xffff) && (hints->dy < 0xffff)) {
|
---|
110 | drm_object_property_set_value(&connector->base,
|
---|
111 | dev->mode_config.suggested_x_property, hints->dx & 0x8fff);
|
---|
112 | drm_object_property_set_value(&connector->base,
|
---|
113 | dev->mode_config.suggested_y_property, hints->dy & 0x8fff);
|
---|
114 | }
|
---|
115 | #endif
|
---|
116 | }
|
---|
117 | }
|
---|
118 | drm_modeset_unlock_all(dev);
|
---|
119 | }
|
---|
120 |
|
---|
121 | static void vbox_hotplug_worker(struct work_struct *work)
|
---|
122 | {
|
---|
123 | struct vbox_private *vbox = container_of(work, struct vbox_private,
|
---|
124 | hotplug_work);
|
---|
125 |
|
---|
126 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
127 | vbox_update_mode_hints(vbox);
|
---|
128 | drm_kms_helper_hotplug_event(vbox->dev);
|
---|
129 | if (vbox->fbdev)
|
---|
130 | drm_fb_helper_hotplug_event(&vbox->fbdev->helper);
|
---|
131 | }
|
---|
132 |
|
---|
133 | int vbox_irq_init(struct vbox_private *vbox)
|
---|
134 | {
|
---|
135 | int ret;
|
---|
136 |
|
---|
137 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
138 | vbox_update_mode_hints(vbox);
|
---|
139 | ret = drm_irq_install(vbox->dev, vbox->dev->pdev->irq);
|
---|
140 | if (unlikely(ret != 0)) {
|
---|
141 | vbox_irq_fini(vbox);
|
---|
142 | DRM_ERROR("Failed installing irq: %d\n", ret);
|
---|
143 | return 1;
|
---|
144 | }
|
---|
145 | INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
|
---|
146 | vbox->isr_installed = true;
|
---|
147 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | void vbox_irq_fini(struct vbox_private *vbox)
|
---|
152 | {
|
---|
153 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
154 | if (vbox->isr_installed) {
|
---|
155 | drm_irq_uninstall(vbox->dev);
|
---|
156 | flush_work(&vbox->hotplug_work);
|
---|
157 | vbox->isr_installed = false;
|
---|
158 | }
|
---|
159 | }
|
---|