VirtualBox

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

Last change on this file since 76199 was 75402, checked in by vboxsync, 6 years ago

Addiitons/linux/vboxvideo: make vboxvideo work with EL7.6 standard kernel.
bugref:4567: Linux kernel driver maintenance.
Contributed by Robert Conde. Many thanks!

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette