VirtualBox

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

Last change on this file since 74615 was 74615, checked in by vboxsync, 6 years ago

Additions/linux/vboxvideo: fix building on various EL 7 minor releases.
bugref:4567: Linux kernel driver maintenance

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

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