VirtualBox

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

Last change on this file since 77390 was 76976, checked in by vboxsync, 6 years ago

Additions/linux/vboxvideo: Update driver to use drm_dev_register.
bugref:8282: Additions/linux: track kernel changes to vboxvideo in our own tree

The use of load and unload hooks is deprecated. DRM drivers should
use drm_dev_alloc|drm_dev_init and drm_dev_register for initialization
and publishing.


Signed-off-by: Fabio Rafael da Rosa <fdr@…>
Reviewed-by: Nicholas Mc Guire <der.herr@…>
Signed-off-by: Greg Kroah-Hartman <gregkh@…>

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