VirtualBox

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

Last change on this file since 79067 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

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