VirtualBox

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

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

Additions/linux/vboxvideo: switch to drm_*_get(), drm_*_put() helpers
bugref:8282: Additions/linux: track kernel changes to vboxvideo in our own tree

Use drm_*_get() and drm_*_put() helpers instead of drm_*_reference()
and drm_*_unreference() helpers.


drm_*_reference() and drm_*_unreference() functions are just
compatibility alias for drm_*_get() and drm_*_put() and should not be
used by new code. So convert all users of compatibility functions to
use the new APIs.


Generated by: scripts/coccinelle/api/drm-get-put.cocci


Signed-off-by: Cihangir Akturk <cakturk@…>
Reviewed-by: Hans de Goede <hdegoede@…>
Signed-off-by: Sean Paul <seanpaul@…>
Link: https://patchwork.freedesktop.org/patch/msgid/1502454794-28558-29-git-

send-email-cakturk@…
Adjusted by the VirtualBox team.

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