VirtualBox

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

Last change on this file since 49133 was 48943, checked in by vboxsync, 11 years ago

Additions/solaris: Whitespace and svn:keyword cleanups by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 13.0 KB
Line 
1/* $Id: vboxvideo_drm.c 48943 2013-10-07 21:30:45Z 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*******************************************************************************/
69static int VBoxVideoSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
70static int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
71static int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult);
72
73static void vboxVideoSolarisConfigure(drm_driver_t *pDriver);
74
75
76/*******************************************************************************
77* Structures and Typedefs *
78*******************************************************************************/
79extern struct cb_ops drm_cb_ops;
80
81/**
82 * dev_ops: for driver device operations
83 */
84static 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 */
102static 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 */
112static 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 */
120static drm_pci_id_list_t vboxvideo_pciidlist[] = {
121 vboxvideo_PCI_IDS
122};
123
124
125/** DRM Driver */
126static drm_driver_t g_VBoxVideoSolarisDRMDriver = { 0 };
127
128
129/*******************************************************************************
130* Global Variables *
131*******************************************************************************/
132/** Device handle (we support only one instance). */
133static dev_info_t *g_pDip;
134
135/** Soft state. */
136static void *g_pVBoxVideoSolarisState;
137
138
139/**
140 * Kernel entry points
141 */
142int _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
156int _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
166int _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 */
182static 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 int rc = -1;
188 switch (enmCmd)
189 {
190 case DDI_ATTACH:
191 {
192 drm_device_t *pState;
193 int Instance = ddi_get_instance(pDip);
194 int rc = ddi_soft_state_zalloc(g_pVBoxVideoSolarisState, Instance);
195 if (rc == DDI_SUCCESS)
196 {
197 pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
198 pState->dip = pDip;
199 pState->driver = &g_VBoxVideoSolarisDRMDriver;
200
201 /*
202 * Register using the DRM module which will create the minor nodes
203 */
204 void *pDRMHandle = drm_supp_register(pDip, pState);
205 if (pDRMHandle)
206 {
207 pState->drm_handle = pDRMHandle;
208
209 /*
210 * Probe with our pci-id.
211 * -XXX- is probing really required???
212 */
213 pState->drm_supported = DRM_UNSUPPORT;
214 rc = drm_probe(pState, vboxvideo_pciidlist);
215 if (rc == DDI_SUCCESS)
216 {
217 pState->drm_supported = DRM_SUPPORT;
218
219 /*
220 * Call the common attach DRM routine.
221 */
222 rc = drm_attach(pState);
223 if (rc == DDI_SUCCESS)
224 {
225 return DDI_SUCCESS;
226 }
227 else
228 LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_attach failed.rc=%d\n", rc));
229 }
230 else
231 LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_probe failed.rc=%d\n", rc));
232
233 drm_supp_unregister(pDRMHandle);
234 }
235 else
236 LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_supp_register failed.\n"));
237
238 ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
239 }
240 else
241 LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach failed to alloc memory for soft state.rc=%d\n", rc));
242 return DDI_FAILURE;
243 }
244
245 case DDI_RESUME:
246 {
247 /* Nothing to do here... */
248 return DDI_SUCCESS;
249 }
250 }
251 return DDI_FAILURE;
252}
253
254
255/**
256 * Detach entry point, to detach a device to the system or suspend it.
257 *
258 * @param pDip The module structure instance.
259 * @param enmCmd Operation type (detach/suspend).
260 *
261 * @returns corresponding solaris error code.
262 */
263static int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
264{
265 LogFlow((DEVICE_NAME ":VBoxVideoSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
266
267 switch (enmCmd)
268 {
269 case DDI_DETACH:
270 {
271 int Instance = ddi_get_instance(pDip);
272 drm_device_t *pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
273 if (pState)
274 {
275 drm_detach(pState);
276 drm_supp_unregister(pState->drm_handle);
277 ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
278 return DDI_SUCCESS;
279 }
280 else
281 LogRel((DEVICE_NAME ":VBoxVideoSolarisDetach failed to get soft state.\n"));
282
283 return DDI_FAILURE;
284 }
285
286 case DDI_RESUME:
287 {
288 /* Nothing to do here... */
289 return DDI_SUCCESS;
290 }
291 }
292 return DDI_FAILURE;
293}
294
295
296/*
297 * Info entry point, called by solaris kernel for obtaining driver info.
298 *
299 * @param pDip The module structure instance (do not use).
300 * @param enmCmd Information request type.
301 * @param pvArg Type specific argument.
302 * @param ppvResult Where to store the requested info.
303 *
304 * @return corresponding solaris error code.
305 */
306static int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult)
307{
308 LogFlow((DEVICE_NAME ":VBoxGuestSolarisGetInfo\n"));
309
310 int rc = DDI_FAILURE;
311 int Instance = drm_dev_to_instance((dev_t)pvArg);
312 drm_device_t *pState = NULL;
313 switch (enmCmd)
314 {
315 case DDI_INFO_DEVT2DEVINFO:
316 {
317 pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
318 if ( pState
319 && pState->dip)
320 {
321 *ppvResult = (void *)pState->dip;
322 rc = DDI_SUCCESS;
323 }
324 else
325 {
326 LogRel((DEVICE_NAME ":VBoxGuestSolarisGetInfo state or state's devinfo invalid.\n"));
327 rc = DDI_FAILURE;
328 }
329 break;
330 }
331
332 case DDI_INFO_DEVT2INSTANCE:
333 {
334 *ppvResult = (void *)(uintptr_t)Instance;
335 rc = DDI_SUCCESS;
336 break;
337 }
338
339 default:
340 {
341 rc = DDI_FAILURE;
342 break;
343 }
344 }
345
346 return rc;
347}
348
349
350static int vboxVideoSolarisLoad(drm_device_t *pDevice, unsigned long fFlag)
351{
352 return 0;
353}
354
355static int vboxVideoSolarisUnload(drm_device_t *pDevice)
356{
357 return 0;
358}
359
360static void vboxVideoSolarisLastClose(drm_device_t *pDevice)
361{
362}
363
364static void vboxVideoSolarisPreClose(drm_device_t *pDevice, drm_file_t *pFile)
365{
366}
367
368
369static void vboxVideoSolarisConfigure(drm_driver_t *pDriver)
370{
371 /*
372 * DRM entry points, use the common DRM extension wherever possible.
373 */
374 pDriver->buf_priv_size = 1;
375 pDriver->load = vboxVideoSolarisLoad;
376 pDriver->unload = vboxVideoSolarisUnload;
377 pDriver->preclose = vboxVideoSolarisPreClose;
378 pDriver->lastclose = vboxVideoSolarisLastClose;
379 pDriver->device_is_agp = drm_device_is_agp;
380#if 0
381 pDriver->get_vblank_counter = drm_vblank_count;
382 pDriver->enable_vblank = NULL;
383 pDriver->disable_vblank = NULL;
384 pDriver->irq_install = drm_driver_irq_install;
385 pDriver->irq_preinstall = drm_driver_irq_preinstall;
386 pDriver->irq_postinstall = drm_driver_irq_postinstall;
387 pDirver->irq_uninstall = drm_driver_irq_uninstall;
388 pDriver->irq_handler = drm_driver_irq_handler;
389
390 pDriver->driver_ioctls =
391 pDriver->max_driver_ioctls =
392#endif
393
394 pDriver->driver_name = DRIVER_NAME;
395 pDriver->driver_desc = DRIVER_DESC;
396 pDriver->driver_date = DRIVER_DATE;
397 pDriver->driver_major = DRIVER_MAJOR;
398 pDriver->driver_minor = DRIVER_MINOR;
399 pDriver->driver_patchlevel = DRIVER_PATCHLEVEL;
400
401 pDriver->use_agp = 1;
402 pDriver->require_agp = 1;
403 pDriver->use_irq = 1;
404}
405
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