2009-07-21 09:23:57 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2009 VMware, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Michel Dänzer
|
|
|
|
*/
|
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/radeon_drm.h>
|
|
|
|
#include "radeon_reg.h"
|
|
|
|
#include "radeon.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Test BO GTT->VRAM and VRAM->GTT GPU copies across the whole GTT aperture */
|
|
|
|
void radeon_test_moves(struct radeon_device *rdev)
|
|
|
|
{
|
2009-11-20 13:29:23 +00:00
|
|
|
struct radeon_bo *vram_obj = NULL;
|
|
|
|
struct radeon_bo **gtt_obj = NULL;
|
2009-07-21 09:23:57 +00:00
|
|
|
struct radeon_fence *fence = NULL;
|
|
|
|
uint64_t gtt_addr, vram_addr;
|
|
|
|
unsigned i, n, size;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
size = 1024 * 1024;
|
|
|
|
|
|
|
|
/* Number of tests =
|
2011-08-19 15:24:16 +00:00
|
|
|
* (Total GTT - IB pool - writeback page - ring buffers) / test size
|
2009-07-21 09:23:57 +00:00
|
|
|
*/
|
2011-08-19 15:24:16 +00:00
|
|
|
n = rdev->mc.gtt_size - RADEON_IB_POOL_SIZE*64*1024 - rdev->cp.ring_size;
|
|
|
|
if (rdev->wb.wb_obj)
|
|
|
|
n -= RADEON_GPU_PAGE_SIZE;
|
|
|
|
if (rdev->ih.ring_obj)
|
|
|
|
n -= rdev->ih.ring_size;
|
|
|
|
n /= size;
|
2009-07-21 09:23:57 +00:00
|
|
|
|
|
|
|
gtt_obj = kzalloc(n * sizeof(*gtt_obj), GFP_KERNEL);
|
|
|
|
if (!gtt_obj) {
|
|
|
|
DRM_ERROR("Failed to allocate %d pointers\n", n);
|
|
|
|
r = 1;
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
2011-02-18 16:59:16 +00:00
|
|
|
r = radeon_bo_create(rdev, size, PAGE_SIZE, true, RADEON_GEM_DOMAIN_VRAM,
|
2009-11-20 13:29:23 +00:00
|
|
|
&vram_obj);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to create VRAM object\n");
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
2009-11-20 13:29:23 +00:00
|
|
|
r = radeon_bo_reserve(vram_obj, false);
|
|
|
|
if (unlikely(r != 0))
|
|
|
|
goto out_cleanup;
|
|
|
|
r = radeon_bo_pin(vram_obj, RADEON_GEM_DOMAIN_VRAM, &vram_addr);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to pin VRAM object\n");
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
void *gtt_map, *vram_map;
|
|
|
|
void **gtt_start, **gtt_end;
|
|
|
|
void **vram_start, **vram_end;
|
|
|
|
|
2011-02-18 16:59:16 +00:00
|
|
|
r = radeon_bo_create(rdev, size, PAGE_SIZE, true,
|
2009-11-20 13:29:23 +00:00
|
|
|
RADEON_GEM_DOMAIN_GTT, gtt_obj + i);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to create GTT object %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
r = radeon_bo_reserve(gtt_obj[i], false);
|
|
|
|
if (unlikely(r != 0))
|
|
|
|
goto out_cleanup;
|
|
|
|
r = radeon_bo_pin(gtt_obj[i], RADEON_GEM_DOMAIN_GTT, >t_addr);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to pin GTT object %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
r = radeon_bo_kmap(gtt_obj[i], >t_map);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to map GTT object %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (gtt_start = gtt_map, gtt_end = gtt_map + size;
|
|
|
|
gtt_start < gtt_end;
|
|
|
|
gtt_start++)
|
|
|
|
*gtt_start = gtt_start;
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
radeon_bo_kunmap(gtt_obj[i]);
|
2009-07-21 09:23:57 +00:00
|
|
|
|
|
|
|
r = radeon_fence_create(rdev, &fence);
|
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to create GTT->VRAM fence %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
2009-10-14 04:34:41 +00:00
|
|
|
r = radeon_copy(rdev, gtt_addr, vram_addr, size / RADEON_GPU_PAGE_SIZE, fence);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed GTT->VRAM copy %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = radeon_fence_wait(fence, false);
|
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to wait for GTT->VRAM fence %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
r = radeon_bo_kmap(vram_obj, &vram_map);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to map VRAM object after copy %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (gtt_start = gtt_map, gtt_end = gtt_map + size,
|
|
|
|
vram_start = vram_map, vram_end = vram_map + size;
|
|
|
|
vram_start < vram_end;
|
|
|
|
gtt_start++, vram_start++) {
|
|
|
|
if (*vram_start != gtt_start) {
|
|
|
|
DRM_ERROR("Incorrect GTT->VRAM copy %d: Got 0x%p, "
|
2011-08-19 15:24:17 +00:00
|
|
|
"expected 0x%p (GTT/VRAM offset "
|
|
|
|
"0x%16llx/0x%16llx)\n",
|
|
|
|
i, *vram_start, gtt_start,
|
|
|
|
(unsigned long long)
|
|
|
|
(gtt_addr - rdev->mc.gtt_start +
|
|
|
|
(void*)gtt_start - gtt_map),
|
|
|
|
(unsigned long long)
|
|
|
|
(vram_addr - rdev->mc.vram_start +
|
|
|
|
(void*)gtt_start - gtt_map));
|
2009-11-20 13:29:23 +00:00
|
|
|
radeon_bo_kunmap(vram_obj);
|
2009-07-21 09:23:57 +00:00
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
*vram_start = vram_start;
|
|
|
|
}
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
radeon_bo_kunmap(vram_obj);
|
2009-07-21 09:23:57 +00:00
|
|
|
|
|
|
|
r = radeon_fence_create(rdev, &fence);
|
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to create VRAM->GTT fence %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
2009-10-14 04:34:41 +00:00
|
|
|
r = radeon_copy(rdev, vram_addr, gtt_addr, size / RADEON_GPU_PAGE_SIZE, fence);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed VRAM->GTT copy %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = radeon_fence_wait(fence, false);
|
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to wait for VRAM->GTT fence %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
r = radeon_bo_kmap(gtt_obj[i], >t_map);
|
2009-07-21 09:23:57 +00:00
|
|
|
if (r) {
|
|
|
|
DRM_ERROR("Failed to map GTT object after copy %d\n", i);
|
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (gtt_start = gtt_map, gtt_end = gtt_map + size,
|
|
|
|
vram_start = vram_map, vram_end = vram_map + size;
|
|
|
|
gtt_start < gtt_end;
|
|
|
|
gtt_start++, vram_start++) {
|
|
|
|
if (*gtt_start != vram_start) {
|
|
|
|
DRM_ERROR("Incorrect VRAM->GTT copy %d: Got 0x%p, "
|
2011-08-19 15:24:17 +00:00
|
|
|
"expected 0x%p (VRAM/GTT offset "
|
|
|
|
"0x%16llx/0x%16llx)\n",
|
|
|
|
i, *gtt_start, vram_start,
|
|
|
|
(unsigned long long)
|
|
|
|
(vram_addr - rdev->mc.vram_start +
|
|
|
|
(void*)vram_start - vram_map),
|
|
|
|
(unsigned long long)
|
|
|
|
(gtt_addr - rdev->mc.gtt_start +
|
|
|
|
(void*)vram_start - vram_map));
|
2009-11-20 13:29:23 +00:00
|
|
|
radeon_bo_kunmap(gtt_obj[i]);
|
2009-07-21 09:23:57 +00:00
|
|
|
goto out_cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 13:29:23 +00:00
|
|
|
radeon_bo_kunmap(gtt_obj[i]);
|
2009-07-21 09:23:57 +00:00
|
|
|
|
|
|
|
DRM_INFO("Tested GTT->VRAM and VRAM->GTT copy for GTT offset 0x%llx\n",
|
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-17 21:54:29 +00:00
|
|
|
gtt_addr - rdev->mc.gtt_start);
|
2009-07-21 09:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out_cleanup:
|
|
|
|
if (vram_obj) {
|
2009-11-20 13:29:23 +00:00
|
|
|
if (radeon_bo_is_reserved(vram_obj)) {
|
|
|
|
radeon_bo_unpin(vram_obj);
|
|
|
|
radeon_bo_unreserve(vram_obj);
|
|
|
|
}
|
|
|
|
radeon_bo_unref(&vram_obj);
|
2009-07-21 09:23:57 +00:00
|
|
|
}
|
|
|
|
if (gtt_obj) {
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (gtt_obj[i]) {
|
2009-11-20 13:29:23 +00:00
|
|
|
if (radeon_bo_is_reserved(gtt_obj[i])) {
|
|
|
|
radeon_bo_unpin(gtt_obj[i]);
|
|
|
|
radeon_bo_unreserve(gtt_obj[i]);
|
|
|
|
}
|
|
|
|
radeon_bo_unref(>t_obj[i]);
|
2009-07-21 09:23:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
kfree(gtt_obj);
|
|
|
|
}
|
|
|
|
if (fence) {
|
|
|
|
radeon_fence_unref(&fence);
|
|
|
|
}
|
|
|
|
if (r) {
|
|
|
|
printk(KERN_WARNING "Error while testing BO move.\n");
|
|
|
|
}
|
|
|
|
}
|