<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 id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Revised accordingly, and pushed. Thanks!</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Yong</p>
</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> Kuehling, Felix<br>
<b>Sent:</b> Tuesday, October 23, 2018 4:37:45 PM<br>
<b>To:</b> Zhao, Yong; brahma_sw_dev; amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH 1/2] drm/amdgpu: Reorganize *_flush_gpu_tlb() for kfd to use</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">It occurred to me that the flush_type is a hardware-specific value, but<br>
you're using it in a hardware-abstracted interface. If the meaning of<br>
the flush type values changes in future HW-generations, we'll need to<br>
define an abstract enum that gets translated to the respective HW values<br>
in the HW-specific code.<br>
<br>
Anyway, this works for now.<br>
<br>
One more cosmetic comment inline ...<br>
<br>
Other than that the series is Reviewed-by: Felix Kuehling<br>
<Felix.Kuehling@amd.com><br>
<br>
Regards,<br>
  Felix<br>
<br>
On 2018-10-23 2:15 p.m., Zhao, Yong wrote:<br>
> Add a flush_type parameter to that series of functions.<br>
><br>
> Change-Id: I3dcd71955297c53b181f82e7078981230c642c01<br>
> Signed-off-by: Yong Zhao <Yong.Zhao@amd.com><br>
> ---<br>
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--<br>
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--<br>
>  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--<br>
>  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--<br>
>  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--<br>
>  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------<br>
>  6 files changed, 22 insertions(+), 19 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c<br>
> index 11fea28..9a212aa 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c<br>
> @@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,<br>
>        }<br>
>        mb();<br>
>        amdgpu_asic_flush_hdp(adev, NULL);<br>
> -     amdgpu_gmc_flush_gpu_tlb(adev, 0);<br>
> +     amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);<br>
>        return 0;<br>
>  }<br>
>  <br>
> @@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,<br>
>  <br>
>        mb();<br>
>        amdgpu_asic_flush_hdp(adev, NULL);<br>
> -     amdgpu_gmc_flush_gpu_tlb(adev, 0);<br>
> +     amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);<br>
>        return 0;<br>
>  }<br>
>  <br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h<br>
> index 6fa7ef4..4c5f18c 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h<br>
> @@ -64,7 +64,7 @@ struct amdgpu_vmhub {<br>
>  struct amdgpu_gmc_funcs {<br>
>        /* flush the vm tlb via mmio */<br>
>        void (*flush_gpu_tlb)(struct amdgpu_device *adev,<br>
> -                           uint32_t vmid);<br>
> +                           uint32_t vmid, uint32_t flush_type);<br>
>        /* flush the vm tlb via ring */<br>
>        uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,<br>
>                                       uint64_t pd_addr);<br>
> @@ -151,7 +151,7 @@ struct amdgpu_gmc {<br>
>        struct amdgpu_xgmi xgmi;<br>
>  };<br>
>  <br>
> -#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))<br>
> +#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))<br>
>  #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))<br>
>  #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))<br>
>  #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c<br>
> index e1c2b4e..2821d1d 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c<br>
> @@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)<br>
>        return 0;<br>
>  }<br>
>  <br>
> -static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)<br>
> +static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,<br>
> +                             uint32_t vmid, uint32_t flush_type)<br>
>  {<br>
>        WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);<br>
>  }<br>
> @@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)<br>
>        else<br>
>                gmc_v6_0_set_fault_enable_default(adev, true);<br>
>  <br>
> -     gmc_v6_0_flush_gpu_tlb(adev, 0);<br>
> +     gmc_v6_0_flush_gpu_tlb(adev, 0, 0);<br>
>        dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",<br>
>                 (unsigned)(adev->gmc.gart_size >> 20),<br>
>                 (unsigned long long)table_addr);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c<br>
> index 910c4ce..761dcfb 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c<br>
> @@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)<br>
>   *<br>
>   * Flush the TLB for the requested page table (CIK).<br>
>   */<br>
> -static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)<br>
> +static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,<br>
> +                             uint32_t vmid, uint32_t flush_type)<br>
>  {<br>
>        /* bits 0-15 are the VM contexts0-15 */<br>
>        WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);<br>
> @@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)<br>
>                WREG32(mmCHUB_CONTROL, tmp);<br>
>        }<br>
>  <br>
> -     gmc_v7_0_flush_gpu_tlb(adev, 0);<br>
> +     gmc_v7_0_flush_gpu_tlb(adev, 0, 0);<br>
>        DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",<br>
>                 (unsigned)(adev->gmc.gart_size >> 20),<br>
>                 (unsigned long long)table_addr);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c<br>
> index 1d3265c..531aaf3 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c<br>
> @@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)<br>
>   * Flush the TLB for the requested page table (CIK).<br>
>   */<br>
>  static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,<br>
> -                                     uint32_t vmid)<br>
> +                             uint32_t vmid, uint32_t flush_type)<br>
>  {<br>
>        /* bits 0-15 are the VM contexts0-15 */<br>
>        WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);<br>
> @@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)<br>
>        else<br>
>                gmc_v8_0_set_fault_enable_default(adev, true);<br>
>  <br>
> -     gmc_v8_0_flush_gpu_tlb(adev, 0);<br>
> +     gmc_v8_0_flush_gpu_tlb(adev, 0, 0);<br>
>        DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",<br>
>                 (unsigned)(adev->gmc.gart_size >> 20),<br>
>                 (unsigned long long)table_addr);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
> index f35d7a5..79d8a84 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
> @@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)<br>
>        adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;<br>
>  }<br>
>  <br>
> -static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)<br>
> +static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,<br>
> +                                     uint32_t flush_type)<br>
>  {<br>
>        u32 req = 0;<br>
>  <br>
>        /* invalidate using legacy mode on vmid*/<br>
<br>
This comment is no longer accurate.<br>
<br>
<br>
>        req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,<br>
>                            PER_VMID_INVALIDATE_REQ, 1 << vmid);<br>
> -     req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);<br>
> +     req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);<br>
>        req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);<br>
>        req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);<br>
>        req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);<br>
> @@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,<br>
>   */<br>
>  <br>
>  /**<br>
> - * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback<br>
> + * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type<br>
>   *<br>
>   * @adev: amdgpu_device pointer<br>
>   * @vmid: vm instance to flush<br>
> + * @flush_type: the flush type<br>
>   *<br>
> - * Flush the TLB for the requested page table.<br>
> + * Flush the TLB for the requested page table using certain type.<br>
>   */<br>
>  static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,<br>
> -                                     uint32_t vmid)<br>
> +                             uint32_t vmid, uint32_t flush_type)<br>
>  {<br>
> -     /* Use register 17 for GART */<br>
>        const unsigned eng = 17;<br>
>        unsigned i, j;<br>
>        int r;<br>
>  <br>
>        for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {<br>
>                struct amdgpu_vmhub *hub = &adev->vmhub[i];<br>
> -             u32 tmp = gmc_v9_0_get_invalidate_req(vmid);<br>
> +             u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);<br>
>  <br>
>                if (adev->gfx.kiq.ring.ready &&<br>
>                    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&<br>
> @@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,<br>
>  {<br>
>        struct amdgpu_device *adev = ring->adev;<br>
>        struct amdgpu_vmhub *hub = &adev->vmhub[ring->funcs->vmhub];<br>
> -     uint32_t req = gmc_v9_0_get_invalidate_req(vmid);<br>
> +     uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);<br>
>        unsigned eng = ring->vm_inv_eng;<br>
>  <br>
>        amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),<br>
> @@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)<br>
>  <br>
>        gfxhub_v1_0_set_fault_enable_default(adev, value);<br>
>        mmhub_v1_0_set_fault_enable_default(adev, value);<br>
> -     gmc_v9_0_flush_gpu_tlb(adev, 0);<br>
> +     gmc_v9_0_flush_gpu_tlb(adev, 0, 0);<br>
>  <br>
>        DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",<br>
>                 (unsigned)(adev->gmc.gart_size >> 20),<br>
</div>
</span></font></div>
</body>
</html>