vboxvideo_drm.c revision 4b9d6701570cb98fd36e209314239d104ec584d3
26456d1900aba0e903e6e1beec552396618322e2vboxsync * vboxvideo_drm - Direct Rendering Module, Solaris Specific Code.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2009 Oracle Corporation
26456d1900aba0e903e6e1beec552396618322e2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
26456d1900aba0e903e6e1beec552396618322e2vboxsync * available from http://www.virtualbox.org. This file is free software;
26456d1900aba0e903e6e1beec552396618322e2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
26456d1900aba0e903e6e1beec552396618322e2vboxsync * General Public License (GPL) as published by the Free Software
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
26456d1900aba0e903e6e1beec552396618322e2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
26456d1900aba0e903e6e1beec552396618322e2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * The contents of this file may alternatively be used under the terms
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * of the Common Development and Distribution License Version 1.0
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * VirtualBox OSE distribution, in which case the provisions of the
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * CDDL are applicable instead of those of the GPL.
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * You may elect to license modified versions of this file under the
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * terms and conditions of either the GPL or the CDDL or both.
26456d1900aba0e903e6e1beec552396618322e2vboxsync/*******************************************************************************
26456d1900aba0e903e6e1beec552396618322e2vboxsync* Header Files *
26456d1900aba0e903e6e1beec552396618322e2vboxsync*******************************************************************************/
26456d1900aba0e903e6e1beec552396618322e2vboxsync#undef u /* /usr/include/sys/user.h:249:1 is where this is defined to (curproc->p_user). very cool. */
26456d1900aba0e903e6e1beec552396618322e2vboxsync/*******************************************************************************
26456d1900aba0e903e6e1beec552396618322e2vboxsync* Defined Constants And Macros *
26456d1900aba0e903e6e1beec552396618322e2vboxsync*******************************************************************************/
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** The module name. */
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** The module description as seen in 'modinfo'. */
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** DRM Specific defines */
26456d1900aba0e903e6e1beec552396618322e2vboxsync#define vboxvideo_PCI_IDS { 0x80ee, 0xbeef, 0, "VirtualBox Video" }, \
26456d1900aba0e903e6e1beec552396618322e2vboxsync { 0, 0, 0, NULL }
26456d1900aba0e903e6e1beec552396618322e2vboxsync/*******************************************************************************
26456d1900aba0e903e6e1beec552396618322e2vboxsync* Internal Functions *
26456d1900aba0e903e6e1beec552396618322e2vboxsync*******************************************************************************/
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult);
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic void vboxVideoSolarisConfigure(drm_driver_t *pDriver);
26456d1900aba0e903e6e1beec552396618322e2vboxsync/*******************************************************************************
26456d1900aba0e903e6e1beec552396618322e2vboxsync* Structures and Typedefs *
26456d1900aba0e903e6e1beec552396618322e2vboxsync*******************************************************************************/
26456d1900aba0e903e6e1beec552396618322e2vboxsync * dev_ops: for driver device operations
26456d1900aba0e903e6e1beec552396618322e2vboxsync 0, /* ref count */
26456d1900aba0e903e6e1beec552396618322e2vboxsync * modldrv: export driver specifics to the kernel
26456d1900aba0e903e6e1beec552396618322e2vboxsync DEVICE_DESC_DRV " " VBOX_VERSION_STRING "r" VBOXSOLQUOTE(VBOX_SVN_REV),
26456d1900aba0e903e6e1beec552396618322e2vboxsync * modlinkage: export install/remove/info to the kernel
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic struct modlinkage g_VBoxVideoSolarisModLinkage =
26456d1900aba0e903e6e1beec552396618322e2vboxsync/* VBoxVideo device PCI ID */
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** DRM Driver */
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic drm_driver_t g_VBoxVideoSolarisDRMDriver = { 0 };
26456d1900aba0e903e6e1beec552396618322e2vboxsync/*******************************************************************************
26456d1900aba0e903e6e1beec552396618322e2vboxsync* Global Variables *
26456d1900aba0e903e6e1beec552396618322e2vboxsync*******************************************************************************/
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** Device handle (we support only one instance). */
26456d1900aba0e903e6e1beec552396618322e2vboxsync/** Soft state. */
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Kernel entry points
6a4c7474dbecb411cc7288459141b7cdd654ab3bvboxsync vboxVideoSolarisConfigure(&g_VBoxVideoSolarisDRMDriver);
26456d1900aba0e903e6e1beec552396618322e2vboxsync int rc = ddi_soft_state_init(&g_pVBoxVideoSolarisState, sizeof(drm_device_t), DRM_MAX_INSTANCES);
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":_init: ddi_soft_state_init failed. rc=%d\n", rc));
26456d1900aba0e903e6e1beec552396618322e2vboxsync int rc = mod_remove(&g_VBoxVideoSolarisModLinkage);
26456d1900aba0e903e6e1beec552396618322e2vboxsync return mod_info(&g_VBoxVideoSolarisModLinkage, pModInfo);
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Attach entry point, to attach a device to the system or resume it.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param pDip The module structure instance.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param enmCmd Operation type (attach/resume).
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @returns corresponding solaris error code.
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogFlow((DEVICE_NAME ":VBoxVideoSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
26456d1900aba0e903e6e1beec552396618322e2vboxsync int rc = ddi_soft_state_zalloc(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Register using the DRM module which will create the minor nodes
26456d1900aba0e903e6e1beec552396618322e2vboxsync void *pDRMHandle = drm_supp_register(pDip, pState);
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Probe with our pci-id.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * -XXX- is probing really required???
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Call the common attach DRM routine.
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_attach failed.rc=%d\n", rc));
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_probe failed.rc=%d\n", rc));
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach drm_supp_register failed.\n"));
26456d1900aba0e903e6e1beec552396618322e2vboxsync ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxVideoSolarisAttach failed to alloc memory for soft state.rc=%d\n", rc));
26456d1900aba0e903e6e1beec552396618322e2vboxsync /* Nothing to do here... */
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Detach entry point, to detach a device to the system or suspend it.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param pDip The module structure instance.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param enmCmd Operation type (detach/suspend).
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @returns corresponding solaris error code.
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogFlow((DEVICE_NAME ":VBoxVideoSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
26456d1900aba0e903e6e1beec552396618322e2vboxsync drm_device_t *pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync ddi_soft_state_free(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxVideoSolarisDetach failed to get soft state.\n"));
26456d1900aba0e903e6e1beec552396618322e2vboxsync /* Nothing to do here... */
26456d1900aba0e903e6e1beec552396618322e2vboxsync * Info entry point, called by solaris kernel for obtaining driver info.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param pDip The module structure instance (do not use).
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param enmCmd Information request type.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param pvArg Type specific argument.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @param ppvResult Where to store the requested info.
26456d1900aba0e903e6e1beec552396618322e2vboxsync * @return corresponding solaris error code.
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic int VBoxVideoSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppvResult)
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogFlow((DEVICE_NAME ":VBoxGuestSolarisGetInfo\n"));
26456d1900aba0e903e6e1beec552396618322e2vboxsync pState = ddi_get_soft_state(g_pVBoxVideoSolarisState, Instance);
26456d1900aba0e903e6e1beec552396618322e2vboxsync LogRel((DEVICE_NAME ":VBoxGuestSolarisGetInfo state or state's devinfo invalid.\n"));
742ee7392dfc0ce0b48216189ce26534208b3f48vboxsyncstatic int vboxVideoSolarisLoad(drm_device_t *pDevice, unsigned long fFlag)
742ee7392dfc0ce0b48216189ce26534208b3f48vboxsyncstatic int vboxVideoSolarisUnload(drm_device_t *pDevice)
742ee7392dfc0ce0b48216189ce26534208b3f48vboxsyncstatic void vboxVideoSolarisLastClose(drm_device_t *pDevice)
742ee7392dfc0ce0b48216189ce26534208b3f48vboxsyncstatic void vboxVideoSolarisPreClose(drm_device_t *pDevice, drm_file_t *pFile)
26456d1900aba0e903e6e1beec552396618322e2vboxsyncstatic void vboxVideoSolarisConfigure(drm_driver_t *pDriver)
26456d1900aba0e903e6e1beec552396618322e2vboxsync * DRM entry points, use the common DRM extension wherever possible.
26456d1900aba0e903e6e1beec552396618322e2vboxsync pDriver->irq_preinstall = drm_driver_irq_preinstall;