VirtualBox

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

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

Linux/GA: ticketref:19391 RedHat 8.2-rc1 kernel DRM backports to 4.18.0 kernels break Virtualbox GAs

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

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