1 | /* $Id: vbox_drv.h 69748 2017-11-18 20:56:56Z 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 <linux/version.h>
|
---|
41 |
|
---|
42 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)
|
---|
43 | # include <linux/types.h>
|
---|
44 | # include <linux/spinlock_types.h>
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <linux/genalloc.h>
|
---|
48 | #include <linux/io.h>
|
---|
49 | #include <linux/string.h>
|
---|
50 |
|
---|
51 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
52 | # if RHEL_MAJOR == 7 && RHEL_MINOR >= 4
|
---|
53 | # define RHEL_73
|
---|
54 | # define RHEL_74
|
---|
55 | # elif RHEL_MAJOR == 7 && RHEL_MINOR >= 3
|
---|
56 | # define RHEL_73
|
---|
57 | # endif
|
---|
58 | #endif
|
---|
59 |
|
---|
60 | #include <drm/drmP.h>
|
---|
61 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 18, 0) || defined(RHEL_73)
|
---|
62 | #include <drm/drm_gem.h>
|
---|
63 | #endif
|
---|
64 | #include <drm/drm_fb_helper.h>
|
---|
65 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
---|
66 | #include <drm/drm_encoder.h>
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | #include <drm/ttm/ttm_bo_api.h>
|
---|
70 | #include <drm/ttm/ttm_bo_driver.h>
|
---|
71 | #include <drm/ttm/ttm_placement.h>
|
---|
72 | #include <drm/ttm/ttm_memory.h>
|
---|
73 | #include <drm/ttm/ttm_module.h>
|
---|
74 |
|
---|
75 | #include "vboxvideo_guest.h"
|
---|
76 | #include "vboxvideo_vbe.h"
|
---|
77 | #include "hgsmi_ch_setup.h"
|
---|
78 |
|
---|
79 | #include "product-generated.h"
|
---|
80 |
|
---|
81 | #define DRIVER_AUTHOR VBOX_VENDOR
|
---|
82 |
|
---|
83 | #define DRIVER_NAME "vboxvideo"
|
---|
84 | #define DRIVER_DESC VBOX_PRODUCT " Graphics Card"
|
---|
85 | #define DRIVER_DATE "20130823"
|
---|
86 |
|
---|
87 | #define DRIVER_MAJOR 1
|
---|
88 | #define DRIVER_MINOR 0
|
---|
89 | #define DRIVER_PATCHLEVEL 0
|
---|
90 |
|
---|
91 | #define VBOX_MAX_CURSOR_WIDTH 64
|
---|
92 | #define VBOX_MAX_CURSOR_HEIGHT 64
|
---|
93 | #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
|
---|
94 | #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
|
---|
95 |
|
---|
96 | #define VBOX_MAX_SCREENS 32
|
---|
97 |
|
---|
98 | #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
|
---|
99 | VBVA_ADAPTER_INFORMATION_SIZE)
|
---|
100 | #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
|
---|
101 | #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
|
---|
102 | sizeof(HGSMIHOSTFLAGS))
|
---|
103 | #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
|
---|
104 |
|
---|
105 | struct vbox_fbdev;
|
---|
106 |
|
---|
107 | struct vbox_private {
|
---|
108 | struct drm_device *dev;
|
---|
109 |
|
---|
110 | u8 __iomem *guest_heap;
|
---|
111 | u8 __iomem *vbva_buffers;
|
---|
112 | struct gen_pool *guest_pool;
|
---|
113 | struct VBVABUFFERCONTEXT *vbva_info;
|
---|
114 | bool any_pitch;
|
---|
115 | unsigned int num_crtcs;
|
---|
116 | /** Amount of available VRAM, including space used for buffers. */
|
---|
117 | u32 full_vram_size;
|
---|
118 | /** Amount of available VRAM, not including space used for buffers. */
|
---|
119 | u32 available_vram_size;
|
---|
120 | /** Array of structures for receiving mode hints. */
|
---|
121 | VBVAMODEHINT *last_mode_hints;
|
---|
122 |
|
---|
123 | struct vbox_fbdev *fbdev;
|
---|
124 |
|
---|
125 | int fb_mtrr;
|
---|
126 |
|
---|
127 | struct {
|
---|
128 | struct drm_global_reference mem_global_ref;
|
---|
129 | struct ttm_bo_global_ref bo_global_ref;
|
---|
130 | struct ttm_bo_device bdev;
|
---|
131 | bool mm_initialised;
|
---|
132 | } ttm;
|
---|
133 |
|
---|
134 | struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
|
---|
135 | bool isr_installed;
|
---|
136 | /**
|
---|
137 | * We decide whether or not user-space supports display hot-plug
|
---|
138 | * depending on whether they react to a hot-plug event after the initial
|
---|
139 | * mode query.
|
---|
140 | */
|
---|
141 | bool initial_mode_queried;
|
---|
142 | struct work_struct hotplug_work;
|
---|
143 | u32 input_mapping_width;
|
---|
144 | u32 input_mapping_height;
|
---|
145 | /**
|
---|
146 | * Is user-space using an X.Org-style layout of one large frame-buffer
|
---|
147 | * encompassing all screen ones or is the fbdev console active?
|
---|
148 | */
|
---|
149 | bool single_framebuffer;
|
---|
150 | u32 cursor_width;
|
---|
151 | u32 cursor_height;
|
---|
152 | u32 cursor_hot_x;
|
---|
153 | u32 cursor_hot_y;
|
---|
154 | size_t cursor_data_size;
|
---|
155 | u8 cursor_data[CURSOR_DATA_SIZE];
|
---|
156 | };
|
---|
157 |
|
---|
158 | #undef CURSOR_PIXEL_COUNT
|
---|
159 | #undef CURSOR_DATA_SIZE
|
---|
160 |
|
---|
161 | int vbox_driver_load(struct drm_device *dev, unsigned long flags);
|
---|
162 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
|
---|
163 | void vbox_driver_unload(struct drm_device *dev);
|
---|
164 | #else
|
---|
165 | int vbox_driver_unload(struct drm_device *dev);
|
---|
166 | #endif
|
---|
167 | void vbox_driver_lastclose(struct drm_device *dev);
|
---|
168 |
|
---|
169 | struct vbox_gem_object;
|
---|
170 |
|
---|
171 | #ifndef VGA_PORT_HGSMI_HOST
|
---|
172 | #define VGA_PORT_HGSMI_HOST 0x3b0
|
---|
173 | #define VGA_PORT_HGSMI_GUEST 0x3d0
|
---|
174 | #endif
|
---|
175 |
|
---|
176 | struct vbox_connector {
|
---|
177 | struct drm_connector base;
|
---|
178 | char name[32];
|
---|
179 | struct vbox_crtc *vbox_crtc;
|
---|
180 | struct {
|
---|
181 | u32 width;
|
---|
182 | u32 height;
|
---|
183 | bool disconnected;
|
---|
184 | } mode_hint;
|
---|
185 | };
|
---|
186 |
|
---|
187 | struct vbox_crtc {
|
---|
188 | struct drm_crtc base;
|
---|
189 | bool blanked;
|
---|
190 | bool disconnected;
|
---|
191 | unsigned int crtc_id;
|
---|
192 | u32 fb_offset;
|
---|
193 | bool cursor_enabled;
|
---|
194 | u32 x_hint;
|
---|
195 | u32 y_hint;
|
---|
196 | };
|
---|
197 |
|
---|
198 | struct vbox_encoder {
|
---|
199 | struct drm_encoder base;
|
---|
200 | };
|
---|
201 |
|
---|
202 | struct vbox_framebuffer {
|
---|
203 | struct drm_framebuffer base;
|
---|
204 | struct drm_gem_object *obj;
|
---|
205 | };
|
---|
206 |
|
---|
207 | struct vbox_fbdev {
|
---|
208 | struct drm_fb_helper helper;
|
---|
209 | struct vbox_framebuffer afb;
|
---|
210 | int size;
|
---|
211 | struct ttm_bo_kmap_obj mapping;
|
---|
212 | int x1, y1, x2, y2; /* dirty rect */
|
---|
213 | spinlock_t dirty_lock;
|
---|
214 | };
|
---|
215 |
|
---|
216 | #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
|
---|
217 | #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
|
---|
218 | #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
|
---|
219 | #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
|
---|
220 |
|
---|
221 | int vbox_mode_init(struct drm_device *dev);
|
---|
222 | void vbox_mode_fini(struct drm_device *dev);
|
---|
223 |
|
---|
224 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)
|
---|
225 | #define DRM_MODE_FB_CMD drm_mode_fb_cmd
|
---|
226 | #else
|
---|
227 | #define DRM_MODE_FB_CMD drm_mode_fb_cmd2
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 15, 0) && !defined(RHEL_73)
|
---|
231 | #define CRTC_FB(crtc) ((crtc)->fb)
|
---|
232 | #else
|
---|
233 | #define CRTC_FB(crtc) ((crtc)->primary->fb)
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | void vbox_enable_accel(struct vbox_private *vbox);
|
---|
237 | void vbox_disable_accel(struct vbox_private *vbox);
|
---|
238 | void vbox_report_caps(struct vbox_private *vbox);
|
---|
239 |
|
---|
240 | void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
|
---|
241 | struct drm_clip_rect *rects,
|
---|
242 | unsigned int num_rects);
|
---|
243 |
|
---|
244 | int vbox_framebuffer_init(struct drm_device *dev,
|
---|
245 | struct vbox_framebuffer *vbox_fb,
|
---|
246 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 5, 0) || defined(RHEL_73)
|
---|
247 | const
|
---|
248 | #endif
|
---|
249 | struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
250 | struct drm_gem_object *obj);
|
---|
251 |
|
---|
252 | int vbox_fbdev_init(struct drm_device *dev);
|
---|
253 | void vbox_fbdev_fini(struct drm_device *dev);
|
---|
254 | void vbox_fbdev_set_suspend(struct drm_device *dev, int state);
|
---|
255 |
|
---|
256 | struct vbox_bo {
|
---|
257 | struct ttm_buffer_object bo;
|
---|
258 | struct ttm_placement placement;
|
---|
259 | struct ttm_bo_kmap_obj kmap;
|
---|
260 | struct drm_gem_object gem;
|
---|
261 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && !defined(RHEL_73)
|
---|
262 | u32 placements[3];
|
---|
263 | #else
|
---|
264 | struct ttm_place placements[3];
|
---|
265 | #endif
|
---|
266 | int pin_count;
|
---|
267 | };
|
---|
268 |
|
---|
269 | #define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
|
---|
270 |
|
---|
271 | static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
|
---|
272 | {
|
---|
273 | return container_of(bo, struct vbox_bo, bo);
|
---|
274 | }
|
---|
275 |
|
---|
276 | #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
|
---|
277 |
|
---|
278 | int vbox_dumb_create(struct drm_file *file,
|
---|
279 | struct drm_device *dev,
|
---|
280 | struct drm_mode_create_dumb *args);
|
---|
281 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0) && !defined(RHEL_73)
|
---|
282 | int vbox_dumb_destroy(struct drm_file *file,
|
---|
283 | struct drm_device *dev, u32 handle);
|
---|
284 | #endif
|
---|
285 |
|
---|
286 | void vbox_gem_free_object(struct drm_gem_object *obj);
|
---|
287 | int vbox_dumb_mmap_offset(struct drm_file *file,
|
---|
288 | struct drm_device *dev,
|
---|
289 | u32 handle, u64 *offset);
|
---|
290 |
|
---|
291 | #define DRM_FILE_PAGE_OFFSET (0x10000000ULL >> PAGE_SHIFT)
|
---|
292 |
|
---|
293 | int vbox_mm_init(struct vbox_private *vbox);
|
---|
294 | void vbox_mm_fini(struct vbox_private *vbox);
|
---|
295 |
|
---|
296 | int vbox_bo_create(struct drm_device *dev, int size, int align,
|
---|
297 | u32 flags, struct vbox_bo **pvboxbo);
|
---|
298 |
|
---|
299 | int vbox_gem_create(struct drm_device *dev,
|
---|
300 | u32 size, bool iskernel, struct drm_gem_object **obj);
|
---|
301 |
|
---|
302 | int vbox_bo_pin(struct vbox_bo *bo, u32 pl_flag, u64 *gpu_addr);
|
---|
303 | int vbox_bo_unpin(struct vbox_bo *bo);
|
---|
304 |
|
---|
305 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
|
---|
306 | {
|
---|
307 | int ret;
|
---|
308 |
|
---|
309 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) || defined(RHEL_74)
|
---|
310 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
|
---|
311 | #else
|
---|
312 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, 0);
|
---|
313 | #endif
|
---|
314 | if (ret) {
|
---|
315 | if (ret != -ERESTARTSYS && ret != -EBUSY)
|
---|
316 | DRM_ERROR("reserve failed %p\n", bo);
|
---|
317 | return ret;
|
---|
318 | }
|
---|
319 | return 0;
|
---|
320 | }
|
---|
321 |
|
---|
322 | static inline void vbox_bo_unreserve(struct vbox_bo *bo)
|
---|
323 | {
|
---|
324 | ttm_bo_unreserve(&bo->bo);
|
---|
325 | }
|
---|
326 |
|
---|
327 | void vbox_ttm_placement(struct vbox_bo *bo, int domain);
|
---|
328 | int vbox_bo_push_sysram(struct vbox_bo *bo);
|
---|
329 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
|
---|
330 |
|
---|
331 | /* vbox_prime.c */
|
---|
332 | int vbox_gem_prime_pin(struct drm_gem_object *obj);
|
---|
333 | void vbox_gem_prime_unpin(struct drm_gem_object *obj);
|
---|
334 | struct sg_table *vbox_gem_prime_get_sg_table(struct drm_gem_object *obj);
|
---|
335 | struct drm_gem_object *vbox_gem_prime_import_sg_table(struct drm_device *dev,
|
---|
336 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) && !defined(RHEL_73)
|
---|
337 | size_t size,
|
---|
338 | #else
|
---|
339 | struct dma_buf_attachment
|
---|
340 | *attach,
|
---|
341 | #endif
|
---|
342 | struct sg_table *table);
|
---|
343 | void *vbox_gem_prime_vmap(struct drm_gem_object *obj);
|
---|
344 | void vbox_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
|
---|
345 | int vbox_gem_prime_mmap(struct drm_gem_object *obj,
|
---|
346 | struct vm_area_struct *area);
|
---|
347 |
|
---|
348 | /* vbox_irq.c */
|
---|
349 | int vbox_irq_init(struct vbox_private *vbox);
|
---|
350 | void vbox_irq_fini(struct vbox_private *vbox);
|
---|
351 | void vbox_report_hotplug(struct vbox_private *vbox);
|
---|
352 | irqreturn_t vbox_irq_handler(int irq, void *arg);
|
---|
353 |
|
---|
354 | /* vbox_hgsmi.c */
|
---|
355 | void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
|
---|
356 | u8 channel, u16 channel_info);
|
---|
357 | void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
|
---|
358 | int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
|
---|
359 |
|
---|
360 | static inline void vbox_write_ioport(u16 index, u16 data)
|
---|
361 | {
|
---|
362 | outw(index, VBE_DISPI_IOPORT_INDEX);
|
---|
363 | outw(data, VBE_DISPI_IOPORT_DATA);
|
---|
364 | }
|
---|
365 |
|
---|
366 | #endif
|
---|