VirtualBox

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

最後變更 在這個檔案從81245是 80712,由 vboxsync 提交於 5 年 前

Additions/linux: ticketref:18917: VBox 6.0.10 GAs fail to compile on Red Hat/CentOS/OL 7.7; also Red Hat 8.1 Beta

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

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