1 | /* $Id: vbox_drv.h 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_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 |
|
---|
88 | struct vbox_fbdev;
|
---|
89 |
|
---|
90 | struct vbox_private
|
---|
91 | {
|
---|
92 | struct drm_device *dev;
|
---|
93 |
|
---|
94 | void __iomem *vram;
|
---|
95 | HGSMIGUESTCOMMANDCONTEXT Ctx;
|
---|
96 | struct VBVABUFFERCONTEXT *paVBVACtx;
|
---|
97 | bool fAnyX;
|
---|
98 | unsigned cCrtcs;
|
---|
99 | bool vga2_clone;
|
---|
100 | /** Amount of available VRAM, including space used for buffers. */
|
---|
101 | uint32_t full_vram_size;
|
---|
102 | /** Amount of available VRAM, not including space used for buffers. */
|
---|
103 | uint32_t vram_size;
|
---|
104 | /** Offset to the host flags in the VRAM. */
|
---|
105 | uint32_t offHostFlags;
|
---|
106 | /** Array of structures for receiving mode hints. */
|
---|
107 | VBVAMODEHINT *paVBVAModeHints;
|
---|
108 |
|
---|
109 | struct vbox_fbdev *fbdev;
|
---|
110 |
|
---|
111 | int fb_mtrr;
|
---|
112 |
|
---|
113 | struct
|
---|
114 | {
|
---|
115 | struct drm_global_reference mem_global_ref;
|
---|
116 | struct ttm_bo_global_ref bo_global_ref;
|
---|
117 | struct ttm_bo_device bdev;
|
---|
118 | } ttm;
|
---|
119 |
|
---|
120 | spinlock_t dev_lock;
|
---|
121 | };
|
---|
122 |
|
---|
123 | int vbox_driver_load(struct drm_device *dev, unsigned long flags);
|
---|
124 | int vbox_driver_unload(struct drm_device *dev);
|
---|
125 |
|
---|
126 | struct vbox_gem_object;
|
---|
127 |
|
---|
128 | struct vbox_connector
|
---|
129 | {
|
---|
130 | struct drm_connector base;
|
---|
131 | char szName[32];
|
---|
132 | unsigned iCrtc;
|
---|
133 | /** Device attribute for sysfs file used for receiving mode hints from user
|
---|
134 | * space. */
|
---|
135 | struct device_attribute deviceAttribute;
|
---|
136 | struct
|
---|
137 | {
|
---|
138 | uint16_t cX;
|
---|
139 | uint16_t cY;
|
---|
140 | bool fDisconnected;
|
---|
141 | } modeHint;
|
---|
142 | };
|
---|
143 |
|
---|
144 | struct vbox_crtc
|
---|
145 | {
|
---|
146 | struct drm_crtc base;
|
---|
147 | bool fBlanked;
|
---|
148 | unsigned crtc_id;
|
---|
149 | uint32_t offFB;
|
---|
150 | struct drm_gem_object *cursor_bo;
|
---|
151 | uint64_t cursor_addr;
|
---|
152 | int cursor_width, cursor_height;
|
---|
153 | u8 offset_x, offset_y;
|
---|
154 | };
|
---|
155 |
|
---|
156 | struct vbox_encoder
|
---|
157 | {
|
---|
158 | struct drm_encoder base;
|
---|
159 | };
|
---|
160 |
|
---|
161 | struct vbox_framebuffer
|
---|
162 | {
|
---|
163 | struct drm_framebuffer base;
|
---|
164 | struct drm_gem_object *obj;
|
---|
165 | };
|
---|
166 |
|
---|
167 | struct vbox_fbdev
|
---|
168 | {
|
---|
169 | struct drm_fb_helper helper;
|
---|
170 | struct vbox_framebuffer afb;
|
---|
171 | struct list_head fbdev_list;
|
---|
172 | void *sysram;
|
---|
173 | int size;
|
---|
174 | struct ttm_bo_kmap_obj mapping;
|
---|
175 | int x1, y1, x2, y2; /* dirty rect */
|
---|
176 | };
|
---|
177 |
|
---|
178 | #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
|
---|
179 | #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
|
---|
180 | #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
|
---|
181 | #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
|
---|
182 |
|
---|
183 | extern int vbox_mode_init(struct drm_device *dev);
|
---|
184 | extern void vbox_mode_fini(struct drm_device *dev);
|
---|
185 | extern void VBoxRefreshModes(struct drm_device *pDev);
|
---|
186 |
|
---|
187 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
---|
188 | # define DRM_MODE_FB_CMD drm_mode_fb_cmd
|
---|
189 | #else
|
---|
190 | # define DRM_MODE_FB_CMD drm_mode_fb_cmd2
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0)
|
---|
194 | # define CRTC_FB(crtc) (crtc)->fb
|
---|
195 | #else
|
---|
196 | # define CRTC_FB(crtc) (crtc)->primary->fb
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
|
---|
200 | struct drm_clip_rect *pRects,
|
---|
201 | unsigned cRects);
|
---|
202 |
|
---|
203 | int vbox_framebuffer_init(struct drm_device *dev,
|
---|
204 | struct vbox_framebuffer *vbox_fb,
|
---|
205 | struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
206 | struct drm_gem_object *obj);
|
---|
207 |
|
---|
208 | int vbox_fbdev_init(struct drm_device *dev);
|
---|
209 | void vbox_fbdev_fini(struct drm_device *dev);
|
---|
210 | void vbox_fbdev_set_suspend(struct drm_device *dev, int state);
|
---|
211 |
|
---|
212 | struct vbox_bo
|
---|
213 | {
|
---|
214 | struct ttm_buffer_object bo;
|
---|
215 | struct ttm_placement placement;
|
---|
216 | struct ttm_bo_kmap_obj kmap;
|
---|
217 | struct drm_gem_object gem;
|
---|
218 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
|
---|
219 | u32 placements[3];
|
---|
220 | #else
|
---|
221 | struct ttm_place placements[3];
|
---|
222 | #endif
|
---|
223 | int pin_count;
|
---|
224 | };
|
---|
225 | #define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
|
---|
226 |
|
---|
227 | static inline struct vbox_bo * vbox_bo(struct ttm_buffer_object *bo)
|
---|
228 | {
|
---|
229 | return container_of(bo, struct vbox_bo, bo);
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
|
---|
234 |
|
---|
235 | extern int vbox_dumb_create(struct drm_file *file,
|
---|
236 | struct drm_device *dev,
|
---|
237 | struct drm_mode_create_dumb *args);
|
---|
238 | extern int vbox_dumb_destroy(struct drm_file *file,
|
---|
239 | struct drm_device *dev,
|
---|
240 | uint32_t handle);
|
---|
241 |
|
---|
242 | extern void vbox_gem_free_object(struct drm_gem_object *obj);
|
---|
243 | extern int vbox_dumb_mmap_offset(struct drm_file *file,
|
---|
244 | struct drm_device *dev,
|
---|
245 | uint32_t handle,
|
---|
246 | uint64_t *offset);
|
---|
247 |
|
---|
248 | #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
|
---|
249 |
|
---|
250 | int vbox_mm_init(struct vbox_private *vbox);
|
---|
251 | void vbox_mm_fini(struct vbox_private *vbox);
|
---|
252 |
|
---|
253 | int vbox_bo_create(struct drm_device *dev, int size, int align,
|
---|
254 | uint32_t flags, struct vbox_bo **pvboxbo);
|
---|
255 |
|
---|
256 | int vbox_gem_create(struct drm_device *dev,
|
---|
257 | u32 size, bool iskernel,
|
---|
258 | struct drm_gem_object **obj);
|
---|
259 |
|
---|
260 | int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr);
|
---|
261 | int vbox_bo_unpin(struct vbox_bo *bo);
|
---|
262 |
|
---|
263 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
|
---|
264 | {
|
---|
265 | int ret;
|
---|
266 |
|
---|
267 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, 0);
|
---|
268 | if (ret)
|
---|
269 | {
|
---|
270 | if (ret != -ERESTARTSYS && ret != -EBUSY)
|
---|
271 | DRM_ERROR("reserve failed %p\n", bo);
|
---|
272 | return ret;
|
---|
273 | }
|
---|
274 | return 0;
|
---|
275 | }
|
---|
276 |
|
---|
277 | static inline void vbox_bo_unreserve(struct vbox_bo *bo)
|
---|
278 | {
|
---|
279 | ttm_bo_unreserve(&bo->bo);
|
---|
280 | }
|
---|
281 |
|
---|
282 | int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait);
|
---|
283 | void vbox_bo_unreserve(struct vbox_bo *bo);
|
---|
284 | void vbox_ttm_placement(struct vbox_bo *bo, int domain);
|
---|
285 | int vbox_bo_push_sysram(struct vbox_bo *bo);
|
---|
286 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
|
---|
287 |
|
---|
288 | /* vbox post */
|
---|
289 | void vbox_post_gpu(struct drm_device *dev);
|
---|
290 | #endif
|
---|