<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Andrey Grodzovsky <andrey.grodzovsky@amd.com><br>
<b>Sent:</b> Friday, July 26, 2019 9:28 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com>; michel@daenzer.net <michel@daenzer.net>; Koenig, Christian <Christian.Koenig@amd.com>; S, Shirish <Shirish.S@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: Fix amdgpu_display_supported_domains logic.</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Add restriction to dissallow GTT domain if the relevant BO<br>
doesn't have USWC flag set to avoid the APU hang scenario.<br>
<br>
Signed-off-by: Andrey Grodzovsky <andrey.grodzovsky@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       | 16 +++++++++++-----<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.h       |  3 ++-<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c       |  2 +-<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c            | 12 ++++++------<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c           |  2 +-<br>
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  2 +-<br>
 6 files changed, 22 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
index 73045a3..4a8b1b1 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
@@ -189,7 +189,8 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,<br>
         }<br>
 <br>
         if (!adev->enable_virtual_display) {<br>
-               r = amdgpu_bo_pin(new_abo, amdgpu_display_supported_domains(adev));<br>
+               r = amdgpu_bo_pin(new_abo,<br>
+                                 amdgpu_display_supported_domains(adev, new_abo->flags));<br>
                 if (unlikely(r != 0)) {<br>
                         DRM_ERROR("failed to pin new abo buffer before flip\n");<br>
                         goto unreserve;<br>
@@ -493,20 +494,25 @@ static const struct drm_framebuffer_funcs amdgpu_fb_funcs = {<br>
         .create_handle = drm_gem_fb_create_handle,<br>
 };<br>
 <br>
-uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev)<br>
+uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev,<br>
+                                         uint64_t bo_flags)<br>
 {<br>
         uint32_t domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
 <br>
 #if defined(CONFIG_DRM_AMD_DC)<br>
         /*<br>
-        * if amdgpu_bo_validate_uswc returns false it means that USWC mappings<br>
+        * if amdgpu_bo_support_uswc returns false it means that USWC mappings<br>
          * is not supported for this board. But this mapping is required<br>
          * to avoid hang caused by placement of scanout BO in GTT on certain<br>
          * APUs. So force the BO placement to VRAM in case this architecture<br>
          * will not allow USWC mappings.<br>
+        * Also, don't allow GTT domain if the BO doens't have USWC falg set.<br>
          */<br>
-       if (adev->asic_type >= CHIP_CARRIZO && adev->asic_type <= CHIP_RAVEN &&<br>
-           adev->flags & AMD_IS_APU && amdgpu_bo_support_uswc(0) &&<br>
+       if (adev->asic_type >= CHIP_CARRIZO &&<br>
+           adev->asic_type <= CHIP_RAVEN &&<br>
+           (adev->flags & AMD_IS_APU) &&<br>
+           (bo_flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC) &&<br>
+           amdgpu_bo_support_uswc(bo_flags) &&<br>
             amdgpu_device_asic_has_dc_support(adev->asic_type))<br>
                 domain |= AMDGPU_GEM_DOMAIN_GTT;<br>
 #endif<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.h<br>
index 06b922f..3620b24 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.h<br>
@@ -38,7 +38,8 @@<br>
 int amdgpu_display_freesync_ioctl(struct drm_device *dev, void *data,<br>
                                   struct drm_file *filp);<br>
 void amdgpu_display_update_priority(struct amdgpu_device *adev);<br>
-uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev);<br>
+uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev,<br>
+                                         uint64_t bo_flags);<br>
 struct drm_framebuffer *<br>
 amdgpu_display_user_framebuffer_create(struct drm_device *dev,<br>
                                        struct drm_file *file_priv,<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c<br>
index 4711cf1..6770eb3 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c<br>
@@ -301,7 +301,7 @@ static int amdgpu_dma_buf_begin_cpu_access(struct dma_buf *dma_buf,<br>
         struct amdgpu_bo *bo = gem_to_amdgpu_bo(dma_buf->priv);<br>
         struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);<br>
         struct ttm_operation_ctx ctx = { true, false };<br>
-       u32 domain = amdgpu_display_supported_domains(adev);<br>
+       u32 domain = amdgpu_display_supported_domains(adev, bo->flags);<br>
         int ret;<br>
         bool reads = (direction == DMA_BIDIRECTIONAL ||<br>
                       direction == DMA_FROM_DEVICE);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
index bf0c61b..4a6f29e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
@@ -130,21 +130,21 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,<br>
         int aligned_size, size;<br>
         int height = mode_cmd->height;<br>
         u32 cpp;<br>
+       u64 flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |<br>
+                              AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS     |<br>
+                              AMDGPU_GEM_CREATE_VRAM_CLEARED          |<br>
+                              AMDGPU_GEM_CREATE_CPU_GTT_USWC;<br>
 <br>
         cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0);<br>
 <br>
         /* need to align pitch with crtc limits */<br>
         mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp,<br>
                                                   fb_tiled);<br>
-       domain = amdgpu_display_supported_domains(adev);<br>
+       domain = amdgpu_display_supported_domains(adev, flags);<br>
         height = ALIGN(mode_cmd->height, 8);<br>
         size = mode_cmd->pitches[0] * height;<br>
         aligned_size = ALIGN(size, PAGE_SIZE);<br>
-       ret = amdgpu_gem_object_create(adev, aligned_size, 0, domain,<br>
-                                      AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |<br>
-                                      AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS     |<br>
-                                      AMDGPU_GEM_CREATE_VRAM_CLEARED          |<br>
-                                      AMDGPU_GEM_CREATE_CPU_GTT_USWC,<br>
+       ret = amdgpu_gem_object_create(adev, aligned_size, 0, domain, flags,<br>
                                        ttm_bo_type_kernel, NULL, &gobj);<br>
         if (ret) {<br>
                 pr_err("failed to allocate framebuffer (%d)\n", aligned_size);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
index eeed089..e7af35c 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c<br>
@@ -761,7 +761,7 @@ int amdgpu_mode_dumb_create(struct drm_file *file_priv,<br>
         args->size = (u64)args->pitch * args->height;<br>
         args->size = ALIGN(args->size, PAGE_SIZE);<br>
         domain = amdgpu_bo_get_preferred_pin_domain(adev,<br>
-                               amdgpu_display_supported_domains(adev));<br>
+                               amdgpu_display_supported_domains(adev, flags));<br>
         r = amdgpu_gem_object_create(adev, args->size, 0, domain, flags,<br>
                                      ttm_bo_type_device, NULL, &gobj);<br>
         if (r)<br>
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
index 066f04b..0401691 100644<br>
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
@@ -4414,7 +4414,7 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,<br>
         }<br>
 <br>
         if (plane->type != DRM_PLANE_TYPE_CURSOR)<br>
-               domain = amdgpu_display_supported_domains(adev);<br>
+               domain = amdgpu_display_supported_domains(adev, rbo->flags);<br>
         else<br>
                 domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
 <br>
-- <br>
2.7.4<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>