2003-05-26 18:37:33 -06:00
|
|
|
/**
|
2004-10-18 08:16:41 -06:00
|
|
|
* \file drm_drv.c
|
2003-05-26 18:37:33 -06:00
|
|
|
* 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_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
|
|
|
|
2006-08-19 00:56:03 -06:00
|
|
|
static void drm_cleanup(drm_device_t * dev);
|
2004-09-27 13:51:38 -06:00
|
|
|
int drm_fb_loaded = 0;
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2005-06-04 00:18:11 -06:00
|
|
|
static int drm_version(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg);
|
|
|
|
|
2003-05-26 18:37:33 -06:00
|
|
|
/** Ioctl table */
|
2006-02-17 19:53:36 -07:00
|
|
|
static drm_ioctl_desc_t drm_ioctls[] = {
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = {drm_version, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = {drm_getunique, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = {drm_getmagic, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = {drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = {drm_getmap, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = {drm_getclient, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = {drm_getstats, 0},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = {drm_setversion, DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = {drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = {drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = {drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = {drm_authmagic, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = {drm_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = {drm_rmmap_ioctl, DRM_AUTH},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, DRM_AUTH},
|
|
|
|
|
2006-04-03 02:06:51 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, DRM_AUTH|DRM_ROOT_ONLY},
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, DRM_AUTH},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = {drm_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = {drm_resctx, DRM_AUTH},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = {drm_adddraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = {drm_rmdraw, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = {drm_lock, DRM_AUTH},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = {drm_unlock, DRM_AUTH},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = {drm_noop, DRM_AUTH},
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = {drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = {drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = {drm_infobufs, DRM_AUTH},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = {drm_mapbufs, DRM_AUTH},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = {drm_freebufs, DRM_AUTH},
|
2003-10-16 23:13:48 -06:00
|
|
|
/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_DMA)] = {NULL, DRM_AUTH},
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = {drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-08-24 05:15:53 -06:00
|
|
|
#if __OS_HAS_AGP
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = {drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = {drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = {drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = {drm_agp_info_ioctl, DRM_AUTH},
|
2005-11-02 17:38:25 -07:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = {drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = {drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = {drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = {drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
2001-02-15 01:12:14 -07:00
|
|
|
#endif
|
|
|
|
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = {drm_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
2001-04-30 10:18:22 -06:00
|
|
|
|
2005-09-02 21:27:14 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0},
|
2006-08-21 13:02:08 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_FENCE)] = {drm_fence_ioctl, DRM_AUTH},
|
2006-08-30 05:04:08 -06:00
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_BUFOBJ)] = {drm_bo_ioctl, DRM_AUTH},
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_MM_INIT)] = {drm_mm_init_ioctl,
|
2006-08-23 08:05:47 -06:00
|
|
|
DRM_AUTH },
|
|
|
|
|
|
|
|
[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
|
2001-02-15 01:12:14 -07:00
|
|
|
};
|
|
|
|
|
2006-08-19 00:43:16 -06:00
|
|
|
#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2006-09-01 07:41:55 -06: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.
|
|
|
|
*
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
* \sa drm_device
|
2003-05-26 18:37:33 -06:00
|
|
|
*/
|
2005-08-04 21:50:23 -06:00
|
|
|
int drm_lastclose(drm_device_t * dev)
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
|
|
|
drm_magic_entry_t *pt, *next;
|
2001-03-14 15:22:50 -07:00
|
|
|
drm_map_list_t *r_list;
|
2001-02-15 01:12:14 -07:00
|
|
|
drm_vma_entry_t *vma, *vma_next;
|
|
|
|
int i;
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
DRM_DEBUG("\n");
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2005-08-04 21:50:23 -06:00
|
|
|
if (dev->driver->lastclose)
|
|
|
|
dev->driver->lastclose(dev);
|
|
|
|
DRM_DEBUG("driver lastclose completed\n");
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2005-03-25 02:05:10 -07:00
|
|
|
if (dev->unique) {
|
|
|
|
drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
|
|
|
|
dev->unique=NULL;
|
|
|
|
dev->unique_len=0;
|
|
|
|
}
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (dev->irq_enabled)
|
|
|
|
drm_irq_uninstall(dev);
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2006-08-30 11:24:04 -06:00
|
|
|
/* Free drawable information memory */
|
|
|
|
for (i = 0; i < dev->drw_bitfield_length / sizeof(*dev->drw_bitfield);
|
|
|
|
i++) {
|
|
|
|
drm_drawable_info_t *info = drm_get_drawable_info(dev, i);
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
drm_free(info->rects, info->num_rects *
|
|
|
|
sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
|
|
|
|
drm_free(info, sizeof(*info), DRM_MEM_BUFS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-23 18:51:27 -06:00
|
|
|
mutex_lock(&dev->struct_mutex);
|
2004-09-30 15:12:10 -06:00
|
|
|
del_timer(&dev->timer);
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-12-07 05:18:47 -07:00
|
|
|
if (dev->unique) {
|
|
|
|
drm_free(dev->unique, strlen(dev->unique) + 1, DRM_MEM_DRIVER);
|
|
|
|
dev->unique = NULL;
|
|
|
|
dev->unique_len = 0;
|
|
|
|
}
|
|
|
|
|
2006-08-14 09:11:14 -06:00
|
|
|
if (dev->magicfree.next) {
|
|
|
|
list_for_each_entry_safe(pt, next, &dev->magicfree, head) {
|
|
|
|
list_del(&pt->head);
|
|
|
|
drm_ht_remove_item(&dev->magiclist, &pt->hash_item);
|
|
|
|
drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC);
|
|
|
|
}
|
2006-08-16 08:36:56 -06:00
|
|
|
drm_ht_remove(&dev->magiclist);
|
2006-08-14 09:11:14 -06:00
|
|
|
}
|
2006-06-06 11:46:17 -06:00
|
|
|
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-30 15:12:10 -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;
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
/* Remove AGP resources, but leave dev->agp
|
|
|
|
intact until drv_cleanup is called. */
|
|
|
|
for (entry = dev->agp->memory; entry; entry = nexte) {
|
2003-06-18 18:09:52 -06:00
|
|
|
nexte = entry->next;
|
2004-09-30 15:12:10 -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-30 15:12:10 -06:00
|
|
|
if (dev->agp->acquired)
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
drm_agp_release(dev);
|
2003-06-18 18:09:52 -06:00
|
|
|
|
|
|
|
dev->agp->acquired = 0;
|
2004-09-30 15:12:10 -06:00
|
|
|
dev->agp->enabled = 0;
|
2003-06-18 18:09:52 -06:00
|
|
|
}
|
- Remove drm_initmap and replace its usage with drm_addmap. This reduces
code duplication, and it also hands you the map pointer so you don't
need to re-find it.
- Remove the permanent maps flag. Instead, for register and framebuffer
maps, we always check whether there's already a map of that type and
offset around. Move the Radeon map initialization into presetup (first
open) so it happens again after every takedown.
- Remove the split cleanup of maps between driver takedown (last close) and
cleanup (module unload). Instead, always tear down maps on takedown,
and drivers can recreate them on first open.
- Make MGA always use addmap, instead of allocating consistent memory in
the PCI case and then faking up a map for it, which accomplished nearly
the same thing, in a different order. Note that the maps are exposed to
the user again: we may want to expose a flag to avoid this, but it's
not a security concern, and saves us a lot of code.
- Remove rmmaps in the MGA driver. Since the function is only called during
takedown anyway, we can let them die a natural death.
- Make removal of maps happen in one function, which is called by both
drm_takedown and drm_rmmap_ioctl.
Reviewed by: idr (previous revision) Tested on: mga (old/new/pci dma),
radeon, savage
2005-06-28 14:58:34 -06:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) {
|
|
|
|
drm_sg_cleanup(dev->sg);
|
|
|
|
dev->sg = NULL;
|
|
|
|
}
|
2003-06-18 18:09:52 -06:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
/* Clear vma list (only built for debugging) */
|
|
|
|
if (dev->vmalist) {
|
|
|
|
for (vma = dev->vmalist; vma; vma = vma_next) {
|
2001-02-15 01:12:14 -07:00
|
|
|
vma_next = vma->next;
|
2004-09-30 15:12:10 -06:00
|
|
|
drm_free(vma, sizeof(*vma), DRM_MEM_VMAS);
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
|
|
|
dev->vmalist = NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (dev->maplist) {
|
- Remove drm_initmap and replace its usage with drm_addmap. This reduces
code duplication, and it also hands you the map pointer so you don't
need to re-find it.
- Remove the permanent maps flag. Instead, for register and framebuffer
maps, we always check whether there's already a map of that type and
offset around. Move the Radeon map initialization into presetup (first
open) so it happens again after every takedown.
- Remove the split cleanup of maps between driver takedown (last close) and
cleanup (module unload). Instead, always tear down maps on takedown,
and drivers can recreate them on first open.
- Make MGA always use addmap, instead of allocating consistent memory in
the PCI case and then faking up a map for it, which accomplished nearly
the same thing, in a different order. Note that the maps are exposed to
the user again: we may want to expose a flag to avoid this, but it's
not a security concern, and saves us a lot of code.
- Remove rmmaps in the MGA driver. Since the function is only called during
takedown anyway, we can let them die a natural death.
- Make removal of maps happen in one function, which is called by both
drm_takedown and drm_rmmap_ioctl.
Reviewed by: idr (previous revision) Tested on: mga (old/new/pci dma),
radeon, savage
2005-06-28 14:58:34 -06:00
|
|
|
while (!list_empty(&dev->maplist->head)) {
|
|
|
|
struct list_head *list = dev->maplist->head.next;
|
|
|
|
r_list = list_entry(list, drm_map_list_t, head);
|
|
|
|
drm_rmmap_locked(dev, r_list->map);
|
2004-09-30 15:12:10 -06:00
|
|
|
}
|
|
|
|
}
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-05 04:54:59 -06:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) {
|
2004-09-30 15:12:10 -06:00
|
|
|
for (i = 0; i < dev->queue_count; i++) {
|
2004-08-17 07:10:05 -06:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (dev->queuelist[i]) {
|
|
|
|
drm_free(dev->queuelist[i],
|
|
|
|
sizeof(*dev->queuelist[0]),
|
|
|
|
DRM_MEM_QUEUES);
|
2001-02-15 01:12:14 -07:00
|
|
|
dev->queuelist[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2004-09-30 15:12:10 -06:00
|
|
|
drm_free(dev->queuelist,
|
|
|
|
dev->queue_slots * sizeof(*dev->queuelist),
|
|
|
|
DRM_MEM_QUEUES);
|
2001-02-15 01:12:14 -07:00
|
|
|
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-30 15:12:10 -06:00
|
|
|
drm_dma_takedown(dev);
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (dev->lock.hw_lock) {
|
|
|
|
dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */
|
2004-07-15 07:03:55 -06:00
|
|
|
dev->lock.filp = NULL;
|
2004-09-30 15:12:10 -06:00
|
|
|
wake_up_interruptible(&dev->lock.lock_queue);
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
2006-10-03 04:08:07 -06:00
|
|
|
dev->dev_mapping = NULL;
|
2006-07-23 18:51:27 -06:00
|
|
|
mutex_unlock(&dev->struct_mutex);
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2006-09-01 07:41:55 -06:00
|
|
|
if (drm_bo_clean_mm(dev)) {
|
|
|
|
DRM_ERROR("DRM memory manager still busy. "
|
|
|
|
"System is unstable. Please reboot.\n");
|
|
|
|
}
|
2005-08-04 21:50:23 -06:00
|
|
|
DRM_DEBUG("lastclose completed\n");
|
2001-02-15 01:12:14 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-23 19:09:41 -06:00
|
|
|
void 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-30 15:12:10 -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
|
|
|
|
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.
|
2004-09-30 15:12:10 -06:00
|
|
|
*
|
2003-05-26 18:37:33 -06:00
|
|
|
* 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-10-11 21:59:17 -06:00
|
|
|
int drm_init(struct drm_driver *driver,
|
|
|
|
struct pci_device_id *pciidlist)
|
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;
|
2005-06-21 23:49:56 -06:00
|
|
|
int rc, i;
|
2004-09-30 15:12:10 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
for (i = 0; (pciidlist[i].vendor != 0) && !drm_fb_loaded; i++) {
|
2004-09-27 13:51:38 -06:00
|
|
|
pid = &pciidlist[i];
|
2004-09-30 15:12:10 -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 */
|
2004-09-30 15:12:10 -06:00
|
|
|
while ((pdev =
|
|
|
|
pci_get_subsys(pid->vendor, pid->device, pid->subvendor,
|
|
|
|
pid->subdevice, pdev))) {
|
2004-08-26 20:26:07 -06:00
|
|
|
/* is there already a driver loaded, or (short circuit saves work) */
|
|
|
|
/* does something like VesaFB have control of the memory region? */
|
2004-09-30 15:12:10 -06:00
|
|
|
if (pci_dev_driver(pdev)
|
|
|
|
|| pci_request_regions(pdev, "DRM scan")) {
|
2004-08-26 20:26:07 -06:00
|
|
|
/* 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-09-30 15:12:10 -06:00
|
|
|
|
2005-05-27 18:08:53 -06:00
|
|
|
if (!drm_fb_loaded)
|
2004-10-11 21:59:17 -06:00
|
|
|
pci_register_driver(&driver->pci_driver);
|
2004-08-26 20:26:07 -06:00
|
|
|
else {
|
2004-09-30 15:12:10 -06:00
|
|
|
for (i = 0; pciidlist[i].vendor != 0; i++) {
|
2004-09-27 13:51:38 -06:00
|
|
|
pid = &pciidlist[i];
|
2004-09-30 15:12:10 -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 */
|
2004-09-30 15:12:10 -06:00
|
|
|
while ((pdev =
|
|
|
|
pci_get_subsys(pid->vendor, pid->device,
|
|
|
|
pid->subvendor, pid->subdevice,
|
|
|
|
pdev))) {
|
2004-08-26 20:26:07 -06:00
|
|
|
/* stealth mode requires a manual probe */
|
2004-10-08 08:31:25 -06:00
|
|
|
pci_dev_get(pdev);
|
2005-06-21 23:49:56 -06:00
|
|
|
if ((rc = drm_get_dev(pdev, &pciidlist[i], driver))) {
|
|
|
|
pci_dev_put(pdev);
|
|
|
|
return rc;
|
|
|
|
}
|
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.
|
|
|
|
*
|
2005-08-04 21:50:23 -06:00
|
|
|
* Cleans up all DRM device, calling drm_lastclose().
|
2004-09-30 15:12:10 -06:00
|
|
|
*
|
Adds support for PCI cards to MGA DRM
This patch adds serveral new ioctls and a new query to get_param query to
support PCI MGA cards.
Two ioctls were added to implement interrupt based waiting. With this
change, the client-side driver no longer needs to map the primary DMA
region or the MMIO region. Previously, end-of-frame waiting was done by
busy waiting in the client-side driver until one of the MMIO registers
(the current DMA pointer) matched a pointer to the end of primary DMA
space. By using interrupts, the busy waiting and the extra mappings are
removed.
A third ioctl was added to bootstrap DMA. This ioctl, which is used by the
X-server, moves a *LOT* of code from the X-server into the kernel. This
allows the kernel to do whatever needs to be done to setup DMA buffers.
The entire process and the locations of the buffers are hidden from
user-mode.
Additionally, a get_param query was added to differentiate between G4x0
cards and G550 cards. A gap was left in the numbering sequence so that,
if needed, G450 cards could be distinguished from G400 cards. According
to Ville Syrjälä, the G4x0 cards and the G550 cards handle
anisotropic filtering differently. This seems the most compatible way
to let the client-side driver know which card it's own. Doing this very
small change now eliminates the need to bump the DRM minor version
twice.
http://marc.theaimsgroup.com/?l=dri-devel&m=106625815319773&w=2
A number of ioctl handlers in linux-core were also modified so that they
could be called in-kernel. In these cases, the in-kernel callable
version kept the existing name (e.g., drm_agp_acquire) and the ioctl
handler added _ioctl to the name (e.g., drm_agp_acquire_ioctl).
This patch also replaces the drm_agp_do_release function with
drm_agp_release. drm_agp_release (drm_core_agp_release in the previous
patch) is very similar to drm_agp_do_release, and I saw no reason to
have both.
This commit *breaks the build* on BSD. Eric said that he would make the
required updates to the BSD side soon.
Xorg bug: 3259 Reviewed by: Eric Anholt
2005-06-14 16:34:11 -06:00
|
|
|
* \sa drm_init
|
2001-02-15 01:12:14 -07:00
|
|
|
*/
|
2006-08-19 00:56:03 -06:00
|
|
|
static void drm_cleanup(drm_device_t * dev)
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
2004-09-30 15:12:10 -06: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
|
|
|
|
2005-08-04 21:50:23 -06:00
|
|
|
drm_lastclose(dev);
|
2006-08-21 13:02:08 -06:00
|
|
|
drm_fence_manager_takedown(dev);
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (dev->maplist) {
|
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;
|
2006-08-16 08:36:56 -06:00
|
|
|
drm_ht_remove(&dev->map_hash);
|
2006-10-02 06:03:15 -06:00
|
|
|
drm_mm_takedown(&dev->offset_manager);
|
2006-08-21 12:30:19 -06:00
|
|
|
drm_ht_remove(&dev->object_hash);
|
2004-09-30 15:12:10 -06:00
|
|
|
}
|
2005-05-27 18:08:53 -06:00
|
|
|
|
|
|
|
if (!drm_fb_loaded)
|
2004-06-21 05:46:52 -06:00
|
|
|
pci_disable_device(dev->pdev);
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
drm_ctxbitmap_cleanup(dev);
|
2004-08-24 05:15:53 -06:00
|
|
|
|
2004-09-30 15:12:10 -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;
|
2004-09-30 15:12:10 -06:00
|
|
|
retval = mtrr_del(dev->agp->agp_mtrr,
|
|
|
|
dev->agp->agp_info.aper_base,
|
|
|
|
dev->agp->agp_info.aper_size * 1024 * 1024);
|
|
|
|
DRM_DEBUG("mtrr_del=%d\n", retval);
|
2004-05-09 00:45:17 -06:00
|
|
|
}
|
2004-09-04 17:21:40 -06:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (drm_core_has_AGP(dev) && dev->agp) {
|
|
|
|
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
|
|
|
}
|
2005-08-04 21:50:23 -06:00
|
|
|
if (dev->driver->unload)
|
|
|
|
dev->driver->unload(dev);
|
2004-09-16 12:42:03 -06:00
|
|
|
|
2004-10-11 21:59:17 -06:00
|
|
|
drm_put_head(&dev->primary);
|
|
|
|
if (drm_put_dev(dev))
|
2004-09-30 15:12:10 -06:00
|
|
|
DRM_ERROR("Cannot unload module\n");
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
|
|
|
|
2006-08-19 00:56:03 -06:00
|
|
|
void drm_exit(struct drm_driver *driver)
|
2004-05-09 00:45:17 -06:00
|
|
|
{
|
2004-09-16 12:42:03 -06:00
|
|
|
int i;
|
2004-10-11 21:59:17 -06:00
|
|
|
drm_device_t *dev = NULL;
|
|
|
|
drm_head_t *head;
|
2004-09-30 15:12:10 -06:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
2004-09-27 13:51:38 -06:00
|
|
|
if (drm_fb_loaded) {
|
2006-01-01 22:54:10 -07:00
|
|
|
for (i = 0; i < drm_cards_limit; i++) {
|
2004-10-11 21:59:17 -06:00
|
|
|
head = drm_heads[i];
|
2004-10-18 20:50:14 -06:00
|
|
|
if (!head)
|
|
|
|
continue;
|
|
|
|
if (!head->dev)
|
|
|
|
continue;
|
2004-10-11 21:59:17 -06:00
|
|
|
if (head->dev->driver != driver)
|
|
|
|
continue;
|
|
|
|
dev = head->dev;
|
2006-02-17 19:38:07 -07:00
|
|
|
if (dev) {
|
|
|
|
/* release the pci driver */
|
|
|
|
if (dev->pdev)
|
|
|
|
pci_dev_put(dev->pdev);
|
|
|
|
drm_cleanup(dev);
|
|
|
|
}
|
2004-05-09 00:45:17 -06:00
|
|
|
}
|
2004-09-16 12:42:03 -06:00
|
|
|
} else
|
2004-10-11 21:59:17 -06:00
|
|
|
pci_unregister_driver(&driver->pci_driver);
|
2006-10-10 02:37:26 -06:00
|
|
|
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
|
|
|
|
free_nopage_retry();
|
|
|
|
#endif
|
2004-09-30 15:12:10 -06:00
|
|
|
DRM_INFO("Module unloaded\n");
|
2004-05-09 00:45:17 -06:00
|
|
|
}
|
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,
|
2004-09-30 15:12:10 -06:00
|
|
|
.open = drm_stub_open
|
2004-09-30 13:26:35 -06:00
|
|
|
};
|
|
|
|
|
2006-09-04 08:57:20 -06:00
|
|
|
static int drm_create_memory_caches(void)
|
|
|
|
{
|
|
|
|
drm_cache.mm = kmem_cache_create("drm_mm_node_t",
|
|
|
|
sizeof(drm_mm_node_t),
|
|
|
|
0,
|
|
|
|
SLAB_HWCACHE_ALIGN,
|
|
|
|
NULL,NULL);
|
|
|
|
if (!drm_cache.mm)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
drm_cache.fence_object= kmem_cache_create("drm_fence_object_t",
|
|
|
|
sizeof(drm_fence_object_t),
|
|
|
|
0,
|
|
|
|
SLAB_HWCACHE_ALIGN,
|
|
|
|
NULL,NULL);
|
2006-09-05 03:00:52 -06:00
|
|
|
if (!drm_cache.fence_object)
|
2006-09-04 08:57:20 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
drm_cache.ref_object= kmem_cache_create("drm_ref_object_t",
|
|
|
|
sizeof(drm_ref_object_t),
|
|
|
|
0,
|
|
|
|
SLAB_HWCACHE_ALIGN,
|
|
|
|
NULL,NULL);
|
|
|
|
if (!drm_cache.ref_object)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drm_free_mem_cache(kmem_cache_t *cache,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
if (!cache)
|
|
|
|
return;
|
|
|
|
if (kmem_cache_destroy(cache)) {
|
|
|
|
DRM_ERROR("Warning! DRM is leaking %s memory.\n",
|
|
|
|
name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drm_free_memory_caches(void )
|
|
|
|
{
|
|
|
|
|
|
|
|
drm_free_mem_cache(drm_cache.ref_object, "ref object");
|
|
|
|
drm_cache.ref_object = NULL;
|
|
|
|
drm_free_mem_cache(drm_cache.fence_object, "fence object");
|
|
|
|
drm_cache.fence_object = NULL;
|
|
|
|
drm_free_mem_cache(drm_cache.mm, "memory manager block");
|
|
|
|
drm_cache.mm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
static int __init drm_core_init(void)
|
|
|
|
{
|
2006-09-04 08:57:20 -06:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = drm_create_memory_caches();
|
|
|
|
if (ret)
|
|
|
|
goto err_p1;
|
2004-09-30 15:12:10 -06:00
|
|
|
|
2006-09-04 08:57:20 -06:00
|
|
|
ret = -ENOMEM;
|
2006-01-01 22:54:10 -07:00
|
|
|
drm_cards_limit =
|
|
|
|
(drm_cards_limit < DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1);
|
|
|
|
drm_heads = drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB);
|
2004-10-11 21:59:17 -06:00
|
|
|
if (!drm_heads)
|
2004-09-27 13:51:38 -06:00
|
|
|
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)) {
|
2004-09-30 15:12:10 -06:00
|
|
|
printk(KERN_ERR "DRM: Error creating drm class.\n");
|
2004-09-27 13:51:38 -06:00
|
|
|
ret = PTR_ERR(drm_class);
|
|
|
|
goto err_p2;
|
|
|
|
}
|
|
|
|
|
2005-11-11 01:59:57 -07:00
|
|
|
drm_proc_root = proc_mkdir("dri", NULL);
|
2004-09-27 13:51:38 -06:00
|
|
|
if (!drm_proc_root) {
|
|
|
|
DRM_ERROR("Cannot create /proc/dri\n");
|
|
|
|
ret = -1;
|
|
|
|
goto err_p3;
|
|
|
|
}
|
2004-09-30 15:12:10 -06:00
|
|
|
|
2005-06-09 07:22:12 -06:00
|
|
|
drm_mem_init();
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
DRM_INFO("Initialized %s %d.%d.%d %s\n",
|
2005-02-07 04:20:43 -07:00
|
|
|
CORE_NAME,
|
|
|
|
CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
|
2004-09-27 13:51:38 -06:00
|
|
|
return 0;
|
2004-10-18 20:50:14 -06:00
|
|
|
err_p3:
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_sysfs_destroy(drm_class);
|
2004-10-18 20:50:14 -06:00
|
|
|
err_p2:
|
2004-09-27 13:51:38 -06:00
|
|
|
unregister_chrdev(DRM_MAJOR, "drm");
|
2006-01-01 22:54:10 -07:00
|
|
|
drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
|
2004-10-18 20:50:14 -06:00
|
|
|
err_p1:
|
2006-09-05 03:00:52 -06:00
|
|
|
drm_free_memory_caches();
|
2004-09-27 13:51:38 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
static void __exit drm_core_exit(void)
|
2004-09-27 13:51:38 -06:00
|
|
|
{
|
2006-09-04 08:57:20 -06:00
|
|
|
drm_free_memory_caches();
|
2004-09-27 13:51:38 -06:00
|
|
|
remove_proc_entry("dri", NULL);
|
|
|
|
drm_sysfs_destroy(drm_class);
|
|
|
|
|
|
|
|
unregister_chrdev(DRM_MAJOR, "drm");
|
|
|
|
|
2006-01-01 22:54:10 -07:00
|
|
|
drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB);
|
2004-09-27 13:51:38 -06:00
|
|
|
}
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
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.
|
|
|
|
*/
|
2005-06-04 00:18:11 -06:00
|
|
|
static int drm_version(struct inode *inode, struct file *filp,
|
2004-09-30 15:12:10 -06:00
|
|
|
unsigned int cmd, unsigned long arg)
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
2004-09-27 13:51:38 -06:00
|
|
|
drm_file_t *priv = filp->private_data;
|
2004-10-11 21:59:17 -06:00
|
|
|
drm_device_t *dev = priv->head->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;
|
2005-08-04 21:50:23 -06:00
|
|
|
int len;
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (copy_from_user(&version, argp, sizeof(version)))
|
2001-02-15 01:12:14 -07:00
|
|
|
return -EFAULT;
|
|
|
|
|
2005-08-04 21:50:23 -06:00
|
|
|
version.version_major = dev->driver->major;
|
|
|
|
version.version_minor = dev->driver->minor;
|
|
|
|
version.version_patchlevel = dev->driver->patchlevel;
|
|
|
|
DRM_COPY(version.name, dev->driver->name);
|
|
|
|
DRM_COPY(version.date, dev->driver->date);
|
|
|
|
DRM_COPY(version.desc, dev->driver->desc);
|
2004-09-30 15:12:10 -06:00
|
|
|
|
|
|
|
if (copy_to_user(argp, &version, sizeof(version)))
|
2001-02-15 01:12:14 -07:00
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
/**
|
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-30 15:12:10 -06:00
|
|
|
int drm_ioctl(struct inode *inode, struct file *filp,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
2001-02-15 01:12:14 -07:00
|
|
|
{
|
|
|
|
drm_file_t *priv = filp->private_data;
|
2004-10-11 21:59:17 -06:00
|
|
|
drm_device_t *dev = priv->head->dev;
|
2001-02-15 01:12:14 -07:00
|
|
|
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
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
atomic_inc(&dev->ioctl_count);
|
|
|
|
atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
|
2001-02-15 01:12:14 -07:00
|
|
|
++priv->ioctl_count;
|
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
|
2004-10-11 21:59:17 -06:00
|
|
|
current->pid, cmd, nr, (long)old_encode_dev(priv->head->device),
|
2004-09-30 15:12:10 -06:00
|
|
|
priv->authenticated);
|
2001-02-15 01:12:14 -07:00
|
|
|
|
2006-08-27 13:16:13 -06:00
|
|
|
if (nr >= DRIVER_IOCTL_COUNT &&
|
|
|
|
(nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END))
|
|
|
|
goto err_i1;
|
|
|
|
if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END)
|
|
|
|
&& (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
|
|
|
|
ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
|
|
|
|
else if (nr >= DRM_COMMAND_END || nr < DRM_COMMAND_BASE)
|
2004-09-27 13:51:38 -06:00
|
|
|
ioctl = &drm_ioctls[nr];
|
2006-08-27 13:16:13 -06:00
|
|
|
else
|
2004-09-27 13:51:38 -06:00
|
|
|
goto err_i1;
|
|
|
|
|
2006-08-27 13:16:13 -06:00
|
|
|
|
|
|
|
|
2004-09-27 13:51:38 -06:00
|
|
|
func = ioctl->func;
|
2004-10-10 16:54:55 -06:00
|
|
|
if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl) /* Local override? */
|
|
|
|
func = dev->driver->dma_ioctl;
|
2004-09-27 13:51:38 -06:00
|
|
|
|
2004-09-30 15:12:10 -06:00
|
|
|
if (!func) {
|
|
|
|
DRM_DEBUG("no function\n");
|
2001-02-15 01:12:14 -07:00
|
|
|
retcode = -EINVAL;
|
2005-09-02 21:27:14 -06:00
|
|
|
} else if (((ioctl->flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)) ||
|
|
|
|
((ioctl->flags & DRM_AUTH) && !priv->authenticated) ||
|
|
|
|
((ioctl->flags & DRM_MASTER) && !priv->master)) {
|
2004-09-27 13:51:38 -06:00
|
|
|
retcode = -EACCES;
|
2001-02-15 01:12:14 -07:00
|
|
|
} else {
|
2004-09-30 15:12:10 -06:00
|
|
|
retcode = func(inode, filp, cmd, arg);
|
2001-02-15 01:12:14 -07:00
|
|
|
}
|
2005-08-04 07:15:27 -06:00
|
|
|
err_i1:
|
2004-09-30 15:12:10 -06:00
|
|
|
atomic_dec(&dev->ioctl_count);
|
|
|
|
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);
|