VirtualBox

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

Last change on this file since 60284 was 60085, checked in by vboxsync, 9 years ago

bugref:8087: Additions/x11: support non-root X server: fix disabling of virtual screens from the host in the kernel graphics driver.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: vbox_irq.c 60085 2016-03-17 19:06:05Z 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
52static void vbox_clear_irq(void)
53{
54 outl((uint32_t)~0, VGA_PORT_HGSMI_HOST);
55}
56
57static uint32_t vbox_get_flags(struct vbox_private *vbox)
58{
59 return (uint32_t)readl(vbox->vram + vbox->host_flags_offset);
60}
61
62irqreturn_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 */
85static 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 uint16_t flags;
92 bool disconnected;
93 unsigned crtc_id;
94 int rc;
95
96 rc = VBoxHGSMIGetModeHints(&vbox->submit_info, vbox->num_crtcs,
97 vbox->last_mode_hints);
98 AssertMsgRCReturnVoid(rc, ("VBoxHGSMIGetModeHints failed, rc=%Rrc.\n", rc));
99#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
100 drm_modeset_lock_all(dev);
101#else
102 mutex_lock(&dev->mode_config.mutex);
103#endif
104 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
105 vbox_connector = to_vbox_connector(connector);
106 hints = &vbox->last_mode_hints[vbox_connector->vbox_crtc->crtc_id];
107 if (hints->magic == VBVAMODEHINT_MAGIC) {
108 LogFunc(("vboxvideo: %d: crtc_id=%u, mode %hdx%hd(enabled:%d),%hdx%hd\n",
109 __LINE__, (unsigned)vbox_connector->vbox_crtc->crtc_id,
110 (short)hints->cx, (short)hints->cy, (int)hints->fEnabled,
111 (short)hints->dx, (short)hints->dy));
112 disconnected = !(hints->fEnabled);
113 crtc_id = vbox_connector->vbox_crtc->crtc_id;
114 flags = VBVA_SCREEN_F_ACTIVE
115 | (disconnected ? VBVA_SCREEN_F_DISABLED : VBVA_SCREEN_F_BLANK);
116 vbox_connector->mode_hint.width = hints->cx & 0x8fff;
117 vbox_connector->mode_hint.height = hints->cy & 0x8fff;
118 vbox_connector->mode_hint.disconnected = disconnected;
119 if (vbox_connector->vbox_crtc->disconnected != disconnected) {
120 VBoxHGSMIProcessDisplayInfo(&vbox->submit_info, crtc_id,
121 0, 0, 0, hints->cx * 4, hints->cx,
122 hints->cy, 0, flags);
123 vbox_connector->vbox_crtc->disconnected = disconnected;
124 }
125#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
126 if ((hints->dx < 0xffff) && (hints->dy < 0xffff)) {
127 drm_object_property_set_value(&connector->base,
128 dev->mode_config.suggested_x_property, hints->dx & 0x8fff);
129 drm_object_property_set_value(&connector->base,
130 dev->mode_config.suggested_y_property, hints->dy & 0x8fff);
131 }
132#endif
133 }
134 }
135#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
136 drm_modeset_unlock_all(dev);
137#else
138 mutex_unlock(&dev->mode_config.mutex);
139#endif
140}
141
142static void vbox_hotplug_worker(struct work_struct *work)
143{
144 struct vbox_private *vbox = container_of(work, struct vbox_private,
145 hotplug_work);
146
147 LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
148 vbox_update_mode_hints(vbox);
149 drm_kms_helper_hotplug_event(vbox->dev);
150 if (vbox->fbdev)
151 drm_fb_helper_hotplug_event(&vbox->fbdev->helper);
152}
153
154int vbox_irq_init(struct vbox_private *vbox)
155{
156 int ret;
157
158 LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
159 vbox_update_mode_hints(vbox);
160#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0)
161 ret = drm_irq_install(vbox->dev, vbox->dev->pdev->irq);
162#else
163 ret = drm_irq_install(vbox->dev);
164#endif
165 if (unlikely(ret != 0)) {
166 vbox_irq_fini(vbox);
167 DRM_ERROR("Failed installing irq: %d\n", ret);
168 return 1;
169 }
170 INIT_WORK(&vbox->hotplug_work, vbox_hotplug_worker);
171 vbox->isr_installed = true;
172 LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
173 return 0;
174}
175
176void vbox_irq_fini(struct vbox_private *vbox)
177{
178 LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
179 if (vbox->isr_installed) {
180 drm_irq_uninstall(vbox->dev);
181 flush_work(&vbox->hotplug_work);
182 vbox->isr_installed = false;
183 }
184}
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