1 | /** @file $Id: vbox_mode.c 53793 2015-01-13 20:06:32Z vboxsync $
|
---|
2 | *
|
---|
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-vbox
|
---|
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 |
|
---|
57 | static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
|
---|
58 | uint32_t handle, uint32_t width, uint32_t height,
|
---|
59 | int32_t hot_x, int32_t hot_y);
|
---|
60 | static int vbox_cursor_move(struct drm_crtc *crtc, int x, int y);
|
---|
61 |
|
---|
62 | /** Set a graphics mode. Poke any required values into registers, do an HGSMI
|
---|
63 | * mode set and tell the host we support advanced graphics functions.
|
---|
64 | */
|
---|
65 | static void vbox_do_modeset(struct drm_crtc *crtc,
|
---|
66 | const struct drm_display_mode *mode)
|
---|
67 | {
|
---|
68 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
69 | struct vbox_private *vbox;
|
---|
70 | int width, height, cBPP, pitch;
|
---|
71 | unsigned iCrtc;
|
---|
72 | uint16_t fFlags;
|
---|
73 |
|
---|
74 | LogFunc(("vboxvideo: %d: vbox_crtc=%p, CRTC_FB(crtc)=%p\n", __LINE__,
|
---|
75 | vbox_crtc, CRTC_FB(crtc)));
|
---|
76 | vbox = crtc->dev->dev_private;
|
---|
77 | width = mode->hdisplay ? mode->hdisplay : 640;
|
---|
78 | height = mode->vdisplay ? mode->vdisplay : 480;
|
---|
79 | iCrtc = vbox_crtc->crtc_id;
|
---|
80 | cBPP = crtc->enabled ? CRTC_FB(crtc)->bits_per_pixel : 32;
|
---|
81 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
---|
82 | pitch = crtc->enabled ? CRTC_FB(crtc)->pitch : width * cBPP / 8;
|
---|
83 | #else
|
---|
84 | pitch = crtc->enabled ? CRTC_FB(crtc)->pitches[0] : width * cBPP / 8;
|
---|
85 | #endif
|
---|
86 | /* if (vbox_crtc->crtc_id == 0 && crtc->enabled)
|
---|
87 | VBoxVideoSetModeRegisters(width, height, pitch * 8 / cBPP,
|
---|
88 | CRTC_FB(crtc)->bits_per_pixel, 0,
|
---|
89 | crtc->x, crtc->y); */
|
---|
90 | fFlags = VBVA_SCREEN_F_ACTIVE;
|
---|
91 | fFlags |= (crtc->enabled ? 0 : VBVA_SCREEN_F_DISABLED);
|
---|
92 | VBoxHGSMIProcessDisplayInfo(&vbox->Ctx, vbox_crtc->crtc_id,
|
---|
93 | crtc->x, crtc->y,
|
---|
94 | crtc->x * cBPP / 8 + crtc->y * pitch,
|
---|
95 | pitch, width, height,
|
---|
96 | vbox_crtc->fBlanked ? 0 : cBPP, fFlags);
|
---|
97 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
98 | }
|
---|
99 |
|
---|
100 | static int vbox_set_view(struct drm_crtc *crtc)
|
---|
101 | {
|
---|
102 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
103 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
104 | void *p;
|
---|
105 |
|
---|
106 | LogFunc(("vboxvideo: %d: vbox_crtc=%p\n", __LINE__, vbox_crtc));
|
---|
107 | /* Tell the host about the view. This design originally targeted the
|
---|
108 | * Windows XP driver architecture and assumed that each screen would have
|
---|
109 | * a dedicated frame buffer with the command buffer following it, the whole
|
---|
110 | * being a "view". The host works out which screen a command buffer belongs
|
---|
111 | * to by checking whether it is in the first view, then whether it is in the
|
---|
112 | * second and so on. The first match wins. We cheat around this by making
|
---|
113 | * the first view be the managed memory plus the first command buffer, the
|
---|
114 | * second the same plus the second buffer and so on. */
|
---|
115 | p = VBoxHGSMIBufferAlloc(&vbox->Ctx, sizeof(VBVAINFOVIEW), HGSMI_CH_VBVA,
|
---|
116 | VBVA_INFO_VIEW);
|
---|
117 | if (p)
|
---|
118 | {
|
---|
119 | VBVAINFOVIEW *pInfo = (VBVAINFOVIEW *)p;
|
---|
120 | pInfo->u32ViewIndex = vbox_crtc->crtc_id;
|
---|
121 | pInfo->u32ViewOffset = vbox_crtc->offFB;
|
---|
122 | pInfo->u32ViewSize = vbox->vram_size - vbox_crtc->offFB
|
---|
123 | + vbox_crtc->crtc_id * VBVA_MIN_BUFFER_SIZE;
|
---|
124 | pInfo->u32MaxScreenSize = vbox->vram_size - vbox_crtc->offFB;
|
---|
125 | VBoxHGSMIBufferSubmit(&vbox->Ctx, p);
|
---|
126 | VBoxHGSMIBufferFree(&vbox->Ctx, p);
|
---|
127 | }
|
---|
128 | else
|
---|
129 | return -ENOMEM;
|
---|
130 | LogFunc(("vboxvideo: %d: p=%p\n", __LINE__, p));
|
---|
131 | return 0;
|
---|
132 | }
|
---|
133 |
|
---|
134 | static void vbox_crtc_load_lut(struct drm_crtc *crtc)
|
---|
135 | {
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | static void vbox_crtc_dpms(struct drm_crtc *crtc, int mode)
|
---|
140 | {
|
---|
141 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
142 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
143 | unsigned long flags;
|
---|
144 |
|
---|
145 | LogFunc(("vboxvideo: %d: vbox_crtc=%p, mode=%d\n", __LINE__, vbox_crtc,
|
---|
146 | mode));
|
---|
147 | switch (mode)
|
---|
148 | {
|
---|
149 | case DRM_MODE_DPMS_ON:
|
---|
150 | vbox_crtc->fBlanked = false;
|
---|
151 | break;
|
---|
152 | case DRM_MODE_DPMS_STANDBY:
|
---|
153 | case DRM_MODE_DPMS_SUSPEND:
|
---|
154 | case DRM_MODE_DPMS_OFF:
|
---|
155 | vbox_crtc->fBlanked = true;
|
---|
156 | break;
|
---|
157 | }
|
---|
158 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
159 | vbox_do_modeset(crtc, &crtc->hwmode);
|
---|
160 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
161 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
162 | }
|
---|
163 |
|
---|
164 | static bool vbox_crtc_mode_fixup(struct drm_crtc *crtc,
|
---|
165 | const struct drm_display_mode *mode,
|
---|
166 | struct drm_display_mode *adjusted_mode)
|
---|
167 | {
|
---|
168 | return true;
|
---|
169 | }
|
---|
170 |
|
---|
171 | static int vbox_crtc_do_set_base(struct drm_crtc *crtc,
|
---|
172 | struct drm_framebuffer *fb,
|
---|
173 | int x, int y, int atomic)
|
---|
174 | {
|
---|
175 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
176 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
177 | struct drm_gem_object *obj;
|
---|
178 | struct vbox_framebuffer *vbox_fb;
|
---|
179 | struct vbox_bo *bo;
|
---|
180 | int ret;
|
---|
181 | u64 gpu_addr;
|
---|
182 |
|
---|
183 | LogFunc(("vboxvideo: %d: fb=%p, vbox_crtc=%p\n", __LINE__, fb, vbox_crtc));
|
---|
184 |
|
---|
185 | vbox_fb = to_vbox_framebuffer(CRTC_FB(crtc));
|
---|
186 | obj = vbox_fb->obj;
|
---|
187 | bo = gem_to_vbox_bo(obj);
|
---|
188 |
|
---|
189 | ret = vbox_bo_reserve(bo, false);
|
---|
190 | if (ret)
|
---|
191 | return ret;
|
---|
192 |
|
---|
193 | ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
|
---|
194 | if (ret)
|
---|
195 | {
|
---|
196 | vbox_bo_unreserve(bo);
|
---|
197 | return ret;
|
---|
198 | }
|
---|
199 |
|
---|
200 | if (&vbox->fbdev->afb == vbox_fb)
|
---|
201 | {
|
---|
202 | /* if pushing console in kmap it */
|
---|
203 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
|
---|
204 | if (ret)
|
---|
205 | DRM_ERROR("failed to kmap fbcon\n");
|
---|
206 | }
|
---|
207 | vbox_bo_unreserve(bo);
|
---|
208 |
|
---|
209 | /* vbox_set_start_address_crt1(crtc, (u32)gpu_addr); */
|
---|
210 | vbox_crtc->offFB = gpu_addr;
|
---|
211 |
|
---|
212 | LogFunc(("vboxvideo: %d: vbox_fb=%p, obj=%p, bo=%p, gpu_addr=%u\n",
|
---|
213 | __LINE__, vbox_fb, obj, bo, (unsigned)gpu_addr));
|
---|
214 | return 0;
|
---|
215 | }
|
---|
216 |
|
---|
217 | static int vbox_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
|
---|
218 | struct drm_framebuffer *old_fb)
|
---|
219 | {
|
---|
220 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
221 | return vbox_crtc_do_set_base(crtc, old_fb, x, y, 0);
|
---|
222 | }
|
---|
223 |
|
---|
224 | static int vbox_crtc_mode_set(struct drm_crtc *crtc,
|
---|
225 | struct drm_display_mode *mode,
|
---|
226 | struct drm_display_mode *adjusted_mode,
|
---|
227 | int x, int y,
|
---|
228 | struct drm_framebuffer *old_fb)
|
---|
229 | {
|
---|
230 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
231 | unsigned long flags;
|
---|
232 | int rc = 0;
|
---|
233 |
|
---|
234 | LogFunc(("vboxvideo: %d: vbox=%p\n", __LINE__, vbox));
|
---|
235 | vbox_crtc_mode_set_base(crtc, x, y, old_fb);
|
---|
236 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
237 | rc = vbox_set_view(crtc);
|
---|
238 | if (!rc)
|
---|
239 | vbox_do_modeset(crtc, mode);
|
---|
240 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
241 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
242 | return rc;
|
---|
243 | }
|
---|
244 |
|
---|
245 | static void vbox_crtc_disable(struct drm_crtc *crtc)
|
---|
246 | {
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | static void vbox_crtc_prepare(struct drm_crtc *crtc)
|
---|
251 | {
|
---|
252 |
|
---|
253 | }
|
---|
254 |
|
---|
255 | static void vbox_crtc_commit(struct drm_crtc *crtc)
|
---|
256 | {
|
---|
257 |
|
---|
258 | }
|
---|
259 |
|
---|
260 |
|
---|
261 | static const struct drm_crtc_helper_funcs vbox_crtc_helper_funcs =
|
---|
262 | {
|
---|
263 | .dpms = vbox_crtc_dpms,
|
---|
264 | .mode_fixup = vbox_crtc_mode_fixup,
|
---|
265 | .mode_set = vbox_crtc_mode_set,
|
---|
266 | /* .mode_set_base = vbox_crtc_mode_set_base, */
|
---|
267 | .disable = vbox_crtc_disable,
|
---|
268 | .load_lut = vbox_crtc_load_lut,
|
---|
269 | .prepare = vbox_crtc_prepare,
|
---|
270 | .commit = vbox_crtc_commit,
|
---|
271 |
|
---|
272 | };
|
---|
273 |
|
---|
274 | static void vbox_crtc_reset(struct drm_crtc *crtc)
|
---|
275 | {
|
---|
276 |
|
---|
277 | }
|
---|
278 |
|
---|
279 |
|
---|
280 | static void vbox_crtc_destroy(struct drm_crtc *crtc)
|
---|
281 | {
|
---|
282 | drm_crtc_cleanup(crtc);
|
---|
283 | kfree(crtc);
|
---|
284 | }
|
---|
285 |
|
---|
286 | static const struct drm_crtc_funcs vbox_crtc_funcs =
|
---|
287 | {
|
---|
288 | .cursor_move = vbox_cursor_move,
|
---|
289 | #ifdef DRM_IOCTL_MODE_CURSOR2
|
---|
290 | .cursor_set2 = vbox_cursor_set2,
|
---|
291 | #endif
|
---|
292 | .reset = vbox_crtc_reset,
|
---|
293 | .set_config = drm_crtc_helper_set_config,
|
---|
294 | /* .gamma_set = vbox_crtc_gamma_set, */
|
---|
295 | .destroy = vbox_crtc_destroy,
|
---|
296 | };
|
---|
297 |
|
---|
298 | int vbox_crtc_init(struct drm_device *pDev, unsigned i)
|
---|
299 | {
|
---|
300 | struct vbox_crtc *pCrtc;
|
---|
301 |
|
---|
302 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
303 | pCrtc = kzalloc(sizeof(struct vbox_crtc), GFP_KERNEL);
|
---|
304 | if (!pCrtc)
|
---|
305 | return -ENOMEM;
|
---|
306 | pCrtc->crtc_id = i;
|
---|
307 |
|
---|
308 | drm_crtc_init(pDev, &pCrtc->base, &vbox_crtc_funcs);
|
---|
309 | drm_mode_crtc_set_gamma_size(&pCrtc->base, 256);
|
---|
310 | drm_crtc_helper_add(&pCrtc->base, &vbox_crtc_helper_funcs);
|
---|
311 | LogFunc(("vboxvideo: %d: pCrtc=%p\n", __LINE__, pCrtc));
|
---|
312 |
|
---|
313 | return 0;
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 | static void vbox_encoder_destroy(struct drm_encoder *encoder)
|
---|
318 | {
|
---|
319 | LogFunc(("vboxvideo: %d: encoder=%p\n", __LINE__, encoder));
|
---|
320 | drm_encoder_cleanup(encoder);
|
---|
321 | kfree(encoder);
|
---|
322 | }
|
---|
323 |
|
---|
324 |
|
---|
325 | static struct drm_encoder *vbox_best_single_encoder(struct drm_connector *connector)
|
---|
326 | {
|
---|
327 | int enc_id = connector->encoder_ids[0];
|
---|
328 | struct drm_mode_object *obj;
|
---|
329 | struct drm_encoder *encoder;
|
---|
330 |
|
---|
331 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, connector));
|
---|
332 | /* pick the encoder ids */
|
---|
333 | if (enc_id)
|
---|
334 | {
|
---|
335 | obj = drm_mode_object_find(connector->dev, enc_id, DRM_MODE_OBJECT_ENCODER);
|
---|
336 | if (!obj)
|
---|
337 | return NULL;
|
---|
338 | encoder = obj_to_encoder(obj);
|
---|
339 | LogFunc(("vboxvideo: %d: encoder=%p\n", __LINE__, encoder));
|
---|
340 | return encoder;
|
---|
341 | }
|
---|
342 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
343 | return NULL;
|
---|
344 | }
|
---|
345 |
|
---|
346 |
|
---|
347 | static const struct drm_encoder_funcs vbox_enc_funcs =
|
---|
348 | {
|
---|
349 | .destroy = vbox_encoder_destroy,
|
---|
350 | };
|
---|
351 |
|
---|
352 | static void vbox_encoder_dpms(struct drm_encoder *encoder, int mode)
|
---|
353 | {
|
---|
354 |
|
---|
355 | }
|
---|
356 |
|
---|
357 | static bool vbox_mode_fixup(struct drm_encoder *encoder,
|
---|
358 | const struct drm_display_mode *mode,
|
---|
359 | struct drm_display_mode *adjusted_mode)
|
---|
360 | {
|
---|
361 | return true;
|
---|
362 | }
|
---|
363 |
|
---|
364 | static void vbox_encoder_mode_set(struct drm_encoder *encoder,
|
---|
365 | struct drm_display_mode *mode,
|
---|
366 | struct drm_display_mode *adjusted_mode)
|
---|
367 | {
|
---|
368 | }
|
---|
369 |
|
---|
370 | static void vbox_encoder_prepare(struct drm_encoder *encoder)
|
---|
371 | {
|
---|
372 |
|
---|
373 | }
|
---|
374 |
|
---|
375 | static void vbox_encoder_commit(struct drm_encoder *encoder)
|
---|
376 | {
|
---|
377 |
|
---|
378 | }
|
---|
379 |
|
---|
380 |
|
---|
381 | static const struct drm_encoder_helper_funcs vbox_enc_helper_funcs =
|
---|
382 | {
|
---|
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 | 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 int vbox_get_modes(struct drm_connector *pConnector)
|
---|
409 | {
|
---|
410 | struct vbox_connector *pVBoxConnector = NULL;
|
---|
411 | struct drm_display_mode *pMode = NULL;
|
---|
412 | unsigned cModes = 0;
|
---|
413 |
|
---|
414 | LogFunc(("vboxvideo: %d: pConnector=%p\n", __LINE__, pConnector));
|
---|
415 | pVBoxConnector = to_vbox_connector(pConnector);
|
---|
416 | cModes = drm_add_modes_noedid(pConnector, 1024, 768);
|
---|
417 | if (pVBoxConnector->modeHint.cX && pVBoxConnector->modeHint.cY)
|
---|
418 | {
|
---|
419 | pMode = drm_cvt_mode(pConnector->dev, pVBoxConnector->modeHint.cX,
|
---|
420 | pVBoxConnector->modeHint.cY, 60, false, false,
|
---|
421 | false);
|
---|
422 | if (pMode)
|
---|
423 | {
|
---|
424 | pMode->type |= DRM_MODE_TYPE_PREFERRED;
|
---|
425 | drm_mode_probed_add(pConnector, pMode);
|
---|
426 | ++cModes;
|
---|
427 | }
|
---|
428 | }
|
---|
429 | return cModes;
|
---|
430 | }
|
---|
431 |
|
---|
432 | static int vbox_mode_valid(struct drm_connector *connector,
|
---|
433 | struct drm_display_mode *mode)
|
---|
434 | {
|
---|
435 | return MODE_OK;
|
---|
436 | }
|
---|
437 |
|
---|
438 | static void vbox_connector_destroy(struct drm_connector *pConnector)
|
---|
439 | {
|
---|
440 | struct vbox_connector *pVBoxConnector = NULL;
|
---|
441 |
|
---|
442 | LogFunc(("vboxvideo: %d: connector=%p\n", __LINE__, pConnector));
|
---|
443 | pVBoxConnector = to_vbox_connector(pConnector);
|
---|
444 | device_remove_file(pConnector->dev->dev, &pVBoxConnector->deviceAttribute);
|
---|
445 | drm_sysfs_connector_remove(pConnector);
|
---|
446 | drm_connector_cleanup(pConnector);
|
---|
447 | kfree(pConnector);
|
---|
448 | }
|
---|
449 |
|
---|
450 | static enum drm_connector_status
|
---|
451 | vbox_connector_detect(struct drm_connector *connector, bool force)
|
---|
452 | {
|
---|
453 | return connector_status_connected;
|
---|
454 | }
|
---|
455 |
|
---|
456 | static const struct drm_connector_helper_funcs vbox_connector_helper_funcs =
|
---|
457 | {
|
---|
458 | .mode_valid = vbox_mode_valid,
|
---|
459 | .get_modes = vbox_get_modes,
|
---|
460 | .best_encoder = vbox_best_single_encoder,
|
---|
461 | };
|
---|
462 |
|
---|
463 | static const struct drm_connector_funcs vbox_connector_funcs =
|
---|
464 | {
|
---|
465 | .dpms = drm_helper_connector_dpms,
|
---|
466 | .detect = vbox_connector_detect,
|
---|
467 | .fill_modes = drm_helper_probe_single_connector_modes,
|
---|
468 | .destroy = vbox_connector_destroy,
|
---|
469 | };
|
---|
470 |
|
---|
471 | ssize_t vbox_connector_write_sysfs(struct device *pDev,
|
---|
472 | struct device_attribute *pAttr,
|
---|
473 | const char *psz, size_t cch)
|
---|
474 | {
|
---|
475 | struct vbox_connector *pVBoxConnector;
|
---|
476 | struct drm_device *pDrmDev;
|
---|
477 | struct vbox_private *pVBox;
|
---|
478 | int cX, cY;
|
---|
479 | char ch;
|
---|
480 |
|
---|
481 | LogFunc(("vboxvideo: %d: pDev=%p, pAttr=%p, psz=%s, cch=%llu\n", __LINE__,
|
---|
482 | pDev, pAttr, psz, (unsigned long long)cch));
|
---|
483 | pVBoxConnector = container_of(pAttr, struct vbox_connector,
|
---|
484 | deviceAttribute);
|
---|
485 | pDrmDev = pVBoxConnector->base.dev;
|
---|
486 | pVBox = pDrmDev->dev_private;
|
---|
487 | if (sscanf(psz, "%dx%d\n%c", &cX, &cY, &ch) != 2)
|
---|
488 | return -EINVAL;
|
---|
489 | if ( cX < 64 || cX > VBE_DISPI_MAX_XRES
|
---|
490 | || cY < 64 || cY > VBE_DISPI_MAX_YRES)
|
---|
491 | return -EINVAL;
|
---|
492 | pVBoxConnector->modeHint.cX = (uint16_t)cX;
|
---|
493 | pVBoxConnector->modeHint.cY = (uint16_t)cY;
|
---|
494 | drm_helper_hpd_irq_event(pVBoxConnector->base.dev);
|
---|
495 | if (pVBox->fbdev)
|
---|
496 | drm_fb_helper_hotplug_event(&pVBox->fbdev->helper);
|
---|
497 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
498 | return cch;
|
---|
499 | }
|
---|
500 |
|
---|
501 | int vbox_connector_init(struct drm_device *pDev, unsigned cScreen,
|
---|
502 | struct drm_encoder *pEncoder)
|
---|
503 | {
|
---|
504 | struct vbox_connector *pVBoxConnector;
|
---|
505 | struct drm_connector *pConnector;
|
---|
506 | int rc;
|
---|
507 |
|
---|
508 | LogFunc(("vboxvideo: %d: pDev=%p, pEncoder=%p\n", __LINE__, pDev,
|
---|
509 | pEncoder));
|
---|
510 | pVBoxConnector = kzalloc(sizeof(struct vbox_connector), GFP_KERNEL);
|
---|
511 | if (!pVBoxConnector)
|
---|
512 | return -ENOMEM;
|
---|
513 |
|
---|
514 | pConnector = &pVBoxConnector->base;
|
---|
515 |
|
---|
516 | /*
|
---|
517 | * Set up the sysfs file we use for getting video mode hints from user
|
---|
518 | * space.
|
---|
519 | */
|
---|
520 | snprintf(pVBoxConnector->szName, sizeof(pVBoxConnector->szName),
|
---|
521 | "vbox_screen_%u", cScreen);
|
---|
522 | pVBoxConnector->deviceAttribute.attr.name = pVBoxConnector->szName;
|
---|
523 | pVBoxConnector->deviceAttribute.attr.mode = S_IWUSR;
|
---|
524 | pVBoxConnector->deviceAttribute.show = NULL;
|
---|
525 | pVBoxConnector->deviceAttribute.store = vbox_connector_write_sysfs;
|
---|
526 | rc = device_create_file(pDev->dev, &pVBoxConnector->deviceAttribute);
|
---|
527 | if (rc < 0)
|
---|
528 | {
|
---|
529 | kfree(pVBoxConnector);
|
---|
530 | return rc;
|
---|
531 | }
|
---|
532 | drm_connector_init(pDev, pConnector, &vbox_connector_funcs,
|
---|
533 | DRM_MODE_CONNECTOR_VGA);
|
---|
534 | drm_connector_helper_add(pConnector, &vbox_connector_helper_funcs);
|
---|
535 |
|
---|
536 | pConnector->interlace_allowed = 0;
|
---|
537 | pConnector->doublescan_allowed = 0;
|
---|
538 |
|
---|
539 | drm_sysfs_connector_add(pConnector);
|
---|
540 |
|
---|
541 | /* The connector supports hot-plug detection: we promise to call
|
---|
542 | * "drm_helper_hpd_irq_event" when hot-plugging occurs. */
|
---|
543 | pConnector->polled = DRM_CONNECTOR_POLL_HPD;
|
---|
544 |
|
---|
545 | drm_mode_connector_attach_encoder(pConnector, pEncoder);
|
---|
546 |
|
---|
547 | LogFunc(("vboxvideo: %d: pConnector=%p\n", __LINE__, pConnector));
|
---|
548 | return 0;
|
---|
549 | }
|
---|
550 |
|
---|
551 | #if 0
|
---|
552 | /* allocate cursor cache and pin at start of VRAM */
|
---|
553 | int vbox_cursor_init(struct drm_device *dev)
|
---|
554 | {
|
---|
555 | struct vbox_private *vbox = dev->dev_private;
|
---|
556 | int size;
|
---|
557 | int ret;
|
---|
558 | struct drm_gem_object *obj;
|
---|
559 | struct vbox_bo *bo;
|
---|
560 | uint64_t gpu_addr;
|
---|
561 |
|
---|
562 | size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM;
|
---|
563 |
|
---|
564 | ret = vbox_gem_create(dev, size, true, &obj);
|
---|
565 | if (ret)
|
---|
566 | return ret;
|
---|
567 | bo = gem_to_vbox_bo(obj);
|
---|
568 | ret = vbox_bo_reserve(bo, false);
|
---|
569 | if (unlikely(ret != 0))
|
---|
570 | goto fail;
|
---|
571 |
|
---|
572 | ret = vbox_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr);
|
---|
573 | vbox_bo_unreserve(bo);
|
---|
574 | if (ret)
|
---|
575 | goto fail;
|
---|
576 |
|
---|
577 | /* kmap the object */
|
---|
578 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &vbox->cache_kmap);
|
---|
579 | if (ret)
|
---|
580 | goto fail;
|
---|
581 |
|
---|
582 | vbox->cursor_cache = obj;
|
---|
583 | vbox->cursor_cache_gpu_addr = gpu_addr;
|
---|
584 | DRM_DEBUG_KMS("pinned cursor cache at %llx\n", vbox->cursor_cache_gpu_addr);
|
---|
585 | return 0;
|
---|
586 | fail:
|
---|
587 | return ret;
|
---|
588 | }
|
---|
589 |
|
---|
590 | void vbox_cursor_fini(struct drm_device *dev)
|
---|
591 | {
|
---|
592 | struct vbox_private *vbox = dev->dev_private;
|
---|
593 | ttm_bo_kunmap(&vbox->cache_kmap);
|
---|
594 | drm_gem_object_unreference_unlocked(vbox->cursor_cache);
|
---|
595 | }
|
---|
596 | #endif
|
---|
597 |
|
---|
598 | int vbox_mode_init(struct drm_device *pDev)
|
---|
599 | {
|
---|
600 | struct vbox_private *pVBox = pDev->dev_private;
|
---|
601 | struct drm_encoder *pEncoder;
|
---|
602 | unsigned i;
|
---|
603 | /* vbox_cursor_init(dev); */
|
---|
604 | LogFunc(("vboxvideo: %d: pDev=%p\n", __LINE__, pDev));
|
---|
605 | for (i = 0; i < pVBox->cCrtcs; ++i)
|
---|
606 | {
|
---|
607 | vbox_crtc_init(pDev, i);
|
---|
608 | pEncoder = vbox_encoder_init(pDev, i);
|
---|
609 | if (pEncoder)
|
---|
610 | vbox_connector_init(pDev, i, pEncoder);
|
---|
611 | }
|
---|
612 | return 0;
|
---|
613 | }
|
---|
614 |
|
---|
615 | void vbox_mode_fini(struct drm_device *dev)
|
---|
616 | {
|
---|
617 | /* vbox_cursor_fini(dev); */
|
---|
618 | }
|
---|
619 |
|
---|
620 |
|
---|
621 | void VBoxRefreshModes(struct drm_device *pDev)
|
---|
622 | {
|
---|
623 | struct vbox_private *vbox = pDev->dev_private;
|
---|
624 | struct drm_crtc *crtci;
|
---|
625 | unsigned long flags;
|
---|
626 |
|
---|
627 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
628 | spin_lock_irqsave(&vbox->dev_lock, flags);
|
---|
629 | list_for_each_entry(crtci, &pDev->mode_config.crtc_list, head)
|
---|
630 | vbox_do_modeset(crtci, &crtci->hwmode);
|
---|
631 | spin_unlock_irqrestore(&vbox->dev_lock, flags);
|
---|
632 | LogFunc(("vboxvideo: %d\n", __LINE__));
|
---|
633 | }
|
---|
634 |
|
---|
635 |
|
---|
636 | /** Copy the ARGB image and generate the mask, which is needed in case the host
|
---|
637 | * does not support ARGB cursors. The mask is a 1BPP bitmap with the bit set
|
---|
638 | * if the corresponding alpha value in the ARGB image is greater than 0xF0. */
|
---|
639 | static void copy_cursor_image(u8 *src, u8 *dst, int width, int height,
|
---|
640 | size_t cbMask)
|
---|
641 | {
|
---|
642 | unsigned i, j;
|
---|
643 | size_t cbLine = (width + 7) / 8;
|
---|
644 |
|
---|
645 | memcpy(dst + cbMask, src, width * height * 4);
|
---|
646 | for (i = 0; i < height; ++i)
|
---|
647 | for (j = 0; j < width; ++j)
|
---|
648 | if (((uint32_t *)src)[i * width + j] > 0xf0000000)
|
---|
649 | dst[i * cbLine + j / 8] |= (0x80 >> (j % 8));
|
---|
650 | }
|
---|
651 |
|
---|
652 | static int vbox_cursor_set2(struct drm_crtc *crtc, struct drm_file *file_priv,
|
---|
653 | uint32_t handle, uint32_t width, uint32_t height,
|
---|
654 | int32_t hot_x, int32_t hot_y)
|
---|
655 | {
|
---|
656 | struct vbox_private *vbox = crtc->dev->dev_private;
|
---|
657 | struct vbox_crtc *vbox_crtc = to_vbox_crtc(crtc);
|
---|
658 | struct drm_gem_object *obj;
|
---|
659 | struct vbox_bo *bo;
|
---|
660 | int ret, rc;
|
---|
661 | struct ttm_bo_kmap_obj uobj_map;
|
---|
662 | u8 *src;
|
---|
663 | u8 *dst = NULL;
|
---|
664 | size_t cbData, cbMask;
|
---|
665 | bool src_isiomem;
|
---|
666 |
|
---|
667 | if (!handle) {
|
---|
668 | /* Hide cursor. */
|
---|
669 | VBoxHGSMIUpdatePointerShape(&vbox->Ctx, 0, 0, 0, 0, 0, NULL, 0);
|
---|
670 | return 0;
|
---|
671 | }
|
---|
672 | if ( width > VBOX_MAX_CURSOR_WIDTH || height > VBOX_MAX_CURSOR_HEIGHT
|
---|
673 | || width == 0 || hot_x > width || height == 0 || hot_y > height)
|
---|
674 | return -EINVAL;
|
---|
675 |
|
---|
676 | obj = drm_gem_object_lookup(crtc->dev, file_priv, handle);
|
---|
677 | if (obj)
|
---|
678 | {
|
---|
679 | bo = gem_to_vbox_bo(obj);
|
---|
680 | ret = vbox_bo_reserve(bo, false);
|
---|
681 | if (!ret)
|
---|
682 | {
|
---|
683 | /* The mask must be calculated based on the alpha channel, one bit
|
---|
684 | * per ARGB word, and must be 32-bit padded. */
|
---|
685 | cbMask = ((width + 7) / 8 * height + 3) & ~3;
|
---|
686 | cbData = width * height * 4 + cbMask;
|
---|
687 | dst = kmalloc(cbData, GFP_KERNEL);
|
---|
688 | if (dst)
|
---|
689 | {
|
---|
690 | ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &uobj_map);
|
---|
691 | if (!ret)
|
---|
692 | {
|
---|
693 | src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
|
---|
694 | if (!src_isiomem)
|
---|
695 | {
|
---|
696 | uint32_t fFlags = VBOX_MOUSE_POINTER_VISIBLE
|
---|
697 | | VBOX_MOUSE_POINTER_SHAPE
|
---|
698 | | VBOX_MOUSE_POINTER_ALPHA;
|
---|
699 | copy_cursor_image(src, dst, width, height, cbMask);
|
---|
700 | rc = VBoxHGSMIUpdatePointerShape(&vbox->Ctx, fFlags,
|
---|
701 | hot_x, hot_y, width,
|
---|
702 | height, dst, cbData);
|
---|
703 | ret = RTErrConvertToErrno(rc);
|
---|
704 | }
|
---|
705 | else
|
---|
706 | DRM_ERROR("src cursor bo should be in main memory\n");
|
---|
707 | ttm_bo_kunmap(&uobj_map);
|
---|
708 | }
|
---|
709 | kfree(dst);
|
---|
710 | }
|
---|
711 | vbox_bo_unreserve(bo);
|
---|
712 | }
|
---|
713 | drm_gem_object_unreference_unlocked(obj);
|
---|
714 | }
|
---|
715 | else
|
---|
716 | {
|
---|
717 | DRM_ERROR("Cannot find cursor object %x for crtc\n", handle);
|
---|
718 | ret = -ENOENT;
|
---|
719 | }
|
---|
720 | return ret;
|
---|
721 | }
|
---|
722 |
|
---|
723 | static int vbox_cursor_move(struct drm_crtc *crtc,
|
---|
724 | int x, int y)
|
---|
725 | {
|
---|
726 | return 0;
|
---|
727 | }
|
---|