VirtualBox

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

Last change on this file since 71947 was 71947, checked in by vboxsync, 7 years ago

Additions/linux/drm: update drm driver to work with EL7.5, standard kernel.
No bugref.

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