VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/drm/vbox_irq.c@ 79177

Last change on this file since 79177 was 77850, checked in by vboxsync, 6 years ago

Additions/linux/vboxvideo: make driver work with Linux 5.0 and 5.1.
bugref:4567: Linux kernel driver maintenance.
This change mainly consists of adaptations of the parts of the following
kernel changes which affect staging/vboxvideo:

commit c58ac649e3553c23a9bafba8c2e5d040aee87484
Author: Cihangir Akturk <cakturk@…>
Date: Fri Aug 11 15:33:14 2017 +0300

drm: vboxvideo: switch to drm_*_get(), drm_*_put() helpers

Author: Christian König <christian.koenig@…>
Date: Fri Oct 19 13:49:05 2018 +0200

drm/ttm: use a static ttm_mem_global instance

commit a64f784bb14a56bfdfad2dc397dd67e4564e3a29
Author: Christian König <christian.koenig@…>
Date: Fri Oct 19 16:55:26 2018 +0200

drm/ttm: initialize globals during device init (v2)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: vbox_irq.c 77850 2019-03-22 14:49:18Z vboxsync $ */
2/** @file
3 * VirtualBox Additions Linux kernel video driver
4 */
5
6/*
7 * Copyright (C) 2016-2019 Oracle Corporation
8 * This file is based on qxl_irq.c
9 * Copyright 2013 Red Hat Inc.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
28 *
29 * Authors: Dave Airlie
30 * Alon Levy
31 * Michael Thayer <[email protected],
32 * Hans de Goede <[email protected]>
33 */
34#include "vbox_drv.h"
35
36#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
37#include <drm/drm_crtc_helper.h>
38#else
39#include <drm/drm_probe_helper.h>
40#endif
41#include <VBoxVideo.h>
42
43static void vbox_clear_irq(void)
44{
45 outl((u32)~0, VGA_PORT_HGSMI_HOST);
46}
47
48static u32 vbox_get_flags(struct vbox_private *vbox)
49{
50 return readl(vbox->guest_heap + HOST_FLAGS_OFFSET);
51}
52
53void vbox_report_hotplug(struct vbox_private *vbox)
54{
55 schedule_work(&vbox->hotplug_work);
56}
57
58irqreturn_t vbox_irq_handler(int irq, void *arg)
59{
60 struct drm_device *dev = (struct drm_device *)arg;
61 struct vbox_private *vbox = (struct vbox_private *)dev->dev_private;
62 u32 host_flags = vbox_get_flags(vbox);
63
64 if (!(host_flags & HGSMIHOSTFLAGS_IRQ))
65 return IRQ_NONE;
66
67 /*
68 * Due to a bug in the initial host implementation of hot-plug irqs,
69 * the hot-plug and cursor capability flags were never cleared.
70 * Fortunately we can tell when they would have been set by checking
71 * that the VSYNC flag is not set.
72 */
73 if (host_flags &
74 (HGSMIHOSTFLAGS_HOTPLUG | HGSMIHOSTFLAGS_CURSOR_CAPABILITIES) &&
75 !(host_flags & HGSMIHOSTFLAGS_VSYNC))
76 vbox_report_hotplug(vbox);
77
78 vbox_clear_irq();
79
80 return IRQ_HANDLED;
81}
82
83/**
84 * Check that the position hints provided by the host are suitable for GNOME
85 * shell (i.e. all screens disjoint and hints for all enabled screens) and if
86 * not replace them with default ones. Providing valid hints improves the
87 * chances that we will get a known screen layout for pointer mapping.
88 */
89static void validate_or_set_position_hints(struct vbox_private *vbox)
90{
91 struct VBVAMODEHINT *hintsi, *hintsj;
92 bool valid = true;
93 u16 currentx = 0;
94 int i, j;
95
96 for (i = 0; i < vbox->num_crtcs; ++i) {
97 for (j = 0; j < i; ++j) {
98 hintsi = &vbox->last_mode_hints[i];
99 hintsj = &vbox->last_mode_hints[j];
100
101 if (hintsi->fEnabled && hintsj->fEnabled) {
102 if (hintsi->dx >= 0xffff ||
103 hintsi->dy >= 0xffff ||
104 hintsj->dx >= 0xffff ||
105 hintsj->dy >= 0xffff ||
106 (hintsi->dx <
107 hintsj->dx + (hintsj->cx & 0x8fff) &&
108 hintsi->dx + (hintsi->cx & 0x8fff) >
109 hintsj->dx) ||
110 (hintsi->dy <
111 hintsj->dy + (hintsj->cy & 0x8fff) &&
112 hintsi->dy + (hintsi->cy & 0x8fff) >
113 hintsj->dy))
114 valid = false;
115 }
116 }
117 }
118 if (!valid)
119 for (i = 0; i < vbox->num_crtcs; ++i) {
120 if (vbox->last_mode_hints[i].fEnabled) {
121 vbox->last_mode_hints[i].dx = currentx;
122 vbox->last_mode_hints[i].dy = 0;
123 currentx +=
124 vbox->last_mode_hints[i].cx & 0x8fff;
125 }
126 }
127}
128
129/**
130 * Query the host for the most recent video mode hints.
131 */
132static void vbox_update_mode_hints(struct vbox_private *vbox)
133{
134 struct drm_device *dev = vbox->dev;
135 struct drm_connector *connector;
136 struct vbox_connector *vbox_conn;
137 struct VBVAMODEHINT *hints;
138 u16 flags;
139 bool disconnected;
140 unsigned int crtc_id;
141 int ret;
142
143 ret = VBoxHGSMIGetModeHints(vbox->guest_pool, vbox->num_crtcs,
144 vbox->last_mode_hints);
145 if (ret) {
146 DRM_ERROR("vboxvideo: hgsmi_get_mode_hints failed: %d\n", ret);
147 return;
148 }
149
150 validate_or_set_position_hints(vbox);
151#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
152 drm_modeset_lock_all(dev);
153#else
154 mutex_lock(&dev->mode_config.mutex);
155#endif
156 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
157 vbox_conn = to_vbox_connector(connector);
158
159 hints = &vbox->last_mode_hints[vbox_conn->vbox_crtc->crtc_id];
160 if (hints->magic != VBVAMODEHINT_MAGIC)
161 continue;
162
163 disconnected = !(hints->fEnabled);
164 crtc_id = vbox_conn->vbox_crtc->crtc_id;
165 vbox_conn->mode_hint.width = hints->cx;
166 vbox_conn->mode_hint.height = hints->cy;
167 vbox_conn->vbox_crtc->x_hint = hints->dx;
168 vbox_conn->vbox_crtc->y_hint = hints->dy;
169 vbox_conn->mode_hint.disconnected = disconnected;
170
171 if (vbox_conn->vbox_crtc->disconnected == disconnected)
172 continue;
173
174 if (disconnected)
175 flags = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_DISABLED;
176 else
177 flags = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_BLANK;
178
179 VBoxHGSMIProcessDisplayInfo(vbox->guest_pool, crtc_id, 0, 0, 0,
180 hints->cx * 4, hints->cx,
181 hints->cy, 0, flags);
182
183 vbox_conn->vbox_crtc->disconnected = disconnected;
184 }
185#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
186 drm_modeset_unlock_all(dev);
187#else
188 mutex_unlock(&dev->mode_config.mutex);
189#endif
190}
191
192static void vbox_hotplug_worker(struct work_struct *work)
193{
194 struct vbox_private *vbox = container_of(work, struct vbox_private,
195 hotplug_work);
196
197 vbox_update_mode_hints(vbox);
198 drm_kms_helper_hotplug_event(vbox->dev);
199}
200
201int vbox_irq_init(struct vbox_private *vbox)
202{
203 INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
204 vbox_update_mode_hints(vbox);
205#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0) || defined(RHEL_71)
206 return drm_irq_install(vbox->dev, vbox->dev->pdev->irq);
207#else
208 return drm_irq_install(vbox->dev);
209#endif
210}
211
212void vbox_irq_fini(struct vbox_private *vbox)
213{
214 drm_irq_uninstall(vbox->dev);
215 flush_work(&vbox->hotplug_work);
216}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette