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