1 | /* $Id: vboxvideo_drm.c 52441 2014-08-21 13:17:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * vboxvideo_drm - Direct Rendering Module, Solaris Specific Code.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #ifdef DEBUG_ramshankar
|
---|
32 | # define LOG_INSTANCE RTLogRelDefaultInstance()
|
---|
33 | #endif
|
---|
34 | #undef offsetof /* This gets redefined in drmP.h */
|
---|
35 | #include "include/drmP.h"
|
---|
36 | #include "include/drm.h"
|
---|
37 |
|
---|
38 | #undef u /* /usr/include/sys/user.h:249:1 is where this is defined to (curproc->p_user). very cool. */
|
---|
39 |
|
---|
40 | #include <VBox/log.h>
|
---|
41 | #include <VBox/version.h>
|
---|
42 |
|
---|
43 |
|
---|
44 | /*******************************************************************************
|
---|
45 | * Defined Constants And Macros *
|
---|
46 | *******************************************************************************/
|
---|
47 | #define VBOXSOLQUOTE2(x) #x
|
---|
48 | #define VBOXSOLQUOTE(x) VBOXSOLQUOTE2(x)
|
---|
49 | /** The module name. */
|
---|
50 | #define DEVICE_NAME "vboxvideo"
|
---|
51 | /** The module description as seen in 'modinfo'. */
|
---|
52 | #define DEVICE_DESC_DRV "VirtualBox DRM"
|
---|
53 |
|
---|
54 | /** DRM Specific defines */
|
---|
55 | #define DRIVER_AUTHOR "Oracle Corporation"
|
---|
56 | #define DRIVER_NAME DEVICE_NAME
|
---|
57 | #define DRIVER_DESC DEVICE_DESC_DRV
|
---|
58 | #define DRIVER_DATE "20090317"
|
---|
59 | #define DRIVER_MAJOR 1
|
---|
60 | #define DRIVER_MINOR 0
|
---|
61 | #define DRIVER_PATCHLEVEL 0
|
---|
62 | #define vboxvideo_PCI_IDS { 0x80ee, 0xbeef, 0, "VirtualBox Video" }, \
|
---|
63 | { 0, 0, 0, NULL }
|
---|
64 |
|
---|
65 |
|
---|
66 | /*******************************************************************************
|
---|
67 | * Internal Functions *
|
---|
68 | *******************************************************************************/
|
---|
69 | static int VBoxVideoSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
|
---|
70 | static int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
|
---|
71 | static int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult);
|
---|
72 |
|
---|
73 | static void vboxVideoSolarisConfigure(drm_driver_t *pDriver);
|
---|
74 |
|
---|
75 |
|
---|
76 | /*******************************************************************************
|
---|
77 | * Structures and Typedefs *
|
---|
78 | *******************************************************************************/
|
---|
79 | extern struct cb_ops drm_cb_ops;
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * dev_ops: for driver device operations
|
---|
83 | */
|
---|
84 | static struct dev_ops g_VBoxVideoSolarisDevOps =
|
---|
85 | {
|
---|
86 | DEVO_REV, /* driver build revision */
|
---|
87 | 0, /* ref count */
|
---|
88 | VBoxVideoSolarisGetInfo,
|
---|
89 | nulldev, /* identify */
|
---|
90 | nulldev, /* probe */
|
---|
91 | VBoxVideoSolarisAttach,
|
---|
92 | VBoxVideoSolarisDetach,
|
---|
93 | nodev, /* reset */
|
---|
94 | &drm_cb_ops,
|
---|
95 | NULL, /* dev bus ops*/
|
---|
96 | NULL /* power */
|
---|
97 | };
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * modldrv: export driver specifics to the kernel
|
---|
101 | */
|
---|
102 | static struct modldrv g_VBoxVideoSolarisModule =
|
---|
103 | {
|
---|
104 | &mod_driverops, /* extern from kernel */
|
---|
105 | DEVICE_DESC_DRV " " VBOX_VERSION_STRING "r" VBOXSOLQUOTE(VBOX_SVN_REV),
|
---|
106 | &g_VBoxVideoSolarisDevOps
|
---|
107 | };
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * modlinkage: export install/remove/info to the kernel
|
---|
111 | */
|
---|
112 | static struct modlinkage g_VBoxVideoSolarisModLinkage =
|
---|
113 | {
|
---|
114 | MODREV_1, /* loadable module system revision */
|
---|
115 | &g_VBoxVideoSolarisModule,
|
---|
116 | NULL /* terminate array of linkage structures */
|
---|
117 | };
|
---|
118 |
|
---|
119 | /* VBoxVideo device PCI ID */
|
---|
120 | static drm_pci_id_list_t vboxvideo_pciidlist[] = {
|
---|
121 | vboxvideo_PCI_IDS
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | /** DRM Driver */
|
---|
126 | static drm_driver_t g_VBoxVideoSolarisDRMDriver = { 0 };
|
---|
127 |
|
---|
128 |
|
---|
129 | /*******************************************************************************
|
---|
130 | * Global Variables *
|
---|
131 | *******************************************************************************/
|
---|
132 | /** Device handle (we support only one instance). */
|
---|
133 | static dev_info_t *g_pDip;
|
---|
134 |
|
---|
135 | /** Soft state. */
|
---|
136 | static void *g_pVBoxVideoSolarisState;
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Kernel entry points
|
---|
141 | */
|
---|
142 | int _init(void)
|
---|
143 | {
|
---|
144 | LogFlow((DEVICE_NAME ":_init flow\n"));
|
---|
145 | cmn_err(CE_NOTE, DEVICE_NAME ":_init\n");
|
---|
146 |
|
---|
147 | vboxVideoSolarisConfigure(&g_VBoxVideoSolarisDRMDriver);
|
---|
148 | int rc = ddi_soft_state_init(&g_pVBoxVideoSolarisState, sizeof(drm_device_t), DRM_MAX_INSTANCES);
|
---|
149 | if (!rc)
|
---|
150 | return mod_install(&g_VBoxVideoSolarisModLinkage);
|
---|
151 | else
|
---|
152 | LogRel((DEVICE_NAME ":_init: ddi_soft_state_init failed. rc=%d\n", rc));
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | int _fini(void)
|
---|
157 | {
|
---|
158 | LogFlow((DEVICE_NAME ":_fini flow\n"));
|
---|
159 | cmn_err(CE_NOTE, DEVICE_NAME ":_fini\n");
|
---|
160 | int rc = mod_remove(&g_VBoxVideoSolarisModLinkage);
|
---|
161 | ddi_soft_state_fini(&g_pVBoxVideoSolarisState);
|
---|
162 | return rc;
|
---|
163 | }
|
---|
164 |
|
---|
165 |
|
---|
166 | int _info(struct modinfo *pModInfo)
|
---|
167 | {
|
---|
168 | LogFlow((DEVICE_NAME ":_info flow\n"));
|
---|
169 | cmn_err(CE_NOTE, DEVICE_NAME ":_info\n");
|
---|
170 | return mod_info(&g_VBoxVideoSolarisModLinkage, pModInfo);
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Attach entry point, to attach a device to the system or resume it.
|
---|
176 | *
|
---|
177 | * @param pDip The module structure instance.
|
---|
178 | * @param enmCmd Operation type (attach/resume).
|
---|
179 | *
|
---|
180 | * @returns corresponding solaris error code.
|
---|
181 | */
|
---|
182 | static int VBoxVideoSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
|
---|
183 | {
|
---|
184 | LogFlow((DEVICE_NAME ":VBoxVideoSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
|
---|
185 | cmn_err(CE_NOTE, DEVICE_NAME ":attach\n");
|
---|
186 |
|
---|
187 | switch (enmCmd)
|
---|
188 | {
|
---|
189 | case DDI_ATTACH:
|
---|
190 | {
|
---|
191 | drm_device_t *pState;
|
---|
192 | int Instance = ddi_get_instance(pDip);
|
---|
193 | int rc = ddi_soft_state_zalloc(g_pVBoxVideoSolarisState, Instance);
|
---|
194 | if (rc == DDI_SUCCESS)
|
---|
195 | {
|
---|
196 | pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
|
---|
197 | pState->dip = pDip;
|
---|
198 | pState->driver = &g_VBoxVideoSolarisDRMDriver;
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * Register using the DRM module which will create the minor nodes
|
---|
202 | */
|
---|
203 | void *pDRMHandle = drm_supp_register(pDip, pState);
|
---|
204 | if (pDRMHandle)
|
---|
205 | {
|
---|
206 | pState->drm_handle = pDRMHandle;
|
---|
207 |
|
---|
208 | /*
|
---|
209 | * Probe with our pci-id.
|
---|
210 | * -XXX- is probing really required???
|
---|
211 | */
|
---|
212 | pState->drm_supported = DRM_UNSUPPORT;
|
---|
213 | rc = drm_probe(pState, vboxvideo_pciidlist);
|
---|
214 | if (rc == DDI_SUCCESS)
|
---|
215 | {
|
---|
216 | pState->drm_supported = DRM_SUPPORT;
|
---|
217 |
|
---|
218 | /*
|
---|
219 | * Call the common attach DRM routine.
|
---|
220 | */
|
---|
221 | rc = drm_attach(pState);
|
---|
222 | if (rc == DDI_SUCCESS)
|
---|
223 | {
|
---|
224 | return DDI_SUCCESS;
|
---|
225 | }
|
---|
226 | else
|
---|
227 | LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_attach failed.rc=%d\n", rc));
|
---|
228 | }
|
---|
229 | else
|
---|
230 | LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_probe failed.rc=%d\n", rc));
|
---|
231 |
|
---|
232 | drm_supp_unregister(pDRMHandle);
|
---|
233 | }
|
---|
234 | else
|
---|
235 | LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_supp_register failed.\n"));
|
---|
236 |
|
---|
237 | ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
|
---|
238 | }
|
---|
239 | else
|
---|
240 | LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach failed to alloc memory for soft state.rc=%d\n", rc));
|
---|
241 | return DDI_FAILURE;
|
---|
242 | }
|
---|
243 |
|
---|
244 | case DDI_RESUME:
|
---|
245 | {
|
---|
246 | /* Nothing to do here... */
|
---|
247 | return DDI_SUCCESS;
|
---|
248 | }
|
---|
249 | }
|
---|
250 | return DDI_FAILURE;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | /**
|
---|
255 | * Detach entry point, to detach a device to the system or suspend it.
|
---|
256 | *
|
---|
257 | * @param pDip The module structure instance.
|
---|
258 | * @param enmCmd Operation type (detach/suspend).
|
---|
259 | *
|
---|
260 | * @returns corresponding solaris error code.
|
---|
261 | */
|
---|
262 | static int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
|
---|
263 | {
|
---|
264 | LogFlow((DEVICE_NAME ":VBoxVideoSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
|
---|
265 |
|
---|
266 | switch (enmCmd)
|
---|
267 | {
|
---|
268 | case DDI_DETACH:
|
---|
269 | {
|
---|
270 | int Instance = ddi_get_instance(pDip);
|
---|
271 | drm_device_t *pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
|
---|
272 | if (pState)
|
---|
273 | {
|
---|
274 | drm_detach(pState);
|
---|
275 | drm_supp_unregister(pState->drm_handle);
|
---|
276 | ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
|
---|
277 | return DDI_SUCCESS;
|
---|
278 | }
|
---|
279 | else
|
---|
280 | LogRel((DEVICE_NAME ":VBoxVideoSolarisDetach failed to get soft state.\n"));
|
---|
281 |
|
---|
282 | return DDI_FAILURE;
|
---|
283 | }
|
---|
284 |
|
---|
285 | case DDI_RESUME:
|
---|
286 | {
|
---|
287 | /* Nothing to do here... */
|
---|
288 | return DDI_SUCCESS;
|
---|
289 | }
|
---|
290 | }
|
---|
291 | return DDI_FAILURE;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | /*
|
---|
296 | * Info entry point, called by solaris kernel for obtaining driver info.
|
---|
297 | *
|
---|
298 | * @param pDip The module structure instance (do not use).
|
---|
299 | * @param enmCmd Information request type.
|
---|
300 | * @param pvArg Type specific argument.
|
---|
301 | * @param ppvResult Where to store the requested info.
|
---|
302 | *
|
---|
303 | * @return corresponding solaris error code.
|
---|
304 | */
|
---|
305 | static int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult)
|
---|
306 | {
|
---|
307 | LogFlow((DEVICE_NAME ":VBoxGuestSolarisGetInfo\n"));
|
---|
308 |
|
---|
309 | int rc = DDI_FAILURE;
|
---|
310 | int Instance = drm_dev_to_instance((dev_t)pvArg);
|
---|
311 | drm_device_t *pState = NULL;
|
---|
312 | switch (enmCmd)
|
---|
313 | {
|
---|
314 | case DDI_INFO_DEVT2DEVINFO:
|
---|
315 | {
|
---|
316 | pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
|
---|
317 | if ( pState
|
---|
318 | && pState->dip)
|
---|
319 | {
|
---|
320 | *ppvResult = (void *)pState->dip;
|
---|
321 | rc = DDI_SUCCESS;
|
---|
322 | }
|
---|
323 | else
|
---|
324 | {
|
---|
325 | LogRel((DEVICE_NAME ":VBoxGuestSolarisGetInfo state or state's devinfo invalid.\n"));
|
---|
326 | rc = DDI_FAILURE;
|
---|
327 | }
|
---|
328 | break;
|
---|
329 | }
|
---|
330 |
|
---|
331 | case DDI_INFO_DEVT2INSTANCE:
|
---|
332 | {
|
---|
333 | *ppvResult = (void *)(uintptr_t)Instance;
|
---|
334 | rc = DDI_SUCCESS;
|
---|
335 | break;
|
---|
336 | }
|
---|
337 |
|
---|
338 | default:
|
---|
339 | {
|
---|
340 | rc = DDI_FAILURE;
|
---|
341 | break;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | return rc;
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | static int vboxVideoSolarisLoad(drm_device_t *pDevice, unsigned long fFlag)
|
---|
350 | {
|
---|
351 | return 0;
|
---|
352 | }
|
---|
353 |
|
---|
354 | static int vboxVideoSolarisUnload(drm_device_t *pDevice)
|
---|
355 | {
|
---|
356 | return 0;
|
---|
357 | }
|
---|
358 |
|
---|
359 | static void vboxVideoSolarisLastClose(drm_device_t *pDevice)
|
---|
360 | {
|
---|
361 | }
|
---|
362 |
|
---|
363 | static void vboxVideoSolarisPreClose(drm_device_t *pDevice, drm_file_t *pFile)
|
---|
364 | {
|
---|
365 | }
|
---|
366 |
|
---|
367 |
|
---|
368 | static void vboxVideoSolarisConfigure(drm_driver_t *pDriver)
|
---|
369 | {
|
---|
370 | /*
|
---|
371 | * DRM entry points, use the common DRM extension wherever possible.
|
---|
372 | */
|
---|
373 | pDriver->buf_priv_size = 1;
|
---|
374 | pDriver->load = vboxVideoSolarisLoad;
|
---|
375 | pDriver->unload = vboxVideoSolarisUnload;
|
---|
376 | pDriver->preclose = vboxVideoSolarisPreClose;
|
---|
377 | pDriver->lastclose = vboxVideoSolarisLastClose;
|
---|
378 | pDriver->device_is_agp = drm_device_is_agp;
|
---|
379 | #if 0
|
---|
380 | pDriver->get_vblank_counter = drm_vblank_count;
|
---|
381 | pDriver->enable_vblank = NULL;
|
---|
382 | pDriver->disable_vblank = NULL;
|
---|
383 | pDriver->irq_install = drm_driver_irq_install;
|
---|
384 | pDriver->irq_preinstall = drm_driver_irq_preinstall;
|
---|
385 | pDriver->irq_postinstall = drm_driver_irq_postinstall;
|
---|
386 | pDirver->irq_uninstall = drm_driver_irq_uninstall;
|
---|
387 | pDriver->irq_handler = drm_driver_irq_handler;
|
---|
388 |
|
---|
389 | pDriver->driver_ioctls =
|
---|
390 | pDriver->max_driver_ioctls =
|
---|
391 | #endif
|
---|
392 |
|
---|
393 | pDriver->driver_name = DRIVER_NAME;
|
---|
394 | pDriver->driver_desc = DRIVER_DESC;
|
---|
395 | pDriver->driver_date = DRIVER_DATE;
|
---|
396 | pDriver->driver_major = DRIVER_MAJOR;
|
---|
397 | pDriver->driver_minor = DRIVER_MINOR;
|
---|
398 | pDriver->driver_patchlevel = DRIVER_PATCHLEVEL;
|
---|
399 |
|
---|
400 | pDriver->use_agp = 1;
|
---|
401 | pDriver->require_agp = 1;
|
---|
402 | pDriver->use_irq = 1;
|
---|
403 | }
|
---|
404 |
|
---|