2012-05-22 11:07:44 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2012-05-22 11:07:44 +00:00
|
|
|
* Copyright (c) 2011 The FreeBSD Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Konstantin Belousov under sponsorship from
|
|
|
|
* the FreeBSD Foundation.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include "opt_vm.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_page.h>
|
|
|
|
|
|
|
|
#include <dev/drm2/drmP.h>
|
|
|
|
#include <dev/drm2/drm.h>
|
|
|
|
#include <dev/drm2/drm_sarea.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We make up offsets for buffer objects so we can recognize them at
|
|
|
|
* mmap time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* pgoff in mmap is an unsigned long, so we need to make sure that
|
|
|
|
* the faked up offset will fit
|
|
|
|
*/
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if BITS_PER_LONG == 64
|
2012-05-22 11:07:44 +00:00
|
|
|
#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
|
|
|
|
#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
|
|
|
|
#else
|
|
|
|
#define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
|
|
|
|
#define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
|
|
|
|
#endif
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* Initialize the GEM device fields
|
|
|
|
*/
|
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
int
|
|
|
|
drm_gem_init(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_gem_mm *mm;
|
|
|
|
|
|
|
|
drm_gem_names_init(&dev->object_names);
|
2015-03-17 18:50:33 +00:00
|
|
|
|
|
|
|
mm = malloc(sizeof(*mm), DRM_MEM_DRIVER, M_NOWAIT);
|
|
|
|
if (!mm) {
|
|
|
|
DRM_ERROR("out of memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
dev->mm_private = mm;
|
2015-03-17 18:50:33 +00:00
|
|
|
|
|
|
|
if (drm_ht_create(&mm->offset_hash, 19)) {
|
2012-05-22 11:07:44 +00:00
|
|
|
free(mm, DRM_MEM_DRIVER);
|
2015-03-17 18:50:33 +00:00
|
|
|
return -ENOMEM;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
mm->idxunr = new_unrhdr(0, DRM_GEM_MAX_IDX, NULL);
|
2015-03-17 18:50:33 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
drm_gem_destroy(struct drm_device *dev)
|
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_gem_mm *mm = dev->mm_private;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
dev->mm_private = NULL;
|
|
|
|
drm_ht_remove(&mm->offset_hash);
|
|
|
|
delete_unrhdr(mm->idxunr);
|
|
|
|
free(mm, DRM_MEM_DRIVER);
|
|
|
|
drm_gem_names_fini(&dev->object_names);
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
int drm_gem_object_init(struct drm_device *dev,
|
|
|
|
struct drm_gem_object *obj, size_t size)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
KASSERT((size & (PAGE_SIZE - 1)) == 0,
|
|
|
|
("Bad size %ju", (uintmax_t)size));
|
|
|
|
|
|
|
|
obj->dev = dev;
|
|
|
|
obj->vm_obj = vm_pager_allocate(OBJT_DEFAULT, NULL, size,
|
|
|
|
VM_PROT_READ | VM_PROT_WRITE, 0, curthread->td_ucred);
|
|
|
|
|
|
|
|
obj->refcount = 1;
|
|
|
|
obj->handle_count = 0;
|
|
|
|
obj->size = size;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_object_init);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* Initialize an already allocated GEM object of the specified size with
|
|
|
|
* no GEM provided backing store. Instead the caller is responsible for
|
|
|
|
* backing the object and handling it.
|
|
|
|
*/
|
|
|
|
int drm_gem_private_object_init(struct drm_device *dev,
|
|
|
|
struct drm_gem_object *obj, size_t size)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
MPASS((size & (PAGE_SIZE - 1)) == 0);
|
|
|
|
|
|
|
|
obj->dev = dev;
|
|
|
|
obj->vm_obj = NULL;
|
|
|
|
|
|
|
|
obj->refcount = 1;
|
2013-08-25 15:38:16 +00:00
|
|
|
atomic_store_rel_int(&obj->handle_count, 0);
|
2012-05-22 11:07:44 +00:00
|
|
|
obj->size = size;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_private_object_init);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
struct drm_gem_object *
|
|
|
|
drm_gem_object_alloc(struct drm_device *dev, size_t size)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
obj = malloc(sizeof(*obj), DRM_MEM_DRIVER, M_NOWAIT | M_ZERO);
|
|
|
|
if (!obj)
|
|
|
|
goto free;
|
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
if (drm_gem_object_init(dev, obj, size) != 0)
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
if (dev->driver->gem_init_object != NULL &&
|
2015-03-17 18:50:33 +00:00
|
|
|
dev->driver->gem_init_object(obj) != 0) {
|
2012-05-22 11:07:44 +00:00
|
|
|
goto dealloc;
|
2015-03-17 18:50:33 +00:00
|
|
|
}
|
|
|
|
return obj;
|
2012-05-22 11:07:44 +00:00
|
|
|
dealloc:
|
|
|
|
vm_object_deallocate(obj->vm_obj);
|
|
|
|
free:
|
|
|
|
free(obj, DRM_MEM_DRIVER);
|
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_gem_object_alloc);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if defined(FREEBSD_NOTYET)
|
|
|
|
static void
|
|
|
|
drm_gem_remove_prime_handles(struct drm_gem_object *obj, struct drm_file *filp)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
if (obj->import_attach) {
|
|
|
|
drm_prime_remove_buf_handle(&filp->prime,
|
|
|
|
obj->import_attach->dmabuf);
|
|
|
|
}
|
|
|
|
if (obj->export_dma_buf) {
|
|
|
|
drm_prime_remove_buf_handle(&filp->prime,
|
|
|
|
obj->export_dma_buf);
|
|
|
|
}
|
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
|
|
|
/**
|
|
|
|
* Removes the mapping from handle to filp for this object.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_gem_handle_delete(struct drm_file *filp, u32 handle)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
struct drm_device *dev;
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_gem_object *obj;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
obj = drm_gem_names_remove(&filp->object_names, handle);
|
|
|
|
if (obj == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-05-22 11:07:44 +00:00
|
|
|
dev = obj->dev;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if defined(FREEBSD_NOTYET)
|
|
|
|
drm_gem_remove_prime_handles(obj, filp);
|
|
|
|
#endif
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (dev->driver->gem_close_object)
|
|
|
|
dev->driver->gem_close_object(obj, filp);
|
|
|
|
drm_gem_object_handle_unreference_unlocked(obj);
|
|
|
|
|
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_handle_delete);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/**
|
|
|
|
* Create a handle for this object. This adds a handle reference
|
|
|
|
* to the object, which includes a regular reference count. Callers
|
|
|
|
* will likely want to dereference the object afterwards.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
drm_gem_handle_create(struct drm_file *file_priv,
|
|
|
|
struct drm_gem_object *obj,
|
|
|
|
u32 *handlep)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_device *dev = obj->dev;
|
|
|
|
int ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
*handlep = 0;
|
|
|
|
ret = drm_gem_name_create(&file_priv->object_names, obj, handlep);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_object_handle_reference(obj);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (dev->driver->gem_open_object) {
|
|
|
|
ret = dev->driver->gem_open_object(obj, file_priv);
|
|
|
|
if (ret) {
|
|
|
|
drm_gem_handle_delete(file_priv, *handlep);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_handle_create);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
void
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_free_mmap_offset(struct drm_gem_object *obj)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_device *dev = obj->dev;
|
|
|
|
struct drm_gem_mm *mm = dev->mm_private;
|
|
|
|
struct drm_hash_item *list = &obj->map_list;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (!obj->on_map)
|
2012-05-22 11:07:44 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_ht_remove_item(&mm->offset_hash, list);
|
|
|
|
free_unr(mm->idxunr, list->key);
|
|
|
|
obj->on_map = false;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_free_mmap_offset);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
int
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_create_mmap_offset(struct drm_gem_object *obj)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2013-08-25 09:58:31 +00:00
|
|
|
struct drm_device *dev = obj->dev;
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_gem_mm *mm = dev->mm_private;
|
2013-08-25 09:58:31 +00:00
|
|
|
int ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (obj->on_map)
|
|
|
|
return 0;
|
2013-08-25 09:58:31 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
obj->map_list.key = alloc_unr(mm->idxunr);
|
|
|
|
ret = drm_ht_insert_item(&mm->offset_hash, &obj->map_list);
|
|
|
|
if (ret) {
|
|
|
|
DRM_ERROR("failed to add to map hash\n");
|
|
|
|
free_unr(mm->idxunr, obj->map_list.key);
|
|
|
|
return ret;
|
2013-08-25 09:58:31 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
obj->on_map = true;
|
2013-08-25 09:58:31 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_create_mmap_offset);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/** Returns a reference to the object named by the handle. */
|
|
|
|
struct drm_gem_object *
|
|
|
|
drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
|
|
|
|
u32 handle)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
obj = drm_gem_name_ref(&filp->object_names, handle,
|
|
|
|
(void (*)(void *))drm_gem_object_reference);
|
2013-08-25 09:58:31 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_gem_object_lookup);
|
2013-08-25 09:58:31 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
int
|
|
|
|
drm_gem_close_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
|
|
|
struct drm_gem_close *args = data;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(dev->driver->driver_features & DRIVER_GEM))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = drm_gem_handle_delete(file_priv, args->handle);
|
|
|
|
|
|
|
|
return ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
int
|
|
|
|
drm_gem_flink_ioctl(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_gem_flink *args = data;
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
int ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (!(dev->driver->driver_features & DRIVER_GEM))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
obj = drm_gem_object_lookup(dev, file_priv, args->handle);
|
|
|
|
if (obj == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
ret = drm_gem_name_create(&dev->object_names, obj, &obj->name);
|
|
|
|
if (ret != 0) {
|
|
|
|
if (ret == -EALREADY)
|
|
|
|
ret = 0;
|
|
|
|
drm_gem_object_unreference_unlocked(obj);
|
|
|
|
}
|
|
|
|
if (ret == 0)
|
|
|
|
args->name = obj->name;
|
|
|
|
return ret;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
drm_gem_open_ioctl(struct drm_device *dev, void *data,
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_file *file_priv)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_gem_open *args = data;
|
2012-05-22 11:07:44 +00:00
|
|
|
struct drm_gem_object *obj;
|
|
|
|
int ret;
|
2015-03-17 18:50:33 +00:00
|
|
|
u32 handle;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (!(dev->driver->driver_features & DRIVER_GEM))
|
|
|
|
return -ENODEV;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
|
|
|
obj = drm_gem_name_ref(&dev->object_names, args->name,
|
|
|
|
(void (*)(void *))drm_gem_object_reference);
|
2015-03-17 18:50:33 +00:00
|
|
|
if (!obj)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
ret = drm_gem_handle_create(file_priv, obj, &handle);
|
|
|
|
drm_gem_object_unreference_unlocked(obj);
|
2015-03-17 18:50:33 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-05-22 11:07:44 +00:00
|
|
|
args->handle = handle;
|
|
|
|
args->size = obj->size;
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_names_init(&file_private->object_names);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_object_release_handle(uint32_t name, void *ptr, void *data)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_file *file_priv = data;
|
|
|
|
struct drm_gem_object *obj = ptr;
|
|
|
|
struct drm_device *dev = obj->dev;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
#if defined(FREEBSD_NOTYET)
|
|
|
|
drm_gem_remove_prime_handles(obj, file_priv);
|
|
|
|
#endif
|
2013-08-25 10:01:59 +00:00
|
|
|
|
|
|
|
if (dev->driver->gem_close_object)
|
|
|
|
dev->driver->gem_close_object(obj, file_priv);
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_object_handle_unreference_unlocked(obj);
|
|
|
|
|
|
|
|
return 0;
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_names_foreach(&file_private->object_names,
|
|
|
|
drm_gem_object_release_handle, file_private);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
drm_gem_names_fini(&file_private->object_names);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
void
|
|
|
|
drm_gem_object_release(struct drm_gem_object *obj)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
/*
|
|
|
|
* obj->vm_obj can be NULL for private gem objects.
|
|
|
|
*/
|
|
|
|
vm_object_deallocate(obj->vm_obj);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_object_release);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
void
|
|
|
|
drm_gem_object_free(struct drm_gem_object *obj)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_device *dev = obj->dev;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
DRM_LOCK_ASSERT(dev);
|
|
|
|
if (dev->driver->gem_free_object != NULL)
|
|
|
|
dev->driver->gem_free_object(obj);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
2015-03-17 18:50:33 +00:00
|
|
|
EXPORT_SYMBOL(drm_gem_object_free);
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
void drm_gem_object_handle_free(struct drm_gem_object *obj)
|
2012-05-22 11:07:44 +00:00
|
|
|
{
|
2015-03-17 18:50:33 +00:00
|
|
|
struct drm_device *dev = obj->dev;
|
|
|
|
struct drm_gem_object *obj1;
|
2012-05-22 11:07:44 +00:00
|
|
|
|
2015-03-17 18:50:33 +00:00
|
|
|
if (obj->name) {
|
|
|
|
obj1 = drm_gem_names_remove(&dev->object_names, obj->name);
|
|
|
|
obj->name = 0;
|
|
|
|
drm_gem_object_unreference(obj1);
|
|
|
|
}
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_gem_object *
|
|
|
|
drm_gem_object_from_offset(struct drm_device *dev, vm_ooffset_t offset)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
struct drm_gem_mm *mm;
|
|
|
|
struct drm_hash_item *map_list;
|
|
|
|
|
|
|
|
if ((offset & DRM_GEM_MAPPING_MASK) != DRM_GEM_MAPPING_KEY)
|
|
|
|
return (NULL);
|
|
|
|
offset &= ~DRM_GEM_MAPPING_KEY;
|
|
|
|
mm = dev->mm_private;
|
|
|
|
if (drm_ht_find_item(&mm->offset_hash, DRM_GEM_MAPPING_IDX(offset),
|
|
|
|
&map_list) != 0) {
|
|
|
|
DRM_DEBUG("drm_gem_object_from_offset: offset 0x%jx obj not found\n",
|
|
|
|
(uintmax_t)offset);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2012-09-15 19:28:54 +00:00
|
|
|
obj = __containerof(map_list, struct drm_gem_object, map_list);
|
2012-05-22 11:07:44 +00:00
|
|
|
return (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-03-05 09:49:34 +00:00
|
|
|
drm_gem_mmap_single(struct drm_device *dev, vm_ooffset_t *offset, vm_size_t size,
|
2012-05-22 11:07:44 +00:00
|
|
|
struct vm_object **obj_res, int nprot)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *gem_obj;
|
|
|
|
struct vm_object *vm_obj;
|
|
|
|
|
|
|
|
DRM_LOCK(dev);
|
|
|
|
gem_obj = drm_gem_object_from_offset(dev, *offset);
|
|
|
|
if (gem_obj == NULL) {
|
|
|
|
DRM_UNLOCK(dev);
|
2015-03-17 18:50:33 +00:00
|
|
|
return (-ENODEV);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
drm_gem_object_reference(gem_obj);
|
|
|
|
DRM_UNLOCK(dev);
|
|
|
|
vm_obj = cdev_pager_allocate(gem_obj, OBJT_MGTDEVICE,
|
|
|
|
dev->driver->gem_pager_ops, size, nprot,
|
|
|
|
DRM_GEM_MAPPING_MAPOFF(*offset), curthread->td_ucred);
|
|
|
|
if (vm_obj == NULL) {
|
|
|
|
drm_gem_object_unreference_unlocked(gem_obj);
|
2015-03-17 18:50:33 +00:00
|
|
|
return (-EINVAL);
|
2012-05-22 11:07:44 +00:00
|
|
|
}
|
|
|
|
*offset = DRM_GEM_MAPPING_MAPOFF(*offset);
|
|
|
|
*obj_res = vm_obj;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
drm_gem_pager_dtr(void *handle)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *obj;
|
|
|
|
struct drm_device *dev;
|
|
|
|
|
|
|
|
obj = handle;
|
|
|
|
dev = obj->dev;
|
|
|
|
|
|
|
|
DRM_LOCK(dev);
|
|
|
|
drm_gem_free_mmap_offset(obj);
|
|
|
|
drm_gem_object_unreference(obj);
|
|
|
|
DRM_UNLOCK(dev);
|
|
|
|
}
|