1 | /* $Id: vbox_drv.h 68297 2017-08-04 10:25:39Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Additions Linux kernel video driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2017 Oracle Corporation
|
---|
8 | * This file is based on ast_drv.h
|
---|
9 | * Copyright 2012 Red Hat Inc.
|
---|
10 | *
|
---|
11 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
12 | * copy of this software and associated documentation files (the
|
---|
13 | * "Software"), to deal in the Software without restriction, including
|
---|
14 | * without limitation the rights to use, copy, modify, merge, publish,
|
---|
15 | * distribute, sub license, and/or sell copies of the Software, and to
|
---|
16 | * permit persons to whom the Software is furnished to do so, subject to
|
---|
17 | * the following conditions:
|
---|
18 | *
|
---|
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
---|
22 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
---|
23 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
---|
24 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
---|
25 | * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
26 | *
|
---|
27 | * The above copyright notice and this permission notice (including the
|
---|
28 | * next paragraph) shall be included in all copies or substantial portions
|
---|
29 | * of the Software.
|
---|
30 | *
|
---|
31 | * Authors: Dave Airlie <[email protected]>
|
---|
32 | * Michael Thayer <[email protected],
|
---|
33 | * Hans de Goede <[email protected]>
|
---|
34 | */
|
---|
35 | #ifndef __VBOX_DRV_H__
|
---|
36 | #define __VBOX_DRV_H__
|
---|
37 |
|
---|
38 | #define LOG_GROUP LOG_GROUP_DEV_VGA
|
---|
39 |
|
---|
40 | #include <VBoxVideoGuest.h>
|
---|
41 |
|
---|
42 | #include <drm/drmP.h>
|
---|
43 | #include <drm/drm_fb_helper.h>
|
---|
44 |
|
---|
45 | #include <drm/ttm/ttm_bo_api.h>
|
---|
46 | #include <drm/ttm/ttm_bo_driver.h>
|
---|
47 | #include <drm/ttm/ttm_placement.h>
|
---|
48 | #include <drm/ttm/ttm_memory.h>
|
---|
49 | #include <drm/ttm/ttm_module.h>
|
---|
50 |
|
---|
51 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
52 | # if RHEL_MAJOR == 7 && RHEL_MINOR >= 3
|
---|
53 | # define RHEL_7
|
---|
54 | # endif
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0) || defined(RHEL_7)
|
---|
58 | #include <drm/drm_gem.h>
|
---|
59 | #endif
|
---|
60 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
---|
61 | #include <drm/drm_encoder.h>
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | #include "product-generated.h"
|
---|
65 |
|
---|
66 | #define DRIVER_AUTHOR VBOX_VENDOR
|
---|
67 |
|
---|
68 | #define DRIVER_NAME "vboxvideo"
|
---|
69 | #define DRIVER_DESC VBOX_PRODUCT " Graphics Card"
|
---|
70 | #define DRIVER_DATE "20130823"
|
---|
71 |
|
---|
72 | #define DRIVER_MAJOR 1
|
---|
73 | #define DRIVER_MINOR 0
|
---|
74 | #define DRIVER_PATCHLEVEL 0
|
---|
75 |
|
---|
76 | #define VBOX_MAX_CURSOR_WIDTH 64
|
---|
77 | #define VBOX_MAX_CURSOR_HEIGHT 64
|
---|
78 | #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
|
---|
79 | #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
|
---|
80 |
|
---|
81 | #define VBOX_MAX_SCREENS 32
|
---|
82 |
|
---|
83 | #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
|
---|
84 | VBVA_ADAPTER_INFORMATION_SIZE)
|
---|
85 | #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
|
---|
86 | #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
|
---|
87 | sizeof(HGSMIHOSTFLAGS))
|
---|
88 | #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
|
---|
89 |
|
---|
90 | struct vbox_fbdev;
|
---|
91 |
|
---|
92 | struct vbox_private {
|
---|
93 | struct drm_device *dev;
|
---|
94 |
|
---|
95 | u8 __iomem *guest_heap;
|
---|
96 | u8 __iomem *vbva_buffers;
|
---|
97 | struct gen_pool *guest_pool;
|
---|
98 | struct VBVABUFFERCONTEXT *vbva_info;
|
---|
99 | bool any_pitch;
|
---|
100 | unsigned int num_crtcs;
|
---|
101 | /** Amount of available VRAM, including space used for buffers. */
|
---|
102 | u32 full_vram_size;
|
---|
103 | /** Amount of available VRAM, not including space used for buffers. */
|
---|
104 | u32 available_vram_size;
|
---|
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; /* protects modeset and accel/vbva accesses */
|
---|
120 | bool isr_installed;
|
---|
121 | /**
|
---|
122 | * We decide whether or not user-space supports display hot-plug
|
---|
123 | * depending on whether they react to a hot-plug event after the initial
|
---|
124 | * mode query.
|
---|
125 | */
|
---|
126 | bool initial_mode_queried;
|
---|
127 | struct work_struct hotplug_work;
|
---|
128 | u32 input_mapping_width;
|
---|
129 | u32 input_mapping_height;
|
---|
130 | /**
|
---|
131 | * Is user-space using an X.Org-style layout of one large frame-buffer
|
---|
132 | * encompassing all screen ones or is the fbdev console active?
|
---|
133 | */
|
---|
134 | bool single_framebuffer;
|
---|
135 | u32 cursor_width;
|
---|
136 | u32 cursor_height;
|
---|
137 | u32 cursor_hot_x;
|
---|
138 | u32 cursor_hot_y;
|
---|
139 | size_t cursor_data_size;
|
---|
140 | u8 cursor_data[CURSOR_DATA_SIZE];
|
---|
141 | };
|
---|
142 |
|
---|
143 | #undef CURSOR_PIXEL_COUNT
|
---|
144 | #undef CURSOR_DATA_SIZE
|
---|
145 |
|
---|
146 | int vbox_driver_load(struct drm_device *dev, unsigned long flags);
|
---|
147 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
---|
148 | void vbox_driver_unload(struct drm_device *dev);
|
---|
149 | #else
|
---|
150 | int vbox_driver_unload(struct drm_device *dev);
|
---|
151 | #endif
|
---|
152 | void vbox_driver_lastclose(struct drm_device *dev);
|
---|
153 |
|
---|
154 | struct vbox_gem_object;
|
---|
155 |
|
---|
156 | #ifndef VGA_PORT_HGSMI_HOST
|
---|
157 | #define VGA_PORT_HGSMI_HOST 0x3b0
|
---|
158 | #define VGA_PORT_HGSMI_GUEST 0x3d0
|
---|
159 | #endif
|
---|
160 |
|
---|
161 | struct vbox_connector {
|
---|
162 | struct drm_connector base;
|
---|
163 | char name[32];
|
---|
164 | struct vbox_crtc *vbox_crtc;
|
---|
165 | struct {
|
---|
166 | u16 width;
|
---|
167 | u16 height;
|
---|
168 | bool disconnected;
|
---|
169 | } mode_hint;
|
---|
170 | };
|
---|
171 |
|
---|
172 | struct vbox_crtc {
|
---|
173 | struct drm_crtc base;
|
---|
174 | bool blanked;
|
---|
175 | bool disconnected;
|
---|
176 | unsigned int crtc_id;
|
---|
177 | u32 fb_offset;
|
---|
178 | bool cursor_enabled;
|
---|
179 | u16 x_hint;
|
---|
180 | u16 y_hint;
|
---|
181 | };
|
---|
182 |
|
---|
183 | struct vbox_encoder {
|
---|
184 | struct drm_encoder base;
|
---|
185 | };
|
---|
186 |
|
---|
187 | struct vbox_framebuffer {
|
---|
188 | struct drm_framebuffer base;
|
---|
189 | struct drm_gem_object *obj;
|
---|
190 | };
|
---|
191 |
|
---|
192 | struct vbox_fbdev {
|
---|
193 | struct drm_fb_helper helper;
|
---|
194 | struct vbox_framebuffer afb;
|
---|
195 | int size;
|
---|
196 | struct ttm_bo_kmap_obj mapping;
|
---|
197 | int x1, y1, x2, y2; /* dirty rect */
|
---|
198 | spinlock_t dirty_lock;
|
---|
199 | };
|
---|
200 |
|
---|
201 | #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
|
---|
202 | #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
|
---|
203 | #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
|
---|
204 | #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
|
---|
205 |
|
---|
206 | int vbox_mode_init(struct drm_device *dev);
|
---|
207 | void vbox_mode_fini(struct drm_device *dev);
|
---|
208 |
|
---|
209 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
---|
210 | #define DRM_MODE_FB_CMD drm_mode_fb_cmd
|
---|
211 | #else
|
---|
212 | #define DRM_MODE_FB_CMD drm_mode_fb_cmd2
|
---|
213 | #endif
|
---|
214 |
|
---|
215 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) && !defined(RHEL_7)
|
---|
216 | #define CRTC_FB(crtc) ((crtc)->fb)
|
---|
217 | #else
|
---|
218 | #define CRTC_FB(crtc) ((crtc)->primary->fb)
|
---|
219 | #endif
|
---|
220 |
|
---|
221 | void vbox_enable_accel(struct vbox_private *vbox);
|
---|
222 | void vbox_disable_accel(struct vbox_private *vbox);
|
---|
223 | void vbox_report_caps(struct vbox_private *vbox);
|
---|
224 |
|
---|
225 | void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
|
---|
226 | struct drm_clip_rect *rects,
|
---|
227 | unsigned int num_rects);
|
---|
228 |
|
---|
229 | int vbox_framebuffer_init(struct drm_device *dev,
|
---|
230 | struct vbox_framebuffer *vbox_fb,
|
---|
231 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || defined(RHEL_7)
|
---|
232 | const
|
---|
233 | #endif
|
---|
234 | struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
235 | struct drm_gem_object *obj);
|
---|
236 |
|
---|
237 | int vbox_fbdev_init(struct drm_device *dev);
|
---|
238 | void vbox_fbdev_fini(struct drm_device *dev);
|
---|
239 | void vbox_fbdev_set_suspend(struct drm_device *dev, int state);
|
---|
240 | void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr);
|
---|
241 |
|
---|
242 | struct vbox_bo {
|
---|
243 | struct ttm_buffer_object bo;
|
---|
244 | struct ttm_placement placement;
|
---|
245 | struct ttm_bo_kmap_obj kmap;
|
---|
246 | struct drm_gem_object gem;
|
---|
247 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && !defined(RHEL_7)
|
---|
248 | u32 placements[3];
|
---|
249 | #else
|
---|
250 | struct ttm_place placements[3];
|
---|
251 | #endif
|
---|
252 | int pin_count;
|
---|
253 | };
|
---|
254 |
|
---|
255 | #define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
|
---|
256 |
|
---|
257 | static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
|
---|
258 | {
|
---|
259 | return container_of(bo, struct vbox_bo, bo);
|
---|
260 | }
|
---|
261 |
|
---|
262 | #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
|
---|
263 |
|
---|
264 | int vbox_dumb_create(struct drm_file *file,
|
---|
265 | struct drm_device *dev,
|
---|
266 | struct drm_mode_create_dumb *args);
|
---|
267 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0) && !defined(RHEL_7)
|
---|
268 | int vbox_dumb_destroy(struct drm_file *file,
|
---|
269 | struct drm_device *dev, u32 handle);
|
---|
270 | #endif
|
---|
271 |
|
---|
272 | void vbox_gem_free_object(struct drm_gem_object *obj);
|
---|
273 | int vbox_dumb_mmap_offset(struct drm_file *file,
|
---|
274 | struct drm_device *dev,
|
---|
275 | u32 handle, u64 *offset);
|
---|
276 |
|
---|
277 | #define DRM_FILE_PAGE_OFFSET (0x10000000ULL >> PAGE_SHIFT)
|
---|
278 |
|
---|
279 | int vbox_mm_init(struct vbox_private *vbox);
|
---|
280 | void vbox_mm_fini(struct vbox_private *vbox);
|
---|
281 |
|
---|
282 | int vbox_bo_create(struct drm_device *dev, int size, int align,
|
---|
283 | u32 flags, struct vbox_bo **pvboxbo);
|
---|
284 |
|
---|
285 | int vbox_gem_create(struct drm_device *dev,
|
---|
286 | u32 size, bool iskernel, struct drm_gem_object **obj);
|
---|
287 |
|
---|
288 | int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr);
|
---|
289 | int vbox_bo_unpin(struct vbox_bo *bo);
|
---|
290 |
|
---|
291 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
|
---|
292 | {
|
---|
293 | int ret;
|
---|
294 |
|
---|
295 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0)
|
---|
296 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
|
---|
297 | #else
|
---|
298 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, 0);
|
---|
299 | #endif
|
---|
300 | if (ret) {
|
---|
301 | if (ret != -ERESTARTSYS && ret != -EBUSY)
|
---|
302 | DRM_ERROR("reserve failed %p\n", bo);
|
---|
303 | return ret;
|
---|
304 | }
|
---|
305 | return 0;
|
---|
306 | }
|
---|
307 |
|
---|
308 | static inline void vbox_bo_unreserve(struct vbox_bo *bo)
|
---|
309 | {
|
---|
310 | ttm_bo_unreserve(&bo->bo);
|
---|
311 | }
|
---|
312 |
|
---|
313 | void vbox_ttm_placement(struct vbox_bo *bo, int domain);
|
---|
314 | int vbox_bo_push_sysram(struct vbox_bo *bo);
|
---|
315 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
|
---|
316 |
|
---|
317 | /* vbox_prime.c */
|
---|
318 | int vbox_gem_prime_pin(struct drm_gem_object *obj);
|
---|
319 | void vbox_gem_prime_unpin(struct drm_gem_object *obj);
|
---|
320 | struct sg_table *vbox_gem_prime_get_sg_table(struct drm_gem_object *obj);
|
---|
321 | struct drm_gem_object *vbox_gem_prime_import_sg_table(struct drm_device *dev,
|
---|
322 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && !defined(RHEL_7)
|
---|
323 | size_t size,
|
---|
324 | #else
|
---|
325 | struct dma_buf_attachment
|
---|
326 | *attach,
|
---|
327 | #endif
|
---|
328 | struct sg_table *table);
|
---|
329 | void *vbox_gem_prime_vmap(struct drm_gem_object *obj);
|
---|
330 | void vbox_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
|
---|
331 | int vbox_gem_prime_mmap(struct drm_gem_object *obj,
|
---|
332 | struct vm_area_struct *area);
|
---|
333 |
|
---|
334 | /* vbox_irq.c */
|
---|
335 | int vbox_irq_init(struct vbox_private *vbox);
|
---|
336 | void vbox_irq_fini(struct vbox_private *vbox);
|
---|
337 | void vbox_report_hotplug(struct vbox_private *vbox);
|
---|
338 | irqreturn_t vbox_irq_handler(int irq, void *arg);
|
---|
339 |
|
---|
340 | #endif
|
---|