VirtualBox

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

最後變更 在這個檔案從80435是 79025,由 vboxsync 提交於 6 年 前

Linux/host and guest drivers: support more openSUSE 15.0 and 15.1 kernels.

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