2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* \file drm_drv.h
|
|
|
|
* Generic driver template
|
|
|
|
*
|
|
|
|
* \author Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* \author Gareth Hughes <gareth@valinux.com>
|
|
|
|
*
|
|
|
|
* To use this template, you must at least define the following (samples
|
|
|
|
* given for the MGA driver):
|
|
|
|
*
|
|
|
|
* \code
|
|
|
|
* #define DRIVER_AUTHOR "VA Linux Systems, Inc."
|
|
|
|
*
|
|
|
|
* #define DRIVER_NAME "mga"
|
|
|
|
* #define DRIVER_DESC "Matrox G200/G400"
|
|
|
|
* #define DRIVER_DATE "20001127"
|
|
|
|
*
|
|
|
|
* #define DRIVER_MAJOR 2
|
|
|
|
* #define DRIVER_MINOR 0
|
|
|
|
* #define DRIVER_PATCHLEVEL 2
|
|
|
|
*
|
|
|
|
* #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
|
|
|
|
*
|
2004-09-27 13:51:38 -06:00
|
|
|
* #define drm_x mga_##x
|
2003-05-26 18:37:33 -06:00
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2001-02-15 01:12:14 -07:00
|
|
|
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
|
|
|
*
|
|
|
|
* Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2004-09-27 13:51:38 -06:00
|
|
|
#include "drmP.h"
|
|
|
|
#include "drm_core.h"
|
2001-08-07 12:15:10 -06:00
|
|
|
|
2004-05-09 00:45:17 -06:00
|
|
|
static void __exit drm_cleanup( drm_device_t *dev );
|
|
|
|
|
2002-07-05 02:31:11 -06:00
|
|
|
#ifndef MODULE
|
2003-05-26 18:37:33 -06:00
|
|
|
/** Use an additional macro to avoid preprocessor troubles */
|
2004-09-27 13:51:38 -06:00
|
|
|
#define DRM_OPTIONS_FUNC drm_options
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Called by the kernel to parse command-line options passed via the
|
|
|
|
* boot-loader (e.g., LILO). It calls the insmod option routine,
|
|
|
|
* parse_options().
|
|
|
|
*/
|
2004-09-27 13:51:38 -06:00
|
|
|
static int __init drm_options( char *str )
|
2002-07-05 02:31:11 -06:00
|
|
|
{
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_parse_options( str );
|
2002-07-05 02:31:11 -06:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup( DRIVER_NAME "=", DRM_OPTIONS_FUNC );
|
|
|
|
#undef DRM_OPTIONS_FUNC
|
|
|
|
#endif
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
int drm_fb_loaded = 0;
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/** Ioctl table */
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_ioctl_desc_t drm_ioctls[] = {
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { drm_irq_by_busid, 0, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = { drm_getmap, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = { drm_getclient, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = { drm_getstats, 0, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = { drm_setversion, 0, 1 },
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_noop, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_noop, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 },
|
2004-08-29 06:17:26 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = { drm_rmmap, 1, 0 },
|
2001-03-14 15:22:50 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = { drm_setsareactx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = { drm_getsareactx, 1, 0 },
|
2004-08-29 06:17:26 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { drm_addctx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { drm_rmctx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { drm_modctx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { drm_getctx, 1, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { drm_switchctx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { drm_newctx, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { drm_resctx, 1, 0 },
|
2001-03-14 15:22:50 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 },
|
2001-03-14 15:22:50 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { drm_lock, 1, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { drm_unlock, 1, 0 },
|
2003-04-22 06:07:24 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_noop, 1, 0 },
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { drm_addbufs, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { drm_markbufs, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { drm_infobufs, 1, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { drm_mapbufs, 1, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { drm_freebufs, 1, 0 },
|
2003-10-16 23:13:48 -06:00
|
|
|
/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { drm_control, 1, 1 },
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-08-24 05:15:53 -06:00
|
|
|
#if __OS_HAS_AGP
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { drm_agp_acquire, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { drm_agp_release, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { drm_agp_enable, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { drm_agp_info, 1, 0 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { drm_agp_alloc, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { drm_agp_free, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { drm_agp_bind, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { drm_agp_unbind, 1, 1 },
|
2001-02-15 01:12:14 -07:00
|
|
|
#endif
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = { drm_sg_alloc, 1, 1 },
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = { drm_sg_free, 1, 1 },
|
2001-04-30 10:18:22 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = { drm_wait_vblank, 0, 0 },
|
2001-02-15 01:12:14 -07:00
|
|
|
};
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls )
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Take down the DRM device.
|
|
|
|
*
|
|
|
|
* \param dev DRM device structure.
|
|
|
|
*
|
|
|
|
* Frees every resource in \p dev.
|
|
|
|
*
|
|
|
|
* \sa drm_device and setup().
|
|
|
|
*/
|
2004-09-30 13:26:35 -06:00
|
|
|
int drm_takedown( drm_device_t *dev )
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
|
|
|
drm_magic_entry_t *pt, *next;
|
|
|
|
drm_map_t *map;
|
2001-03-14 15:22:50 -07:00
|
|
|
drm_map_list_t *r_list;
|
2001-08-07 12:15:10 -06:00
|
|
|
struct list_head *list, *list_next;
|
2001-02-15 01:12:14 -07:00
|
|
|
drm_vma_entry_t *vma, *vma_next;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DRM_DEBUG( "\n" );
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if (dev->fn_tbl->pretakedown)
|
|
|
|
dev->fn_tbl->pretakedown(dev);
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if ( dev->irq_enabled ) drm_irq_uninstall( dev );
|
2001-02-15 01:12:14 -07:00
|
|
|
|
|
|
|
down( &dev->struct_sem );
|
|
|
|
del_timer( &dev->timer );
|
|
|
|
|
|
|
|
if ( dev->devname ) {
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( dev->devname, strlen( dev->devname ) + 1,
|
2001-02-15 01:12:14 -07:00
|
|
|
DRM_MEM_DRIVER );
|
|
|
|
dev->devname = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( dev->unique ) {
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( dev->unique, strlen( dev->unique ) + 1,
|
2001-02-15 01:12:14 -07:00
|
|
|
DRM_MEM_DRIVER );
|
|
|
|
dev->unique = NULL;
|
|
|
|
dev->unique_len = 0;
|
|
|
|
}
|
|
|
|
/* Clear pid list */
|
|
|
|
for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) {
|
|
|
|
for ( pt = dev->magiclist[i].head ; pt ; pt = next ) {
|
|
|
|
next = pt->next;
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( pt, sizeof(*pt), DRM_MEM_MAGIC );
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
|
|
|
dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
|
|
|
|
}
|
|
|
|
|
2003-06-18 18:09:52 -06:00
|
|
|
/* Clear AGP information */
|
2004-09-05 04:54:59 -06:00
|
|
|
if (drm_core_has_AGP(dev) && dev->agp) {
|
2003-06-18 18:09:52 -06:00
|
|
|
drm_agp_mem_t *entry;
|
|
|
|
drm_agp_mem_t *nexte;
|
|
|
|
|
|
|
|
/* Remove AGP resources, but leave dev->agp
|
|
|
|
intact until drv_cleanup is called. */
|
|
|
|
for ( entry = dev->agp->memory ; entry ; entry = nexte ) {
|
|
|
|
nexte = entry->next;
|
2004-09-27 13:51:38 -06:00
|
|
|
if ( entry->bound ) drm_unbind_agp( entry->memory );
|
|
|
|
drm_free_agp( entry->memory, entry->pages );
|
|
|
|
drm_free( entry, sizeof(*entry), DRM_MEM_AGPLISTS );
|
2003-06-18 18:09:52 -06:00
|
|
|
}
|
|
|
|
dev->agp->memory = NULL;
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if ( dev->agp->acquired ) drm_agp_do_release();
|
2003-06-18 18:09:52 -06:00
|
|
|
|
|
|
|
dev->agp->acquired = 0;
|
|
|
|
dev->agp->enabled = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
/* Clear vma list (only built for debugging) */
|
|
|
|
if ( dev->vmalist ) {
|
|
|
|
for ( vma = dev->vmalist ; vma ; vma = vma_next ) {
|
|
|
|
vma_next = vma->next;
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( vma, sizeof(*vma), DRM_MEM_VMAS );
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
|
|
|
dev->vmalist = NULL;
|
|
|
|
}
|
|
|
|
|
2001-03-14 15:22:50 -07:00
|
|
|
if( dev->maplist ) {
|
2003-08-06 05:46:21 -06:00
|
|
|
list_for_each_safe( list, list_next, &dev->maplist->head ) {
|
2001-03-14 15:22:50 -07:00
|
|
|
r_list = (drm_map_list_t *)list;
|
|
|
|
|
2003-08-06 05:46:21 -06:00
|
|
|
if ( ( map = r_list->map ) ) {
|
|
|
|
switch ( map->type ) {
|
|
|
|
case _DRM_REGISTERS:
|
|
|
|
case _DRM_FRAME_BUFFER:
|
2004-08-24 04:43:45 -06:00
|
|
|
continue;
|
|
|
|
|
2003-08-06 05:46:21 -06:00
|
|
|
case _DRM_SHM:
|
|
|
|
vfree(map->handle);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _DRM_AGP:
|
|
|
|
/* Do nothing here, because this is all
|
|
|
|
* handled in the AGP/GART driver.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case _DRM_SCATTER_GATHER:
|
2004-08-24 05:15:53 -06:00
|
|
|
/* Handle it */
|
2004-08-30 05:34:51 -06:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_sg_cleanup(dev->sg);
|
2003-08-06 05:46:21 -06:00
|
|
|
dev->sg = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
2003-08-06 05:46:21 -06:00
|
|
|
list_del( list );
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS);
|
2001-03-14 15:22:50 -07:00
|
|
|
}
|
|
|
|
}
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-05 04:54:59 -06:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
|
2001-02-15 01:12:14 -07:00
|
|
|
for ( i = 0 ; i < dev->queue_count ; i++ ) {
|
2004-08-17 07:10:05 -06:00
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
if ( dev->queuelist[i] ) {
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( dev->queuelist[i],
|
2001-02-15 01:12:14 -07:00
|
|
|
sizeof(*dev->queuelist[0]),
|
|
|
|
DRM_MEM_QUEUES );
|
|
|
|
dev->queuelist[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( dev->queuelist,
|
2001-02-15 01:12:14 -07:00
|
|
|
dev->queue_slots * sizeof(*dev->queuelist),
|
|
|
|
DRM_MEM_QUEUES );
|
|
|
|
dev->queuelist = NULL;
|
|
|
|
}
|
|
|
|
dev->queue_count = 0;
|
|
|
|
|
2004-08-30 05:34:51 -06:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_HAVE_DMA))
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_dma_takedown( dev );
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
if ( dev->lock.hw_lock ) {
|
2002-09-21 17:18:54 -06:00
|
|
|
dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
|
2004-07-15 07:03:55 -06:00
|
|
|
dev->lock.filp = NULL;
|
2001-02-15 01:12:14 -07:00
|
|
|
wake_up_interruptible( &dev->lock.lock_queue );
|
|
|
|
}
|
|
|
|
up( &dev->struct_sem );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
void __exit drm_cleanup_pci(struct pci_dev *pdev)
|
2004-05-09 00:45:17 -06:00
|
|
|
{
|
|
|
|
drm_device_t *dev = pci_get_drvdata(pdev);
|
2004-09-04 17:21:40 -06:00
|
|
|
|
2004-05-09 00:45:17 -06:00
|
|
|
pci_set_drvdata(pdev, NULL);
|
2004-09-10 10:44:28 -06:00
|
|
|
pci_release_regions(pdev);
|
2004-09-16 12:42:03 -06:00
|
|
|
if (dev)
|
|
|
|
drm_cleanup(dev);
|
2003-10-16 21:14:39 -06:00
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
EXPORT_SYMBOL(drm_cleanup_pci);
|
2003-10-16 21:14:39 -06:00
|
|
|
|
2004-09-16 12:42:03 -06:00
|
|
|
#ifdef MODULE
|
|
|
|
static char *drm_opts = NULL;
|
|
|
|
#endif
|
|
|
|
MODULE_PARM( drm_opts, "s" );
|
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Module initialization. Called via init_module at module load time, or via
|
2001-02-15 01:12:14 -07:00
|
|
|
* linux/init/main.c (this is not currently supported).
|
2003-05-26 18:37:33 -06:00
|
|
|
*
|
|
|
|
* \return zero on success or a negative number on failure.
|
|
|
|
*
|
2003-10-16 21:14:39 -06:00
|
|
|
* Initializes an array of drm_device structures, and attempts to
|
2003-05-26 18:37:33 -06:00
|
|
|
* initialize all available devices, using consecutive minors, registering the
|
|
|
|
* stubs and initializing the AGP device.
|
|
|
|
*
|
|
|
|
* Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and
|
|
|
|
* after the initialization for driver customization.
|
2001-02-15 01:12:14 -07:00
|
|
|
*/
|
2004-09-27 13:51:38 -06:00
|
|
|
int __devinit drm_init( struct pci_driver *driver, struct pci_device_id* pciidlist, struct drm_driver_fn *driver_fn)
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
2004-08-28 17:59:51 -06:00
|
|
|
struct pci_dev *pdev;
|
2004-08-26 20:26:07 -06:00
|
|
|
struct pci_device_id *pid;
|
2004-05-09 00:45:17 -06:00
|
|
|
int i;
|
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
DRM_DEBUG( "\n" );
|
|
|
|
|
|
|
|
#ifdef MODULE
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_parse_options( drm_opts );
|
2001-02-15 01:12:14 -07:00
|
|
|
#endif
|
2001-07-30 13:59:39 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_mem_init();
|
2004-05-09 00:45:17 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
for (i=0; (pciidlist[i].vendor != 0) && !drm_fb_loaded; i++) {
|
|
|
|
pid = &pciidlist[i];
|
2004-08-26 20:26:07 -06:00
|
|
|
|
2004-08-28 17:59:51 -06:00
|
|
|
pdev = NULL;
|
2004-08-26 20:26:07 -06:00
|
|
|
/* pass back in pdev to account for multiple identical cards */
|
|
|
|
while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev))) {
|
|
|
|
/* is there already a driver loaded, or (short circuit saves work) */
|
|
|
|
/* does something like VesaFB have control of the memory region? */
|
|
|
|
if (pci_dev_driver(pdev) || pci_request_regions(pdev, "DRM scan")) {
|
|
|
|
/* go into stealth mode */
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_fb_loaded = 1;
|
2004-05-09 00:45:17 -06:00
|
|
|
pci_dev_put(pdev);
|
2004-08-26 20:26:07 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* no fbdev or vesadev, put things back and wait for normal probe */
|
|
|
|
pci_release_regions(pdev);
|
2004-05-09 00:45:17 -06:00
|
|
|
}
|
2003-10-22 23:56:13 -06:00
|
|
|
}
|
2004-05-09 00:45:17 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if (drm_fb_loaded == 0)
|
|
|
|
pci_register_driver(driver);
|
2004-08-26 20:26:07 -06:00
|
|
|
else {
|
2004-09-27 13:51:38 -06:00
|
|
|
for (i=0; pciidlist[i].vendor != 0; i++) {
|
|
|
|
pid = &pciidlist[i];
|
2004-08-26 20:26:07 -06:00
|
|
|
|
2004-08-28 17:59:51 -06:00
|
|
|
pdev = NULL;
|
2004-08-26 20:26:07 -06:00
|
|
|
/* pass back in pdev to account for multiple identical cards */
|
|
|
|
while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev))) {
|
|
|
|
/* stealth mode requires a manual probe */
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_probe(pdev, &pciidlist[i], driver_fn);
|
2004-08-26 20:26:07 -06:00
|
|
|
}
|
|
|
|
}
|
2004-05-09 00:45:17 -06:00
|
|
|
DRM_INFO("Used old pci detect: framebuffer loaded\n");
|
2004-08-26 20:26:07 -06:00
|
|
|
}
|
2003-10-22 23:56:13 -06:00
|
|
|
return 0;
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
EXPORT_SYMBOL(drm_init);
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Called via cleanup_module() at module unload time.
|
|
|
|
*
|
|
|
|
* Cleans up all DRM device, calling takedown().
|
|
|
|
*
|
|
|
|
* \sa drm_init().
|
2001-02-15 01:12:14 -07:00
|
|
|
*/
|
2004-05-09 00:45:17 -06:00
|
|
|
static void __exit drm_cleanup( drm_device_t *dev )
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
2004-08-24 04:43:45 -06:00
|
|
|
drm_map_t *map;
|
|
|
|
drm_map_list_t *r_list;
|
|
|
|
struct list_head *list, *list_next;
|
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
DRM_DEBUG( "\n" );
|
2004-05-09 00:45:17 -06:00
|
|
|
if (!dev) {
|
|
|
|
DRM_ERROR("cleanup called no dev\n");
|
|
|
|
return;
|
|
|
|
}
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_takedown(dev);
|
2004-05-09 00:45:17 -06:00
|
|
|
|
2004-08-24 04:43:45 -06:00
|
|
|
if( dev->maplist ) {
|
|
|
|
list_for_each_safe( list, list_next, &dev->maplist->head ) {
|
|
|
|
r_list = (drm_map_list_t *)list;
|
|
|
|
|
|
|
|
if ( ( map = r_list->map ) ) {
|
|
|
|
switch ( map->type ) {
|
|
|
|
case _DRM_REGISTERS:
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_ioremapfree( map->handle, map->size, dev );
|
2004-08-24 04:43:45 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case _DRM_FRAME_BUFFER:
|
2004-09-04 17:21:40 -06:00
|
|
|
if ( drm_core_has_MTRR(dev)) {
|
2004-08-24 05:15:53 -06:00
|
|
|
if ( map->mtrr >= 0 ) {
|
|
|
|
int retcode;
|
|
|
|
retcode = mtrr_del( map->mtrr,
|
|
|
|
map->offset,
|
|
|
|
map->size );
|
|
|
|
DRM_DEBUG( "mtrr_del=%d\n", retcode );
|
|
|
|
}
|
2004-08-24 04:43:45 -06:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _DRM_SHM:
|
|
|
|
case _DRM_AGP:
|
|
|
|
case _DRM_SCATTER_GATHER:
|
|
|
|
DRM_DEBUG("Extra maplist item\n");
|
|
|
|
break;
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free(map, sizeof(*map), DRM_MEM_MAPS);
|
2004-08-24 04:43:45 -06:00
|
|
|
}
|
|
|
|
list_del( list );
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free(r_list, sizeof(*r_list), DRM_MEM_MAPS);
|
2004-08-24 04:43:45 -06:00
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS);
|
2004-08-24 04:43:45 -06:00
|
|
|
dev->maplist = NULL;
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
if (drm_fb_loaded==0)
|
2004-06-21 05:46:52 -06:00
|
|
|
pci_disable_device(dev->pdev);
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_ctxbitmap_cleanup( dev );
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-04 17:21:40 -06:00
|
|
|
if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && dev->agp && dev->agp->agp_mtrr >= 0) {
|
2004-05-09 00:45:17 -06:00
|
|
|
int retval;
|
|
|
|
retval = mtrr_del( dev->agp->agp_mtrr,
|
2001-02-15 01:12:14 -07:00
|
|
|
dev->agp->agp_info.aper_base,
|
|
|
|
dev->agp->agp_info.aper_size*1024*1024 );
|
2004-05-09 00:45:17 -06:00
|
|
|
DRM_DEBUG( "mtrr_del=%d\n", retval );
|
|
|
|
}
|
2004-09-04 17:21:40 -06:00
|
|
|
|
|
|
|
if (drm_core_has_AGP(dev) && dev->agp ) {
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_free( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS );
|
2004-05-09 00:45:17 -06:00
|
|
|
dev->agp = NULL;
|
2001-07-30 13:59:39 -06:00
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
if (dev->fn_tbl->postcleanup)
|
|
|
|
dev->fn_tbl->postcleanup(dev);
|
2004-09-16 12:42:03 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if ( drm_put_minor(dev) )
|
2004-09-16 12:42:03 -06:00
|
|
|
DRM_ERROR( "Cannot unload module\n" );
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
void __exit drm_exit (struct pci_driver *driver)
|
2004-05-09 00:45:17 -06:00
|
|
|
{
|
2004-09-16 12:42:03 -06:00
|
|
|
int i;
|
|
|
|
drm_device_t *dev;
|
|
|
|
drm_minor_t *minor;
|
|
|
|
|
2004-07-14 06:34:55 -06:00
|
|
|
DRM_DEBUG( "\n" );
|
2004-09-27 13:51:38 -06:00
|
|
|
if (drm_fb_loaded) {
|
|
|
|
for (i = 0; i < cards_limit; i++) {
|
|
|
|
minor = &drm_minors[i];
|
|
|
|
dev = minor->dev;
|
|
|
|
DRM_DEBUG("fb loaded release minor %d\n", dev->minor);
|
2004-09-30 12:13:33 -06:00
|
|
|
if (minor->class == DRM_MINOR_PRIMARY) {
|
2004-09-27 13:51:38 -06:00
|
|
|
/* release the pci driver */
|
|
|
|
if (dev->pdev)
|
|
|
|
pci_dev_put(dev->pdev);
|
|
|
|
drm_cleanup(dev);
|
2004-09-16 12:42:03 -06:00
|
|
|
}
|
2004-05-09 00:45:17 -06:00
|
|
|
}
|
2004-09-16 12:42:03 -06:00
|
|
|
} else
|
2004-09-27 13:51:38 -06:00
|
|
|
pci_unregister_driver(driver);
|
2004-05-09 00:45:17 -06:00
|
|
|
DRM_INFO( "Module unloaded\n" );
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
EXPORT_SYMBOL(drm_exit);
|
2004-05-09 00:45:17 -06:00
|
|
|
|
2004-09-30 13:26:35 -06:00
|
|
|
/** File operations structure */
|
|
|
|
static struct file_operations drm_stub_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = drm_stub_open
|
|
|
|
};
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
static int __init drm_core_init(void)
|
|
|
|
{
|
|
|
|
int ret = -ENOMEM;
|
2004-05-09 00:45:17 -06:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
cards_limit = (cards_limit < DRM_MAX_MINOR + 1 ? cards_limit : DRM_MAX_MINOR + 1);
|
|
|
|
drm_minors = drm_calloc(cards_limit,
|
|
|
|
sizeof(*drm_minors), DRM_MEM_STUB);
|
|
|
|
if(!drm_minors)
|
|
|
|
goto err_p1;
|
|
|
|
|
|
|
|
if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops))
|
|
|
|
goto err_p1;
|
|
|
|
|
|
|
|
drm_class = drm_sysfs_create(THIS_MODULE, "drm");
|
|
|
|
if (IS_ERR(drm_class)) {
|
|
|
|
printk (KERN_ERR "DRM: Error creating drm class.\n");
|
|
|
|
ret = PTR_ERR(drm_class);
|
|
|
|
goto err_p2;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_proc_root = create_proc_entry("dri", S_IFDIR, NULL);
|
|
|
|
if (!drm_proc_root) {
|
|
|
|
DRM_ERROR("Cannot create /proc/dri\n");
|
|
|
|
ret = -1;
|
|
|
|
goto err_p3;
|
|
|
|
}
|
2004-09-28 16:25:06 -06:00
|
|
|
drm_agp = (drm_agp_t *)inter_module_get("drm_agp");
|
2004-09-27 13:51:38 -06:00
|
|
|
|
|
|
|
DRM_INFO( "Initialized %s %d.%d.%d %s\n",
|
|
|
|
DRIVER_NAME,
|
|
|
|
DRIVER_MAJOR,
|
|
|
|
DRIVER_MINOR,
|
|
|
|
DRIVER_PATCHLEVEL,
|
|
|
|
DRIVER_DATE
|
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
err_p3:
|
|
|
|
drm_sysfs_destroy(drm_class);
|
|
|
|
err_p2:
|
|
|
|
unregister_chrdev(DRM_MAJOR, "drm");
|
|
|
|
drm_free(drm_minors, sizeof(*drm_minors) * cards_limit, DRM_MEM_STUB);
|
|
|
|
err_p1:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit drm_core_exit (void)
|
|
|
|
{
|
2004-09-28 16:25:06 -06:00
|
|
|
if (drm_agp)
|
|
|
|
inter_module_put("drm_agp");
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
remove_proc_entry("dri", NULL);
|
|
|
|
drm_sysfs_destroy(drm_class);
|
|
|
|
|
|
|
|
unregister_chrdev(DRM_MAJOR, "drm");
|
|
|
|
|
|
|
|
drm_free(drm_minors, sizeof(*drm_minors) *
|
|
|
|
cards_limit, DRM_MEM_STUB);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init( drm_core_init );
|
|
|
|
module_exit( drm_core_exit );
|
2001-02-15 01:12:14 -07:00
|
|
|
|
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Get version information
|
|
|
|
*
|
|
|
|
* \param inode device inode.
|
|
|
|
* \param filp file pointer.
|
|
|
|
* \param cmd command.
|
|
|
|
* \param arg user argument, pointing to a drm_version structure.
|
|
|
|
* \return zero on success or negative number on failure.
|
|
|
|
*
|
|
|
|
* Fills in the version information in \p arg.
|
|
|
|
*/
|
2004-09-27 13:51:38 -06:00
|
|
|
int drm_version( struct inode *inode, struct file *filp,
|
2001-02-15 01:12:14 -07:00
|
|
|
unsigned int cmd, unsigned long arg )
|
|
|
|
{
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
2004-07-20 06:43:12 -06:00
|
|
|
drm_version_t __user *argp = (void __user *)arg;
|
2001-02-15 01:12:14 -07:00
|
|
|
drm_version_t version;
|
2004-09-27 13:51:38 -06:00
|
|
|
int ret;
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-07-20 06:43:12 -06:00
|
|
|
if ( copy_from_user( &version, argp, sizeof(version) ) )
|
2001-02-15 01:12:14 -07:00
|
|
|
return -EFAULT;
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
/* version is a required function to return the personality module version */
|
|
|
|
if ((ret = dev->fn_tbl->version(&version)))
|
|
|
|
return ret;
|
|
|
|
|
2004-07-20 06:43:12 -06:00
|
|
|
if ( copy_to_user( argp, &version, sizeof(version) ) )
|
2001-02-15 01:12:14 -07:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/**
|
|
|
|
* Called whenever a process performs an ioctl on /dev/drm.
|
|
|
|
*
|
|
|
|
* \param inode device inode.
|
|
|
|
* \param filp file pointer.
|
|
|
|
* \param cmd command.
|
|
|
|
* \param arg user argument.
|
|
|
|
* \return zero on success or negative number on failure.
|
|
|
|
*
|
|
|
|
* Looks up the ioctl function in the ::ioctls table, checking for root
|
|
|
|
* previleges if so required, and dispatches to the respective function.
|
2001-02-15 01:12:14 -07:00
|
|
|
*/
|
2004-09-27 13:51:38 -06:00
|
|
|
int drm_ioctl( struct inode *inode, struct file *filp,
|
2001-02-15 01:12:14 -07:00
|
|
|
unsigned int cmd, unsigned long arg )
|
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
|
|
|
drm_device_t *dev = priv->dev;
|
|
|
|
drm_ioctl_desc_t *ioctl;
|
|
|
|
drm_ioctl_t *func;
|
2004-09-27 13:51:38 -06:00
|
|
|
unsigned int nr = DRM_IOCTL_NR(cmd);
|
|
|
|
int retcode = -EINVAL;
|
2001-02-15 01:12:14 -07:00
|
|
|
|
|
|
|
atomic_inc( &dev->ioctl_count );
|
|
|
|
atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] );
|
|
|
|
++priv->ioctl_count;
|
|
|
|
|
2003-03-25 04:36:43 -07:00
|
|
|
DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
|
2004-04-08 06:22:22 -06:00
|
|
|
current->pid, cmd, nr, (long)old_encode_dev(dev->device),
|
2003-03-25 04:36:43 -07:00
|
|
|
priv->authenticated );
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
if (nr < DRIVER_IOCTL_COUNT)
|
|
|
|
ioctl = &drm_ioctls[nr];
|
|
|
|
else if ((nr >= DRM_COMMAND_BASE) || (nr < DRM_COMMAND_BASE + dev->fn_tbl->num_ioctls))
|
|
|
|
ioctl = &dev->fn_tbl->ioctls[nr - DRM_COMMAND_BASE];
|
|
|
|
else
|
|
|
|
goto err_i1;
|
|
|
|
|
|
|
|
func = ioctl->func;
|
|
|
|
if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->fn_tbl->dma_ioctl) /* Local override? */
|
|
|
|
func = dev->fn_tbl->dma_ioctl;
|
|
|
|
|
|
|
|
if ( !func ) {
|
|
|
|
DRM_DEBUG( "no function\n" );
|
2001-02-15 01:12:14 -07:00
|
|
|
retcode = -EINVAL;
|
2004-09-27 13:51:38 -06:00
|
|
|
} else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )||
|
|
|
|
( ioctl->auth_needed && !priv->authenticated ) ) {
|
|
|
|
retcode = -EACCES;
|
2001-02-15 01:12:14 -07:00
|
|
|
} else {
|
2004-09-27 13:51:38 -06:00
|
|
|
retcode = func( inode, filp, cmd, arg );
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
err_i1:
|
2001-02-15 01:12:14 -07:00
|
|
|
atomic_dec( &dev->ioctl_count );
|
2004-09-20 13:23:27 -06:00
|
|
|
if (retcode) DRM_DEBUG( "ret = %x\n", retcode);
|
2001-02-15 01:12:14 -07:00
|
|
|
return retcode;
|
|
|
|
}
|
2004-09-27 13:51:38 -06:00
|
|
|
EXPORT_SYMBOL(drm_ioctl);
|
2001-02-15 01:12:14 -07:00
|
|
|
|