Skip to contentSkip to conversation

hsa/radeon: Fix memory size allocated for HPD

PATCH In review Oded Gabbay 3 participants 58 messages Jul 10, 2014 – Jul 11, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 29/83 hsa/radeon: Fix memory size allocated for HPD

---
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +1 -1
index 3c3e7d6..5bfde5c 100644
@@ -433,7 +433,7 @@ static int cik_static_create(struct kfd_dev *dev, struct kfd_scheduler **schedul
 	 * are no active queues.
 	 */
 	err = radeon_kfd_vidmem_alloc(dev,
-				      CIK_HPD_SIZE * priv->num_pipes * 2,
+				      CIK_HPD_SIZE * priv->num_pipes,
 				      PAGE_SIZE,
 				      KFD_MEMPOOL_SYSTEM_WRITECOMBINE,
 				      &priv->hpd_mem);
Signature · 1 line
1.9.1
#1 lore raw

PATCH 30/83 hsa/radeon: Fix list of supported devices

---
 drivers/gpu/hsa/radeon/kfd_device.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
drivers/gpu/hsa/radeon/kfd_device.c +23 -5
index b627e57..a21c095 100644
@@ -27,7 +27,7 @@
 #include "kfd_priv.h"
 #include "kfd_scheduler.h"
 
-static const struct kfd_device_info bonaire_device_info = {
+static const struct kfd_device_info kaveri_device_info = {
 	.scheduler_class = &radeon_kfd_cik_static_scheduler_class,
 	.max_pasid_bits = 16,
 	.ih_ring_entry_size = 4 * sizeof(uint32_t)
@@ -40,10 +40,28 @@ struct kfd_deviceid {
 
 /* Please keep this sorted by increasing device id. */
 static const struct kfd_deviceid supported_devices[] = {
-	{ 0x1305, &bonaire_device_info },	/* Kaveri */
-	{ 0x1307, &bonaire_device_info },	/* Kaveri */
-	{ 0x130F, &bonaire_device_info },	/* Kaveri */
-	{ 0x665C, &bonaire_device_info },	/* Bonaire */
+	{ 0x1304, &kaveri_device_info },	/* Kaveri */
+	{ 0x1305, &kaveri_device_info },	/* Kaveri */
+	{ 0x1306, &kaveri_device_info },	/* Kaveri */
+	{ 0x1307, &kaveri_device_info },	/* Kaveri */
+	{ 0x1309, &kaveri_device_info },	/* Kaveri */
+	{ 0x130A, &kaveri_device_info },	/* Kaveri */
+	{ 0x130B, &kaveri_device_info },	/* Kaveri */
+	{ 0x130C, &kaveri_device_info },	/* Kaveri */
+	{ 0x130D, &kaveri_device_info },	/* Kaveri */
+	{ 0x130E, &kaveri_device_info },	/* Kaveri */
+	{ 0x130F, &kaveri_device_info },	/* Kaveri */
+	{ 0x1310, &kaveri_device_info },	/* Kaveri */
+	{ 0x1311, &kaveri_device_info },	/* Kaveri */
+	{ 0x1312, &kaveri_device_info },	/* Kaveri */
+	{ 0x1313, &kaveri_device_info },	/* Kaveri */
+	{ 0x1315, &kaveri_device_info },	/* Kaveri */
+	{ 0x1316, &kaveri_device_info },	/* Kaveri */
+	{ 0x1317, &kaveri_device_info },	/* Kaveri */
+	{ 0x1318, &kaveri_device_info },	/* Kaveri */
+	{ 0x131B, &kaveri_device_info },	/* Kaveri */
+	{ 0x131C, &kaveri_device_info },	/* Kaveri */
+	{ 0x131D, &kaveri_device_info },	/* Kaveri */
 };
 
 static const struct kfd_device_info *
Signature · 1 line
1.9.1
#2 lore raw

PATCH 31/83 drm/radeon: extending kfd-kgd interface

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Adding API for KFD to be able to query the GPU clock counter.

---
 drivers/gpu/drm/radeon/radeon_kfd.c | 9 +++++++++
 include/linux/radeon_kfd.h          | 1 +
 2 files changed, 10 insertions(+)
drivers/gpu/drm/radeon/radeon_kfd.c +9 -0
index f4cc3c5..121e67b 100644
@@ -42,6 +42,7 @@ static int kmap_mem(struct kgd_dev *kgd, struct kgd_mem *mem, void **ptr);
 static void unkmap_mem(struct kgd_dev *kgd, struct kgd_mem *mem);
 
 static uint64_t get_vmem_size(struct kgd_dev *kgd);
+static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd);
 
 static void lock_srbm_gfx_cntl(struct kgd_dev *kgd);
 static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd);
@@ -55,6 +56,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
 	.kmap_mem = kmap_mem,
 	.unkmap_mem = unkmap_mem,
 	.get_vmem_size = get_vmem_size,
+	.get_gpu_clock_counter = get_gpu_clock_counter,
 	.lock_srbm_gfx_cntl = lock_srbm_gfx_cntl,
 	.unlock_srbm_gfx_cntl = unlock_srbm_gfx_cntl,
 };
@@ -275,3 +277,10 @@ static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd)
 
 	mutex_unlock(&rdev->srbm_mutex);
 }
+
+static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd)
+{
+	struct radeon_device *rdev = (struct radeon_device *)kgd;
+
+	return rdev->asic->get_gpu_clock_counter(rdev);
+}
include/linux/radeon_kfd.h +1 -0
index 63b7bac..fcb6c7a 100644
@@ -84,6 +84,7 @@ struct kfd2kgd_calls {
 	void (*unkmap_mem)(struct kgd_dev *kgd, struct kgd_mem *mem);
 
 	uint64_t (*get_vmem_size)(struct kgd_dev *kgd);
+	uint64_t (*get_gpu_clock_counter)(struct kgd_dev *kgd);
 
 	/* SRBM_GFX_CNTL mutex */
 	void (*lock_srbm_gfx_cntl)(struct kgd_dev *kgd);
Signature · 1 line
1.9.1
#3 lore raw

PATCH 32/83 hsa/radeon: implementing IOCTL for clock counters

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Implemented new IOCTL to query the CPU and GPU clock counters.

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 37 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/kfd_ioctl.h       |  9 +++++++++
 2 files changed, 46 insertions(+)
drivers/gpu/hsa/radeon/kfd_chardev.c +37 -0
index ddaf357..d6fa980 100644
@@ -28,6 +28,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <uapi/linux/kfd_ioctl.h>
+#include <linux/time.h>
 #include "kfd_priv.h"
 #include "kfd_scheduler.h"
 
@@ -284,6 +285,38 @@ out:
 	return err;
 }
 
+static long
+kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_process *p, void __user *arg)
+{
+	struct kfd_ioctl_get_clock_counters_args args;
+	struct kfd_dev *dev;
+	struct timespec time;
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+
+	dev = radeon_kfd_device_by_id(args.gpu_id);
+	if (dev == NULL)
+		return -EINVAL;
+
+	/* Reading GPU clock counter from KGD */
+	args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd);
+
+	/* No access to rdtsc. Using raw monotonic time */
+	getrawmonotonic(&time);
+	args.cpu_clock_counter = time.tv_nsec;
+
+	get_monotonic_boottime(&time);
+	args.system_clock_counter = time.tv_nsec;
+
+	/* Since the counter is in nano-seconds we use 1GHz frequency */
+	args.system_clock_freq = 1000000000;
+
+	if (copy_to_user(arg, &args, sizeof(args)))
+		return -EFAULT;
+
+	return 0;
+}
 
 static long
 kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
@@ -312,6 +345,10 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		err = kfd_ioctl_set_memory_policy(filep, process, (void __user *)arg);
 		break;
 
+	case KFD_IOC_GET_CLOCK_COUNTERS:
+		err = kfd_ioctl_get_clock_counters(filep, process, (void __user *)arg);
+		break;
+
 	default:
 		dev_err(kfd_device,
 			"unknown ioctl cmd 0x%x, arg 0x%lx)\n",
include/uapi/linux/kfd_ioctl.h +9 -0
index 928e628..5b9517e 100644
@@ -70,12 +70,21 @@ struct kfd_ioctl_set_memory_policy_args {
 	uint64_t alternate_aperture_size;	/* to KFD */
 };
 
+struct kfd_ioctl_get_clock_counters_args {
+	uint32_t gpu_id;		/* to KFD */
+	uint64_t gpu_clock_counter;	/* from KFD */
+	uint64_t cpu_clock_counter;	/* from KFD */
+	uint64_t system_clock_counter;	/* from KFD */
+	uint64_t system_clock_freq;	/* from KFD */
+};
+
 #define KFD_IOC_MAGIC 'K'
 
 #define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
 #define KFD_IOC_CREATE_QUEUE	_IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args)
 #define KFD_IOC_DESTROY_QUEUE	_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
+#define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1
#5 lore raw

PATCH 33/83 hsa/radeon: Fix coding style in cik_int.h

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/cik_int.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/hsa/radeon/cik_int.h +10 -10
index e98551d..350f0c2 100644
@@ -26,20 +26,20 @@
 #include <linux/types.h>
 
 struct cik_ih_ring_entry {
-	uint32_t source_id	: 8;
-	uint32_t reserved1	: 8;
-	uint32_t reserved2	: 16;
+	uint32_t source_id:8;
+	uint32_t reserved1:8;
+	uint32_t reserved2:16;
 
-	uint32_t data		: 28;
-	uint32_t reserved3	: 4;
+	uint32_t data:28;
+	uint32_t reserved3:4;
 
 	/* pipeid, meid and unused3 are officially called RINGID,
 	 * but for our purposes, they always decode into pipe and ME. */
-	uint32_t pipeid		: 2;
-	uint32_t meid		: 2;
-	uint32_t reserved4	: 4;
-	uint32_t vmid		: 8;
-	uint32_t pasid		: 16;
+	uint32_t pipeid:2;
+	uint32_t meid:2;
+	uint32_t reserved4:4;
+	uint32_t vmid:8;
+	uint32_t pasid:16;
 
 	uint32_t reserved5;
 };
Signature · 1 line
1.9.1
#6 lore raw

PATCH 34/83 drm/radeon: adding synchronization for GRBM GFX

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Implementing a lock for selecting and accessing shader engines and arrays. This lock will make sure that drm/radeon and hsa/radeon are not colliding when accessing shader engines and arrays with GRBM_GFX_INDEX register.

---
 drivers/gpu/drm/radeon/cik.c           | 26 ++++++++++++++++++++++++++
 drivers/gpu/drm/radeon/radeon.h        |  2 ++
 drivers/gpu/drm/radeon/radeon_device.c |  1 +
 drivers/gpu/drm/radeon/radeon_kfd.c    | 23 +++++++++++++++++++++++
 include/linux/radeon_kfd.h             |  4 ++++
 5 files changed, 56 insertions(+)
drivers/gpu/drm/radeon/cik.c +26 -0
index 6f4999a..fc560b0 100644
@@ -1566,6 +1566,8 @@ static const u32 godavari_golden_registers[] =
 
 static void cik_init_golden_registers(struct radeon_device *rdev)
 {
+	/* Some of the registers might be dependant on GRBM_GFX_INDEX */
+	mutex_lock(&rdev->grbm_idx_mutex);
 	switch (rdev->family) {
 	case CHIP_BONAIRE:
 		radeon_program_register_sequence(rdev,
@@ -1640,6 +1642,7 @@ static void cik_init_golden_registers(struct radeon_device *rdev)
 	default:
 		break;
 	}
+	mutex_unlock(&rdev->grbm_idx_mutex);
 }
 
 /**
@@ -3421,6 +3424,7 @@ static void cik_setup_rb(struct radeon_device *rdev,
 	u32 disabled_rbs = 0;
 	u32 enabled_rbs = 0;
 
+	mutex_lock(&rdev->grbm_idx_mutex);
 	for (i = 0; i < se_num; i++) {
 		for (j = 0; j < sh_per_se; j++) {
 			cik_select_se_sh(rdev, i, j);
@@ -3432,6 +3436,7 @@ static void cik_setup_rb(struct radeon_device *rdev,
 		}
 	}
 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 
 	mask = 1;
 	for (i = 0; i < max_rb_num_per_se * se_num; i++) {
@@ -3442,6 +3447,7 @@ static void cik_setup_rb(struct radeon_device *rdev,
 
 	rdev->config.cik.backend_enable_mask = enabled_rbs;
 
+	mutex_lock(&rdev->grbm_idx_mutex);
 	for (i = 0; i < se_num; i++) {
 		cik_select_se_sh(rdev, i, 0xffffffff);
 		data = 0;
@@ -3469,6 +3475,7 @@ static void cik_setup_rb(struct radeon_device *rdev,
 		WREG32(PA_SC_RASTER_CONFIG, data);
 	}
 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 }
 
 /**
@@ -3686,6 +3693,12 @@ static void cik_gpu_init(struct radeon_device *rdev)
 	/* set HW defaults for 3D engine */
 	WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
 
+	mutex_lock(&rdev->grbm_idx_mutex);
+	/*
+	 * making sure that the following register writes will be broadcasted
+	 * to all the shaders
+	 */
+	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
 	WREG32(SX_DEBUG_1, 0x20);
 
 	WREG32(TA_CNTL_AUX, 0x00010000);
@@ -3741,6 +3754,7 @@ static void cik_gpu_init(struct radeon_device *rdev)
 
 	WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
 	WREG32(PA_SC_ENHANCE, ENABLE_PA_SC_OUT_OF_ORDER);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 
 	udelay(50);
 }
@@ -6040,6 +6054,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
 	u32 i, j, k;
 	u32 mask;
 
+	mutex_lock(&rdev->grbm_idx_mutex);
 	for (i = 0; i < rdev->config.cik.max_shader_engines; i++) {
 		for (j = 0; j < rdev->config.cik.max_sh_per_se; j++) {
 			cik_select_se_sh(rdev, i, j);
@@ -6051,6 +6066,7 @@ static void cik_wait_for_rlc_serdes(struct radeon_device *rdev)
 		}
 	}
 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 
 	mask = SE_MASTER_BUSY_MASK | GC_MASTER_BUSY | TC0_MASTER_BUSY | TC1_MASTER_BUSY;
 	for (k = 0; k < rdev->usec_timeout; k++) {
@@ -6185,10 +6201,12 @@ static int cik_rlc_resume(struct radeon_device *rdev)
 	WREG32(RLC_LB_CNTR_INIT, 0);
 	WREG32(RLC_LB_CNTR_MAX, 0x00008000);
 
+	mutex_lock(&rdev->grbm_idx_mutex);
 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
 	WREG32(RLC_LB_INIT_CU_MASK, 0xffffffff);
 	WREG32(RLC_LB_PARAMS, 0x00600408);
 	WREG32(RLC_LB_CNTL, 0x80000004);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 
 	WREG32(RLC_MC_CNTL, 0);
 	WREG32(RLC_UCODE_CNTL, 0);
@@ -6255,11 +6273,13 @@ static void cik_enable_cgcg(struct radeon_device *rdev, bool enable)
 
 		tmp = cik_halt_rlc(rdev);
 
+		mutex_lock(&rdev->grbm_idx_mutex);
 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
 		tmp2 = BPM_ADDR_MASK | CGCG_OVERRIDE_0 | CGLS_ENABLE;
 		WREG32(RLC_SERDES_WR_CTRL, tmp2);
+		mutex_unlock(&rdev->grbm_idx_mutex);
 
 		cik_update_rlc(rdev, tmp);
 
@@ -6301,11 +6321,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
 
 		tmp = cik_halt_rlc(rdev);
 
+		mutex_lock(&rdev->grbm_idx_mutex);
 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
 		data = BPM_ADDR_MASK | MGCG_OVERRIDE_0;
 		WREG32(RLC_SERDES_WR_CTRL, data);
+		mutex_unlock(&rdev->grbm_idx_mutex);
 
 		cik_update_rlc(rdev, tmp);
 
@@ -6349,11 +6371,13 @@ static void cik_enable_mgcg(struct radeon_device *rdev, bool enable)
 
 		tmp = cik_halt_rlc(rdev);
 
+		mutex_lock(&rdev->grbm_idx_mutex);
 		cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
 		WREG32(RLC_SERDES_WR_CU_MASTER_MASK, 0xffffffff);
 		WREG32(RLC_SERDES_WR_NONCU_MASTER_MASK, 0xffffffff);
 		data = BPM_ADDR_MASK | MGCG_OVERRIDE_1;
 		WREG32(RLC_SERDES_WR_CTRL, data);
+		mutex_unlock(&rdev->grbm_idx_mutex);
 
 		cik_update_rlc(rdev, tmp);
 	}
@@ -6786,10 +6810,12 @@ static u32 cik_get_cu_active_bitmap(struct radeon_device *rdev, u32 se, u32 sh)
 	u32 mask = 0, tmp, tmp1;
 	int i;
 
+	mutex_lock(&rdev->grbm_idx_mutex);
 	cik_select_se_sh(rdev, se, sh);
 	tmp = RREG32(CC_GC_SHADER_ARRAY_CONFIG);
 	tmp1 = RREG32(GC_USER_SHADER_ARRAY_CONFIG);
 	cik_select_se_sh(rdev, 0xffffffff, 0xffffffff);
+	mutex_unlock(&rdev->grbm_idx_mutex);
 
 	tmp &= 0xffff0000;
 
drivers/gpu/drm/radeon/radeon.h +2 -0
index 90f66bb..94b38a7 100644
@@ -2334,6 +2334,8 @@ struct radeon_device {
 	struct radeon_atcs		atcs;
 	/* srbm instance registers */
 	struct mutex			srbm_mutex;
+	/* GRBM index mutex. Protects concurrents access to GRBM index */
+	struct mutex			grbm_idx_mutex;
 	/* clock, powergating flags */
 	u32 cg_flags;
 	u32 pg_flags;
drivers/gpu/drm/radeon/radeon_device.c +1 -0
index 98538d2..1b8b8b7 100644
@@ -1258,6 +1258,7 @@ int radeon_device_init(struct radeon_device *rdev,
 	mutex_init(&rdev->pm.mutex);
 	mutex_init(&rdev->gpu_clock_mutex);
 	mutex_init(&rdev->srbm_mutex);
+	mutex_init(&rdev->grbm_idx_mutex);
 	init_rwsem(&rdev->pm.mclk_lock);
 	init_rwsem(&rdev->exclusive_lock);
 	init_waitqueue_head(&rdev->irq.vblank_queue);
drivers/gpu/drm/radeon/radeon_kfd.c +23 -0
index 121e67b..6dba170 100644
@@ -47,6 +47,9 @@ static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd);
 static void lock_srbm_gfx_cntl(struct kgd_dev *kgd);
 static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd);
 
+static void lock_grbm_gfx_idx(struct kgd_dev *kgd);
+static void unlock_grbm_gfx_idx(struct kgd_dev *kgd);
+
 
 static const struct kfd2kgd_calls kfd2kgd = {
 	.allocate_mem = allocate_mem,
@@ -59,6 +62,8 @@ static const struct kfd2kgd_calls kfd2kgd = {
 	.get_gpu_clock_counter = get_gpu_clock_counter,
 	.lock_srbm_gfx_cntl = lock_srbm_gfx_cntl,
 	.unlock_srbm_gfx_cntl = unlock_srbm_gfx_cntl,
+	.lock_grbm_gfx_idx = lock_grbm_gfx_idx,
+	.unlock_grbm_gfx_idx = unlock_grbm_gfx_idx,
 };
 
 static const struct kgd2kfd_calls *kgd2kfd;
@@ -278,6 +283,24 @@ static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd)
 	mutex_unlock(&rdev->srbm_mutex);
 }
 
+static void lock_grbm_gfx_idx(struct kgd_dev *kgd)
+{
+	struct radeon_device *rdev = (struct radeon_device *)kgd;
+
+	BUG_ON(kgd == NULL);
+
+	mutex_lock(&rdev->grbm_idx_mutex);
+}
+
+static void unlock_grbm_gfx_idx(struct kgd_dev *kgd)
+{
+	struct radeon_device *rdev = (struct radeon_device *)kgd;
+
+	BUG_ON(kgd == NULL);
+
+	mutex_unlock(&rdev->grbm_idx_mutex);
+}
+
 static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd)
 {
 	struct radeon_device *rdev = (struct radeon_device *)kgd;
include/linux/radeon_kfd.h +4 -0
index fcb6c7a..4c7e923 100644
@@ -89,6 +89,10 @@ struct kfd2kgd_calls {
 	/* SRBM_GFX_CNTL mutex */
 	void (*lock_srbm_gfx_cntl)(struct kgd_dev *kgd);
 	void (*unlock_srbm_gfx_cntl)(struct kgd_dev *kgd);
+
+	/* GRBM_GFX_INDEX mutex */
+	void (*lock_grbm_gfx_idx)(struct kgd_dev *kgd);
+	void (*unlock_grbm_gfx_idx)(struct kgd_dev *kgd);
 };
 
 bool kgd2kfd_init(unsigned interface_version,
Signature · 1 line
1.9.1
#7 lore raw

PATCH 35/83 hsa/radeon: Print ioctl commnad only in debug mode

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +3 -3
index d6fa980..dba6084 100644
@@ -324,9 +324,9 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 	struct kfd_process *process;
 	long err = -EINVAL;
 
-	dev_info(kfd_device,
-		 "ioctl cmd 0x%x (#%d), arg 0x%lx\n",
-		 cmd, _IOC_NR(cmd), arg);
+	dev_dbg(kfd_device,
+		"ioctl cmd 0x%x (#%d), arg 0x%lx\n",
+		cmd, _IOC_NR(cmd), arg);
 
 	process = radeon_kfd_get_process(current);
 	if (IS_ERR(process))
Signature · 1 line
1.9.1
#8 lore raw

PATCH 36/83 hsa/radeon: fixing clock counters bug

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Fixed wrong reporting of timestamps in kfd_ioctl_get_clock_counters.

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +2 -2
index dba6084..75fe11f 100644
@@ -304,10 +304,10 @@ kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_process *p, void __u
 
 	/* No access to rdtsc. Using raw monotonic time */
 	getrawmonotonic(&time);
-	args.cpu_clock_counter = time.tv_nsec;
+	args.cpu_clock_counter = (uint64_t)timespec_to_ns(&time);
 
 	get_monotonic_boottime(&time);
-	args.system_clock_counter = time.tv_nsec;
+	args.system_clock_counter = (uint64_t)timespec_to_ns(&time);
 
 	/* Since the counter is in nano-seconds we use 1GHz frequency */
 	args.system_clock_freq = 1000000000;
Signature · 1 line
1.9.1
#9 lore raw

PATCH 37/83 hsa/radeon: Print ISR info only in debug mode

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +1 -1
index 5bfde5c..7573d25 100644
@@ -899,7 +899,7 @@ cik_static_interrupt_isr(struct kfd_scheduler *scheduler, const void *ih_ring_en
 	if (!int_compute_pipe(priv, ihre, &pipe_id))
 		return false;
 
-	dev_info(radeon_kfd_chardev(), "INT(ISR): src=%02x, data=0x%x, pipe=%u, vmid=%u, pasid=%u\n",
+	dev_dbg(radeon_kfd_chardev(), "INT(ISR): src=%02x, data=0x%x, pipe=%u, vmid=%u, pasid=%u\n",
 		 ihre->source_id, ihre->data, pipe_id, ihre->vmid, ihre->pasid);
 
 	switch (source_id) {
Signature · 1 line
1.9.1
#10 lore raw

PATCH 38/83 hsa/radeon: Workaround for a bug in amd_iommu

In reply to Oded Gabbay

This patch creates a workaround for a bug in amd_iommu driver, where the driver
doesn't save all necessary information when going to suspend.
The workaround removes a device from the IOMMU device list on suspend and register a resumed device in the IOMMU device list.

---
 drivers/gpu/hsa/radeon/Makefile     |  2 +-
 drivers/gpu/hsa/radeon/kfd_device.c | 30 ++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_pasid.c  |  5 +++++
 drivers/gpu/hsa/radeon/kfd_pm.c     | 43 -------------------------------------
 drivers/gpu/hsa/radeon/kfd_priv.h   |  1 +
 5 files changed, 37 insertions(+), 44 deletions(-)
 delete mode 100644 drivers/gpu/hsa/radeon/kfd_pm.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index 935f9b7..5422e6a 100644
@@ -5,6 +5,6 @@
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
-		kfd_vidmem.o kfd_interrupt.o kfd_pm.o
+		kfd_vidmem.o kfd_interrupt.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_device.c +30 -0
index a21c095..2e7d50d 100644
@@ -188,3 +188,33 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)
 
 	kfree(kfd);
 }
+
+void kgd2kfd_suspend(struct kfd_dev *kfd)
+{
+	BUG_ON(kfd == NULL);
+
+	if (kfd->init_complete) {
+		kfd->device_info->scheduler_class->stop(kfd->scheduler);
+		amd_iommu_free_device(kfd->pdev);
+	}
+}
+
+int kgd2kfd_resume(struct kfd_dev *kfd)
+{
+	pasid_t pasid_limit;
+	int err;
+
+	BUG_ON(kfd == NULL);
+
+	pasid_limit = radeon_kfd_get_pasid_limit();
+
+	if (kfd->init_complete) {
+		err = amd_iommu_init_device(kfd->pdev, pasid_limit);
+		if (err < 0)
+			return -ENXIO;
+		amd_iommu_set_invalidate_ctx_cb(kfd->pdev, iommu_pasid_shutdown_callback);
+		kfd->device_info->scheduler_class->start(kfd->scheduler);
+	}
+
+	return 0;
+}
drivers/gpu/hsa/radeon/kfd_pasid.c +5 -0
index d78bd00..8bd1562 100644
@@ -68,6 +68,11 @@ bool radeon_kfd_set_pasid_limit(pasid_t new_limit)
 	return true;
 }
 
+inline pasid_t radeon_kfd_get_pasid_limit(void)
+{
+	return pasid_limit;
+}
+
 pasid_t radeon_kfd_pasid_alloc(void)
 {
 	pasid_t found;
drivers/gpu/hsa/radeon/kfd_pm.c deleted +0 -43

43 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +1 -0
index bca9cce..8b877ca 100644
@@ -213,6 +213,7 @@ struct kfd_queue *radeon_kfd_get_queue(struct kfd_process *p, unsigned int queue
 int radeon_kfd_pasid_init(void);
 void radeon_kfd_pasid_exit(void);
 bool radeon_kfd_set_pasid_limit(pasid_t new_limit);
+pasid_t radeon_kfd_get_pasid_limit(void);
 pasid_t radeon_kfd_pasid_alloc(void);
 void radeon_kfd_pasid_free(pasid_t pasid);
 
Signature · 1 line
1.9.1
#12 lore raw

PATCH 39/83 drm/radeon: Extending kfd interface

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Adding new function to the interface used by kfd. The new function retrieves the max engine clock speed.

---
 drivers/gpu/drm/radeon/radeon_kfd.c | 11 +++++++++++
 include/linux/radeon_kfd.h          |  2 ++
 2 files changed, 13 insertions(+)
drivers/gpu/drm/radeon/radeon_kfd.c +11 -0
index 6dba170..8b6d497 100644
@@ -50,6 +50,8 @@ static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd);
 static void lock_grbm_gfx_idx(struct kgd_dev *kgd);
 static void unlock_grbm_gfx_idx(struct kgd_dev *kgd);
 
+static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd);
+
 
 static const struct kfd2kgd_calls kfd2kgd = {
 	.allocate_mem = allocate_mem,
@@ -64,6 +66,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
 	.unlock_srbm_gfx_cntl = unlock_srbm_gfx_cntl,
 	.lock_grbm_gfx_idx = lock_grbm_gfx_idx,
 	.unlock_grbm_gfx_idx = unlock_grbm_gfx_idx,
+	.get_max_engine_clock_in_mhz = get_max_engine_clock_in_mhz,
 };
 
 static const struct kgd2kfd_calls *kgd2kfd;
@@ -307,3 +310,11 @@ static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd)
 
 	return rdev->asic->get_gpu_clock_counter(rdev);
 }
+
+static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd)
+{
+	struct radeon_device *rdev = (struct radeon_device *)kgd;
+
+	/* The sclk is in quantas of 10kHz */
+	return rdev->pm.power_state->clock_info->sclk / 100;
+}
include/linux/radeon_kfd.h +2 -0
index 4c7e923..4114c8e 100644
@@ -93,6 +93,8 @@ struct kfd2kgd_calls {
 	/* GRBM_GFX_INDEX mutex */
 	void (*lock_grbm_gfx_idx)(struct kgd_dev *kgd);
 	void (*unlock_grbm_gfx_idx)(struct kgd_dev *kgd);
+
+	uint32_t (*get_max_engine_clock_in_mhz)(struct kgd_dev *kgd);
 };
 
 bool kgd2kfd_init(unsigned interface_version,
Signature · 1 line
1.9.1
#13 lore raw

PATCH 40/83 hsa/radeon: Adding max clock speeds to topology

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Adding support for CPU and GPU max clock speeds in node properties.

---
 drivers/gpu/hsa/radeon/kfd_topology.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_topology.c +4 -2
index 2ee5444..21bb66e 100644
@@ -26,6 +26,7 @@
 #include <linux/errno.h>
 #include <linux/acpi.h>
 #include <linux/hash.h>
+#include <linux/cpufreq.h>
 
 #include "kfd_priv.h"
 #include "kfd_crat.h"
@@ -712,9 +713,10 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 		sysfs_show_32bit_prop(buffer, "location_id",
 				dev->node_props.location_id);
 		sysfs_show_32bit_prop(buffer, "max_engine_clk_fcompute",
-				dev->node_props.max_engine_clk_fcompute);
+				kfd2kgd->get_max_engine_clock_in_mhz(
+					dev->gpu->kgd));
 		ret = sysfs_show_32bit_prop(buffer, "max_engine_clk_ccompute",
-				dev->node_props.max_engine_clk_ccompute);
+				cpufreq_quick_get_max(0)/1000);
 	}
 
 	return ret;
Signature · 1 line
1.9.1
#14 lore raw

PATCH 41/83 hsa/radeon: Alternating the source of max clock

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Changing the source of the max engine clock value.

---
 drivers/gpu/drm/radeon/radeon_kfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/radeon/radeon_kfd.c +1 -1
index 8b6d497..a28cf6b 100644
@@ -316,5 +316,5 @@ static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd)
 	struct radeon_device *rdev = (struct radeon_device *)kgd;
 
 	/* The sclk is in quantas of 10kHz */
-	return rdev->pm.power_state->clock_info->sclk / 100;
+	return rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac.sclk / 100;
 }
Signature · 1 line
1.9.1
#15 lore raw

PATCH 42/83 hsa/radeon: 32-bit processes support

In reply to Oded Gabbay

From: Alexey Skidanov <[email protected]>

Initializing compat_ioctl properly. All ioctls args are packed.

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 7 +++++--
 drivers/gpu/hsa/radeon/kfd_priv.h    | 4 ++++
 include/uapi/linux/kfd_ioctl.h       | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +5 -2
index 75fe11f..e95d597 100644
@@ -27,6 +27,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/compat.h>
 #include <uapi/linux/kfd_ioctl.h>
 #include <linux/time.h>
 #include "kfd_priv.h"
@@ -41,6 +42,7 @@ static const char kfd_dev_name[] = "kfd";
 static const struct file_operations kfd_fops = {
 	.owner = THIS_MODULE,
 	.unlocked_ioctl = kfd_ioctl,
+	.compat_ioctl = kfd_ioctl,
 	.open = kfd_open,
 	.mmap = kfd_mmap,
 };
@@ -105,8 +107,9 @@ kfd_open(struct inode *inode, struct file *filep)
 	process = radeon_kfd_create_process(current);
 	if (IS_ERR(process))
 		return PTR_ERR(process);
-
-	pr_debug("\nkfd: process %d opened dev/kfd", process->pasid);
+	process->is_32bit_user_mode = is_compat_task();
+	dev_info(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
+				process->pasid, process->is_32bit_user_mode);
 
 	return 0;
 }
drivers/gpu/hsa/radeon/kfd_priv.h +4 -0
index 8b877ca..9d3b1fc 100644
@@ -194,6 +194,10 @@ struct kfd_process {
 	size_t queue_array_size;
 	struct kfd_queue **queues;	/* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */
 	unsigned long allocated_queue_bitmap[DIV_ROUND_UP(MAX_PROCESS_QUEUES, BITS_PER_LONG)];
+
+	/*Is the user space process 32 bit?*/
+	bool is_32bit_user_mode;
+
 };
 
 struct kfd_process *radeon_kfd_create_process(const struct task_struct *);
include/uapi/linux/kfd_ioctl.h +1 -1
index 5b9517e..a7c3abd 100644
@@ -29,7 +29,7 @@
 #define KFD_IOCTL_CURRENT_VERSION 1
 
 /* The 64-bit ABI is the authoritative version. */
-#pragma pack(push, 8)
+#pragma pack(push, 1)
 
 struct kfd_ioctl_get_version_args {
 	uint32_t min_supported_version;	/* from KFD */
Signature · 1 line
1.9.1
#16 lore raw

PATCH 43/83 hsa/radeon: NULL pointer dereference bug workaround

In reply to Oded Gabbay

From: Alexey Skidanov <[email protected]>

---
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +4 -2
index 7573d25..7ee8125 100644
@@ -627,8 +627,10 @@ static void cik_static_deregister_process(struct kfd_scheduler *scheduler,
 	struct cik_static_private *priv = kfd_scheduler_to_private(scheduler);
 	struct cik_static_process *pp = kfd_process_to_private(scheduler_process);
 
-	release_vmid(priv, pp->vmid);
-	kfree(pp);
+	if (priv && pp) {
+		release_vmid(priv, pp->vmid);
+		kfree(pp);
+	}
 }
 
 static bool allocate_hqd(struct cik_static_private *priv, unsigned int *queue)
Signature · 1 line
1.9.1
#17 lore raw

PATCH 44/83 hsa/radeon: HSA64/HSA32 modes support

In reply to Oded Gabbay

From: Alexey Skidanov <[email protected]>

Added apertures initialization and appropriate ioctl

---
 drivers/gpu/hsa/radeon/Makefile               |   2 +-
 drivers/gpu/hsa/radeon/kfd_aperture.c         | 124 ++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_chardev.c          |  58 +++++++++++-
 drivers/gpu/hsa/radeon/kfd_priv.h             |  18 ++++
 drivers/gpu/hsa/radeon/kfd_process.c          |  17 ++++
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c |   3 +-
 drivers/gpu/hsa/radeon/kfd_topology.c         |  27 ++++++
 include/uapi/linux/kfd_ioctl.h                |  18 ++++
 8 files changed, 264 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_aperture.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index 5422e6a..813b31f 100644
@@ -5,6 +5,6 @@
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
-		kfd_vidmem.o kfd_interrupt.o
+		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_aperture.c new file +124 -0

124 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_chardev.c +57 -1

84 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +18 -0
index 9d3b1fc..28155bc 100644
@@ -171,6 +171,16 @@ struct kfd_process_device {
 
 	/* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */
 	bool bound;
+
+	/*Apertures*/
+	uint64_t lds_base;
+	uint64_t lds_limit;
+	uint64_t gpuvm_base;
+	uint64_t gpuvm_limit;
+	uint64_t scratch_base;
+	uint64_t scratch_limit;
+
+
 };
 
 /* Process data */
@@ -212,6 +222,10 @@ void radeon_kfd_install_queue(struct kfd_process *p, unsigned int queue_id, stru
 void radeon_kfd_remove_queue(struct kfd_process *p, unsigned int queue_id);
 struct kfd_queue *radeon_kfd_get_queue(struct kfd_process *p, unsigned int queue_id);
 
+/* Process device data iterator */
+struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p);
+struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p, struct kfd_process_device *pdd);
+bool kfd_has_process_device_data(struct kfd_process *p);
 
 /* PASIDs */
 int radeon_kfd_pasid_init(void);
@@ -237,6 +251,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu);
 int kfd_topology_remove_device(struct kfd_dev *gpu);
 struct kfd_dev *radeon_kfd_device_by_id(uint32_t gpu_id);
 struct kfd_dev *radeon_kfd_device_by_pci_dev(const struct pci_dev *pdev);
+struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx);
 
 /* MMIO registers */
 #define WRITE_REG(dev, reg, value) radeon_kfd_write_reg((dev), (reg), (value))
@@ -253,4 +268,7 @@ void kgd2kfd_interrupt(struct kfd_dev *dev, const void *ih_ring_entry);
 void kgd2kfd_suspend(struct kfd_dev *dev);
 int kgd2kfd_resume(struct kfd_dev *dev);
 
+/*HSA apertures*/
+int kfd_init_apertures(struct kfd_process *process);
+
 #endif
drivers/gpu/hsa/radeon/kfd_process.c +17 -0
index f89f855..80136e6 100644
@@ -397,3 +397,20 @@ struct kfd_queue *radeon_kfd_get_queue(struct kfd_process *p, unsigned int queue
 		test_bit(queue_id, p->allocated_queue_bitmap)) ?
 			p->queues[queue_id] : NULL;
 }
+
+struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p)
+{
+	return list_first_entry(&p->per_device_data, struct kfd_process_device, per_device_list);
+}
+
+struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p, struct kfd_process_device *pdd)
+{
+	if (list_is_last(&pdd->per_device_list, &p->per_device_data))
+		return NULL;
+	return list_next_entry(pdd, per_device_list);
+}
+
+bool kfd_has_process_device_data(struct kfd_process *p)
+{
+	return !(list_empty(&p->per_device_data));
+}
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +2 -1
index 7ee8125..30561a6 100644
@@ -627,7 +627,8 @@ static void cik_static_deregister_process(struct kfd_scheduler *scheduler,
 	struct cik_static_private *priv = kfd_scheduler_to_private(scheduler);
 	struct cik_static_process *pp = kfd_process_to_private(scheduler_process);
 
-	if (priv && pp) {
+
+	if (priv && pp)	{
 		release_vmid(priv, pp->vmid);
 		kfree(pp);
 	}
drivers/gpu/hsa/radeon/kfd_topology.c +27 -0
index 21bb66e..213ae7b 100644
@@ -1201,3 +1201,30 @@ int kfd_topology_remove_device(struct kfd_dev *gpu)
 
 	return res;
 }
+
+/*
+ * When idx is out of bounds, the function will return NULL
+ */
+struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx)
+{
+
+	struct kfd_topology_device *top_dev;
+	struct kfd_dev *device = NULL;
+	uint8_t device_idx = 0;
+
+	down_read(&topology_lock);
+
+	list_for_each_entry(top_dev, &topology_device_list, list) {
+		if (device_idx == idx) {
+			device = top_dev->gpu;
+			break;
+		}
+
+		device_idx++;
+	}
+
+	up_read(&topology_lock);
+
+	return device;
+
+}
include/uapi/linux/kfd_ioctl.h +18 -0
index a7c3abd..e5fcb8b 100644
@@ -78,6 +78,23 @@ struct kfd_ioctl_get_clock_counters_args {
 	uint64_t system_clock_freq;	/* from KFD */
 };
 
+#define NUM_OF_SUPPORTED_GPUS 7
+
+struct kfd_process_device_apertures {
+	uint64_t lds_base;/* from KFD */
+	uint64_t lds_limit;/* from KFD */
+	uint64_t scratch_base;/* from KFD */
+	uint64_t scratch_limit;/* from KFD */
+	uint64_t gpuvm_base;/* from KFD */
+	uint64_t gpuvm_limit;/* from KFD */
+	uint32_t gpu_id;/* from KFD */
+};
+
+struct kfd_ioctl_get_process_apertures_args {
+	struct kfd_process_device_apertures process_apertures[NUM_OF_SUPPORTED_GPUS];/* from KFD */
+	uint8_t num_of_nodes; /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/
+};
+
 #define KFD_IOC_MAGIC 'K'
 
 #define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
@@ -85,6 +102,7 @@ struct kfd_ioctl_get_clock_counters_args {
 #define KFD_IOC_DESTROY_QUEUE	_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
 #define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
+#define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1
#19 lore raw

PATCH 45/83 hsa/radeon: debugging print statements

In reply to Oded Gabbay

From: Michael Varga <[email protected]>

Added debug print statements so critical errors during init may be debugged more easily.

---
 drivers/gpu/hsa/radeon/kfd_device.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_device.c +15 -3
index 2e7d50d..82febf4 100644
@@ -107,20 +107,30 @@ device_iommu_pasid_init(struct kfd_dev *kfd)
 	int err;
 
 	err = amd_iommu_device_info(kfd->pdev, &iommu_info);
-	if (err < 0)
+	if (err < 0) {
+		dev_err(kfd_device, "error getting iommu info. is the iommu enabled?\n");
 		return false;
+	}
 
-	if ((iommu_info.flags & required_iommu_flags) != required_iommu_flags)
+	if ((iommu_info.flags & required_iommu_flags) != required_iommu_flags) {
+		dev_err(kfd_device, "error required iommu flags ats(%i), pri(%i), pasid(%i)\n",
+		       (iommu_info.flags & AMD_IOMMU_DEVICE_FLAG_ATS_SUP) != 0,
+		       (iommu_info.flags & AMD_IOMMU_DEVICE_FLAG_PRI_SUP) != 0,
+		       (iommu_info.flags & AMD_IOMMU_DEVICE_FLAG_PASID_SUP) != 0);
 		return false;
+	}
 
 	pasid_limit = min_t(pasid_t, (pasid_t)1 << kfd->device_info->max_pasid_bits, iommu_info.max_pasids);
 	pasid_limit = min_t(pasid_t, pasid_limit, kfd->doorbell_process_limit);
 
 	err = amd_iommu_init_device(kfd->pdev, pasid_limit);
-	if (err < 0)
+	if (err < 0) {
+		dev_err(kfd_device, "error initializing iommu device\n");
 		return false;
+	}
 
 	if (!radeon_kfd_set_pasid_limit(pasid_limit)) {
+		dev_err(kfd_device, "error setting pasid limit\n");
 		amd_iommu_free_device(kfd->pdev);
 		return false;
 	}
@@ -166,6 +176,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 	kfd->device_info->scheduler_class->start(kfd->scheduler);
 
 	kfd->init_complete = true;
+	dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
+		 kfd->pdev->device);
 
 	return true;
 }
Signature · 1 line
1.9.1
#20 lore raw

PATCH 46/83 hsa/radeon: Add queue and hw_pointer_store modules

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The queue module enables allocating and initializing queues uniformly. The hw_pointer_store module handles allocation and assignment of read and write pointers to user HSA queues.

---
 drivers/gpu/hsa/radeon/Makefile               |   3 +-
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c | 150 ++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h |  65 +++++++++++
 drivers/gpu/hsa/radeon/kfd_priv.h             |  55 ++++++++++
 drivers/gpu/hsa/radeon/kfd_queue.c            | 110 +++++++++++++++++++
 5 files changed, 382 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c
 create mode 100644 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h
 create mode 100644 drivers/gpu/hsa/radeon/kfd_queue.c
drivers/gpu/hsa/radeon/Makefile +2 -1
index 813b31f..18e1639 100644
@@ -5,6 +5,7 @@
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
-		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o
+		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
+		kfd_queue.o kfd_hw_pointer_store.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c new file +150 -0

150 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h new file +65 -0

65 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +55 -0

77 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_queue.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
1.9.1
#21 lore raw

PATCH 47/83 hsa/radeon: Add support allocating kernel doorbells

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch adds infrastructure to allocate doorbells which are not exposed to user space.

---
 drivers/gpu/hsa/radeon/kfd_doorbell.c | 76 ++++++++++++++++++++++++++++++++++-
 drivers/gpu/hsa/radeon/kfd_priv.h     |  5 +++
 2 files changed, 80 insertions(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_doorbell.c +75 -1
index 3de8a02..abf4cb0 100644
@@ -23,6 +23,16 @@
 #include "kfd_priv.h"
 #include <linux/mm.h>
 #include <linux/mman.h>
+#include <linux/slab.h>
+
+/*
+ * This extension supports a kernel level doorbells management for the kernel queues
+ * basically the last doorbells page is devoted to kernel queues and that's assures
+ * that any user process won't get access to the kernel doorbells page
+ */
+static DEFINE_MUTEX(doorbell_mutex);
+static unsigned long doorbell_available_index[DIV_ROUND_UP(MAX_PROCESS_QUEUES, BITS_PER_LONG)] = { 0 };
+#define KERNEL_DOORBELL_PASID 1
 
 /*
  * Each device exposes a doorbell aperture, a PCI MMIO aperture that
@@ -67,7 +77,22 @@ void radeon_kfd_doorbell_init(struct kfd_dev *kfd)
 
 	kfd->doorbell_base = kfd->shared_resources.doorbell_physical_address + doorbell_start_offset;
 	kfd->doorbell_id_offset = doorbell_start_offset / sizeof(doorbell_t);
-	kfd->doorbell_process_limit = doorbell_process_limit;
+	kfd->doorbell_process_limit = doorbell_process_limit - 1;
+
+	kfd->doorbell_kernel_ptr = ioremap(kfd->doorbell_base, doorbell_process_allocation());
+	BUG_ON(!kfd->doorbell_kernel_ptr);
+
+	pr_debug("kfd: doorbell initialization\n"
+				 "     doorbell base           == 0x%08lX\n"
+				 "     doorbell_id_offset      == 0x%08lu\n"
+				 "     doorbell_process_limit  == 0x%08lu\n"
+				 "     doorbell_kernel_offset  == 0x%08lX\n"
+				 "     doorbell aperture size  == 0x%08lX\n"
+				 "     doorbell kernel address == 0x%08lX\n",
+				 (uintptr_t)kfd->doorbell_base, kfd->doorbell_id_offset, doorbell_process_limit,
+				 (uintptr_t)kfd->doorbell_base, kfd->shared_resources.doorbell_aperture_size,
+				 (uintptr_t)kfd->doorbell_kernel_ptr);
+
 }
 
 /* This is the /dev/kfd mmap (for doorbell) implementation. We intend that this is only called through map_doorbells,
@@ -136,6 +161,53 @@ map_doorbells(struct file *devkfd, struct kfd_process *process, struct kfd_dev *
 	return 0;
 }
 
+/* get kernel iomem pointer for a doorbell */
+u32 __iomem *radeon_kfd_get_kernel_doorbell(struct kfd_dev *kfd, unsigned int *doorbell_off)
+{
+	u32 inx;
+
+	BUG_ON(!kfd || !doorbell_off);
+
+	mutex_lock(&doorbell_mutex);
+	inx = find_first_zero_bit(doorbell_available_index, MAX_PROCESS_QUEUES);
+	__set_bit(inx, doorbell_available_index);
+	mutex_unlock(&doorbell_mutex);
+
+	if (inx >= MAX_PROCESS_QUEUES)
+		return NULL;
+
+	/* caluculating the kernel doorbell offset using "faked" kernel pasid that allocated for kernel queues only */
+	*doorbell_off = KERNEL_DOORBELL_PASID * (doorbell_process_allocation()/sizeof(doorbell_t)) + inx;
+
+	pr_debug("kfd: get kernel queue doorbell\n"
+			 "     doorbell offset   == 0x%08d\n"
+			 "     kernel address    == 0x%08lX\n",
+			 *doorbell_off, (uintptr_t)(kfd->doorbell_kernel_ptr + inx));
+
+	return kfd->doorbell_kernel_ptr + inx;
+}
+
+void radeon_kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr)
+{
+	unsigned int inx;
+
+	BUG_ON(!kfd || !db_addr);
+
+	inx = (unsigned int)(db_addr - kfd->doorbell_kernel_ptr);
+
+	mutex_lock(&doorbell_mutex);
+	__clear_bit(inx, doorbell_available_index);
+	mutex_unlock(&doorbell_mutex);
+}
+
+inline void write_kernel_doorbell(u32 __iomem *db, u32 value)
+{
+	if (db) {
+		writel(value, db);
+		pr_debug("writing %d to doorbell address 0x%p\n", value, db);
+	}
+}
+
 /* Get the user-mode address of a doorbell. Assumes that the process mutex is being held. */
 doorbell_t __user *radeon_kfd_get_doorbell(struct file *devkfd, struct kfd_process *process, struct kfd_dev *dev,
 					   unsigned int doorbell_index)
