AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
@ 2019-04-11 20:31 Zeng, Oak
       [not found] ` <1555014669-30077-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Zeng, Oak @ 2019-04-11 20:31 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean

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.

Change-Id: Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  6 +++++-
 drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c |  7 +++----
 drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c |  7 +++----
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h |  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.c     | 22 ++++++++++++++++++++++
 8 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index bc96ec4..840be05 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -644,6 +644,10 @@ struct nbio_hdp_flush_reg {
 
 struct amdgpu_nbio_funcs {
 	const struct nbio_hdp_flush_reg *hdp_flush_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;
 	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
 	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
 	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
@@ -905,7 +909,7 @@ struct amdgpu_device {
 	/* soc15 register offset based on ip, instance and  segment */
 	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
 
-	const struct amdgpu_nbio_funcs	*nbio_funcs;
+	struct amdgpu_nbio_funcs	*nbio_funcs;
 	const struct amdgpu_df_funcs	*df_funcs;
 
 	/* delayed work_func for deferring clockgating during resume */
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
index 6590143..2470b8e 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
@@ -276,7 +276,7 @@ static void nbio_v6_1_init_registers(struct amdgpu_device *adev)
 		WREG32_PCIE(smnPCIE_CI_CNTL, data);
 }
 
-const struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
+struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
 	.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg,
 	.get_hdp_flush_req_offset = nbio_v6_1_get_hdp_flush_req_offset,
 	.get_hdp_flush_done_offset = nbio_v6_1_get_hdp_flush_done_offset,
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
index 0743a6f..d409bb6 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
@@ -26,6 +26,6 @@
 
 #include "soc15_common.h"
 
-extern const struct amdgpu_nbio_funcs nbio_v6_1_funcs;
+extern struct amdgpu_nbio_funcs nbio_v6_1_funcs;
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
index 1cdb98a..9a5abf5 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
@@ -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->nbio_funcs->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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
 }
 
 static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev)
@@ -263,7 +262,7 @@ static void nbio_v7_0_init_registers(struct amdgpu_device *adev)
 
 }
 
-const struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
+struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
 	.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg,
 	.get_hdp_flush_req_offset = nbio_v7_0_get_hdp_flush_req_offset,
 	.get_hdp_flush_done_offset = nbio_v7_0_get_hdp_flush_done_offset,
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
index 508d549..db50618 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
@@ -26,6 +26,6 @@
 
 #include "soc15_common.h"
 
-extern const struct amdgpu_nbio_funcs nbio_v7_0_funcs;
+extern struct amdgpu_nbio_funcs nbio_v7_0_funcs;
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
index c69d515..25203cc 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
@@ -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->nbio_funcs->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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
 }
 
 static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev)
@@ -242,7 +241,7 @@ static void nbio_v7_4_init_registers(struct amdgpu_device *adev)
 		WREG32_PCIE(smnPCIE_CI_CNTL, data);
 }
 
-const struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
+struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
 	.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg,
 	.get_hdp_flush_req_offset = nbio_v7_4_get_hdp_flush_req_offset,
 	.get_hdp_flush_done_offset = nbio_v7_4_get_hdp_flush_done_offset,
diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
index c442865..2e5bb03 100644
--- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
+++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
@@ -26,6 +26,6 @@
 
 #include "soc15_common.h"
 
-extern const struct amdgpu_nbio_funcs nbio_v7_4_funcs;
+extern struct amdgpu_nbio_funcs nbio_v7_4_funcs;
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
index bdb5ad9..c47e7a5 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -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,26 @@ 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)
+{
+	/* Remap hdp coherency registers to the last page of mmio
+	 * space, for the purpose of mapping them to process space(
+	 * so process can flush hdp)
+	 */
+	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_MEM_FLUSH_CNTL,
+			adev->rmmio_size - PAGE_SIZE);
+	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_REG_FLUSH_CNTL,
+			adev->rmmio_size - PAGE_SIZE + 4);
+	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset =
+			(adev->rmmio_size - PAGE_SIZE) >> 2;
+	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_reg_offset =
+			(adev->rmmio_size - PAGE_SIZE + 4) >> 2;
+	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_physical_addr =
+			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE;
+	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_physical_addr =
+			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE + 4;
+}
+
 static int soc15_common_early_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -794,6 +815,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;
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found] ` <1555014669-30077-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-11 20:31   ` Zeng, Oak
  2019-04-12  7:23   ` [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Christian König
  1 sibling, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-11 20:31 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean

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.

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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         | 2 ++
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  | 1 +
 include/uapi/linux/kfd_ioctl.h                   | 1 +
 6 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..d844f0c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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->nbio_funcs->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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e778679 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..4394f61 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..f08bdce 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1272,6 +1272,8 @@ 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) {
+		offset = amdgpu_amdkfd_get_hdp_register_physical_addr(dev->kgd);
 	}
 
 	mutex_lock(&p->mutex);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3bc78b26 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index dc067ed..96afd01 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
       [not found] ` <1555014669-30077-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
  2019-04-11 20:31   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak
@ 2019-04-12  7:23   ` Christian König
       [not found]     ` <9cc46562-129b-5e1f-14a9-6244ede19f3e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 14+ messages in thread
From: Christian König @ 2019-04-12  7:23 UTC (permalink / raw)
  To: Zeng, Oak,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Keely, Sean

Am 11.04.19 um 22:31 schrieb Zeng, Oak:
> 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.
>
> Change-Id: Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6
> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  6 +++++-
>   drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c |  7 +++----
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c |  7 +++----
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/soc15.c     | 22 ++++++++++++++++++++++
>   8 files changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index bc96ec4..840be05 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -644,6 +644,10 @@ struct nbio_hdp_flush_reg {
>   
>   struct amdgpu_nbio_funcs {
>   	const struct nbio_hdp_flush_reg *hdp_flush_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;
>   	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
>   	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
>   	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev);
> @@ -905,7 +909,7 @@ struct amdgpu_device {
>   	/* soc15 register offset based on ip, instance and  segment */
>   	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
>   
> -	const struct amdgpu_nbio_funcs	*nbio_funcs;
> +	struct amdgpu_nbio_funcs	*nbio_funcs;

Please kep the function pointers constant. Those should never be changed 
on a running system.

Christian.

>   	const struct amdgpu_df_funcs	*df_funcs;
>   
>   	/* delayed work_func for deferring clockgating during resume */
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> index 6590143..2470b8e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> @@ -276,7 +276,7 @@ static void nbio_v6_1_init_registers(struct amdgpu_device *adev)
>   		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
> +struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>   	.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v6_1_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v6_1_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> index 0743a6f..d409bb6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v6_1_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> index 1cdb98a..9a5abf5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> @@ -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->nbio_funcs->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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>   }
>   
>   static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev)
> @@ -263,7 +262,7 @@ static void nbio_v7_0_init_registers(struct amdgpu_device *adev)
>   
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
> +struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>   	.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v7_0_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v7_0_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> index 508d549..db50618 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v7_0_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> index c69d515..25203cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> @@ -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->nbio_funcs->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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>   }
>   
>   static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev)
> @@ -242,7 +241,7 @@ static void nbio_v7_4_init_registers(struct amdgpu_device *adev)
>   		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
> +struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>   	.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v7_4_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v7_4_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> index c442865..2e5bb03 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v7_4_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
> index bdb5ad9..c47e7a5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
> @@ -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,26 @@ 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)
> +{
> +	/* Remap hdp coherency registers to the last page of mmio
> +	 * space, for the purpose of mapping them to process space(
> +	 * so process can flush hdp)
> +	 */
> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_MEM_FLUSH_CNTL,
> +			adev->rmmio_size - PAGE_SIZE);
> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_REG_FLUSH_CNTL,
> +			adev->rmmio_size - PAGE_SIZE + 4);
> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset =
> +			(adev->rmmio_size - PAGE_SIZE) >> 2;
> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_reg_offset =
> +			(adev->rmmio_size - PAGE_SIZE + 4) >> 2;
> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_physical_addr =
> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE;
> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_physical_addr =
> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE + 4;
> +}
> +
>   static int soc15_common_early_init(void *handle)
>   {
>   	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
> @@ -794,6 +815,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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
       [not found]     ` <9cc46562-129b-5e1f-14a9-6244ede19f3e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2019-04-12 15:39       ` Zeng, Oak
       [not found]         ` <BL0PR12MB25804A7060A56A0EAD36D97180280-b4cIHhjg/p/XzH18dTCKOgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Zeng, Oak @ 2019-04-12 15:39 UTC (permalink / raw)
  To: Koenig, Christian,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Keely, Sean

Hi Christian,

After hdp registers are moved to a new place in mmio space, we can't access those registers through the pre-defined register offset. I recorded the new register offset in struct amdgpu_nbio_funcs (because those registers are nbio registers) and initialized them in the early init. After those changes, I can't keep instance of struct amdgpu_nbio_funcs to be constant anymore - we don't know the new register offset before the remap function. When I made the change, I also felt not comfortable. Do you have any better solution? Introduce new r/w members directly to adev? - I also feel not comfortable because those registers I added belongs to nbio by nature...

Regards,
Oak

-----Original Message-----
From: Christian König <ckoenig.leichtzumerken@gmail.com> 
Sent: Friday, April 12, 2019 3:24 AM
To: Zeng, Oak <Oak.Zeng@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix <Felix.Kuehling@amd.com>; Keely, Sean <Sean.Keely@amd.com>
Subject: Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers

Am 11.04.19 um 22:31 schrieb Zeng, Oak:
> 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.
>
> Change-Id: Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6
> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  6 +++++-
>   drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c |  7 +++----
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c |  7 +++----
>   drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h |  2 +-
>   drivers/gpu/drm/amd/amdgpu/soc15.c     | 22 ++++++++++++++++++++++
>   8 files changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index bc96ec4..840be05 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -644,6 +644,10 @@ struct nbio_hdp_flush_reg {
>   
>   struct amdgpu_nbio_funcs {
>   	const struct nbio_hdp_flush_reg *hdp_flush_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;
>   	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
>   	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
>   	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev); @@ -905,7 
> +909,7 @@ struct amdgpu_device {
>   	/* soc15 register offset based on ip, instance and  segment */
>   	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
>   
> -	const struct amdgpu_nbio_funcs	*nbio_funcs;
> +	struct amdgpu_nbio_funcs	*nbio_funcs;

Please kep the function pointers constant. Those should never be changed on a running system.

Christian.

>   	const struct amdgpu_df_funcs	*df_funcs;
>   
>   	/* delayed work_func for deferring clockgating during resume */ 
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> index 6590143..2470b8e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
> @@ -276,7 +276,7 @@ static void nbio_v6_1_init_registers(struct amdgpu_device *adev)
>   		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
> +struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>   	.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v6_1_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v6_1_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> index 0743a6f..d409bb6 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v6_1_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> index 1cdb98a..9a5abf5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offse
> +t, 0);
>   	else
> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
> +		amdgpu_ring_emit_wreg(ring, 
> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>   }
>   
>   static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev) @@ 
> -263,7 +262,7 @@ static void nbio_v7_0_init_registers(struct 
> amdgpu_device *adev)
>   
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
> +struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>   	.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v7_0_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v7_0_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> index 508d549..db50618 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v7_0_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> index c69d515..25203cc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offse
> +t, 0);
>   	else
> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
> +		amdgpu_ring_emit_wreg(ring, 
> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>   }
>   
>   static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev) @@ 
> -242,7 +241,7 @@ static void nbio_v7_4_init_registers(struct amdgpu_device *adev)
>   		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>   }
>   
> -const struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
> +struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>   	.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg,
>   	.get_hdp_flush_req_offset = nbio_v7_4_get_hdp_flush_req_offset,
>   	.get_hdp_flush_done_offset = nbio_v7_4_get_hdp_flush_done_offset,
> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h 
> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> index c442865..2e5bb03 100644
> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
> @@ -26,6 +26,6 @@
>   
>   #include "soc15_common.h"
>   
> -extern const struct amdgpu_nbio_funcs nbio_v7_4_funcs;
> +extern struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>   
>   #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
> b/drivers/gpu/drm/amd/amdgpu/soc15.c
> index bdb5ad9..c47e7a5 100644
> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
> @@ -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,26 @@ 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) {
> +	/* Remap hdp coherency registers to the last page of mmio
> +	 * space, for the purpose of mapping them to process space(
> +	 * so process can flush hdp)
> +	 */
> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_MEM_FLUSH_CNTL,
> +			adev->rmmio_size - PAGE_SIZE);
> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_REG_FLUSH_CNTL,
> +			adev->rmmio_size - PAGE_SIZE + 4);
> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset =
> +			(adev->rmmio_size - PAGE_SIZE) >> 2;
> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_reg_offset =
> +			(adev->rmmio_size - PAGE_SIZE + 4) >> 2;
> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_physical_addr =
> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE;
> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_physical_addr =
> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE + 4; }
> +
>   static int soc15_common_early_init(void *handle)
>   {
>   	struct amdgpu_device *adev = (struct amdgpu_device *)handle; @@ 
> -794,6 +815,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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
       [not found]         ` <BL0PR12MB25804A7060A56A0EAD36D97180280-b4cIHhjg/p/XzH18dTCKOgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-04-15  8:06           ` Koenig, Christian
       [not found]             ` <677f9d24-2c03-bf30-7bb6-0e57a38f158d-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Koenig, Christian @ 2019-04-15  8:06 UTC (permalink / raw)
  To: Zeng, Oak,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Keely, Sean

Hi Oak,

well, we make the function pointer structures constant is exactly to 
prevent those scenarios.

Background is that multiple GPU can use the same function pointer 
structure, but with different register offsets. So what you do here is 
actually illegal and could break in some cases.

Easiest solution would indeed be to add a new stuff directly to the 
adev, probably best encapsulated in a new structure.

Regards,
Christian.

Am 12.04.19 um 17:39 schrieb Zeng, Oak:
> Hi Christian,
>
> After hdp registers are moved to a new place in mmio space, we can't access those registers through the pre-defined register offset. I recorded the new register offset in struct amdgpu_nbio_funcs (because those registers are nbio registers) and initialized them in the early init. After those changes, I can't keep instance of struct amdgpu_nbio_funcs to be constant anymore - we don't know the new register offset before the remap function. When I made the change, I also felt not comfortable. Do you have any better solution? Introduce new r/w members directly to adev? - I also feel not comfortable because those registers I added belongs to nbio by nature...
>
> Regards,
> Oak
>
> -----Original Message-----
> From: Christian König <ckoenig.leichtzumerken@gmail.com>
> Sent: Friday, April 12, 2019 3:24 AM
> To: Zeng, Oak <Oak.Zeng@amd.com>; amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix <Felix.Kuehling@amd.com>; Keely, Sean <Sean.Keely@amd.com>
> Subject: Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
>
> Am 11.04.19 um 22:31 schrieb Zeng, Oak:
>> 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.
>>
>> Change-Id: Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6
>> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
>> ---
>>    drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  6 +++++-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c |  7 +++----
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c |  7 +++----
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/soc15.c     | 22 ++++++++++++++++++++++
>>    8 files changed, 37 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index bc96ec4..840be05 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -644,6 +644,10 @@ struct nbio_hdp_flush_reg {
>>    
>>    struct amdgpu_nbio_funcs {
>>    	const struct nbio_hdp_flush_reg *hdp_flush_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;
>>    	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
>>    	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
>>    	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev); @@ -905,7
>> +909,7 @@ struct amdgpu_device {
>>    	/* soc15 register offset based on ip, instance and  segment */
>>    	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
>>    
>> -	const struct amdgpu_nbio_funcs	*nbio_funcs;
>> +	struct amdgpu_nbio_funcs	*nbio_funcs;
> Please kep the function pointers constant. Those should never be changed on a running system.
>
> Christian.
>
>>    	const struct amdgpu_df_funcs	*df_funcs;
>>    
>>    	/* delayed work_func for deferring clockgating during resume */
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> index 6590143..2470b8e 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> @@ -276,7 +276,7 @@ static void nbio_v6_1_init_registers(struct amdgpu_device *adev)
>>    		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>>    	.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v6_1_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v6_1_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> index 0743a6f..d409bb6 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> index 1cdb98a..9a5abf5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offse
>> +t, 0);
>>    	else
>> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
>> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
>> +		amdgpu_ring_emit_wreg(ring,
>> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>>    }
>>    
>>    static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev) @@
>> -263,7 +262,7 @@ static void nbio_v7_0_init_registers(struct
>> amdgpu_device *adev)
>>    
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>>    	.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v7_0_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v7_0_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> index 508d549..db50618 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> index c69d515..25203cc 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offse
>> +t, 0);
>>    	else
>> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
>> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
>> +		amdgpu_ring_emit_wreg(ring,
>> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>>    }
>>    
>>    static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev) @@
>> -242,7 +241,7 @@ static void nbio_v7_4_init_registers(struct amdgpu_device *adev)
>>    		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>>    	.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v7_4_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v7_4_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> index c442865..2e5bb03 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c
>> b/drivers/gpu/drm/amd/amdgpu/soc15.c
>> index bdb5ad9..c47e7a5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
>> @@ -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,26 @@ 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) {
>> +	/* Remap hdp coherency registers to the last page of mmio
>> +	 * space, for the purpose of mapping them to process space(
>> +	 * so process can flush hdp)
>> +	 */
>> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_MEM_FLUSH_CNTL,
>> +			adev->rmmio_size - PAGE_SIZE);
>> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_REG_FLUSH_CNTL,
>> +			adev->rmmio_size - PAGE_SIZE + 4);
>> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset =
>> +			(adev->rmmio_size - PAGE_SIZE) >> 2;
>> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_reg_offset =
>> +			(adev->rmmio_size - PAGE_SIZE + 4) >> 2;
>> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_physical_addr =
>> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE;
>> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_physical_addr =
>> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE + 4; }
>> +
>>    static int soc15_common_early_init(void *handle)
>>    {
>>    	struct amdgpu_device *adev = (struct amdgpu_device *)handle; @@
>> -794,6 +815,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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
       [not found]             ` <677f9d24-2c03-bf30-7bb6-0e57a38f158d-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-15 14:10               ` Zeng, Oak
  0 siblings, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-15 14:10 UTC (permalink / raw)
  To: Koenig, Christian,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Keely, Sean

Ok, will do it.

Regards,
Oak

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Koenig, Christian
Sent: Monday, April 15, 2019 4:06 AM
To: Zeng, Oak <Oak.Zeng@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix <Felix.Kuehling@amd.com>; Keely, Sean <Sean.Keely@amd.com>
Subject: Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers

Hi Oak,

well, we make the function pointer structures constant is exactly to prevent those scenarios.

Background is that multiple GPU can use the same function pointer structure, but with different register offsets. So what you do here is actually illegal and could break in some cases.

Easiest solution would indeed be to add a new stuff directly to the adev, probably best encapsulated in a new structure.

Regards,
Christian.

Am 12.04.19 um 17:39 schrieb Zeng, Oak:
> Hi Christian,
>
> After hdp registers are moved to a new place in mmio space, we can't access those registers through the pre-defined register offset. I recorded the new register offset in struct amdgpu_nbio_funcs (because those registers are nbio registers) and initialized them in the early init. After those changes, I can't keep instance of struct amdgpu_nbio_funcs to be constant anymore - we don't know the new register offset before the remap function. When I made the change, I also felt not comfortable. Do you have any better solution? Introduce new r/w members directly to adev? - I also feel not comfortable because those registers I added belongs to nbio by nature...
>
> Regards,
> Oak
>
> -----Original Message-----
> From: Christian König <ckoenig.leichtzumerken@gmail.com>
> Sent: Friday, April 12, 2019 3:24 AM
> To: Zeng, Oak <Oak.Zeng@amd.com>; amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix 
> <Felix.Kuehling@amd.com>; Keely, Sean <Sean.Keely@amd.com>
> Subject: Re: [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers
>
> Am 11.04.19 um 22:31 schrieb Zeng, Oak:
>> 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.
>>
>> Change-Id: Ia8d27c0c9a082711d16bbf55602bf5712a47b6d6
>> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
>> ---
>>    drivers/gpu/drm/amd/amdgpu/amdgpu.h    |  6 +++++-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c |  7 +++----
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c |  7 +++----
>>    drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h |  2 +-
>>    drivers/gpu/drm/amd/amdgpu/soc15.c     | 22 ++++++++++++++++++++++
>>    8 files changed, 37 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index bc96ec4..840be05 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -644,6 +644,10 @@ struct nbio_hdp_flush_reg {
>>    
>>    struct amdgpu_nbio_funcs {
>>    	const struct nbio_hdp_flush_reg *hdp_flush_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;
>>    	u32 (*get_hdp_flush_req_offset)(struct amdgpu_device *adev);
>>    	u32 (*get_hdp_flush_done_offset)(struct amdgpu_device *adev);
>>    	u32 (*get_pcie_index_offset)(struct amdgpu_device *adev); @@ 
>> -905,7
>> +909,7 @@ struct amdgpu_device {
>>    	/* soc15 register offset based on ip, instance and  segment */
>>    	uint32_t 		*reg_offset[MAX_HWIP][HWIP_MAX_INSTANCE];
>>    
>> -	const struct amdgpu_nbio_funcs	*nbio_funcs;
>> +	struct amdgpu_nbio_funcs	*nbio_funcs;
> Please kep the function pointers constant. Those should never be changed on a running system.
>
> Christian.
>
>>    	const struct amdgpu_df_funcs	*df_funcs;
>>    
>>    	/* delayed work_func for deferring clockgating during resume */ 
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> index 6590143..2470b8e 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c
>> @@ -276,7 +276,7 @@ static void nbio_v6_1_init_registers(struct amdgpu_device *adev)
>>    		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v6_1_funcs = {
>>    	.hdp_flush_reg = &nbio_v6_1_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v6_1_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v6_1_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> index 0743a6f..d409bb6 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v6_1.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v6_1_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> index 1cdb98a..9a5abf5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c
>> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offs
>> +e
>> +t, 0);
>>    	else
>> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
>> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
>> +		amdgpu_ring_emit_wreg(ring,
>> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>>    }
>>    
>>    static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev) @@
>> -263,7 +262,7 @@ static void nbio_v7_0_init_registers(struct 
>> amdgpu_device *adev)
>>    
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v7_0_funcs = {
>>    	.hdp_flush_reg = &nbio_v7_0_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v7_0_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v7_0_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> index 508d549..db50618 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_0.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v7_0_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> index c69d515..25203cc 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c
>> @@ -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->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offs
>> +e
>> +t, 0);
>>    	else
>> -		amdgpu_ring_emit_wreg(ring, SOC15_REG_OFFSET(
>> -			NBIO, 0, mmHDP_MEM_COHERENCY_FLUSH_CNTL), 0);
>> +		amdgpu_ring_emit_wreg(ring,
>> +adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset, 0);
>>    }
>>    
>>    static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev) @@
>> -242,7 +241,7 @@ static void nbio_v7_4_init_registers(struct amdgpu_device *adev)
>>    		WREG32_PCIE(smnPCIE_CI_CNTL, data);
>>    }
>>    
>> -const struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>> +struct amdgpu_nbio_funcs nbio_v7_4_funcs = {
>>    	.hdp_flush_reg = &nbio_v7_4_hdp_flush_reg,
>>    	.get_hdp_flush_req_offset = nbio_v7_4_get_hdp_flush_req_offset,
>>    	.get_hdp_flush_done_offset = nbio_v7_4_get_hdp_flush_done_offset,
>> diff --git a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> index c442865..2e5bb03 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/nbio_v7_4.h
>> @@ -26,6 +26,6 @@
>>    
>>    #include "soc15_common.h"
>>    
>> -extern const struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>> +extern struct amdgpu_nbio_funcs nbio_v7_4_funcs;
>>    
>>    #endif
>> diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c
>> b/drivers/gpu/drm/amd/amdgpu/soc15.c
>> index bdb5ad9..c47e7a5 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/soc15.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
>> @@ -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,26 @@ 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) {
>> +	/* Remap hdp coherency registers to the last page of mmio
>> +	 * space, for the purpose of mapping them to process space(
>> +	 * so process can flush hdp)
>> +	 */
>> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_MEM_FLUSH_CNTL,
>> +			adev->rmmio_size - PAGE_SIZE);
>> +	WREG32_SOC15(NBIO, 0, mmREMAP_HDP_REG_FLUSH_CNTL,
>> +			adev->rmmio_size - PAGE_SIZE + 4);
>> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_reg_offset =
>> +			(adev->rmmio_size - PAGE_SIZE) >> 2;
>> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_reg_offset =
>> +			(adev->rmmio_size - PAGE_SIZE + 4) >> 2;
>> +	adev->nbio_funcs->remapped_hdp_mem_flush_cntl_physical_addr =
>> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE;
>> +	adev->nbio_funcs->remapped_hdp_reg_flush_cntl_physical_addr =
>> +			adev->rmmio_base + adev->rmmio_size - PAGE_SIZE + 4; }
>> +
>>    static int soc15_common_early_init(void *handle)
>>    {
>>    	struct amdgpu_device *adev = (struct amdgpu_device *)handle; @@
>> -794,6 +815,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
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found] ` <1555510818-4016-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-17 14:20   ` Zeng, Oak
       [not found]     ` <1555510818-4016-2-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Zeng, Oak @ 2019-04-17 14:20 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean,
	Koenig, Christian

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

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..d953338b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e778679 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..4394f61 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..973d2fe 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -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);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3bc78b26 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index dc067ed..96afd01 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found]     ` <1555510818-4016-2-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-17 16:20       ` Deucher, Alexander
       [not found]         ` <BN6PR12MB1809963155D309C7B964175CF7250-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 14+ messages in thread
From: Deucher, Alexander @ 2019-04-17 16:20 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Kuehling, Felix, Zeng, Oak, Keely, Sean, Koenig, Christian

> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> Zeng, Oak
> Sent: Wednesday, April 17, 2019 10:21 AM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix
> <Felix.Kuehling@amd.com>; Zeng, Oak <Oak.Zeng@amd.com>; Keely, Sean
> <Sean.Keely@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>
> Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
> 
> Introduce 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

> 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: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
> ---
>  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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index acf8ae0..d953338b8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> index e6a5037..e778679 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> @@ -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)				\
>  	({								\
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 047bba8..4394f61 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -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);
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 083bd81..973d2fe 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -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);
> diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> index 5f3c10e..3bc78b26 100644
> --- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> +++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> @@ -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.
> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
> index dc067ed..96afd01 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -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
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found]         ` <BN6PR12MB1809963155D309C7B964175CF7250-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2019-04-17 20:19           ` Zeng, Oak
  2019-04-17 21:13           ` Kuehling, Felix
  1 sibling, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-17 20:19 UTC (permalink / raw)
  To: Deucher, Alexander,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Kuehling, Felix, Keely, Sean, Koenig, Christian

