drm/amdgpu: Remap hdp coherency registers
Subsystems (3)
PATCH 1/2 drm/amdgpu: Remap hdp coherency registers
Remap HDP_MEM_COHERENCY_FLUSH_CNTL and HDP_REG_COHERENCY_FLUSH_CNTL to an empty page in mmio space. We will later map this page to process space so application can flush hdp. This can't be done properly at those registers' original location because it will expose more than desired registers to process space.
v2: Use explicit register hole location
v3: Moved remapped hdp registers into adev struct
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/soc15.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8 -0
@@ -642,6 +642,13 @@ struct nbio_hdp_flush_reg {u32 ref_and_mask_sdma1; }; +struct remapped_hdp_reg { +u32 remapped_hdp_mem_flush_cntl_reg_offset; +u32 remapped_hdp_reg_flush_cntl_reg_offset; +resource_size_t remapped_hdp_mem_flush_cntl_physical_addr; +resource_size_t remapped_hdp_reg_flush_cntl_physical_addr; +}; +struct amdgpu_nbio_funcs {const struct nbio_hdp_flush_reg *hdp_flush_reg;u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
@@ -939,6 +946,7 @@ struct amdgpu_device {struct work_struct xgmi_reset_work;bool in_baco_reset; +struct remapped_hdp_reg remapped_hdp_reg; };static inline struct amdgpu_device *amdgpu_ttm_adev (struct ttm_bo_device *bdev)
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +2 -3
@@ -55,10 +55,9 @@ static void nbio_v7_0_hdp_flush(struct amdgpu_device *adev, struct amdgpu_ring *ring) {if (!ring || !ring->funcs->emit_wreg) -WREG32_SOC15_NO_KIQ (NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL,0 ); +WREG32_NO_KIQ (adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 );else -amdgpu_ring_emit_wreg (ring,SOC15_REG_OFFSET ( -NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL),0 ); +amdgpu_ring_emit_wreg (ring, adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 ); }static u32 nbio_v7_0_get_memsize (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +2 -3
@@ -53,10 +53,9 @@ static void nbio_v7_4_hdp_flush(struct amdgpu_device *adev, struct amdgpu_ring *ring) {if (!ring || !ring->funcs->emit_wreg) -WREG32_SOC15_NO_KIQ (NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL,0 ); +WREG32_NO_KIQ (adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 );else -amdgpu_ring_emit_wreg (ring,SOC15_REG_OFFSET ( -NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL),0 ); +amdgpu_ring_emit_wreg (ring, adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 ); }static u32 nbio_v7_4_get_memsize (struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/soc15.c +23 -0
@@ -44,6 +44,7 @@#include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" #include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_offset.h" #include "nbio/nbio_7_0_sh_mask.h" #include "nbio/nbio_7_0_smn.h" #include "mp/mp_9_0_offset.h"
@@ -775,6 +776,27 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .need_reset_on_init = &soc15_need_reset_on_init, }; +static void soc15_remap_hdp_coherency_registers (struct amdgpu_device *adev) +{ +#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE) +/* Remap hdp coherency registers to a hole in register space, +* for the purpose of mapping them to process space(so process +* can flush hdp) +*/ +WREG32_SOC15 (NBIO ,0 , mmREMAP_HDP_MEM_FLUSH_CNTL, +MMIO_REG_HOLE_OFFSET ); +WREG32_SOC15 (NBIO ,0 , mmREMAP_HDP_REG_FLUSH_CNTL, +MMIO_REG_HOLE_OFFSET +4 ); + adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset = + (MMIO_REG_HOLE_OFFSET ) >>2 ; + adev->remapped_hdp_reg.remapped_hdp_reg_flush_cntl_reg_offset = + (MMIO_REG_HOLE_OFFSET +4 ) >>2 ; + adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr = + adev->rmmio_base +MMIO_REG_HOLE_OFFSET ; + adev->remapped_hdp_reg.remapped_hdp_reg_flush_cntl_physical_addr = + adev->rmmio_base +MMIO_REG_HOLE_OFFSET +4 ; +} +static int soc15_common_early_init (void *handle) {struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -794,6 +816,7 @@ static int soc15_common_early_init(void *handle) adev->external_rev_id =0xFF ; +soc15_remap_hdp_coherency_registers (adev);switch (adev->asic_type) {case CHIP_VEGA10 : adev->asic_funcs = &soc15_asic_funcs;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1555510818-4016-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdkfd: Expose HDP registers to user space
Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH) and expose mmio page of HDP registers to user space through this new memory type.
v2: moved remapped hdp regs to adev struct
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ++++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++++ drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 1 + 6 files changed, 18 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +7 -0
@@ -482,6 +482,13 @@ uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)return adev->gmc.xgmi.hive_id; } +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev *kgd) +{ +struct amdgpu_device *adev = (struct amdgpu_device *)kgd; + +return adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr; +} +int amdgpu_amdkfd_submit_ib (struct kgd_dev *kgd,enum kgd_engine_type engine,uint32_t vmid,uint64_t gpu_addr,uint32_t *ib_cmd,uint32_t ib_len)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -154,6 +154,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd, uint32_t *flags);uint64_t amdgpu_amdkfd_get_vram_usage (struct kgd_dev *kgd);uint64_t amdgpu_amdkfd_get_hive_id (struct kgd_dev *kgd); +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev *kgd);#define read_user_wptr (mmptr, wptr, dst) \ ({ \
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -3
@@ -1087,7 +1087,8 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(if (!offset || !*offset)return -EINVAL ; user_addr = *offset; - }else if (flags &ALLOC_MEM_FLAGS_DOORBELL ) { + }else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | +ALLOC_MEM_FLAGS_HDP_FLUSH )) { domain =AMDGPU_GEM_DOMAIN_GTT ; alloc_domain =AMDGPU_GEM_DOMAIN_CPU ; bo_type = ttm_bo_type_sg;
@@ -1263,8 +1264,8 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(/* Free the sync object */ amdgpu_sync_free (&mem->sync); -/* If the SG is not NULL, it's one we created for a doorbell -* BO. We need to free it. +/* If the SG is not NULL, it's one we created for a doorbell or hdp +* flush BO. We need to free it. */ if (mem->bo->tbo.sg) {sg_free_table (mem->bo->tbo.sg);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -0
@@ -1272,6 +1272,10 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,if (args->size !=kfd_doorbell_process_slice (dev))return -EINVAL ; offset =kfd_get_process_doorbells (dev, p); + }else if (flags &KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH ) { +if (args->size !=PAGE_SIZE ) +return -EINVAL ; + offset =amdgpu_amdkfd_get_hdp_register_physical_addr (dev->kgd); }mutex_lock (&p->mutex);
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -0
@@ -186,6 +186,7 @@ struct tile_config {#define ALLOC_MEM_FLAGS_GTT (1 << 1)#define ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* * Allocation flags attributes/access options.
include/uapi/linux/kfd_ioctl.h +1 -0
@@ -338,6 +338,7 @@ struct kfd_ioctl_acquire_vm_args {#define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)#define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* Allocation flags: attributes/access options */ #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)#define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1555510818-4016-2-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org
RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
Quoted 11 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zeng, Oak
Sent: Wednesday, April 17, 2019 10:21 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zeng, Oak <[email protected]>; Keely, Sean <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user spaceIntroduce a new memory type (
KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH)
I'd suggest calling this something like ALLOC_MEM_FLAGS_MMIO_REMAP or something like that in case we end up needing to remap other registers in the future.
Alex
Quoted 128 lines
and expose mmio page of HDP registers to user space through this new memory type.
v2: moved remapped hdp regs to adev struct
Change-Id If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ++++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++++ drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 1 + 6 files changed, 18 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -482,6 +482,13 @@ uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)return adev->gmc.xgmi.hive_id; } +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd) { +struct amdgpu_device *adev = (struct amdgpu_device *)kgd; + +return +adev- >remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr; +} + int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum
kgd_engine_typeengine,drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-0uint32_t vmid, uint64_t gpu_addr, uint32_t *ib_cmd, uint32_t ib_len)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-0@@ -154,6 +154,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd, uint32_t *flags);uint64_t amdgpu_amdkfd_get_vram_usage (struct kgd_dev *kgd);uint64_t amdgpu_amdkfd_get_hive_id (struct kgd_dev *kgd); +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd);#define read_user_wptr (mmptr, wptr, dst) \ ({ \drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -1087,7 +1087,8 @@ intamdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1if (!offset || !*offset)return -EINVAL ; user_addr = *offset; - }else if (flags &ALLOC_MEM_FLAGS_DOORBELL ) { + }else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | +ALLOC_MEM_FLAGS_HDP_FLUSH )) { domain =AMDGPU_GEM_DOMAIN_GTT ; alloc_domain =AMDGPU_GEM_DOMAIN_CPU ; bo_type = ttm_bo_type_sg;@@ -1263,8 +1264,8 @@ intamdgpu_amdkfd_gpuvm_free_memory_of_gpu(
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-2/* Free the sync object */ amdgpu_sync_free (&mem->sync); -/* If the SG is not NULL, it's one we created for a doorbell -* BO. We need to free it. +/* If the SG is not NULL, it's one we created for a doorbell or hdp +* flush BO. We need to free it. */ if (mem->bo->tbo.sg) {sg_free_table (mem->bo->tbo.sg);drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4
-0@@ -1272,6 +1272,10 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep, if (args->size != kfd_doorbell_process_slice(dev)) return -EINVAL; offset =kfd_get_process_doorbells (dev, p); + }else if (flags &KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH ) { +if (args->size !=PAGE_SIZE ) +return -EINVAL ; + offset =amdgpu_amdkfd_get_hdp_register_physical_addr (dev->kgd); }drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0mutex_lock (&p->mutex);drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1
-0@@ -186,6 +186,7 @@ struct tile_config {#define ALLOC_MEM_FLAGS_GTT (1 << 1)#define ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* * Allocation flags attributes/access options. include/uapi/linux/kfd_ioctl.h +1
-1@@ -338,6 +338,7 @@ struct kfd_ioctl_acquire_vm_args {#define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)#define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* Allocation flags: attributes/access options */ #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)#define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30) --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BN6PR12MB1809963155D309C7B964175CF7250-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
Thanks, I agree. Will change it.
Regards,
Oak
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Deucher, Alexander
Sent: Wednesday, April 17, 2019 12:21 PM
To: Zeng, Oak <[email protected]>; [email protected]
Cc: Kuehling, Felix <[email protected]>; Zeng, Oak <[email protected]>; Keely, Sean <[email protected]>; Koenig, Christian <[email protected]>
Subject: RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
Quoted 11 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zeng, Oak
Sent: Wednesday, April 17, 2019 10:21 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zeng, Oak <[email protected]>; Keely, Sean <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user spaceIntroduce a new memory type (
KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH)
I'd suggest calling this something like ALLOC_MEM_FLAGS_MMIO_REMAP or something like that in case we end up needing to remap other registers in the future.
Alex
Quoted 128 lines
and expose mmio page of HDP registers to user space through this new memory type.
v2: moved remapped hdp regs to adev struct
Change-Id If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ++++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++++ drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 1 + 6 files changed, 18 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -482,6 +482,13 @@ uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)return adev->gmc.xgmi.hive_id; } +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd) { +struct amdgpu_device *adev = (struct amdgpu_device *)kgd; + +return +adev- >remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr; +} + int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_typeengine,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-0uint32_t vmid, uint64_t gpu_addr, uint32_t *ib_cmd, uint32_t ib_len) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e778679 100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-0@@ -154,6 +154,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd, uint32_t *flags);uint64_t amdgpu_amdkfd_get_vram_usage (struct kgd_dev *kgd);uint64_t amdgpu_amdkfd_get_hive_id (struct kgd_dev *kgd); +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd);#define read_user_wptr (mmptr, wptr, dst) \ ({ \drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -1087,7 +1087,8 @@ intamdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1if (!offset || !*offset)return -EINVAL ; user_addr = *offset; - }else if (flags &ALLOC_MEM_FLAGS_DOORBELL ) { + }else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | +ALLOC_MEM_FLAGS_HDP_FLUSH )) { domain =AMDGPU_GEM_DOMAIN_GTT ; alloc_domain =AMDGPU_GEM_DOMAIN_CPU ; bo_type = ttm_bo_type_sg;@@ -1263,8 +1264,8 @@ intamdgpu_amdkfd_gpuvm_free_memory_of_gpu(
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-2/* Free the sync object */ amdgpu_sync_free (&mem->sync); -/* If the SG is not NULL, it's one we created for a doorbell -* BO. We need to free it. +/* If the SG is not NULL, it's one we created for a doorbell or hdp +* flush BO. We need to free it. */ if (mem->bo->tbo.sg) {sg_free_table (mem->bo->tbo.sg);drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4
-0@@ -1272,6 +1272,10 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep, if (args->size != kfd_doorbell_process_slice(dev)) return -EINVAL; offset =kfd_get_process_doorbells (dev, p); + }else if (flags &KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH ) { +if (args->size !=PAGE_SIZE ) +return -EINVAL ; + offset =amdgpu_amdkfd_get_hdp_register_physical_addr (dev->kgd); }drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0
-0mutex_lock (&p->mutex);drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1
-0@@ -186,6 +186,7 @@ struct tile_config {#define ALLOC_MEM_FLAGS_GTT (1 << 1)#define ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* * Allocation flags attributes/access options. (quoted diff) +0
-0
b/include/uapi/linux/kfd_ioctl.hindex dc067ed..96afd01 100644include/uapi/linux/kfd_ioctl.h +1
-1@@ -338,6 +338,7 @@ struct kfd_ioctl_acquire_vm_args {#define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)#define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* Allocation flags: attributes/access options */ #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)#define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30) --2.7.4
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
In reply to a message not in the archiveQuoted 10 lines · Alexander
Quoted 10 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zeng, Oak
Sent: Wednesday, April 17, 2019 10:21 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Zeng, Oak <[email protected]>; Keely, Sean <[email protected]>; Koenig, Christian <[email protected]>
Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
Quoted 2 lines
Quoted 1 line
Introduce a new memory type (
KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH)I'd suggest calling this something like
ALLOC_MEM_FLAGS_MMIO_REMAPor something like that in case we end up needing to remap other registers in the future.
So that's assuming other registers would get remapped into the same page. Makes sense.
Regards,
Felix
Quoted 131 lines
Alex
Quoted 128 lines
and expose mmio page of HDP registers to user space through this new memory type.
v2: moved remapped hdp regs to adev struct
Change-Id If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 ++++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++++ drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 1 + 6 files changed, 18 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +8
-0@@ -482,6 +482,13 @@ uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)return adev->gmc.xgmi.hive_id; } +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd) { +struct amdgpu_device *adev = (struct amdgpu_device *)kgd; + +return +adev- > remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr; +} + int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum
kgd_engine_typeengine,
uint32_tvmid,uint64_tgpu_addr,uint32_t*ib_cmd,uint32_tib_len)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-0@@ -154,6 +154,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd, uint32_t *flags);uint64_t amdgpu_amdkfd_get_vram_usage (struct kgd_dev *kgd);uint64_t amdgpu_amdkfd_get_hive_id (struct kgd_dev *kgd); +uint64_t amdgpu_amdkfd_get_hdp_register_physical_addr (struct kgd_dev +*kgd);#define read_user_wptr (mmptr, wptr, dst) \ ({ \drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -1087,7 +1087,8 @@ intamdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
if (!offset || !*offset)
return-EINVAL;
user_addr= *offset;drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1- }else if (flags &ALLOC_MEM_FLAGS_DOORBELL ) { + }else if (flags & (ALLOC_MEM_FLAGS_DOORBELL | +ALLOC_MEM_FLAGS_HDP_FLUSH )) { domain =AMDGPU_GEM_DOMAIN_GTT ; alloc_domain =AMDGPU_GEM_DOMAIN_CPU ; bo_type = ttm_bo_type_sg;@@ -1263,8 +1264,8 @@ intamdgpu_amdkfd_gpuvm_free_memory_of_gpu(
/* Free the sync object */
amdgpu_sync_free(&mem->sync);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-2-/* If the SG is not NULL, it's one we created for a doorbell -* BO. We need to free it. +/* If the SG is not NULL, it's one we created for a doorbell or hdp +* flush BO. We need to free it. */ if (mem->bo->tbo.sg) {sg_free_table (mem->bo->tbo.sg);drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4
-0@@ -1272,6 +1272,10 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep, if (args->size != kfd_doorbell_process_slice(dev)) return -EINVAL; offset =kfd_get_process_doorbells (dev, p); + }else if (flags &KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH ) { +if (args->size !=PAGE_SIZE ) +return -EINVAL ; + offset =amdgpu_amdkfd_get_hdp_register_physical_addr (dev->kgd); }mutex_lock(&p->mutex);drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1
-0@@ -186,6 +186,7 @@ struct tile_config {#define ALLOC_MEM_FLAGS_GTT (1 << 1)#define ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* * Allocation flags attributes/access options. include/uapi/linux/kfd_ioctl.h +1
-1@@ -338,6 +338,7 @@ struct kfd_ioctl_acquire_vm_args {#define KFD_IOC_ALLOC_MEM_FLAGS_GTT (1 << 1)#define KFD_IOC_ALLOC_MEM_FLAGS_USERPTR (1 << 2)#define KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL (1 << 3) +#define KFD_IOC_ALLOC_MEM_FLAGS_HDP_FLUSH (1 << 4)/* Allocation flags: attributes/access options */ #define KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE (1 << 31)#define KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30) --2.7.4
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 23 lines · Oak
Remap
HDP_MEM_COHERENCY_FLUSH_CNTLandHDP_REG_COHERENCY_FLUSH_CNTLto an empty page in mmio space. We will later map this page to process space so application can flush hdp. This can't be done properly at those registers' original location because it will expose more than desired registers to process space.v2: Use explicit register hole location
v3: Moved remapped hdp registers into adev structChange-Id Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6Signed-off-by Oak Zeng <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/soc15.c | 23 +++++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct nbio_hdp_flush_reg { · line 647
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -642,6 +642,13 @@ struct nbio_hdp_flush_reg {u32 ref_and_mask_sdma1; }; +struct remapped_hdp_reg { +u32 remapped_hdp_mem_flush_cntl_reg_offset; +u32 remapped_hdp_reg_flush_cntl_reg_offset;
I think the offsets or indexes of the remapped register inside the remapped MMIO page should not be variable. We need an agreed convention between user mode and kernel mode, which register is mapped where. This will be part of the driver ABI that must be maintained for backwards compatibility. This should probably be defined in include/uapi/linux/kfd_ioctl.h as an enum or #define.
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct nbio_hdp_flush_reg { · line 650
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0+resource_size_t remapped_hdp_mem_flush_cntl_physical_addr; +resource_size_t remapped_hdp_reg_flush_cntl_physical_addr; +};
The variable names are a bit verbose.
Alex suggested in patch 2 to use a more generic name for the buffer type. Maybe a more generic name makes sense here too for any future mmio remappings. Maybe struct amdgpu_mmio_remap.
I don't think we need both the offset and the physical address. I don't see that we need the physical address of each remapped register. Your patch 2 only needs the physical address of the first remapped register, for the start address of the remapped MMIO page. So instead of adding the physical address of each register just add one member phys_addr (or bus_addr) that is the bus address of the remapped MMIO page.
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_device { · line 949
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+struct amdgpu_nbio_funcs {const struct nbio_hdp_flush_reg *hdp_flush_reg;u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);@@ -939,6 +946,7 @@ struct amdgpu_device {struct work_struct xgmi_reset_work;bool in_baco_reset; +struct remapped_hdp_reg remapped_hdp_reg;
Move this to just after the other mmio members in struct amdgpu_device and give it a more generic name like adev->rmmio_remap.
Quoted 50 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0};static inline struct amdgpu_device *amdgpu_ttm_adev (struct ttm_bo_device *bdev)drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +2
-3@@ -55,10 +55,9 @@ static void nbio_v7_0_hdp_flush(struct amdgpu_device *adev, struct amdgpu_ring *ring) {if (!ring || !ring->funcs->emit_wreg) -WREG32_SOC15_NO_KIQ (NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL,0 ); +WREG32_NO_KIQ (adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 );else -amdgpu_ring_emit_wreg (ring,SOC15_REG_OFFSET ( -NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL),0 ); +amdgpu_ring_emit_wreg (ring, adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 ); }static u32 nbio_v7_0_get_memsize (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +2
-3@@ -53,10 +53,9 @@ static void nbio_v7_4_hdp_flush(struct amdgpu_device *adev, struct amdgpu_ring *ring) {if (!ring || !ring->funcs->emit_wreg) -WREG32_SOC15_NO_KIQ (NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL,0 ); +WREG32_NO_KIQ (adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 );else -amdgpu_ring_emit_wreg (ring,SOC15_REG_OFFSET ( -NBIO ,0 , mmHDP_MEM_COHERENCY_FLUSH_CNTL),0 ); +amdgpu_ring_emit_wreg (ring, adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset,0 ); }static u32 nbio_v7_4_get_memsize (struct amdgpu_device *adev)drivers/gpu/drm/amd/amdgpu/soc15.c +1
-0@@ -44,6 +44,7 @@#include "smuio/smuio_9_0_offset.h" #include "smuio/smuio_9_0_sh_mask.h" #include "nbio/nbio_7_0_default.h" +#include "nbio/nbio_7_0_offset.h" #include "nbio/nbio_7_0_sh_mask.h" #include "nbio/nbio_7_0_smn.h" #include "mp/mp_9_0_offset.h"
drivers/gpu/drm/amd/amdgpu/soc15.c static const struct amdgpu_asic_funcs vega20_asic_funcs = · line 781
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +3
-0@@ -775,6 +776,27 @@ static const struct amdgpu_asic_funcs vega20_asic_funcs = .need_reset_on_init = &soc15_need_reset_on_init, }; +static void soc15_remap_hdp_coherency_registers (struct amdgpu_device *adev) +{ +#define MMIO_REG_HOLE_OFFSET (0x80000 - PAGE_SIZE)
This definition and the initialization of adev->rmmio_remap.bus_addr would belong in soc15.c or an ASIC-specific file, not an IP-specific file. The code below should only use adev->rmmio_remap and the offset definitions from kfd_ioctl.h to program the IP-specific remapping registers.
Regards,
Felix
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +18
-0+/* Remap hdp coherency registers to a hole in register space, +* for the purpose of mapping them to process space(so process +* can flush hdp) +*/ +WREG32_SOC15 (NBIO ,0 , mmREMAP_HDP_MEM_FLUSH_CNTL, +MMIO_REG_HOLE_OFFSET ); +WREG32_SOC15 (NBIO ,0 , mmREMAP_HDP_REG_FLUSH_CNTL, +MMIO_REG_HOLE_OFFSET +4 ); + adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_reg_offset = + (MMIO_REG_HOLE_OFFSET ) >>2 ; + adev->remapped_hdp_reg.remapped_hdp_reg_flush_cntl_reg_offset = + (MMIO_REG_HOLE_OFFSET +4 ) >>2 ; + adev->remapped_hdp_reg.remapped_hdp_mem_flush_cntl_physical_addr = + adev->rmmio_base +MMIO_REG_HOLE_OFFSET ; + adev->remapped_hdp_reg.remapped_hdp_reg_flush_cntl_physical_addr = + adev->rmmio_base +MMIO_REG_HOLE_OFFSET +4 ; +} +static int soc15_common_early_init (void *handle) {struct amdgpu_device *adev = (struct amdgpu_device *)handle;
drivers/gpu/drm/amd/amdgpu/soc15.c static int soc15_common_early_init(void *handle) · line 822
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/soc15.c +1
-0@@ -794,6 +816,7 @@ static int soc15_common_early_init(void *handle) adev->external_rev_id =0xFF ; +soc15_remap_hdp_coherency_registers (adev);switch (adev->asic_type) {case CHIP_VEGA10 : adev->asic_funcs = &soc15_asic_funcs;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx