i915_sundrv.c revision d0538f66491267879b7418b21ad78e3dcc2dcc83
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* I915 DRM Driver for Solaris
*
* This driver provides the hardware 3D acceleration support for Intel
* DRI (Direct Rendering Infrastructure). DRM (Direct Rendering Manager) here
* means the kernel device driver in DRI.
*
* I915 driver is a device dependent driver only, it depends on a misc module
* named drm for generic DRM operations.
*
* This driver also calls into gfx and agpmaster misc modules respectively for
* generic graphics operations and AGP master device support.
*/
#include <sys/visual_io.h>
#include <sys/ddi_impldefs.h>
#include <gfx_private.h>
#include <drmP.h>
/*
* Macros used only in this file
*/
/*
* dev_t of this driver looks consists of:
*
* major number with NBITSMAJOR bits
* instance node number with NBITSINST bits
* minor node number with NBITSMINOR - NBITSINST bits
*
* Each instance has at most 2^(NBITSMINOR - NBITSINST) minor nodes, the first
* three are:
* 0: gfx<instance number>, graphics common node
* 1: agpmaster<instance number>, agpmaster node
* 2: drm<instance number>, drm node
*/
#define GFX_MINOR 0
#define AGPMASTER_MINOR 1
#define DRM_MINOR 2
/*
* Number of bits occupied by instance number in dev_t, currently maximum 8
* instances are supported.
*/
#define NBITSINST 3
/* Number of bits occupied in dev_t by minor node */
/*
* DRM use a "cloning" minor node mechanism to release lock on every close(2),
* thus there will be a minor node for every open(2) operation. Here we give
* the maximum DRM cloning minor node number.
*/
/* graphics name for the common graphics minor node */
#define GFX_NAME "gfx"
/* i915 extern declarations */
struct drm_softstate **);
/*
* Driver entry points prototypes
*/
void **result);
/* Softstate */
typedef struct drm_i915_state {
/* Entry points structure */
static struct cb_ops cb_i915_sun_ops = {
i915_sun_open, /* cb_open */
i915_sun_close, /* cb_close */
nodev, /* cb_strategy */
nodev, /* cb_print */
nodev, /* cb_dump */
nodev, /* cb_read */
nodev, /* cb_write */
i915_sun_ioctl, /* cb_ioctl */
i915_sun_devmap, /* cb_devmap */
nodev, /* cb_mmap */
ddi_devmap_segmap, /* cb_segmap */
nochpoll, /* cb_chpoll */
ddi_prop_op, /* cb_prop_op */
0, /* cb_stream */
};
/* Device operations structure */
static struct dev_ops i915_sun_ops = {
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
i915_sun_info, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
i915_sun_attach, /* devo_attach */
i915_sun_detach, /* devo_detach */
nodev, /* devo_reset */
&cb_i915_sun_ops, /* devo_cb_ops */
NULL /* power */
};
/* Anchor of soft state structures */
static void *i915_softc_head;
/* Loadable Driver stuff */
&mod_driverops, /* Type of module. This one is a driver */
"I915 DRM driver v%I%", /* Name of the module. */
&i915_sun_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
};
static ddi_device_acc_attr_t dev_attr = {
};
/* Identifier of this driver */
int
_init(void)
{
int e;
if ((e = ddi_soft_state_init(&i915_softc_head,
sizeof (drm_i915_state_t), DRM_MAX_INSTANCES)) != 0) {
return (e);
}
e = mod_install(&modlinkage);
if (e) {
}
return (e);
}
int
_fini(void)
{
int e;
if ((e = mod_remove(&modlinkage)) != 0)
return (e);
return (0);
}
int
{
}
static int
{
int error;
char buf[80];
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_FAILURE);
default:
return (DDI_FAILURE);
}
/* DDI_ATTACH */
/* allocate softc struct */
return (DDI_FAILURE);
}
/* link it in */
/* common graphics initialization works */
if (error != DDI_SUCCESS)
goto fail;
/* create a minor node for common graphics ops */
if (error != DDI_SUCCESS)
goto fail;
/* setup mapping for later PCI config space access */
if (error != DDI_SUCCESS) {
DRM_ERROR("i915_sun_attach: "
"PCI configuration space setup failed");
goto fail;
}
/* AGP master attach */
if (error != DDI_SUCCESS) {
DRM_ERROR("i915_sun_attach: "
"AGP master support not available");
}
/* DRM driver (i915) attach */
if (error != DDI_SUCCESS) {
DRM_ERROR("i915_sun_attach: DRM support not available\n");
}
return (DDI_SUCCESS);
fail:
DRM_ERROR("i915_sun_attach: failed, invoke detach\n");
return (error);
}
static int
{
switch (cmd) {
case DDI_DETACH:
/* i915 DRM detach */
/* AGP master detach */
if (softc->pci_cfg_hdlp) {
/* free PCI config access handle */
/* free PCI configuration handle */
(sizeof (ddi_acc_handle_t)));
}
/* graphics misc module detach */
/* remove all minor nodes */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/*ARGSUSED*/
static int
{
int error;
int instance;
error = DDI_SUCCESS;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
error = DDI_FAILURE;
} else {
error = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
error = DDI_SUCCESS;
break;
default:
error = DDI_FAILURE;
break;
}
return (error);
}
/*ARGSUSED*/
static int
{
int err;
return (ENXIO);
return (0);
return (err);
}
/*ARGSUSED*/
static int
{
int err;
return (0);
return (EBADF);
return (err);
}
/*ARGSUSED*/
static int
int *rval)
{
int err;
if (cmd == VIS_GETIDENTIFIER) {
sizeof (struct vis_identifier), mode))
return (EFAULT);
}
case GFX_MINOR:
break;
case AGPMASTER_MINOR:
softc->agp_master);
break;
case DRM_MINOR:
default: /* DRM cloning minor nodes */
/* check if it's a valide cloning minor node */
if (minor > MAX_CLONE_MINOR)
return (EBADF);
break;
}
return (err);
}
/*ARGSUSED*/
static int
{
int err;
return (-1);
case GFX_MINOR:
break;
case DRM_MINOR:
default: /* DRM cloning minor nodes */
/* check if it's a valide cloning minor node */
if (minor > MAX_CLONE_MINOR)
return (EBADF);
break;
}
return (err);
}