VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/drm/vbox_drv.h@ 60198

Last change on this file since 60198 was 60141, checked in by vboxsync, 9 years ago

bugref:8087: Additions/x11: support non-root X server: the Linux kernel sends cursor events to each screen, but we handle them globally. Keep track of whether the cursor is enabled for each screen, and only disable it globally if it is disabled everywhere. Also take screen offset into account when reporting cursor position to the host.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/* $Id: vbox_drv.h 60141 2016-03-22 19:23:35Z 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_drv.h
20 * with the following copyright and permission notice:
21 *
22 * Copyright 2012 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
26 * "Software"), to deal in the Software without restriction, including
27 * without limitation the rights to use, copy, modify, merge, publish,
28 * distribute, sub license, and/or sell copies of the Software, and to
29 * permit persons to whom the Software is furnished to do so, subject to
30 * the following conditions:
31 *
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
35 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
36 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
37 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
38 * USE OR OTHER DEALINGS IN THE SOFTWARE.
39 *
40 * The above copyright notice and this permission notice (including the
41 * next paragraph) shall be included in all copies or substantial portions
42 * of the Software.
43 *
44 */
45/*
46 * Authors: Dave Airlie <[email protected]>
47 */
48#ifndef __VBOX_DRV_H__
49#define __VBOX_DRV_H__
50
51#define LOG_GROUP LOG_GROUP_DEV_VGA
52
53#include "the-linux-kernel.h"
54
55#include <VBox/VBoxVideoGuest.h>
56#include <VBox/log.h>
57
58#include <drm/drmP.h>
59#include <drm/drm_fb_helper.h>
60
61#include <drm/ttm/ttm_bo_api.h>
62#include <drm/ttm/ttm_bo_driver.h>
63#include <drm/ttm/ttm_placement.h>
64#include <drm/ttm/ttm_memory.h>
65#include <drm/ttm/ttm_module.h>
66
67#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0)
68# include <drm/drm_gem.h>
69#endif
70
71/* #include "vboxvideo.h" */
72
73#include "product-generated.h"
74
75#define DRIVER_AUTHOR VBOX_VENDOR
76
77#define DRIVER_NAME "vboxvideo"
78#define DRIVER_DESC VBOX_PRODUCT " Graphics Card"
79#define DRIVER_DATE "20130823"
80
81#define DRIVER_MAJOR 1
82#define DRIVER_MINOR 0
83#define DRIVER_PATCHLEVEL 0
84
85#define VBOX_MAX_CURSOR_WIDTH 64
86#define VBOX_MAX_CURSOR_HEIGHT 64
87
88struct vbox_fbdev;
89
90struct vbox_private {
91 struct drm_device *dev;
92
93 uint8_t __iomem *vram;
94 HGSMIGUESTCOMMANDCONTEXT submit_info;
95 struct VBVABUFFERCONTEXT *vbva_info;
96 bool any_pitch;
97 unsigned num_crtcs;
98 bool vga2_clone;
99 /** Amount of available VRAM, including space used for buffers. */
100 uint32_t full_vram_size;
101 /** Amount of available VRAM, not including space used for buffers. */
102 uint32_t vram_size;
103 /** Offset to the host flags in the VRAM. */
104 uint32_t host_flags_offset;
105 /** Array of structures for receiving mode hints. */
106 VBVAMODEHINT *last_mode_hints;
107
108 struct vbox_fbdev *fbdev;
109
110 int fb_mtrr;
111
112 struct {
113 struct drm_global_reference mem_global_ref;
114 struct ttm_bo_global_ref bo_global_ref;
115 struct ttm_bo_device bdev;
116 bool mm_initialised;
117 } ttm;
118
119 struct mutex hw_mutex;
120 bool isr_installed;
121 /** Have we finished fbdev initialisation? We limit reported display
122 * modes to 800x600 until this point to get a sensible console size. */
123 bool fbdev_init;
124 struct work_struct hotplug_work;
125};
126
127int vbox_driver_load(struct drm_device *dev, unsigned long flags);
128int vbox_driver_unload(struct drm_device *dev);
129void vbox_driver_lastclose(struct drm_device *dev);
130
131struct vbox_gem_object;
132
133#ifndef VGA_PORT_HGSMI_HOST
134# define VGA_PORT_HGSMI_HOST 0x3b0
135# define VGA_PORT_HGSMI_GUEST 0x3d0
136#endif
137
138struct vbox_connector {
139 struct drm_connector base;
140 char name[32];
141 struct vbox_crtc *vbox_crtc;
142 struct {
143 uint16_t width;
144 uint16_t height;
145 bool disconnected;
146 } mode_hint;
147};
148
149struct vbox_crtc {
150 struct drm_crtc base;
151 bool blanked;
152 bool disconnected;
153 unsigned crtc_id;
154 uint32_t fb_offset;
155 bool cursor_enabled;
156};
157
158struct vbox_encoder {
159 struct drm_encoder base;
160};
161
162struct vbox_framebuffer {
163 struct drm_framebuffer base;
164 struct drm_gem_object *obj;
165};
166
167struct vbox_fbdev {
168 struct drm_fb_helper helper;
169 struct vbox_framebuffer afb;
170 void *sysram;
171 int size;
172 struct ttm_bo_kmap_obj mapping;
173 int x1, y1, x2, y2; /* dirty rect */
174 spinlock_t dirty_lock;
175};
176
177#define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
178#define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
179#define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
180#define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
181
182extern int vbox_mode_init(struct drm_device *dev);
183extern void vbox_mode_fini(struct drm_device *dev);
184extern void vbox_refresh_modes(struct drm_device *dev);
185
186#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
187# define DRM_MODE_FB_CMD drm_mode_fb_cmd
188#else
189# define DRM_MODE_FB_CMD drm_mode_fb_cmd2
190#endif
191
192#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
193# define CRTC_FB(crtc) (crtc)->fb
194#else
195# define CRTC_FB(crtc) (crtc)->primary->fb
196#endif
197
198void vbox_enable_accel(struct vbox_private *vbox);
199void vbox_disable_accel(struct vbox_private *vbox);
200void vbox_enable_caps(struct vbox_private *vbox);
201void vbox_disable_caps(struct vbox_private *vbox);
202
203void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
204 struct drm_clip_rect *rects,
205 unsigned num_rects);
206
207int vbox_framebuffer_init(struct drm_device *dev,
208 struct vbox_framebuffer *vbox_fb,
209#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0)
210 const
211#endif
212 struct DRM_MODE_FB_CMD *mode_cmd,
213 struct drm_gem_object *obj);
214
215int vbox_fbdev_init(struct drm_device *dev);
216void vbox_fbdev_fini(struct drm_device *dev);
217void vbox_fbdev_set_suspend(struct drm_device *dev, int state);
218
219struct vbox_bo {
220 struct ttm_buffer_object bo;
221 struct ttm_placement placement;
222 struct ttm_bo_kmap_obj kmap;
223 struct drm_gem_object gem;
224#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
225 u32 placements[3];
226#else
227 struct ttm_place placements[3];
228#endif
229 int pin_count;
230};
231#define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
232
233static inline struct vbox_bo *
234vbox_bo(struct ttm_buffer_object *bo)
235{
236 return container_of(bo, struct vbox_bo, bo);
237}
238
239
240#define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
241
242extern int vbox_dumb_create(struct drm_file *file,
243 struct drm_device *dev,
244 struct drm_mode_create_dumb *args);
245#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
246extern int vbox_dumb_destroy(struct drm_file *file,
247 struct drm_device *dev,
248 uint32_t handle);
249#endif
250
251extern void vbox_gem_free_object(struct drm_gem_object *obj);
252extern int vbox_dumb_mmap_offset(struct drm_file *file,
253 struct drm_device *dev,
254 uint32_t handle,
255 uint64_t *offset);
256
257#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
258
259int vbox_mm_init(struct vbox_private *vbox);
260void vbox_mm_fini(struct vbox_private *vbox);
261
262int vbox_bo_create(struct drm_device *dev, int size, int align,
263 uint32_t flags, struct vbox_bo **pvboxbo);
264
265int vbox_gem_create(struct drm_device *dev,
266 u32 size, bool iskernel,
267 struct drm_gem_object **obj);
268
269int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr);
270int vbox_bo_unpin(struct vbox_bo *bo);
271
272static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
273{
274 int ret;
275
276 ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, 0);
277 if (ret)
278 {
279 if (ret != -ERESTARTSYS && ret != -EBUSY)
280 DRM_ERROR("reserve failed %p\n", bo);
281 return ret;
282 }
283 return 0;
284}
285
286static inline void vbox_bo_unreserve(struct vbox_bo *bo)
287{
288 ttm_bo_unreserve(&bo->bo);
289}
290
291void vbox_ttm_placement(struct vbox_bo *bo, int domain);
292int vbox_bo_push_sysram(struct vbox_bo *bo);
293int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
294
295/* vbox_irq.c */
296int vbox_irq_init(struct vbox_private *vbox);
297void vbox_irq_fini(struct vbox_private *vbox);
298irqreturn_t vbox_irq_handler(int irq, void *arg);
299#endif
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