VirtualBox

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

最後變更 在這個檔案從18321是 18085,由 vboxsync 提交於 16 年 前

Solaris/DRM: bits.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette