1 | /* $Id: vbox_drv.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Additions Linux kernel video driver
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2024 Oracle and/or its affiliates.
|
---|
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 |
|
---|
36 | #ifndef GA_INCLUDED_SRC_linux_drm_vbox_drv_h
|
---|
37 | #define GA_INCLUDED_SRC_linux_drm_vbox_drv_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <linux/version.h>
|
---|
43 |
|
---|
44 | /* iprt/linux/version.h copy - start */
|
---|
45 | /** @def RTLNX_VER_MIN
|
---|
46 | * Evaluates to true if the linux kernel version is equal or higher to the
|
---|
47 | * one specfied. */
|
---|
48 | #define RTLNX_VER_MIN(a_Major, a_Minor, a_Patch) \
|
---|
49 | (LINUX_VERSION_CODE >= KERNEL_VERSION(a_Major, a_Minor, a_Patch))
|
---|
50 |
|
---|
51 | /** @def RTLNX_VER_MAX
|
---|
52 | * Evaluates to true if the linux kernel version is less to the one specfied
|
---|
53 | * (exclusive). */
|
---|
54 | #define RTLNX_VER_MAX(a_Major, a_Minor, a_Patch) \
|
---|
55 | (LINUX_VERSION_CODE < KERNEL_VERSION(a_Major, a_Minor, a_Patch))
|
---|
56 |
|
---|
57 | /** @def RTLNX_VER_RANGE
|
---|
58 | * Evaluates to true if the linux kernel version is equal or higher to the given
|
---|
59 | * minimum version and less (but not equal) to the maximum version (exclusive). */
|
---|
60 | #define RTLNX_VER_RANGE(a_MajorMin, a_MinorMin, a_PatchMin, a_MajorMax, a_MinorMax, a_PatchMax) \
|
---|
61 | ( LINUX_VERSION_CODE >= KERNEL_VERSION(a_MajorMin, a_MinorMin, a_PatchMin) \
|
---|
62 | && LINUX_VERSION_CODE < KERNEL_VERSION(a_MajorMax, a_MinorMax, a_PatchMax) )
|
---|
63 |
|
---|
64 |
|
---|
65 | /** @def RTLNX_RHEL_MIN
|
---|
66 | * Require a minium RedHat release.
|
---|
67 | * @param a_iMajor The major release number (RHEL_MAJOR).
|
---|
68 | * @param a_iMinor The minor release number (RHEL_MINOR).
|
---|
69 | * @sa RTLNX_RHEL_MAX, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
|
---|
70 | */
|
---|
71 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
72 | # define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) \
|
---|
73 | ((RHEL_MAJOR) > (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor)))
|
---|
74 | #else
|
---|
75 | # define RTLNX_RHEL_MIN(a_iMajor, a_iMinor) (0)
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | /** @def RTLNX_RHEL_MAX
|
---|
79 | * Require a maximum RedHat release, true for all RHEL versions below it.
|
---|
80 | * @param a_iMajor The major release number (RHEL_MAJOR).
|
---|
81 | * @param a_iMinor The minor release number (RHEL_MINOR).
|
---|
82 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_RANGE, RTLNX_RHEL_MAJ_PREREQ
|
---|
83 | */
|
---|
84 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
85 | # define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) \
|
---|
86 | ((RHEL_MAJOR) < (a_iMajor) || ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) < (a_iMinor)))
|
---|
87 | #else
|
---|
88 | # define RTLNX_RHEL_MAX(a_iMajor, a_iMinor) (0)
|
---|
89 | #endif
|
---|
90 |
|
---|
91 | /** @def RTLNX_RHEL_RANGE
|
---|
92 | * Check that it's a RedHat kernel in the given version range.
|
---|
93 | * The max version is exclusive, the minimum inclusive.
|
---|
94 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX, RTLNX_RHEL_MAJ_PREREQ
|
---|
95 | */
|
---|
96 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
97 | # define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) \
|
---|
98 | (RTLNX_RHEL_MIN(a_iMajorMin, a_iMinorMin) && RTLNX_RHEL_MAX(a_iMajorMax, a_iMinorMax))
|
---|
99 | #else
|
---|
100 | # define RTLNX_RHEL_RANGE(a_iMajorMin, a_iMinorMin, a_iMajorMax, a_iMinorMax) (0)
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /** @def RTLNX_RHEL_MAJ_PREREQ
|
---|
104 | * Require a minimum minor release number for the given RedHat release.
|
---|
105 | * @param a_iMajor RHEL_MAJOR must _equal_ this.
|
---|
106 | * @param a_iMinor RHEL_MINOR must be greater or equal to this.
|
---|
107 | * @sa RTLNX_RHEL_MIN, RTLNX_RHEL_MAX
|
---|
108 | */
|
---|
109 | #if defined(RHEL_MAJOR) && defined(RHEL_MINOR)
|
---|
110 | # define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) ((RHEL_MAJOR) == (a_iMajor) && (RHEL_MINOR) >= (a_iMinor))
|
---|
111 | #else
|
---|
112 | # define RTLNX_RHEL_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
|
---|
113 | #endif
|
---|
114 |
|
---|
115 |
|
---|
116 | /** @def RTLNX_SUSE_MAJ_PREREQ
|
---|
117 | * Require a minimum minor release number for the given SUSE release.
|
---|
118 | * @param a_iMajor CONFIG_SUSE_VERSION must _equal_ this.
|
---|
119 | * @param a_iMinor CONFIG_SUSE_PATCHLEVEL must be greater or equal to this.
|
---|
120 | */
|
---|
121 | #if defined(CONFIG_SUSE_VERSION) && defined(CONFIG_SUSE_PATCHLEVEL)
|
---|
122 | # define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) ((CONFIG_SUSE_VERSION) == (a_iMajor) && (CONFIG_SUSE_PATCHLEVEL) >= (a_iMinor))
|
---|
123 | #else
|
---|
124 | # define RTLNX_SUSE_MAJ_PREREQ(a_iMajor, a_iMinor) (0)
|
---|
125 | #endif
|
---|
126 | /* iprt/linux/version.h copy - end */
|
---|
127 |
|
---|
128 | #if RTLNX_VER_MAX(4,5,0)
|
---|
129 | # include <linux/types.h>
|
---|
130 | # include <linux/spinlock_types.h>
|
---|
131 | #endif
|
---|
132 |
|
---|
133 | #include <linux/genalloc.h>
|
---|
134 | #include <linux/io.h>
|
---|
135 | #include <linux/string.h>
|
---|
136 | #include <linux/pci.h>
|
---|
137 |
|
---|
138 |
|
---|
139 | #if RTLNX_VER_MAX(3,14,0) || RTLNX_RHEL_MAJ_PREREQ(7,1)
|
---|
140 | #define U8_MAX ((u8)~0U)
|
---|
141 | #define S8_MAX ((s8)(U8_MAX>>1))
|
---|
142 | #define S8_MIN ((s8)(-S8_MAX - 1))
|
---|
143 | #define U16_MAX ((u16)~0U)
|
---|
144 | #define S16_MAX ((s16)(U16_MAX>>1))
|
---|
145 | #define S16_MIN ((s16)(-S16_MAX - 1))
|
---|
146 | #define U32_MAX ((u32)~0U)
|
---|
147 | #define S32_MAX ((s32)(U32_MAX>>1))
|
---|
148 | #define S32_MIN ((s32)(-S32_MAX - 1))
|
---|
149 | #define U64_MAX ((u64)~0ULL)
|
---|
150 | #define S64_MAX ((s64)(U64_MAX>>1))
|
---|
151 | #define S64_MIN ((s64)(-S64_MAX - 1))
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | #if RTLNX_VER_MIN(5,5,0) || RTLNX_RHEL_MIN(8,3) || RTLNX_SUSE_MAJ_PREREQ(15,3)
|
---|
155 | # include <drm/drm_file.h>
|
---|
156 | # include <drm/drm_drv.h>
|
---|
157 | # include <drm/drm_device.h>
|
---|
158 | # include <drm/drm_ioctl.h>
|
---|
159 | # include <drm/drm_fourcc.h>
|
---|
160 | # if RTLNX_VER_MAX(5,15,0) && !RTLNX_RHEL_RANGE(8,7, 8,99) && !RTLNX_RHEL_MAJ_PREREQ(9,1) && !RTLNX_SUSE_MAJ_PREREQ(15,5)
|
---|
161 | # include <drm/drm_irq.h>
|
---|
162 | # endif
|
---|
163 | # include <drm/drm_vblank.h>
|
---|
164 | #else /* < 5.5.0 || RHEL < 8.3 || SLES < 15-SP3 */
|
---|
165 | # include <drm/drmP.h>
|
---|
166 | #endif
|
---|
167 | #if RTLNX_VER_MIN(4,11,0) || RTLNX_RHEL_MAJ_PREREQ(7,5)
|
---|
168 | # include <drm/drm_encoder.h>
|
---|
169 | #endif
|
---|
170 | #include <drm/drm_fb_helper.h>
|
---|
171 | #if RTLNX_VER_MIN(3,18,0) || RTLNX_RHEL_MAJ_PREREQ(7,2)
|
---|
172 | # include <drm/drm_gem.h>
|
---|
173 | #endif
|
---|
174 |
|
---|
175 | #if RTLNX_VER_MIN(6,3,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
176 | # include <drm/ttm/ttm_bo.h>
|
---|
177 | #else
|
---|
178 | # include <drm/ttm/ttm_bo_api.h>
|
---|
179 | # include <drm/ttm/ttm_bo_driver.h>
|
---|
180 | #endif
|
---|
181 | #include <drm/ttm/ttm_placement.h>
|
---|
182 | #if RTLNX_VER_MAX(5,13,0) && !RTLNX_RHEL_RANGE(8,6, 8,99)
|
---|
183 | # include <drm/ttm/ttm_memory.h>
|
---|
184 | #endif
|
---|
185 | #if RTLNX_VER_MAX(5,12,0) && !RTLNX_RHEL_MAJ_PREREQ(8,5)
|
---|
186 | # include <drm/ttm/ttm_module.h>
|
---|
187 | #endif
|
---|
188 | #if RTLNX_VER_MIN(5,10,0)
|
---|
189 | # include <drm/ttm/ttm_resource.h>
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #if RTLNX_VER_MIN(6,0,0) || RTLNX_RHEL_RANGE(8,8, 8,99) || RTLNX_RHEL_MAJ_PREREQ(9,2) || RTLNX_SUSE_MAJ_PREREQ(15,5)
|
---|
193 | # include <drm/drm_framebuffer.h>
|
---|
194 | #endif
|
---|
195 |
|
---|
196 | #include "vboxvideo_guest.h"
|
---|
197 | #include "vboxvideo_vbe.h"
|
---|
198 | #include "hgsmi_ch_setup.h"
|
---|
199 |
|
---|
200 | #include "product-generated.h"
|
---|
201 |
|
---|
202 | #if RTLNX_VER_MAX(4,12,0) && !RTLNX_RHEL_MAJ_PREREQ(7,5)
|
---|
203 | static inline void drm_gem_object_put_unlocked(struct drm_gem_object *obj)
|
---|
204 | {
|
---|
205 | drm_gem_object_unreference_unlocked(obj);
|
---|
206 | }
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | #if RTLNX_VER_MAX(4,12,0) && !RTLNX_RHEL_MAJ_PREREQ(7,5)
|
---|
210 | static inline void drm_gem_object_put(struct drm_gem_object *obj)
|
---|
211 | {
|
---|
212 | drm_gem_object_unreference(obj);
|
---|
213 | }
|
---|
214 | #endif
|
---|
215 |
|
---|
216 | #define DRIVER_AUTHOR VBOX_VENDOR
|
---|
217 |
|
---|
218 | #define DRIVER_NAME "vboxvideo"
|
---|
219 | #define DRIVER_DESC VBOX_PRODUCT " Graphics Card"
|
---|
220 | #define DRIVER_DATE "20130823"
|
---|
221 |
|
---|
222 | #define DRIVER_MAJOR 1
|
---|
223 | #define DRIVER_MINOR 0
|
---|
224 | #define DRIVER_PATCHLEVEL 0
|
---|
225 |
|
---|
226 | #define VBOX_MAX_CURSOR_WIDTH 64
|
---|
227 | #define VBOX_MAX_CURSOR_HEIGHT 64
|
---|
228 | #define CURSOR_PIXEL_COUNT (VBOX_MAX_CURSOR_WIDTH * VBOX_MAX_CURSOR_HEIGHT)
|
---|
229 | #define CURSOR_DATA_SIZE (CURSOR_PIXEL_COUNT * 4 + CURSOR_PIXEL_COUNT / 8)
|
---|
230 |
|
---|
231 | #define VBOX_MAX_SCREENS 32
|
---|
232 |
|
---|
233 | #define GUEST_HEAP_OFFSET(vbox) ((vbox)->full_vram_size - \
|
---|
234 | VBVA_ADAPTER_INFORMATION_SIZE)
|
---|
235 | #define GUEST_HEAP_SIZE VBVA_ADAPTER_INFORMATION_SIZE
|
---|
236 | #define GUEST_HEAP_USABLE_SIZE (VBVA_ADAPTER_INFORMATION_SIZE - \
|
---|
237 | sizeof(HGSMIHOSTFLAGS))
|
---|
238 | #define HOST_FLAGS_OFFSET GUEST_HEAP_USABLE_SIZE
|
---|
239 |
|
---|
240 | /** Field "pdev" of struct drm_device was removed in 5.14. This macro
|
---|
241 | * transparently handles this change. Input argument is a pointer
|
---|
242 | * to struct drm_device. */
|
---|
243 | #if RTLNX_VER_MIN(5,14,0) || RTLNX_RHEL_RANGE(8,6, 8,99)
|
---|
244 | # define VBOX_DRM_TO_PCI_DEV(_dev) to_pci_dev(_dev->dev)
|
---|
245 | #else
|
---|
246 | # define VBOX_DRM_TO_PCI_DEV(_dev) _dev->pdev
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | /** Field "num_pages" of struct ttm_resource was renamed to "size" in 6.2 and
|
---|
250 | * now represents number of bytes. This macro handles this change. Input
|
---|
251 | * argument is a pointer to struct ttm_resource. */
|
---|
252 | #if RTLNX_VER_MIN(6,2,0) || RTLNX_RHEL_RANGE(8,9, 8,99) || RTLNX_RHEL_RANGE(9,3, 9,99)
|
---|
253 | # define VBOX_BO_RESOURCE_NUM_PAGES(_resource) PFN_UP(_resource->size)
|
---|
254 | #else
|
---|
255 | # define VBOX_BO_RESOURCE_NUM_PAGES(_resource) _resource->num_pages
|
---|
256 | #endif
|
---|
257 |
|
---|
258 | /** How frequently we refresh if the guest is not providing dirty rectangles. */
|
---|
259 | #define VBOX_REFRESH_PERIOD (HZ / 2)
|
---|
260 |
|
---|
261 | #if RTLNX_VER_MAX(3,13,0) && !RTLNX_RHEL_MAJ_PREREQ(7,2)
|
---|
262 | static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size,
|
---|
263 | gfp_t flags)
|
---|
264 | {
|
---|
265 | return devm_kzalloc(dev, n * size, flags);
|
---|
266 | }
|
---|
267 | #endif
|
---|
268 |
|
---|
269 | struct vbox_fbdev;
|
---|
270 |
|
---|
271 | struct vbox_private {
|
---|
272 | struct drm_device *dev;
|
---|
273 |
|
---|
274 | u8 __iomem *guest_heap;
|
---|
275 | u8 __iomem *vbva_buffers;
|
---|
276 | struct gen_pool *guest_pool;
|
---|
277 | struct VBVABUFFERCONTEXT *vbva_info;
|
---|
278 | bool any_pitch;
|
---|
279 | u32 num_crtcs;
|
---|
280 | /** Amount of available VRAM, including space used for buffers. */
|
---|
281 | u32 full_vram_size;
|
---|
282 | /** Amount of available VRAM, not including space used for buffers. */
|
---|
283 | u32 available_vram_size;
|
---|
284 | /** Array of structures for receiving mode hints. */
|
---|
285 | VBVAMODEHINT *last_mode_hints;
|
---|
286 |
|
---|
287 | struct vbox_fbdev *fbdev;
|
---|
288 |
|
---|
289 | int fb_mtrr;
|
---|
290 |
|
---|
291 | struct {
|
---|
292 | #if RTLNX_VER_MAX(5,0,0) && !RTLNX_RHEL_MAJ_PREREQ(7,7) && !RTLNX_RHEL_MAJ_PREREQ(8,1)
|
---|
293 | struct drm_global_reference mem_global_ref;
|
---|
294 | struct ttm_bo_global_ref bo_global_ref;
|
---|
295 | #endif
|
---|
296 | #if RTLNX_VER_MIN(5,13,0) || RTLNX_RHEL_RANGE(8,6, 8,99)
|
---|
297 | struct ttm_device bdev;
|
---|
298 | #else
|
---|
299 | struct ttm_bo_device bdev;
|
---|
300 | #endif
|
---|
301 | bool mm_initialised;
|
---|
302 | } ttm;
|
---|
303 |
|
---|
304 | struct mutex hw_mutex; /* protects modeset and accel/vbva accesses */
|
---|
305 | /**
|
---|
306 | * We decide whether or not user-space supports display hot-plug
|
---|
307 | * depending on whether they react to a hot-plug event after the initial
|
---|
308 | * mode query.
|
---|
309 | */
|
---|
310 | bool initial_mode_queried;
|
---|
311 | /**
|
---|
312 | * Do we know that the current user can send us dirty rectangle information?
|
---|
313 | * If not, do periodic refreshes until we do know.
|
---|
314 | */
|
---|
315 | bool need_refresh_timer;
|
---|
316 | /**
|
---|
317 | * As long as the user is not sending us dirty rectangle information,
|
---|
318 | * refresh the whole screen at regular intervals.
|
---|
319 | */
|
---|
320 | struct delayed_work refresh_work;
|
---|
321 | struct work_struct hotplug_work;
|
---|
322 | u32 input_mapping_width;
|
---|
323 | u32 input_mapping_height;
|
---|
324 | /**
|
---|
325 | * Is user-space using an X.Org-style layout of one large frame-buffer
|
---|
326 | * encompassing all screen ones or is the fbdev console active?
|
---|
327 | */
|
---|
328 | bool single_framebuffer;
|
---|
329 | u32 cursor_width;
|
---|
330 | u32 cursor_height;
|
---|
331 | u32 cursor_hot_x;
|
---|
332 | u32 cursor_hot_y;
|
---|
333 | size_t cursor_data_size;
|
---|
334 | u8 cursor_data[CURSOR_DATA_SIZE];
|
---|
335 | };
|
---|
336 |
|
---|
337 | #undef CURSOR_PIXEL_COUNT
|
---|
338 | #undef CURSOR_DATA_SIZE
|
---|
339 |
|
---|
340 | #if RTLNX_VER_MIN(4,19,0) || RTLNX_RHEL_MIN(8,3)
|
---|
341 | int vbox_driver_load(struct drm_device *dev);
|
---|
342 | #else
|
---|
343 | int vbox_driver_load(struct drm_device *dev, unsigned long flags);
|
---|
344 | #endif
|
---|
345 | #if RTLNX_VER_MIN(4,11,0) || RTLNX_RHEL_MAJ_PREREQ(7,5)
|
---|
346 | void vbox_driver_unload(struct drm_device *dev);
|
---|
347 | #else
|
---|
348 | int vbox_driver_unload(struct drm_device *dev);
|
---|
349 | #endif
|
---|
350 | void vbox_driver_lastclose(struct drm_device *dev);
|
---|
351 |
|
---|
352 | struct vbox_gem_object;
|
---|
353 |
|
---|
354 | #ifndef VGA_PORT_HGSMI_HOST
|
---|
355 | #define VGA_PORT_HGSMI_HOST 0x3b0
|
---|
356 | #define VGA_PORT_HGSMI_GUEST 0x3d0
|
---|
357 | #endif
|
---|
358 |
|
---|
359 | struct vbox_connector {
|
---|
360 | struct drm_connector base;
|
---|
361 | char name[32];
|
---|
362 | struct vbox_crtc *vbox_crtc;
|
---|
363 | struct {
|
---|
364 | u32 width;
|
---|
365 | u32 height;
|
---|
366 | bool disconnected;
|
---|
367 | } mode_hint;
|
---|
368 | };
|
---|
369 |
|
---|
370 | struct vbox_crtc {
|
---|
371 | struct drm_crtc base;
|
---|
372 | bool blanked;
|
---|
373 | bool disconnected;
|
---|
374 | unsigned int crtc_id;
|
---|
375 | u32 fb_offset;
|
---|
376 | bool cursor_enabled;
|
---|
377 | u32 x_hint;
|
---|
378 | u32 y_hint;
|
---|
379 | };
|
---|
380 |
|
---|
381 | struct vbox_encoder {
|
---|
382 | struct drm_encoder base;
|
---|
383 | };
|
---|
384 |
|
---|
385 | struct vbox_framebuffer {
|
---|
386 | struct drm_framebuffer base;
|
---|
387 | struct drm_gem_object *obj;
|
---|
388 | };
|
---|
389 |
|
---|
390 | struct vbox_fbdev {
|
---|
391 | struct drm_fb_helper helper;
|
---|
392 | struct vbox_framebuffer afb;
|
---|
393 | int size;
|
---|
394 | struct ttm_bo_kmap_obj mapping;
|
---|
395 | int x1, y1, x2, y2; /* dirty rect */
|
---|
396 | spinlock_t dirty_lock;
|
---|
397 | };
|
---|
398 |
|
---|
399 | #define to_vbox_crtc(x) container_of(x, struct vbox_crtc, base)
|
---|
400 | #define to_vbox_connector(x) container_of(x, struct vbox_connector, base)
|
---|
401 | #define to_vbox_encoder(x) container_of(x, struct vbox_encoder, base)
|
---|
402 | #define to_vbox_framebuffer(x) container_of(x, struct vbox_framebuffer, base)
|
---|
403 |
|
---|
404 | int vbox_mode_init(struct drm_device *dev);
|
---|
405 | void vbox_mode_fini(struct drm_device *dev);
|
---|
406 |
|
---|
407 | #if RTLNX_VER_MAX(3,3,0)
|
---|
408 | # define DRM_MODE_FB_CMD drm_mode_fb_cmd
|
---|
409 | #else
|
---|
410 | # define DRM_MODE_FB_CMD drm_mode_fb_cmd2
|
---|
411 | #endif
|
---|
412 |
|
---|
413 | #if RTLNX_VER_MAX(3,15,0) && !RTLNX_RHEL_MAJ_PREREQ(7,1)
|
---|
414 | # define CRTC_FB(crtc) ((crtc)->fb)
|
---|
415 | #else
|
---|
416 | # define CRTC_FB(crtc) ((crtc)->primary->fb)
|
---|
417 | #endif
|
---|
418 |
|
---|
419 | void vbox_enable_accel(struct vbox_private *vbox);
|
---|
420 | void vbox_disable_accel(struct vbox_private *vbox);
|
---|
421 | void vbox_report_caps(struct vbox_private *vbox);
|
---|
422 |
|
---|
423 | void vbox_framebuffer_dirty_rectangles(struct drm_framebuffer *fb,
|
---|
424 | struct drm_clip_rect *rects,
|
---|
425 | unsigned int num_rects);
|
---|
426 |
|
---|
427 | int vbox_framebuffer_init(struct drm_device *dev,
|
---|
428 | struct vbox_framebuffer *vbox_fb,
|
---|
429 | #if RTLNX_VER_MIN(4,5,0) || RTLNX_RHEL_MAJ_PREREQ(7,3)
|
---|
430 | const struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
431 | #else
|
---|
432 | struct DRM_MODE_FB_CMD *mode_cmd,
|
---|
433 | #endif
|
---|
434 | struct drm_gem_object *obj);
|
---|
435 |
|
---|
436 | int vbox_fbdev_init(struct drm_device *dev);
|
---|
437 | void vbox_fbdev_fini(struct drm_device *dev);
|
---|
438 | void vbox_fbdev_set_base(struct vbox_private *vbox, unsigned long gpu_addr);
|
---|
439 |
|
---|
440 | struct vbox_bo {
|
---|
441 | struct ttm_buffer_object bo;
|
---|
442 | struct ttm_placement placement;
|
---|
443 | struct ttm_bo_kmap_obj kmap;
|
---|
444 | struct drm_gem_object gem;
|
---|
445 | #if RTLNX_VER_MAX(3,18,0) && !RTLNX_RHEL_MAJ_PREREQ(7,2)
|
---|
446 | u32 placements[3];
|
---|
447 | #else
|
---|
448 | struct ttm_place placements[3];
|
---|
449 | #endif
|
---|
450 | int pin_count;
|
---|
451 | };
|
---|
452 |
|
---|
453 | #define gem_to_vbox_bo(gobj) container_of((gobj), struct vbox_bo, gem)
|
---|
454 |
|
---|
455 | static inline struct vbox_bo *vbox_bo(struct ttm_buffer_object *bo)
|
---|
456 | {
|
---|
457 | return container_of(bo, struct vbox_bo, bo);
|
---|
458 | }
|
---|
459 |
|
---|
460 | #define to_vbox_obj(x) container_of(x, struct vbox_gem_object, base)
|
---|
461 |
|
---|
462 | int vbox_dumb_create(struct drm_file *file,
|
---|
463 | struct drm_device *dev,
|
---|
464 | struct drm_mode_create_dumb *args);
|
---|
465 | #if RTLNX_VER_MAX(3,12,0) && !RTLNX_RHEL_MAJ_PREREQ(7,3)
|
---|
466 | int vbox_dumb_destroy(struct drm_file *file,
|
---|
467 | struct drm_device *dev, u32 handle);
|
---|
468 | #endif
|
---|
469 |
|
---|
470 | void vbox_gem_free_object(struct drm_gem_object *obj);
|
---|
471 | int vbox_dumb_mmap_offset(struct drm_file *file,
|
---|
472 | struct drm_device *dev,
|
---|
473 | u32 handle, u64 *offset);
|
---|
474 |
|
---|
475 | #define DRM_FILE_PAGE_OFFSET (0x10000000ULL >> PAGE_SHIFT)
|
---|
476 |
|
---|
477 | int vbox_mm_init(struct vbox_private *vbox);
|
---|
478 | void vbox_mm_fini(struct vbox_private *vbox);
|
---|
479 |
|
---|
480 | int vbox_bo_create(struct drm_device *dev, int size, int align,
|
---|
481 | u32 flags, struct vbox_bo **pvboxbo);
|
---|
482 |
|
---|
483 | int vbox_gem_create(struct drm_device *dev,
|
---|
484 | u32 size, bool iskernel, struct drm_gem_object **obj);
|
---|
485 |
|
---|
486 | #define VBOX_MEM_TYPE_VRAM 0x1
|
---|
487 | #define VBOX_MEM_TYPE_SYSTEM 0x2
|
---|
488 |
|
---|
489 | int vbox_bo_pin(struct vbox_bo *bo, u32 mem_type, u64 *gpu_addr);
|
---|
490 | int vbox_bo_unpin(struct vbox_bo *bo);
|
---|
491 |
|
---|
492 | static inline int vbox_bo_reserve(struct vbox_bo *bo, bool no_wait)
|
---|
493 | {
|
---|
494 | int ret;
|
---|
495 |
|
---|
496 | #if RTLNX_VER_MIN(4,7,0) || RTLNX_RHEL_MAJ_PREREQ(7,4)
|
---|
497 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
|
---|
498 | #else
|
---|
499 | ret = ttm_bo_reserve(&bo->bo, true, no_wait, false, 0);
|
---|
500 | #endif
|
---|
501 | if (ret) {
|
---|
502 | if (ret != -ERESTARTSYS && ret != -EBUSY)
|
---|
503 | DRM_ERROR("reserve failed %p\n", bo);
|
---|
504 | return ret;
|
---|
505 | }
|
---|
506 | return 0;
|
---|
507 | }
|
---|
508 |
|
---|
509 | static inline void vbox_bo_unreserve(struct vbox_bo *bo)
|
---|
510 | {
|
---|
511 | ttm_bo_unreserve(&bo->bo);
|
---|
512 | }
|
---|
513 |
|
---|
514 | void vbox_ttm_placement(struct vbox_bo *bo, u32 mem_type);
|
---|
515 | int vbox_bo_push_sysram(struct vbox_bo *bo);
|
---|
516 | int vbox_mmap(struct file *filp, struct vm_area_struct *vma);
|
---|
517 |
|
---|
518 | /* vbox_prime.c */
|
---|
519 | int vbox_gem_prime_pin(struct drm_gem_object *obj);
|
---|
520 | void vbox_gem_prime_unpin(struct drm_gem_object *obj);
|
---|
521 | struct sg_table *vbox_gem_prime_get_sg_table(struct drm_gem_object *obj);
|
---|
522 | #if RTLNX_VER_MAX(3,18,0) && !RTLNX_RHEL_MAJ_PREREQ(7,2)
|
---|
523 | struct drm_gem_object *vbox_gem_prime_import_sg_table(
|
---|
524 | struct drm_device *dev, size_t size, struct sg_table *table);
|
---|
525 | #else
|
---|
526 | struct drm_gem_object *vbox_gem_prime_import_sg_table(
|
---|
527 | struct drm_device *dev, struct dma_buf_attachment *attach,
|
---|
528 | struct sg_table *table);
|
---|
529 | #endif
|
---|
530 | void *vbox_gem_prime_vmap(struct drm_gem_object *obj);
|
---|
531 | void vbox_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
|
---|
532 | #if RTLNX_VER_MAX(6,6,0) && !RTLNX_RHEL_RANGE(9,4, 9,99)
|
---|
533 | int vbox_gem_prime_mmap(struct drm_gem_object *obj,
|
---|
534 | struct vm_area_struct *area);
|
---|
535 | #endif
|
---|
536 |
|
---|
537 | /* vbox_irq.c */
|
---|
538 | int vbox_irq_init(struct vbox_private *vbox);
|
---|
539 | void vbox_irq_fini(struct vbox_private *vbox);
|
---|
540 | void vbox_report_hotplug(struct vbox_private *vbox);
|
---|
541 | irqreturn_t vbox_irq_handler(int irq, void *arg);
|
---|
542 |
|
---|
543 | /* vbox_hgsmi.c */
|
---|
544 | void *hgsmi_buffer_alloc(struct gen_pool *guest_pool, size_t size,
|
---|
545 | u8 channel, u16 channel_info);
|
---|
546 | void hgsmi_buffer_free(struct gen_pool *guest_pool, void *buf);
|
---|
547 | int hgsmi_buffer_submit(struct gen_pool *guest_pool, void *buf);
|
---|
548 |
|
---|
549 | static inline void vbox_write_ioport(u16 index, u16 data)
|
---|
550 | {
|
---|
551 | outw(index, VBE_DISPI_IOPORT_INDEX);
|
---|
552 | outw(data, VBE_DISPI_IOPORT_DATA);
|
---|
553 | }
|
---|
554 |
|
---|
555 | #endif /* !GA_INCLUDED_SRC_linux_drm_vbox_drv_h */
|
---|