2009-07-05 11:51:42 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright 2008 Red Hat Inc.
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
*
|
|
|
|
* 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 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
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
|
|
|
|
*
|
|
|
|
* Authors: Dave Airlie
|
|
|
|
* Alex Deucher
|
|
|
|
* Jerome Glisse
|
|
|
|
*/
|
2012-11-03 03:41:31 +01:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/radeon_drm.h>
|
2009-07-05 11:51:42 +02:00
|
|
|
#include "radeon.h"
|
|
|
|
|
|
|
|
void radeon_gem_object_free(struct drm_gem_object *gobj)
|
|
|
|
{
|
2011-06-29 07:52:36 +02:00
|
|
|
struct radeon_bo *robj = gem_to_radeon_bo(gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
|
|
|
|
if (robj) {
|
2010-02-12 14:55:15 +01:00
|
|
|
radeon_bo_unref(&robj);
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size,
|
2012-11-03 03:41:31 +01:00
|
|
|
int alignment, int initial_domain,
|
2014-09-01 13:49:48 +02:00
|
|
|
u32 flags, bool kernel,
|
2012-11-03 03:41:31 +01:00
|
|
|
struct drm_gem_object **obj)
|
2009-07-05 11:51:42 +02:00
|
|
|
{
|
2010-02-12 14:55:15 +01:00
|
|
|
struct radeon_bo *robj;
|
2012-11-03 03:41:31 +01:00
|
|
|
unsigned long max_size;
|
2009-07-05 11:51:42 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
*obj = NULL;
|
|
|
|
/* At least align on page size */
|
|
|
|
if (alignment < PAGE_SIZE) {
|
|
|
|
alignment = PAGE_SIZE;
|
|
|
|
}
|
2012-11-03 03:41:31 +01:00
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
/* Maximum bo size is the unpinned gtt size since we use the gtt to
|
|
|
|
* handle vram to system pool migrations.
|
|
|
|
*/
|
|
|
|
max_size = rdev->mc.gtt_size - rdev->gart_pin_size;
|
2012-11-03 03:41:31 +01:00
|
|
|
if (size > max_size) {
|
2014-09-01 13:49:48 +02:00
|
|
|
DRM_DEBUG("Allocation size %ldMb bigger than %ldMb limit\n",
|
|
|
|
size >> 20, max_size >> 20);
|
2012-11-03 03:41:31 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
retry:
|
2014-09-01 13:49:48 +02:00
|
|
|
r = radeon_bo_create(rdev, size, alignment, kernel, initial_domain,
|
2014-12-27 16:58:21 +01:00
|
|
|
flags, NULL, NULL, &robj);
|
2009-07-05 11:51:42 +02:00
|
|
|
if (r) {
|
2012-11-03 03:41:31 +01:00
|
|
|
if (r != -ERESTARTSYS) {
|
|
|
|
if (initial_domain == RADEON_GEM_DOMAIN_VRAM) {
|
|
|
|
initial_domain |= RADEON_GEM_DOMAIN_GTT;
|
|
|
|
goto retry;
|
|
|
|
}
|
2014-09-01 13:49:48 +02:00
|
|
|
DRM_ERROR("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
|
2011-06-29 07:52:36 +02:00
|
|
|
size, initial_domain, alignment, r);
|
2012-11-03 03:41:31 +01:00
|
|
|
}
|
2010-02-12 14:55:15 +01:00
|
|
|
return r;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
2011-06-29 07:52:36 +02:00
|
|
|
*obj = &robj->gem_base;
|
|
|
|
|
|
|
|
mutex_lock(&rdev->gem.mutex);
|
|
|
|
list_add_tail(&robj->list, &rdev->gem.objects);
|
|
|
|
mutex_unlock(&rdev->gem.mutex);
|
|
|
|
|
2009-07-05 11:51:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-01 13:49:48 +02:00
|
|
|
static int radeon_gem_set_domain(struct drm_gem_object *gobj,
|
2009-07-05 11:51:42 +02:00
|
|
|
uint32_t rdomain, uint32_t wdomain)
|
|
|
|
{
|
2010-02-12 14:55:15 +01:00
|
|
|
struct radeon_bo *robj;
|
2009-07-05 11:51:42 +02:00
|
|
|
uint32_t domain;
|
2014-12-27 16:58:21 +01:00
|
|
|
long r;
|
2009-07-05 11:51:42 +02:00
|
|
|
|
|
|
|
/* FIXME: reeimplement */
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
/* work out where to validate the buffer to */
|
|
|
|
domain = wdomain;
|
|
|
|
if (!domain) {
|
|
|
|
domain = rdomain;
|
|
|
|
}
|
|
|
|
if (!domain) {
|
|
|
|
/* Do nothings */
|
2012-11-03 03:41:31 +01:00
|
|
|
printk(KERN_WARNING "Set domain without domain !\n");
|
2009-07-05 11:51:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (domain == RADEON_GEM_DOMAIN_CPU) {
|
|
|
|
/* Asking for cpu access wait for object idle */
|
2010-02-12 14:55:15 +01:00
|
|
|
// r = radeon_bo_wait(robj, NULL, false);
|
|
|
|
// if (r) {
|
|
|
|
// printk(KERN_ERR "Failed to wait for object !\n");
|
|
|
|
// return r;
|
|
|
|
// }
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_init(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&rdev->gem.objects);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void radeon_gem_fini(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
// radeon_object_force_delete(rdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* GEM ioctls.
|
|
|
|
*/
|
|
|
|
int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
|
|
|
struct drm_radeon_gem_info *args = data;
|
2011-06-29 07:52:36 +02:00
|
|
|
struct ttm_mem_type_manager *man;
|
|
|
|
|
|
|
|
man = &rdev->mman.bdev.man[TTM_PL_VRAM];
|
2009-07-05 11:51:42 +02:00
|
|
|
|
2009-09-26 16:08:05 +02:00
|
|
|
args->vram_size = rdev->mc.real_vram_size;
|
2011-06-29 07:52:36 +02:00
|
|
|
args->vram_visible = (u64)man->size << PAGE_SHIFT;
|
2014-09-01 13:49:48 +02:00
|
|
|
args->vram_visible -= rdev->vram_pin_size;
|
|
|
|
args->gart_size = rdev->mc.gtt_size;
|
|
|
|
args->gart_size -= rdev->gart_pin_size;
|
|
|
|
|
2009-07-05 11:51:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
/* TODO: implement */
|
|
|
|
DRM_ERROR("unimplemented %s\n", __func__);
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
/* TODO: implement */
|
|
|
|
DRM_ERROR("unimplemented %s\n", __func__);
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
|
|
|
struct drm_radeon_gem_create *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
uint32_t handle;
|
|
|
|
int r;
|
|
|
|
|
2012-11-03 03:41:31 +01:00
|
|
|
down_read(&rdev->exclusive_lock);
|
2009-07-05 11:51:42 +02:00
|
|
|
/* create a gem object to contain this object in */
|
|
|
|
args->size = roundup(args->size, PAGE_SIZE);
|
|
|
|
r = radeon_gem_object_create(rdev, args->size, args->alignment,
|
2014-09-01 13:49:48 +02:00
|
|
|
args->initial_domain, args->flags,
|
2010-02-12 14:55:15 +01:00
|
|
|
false, &gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
if (r) {
|
2012-11-03 03:41:31 +01:00
|
|
|
up_read(&rdev->exclusive_lock);
|
|
|
|
r = radeon_gem_handle_lockup(rdev, r);
|
2009-07-05 11:51:42 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = drm_gem_handle_create(filp, gobj, &handle);
|
2011-06-24 12:44:10 +02:00
|
|
|
/* drop reference from allocate - handle holds it now */
|
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
if (r) {
|
2012-11-03 03:41:31 +01:00
|
|
|
up_read(&rdev->exclusive_lock);
|
|
|
|
r = radeon_gem_handle_lockup(rdev, r);
|
2009-07-05 11:51:42 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
args->handle = handle;
|
2012-11-03 03:41:31 +01:00
|
|
|
up_read(&rdev->exclusive_lock);
|
2009-07-05 11:51:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
/* transition the BO to a domain -
|
|
|
|
* just validate the BO into a certain domain */
|
2012-11-03 03:41:31 +01:00
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
2009-07-05 11:51:42 +02:00
|
|
|
struct drm_radeon_gem_set_domain *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
2010-02-12 14:55:15 +01:00
|
|
|
struct radeon_bo *robj;
|
2009-07-05 11:51:42 +02:00
|
|
|
int r;
|
|
|
|
|
|
|
|
/* for now if someone requests domain CPU -
|
|
|
|
* just make sure the buffer is finished with */
|
2012-11-03 03:41:31 +01:00
|
|
|
down_read(&rdev->exclusive_lock);
|
2009-07-05 11:51:42 +02:00
|
|
|
|
|
|
|
/* just do a BO wait for now */
|
|
|
|
gobj = drm_gem_object_lookup(dev, filp, args->handle);
|
|
|
|
if (gobj == NULL) {
|
2012-11-03 03:41:31 +01:00
|
|
|
up_read(&rdev->exclusive_lock);
|
2011-06-24 12:44:10 +02:00
|
|
|
return -ENOENT;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
|
|
|
|
r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain);
|
|
|
|
|
2011-06-24 12:44:10 +02:00
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2012-11-03 03:41:31 +01:00
|
|
|
up_read(&rdev->exclusive_lock);
|
|
|
|
r = radeon_gem_handle_lockup(robj->rdev, r);
|
2009-07-05 11:51:42 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-12-27 16:58:21 +01:00
|
|
|
static int radeon_mode_mmap(struct drm_file *filp,
|
2011-06-29 07:52:36 +02:00
|
|
|
struct drm_device *dev,
|
2014-12-27 16:58:21 +01:00
|
|
|
uint32_t handle, bool dumb,
|
|
|
|
uint64_t *offset_p)
|
2009-07-05 11:51:42 +02:00
|
|
|
{
|
|
|
|
struct drm_gem_object *gobj;
|
2010-02-12 14:55:15 +01:00
|
|
|
struct radeon_bo *robj;
|
2009-07-05 11:51:42 +02:00
|
|
|
|
2011-06-29 07:52:36 +02:00
|
|
|
gobj = drm_gem_object_lookup(dev, filp, handle);
|
2009-07-05 11:51:42 +02:00
|
|
|
if (gobj == NULL) {
|
2011-06-24 12:44:10 +02:00
|
|
|
return -ENOENT;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
2014-12-27 16:58:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't allow dumb mmaps on objects created using another
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
WARN_ONCE(dumb && !(gobj->dumb || gobj->import_attach),
|
|
|
|
"Illegal dumb map of GPU buffer.\n");
|
|
|
|
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
|
|
|
*offset_p = radeon_bo_mmap_offset(robj);
|
2011-06-24 12:44:10 +02:00
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2010-02-12 14:55:15 +01:00
|
|
|
return 0;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
|
|
|
|
2011-06-29 07:52:36 +02:00
|
|
|
int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct drm_radeon_gem_mmap *args = data;
|
|
|
|
|
2014-12-27 16:58:21 +01:00
|
|
|
return radeon_mode_mmap(filp, dev, args->handle, false,
|
|
|
|
&args->addr_ptr);
|
2011-06-29 07:52:36 +02:00
|
|
|
}
|
|
|
|
|
2009-07-05 11:51:42 +02:00
|
|
|
int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
2012-11-03 03:41:31 +01:00
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
2010-02-12 14:55:15 +01:00
|
|
|
struct drm_radeon_gem_busy *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct radeon_bo *robj;
|
|
|
|
int r;
|
|
|
|
uint32_t cur_placement = 0;
|
|
|
|
|
|
|
|
gobj = drm_gem_object_lookup(dev, filp, args->handle);
|
|
|
|
if (gobj == NULL) {
|
2011-06-24 12:44:10 +02:00
|
|
|
return -ENOENT;
|
2010-02-12 14:55:15 +01:00
|
|
|
}
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
2010-02-12 14:55:15 +01:00
|
|
|
r = radeon_bo_wait(robj, &cur_placement, true);
|
2014-09-01 13:49:48 +02:00
|
|
|
args->domain = radeon_mem_type_to_domain(cur_placement);
|
2011-06-24 12:44:10 +02:00
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2012-11-03 03:41:31 +01:00
|
|
|
r = radeon_gem_handle_lockup(rdev, r);
|
2010-02-12 14:55:15 +01:00
|
|
|
return r;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
2012-11-03 03:41:31 +01:00
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
2009-07-05 11:51:42 +02:00
|
|
|
struct drm_radeon_gem_wait_idle *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
2010-02-12 14:55:15 +01:00
|
|
|
struct radeon_bo *robj;
|
2014-12-27 16:58:21 +01:00
|
|
|
int r = 0;
|
2014-09-01 13:49:48 +02:00
|
|
|
uint32_t cur_placement = 0;
|
2014-12-27 16:58:21 +01:00
|
|
|
long ret;
|
2009-07-05 11:51:42 +02:00
|
|
|
|
|
|
|
gobj = drm_gem_object_lookup(dev, filp, args->handle);
|
|
|
|
if (gobj == NULL) {
|
2011-06-24 12:44:10 +02:00
|
|
|
return -ENOENT;
|
2009-07-05 11:51:42 +02:00
|
|
|
}
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
2014-09-01 13:49:48 +02:00
|
|
|
r = radeon_bo_wait(robj, &cur_placement, false);
|
|
|
|
/* Flush HDP cache via MMIO if necessary */
|
|
|
|
if (rdev->asic->mmio_hdp_flush &&
|
|
|
|
radeon_mem_type_to_domain(cur_placement) == RADEON_GEM_DOMAIN_VRAM)
|
|
|
|
robj->rdev->asic->mmio_hdp_flush(rdev);
|
2011-06-24 12:44:10 +02:00
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2012-11-03 03:41:31 +01:00
|
|
|
r = radeon_gem_handle_lockup(rdev, r);
|
2010-02-12 14:55:15 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct drm_radeon_gem_set_tiling *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct radeon_bo *robj;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
DRM_DEBUG("%d \n", args->handle);
|
|
|
|
gobj = drm_gem_object_lookup(dev, filp, args->handle);
|
|
|
|
if (gobj == NULL)
|
2011-06-24 12:44:10 +02:00
|
|
|
return -ENOENT;
|
2011-06-29 07:52:36 +02:00
|
|
|
robj = gem_to_radeon_bo(gobj);
|
2010-02-12 14:55:15 +01:00
|
|
|
r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch);
|
2011-06-24 12:44:10 +02:00
|
|
|
drm_gem_object_unreference_unlocked(gobj);
|
2009-07-05 11:51:42 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|