@@ -152,6 +224,8 @@ doorbell_t __user *radeon_kfd_get_doorbell(struct file *devkfd, struct kfd_proce
 	pdd = radeon_kfd_get_process_device_data(dev, process);
 	BUG_ON(pdd == NULL); /* map_doorbells would have failed otherwise */
 
+	pr_debug("doorbell value on creation 0x%x\n", pdd->doorbell_mapping[doorbell_index]);
+
 	return &pdd->doorbell_mapping[doorbell_index];
 }
 
drivers/gpu/hsa/radeon/kfd_priv.h +5 -0
index 14a3f9b..df17387 100644
@@ -95,6 +95,7 @@ struct kfd_dev {
 					 * at the start)
 					 */
 	size_t doorbell_process_limit;	/* Number of processes we have doorbell space for. */
+	u32 __iomem *doorbell_kernel_ptr; /* this is a pointer for a doorbells page used by kernel queue */
 
 	struct kgd2kfd_shared_resources shared_resources;
 
@@ -288,6 +289,10 @@ void radeon_kfd_doorbell_init(struct kfd_dev *kfd);
 int radeon_kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma);
 doorbell_t __user *radeon_kfd_get_doorbell(struct file *devkfd, struct kfd_process *process, struct kfd_dev *dev,
 					   unsigned int doorbell_index);
+u32 __iomem *radeon_kfd_get_kernel_doorbell(struct kfd_dev *kfd, unsigned int *doorbell_off);
+void radeon_kfd_release_kernel_doorbell(struct kfd_dev *kfd, u32 __iomem *db_addr);
+u32 read_kernel_doorbell(u32 __iomem *db);
+void write_kernel_doorbell(u32 __iomem *db, u32 value);
 unsigned int radeon_kfd_queue_id_to_doorbell(struct kfd_dev *kfd, struct kfd_process *process, unsigned int queue_id);
 
 extern struct device *kfd_device;
Signature · 1 line
1.9.1
#22 lore raw

PATCH 48/83 hsa/radeon: Add mqd_manager module

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The mqd_manager module handles MQD data structures. MQD stands for Memory Queue Descriptor, which is used by the H/W to keep the HSA queue state in memory.

---
 drivers/gpu/hsa/radeon/Makefile               |   2 +-
 drivers/gpu/hsa/radeon/cik_mqds.h             | 251 ++++++++++++++
 drivers/gpu/hsa/radeon/cik_regs.h             |   1 +
 drivers/gpu/hsa/radeon/kfd_mqd_manager.c      | 453 ++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_mqd_manager.h      |  48 +++
 drivers/gpu/hsa/radeon/kfd_priv.h             |  26 ++
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c |  10 -
 drivers/gpu/hsa/radeon/kfd_vidmem.c           |  36 ++
 8 files changed, 816 insertions(+), 11 deletions(-)
 create mode 100644 drivers/gpu/hsa/radeon/cik_mqds.h
 create mode 100644 drivers/gpu/hsa/radeon/kfd_mqd_manager.c
 create mode 100644 drivers/gpu/hsa/radeon/kfd_mqd_manager.h
drivers/gpu/hsa/radeon/Makefile +1 -1
index 18e1639..c87b518 100644
@@ -6,6 +6,6 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
-		kfd_queue.o kfd_hw_pointer_store.o
+		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/cik_mqds.h new file +251 -0

251 lines not on this page · raw message

drivers/gpu/hsa/radeon/cik_regs.h +1 -0
index 93f7b34..fa5ec01 100644
@@ -168,6 +168,7 @@
 
 #define CP_HQD_DEQUEUE_REQUEST				0xC974
 #define	DEQUEUE_REQUEST_DRAIN				1
+#define DEQUEUE_REQUEST_RESET				2
 #define		DEQUEUE_INT					(1U << 8)
 
 #define CP_HQD_SEMA_CMD					0xC97Cu
drivers/gpu/hsa/radeon/kfd_mqd_manager.c new file +453 -0

453 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_mqd_manager.h new file +48 -0

48 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +26 -0
index df17387..cc60b48 100644
@@ -141,6 +141,9 @@ int radeon_kfd_vidmem_gpumap(struct kfd_dev *kfd, kfd_mem_obj mem_obj, uint64_t
 void radeon_kfd_vidmem_ungpumap(struct kfd_dev *kfd, kfd_mem_obj mem_obj);
 int radeon_kfd_vidmem_kmap(struct kfd_dev *kfd, kfd_mem_obj mem_obj, void **ptr);
 void radeon_kfd_vidmem_unkmap(struct kfd_dev *kfd, kfd_mem_obj mem_obj);
+int radeon_kfd_vidmem_alloc_map(struct kfd_dev *kfd, kfd_mem_obj *mem_obj, void **ptr,
+				uint64_t *vmid0_address, size_t size);
+void radeon_kfd_vidmem_free_unmap(struct kfd_dev *kfd, kfd_mem_obj mem_obj);
 
 /* Character device interface */
 int radeon_kfd_chardev_init(void);
@@ -161,6 +164,17 @@ struct kfd_queue {
 	struct kfd_scheduler_queue scheduler_queue;
 };
 
+enum kfd_preempt_type_filter {
+	KFD_PREEMPT_TYPE_FILTER_SINGLE_QUEUE,
+	KFD_PRERMPT_TYPE_FILTER_ALL_QUEUES,
+	KFD_PRERMPT_TYPE_FILTER_BY_PASID
+};
+
+enum kfd_preempt_type {
+	KFD_PREEMPT_TYPE_WAVEFRONT,
+	KFD_PREEMPT_TYPE_WAVEFRONT_RESET
+};
+
 enum kfd_queue_type  {
 	KFD_QUEUE_TYPE_COMPUTE,
 	KFD_QUEUE_TYPE_SDMA,
@@ -204,6 +218,14 @@ struct queue {
 	struct kfd_dev		*device;
 };
 
+enum KFD_MQD_TYPE {
+	KFD_MQD_TYPE_CIK_COMPUTE = 0, /* for no cp scheduling */
+	KFD_MQD_TYPE_CIK_HIQ, /* for hiq */
+	KFD_MQD_TYPE_CIK_CP, /* for cp queues and diq */
+	KFD_MQD_TYPE_CIK_SDMA, /* for sdma queues */
+	KFD_MQD_TYPE_MAX
+};
+
 /* Data that is per-process-per device. */
 struct kfd_process_device {
 	/* List of all per-device data for a process. Starts from kfd_process.per_device_data. */
@@ -325,10 +347,14 @@ int kgd2kfd_resume(struct kfd_dev *dev);
 int kfd_init_apertures(struct kfd_process *process);
 
 /* Queue Context Management */
+inline uint32_t lower_32(uint64_t x);
+inline uint32_t upper_32(uint64_t x);
+inline void busy_wait(unsigned long ms);
 
 int init_queue(struct queue **q, struct queue_properties properties);
 void uninit_queue(struct queue *q);
 void print_queue_properties(struct queue_properties *q);
 void print_queue(struct queue *q);
 
+struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, struct kfd_dev *dev);
 #endif
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +0 -10
index 30561a6..d576d95 100644
@@ -182,16 +182,6 @@ struct cik_static_queue {
 	uint32_t queue_size_encoded; /* CP_HQD_PQ_CONTROL.QUEUE_SIZE takes the queue size as log2(size) - 3. */
 };
 
-static uint32_t lower_32(uint64_t x)
-{
-	return (uint32_t)x;
-}
-
-static uint32_t upper_32(uint64_t x)
-{
-	return (uint32_t)(x >> 32);
-}
-
 /* SRBM_GFX_CNTL provides the MEC/pipe/queue and vmid for many registers that are
  * In particular, CP_HQD_* and CP_MQD_* are instanced for each queue. CP_HPD_* are instanced for each pipe.
  * SH_MEM_* are instanced per-VMID.
drivers/gpu/hsa/radeon/kfd_vidmem.c +36 -0
index c8d3770..9713373 100644
@@ -59,3 +59,39 @@ void radeon_kfd_vidmem_unkmap(struct kfd_dev *kfd, kfd_mem_obj mem_obj)
 {
 	kfd2kgd->unkmap_mem(kfd->kgd, (struct kgd_mem *)mem_obj);
 }
+
+int radeon_kfd_vidmem_alloc_map(struct kfd_dev *kfd, kfd_mem_obj *mem_obj,
+				void **ptr, uint64_t *vmid0_address,
+				size_t size)
+{
+	int retval;
+
+	retval = radeon_kfd_vidmem_alloc(kfd, size, PAGE_SIZE, KFD_MEMPOOL_SYSTEM_WRITECOMBINE,
+			mem_obj);
+	if (retval != 0)
+		goto fail_vidmem_alloc;
+
+	retval = radeon_kfd_vidmem_kmap(kfd, *mem_obj, ptr);
+	if (retval != 0)
+		goto fail_vidmem_kmap;
+
+	retval = radeon_kfd_vidmem_gpumap(kfd, *mem_obj, vmid0_address);
+	if (retval != 0)
+		goto fail_vidmem_gpumap;
+
+	return 0;
+
+fail_vidmem_gpumap:
+	radeon_kfd_vidmem_unkmap(kfd, *mem_obj);
+fail_vidmem_kmap:
+	radeon_kfd_vidmem_free(kfd, *mem_obj);
+fail_vidmem_alloc:
+	return retval;
+}
+
+void radeon_kfd_vidmem_free_unmap(struct kfd_dev *kfd, kfd_mem_obj mem_obj)
+{
+	radeon_kfd_vidmem_ungpumap(kfd, mem_obj);
+	radeon_kfd_vidmem_unkmap(kfd, mem_obj);
+	radeon_kfd_vidmem_free(kfd, mem_obj);
+}
Signature · 1 line
1.9.1
#23 lore raw

PATCH 49/83 hsa/radeon: Add kernel queue support for KFD

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The kernel queue module enables the KFD to establish kernel queues, not exposed to user space. The kernel queues are used for HIQ (HSA Interface Queue) and DIQ (Debug Interface Queue) operations.

---
 drivers/gpu/hsa/radeon/Makefile                   |   3 +-
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.h | 102 ++++
 drivers/gpu/hsa/radeon/kfd_kernel_queue.c         | 302 ++++++++++
 drivers/gpu/hsa/radeon/kfd_kernel_queue.h         |  67 +++
 drivers/gpu/hsa/radeon/kfd_pm4_headers.h          | 681 ++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_pm4_opcodes.h          | 107 ++++
 drivers/gpu/hsa/radeon/kfd_priv.h                 |  34 ++
 drivers/gpu/hsa/radeon/kfd_scheduler.h            |   5 -
 8 files changed, 1295 insertions(+), 6 deletions(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_device_queue_manager.h
 create mode 100644 drivers/gpu/hsa/radeon/kfd_kernel_queue.c
 create mode 100644 drivers/gpu/hsa/radeon/kfd_kernel_queue.h
 create mode 100644 drivers/gpu/hsa/radeon/kfd_pm4_headers.h
 create mode 100644 drivers/gpu/hsa/radeon/kfd_pm4_opcodes.h
drivers/gpu/hsa/radeon/Makefile +2 -1
index c87b518..f06d925 100644
@@ -6,6 +6,7 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
-		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o
+		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o \
+		kfd_kernel_queue.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_device_queue_manager.h new file +102 -0

102 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_kernel_queue.c new file +302 -0

302 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_kernel_queue.h new file +67 -0

67 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_pm4_headers.h new file +681 -0

681 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_pm4_opcodes.h new file +107 -0

107 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +34 -0
index cc60b48..3a5cecf 100644
@@ -55,6 +55,15 @@ struct kfd_scheduler_class;
 #define KFD_MMAP_WPTR_START	KFD_MMAP_RPTR_END
 #define KFD_MMAP_WPTR_END	(((1ULL << 32)*4) >> PAGE_SHIFT)
 
+/*
+ * When working with cp scheduler we should assign the HIQ manually or via the radeon driver
+ * to a fixed hqd slot, here are the fixed HIQ hqd slot definitions for Kaveri.
+ * In Kaveri only the first ME queues participates in the cp scheduling taking that in mind
+ * we set the HIQ slot in the second ME.
+ */
+#define KFD_CIK_HIQ_PIPE 4
+#define KFD_CIK_HIQ_QUEUE 0
+
 /* GPU ID hash width in bits */
 #define KFD_GPU_ID_HASH_WIDTH 16
 
@@ -68,6 +77,11 @@ typedef unsigned int pasid_t;
 /* Type that represents a HW doorbell slot. */
 typedef u32 doorbell_t;
 
+enum cache_policy {
+	cache_policy_coherent,
+	cache_policy_noncoherent
+};
+
 struct kfd_device_info {
 	const struct kfd_scheduler_class *scheduler_class;
 	unsigned int max_pasid_bits;
@@ -109,6 +123,9 @@ struct kfd_dev {
 	atomic_t interrupt_ring_wptr;
 	struct work_struct interrupt_work;
 	spinlock_t interrupt_lock;
+
+	/* QCM Device instance */
+	struct device_queue_manager *dqm;
 };
 
 /* KGD2KFD callbacks */
@@ -357,4 +374,21 @@ void print_queue_properties(struct queue_properties *q);
 void print_queue(struct queue *q);
 
 struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, struct kfd_dev *dev);
+
+/* Packet Manager */
+
+#define KFD_HIQ_TIMEOUT (500)
+
+#define KFD_FENCE_COMPLETED (100)
+#define KFD_FENCE_INIT   (10)
+#define KFD_UNMAP_LATENCY (15)
+
+struct packet_manager {
+	struct device_queue_manager *dqm;
+	struct kernel_queue *priv_queue;
+	struct mutex lock;
+	bool allocated;
+	kfd_mem_obj ib_buffer_obj;
+};
+
 #endif
drivers/gpu/hsa/radeon/kfd_scheduler.h +0 -5
index 9dc2994..d2e74b0 100644
@@ -31,11 +31,6 @@ struct kfd_scheduler;
 struct kfd_scheduler_process;
 struct kfd_scheduler_queue;
 
-enum cache_policy {
-	cache_policy_coherent,
-	cache_policy_noncoherent
-};
-
 struct kfd_scheduler_class {
 	const char *name;
 
Signature · 1 line
1.9.1
#24 lore raw

PATCH 50/83 hsa/radeon: Add module parameter of scheduling policy

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch adds a new parameter to the KFD module. This parameter enables the user to select the scheduling policy of the CP. The choices are:

* CP Scheduling with support for over-subscription
* CP Scheduling without support for over-subscription
* Without CP Scheduling

---
 drivers/gpu/hsa/radeon/kfd_module.c |  5 +++
 drivers/gpu/hsa/radeon/kfd_priv.h   | 65 +++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+)
drivers/gpu/hsa/radeon/kfd_module.c +5 -0
index a03743a..e8bb67c 100644
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
+#include <linux/moduleparam.h>
 
 #include "kfd_priv.h"
 
@@ -43,6 +44,10 @@ static const struct kgd2kfd_calls kgd2kfd = {
 	.resume		= kgd2kfd_resume,
 };
 
+int sched_policy = KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION;
+module_param(sched_policy, int, S_IRUSR | S_IWUSR);
+MODULE_PARM_DESC(sched_policy, "Kernel comline parameter define the kfd scheduling policy");
+
 bool kgd2kfd_init(unsigned interface_version,
 		  const struct kfd2kgd_calls *f2g,
 		  const struct kgd2kfd_calls **g2f)
drivers/gpu/hsa/radeon/kfd_priv.h +65 -0

87 lines not on this page · raw message

Signature · 1 line
1.9.1
#25 lore raw

PATCH 51/83 hsa/radeon: Add packet manager module

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The packet manager module builds PM4 packets for the sole use of the CP scheduler. Those packets are used by the HIQ to submit runlists to the CP.

---
 drivers/gpu/hsa/radeon/Makefile             |   2 +-
 drivers/gpu/hsa/radeon/kfd_packet_manager.c | 473 ++++++++++++++++++++++++++++
 2 files changed, 474 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_packet_manager.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index f06d925..4978915 100644
@@ -7,6 +7,6 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
 		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o \
-		kfd_kernel_queue.o
+		kfd_kernel_queue.o kfd_packet_manager.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_packet_manager.c new file +473 -0

473 lines not on this page · raw message

Signature · 1 line
1.9.1
#26 lore raw

PATCH 52/83 hsa/radeon: Add process queue manager module

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The queue scheduler divides into two sections, one section is process bounded
and the other section is device bounded.
The process bounded section is handled by this module. The PQM handles HSA queue setup, updates and tear-down.

---
 drivers/gpu/hsa/radeon/Makefile                    |   3 +-
 drivers/gpu/hsa/radeon/kfd_priv.h                  |  29 ++
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c | 370 +++++++++++++++++++++
 3 files changed, 401 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c
drivers/gpu/hsa/radeon/Makefile +2 -1
index 4978915..341fa67 100644
@@ -7,6 +7,7 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
 		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o \
-		kfd_kernel_queue.o kfd_packet_manager.o
+		kfd_kernel_queue.o kfd_packet_manager.o \
+		kfd_process_queue_manager.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_priv.h +29 -0
index b3889aa..e716745 100644
@@ -311,6 +311,9 @@ struct kfd_process_device {
 	/* Scheduler process data for this device. */
 	struct kfd_scheduler_process *scheduler_process;
 
+	/* per-process-per device QCM data structure */
+	struct qcm_process_device qpd;
+
 	/* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */
 	bool bound;
 
@@ -342,6 +345,11 @@ struct kfd_process {
 	/* List of kfd_process_device structures, one for each device the process is using. */
 	struct list_head per_device_data;
 
+	struct hw_pointer_store_properties write_ptr;
+	struct hw_pointer_store_properties read_ptr;
+
+	struct process_queue_manager pqm;
+
 	/* The process's queues. */
 	size_t queue_array_size;
 	struct kfd_queue **queues;	/* Size is queue_array_size, up to MAX_PROCESS_QUEUES. */
@@ -431,6 +439,27 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, struct kfd_dev *dev
 struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, enum kfd_queue_type type);
 void kernel_queue_uninit(struct kernel_queue *kq);
 
+/* Process Queue Manager */
+struct process_queue_node {
+	struct queue *q;
+	struct kernel_queue *kq;
+	struct list_head process_queue_list;
+};
+
+int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p);
+void pqm_uninit(struct process_queue_manager *pqm);
+int pqm_create_queue(struct process_queue_manager *pqm,
+			    struct kfd_dev *dev,
+			    struct file *f,
+			    struct queue_properties *properties,
+			    unsigned int flags,
+			    enum kfd_queue_type type,
+			    unsigned int *qid);
+int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid);
+int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, struct queue_properties *p);
+struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm, unsigned int qid);
+void test_diq(struct kfd_dev *dev, struct process_queue_manager *pqm);
+
 /* Packet Manager */
 
 #define KFD_HIQ_TIMEOUT (500)
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c new file +370 -0

370 lines not on this page · raw message

Signature · 1 line
1.9.1
#27 lore raw

PATCH 53/83 hsa/radeon: Add device queue manager module

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

The queue scheduler divides into two sections, one section is process bounded and the other section is device bounded.
The device bounded section is handled by this module.
The DQM module handles queue setup, update and tear-down from the device side. It also supports suspend/resume operation.

---
 drivers/gpu/hsa/radeon/Makefile                   |    2 +-
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 1006 +++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_priv.h                 |    2 +
 3 files changed, 1009 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index 341fa67..3409203 100644
@@ -8,6 +8,6 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
 		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o \
 		kfd_kernel_queue.o kfd_packet_manager.o \
-		kfd_process_queue_manager.o
+		kfd_process_queue_manager.o kfd_device_queue_manager.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c new file +1006 -0

1,006 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +2 -0
index e716745..0af4c71 100644
@@ -436,6 +436,8 @@ void print_queue_properties(struct queue_properties *q);
 void print_queue(struct queue *q);
 
 struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, struct kfd_dev *dev);
+struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev);
+void device_queue_manager_uninit(struct device_queue_manager *dqm);
 struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, enum kfd_queue_type type);
 void kernel_queue_uninit(struct kernel_queue *kq);
 
Signature · 1 line
1.9.1
#28 lore raw

PATCH 54/83 hsa/radeon: Switch to new queue scheduler

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch makes the switch between the old KFD queue scheduler to the new KFD queue scheduler. The new scheduler supports H/W CP scheduling, over-subscription of queues and pre-emption of queues.

---
 drivers/gpu/hsa/radeon/kfd_aperture.c  |   1 -
 drivers/gpu/hsa/radeon/kfd_chardev.c   | 107 +++++++++++++++------------------
 drivers/gpu/hsa/radeon/kfd_device.c    |  31 ++++++----
 drivers/gpu/hsa/radeon/kfd_interrupt.c |   4 +-
 drivers/gpu/hsa/radeon/kfd_priv.h      |   2 +
 drivers/gpu/hsa/radeon/kfd_process.c   |  56 ++++-------------
 include/uapi/linux/kfd_ioctl.h         |   4 +-
 7 files changed, 88 insertions(+), 117 deletions(-)
drivers/gpu/hsa/radeon/kfd_aperture.c +0 -1
index 9e2d6da..2c72b21 100644
@@ -32,7 +32,6 @@
 #include <uapi/linux/kfd_ioctl.h>
 #include <linux/time.h>
 #include "kfd_priv.h"
-#include "kfd_scheduler.h"
 #include <linux/mm.h>
 #include <uapi/asm-generic/mman-common.h>
 #include <asm/processor.h>
drivers/gpu/hsa/radeon/kfd_chardev.c +50 -57

178 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_device.c +20 -11
index 82febf4..c602e16 100644
@@ -25,10 +25,9 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include "kfd_priv.h"
-#include "kfd_scheduler.h"
+#include "kfd_device_queue_manager.h"
 
 static const struct kfd_device_info kaveri_device_info = {
-	.scheduler_class = &radeon_kfd_cik_static_scheduler_class,
 	.max_pasid_bits = 16,
 	.ih_ring_entry_size = 4 * sizeof(uint32_t)
 };
@@ -121,7 +120,11 @@ device_iommu_pasid_init(struct kfd_dev *kfd)
 	}
 
 	pasid_limit = min_t(pasid_t, (pasid_t)1 << kfd->device_info->max_pasid_bits, iommu_info.max_pasids);
-	pasid_limit = min_t(pasid_t, pasid_limit, kfd->doorbell_process_limit);
+	/*
+	 * last pasid is used for kernel queues doorbells
+	 * in the future the last pasid might be used for a kernel thread.
+	 */
+	pasid_limit = min_t(pasid_t, pasid_limit, kfd->doorbell_process_limit - 1);
 
 	err = amd_iommu_init_device(kfd->pdev, pasid_limit);
 	if (err < 0) {
@@ -168,17 +171,26 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 
 	amd_iommu_set_invalidate_ctx_cb(kfd->pdev, iommu_pasid_shutdown_callback);
 
-	if (kfd->device_info->scheduler_class->create(kfd, &kfd->scheduler)) {
+	kfd->dqm = device_queue_manager_init(kfd);
+	if (!kfd->dqm) {
+		kfd_topology_remove_device(kfd);
 		amd_iommu_free_device(kfd->pdev);
 		return false;
 	}
 
-	kfd->device_info->scheduler_class->start(kfd->scheduler);
+	if (kfd->dqm->start(kfd->dqm) != 0) {
+		device_queue_manager_uninit(kfd->dqm);
+		kfd_topology_remove_device(kfd);
+		amd_iommu_free_device(kfd->pdev);
+		return false;
+	}
 
 	kfd->init_complete = true;
 	dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
 		 kfd->pdev->device);
 
+	pr_debug("kfd: Starting kfd with the following scheduling policy %d\n", sched_policy);
+
 	return true;
 }
 
@@ -188,13 +200,10 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd)
 
 	BUG_ON(err != 0);
 
-	if (kfd->init_complete)
-		kfd->device_info->scheduler_class->stop(kfd->scheduler);
-
 	radeon_kfd_interrupt_exit(kfd);
 
 	if (kfd->init_complete) {
-		kfd->device_info->scheduler_class->destroy(kfd->scheduler);
+		device_queue_manager_uninit(kfd->dqm);
 		amd_iommu_free_device(kfd->pdev);
 	}
 
@@ -206,7 +215,7 @@ void kgd2kfd_suspend(struct kfd_dev *kfd)
 	BUG_ON(kfd == NULL);
 
 	if (kfd->init_complete) {
-		kfd->device_info->scheduler_class->stop(kfd->scheduler);
+		kfd->dqm->stop(kfd->dqm);
 		amd_iommu_free_device(kfd->pdev);
 	}
 }
@@ -225,7 +234,7 @@ int kgd2kfd_resume(struct kfd_dev *kfd)
 		if (err < 0)
 			return -ENXIO;
 		amd_iommu_set_invalidate_ctx_cb(kfd->pdev, iommu_pasid_shutdown_callback);
-		kfd->device_info->scheduler_class->start(kfd->scheduler);
+		kfd->dqm->start(kfd->dqm);
 	}
 
 	return 0;
drivers/gpu/hsa/radeon/kfd_interrupt.c +1 -3
index 2179780..1c9ad46 100644
@@ -43,7 +43,6 @@
 #include <linux/slab.h>
 #include <linux/device.h>
 #include "kfd_priv.h"
-#include "kfd_scheduler.h"
 
 #define KFD_INTERRUPT_RING_SIZE 256
 
@@ -162,7 +161,7 @@ static void interrupt_wq(struct work_struct *work)
 	uint32_t ih_ring_entry[DIV_ROUND_UP(dev->device_info->ih_ring_entry_size, sizeof(uint32_t))];
 
 	while (dequeue_ih_ring_entry(dev, ih_ring_entry))
-		dev->device_info->scheduler_class->interrupt_wq(dev->scheduler, ih_ring_entry);
+		;
 }
 
 /* This is called directly from KGD at ISR. */
@@ -171,7 +170,6 @@ void kgd2kfd_interrupt(struct kfd_dev *kfd, const void *ih_ring_entry)
 	spin_lock(&kfd->interrupt_lock);
 
 	if (kfd->interrupts_active
-	    && kfd->device_info->scheduler_class->interrupt_isr(kfd->scheduler, ih_ring_entry)
 	    && enqueue_ih_ring_entry(kfd, ih_ring_entry))
 		schedule_work(&kfd->interrupt_work);
 
drivers/gpu/hsa/radeon/kfd_priv.h +2 -0
index 0af4c71..049671b 100644
@@ -441,6 +441,8 @@ void device_queue_manager_uninit(struct device_queue_manager *dqm);
 struct kernel_queue *kernel_queue_init(struct kfd_dev *dev, enum kfd_queue_type type);
 void kernel_queue_uninit(struct kernel_queue *kq);
 
+int get_vmid_from_pasid(struct kfd_dev *dev, pasid_t pasid , unsigned int *vmid);
+
 /* Process Queue Manager */
 struct process_queue_node {
 	struct queue *q;
drivers/gpu/hsa/radeon/kfd_process.c +13 -43

103 lines not on this page · raw message

include/uapi/linux/kfd_ioctl.h +2 -2
index e5fcb8b..5134880 100644
@@ -47,9 +47,9 @@ struct kfd_ioctl_create_queue_args {
 	uint32_t queue_type;		/* to KFD */
 	uint32_t queue_percentage;	/* to KFD */
 	uint32_t queue_priority;	/* to KFD */
-	uint64_t write_pointer_address;	/* to KFD */
-	uint64_t read_pointer_address;	/* to KFD */
 
+	uint64_t write_pointer_address;	/* from KFD */
+	uint64_t read_pointer_address;	/* from KFD */
 	uint64_t doorbell_address;	/* from KFD */
 	uint32_t queue_id;		/* from KFD */
 };
Signature · 1 line
1.9.1
#29 lore raw

PATCH 55/83 hsa/radeon: Add IOCTL for update queue

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch adds a new IOCTL that enables the user to perform update to an HSA queue.

---
 drivers/gpu/hsa/radeon/cik_mqds.h                  |  1 -
 drivers/gpu/hsa/radeon/kfd_chardev.c               | 29 ++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c  |  1 -
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.h  |  1 -
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c      |  1 -
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h      |  1 -
 drivers/gpu/hsa/radeon/kfd_kernel_queue.c          |  1 -
 drivers/gpu/hsa/radeon/kfd_kernel_queue.h          |  1 -
 drivers/gpu/hsa/radeon/kfd_mqd_manager.c           |  1 -
 drivers/gpu/hsa/radeon/kfd_mqd_manager.h           |  1 -
 drivers/gpu/hsa/radeon/kfd_packet_manager.c        | 23 ++++++++++++++---
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c |  1 -
 drivers/gpu/hsa/radeon/kfd_queue.c                 |  1 -
 include/uapi/linux/kfd_ioctl.h                     |  9 +++++++
 14 files changed, 58 insertions(+), 14 deletions(-)
drivers/gpu/hsa/radeon/cik_mqds.h +0 -1
index 58945c8..35a35b4 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #ifndef CIK_MQDS_H_
drivers/gpu/hsa/radeon/kfd_chardev.c +29 -0
index bb2ef02..9a77332 100644
@@ -230,6 +230,31 @@ kfd_ioctl_destroy_queue(struct file *filp, struct kfd_process *p, void __user *a
 	return retval;
 }
 
+static int
+kfd_ioctl_update_queue(struct file *filp, struct kfd_process *p, void __user *arg)
+{
+	int retval;
+	struct kfd_ioctl_update_queue_args args;
+	struct queue_properties properties;
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+
+	properties.queue_address = args.ring_base_address;
+	properties.queue_size = args.ring_size;
+	properties.queue_percent = args.queue_percentage;
+	properties.priority = args.queue_priority;
+
+	pr_debug("kfd: updating queue id %d for PASID %d\n", args.queue_id, p->pasid);
+
+	mutex_lock(&p->mutex);
+
+	retval = pqm_update_queue(&p->pqm, args.queue_id, &properties);
+
+	mutex_unlock(&p->mutex);
+
+	return retval;
+}
 
 static long
 kfd_ioctl_set_memory_policy(struct file *filep, struct kfd_process *p, void __user *arg)
@@ -398,6 +423,10 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		err = kfd_ioctl_get_process_apertures(filep, process, (void __user *)arg);
 		break;
 
+	case KFD_IOC_UPDATE_QUEUE:
+		err = kfd_ioctl_update_queue(filep, process, (void __user *)arg);
+		break;
+
 	default:
 		dev_err(kfd_device,
 			"unknown ioctl cmd 0x%x, arg 0x%lx)\n",
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +0 -1
index 9e21074..c2d91c9 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/slab.h>
drivers/gpu/hsa/radeon/kfd_device_queue_manager.h +0 -1
index 0529a96..fe9ef10 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #ifndef DEVICE_QUEUE_MANAGER_H_
drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c +0 -1
index 1372fb2..4e71f7d 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/types.h>
drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h +0 -1
index be1d6cb..f384b7f 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #ifndef HW_POINTER_STORE_H_
drivers/gpu/hsa/radeon/kfd_kernel_queue.c +0 -1
index 61f420f..aa64693e 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/types.h>
drivers/gpu/hsa/radeon/kfd_kernel_queue.h +0 -1
index 339376c..963e861 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #ifndef KERNEL_QUEUE_H_
drivers/gpu/hsa/radeon/kfd_mqd_manager.c +0 -1
index 14b248f..a3e9f7c 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/printk.h>
drivers/gpu/hsa/radeon/kfd_mqd_manager.h +0 -1
index e7b39ee..8e7a5fd 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #ifndef MQD_MANAGER_H_
drivers/gpu/hsa/radeon/kfd_packet_manager.c +20 -3
index 4967b7c..3fc8c34 100644
@@ -1,9 +1,26 @@
 /*
- * packet_manager.c
+ * Copyright 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  *
- *  Created on: Mar 16, 2014
- *      Author: ben
  */
+
 #include <linux/slab.h>
 #include <linux/mutex.h>
 #include "kfd_device_queue_manager.h"
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c +0 -1
index 6e38ca4..fe74dd7 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/slab.h>
drivers/gpu/hsa/radeon/kfd_queue.c +0 -1
index 78fe180..2d22cc1 100644
@@ -19,7 +19,6 @@
  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  * OTHER DEALINGS IN THE SOFTWARE.
  *
- * Author: Ben Goz
  */
 
 #include <linux/slab.h>
include/uapi/linux/kfd_ioctl.h +9 -0
index 5134880..d58231d 100644
@@ -58,6 +58,14 @@ struct kfd_ioctl_destroy_queue_args {
 	uint32_t queue_id;		/* to KFD */
 };
 
+struct kfd_ioctl_update_queue_args {
+	uint32_t queue_id;		/* to KFD */
+	uint64_t ring_base_address;	/* to KFD */
+	uint32_t ring_size;		/* to KFD */
+	uint32_t queue_percentage;	/* to KFD */
+	uint32_t queue_priority;	/* to KFD */
+};
+
 /* For kfd_ioctl_set_memory_policy_args.default_policy and alternate_policy */
 #define KFD_IOC_CACHE_POLICY_COHERENT 0
 #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
@@ -103,6 +111,7 @@ struct kfd_ioctl_get_process_apertures_args {
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
 #define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
 #define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
+#define KFD_IOC_UPDATE_QUEUE	_IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1
#30 lore raw

PATCH 56/83 hsa/radeon: Queue Management integration with Memory Management

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch adding support for LDS aperture for user processes.

---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 41 +++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +39 -2
index c2d91c9..01573b1 100644
@@ -58,16 +58,50 @@ static inline unsigned int get_pipes_num_cpsch(void)
 	return PIPE_PER_ME_CP_SCHEDULING - 1;
 }
 
+static unsigned int get_sh_mem_bases_nybble_64(struct kfd_process *process, struct kfd_dev *dev)
+{
+	struct kfd_process_device *pdd;
+	uint32_t nybble;
+
+	pdd = radeon_kfd_get_process_device_data(dev, process);
+	nybble = (pdd->lds_base >> 60) & 0x0E;
+
+	return nybble;
+
+}
+
+static unsigned int get_sh_mem_bases_32(struct kfd_process *process, struct kfd_dev *dev)
+{
+	struct kfd_process_device *pdd;
+	unsigned int shared_base;
+
+	pdd = radeon_kfd_get_process_device_data(dev, process);
+	shared_base = (pdd->lds_base >> 16) & 0xFF;
+
+	return shared_base;
+}
+
 static uint32_t compute_sh_mem_bases_64bit(unsigned int top_address_nybble);
 static void init_process_memory(struct device_queue_manager *dqm, struct qcm_process_device *qpd)
 {
+	unsigned int temp;
 	BUG_ON(!dqm || !qpd);
 
+	if (qpd->pqm->process->is_32bit_user_mode) {
+		temp = get_sh_mem_bases_32(qpd->pqm->process, dqm->dev);
+		qpd->sh_mem_bases = SHARED_BASE(temp);
+	} else {
+		temp = get_sh_mem_bases_nybble_64(qpd->pqm->process, dqm->dev);
+		qpd->sh_mem_bases = compute_sh_mem_bases_64bit(temp);
+	}
+
 	qpd->sh_mem_config = ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
 	qpd->sh_mem_config |= DEFAULT_MTYPE(MTYPE_NONCACHED);
-	qpd->sh_mem_bases = compute_sh_mem_bases_64bit(6);
 	qpd->sh_mem_ape1_limit = 0;
 	qpd->sh_mem_ape1_base = 1;
+
+	pr_debug("kfd: is32bit process: %d sh_mem_bases nybble: 0x%X and register 0x%X\n",
+		qpd->pqm->process->is_32bit_user_mode, temp, qpd->sh_mem_bases);
 }
 
 static void program_sh_mem_settings(struct device_queue_manager *dqm, struct qcm_process_device *qpd)
@@ -84,6 +118,7 @@ static void program_sh_mem_settings(struct device_queue_manager *dqm, struct qcm
 
 	WRITE_REG(dqm->dev, SH_MEM_APE1_BASE, qpd->sh_mem_ape1_base);
 	WRITE_REG(dqm->dev, SH_MEM_APE1_LIMIT, qpd->sh_mem_ape1_limit);
+	WRITE_REG(dqm->dev, SH_MEM_BASES, qpd->sh_mem_bases);
 
 	mqd->release_hqd(mqd);
 }
@@ -128,6 +163,8 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm, struct queue *
 		set_pasid_vmid_mapping(dqm, q->process->pasid, q->properties.vmid);
 		qpd->vmid = *allocate_vmid;
 		is_new_vmid = true;
+
+		program_sh_mem_settings(dqm, qpd);
 	}
 	q->properties.vmid = qpd->vmid;
 
@@ -418,7 +455,7 @@ static uint32_t compute_sh_mem_bases_64bit(unsigned int top_address_nybble)
 	 * We don't bother to support different top nybbles for LDS/Scratch and GPUVM.
 	 */
 
-	BUG_ON((top_address_nybble & 1) || top_address_nybble > 0xE);
+	BUG_ON((top_address_nybble & 1) || top_address_nybble > 0xE || top_address_nybble == 0);
 
 	return PRIVATE_BASE(top_address_nybble << 12) | SHARED_BASE(top_address_nybble << 12);
 }
Signature · 1 line
1.9.1
#31 lore raw

PATCH 57/83 hsa/radeon: Eliminate warnings in compilation

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_chardev.c      | 6 +++---
 drivers/gpu/hsa/radeon/kfd_kernel_queue.c | 4 ++--
 drivers/gpu/hsa/radeon/kfd_queue.c        | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +3 -3
index 9a77332..80b702e 100644
@@ -114,8 +114,8 @@ kfd_open(struct inode *inode, struct file *filep)
 
 	process->is_32bit_user_mode = is_compat_task();
 
-	dev_info(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
-			process->pasid, process->is_32bit_user_mode);
+	dev_dbg(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
+		process->pasid, process->is_32bit_user_mode);
 
 	kfd_init_apertures(process);
 
