<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <br>
    <br>
    <div class="moz-cite-prefix">Am 15.08.24 um 02:04 schrieb Alex
      Deucher:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">From: Srinivasan Shanmugam <a class="moz-txt-link-rfc2396E" href="mailto:srinivasan.shanmugam@amd.com"><srinivasan.shanmugam@amd.com></a>

The cleaner shader is used by the CP firmware to clean LDS and GPRs
between processes on the CUs.

This adds an internal API for GFX IP code to allocate and initialize the
cleaner shader.

Cc: Christian König <a class="moz-txt-link-rfc2396E" href="mailto:christian.koenig@amd.com"><christian.koenig@amd.com></a>
Cc: Alex Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexander.deucher@amd.com"><alexander.deucher@amd.com></a>
Signed-off-by: Alex Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexander.deucher@amd.com"><alexander.deucher@amd.com></a>
Signed-off-by: Srinivasan Shanmugam <a class="moz-txt-link-rfc2396E" href="mailto:srinivasan.shanmugam@amd.com"><srinivasan.shanmugam@amd.com></a>
Suggested-by: Christian König <a class="moz-txt-link-rfc2396E" href="mailto:christian.koenig@amd.com"><christian.koenig@amd.com></a>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 35 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 14 ++++++++++
 2 files changed, 49 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 9be8cafdcecc..4ed69fcfe9c1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -1416,3 +1416,38 @@ void amdgpu_gfx_sysfs_fini(struct amdgpu_device *adev)
        device_remove_file(adev->dev, &dev_attr_current_compute_partition);
        device_remove_file(adev->dev, &dev_attr_available_compute_partition);
 }
+
+int amdgpu_gfx_cleaner_shader_sw_init(struct amdgpu_device *adev,
+                                     unsigned int cleaner_shader_size)
+{
+       if (!adev->gfx.enable_cleaner_shader)
+               return -EOPNOTSUPP;</pre>
    </blockquote>
    <br>
    It's probably better to not call the function in the first place
    instead of returning an error.<br>
    <br>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">
+
+       return amdgpu_bo_create_kernel(adev, cleaner_shader_size, PAGE_SIZE,
+                                      AMDGPU_GEM_DOMAIN_VRAM | AMDGPU_GEM_DOMAIN_GTT,
+                                      &adev->gfx.cleaner_shader_obj,
+                                      &adev->gfx.cleaner_shader_gpu_addr,
+                                      (void **)&adev->gfx.cleaner_shader_cpu_ptr);
+}
+
+void amdgpu_gfx_cleaner_shader_sw_fini(struct amdgpu_device *adev)
+{
+       if (!adev->gfx.enable_cleaner_shader)
+               return;
+
+       amdgpu_bo_free_kernel(&adev->gfx.cleaner_shader_obj,
+                             &adev->gfx.cleaner_shader_gpu_addr,
+                             (void **)&adev->gfx.cleaner_shader_cpu_ptr);
+}
+
+void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
+                                   unsigned int cleaner_shader_size,
+                                   const void *cleaner_shader_ptr)
+{
+       if (!adev->gfx.enable_cleaner_shader)
+               return;
+
+       if (adev->gfx.cleaner_shader_cpu_ptr && cleaner_shader_ptr)
+               memcpy_toio(adev->gfx.cleaner_shader_cpu_ptr, cleaner_shader_ptr,
+                           cleaner_shader_size);
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 6fe77e483bb7..5ff3ab7d429a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -444,6 +444,14 @@ struct amdgpu_gfx {
        uint32_t                        *ip_dump_core;
        uint32_t                        *ip_dump_compute_queues;
        uint32_t                        *ip_dump_gfx_queues;
+
+       /* cleaner shader */
+       struct amdgpu_bo                *cleaner_shader_obj;</pre>
    </blockquote>
    <span style="white-space: pre-wrap">
</span>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">+    unsigned int                    cleaner_shader_size;</pre>
    </blockquote>
    This is a parameter now and the member unused.<br>
    <br>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">
+       u64                             cleaner_shader_gpu_addr;
+       void                            *cleaner_shader_cpu_ptr;
+       const void                      *cleaner_shader_ptr;</pre>
    </blockquote>
    <br>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">
+       bool                            enable_cleaner_shader;</pre>
    </blockquote>
    Probably better to test if cleaner_shader_obj is allocated or not
    instead of having a separate bool.<br>
    <br>
    Regards,<br>
    Christian.<br>
    <br>
    <blockquote type="cite"
      cite="mid:20240815000501.1845226-3-alexander.deucher@amd.com">
      <pre class="moz-quote-pre" wrap="">
 };
 
 struct amdgpu_gfx_ras_reg_entry {
@@ -545,6 +553,12 @@ void amdgpu_gfx_ras_error_func(struct amdgpu_device *adev,
                void *ras_error_status,
                void (*func)(struct amdgpu_device *adev, void *ras_error_status,
                                int xcc_id));
+int amdgpu_gfx_cleaner_shader_sw_init(struct amdgpu_device *adev,
+                                     unsigned int cleaner_shader_size);
+void amdgpu_gfx_cleaner_shader_sw_fini(struct amdgpu_device *adev);
+void amdgpu_gfx_cleaner_shader_init(struct amdgpu_device *adev,
+                                   unsigned int cleaner_shader_size,
+                                   const void *cleaner_shader_ptr);
 
 static inline const char *amdgpu_gfx_compute_mode_desc(int mode)
 {
</pre>
    </blockquote>
    <br>
  </body>
</html>