VirtualBox

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

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

ticketref:19521 Can't build kernel modules on SLES12 SP5

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