2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* \file drm_drv.c
|
|
|
|
* 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 drm_x mga_##x
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com
|
|
|
|
*
|
2012-05-22 11:07:44 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2012-08-18 18:26:25 +00:00
|
|
|
#include <sys/sysent.h>
|
2015-03-17 18:50:33 +00:00
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
#include <dev/drm2/drmP.h>
|
2013-08-24 15:47:15 +00:00
|
|
|
#include <dev/drm2/drm_core.h>
|
|
|
|
#include <dev/drm2/drm_global.h>
|
2013-11-17 16:07:52 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
struct sx drm_global_mutex;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/** Ioctl table */
|
|
|
|
static struct drm_ioctl_desc drm_ioctls[] = {
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_getmap, DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_CAP, drm_getcap, DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER),
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_AUTH|DRM_MASTER),
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_rmmap_ioctl, DRM_AUTH),
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_getsareactx, DRM_AUTH),
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_ROOT_ONLY),
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_addctx, DRM_AUTH|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_modctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_getctx, DRM_AUTH),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_resctx, DRM_AUTH),
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_LOCK, drm_lock, DRM_AUTH),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_unlock, DRM_AUTH),
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_infobufs, DRM_AUTH),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_mapbufs, DRM_AUTH),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_freebufs, DRM_AUTH),
|
2015-03-17 18:50:33 +00:00
|
|
|
/* The DRM_IOCTL_DMA ioctl should be defined by the driver. */
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_DMA, NULL, DRM_AUTH),
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if __OS_HAS_AGP
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2015-03-17 18:50:33 +00:00
|
|
|
#endif
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_sg_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2015-03-17 18:50:33 +00:00
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank, DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_modeset_ctl, 0),
|
2015-03-17 18:50:33 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH|DRM_UNLOCKED),
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
|
|
|
|
#ifdef FREEBSD_NOTYET
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_AUTH|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_AUTH|DRM_UNLOCKED),
|
|
|
|
#endif /* FREEBSD_NOTYET */
|
|
|
|
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANE, drm_mode_getplane, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPLANE, drm_mode_setplane, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR, drm_mode_cursor_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCONNECTOR, drm_mode_getconnector, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_mode_attachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_mode_detachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPERTY, drm_mode_getproperty_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_mode_connector_property_set_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_DUMB, drm_mode_create_dumb_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_MAP_DUMB, drm_mode_mmap_dumb_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_GETPROPERTIES, drm_mode_obj_get_properties_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2015-01-21 16:10:37 +00:00
|
|
|
DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
|
2012-05-22 11:07:44 +00:00
|
|
|
};
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
|
|
|
extern struct drm_ioctl_desc drm_compat_ioctls[];
|
2012-05-22 11:07:44 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* Take down the DRM device.
|
|
|
|
*
|
|
|
|
* \param dev DRM device structure.
|
|
|
|
*
|
|
|
|
* Frees every resource in \p dev.
|
|
|
|
*
|
|
|
|
* \sa drm_device
|
|
|
|
*/
|
|
|
|
int drm_lastclose(struct drm_device * dev)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
struct drm_vma_entry *vma, *vma_temp;
|
|
|
|
#endif
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_DEBUG("\n");
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (dev->driver->lastclose)
|
2012-05-22 11:07:44 +00:00
|
|
|
dev->driver->lastclose(dev);
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_DEBUG("driver lastclose completed\n");
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (dev->irq_enabled && !drm_core_check_feature(dev, DRIVER_MODESET))
|
2012-05-22 11:07:44 +00:00
|
|
|
drm_irq_uninstall(dev);
|
|
|
|
|
|
|
|
DRM_LOCK(dev);
|
|
|
|
|
|
|
|
/* Clear AGP information */
|
2015-03-17 18:50:33 +00:00
|
|
|
if (drm_core_has_AGP(dev) && dev->agp &&
|
|
|
|
!drm_core_check_feature(dev, DRIVER_MODESET)) {
|
|
|
|
struct drm_agp_mem *entry, *tempe;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/* Remove AGP resources, but leave dev->agp
|
|
|
|
intact until drv_cleanup is called. */
|
|
|
|
list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) {
|
2012-05-22 11:07:44 +00:00
|
|
|
if (entry->bound)
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_unbind_agp(entry->memory);
|
|
|
|
drm_free_agp(entry->memory, entry->pages);
|
2012-05-22 11:07:44 +00:00
|
|
|
free(entry, DRM_MEM_AGPLISTS);
|
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
INIT_LIST_HEAD(&dev->agp->memory);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
if (dev->agp->acquired)
|
|
|
|
drm_agp_release(dev);
|
|
|
|
|
|
|
|
dev->agp->acquired = 0;
|
2015-03-17 18:50:33 +00:00
|
|
|
dev->agp->enabled = 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg &&
|
|
|
|
!drm_core_check_feature(dev, DRIVER_MODESET)) {
|
2012-05-22 11:07:44 +00:00
|
|
|
drm_sg_cleanup(dev->sg);
|
|
|
|
dev->sg = NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
/* Clear vma list (only built for debugging) */
|
|
|
|
list_for_each_entry_safe(vma, vma_temp, &dev->vmalist, head) {
|
|
|
|
list_del(&vma->head);
|
|
|
|
kfree(vma);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
#endif
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
|
|
|
|
!drm_core_check_feature(dev, DRIVER_MODESET))
|
|
|
|
drm_dma_takedown(dev);
|
|
|
|
|
|
|
|
DRM_UNLOCK(dev);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_DEBUG("lastclose completed\n");
|
2012-05-22 11:07:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
/** File operations structure */
|
|
|
|
static const struct file_operations drm_stub_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = drm_stub_open,
|
|
|
|
.llseek = noop_llseek,
|
|
|
|
};
|
|
|
|
#endif
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
static int __init drm_core_init(void)
|
|
|
|
{
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
sx_init(&drm_global_mutex, "drm_global_mutex");
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_global_init();
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if DRM_LINUX
|
|
|
|
linux_ioctl_register_handler(&drm_handler);
|
|
|
|
#endif /* DRM_LINUX */
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
DRM_INFO("Initialized %s %d.%d.%d %s\n",
|
2015-03-17 18:50:33 +00:00
|
|
|
CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
|
2012-05-22 11:07:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
static void __exit drm_core_exit(void)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if DRM_LINUX
|
|
|
|
linux_ioctl_unregister_handler(&drm_handler);
|
|
|
|
#endif /* DRM_LINUX */
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_global_release();
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
sx_destroy(&drm_global_mutex);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
SYSINIT(drm_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
|
|
|
drm_core_init, NULL);
|
|
|
|
SYSUNINIT(drm_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
|
|
|
|
drm_core_exit, NULL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy and IOCTL return string to user space
|
|
|
|
*/
|
|
|
|
static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/* don't overflow userbuf */
|
|
|
|
len = strlen(value);
|
|
|
|
if (len > *buf_len)
|
|
|
|
len = *buf_len;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/* let userspace know exact length of driver value (which could be
|
|
|
|
* larger than the userspace-supplied buffer) */
|
|
|
|
*buf_len = strlen(value);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/* finally, try filling in the userbuf */
|
|
|
|
if (len && buf)
|
|
|
|
if (copy_to_user(buf, value, len))
|
|
|
|
return -EFAULT;
|
2012-05-22 11:07:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00: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.
|
|
|
|
*/
|
|
|
|
int drm_version(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_version *version = data;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
version->version_major = dev->driver->major;
|
|
|
|
version->version_minor = dev->driver->minor;
|
|
|
|
version->version_patchlevel = dev->driver->patchlevel;
|
|
|
|
err = drm_copy_field(version->name, &version->name_len,
|
|
|
|
dev->driver->name);
|
|
|
|
if (!err)
|
|
|
|
err = drm_copy_field(version->date, &version->date_len,
|
|
|
|
dev->driver->date);
|
|
|
|
if (!err)
|
|
|
|
err = drm_copy_field(version->desc, &version->desc_len,
|
|
|
|
dev->driver->desc);
|
|
|
|
|
|
|
|
return err;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* Called whenever a process performs an ioctl on /dev/drm.
|
|
|
|
*
|
|
|
|
* \param inode device inode.
|
|
|
|
* \param file_priv DRM file private.
|
|
|
|
* \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.
|
2012-05-22 11:07:44 +00:00
|
|
|
*/
|
2013-08-24 15:47:15 +00:00
|
|
|
int drm_ioctl(struct cdev *kdev, u_long cmd, caddr_t data, int flags,
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_STRUCTPROC *p)
|
|
|
|
{
|
|
|
|
struct drm_file *file_priv;
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_device *dev;
|
|
|
|
struct drm_ioctl_desc *ioctl;
|
|
|
|
drm_ioctl_t *func;
|
|
|
|
unsigned int nr = DRM_IOCTL_NR(cmd);
|
|
|
|
int retcode;
|
|
|
|
|
|
|
|
dev = drm_get_device_from_kdev(kdev);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
retcode = devfs_get_cdevpriv((void **)&file_priv);
|
|
|
|
if (retcode != 0) {
|
|
|
|
DRM_ERROR("can't find authenticator\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
retcode = -EINVAL;
|
|
|
|
|
|
|
|
atomic_inc(&dev->ioctl_count);
|
2012-05-22 11:07:44 +00:00
|
|
|
atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
|
|
|
|
++file_priv->ioctl_count;
|
|
|
|
|
|
|
|
DRM_DEBUG("pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_CURRENTPID, cmd, nr,
|
|
|
|
(long)file_priv->minor->device,
|
|
|
|
file_priv->authenticated);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO:
|
|
|
|
case FIOASYNC:
|
2016-03-11 18:59:15 +00:00
|
|
|
atomic_dec(&dev->ioctl_count);
|
2012-05-22 11:07:44 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FIOSETOWN:
|
2016-03-11 18:59:15 +00:00
|
|
|
atomic_dec(&dev->ioctl_count);
|
2015-03-17 18:50:33 +00:00
|
|
|
return fsetown(*(int *)data, &file_priv->minor->buf_sigio);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
case FIOGETOWN:
|
2016-03-11 18:59:15 +00:00
|
|
|
atomic_dec(&dev->ioctl_count);
|
2015-03-17 18:50:33 +00:00
|
|
|
*(int *) data = fgetown(&file_priv->minor->buf_sigio);
|
2012-05-22 11:07:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IOCGROUP(cmd) != DRM_IOCTL_BASE) {
|
2016-03-11 18:59:15 +00:00
|
|
|
atomic_dec(&dev->ioctl_count);
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_DEBUG("Bad ioctl group 0x%x\n", (int)IOCGROUP(cmd));
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if ((nr >= DRM_CORE_IOCTL_COUNT) &&
|
|
|
|
((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END)))
|
|
|
|
goto err_i1;
|
2012-08-18 18:26:25 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2015-03-17 18:50:33 +00:00
|
|
|
if (SV_CURPROC_FLAG(SV_ILP32) &&
|
|
|
|
(nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) &&
|
|
|
|
(nr < DRM_COMMAND_BASE + *dev->driver->num_compat_ioctls) &&
|
|
|
|
(dev->driver->compat_ioctls[nr - DRM_COMMAND_BASE].func != NULL)) {
|
|
|
|
ioctl = &dev->driver->compat_ioctls[nr - DRM_COMMAND_BASE];
|
|
|
|
} else
|
2012-08-18 18:26:25 +00:00
|
|
|
#endif
|
2015-03-17 18:50:33 +00:00
|
|
|
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)) {
|
2012-08-18 18:26:25 +00:00
|
|
|
#ifdef COMPAT_FREEBSD32
|
2015-03-17 18:50:33 +00:00
|
|
|
/*
|
|
|
|
* Called whenever a 32-bit process running under a 64-bit
|
|
|
|
* kernel performs an ioctl on /dev/drm.
|
|
|
|
*/
|
|
|
|
if (SV_CURPROC_FLAG(SV_ILP32) && drm_compat_ioctls[nr].func != NULL)
|
|
|
|
/*
|
|
|
|
* Assume that ioctls without an explicit compat
|
|
|
|
* routine will just work. This may not always be a
|
|
|
|
* good assumption, but it's better than always
|
|
|
|
* failing.
|
|
|
|
*/
|
|
|
|
ioctl = &drm_compat_ioctls[nr];
|
2012-08-18 18:26:25 +00:00
|
|
|
else
|
|
|
|
#endif
|
2015-03-17 18:50:33 +00:00
|
|
|
ioctl = &drm_ioctls[nr];
|
|
|
|
} else
|
|
|
|
goto err_i1;
|
|
|
|
|
|
|
|
/* Do not trust userspace, use our own definition */
|
2012-05-22 11:07:44 +00:00
|
|
|
func = ioctl->func;
|
2015-03-17 18:50:33 +00:00
|
|
|
/* is there a local override? */
|
|
|
|
#ifdef FREEBSD_NOTYET
|
|
|
|
#ifdef COMPAT_FREEBSD32
|
|
|
|
if (SV_CURPROC_FLAG(SV_ILP32) &&
|
|
|
|
(nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_compat_ioctl)
|
|
|
|
func = dev->driver->dma_compat_ioctl;
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#endif /* FREEBSD_NOTYET */
|
|
|
|
if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl)
|
|
|
|
func = dev->driver->dma_ioctl;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (!func) {
|
2012-05-22 11:07:44 +00:00
|
|
|
DRM_DEBUG("no function\n");
|
2015-03-17 18:50:33 +00:00
|
|
|
retcode = -EINVAL;
|
|
|
|
} else if (((ioctl->flags & DRM_ROOT_ONLY) && !DRM_SUSER(p)) ||
|
|
|
|
((ioctl->flags & DRM_AUTH) && !file_priv->authenticated) ||
|
|
|
|
((ioctl->flags & DRM_MASTER) && !file_priv->is_master) ||
|
|
|
|
(!(ioctl->flags & DRM_CONTROL_ALLOW) && (file_priv->minor->type == DRM_MINOR_CONTROL))) {
|
|
|
|
retcode = -EACCES;
|
2012-05-22 11:07:44 +00:00
|
|
|
} else {
|
2015-03-17 18:50:33 +00:00
|
|
|
if (ioctl->flags & DRM_UNLOCKED)
|
|
|
|
retcode = func(dev, data, file_priv);
|
|
|
|
else {
|
|
|
|
sx_xlock(&drm_global_mutex);
|
|
|
|
retcode = func(dev, data, file_priv);
|
|
|
|
sx_xunlock(&drm_global_mutex);
|
|
|
|
}
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
err_i1:
|
|
|
|
atomic_dec(&dev->ioctl_count);
|
2016-03-08 20:33:02 +00:00
|
|
|
if (retcode == -ERESTARTSYS) {
|
|
|
|
/*
|
|
|
|
* FIXME: Find where in i915 ERESTARTSYS should be
|
|
|
|
* converted to EINTR.
|
|
|
|
*/
|
|
|
|
DRM_DEBUG("ret = %d -> %d\n", retcode, -EINTR);
|
|
|
|
retcode = -EINTR;
|
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
if (retcode)
|
|
|
|
DRM_DEBUG("ret = %d\n", retcode);
|
2012-05-22 11:07:44 +00:00
|
|
|
if (retcode != 0 &&
|
2015-03-17 18:50:33 +00:00
|
|
|
(drm_debug & DRM_DEBUGBITS_FAILED_IOCTL) != 0) {
|
2012-05-22 11:07:44 +00:00
|
|
|
printf(
|
2015-03-17 18:50:33 +00:00
|
|
|
"pid %d, cmd 0x%02lx, nr 0x%02x, dev 0x%lx, auth %d, res %d\n",
|
|
|
|
DRM_CURRENTPID, cmd, nr, (long)file_priv->minor->device,
|
|
|
|
file_priv->authenticated, -retcode);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return -retcode;
|
2013-03-05 09:49:34 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_ioctl);
|
2013-03-05 09:49:34 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_local_map *drm_getsarea(struct drm_device *dev)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_map_list *entry;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
list_for_each_entry(entry, &dev->maplist, head) {
|
|
|
|
if (entry->map && entry->map->type == _DRM_SHM &&
|
|
|
|
(entry->map->flags & _DRM_CONTAINS_LOCK)) {
|
|
|
|
return entry->map;
|
2015-01-21 16:10:37 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
return NULL;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_getsarea);
|