VirtualBox

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

最後變更 在這個檔案從91233是 91233,由 vboxsync 提交於 3 年 前

Additions: Linux: vboxvideo: introduce initial support for kernel 5.15, bugref:10104.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 6.5 KB
 
1/* $Id: vbox_irq.c 91233 2021-09-14 12:14:49Z vboxsync $ */
2/** @file
3 * VirtualBox Additions Linux kernel video driver
4 */
5
6/*
7 * Copyright (C) 2016-2020 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 RTLNX_VER_MAX(5,1,0)
37# include <drm/drm_crtc_helper.h>
38# if RTLNX_RHEL_MAJ_PREREQ(8,1)
39# include <drm/drm_probe_helper.h>
40# endif
41#else
42# include <drm/drm_probe_helper.h>
43#endif
44#include <VBoxVideo.h>
45
46static void vbox_clear_irq(void)
47{
48 outl((u32)~0, VGA_PORT_HGSMI_HOST);
49}
50
51static u32 vbox_get_flags(struct vbox_private *vbox)
52{
53 return readl(vbox->guest_heap + HOST_FLAGS_OFFSET);
54}
55
56void vbox_report_hotplug(struct vbox_private *vbox)
57{
58 schedule_work(&vbox->hotplug_work);
59}
60
61irqreturn_t vbox_irq_handler(int irq, void *arg)
62{
63 struct drm_device *dev = (struct drm_device *)arg;
64 struct vbox_private *vbox = (struct vbox_private *)dev->dev_private;
65 u32 host_flags = vbox_get_flags(vbox);
66
67 if (!(host_flags & HGSMIHOSTFLAGS_IRQ))
68 return IRQ_NONE;
69
70 /*
71 * Due to a bug in the initial host implementation of hot-plug irqs,
72 * the hot-plug and cursor capability flags were never cleared.
73 * Fortunately we can tell when they would have been set by checking
74 * that the VSYNC flag is not set.
75 */
76 if (host_flags &
77 (HGSMIHOSTFLAGS_HOTPLUG | HGSMIHOSTFLAGS_CURSOR_CAPABILITIES) &&
78 !(host_flags & HGSMIHOSTFLAGS_VSYNC))
79 vbox_report_hotplug(vbox);
80
81 vbox_clear_irq();
82
83 return IRQ_HANDLED;
84}
85
86/**
87 * Check that the position hints provided by the host are suitable for GNOME
88 * shell (i.e. all screens disjoint and hints for all enabled screens) and if
89 * not replace them with default ones. Providing valid hints improves the
90 * chances that we will get a known screen layout for pointer mapping.
91 */
92static void validate_or_set_position_hints(struct vbox_private *vbox)
93{
94 struct VBVAMODEHINT *hintsi, *hintsj;
95 bool valid = true;
96 u16 currentx = 0;
97 int i, j;
98
99 for (i = 0; i < vbox->num_crtcs; ++i) {
100 for (j = 0; j < i; ++j) {
101 hintsi = &vbox->last_mode_hints[i];
102 hintsj = &vbox->last_mode_hints[j];
103
104 if (hintsi->fEnabled && hintsj->fEnabled) {
105 if (hintsi->dx >= 0xffff ||
106 hintsi->dy >= 0xffff ||
107 hintsj->dx >= 0xffff ||
108 hintsj->dy >= 0xffff ||
109 (hintsi->dx <
110 hintsj->dx + (hintsj->cx & 0x8fff) &&
111 hintsi->dx + (hintsi->cx & 0x8fff) >
112 hintsj->dx) ||
113 (hintsi->dy <
114 hintsj->dy + (hintsj->cy & 0x8fff) &&
115 hintsi->dy + (hintsi->cy & 0x8fff) >
116 hintsj->dy))
117 valid = false;
118 }
119 }
120 }
121 if (!valid)
122 for (i = 0; i < vbox->num_crtcs; ++i) {
123 if (vbox->last_mode_hints[i].fEnabled) {
124 vbox->last_mode_hints[i].dx = currentx;
125 vbox->last_mode_hints[i].dy = 0;
126 currentx +=
127 vbox->last_mode_hints[i].cx & 0x8fff;
128 }
129 }
130}
131
132/**
133 * Query the host for the most recent video mode hints.
134 */
135static void vbox_update_mode_hints(struct vbox_private *vbox)
136{
137 struct drm_device *dev = vbox->dev;
138 struct drm_connector *connector;
139 struct vbox_connector *vbox_conn;
140 struct VBVAMODEHINT *hints;
141 u16 flags;
142 bool disconnected;
143 unsigned int crtc_id;
144 int ret;
145
146 ret = VBoxHGSMIGetModeHints(vbox->guest_pool, vbox->num_crtcs,
147 vbox->last_mode_hints);
148 if (ret) {
149 DRM_ERROR("vboxvideo: hgsmi_get_mode_hints failed: %d\n", ret);
150 return;
151 }
152
153 validate_or_set_position_hints(vbox);
154#if RTLNX_VER_MIN(3,9,0)
155 drm_modeset_lock_all(dev);
156#else
157 mutex_lock(&dev->mode_config.mutex);
158#endif
159 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
160 vbox_conn = to_vbox_connector(connector);
161
162 hints = &vbox->last_mode_hints[vbox_conn->vbox_crtc->crtc_id];
163 if (hints->magic != VBVAMODEHINT_MAGIC)
164 continue;
165
166 disconnected = !(hints->fEnabled);
167 crtc_id = vbox_conn->vbox_crtc->crtc_id;
168 vbox_conn->mode_hint.width = hints->cx;
169 vbox_conn->mode_hint.height = hints->cy;
170 vbox_conn->vbox_crtc->x_hint = hints->dx;
171 vbox_conn->vbox_crtc->y_hint = hints->dy;
172 vbox_conn->mode_hint.disconnected = disconnected;
173
174 if (vbox_conn->vbox_crtc->disconnected == disconnected)
175 continue;
176
177 if (disconnected)
178 flags = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_DISABLED;
179 else
180 flags = VBVA_SCREEN_F_ACTIVE | VBVA_SCREEN_F_BLANK;
181
182 VBoxHGSMIProcessDisplayInfo(vbox->guest_pool, crtc_id, 0, 0, 0,
183 hints->cx * 4, hints->cx,
184 hints->cy, 0, flags);
185
186 vbox_conn->vbox_crtc->disconnected = disconnected;
187 }
188#if RTLNX_VER_MIN(3,9,0)
189 drm_modeset_unlock_all(dev);
190#else
191 mutex_unlock(&dev->mode_config.mutex);
192#endif
193}
194
195static void vbox_hotplug_worker(struct work_struct *work)
196{
197 struct vbox_private *vbox = container_of(work, struct vbox_private,
198 hotplug_work);
199
200 vbox_update_mode_hints(vbox);
201 drm_kms_helper_hotplug_event(vbox->dev);
202}
203
204int vbox_irq_init(struct vbox_private *vbox)
205{
206 INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
207 vbox_update_mode_hints(vbox);
208#if RTLNX_VER_MIN(5,15,0)
209 return request_irq(VBOX_DRM_TO_PCI_DEV(vbox->dev)->irq, vbox_irq_handler, IRQF_SHARED, vbox->dev->driver->name, vbox->dev);
210#elif RTLNX_VER_MIN(3,16,0) || RTLNX_RHEL_MAJ_PREREQ(7,1)
211 return drm_irq_install(vbox->dev, VBOX_DRM_TO_PCI_DEV(vbox->dev)->irq);
212#else
213 return drm_irq_install(vbox->dev);
214#endif
215}
216
217void vbox_irq_fini(struct vbox_private *vbox)
218{
219#if RTLNX_VER_MIN(5,15,0)
220 free_irq(VBOX_DRM_TO_PCI_DEV(vbox->dev)->irq, vbox->dev);
221#else
222 drm_irq_uninstall(vbox->dev);
223#endif
224 flush_work(&vbox->hotplug_work);
225}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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