VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use