@@ -149,7 +149,7 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a
 	pr_debug("%s Arguments: Queue Percentage (%d, %d)\n"
 			"Queue Priority (%d, %d)\n"
 			"Queue Address (0x%llX, 0x%llX)\n"
-			"Queue Size (%u64, %ll)\n",
+			"Queue Size (%llX, %u)\n",
 			__func__,
 			q_properties.queue_percent, args.queue_percentage,
 			q_properties.priority, args.queue_priority,
drivers/gpu/hsa/radeon/kfd_kernel_queue.c +2 -2
index aa64693e..25528b3 100644
@@ -89,8 +89,8 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev,
 	prop.type = type;
 	prop.vmid = 0;
 	prop.queue_address = kq->pq_gpu_addr;
-	prop.read_ptr = kq->rptr_gpu_addr;
-	prop.write_ptr = kq->wptr_gpu_addr;
+	prop.read_ptr = (qptr_t *) kq->rptr_gpu_addr;
+	prop.write_ptr = (qptr_t *) kq->wptr_gpu_addr;
 
 	if (init_queue(&kq->queue, prop) != 0)
 		goto err_init_queue;
drivers/gpu/hsa/radeon/kfd_queue.c +1 -1
index 2d22cc1..646b6d1 100644
@@ -67,7 +67,7 @@ void print_queue(struct queue *q)
 			"Queue Doorbell Pointer: 0x%p\n"
 			"Queue Doorbell Offset: %u\n"
 			"Queue MQD Address: 0x%p\n"
-			"Queue MQD Gart: 0x%p\n"
+			"Queue MQD Gart: 0x%llX\n"
 			"Queue Process Address: 0x%p\n"
 			"Queue Device Address: 0x%p\n",
 					q->properties.type,
Signature · 1 line
1.9.1
#32 lore raw

PATCH 58/83 hsa/radeon: Various kernel styling fixes

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.h |  6 +++---
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h     |  6 +++---
 drivers/gpu/hsa/radeon/kfd_kernel_queue.h         |  6 +++---
 drivers/gpu/hsa/radeon/kfd_module.c               |  8 ++++----
 drivers/gpu/hsa/radeon/kfd_mqd_manager.h          |  6 +++---
 drivers/gpu/hsa/radeon/kfd_pm4_headers.h          | 11 ++++++-----
 drivers/gpu/hsa/radeon/kfd_pm4_opcodes.h          |  6 +++---
 7 files changed, 25 insertions(+), 24 deletions(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.h +3 -3
index fe9ef10..57dc636 100644
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef DEVICE_QUEUE_MANAGER_H_
-#define DEVICE_QUEUE_MANAGER_H_
+#ifndef KFD_DEVICE_QUEUE_MANAGER_H_
+#define KFD_DEVICE_QUEUE_MANAGER_H_
 
 #include <linux/rwsem.h>
 #include <linux/list.h>
@@ -98,4 +98,4 @@ struct device_queue_manager {
 
 
 
-#endif /* DEVICE_QUEUE_MANAGER_H_ */
+#endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */
drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h +3 -3
index f384b7f..642703f 100644
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef HW_POINTER_STORE_H_
-#define HW_POINTER_STORE_H_
+#ifndef KFD_HW_POINTER_STORE_H_
+#define KFD_HW_POINTER_STORE_H_
 
 #include <linux/mutex.h>
 
@@ -61,4 +61,4 @@ radeon_kfd_hw_pointer_store_mmap(struct hw_pointer_store_properties *ptr,
 		struct vm_area_struct *vma);
 
 
-#endif /* HW_POINTER_STORE_H_ */
+#endif /* KFD_HW_POINTER_STORE_H_ */
drivers/gpu/hsa/radeon/kfd_kernel_queue.h +3 -3
index 963e861..abfb9c8 100644
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef KERNEL_QUEUE_H_
-#define KERNEL_QUEUE_H_
+#ifndef KFD_KERNEL_QUEUE_H_
+#define KFD_KERNEL_QUEUE_H_
 
 #include <linux/list.h>
 #include <linux/types.h>
@@ -63,4 +63,4 @@ struct kernel_queue {
 	struct list_head	list;
 };
 
-#endif /* KERNEL_QUEUE_H_ */
+#endif /* KFD_KERNEL_QUEUE_H_ */
drivers/gpu/hsa/radeon/kfd_module.c +4 -4
index e8bb67c..85069c5 100644
@@ -24,7 +24,7 @@
 #include <linux/sched.h>
 #include <linux/notifier.h>
 #include <linux/moduleparam.h>
-
+#include <linux/device.h>
 #include "kfd_priv.h"
 
 #define DRIVER_AUTHOR		"Andrew Lewycky, Oded Gabbay, Evgeny Pinchuk, others."
@@ -46,7 +46,7 @@ static const struct kgd2kfd_calls kgd2kfd = {
 
 int sched_policy = KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION;
 module_param(sched_policy, int, S_IRUSR | S_IWUSR);
-MODULE_PARM_DESC(sched_policy, "Kernel comline parameter define the kfd scheduling policy");
+MODULE_PARM_DESC(sched_policy, "Kernel cmdline parameter define the kfd scheduling policy");
 
 bool kgd2kfd_init(unsigned interface_version,
 		  const struct kfd2kgd_calls *f2g,
@@ -95,7 +95,7 @@ static int __init kfd_module_init(void)
 	if (err < 0)
 		goto err_topology;
 
-	pr_info("[hsa] Initialized kfd module");
+	dev_info(kfd_device, "Initialized module\n");
 
 	return 0;
 err_topology:
@@ -114,7 +114,7 @@ static void __exit kfd_module_exit(void)
 	mmput_unregister_notifier(&kfd_mmput_nb);
 	radeon_kfd_chardev_exit();
 	radeon_kfd_pasid_exit();
-	pr_info("[hsa] Removed kfd module");
+	dev_info(kfd_device, "Removed module\n");
 }
 
 module_init(kfd_module_init);
drivers/gpu/hsa/radeon/kfd_mqd_manager.h +3 -3
index 8e7a5fd..314d490 100644
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef MQD_MANAGER_H_
-#define MQD_MANAGER_H_
+#ifndef KFD_MQD_MANAGER_H_
+#define KFD_MQD_MANAGER_H_
 
 #include "kfd_priv.h"
 
@@ -44,4 +44,4 @@ struct mqd_manager {
 };
 
 
-#endif /* MQD_MANAGER_H_ */
+#endif /* KFD_MQD_MANAGER_H_ */
drivers/gpu/hsa/radeon/kfd_pm4_headers.h +6 -5
index dae460f..3ffb3f4 100644
@@ -21,8 +21,8 @@
  *
  */
 
-#ifndef F32_MES_PM4_PACKETS_72_H
-#define F32_MES_PM4_PACKETS_72_H
+#ifndef KFD_PM4_HEADERS_H_
+#define KFD_PM4_HEADERS_H_
 
 #ifndef PM4_HEADER_DEFINED
 #define PM4_HEADER_DEFINED
@@ -657,7 +657,7 @@ typedef struct _PM4__SET_SH_REG {
 #ifndef _PM4__SET_CONFIG_REG_DEFINED
 #define _PM4__SET_CONFIG_REG_DEFINED
 
-typedef struct _PM4__SET_CONFIG_REG {
+struct pm4__set_config_reg {
 	union {
 		PM4_TYPE_3_HEADER header;
 		unsigned int ordinal1;
@@ -676,6 +676,7 @@ typedef struct _PM4__SET_CONFIG_REG {
 
 	unsigned int reg_data[1];	/* 1..N of these fields */
 
-}  PM4_SET_CONFIG_REG, *PPM4_SET_CONFIG_REG;
-#endif
+};
 #endif
+
+#endif /* KFD_PM4_HEADERS_H_ */
drivers/gpu/hsa/radeon/kfd_pm4_opcodes.h +3 -3
index c04060c..b72fa3b 100644
@@ -22,8 +22,8 @@
  */
 
 
-#ifndef PM4_IT_OPCODES_H
-#define PM4_IT_OPCODES_H
+#ifndef KFD_PM4_OPCODES_H
+#define KFD_PM4_OPCODES_H
 
 enum it_opcode_type {
 	IT_NOP                               = 0x10,
@@ -103,5 +103,5 @@ enum it_opcode_type {
 #define PM4_TYPE_2 2
 #define PM4_TYPE_3 3
 
-#endif /* PM4_IT_OPCODES_H */
+#endif /* KFD_PM4_OPCODES_H */
 
Signature · 1 line
1.9.1
#33 lore raw

PATCH 59/83 hsa/radeon: Exclusive access for perf. counters

In reply to Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Introducing IOCTL implementation for controlling exclusive access to performace counters. The exclusive access is per GPU device.

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 61 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_device.c  |  2 ++
 drivers/gpu/hsa/radeon/kfd_priv.h    |  5 +++
 drivers/gpu/hsa/radeon/kfd_process.c |  8 +++--
 include/uapi/linux/kfd_ioctl.h       | 12 +++++++
 5 files changed, 86 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +61 -0
index 80b702e..b39df68 100644
@@ -387,6 +387,59 @@ static int kfd_ioctl_get_process_apertures(struct file *filp, struct kfd_process
 	return 0;
 }
 
+static long
+kfd_ioctl_pmc_acquire_access(struct file *filp, struct kfd_process *p, void __user *arg)
+{
+	struct kfd_ioctl_pmc_acquire_access_args args;
+	struct kfd_dev *dev;
+	int err = -EBUSY;
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+
+	dev = radeon_kfd_device_by_id(args.gpu_id);
+	if (dev == NULL)
+		return -EINVAL;
+
+	spin_lock(&dev->pmc_access_lock);
+	if (dev->pmc_locking_process == NULL) {
+		dev->pmc_locking_process = p;
+		dev->pmc_locking_trace = args.trace_id;
+		err = 0;
+	} else if (dev->pmc_locking_process == p && dev->pmc_locking_trace == args.trace_id) {
+		/* Same trace already has an access. Returning success */
+		err = 0;
+	}
+
+	spin_unlock(&dev->pmc_access_lock);
+
+	return err;
+}
+
+static long
+kfd_ioctl_pmc_release_access(struct file *filp, struct kfd_process *p, void __user *arg)
+{
+	struct kfd_ioctl_pmc_release_access_args args;
+	struct kfd_dev *dev;
+	int err = -EINVAL;
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+
+	dev = radeon_kfd_device_by_id(args.gpu_id);
+	if (dev == NULL)
+		return -EINVAL;
+
+	spin_lock(&dev->pmc_access_lock);
+	if (dev->pmc_locking_process == p && dev->pmc_locking_trace == args.trace_id) {
+		dev->pmc_locking_process = NULL;
+		dev->pmc_locking_trace = 0;
+		err = 0;
+	}
+	spin_unlock(&dev->pmc_access_lock);
+
+	return err;
+}
 
 static long
 kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
@@ -427,6 +480,14 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		err = kfd_ioctl_update_queue(filep, process, (void __user *)arg);
 		break;
 
+	case KFD_IOC_PMC_ACQUIRE_ACCESS:
+		err = kfd_ioctl_pmc_acquire_access(filep, process, (void __user *) arg);
+		break;
+
+	case KFD_IOC_PMC_RELEASE_ACCESS:
+		err = kfd_ioctl_pmc_release_access(filep, process, (void __user *) arg);
+		break;
+
 	default:
 		dev_err(kfd_device,
 			"unknown ioctl cmd 0x%x, arg 0x%lx)\n",
drivers/gpu/hsa/radeon/kfd_device.c +2 -0
index c602e16..9af812b 100644
@@ -185,6 +185,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 		return false;
 	}
 
+	spin_lock_init(&kfd->pmc_access_lock);
+
 	kfd->init_complete = true;
 	dev_info(kfd_device, "added device (%x:%x)\n", kfd->pdev->vendor,
 		 kfd->pdev->device);
drivers/gpu/hsa/radeon/kfd_priv.h +5 -0
index 049671b..e6d4993 100644
@@ -135,6 +135,11 @@ struct kfd_dev {
 
 	/* QCM Device instance */
 	struct device_queue_manager *dqm;
+
+	/* Performance counters exclusivity lock */
+	spinlock_t pmc_access_lock;
+	struct kfd_process *pmc_locking_process;
+	uint64_t pmc_locking_trace;
 };
 
 /* KGD2KFD callbacks */
drivers/gpu/hsa/radeon/kfd_process.c +6 -2
index f967c15..9bb5cab 100644
@@ -96,9 +96,13 @@ static void free_process(struct kfd_process *p)
 
 	BUG_ON(p == NULL);
 
-	/* doorbell mappings: automatic */
-
 	list_for_each_entry_safe(pdd, temp, &p->per_device_data, per_device_list) {
+		spin_lock(&pdd->dev->pmc_access_lock);
+		if (pdd->dev->pmc_locking_process == p) {
+			pdd->dev->pmc_locking_process = NULL;
+			pdd->dev->pmc_locking_trace = 0;
+		}
+		spin_unlock(&pdd->dev->pmc_access_lock);
 		amd_iommu_unbind_pasid(pdd->dev->pdev, p->pasid);
 		list_del(&pdd->per_device_list);
 		kfree(pdd);
include/uapi/linux/kfd_ioctl.h +12 -0
index d58231d..509c4a0 100644
@@ -103,6 +103,16 @@ struct kfd_ioctl_get_process_apertures_args {
 	uint8_t num_of_nodes; /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/
 };
 
+struct kfd_ioctl_pmc_acquire_access_args {
+	uint32_t gpu_id;	/* to KFD */
+	uint64_t trace_id;	/* to KFD */
+};
+
+struct kfd_ioctl_pmc_release_access_args {
+	uint32_t gpu_id;	/* to KFD */
+	uint64_t trace_id;	/* to KFD */
+};
+
 #define KFD_IOC_MAGIC 'K'
 
 #define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
@@ -112,6 +122,8 @@ struct kfd_ioctl_get_process_apertures_args {
 #define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
 #define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
 #define KFD_IOC_UPDATE_QUEUE	_IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args)
+#define KFD_IOC_PMC_ACQUIRE_ACCESS	_IOW(KFD_IOC_MAGIC, 12, struct kfd_ioctl_pmc_acquire_access_args)
+#define KFD_IOC_PMC_RELEASE_ACCESS	_IOW(KFD_IOC_MAGIC, 13, struct kfd_ioctl_pmc_release_access_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1
#34 lore raw

PATCH 60/83 hsa/radeon: Rearrange structures in kfd_ioctl.h

In reply to Oded Gabbay

This patch rearranges the structures defined in kfd_ioctl.h so that all the uint64_t variables are located at the start of each structure and then all the uint32_t variables are located.

---
 include/uapi/linux/kfd_ioctl.h | 51 ++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 24 deletions(-)
include/uapi/linux/kfd_ioctl.h +27 -24
index 509c4a0..3cedd1a 100644
@@ -42,15 +42,15 @@ struct kfd_ioctl_get_version_args {
 
 struct kfd_ioctl_create_queue_args {
 	uint64_t ring_base_address;	/* to KFD */
+	uint64_t write_pointer_address;	/* from KFD */
+	uint64_t read_pointer_address;	/* from KFD */
+	uint64_t doorbell_address;	/* from KFD */
+
 	uint32_t ring_size;		/* to KFD */
 	uint32_t gpu_id;		/* to KFD */
 	uint32_t queue_type;		/* to KFD */
 	uint32_t queue_percentage;	/* to KFD */
 	uint32_t queue_priority;	/* to KFD */
-
-	uint64_t write_pointer_address;	/* from KFD */
-	uint64_t read_pointer_address;	/* from KFD */
-	uint64_t doorbell_address;	/* from KFD */
 	uint32_t queue_id;		/* from KFD */
 };
 
@@ -59,8 +59,9 @@ struct kfd_ioctl_destroy_queue_args {
 };
 
 struct kfd_ioctl_update_queue_args {
-	uint32_t queue_id;		/* to KFD */
 	uint64_t ring_base_address;	/* to KFD */
+
+	uint32_t queue_id;		/* to KFD */
 	uint32_t ring_size;		/* to KFD */
 	uint32_t queue_percentage;	/* to KFD */
 	uint32_t queue_priority;	/* to KFD */
@@ -71,31 +72,33 @@ struct kfd_ioctl_update_queue_args {
 #define KFD_IOC_CACHE_POLICY_NONCOHERENT 1
 
 struct kfd_ioctl_set_memory_policy_args {
+	uint64_t alternate_aperture_base;	/* to KFD */
+	uint64_t alternate_aperture_size;	/* to KFD */
+
 	uint32_t gpu_id;			/* to KFD */
 	uint32_t default_policy;		/* to KFD */
 	uint32_t alternate_policy;		/* to KFD */
-	uint64_t alternate_aperture_base;	/* to KFD */
-	uint64_t alternate_aperture_size;	/* to KFD */
 };
 
 struct kfd_ioctl_get_clock_counters_args {
-	uint32_t gpu_id;		/* to KFD */
 	uint64_t gpu_clock_counter;	/* from KFD */
 	uint64_t cpu_clock_counter;	/* from KFD */
 	uint64_t system_clock_counter;	/* from KFD */
 	uint64_t system_clock_freq;	/* from KFD */
+
+	uint32_t gpu_id;		/* to KFD */
 };
 
 #define NUM_OF_SUPPORTED_GPUS 7
 
 struct kfd_process_device_apertures {
-	uint64_t lds_base;/* from KFD */
-	uint64_t lds_limit;/* from KFD */
-	uint64_t scratch_base;/* from KFD */
-	uint64_t scratch_limit;/* from KFD */
-	uint64_t gpuvm_base;/* from KFD */
-	uint64_t gpuvm_limit;/* from KFD */
-	uint32_t gpu_id;/* from KFD */
+	uint64_t lds_base;		/* from KFD */
+	uint64_t lds_limit;		/* from KFD */
+	uint64_t scratch_base;		/* from KFD */
+	uint64_t scratch_limit;		/* from KFD */
+	uint64_t gpuvm_base;		/* from KFD */
+	uint64_t gpuvm_limit;		/* from KFD */
+	uint32_t gpu_id;		/* from KFD */
 };
 
 struct kfd_ioctl_get_process_apertures_args {
@@ -104,24 +107,24 @@ struct kfd_ioctl_get_process_apertures_args {
 };
 
 struct kfd_ioctl_pmc_acquire_access_args {
-	uint32_t gpu_id;	/* to KFD */
-	uint64_t trace_id;	/* to KFD */
+	uint64_t trace_id;		/* to KFD */
+	uint32_t gpu_id;		/* to KFD */
 };
 
 struct kfd_ioctl_pmc_release_access_args {
-	uint32_t gpu_id;	/* to KFD */
-	uint64_t trace_id;	/* to KFD */
+	uint64_t trace_id;		/* to KFD */
+	uint32_t gpu_id;		/* to KFD */
 };
 
 #define KFD_IOC_MAGIC 'K'
 
-#define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
-#define KFD_IOC_CREATE_QUEUE	_IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args)
-#define KFD_IOC_DESTROY_QUEUE	_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
+#define KFD_IOC_GET_VERSION		_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
+#define KFD_IOC_CREATE_QUEUE		_IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args)
+#define KFD_IOC_DESTROY_QUEUE		_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
 #define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
-#define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
-#define KFD_IOC_UPDATE_QUEUE	_IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args)
+#define KFD_IOC_GET_PROCESS_APERTURES	_IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
+#define KFD_IOC_UPDATE_QUEUE		_IOW(KFD_IOC_MAGIC, 7, struct kfd_ioctl_update_queue_args)
 #define KFD_IOC_PMC_ACQUIRE_ACCESS	_IOW(KFD_IOC_MAGIC, 12, struct kfd_ioctl_pmc_acquire_access_args)
 #define KFD_IOC_PMC_RELEASE_ACCESS	_IOW(KFD_IOC_MAGIC, 13, struct kfd_ioctl_pmc_release_access_args)
 
Signature · 1 line
1.9.1
#35 lore raw

PATCH 61/83 hsa/radeon: change another pr_info to pr_debug

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_topology.c +1 -1
index 213ae7b..059b7db 100644
@@ -1121,7 +1121,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu)
 
 	gpu_id = kfd_generate_gpu_id(gpu);
 
-	pr_info("Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
+	pr_debug("kfd: Adding new GPU (ID: 0x%x) to topology\n", gpu_id);
 
 	down_write(&topology_lock);
 	/*
Signature · 1 line
1.9.1
#36 lore raw

PATCH 62/83 hsa/radeon: Fix timeout calculation in sync_with_hw

In reply to Oded Gabbay

This patch fixes a bug in the timeout calculation done in sync_with_hw functions. The original code assumed that jiffies is incremented in ms.

---
 drivers/gpu/hsa/radeon/kfd_kernel_queue.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/hsa/radeon/kfd_kernel_queue.c +10 -4
index 25528b3..ce3261b 100644
@@ -222,12 +222,18 @@ static void submit_packet(struct kernel_queue *kq)
 
 static int sync_with_hw(struct kernel_queue *kq, unsigned long timeout_ms)
 {
+	unsigned long org_timeout_ms;
+
 	BUG_ON(!kq);
-	timeout_ms += jiffies;
+
+	org_timeout_ms = timeout_ms;
+	timeout_ms += jiffies * 1000 / HZ;
 	while (*kq->wptr_kernel != *kq->rptr_kernel) {
-		if (time_after(jiffies, timeout_ms)) {
-			pr_err("kfd: kernel_queue %s timeout expired %lu\n", __func__, timeout_ms);
-			pr_err("kfd: wptr: %d rptr: %d\n", *kq->wptr_kernel, *kq->rptr_kernel);
+		if (time_after(jiffies * 1000 / HZ, timeout_ms)) {
+			pr_err("kfd: kernel_queue %s timeout expired %lu\n",
+				__func__, org_timeout_ms);
+			pr_err("kfd: wptr: %d rptr: %d\n",
+				*kq->wptr_kernel, *kq->rptr_kernel);
 			return -ETIME;
 		}
 		cpu_relax();
Signature · 1 line
1.9.1
#37 lore raw

PATCH 63/83 hsa/radeon: Update module information and version

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_module.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/hsa/radeon/kfd_module.c +12 -7
index 85069c5..fbfcce6 100644
@@ -27,11 +27,13 @@
 #include <linux/device.h>
 #include "kfd_priv.h"
 
-#define DRIVER_AUTHOR		"Andrew Lewycky, Oded Gabbay, Evgeny Pinchuk, others."
+#define KFD_DRIVER_AUTHOR	"AMD Inc. and others"
 
-#define DRIVER_NAME		"kfd"
-#define DRIVER_DESC		"AMD HSA Kernel Fusion Driver"
-#define DRIVER_DATE		"20140127"
+#define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
+#define KFD_DRIVER_DATE		"20140424"
+#define KFD_DRIVER_MAJOR	0
+#define KFD_DRIVER_MINOR	5
+#define KFD_DRIVER_PATCHLEVEL	0
 
 const struct kfd2kgd_calls *kfd2kgd;
 static const struct kgd2kfd_calls kgd2kfd = {
@@ -120,6 +122,9 @@ static void __exit kfd_module_exit(void)
 module_init(kfd_module_init);
 module_exit(kfd_module_exit);
 
-MODULE_AUTHOR(DRIVER_AUTHOR);
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_LICENSE("GPL");
+MODULE_AUTHOR(KFD_DRIVER_AUTHOR);
+MODULE_DESCRIPTION(KFD_DRIVER_DESC);
+MODULE_LICENSE("GPL and additional rights");
+MODULE_VERSION(__stringify(KFD_DRIVER_MAJOR) "."
+	       __stringify(KFD_DRIVER_MINOR) "."
+	       __stringify(KFD_DRIVER_PATCHLEVEL));
Signature · 1 line
1.9.1
#38 lore raw

PATCH 64/83 hsa/radeon: update queue fault handling

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This commit adding fault handling for process queue manager update queue

---
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c +12 -3
index fe74dd7..2034d2b 100644
@@ -334,6 +334,7 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
 
 int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, struct queue_properties *p)
 {
+	int retval;
 	struct process_queue_node *pqn;
 
 	BUG_ON(!pqm);
@@ -346,9 +347,17 @@ int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, struct
 	pqn->q->properties.queue_percent = p->queue_percent;
 	pqn->q->properties.priority = p->priority;
 
-	pqn->q->device->dqm->destroy_queues(pqn->q->device->dqm);
-	pqn->q->device->dqm->update_queue(pqn->q->device->dqm, pqn->q);
-	pqn->q->device->dqm->execute_queues(pqn->q->device->dqm);
+	retval = pqn->q->device->dqm->destroy_queues(pqn->q->device->dqm);
+	if (retval != 0)
+		return retval;
+
+	retval = pqn->q->device->dqm->update_queue(pqn->q->device->dqm, pqn->q);
+	if (retval != 0)
+		return retval;
+
+	retval = pqn->q->device->dqm->execute_queues(pqn->q->device->dqm);
+	if (retval != 0)
+		return retval;
 
 	return 0;
 }
Signature · 1 line
1.9.1
#39 lore raw

PATCH 65/83 hsa/radeon: fixing a bug to support 32b processes

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This commit is a bug fix for 32b hsa processes support

---
 drivers/gpu/hsa/radeon/cik_regs.h                 | 1 +
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 8 +++++---
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/cik_regs.h +1 -0
index fa5ec01..a6404e3 100644
@@ -45,6 +45,7 @@
 /* if PTR32, this is the upper limit of GPUVM */
 #define	SH_MEM_CONFIG					0x8C34
 #define	PTR32						(1 << 0)
+#define PRIVATE_ATC					(1 << 1)
 #define	ALIGNMENT_MODE(x)				((x) << 2)
 #define	SH_MEM_ALIGNMENT_MODE_DWORD			0
 #define	SH_MEM_ALIGNMENT_MODE_DWORD_STRICT		1
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +5 -3
index 01573b1..3e1def1 100644
@@ -90,15 +90,17 @@ static void init_process_memory(struct device_queue_manager *dqm, struct qcm_pro
 	if (qpd->pqm->process->is_32bit_user_mode) {
 		temp = get_sh_mem_bases_32(qpd->pqm->process, dqm->dev);
 		qpd->sh_mem_bases = SHARED_BASE(temp);
+		qpd->sh_mem_config = PTR32;
 	} else {
 		temp = get_sh_mem_bases_nybble_64(qpd->pqm->process, dqm->dev);
 		qpd->sh_mem_bases = compute_sh_mem_bases_64bit(temp);
+		qpd->sh_mem_config = 0;
 	}
 
-	qpd->sh_mem_config = ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
+	qpd->sh_mem_config |= ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
 	qpd->sh_mem_config |= DEFAULT_MTYPE(MTYPE_NONCACHED);
 	qpd->sh_mem_ape1_limit = 0;
-	qpd->sh_mem_ape1_base = 1;
+	qpd->sh_mem_ape1_base = 0;
 
 	pr_debug("kfd: is32bit process: %d sh_mem_bases nybble: 0x%X and register 0x%X\n",
 		qpd->pqm->process->is_32bit_user_mode, temp, qpd->sh_mem_bases);
@@ -854,7 +856,7 @@ static int execute_queues_cpsch(struct device_queue_manager *dqm)
 	}
 
 	if (dqm->queue_count <= 0 || dqm->processes_count <= 0)
-				return 0;
+		return 0;
 
 	mutex_lock(&dqm->lock);
 	if (dqm->active_runlist) {
Signature · 1 line
1.9.1
#40 lore raw

PATCH 66/83 hsa/radeon: Fix number of pipes per ME

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 2 +-
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.h | 2 +-
 drivers/gpu/hsa/radeon/kfd_packet_manager.c       | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +1 -1
index 3e1def1..5ec8da7 100644
@@ -55,7 +55,7 @@ static inline unsigned int get_first_pipe(struct device_queue_manager *dqm)
 
 static inline unsigned int get_pipes_num_cpsch(void)
 {
-	return PIPE_PER_ME_CP_SCHEDULING - 1;
+	return PIPE_PER_ME_CP_SCHEDULING;
 }
 
 static unsigned int get_sh_mem_bases_nybble_64(struct kfd_process *process, struct kfd_dev *dev)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.h +1 -1
index 57dc636..037eaf8 100644
@@ -31,7 +31,7 @@
 
 #define QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS	(500)
 #define QUEUES_PER_PIPE				(8)
-#define PIPE_PER_ME_CP_SCHEDULING		(4)
+#define PIPE_PER_ME_CP_SCHEDULING		(3)
 #define CIK_VMID_NUM				(8)
 #define KFD_VMID_START_OFFSET			(8)
 #define VMID_PER_DEVICE				CIK_VMID_NUM
drivers/gpu/hsa/radeon/kfd_packet_manager.c +1 -1
index 3fc8c34..621a720 100644
@@ -62,7 +62,7 @@ static void pm_calc_rlib_size(struct packet_manager *pm, unsigned int *rlib_size
 	/* check if there is over subscription*/
 	*over_subscription = false;
 	if ((process_count >= VMID_PER_DEVICE) ||
-			queue_count >= PIPE_PER_ME_CP_SCHEDULING * QUEUES_PER_PIPE) {
+			queue_count > PIPE_PER_ME_CP_SCHEDULING * QUEUES_PER_PIPE) {
 		*over_subscription = true;
 		pr_debug("kfd: over subscribed runlist\n");
 	}
Signature · 1 line
1.9.1
#41 lore raw

PATCH 67/83 hsa/radeon: Removing hw pointer store module

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This module is unnecessary as we allocating read/write pointers from userspace thunk layer

---
 drivers/gpu/hsa/radeon/Makefile                    |   2 +-
 drivers/gpu/hsa/radeon/kfd_chardev.c               |  22 +--
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c      | 149 ---------------------
 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h      |  64 ---------
 drivers/gpu/hsa/radeon/kfd_priv.h                  |  10 +-
 drivers/gpu/hsa/radeon/kfd_process.c               |   1 -
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c |  62 ++-------
 7 files changed, 23 insertions(+), 287 deletions(-)
 delete mode 100644 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c
 delete mode 100644 drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h
drivers/gpu/hsa/radeon/Makefile +1 -1
index 3409203..26ce0ae 100644
@@ -6,7 +6,7 @@ radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
 		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
-		kfd_queue.o kfd_hw_pointer_store.o kfd_mqd_manager.o \
+		kfd_queue.o kfd_mqd_manager.o \
 		kfd_kernel_queue.o kfd_packet_manager.o \
 		kfd_process_queue_manager.o kfd_device_queue_manager.o
 
drivers/gpu/hsa/radeon/kfd_chardev.c +11 -11
index b39df68..51f790f 100644
@@ -32,9 +32,9 @@
 #include <linux/time.h>
 #include "kfd_priv.h"
 #include <linux/mm.h>
+#include <linux/uaccess.h>
 #include <uapi/asm-generic/mman-common.h>
 #include <asm/processor.h>
-#include "kfd_hw_pointer_store.h"
 #include "kfd_device_queue_manager.h"
 
 static long kfd_ioctl(struct file *, unsigned int, unsigned long);
@@ -137,24 +137,32 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a
 	if (copy_from_user(&args, arg, sizeof(args)))
 		return -EFAULT;
 
-	/* need to validate parameters */
+	if (!access_ok(VERIFY_WRITE, args.read_pointer_address, sizeof(qptr_t)))
+		return -EFAULT;
+
+	if (!access_ok(VERIFY_WRITE, args.write_pointer_address, sizeof(qptr_t)))
+		return -EFAULT;
 
 	q_properties.is_interop = false;
 	q_properties.queue_percent = args.queue_percentage;
 	q_properties.priority = args.queue_priority;
 	q_properties.queue_address = args.ring_base_address;
 	q_properties.queue_size = args.ring_size;
+	q_properties.read_ptr = args.read_pointer_address;
+	q_properties.write_ptr = args.write_pointer_address;
 
 
 	pr_debug("%s Arguments: Queue Percentage (%d, %d)\n"
 			"Queue Priority (%d, %d)\n"
 			"Queue Address (0x%llX, 0x%llX)\n"
 			"Queue Size (%llX, %u)\n",
+			"Queue r/w Pointers (%llX, %llX)\n",
 			__func__,
 			q_properties.queue_percent, args.queue_percentage,
 			q_properties.priority, args.queue_priority,
 			q_properties.queue_address, args.ring_base_address,
-			q_properties.queue_size, args.ring_size);
+			q_properties.queue_size, args.ring_size,
+			q_properties.read_ptr, q_properties.write_ptr);
 
 	dev = radeon_kfd_device_by_id(args.gpu_id);
 	if (dev == NULL)
@@ -177,8 +185,6 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a
 		goto err_create_queue;
 
 	args.queue_id = queue_id;
-	args.read_pointer_address = (uint64_t)q_properties.read_ptr;
-	args.write_pointer_address = (uint64_t)q_properties.write_ptr;
 	args.doorbell_address = (uint64_t)q_properties.doorbell_ptr;
 
 	if (copy_to_user(arg, &args, sizeof(args))) {
@@ -515,11 +521,5 @@ kfd_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (pgoff >= KFD_MMAP_DOORBELL_START && pgoff < KFD_MMAP_DOORBELL_END)
 		return radeon_kfd_doorbell_mmap(process, vma);
 
-	if (pgoff >= KFD_MMAP_RPTR_START && pgoff < KFD_MMAP_RPTR_END)
-		return radeon_kfd_hw_pointer_store_mmap(&process->read_ptr, vma);
-
-	if (pgoff >= KFD_MMAP_WPTR_START && pgoff < KFD_MMAP_WPTR_END)
-		return radeon_kfd_hw_pointer_store_mmap(&process->write_ptr, vma);
-
 	return -EINVAL;
 }
drivers/gpu/hsa/radeon/kfd_hw_pointer_store.c deleted +0 -149

149 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_hw_pointer_store.h deleted +0 -64

64 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_priv.h +2 -8
index e6d4993..97bf58a 100644
@@ -31,7 +31,6 @@
 #include <linux/atomic.h>
 #include <linux/workqueue.h>
 #include <linux/spinlock.h>
-#include "kfd_hw_pointer_store.h"
 
 struct kfd_scheduler_class;
 
@@ -50,10 +49,6 @@ struct kfd_scheduler_class;
 ** We figure out what type of memory the caller wanted by comparing the mmap page offset to known ranges. */
 #define KFD_MMAP_DOORBELL_START	(((1ULL << 32)*1) >> PAGE_SHIFT)
 #define KFD_MMAP_DOORBELL_END	(((1ULL << 32)*2) >> PAGE_SHIFT)
-#define KFD_MMAP_RPTR_START	KFD_MMAP_DOORBELL_END
-#define KFD_MMAP_RPTR_END	(((1ULL << 32)*3) >> PAGE_SHIFT)
-#define KFD_MMAP_WPTR_START	KFD_MMAP_RPTR_END
-#define KFD_MMAP_WPTR_END	(((1ULL << 32)*4) >> PAGE_SHIFT)
 
 /*
  * When working with cp scheduler we should assign the HIQ manually or via the radeon driver
@@ -85,6 +80,8 @@ typedef unsigned int pasid_t;
 
 /* Type that represents a HW doorbell slot. */
 typedef u32 doorbell_t;
+/* Type that represents queue pointer */
+typedef u32 qptr_t;
 
 enum cache_policy {
 	cache_policy_coherent,
@@ -350,9 +347,6 @@ struct kfd_process {
 	/* List of kfd_process_device structures, one for each device the process is using. */
 	struct list_head per_device_data;
 
-	struct hw_pointer_store_properties write_ptr;
-	struct hw_pointer_store_properties read_ptr;
-
 	struct process_queue_manager pqm;
 
 	/* The process's queues. */
drivers/gpu/hsa/radeon/kfd_process.c +0 -1
index 9bb5cab..eb30cb3 100644
@@ -168,7 +168,6 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 
 	INIT_LIST_HEAD(&process->per_device_data);
 
-	process->read_ptr.page_mapping = process->write_ptr.page_mapping = NULL;
 	err = pqm_init(&process->pqm, process);
 	if (err != 0)
 		goto err_process_pqm_init;
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c +9 -53

95 lines not on this page · raw message

Signature · 1 line
1.9.1
#42 lore raw

PATCH 68/83 hsa/radeon: Update module version to 0.6.0

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_module.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_module.c +1 -1
index fbfcce6..33cee3c 100644
@@ -32,7 +32,7 @@
 #define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
 #define KFD_DRIVER_DATE		"20140424"
 #define KFD_DRIVER_MAJOR	0
-#define KFD_DRIVER_MINOR	5
+#define KFD_DRIVER_MINOR	6
 #define KFD_DRIVER_PATCHLEVEL	0
 
 const struct kfd2kgd_calls *kfd2kgd;
Signature · 1 line
1.9.1
#43 lore raw

PATCH 69/83 hsa/radeon: Fix initialization of sh_mem registers

In reply to Oded Gabbay

This patch fixes a bug in the code flow that caused an override of the sh_mem registers.
The bug resulted in sh_mem registers being not initialized properly and overwrite over sh_mem registers for vmid 0 (which is a vmid of non-HSA processes).

---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 48 ++++++++++++-----------
 1 file changed, 26 insertions(+), 22 deletions(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +26 -22
index 5ec8da7..56875f9 100644
@@ -87,21 +87,25 @@ static void init_process_memory(struct device_queue_manager *dqm, struct qcm_pro
 	unsigned int temp;
 	BUG_ON(!dqm || !qpd);
 
+	/* check if sh_mem_config register already configured */
+	if (qpd->sh_mem_config == 0) {
+		qpd->sh_mem_config =
+			ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED) |
+			DEFAULT_MTYPE(MTYPE_NONCACHED) |
+			APE1_MTYPE(MTYPE_NONCACHED);
+		qpd->sh_mem_ape1_limit = 0;
+		qpd->sh_mem_ape1_base = 0;
+	}
+
 	if (qpd->pqm->process->is_32bit_user_mode) {
 		temp = get_sh_mem_bases_32(qpd->pqm->process, dqm->dev);
 		qpd->sh_mem_bases = SHARED_BASE(temp);
-		qpd->sh_mem_config = PTR32;
+		qpd->sh_mem_config |= PTR32;
 	} else {
 		temp = get_sh_mem_bases_nybble_64(qpd->pqm->process, dqm->dev);
 		qpd->sh_mem_bases = compute_sh_mem_bases_64bit(temp);
-		qpd->sh_mem_config = 0;
 	}
 
-	qpd->sh_mem_config |= ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED);
-	qpd->sh_mem_config |= DEFAULT_MTYPE(MTYPE_NONCACHED);
-	qpd->sh_mem_ape1_limit = 0;
-	qpd->sh_mem_ape1_base = 0;
-
 	pr_debug("kfd: is32bit process: %d sh_mem_bases nybble: 0x%X and register 0x%X\n",
 		qpd->pqm->process->is_32bit_user_mode, temp, qpd->sh_mem_bases);
 }
@@ -110,6 +114,8 @@ static void program_sh_mem_settings(struct device_queue_manager *dqm, struct qcm
 {
 	struct mqd_manager *mqd;
 
+	BUG_ON(qpd->vmid < KFD_VMID_START_OFFSET);
+
 	mqd = dqm->get_mqd_manager(dqm, KFD_MQD_TYPE_CIK_COMPUTE);
 	if (mqd == NULL)
 		return;
@@ -139,12 +145,6 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm, struct queue *
 	print_queue(q);
 
 	mutex_lock(&dqm->lock);
-	/* later memory apertures should be initialized in lazy mode */
-	if (!is_mem_initialized)
-		if (init_memory(dqm) != 0) {
-			retval = -ENODATA;
-			goto init_memory_failed;
-		}
 
 	if (dqm->vmid_bitmap == 0 && qpd->vmid == 0) {
 		retval = -ENOMEM;
@@ -217,7 +217,6 @@ no_hqd:
 		*allocate_vmid = qpd->vmid = q->properties.vmid = 0;
 	}
 no_vmid:
-init_memory_failed:
 	mutex_unlock(&dqm->lock);
 	return retval;
 }
@@ -951,20 +950,25 @@ static bool set_cache_memory_policy(struct device_queue_manager *dqm,
 		qpd->sh_mem_ape1_limit = limit >> 16;
 	}
 
-	default_mtype = (default_policy == cache_policy_coherent) ? MTYPE_NONCACHED : MTYPE_CACHED;
-	ape1_mtype = (alternate_policy == cache_policy_coherent) ? MTYPE_NONCACHED : MTYPE_CACHED;
+	default_mtype = (default_policy == cache_policy_coherent) ?
+			MTYPE_NONCACHED :
+			MTYPE_CACHED;
+
+	ape1_mtype = (alternate_policy == cache_policy_coherent) ?
+			MTYPE_NONCACHED :
+			MTYPE_CACHED;
 
-	qpd->sh_mem_config = ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
+	qpd->sh_mem_config = (qpd->sh_mem_config & PTR32)
+			| ALIGNMENT_MODE(SH_MEM_ALIGNMENT_MODE_UNALIGNED)
 			| DEFAULT_MTYPE(default_mtype)
 			| APE1_MTYPE(ape1_mtype);
 
-
-	if (sched_policy == KFD_SCHED_POLICY_NO_HWS)
+	if ((sched_policy == KFD_SCHED_POLICY_NO_HWS) && (qpd->vmid != 0))
 		program_sh_mem_settings(dqm, qpd);
 
-
-	pr_debug("kfd: sh_mem_config: 0x%x, ape1_base: 0x%x, ape1_limit: 0x%x\n", qpd->sh_mem_config,
-		 qpd->sh_mem_ape1_base, qpd->sh_mem_ape1_limit);
+	pr_debug("kfd: sh_mem_config: 0x%x, ape1_base: 0x%x, ape1_limit: 0x%x\n",
+		qpd->sh_mem_config, qpd->sh_mem_ape1_base,
+		qpd->sh_mem_ape1_limit);
 
 	mutex_unlock(&dqm->lock);
 	return true;
Signature · 1 line
1.9.1
#44 lore raw

PATCH 70/83 hsa/radeon: Fix compilation warnings

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +6 -5
index 51f790f..09c9a61 100644
@@ -148,21 +148,22 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a
 	q_properties.priority = args.queue_priority;
 	q_properties.queue_address = args.ring_base_address;
 	q_properties.queue_size = args.ring_size;
-	q_properties.read_ptr = args.read_pointer_address;
-	q_properties.write_ptr = args.write_pointer_address;
+	q_properties.read_ptr = (qptr_t *) args.read_pointer_address;
+	q_properties.write_ptr = (qptr_t *) args.write_pointer_address;
 
 
 	pr_debug("%s Arguments: Queue Percentage (%d, %d)\n"
 			"Queue Priority (%d, %d)\n"
 			"Queue Address (0x%llX, 0x%llX)\n"
-			"Queue Size (%llX, %u)\n",
-			"Queue r/w Pointers (%llX, %llX)\n",
+			"Queue Size (0x%llX, %u)\n"
+			"Queue r/w Pointers (0x%llX, 0x%llX)\n",
 			__func__,
 			q_properties.queue_percent, args.queue_percentage,
 			q_properties.priority, args.queue_priority,
 			q_properties.queue_address, args.ring_base_address,
 			q_properties.queue_size, args.ring_size,
-			q_properties.read_ptr, q_properties.write_ptr);
+			(uint64_t) q_properties.read_ptr,
+			(uint64_t) q_properties.write_ptr);
 
 	dev = radeon_kfd_device_by_id(args.gpu_id);
 	if (dev == NULL)
Signature · 1 line
1.9.1
#45 lore raw

PATCH 71/83 hsa/radeon: Remove old scheduler code

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/Makefile               |   5 +-
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c | 987 --------------------------
 2 files changed, 2 insertions(+), 990 deletions(-)
 delete mode 100644 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c
drivers/gpu/hsa/radeon/Makefile +2 -3
index 26ce0ae..b5f05b4 100644
@@ -4,9 +4,8 @@
 
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
-		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
-		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o \
-		kfd_queue.o kfd_mqd_manager.o \
+		kfd_doorbell.o kfd_registers.o kfd_vidmem.o \
+		kfd_interrupt.o kfd_aperture.o kfd_queue.o kfd_mqd_manager.o \
 		kfd_kernel_queue.o kfd_packet_manager.o \
 		kfd_process_queue_manager.o kfd_device_queue_manager.o
 
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c deleted +0 -987

987 lines not on this page · raw message

Signature · 1 line
1.9.1
#46 lore raw

PATCH 72/83 hsa/radeon: Static analysis (smatch) fixes

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_device.c               |  3 +++
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c |  2 +-
 drivers/gpu/hsa/radeon/kfd_mqd_manager.c          |  1 +
 drivers/gpu/hsa/radeon/kfd_packet_manager.c       |  3 ++-
 drivers/gpu/hsa/radeon/kfd_process.c              | 10 ++++++----
 5 files changed, 13 insertions(+), 6 deletions(-)
drivers/gpu/hsa/radeon/kfd_device.c +3 -0
index 9af812b..30558c9 100644
@@ -88,6 +88,9 @@ struct kfd_dev *kgd2kfd_probe(struct kgd_dev *kgd, struct pci_dev *pdev)
 		return NULL;
 
 	kfd = kzalloc(sizeof(*kfd), GFP_KERNEL);
+	if (!kfd)
+		return NULL;
+
 	kfd->kgd = kgd;
 	kfd->device_info = device_info;
 	kfd->pdev = pdev;
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +1 -1
index 56875f9..4931f8a 100644
@@ -317,7 +317,7 @@ static struct mqd_manager *get_mqd_manager_nocpsch(struct device_queue_manager *
 {
 	struct mqd_manager *mqd;
 
-	BUG_ON(!dqm || type > KFD_MQD_TYPE_MAX);
+	BUG_ON(!dqm || type >= KFD_MQD_TYPE_MAX);
 
 	pr_debug("kfd: In func %s mqd type %d\n", __func__, type);
 
drivers/gpu/hsa/radeon/kfd_mqd_manager.c +1 -0
index a3e9f7c..8c1192e 100644
@@ -437,6 +437,7 @@ struct mqd_manager *mqd_manager_init(enum KFD_MQD_TYPE type, struct kfd_dev *dev
 		mqd->uninitialize = uninitialize;
 		break;
 	default:
+		kfree(mqd);
 		return NULL;
 		break;
 	}
drivers/gpu/hsa/radeon/kfd_packet_manager.c +2 -1
index 621a720..5cd23b0 100644
@@ -85,9 +85,10 @@ static int pm_allocate_runlist_ib(struct packet_manager *pm, unsigned int **rl_b
 
 	BUG_ON(!pm);
 	BUG_ON(pm->allocated == true);
+	BUG_ON(is_over_subscription == NULL);
 
 	pm_calc_rlib_size(pm, rl_buffer_size, is_over_subscription);
-	if (is_over_subscription &&
+	if (*is_over_subscription &&
 			sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION)
 		return -EFAULT;
 
drivers/gpu/hsa/radeon/kfd_process.c +6 -4
index eb30cb3..aacc7ef 100644
@@ -146,15 +146,15 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 	process = kzalloc(sizeof(*process), GFP_KERNEL);
 
 	if (!process)
-		goto err_alloc;
+		goto err_alloc_process;
 
 	process->queues = kmalloc_array(INITIAL_QUEUE_ARRAY_SIZE, sizeof(process->queues[0]), GFP_KERNEL);
 	if (!process->queues)
-		goto err_alloc;
+		goto err_alloc_queues;
 
 	process->pasid = radeon_kfd_pasid_alloc();
 	if (process->pasid == 0)
-		goto err_alloc;
+		goto err_alloc_pasid;
 
 	mutex_init(&process->mutex);
 
@@ -178,9 +178,11 @@ err_process_pqm_init:
 	radeon_kfd_pasid_free(process->pasid);
 	list_del(&process->processes_list);
 	thread->mm->kfd_process = NULL;
-err_alloc:
+err_alloc_pasid:
 	kfree(process->queues);
+err_alloc_queues:
 	kfree(process);
+err_alloc_process:
 	return ERR_PTR(err);
 }
 
Signature · 1 line
1.9.1
#47 lore raw

PATCH 73/83 hsa/radeon: Adding qcm fence return status

In reply to Oded Gabbay

From: Yair Shachar <[email protected]>

Waiting on fence returns status

---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 6 ++++--
 drivers/gpu/hsa/radeon/kfd_priv.h                 | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +4 -2
index 4931f8a..4c53e57 100644
@@ -800,7 +800,7 @@ out:
 	return retval;
 }
 
-static void fence_wait_timeout(unsigned int *fence_addr, unsigned int fence_value, unsigned long timeout)
+int fence_wait_timeout(unsigned int *fence_addr, unsigned int fence_value, unsigned long timeout)
 {
 	BUG_ON(!fence_addr);
 	timeout += jiffies;
@@ -808,10 +808,12 @@ static void fence_wait_timeout(unsigned int *fence_addr, unsigned int fence_valu
 	while (*fence_addr != fence_value) {
 		if (time_after(jiffies, timeout)) {
 			pr_err("kfd: qcm fence wait loop timeout expired\n");
-			break;
+			return -ETIME;
 		}
 		cpu_relax();
 	}
+
+	return 0;
 }
 
 static int destroy_queues_cpsch(struct device_queue_manager *dqm)
drivers/gpu/hsa/radeon/kfd_priv.h +2 -0
index 97bf58a..b61187a 100644
@@ -463,6 +463,8 @@ int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid, struct
 struct kernel_queue *pqm_get_kernel_queue(struct process_queue_manager *pqm, unsigned int qid);
 void test_diq(struct kfd_dev *dev, struct process_queue_manager *pqm);
 
+int fence_wait_timeout(unsigned int *fence_addr, unsigned int fence_value, unsigned long timeout);
+
 /* Packet Manager */
 
 #define KFD_HIQ_TIMEOUT (500)
Signature · 1 line
1.9.1
#48 lore raw

PATCH 74/83 hsa/radeon: Adding some error messages

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_chardev.c +6 -2
index 09c9a61..be89d26 100644
@@ -137,11 +137,15 @@ kfd_ioctl_create_queue(struct file *filep, struct kfd_process *p, void __user *a
 	if (copy_from_user(&args, arg, sizeof(args)))
 		return -EFAULT;
 
-	if (!access_ok(VERIFY_WRITE, args.read_pointer_address, sizeof(qptr_t)))
+	if (!access_ok(VERIFY_WRITE, args.read_pointer_address, sizeof(qptr_t))) {
+		pr_err("kfd: can't access read pointer");
 		return -EFAULT;
+	}
 
-	if (!access_ok(VERIFY_WRITE, args.write_pointer_address, sizeof(qptr_t)))
+	if (!access_ok(VERIFY_WRITE, args.write_pointer_address, sizeof(qptr_t))) {
+		pr_err("kfd: can't access write pointer");
 		return -EFAULT;
+	}
 
 	q_properties.is_interop = false;
 	q_properties.queue_percent = args.queue_percentage;
Signature · 1 line
1.9.1
#49 lore raw

PATCH 75/83 hsa/radeon: Fixing minor issues with kernel queues (DIQ)

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

* re-execute runlist on kernel queues destruction.
* delete kernel queues from pqm's queues list on pqm unint

---
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c  | 4 ++++
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +4 -0
index 4c53e57..12b8b33 100644
@@ -759,6 +759,10 @@ static void destroy_kernel_queue_cpsch(struct device_queue_manager *dqm,
 {
 	BUG_ON(!dqm || !kq);
 
+	pr_debug("kfd: In %s\n", __func__);
+
+	dqm->destroy_queues(dqm);
+
 	mutex_lock(&dqm->lock);
 	list_del(&kq->list);
 	dqm->queue_count--;
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c +1 -1
index 89461ab..5d7c46d 100644
@@ -273,10 +273,10 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
 		if (retval != 0)
 			return retval;
 
-		list_del(&pqn->process_queue_list);
 		uninit_queue(pqn->q);
 	}
 
+	list_del(&pqn->process_queue_list);
 	kfree(pqn);
 	clear_bit(qid, pqm->queue_slot_bitmap);
 
Signature · 1 line
1.9.1
#50 lore raw

PATCH 76/83 hsa/radeon: Check oversubscription before destroying runlist

In reply to Oded Gabbay

This patch fixes a bug when using the mode of CP hardware scheduling without oversubscription.

The bug was that the oversubscription check was performed _after_ the current runlist was destroyed, which caused the current HSA application to stop working.

This patch moves the oversubscription check before the call to destroy the current runlist. If there is oversubscription, the function prints an error to dmesg and simply exits.

---
 drivers/gpu/hsa/radeon/kfd_packet_manager.c        | 3 ---
 drivers/gpu/hsa/radeon/kfd_process_queue_manager.c | 9 +++++++++
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/hsa/radeon/kfd_packet_manager.c +0 -3
index 5cd23b0..0aef907 100644
@@ -88,9 +88,6 @@ static int pm_allocate_runlist_ib(struct packet_manager *pm, unsigned int **rl_b
 	BUG_ON(is_over_subscription == NULL);
 
 	pm_calc_rlib_size(pm, rl_buffer_size, is_over_subscription);
-	if (*is_over_subscription &&
-			sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION)
-		return -EFAULT;
 
 	retval = radeon_kfd_vidmem_alloc_map(pm->dqm->dev, &pm->ib_buffer_obj, (void **)rl_buffer,
 					     rl_gpu_buffer, ALIGN(*rl_buffer_size, PAGE_SIZE));
drivers/gpu/hsa/radeon/kfd_process_queue_manager.c +9 -0
index 5d7c46d..97b3cc6 100644
@@ -174,6 +174,15 @@ int pqm_create_queue(struct process_queue_manager *pqm,
 
 	switch (type) {
 	case KFD_QUEUE_TYPE_COMPUTE:
+		/* check if there is over subscription */
+		if ((sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION) &&
+		((dev->dqm->processes_count >= VMID_PER_DEVICE) ||
+		(dev->dqm->queue_count >= PIPE_PER_ME_CP_SCHEDULING * QUEUES_PER_PIPE))) {
+			pr_err("kfd: over-subscription is not allowed in radeon_kfd.sched_policy == 1\n");
+			retval = -EPERM;
+			goto err_create_queue;
+		}
+
 		retval = create_cp_queue(pqm, dev, &q, &q_properties, f, *qid);
 		if (retval != 0)
 			goto err_create_queue;
Signature · 1 line
1.9.1
#51 lore raw

PATCH 77/83 hsa/radeon: Add local memory to topology

In reply to Oded Gabbay

From: Alexey Skidanov <[email protected]>

---
 drivers/gpu/hsa/radeon/kfd_topology.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/hsa/radeon/kfd_topology.c +2 -0
index 059b7db..d3aaad1 100644
@@ -715,6 +715,8 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 		sysfs_show_32bit_prop(buffer, "max_engine_clk_fcompute",
 				kfd2kgd->get_max_engine_clock_in_mhz(
 					dev->gpu->kgd));
+		sysfs_show_64bit_prop(buffer, "local_mem_size",
+				kfd2kgd->get_vmem_size(dev->gpu->kgd));
 		ret = sysfs_show_32bit_prop(buffer, "max_engine_clk_ccompute",
 				cpufreq_quick_get_max(0)/1000);
 	}
Signature · 1 line
1.9.1
#52 lore raw

PATCH 78/83 hsa/radeon: Don't verify cksum when parsing CRAT table

In reply to Oded Gabbay

This patch removes the checksum verification done when parsing a CRAT table. The verification was both erronous and redundant, as it is done by another piece of kernel code.

---
 drivers/gpu/hsa/radeon/kfd_topology.c | 29 ++---------------------------
 1 file changed, 2 insertions(+), 27 deletions(-)
drivers/gpu/hsa/radeon/kfd_topology.c +2 -27
index d3aaad1..b686b7e 100644
@@ -38,21 +38,6 @@ static struct kfd_system_properties sys_props;
 
 static DECLARE_RWSEM(topology_lock);
 
-
-static uint8_t checksum_image(const void *buf, size_t len)
-{
-	uint8_t *p = (uint8_t *)buf;
-	uint8_t sum = 0;
-
-	if (!buf)
-		return 0;
-
-	while (len-- > 0)
-		sum += *p++;
-
-	return sum;
-		}
-
 struct kfd_dev *radeon_kfd_device_by_id(uint32_t gpu_id)
 {
 	struct kfd_topology_device *top_dev;
@@ -97,9 +82,9 @@ static int kfd_topology_get_crat_acpi(void *crat_image, size_t *size)
 	if (!size)
 		return -EINVAL;
 
-/*
+	/*
 	 * Fetch the CRAT table from ACPI
- */
+	 */
 	status = acpi_get_table(CRAT_SIGNATURE, 0, &crat_table);
 	if (status == AE_NOT_FOUND) {
 		pr_warn("CRAT table not found\n");
@@ -111,16 +96,6 @@ static int kfd_topology_get_crat_acpi(void *crat_image, size_t *size)
 		return -EINVAL;
 	}
 
-	/*
-	 * The checksum of the table should be verified
-	 */
-	if (checksum_image(crat_table, crat_table->length) ==
-		crat_table->checksum) {
-		pr_err("Bad checksum for the CRAT table\n");
-		return -EINVAL;
-}
-
-
 	if (*size >= crat_table->length && crat_image != 0)
 		memcpy(crat_image, crat_table, crat_table->length);
 
Signature · 1 line
1.9.1
#53 lore raw

PATCH 79/83 hsa/radeon: Update module version to 0.6.1

In reply to Oded Gabbay
---
 drivers/gpu/hsa/radeon/kfd_module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_module.c +2 -2
index 33cee3c..c706236 100644
@@ -30,10 +30,10 @@
 #define KFD_DRIVER_AUTHOR	"AMD Inc. and others"
 
 #define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
-#define KFD_DRIVER_DATE		"20140424"
+#define KFD_DRIVER_DATE		"20140623"
 #define KFD_DRIVER_MAJOR	0
 #define KFD_DRIVER_MINOR	6
-#define KFD_DRIVER_PATCHLEVEL	0
+#define KFD_DRIVER_PATCHLEVEL	1
 
 const struct kfd2kgd_calls *kfd2kgd;
 static const struct kgd2kfd_calls kgd2kfd = {
Signature · 1 line
1.9.1
#54 lore raw

PATCH 80/83 drm/radeon: Add register access functions to kfd2kgd interface

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch extends the kfd2kgd interface by adding functions that perform direct register access.

These functions can be called from kfd and will allow to eliminate all direct register accesses from within the kfd.

---
 drivers/gpu/drm/radeon/cikd.h       |  51 +++++-
 drivers/gpu/drm/radeon/radeon_kfd.c | 354 ++++++++++++++++++++++++++++++++++++
 include/linux/radeon_kfd.h          |  11 ++
 3 files changed, 415 insertions(+), 1 deletion(-)
drivers/gpu/drm/radeon/cikd.h +50 -1
index 0c6e1b5..0a2a403 100644
@@ -1137,6 +1137,9 @@
 #define			SH_MEM_ALIGNMENT_MODE_UNALIGNED			3
 #define		DEFAULT_MTYPE(x)				((x) << 4)
 #define		APE1_MTYPE(x)					((x) << 7)
+/* valid for both DEFAULT_MTYPE and APE1_MTYPE */
+#define	MTYPE_CACHED					0
+#define	MTYPE_NONCACHED					3
 
 #define	SX_DEBUG_1					0x9060
 
@@ -1447,6 +1450,16 @@
 #define CP_HQD_ACTIVE                                     0xC91C
 #define CP_HQD_VMID                                       0xC920
 
+#define CP_HQD_PERSISTENT_STATE							0xC924u
+#define	DEFAULT_CP_HQD_PERSISTENT_STATE						(0x33U << 8)
+
+#define CP_HQD_PIPE_PRIORITY							0xC928u
+#define CP_HQD_QUEUE_PRIORITY							0xC92Cu
+#define CP_HQD_QUANTUM									0xC930u
+#define	QUANTUM_EN											1U
+#define	QUANTUM_SCALE_1MS									(1U << 4)
+#define	QUANTUM_DURATION(x)									((x) << 8)
+
 #define CP_HQD_PQ_BASE                                    0xC934
 #define CP_HQD_PQ_BASE_HI                                 0xC938
 #define CP_HQD_PQ_RPTR                                    0xC93C
@@ -1474,12 +1487,32 @@
 #define		PRIV_STATE      			(1 << 30)
 #define		KMD_QUEUE      				(1 << 31)
 
-#define CP_HQD_DEQUEUE_REQUEST                          0xC974
+#define CP_HQD_IB_BASE_ADDR				0xC95Cu
+#define CP_HQD_IB_BASE_ADDR_HI			0xC960u
+#define CP_HQD_IB_RPTR					0xC964u
+#define CP_HQD_IB_CONTROL				0xC968u
+#define	IB_ATC_EN							(1U << 23)
+#define	DEFAULT_MIN_IB_AVAIL_SIZE			(3U << 20)
+
+#define CP_HQD_DEQUEUE_REQUEST			0xC974
+#define	DEQUEUE_REQUEST_DRAIN				1
+#define DEQUEUE_REQUEST_RESET				2
 
 #define CP_MQD_CONTROL                                  0xC99C
 #define		MQD_VMID(x)				((x) << 0)
 #define		MQD_VMID_MASK      			(0xf << 0)
 
+#define CP_HQD_SEMA_CMD					0xC97Cu
+#define CP_HQD_MSG_TYPE					0xC980u
+#define CP_HQD_ATOMIC0_PREOP_LO			0xC984u
+#define CP_HQD_ATOMIC0_PREOP_HI			0xC988u
+#define CP_HQD_ATOMIC1_PREOP_LO			0xC98Cu
+#define CP_HQD_ATOMIC1_PREOP_HI			0xC990u
+#define CP_HQD_HQ_SCHEDULER0			0xC994u
+#define CP_HQD_HQ_SCHEDULER1			0xC998u
+
+#define SH_STATIC_MEM_CONFIG			0x9604u
+
 #define DB_RENDER_CONTROL                               0x28000
 
 #define PA_SC_RASTER_CONFIG                             0x28350
@@ -2069,4 +2102,20 @@
 #define VCE_CMD_IB_AUTO		0x00000005
 #define VCE_CMD_SEMAPHORE	0x00000006
 
+#define ATC_VMID0_PASID_MAPPING					0x339Cu
+#define	ATC_VMID_PASID_MAPPING_UPDATE_STATUS	0x3398u
+#define	ATC_VMID_PASID_MAPPING_VALID				(1U << 31)
+
+#define ATC_VM_APERTURE0_CNTL					0x3310u
+#define	ATS_ACCESS_MODE_NEVER						0
+#define	ATS_ACCESS_MODE_ALWAYS						1
+
+#define ATC_VM_APERTURE0_CNTL2					0x3318u
+#define ATC_VM_APERTURE0_HIGH_ADDR				0x3308u
+#define ATC_VM_APERTURE0_LOW_ADDR				0x3300u
+#define ATC_VM_APERTURE1_CNTL					0x3314u
+#define ATC_VM_APERTURE1_CNTL2					0x331Cu
+#define ATC_VM_APERTURE1_HIGH_ADDR				0x330Cu
+#define ATC_VM_APERTURE1_LOW_ADDR				0x3304u
+
 #endif
drivers/gpu/drm/radeon/radeon_kfd.c +354 -0

379 lines not on this page · raw message

include/linux/radeon_kfd.h +11 -0
index 4114c8e..aa021fb 100644
@@ -95,6 +95,17 @@ struct kfd2kgd_calls {
 	void (*unlock_grbm_gfx_idx)(struct kgd_dev *kgd);
 
 	uint32_t (*get_max_engine_clock_in_mhz)(struct kgd_dev *kgd);
+
+	/* Register access functions */
+	void (*program_sh_mem_settings)(struct kgd_dev *kgd, uint32_t vmid, uint32_t sh_mem_config,
+			uint32_t sh_mem_ape1_base, uint32_t sh_mem_ape1_limit, uint32_t sh_mem_bases);
+	int (*set_pasid_vmid_mapping)(struct kgd_dev *kgd, unsigned int pasid, unsigned int vmid);
+	int (*init_memory)(struct kgd_dev *kgd);
+	int (*init_pipeline)(struct kgd_dev *kgd, uint32_t pipe_id, uint32_t hpd_size, uint64_t hpd_gpu_addr);
+	int (*hqd_load)(struct kgd_dev *kgd, void *mqd, uint32_t pipe_id, uint32_t queue_id, uint32_t __user *wptr);
+	bool (*hqd_is_occupies)(struct kgd_dev *kgd, uint64_t queue_address, uint32_t pipe_id, uint32_t queue_id);
+	int (*hqd_destroy)(struct kgd_dev *kgd, bool is_reset, unsigned int timeout,
+				uint32_t pipe_id, uint32_t queue_id);
 };
 
 bool kgd2kfd_init(unsigned interface_version,
Signature · 1 line
1.9.1
#55 lore raw

PATCH 81/83 hsa/radeon: Eliminating all direct register accesses

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

This patch eliminates all direct register accesses from KFD and eliminate using of shared locks between KFD and radeon.

The single exception is the doorbells that are used in both of the drivers. However, because they are located in separate pci bar pages, the danger of sharing registers between the drivers is minimal.

Having said that, we are planning to move the doorbells as well to radeon.

---
 drivers/gpu/hsa/radeon/Makefile                   |   2 +-
 drivers/gpu/hsa/radeon/kfd_device.c               |   2 -
 drivers/gpu/hsa/radeon/kfd_device_queue_manager.c | 113 +++-----------
 drivers/gpu/hsa/radeon/kfd_kernel_queue.c         |  12 +-
 drivers/gpu/hsa/radeon/kfd_mqd_manager.c          | 175 +---------------------
 drivers/gpu/hsa/radeon/kfd_mqd_manager.h          |  37 +++--
 drivers/gpu/hsa/radeon/kfd_priv.h                 |  18 ---
 drivers/gpu/hsa/radeon/kfd_registers.c            |  50 -------
 8 files changed, 54 insertions(+), 355 deletions(-)
 delete mode 100644 drivers/gpu/hsa/radeon/kfd_registers.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index b5f05b4..d838bce 100644
@@ -4,7 +4,7 @@
 
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
-		kfd_doorbell.o kfd_registers.o kfd_vidmem.o \
+		kfd_doorbell.o kfd_vidmem.o \
 		kfd_interrupt.o kfd_aperture.o kfd_queue.o kfd_mqd_manager.o \
 		kfd_kernel_queue.o kfd_packet_manager.o \
 		kfd_process_queue_manager.o kfd_device_queue_manager.o
drivers/gpu/hsa/radeon/kfd_device.c +0 -2
index 30558c9..0ff2241 100644
@@ -157,8 +157,6 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
 {
 	kfd->shared_resources = *gpu_resources;
 
-	kfd->regs = gpu_resources->mmio_registers;
-
 	radeon_kfd_doorbell_init(kfd);
 
 	if (radeon_kfd_interrupt_init(kfd))
drivers/gpu/hsa/radeon/kfd_device_queue_manager.c +20 -93

186 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_kernel_queue.c +5 -7
index ce3261b..315d48e 100644
@@ -108,10 +108,7 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev,
 		pr_debug("assigning hiq to hqd\n");
 		kq->queue->pipe = KFD_CIK_HIQ_PIPE;
 		kq->queue->queue = KFD_CIK_HIQ_QUEUE;
-
-		kq->mqd->acquire_hqd(kq->mqd, kq->queue->pipe, kq->queue->queue, 0);
-		kq->mqd->load_mqd(kq->mqd, kq->queue->mqd);
-		kq->mqd->release_hqd(kq->mqd);
+		kq->mqd->load_mqd(kq->mqd, kq->queue->mqd, kq->queue->pipe, kq->queue->queue, NULL);
 	} else {
 		/* allocate fence for DIQ */
 		retval = radeon_kfd_vidmem_alloc_map(
@@ -152,9 +149,10 @@ static void uninitialize(struct kernel_queue *kq)
 
 	if (kq->queue->properties.type == KFD_QUEUE_TYPE_HIQ)
 		kq->mqd->destroy_mqd(kq->mqd,
-					kq->queue->mqd,
-					KFD_PREEMPT_TYPE_WAVEFRONT,
-					QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS);
+					false,
+					QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS,
+					kq->queue->pipe,
+					kq->queue->queue);
 
 	radeon_kfd_vidmem_free_unmap(kq->dev, kq->rptr_mem);
 	radeon_kfd_vidmem_free_unmap(kq->dev, kq->wptr_mem);
drivers/gpu/hsa/radeon/kfd_mqd_manager.c +6 -169

215 lines not on this page · raw message

drivers/gpu/hsa/radeon/kfd_mqd_manager.h +22 -15
index 314d490..a6b0007 100644
@@ -27,21 +27,28 @@
 #include "kfd_priv.h"
 
 struct mqd_manager {
-	int	(*init_mqd)(struct mqd_manager *mm, void **mqd, kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
-			    struct queue_properties *q);
-	int	(*load_mqd)(struct mqd_manager *mm, void *mqd);
-	int	(*update_mqd)(struct mqd_manager *mm, void *mqd, struct queue_properties *q);
-	int	(*destroy_mqd)(struct mqd_manager *mm, void *mqd, enum kfd_preempt_type type, unsigned int timeout);
-	void	(*uninit_mqd)(struct mqd_manager *mm, void *mqd, kfd_mem_obj mqd_mem_obj);
-	void	(*acquire_hqd)(struct mqd_manager *mm, unsigned int pipe, unsigned int queue, unsigned int vmid);
-	void	(*release_hqd)(struct mqd_manager *mm);
-	bool	(*is_occupied)(struct mqd_manager *mm, void *mqd, struct queue_properties *q);
-	int	(*initialize)(struct mqd_manager *mm);
-	void	(*uninitialize)(struct mqd_manager *mm);
-
-	struct mutex		mqd_mutex;
-	struct kfd_dev		*dev;
-};
+	int	(*init_mqd)(struct mqd_manager *mm, void **mqd,
+			kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
+			struct queue_properties *q);
+
+	int	(*load_mqd)(struct mqd_manager *mm, void *mqd,
+				uint32_t pipe_id, uint32_t queue_id,
+				uint32_t __user *wptr);
+
+	int	(*update_mqd)(struct mqd_manager *mm, void *mqd,
+				struct queue_properties *q);
 
+	int	(*destroy_mqd)(struct mqd_manager *mm, bool is_reset,
+				unsigned int timeout, uint32_t pipe_id,
+				uint32_t queue_id);
+
+	void	(*uninit_mqd)(struct mqd_manager *mm, void *mqd,
+				kfd_mem_obj mqd_mem_obj);
+	bool	(*is_occupied)(struct mqd_manager *mm, uint64_t queue_address,
+				uint32_t pipe_id, uint32_t queue_id);
+
+	struct mutex	mqd_mutex;
+	struct kfd_dev	*dev;
+};
 
 #endif /* KFD_MQD_MANAGER_H_ */
drivers/gpu/hsa/radeon/kfd_priv.h +0 -18
index b61187a..be77ca8 100644
@@ -100,8 +100,6 @@ struct kfd_dev {
 	const struct kfd_device_info *device_info;
 	struct pci_dev *pdev;
 
-	void __iomem *regs;
-
 	bool init_complete;
 
 	unsigned int id;		/* topology stub index */
@@ -148,11 +146,6 @@ void kgd2kfd_device_exit(struct kfd_dev *kfd);
 
 extern const struct kfd2kgd_calls *kfd2kgd;
 
-
-/* KFD2KGD callback wrappers */
-void radeon_kfd_lock_srbm_index(struct kfd_dev *kfd);
-void radeon_kfd_unlock_srbm_index(struct kfd_dev *kfd);
-
 enum kfd_mempool {
 	KFD_MEMPOOL_SYSTEM_CACHEABLE = 1,
 	KFD_MEMPOOL_SYSTEM_WRITECOMBINE = 2,
@@ -198,11 +191,6 @@ enum kfd_preempt_type_filter {
 	KFD_PRERMPT_TYPE_FILTER_BY_PASID
 };
 
-enum kfd_preempt_type {
-	KFD_PREEMPT_TYPE_WAVEFRONT,
-	KFD_PREEMPT_TYPE_WAVEFRONT_RESET
-};
-
 enum kfd_queue_type  {
 	KFD_QUEUE_TYPE_COMPUTE,
 	KFD_QUEUE_TYPE_SDMA,
@@ -406,12 +394,6 @@ struct kfd_dev *radeon_kfd_device_by_id(uint32_t gpu_id);
 struct kfd_dev *radeon_kfd_device_by_pci_dev(const struct pci_dev *pdev);
 struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx);
 
-/* MMIO registers */
-#define WRITE_REG(dev, reg, value) radeon_kfd_write_reg((dev), (reg), (value))
-#define READ_REG(dev, reg) radeon_kfd_read_reg((dev), (reg))
-void radeon_kfd_write_reg(struct kfd_dev *dev, uint32_t reg, uint32_t value);
-uint32_t radeon_kfd_read_reg(struct kfd_dev *dev, uint32_t reg);
-
 /* Interrupts */
 int radeon_kfd_interrupt_init(struct kfd_dev *dev);
 void radeon_kfd_interrupt_exit(struct kfd_dev *dev);
drivers/gpu/hsa/radeon/kfd_registers.c deleted +0 -50

50 lines not on this page · raw message

Signature · 1 line
1.9.1
#56 lore raw

PATCH 82/83 drm/radeon: Remove lock functions from kfd2kgd interface

In reply to Oded Gabbay

From: Ben Goz <[email protected]>

---
 drivers/gpu/drm/radeon/radeon_kfd.c | 44 -------------------------------------
 include/linux/radeon_kfd.h          | 10 ---------
 2 files changed, 54 deletions(-)
drivers/gpu/drm/radeon/radeon_kfd.c +0 -44
index 738c2b3..7e8e041 100644
@@ -115,12 +115,6 @@ static void unkmap_mem(struct kgd_dev *kgd, struct kgd_mem *mem);
 static uint64_t get_vmem_size(struct kgd_dev *kgd);
 static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd);
 
-static void lock_srbm_gfx_cntl(struct kgd_dev *kgd);
-static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd);
-
-static void lock_grbm_gfx_idx(struct kgd_dev *kgd);
-static void unlock_grbm_gfx_idx(struct kgd_dev *kgd);
-
 static uint32_t get_max_engine_clock_in_mhz(struct kgd_dev *kgd);
 
 /*
@@ -146,10 +140,6 @@ static const struct kfd2kgd_calls kfd2kgd = {
 	.unkmap_mem = unkmap_mem,
 	.get_vmem_size = get_vmem_size,
 	.get_gpu_clock_counter = get_gpu_clock_counter,
-	.lock_srbm_gfx_cntl = lock_srbm_gfx_cntl,
-	.unlock_srbm_gfx_cntl = unlock_srbm_gfx_cntl,
-	.lock_grbm_gfx_idx = lock_grbm_gfx_idx,
-	.unlock_grbm_gfx_idx = unlock_grbm_gfx_idx,
 	.get_max_engine_clock_in_mhz = get_max_engine_clock_in_mhz,
 	.program_sh_mem_settings = kgd_program_sh_mem_settings,
 	.set_pasid_vmid_mapping = kgd_set_pasid_vmid_mapping,
@@ -200,8 +190,6 @@ void radeon_kfd_device_init(struct radeon_device *rdev)
 {
 	if (rdev->kfd) {
 		struct kgd2kfd_shared_resources gpu_resources = {
-			.mmio_registers = rdev->rmmio,
-
 			.compute_vmid_bitmap = 0xFF00,
 
 			.first_compute_pipe = 1,
@@ -363,38 +351,6 @@ static uint64_t get_vmem_size(struct kgd_dev *kgd)
 	return rdev->mc.real_vram_size;
 }
 
-static void lock_srbm_gfx_cntl(struct kgd_dev *kgd)
-{
-	struct radeon_device *rdev = (struct radeon_device *)kgd;
-
-	mutex_lock(&rdev->srbm_mutex);
-}
-
-static void unlock_srbm_gfx_cntl(struct kgd_dev *kgd)
-{
-	struct radeon_device *rdev = (struct radeon_device *)kgd;
-
-	mutex_unlock(&rdev->srbm_mutex);
-}
-
-static void lock_grbm_gfx_idx(struct kgd_dev *kgd)
-{
-	struct radeon_device *rdev = (struct radeon_device *)kgd;
-
-	BUG_ON(kgd == NULL);
-
-	mutex_lock(&rdev->grbm_idx_mutex);
-}
-
-static void unlock_grbm_gfx_idx(struct kgd_dev *kgd)
-{
-	struct radeon_device *rdev = (struct radeon_device *)kgd;
-
-	BUG_ON(kgd == NULL);
-
-	mutex_unlock(&rdev->grbm_idx_mutex);
-}
-
 static uint64_t get_gpu_clock_counter(struct kgd_dev *kgd)
 {
 	struct radeon_device *rdev = (struct radeon_device *)kgd;
include/linux/radeon_kfd.h +0 -10
index aa021fb..2fffe32 100644
@@ -45,8 +45,6 @@ enum kgd_memory_pool {
 };
 
 struct kgd2kfd_shared_resources {
-	void __iomem *mmio_registers; /* Mapped pointer to GFX MMIO registers. */
-
 	unsigned int compute_vmid_bitmap; /* Bit n == 1 means VMID n is available for KFD. */
 
 	unsigned int first_compute_pipe; /* Compute pipes are counted starting from MEC0/pipe0 as 0. */
@@ -86,14 +84,6 @@ struct kfd2kgd_calls {
 	uint64_t (*get_vmem_size)(struct kgd_dev *kgd);
 	uint64_t (*get_gpu_clock_counter)(struct kgd_dev *kgd);
 
-	/* SRBM_GFX_CNTL mutex */
-	void (*lock_srbm_gfx_cntl)(struct kgd_dev *kgd);
-	void (*unlock_srbm_gfx_cntl)(struct kgd_dev *kgd);
-
-	/* GRBM_GFX_INDEX mutex */
-	void (*lock_grbm_gfx_idx)(struct kgd_dev *kgd);
-	void (*unlock_grbm_gfx_idx)(struct kgd_dev *kgd);
-
 	uint32_t (*get_max_engine_clock_in_mhz)(struct kgd_dev *kgd);
 
 	/* Register access functions */
Signature · 1 line
1.9.1
#57 lore raw

PATCH 83/83 hsa/radeon: Update module version to 0.6.2

In reply to Oded Gabbay

This version is intended for upstreaming to the Linux kernel 3.17

---
 drivers/gpu/hsa/radeon/kfd_module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/hsa/radeon/kfd_module.c +2 -2
index c706236..c783eeb 100644
@@ -30,10 +30,10 @@
 #define KFD_DRIVER_AUTHOR	"AMD Inc. and others"
 
 #define KFD_DRIVER_DESC		"Standalone HSA driver for AMD's GPUs"
-#define KFD_DRIVER_DATE		"20140623"
+#define KFD_DRIVER_DATE		"20140710"
 #define KFD_DRIVER_MAJOR	0
 #define KFD_DRIVER_MINOR	6
-#define KFD_DRIVER_PATCHLEVEL	1
+#define KFD_DRIVER_PATCHLEVEL	2
 
 const struct kfd2kgd_calls *kfd2kgd;
 static const struct kgd2kfd_calls kgd2kfd = {
Signature · 1 line
1.9.1
#11 lore raw

Re: [PATCH 38/83] hsa/radeon: Workaround for a bug in amd_iommu

In reply to Oded Gabbay
Quoted 6 lines · Oded Gabbay

This patch creates a workaround for a bug in amd_iommu driver, where the driver doesn't save all necessary information when going to suspend. The workaround removes a device from the IOMMU device list on suspend and register a resumed device in the IOMMU device list.

Which bug do you workaround here? It needs to be fixed in the AMD IOMMU driver instead of being wrapped in KFD.

Joerg

#4 lore raw

Re: [PATCH 32/83] hsa/radeon: implementing IOCTL for clock counters

In reply to Oded Gabbay
Quoted 37 lines · Oded Gabbay

From: Evgeny Pinchuk <[email protected]>

Implemented new IOCTL to query the CPU and GPU clock counters.

---
 drivers/gpu/hsa/radeon/kfd_chardev.c | 37 ++++++++++++++++++++++++++++++++++++
 include/uapi/linux/kfd_ioctl.h       |  9 +++++++++
 2 files changed, 46 insertions(+)
drivers/gpu/hsa/radeon/kfd_chardev.c +11 -0
index ddaf357..d6fa980 100644
@@ -28,6 +28,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <uapi/linux/kfd_ioctl.h>
+#include <linux/time.h>
 #include "kfd_priv.h"
 #include "kfd_scheduler.h"
 
@@ -284,6 +285,38 @@ out:
 	return err;
 }
 
+static long
+kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_process *p, void __user *arg)
+{
+	struct kfd_ioctl_get_clock_counters_args args;
+	struct kfd_dev *dev;
+	struct timespec time;
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+

drivers/gpu/hsa/radeon/kfd_chardev.c out: · line 307

Quoted 10 lines
drivers/gpu/hsa/radeon/kfd_chardev.c +10 -0
+	dev = radeon_kfd_device_by_id(args.gpu_id);
+	if (dev == NULL)
+		return -EINVAL;
+
+	/* Reading GPU clock counter from KGD */
+	args.gpu_clock_counter = kfd2kgd->get_gpu_clock_counter(dev->kgd);
+
+	/* No access to rdtsc. Using raw monotonic time */
+	getrawmonotonic(&time);
+	args.cpu_clock_counter = time.tv_nsec;

Is the GPU clock counter monotonic too ? Even after GPU reset (hard reset included) what could go wrong if it rolls back ?

Quoted 55 lines
drivers/gpu/hsa/radeon/kfd_chardev.c +16 -0
+
+	get_monotonic_boottime(&time);
+	args.system_clock_counter = time.tv_nsec;
+
+	/* Since the counter is in nano-seconds we use 1GHz frequency */
+	args.system_clock_freq = 1000000000;
+
+	if (copy_to_user(arg, &args, sizeof(args)))
+		return -EFAULT;
+
+	return 0;
+}
 
 static long
 kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
@@ -312,6 +345,10 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		err = kfd_ioctl_set_memory_policy(filep, process, (void __user *)arg);
 		break;
 
+	case KFD_IOC_GET_CLOCK_COUNTERS:
+		err = kfd_ioctl_get_clock_counters(filep, process, (void __user *)arg);
+		break;
+
 	default:
 		dev_err(kfd_device,
 			"unknown ioctl cmd 0x%x, arg 0x%lx)\n",
include/uapi/linux/kfd_ioctl.h +9 -0
index 928e628..5b9517e 100644
@@ -70,12 +70,21 @@ struct kfd_ioctl_set_memory_policy_args {
 	uint64_t alternate_aperture_size;	/* to KFD */
 };
 
+struct kfd_ioctl_get_clock_counters_args {
+	uint32_t gpu_id;		/* to KFD */
+	uint64_t gpu_clock_counter;	/* from KFD */
+	uint64_t cpu_clock_counter;	/* from KFD */
+	uint64_t system_clock_counter;	/* from KFD */
+	uint64_t system_clock_freq;	/* from KFD */
+};
+
 #define KFD_IOC_MAGIC 'K'
 
 #define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
 #define KFD_IOC_CREATE_QUEUE	_IOWR(KFD_IOC_MAGIC, 2, struct kfd_ioctl_create_queue_args)
 #define KFD_IOC_DESTROY_QUEUE	_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
+#define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1
#18 lore raw

Re: [PATCH 44/83] hsa/radeon: HSA64/HSA32 modes support

In reply to Oded Gabbay
Quoted 3 lines · Oded Gabbay

From: Alexey Skidanov <[email protected]>

Added apertures initialization and appropriate ioctl

What is process aperture and what it is use for ? This is a very cryptic commit message.

Cheers,
Jérôme

Quoted 410 lines
---
 drivers/gpu/hsa/radeon/Makefile               |   2 +-
 drivers/gpu/hsa/radeon/kfd_aperture.c         | 124 ++++++++++++++++++++++++++
 drivers/gpu/hsa/radeon/kfd_chardev.c          |  58 +++++++++++-
 drivers/gpu/hsa/radeon/kfd_priv.h             |  18 ++++
 drivers/gpu/hsa/radeon/kfd_process.c          |  17 ++++
 drivers/gpu/hsa/radeon/kfd_sched_cik_static.c |   3 +-
 drivers/gpu/hsa/radeon/kfd_topology.c         |  27 ++++++
 include/uapi/linux/kfd_ioctl.h                |  18 ++++
 8 files changed, 264 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/hsa/radeon/kfd_aperture.c
drivers/gpu/hsa/radeon/Makefile +1 -1
index 5422e6a..813b31f 100644
@@ -5,6 +5,6 @@
 radeon_kfd-y	:= kfd_module.o kfd_device.o kfd_chardev.o \
 		kfd_pasid.o kfd_topology.o kfd_process.o \
 		kfd_doorbell.o kfd_sched_cik_static.o kfd_registers.o \
-		kfd_vidmem.o kfd_interrupt.o
+		kfd_vidmem.o kfd_interrupt.o kfd_aperture.o
 
 obj-$(CONFIG_HSA_RADEON)	+= radeon_kfd.o
drivers/gpu/hsa/radeon/kfd_aperture.c new file +124 -0
new file mode 100644
index 0000000..9e2d6da
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/export.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/compat.h>
+#include <uapi/linux/kfd_ioctl.h>
+#include <linux/time.h>
+#include "kfd_priv.h"
+#include "kfd_scheduler.h"
+#include <linux/mm.h>
+#include <uapi/asm-generic/mman-common.h>
+#include <asm/processor.h>
+
+
+#define MAKE_GPUVM_APP_BASE(gpu_num) (((uint64_t)(gpu_num) << 61) + 0x1000000000000)
+#define MAKE_GPUVM_APP_LIMIT(base) (((uint64_t)(base) & 0xFFFFFF0000000000) | 0xFFFFFFFFFF)
+#define MAKE_SCRATCH_APP_BASE(gpu_num) (((uint64_t)(gpu_num) << 61) + 0x100000000)
+#define MAKE_SCRATCH_APP_LIMIT(base) (((uint64_t)base & 0xFFFFFFFF00000000) | 0xFFFFFFFF)
+#define MAKE_LDS_APP_BASE(gpu_num) (((uint64_t)(gpu_num) << 61) + 0x0)
+#define MAKE_LDS_APP_LIMIT(base) (((uint64_t)(base) & 0xFFFFFFFF00000000) | 0xFFFFFFFF)
+
+#define HSA_32BIT_LDS_APP_SIZE 0x10000
+#define HSA_32BIT_LDS_APP_ALIGNMENT 0x10000
+
+static unsigned long kfd_reserve_aperture(struct kfd_process *process, unsigned long len, unsigned long alignment)
+{
+
+	unsigned long addr = 0;
+	unsigned long start_address;
+
+	/*
+	 * Go bottom up and find the first available aligned address.
+	 * We may narrow space to scan by getting mmap range limits.
+	 */
+	for (start_address =  alignment; start_address < (TASK_SIZE - alignment); start_address += alignment) {
+		addr = vm_mmap(NULL, start_address, len, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0);
+		if (!IS_ERR_VALUE(addr)) {
+			if (addr == start_address)
+				return addr;
+			vm_munmap(addr, len);
+		}
+	}
+	return 0;
+
+}
+
+int kfd_init_apertures(struct kfd_process *process)
+{
+	uint8_t id  = 0;
+	struct kfd_dev *dev;
+	struct kfd_process_device *pdd;
+
+	mutex_lock(&process->mutex);
+
+	/*Iterating over all devices*/
+	while ((dev = kfd_topology_enum_kfd_devices(id)) != NULL && id < NUM_OF_SUPPORTED_GPUS) {
+
+		pdd = radeon_kfd_get_process_device_data(dev, process);
+
+		/*for 64 bit process aperture will be statically reserved in the non canonical process address space
+		 *for 32 bit process the aperture will be reserved in the process address space
+		 */
+		if (process->is_32bit_user_mode) {
+			/*try to reserve aperture. continue on failure, just put the aperture size to be 0*/
+			pdd->lds_base = kfd_reserve_aperture(
+						process,
+						HSA_32BIT_LDS_APP_SIZE,
+						HSA_32BIT_LDS_APP_ALIGNMENT);
+
+			if (pdd->lds_base)
+				pdd->lds_limit = pdd->lds_base + HSA_32BIT_LDS_APP_SIZE - 1;
+			else
+				pdd->lds_limit = 0;
+
+			/*GPUVM and Scratch apertures are not supported*/
+			pdd->gpuvm_base = pdd->gpuvm_limit = pdd->scratch_base = pdd->scratch_limit = 0;
+		} else {
+			/*node id couldn't be 0 - the three MSB bits of aperture shoudn't be 0*/
+			pdd->lds_base = MAKE_LDS_APP_BASE(id + 1);
+			pdd->lds_limit = MAKE_LDS_APP_LIMIT(pdd->lds_base);
+			pdd->gpuvm_base = MAKE_GPUVM_APP_BASE(id + 1);
+			pdd->gpuvm_limit = MAKE_GPUVM_APP_LIMIT(pdd->gpuvm_base);
+			pdd->scratch_base = MAKE_SCRATCH_APP_BASE(id + 1);
+			pdd->scratch_limit = MAKE_SCRATCH_APP_LIMIT(pdd->scratch_base);
+		}
+
+		dev_dbg(kfd_device, "node id %u, gpu id %u, lds_base %llX lds_limit %llX gpuvm_base %llX gpuvm_limit %llX scratch_base %llX scratch_limit %llX",
+				id, pdd->dev->id, pdd->lds_base, pdd->lds_limit, pdd->gpuvm_base, pdd->gpuvm_limit, pdd->scratch_base, pdd->scratch_limit);
+
+		id++;
+	}
+
+	mutex_unlock(&process->mutex);
+
+	return 0;
+}
+
+
drivers/gpu/hsa/radeon/kfd_chardev.c +57 -1
index e95d597..07cac88 100644
@@ -32,6 +32,9 @@
 #include <linux/time.h>
 #include "kfd_priv.h"
 #include "kfd_scheduler.h"
+#include <linux/mm.h>
+#include <uapi/asm-generic/mman-common.h>
+#include <asm/processor.h>
 
 static long kfd_ioctl(struct file *, unsigned int, unsigned long);
 static int kfd_open(struct inode *, struct file *);
@@ -107,9 +110,13 @@ kfd_open(struct inode *inode, struct file *filep)
 	process = radeon_kfd_create_process(current);
 	if (IS_ERR(process))
 		return PTR_ERR(process);
+
 	process->is_32bit_user_mode = is_compat_task();
+
 	dev_info(kfd_device, "process %d opened, compat mode (32 bit) - %d\n",
-				process->pasid, process->is_32bit_user_mode);
+			process->pasid, process->is_32bit_user_mode);
+
+	kfd_init_apertures(process);
 
 	return 0;
 }
@@ -321,6 +328,51 @@ kfd_ioctl_get_clock_counters(struct file *filep, struct kfd_process *p, void __u
 	return 0;
 }
 
+
+static int kfd_ioctl_get_process_apertures(struct file *filp, struct kfd_process *p, void __user *arg)
+{
+	struct kfd_ioctl_get_process_apertures_args args;
+	struct kfd_process_device *pdd;
+
+	dev_dbg(kfd_device, "get apertures for PASID %d", p->pasid);
+
+	if (copy_from_user(&args, arg, sizeof(args)))
+		return -EFAULT;
+
+	args.num_of_nodes = 0;
+
+	mutex_lock(&p->mutex);
+
+	/*if the process-device list isn't empty*/
+	if (kfd_has_process_device_data(p)) {
+		/* Run over all pdd of the process */
+		pdd = kfd_get_first_process_device_data(p);
+		do {
+
+			args.process_apertures[args.num_of_nodes].gpu_id = pdd->dev->id;
+			args.process_apertures[args.num_of_nodes].lds_base = pdd->lds_base;
+			args.process_apertures[args.num_of_nodes].lds_limit = pdd->lds_limit;
+			args.process_apertures[args.num_of_nodes].gpuvm_base = pdd->gpuvm_base;
+			args.process_apertures[args.num_of_nodes].gpuvm_limit = pdd->gpuvm_limit;
+			args.process_apertures[args.num_of_nodes].scratch_base = pdd->scratch_base;
+			args.process_apertures[args.num_of_nodes].scratch_limit = pdd->scratch_limit;
+
+			dev_dbg(kfd_device, "node id %u, gpu id %u, lds_base %llX lds_limit %llX gpuvm_base %llX gpuvm_limit %llX scratch_base %llX scratch_limit %llX",
+					args.num_of_nodes, pdd->dev->id, pdd->lds_base, pdd->lds_limit, pdd->gpuvm_base, pdd->gpuvm_limit, pdd->scratch_base, pdd->scratch_limit);
+			args.num_of_nodes++;
+		} while ((pdd = kfd_get_next_process_device_data(p, pdd)) != NULL &&
+				(args.num_of_nodes < NUM_OF_SUPPORTED_GPUS));
+	}
+
+	mutex_unlock(&p->mutex);
+
+	if (copy_to_user(arg, &args, sizeof(args)))
+		return -EFAULT;
+
+	return 0;
+}
+
+
 static long
 kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 {
@@ -352,6 +404,10 @@ kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
 		err = kfd_ioctl_get_clock_counters(filep, process, (void __user *)arg);
 		break;
 
+	case KFD_IOC_GET_PROCESS_APERTURES:
+		err = kfd_ioctl_get_process_apertures(filep, process, (void __user *)arg);
+		break;
+
 	default:
 		dev_err(kfd_device,
 			"unknown ioctl cmd 0x%x, arg 0x%lx)\n",
drivers/gpu/hsa/radeon/kfd_priv.h +18 -0
index 9d3b1fc..28155bc 100644
@@ -171,6 +171,16 @@ struct kfd_process_device {
 
 	/* Is this process/pasid bound to this device? (amd_iommu_bind_pasid) */
 	bool bound;
+
+	/*Apertures*/
+	uint64_t lds_base;
+	uint64_t lds_limit;
+	uint64_t gpuvm_base;
+	uint64_t gpuvm_limit;
+	uint64_t scratch_base;
+	uint64_t scratch_limit;
+
+
 };
 
 /* Process data */
@@ -212,6 +222,10 @@ void radeon_kfd_install_queue(struct kfd_process *p, unsigned int queue_id, stru
 void radeon_kfd_remove_queue(struct kfd_process *p, unsigned int queue_id);
 struct kfd_queue *radeon_kfd_get_queue(struct kfd_process *p, unsigned int queue_id);
 
+/* Process device data iterator */
+struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p);
+struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p, struct kfd_process_device *pdd);
+bool kfd_has_process_device_data(struct kfd_process *p);
 
 /* PASIDs */
 int radeon_kfd_pasid_init(void);
@@ -237,6 +251,7 @@ int kfd_topology_add_device(struct kfd_dev *gpu);
 int kfd_topology_remove_device(struct kfd_dev *gpu);
 struct kfd_dev *radeon_kfd_device_by_id(uint32_t gpu_id);
 struct kfd_dev *radeon_kfd_device_by_pci_dev(const struct pci_dev *pdev);
+struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx);
 
 /* MMIO registers */
 #define WRITE_REG(dev, reg, value) radeon_kfd_write_reg((dev), (reg), (value))
@@ -253,4 +268,7 @@ void kgd2kfd_interrupt(struct kfd_dev *dev, const void *ih_ring_entry);
 void kgd2kfd_suspend(struct kfd_dev *dev);
 int kgd2kfd_resume(struct kfd_dev *dev);
 
+/*HSA apertures*/
+int kfd_init_apertures(struct kfd_process *process);
+
 #endif
drivers/gpu/hsa/radeon/kfd_process.c +17 -0
index f89f855..80136e6 100644
@@ -397,3 +397,20 @@ struct kfd_queue *radeon_kfd_get_queue(struct kfd_process *p, unsigned int queue
 		test_bit(queue_id, p->allocated_queue_bitmap)) ?
 			p->queues[queue_id] : NULL;
 }
+
+struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p)
+{
+	return list_first_entry(&p->per_device_data, struct kfd_process_device, per_device_list);
+}
+
+struct kfd_process_device *kfd_get_next_process_device_data(struct kfd_process *p, struct kfd_process_device *pdd)
+{
+	if (list_is_last(&pdd->per_device_list, &p->per_device_data))
+		return NULL;
+	return list_next_entry(pdd, per_device_list);
+}
+
+bool kfd_has_process_device_data(struct kfd_process *p)
+{
+	return !(list_empty(&p->per_device_data));
+}
drivers/gpu/hsa/radeon/kfd_sched_cik_static.c +2 -1
index 7ee8125..30561a6 100644
@@ -627,7 +627,8 @@ static void cik_static_deregister_process(struct kfd_scheduler *scheduler,
 	struct cik_static_private *priv = kfd_scheduler_to_private(scheduler);
 	struct cik_static_process *pp = kfd_process_to_private(scheduler_process);
 
-	if (priv && pp) {
+
+	if (priv && pp)	{
 		release_vmid(priv, pp->vmid);
 		kfree(pp);
 	}
drivers/gpu/hsa/radeon/kfd_topology.c +27 -0
index 21bb66e..213ae7b 100644
@@ -1201,3 +1201,30 @@ int kfd_topology_remove_device(struct kfd_dev *gpu)
 
 	return res;
 }
+
+/*
+ * When idx is out of bounds, the function will return NULL
+ */
+struct kfd_dev *kfd_topology_enum_kfd_devices(uint8_t idx)
+{
+
+	struct kfd_topology_device *top_dev;
+	struct kfd_dev *device = NULL;
+	uint8_t device_idx = 0;
+
+	down_read(&topology_lock);
+
+	list_for_each_entry(top_dev, &topology_device_list, list) {
+		if (device_idx == idx) {
+			device = top_dev->gpu;
+			break;
+		}
+
+		device_idx++;
+	}
+
+	up_read(&topology_lock);
+
+	return device;
+
+}
include/uapi/linux/kfd_ioctl.h +18 -0
index a7c3abd..e5fcb8b 100644
@@ -78,6 +78,23 @@ struct kfd_ioctl_get_clock_counters_args {
 	uint64_t system_clock_freq;	/* from KFD */
 };
 
+#define NUM_OF_SUPPORTED_GPUS 7
+
+struct kfd_process_device_apertures {
+	uint64_t lds_base;/* from KFD */
+	uint64_t lds_limit;/* from KFD */
+	uint64_t scratch_base;/* from KFD */
+	uint64_t scratch_limit;/* from KFD */
+	uint64_t gpuvm_base;/* from KFD */
+	uint64_t gpuvm_limit;/* from KFD */
+	uint32_t gpu_id;/* from KFD */
+};
+
+struct kfd_ioctl_get_process_apertures_args {
+	struct kfd_process_device_apertures process_apertures[NUM_OF_SUPPORTED_GPUS];/* from KFD */
+	uint8_t num_of_nodes; /* from KFD, should be in the range [1 - NUM_OF_SUPPORTED_GPUS]*/
+};
+
 #define KFD_IOC_MAGIC 'K'
 
 #define KFD_IOC_GET_VERSION	_IOR(KFD_IOC_MAGIC, 1, struct kfd_ioctl_get_version_args)
@@ -85,6 +102,7 @@ struct kfd_ioctl_get_clock_counters_args {
 #define KFD_IOC_DESTROY_QUEUE	_IOWR(KFD_IOC_MAGIC, 3, struct kfd_ioctl_destroy_queue_args)
 #define KFD_IOC_SET_MEMORY_POLICY	_IOW(KFD_IOC_MAGIC, 4, struct kfd_ioctl_set_memory_policy_args)
 #define KFD_IOC_GET_CLOCK_COUNTERS	_IOWR(KFD_IOC_MAGIC, 5, struct kfd_ioctl_get_clock_counters_args)
+#define KFD_IOC_GET_PROCESS_APERTURES _IOR(KFD_IOC_MAGIC, 6, struct kfd_ioctl_get_process_apertures_args)
 
 #pragma pack(pop)
 
Signature · 1 line
1.9.1