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
|
|
|
|
*/
|
|
|
|
#include <linux/list.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-06-05 20:42:42 +08:00
|
|
|
#include <drm/drmP.h>
|
2012-10-03 01:01:07 +08:00
|
|
|
#include <drm/radeon_drm.h>
|
2009-06-05 20:42:42 +08:00
|
|
|
#include "radeon.h"
|
2010-11-23 09:47:49 +08:00
|
|
|
#include "radeon_trace.h"
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
int radeon_ttm_init(struct radeon_device *rdev);
|
|
|
|
void radeon_ttm_fini(struct radeon_device *rdev);
|
2009-11-20 21:29:23 +08:00
|
|
|
static void radeon_bo_clear_surface_reg(struct radeon_bo *bo);
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To exclude mutual BO access we rely on bo_reserve exclusion, as all
|
|
|
|
* function are calling it.
|
|
|
|
*/
|
|
|
|
|
2014-03-02 07:56:18 +08:00
|
|
|
static void radeon_update_memory_usage(struct radeon_bo *bo,
|
|
|
|
unsigned mem_type, int sign)
|
|
|
|
{
|
|
|
|
struct radeon_device *rdev = bo->rdev;
|
|
|
|
u64 size = (u64)bo->tbo.num_pages << PAGE_SHIFT;
|
|
|
|
|
|
|
|
switch (mem_type) {
|
|
|
|
case TTM_PL_TT:
|
|
|
|
if (sign > 0)
|
|
|
|
atomic64_add(size, &rdev->gtt_usage);
|
|
|
|
else
|
|
|
|
atomic64_sub(size, &rdev->gtt_usage);
|
|
|
|
break;
|
|
|
|
case TTM_PL_VRAM:
|
|
|
|
if (sign > 0)
|
|
|
|
atomic64_add(size, &rdev->vram_usage);
|
|
|
|
else
|
|
|
|
atomic64_sub(size, &rdev->vram_usage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
static void radeon_ttm_bo_destroy(struct ttm_buffer_object *tbo)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_bo *bo;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
bo = container_of(tbo, struct radeon_bo, tbo);
|
2014-03-02 07:56:18 +08:00
|
|
|
|
|
|
|
radeon_update_memory_usage(bo, bo->tbo.mem.mem_type, -1);
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
mutex_lock(&bo->rdev->gem.mutex);
|
|
|
|
list_del_init(&bo->list);
|
|
|
|
mutex_unlock(&bo->rdev->gem.mutex);
|
|
|
|
radeon_bo_clear_surface_reg(bo);
|
2014-07-18 15:24:54 +08:00
|
|
|
WARN_ON(!list_empty(&bo->va));
|
2011-02-19 00:59:16 +08:00
|
|
|
drm_gem_object_release(&bo->gem_base);
|
2009-11-20 21:29:23 +08:00
|
|
|
kfree(bo);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2009-12-15 04:02:09 +08:00
|
|
|
bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo)
|
|
|
|
{
|
|
|
|
if (bo->destroy == &radeon_ttm_bo_destroy)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-07 22:52:58 +08:00
|
|
|
void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
|
|
|
|
{
|
2014-04-03 01:33:42 +08:00
|
|
|
u32 c = 0, i;
|
2009-12-07 22:52:58 +08:00
|
|
|
|
|
|
|
rbo->placement.placement = rbo->placements;
|
2013-01-18 02:10:50 +08:00
|
|
|
rbo->placement.busy_placement = rbo->placements;
|
2014-10-10 11:28:36 +08:00
|
|
|
if (domain & RADEON_GEM_DOMAIN_VRAM) {
|
|
|
|
/* Try placing BOs which don't need CPU access outside of the
|
|
|
|
* CPU accessible part of VRAM
|
|
|
|
*/
|
|
|
|
if ((rbo->flags & RADEON_GEM_NO_CPU_ACCESS) &&
|
|
|
|
rbo->rdev->mc.visible_vram_size < rbo->rdev->mc.real_vram_size) {
|
|
|
|
rbo->placements[c].fpfn =
|
|
|
|
rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
|
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
|
|
|
|
TTM_PL_FLAG_UNCACHED |
|
|
|
|
TTM_PL_FLAG_VRAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
|
|
|
|
TTM_PL_FLAG_UNCACHED |
|
|
|
|
TTM_PL_FLAG_VRAM;
|
2014-10-10 11:28:36 +08:00
|
|
|
}
|
2014-08-27 19:16:04 +08:00
|
|
|
|
2012-11-29 02:47:55 +08:00
|
|
|
if (domain & RADEON_GEM_DOMAIN_GTT) {
|
2014-07-17 18:01:08 +08:00
|
|
|
if (rbo->flags & RADEON_GEM_GTT_UC) {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
|
|
|
|
TTM_PL_FLAG_TT;
|
|
|
|
|
2014-07-17 18:01:08 +08:00
|
|
|
} else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
|
|
|
|
(rbo->rdev->flags & RADEON_IS_AGP)) {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
|
|
|
|
TTM_PL_FLAG_UNCACHED |
|
2014-07-17 18:01:08 +08:00
|
|
|
TTM_PL_FLAG_TT;
|
2012-11-29 02:47:55 +08:00
|
|
|
} else {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
|
|
|
|
TTM_PL_FLAG_TT;
|
2012-11-29 02:47:55 +08:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 19:16:04 +08:00
|
|
|
|
2012-11-29 02:47:55 +08:00
|
|
|
if (domain & RADEON_GEM_DOMAIN_CPU) {
|
2014-07-17 18:01:08 +08:00
|
|
|
if (rbo->flags & RADEON_GEM_GTT_UC) {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
|
|
|
|
TTM_PL_FLAG_SYSTEM;
|
|
|
|
|
2014-07-17 18:01:08 +08:00
|
|
|
} else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
|
|
|
|
rbo->rdev->flags & RADEON_IS_AGP) {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
|
|
|
|
TTM_PL_FLAG_UNCACHED |
|
2014-07-17 18:01:08 +08:00
|
|
|
TTM_PL_FLAG_SYSTEM;
|
2012-11-29 02:47:55 +08:00
|
|
|
} else {
|
2014-10-10 11:28:36 +08:00
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
|
|
|
|
TTM_PL_FLAG_SYSTEM;
|
2012-11-29 02:47:55 +08:00
|
|
|
}
|
|
|
|
}
|
2014-10-10 11:28:36 +08:00
|
|
|
if (!c) {
|
|
|
|
rbo->placements[c].fpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
rbo->placements[c++].flags = TTM_PL_MASK_CACHING |
|
|
|
|
TTM_PL_FLAG_SYSTEM;
|
2014-10-10 11:28:36 +08:00
|
|
|
}
|
2014-08-27 19:16:04 +08:00
|
|
|
|
2009-12-07 22:52:58 +08:00
|
|
|
rbo->placement.num_placement = c;
|
|
|
|
rbo->placement.num_busy_placement = c;
|
2014-04-03 01:33:42 +08:00
|
|
|
|
2014-08-27 19:16:04 +08:00
|
|
|
for (i = 0; i < c; ++i) {
|
2014-08-28 14:56:00 +08:00
|
|
|
if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
|
2014-10-10 11:28:36 +08:00
|
|
|
(rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
|
|
|
|
!rbo->placements[i].fpfn)
|
2014-08-28 14:56:00 +08:00
|
|
|
rbo->placements[i].lpfn =
|
|
|
|
rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
|
|
|
|
else
|
|
|
|
rbo->placements[i].lpfn = 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
}
|
2009-12-07 22:52:58 +08:00
|
|
|
}
|
|
|
|
|
2011-02-19 00:59:16 +08:00
|
|
|
int radeon_bo_create(struct radeon_device *rdev,
|
2014-09-18 20:11:56 +08:00
|
|
|
unsigned long size, int byte_align, bool kernel,
|
|
|
|
u32 domain, u32 flags, struct sg_table *sg,
|
|
|
|
struct reservation_object *resv,
|
|
|
|
struct radeon_bo **bo_ptr)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_bo *bo;
|
2009-06-05 20:42:42 +08:00
|
|
|
enum ttm_bo_type type;
|
2010-12-04 05:38:19 +08:00
|
|
|
unsigned long page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
|
2011-11-12 04:42:57 +08:00
|
|
|
size_t acc_size;
|
2009-06-05 20:42:42 +08:00
|
|
|
int r;
|
|
|
|
|
2011-02-19 00:59:16 +08:00
|
|
|
size = ALIGN(size, PAGE_SIZE);
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
if (kernel) {
|
|
|
|
type = ttm_bo_type_kernel;
|
2012-05-11 06:33:13 +08:00
|
|
|
} else if (sg) {
|
|
|
|
type = ttm_bo_type_sg;
|
2009-06-05 20:42:42 +08:00
|
|
|
} else {
|
|
|
|
type = ttm_bo_type_device;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
*bo_ptr = NULL;
|
2010-11-09 18:50:05 +08:00
|
|
|
|
2011-11-12 04:42:57 +08:00
|
|
|
acc_size = ttm_bo_dma_acc_size(&rdev->mman.bdev, size,
|
|
|
|
sizeof(struct radeon_bo));
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
bo = kzalloc(sizeof(struct radeon_bo), GFP_KERNEL);
|
|
|
|
if (bo == NULL)
|
2009-06-05 20:42:42 +08:00
|
|
|
return -ENOMEM;
|
2011-02-19 00:59:16 +08:00
|
|
|
r = drm_gem_object_init(rdev->ddev, &bo->gem_base, size);
|
|
|
|
if (unlikely(r)) {
|
|
|
|
kfree(bo);
|
|
|
|
return r;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->rdev = rdev;
|
|
|
|
bo->surface_reg = -1;
|
|
|
|
INIT_LIST_HEAD(&bo->list);
|
drm/radeon: GPU virtual memory support v22
Virtual address space are per drm client (opener of /dev/drm).
Client are in charge of virtual address space, they need to
map bo into it by calling DRM_RADEON_GEM_VA ioctl.
First 16M of virtual address space is reserved by the kernel.
Once using 2 level page table we should be able to have a small
vram memory footprint for each pt (there would be one pt for all
gart, one for all vram and then one first level for each virtual
address space).
Plan include using the sub allocator for a common vm page table
area and using memcpy to copy vm page table in & out. Or use
a gart object and copy things in & out using dma.
v2: agd5f fixes:
- Add vram base offset for vram pages. The GPU physical address of a
vram page is FB_OFFSET + page offset. FB_OFFSET is 0 on discrete
cards and the physical bus address of the stolen memory on
integrated chips.
- VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR covers all vmid's >= 1
v3: agd5f:
- integrate with the semaphore/multi-ring stuff
v4:
- rebase on top ttm dma & multi-ring stuff
- userspace is now in charge of the address space
- no more specific cs vm ioctl, instead cs ioctl has a new
chunk
v5:
- properly handle mem == NULL case from move_notify callback
- fix the vm cleanup path
v6:
- fix update of page table to only happen on valid mem placement
v7:
- add tlb flush for each vm context
- add flags to define mapping property (readable, writeable, snooped)
- make ring id implicit from ib->fence->ring, up to each asic callback
to then do ring specific scheduling if vm ib scheduling function
v8:
- add query for ib limit and kernel reserved virtual space
- rename vm->size to max_pfn (maximum number of page)
- update gem_va ioctl to also allow unmap operation
- bump kernel version to allow userspace to query for vm support
v9:
- rebuild page table only when bind and incrementaly depending
on bo referenced by cs and that have been moved
- allow virtual address space to grow
- use sa allocator for vram page table
- return invalid when querying vm limit on non cayman GPU
- dump vm fault register on lockup
v10: agd5f:
- Move the vm schedule_ib callback to a standalone function, remove
the callback and use the existing ib_execute callback for VM IBs.
v11:
- rebase on top of lastest Linus
v12: agd5f:
- remove spurious backslash
- set IB vm_id to 0 in radeon_ib_get()
v13: agd5f:
- fix handling of RADEON_CHUNK_ID_FLAGS
v14:
- fix va destruction
- fix suspend resume
- forbid bo to have several different va in same vm
v15:
- rebase
v16:
- cleanup left over of vm init/fini
v17: agd5f:
- cs checker
v18: agd5f:
- reworks the CS ioctl to better support multiple rings and
VM. Rather than adding a new chunk id for VM, just re-use the
IB chunk id and add a new flags for VM mode. Also define additional
dwords for the flags chunk id to define the what ring we want to use
(gfx, compute, uvd, etc.) and the priority.
v19:
- fix cs fini in weird case of no ib
- semi working flush fix for ni
- rebase on top of sa allocator changes
v20: agd5f:
- further CS ioctl cleanups from Christian's comments
v21: agd5f:
- integrate CS checker improvements
v22: agd5f:
- final cleanups for release, only allow VM CS on cayman
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-01-06 11:11:05 +08:00
|
|
|
INIT_LIST_HEAD(&bo->va);
|
2014-03-02 07:56:17 +08:00
|
|
|
bo->initial_domain = domain & (RADEON_GEM_DOMAIN_VRAM |
|
|
|
|
RADEON_GEM_DOMAIN_GTT |
|
|
|
|
RADEON_GEM_DOMAIN_CPU);
|
2014-07-17 18:01:08 +08:00
|
|
|
|
|
|
|
bo->flags = flags;
|
|
|
|
/* PCI GART is always snooped */
|
|
|
|
if (!(rdev->flags & RADEON_IS_PCIE))
|
|
|
|
bo->flags &= ~(RADEON_GEM_GTT_WC | RADEON_GEM_GTT_UC);
|
|
|
|
|
2014-11-27 17:00:54 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
/* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
|
|
|
|
* See https://bugs.freedesktop.org/show_bug.cgi?id=84627
|
|
|
|
*/
|
|
|
|
bo->flags &= ~RADEON_GEM_GTT_WC;
|
2015-02-04 09:19:51 +08:00
|
|
|
#elif defined(CONFIG_X86) && !defined(CONFIG_X86_PAT)
|
|
|
|
/* Don't try to enable write-combining when it can't work, or things
|
|
|
|
* may be slow
|
|
|
|
* See https://bugs.freedesktop.org/show_bug.cgi?id=88758
|
|
|
|
*/
|
|
|
|
|
|
|
|
#warning Please enable CONFIG_MTRR and CONFIG_X86_PAT for better performance \
|
|
|
|
thanks to write-combining
|
|
|
|
|
|
|
|
DRM_INFO_ONCE("Please enable CONFIG_MTRR and CONFIG_X86_PAT for "
|
|
|
|
"better performance thanks to write-combining\n");
|
|
|
|
bo->flags &= ~RADEON_GEM_GTT_WC;
|
2014-11-27 17:00:54 +08:00
|
|
|
#endif
|
|
|
|
|
2009-12-11 00:16:28 +08:00
|
|
|
radeon_ttm_placement_from_domain(bo, domain);
|
2009-12-08 01:36:19 +08:00
|
|
|
/* Kernel allocation are uninterruptible */
|
2012-05-11 20:57:18 +08:00
|
|
|
down_read(&rdev->pm.mclk_lock);
|
2009-12-11 00:16:28 +08:00
|
|
|
r = ttm_bo_init(&rdev->mman.bdev, &bo->tbo, size, type,
|
2012-11-07 05:49:51 +08:00
|
|
|
&bo->placement, page_align, !kernel, NULL,
|
2014-09-18 20:11:56 +08:00
|
|
|
acc_size, sg, resv, &radeon_ttm_bo_destroy);
|
2012-05-11 20:57:18 +08:00
|
|
|
up_read(&rdev->pm.mclk_lock);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (unlikely(r != 0)) {
|
|
|
|
return r;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
*bo_ptr = bo;
|
2011-02-19 00:59:16 +08:00
|
|
|
|
2010-11-23 09:47:49 +08:00
|
|
|
trace_radeon_bo_create(bo);
|
2011-02-19 00:59:16 +08:00
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_kmap(struct radeon_bo *bo, void **ptr)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
bool is_iomem;
|
2009-06-05 20:42:42 +08:00
|
|
|
int r;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->kptr) {
|
2009-06-05 20:42:42 +08:00
|
|
|
if (ptr) {
|
2009-11-20 21:29:23 +08:00
|
|
|
*ptr = bo->kptr;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
r = ttm_bo_kmap(&bo->tbo, 0, bo->tbo.num_pages, &bo->kmap);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->kptr = ttm_kmap_obj_virtual(&bo->kmap, &is_iomem);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (ptr) {
|
2009-11-20 21:29:23 +08:00
|
|
|
*ptr = bo->kptr;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
radeon_bo_check_tiling(bo, 0, 0);
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
void radeon_bo_kunmap(struct radeon_bo *bo)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->kptr == NULL)
|
2009-06-05 20:42:42 +08:00
|
|
|
return;
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->kptr = NULL;
|
|
|
|
radeon_bo_check_tiling(bo, 0, 0);
|
|
|
|
ttm_bo_kunmap(&bo->kmap);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2014-07-31 03:04:56 +08:00
|
|
|
struct radeon_bo *radeon_bo_ref(struct radeon_bo *bo)
|
|
|
|
{
|
|
|
|
if (bo == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ttm_bo_reference(&bo->tbo);
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
void radeon_bo_unref(struct radeon_bo **bo)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct ttm_buffer_object *tbo;
|
2010-04-29 16:37:59 +08:00
|
|
|
struct radeon_device *rdev;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if ((*bo) == NULL)
|
2009-06-05 20:42:42 +08:00
|
|
|
return;
|
2010-04-29 16:37:59 +08:00
|
|
|
rdev = (*bo)->rdev;
|
2009-11-20 21:29:23 +08:00
|
|
|
tbo = &((*bo)->tbo);
|
|
|
|
ttm_bo_unref(&tbo);
|
|
|
|
if (tbo == NULL)
|
|
|
|
*bo = NULL;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2012-03-15 00:12:41 +08:00
|
|
|
int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
|
|
|
|
u64 *gpu_addr)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-12-07 22:52:58 +08:00
|
|
|
int r, i;
|
2009-06-05 20:42:42 +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
|
|
|
if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
|
|
|
|
return -EPERM;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->pin_count) {
|
|
|
|
bo->pin_count++;
|
|
|
|
if (gpu_addr)
|
|
|
|
*gpu_addr = radeon_bo_gpu_offset(bo);
|
2012-03-28 14:52:32 +08:00
|
|
|
|
|
|
|
if (max_offset != 0) {
|
|
|
|
u64 domain_start;
|
|
|
|
|
|
|
|
if (domain == RADEON_GEM_DOMAIN_VRAM)
|
|
|
|
domain_start = bo->rdev->mc.vram_start;
|
|
|
|
else
|
|
|
|
domain_start = bo->rdev->mc.gtt_start;
|
2012-03-29 22:47:43 +08:00
|
|
|
WARN_ON_ONCE(max_offset <
|
|
|
|
(radeon_bo_gpu_offset(bo) - domain_start));
|
2012-03-28 14:52:32 +08:00
|
|
|
}
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-12-07 22:52:58 +08:00
|
|
|
radeon_ttm_placement_from_domain(bo, domain);
|
2014-08-27 19:16:04 +08:00
|
|
|
for (i = 0; i < bo->placement.num_placement; i++) {
|
2010-03-27 03:18:55 +08:00
|
|
|
/* force to pin into visible video ram */
|
2014-09-09 09:09:23 +08:00
|
|
|
if ((bo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
|
2014-08-28 22:59:05 +08:00
|
|
|
!(bo->flags & RADEON_GEM_NO_CPU_ACCESS) &&
|
2014-09-09 09:09:23 +08:00
|
|
|
(!max_offset || max_offset > bo->rdev->mc.visible_vram_size))
|
|
|
|
bo->placements[i].lpfn =
|
|
|
|
bo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
|
2014-08-27 19:16:04 +08:00
|
|
|
else
|
2014-09-09 09:09:23 +08:00
|
|
|
bo->placements[i].lpfn = max_offset >> PAGE_SHIFT;
|
2012-03-15 00:12:41 +08:00
|
|
|
|
2014-08-27 19:16:04 +08:00
|
|
|
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
|
2012-03-15 00:12:41 +08:00
|
|
|
}
|
2014-08-27 19:16:04 +08:00
|
|
|
|
2012-11-28 19:25:44 +08:00
|
|
|
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
|
2009-11-20 21:29:23 +08:00
|
|
|
if (likely(r == 0)) {
|
|
|
|
bo->pin_count = 1;
|
|
|
|
if (gpu_addr != NULL)
|
|
|
|
*gpu_addr = radeon_bo_gpu_offset(bo);
|
2014-07-18 00:09:25 +08:00
|
|
|
if (domain == RADEON_GEM_DOMAIN_VRAM)
|
|
|
|
bo->rdev->vram_pin_size += radeon_bo_size(bo);
|
|
|
|
else
|
|
|
|
bo->rdev->gart_pin_size += radeon_bo_size(bo);
|
|
|
|
} else {
|
2009-11-20 21:29:23 +08:00
|
|
|
dev_err(bo->rdev->dev, "%p pin failed\n", bo);
|
2014-07-18 00:09:25 +08:00
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
return r;
|
|
|
|
}
|
2012-03-15 00:12:41 +08:00
|
|
|
|
|
|
|
int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)
|
|
|
|
{
|
|
|
|
return radeon_bo_pin_restricted(bo, domain, 0, gpu_addr);
|
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_unpin(struct radeon_bo *bo)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-12-07 22:52:58 +08:00
|
|
|
int r, i;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (!bo->pin_count) {
|
|
|
|
dev_warn(bo->rdev->dev, "%p unpin not necessary\n", bo);
|
|
|
|
return 0;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->pin_count--;
|
|
|
|
if (bo->pin_count)
|
|
|
|
return 0;
|
2014-08-27 19:16:04 +08:00
|
|
|
for (i = 0; i < bo->placement.num_placement; i++) {
|
|
|
|
bo->placements[i].lpfn = 0;
|
|
|
|
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
|
|
|
|
}
|
2012-11-28 19:25:44 +08:00
|
|
|
r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
|
2014-07-18 00:09:25 +08:00
|
|
|
if (likely(r == 0)) {
|
|
|
|
if (bo->tbo.mem.mem_type == TTM_PL_VRAM)
|
|
|
|
bo->rdev->vram_pin_size -= radeon_bo_size(bo);
|
|
|
|
else
|
|
|
|
bo->rdev->gart_pin_size -= radeon_bo_size(bo);
|
|
|
|
} else {
|
2009-11-20 21:29:23 +08:00
|
|
|
dev_err(bo->rdev->dev, "%p validate failed for unpin\n", bo);
|
2014-07-18 00:09:25 +08:00
|
|
|
}
|
2009-12-08 01:36:19 +08:00
|
|
|
return r;
|
2009-08-16 19:05:45 +08:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_evict_vram(struct radeon_device *rdev)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2010-01-25 11:08:08 +08:00
|
|
|
/* late 2.6.33 fix IGP hibernate - we need pm ops to do this correct */
|
|
|
|
if (0 && (rdev->flags & RADEON_IS_IGP)) {
|
2010-01-06 00:27:29 +08:00
|
|
|
if (rdev->mc.igp_sideport_enabled == false)
|
|
|
|
/* Useless to evict on IGP chips */
|
|
|
|
return 0;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
return ttm_bo_evict_mm(&rdev->mman.bdev, TTM_PL_VRAM);
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
void radeon_bo_force_delete(struct radeon_device *rdev)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_bo *bo, *n;
|
2009-06-05 20:42:42 +08:00
|
|
|
|
|
|
|
if (list_empty(&rdev->gem.objects)) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
dev_err(rdev->dev, "Userspace still has active objects !\n");
|
|
|
|
list_for_each_entry_safe(bo, n, &rdev->gem.objects, list) {
|
2009-06-05 20:42:42 +08:00
|
|
|
mutex_lock(&rdev->ddev->struct_mutex);
|
2009-11-20 21:29:23 +08:00
|
|
|
dev_err(rdev->dev, "%p %p %lu %lu force free\n",
|
2011-02-19 00:59:18 +08:00
|
|
|
&bo->gem_base, bo, (unsigned long)bo->gem_base.size,
|
|
|
|
*((unsigned long *)&bo->gem_base.refcount));
|
2009-11-20 21:29:23 +08:00
|
|
|
mutex_lock(&bo->rdev->gem.mutex);
|
|
|
|
list_del_init(&bo->list);
|
|
|
|
mutex_unlock(&bo->rdev->gem.mutex);
|
2011-03-01 11:40:06 +08:00
|
|
|
/* this should unref the ttm bo */
|
2011-02-19 00:59:18 +08:00
|
|
|
drm_gem_object_unreference(&bo->gem_base);
|
2009-06-05 20:42:42 +08:00
|
|
|
mutex_unlock(&rdev->ddev->struct_mutex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_init(struct radeon_device *rdev)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-09-11 19:00:43 +08:00
|
|
|
/* Add an MTRR for the VRAM */
|
2013-04-09 05:25:47 +08:00
|
|
|
if (!rdev->fastfb_working) {
|
2013-05-14 07:58:45 +08:00
|
|
|
rdev->mc.vram_mtrr = arch_phys_wc_add(rdev->mc.aper_base,
|
|
|
|
rdev->mc.aper_size);
|
2013-04-09 05:25:47 +08:00
|
|
|
}
|
2009-09-11 19:00:43 +08:00
|
|
|
DRM_INFO("Detected VRAM RAM=%lluM, BAR=%lluM\n",
|
|
|
|
rdev->mc.mc_vram_size >> 20,
|
|
|
|
(unsigned long long)rdev->mc.aper_size >> 20);
|
|
|
|
DRM_INFO("RAM width %dbits %cDR\n",
|
|
|
|
rdev->mc.vram_width, rdev->mc.vram_is_ddr ? 'D' : 'S');
|
2009-06-05 20:42:42 +08:00
|
|
|
return radeon_ttm_init(rdev);
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
void radeon_bo_fini(struct radeon_device *rdev)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
|
|
|
radeon_ttm_fini(rdev);
|
2013-05-14 07:58:45 +08:00
|
|
|
arch_phys_wc_del(rdev->mc.vram_mtrr);
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
|
|
|
|
2014-03-02 07:56:22 +08:00
|
|
|
/* Returns how many bytes TTM can move per IB.
|
|
|
|
*/
|
|
|
|
static u64 radeon_bo_get_threshold_for_moves(struct radeon_device *rdev)
|
|
|
|
{
|
|
|
|
u64 real_vram_size = rdev->mc.real_vram_size;
|
|
|
|
u64 vram_usage = atomic64_read(&rdev->vram_usage);
|
|
|
|
|
|
|
|
/* This function is based on the current VRAM usage.
|
|
|
|
*
|
|
|
|
* - If all of VRAM is free, allow relocating the number of bytes that
|
|
|
|
* is equal to 1/4 of the size of VRAM for this IB.
|
|
|
|
|
|
|
|
* - If more than one half of VRAM is occupied, only allow relocating
|
|
|
|
* 1 MB of data for this IB.
|
|
|
|
*
|
|
|
|
* - From 0 to one half of used VRAM, the threshold decreases
|
|
|
|
* linearly.
|
|
|
|
* __________________
|
|
|
|
* 1/4 of -|\ |
|
|
|
|
* VRAM | \ |
|
|
|
|
* | \ |
|
|
|
|
* | \ |
|
|
|
|
* | \ |
|
|
|
|
* | \ |
|
|
|
|
* | \ |
|
|
|
|
* | \________|1 MB
|
|
|
|
* |----------------|
|
|
|
|
* VRAM 0 % 100 %
|
|
|
|
* used used
|
|
|
|
*
|
|
|
|
* Note: It's a threshold, not a limit. The threshold must be crossed
|
|
|
|
* for buffer relocations to stop, so any buffer of an arbitrary size
|
|
|
|
* can be moved as long as the threshold isn't crossed before
|
|
|
|
* the relocation takes place. We don't want to disable buffer
|
|
|
|
* relocations completely.
|
|
|
|
*
|
|
|
|
* The idea is that buffers should be placed in VRAM at creation time
|
|
|
|
* and TTM should only do a minimum number of relocations during
|
|
|
|
* command submission. In practice, you need to submit at least
|
|
|
|
* a dozen IBs to move all buffers to VRAM if they are in GTT.
|
|
|
|
*
|
|
|
|
* Also, things can get pretty crazy under memory pressure and actual
|
|
|
|
* VRAM usage can change a lot, so playing safe even at 50% does
|
|
|
|
* consistently increase performance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
u64 half_vram = real_vram_size >> 1;
|
|
|
|
u64 half_free_vram = vram_usage >= half_vram ? 0 : half_vram - vram_usage;
|
|
|
|
u64 bytes_moved_threshold = half_free_vram >> 1;
|
|
|
|
return max(bytes_moved_threshold, 1024*1024ull);
|
|
|
|
}
|
|
|
|
|
|
|
|
int radeon_bo_list_validate(struct radeon_device *rdev,
|
|
|
|
struct ww_acquire_ctx *ticket,
|
2013-06-27 19:48:17 +08:00
|
|
|
struct list_head *head, int ring)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2014-11-27 21:48:42 +08:00
|
|
|
struct radeon_bo_list *lobj;
|
2014-12-03 22:46:49 +08:00
|
|
|
struct list_head duplicates;
|
2009-06-05 20:42:42 +08:00
|
|
|
int r;
|
2014-03-02 07:56:22 +08:00
|
|
|
u64 bytes_moved = 0, initial_bytes_moved;
|
|
|
|
u64 bytes_moved_threshold = radeon_bo_get_threshold_for_moves(rdev);
|
2009-06-05 20:42:42 +08:00
|
|
|
|
2014-12-03 22:46:49 +08:00
|
|
|
INIT_LIST_HEAD(&duplicates);
|
|
|
|
r = ttm_eu_reserve_buffers(ticket, head, true, &duplicates);
|
2009-06-05 20:42:42 +08:00
|
|
|
if (unlikely(r != 0)) {
|
|
|
|
return r;
|
|
|
|
}
|
2014-03-02 07:56:22 +08:00
|
|
|
|
2010-11-17 20:38:32 +08:00
|
|
|
list_for_each_entry(lobj, head, tv.head) {
|
2014-12-03 22:46:49 +08:00
|
|
|
struct radeon_bo *bo = lobj->robj;
|
2009-11-20 21:29:23 +08:00
|
|
|
if (!bo->pin_count) {
|
2014-06-02 23:33:07 +08:00
|
|
|
u32 domain = lobj->prefered_domains;
|
2014-08-21 18:18:12 +08:00
|
|
|
u32 allowed = lobj->allowed_domains;
|
2014-03-02 07:56:22 +08:00
|
|
|
u32 current_domain =
|
|
|
|
radeon_mem_type_to_domain(bo->tbo.mem.mem_type);
|
|
|
|
|
|
|
|
/* Check if this buffer will be moved and don't move it
|
|
|
|
* if we have moved too many buffers for this IB already.
|
|
|
|
*
|
|
|
|
* Note that this allows moving at least one buffer of
|
|
|
|
* any size, because it doesn't take the current "bo"
|
|
|
|
* into account. We don't want to disallow buffer moves
|
|
|
|
* completely.
|
|
|
|
*/
|
2014-08-21 18:18:12 +08:00
|
|
|
if ((allowed & current_domain) != 0 &&
|
2014-03-02 07:56:22 +08:00
|
|
|
(domain & current_domain) == 0 && /* will be moved */
|
|
|
|
bytes_moved > bytes_moved_threshold) {
|
|
|
|
/* don't move it */
|
|
|
|
domain = current_domain;
|
|
|
|
}
|
|
|
|
|
2013-01-18 02:10:50 +08:00
|
|
|
retry:
|
|
|
|
radeon_ttm_placement_from_domain(bo, domain);
|
2013-04-08 18:41:29 +08:00
|
|
|
if (ring == R600_RING_TYPE_UVD_INDEX)
|
2014-08-21 18:18:12 +08:00
|
|
|
radeon_uvd_force_into_uvd_segment(bo, allowed);
|
2014-03-02 07:56:22 +08:00
|
|
|
|
|
|
|
initial_bytes_moved = atomic64_read(&rdev->num_bytes_moved);
|
|
|
|
r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false);
|
|
|
|
bytes_moved += atomic64_read(&rdev->num_bytes_moved) -
|
|
|
|
initial_bytes_moved;
|
|
|
|
|
2010-07-08 10:43:28 +08:00
|
|
|
if (unlikely(r)) {
|
2014-06-02 23:33:07 +08:00
|
|
|
if (r != -ERESTARTSYS &&
|
|
|
|
domain != lobj->allowed_domains) {
|
|
|
|
domain = lobj->allowed_domains;
|
2013-01-18 02:10:50 +08:00
|
|
|
goto retry;
|
|
|
|
}
|
drm/radeon: add missing ttm_eu_backoff_reservation to radeon_bo_list_validate
Op 10-07-13 12:03, Markus Trippelsdorf schreef:
> On 2013.07.10 at 11:56 +0200, Maarten Lankhorst wrote:
>> Op 10-07-13 11:46, Markus Trippelsdorf schreef:
>>> On 2013.07.10 at 11:29 +0200, Maarten Lankhorst wrote:
>>>> Op 10-07-13 11:22, Markus Trippelsdorf schreef:
>>>>> By simply copy/pasting a big document under LibreOffice my system hangs
>>>>> itself up. Only a hard reset gets it working again.
>>>>> see also: https://bugs.freedesktop.org/show_bug.cgi?id=66551
>>>>>
>>>>> I've bisected the issue to:
>>>>>
>>>>> commit ecff665f5e3f1c6909353e00b9420e45ae23d995
>>>>> Author: Maarten Lankhorst <m.b.lankhorst@gmail.com>
>>>>> Date: Thu Jun 27 13:48:17 2013 +0200
>>>>>
>>>>> drm/ttm: make ttm reservation calls behave like reservation calls
>>>>>
>>>>> This commit converts the source of the val_seq counter to
>>>>> the ww_mutex api. The reservation objects are converted later,
>>>>> because there is still a lockdep splat in nouveau that has to
>>>>> resolved first.
>>>>>
>>>>> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
>>>>> Reviewed-by: Jerome Glisse <jglisse@redhat.com>
>>>>> Signed-off-by: Dave Airlie <airlied@redhat.com>
>>>> Hey,
>>>>
>>>> Can you try current head with CONFIG_PROVE_LOCKING set and post the
>>>> lockdep splat from dmesg, if any? If there is any locking issue
>>>> lockdep should warn about it. Lockdep will turn itself off after the
>>>> first splat, so if the lockdep splat happens before running the
>>>> affected parts those will have to be fixed first.
>>> There was an unrelated EDAC lockdep splat, so I simply disabled it.
>>>
>>> This is what I get:
>>>
>>> Jul 10 11:40:44 x4 kernel: ================================================
>>> Jul 10 11:40:44 x4 kernel: [ BUG: lock held when returning to user space! ]
>>> Jul 10 11:40:44 x4 kernel: 3.10.0-08587-g496322b #35 Not tainted
>>> Jul 10 11:40:44 x4 kernel: ------------------------------------------------
>>> Jul 10 11:40:44 x4 kernel: X/211 is leaving the kernel with locks still held!
>>> Jul 10 11:40:44 x4 kernel: 2 locks held by X/211:
>>> Jul 10 11:40:44 x4 kernel: #0: (reservation_ww_class_acquire){+.+.+.}, at: [<ffffffff813279f0>] radeon_bo_list_validate+0x20/0xd0
>>> Jul 10 11:40:44 x4 kernel: #1: (reservation_ww_class_mutex){+.+.+.}, at: [<ffffffff81309306>] ttm_eu_reserve_buffers+0x126/0x4b0
>>> Jul 10 11:40:52 x4 kernel: SysRq : Emergency Sync
>>> Jul 10 11:40:53 x4 kernel: Emergency Sync complete
>>>
>> Thanks, exactly what I thought. I missed a backoff somewhere..
>>
>> Does the below patch fix it?
> Yes. Thank you for your quick reply.
8<------
If radeon_cs_parser_relocs fails ttm_eu_backoff_reservation doesn't get called.
This left open a bug where ttm_eu_reserve_buffers succeeded but the bo's were
not unlocked afterwards:
Jul 10 11:40:44 x4 kernel: ================================================
Jul 10 11:40:44 x4 kernel: [ BUG: lock held when returning to user space! ]
Jul 10 11:40:44 x4 kernel: 3.10.0-08587-g496322b #35 Not tainted
Jul 10 11:40:44 x4 kernel: ------------------------------------------------
Jul 10 11:40:44 x4 kernel: X/211 is leaving the kernel with locks still held!
Jul 10 11:40:44 x4 kernel: 2 locks held by X/211:
Jul 10 11:40:44 x4 kernel: #0: (reservation_ww_class_acquire){+.+.+.}, at: [<ffffffff813279f0>] radeon_bo_list_validate+0x20/0xd0
Jul 10 11:40:44 x4 kernel: #1: (reservation_ww_class_mutex){+.+.+.}, at: [<ffffffff81309306>] ttm_eu_reserve_buffers+0x126/0x4b0
Jul 10 11:40:52 x4 kernel: SysRq : Emergency Sync
Jul 10 11:40:53 x4 kernel: Emergency Sync complete
This is a regression caused by commit ecff665f5e.
"drm/ttm: make ttm reservation calls behave like reservation calls"
Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Tested-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2013-07-10 18:26:56 +08:00
|
|
|
ttm_eu_backoff_reservation(ticket, head);
|
2009-06-05 20:42:42 +08:00
|
|
|
return r;
|
2010-07-08 10:43:28 +08:00
|
|
|
}
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
lobj->gpu_offset = radeon_bo_gpu_offset(bo);
|
|
|
|
lobj->tiling_flags = bo->tiling_flags;
|
2009-06-05 20:42:42 +08:00
|
|
|
}
|
2014-12-03 22:46:49 +08:00
|
|
|
|
|
|
|
list_for_each_entry(lobj, &duplicates, tv.head) {
|
|
|
|
lobj->gpu_offset = radeon_bo_gpu_offset(lobj->robj);
|
|
|
|
lobj->tiling_flags = lobj->robj->tiling_flags;
|
|
|
|
}
|
|
|
|
|
2009-06-05 20:42:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-09 12:15:38 +08:00
|
|
|
int radeon_bo_get_surface_reg(struct radeon_bo *bo)
|
2009-06-05 20:42:42 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_device *rdev = bo->rdev;
|
2009-06-24 07:48:08 +08:00
|
|
|
struct radeon_surface_reg *reg;
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_bo *old_object;
|
2009-06-24 07:48:08 +08:00
|
|
|
int steal;
|
|
|
|
int i;
|
|
|
|
|
2013-06-27 19:48:26 +08:00
|
|
|
lockdep_assert_held(&bo->tbo.resv->lock.base);
|
2009-11-20 21:29:23 +08:00
|
|
|
|
|
|
|
if (!bo->tiling_flags)
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->surface_reg >= 0) {
|
|
|
|
reg = &rdev->surface_regs[bo->surface_reg];
|
|
|
|
i = bo->surface_reg;
|
2009-06-24 07:48:08 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
steal = -1;
|
|
|
|
for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
|
|
|
|
|
|
|
|
reg = &rdev->surface_regs[i];
|
2009-11-20 21:29:23 +08:00
|
|
|
if (!reg->bo)
|
2009-06-24 07:48:08 +08:00
|
|
|
break;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
old_object = reg->bo;
|
2009-06-24 07:48:08 +08:00
|
|
|
if (old_object->pin_count == 0)
|
|
|
|
steal = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we are all out */
|
|
|
|
if (i == RADEON_GEM_MAX_SURFACES) {
|
|
|
|
if (steal == -1)
|
|
|
|
return -ENOMEM;
|
|
|
|
/* find someone with a surface reg and nuke their BO */
|
|
|
|
reg = &rdev->surface_regs[steal];
|
2009-11-20 21:29:23 +08:00
|
|
|
old_object = reg->bo;
|
2009-06-24 07:48:08 +08:00
|
|
|
/* blow away the mapping */
|
|
|
|
DRM_DEBUG("stealing surface reg %d from %p\n", steal, old_object);
|
2009-11-20 21:29:23 +08:00
|
|
|
ttm_bo_unmap_virtual(&old_object->tbo);
|
2009-06-24 07:48:08 +08:00
|
|
|
old_object->surface_reg = -1;
|
|
|
|
i = steal;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->surface_reg = i;
|
|
|
|
reg->bo = bo;
|
2009-06-24 07:48:08 +08:00
|
|
|
|
|
|
|
out:
|
2009-11-20 21:29:23 +08:00
|
|
|
radeon_set_surface_reg(rdev, i, bo->tiling_flags, bo->pitch,
|
2010-08-05 08:48:18 +08:00
|
|
|
bo->tbo.mem.start << PAGE_SHIFT,
|
2009-11-20 21:29:23 +08:00
|
|
|
bo->tbo.num_pages << PAGE_SHIFT);
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
static void radeon_bo_clear_surface_reg(struct radeon_bo *bo)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2009-11-20 21:29:23 +08:00
|
|
|
struct radeon_device *rdev = bo->rdev;
|
2009-06-24 07:48:08 +08:00
|
|
|
struct radeon_surface_reg *reg;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->surface_reg == -1)
|
2009-06-24 07:48:08 +08:00
|
|
|
return;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
reg = &rdev->surface_regs[bo->surface_reg];
|
|
|
|
radeon_clear_surface_reg(rdev, bo->surface_reg);
|
2009-06-24 07:48:08 +08:00
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
reg->bo = NULL;
|
|
|
|
bo->surface_reg = -1;
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_set_tiling_flags(struct radeon_bo *bo,
|
|
|
|
uint32_t tiling_flags, uint32_t pitch)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2011-12-17 06:03:42 +08:00
|
|
|
struct radeon_device *rdev = bo->rdev;
|
2009-11-20 21:29:23 +08:00
|
|
|
int r;
|
|
|
|
|
2011-12-17 06:03:42 +08:00
|
|
|
if (rdev->family >= CHIP_CEDAR) {
|
|
|
|
unsigned bankw, bankh, mtaspect, tilesplit, stilesplit;
|
|
|
|
|
|
|
|
bankw = (tiling_flags >> RADEON_TILING_EG_BANKW_SHIFT) & RADEON_TILING_EG_BANKW_MASK;
|
|
|
|
bankh = (tiling_flags >> RADEON_TILING_EG_BANKH_SHIFT) & RADEON_TILING_EG_BANKH_MASK;
|
|
|
|
mtaspect = (tiling_flags >> RADEON_TILING_EG_MACRO_TILE_ASPECT_SHIFT) & RADEON_TILING_EG_MACRO_TILE_ASPECT_MASK;
|
|
|
|
tilesplit = (tiling_flags >> RADEON_TILING_EG_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_TILE_SPLIT_MASK;
|
|
|
|
stilesplit = (tiling_flags >> RADEON_TILING_EG_STENCIL_TILE_SPLIT_SHIFT) & RADEON_TILING_EG_STENCIL_TILE_SPLIT_MASK;
|
|
|
|
switch (bankw) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
switch (bankh) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
switch (mtaspect) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 8:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (tilesplit > 6) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (stilesplit > 6) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2009-11-20 21:29:23 +08:00
|
|
|
r = radeon_bo_reserve(bo, false);
|
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
|
|
|
bo->tiling_flags = tiling_flags;
|
|
|
|
bo->pitch = pitch;
|
|
|
|
radeon_bo_unreserve(bo);
|
|
|
|
return 0;
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
void radeon_bo_get_tiling_flags(struct radeon_bo *bo,
|
|
|
|
uint32_t *tiling_flags,
|
|
|
|
uint32_t *pitch)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2013-06-27 19:48:26 +08:00
|
|
|
lockdep_assert_held(&bo->tbo.resv->lock.base);
|
|
|
|
|
2009-06-24 07:48:08 +08:00
|
|
|
if (tiling_flags)
|
2009-11-20 21:29:23 +08:00
|
|
|
*tiling_flags = bo->tiling_flags;
|
2009-06-24 07:48:08 +08:00
|
|
|
if (pitch)
|
2009-11-20 21:29:23 +08:00
|
|
|
*pitch = bo->pitch;
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
int radeon_bo_check_tiling(struct radeon_bo *bo, bool has_moved,
|
|
|
|
bool force_drop)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2013-06-27 19:48:26 +08:00
|
|
|
if (!force_drop)
|
|
|
|
lockdep_assert_held(&bo->tbo.resv->lock.base);
|
2009-11-20 21:29:23 +08:00
|
|
|
|
|
|
|
if (!(bo->tiling_flags & RADEON_TILING_SURFACE))
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (force_drop) {
|
2009-11-20 21:29:23 +08:00
|
|
|
radeon_bo_clear_surface_reg(bo);
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->tbo.mem.mem_type != TTM_PL_VRAM) {
|
2009-06-24 07:48:08 +08:00
|
|
|
if (!has_moved)
|
|
|
|
return 0;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if (bo->surface_reg >= 0)
|
|
|
|
radeon_bo_clear_surface_reg(bo);
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
if ((bo->surface_reg >= 0) && !has_moved)
|
2009-06-24 07:48:08 +08:00
|
|
|
return 0;
|
|
|
|
|
2009-11-20 21:29:23 +08:00
|
|
|
return radeon_bo_get_surface_reg(bo);
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void radeon_bo_move_notify(struct ttm_buffer_object *bo,
|
2014-03-02 07:56:18 +08:00
|
|
|
struct ttm_mem_reg *new_mem)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2009-12-15 04:02:09 +08:00
|
|
|
struct radeon_bo *rbo;
|
2014-03-02 07:56:18 +08:00
|
|
|
|
2009-12-15 04:02:09 +08:00
|
|
|
if (!radeon_ttm_bo_is_radeon_bo(bo))
|
|
|
|
return;
|
2014-03-02 07:56:18 +08:00
|
|
|
|
2009-12-15 04:02:09 +08:00
|
|
|
rbo = container_of(bo, struct radeon_bo, tbo);
|
2009-11-20 21:29:23 +08:00
|
|
|
radeon_bo_check_tiling(rbo, 0, 1);
|
drm/radeon: GPU virtual memory support v22
Virtual address space are per drm client (opener of /dev/drm).
Client are in charge of virtual address space, they need to
map bo into it by calling DRM_RADEON_GEM_VA ioctl.
First 16M of virtual address space is reserved by the kernel.
Once using 2 level page table we should be able to have a small
vram memory footprint for each pt (there would be one pt for all
gart, one for all vram and then one first level for each virtual
address space).
Plan include using the sub allocator for a common vm page table
area and using memcpy to copy vm page table in & out. Or use
a gart object and copy things in & out using dma.
v2: agd5f fixes:
- Add vram base offset for vram pages. The GPU physical address of a
vram page is FB_OFFSET + page offset. FB_OFFSET is 0 on discrete
cards and the physical bus address of the stolen memory on
integrated chips.
- VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR covers all vmid's >= 1
v3: agd5f:
- integrate with the semaphore/multi-ring stuff
v4:
- rebase on top ttm dma & multi-ring stuff
- userspace is now in charge of the address space
- no more specific cs vm ioctl, instead cs ioctl has a new
chunk
v5:
- properly handle mem == NULL case from move_notify callback
- fix the vm cleanup path
v6:
- fix update of page table to only happen on valid mem placement
v7:
- add tlb flush for each vm context
- add flags to define mapping property (readable, writeable, snooped)
- make ring id implicit from ib->fence->ring, up to each asic callback
to then do ring specific scheduling if vm ib scheduling function
v8:
- add query for ib limit and kernel reserved virtual space
- rename vm->size to max_pfn (maximum number of page)
- update gem_va ioctl to also allow unmap operation
- bump kernel version to allow userspace to query for vm support
v9:
- rebuild page table only when bind and incrementaly depending
on bo referenced by cs and that have been moved
- allow virtual address space to grow
- use sa allocator for vram page table
- return invalid when querying vm limit on non cayman GPU
- dump vm fault register on lockup
v10: agd5f:
- Move the vm schedule_ib callback to a standalone function, remove
the callback and use the existing ib_execute callback for VM IBs.
v11:
- rebase on top of lastest Linus
v12: agd5f:
- remove spurious backslash
- set IB vm_id to 0 in radeon_ib_get()
v13: agd5f:
- fix handling of RADEON_CHUNK_ID_FLAGS
v14:
- fix va destruction
- fix suspend resume
- forbid bo to have several different va in same vm
v15:
- rebase
v16:
- cleanup left over of vm init/fini
v17: agd5f:
- cs checker
v18: agd5f:
- reworks the CS ioctl to better support multiple rings and
VM. Rather than adding a new chunk id for VM, just re-use the
IB chunk id and add a new flags for VM mode. Also define additional
dwords for the flags chunk id to define the what ring we want to use
(gfx, compute, uvd, etc.) and the priority.
v19:
- fix cs fini in weird case of no ib
- semi working flush fix for ni
- rebase on top of sa allocator changes
v20: agd5f:
- further CS ioctl cleanups from Christian's comments
v21: agd5f:
- integrate CS checker improvements
v22: agd5f:
- final cleanups for release, only allow VM CS on cayman
Signed-off-by: Jerome Glisse <jglisse@redhat.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
2012-01-06 11:11:05 +08:00
|
|
|
radeon_vm_bo_invalidate(rbo->rdev, rbo);
|
2014-03-02 07:56:18 +08:00
|
|
|
|
|
|
|
/* update statistics */
|
|
|
|
if (!new_mem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
radeon_update_memory_usage(rbo, bo->mem.mem_type, -1);
|
|
|
|
radeon_update_memory_usage(rbo, new_mem->mem_type, 1);
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
|
|
|
|
2010-04-09 20:39:24 +08:00
|
|
|
int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
|
2009-06-24 07:48:08 +08:00
|
|
|
{
|
2010-04-09 20:39:24 +08:00
|
|
|
struct radeon_device *rdev;
|
2009-12-15 04:02:09 +08:00
|
|
|
struct radeon_bo *rbo;
|
2014-10-10 11:28:36 +08:00
|
|
|
unsigned long offset, size, lpfn;
|
|
|
|
int i, r;
|
2010-04-09 20:39:24 +08:00
|
|
|
|
2009-12-15 04:02:09 +08:00
|
|
|
if (!radeon_ttm_bo_is_radeon_bo(bo))
|
2010-04-09 20:39:24 +08:00
|
|
|
return 0;
|
2009-12-15 04:02:09 +08:00
|
|
|
rbo = container_of(bo, struct radeon_bo, tbo);
|
2009-11-20 21:29:23 +08:00
|
|
|
radeon_bo_check_tiling(rbo, 0, 0);
|
2010-04-09 20:39:24 +08:00
|
|
|
rdev = rbo->rdev;
|
2014-05-06 00:40:12 +08:00
|
|
|
if (bo->mem.mem_type != TTM_PL_VRAM)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = bo->mem.num_pages << PAGE_SHIFT;
|
|
|
|
offset = bo->mem.start << PAGE_SHIFT;
|
|
|
|
if ((offset + size) <= rdev->mc.visible_vram_size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* hurrah the memory is not visible ! */
|
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM);
|
2014-10-10 11:28:36 +08:00
|
|
|
lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
|
|
|
|
for (i = 0; i < rbo->placement.num_placement; i++) {
|
|
|
|
/* Force into visible VRAM */
|
|
|
|
if ((rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
|
|
|
|
(!rbo->placements[i].lpfn || rbo->placements[i].lpfn > lpfn))
|
|
|
|
rbo->placements[i].lpfn = lpfn;
|
|
|
|
}
|
2014-05-06 00:40:12 +08:00
|
|
|
r = ttm_bo_validate(bo, &rbo->placement, false, false);
|
|
|
|
if (unlikely(r == -ENOMEM)) {
|
|
|
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);
|
|
|
|
return ttm_bo_validate(bo, &rbo->placement, false, false);
|
|
|
|
} else if (unlikely(r != 0)) {
|
|
|
|
return r;
|
2010-04-09 20:39:24 +08:00
|
|
|
}
|
2014-05-06 00:40:12 +08:00
|
|
|
|
|
|
|
offset = bo->mem.start << PAGE_SHIFT;
|
|
|
|
/* this should never happen */
|
|
|
|
if ((offset + size) > rdev->mc.visible_vram_size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2010-04-09 20:39:24 +08:00
|
|
|
return 0;
|
2009-06-24 07:48:08 +08:00
|
|
|
}
|
2011-10-14 07:08:47 +08:00
|
|
|
|
2011-10-28 00:15:10 +08:00
|
|
|
int radeon_bo_wait(struct radeon_bo *bo, u32 *mem_type, bool no_wait)
|
2011-10-14 07:08:47 +08:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2014-05-19 23:18:52 +08:00
|
|
|
r = ttm_bo_reserve(&bo->tbo, true, no_wait, false, NULL);
|
2011-10-14 07:08:47 +08:00
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
|
|
|
if (mem_type)
|
|
|
|
*mem_type = bo->tbo.mem.mem_type;
|
2014-04-02 23:14:48 +08:00
|
|
|
|
|
|
|
r = ttm_bo_wait(&bo->tbo, true, true, no_wait);
|
2011-10-14 07:08:47 +08:00
|
|
|
ttm_bo_unreserve(&bo->tbo);
|
|
|
|
return r;
|
|
|
|
}
|
2014-11-19 21:01:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* radeon_bo_fence - add fence to buffer object
|
|
|
|
*
|
|
|
|
* @bo: buffer object in question
|
|
|
|
* @fence: fence to add
|
|
|
|
* @shared: true if fence should be added shared
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void radeon_bo_fence(struct radeon_bo *bo, struct radeon_fence *fence,
|
|
|
|
bool shared)
|
|
|
|
{
|
|
|
|
struct reservation_object *resv = bo->tbo.resv;
|
|
|
|
|
|
|
|
if (shared)
|
|
|
|
reservation_object_add_shared_fence(resv, &fence->base);
|
|
|
|
else
|
|
|
|
reservation_object_add_excl_fence(resv, &fence->base);
|
|
|
|
}
|