VirtualBox

source: vbox/trunk/src/VBox/Additions/solaris/DRM/vboxvideo_drm.c@ 26493

Last change on this file since 26493 was 26493, checked in by vboxsync, 15 years ago

Additions: whitespace cleanup

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