1 | /* $Id: vbox_mode.c 59526 2016-01-31 09:31:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Additions Linux kernel video driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013 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 | * ast_mode.c
|
---|
20 | * with the following copyright and permission notice:
|
---|
21 | *
|
---|
22 | * Copyright 2012 Red Hat Inc.
|
---|
23 | * Parts based on xf86-video-ast
|
---|
24 | * Copyright (c) 2005 ASPEED Technology Inc.
|
---|
25 | *
|
---|
26 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
27 | * copy of this software and associated documentation files (the
|
---|
28 | * "Software"), to deal in the Software without restriction, including
|
---|
29 | * without limitation the rights to use, copy, modify, merge, publish,
|
---|
30 | * distribute, sub license, and/or sell copies of the Software, and to
|
---|
31 | * permit persons to whom the Software is furnished to do so, subject to
|
---|
32 | * the following conditions:
|
---|
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 NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
37 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
---|
38 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
---|
39 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
---|
40 | * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
41 | *
|
---|
42 | * The above copyright notice and this permission notice (including the
|
---|
43 | * next paragraph) shall be included in all copies or substantial portions
|
---|
44 | * of the Software.
|
---|
45 | *
|
---|
46 | */
|
---|
47 | /*
|
---|
48 | * Authors: Dave Airlie <[email protected]>
|
---|
49 | */
|
---|
50 | #include "vbox_drv.h"
|
---|
51 |
|
---|
52 | #include <VBox/VBoxVideo.h>
|
---|
53 |
|
---|
54 | #include <linux/export.h>
|
---|
55 | #include <drm/drm_crtc_helper.h>
|
---|
56 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
|
---|
57 | # include <drm/drm_plane_helper.h>
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
|
---|
61 | uint32_t handle, uint32_t width, uint32_t height,
|
---|
62 | int32_t hot_x, int32_t hot_y);
|
---|
63 | static int vbox_cursor_move(struct drm_crtc *crtc, int x, int y);
|
---|
64 |
|
---|
65 | /** Set a graphics mode. Poke any required values into registers, do an HGSMI
|
---|
66 | * mode set and tell the host we support advanced graphics functions.
|
---|
67 | */
|
---|
68 | static void vbox_do_modeset(struct drm_crtc *crtc,
|
---|
69 | const struct drm_display_mode *mode)
|
---|
70 | {
|
---|
71 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
72 | struct vbox_private *vbox;
|
---|
73 | int width, height, cBPP, pitch;
|
---|
74 | unsigned iCrtc;
|
---|
75 | uint16_t fFlags;
|
---|
76 |
|
---|
77 | LogFunc(("vboxvideo: %d: vbox_crtc=%p, CRTC_FB(crtc)=%p\n", __LINE__,
|
---|
78 | vbox_crtc, CRTC_FB(crtc)));
|
---|
79 | vbox = crtc->dev->dev_private;
|
---|
80 | width = mode->hdisplay ? mode->hdisplay : 640;
|
---|
81 | height = mode->vdisplay ? mode->vdisplay : 480;
|
---|
82 | iCrtc = vbox_crtc->crtc_id;
|
---|
83 | cBPP = crtc->enabled ? CRTC_FB(crtc)->bits_per_pixel : 32;
|
---|
84 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
---|
85 | pitch = crtc->enabled ? CRTC_FB(crtc)->pitch : width * cBPP / 8;
|
---|
86 | #else
|
---|
87 | pitch = crtc->enabled ? CRTC_FB(crtc)->pitches[0] : width * cBPP / 8;
|
---|
88 | #endif
|
---|
89 | /* if (vbox_crtc->crtc_id == 0 && crtc->enabled)
|
---|
90 | VBoxVideoSetModeRegisters(width, height, pitch * 8 / cBPP,
|
---|
91 | CRTC_FB(crtc)->bits_per_pixel, 0,
|
---|
92 | crtc->x, crtc->y); */
|
---|
93 | fFlags = VBVA_SCREEN_F_ACTIVE;
|
---|
94 | fFlags |= (crtc->enabled ? 0 : VBVA_SCREEN_F_DISABLED);
|
---|
95 | VBoxHGSMIProcessDisplayInfo(&vbox->Ctx, vbox_crtc->crtc_id,
|
---|
96 | crtc->x, crtc->y,
|
---|
97 | crtc->x * cBPP / 8 + crtc->y * pitch,
|
---|
98 | pitch, width, height,
|
---|
99 | vbox_crtc->fBlanked ? 0 : cBPP, fFlags);
|
---|
100 | VBoxHGSMIReportFlagsLocation(&vbox->Ctx, vbox->offHostFlags);
|
---|
101 | VBoxHGSMISendCapsInfo(&vbox->Ctx, VBVACAPS_VIDEO_MODE_HINTS | VBVACAPS_DISABLE_CURSOR_INTEGRATION);
|
---|
102 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
103 | }
|
---|
104 |
|
---|
105 | static int vbox_set_view(struct drm_crtc *crtc)
|
---|
106 | {
|
---|
107 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
108 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
109 | void *p;
|
---|
110 |
|
---|
111 | LogFunc(("vboxvideo: %d: vbox_crtc=%p\n", __LINE__, vbox_crtc));
|
---|
112 | /* Tell the host about the view. This design originally targeted the
|
---|
113 | * Windows XP driver architecture and assumed that each screen would have
|
---|
114 | * a dedicated frame buffer with the command buffer following it, the whole
|
---|
115 | * being a "view". The host works out which screen a command buffer belongs
|
---|
116 | * to by checking whether it is in the first view, then whether it is in the
|
---|
117 | * second and so on. The first match wins. We cheat around this by making
|
---|
118 | * the first view be the managed memory plus the first command buffer, the
|
---|
119 | * second the same plus the second buffer and so on. */
|
---|
120 | p = VBoxHGSMIBufferAlloc(&vbox->Ctx, sizeof(VBVAINFOVIEW), HGSMI_CH_VBVA,
|
---|
121 | VBVA_INFO_VIEW);
|
---|
122 | if (p)
|
---|
123 | {
|
---|
124 | VBVAINFOVIEW *pInfo = (VBVAINFOVIEW *)p;
|
---|
125 | pInfo->u32ViewIndex = vbox_crtc->crtc_id;
|
---|
126 | pInfo->u32ViewOffset = vbox_crtc->offFB;
|
---|
127 | pInfo->u32ViewSize = vbox->vram_size - vbox_crtc->offFB
|
---|
128 | + vbox_crtc->crtc_id * VBVA_MIN_BUFFER_SIZE;
|
---|
129 | pInfo->u32MaxScreenSize = vbox->vram_size - vbox_crtc->offFB;
|
---|
130 | VBoxHGSMIBufferSubmit(&vbox->Ctx, p);
|
---|
131 | VBoxHGSMIBufferFree(&vbox->Ctx, p);
|
---|
132 | }
|
---|
133 | else
|
---|
134 | return -ENOMEM;
|
---|
135 | LogFunc(("vboxvideo: %d: p=%p\n", __LINE__, p));
|
---|
136 | return 0;
|
---|
137 | }
|
---|
138 |
|
---|
139 | static void vbox_crtc_load_lut(struct drm_crtc *crtc)
|
---|
140 | {
|
---|
141 |
|
---|
142 | }
|
---|
143 |
|
---|
144 | static void vbox_crtc_dpms(struct drm_crtc *crtc, int mode)
|
---|
145 | {
|
---|
146 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
147 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
148 | unsigned long flags;
|
---|
149 |
|
---|
150 | LogFunc(("vboxvideo: %d: vbox_crtc=%p, mode=%d\n", __LINE__, vbox_crtc,
|
---|
151 | mode));
|
---|
152 | switch (mode) {
|
---|
153 | case DRM_MODE_DPMS_ON:
|
---|
154 | vbox_crtc->fBlanked = false;
|
---|
155 | break;
|
---|
156 | case DRM_MODE_DPMS_STANDBY:
|
---|
157 | case DRM_MODE_DPMS_SUSPEND:
|
---|
158 | case DRM_MODE_DPMS_OFF:
|
---|
159 | vbox_crtc->fBlanked = true;
|
---|
160 | break;
|
---|
161 | }
|
---|
162 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
163 | vbox_do_modeset(crtc, &crtc->hwmode);
|
---|
164 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
165 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
166 | }
|
---|
167 |
|
---|
168 | static bool vbox_crtc_mode_fixup(struct drm_crtc *crtc,
|
---|
169 | const struct drm_display_mode *mode,
|
---|
170 | struct drm_display_mode *adjusted_mode)
|
---|
171 | {
|
---|
172 | return true;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /* We move buffers which are not in active use out of VRAM to save memory. */
|
---|
176 | static int vbox_crtc_do_set_base(struct drm_crtc *crtc,
|
---|
177 | struct drm_framebuffer *fb,
|
---|
178 | int x, int y, int atomic)
|
---|
179 | {
|
---|
180 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
181 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
182 | struct drm_gem_object *obj;
|
---|
183 | struct vbox_framebuffer *vbox_fb;
|
---|
184 | struct vbox_bo *bo;
|
---|
185 | int ret;
|
---|
186 | u64 gpu_addr;
|
---|
187 |
|
---|
188 | LogFunc(("vboxvideo: %d: fb=%p, vbox_crtc=%p\n", __LINE__, fb, vbox_crtc));
|
---|
189 | /* push the previous fb to system ram */
|
---|
190 | if (!atomic && fb) {
|
---|
191 | vbox_fb = to_vbox_framebuffer(fb);
|
---|
192 | obj = vbox_fb->obj;
|
---|
193 | bo = gem_to_vbox_bo(obj);
|
---|
194 | ret = vbox_bo_reserve(bo, false);
|
---|
195 | if (ret)
|
---|
196 | return ret;
|
---|
197 | vbox_bo_push_sysram(bo);
|
---|
198 | vbox_bo_unreserve(bo);
|
---|
199 | }
|
---|
200 |
|
---|
201 | vbox_fb = to_vbox_framebuffer(CRTC_FB(crtc));
|
---|
202 | obj = vbox_fb->obj;
|
---|
203 | bo = gem_to_vbox_bo(obj);
|
---|
204 |
|
---|
205 | ret = vbox_bo_reserve(bo, false);
|
---|
206 | if (ret)
|
---|
207 | return ret;
|
---|
208 |
|
---|
209 | ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
|
---|
210 | if (ret) {
|
---|
211 | vbox_bo_unreserve(bo);
|
---|
212 | return ret;
|
---|
213 | }
|
---|
214 |
|
---|
215 | if (&vbox->fbdev->afb == vbox_fb) {
|
---|
216 | /* if pushing console in kmap it */
|
---|
217 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
|
---|
218 | if (ret)
|
---|
219 | DRM_ERROR("failed to kmap fbcon\n");
|
---|
220 | }
|
---|
221 | vbox_bo_unreserve(bo);
|
---|
222 |
|
---|
223 | /* vbox_set_start_address_crt1(crtc, (u32)gpu_addr); */
|
---|
224 | vbox_crtc->offFB = gpu_addr;
|
---|
225 |
|
---|
226 | LogFunc(("vboxvideo: %d: vbox_fb=%p, obj=%p, bo=%p, gpu_addr=%u\n",
|
---|
227 | __LINE__, vbox_fb, obj, bo, (unsigned)gpu_addr));
|
---|
228 | return 0;
|
---|
229 | }
|
---|
230 |
|
---|
231 | static int vbox_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
|
---|
232 | struct drm_framebuffer *old_fb)
|
---|
233 | {
|
---|
234 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
235 | return vbox_crtc_do_set_base(crtc, old_fb, x, y, 0);
|
---|
236 | }
|
---|
237 |
|
---|
238 | static int vbox_crtc_mode_set(struct drm_crtc *crtc,
|
---|
239 | struct drm_display_mode *mode,
|
---|
240 | struct drm_display_mode *adjusted_mode,
|
---|
241 | int x, int y,
|
---|
242 | struct drm_framebuffer *old_fb)
|
---|
243 | {
|
---|
244 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
245 | unsigned long flags;
|
---|
246 | int rc = 0;
|
---|
247 |
|
---|
248 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
249 | vbox_crtc_mode_set_base(crtc, x, y, old_fb);
|
---|
250 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
251 | rc = vbox_set_view(crtc);
|
---|
252 | if (!rc)
|
---|
253 | vbox_do_modeset(crtc, mode);
|
---|
254 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
255 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
256 | return rc;
|
---|
257 | }
|
---|
258 |
|
---|
259 | static void vbox_crtc_disable(struct drm_crtc *crtc)
|
---|
260 | {
|
---|
261 |
|
---|
262 | }
|
---|
263 |
|
---|
264 | static void vbox_crtc_prepare(struct drm_crtc *crtc)
|
---|
265 | {
|
---|
266 |
|
---|
267 | }
|
---|
268 |
|
---|
269 | static void vbox_crtc_commit(struct drm_crtc *crtc)
|
---|
270 | {
|
---|
271 |
|
---|
272 | }
|
---|
273 |
|
---|
274 |
|
---|
275 | static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs = {
|
---|
276 | .dpms = vbox_crtc_dpms,
|
---|
277 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
278 | .mode_set = vbox_crtc_mode_set,
|
---|
279 | /* .mode_set_base = vbox_crtc_mode_set_base, */
|
---|
280 | .disable = vbox_crtc_disable,
|
---|
281 | .load_lut = vbox_crtc_load_lut,
|
---|
282 | .prepare = vbox_crtc_prepare,
|
---|
283 | .commit = vbox_crtc_commit,
|
---|
284 |
|
---|
285 | };
|
---|
286 |
|
---|
287 | static void vbox_crtc_reset(struct drm_crtc *crtc)
|
---|
288 | {
|
---|
289 |
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 | static void vbox_crtc_destroy(struct drm_crtc *crtc)
|
---|
294 | {
|
---|
295 | drm_crtc_cleanup(crtc);
|
---|
296 | kfree(crtc);
|
---|
297 | }
|
---|
298 |
|
---|
299 | static const struct drm_crtc_funcs vbox_crtc_funcs = {
|
---|
300 | .cursor_move = vbox_cursor_move,
|
---|
301 | #ifdef DRM_IOCTL_MODE_CURSOR2
|
---|
302 | .cursor_set2 = vbox_cursor_set2,
|
---|
303 | #endif
|
---|
304 | .reset = vbox_crtc_reset,
|
---|
305 | .set_config = drm_crtc_helper_set_config,
|
---|
306 | /* .gamma_set = vbox_crtc_gamma_set, */
|
---|
307 | .destroy = vbox_crtc_destroy,
|
---|
308 | };
|
---|
309 |
|
---|
310 | static int vbox_crtc_init(struct drm_device *dev, unsigned i)
|
---|
311 | {
|
---|
312 | struct vbox_crtc *crtc;
|
---|
313 |
|
---|
314 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
315 | crtc = kzalloc(sizeof(struct vbox_crtc), GFP_KERNEL);
|
---|
316 | if (!crtc)
|
---|
317 | return -ENOMEM;
|
---|
318 | crtc->crtc_id = i;
|
---|
319 |
|
---|
320 | drm_crtc_init(dev, &crtc->base, &vbox_crtc_funcs);
|
---|
321 | drm_mode_crtc_set_gamma_size(&crtc->base, 256);
|
---|
322 | drm_crtc_helper_add(&crtc->base, &vbox_crtc_helper_funcs);
|
---|
323 | LogFunc(("vboxvideo: %d: crtc=%p\n", __LINE__, crtc));
|
---|
324 |
|
---|
325 | return 0;
|
---|
326 | }
|
---|
327 |
|
---|
328 | static void vbox_encoder_destroy(struct drm_encoder *encoder)
|
---|
329 | {
|
---|
330 | LogFunc(("vboxvideo: %d: encoder=%p\n", __LINE__, encoder));
|
---|
331 | drm_encoder_cleanup(encoder);
|
---|
332 | kfree(encoder);
|
---|
333 | }
|
---|
334 |
|
---|
335 |
|
---|
336 | static struct drm_encoder *vbox_best_single_encoder(struct drm_connector *connector)
|
---|
337 | {
|
---|
338 | int enc_id = connector->encoder_ids[0];
|
---|
339 |
|
---|
340 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
341 | /* pick the encoder ids */
|
---|
342 | if (enc_id)
|
---|
343 | return drm_encoder_find(connector->dev, enc_id);
|
---|
344 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
345 | return NULL;
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | static const struct drm_encoder_funcs vbox_enc_funcs = {
|
---|
350 | .destroy = vbox_encoder_destroy,
|
---|
351 | };
|
---|
352 |
|
---|
353 | static void vbox_encoder_dpms(struct drm_encoder *encoder, int mode)
|
---|
354 | {
|
---|
355 |
|
---|
356 | }
|
---|
357 |
|
---|
358 | static bool vbox_mode_fixup(struct drm_encoder *encoder,
|
---|
359 | const struct drm_display_mode *mode,
|
---|
360 | struct drm_display_mode *adjusted_mode)
|
---|
361 | {
|
---|
362 | return true;
|
---|
363 | }
|
---|
364 |
|
---|
365 | static void vbox_encoder_mode_set(struct drm_encoder *encoder,
|
---|
366 | struct drm_display_mode *mode,
|
---|
367 | struct drm_display_mode *adjusted_mode)
|
---|
368 | {
|
---|
369 | }
|
---|
370 |
|
---|
371 | static void vbox_encoder_prepare(struct drm_encoder *encoder)
|
---|
372 | {
|
---|
373 |
|
---|
374 | }
|
---|
375 |
|
---|
376 | static void vbox_encoder_commit(struct drm_encoder *encoder)
|
---|
377 | {
|
---|
378 |
|
---|
379 | }
|
---|
380 |
|
---|
381 |
|
---|
382 | static const struct drm_encoder_helper_funcs vbox_enc_helper_funcs = {
|
---|
383 | .dpms = vbox_encoder_dpms,
|
---|
384 | .mode_fixup = vbox_mode_fixup,
|
---|
385 | .prepare = vbox_encoder_prepare,
|
---|
386 | .commit = vbox_encoder_commit,
|
---|
387 | .mode_set = vbox_encoder_mode_set,
|
---|
388 | };
|
---|
389 |
|
---|
390 | static struct drm_encoder *vbox_encoder_init(struct drm_device *dev, unsigned i)
|
---|
391 | {
|
---|
392 | struct vbox_encoder *vbox_encoder;
|
---|
393 |
|
---|
394 | LogFunc(("vboxvideo: %d: dev=%d\n", __LINE__));
|
---|
395 | vbox_encoder = kzalloc(sizeof(struct vbox_encoder), GFP_KERNEL);
|
---|
396 | if (!vbox_encoder)
|
---|
397 | return NULL;
|
---|
398 |
|
---|
399 | drm_encoder_init(dev, &vbox_encoder->base, &vbox_enc_funcs,
|
---|
400 | DRM_MODE_ENCODER_DAC);
|
---|
401 | drm_encoder_helper_add(&vbox_encoder->base, &vbox_enc_helper_funcs);
|
---|
402 |
|
---|
403 | vbox_encoder->base.possible_crtcs = 1 << i;
|
---|
404 | LogFunc(("vboxvideo: %d: vbox_encoder=%p\n", __LINE__, vbox_encoder));
|
---|
405 | return &vbox_encoder->base;
|
---|
406 | }
|
---|
407 |
|
---|
408 | static void vboxUpdateHints(struct vbox_connector *vbox_connector)
|
---|
409 | {
|
---|
410 | struct vbox_private *pVBox;
|
---|
411 | int rc;
|
---|
412 |
|
---|
413 | LogFunc(("vboxvideo: %d: vbox_connector=%p\n", __LINE__, vbox_connector));
|
---|
414 | pVBox = vbox_connector->base.dev->dev_private;
|
---|
415 | rc = VBoxHGSMIGetModeHints(&pVBox->Ctx, pVBox->cCrtcs, pVBox->paVBVAModeHints);
|
---|
416 | AssertMsgRCReturnVoid(rc, ("VBoxHGSMIGetModeHints failed, rc=%Rrc.\n", rc));
|
---|
417 | if (pVBox->paVBVAModeHints[vbox_connector->iCrtc].magic == VBVAMODEHINT_MAGIC)
|
---|
418 | {
|
---|
419 | vbox_connector->modeHint.cX = pVBox->paVBVAModeHints[vbox_connector->iCrtc].cx & 0x8fff;
|
---|
420 | vbox_connector->modeHint.cY = pVBox->paVBVAModeHints[vbox_connector->iCrtc].cy & 0x8fff;
|
---|
421 | vbox_connector->modeHint.fDisconnected = !(pVBox->paVBVAModeHints[vbox_connector->iCrtc].fEnabled);
|
---|
422 | LogFunc(("vboxvideo: %d: cX=%u, cY=%u, fDisconnected=%RTbool\n", __LINE__,
|
---|
423 | (unsigned)vbox_connector->modeHint.cX, (unsigned)vbox_connector->modeHint.cY,
|
---|
424 | vbox_connector->modeHint.fDisconnected));
|
---|
425 | }
|
---|
426 | }
|
---|
427 |
|
---|
428 | static int vbox_get_modes(struct drm_connector *connector)
|
---|
429 | {
|
---|
430 | struct vbox_connector *vbox_connector = NULL;
|
---|
431 | struct drm_display_mode *pMode = NULL;
|
---|
432 | unsigned cModes = 0;
|
---|
433 | int cxPreferred, cyPreferred;
|
---|
434 |
|
---|
435 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
436 | vbox_connector = to_vbox_connector(connector);
|
---|
437 | vboxUpdateHints(vbox_connector);
|
---|
438 | cModes = drm_add_modes_noedid(connector, 2560, 1600);
|
---|
439 | cxPreferred = vbox_connector->modeHint.cX ? vbox_connector->modeHint.cX : 1024;
|
---|
440 | cyPreferred = vbox_connector->modeHint.cY ? vbox_connector->modeHint.cY : 768;
|
---|
441 | pMode = drm_cvt_mode(connector->dev, cxPreferred, cyPreferred, 60, false,
|
---|
442 | false, false);
|
---|
443 | if (pMode)
|
---|
444 | {
|
---|
445 | pMode->type |= DRM_MODE_TYPE_PREFERRED;
|
---|
446 | drm_mode_probed_add(connector, pMode);
|
---|
447 | ++cModes;
|
---|
448 | }
|
---|
449 | return cModes;
|
---|
450 | }
|
---|
451 |
|
---|
452 | static int vbox_mode_valid(struct drm_connector *connector,
|
---|
453 | struct drm_display_mode *mode)
|
---|
454 | {
|
---|
455 | return MODE_OK;
|
---|
456 | }
|
---|
457 |
|
---|
458 | static void vbox_connector_destroy(struct drm_connector *connector)
|
---|
459 | {
|
---|
460 | struct vbox_connector *vbox_connector = NULL;
|
---|
461 |
|
---|
462 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
463 | vbox_connector = to_vbox_connector(connector);
|
---|
464 | device_remove_file(connector->dev->dev, &vbox_connector->deviceAttribute);
|
---|
465 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
|
---|
466 | drm_sysfs_connector_remove(connector);
|
---|
467 | #else
|
---|
468 | drm_connector_unregister(connector);
|
---|
469 | #endif
|
---|
470 | drm_connector_cleanup(connector);
|
---|
471 | kfree(connector);
|
---|
472 | }
|
---|
473 |
|
---|
474 | static enum drm_connector_status
|
---|
475 | vbox_connector_detect(struct drm_connector *connector, bool force)
|
---|
476 | {
|
---|
477 | struct vbox_connector *vbox_connector = NULL;
|
---|
478 |
|
---|
479 | (void) force;
|
---|
480 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
481 | vbox_connector = to_vbox_connector(connector);
|
---|
482 | vboxUpdateHints(vbox_connector);
|
---|
483 | return !vbox_connector->modeHint.fDisconnected;
|
---|
484 | }
|
---|
485 |
|
---|
486 | static int vbox_fill_modes(struct drm_connector *connector, uint32_t xMax, uint32_t yMax)
|
---|
487 | {
|
---|
488 | struct vbox_connector *vbox_connector;
|
---|
489 | struct drm_device *pDrmDev;
|
---|
490 | struct drm_display_mode *pMode, *pIter;
|
---|
491 |
|
---|
492 | LogFunc(("vboxvideo: %d: connector=%p, xMax=%lu, yMax = %lu\n", __LINE__,
|
---|
493 | connector, (unsigned long)xMax, (unsigned long)yMax));
|
---|
494 | vbox_connector = to_vbox_connector(connector);
|
---|
495 | pDrmDev = vbox_connector->base.dev;
|
---|
496 | list_for_each_entry_safe(pMode, pIter, &connector->modes, head)
|
---|
497 | {
|
---|
498 | list_del(&pMode->head);
|
---|
499 | drm_mode_destroy(pDrmDev, pMode);
|
---|
500 | }
|
---|
501 | return drm_helper_probe_single_connector_modes(connector, xMax, yMax);
|
---|
502 | }
|
---|
503 |
|
---|
504 | static const struct drm_connector_helper_funcs vbox_connector_helper_funcs = {
|
---|
505 | .mode_valid = vbox_mode_valid,
|
---|
506 | .get_modes = vbox_get_modes,
|
---|
507 | .best_encoder = vbox_best_single_encoder,
|
---|
508 | };
|
---|
509 |
|
---|
510 | static const struct drm_connector_funcs vbox_connector_funcs = {
|
---|
511 | .dpms = drm_helper_connector_dpms,
|
---|
512 | .detect = vbox_connector_detect,
|
---|
513 | .fill_modes = vbox_fill_modes,
|
---|
514 | .destroy = vbox_connector_destroy,
|
---|
515 | };
|
---|
516 |
|
---|
517 | ssize_t vbox_connector_write_sysfs(struct device *dev,
|
---|
518 | struct device_attribute *pAttr,
|
---|
519 | const char *psz, size_t cch)
|
---|
520 | {
|
---|
521 | struct vbox_connector *vbox_connector;
|
---|
522 | struct vbox_private *pVBox;
|
---|
523 |
|
---|
524 | LogFunc(("vboxvideo: %d: dev=%p, pAttr=%p, psz=%s, cch=%llu\n", __LINE__,
|
---|
525 | dev, pAttr, psz, (unsigned long long)cch));
|
---|
526 | vbox_connector = container_of(pAttr, struct vbox_connector,
|
---|
527 | deviceAttribute);
|
---|
528 | pVBox = vbox_connector->base.dev->dev_private;
|
---|
529 | drm_kms_helper_hotplug_event(vbox_connector->base.dev);
|
---|
530 | if (pVBox->fbdev)
|
---|
531 | drm_fb_helper_hotplug_event(&pVBox->fbdev->helper);
|
---|
532 | return cch;
|
---|
533 | }
|
---|
534 |
|
---|
535 | static int vbox_connector_init(struct drm_device *dev, unsigned cScreen,
|
---|
536 | struct drm_encoder *encoder)
|
---|
537 | {
|
---|
538 | struct vbox_connector *vbox_connector;
|
---|
539 | struct drm_connector *connector;
|
---|
540 | int rc;
|
---|
541 |
|
---|
542 | LogFunc(("vboxvideo: %d: dev=%p, encoder=%p\n", __LINE__, dev,
|
---|
543 | encoder));
|
---|
544 | vbox_connector = kzalloc(sizeof(struct vbox_connector), GFP_KERNEL);
|
---|
545 | if (!vbox_connector)
|
---|
546 | return -ENOMEM;
|
---|
547 |
|
---|
548 | connector = &vbox_connector->base;
|
---|
549 | vbox_connector->iCrtc = cScreen;
|
---|
550 |
|
---|
551 | /*
|
---|
552 | * Set up the sysfs file we use for getting video mode hints from user
|
---|
553 | * space.
|
---|
554 | */
|
---|
555 | snprintf(vbox_connector->szName, sizeof(vbox_connector->szName),
|
---|
556 | "vbox_screen_%u", cScreen);
|
---|
557 | vbox_connector->deviceAttribute.attr.name = vbox_connector->szName;
|
---|
558 | vbox_connector->deviceAttribute.attr.mode = S_IWUSR;
|
---|
559 | vbox_connector->deviceAttribute.show = NULL;
|
---|
560 | vbox_connector->deviceAttribute.store = vbox_connector_write_sysfs;
|
---|
561 | rc = device_create_file(dev->dev, &vbox_connector->deviceAttribute);
|
---|
562 | if (rc < 0)
|
---|
563 | {
|
---|
564 | kfree(vbox_connector);
|
---|
565 | return rc;
|
---|
566 | }
|
---|
567 | drm_connector_init(dev, connector, &vbox_connector_funcs,
|
---|
568 | DRM_MODE_CONNECTOR_VGA);
|
---|
569 | drm_connector_helper_add(connector, &vbox_connector_helper_funcs);
|
---|
570 |
|
---|
571 | connector->interlace_allowed = 0;
|
---|
572 | connector->doublescan_allowed = 0;
|
---|
573 |
|
---|
574 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0)
|
---|
575 | drm_sysfs_connector_add(connector);
|
---|
576 | #else
|
---|
577 | drm_connector_register(connector);
|
---|
578 | #endif
|
---|
579 |
|
---|
580 | drm_mode_connector_attach_encoder(connector, encoder);
|
---|
581 |
|
---|
582 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
583 | return 0;
|
---|
584 | }
|
---|
585 |
|
---|
586 | #if 0
|
---|
587 | /* allocate cursor cache and pin at start of VRAM */
|
---|
588 | int vbox_cursor_init(struct drm_device *dev)
|
---|
589 | {
|
---|
590 | struct vbox_private *vbox = dev->dev_private;
|
---|
591 | int size;
|
---|
592 | int ret;
|
---|
593 | struct drm_gem_object *obj;
|
---|
594 | struct vbox_bo *bo;
|
---|
595 | uint64_t gpu_addr;
|
---|
596 |
|
---|
597 | size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM;
|
---|
598 |
|
---|
599 | ret = vbox_gem_create(dev, size, true, &obj);
|
---|
600 | if (ret)
|
---|
601 | return ret;
|
---|
602 | bo = gem_to_vbox_bo(obj);
|
---|
603 | ret = vbox_bo_reserve(bo, false);
|
---|
604 | if (unlikely(ret != 0))
|
---|
605 | goto fail;
|
---|
606 |
|
---|
607 | ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
|
---|
608 | vbox_bo_unreserve(bo);
|
---|
609 | if (ret)
|
---|
610 | goto fail;
|
---|
611 |
|
---|
612 | /* kmap the object */
|
---|
613 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &vbox->cache_kmap);
|
---|
614 | if (ret)
|
---|
615 | goto fail;
|
---|
616 |
|
---|
617 | vbox->cursor_cache = obj;
|
---|
618 | vbox->cursor_cache_gpu_addr = gpu_addr;
|
---|
619 | DRM_DEBUG_KMS("pinned cursor cache at %llx\n", vbox->cursor_cache_gpu_addr);
|
---|
620 | return 0;
|
---|
621 | fail:
|
---|
622 | return ret;
|
---|
623 | }
|
---|
624 |
|
---|
625 | void vbox_cursor_fini(struct drm_device *dev)
|
---|
626 | {
|
---|
627 | struct vbox_private *vbox = dev->dev_private;
|
---|
628 | ttm_bo_kunmap(&vbox->cache_kmap);
|
---|
629 | drm_gem_object_unreference_unlocked(vbox->cursor_cache);
|
---|
630 | }
|
---|
631 | #endif
|
---|
632 |
|
---|
633 | int vbox_mode_init(struct drm_device *dev)
|
---|
634 | {
|
---|
635 | struct vbox_private *pVBox = dev->dev_private;
|
---|
636 | struct drm_encoder *encoder;
|
---|
637 | unsigned i;
|
---|
638 | /* vbox_cursor_init(dev); */
|
---|
639 | LogFunc(("vboxvideo: %d: dev=%p\n", __LINE__, dev));
|
---|
640 | for (i = 0; i < pVBox->cCrtcs; ++i)
|
---|
641 | {
|
---|
642 | vbox_crtc_init(dev, i);
|
---|
643 | encoder = vbox_encoder_init(dev, i);
|
---|
644 | if (encoder)
|
---|
645 | vbox_connector_init(dev, i, encoder);
|
---|
646 | }
|
---|
647 | return 0;
|
---|
648 | }
|
---|
649 |
|
---|
650 | void vbox_mode_fini(struct drm_device *dev)
|
---|
651 | {
|
---|
652 | /* vbox_cursor_fini(dev); */
|
---|
653 | }
|
---|
654 |
|
---|
655 |
|
---|
656 | void VBoxRefreshModes(struct drm_device *dev)
|
---|
657 | {
|
---|
658 | struct vbox_private *vbox = dev->dev_private;
|
---|
659 | struct drm_crtc *crtci;
|
---|
660 | unsigned long flags;
|
---|
661 |
|
---|
662 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
663 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
664 | list_for_each_entry(crtci, &dev->mode_config.crtc_list, head)
|
---|
665 | vbox_do_modeset(crtci, &crtci->hwmode);
|
---|
666 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
667 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
668 | }
|
---|
669 |
|
---|
670 |
|
---|
671 | /** Copy the ARGB image and generate the mask, which is needed in case the host
|
---|
672 | * does not support ARGB cursors. The mask is a 1BPP bitmap with the bit set
|
---|
673 | * if the corresponding alpha value in the ARGB image is greater than 0xF0. */
|
---|
674 | static void copy_cursor_image(u8 *src, u8 *dst, int width, int height,
|
---|
675 | size_t cbMask)
|
---|
676 | {
|
---|
677 | unsigned i, j;
|
---|
678 | size_t cbLine = (width + 7) / 8;
|
---|
679 |
|
---|
680 | memcpy(dst + cbMask, src, width * height * 4);
|
---|
681 | for (i = 0; i < height; ++i)
|
---|
682 | for (j = 0; j < width; ++j)
|
---|
683 | if (((uint32_t *)src)[i * width + j] > 0xf0000000)
|
---|
684 | dst[i * cbLine + j / 8] |= (0x80 >> (j % 8));
|
---|
685 | }
|
---|
686 |
|
---|
687 | static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
|
---|
688 | uint32_t handle, uint32_t width, uint32_t height,
|
---|
689 | int32_t hot_x, int32_t hot_y)
|
---|
690 | {
|
---|
691 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
692 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
693 | struct drm_gem_object *obj;
|
---|
694 | struct vbox_bo *bo;
|
---|
695 | int ret, rc;
|
---|
696 | struct ttm_bo_kmap_obj uobj_map;
|
---|
697 | u8 *src;
|
---|
698 | u8 *dst = NULL;
|
---|
699 | size_t cbData, cbMask;
|
---|
700 | bool src_isiomem;
|
---|
701 |
|
---|
702 | if (!handle) {
|
---|
703 | /* Hide cursor. */
|
---|
704 | VBoxHGSMIUpdatePointerShape(&vbox->Ctx, 0, 0, 0, 0, 0, NULL, 0);
|
---|
705 | return 0;
|
---|
706 | }
|
---|
707 | if ( width > VBOX_MAX_CURSOR_WIDTH || height > VBOX_MAX_CURSOR_HEIGHT
|
---|
708 | || width == 0 || hot_x > width || height == 0 || hot_y > height)
|
---|
709 | return -EINVAL;
|
---|
710 |
|
---|
711 | obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
|
---|
712 | if (obj)
|
---|
713 | {
|
---|
714 | bo = gem_to_vbox_bo(obj);
|
---|
715 | ret = vbox_bo_reserve(bo, false);
|
---|
716 | if (!ret)
|
---|
717 | {
|
---|
718 | /* The mask must be calculated based on the alpha channel, one bit
|
---|
719 | * per ARGB word, and must be 32-bit padded. */
|
---|
720 | cbMask = ((width + 7) / 8 * height + 3) & ~3;
|
---|
721 | cbData = width * height * 4 + cbMask;
|
---|
722 | dst = kmalloc(cbData, GFP_KERNEL);
|
---|
723 | if (dst)
|
---|
724 | {
|
---|
725 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map);
|
---|
726 | if (!ret)
|
---|
727 | {
|
---|
728 | src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
|
---|
729 | if (!src_isiomem)
|
---|
730 | {
|
---|
731 | uint32_t fFlags = VBOX_MOUSE_POINTER_VISIBLE
|
---|
732 | | VBOX_MOUSE_POINTER_SHAPE
|
---|
733 | | VBOX_MOUSE_POINTER_ALPHA;
|
---|
734 | copy_cursor_image(src, dst, width, height, cbMask);
|
---|
735 | rc = VBoxHGSMIUpdatePointerShape(&vbox->Ctx, fFlags,
|
---|
736 | hot_x, hot_y, width,
|
---|
737 | height, dst, cbData);
|
---|
738 | ret = RTErrConvertToErrno(rc);
|
---|
739 | }
|
---|
740 | else
|
---|
741 | DRM_ERROR("src cursor bo should be in main memory\n");
|
---|
742 | ttm_bo_kunmap(&uobj_map);
|
---|
743 | }
|
---|
744 | kfree(dst);
|
---|
745 | }
|
---|
746 | vbox_bo_unreserve(bo);
|
---|
747 | }
|
---|
748 | drm_gem_object_unreference_unlocked(obj);
|
---|
749 | }
|
---|
750 | else
|
---|
751 | {
|
---|
752 | DRM_ERROR("Cannot find cursor object %x for crtc\n", handle);
|
---|
753 | ret = -ENOENT;
|
---|
754 | }
|
---|
755 | return ret;
|
---|
756 | }
|
---|
757 |
|
---|
758 | static int vbox_cursor_move(struct drm_crtc *crtc,
|
---|
759 | int x, int y)
|
---|
760 | {
|
---|
761 | return 0;
|
---|
762 | }
|
---|