VirtualBox

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

Last change on this file since 78314 was 77850, checked in by vboxsync, 6 years ago

Additions/linux/vboxvideo: make driver work with Linux 5.0 and 5.1.
bugref:4567: Linux kernel driver maintenance.
This change mainly consists of adaptations of the parts of the following
kernel changes which affect staging/vboxvideo:

commit c58ac649e3553c23a9bafba8c2e5d040aee87484
Author: Cihangir Akturk <cakturk@…>
Date: Fri Aug 11 15:33:14 2017 +0300

drm: vboxvideo: switch to drm_*_get(), drm_*_put() helpers

Author: Christian König <christian.koenig@…>
Date: Fri Oct 19 13:49:05 2018 +0200

drm/ttm: use a static ttm_mem_global instance

commit a64f784bb14a56bfdfad2dc397dd67e4564e3a29
Author: Christian König <christian.koenig@…>
Date: Fri Oct 19 16:55:26 2018 +0200

drm/ttm: initialize globals during device init (v2)

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