VirtualBox

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

最後變更 在這個檔案從66940是 66544,由 vboxsync 提交於 8 年 前

bugref:8524: Additions/linux: play nicely with distribution-installed Additions
Change header of files which are expected to end up in the Linux kernel to the MIT licence to simplify life for people wanting to port vboxvideo to other kernels and to simplify synchronising changes back to VirtualBox. Update author information in files which have it, but do not add it to files which do not.

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

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