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