Thanks, I agree. Will change it.

Regards,
Oak

-----Original Message-----
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Deucher, Alexander
Sent: Wednesday, April 17, 2019 12:21 PM
To: Zeng, Oak <Oak.Zeng@amd.com>; amd-gfx@lists.freedesktop.org
Cc: Kuehling, Felix <Felix.Kuehling@amd.com>; Zeng, Oak <Oak.Zeng@amd.com>; Keely, Sean <Sean.Keely@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>
Subject: RE: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space

> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of 
> Zeng, Oak
> Sent: Wednesday, April 17, 2019 10:21 AM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix 
> <Felix.Kuehling@amd.com>; Zeng, Oak <Oak.Zeng@amd.com>; Keely, Sean 
> <Sean.Keely@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>
> Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
> 
> Introduce 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

> 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: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
> ---
>  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(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index acf8ae0..d953338b8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> @@ -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) diff --git 
> a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> index e6a5037..e778679 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
> @@ -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)				\
>  	({								\
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 047bba8..4394f61 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -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);
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 083bd81..973d2fe 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -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);
> diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> index 5f3c10e..3bc78b26 100644
> --- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> +++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
> @@ -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.
> diff --git a/include/uapi/linux/kfd_ioctl.h 
> b/include/uapi/linux/kfd_ioctl.h index dc067ed..96afd01 100644
> --- a/include/uapi/linux/kfd_ioctl.h
> +++ b/include/uapi/linux/kfd_ioctl.h
> @@ -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
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
@ 2019-04-17 20:26 Zeng, Oak
  0 siblings, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-17 20:26 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean,
	Koenig, Christian

Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) and
expose mmio page of HDP registers to user space through this new
memory type.

