VirtualBox

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

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

branding

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