2009-06-05 20:42:42 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
* 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDERS, AUTHORS 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.
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* Jerome Glisse <glisse@freedesktop.org>
|
|
|
|
* Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
|
|
|
|
* Dave Airlie
|
|
|
|
*/
|
2019-06-08 16:02:40 +08:00
|
|
|
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/pagemap.h>
|
2019-12-03 18:04:02 +08:00
|
|
|
#include <linux/pci.h>
|
2019-06-08 16:02:40 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/swap.h>
|
|
|
|
#include <linux/swiotlb.h>
|
|
|
|
|
|
|
|
#include <drm/drm_agpsupport.h>
|
|
|
|
#include <drm/drm_debugfs.h>
|
|
|
|
#include <drm/drm_device.h>
|
|
|
|
#include <drm/drm_file.h>
|
|
|
|
#include <drm/drm_prime.h>
|
|
|
|
#include <drm/radeon_drm.h>
|
2017-04-24 12:50:31 +08:00
|
|
|
#include <drm/ttm/ttm_bo_api.h>
|
|
|
|
#include <drm/ttm/ttm_bo_driver.h>
|
2019-06-08 16:02:40 +08:00
|
|
|
#include <drm/ttm/ttm_placement.h>
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
#include "radeon_reg.h"
|
|
|
|
#include "radeon.h"
|
2020-11-17 01:29:27 +08:00
|
|
|
#include "radeon_ttm.h"
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2009-08-26 11:13:37 +08:00
|
|
|
static int radeon_ttm_debugfs_init(struct radeon_device *rdev);
|
|
|
|
|
2020-09-17 11:48:59 +08:00
|
|
|
static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm,
|
|
|
|
struct ttm_resource *bo_mem);
|
2020-10-20 09:03:15 +08:00
|
|
|
static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm);
|
2020-09-17 11:48:59 +08:00
|
|
|
|
2020-06-25 02:26:42 +08:00
|
|
|
struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
struct radeon_mman *mman;
|
|
|
|
struct radeon_device *rdev;
|
|
|
|
|
|
|
|
mman = container_of(bdev, struct radeon_mman, bdev);
|
|
|
|
rdev = container_of(mman, struct radeon_device, mman);
|
|
|
|
return rdev;
|
|
|
|
}
|
|
|
|
|
2020-07-23 17:47:57 +08:00
|
|
|
static int radeon_ttm_init_vram(struct radeon_device *rdev)
|
|
|
|
{
|
2020-08-04 10:56:19 +08:00
|
|
|
return ttm_range_man_init(&rdev->mman.bdev, TTM_PL_VRAM,
|
2020-09-11 21:06:53 +08:00
|
|
|
false, rdev->mc.real_vram_size >> PAGE_SHIFT);
|
2020-07-23 17:47:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int radeon_ttm_init_gtt(struct radeon_device *rdev)
|
|
|
|
{
|
2020-08-04 10:56:19 +08:00
|
|
|
return ttm_range_man_init(&rdev->mman.bdev, TTM_PL_TT,
|
2020-09-11 21:06:53 +08:00
|
|
|
true, rdev->mc.gtt_size >> PAGE_SHIFT);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2009-12-07 22:52:58 +08:00
|
|
|
static void radeon_evict_flags(struct ttm_buffer_object *bo,
|
|
|
|
struct ttm_placement *placement)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2017-07-02 17:06:47 +08:00
|
|
|
static const struct ttm_place placements = {
|
2014-08-27 19:16:04 +08:00
|
|
|
.fpfn = 0,
|
|
|
|
.lpfn = 0,
|
2020-09-10 19:39:41 +08:00
|
|
|
.mem_type = TTM_PL_SYSTEM,
|
2020-09-30 22:44:16 +08:00
|
|
|
.flags = 0
|
2014-08-27 19:16:04 +08:00
|
|
|
};
|
|
|
|
|
2009-12-15 04:02:09 +08:00
|
|
|
struct radeon_bo *rbo;
|
|
|
|
|
|
|
|
if (!radeon_ttm_bo_is_radeon_bo(bo)) {
|
|
|
|
placement->placement = &placements;
|
|
|
|
placement->busy_placement = &placements;
|
|
|
|
placement->num_placement = 1;
|
|
|
|
placement->num_busy_placement = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rbo = container_of(bo, struct radeon_bo, tbo);
|
2009-06-05 20:42:42 +08:00
|
|
|
switch (bo->mem.mem_type) {
|
2009-12-07 22:52:58 +08:00
|
|
|
case TTM_PL_VRAM:
|
2014-12-03 13:03:49 +08:00
|
|
|
if (rbo->rdev->ring[radeon_copy_ring_index(rbo->rdev)].ready == false)
|
2010-01-13 07:21:49 +08:00
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_CPU);
|
2014-10-09 17:55:04 +08:00
|
|
|
else if (rbo->rdev->mc.visible_vram_size < rbo->rdev->mc.real_vram_size &&
|
|
|
|
bo->mem.start < (rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT)) {
|
|
|
|
unsigned fpfn = rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Try evicting to the CPU inaccessible part of VRAM
|
|
|
|
* first, but only set GTT as busy placement, so this
|
|
|
|
* BO will be evicted to GTT rather than causing other
|
|
|
|
* BOs to be evicted from VRAM
|
|
|
|
*/
|
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM |
|
|
|
|
RADEON_GEM_DOMAIN_GTT);
|
|
|
|
rbo->placement.num_busy_placement = 0;
|
|
|
|
for (i = 0; i < rbo->placement.num_placement; i++) {
|
2020-09-10 19:39:41 +08:00
|
|
|
if (rbo->placements[i].mem_type == TTM_PL_VRAM) {
|
2017-03-24 18:01:09 +08:00
|
|
|
if (rbo->placements[i].fpfn < fpfn)
|
|
|
|
rbo->placements[i].fpfn = fpfn;
|
2014-10-09 17:55:04 +08:00
|
|
|
} else {
|
|
|
|
rbo->placement.busy_placement =
|
|
|
|
&rbo->placements[i];
|
|
|
|
rbo->placement.num_busy_placement = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2010-01-13 07:21:49 +08:00
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);
|
2009-12-07 22:52:58 +08:00
|
|
|
break;
|
|
|
|
case TTM_PL_TT:
|
2009-06-05 20:42:42 +08:00
|
|
|
default:
|
2009-12-07 22:52:58 +08:00
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_CPU);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2009-12-10 04:57:37 +08:00
|
|
|
*placement = rbo->placement;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp)
|
|
|
|
{
|
2013-08-26 00:28:59 +08:00
|
|
|
struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo);
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
|
2013-08-26 00:28:59 +08:00
|
|
|
|
2020-09-08 04:46:22 +08:00
|
|
|
if (radeon_ttm_tt_has_userptr(rdev, bo->ttm))
|
2016-04-19 21:07:50 +08:00
|
|
|
return -EPERM;
|
2019-08-05 22:01:06 +08:00
|
|
|
return drm_vma_node_verify_access(&rbo->tbo.base.vma_node,
|
2016-09-01 20:48:33 +08:00
|
|
|
filp->private_data);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int radeon_move_blit(struct ttm_buffer_object *bo,
|
2020-09-23 11:04:47 +08:00
|
|
|
bool evict,
|
2020-08-04 10:56:32 +08:00
|
|
|
struct ttm_resource *new_mem,
|
|
|
|
struct ttm_resource *old_mem)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
|
|
|
uint64_t old_start, new_start;
|
2012-05-08 20:24:01 +08:00
|
|
|
struct radeon_fence *fence;
|
2014-09-05 02:01:53 +08:00
|
|
|
unsigned num_pages;
|
2012-05-08 20:24:01 +08:00
|
|
|
int r, ridx;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
rdev = radeon_get_rdev(bo->bdev);
|
2012-05-08 20:24:01 +08:00
|
|
|
ridx = radeon_copy_ring_index(rdev);
|
2016-08-17 15:46:42 +08:00
|
|
|
old_start = (u64)old_mem->start << PAGE_SHIFT;
|
|
|
|
new_start = (u64)new_mem->start << PAGE_SHIFT;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
switch (old_mem->mem_type) {
|
|
|
|
case TTM_PL_VRAM:
|
drm/radeon/kms: simplify memory controller setup V2
Get rid of _location and use _start/_end also simplify the
computation of vram_start|end & gtt_start|end. For R1XX-R2XX
we place VRAM at the same address of PCI aperture, those GPU
shouldn't have much memory and seems to behave better when
setup that way. For R3XX and newer we place VRAM at 0. For
R6XX-R7XX AGP we place VRAM before or after AGP aperture this
might limit to limit the VRAM size but it's very unlikely.
For IGP we don't change the VRAM placement.
Tested on (compiz,quake3,suspend/resume):
PCI/PCIE:RV280,R420,RV515,RV570,RV610,RV710
AGP:RV100,RV280,R420,RV350,RV620(RPB*),RV730
IGP:RS480(RPB*),RS690,RS780(RPB*),RS880
RPB: resume previously broken
V2 correct commit message to reflect more accurately the bug
and move VRAM placement to 0 for most of the GPU to avoid
limiting VRAM.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2010-02-18 05:54:29 +08:00
|
|
|
old_start += rdev->mc.vram_start;
|
2009-06-05 20:42:42 +08:00
|
|
|
break;
|
|
|
|
case TTM_PL_TT:
|
drm/radeon/kms: simplify memory controller setup V2
Get rid of _location and use _start/_end also simplify the
computation of vram_start|end & gtt_start|end. For R1XX-R2XX
we place VRAM at the same address of PCI aperture, those GPU
shouldn't have much memory and seems to behave better when
setup that way. For R3XX and newer we place VRAM at 0. For
R6XX-R7XX AGP we place VRAM before or after AGP aperture this
might limit to limit the VRAM size but it's very unlikely.
For IGP we don't change the VRAM placement.
Tested on (compiz,quake3,suspend/resume):
PCI/PCIE:RV280,R420,RV515,RV570,RV610,RV710
AGP:RV100,RV280,R420,RV350,RV620(RPB*),RV730
IGP:RS480(RPB*),RS690,RS780(RPB*),RS880
RPB: resume previously broken
V2 correct commit message to reflect more accurately the bug
and move VRAM placement to 0 for most of the GPU to avoid
limiting VRAM.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2010-02-18 05:54:29 +08:00
|
|
|
old_start += rdev->mc.gtt_start;
|
2009-06-05 20:42:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DRM_ERROR("Unknown placement %d\n", old_mem->mem_type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
switch (new_mem->mem_type) {
|
|
|
|
case TTM_PL_VRAM:
|
drm/radeon/kms: simplify memory controller setup V2
Get rid of _location and use _start/_end also simplify the
computation of vram_start|end & gtt_start|end. For R1XX-R2XX
we place VRAM at the same address of PCI aperture, those GPU
shouldn't have much memory and seems to behave better when
setup that way. For R3XX and newer we place VRAM at 0. For
R6XX-R7XX AGP we place VRAM before or after AGP aperture this
might limit to limit the VRAM size but it's very unlikely.
For IGP we don't change the VRAM placement.
Tested on (compiz,quake3,suspend/resume):
PCI/PCIE:RV280,R420,RV515,RV570,RV610,RV710
AGP:RV100,RV280,R420,RV350,RV620(RPB*),RV730
IGP:RS480(RPB*),RS690,RS780(RPB*),RS880
RPB: resume previously broken
V2 correct commit message to reflect more accurately the bug
and move VRAM placement to 0 for most of the GPU to avoid
limiting VRAM.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2010-02-18 05:54:29 +08:00
|
|
|
new_start += rdev->mc.vram_start;
|
2009-06-05 20:42:42 +08:00
|
|
|
break;
|
|
|
|
case TTM_PL_TT:
|
drm/radeon/kms: simplify memory controller setup V2
Get rid of _location and use _start/_end also simplify the
computation of vram_start|end & gtt_start|end. For R1XX-R2XX
we place VRAM at the same address of PCI aperture, those GPU
shouldn't have much memory and seems to behave better when
setup that way. For R3XX and newer we place VRAM at 0. For
R6XX-R7XX AGP we place VRAM before or after AGP aperture this
might limit to limit the VRAM size but it's very unlikely.
For IGP we don't change the VRAM placement.
Tested on (compiz,quake3,suspend/resume):
PCI/PCIE:RV280,R420,RV515,RV570,RV610,RV710
AGP:RV100,RV280,R420,RV350,RV620(RPB*),RV730
IGP:RS480(RPB*),RS690,RS780(RPB*),RS880
RPB: resume previously broken
V2 correct commit message to reflect more accurately the bug
and move VRAM placement to 0 for most of the GPU to avoid
limiting VRAM.
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2010-02-18 05:54:29 +08:00
|
|
|
new_start += rdev->mc.gtt_start;
|
2009-06-05 20:42:42 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DRM_ERROR("Unknown placement %d\n", old_mem->mem_type);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2012-05-08 20:24:01 +08:00
|
|
|
if (!rdev->ring[ridx].ready) {
|
2012-01-06 11:11:07 +08:00
|
|
|
DRM_ERROR("Trying to move memory with ring turned off.\n");
|
2009-06-05 20:42:42 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2011-09-17 00:04:08 +08:00
|
|
|
|
|
|
|
BUILD_BUG_ON((PAGE_SIZE % RADEON_GPU_PAGE_SIZE) != 0);
|
|
|
|
|
2014-09-05 02:01:53 +08:00
|
|
|
num_pages = new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE);
|
2019-08-05 22:01:13 +08:00
|
|
|
fence = radeon_copy(rdev, old_start, new_start, num_pages, bo->base.resv);
|
2014-09-05 02:01:53 +08:00
|
|
|
if (IS_ERR(fence))
|
|
|
|
return PTR_ERR(fence);
|
|
|
|
|
2020-09-17 14:36:14 +08:00
|
|
|
r = ttm_bo_move_accel_cleanup(bo, &fence->base, evict, false, new_mem);
|
2009-06-05 20:42:42 +08:00
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-04-26 22:31:14 +08:00
|
|
|
static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
|
|
|
|
struct ttm_operation_ctx *ctx,
|
2020-10-29 11:58:52 +08:00
|
|
|
struct ttm_resource *new_mem,
|
|
|
|
struct ttm_place *hop)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
struct radeon_device *rdev;
|
2016-03-28 15:39:14 +08:00
|
|
|
struct radeon_bo *rbo;
|
2020-08-04 10:56:32 +08:00
|
|
|
struct ttm_resource *old_mem = &bo->mem;
|
2009-06-05 20:42:42 +08:00
|
|
|
int r;
|
|
|
|
|
2020-10-20 09:03:19 +08:00
|
|
|
if (new_mem->mem_type == TTM_PL_TT) {
|
|
|
|
r = radeon_ttm_tt_bind(bo->bdev, bo->ttm, new_mem);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
2020-10-20 09:03:18 +08:00
|
|
|
|
2020-09-23 11:04:49 +08:00
|
|
|
r = ttm_bo_wait_ctx(bo, ctx);
|
2016-06-06 16:17:53 +08:00
|
|
|
if (r)
|
2020-11-25 22:32:23 +08:00
|
|
|
return r;
|
2016-06-06 16:17:53 +08:00
|
|
|
|
2016-03-28 15:39:14 +08:00
|
|
|
/* Can't move a pinned BO */
|
|
|
|
rbo = container_of(bo, struct radeon_bo, tbo);
|
2020-09-21 19:18:02 +08:00
|
|
|
if (WARN_ON_ONCE(rbo->tbo.pin_count > 0))
|
2016-03-28 15:39:14 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
rdev = radeon_get_rdev(bo->bdev);
|
|
|
|
if (old_mem->mem_type == TTM_PL_SYSTEM && bo->ttm == NULL) {
|
2020-09-08 04:46:18 +08:00
|
|
|
ttm_bo_move_null(bo, new_mem);
|
2020-11-25 22:32:23 +08:00
|
|
|
goto out;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2020-09-24 13:18:04 +08:00
|
|
|
if (old_mem->mem_type == TTM_PL_SYSTEM &&
|
|
|
|
new_mem->mem_type == TTM_PL_TT) {
|
2020-09-08 04:46:18 +08:00
|
|
|
ttm_bo_move_null(bo, new_mem);
|
2020-11-25 22:32:23 +08:00
|
|
|
goto out;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2020-09-24 13:18:04 +08:00
|
|
|
|
|
|
|
if (old_mem->mem_type == TTM_PL_TT &&
|
2020-10-19 15:13:13 +08:00
|
|
|
new_mem->mem_type == TTM_PL_SYSTEM) {
|
2020-10-20 09:03:15 +08:00
|
|
|
radeon_ttm_tt_unbind(bo->bdev, bo->ttm);
|
|
|
|
ttm_resource_free(bo, &bo->mem);
|
2020-10-19 15:13:13 +08:00
|
|
|
ttm_bo_assign_mem(bo, new_mem);
|
2020-11-25 22:32:23 +08:00
|
|
|
goto out;
|
2020-10-19 15:13:13 +08:00
|
|
|
}
|
2020-11-25 22:32:23 +08:00
|
|
|
if (rdev->ring[radeon_copy_ring_index(rdev)].ready &&
|
|
|
|
rdev->asic->copy.copy != NULL) {
|
|
|
|
if ((old_mem->mem_type == TTM_PL_SYSTEM &&
|
|
|
|
new_mem->mem_type == TTM_PL_VRAM) ||
|
|
|
|
(old_mem->mem_type == TTM_PL_VRAM &&
|
|
|
|
new_mem->mem_type == TTM_PL_SYSTEM)) {
|
|
|
|
hop->fpfn = 0;
|
|
|
|
hop->lpfn = 0;
|
|
|
|
hop->mem_type = TTM_PL_TT;
|
|
|
|
hop->flags = 0;
|
|
|
|
return -EMULTIHOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = radeon_move_blit(bo, evict, new_mem, old_mem);
|
|
|
|
} else {
|
|
|
|
r = -ENODEV;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2009-07-28 18:30:56 +08:00
|
|
|
if (r) {
|
2017-12-08 20:19:32 +08:00
|
|
|
r = ttm_bo_move_memcpy(bo, ctx, new_mem);
|
2020-11-25 22:32:23 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
2009-07-28 18:30:56 +08:00
|
|
|
}
|
2014-03-02 07:56:18 +08:00
|
|
|
|
2020-11-25 22:32:23 +08:00
|
|
|
out:
|
2014-03-02 07:56:18 +08:00
|
|
|
/* update statistics */
|
2020-12-09 22:07:50 +08:00
|
|
|
atomic64_add(bo->base.size, &rdev->num_bytes_moved);
|
2020-11-25 22:32:23 +08:00
|
|
|
radeon_bo_move_notify(bo, evict, new_mem);
|
2014-03-02 07:56:18 +08:00
|
|
|
return 0;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2020-08-04 10:56:32 +08:00
|
|
|
static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_resource *mem)
|
2010-04-09 20:39:24 +08:00
|
|
|
{
|
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
2020-08-11 15:46:58 +08:00
|
|
|
size_t bus_size = (size_t)mem->num_pages << PAGE_SHIFT;
|
2010-04-09 20:39:24 +08:00
|
|
|
|
|
|
|
switch (mem->mem_type) {
|
|
|
|
case TTM_PL_SYSTEM:
|
|
|
|
/* system memory */
|
|
|
|
return 0;
|
|
|
|
case TTM_PL_TT:
|
2015-09-09 22:45:52 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
2010-04-09 20:39:24 +08:00
|
|
|
if (rdev->flags & RADEON_IS_AGP) {
|
|
|
|
/* RADEON_IS_AGP is set only if AGP is active */
|
2020-09-07 19:44:36 +08:00
|
|
|
mem->bus.offset = (mem->start << PAGE_SHIFT) +
|
|
|
|
rdev->mc.agp_base;
|
2010-05-19 18:46:22 +08:00
|
|
|
mem->bus.is_iomem = !rdev->ddev->agp->cant_use_aperture;
|
2020-09-30 17:17:44 +08:00
|
|
|
mem->bus.caching = ttm_write_combined;
|
2010-04-09 20:39:24 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case TTM_PL_VRAM:
|
2010-08-05 08:48:18 +08:00
|
|
|
mem->bus.offset = mem->start << PAGE_SHIFT;
|
2010-04-09 20:39:24 +08:00
|
|
|
/* check if it's visible */
|
2020-08-11 15:46:58 +08:00
|
|
|
if ((mem->bus.offset + bus_size) > rdev->mc.visible_vram_size)
|
2010-04-09 20:39:24 +08:00
|
|
|
return -EINVAL;
|
2020-09-07 19:44:36 +08:00
|
|
|
mem->bus.offset += rdev->mc.aper_base;
|
2010-04-09 20:39:24 +08:00
|
|
|
mem->bus.is_iomem = true;
|
2020-09-30 17:17:44 +08:00
|
|
|
mem->bus.caching = ttm_write_combined;
|
2011-07-07 07:57:13 +08:00
|
|
|
#ifdef __alpha__
|
|
|
|
/*
|
|
|
|
* Alpha: use bus.addr to hold the ioremap() return,
|
|
|
|
* so we can modify bus.base below.
|
|
|
|
*/
|
2020-09-30 22:44:16 +08:00
|
|
|
mem->bus.addr = ioremap_wc(mem->bus.offset, bus_size);
|
2017-01-24 17:16:16 +08:00
|
|
|
if (!mem->bus.addr)
|
|
|
|
return -ENOMEM;
|
2011-07-07 07:57:13 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Alpha: Use just the bus offset plus
|
|
|
|
* the hose/domain memory base for bus.base.
|
|
|
|
* It then can be used to build PTEs for VRAM
|
|
|
|
* access, as done in ttm_bo_vm_fault().
|
|
|
|
*/
|
2020-09-07 19:44:36 +08:00
|
|
|
mem->bus.offset = (mem->bus.offset & 0x0ffffffffUL) +
|
2021-01-12 16:10:34 +08:00
|
|
|
rdev->hose->dense_mem_base;
|
2011-07-07 07:57:13 +08:00
|
|
|
#endif
|
2010-04-09 20:39:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
/*
|
|
|
|
* TTM backend functions.
|
|
|
|
*/
|
|
|
|
struct radeon_ttm_tt {
|
2020-10-21 20:06:49 +08:00
|
|
|
struct ttm_tt ttm;
|
2011-11-02 08:46:13 +08:00
|
|
|
u64 offset;
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
uint64_t userptr;
|
|
|
|
struct mm_struct *usermm;
|
|
|
|
uint32_t userflags;
|
2020-09-17 10:54:24 +08:00
|
|
|
bool bound;
|
2011-11-02 08:46:13 +08:00
|
|
|
};
|
|
|
|
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
/* prepare the sg table with the user pages */
|
2020-08-25 07:46:00 +08:00
|
|
|
static int radeon_ttm_tt_pin_userptr(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
{
|
2020-08-25 07:46:00 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
struct radeon_ttm_tt *gtt = (void *)ttm;
|
2020-06-19 18:36:17 +08:00
|
|
|
unsigned pinned = 0;
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
int r;
|
|
|
|
|
|
|
|
int write = !(gtt->userflags & RADEON_GEM_USERPTR_READONLY);
|
|
|
|
enum dma_data_direction direction = write ?
|
|
|
|
DMA_BIDIRECTIONAL : DMA_TO_DEVICE;
|
|
|
|
|
|
|
|
if (current->mm != gtt->usermm)
|
|
|
|
return -EPERM;
|
|
|
|
|
2014-08-07 15:36:01 +08:00
|
|
|
if (gtt->userflags & RADEON_GEM_USERPTR_ANONONLY) {
|
|
|
|
/* check that we only pin down anonymous memory
|
|
|
|
to prevent problems with writeback */
|
|
|
|
unsigned long end = gtt->userptr + ttm->num_pages * PAGE_SIZE;
|
|
|
|
struct vm_area_struct *vma;
|
|
|
|
vma = find_vma(gtt->usermm, gtt->userptr);
|
|
|
|
if (!vma || vma->vm_file || vma->vm_end < end)
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
do {
|
|
|
|
unsigned num_pages = ttm->num_pages - pinned;
|
|
|
|
uint64_t userptr = gtt->userptr + pinned * PAGE_SIZE;
|
|
|
|
struct page **pages = ttm->pages + pinned;
|
|
|
|
|
2016-10-13 08:20:16 +08:00
|
|
|
r = get_user_pages(userptr, num_pages, write ? FOLL_WRITE : 0,
|
|
|
|
pages, NULL);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
if (r < 0)
|
|
|
|
goto release_pages;
|
|
|
|
|
|
|
|
pinned += r;
|
|
|
|
|
|
|
|
} while (pinned < ttm->num_pages);
|
|
|
|
|
|
|
|
r = sg_alloc_table_from_pages(ttm->sg, ttm->pages, ttm->num_pages, 0,
|
|
|
|
ttm->num_pages << PAGE_SHIFT,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (r)
|
|
|
|
goto release_sg;
|
|
|
|
|
2020-06-19 18:36:17 +08:00
|
|
|
r = dma_map_sgtable(rdev->dev, ttm->sg, direction, 0);
|
|
|
|
if (r)
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
goto release_sg;
|
|
|
|
|
2020-10-08 18:57:32 +08:00
|
|
|
drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
|
|
|
|
ttm->num_pages);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
release_sg:
|
|
|
|
kfree(ttm->sg);
|
|
|
|
|
|
|
|
release_pages:
|
2017-11-16 09:37:55 +08:00
|
|
|
release_pages(ttm->pages, pinned);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static void radeon_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
{
|
2020-08-25 07:46:00 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
struct radeon_ttm_tt *gtt = (void *)ttm;
|
2015-05-05 15:24:17 +08:00
|
|
|
struct sg_page_iter sg_iter;
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
int write = !(gtt->userflags & RADEON_GEM_USERPTR_READONLY);
|
|
|
|
enum dma_data_direction direction = write ?
|
|
|
|
DMA_BIDIRECTIONAL : DMA_TO_DEVICE;
|
|
|
|
|
2015-03-31 23:36:57 +08:00
|
|
|
/* double check that we don't free the table twice */
|
|
|
|
if (!ttm->sg->sgl)
|
|
|
|
return;
|
|
|
|
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
/* free the sg table and pages again */
|
2020-06-19 18:36:17 +08:00
|
|
|
dma_unmap_sgtable(rdev->dev, ttm->sg, direction, 0);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
2020-06-19 18:36:17 +08:00
|
|
|
for_each_sgtable_page(ttm->sg, &sg_iter, 0) {
|
2015-05-05 15:24:17 +08:00
|
|
|
struct page *page = sg_page_iter_page(&sg_iter);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
|
|
|
|
set_page_dirty(page);
|
|
|
|
|
|
|
|
mark_page_accessed(page);
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
put_page(page);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sg_free_table(ttm->sg);
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:54:24 +08:00
|
|
|
static bool radeon_ttm_backend_is_bound(struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
struct radeon_ttm_tt *gtt = (void*)ttm;
|
|
|
|
|
|
|
|
return (gtt->bound);
|
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static int radeon_ttm_backend_bind(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm,
|
2020-08-04 10:56:32 +08:00
|
|
|
struct ttm_resource *bo_mem)
|
2011-11-02 08:46:13 +08:00
|
|
|
{
|
2011-11-10 06:15:26 +08:00
|
|
|
struct radeon_ttm_tt *gtt = (void*)ttm;
|
2020-08-25 07:46:00 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
2014-07-17 18:01:07 +08:00
|
|
|
uint32_t flags = RADEON_GART_PAGE_VALID | RADEON_GART_PAGE_READ |
|
|
|
|
RADEON_GART_PAGE_WRITE;
|
2011-11-02 08:46:13 +08:00
|
|
|
int r;
|
|
|
|
|
2020-09-17 10:54:24 +08:00
|
|
|
if (gtt->bound)
|
|
|
|
return 0;
|
|
|
|
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
if (gtt->userptr) {
|
2020-08-25 07:46:00 +08:00
|
|
|
radeon_ttm_tt_pin_userptr(bdev, ttm);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
flags &= ~RADEON_GART_PAGE_WRITE;
|
|
|
|
}
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
gtt->offset = (unsigned long)(bo_mem->start << PAGE_SHIFT);
|
|
|
|
if (!ttm->num_pages) {
|
2020-10-21 02:10:39 +08:00
|
|
|
WARN(1, "nothing to bind %u pages for mreg %p back %p!\n",
|
2011-11-02 08:46:13 +08:00
|
|
|
ttm->num_pages, bo_mem, ttm);
|
|
|
|
}
|
2020-09-30 16:38:48 +08:00
|
|
|
if (ttm->caching == ttm_cached)
|
2014-07-17 18:01:07 +08:00
|
|
|
flags |= RADEON_GART_PAGE_SNOOP;
|
2020-08-25 07:08:11 +08:00
|
|
|
r = radeon_gart_bind(rdev, gtt->offset, ttm->num_pages,
|
2014-07-17 18:01:07 +08:00
|
|
|
ttm->pages, gtt->ttm.dma_address, flags);
|
2011-11-02 08:46:13 +08:00
|
|
|
if (r) {
|
2020-10-21 02:10:39 +08:00
|
|
|
DRM_ERROR("failed to bind %u pages at 0x%08X\n",
|
2011-11-02 08:46:13 +08:00
|
|
|
ttm->num_pages, (unsigned)gtt->offset);
|
|
|
|
return r;
|
|
|
|
}
|
2020-09-17 10:54:24 +08:00
|
|
|
gtt->bound = true;
|
2011-11-02 08:46:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static void radeon_ttm_backend_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
|
2011-11-02 08:46:13 +08:00
|
|
|
{
|
2011-11-10 06:15:26 +08:00
|
|
|
struct radeon_ttm_tt *gtt = (void *)ttm;
|
2020-08-25 07:46:00 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
2011-11-02 08:46:13 +08:00
|
|
|
|
2020-09-17 10:54:24 +08:00
|
|
|
if (!gtt->bound)
|
|
|
|
return;
|
|
|
|
|
2020-08-25 07:08:11 +08:00
|
|
|
radeon_gart_unbind(rdev, gtt->offset, ttm->num_pages);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
if (gtt->userptr)
|
2020-08-25 07:46:00 +08:00
|
|
|
radeon_ttm_tt_unpin_userptr(bdev, ttm);
|
2020-09-17 10:54:24 +08:00
|
|
|
gtt->bound = false;
|
2011-11-02 08:46:13 +08:00
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
|
2011-11-02 08:46:13 +08:00
|
|
|
{
|
2011-11-10 06:15:26 +08:00
|
|
|
struct radeon_ttm_tt *gtt = (void *)ttm;
|
2011-11-02 08:46:13 +08:00
|
|
|
|
2020-09-17 11:24:50 +08:00
|
|
|
radeon_ttm_backend_unbind(bdev, ttm);
|
2020-09-17 11:20:48 +08:00
|
|
|
ttm_tt_destroy_common(bdev, ttm);
|
|
|
|
|
2020-10-21 20:06:49 +08:00
|
|
|
ttm_tt_fini(>t->ttm);
|
2011-11-02 08:46:13 +08:00
|
|
|
kfree(gtt);
|
|
|
|
}
|
|
|
|
|
2018-02-22 17:18:14 +08:00
|
|
|
static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
|
|
|
|
uint32_t page_flags)
|
2011-11-02 08:46:13 +08:00
|
|
|
{
|
|
|
|
struct radeon_ttm_tt *gtt;
|
2020-09-30 16:38:48 +08:00
|
|
|
enum ttm_caching caching;
|
|
|
|
struct radeon_bo *rbo;
|
2015-09-09 22:45:52 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
2020-11-13 13:06:52 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
|
|
|
|
|
2011-11-02 08:46:13 +08:00
|
|
|
if (rdev->flags & RADEON_IS_AGP) {
|
2018-02-22 17:18:14 +08:00
|
|
|
return ttm_agp_tt_create(bo, rdev->ddev->agp->bridge,
|
|
|
|
page_flags);
|
2011-11-02 08:46:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
2020-11-13 13:06:52 +08:00
|
|
|
rbo = container_of(bo, struct radeon_bo, tbo);
|
2011-11-02 08:46:13 +08:00
|
|
|
|
|
|
|
gtt = kzalloc(sizeof(struct radeon_ttm_tt), GFP_KERNEL);
|
|
|
|
if (gtt == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-09-30 16:38:48 +08:00
|
|
|
|
|
|
|
if (rbo->flags & RADEON_GEM_GTT_UC)
|
|
|
|
caching = ttm_uncached;
|
|
|
|
else if (rbo->flags & RADEON_GEM_GTT_WC)
|
|
|
|
caching = ttm_write_combined;
|
|
|
|
else
|
|
|
|
caching = ttm_cached;
|
|
|
|
|
2020-10-08 19:01:35 +08:00
|
|
|
if (ttm_sg_tt_init(>t->ttm, bo, page_flags, caching)) {
|
2011-11-10 06:15:26 +08:00
|
|
|
kfree(gtt);
|
2011-11-02 08:46:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-10-21 20:06:49 +08:00
|
|
|
return >t->ttm;
|
2011-11-02 08:46:13 +08:00
|
|
|
}
|
|
|
|
|
2020-09-08 04:46:22 +08:00
|
|
|
static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,
|
|
|
|
struct ttm_tt *ttm)
|
2014-09-17 18:00:05 +08:00
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
|
|
|
if (rdev->flags & RADEON_IS_AGP)
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!ttm)
|
2014-09-17 18:00:05 +08:00
|
|
|
return NULL;
|
2020-10-21 20:06:49 +08:00
|
|
|
return container_of(ttm, struct radeon_ttm_tt, ttm);
|
2014-09-17 18:00:05 +08:00
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm,
|
|
|
|
struct ttm_operation_ctx *ctx)
|
2011-10-18 05:15:08 +08:00
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
|
|
|
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
|
2012-05-11 06:33:13 +08:00
|
|
|
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
|
2011-10-18 05:15:08 +08:00
|
|
|
|
2014-09-17 18:00:05 +08:00
|
|
|
if (gtt && gtt->userptr) {
|
2015-06-19 12:05:23 +08:00
|
|
|
ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
if (!ttm->sg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ttm->page_flags |= TTM_PAGE_FLAG_SG;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-11 06:33:13 +08:00
|
|
|
if (slave && ttm->sg) {
|
2020-10-08 18:57:32 +08:00
|
|
|
drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
|
|
|
|
ttm->num_pages);
|
2012-05-11 06:33:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-24 19:12:23 +08:00
|
|
|
return ttm_pool_alloc(&rdev->mman.bdev.pool, ttm, ctx);
|
2011-10-18 05:15:08 +08:00
|
|
|
}
|
|
|
|
|
2020-08-25 07:46:00 +08:00
|
|
|
static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
|
2011-10-18 05:15:08 +08:00
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
|
|
|
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
|
2012-05-11 06:33:13 +08:00
|
|
|
bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
|
|
|
|
|
2014-09-17 18:00:05 +08:00
|
|
|
if (gtt && gtt->userptr) {
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
kfree(ttm->sg);
|
|
|
|
ttm->page_flags &= ~TTM_PAGE_FLAG_SG;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-11 06:33:13 +08:00
|
|
|
if (slave)
|
|
|
|
return;
|
2011-10-18 05:15:08 +08:00
|
|
|
|
2020-10-24 19:12:23 +08:00
|
|
|
return ttm_pool_free(&rdev->mman.bdev.pool, ttm);
|
2011-10-18 05:15:08 +08:00
|
|
|
}
|
2011-11-02 08:46:13 +08:00
|
|
|
|
2020-09-08 04:46:22 +08:00
|
|
|
int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
|
|
|
|
struct ttm_tt *ttm, uint64_t addr,
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
uint32_t flags)
|
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
if (gtt == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
gtt->userptr = addr;
|
|
|
|
gtt->usermm = current->mm;
|
|
|
|
gtt->userflags = flags;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:54:24 +08:00
|
|
|
bool radeon_ttm_tt_is_bound(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
|
|
|
if (rdev->flags & RADEON_IS_AGP)
|
|
|
|
return ttm_agp_is_bound(ttm);
|
|
|
|
#endif
|
|
|
|
return radeon_ttm_backend_is_bound(ttm);
|
|
|
|
}
|
|
|
|
|
2020-09-08 04:46:22 +08:00
|
|
|
static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm,
|
|
|
|
struct ttm_resource *bo_mem)
|
|
|
|
{
|
2020-09-17 10:54:24 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
2020-09-17 10:54:24 +08:00
|
|
|
#endif
|
2020-09-08 04:46:22 +08:00
|
|
|
|
2020-09-17 10:54:24 +08:00
|
|
|
if (!bo_mem)
|
|
|
|
return -EINVAL;
|
2020-09-08 04:46:22 +08:00
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
|
|
|
if (rdev->flags & RADEON_IS_AGP)
|
2020-09-08 04:46:29 +08:00
|
|
|
return ttm_agp_bind(ttm, bo_mem);
|
2020-09-08 04:46:22 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return radeon_ttm_backend_bind(bdev, ttm, bo_mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
|
|
|
|
|
|
|
if (rdev->flags & RADEON_IS_AGP) {
|
2020-09-08 04:46:29 +08:00
|
|
|
ttm_agp_unbind(ttm);
|
2020-09-08 04:46:22 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
radeon_ttm_backend_unbind(bdev, ttm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void radeon_ttm_tt_destroy(struct ttm_bo_device *bdev,
|
|
|
|
struct ttm_tt *ttm)
|
|
|
|
{
|
|
|
|
#if IS_ENABLED(CONFIG_AGP)
|
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bdev);
|
|
|
|
|
|
|
|
if (rdev->flags & RADEON_IS_AGP) {
|
2020-09-17 11:24:50 +08:00
|
|
|
ttm_agp_unbind(ttm);
|
2020-09-17 11:20:48 +08:00
|
|
|
ttm_tt_destroy_common(bdev, ttm);
|
2020-09-08 04:46:29 +08:00
|
|
|
ttm_agp_destroy(ttm);
|
2020-09-08 04:46:22 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
radeon_ttm_backend_destroy(bdev, ttm);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev,
|
|
|
|
struct ttm_tt *ttm)
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
if (gtt == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !!gtt->userptr;
|
|
|
|
}
|
|
|
|
|
2020-09-08 04:46:22 +08:00
|
|
|
bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev,
|
|
|
|
struct ttm_tt *ttm)
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
{
|
2020-09-08 04:46:22 +08:00
|
|
|
struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
|
drm/radeon: add userptr support v8
This patch adds an IOCTL for turning a pointer supplied by
userspace into a buffer object.
It imposes several restrictions upon the memory being mapped:
1. It must be page aligned (both start/end addresses, i.e ptr and size).
2. It must be normal system memory, not a pointer into another map of IO
space (e.g. it must not be a GTT mmapping of another object).
3. The BO is mapped into GTT, so the maximum amount of memory mapped at
all times is still the GTT limit.
4. The BO is only mapped readonly for now, so no write support.
5. List of backing pages is only acquired once, so they represent a
snapshot of the first use.
Exporting and sharing as well as mapping of buffer objects created by
this function is forbidden and results in an -EPERM.
v2: squash all previous changes into first public version
v3: fix tabs, map readonly, don't use MM callback any more
v4: set TTM_PAGE_FLAG_SG so that TTM never messes with the pages,
pin/unpin pages on bind/unbind instead of populate/unpopulate
v5: rebased on 3.17-wip, IOCTL renamed to userptr, reject any unknown
flags, better handle READONLY flag, improve permission check
v6: fix ptr cast warning, use set_page_dirty/mark_page_accessed on unpin
v7: add warning about it's availability in the API definition
v8: drop access_ok check, fix VM mapping bits
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> (v4)
Reviewed-by: Jérôme Glisse <jglisse@redhat.com> (v4)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2014-08-07 15:36:00 +08:00
|
|
|
|
|
|
|
if (gtt == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !!(gtt->userflags & RADEON_GEM_USERPTR_READONLY);
|
|
|
|
}
|
|
|
|
|
2020-10-21 12:40:29 +08:00
|
|
|
static void
|
|
|
|
radeon_bo_delete_mem_notify(struct ttm_buffer_object *bo)
|
|
|
|
{
|
|
|
|
radeon_bo_move_notify(bo, false, NULL);
|
|
|
|
}
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
static struct ttm_bo_driver radeon_bo_driver = {
|
2011-11-02 08:46:13 +08:00
|
|
|
.ttm_tt_create = &radeon_ttm_tt_create,
|
2011-10-18 05:15:08 +08:00
|
|
|
.ttm_tt_populate = &radeon_ttm_tt_populate,
|
|
|
|
.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
|
2020-09-08 04:46:22 +08:00
|
|
|
.ttm_tt_destroy = &radeon_ttm_tt_destroy,
|
2016-08-30 23:26:04 +08:00
|
|
|
.eviction_valuable = ttm_bo_eviction_valuable,
|
2009-06-05 20:42:42 +08:00
|
|
|
.evict_flags = &radeon_evict_flags,
|
|
|
|
.move = &radeon_bo_move,
|
|
|
|
.verify_access = &radeon_verify_access,
|
2020-10-21 12:40:29 +08:00
|
|
|
.delete_mem_notify = &radeon_bo_delete_mem_notify,
|
2010-04-09 20:39:24 +08:00
|
|
|
.io_mem_reserve = &radeon_ttm_io_mem_reserve,
|
2009-06-05 20:42:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int radeon_ttm_init(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* No others user of address space so set it to 0 */
|
2020-10-24 19:10:28 +08:00
|
|
|
r = ttm_bo_device_init(&rdev->mman.bdev, &radeon_bo_driver, rdev->dev,
|
2013-08-14 01:10:30 +08:00
|
|
|
rdev->ddev->anon_inode->i_mapping,
|
2019-09-05 15:05:05 +08:00
|
|
|
rdev->ddev->vma_offset_manager,
|
2020-10-24 19:10:28 +08:00
|
|
|
rdev->need_swiotlb,
|
2019-08-15 15:27:00 +08:00
|
|
|
dma_addressing_limited(&rdev->pdev->dev));
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("failed initializing buffer object driver(%d).\n", r);
|
|
|
|
return r;
|
|
|
|
}
|
2009-12-12 03:36:19 +08:00
|
|
|
rdev->mman.initialized = true;
|
2020-07-23 17:47:57 +08:00
|
|
|
|
|
|
|
r = radeon_ttm_init_vram(rdev);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed initializing VRAM heap.\n");
|
|
|
|
return r;
|
|
|
|
}
|
2014-03-01 02:50:23 +08:00
|
|
|
/* Change the size here instead of the init above so only lpfn is affected */
|
|
|
|
radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
|
|
|
|
|
2011-02-19 00:59:16 +08:00
|
|
|
r = radeon_bo_create(rdev, 256 * 1024, PAGE_SIZE, true,
|
2014-09-18 20:11:56 +08:00
|
|
|
RADEON_GEM_DOMAIN_VRAM, 0, NULL,
|
2017-08-08 19:48:52 +08:00
|
|
|
NULL, &rdev->stolen_vga_memory);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
2017-08-08 19:48:52 +08:00
|
|
|
r = radeon_bo_reserve(rdev->stolen_vga_memory, false);
|
2009-11-20 21:29:23 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
2017-08-08 19:48:52 +08:00
|
|
|
r = radeon_bo_pin(rdev->stolen_vga_memory, RADEON_GEM_DOMAIN_VRAM, NULL);
|
|
|
|
radeon_bo_unreserve(rdev->stolen_vga_memory);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
2017-08-08 19:48:52 +08:00
|
|
|
radeon_bo_unref(&rdev->stolen_vga_memory);
|
2009-06-05 20:42:42 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
DRM_INFO("radeon: %uM of VRAM memory ready\n",
|
2013-05-19 03:19:23 +08:00
|
|
|
(unsigned) (rdev->mc.real_vram_size / (1024 * 1024)));
|
2020-07-23 17:47:57 +08:00
|
|
|
|
|
|
|
r = radeon_ttm_init_gtt(rdev);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed initializing GTT heap.\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
DRM_INFO("radeon: %uM of GTT memory ready.\n",
|
2009-09-08 08:10:24 +08:00
|
|
|
(unsigned)(rdev->mc.gtt_size / (1024 * 1024)));
|
2009-08-26 11:13:37 +08:00
|
|
|
|
|
|
|
r = radeon_ttm_debugfs_init(rdev);
|
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to init debugfs\n");
|
|
|
|
return r;
|
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void radeon_ttm_fini(struct radeon_device *rdev)
|
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
int r;
|
|
|
|
|
2009-12-12 03:36:19 +08:00
|
|
|
if (!rdev->mman.initialized)
|
|
|
|
return;
|
2021-02-10 23:19:20 +08:00
|
|
|
|
2017-08-08 19:48:52 +08:00
|
|
|
if (rdev->stolen_vga_memory) {
|
|
|
|
r = radeon_bo_reserve(rdev->stolen_vga_memory, false);
|
2009-11-20 21:29:23 +08:00
|
|
|
if (r == 0) {
|
2017-08-08 19:48:52 +08:00
|
|
|
radeon_bo_unpin(rdev->stolen_vga_memory);
|
|
|
|
radeon_bo_unreserve(rdev->stolen_vga_memory);
|
2009-11-20 21:29:23 +08:00
|
|
|
}
|
2017-08-08 19:48:52 +08:00
|
|
|
radeon_bo_unref(&rdev->stolen_vga_memory);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2020-08-04 10:56:19 +08:00
|
|
|
ttm_range_man_fini(&rdev->mman.bdev, TTM_PL_VRAM);
|
|
|
|
ttm_range_man_fini(&rdev->mman.bdev, TTM_PL_TT);
|
2009-06-05 20:42:42 +08:00
|
|
|
ttm_bo_device_release(&rdev->mman.bdev);
|
|
|
|
radeon_gart_fini(rdev);
|
2009-12-12 03:36:19 +08:00
|
|
|
rdev->mman.initialized = false;
|
2009-06-05 20:42:42 +08:00
|
|
|
DRM_INFO("radeon: ttm finalized\n");
|
|
|
|
}
|
|
|
|
|
2011-03-14 07:47:24 +08:00
|
|
|
/* this should only be called at bootup or when userspace
|
|
|
|
* isn't running */
|
|
|
|
void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
|
|
|
|
{
|
2020-08-04 10:56:31 +08:00
|
|
|
struct ttm_resource_manager *man;
|
2011-03-14 07:47:24 +08:00
|
|
|
|
|
|
|
if (!rdev->mman.initialized)
|
|
|
|
return;
|
|
|
|
|
2020-08-04 10:56:14 +08:00
|
|
|
man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
|
2011-03-14 07:47:24 +08:00
|
|
|
/* this just adjusts TTM size idea, which sets lpfn to the correct value */
|
|
|
|
man->size = size >> PAGE_SHIFT;
|
|
|
|
}
|
|
|
|
|
2018-04-16 21:43:51 +08:00
|
|
|
static vm_fault_t radeon_ttm_fault(struct vm_fault *vmf)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2020-09-25 20:17:09 +08:00
|
|
|
struct ttm_buffer_object *bo = vmf->vma->vm_private_data;
|
|
|
|
struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
|
2018-04-16 21:43:51 +08:00
|
|
|
vm_fault_t ret;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2012-05-11 20:57:18 +08:00
|
|
|
down_read(&rdev->pm.mclk_lock);
|
2020-09-25 20:17:09 +08:00
|
|
|
|
|
|
|
ret = ttm_bo_vm_reserve(bo, vmf);
|
|
|
|
if (ret)
|
|
|
|
goto unlock_mclk;
|
|
|
|
|
|
|
|
ret = radeon_bo_fault_reserve_notify(bo);
|
|
|
|
if (ret)
|
|
|
|
goto unlock_resv;
|
|
|
|
|
|
|
|
ret = ttm_bo_vm_fault_reserved(vmf, vmf->vma->vm_page_prot,
|
|
|
|
TTM_BO_VM_NUM_PREFAULT, 1);
|
|
|
|
if (ret == VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT))
|
|
|
|
goto unlock_mclk;
|
|
|
|
|
|
|
|
unlock_resv:
|
|
|
|
dma_resv_unlock(bo->base.resv);
|
|
|
|
|
|
|
|
unlock_mclk:
|
2012-05-11 20:57:18 +08:00
|
|
|
up_read(&rdev->pm.mclk_lock);
|
2018-04-16 21:43:51 +08:00
|
|
|
return ret;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 20:34:25 +08:00
|
|
|
static struct vm_operations_struct radeon_ttm_vm_ops = {
|
|
|
|
.fault = radeon_ttm_fault,
|
|
|
|
.open = ttm_bo_vm_open,
|
|
|
|
.close = ttm_bo_vm_close,
|
|
|
|
.access = ttm_bo_vm_access
|
|
|
|
};
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
int r;
|
2019-02-07 16:59:30 +08:00
|
|
|
struct drm_file *file_priv = filp->private_data;
|
|
|
|
struct radeon_device *rdev = file_priv->minor->dev->dev_private;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2019-09-27 20:34:25 +08:00
|
|
|
if (rdev == NULL)
|
2009-06-05 20:42:42 +08:00
|
|
|
return -EINVAL;
|
2019-09-27 20:34:25 +08:00
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
r = ttm_bo_mmap(filp, vma, &rdev->mman.bdev);
|
2019-09-27 20:34:25 +08:00
|
|
|
if (unlikely(r != 0))
|
2009-06-05 20:42:42 +08:00
|
|
|
return r;
|
2019-09-27 20:34:25 +08:00
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
vma->vm_ops = &radeon_ttm_vm_ops;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-26 11:13:37 +08:00
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
2013-12-12 16:42:40 +08:00
|
|
|
|
2009-08-26 11:13:37 +08:00
|
|
|
static int radeon_mm_dump_table(struct seq_file *m, void *data)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *)m->private;
|
2017-08-07 20:03:54 +08:00
|
|
|
unsigned ttm_pl = *(int*)node->info_ent->data;
|
2009-08-26 11:13:37 +08:00
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
2020-08-04 10:56:31 +08:00
|
|
|
struct ttm_resource_manager *man = ttm_manager_type(&rdev->mman.bdev, ttm_pl);
|
2016-12-29 19:09:24 +08:00
|
|
|
struct drm_printer p = drm_seq_file_printer(m);
|
2009-08-26 11:13:37 +08:00
|
|
|
|
2017-08-07 20:03:54 +08:00
|
|
|
man->func->debug(man, &p);
|
2016-12-29 19:09:24 +08:00
|
|
|
return 0;
|
2009-08-26 11:13:37 +08:00
|
|
|
}
|
2013-12-12 16:42:40 +08:00
|
|
|
|
2020-10-24 19:12:23 +08:00
|
|
|
static int radeon_ttm_pool_debugfs(struct seq_file *m, void *data)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *)m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
|
|
|
struct radeon_device *rdev = dev->dev_private;
|
|
|
|
|
|
|
|
return ttm_pool_debugfs(&rdev->mman.bdev.pool, m);
|
|
|
|
}
|
2017-08-07 20:03:54 +08:00
|
|
|
|
2013-12-12 16:42:40 +08:00
|
|
|
static int ttm_pl_vram = TTM_PL_VRAM;
|
|
|
|
static int ttm_pl_tt = TTM_PL_TT;
|
|
|
|
|
|
|
|
static struct drm_info_list radeon_ttm_debugfs_list[] = {
|
|
|
|
{"radeon_vram_mm", radeon_mm_dump_table, 0, &ttm_pl_vram},
|
|
|
|
{"radeon_gtt_mm", radeon_mm_dump_table, 0, &ttm_pl_tt},
|
2020-10-24 19:12:23 +08:00
|
|
|
{"ttm_page_pool", radeon_ttm_pool_debugfs, 0, NULL}
|
2013-12-12 16:42:40 +08:00
|
|
|
};
|
|
|
|
|
2013-12-19 04:07:39 +08:00
|
|
|
static int radeon_ttm_vram_open(struct inode *inode, struct file *filep)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = inode->i_private;
|
|
|
|
i_size_write(inode, rdev->mc.mc_vram_size);
|
|
|
|
filep->private_data = inode->i_private;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t radeon_ttm_vram_read(struct file *f, char __user *buf,
|
|
|
|
size_t size, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = f->private_data;
|
|
|
|
ssize_t result = 0;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (size & 0x3 || *pos & 0x3)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
while (size) {
|
|
|
|
unsigned long flags;
|
|
|
|
uint32_t value;
|
|
|
|
|
|
|
|
if (*pos >= rdev->mc.mc_vram_size)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rdev->mmio_idx_lock, flags);
|
|
|
|
WREG32(RADEON_MM_INDEX, ((uint32_t)*pos) | 0x80000000);
|
|
|
|
if (rdev->family >= CHIP_CEDAR)
|
|
|
|
WREG32(EVERGREEN_MM_INDEX_HI, *pos >> 31);
|
|
|
|
value = RREG32(RADEON_MM_DATA);
|
|
|
|
spin_unlock_irqrestore(&rdev->mmio_idx_lock, flags);
|
|
|
|
|
|
|
|
r = put_user(value, (uint32_t *)buf);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
result += 4;
|
|
|
|
buf += 4;
|
|
|
|
*pos += 4;
|
|
|
|
size -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations radeon_ttm_vram_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = radeon_ttm_vram_open,
|
|
|
|
.read = radeon_ttm_vram_read,
|
|
|
|
.llseek = default_llseek
|
|
|
|
};
|
|
|
|
|
2013-12-19 04:07:40 +08:00
|
|
|
static int radeon_ttm_gtt_open(struct inode *inode, struct file *filep)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = inode->i_private;
|
|
|
|
i_size_write(inode, rdev->mc.gtt_size);
|
|
|
|
filep->private_data = inode->i_private;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t radeon_ttm_gtt_read(struct file *f, char __user *buf,
|
|
|
|
size_t size, loff_t *pos)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = f->private_data;
|
|
|
|
ssize_t result = 0;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
while (size) {
|
|
|
|
loff_t p = *pos / PAGE_SIZE;
|
|
|
|
unsigned off = *pos & ~PAGE_MASK;
|
2014-03-04 17:34:48 +08:00
|
|
|
size_t cur_size = min_t(size_t, size, PAGE_SIZE - off);
|
2013-12-19 04:07:40 +08:00
|
|
|
struct page *page;
|
|
|
|
void *ptr;
|
|
|
|
|
|
|
|
if (p >= rdev->gart.num_cpu_pages)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
page = rdev->gart.pages[p];
|
|
|
|
if (page) {
|
|
|
|
ptr = kmap(page);
|
|
|
|
ptr += off;
|
|
|
|
|
|
|
|
r = copy_to_user(buf, ptr, cur_size);
|
|
|
|
kunmap(rdev->gart.pages[p]);
|
|
|
|
} else
|
|
|
|
r = clear_user(buf, cur_size);
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
result += cur_size;
|
|
|
|
buf += cur_size;
|
|
|
|
*pos += cur_size;
|
|
|
|
size -= cur_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct file_operations radeon_ttm_gtt_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = radeon_ttm_gtt_open,
|
|
|
|
.read = radeon_ttm_gtt_read,
|
|
|
|
.llseek = default_llseek
|
|
|
|
};
|
|
|
|
|
2009-08-26 11:13:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
|
|
|
|
{
|
2009-09-29 00:27:23 +08:00
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
2013-12-19 04:07:39 +08:00
|
|
|
unsigned count;
|
|
|
|
|
|
|
|
struct drm_minor *minor = rdev->ddev->primary;
|
2019-06-13 19:56:31 +08:00
|
|
|
struct dentry *root = minor->debugfs_root;
|
|
|
|
|
2021-02-10 23:19:20 +08:00
|
|
|
debugfs_create_file("radeon_vram", S_IFREG | S_IRUGO, root, rdev,
|
|
|
|
&radeon_ttm_vram_fops);
|
2019-06-13 19:56:31 +08:00
|
|
|
|
2021-02-10 23:19:20 +08:00
|
|
|
debugfs_create_file("radeon_gtt", S_IFREG | S_IRUGO, root, rdev,
|
|
|
|
&radeon_ttm_gtt_fops);
|
2013-12-19 04:07:40 +08:00
|
|
|
|
2013-12-19 04:07:39 +08:00
|
|
|
count = ARRAY_SIZE(radeon_ttm_debugfs_list);
|
2009-08-26 11:13:37 +08:00
|
|
|
|
2013-12-12 16:42:40 +08:00
|
|
|
return radeon_debugfs_add_files(rdev, radeon_ttm_debugfs_list, count);
|
|
|
|
#else
|
|
|
|
|
2009-08-26 11:13:37 +08:00
|
|
|
return 0;
|
2013-12-12 16:42:40 +08:00
|
|
|
#endif
|
2009-08-26 11:13:37 +08:00
|
|
|
}
|