drm/radeon/kms: Convert radeon to new TTM validation API (V2)
This convert radeon to use new TTM validation API, it doesn't really take advantage of it beside in the eviction case. Signed-off-by: Jerome Glisse <jglisse@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
parent
ca262a9998
commit
312ea8da04
@ -208,6 +208,8 @@ struct radeon_bo {
|
|||||||
/* Protected by gem.mutex */
|
/* Protected by gem.mutex */
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
/* Protected by tbo.reserved */
|
/* Protected by tbo.reserved */
|
||||||
|
u32 placements[3];
|
||||||
|
struct ttm_placement placement;
|
||||||
struct ttm_buffer_object tbo;
|
struct ttm_buffer_object tbo;
|
||||||
struct ttm_bo_kmap_obj kmap;
|
struct ttm_bo_kmap_obj kmap;
|
||||||
unsigned pin_count;
|
unsigned pin_count;
|
||||||
@ -1012,6 +1014,7 @@ extern void radeon_surface_init(struct radeon_device *rdev);
|
|||||||
extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
|
extern int radeon_cs_parser_init(struct radeon_cs_parser *p, void *data);
|
||||||
extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
|
extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enable);
|
||||||
extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
|
extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
|
||||||
|
extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
|
||||||
|
|
||||||
/* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */
|
/* r100,rv100,rs100,rv200,rs200,r200,rv250,rs300,rv280 */
|
||||||
struct r100_mc_save {
|
struct r100_mc_save {
|
||||||
|
@ -75,6 +75,25 @@ static inline u32 radeon_ttm_flags_from_domain(u32 domain)
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
|
||||||
|
{
|
||||||
|
u32 c = 0;
|
||||||
|
|
||||||
|
rbo->placement.fpfn = 0;
|
||||||
|
rbo->placement.lpfn = 0;
|
||||||
|
rbo->placement.placement = rbo->placements;
|
||||||
|
rbo->placement.busy_placement = rbo->placements;
|
||||||
|
if (domain & RADEON_GEM_DOMAIN_VRAM)
|
||||||
|
rbo->placements[c++] = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
|
||||||
|
TTM_PL_FLAG_VRAM;
|
||||||
|
if (domain & RADEON_GEM_DOMAIN_GTT)
|
||||||
|
rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
|
||||||
|
if (domain & RADEON_GEM_DOMAIN_CPU)
|
||||||
|
rbo->placements[c++] = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
|
||||||
|
rbo->placement.num_placement = c;
|
||||||
|
rbo->placement.num_busy_placement = c;
|
||||||
|
}
|
||||||
|
|
||||||
int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
|
int radeon_bo_create(struct radeon_device *rdev, struct drm_gem_object *gobj,
|
||||||
unsigned long size, bool kernel, u32 domain,
|
unsigned long size, bool kernel, u32 domain,
|
||||||
struct radeon_bo **bo_ptr)
|
struct radeon_bo **bo_ptr)
|
||||||
@ -169,24 +188,20 @@ void radeon_bo_unref(struct radeon_bo **bo)
|
|||||||
|
|
||||||
int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)
|
int radeon_bo_pin(struct radeon_bo *bo, u32 domain, u64 *gpu_addr)
|
||||||
{
|
{
|
||||||
u32 flags;
|
int r, i;
|
||||||
u32 tmp;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
flags = radeon_ttm_flags_from_domain(domain);
|
radeon_ttm_placement_from_domain(bo, domain);
|
||||||
if (bo->pin_count) {
|
if (bo->pin_count) {
|
||||||
bo->pin_count++;
|
bo->pin_count++;
|
||||||
if (gpu_addr)
|
if (gpu_addr)
|
||||||
*gpu_addr = radeon_bo_gpu_offset(bo);
|
*gpu_addr = radeon_bo_gpu_offset(bo);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
tmp = bo->tbo.mem.placement;
|
radeon_ttm_placement_from_domain(bo, domain);
|
||||||
ttm_flag_masked(&tmp, flags, TTM_PL_MASK_MEM);
|
for (i = 0; i < bo->placement.num_placement; i++)
|
||||||
bo->tbo.proposed_placement = tmp | TTM_PL_FLAG_NO_EVICT |
|
bo->placements[i] |= TTM_PL_FLAG_NO_EVICT;
|
||||||
TTM_PL_MASK_CACHING;
|
|
||||||
retry:
|
retry:
|
||||||
r = ttm_buffer_object_validate(&bo->tbo, bo->tbo.proposed_placement,
|
r = ttm_buffer_object_validate(&bo->tbo, &bo->placement, true, false);
|
||||||
true, false);
|
|
||||||
if (likely(r == 0)) {
|
if (likely(r == 0)) {
|
||||||
bo->pin_count = 1;
|
bo->pin_count = 1;
|
||||||
if (gpu_addr != NULL)
|
if (gpu_addr != NULL)
|
||||||
@ -202,7 +217,7 @@ retry:
|
|||||||
|
|
||||||
int radeon_bo_unpin(struct radeon_bo *bo)
|
int radeon_bo_unpin(struct radeon_bo *bo)
|
||||||
{
|
{
|
||||||
int r;
|
int r, i;
|
||||||
|
|
||||||
if (!bo->pin_count) {
|
if (!bo->pin_count) {
|
||||||
dev_warn(bo->rdev->dev, "%p unpin not necessary\n", bo);
|
dev_warn(bo->rdev->dev, "%p unpin not necessary\n", bo);
|
||||||
@ -211,11 +226,10 @@ int radeon_bo_unpin(struct radeon_bo *bo)
|
|||||||
bo->pin_count--;
|
bo->pin_count--;
|
||||||
if (bo->pin_count)
|
if (bo->pin_count)
|
||||||
return 0;
|
return 0;
|
||||||
bo->tbo.proposed_placement = bo->tbo.mem.placement &
|
for (i = 0; i < bo->placement.num_placement; i++)
|
||||||
~TTM_PL_FLAG_NO_EVICT;
|
bo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT;
|
||||||
retry:
|
retry:
|
||||||
r = ttm_buffer_object_validate(&bo->tbo, bo->tbo.proposed_placement,
|
r = ttm_buffer_object_validate(&bo->tbo, &bo->placement, true, false);
|
||||||
true, false);
|
|
||||||
if (unlikely(r != 0)) {
|
if (unlikely(r != 0)) {
|
||||||
if (r == -ERESTART)
|
if (r == -ERESTART)
|
||||||
goto retry;
|
goto retry;
|
||||||
@ -326,15 +340,15 @@ int radeon_bo_list_validate(struct list_head *head, void *fence)
|
|||||||
bo = lobj->bo;
|
bo = lobj->bo;
|
||||||
if (!bo->pin_count) {
|
if (!bo->pin_count) {
|
||||||
if (lobj->wdomain) {
|
if (lobj->wdomain) {
|
||||||
bo->tbo.proposed_placement =
|
radeon_ttm_placement_from_domain(bo,
|
||||||
radeon_ttm_flags_from_domain(lobj->wdomain);
|
lobj->wdomain);
|
||||||
} else {
|
} else {
|
||||||
bo->tbo.proposed_placement =
|
radeon_ttm_placement_from_domain(bo,
|
||||||
radeon_ttm_flags_from_domain(lobj->rdomain);
|
lobj->rdomain);
|
||||||
}
|
}
|
||||||
retry:
|
retry:
|
||||||
r = ttm_buffer_object_validate(&bo->tbo,
|
r = ttm_buffer_object_validate(&bo->tbo,
|
||||||
bo->tbo.proposed_placement,
|
&bo->placement,
|
||||||
true, false);
|
true, false);
|
||||||
if (unlikely(r)) {
|
if (unlikely(r)) {
|
||||||
if (r == -ERESTART)
|
if (r == -ERESTART)
|
||||||
|
@ -197,15 +197,17 @@ static int radeon_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t radeon_evict_flags(struct ttm_buffer_object *bo)
|
static void radeon_evict_flags(struct ttm_buffer_object *bo,
|
||||||
|
struct ttm_placement *placement)
|
||||||
{
|
{
|
||||||
uint32_t cur_placement = bo->mem.placement & ~TTM_PL_MASK_MEMTYPE;
|
struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo);
|
||||||
|
|
||||||
switch (bo->mem.mem_type) {
|
switch (bo->mem.mem_type) {
|
||||||
|
case TTM_PL_VRAM:
|
||||||
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);
|
||||||
|
break;
|
||||||
|
case TTM_PL_TT:
|
||||||
default:
|
default:
|
||||||
return (cur_placement & ~TTM_PL_MASK_CACHING) |
|
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_CPU);
|
||||||
TTM_PL_FLAG_SYSTEM |
|
|
||||||
TTM_PL_FLAG_CACHED;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,14 +285,21 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
|
|||||||
struct radeon_device *rdev;
|
struct radeon_device *rdev;
|
||||||
struct ttm_mem_reg *old_mem = &bo->mem;
|
struct ttm_mem_reg *old_mem = &bo->mem;
|
||||||
struct ttm_mem_reg tmp_mem;
|
struct ttm_mem_reg tmp_mem;
|
||||||
uint32_t proposed_placement;
|
u32 placements;
|
||||||
|
struct ttm_placement placement;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
rdev = radeon_get_rdev(bo->bdev);
|
rdev = radeon_get_rdev(bo->bdev);
|
||||||
tmp_mem = *new_mem;
|
tmp_mem = *new_mem;
|
||||||
tmp_mem.mm_node = NULL;
|
tmp_mem.mm_node = NULL;
|
||||||
proposed_placement = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
|
placement.fpfn = 0;
|
||||||
r = ttm_bo_mem_space(bo, proposed_placement, &tmp_mem,
|
placement.lpfn = 0;
|
||||||
|
placement.num_placement = 1;
|
||||||
|
placement.placement = &placements;
|
||||||
|
placement.num_busy_placement = 1;
|
||||||
|
placement.busy_placement = &placements;
|
||||||
|
placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
|
||||||
|
r = ttm_bo_mem_space(bo, &placement, &tmp_mem,
|
||||||
interruptible, no_wait);
|
interruptible, no_wait);
|
||||||
if (unlikely(r)) {
|
if (unlikely(r)) {
|
||||||
return r;
|
return r;
|
||||||
@ -329,15 +338,21 @@ static int radeon_move_ram_vram(struct ttm_buffer_object *bo,
|
|||||||
struct radeon_device *rdev;
|
struct radeon_device *rdev;
|
||||||
struct ttm_mem_reg *old_mem = &bo->mem;
|
struct ttm_mem_reg *old_mem = &bo->mem;
|
||||||
struct ttm_mem_reg tmp_mem;
|
struct ttm_mem_reg tmp_mem;
|
||||||
uint32_t proposed_flags;
|
struct ttm_placement placement;
|
||||||
|
u32 placements;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
rdev = radeon_get_rdev(bo->bdev);
|
rdev = radeon_get_rdev(bo->bdev);
|
||||||
tmp_mem = *new_mem;
|
tmp_mem = *new_mem;
|
||||||
tmp_mem.mm_node = NULL;
|
tmp_mem.mm_node = NULL;
|
||||||
proposed_flags = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING;
|
placement.fpfn = 0;
|
||||||
r = ttm_bo_mem_space(bo, proposed_flags, &tmp_mem,
|
placement.lpfn = 0;
|
||||||
interruptible, no_wait);
|
placement.num_placement = 1;
|
||||||
|
placement.placement = &placements;
|
||||||
|
placement.num_busy_placement = 1;
|
||||||
|
placement.busy_placement = &placements;
|
||||||
|
placements = TTM_PL_MASK_CACHING | TTM_PL_FLAG_TT;
|
||||||
|
r = ttm_bo_mem_space(bo, &placement, &tmp_mem, interruptible, no_wait);
|
||||||
if (unlikely(r)) {
|
if (unlikely(r)) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -407,18 +422,6 @@ memcpy:
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t radeon_mem_prios[] = {
|
|
||||||
TTM_PL_VRAM,
|
|
||||||
TTM_PL_TT,
|
|
||||||
TTM_PL_SYSTEM,
|
|
||||||
};
|
|
||||||
|
|
||||||
const uint32_t radeon_busy_prios[] = {
|
|
||||||
TTM_PL_TT,
|
|
||||||
TTM_PL_VRAM,
|
|
||||||
TTM_PL_SYSTEM,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int radeon_sync_obj_wait(void *sync_obj, void *sync_arg,
|
static int radeon_sync_obj_wait(void *sync_obj, void *sync_arg,
|
||||||
bool lazy, bool interruptible)
|
bool lazy, bool interruptible)
|
||||||
{
|
{
|
||||||
@ -446,10 +449,6 @@ static bool radeon_sync_obj_signaled(void *sync_obj, void *sync_arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct ttm_bo_driver radeon_bo_driver = {
|
static struct ttm_bo_driver radeon_bo_driver = {
|
||||||
.mem_type_prio = radeon_mem_prios,
|
|
||||||
.mem_busy_prio = radeon_busy_prios,
|
|
||||||
.num_mem_type_prio = ARRAY_SIZE(radeon_mem_prios),
|
|
||||||
.num_mem_busy_prio = ARRAY_SIZE(radeon_busy_prios),
|
|
||||||
.create_ttm_backend_entry = &radeon_create_ttm_backend_entry,
|
.create_ttm_backend_entry = &radeon_create_ttm_backend_entry,
|
||||||
.invalidate_caches = &radeon_invalidate_caches,
|
.invalidate_caches = &radeon_invalidate_caches,
|
||||||
.init_mem_type = &radeon_init_mem_type,
|
.init_mem_type = &radeon_init_mem_type,
|
||||||
@ -483,7 +482,7 @@ int radeon_ttm_init(struct radeon_device *rdev)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
r = ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_VRAM,
|
r = ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_VRAM,
|
||||||
0, rdev->mc.real_vram_size >> PAGE_SHIFT);
|
rdev->mc.real_vram_size >> PAGE_SHIFT);
|
||||||
if (r) {
|
if (r) {
|
||||||
DRM_ERROR("Failed initializing VRAM heap.\n");
|
DRM_ERROR("Failed initializing VRAM heap.\n");
|
||||||
return r;
|
return r;
|
||||||
@ -506,7 +505,7 @@ int radeon_ttm_init(struct radeon_device *rdev)
|
|||||||
DRM_INFO("radeon: %uM of VRAM memory ready\n",
|
DRM_INFO("radeon: %uM of VRAM memory ready\n",
|
||||||
(unsigned)rdev->mc.real_vram_size / (1024 * 1024));
|
(unsigned)rdev->mc.real_vram_size / (1024 * 1024));
|
||||||
r = ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_TT,
|
r = ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_TT,
|
||||||
0, rdev->mc.gtt_size >> PAGE_SHIFT);
|
rdev->mc.gtt_size >> PAGE_SHIFT);
|
||||||
if (r) {
|
if (r) {
|
||||||
DRM_ERROR("Failed initializing GTT heap.\n");
|
DRM_ERROR("Failed initializing GTT heap.\n");
|
||||||
return r;
|
return r;
|
||||||
|
Loading…
Reference in New Issue
Block a user