v2: moved remapped hdp regs to adev struct
v3: rename the new memory type to ALLOC_MEM_FLAGS_MMIO_REMAP

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..d953338b8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e778679 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..fa21e0e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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_MMIO_REMAP)) {
 		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);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..130b1e5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -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_MMIO_REMAP) {
+		if (args->size != PAGE_SIZE)
+			return -EINVAL;
+		offset = amdgpu_amdkfd_get_hdp_register_physical_addr(dev->kgd);
 	}
 
 	mutex_lock(&p->mutex);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3ecb109 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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_MMIO_REMAP	(1 << 4)
 
 /*
  * Allocation flags attributes/access options.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index dc067ed..f5fdc8a 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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_MMIO_REMAP	(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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found]         ` <BN6PR12MB1809963155D309C7B964175CF7250-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  2019-04-17 20:19           ` Zeng, Oak
@ 2019-04-17 21:13           ` Kuehling, Felix
  1 sibling, 0 replies; 14+ messages in thread
From: Kuehling, Felix @ 2019-04-17 21:13 UTC (permalink / raw)
  To: Deucher, Alexander, Zeng, Oak,
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Keely, Sean, Koenig, Christian

On 2019-04-17 12:20 p.m., Deucher, Alexander wrote:
>> -----Original Message-----
>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
>> Zeng, Oak
>> Sent: Wednesday, April 17, 2019 10:21 AM
>> To: amd-gfx@lists.freedesktop.org
>> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Kuehling, Felix
>> <Felix.Kuehling@amd.com>; Zeng, Oak <Oak.Zeng@amd.com>; Keely, Sean
>> <Sean.Keely@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>
>> Subject: [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
>>
>> Introduce 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.

So that's assuming other registers would get remapped into the same 
page. Makes sense.

Regards,
   Felix


>
> Alex
>
>> 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: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
>> Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
>> ---
>>   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(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> index acf8ae0..d953338b8 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
>> @@ -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)
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> index e6a5037..e778679 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
>> @@ -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)				\
>>   	({								\
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> index 047bba8..4394f61 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> @@ -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);
>> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> index 083bd81..973d2fe 100644
>> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
>> @@ -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);
>> diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
>> b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
>> index 5f3c10e..3bc78b26 100644
>> --- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
>> +++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
>> @@ -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.
>> diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
>> index dc067ed..96afd01 100644
>> --- a/include/uapi/linux/kfd_ioctl.h
>> +++ b/include/uapi/linux/kfd_ioctl.h
>> @@ -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
>>
>> _______________________________________________
>> amd-gfx mailing list
>> amd-gfx@lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found] ` <1556039638-26171-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-23 17:14   ` Zeng, Oak
  0 siblings, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-23 17:14 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Kuehling, Felix, Koenig, Christian, Keely, Sean, Zeng, Oak,
	alex.deucher-5C7GfCeVMHo@public.gmane.org

Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) and
expose mmio page of HDP registers to user space through this new
memory type.

v2: moved remapped hdp regs to adev struct
v3: rename the new memory type to ALLOC_MEM_FLAGS_MMIO_REMAP
v4: use more generic function name

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..03c3ac5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+
+	return adev->rmmio_remap.bus_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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e45ba9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd);
 
 #define read_user_wptr(mmptr, wptr, dst)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..697b8ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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_MMIO_REMAP)) {
 		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 mmio
+	 * remap BO. We need to free it.
 	 */
 	if (mem->bo->tbo.sg) {
 		sg_free_table(mem->bo->tbo.sg);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..9b907e1 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -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_MMIO_REMAP) {
+		if (args->size != PAGE_SIZE)
+			return -EINVAL;
+		offset = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
 	}
 
 	mutex_lock(&p->mutex);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3ecb109 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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_MMIO_REMAP	(1 << 4)
 
 /*
  * Allocation flags attributes/access options.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 7524e6e..f5aada4 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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_MMIO_REMAP	(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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found] ` <1556047414-19404-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-23 19:23   ` Zeng, Oak
  0 siblings, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-23 19:23 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean,
	Koenig, Christian

Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) and
expose mmio page of HDP registers to user space through this new
memory type.

v2: moved remapped hdp regs to adev struct
v3: rename the new memory type to ALLOC_MEM_FLAGS_MMIO_REMAP
v4: use more generic function name
v5: Fail remapped mmio allocation for asics before gfx9

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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         | 6 ++++++
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  | 1 +
 include/uapi/linux/kfd_ioctl.h                   | 1 +
 6 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..03c3ac5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+
+	return adev->rmmio_remap.bus_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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e45ba9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd);
 
 #define read_user_wptr(mmptr, wptr, dst)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..697b8ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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_MMIO_REMAP)) {
 		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 mmio
+	 * remap BO. We need to free it.
 	 */
 	if (mem->bo->tbo.sg) {
 		sg_free_table(mem->bo->tbo.sg);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..272cec0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1272,6 +1272,12 @@ 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_MMIO_REMAP) {
+		if (args->size != PAGE_SIZE)
+			return -EINVAL;
+		offset = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+		if (offset == ULLONG_MAX)
+			return -ENOMEM;
 	}
 
 	mutex_lock(&p->mutex);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3ecb109 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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_MMIO_REMAP	(1 << 4)
 
 /*
  * Allocation flags attributes/access options.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index 7524e6e..f5aada4 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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_MMIO_REMAP	(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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space
       [not found] ` <1556053179-5644-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
@ 2019-04-23 20:59   ` Zeng, Oak
  0 siblings, 0 replies; 14+ messages in thread
From: Zeng, Oak @ 2019-04-23 20:59 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
  Cc: Deucher, Alexander, Kuehling, Felix, Zeng, Oak, Keely, Sean,
	Koenig, Christian

Introduce a new memory type (KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) and
expose mmio page of HDP registers to user space through this new
memory type.

v2: moved remapped hdp regs to adev struct
v3: rename the new memory type to ALLOC_MEM_FLAGS_MMIO_REMAP
v4: use more generic function name
v5: Fail remapped mmio allocation for asics before gfx9

Change-Id: If5ac13c46ea7fbd2194ddc8b2ece26ef4f76c330
Signed-off-by: Oak Zeng <Oak.Zeng@amd.com>
---
 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         | 6 ++++++
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  | 1 +
 include/uapi/linux/kfd_ioctl.h                   | 1 +
 6 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index acf8ae0..03c3ac5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+
+	return adev->rmmio_remap.bus_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)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e6a5037..e45ba9e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -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_mmio_remap_phys_addr(struct kgd_dev *kgd);
 
 #define read_user_wptr(mmptr, wptr, dst)				\
 	({								\
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 047bba8..697b8ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -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_MMIO_REMAP)) {
 		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 mmio
+	 * remap BO. We need to free it.
 	 */
 	if (mem->bo->tbo.sg) {
 		sg_free_table(mem->bo->tbo.sg);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 083bd81..272cec0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -1272,6 +1272,12 @@ 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_MMIO_REMAP) {
+		if (args->size != PAGE_SIZE)
+			return -EINVAL;
+		offset = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+		if (offset == ULLONG_MAX)
+			return -ENOMEM;
 	}
 
 	mutex_lock(&p->mutex);
