VirtualBox

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

Last change on this file since 56294 was 55980, checked in by vboxsync, 10 years ago

iprt/log.h,++: Added extended logger instance getters that also checks whether the given logger and group-flags are enabled, making the LogRel* checks more efficient in avoid uncessary RTLogLoggerEx parameter building and calls. Ditto for debug logging. The LOG_INSTANCE and LOG_REL_INSTANCE tricks are gone for now.

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