VirtualBox

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

Last change on this file since 83935 was 83073, checked in by vboxsync, 5 years ago

GA/Linux: ticketref:19145 kernel 5.5-rc1/rc2 - we need changes, portions contributed by Larry Finger

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