Skip to contentSkip to conversation

drm/amdkfd: Add gws number to kfd topology node properties

PATCH In review Zeng, Oak 4 participants 16 messages May 23, 2019 – May 31, 2019 8 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Zeng, Oak

author
#0 lore raw

PATCH 1/8 drm/amdkfd: Add gws number to kfd topology node properties

Add amdgpu_amdkfd interface to get num_gws and add num_gws to /sys/class/kfd/kfd/topology/nodes/x/properties. Only report num_gws if MEC FW support GWS barriers. Currently it is determined by a module parameter which will be replaced with MEC FW version check when firmware is ready.

Change-Id Ie0d00fb20a37ef2856860dbecbe1ad0ca1ef09f7
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  7 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 10 ++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h      |  5 +++++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  5 +++++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.h  |  1 +
 6 files changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +7 -0
index 98326e3b..a4780d5 100644
@@ -544,6 +544,13 @@ uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
 	return adev->rmmio_remap.bus_addr;
 }
 
+uint32_t amdgpu_amdkfd_get_num_gws(struct kgd_dev *kgd)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+
+	return adev->gds.gws_size;
+}
+
 int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine,
 				uint32_t vmid, uint64_t gpu_addr,
 				uint32_t *ib_cmd, uint32_t ib_len)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index f57f297..5700643 100644
@@ -169,6 +169,7 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
 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);
+uint32_t amdgpu_amdkfd_get_num_gws(struct kgd_dev *kgd);
 uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src);
 
 #define read_user_wptr(mmptr, wptr, dst)				\
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10 -0
index a334d3b..3a03c2b 100644
@@ -666,6 +666,16 @@ MODULE_PARM_DESC(noretry,
 int halt_if_hws_hang;
 module_param(halt_if_hws_hang, int, 0644);
 MODULE_PARM_DESC(halt_if_hws_hang, "Halt if HWS hang is detected (0 = off (default), 1 = on)");
+
+/**
+ * DOC: hws_gws_support(bool)
+ * Whether HWS support gws barriers. Default value: false (not supported)
+ * This will be replaced with a MEC firmware version check once firmware
+ * is ready
+ */
+bool hws_gws_support;
+module_param(hws_gws_support, bool, 0444);
+MODULE_PARM_DESC(hws_gws_support, "MEC FW support gws barriers (false = not supported (Default), true = supported)");
 #endif
 
 /**
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +5 -0
index 8f02d78..338fb07 100644
@@ -160,6 +160,11 @@ extern int noretry;
  */
 extern int halt_if_hws_hang;
 
+/*
+ * Whether MEC FW support GWS barriers
+ */
+extern bool hws_gws_support;
+
 enum cache_policy {
 	cache_policy_coherent,
 	cache_policy_noncoherent
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +5 -0
index 2c06d6c..128c72c 100644
@@ -454,6 +454,8 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 			dev->node_props.lds_size_in_kb);
 	sysfs_show_32bit_prop(buffer, "gds_size_in_kb",
 			dev->node_props.gds_size_in_kb);
+	sysfs_show_32bit_prop(buffer, "num_gws",
+			dev->node_props.num_gws);
 	sysfs_show_32bit_prop(buffer, "wave_front_size",
 			dev->node_props.wave_front_size);
 	sysfs_show_32bit_prop(buffer, "array_count",
@@ -1290,6 +1292,9 @@ int kfd_topology_add_device(struct kfd_dev *gpu)
 	dev->node_props.num_sdma_engines = gpu->device_info->num_sdma_engines;
 	dev->node_props.num_sdma_xgmi_engines =
 				gpu->device_info->num_xgmi_sdma_engines;
+	dev->node_props.num_gws = (hws_gws_support &&
+		dev->gpu->dqm->sched_policy != KFD_SCHED_POLICY_NO_HWS) ?
+		amdgpu_amdkfd_get_num_gws(dev->gpu->kgd) : 0;
 
 	kfd_fill_mem_clk_max_info(dev);
 	kfd_fill_iolink_non_crat_info(dev);
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +1 -0
index 949e885..276354a 100644
@@ -65,6 +65,7 @@ struct kfd_node_properties {
 	uint32_t max_waves_per_simd;
 	uint32_t lds_size_in_kb;
 	uint32_t gds_size_in_kb;
+	uint32_t num_gws;
 	uint32_t wave_front_size;
 	uint32_t array_count;
 	uint32_t simd_arrays_per_engine;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1558651263-3478-1-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/8 drm/amdgpu: Add interface to alloc gws from amdgpu

Add amdgpu_amdkfd interface to alloc and free gws
from amdgpu

Change-Id I4eb418356e5a6051aa09c5e2c4a454263631d6ab
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 34 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  2 ++
 2 files changed, 36 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +34 -0
index a4780d5..4af3989 100644
@@ -339,6 +339,40 @@ void amdgpu_amdkfd_free_gtt_mem(struct kgd_dev *kgd, void *mem_obj)
 	amdgpu_bo_unref(&(bo));
 }
 
+int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size,
+				void **mem_obj)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+	struct amdgpu_bo *bo = NULL;
+	struct amdgpu_bo_param bp;
+	int r;
+
+	memset(&bp, 0, sizeof(bp));
+	bp.size = size;
+	bp.byte_align = 1;
+	bp.domain = AMDGPU_GEM_DOMAIN_GWS;
+	bp.flags = AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
+	bp.type = ttm_bo_type_device;
+	bp.resv = NULL;
+
+	r = amdgpu_bo_create(adev, &bp, &bo);
+	if (r) {
+		dev_err(adev->dev,
+			"failed to allocate gws BO for amdkfd (%d)\n", r);
+		return r;
+	}
+
+	*mem_obj = bo;
+	return 0;
+}
+
+void amdgpu_amdkfd_free_gws(struct kgd_dev *kgd, void *mem_obj)
+{
+	struct amdgpu_bo *bo = (struct amdgpu_bo *)mem_obj;
+
+	amdgpu_bo_unref(&bo);
+}
+
 uint32_t amdgpu_amdkfd_get_fw_version(struct kgd_dev *kgd,
 				      enum kgd_engine_type type)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index 5700643..c00c974 100644
@@ -153,6 +153,8 @@ int amdgpu_amdkfd_alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
 				void **mem_obj, uint64_t *gpu_addr,
 				void **cpu_ptr, bool mqd_gfx9);
 void amdgpu_amdkfd_free_gtt_mem(struct kgd_dev *kgd, void *mem_obj);
+int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size, void **mem_obj);
+void amdgpu_amdkfd_free_gws(struct kgd_dev *kgd, void *mem_obj);
 uint32_t amdgpu_amdkfd_get_fw_version(struct kgd_dev *kgd,
 				      enum kgd_engine_type type);
 void amdgpu_amdkfd_get_local_mem_info(struct kgd_dev *kgd,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#3 lore raw

PATCH 3/8 drm/amdkfd: Allocate gws on device initialization

In reply to a message not in the archive

On device initialization, KFD allocates all (64) gws which is shared by all KFD processes.

Change-Id I1f1274b8d4f6a8ad08785e2791a9a79def75e913
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 14 +++++++++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h   |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_device.c +13 -1
index 7b4ea24..9d1b026 100644
@@ -553,6 +553,13 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 	} else
 		kfd->max_proc_per_quantum = hws_max_conc_proc;
 
+	/* Allocate global GWS that is shared by all KFD processes */
+	if (hws_gws_support && amdgpu_amdkfd_alloc_gws(kfd->kgd,
+			amdgpu_amdkfd_get_num_gws(kfd->kgd), &kfd->gws)) {
+		dev_err(kfd_device, "Could not allocate %d gws\n",
+			amdgpu_amdkfd_get_num_gws(kfd->kgd));
+		goto out;
+	}
 	/* calculate max size of mqds needed for queues */
 	size = max_num_of_queues_per_device *
 			kfd->device_info->mqd_size_aligned;
@@ -576,7 +583,7 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 			&kfd->gtt_start_gpu_addr, &kfd->gtt_start_cpu_ptr,
 			false)) {
 		dev_err(kfd_device, "Could not allocate %d bytes\n", size);
-		goto out;
+		goto alloc_gtt_mem_failure;
 	}
 
 	dev_info(kfd_device, "Allocated %d bytes on gart\n", size);
@@ -646,6 +653,9 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 	kfd_gtt_sa_fini(kfd);
 kfd_gtt_sa_init_error:
 	amdgpu_amdkfd_free_gtt_mem(kfd->kgd, kfd->gtt_mem);
+alloc_gtt_mem_failure:
+	if (hws_gws_support)
+		amdgpu_amdkfd_free_gws(kfd->kgd, kfd->gws);
 	dev_err(kfd_device,
 		"device %x:%x NOT added due to errors\n",
 		kfd->pdev->vendor, kfd->pdev->device);
@@ -663,6 +673,8 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)
 		kfd_doorbell_fini(kfd);
 		kfd_gtt_sa_fini(kfd);
 		amdgpu_amdkfd_free_gtt_mem(kfd->kgd, kfd->gtt_mem);
+		if (hws_gws_support)
+			amdgpu_amdkfd_free_gws(kfd->kgd, kfd->gws);
 	}
 
 	kfree(kfd);
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
index 338fb07..5969e37 100644
@@ -288,6 +288,9 @@ struct kfd_dev {
 
 	/* Compute Profile ref. count */
 	atomic_t compute_profile;
+
+	/* Global GWS resource shared b/t processes*/
+	void *gws;
 };
 
 enum kfd_mempool {
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#4 lore raw

PATCH 4/8 drm/amdgpu: Add function to add/remove gws to kfd process

In reply to a message not in the archive

GWS bo is shared between all kfd processes. Add function to add gws to kfd process's bo list so gws can be evicted from and restored for process.

Change-Id I75d74cfdadb7075ff8b2b68634e205deb73dc1ea
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h       |   2 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 103 +++++++++++++++++++++--
 2 files changed, 100 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
index c00c974..f968bf1 100644
@@ -155,6 +155,8 @@ int amdgpu_amdkfd_alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
 void amdgpu_amdkfd_free_gtt_mem(struct kgd_dev *kgd, void *mem_obj);
 int amdgpu_amdkfd_alloc_gws(struct kgd_dev *kgd, size_t size, void **mem_obj);
 void amdgpu_amdkfd_free_gws(struct kgd_dev *kgd, void *mem_obj);
+int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem);
+int amdgpu_amdkfd_remove_gws_from_process(void *info, void *mem);
 uint32_t amdgpu_amdkfd_get_fw_version(struct kgd_dev *kgd,
 				      enum kgd_engine_type type);
 void amdgpu_amdkfd_get_local_mem_info(struct kgd_dev *kgd,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +98 -5

125 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#5 lore raw

PATCH 5/8 drm/amdkfd: Add function to set queue gws

In reply to a message not in the archive

Add functions in process queue manager to set/unset queue gws. Also set process's number of gws used. Currently only one queue in process can use and use all gws.

Change-Id I03e480c8692db3eabfc3a188cce8904d5d962ab7
---
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  6 +++
 .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 57 ++++++++++++++++++++++
 2 files changed, 63 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
index 5969e37..40a5c67 100644
@@ -454,6 +454,9 @@ struct queue_properties {
  *
  * @device: The kfd device that created this queue.
  *
+ * @gws: Pointing to gws kgd_mem if this is a gws control queue; NULL
+ * otherwise.
+ *
  * This structure represents user mode compute queues.
  * It contains all the necessary data to handle such queues.
  *
@@ -475,6 +478,7 @@ struct queue {
 
 	struct kfd_process	*process;
 	struct kfd_dev		*device;
+	void *gws;
 };
 
 /*
@@ -868,6 +872,8 @@ int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
 			struct queue_properties *p);
 int pqm_set_cu_mask(struct process_queue_manager *pqm, unsigned int qid,
 			struct queue_properties *p);
+int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid,
+			void *gws);
 struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm,
 						unsigned int qid);
 int pqm_get_wave_state(struct process_queue_manager *pqm,
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +57 -0

75 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1558651263-3478-5-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org

#7 lore raw

Re: [PATCH 5/8] drm/amdkfd: Add function to set queue gws

Quoted 89 lines · Oak

Add functions in process queue manager to set/unset queue gws. Also set process's number of gws used. Currently only one queue in process can use and use all gws.

Change-Id I03e480c8692db3eabfc3a188cce8904d5d962ab7
---
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h              |  6 +++
  .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 57 ++++++++++++++++++++++
  2 files changed, 63 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
index 5969e37..40a5c67 100644
@@ -454,6 +454,9 @@ struct queue_properties {
   *
   * @device: The kfd device that created this queue.
   *
+ * @gws: Pointing to gws kgd_mem if this is a gws control queue; NULL
+ * otherwise.
+ *
   * This structure represents user mode compute queues.
   * It contains all the necessary data to handle such queues.
   *
@@ -475,6 +478,7 @@ struct queue {
 
  	struct kfd_process	*process;
  	struct kfd_dev		*device;
+	void *gws;
  };
 
  /*
@@ -868,6 +872,8 @@ int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
  			struct queue_properties *p);
  int pqm_set_cu_mask(struct process_queue_manager *pqm, unsigned int qid,
  			struct queue_properties *p);
+int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid,
+			void *gws);
  struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm,
  						unsigned int qid);
  int pqm_get_wave_state(struct process_queue_manager *pqm,
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +31 -0
index e652e25..5764491 100644
@@ -26,6 +26,7 @@
  #include "kfd_device_queue_manager.h"
  #include "kfd_priv.h"
  #include "kfd_kernel_queue.h"
+#include "amdgpu_amdkfd.h"
 
  static inline struct process_queue_node *get_queue_by_qid(
  			struct process_queue_manager *pqm, unsigned int qid)
@@ -74,6 +75,55 @@ void kfd_process_dequeue_from_device(struct kfd_process_device *pdd)
  	pdd->already_dequeued = true;
  }
 
+int pqm_set_gws(struct process_queue_manager *pqm, unsigned int qid,
+			void *gws)
+{
+	struct kfd_dev *dev = NULL;
+	struct process_queue_node *pqn;
+	struct kfd_process_device *pdd;
+	struct kgd_mem *mem;
+	int ret;
+
+	pqn = get_queue_by_qid(pqm, qid);
+	if (!pqn) {
+		pr_err("Queue id does not match any known queue\n");
+		return -EINVAL;
+	}
+
+	if (pqn->q)
+		dev = pqn->q->device;
+	if (WARN_ON(!dev))
+		return -ENODEV;
+
+	pdd = kfd_get_process_device_data(dev, pqm->process);
+	if (!pdd) {
+		pr_err("Process device data doesn't exist\n");
+		return -EINVAL;
+	}
+
+	/* Only allow one queue per process can have GWS assigned */
+	if (gws && pdd->qpd.num_gws)
+		return -EINVAL;
+

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c void kfd_process_dequeue_from_device(struct kfd_process_device *pdd) · line 117

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +10 -0
+	if (!gws && pdd->qpd.num_gws == 0)
+		return -EINVAL;
+
+	if (gws)
+		ret = amdgpu_amdkfd_add_gws_to_process(pdd->process->kgd_process_info,
+			gws, &mem);
+	else
+		amdgpu_amdkfd_remove_gws_from_process(pdd->process->kgd_process_info,
+			pqn->q->gws);
+	if (unlikely(ret))

ret may be uninitialized here. You probably get a compiler warning for that. Please check for compiler warnings and initialize ret at the start of the function.

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c void kfd_process_dequeue_from_device(struct kfd_process_device *pdd) · line 120

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +3 -0
+		return ret;
+
+	pqn->q->gws = gws ? mem : NULL;

I think there is a chance that some compilers will complain here that mem can be used uninitialized. It may be safer to initialize mem to NULL at the start of the function, just in case. Then you can also just assign mem here without the conditional.

With these two issues fixed, this patch is Reviewed-by: Felix Kuehling <[email protected]>

Quoted 13 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +6 -0
+	pdd->qpd.num_gws = gws ? amdgpu_amdkfd_get_num_gws(dev->kgd) : 0;
+
+	return pqn->q->device->dqm->ops.update_queue(pqn->q->device->dqm,
+							pqn->q);
+}
+
  void kfd_process_dequeue_from_all_devices(struct kfd_process *p)
  {
  	struct kfd_process_device *pdd;
@@ -330,6 +380,13 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
  			if (retval != -ETIME)
  				goto err_destroy_queue;
  		}

drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid) · line 392

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +7 -0
+
+		if (pqn->q->gws) {
+			amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info,
+				pqn->q->gws);
+			pdd->qpd.num_gws = 0;
+		}
+
  		kfree(pqn->q->properties.cu_mask);
  		pqn->q->properties.cu_mask = NULL;
  		uninit_queue(pqn->q);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#8 lore raw

PATCH 6/8 drm/amdkfd: New IOCTL to allocate queue GWS

In reply to a message not in the archive

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 27 +++++++++++++++++++++++++++
 include/uapi/linux/kfd_ioctl.h           | 20 +++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +27 -0
index 38ae53f..455a3db 100644
@@ -1559,6 +1559,31 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
 	return err;
 }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+		struct kfd_process *p, void *data)
+{
+	int retval;
+	struct kfd_ioctl_alloc_queue_gws_args *args = data;
+	struct kfd_dev *dev = NULL;
+
+	if (!hws_gws_support ||
+		dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+		return -EINVAL;
+
+	dev = kfd_device_by_id(args->gpu_id);
+	if (!dev) {
+		pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
+		return -EINVAL;
+	}
+
+	mutex_lock(&p->mutex);
+	retval = pqm_set_gws(&p->pqm, args->queue_id, args->num_gws ? dev->gws : NULL);
+	mutex_unlock(&p->mutex);
+
+	args->first_gws = 0;
+	return retval;
+}
+
 static int kfd_ioctl_get_dmabuf_info(struct file *filep,
 		struct kfd_process *p, void *data)
 {
@@ -1761,6 +1786,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
 	AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
 				kfd_ioctl_import_dmabuf, 0),
 
+	AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+			kfd_ioctl_alloc_queue_gws, 0),
 };
 
 #define AMDKFD_CORE_IOCTL_COUNT	ARRAY_SIZE(amdkfd_ioctls)
include/uapi/linux/kfd_ioctl.h +19 -1
index 20917c5..070d1bc 100644
@@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
 	__u32 n_success;		/* to/from KFD */
 };
 
+/* Allocate GWS for specific queue
+ *
+ * @gpu_id:      device identifier
+ * @queue_id:    queue's id that GWS is allocated for
+ * @num_gws:     how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *               only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+	__u32 gpu_id;		/* to KFD */
+	__u32 queue_id;		/* to KFD */
+	__u32 num_gws;		/* to KFD */
+	__u32 first_gws;	/* from KFD */
+};
+
 struct kfd_ioctl_get_dmabuf_info_args {
 	__u64 size;		/* from KFD */
 	__u64 metadata_ptr;	/* to KFD */
@@ -529,7 +544,10 @@ enum kfd_mmio_remap {
 #define AMDKFD_IOC_IMPORT_DMABUF		\
 		AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS		\
+		AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
+
 #define AMDKFD_COMMAND_START		0x01
-#define AMDKFD_COMMAND_END		0x1E
+#define AMDKFD_COMMAND_END		0x1F
 
 #endif
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1558651263-3478-6-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org

Reviewed-by Felix Kuehling
#10 lore raw

Re: [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS

Quoted 5 lines · Oak

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15
Quoted 78 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 27 +++++++++++++++++++++++++++
  include/uapi/linux/kfd_ioctl.h           | 20 +++++++++++++++++++-
  2 files changed, 46 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +27 -0
index 38ae53f..455a3db 100644
@@ -1559,6 +1559,31 @@ static int kfd_ioctl_unmap_memory_from_gpu(struct file *filep,
  	return err;
  }
 
+static int kfd_ioctl_alloc_queue_gws(struct file *filep,
+		struct kfd_process *p, void *data)
+{
+	int retval;
+	struct kfd_ioctl_alloc_queue_gws_args *args = data;
+	struct kfd_dev *dev = NULL;
+
+	if (!hws_gws_support ||
+		dev->dqm->sched_policy == KFD_SCHED_POLICY_NO_HWS)
+		return -EINVAL;
+
+	dev = kfd_device_by_id(args->gpu_id);
+	if (!dev) {
+		pr_debug("Could not find gpu id 0x%x\n", args->gpu_id);
+		return -EINVAL;
+	}
+
+	mutex_lock(&p->mutex);
+	retval = pqm_set_gws(&p->pqm, args->queue_id, args->num_gws ? dev->gws : NULL);
+	mutex_unlock(&p->mutex);
+
+	args->first_gws = 0;
+	return retval;
+}
+
  static int kfd_ioctl_get_dmabuf_info(struct file *filep,
  		struct kfd_process *p, void *data)
  {
@@ -1761,6 +1786,8 @@ static const struct amdkfd_ioctl_desc amdkfd_ioctls[] = {
  	AMDKFD_IOCTL_DEF(AMDKFD_IOC_IMPORT_DMABUF,
  				kfd_ioctl_import_dmabuf, 0),
 
+	AMDKFD_IOCTL_DEF(AMDKFD_IOC_ALLOC_QUEUE_GWS,
+			kfd_ioctl_alloc_queue_gws, 0),
  };
 
  #define AMDKFD_CORE_IOCTL_COUNT	ARRAY_SIZE(amdkfd_ioctls)
include/uapi/linux/kfd_ioctl.h +15 -0
index 20917c5..070d1bc 100644
@@ -410,6 +410,21 @@ struct kfd_ioctl_unmap_memory_from_gpu_args {
  	__u32 n_success;		/* to/from KFD */
  };
 
+/* Allocate GWS for specific queue
+ *
+ * @gpu_id:      device identifier
+ * @queue_id:    queue's id that GWS is allocated for
+ * @num_gws:     how many GWS to allocate
+ * @first_gws:   index of the first GWS allocated.
+ *               only support contiguous GWS allocation
+ */
+struct kfd_ioctl_alloc_queue_gws_args {
+	__u32 gpu_id;		/* to KFD */
+	__u32 queue_id;		/* to KFD */
+	__u32 num_gws;		/* to KFD */
+	__u32 first_gws;	/* from KFD */
+};
+
  struct kfd_ioctl_get_dmabuf_info_args {
  	__u64 size;		/* from KFD */
  	__u64 metadata_ptr;	/* to KFD */
@@ -529,7 +544,10 @@ enum kfd_mmio_remap {
  #define AMDKFD_IOC_IMPORT_DMABUF		\

include/uapi/linux/kfd_ioctl.h enum kfd_mmio_remap { · line 553

Quoted 10 lines
include/uapi/linux/kfd_ioctl.h +4 -1
  		AMDKFD_IOWR(0x1D, struct kfd_ioctl_import_dmabuf_args)
 
+#define AMDKFD_IOC_ALLOC_QUEUE_GWS		\
+		AMDKFD_IOWR(0x1E, struct kfd_ioctl_alloc_queue_gws_args)
+
  #define AMDKFD_COMMAND_START		0x01
-#define AMDKFD_COMMAND_END		0x1E
+#define AMDKFD_COMMAND_END		0x1F
 
  #endif

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 4f49af4d-0953-030c-bb1b-47b7a5fa7c7c-5C7GfCeVMHo@public.gmane.org

#12 lore raw

Re: [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS

Quoted 10 lines · Felix
Quoted 5 lines · Oak

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15

btw just noticed in passing we are adding new features to kfd, is there an open source developed userspace to go along with this, there needs to a dev branch in public before new ioctls/uapi surfaces should be added to the kernel.

The commits should probably have pointers to that branch.

Dave.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAPM=9tzs9adV7_ef4hpgswB-S==iQizAF_=FTarVm3EYwPCg0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#14 lore raw

Re: [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS

Quoted 7 lines · Dave Airlie
Quoted 6 lines · Felix
Quoted 5 lines · Oak

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15
Quoted 8 lines
Quoted 2 lines

btw just noticed in passing we are adding new features to kfd, is there an open source developed userspace to go along with this, there needs to a dev branch in public before new ioctls/uapi surfaces should be added to the kernel.

The commits should probably have pointers to that branch.

Ah, a chicken and egg problem. I think this is the first time we're adding a new ioctl to upstream KFD rather than upstreaming one that's been developed internally first. Maybe not the right way to do it.

I should be able to publish the user mode code in libhsakmt next week. Then we'll work on a kfdtest to validate the firmware functionality. Finally we'll use GWS further up the software stack for synchronization of concurrent compute workgroups.

Regards,
  Felix

Quoted 2 lines

Dave.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): e857f0f4-341d-1e64-0ffe-5b6812ca5b7f-5C7GfCeVMHo@public.gmane.org

#16 lore raw

Re: [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS

Quoted 16 lines · Felix
Quoted 14 lines · Dave Airlie
Quoted 8 lines · Felix
Quoted 5 lines · Oak

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15

btw just noticed in passing we are adding new features to kfd, is there an open source developed userspace to go along with this, there needs to a dev branch in public before new ioctls/uapi surfaces should be added to the kernel.

Quoted 5 lines
Quoted 1 line

The commits should probably have pointers to that branch.

Ah, a chicken and egg problem. I think this is the first time we're adding a new ioctl to upstream KFD rather than upstreaming one that's been developed internally first. Maybe not the right way to do it.

There is no chicken/egg problem here. You develop kernel and userspace in parallel in the open, once you are happy and both sides are reviewed you merge kernel then userspace.

Dave.

Quoted 12 lines

I should be able to publish the user mode code in libhsakmt next week. Then we'll work on a kfdtest to validate the firmware functionality. Finally we'll use GWS further up the software stack for synchronization of concurrent compute workgroups.

Regards,
Felix

Quoted 2 lines

Dave.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAPM=9tzQB_SbCHcAcs3PRq-maed9XdMroROWNQuf9DdgOH5zcQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#18 lore raw

Re: [PATCH 6/8] drm/amdkfd: New IOCTL to allocate queue GWS

Quoted 16 lines · Dave Airlie
Quoted 15 lines · Felix
Quoted 14 lines · Dave Airlie
Quoted 8 lines · Felix
Quoted 5 lines · Oak

Add a new kfd ioctl to allocate queue GWS. Queue
GWS is released on queue destroy.

Change-Id I60153c26a577992ad873e4292e759e5c3d5bbd15

btw just noticed in passing we are adding new features to kfd, is there an open source developed userspace to go along with this, there needs to a dev branch in public before new ioctls/uapi surfaces should be added to the kernel.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

The commits should probably have pointers to that branch.

Ah, a chicken and egg problem. I think this is the first time we're adding a new ioctl to upstream KFD rather than upstreaming one that's been developed internally first. Maybe not the right way to do it.

There is no chicken/egg problem here. You develop kernel and userspace in parallel in the open, once you are happy and both sides are reviewed you merge kernel then userspace.

You're right. It would be straight forward if we had public code review for the user mode component. We're trying to convince our dev-ops team that we need public git repositories without losing support from our internal build and test infrastructure. Your comment helps provide some context and urgency for that request.

Thanks,
  Felix

Quoted 13 lines

Dave.

Quoted 10 lines

I should be able to publish the user mode code in libhsakmt next week. Then we'll work on a kfdtest to validate the firmware functionality. Finally we'll use GWS further up the software stack for synchronization of concurrent compute workgroups.

Regards,
Felix

Quoted 1 line

Dave.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#19 lore raw

PATCH 7/8 drm/amdkfd: PM4 packets change to support GWS

In reply to a message not in the archive

Add a field in map_queues packet to indicate whether this is a gws control queue. Only one queue per process can be gws control queue. Change num_gws field in map_process packet to 7 bits

Change-Id I0db91d99c6962d14f9202b2eb950f8e7e497b79e
---
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue_v9.c | 1 +
 drivers/gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h  | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue_v9.c +1 -0
index 3dd731c..07f02f8e 100644
@@ -159,6 +159,7 @@ static int pm_map_queues_v9(struct packet_manager *pm, uint32_t *buffer,
 
 	packet->bitfields2.engine_sel =
 		engine_sel__mes_map_queues__compute_vi;
+	packet->bitfields2.gws_control_queue = q->gws ? 1 : 0;
 	packet->bitfields2.queue_type =
 		queue_type__mes_map_queues__normal_compute_vi;
 
drivers/gpu/drm/amd/amdkfd/kfd_pm4_headers_ai.h +4 -3
index 0661339..49ab66b 100644
@@ -176,8 +176,7 @@ struct pm4_mes_map_process {
 
 	union {
 		struct {
-			uint32_t num_gws:6;
-			uint32_t reserved7:1;
+			uint32_t num_gws:7;
 			uint32_t sdma_enable:1;
 			uint32_t num_oac:4;
 			uint32_t reserved8:4;
@@ -272,7 +271,9 @@ struct pm4_mes_map_queues {
 		struct {
 			uint32_t reserved1:4;
 			enum mes_map_queues_queue_sel_enum queue_sel:2;
-			uint32_t reserved2:15;
+			uint32_t reserved5:6;
+			uint32_t gws_control_queue:1;
+			uint32_t reserved2:8;
 			enum mes_map_queues_queue_type_enum queue_type:3;
 			uint32_t reserved3:2;
 			enum mes_map_queues_engine_sel_enum engine_sel:3;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#20 lore raw

PATCH 8/8 drm/amdkfd: Use kfd fd to mmap mmio

In reply to a message not in the archive

TTM doesn't support CPU mapping of sg type bo (under which mmio bo is created). Switch mmaping of mmio page to kfd device file.

Change-Id I1a1a24f2ac0662be3783d460c137731ade007b83
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 46 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
 2 files changed, 47 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +46 -0
index 455a3db..67d269b 100644
@@ -1309,6 +1309,15 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
 	args->handle = MAKE_HANDLE(args->gpu_id, idr_handle);
 	args->mmap_offset = offset;
 
+	/* MMIO is mapped through kfd device
+	 * Generate a kfd mmap offset
+	 */
+	if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {
+		args->mmap_offset = KFD_MMAP_TYPE_MMIO | KFD_MMAP_GPU_ID(args->gpu_id);
+		args->mmap_offset <<= PAGE_SHIFT;
+		args->mmap_offset |= amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+	}
+
 	return 0;
 
 err_free:
@@ -1880,6 +1889,39 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 	return retcode;
 }
 
+static int kfd_mmio_mmap(struct kfd_dev *dev, struct kfd_process *process,
+		      struct vm_area_struct *vma)
+{
+	phys_addr_t address;
+	int ret;
+
+	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
+		return -EINVAL;
+
+	address = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+
+	vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
+				VM_DONTDUMP | VM_PFNMAP;
+
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	pr_debug("Process %d mapping mmio page\n"
+		 "     target user address == 0x%08llX\n"
+		 "     physical address    == 0x%08llX\n"
+		 "     vm_flags            == 0x%04lX\n"
+		 "     size                == 0x%04lX\n",
+		 process->pasid, (unsigned long long) vma->vm_start,
+		 address, vma->vm_flags, PAGE_SIZE);
+
+	ret = io_remap_pfn_range(vma,
+				vma->vm_start,
+				address >> PAGE_SHIFT,
+				PAGE_SIZE,
+				vma->vm_page_prot);
+	return ret;
+}
+
+
 static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct kfd_process *process;
@@ -1910,6 +1952,10 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
 		if (!dev)
 			return -ENODEV;
 		return kfd_reserved_mem_mmap(dev, process, vma);
+	case KFD_MMAP_TYPE_MMIO:
+		if (!dev)
+			return -ENODEV;
+		return kfd_mmio_mmap(dev, process, vma);
 	}
 
 	return -EFAULT;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index 40a5c67..b61dc53 100644
@@ -59,6 +59,7 @@
 #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
 #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
+#define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
 #define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
 #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1558651263-3478-8-git-send-email-Oak.Zeng-5C7GfCeVMHo@public.gmane.org

#22 lore raw

Re: [PATCH 8/8] drm/amdkfd: Use kfd fd to mmap mmio

Am 24.05.19 um 00:41 schrieb Zeng, Oak:

Quoted 6 lines

TTM doesn't support CPU mapping of sg type bo (under which mmio bo is created). Switch mmaping of mmio page to kfd device file.

Change-Id I1a1a24f2ac0662be3783d460c137731ade007b83
Quoted 81 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 46 ++++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
  2 files changed, 47 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +46 -0
index 455a3db..67d269b 100644
@@ -1309,6 +1309,15 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
  	args->handle = MAKE_HANDLE(args->gpu_id, idr_handle);
  	args->mmap_offset = offset;
 
+	/* MMIO is mapped through kfd device
+	 * Generate a kfd mmap offset
+	 */
+	if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {
+		args->mmap_offset = KFD_MMAP_TYPE_MMIO | KFD_MMAP_GPU_ID(args->gpu_id);
+		args->mmap_offset <<= PAGE_SHIFT;
+		args->mmap_offset |= amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+	}
+
  	return 0;
 
  err_free:
@@ -1880,6 +1889,39 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  	return retcode;
  }
 
+static int kfd_mmio_mmap(struct kfd_dev *dev, struct kfd_process *process,
+		      struct vm_area_struct *vma)
+{
+	phys_addr_t address;
+	int ret;
+
+	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
+		return -EINVAL;
+
+	address = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+
+	vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
+				VM_DONTDUMP | VM_PFNMAP;
+
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	pr_debug("Process %d mapping mmio page\n"
+		 "     target user address == 0x%08llX\n"
+		 "     physical address    == 0x%08llX\n"
+		 "     vm_flags            == 0x%04lX\n"
+		 "     size                == 0x%04lX\n",
+		 process->pasid, (unsigned long long) vma->vm_start,
+		 address, vma->vm_flags, PAGE_SIZE);
+
+	ret = io_remap_pfn_range(vma,
+				vma->vm_start,
+				address >> PAGE_SHIFT,
+				PAGE_SIZE,
+				vma->vm_page_prot);
+	return ret;
+}
+
+
  static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
  	struct kfd_process *process;
@@ -1910,6 +1952,10 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  		if (!dev)
  			return -ENODEV;
  		return kfd_reserved_mem_mmap(dev, process, vma);
+	case KFD_MMAP_TYPE_MMIO:
+		if (!dev)
+			return -ENODEV;
+		return kfd_mmio_mmap(dev, process, vma);
  	}
 
  	return -EFAULT;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
index 40a5c67..b61dc53 100644

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 65

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -59,6 +59,7 @@
  #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
+#define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
  #define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#23 lore raw

Re: [PATCH 8/8] drm/amdkfd: Use kfd fd to mmap mmio

In reply to a message not in the archive

Hi Oak,

I'm not sure why this is part of the GWS patch series. It's unrelated to GWS. Anyway, see one comment inline.

Quoted 16 lines · Oak

TTM doesn't support CPU mapping of sg type bo (under which mmio bo is created). Switch mmaping of mmio page to kfd device file.

Change-Id I1a1a24f2ac0662be3783d460c137731ade007b83
---
  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 46 ++++++++++++++++++++++++++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h    |  1 +
  2 files changed, 47 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +0 -0
index 455a3db..67d269b 100644

drivers/gpu/drm/amd/amdkfd/kfd_chardev.c static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep, · line 1318

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +7 -0
@@ -1309,6 +1309,15 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file *filep,
  	args->handle = MAKE_HANDLE(args->gpu_id, idr_handle);
  	args->mmap_offset = offset;
 
+	/* MMIO is mapped through kfd device
+	 * Generate a kfd mmap offset
+	 */
+	if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {
+		args->mmap_offset = KFD_MMAP_TYPE_MMIO | KFD_MMAP_GPU_ID(args->gpu_id);
+		args->mmap_offset <<= PAGE_SHIFT;
+		args->mmap_offset |= amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);

It seems the mmio_remap_phys_addr doesn't need to be part of the mmap_offset. It's not used for anything in kfd_mmap. And it unnecessarily exposes a physical address to user mode, which we usually tend to avoid.

With that fixes, the patch is Reviewed-by: Felix Kuehling <[email protected]>

Regards,
  Felix

Quoted 61 lines
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +39 -0
+	}
+
  	return 0;
 
  err_free:
@@ -1880,6 +1889,39 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  	return retcode;
  }
 
+static int kfd_mmio_mmap(struct kfd_dev *dev, struct kfd_process *process,
+		      struct vm_area_struct *vma)
+{
+	phys_addr_t address;
+	int ret;
+
+	if (vma->vm_end - vma->vm_start != PAGE_SIZE)
+		return -EINVAL;
+
+	address = amdgpu_amdkfd_get_mmio_remap_phys_addr(dev->kgd);
+
+	vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND | VM_NORESERVE |
+				VM_DONTDUMP | VM_PFNMAP;
+
+	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+
+	pr_debug("Process %d mapping mmio page\n"
+		 "     target user address == 0x%08llX\n"
+		 "     physical address    == 0x%08llX\n"
+		 "     vm_flags            == 0x%04lX\n"
+		 "     size                == 0x%04lX\n",
+		 process->pasid, (unsigned long long) vma->vm_start,
+		 address, vma->vm_flags, PAGE_SIZE);
+
+	ret = io_remap_pfn_range(vma,
+				vma->vm_start,
+				address >> PAGE_SHIFT,
+				PAGE_SIZE,
+				vma->vm_page_prot);
+	return ret;
+}
+
+
  static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  {
  	struct kfd_process *process;
@@ -1910,6 +1952,10 @@ static int kfd_mmap(struct file *filp, struct vm_area_struct *vma)
  		if (!dev)
  			return -ENODEV;
  		return kfd_reserved_mem_mmap(dev, process, vma);
+	case KFD_MMAP_TYPE_MMIO:
+		if (!dev)
+			return -ENODEV;
+		return kfd_mmio_mmap(dev, process, vma);
  	}
 
  	return -EFAULT;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +0 -0
index 40a5c67..b61dc53 100644

drivers/gpu/drm/amd/amdkfd/kfd_priv.h line 65

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
@@ -59,6 +59,7 @@
  #define KFD_MMAP_TYPE_DOORBELL	(0x3ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_EVENTS	(0x2ULL << KFD_MMAP_TYPE_SHIFT)
  #define KFD_MMAP_TYPE_RESERVED_MEM	(0x1ULL << KFD_MMAP_TYPE_SHIFT)
+#define KFD_MMAP_TYPE_MMIO	(0x0ULL << KFD_MMAP_TYPE_SHIFT)
 
  #define KFD_MMAP_GPU_ID_SHIFT (46 - PAGE_SHIFT)
  #define KFD_MMAP_GPU_ID_MASK (((1ULL << KFD_GPU_ID_HASH_WIDTH) - 1) \

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx