VirtualBox

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

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

Additions/linux/drm: lots of formatting changes to match kernel style.
bugref:8524: Additions/linux: play nicely with distribution-installed Additions

This change makes a lot of formatting changes to the Linux Additions drm
driver, with no intended changes to functionality, and much of the
formatting change done using the sed script which installs the driver
sources to the Additions archive. Hans de Goede's clean-up of the driver for
submission to staging is the base for these changes.

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