diff mbox

[02/11] drm/radeon: rework fallback handling

Message ID 1365254701-2033-3-git-send-email-deathsimple@vodafone.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christian König April 6, 2013, 1:24 p.m. UTC
From: Christian König <christian.koenig@amd.com>

Let the CS module decide if we can fall back to VRAM or not.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/radeon/radeon.h        |    5 ++--
 drivers/gpu/drm/radeon/radeon_cs.c     |   51 ++++++++++++++++++--------------
 drivers/gpu/drm/radeon/radeon_object.c |    8 ++---
 3 files changed, 36 insertions(+), 28 deletions(-)

Comments

Christian König April 6, 2013, 1:39 p.m. UTC | #1
Am 06.04.2013 15:24, schrieb Christian König:
> From: Christian König <christian.koenig@amd.com>
>
> Let the CS module decide if we can fall back to VRAM or not.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>

Crap, just seen another typo in this patch.

Going to resend a v2 of it soon.

Christian.

> ---
>   drivers/gpu/drm/radeon/radeon.h        |    5 ++--
>   drivers/gpu/drm/radeon/radeon_cs.c     |   51 ++++++++++++++++++--------------
>   drivers/gpu/drm/radeon/radeon_object.c |    8 ++---
>   3 files changed, 36 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> index 8263af3..7c2498c 100644
> --- a/drivers/gpu/drm/radeon/radeon.h
> +++ b/drivers/gpu/drm/radeon/radeon.h
> @@ -357,8 +357,9 @@ struct radeon_bo_list {
>   	struct ttm_validate_buffer tv;
>   	struct radeon_bo	*bo;
>   	uint64_t		gpu_offset;
> -	unsigned		rdomain;
> -	unsigned		wdomain;
> +	bool			written;
> +	unsigned		domain;
> +	unsigned		alt_domain;
>   	u32			tiling_flags;
>   };
>   
> diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
> index a3dd04d..8223cf8 100644
> --- a/drivers/gpu/drm/radeon/radeon_cs.c
> +++ b/drivers/gpu/drm/radeon/radeon_cs.c
> @@ -53,6 +53,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
>   	}
>   	for (i = 0; i < p->nrelocs; i++) {
>   		struct drm_radeon_cs_reloc *r;
> +		uint32_t domain;
>   
>   		duplicate = false;
>   		r = (struct drm_radeon_cs_reloc *)&chunk->kdata[i*4];
> @@ -63,30 +64,36 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
>   				break;
>   			}
>   		}
> -		if (!duplicate) {
> -			p->relocs[i].gobj = drm_gem_object_lookup(ddev,
> -								  p->filp,
> -								  r->handle);
> -			if (p->relocs[i].gobj == NULL) {
> -				DRM_ERROR("gem object lookup failed 0x%x\n",
> -					  r->handle);
> -				return -ENOENT;
> -			}
> -			p->relocs_ptr[i] = &p->relocs[i];
> -			p->relocs[i].robj = gem_to_radeon_bo(p->relocs[i].gobj);
> -			p->relocs[i].lobj.bo = p->relocs[i].robj;
> -			p->relocs[i].lobj.wdomain = r->write_domain;
> -			p->relocs[i].lobj.rdomain = r->read_domains;
> -			p->relocs[i].lobj.tv.bo = &p->relocs[i].robj->tbo;
> -			p->relocs[i].handle = r->handle;
> -			p->relocs[i].flags = r->flags;
> -			radeon_bo_list_add_object(&p->relocs[i].lobj,
> -						  &p->validated);
> -
> -		} else
> +		if (duplicate) {
>   			p->relocs[i].handle = 0;
> +			continue;
> +		}
> +
> +		p->relocs[i].gobj = drm_gem_object_lookup(ddev, p->filp,
> +							  r->handle);
> +		if (p->relocs[i].gobj == NULL) {
> +			DRM_ERROR("gem object lookup failed 0x%x\n",
> +				  r->handle);
> +			return -ENOENT;
> +		}
> +		p->relocs_ptr[i] = &p->relocs[i];
> +		p->relocs[i].robj = gem_to_radeon_bo(p->relocs[i].gobj);
> +		p->relocs[i].lobj.bo = p->relocs[i].robj;
> +		p->relocs[i].lobj.written = !!r->write_domain;
> +
> +		domain = r->write_domain ? r->write_domain : r->read_domains;
> +		p->relocs[i].lobj.domain = domain;
> +		if (domain == RADEON_GEM_DOMAIN_VRAM)
> +			domain |= RADEON_GEM_DOMAIN_GTT;
> +		p->relocs[i].lobj.alt_domain = domain;
> +
> +		p->relocs[i].lobj.tv.bo = &p->relocs[i].robj->tbo;
> +		p->relocs[i].handle = r->handle;
> +
> +		radeon_bo_list_add_object(&p->relocs[i].lobj,
> +					  &p->validated);
>   	}
> -	return radeon_bo_list_validate(&p->validated);
> +	return radeon_bo_list_validate(&p->validated, p->ring);
>   }
>   
>   static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority)
> diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
> index d3aface..9633325 100644
> --- a/drivers/gpu/drm/radeon/radeon_object.c
> +++ b/drivers/gpu/drm/radeon/radeon_object.c
> @@ -339,7 +339,7 @@ void radeon_bo_fini(struct radeon_device *rdev)
>   void radeon_bo_list_add_object(struct radeon_bo_list *lobj,
>   				struct list_head *head)
>   {
> -	if (lobj->wdomain) {
> +	if (lobj->written) {
>   		list_add(&lobj->tv.head, head);
>   	} else {
>   		list_add_tail(&lobj->tv.head, head);
> @@ -360,15 +360,15 @@ int radeon_bo_list_validate(struct list_head *head)
>   	list_for_each_entry(lobj, head, tv.head) {
>   		bo = lobj->bo;
>   		if (!bo->pin_count) {
> -			domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain;
> +			domain = lobj->domain;
>   			
>   		retry:
>   			radeon_ttm_placement_from_domain(bo, domain);
>   			r = ttm_bo_validate(&bo->tbo, &bo->placement,
>   						true, false);
>   			if (unlikely(r)) {
> -				if (r != -ERESTARTSYS && domain == RADEON_GEM_DOMAIN_VRAM) {
> -					domain |= RADEON_GEM_DOMAIN_GTT;
> +				if (r != -ERESTARTSYS && domain != lobj->alt_domain) {
> +					domain = lobj->alt_domain;
>   					goto retry;
>   				}
>   				return r;
diff mbox

Patch

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 8263af3..7c2498c 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -357,8 +357,9 @@  struct radeon_bo_list {
 	struct ttm_validate_buffer tv;
 	struct radeon_bo	*bo;
 	uint64_t		gpu_offset;
-	unsigned		rdomain;
-	unsigned		wdomain;
+	bool			written;
+	unsigned		domain;
+	unsigned		alt_domain;
 	u32			tiling_flags;
 };
 
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index a3dd04d..8223cf8 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -53,6 +53,7 @@  static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
 	}
 	for (i = 0; i < p->nrelocs; i++) {
 		struct drm_radeon_cs_reloc *r;
+		uint32_t domain;
 
 		duplicate = false;
 		r = (struct drm_radeon_cs_reloc *)&chunk->kdata[i*4];
@@ -63,30 +64,36 @@  static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
 				break;
 			}
 		}
-		if (!duplicate) {
-			p->relocs[i].gobj = drm_gem_object_lookup(ddev,
-								  p->filp,
-								  r->handle);
-			if (p->relocs[i].gobj == NULL) {
-				DRM_ERROR("gem object lookup failed 0x%x\n",
-					  r->handle);
-				return -ENOENT;
-			}
-			p->relocs_ptr[i] = &p->relocs[i];
-			p->relocs[i].robj = gem_to_radeon_bo(p->relocs[i].gobj);
-			p->relocs[i].lobj.bo = p->relocs[i].robj;
-			p->relocs[i].lobj.wdomain = r->write_domain;
-			p->relocs[i].lobj.rdomain = r->read_domains;
-			p->relocs[i].lobj.tv.bo = &p->relocs[i].robj->tbo;
-			p->relocs[i].handle = r->handle;
-			p->relocs[i].flags = r->flags;
-			radeon_bo_list_add_object(&p->relocs[i].lobj,
-						  &p->validated);
-
-		} else
+		if (duplicate) {
 			p->relocs[i].handle = 0;
+			continue;
+		}
+
+		p->relocs[i].gobj = drm_gem_object_lookup(ddev, p->filp,
+							  r->handle);
+		if (p->relocs[i].gobj == NULL) {
+			DRM_ERROR("gem object lookup failed 0x%x\n",
+				  r->handle);
+			return -ENOENT;
+		}
+		p->relocs_ptr[i] = &p->relocs[i];
+		p->relocs[i].robj = gem_to_radeon_bo(p->relocs[i].gobj);
+		p->relocs[i].lobj.bo = p->relocs[i].robj;
+		p->relocs[i].lobj.written = !!r->write_domain;
+
+		domain = r->write_domain ? r->write_domain : r->read_domains;
+		p->relocs[i].lobj.domain = domain;
+		if (domain == RADEON_GEM_DOMAIN_VRAM)
+			domain |= RADEON_GEM_DOMAIN_GTT;
+		p->relocs[i].lobj.alt_domain = domain;
+
+		p->relocs[i].lobj.tv.bo = &p->relocs[i].robj->tbo;
+		p->relocs[i].handle = r->handle;
+
+		radeon_bo_list_add_object(&p->relocs[i].lobj,
+					  &p->validated);
 	}
-	return radeon_bo_list_validate(&p->validated);
+	return radeon_bo_list_validate(&p->validated, p->ring);
 }
 
 static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority)
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index d3aface..9633325 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -339,7 +339,7 @@  void radeon_bo_fini(struct radeon_device *rdev)
 void radeon_bo_list_add_object(struct radeon_bo_list *lobj,
 				struct list_head *head)
 {
-	if (lobj->wdomain) {
+	if (lobj->written) {
 		list_add(&lobj->tv.head, head);
 	} else {
 		list_add_tail(&lobj->tv.head, head);
@@ -360,15 +360,15 @@  int radeon_bo_list_validate(struct list_head *head)
 	list_for_each_entry(lobj, head, tv.head) {
 		bo = lobj->bo;
 		if (!bo->pin_count) {
-			domain = lobj->wdomain ? lobj->wdomain : lobj->rdomain;
+			domain = lobj->domain;
 			
 		retry:
 			radeon_ttm_placement_from_domain(bo, domain);
 			r = ttm_bo_validate(&bo->tbo, &bo->placement,
 						true, false);
 			if (unlikely(r)) {
-				if (r != -ERESTARTSYS && domain == RADEON_GEM_DOMAIN_VRAM) {
-					domain |= RADEON_GEM_DOMAIN_GTT;
+				if (r != -ERESTARTSYS && domain != lobj->alt_domain) {
+					domain = lobj->alt_domain;
 					goto retry;
 				}
 				return r;