diff --git a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
index 5f3c10e..3ecb109 100644
--- a/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
+++ b/drivers/gpu/drm/amd/include/kgd_kfd_interface.h
@@ -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_MMIO_REMAP	(1 << 4)
 
 /*
  * Allocation flags attributes/access options.
diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index bb1b428..1e7d5f3 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -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_MMIO_REMAP	(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

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-04-23 20:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-11 20:31 [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Zeng, Oak
     [not found] ` <1555014669-30077-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-11 20:31   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak
2019-04-12  7:23   ` [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Christian König
     [not found]     ` <9cc46562-129b-5e1f-14a9-6244ede19f3e-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-04-12 15:39       ` Zeng, Oak
     [not found]         ` <BL0PR12MB25804A7060A56A0EAD36D97180280-b4cIHhjg/p/XzH18dTCKOgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-04-15  8:06           ` Koenig, Christian
     [not found]             ` <677f9d24-2c03-bf30-7bb6-0e57a38f158d-5C7GfCeVMHo@public.gmane.org>
2019-04-15 14:10               ` Zeng, Oak
  -- strict thread matches above, loose matches on Subject: below --
2019-04-17 14:20 Zeng, Oak
     [not found] ` <1555510818-4016-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-17 14:20   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak
     [not found]     ` <1555510818-4016-2-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-17 16:20       ` Deucher, Alexander
     [not found]         ` <BN6PR12MB1809963155D309C7B964175CF7250-/b2+HYfkarSEx6ez0IUAagdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-04-17 20:19           ` Zeng, Oak
2019-04-17 21:13           ` Kuehling, Felix
2019-04-17 20:26 Zeng, Oak
2019-04-23 17:14 [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Zeng, Oak
     [not found] ` <1556039638-26171-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-23 17:14   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak
2019-04-23 19:23 [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Zeng, Oak
     [not found] ` <1556047414-19404-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-23 19:23   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak
2019-04-23 20:59 [PATCH 1/2] drm/amdgpu: Remap hdp coherency registers Zeng, Oak
     [not found] ` <1556053179-5644-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org>
2019-04-23 20:59   ` [PATCH 2/2] drm/amdkfd: Expose HDP registers to user space Zeng, Oak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox