[PATCH 4/5] drm/amdkfd: Set priv_queue to NULL after it is freed

2021-07-16 Thread Oak Zeng
This variable will be used to determine whether packet
manager is initialized or not, in a future patch.

Signed-off-by: Oak Zeng 
Acked-by: Christian Konig 
Reviewed-by: Felix Kuehling 
---
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index d8e940f..b130cc0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -278,6 +278,7 @@ void pm_uninit(struct packet_manager *pm, bool hanging)
 {
mutex_destroy(&pm->lock);
kernel_queue_uninit(pm->priv_queue, hanging);
+   pm->priv_queue = NULL;
 }
 
 int pm_send_set_resources(struct packet_manager *pm,
-- 
2.7.4

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


[PATCH 0/5] MISC fixes

2021-07-16 Thread Oak Zeng
Oak Zeng (5):
  drm/amdgpu: Fix a printing message
  drm/amdgpu: Change a few function names
  drm/amdkfd: Renaming dqm->packets to dqm->packet_mgr
  drm/amdkfd: Set priv_queue to NULL after it is freed
  drm/amdkfd: Fix a concurrency issue during kfd recovery

 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c| 16 -
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  8 +
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 38 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c|  4 +++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 11 files changed, 42 insertions(+), 38 deletions(-)

-- 
2.7.4

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


[PATCH 1/5] drm/amdgpu: Fix a printing message

2021-07-16 Thread Oak Zeng
The printing message "PSP loading VCN firmware" is mis-leading because
people might think driver is loading VCN firmware. Actually when this
message is printed, driver is just preparing some VCN ucode, not loading
VCN firmware yet. The actual VCN firmware loading will be in the PSP block
hw_init. Fix the printing message

Signed-off-by: Oak Zeng 
Reviewed-by: Christian Konig 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index 284bb42..121ee9f 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
@@ -119,7 +119,7 @@ static int vcn_v1_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
index 8af567c..f4686e9 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
@@ -122,7 +122,7 @@ static int vcn_v2_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index 888b17d..e0c0c37 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
@@ -152,7 +152,7 @@ static int vcn_v2_5_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index c3580de..a1bbe33 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -158,7 +158,7 @@ static int vcn_v3_0_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
-- 
2.7.4

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


[PATCH 2/5] drm/amdgpu: Change a few function names

2021-07-16 Thread Oak Zeng
Function name "psp_np_fw_load" is not proper as people don't
know _np_fw_ means "non psp firmware". Change the function
name to psp_load_non_psp_fw for better understanding. Same
thing for function psp_execute_np_fw_load.

Signed-off-by: Oak Zeng 
Reviewed-by: Alex Deucher 
Reviewed-by: Christian Konig 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d9ddb2c..8d1e2b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2351,7 +2351,7 @@ static int psp_prep_load_ip_fw_cmd_buf(struct 
amdgpu_firmware_info *ucode,
return ret;
 }
 
-static int psp_execute_np_fw_load(struct psp_context *psp,
+static int psp_execute_non_psp_fw_load(struct psp_context *psp,
  struct amdgpu_firmware_info *ucode)
 {
int ret = 0;
@@ -2387,7 +2387,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
}
}
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
 
if (ret)
DRM_ERROR("PSP load smu failed!\n");
@@ -2442,14 +2442,14 @@ int psp_load_fw_list(struct psp_context *psp,
for (i = 0; i < ucode_count; ++i) {
ucode = ucode_list[i];
psp_print_fw_hdr(psp, ucode);
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
}
return ret;
 }
 
-static int psp_np_fw_load(struct psp_context *psp)
+static int psp_load_non_psp_fw(struct psp_context *psp)
 {
int i, ret;
struct amdgpu_firmware_info *ucode;
@@ -2488,7 +2488,7 @@ static int psp_np_fw_load(struct psp_context *psp)
 
psp_print_fw_hdr(psp, ucode);
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
 
@@ -2565,7 +2565,7 @@ static int psp_load_fw(struct amdgpu_device *adev)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2765,7 +2765,7 @@ static int psp_resume(void *handle)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2863,7 +2863,7 @@ int psp_update_vcn_sram(struct amdgpu_device *adev, int 
inst_idx,
ucode.mc_addr = cmd_gpu_addr;
ucode.ucode_size = cmd_size;
 
-   return psp_execute_np_fw_load(&adev->psp, &ucode);
+   return psp_execute_non_psp_fw_load(&adev->psp, &ucode);
 }
 
 int psp_ring_cmd_submit(struct psp_context *psp,
-- 
2.7.4

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


[PATCH 5/5] drm/amdkfd: Fix a concurrency issue during kfd recovery

2021-07-16 Thread Oak Zeng
start_cpsch and stop_cpsch can be called during kfd device
initialization or during gpu reset/recovery. So they can
run concurrently. Currently in start_cpsch and stop_cpsch,
pm_init and pm_uninit is not protected by the dpm lock.
Imagine such a case that user use packet manager's function
to submit a pm4 packet to hang hws (ie through command
cat /sys/class/kfd/kfd/topology/nodes/1/gpu_id | sudo tee
/sys/kernel/debug/kfd/hang_hws), while kfd device is under
device reset/recovery so packet manager can be not initialized.
There will be unpredictable protection fault in such case.

This patch moves pm_init/uninit inside the dpm lock and check
packet manager is initialized before using packet manager
function.

Signed-off-by: Oak Zeng 
Acked-by: Christian Konig 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c   |  8 +---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 12 +---
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c   |  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h |  2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 03875d2..56b5010 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1383,18 +1383,12 @@ void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, 
uint32_t throttle_bitmask)
  */
 int kfd_debugfs_hang_hws(struct kfd_dev *dev)
 {
-   int r = 0;
-
if (dev->dqm->sched_policy != KFD_SCHED_POLICY_HWS) {
pr_err("HWS is not enabled");
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->packet_mgr);
-   if (!r)
-   r = dqm_debugfs_execute_queues(dev->dqm);
-
-   return r;
+   return dqm_debugfs_hang_hws(dev->dqm);
 }
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 6b2f594..6b89ca6 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1164,6 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
+   dqm_lock(dqm);
retval = pm_init(&dqm->packet_mgr, dqm);
if (retval)
goto fail_packet_manager_init;
@@ -1186,7 +1187,6 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
init_interrupts(dqm);
 
-   dqm_lock(dqm);
/* clear hang status when driver try to start the hw scheduler */
dqm->is_hws_hang = false;
dqm->is_resetting = false;
@@ -1199,6 +1199,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 fail_set_sched_resources:
pm_uninit(&dqm->packet_mgr, false);
 fail_packet_manager_init:
+   dqm_unlock(dqm);
return retval;
 }
 
@@ -1211,12 +1212,12 @@ static int stop_cpsch(struct device_queue_manager *dqm)
unmap_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
hanging = dqm->is_hws_hang || dqm->is_resetting;
dqm->sched_running = false;
-   dqm_unlock(dqm);
 
pm_release_ib(&dqm->packet_mgr);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
pm_uninit(&dqm->packet_mgr, hanging);
+   dqm_unlock(dqm);
 
return 0;
 }
@@ -2099,11 +2100,16 @@ int dqm_debugfs_hqds(struct seq_file *m, void *data)
return r;
 }
 
-int dqm_debugfs_execute_queues(struct device_queue_manager *dqm)
+int dqm_debugfs_hang_hws(struct device_queue_manager *dqm)
 {
int r = 0;
 
dqm_lock(dqm);
+   r = pm_debugfs_hang_hws(&dqm->packet_mgr);
+   if (r) {
+   dqm_unlock(dqm);
+   return r;
+   }
dqm->active_runlist = true;
r = execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
dqm_unlock(dqm);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index b130cc0..b33ebe8 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -448,6 +448,9 @@ int pm_debugfs_hang_hws(struct packet_manager *pm)
uint32_t *buffer, size;
int r = 0;
 
+   if (!pm->priv_queue)
+   return -EAGAIN;
+
size = pm->pmf->query_status_size;
mutex_lock(&pm->lock);
kq_acquire_packet_buffer(pm->priv_queue,
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
index 3426743..8a5dfda 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -1194,7 +1194,7 @@ int pm_debugfs_runlist(struct seq_file *m, void *data);
 
 int kfd_debugfs_hang_hws(struct kfd_dev *dev);
 int pm_debugfs_hang_hws(struct packet_manager *pm);
-int dqm_debugfs_execute_queues(s

[PATCH 3/5] drm/amdkfd: Renaming dqm->packets to dqm->packet_mgr

2021-07-16 Thread Oak Zeng
Renaming packets to packet_mgr to reflect the real meaning
of this variable.

Signed-off-by: Oak Zeng 
Acked-by: Christian Konig 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  2 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 26 +++---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 9e4a05e..03875d2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1390,7 +1390,7 @@ int kfd_debugfs_hang_hws(struct kfd_dev *dev)
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->packets);
+   r = pm_debugfs_hang_hws(&dev->dqm->packet_mgr);
if (!r)
r = dqm_debugfs_execute_queues(dev->dqm);
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 16a1713..6b2f594 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -260,7 +260,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
 static int flush_texture_cache_nocpsch(struct kfd_dev *kdev,
struct qcm_process_device *qpd)
 {
-   const struct packet_manager_funcs *pmf = qpd->dqm->packets.pmf;
+   const struct packet_manager_funcs *pmf = qpd->dqm->packet_mgr.pmf;
int ret;
 
if (!qpd->ib_kaddr)
@@ -1000,7 +1000,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
init_interrupts(dqm);

if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   return pm_init(&dqm->packets, dqm);
+   return pm_init(&dqm->packet_mgr, dqm);
dqm->sched_running = true;
 
return 0;
@@ -1009,7 +1009,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
 static int stop_nocpsch(struct device_queue_manager *dqm)
 {
if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->packet_mgr, false);
dqm->sched_running = false;
 
return 0;
@@ -1124,7 +1124,7 @@ static int set_sched_resources(struct 
device_queue_manager *dqm)
"queue mask: 0x%8llX\n",
res.vmid_mask, res.queue_mask);
 
-   return pm_send_set_resources(&dqm->packets, &res);
+   return pm_send_set_resources(&dqm->packet_mgr, &res);
 }
 
 static int initialize_cpsch(struct device_queue_manager *dqm)
@@ -1164,7 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
-   retval = pm_init(&dqm->packets, dqm);
+   retval = pm_init(&dqm->packet_mgr, dqm);
if (retval)
goto fail_packet_manager_init;
 
@@ -1197,7 +1197,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
return 0;
 fail_allocate_vidmem:
 fail_set_sched_resources:
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->packet_mgr, false);
 fail_packet_manager_init:
return retval;
 }
@@ -1213,10 +1213,10 @@ static int stop_cpsch(struct device_queue_manager *dqm)
dqm->sched_running = false;
dqm_unlock(dqm);
 
-   pm_release_ib(&dqm->packets);
+   pm_release_ib(&dqm->packet_mgr);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
-   pm_uninit(&dqm->packets, hanging);
+   pm_uninit(&dqm->packet_mgr, hanging);
 
return 0;
 }
@@ -1390,7 +1390,7 @@ static int map_queues_cpsch(struct device_queue_manager 
*dqm)
if (dqm->active_runlist)
return 0;
 
-   retval = pm_send_runlist(&dqm->packets, &dqm->queues);
+   retval = pm_send_runlist(&dqm->packet_mgr, &dqm->queues);
pr_debug("%s sent runlist\n", __func__);
if (retval) {
pr_err("failed to execute runlist\n");
@@ -1416,13 +1416,13 @@ static int unmap_queues_cpsch(struct 
device_queue_manager *dqm,
if (!dqm->active_runlist)
return retval;
 
-   retval = pm_send_unmap_queue(&dqm->packets, KFD_QUEUE_TYPE_COMPUTE,
+   retval = pm_send_unmap_queue(&dqm->packet_mgr, KFD_QUEUE_TYPE_COMPUTE,
filter, filter_param, false, 0);
if (retval)
return retval;
 
*dqm->fence_addr = KFD_FENCE_INIT;
-   pm_send_query_status(&dqm->packets, dqm->fence_gpu_addr,
+   pm_send_query_status(&dqm->packet_mgr, dqm->fence_gpu_addr,
KFD_FENCE_COMPLETED);

[PATCH 1/5] drm/amdgpu: Fix a printing message

2021-07-15 Thread Oak Zeng
The printing message "PSP loading VCN firmware" is mis-leading because
people might think driver is loading VCN firmware. Actually when this
message is printed, driver is just preparing some VCN ucode, not loading
VCN firmware yet. The actual VCN firmware loading will be in the PSP block
hw_init. Fix the printing message

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index 284bb42..121ee9f 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
@@ -119,7 +119,7 @@ static int vcn_v1_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
index 8af567c..f4686e9 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
@@ -122,7 +122,7 @@ static int vcn_v2_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index 888b17d..e0c0c37 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
@@ -152,7 +152,7 @@ static int vcn_v2_5_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index c3580de..a1bbe33 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -158,7 +158,7 @@ static int vcn_v3_0_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   dev_info(adev->dev, "Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
-- 
2.7.4

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


[PATCH 4/5] drm/amdkfd: Set priv_queue to NULL after it is freed

2021-07-15 Thread Oak Zeng
This variable will be used to determine whether packet
manager is initialized or not, in a future patch.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index d8e940f..b130cc0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -278,6 +278,7 @@ void pm_uninit(struct packet_manager *pm, bool hanging)
 {
mutex_destroy(&pm->lock);
kernel_queue_uninit(pm->priv_queue, hanging);
+   pm->priv_queue = NULL;
 }
 
 int pm_send_set_resources(struct packet_manager *pm,
-- 
2.7.4

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


[PATCH 0/5] MISC fixes

2021-07-15 Thread Oak Zeng
Oak Zeng (5):
  drm/amdgpu: Fix a printing message
  drm/amdgpu: Change a few function names
  drm/amdkfd: Renaming dqm->packets to dqm->dpm
  drm/amdkfd: Set priv_queue to NULL after it is freed
  drm/amdkfd: Fix a concurrency issue during kfd recovery

 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c| 16 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  8 +
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 36 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c|  4 +++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 10 files changed, 40 insertions(+), 36 deletions(-)

-- 
2.7.4

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


[PATCH 3/5] drm/amdkfd: Renaming dqm->packets to dqm->dpm

2021-07-15 Thread Oak Zeng
Renaming packets to dpm (device packet manager) to
reflect the real meaning of this variable.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  2 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 26 +++---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 9e4a05e..c51402b 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1390,7 +1390,7 @@ int kfd_debugfs_hang_hws(struct kfd_dev *dev)
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->packets);
+   r = pm_debugfs_hang_hws(&dev->dqm->dpm);
if (!r)
r = dqm_debugfs_execute_queues(dev->dqm);
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 16a1713..f2984d3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -260,7 +260,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
 static int flush_texture_cache_nocpsch(struct kfd_dev *kdev,
struct qcm_process_device *qpd)
 {
-   const struct packet_manager_funcs *pmf = qpd->dqm->packets.pmf;
+   const struct packet_manager_funcs *pmf = qpd->dqm->dpm.pmf;
int ret;
 
if (!qpd->ib_kaddr)
@@ -1000,7 +1000,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
init_interrupts(dqm);

if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   return pm_init(&dqm->packets, dqm);
+   return pm_init(&dqm->dpm, dqm);
dqm->sched_running = true;
 
return 0;
@@ -1009,7 +1009,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
 static int stop_nocpsch(struct device_queue_manager *dqm)
 {
if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->dpm, false);
dqm->sched_running = false;
 
return 0;
@@ -1124,7 +1124,7 @@ static int set_sched_resources(struct 
device_queue_manager *dqm)
"queue mask: 0x%8llX\n",
res.vmid_mask, res.queue_mask);
 
-   return pm_send_set_resources(&dqm->packets, &res);
+   return pm_send_set_resources(&dqm->dpm, &res);
 }
 
 static int initialize_cpsch(struct device_queue_manager *dqm)
@@ -1164,7 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
-   retval = pm_init(&dqm->packets, dqm);
+   retval = pm_init(&dqm->dpm, dqm);
if (retval)
goto fail_packet_manager_init;
 
@@ -1197,7 +1197,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
return 0;
 fail_allocate_vidmem:
 fail_set_sched_resources:
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->dpm, false);
 fail_packet_manager_init:
return retval;
 }
@@ -1213,10 +1213,10 @@ static int stop_cpsch(struct device_queue_manager *dqm)
dqm->sched_running = false;
dqm_unlock(dqm);
 
-   pm_release_ib(&dqm->packets);
+   pm_release_ib(&dqm->dpm);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
-   pm_uninit(&dqm->packets, hanging);
+   pm_uninit(&dqm->dpm, hanging);
 
return 0;
 }
@@ -1390,7 +1390,7 @@ static int map_queues_cpsch(struct device_queue_manager 
*dqm)
if (dqm->active_runlist)
return 0;
 
-   retval = pm_send_runlist(&dqm->packets, &dqm->queues);
+   retval = pm_send_runlist(&dqm->dpm, &dqm->queues);
pr_debug("%s sent runlist\n", __func__);
if (retval) {
pr_err("failed to execute runlist\n");
@@ -1416,13 +1416,13 @@ static int unmap_queues_cpsch(struct 
device_queue_manager *dqm,
if (!dqm->active_runlist)
return retval;
 
-   retval = pm_send_unmap_queue(&dqm->packets, KFD_QUEUE_TYPE_COMPUTE,
+   retval = pm_send_unmap_queue(&dqm->dpm, KFD_QUEUE_TYPE_COMPUTE,
filter, filter_param, false, 0);
if (retval)
return retval;
 
*dqm->fence_addr = KFD_FENCE_INIT;
-   pm_send_query_status(&dqm->packets, dqm->fence_gpu_addr,
+   pm_send_query_status(&dqm->dpm, dqm->fence_gpu_addr,
KFD_FENCE_COMPLETED);
/* should be timed out */
retval = amdkfd_fence_wait_timeout(dqm->fence_a

[PATCH 2/5] drm/amdgpu: Change a few function names

2021-07-15 Thread Oak Zeng
Function name "psp_np_fw_load" is not proper as people don't
know _np_fw_ means "non psp firmware". Change the function
name to psp_load_non_psp_fw for better understanding. Same
thing for function psp_execute_np_fw_load.

Signed-off-by: Oak Zeng 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d9ddb2c..8d1e2b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2351,7 +2351,7 @@ static int psp_prep_load_ip_fw_cmd_buf(struct 
amdgpu_firmware_info *ucode,
return ret;
 }
 
-static int psp_execute_np_fw_load(struct psp_context *psp,
+static int psp_execute_non_psp_fw_load(struct psp_context *psp,
  struct amdgpu_firmware_info *ucode)
 {
int ret = 0;
@@ -2387,7 +2387,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
}
}
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
 
if (ret)
DRM_ERROR("PSP load smu failed!\n");
@@ -2442,14 +2442,14 @@ int psp_load_fw_list(struct psp_context *psp,
for (i = 0; i < ucode_count; ++i) {
ucode = ucode_list[i];
psp_print_fw_hdr(psp, ucode);
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
}
return ret;
 }
 
-static int psp_np_fw_load(struct psp_context *psp)
+static int psp_load_non_psp_fw(struct psp_context *psp)
 {
int i, ret;
struct amdgpu_firmware_info *ucode;
@@ -2488,7 +2488,7 @@ static int psp_np_fw_load(struct psp_context *psp)
 
psp_print_fw_hdr(psp, ucode);
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
 
@@ -2565,7 +2565,7 @@ static int psp_load_fw(struct amdgpu_device *adev)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2765,7 +2765,7 @@ static int psp_resume(void *handle)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2863,7 +2863,7 @@ int psp_update_vcn_sram(struct amdgpu_device *adev, int 
inst_idx,
ucode.mc_addr = cmd_gpu_addr;
ucode.ucode_size = cmd_size;
 
-   return psp_execute_np_fw_load(&adev->psp, &ucode);
+   return psp_execute_non_psp_fw_load(&adev->psp, &ucode);
 }
 
 int psp_ring_cmd_submit(struct psp_context *psp,
-- 
2.7.4

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


[PATCH 5/5] drm/amdkfd: Fix a concurrency issue during kfd recovery

2021-07-15 Thread Oak Zeng
start_cpsch and stop_cpsch can be called during kfd device
initialization or during gpu reset/recovery. So they can
run concurrently. Currently in start_cpsch and stop_cpsch,
pm_init and pm_uninit is not protected by the dpm lock.
Imagine such a case that user use packet manager's function
to submit a pm4 packet to hang hws (ie through command
cat /sys/class/kfd/kfd/topology/nodes/1/gpu_id | sudo tee
/sys/kernel/debug/kfd/hang_hws), while kfd device is under
device reset/recovery so packet manager can be not initialized.
There will be unpredictable protection fault in such case.

This patch moves pm_init/uninit inside the dpm lock and check
packet manager is initialized before using packet manager
function.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c   |  8 +---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 10 --
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c   |  3 +++
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index c51402b..adc2342 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1383,18 +1383,12 @@ void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, 
uint32_t throttle_bitmask)
  */
 int kfd_debugfs_hang_hws(struct kfd_dev *dev)
 {
-   int r = 0;
-
if (dev->dqm->sched_policy != KFD_SCHED_POLICY_HWS) {
pr_err("HWS is not enabled");
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->dpm);
-   if (!r)
-   r = dqm_debugfs_execute_queues(dev->dqm);
-
-   return r;
+   return dqm_debugfs_execute_queues(dev->dqm);
 }
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index f2984d3..44136d2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1164,6 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
+   dqm_lock(dqm);
retval = pm_init(&dqm->dpm, dqm);
if (retval)
goto fail_packet_manager_init;
@@ -1186,7 +1187,6 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
init_interrupts(dqm);
 
-   dqm_lock(dqm);
/* clear hang status when driver try to start the hw scheduler */
dqm->is_hws_hang = false;
dqm->is_resetting = false;
@@ -1199,6 +1199,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 fail_set_sched_resources:
pm_uninit(&dqm->dpm, false);
 fail_packet_manager_init:
+   dqm_unlock(dqm);
return retval;
 }
 
@@ -1211,12 +1212,12 @@ static int stop_cpsch(struct device_queue_manager *dqm)
unmap_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
hanging = dqm->is_hws_hang || dqm->is_resetting;
dqm->sched_running = false;
-   dqm_unlock(dqm);
 
pm_release_ib(&dqm->dpm);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
pm_uninit(&dqm->dpm, hanging);
+   dqm_unlock(dqm);
 
return 0;
 }
@@ -2104,6 +2105,11 @@ int dqm_debugfs_execute_queues(struct 
device_queue_manager *dqm)
int r = 0;
 
dqm_lock(dqm);
+   r = pm_debugfs_hang_hws(&dqm->dpm);
+   if (r) {
+   dqm_unlock(dqm);
+   return r;
+   }
dqm->active_runlist = true;
r = execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
dqm_unlock(dqm);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index b130cc0..0123e64 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -448,6 +448,9 @@ int pm_debugfs_hang_hws(struct packet_manager *pm)
uint32_t *buffer, size;
int r = 0;
 
+   if (!pm->priv_queue)
+   return -EBUSY;
+
size = pm->pmf->query_status_size;
mutex_lock(&pm->lock);
kq_acquire_packet_buffer(pm->priv_queue,
-- 
2.7.4

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


[PATCH 4/5] drm/amdkfd: Set priv_queue to NULL after it is freed

2021-07-15 Thread Oak Zeng
This variable will be used to determine whether packet
manager is initialized or not, in a future patch.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index d8e940f..b130cc0 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -278,6 +278,7 @@ void pm_uninit(struct packet_manager *pm, bool hanging)
 {
mutex_destroy(&pm->lock);
kernel_queue_uninit(pm->priv_queue, hanging);
+   pm->priv_queue = NULL;
 }
 
 int pm_send_set_resources(struct packet_manager *pm,
-- 
2.7.4

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


[PATCH 2/5] drm/amdgpu: Change a few function names

2021-07-15 Thread Oak Zeng
Function name "psp_np_fw_load" is not proper as people don't
know _np_fw_ means "non psp firmware". Change the function
name to psp_load_non_psp_fw for better understanding. Same
thing for function psp_execute_np_fw_load.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d9ddb2c..8d1e2b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2351,7 +2351,7 @@ static int psp_prep_load_ip_fw_cmd_buf(struct 
amdgpu_firmware_info *ucode,
return ret;
 }
 
-static int psp_execute_np_fw_load(struct psp_context *psp,
+static int psp_execute_non_psp_fw_load(struct psp_context *psp,
  struct amdgpu_firmware_info *ucode)
 {
int ret = 0;
@@ -2387,7 +2387,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
}
}
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
 
if (ret)
DRM_ERROR("PSP load smu failed!\n");
@@ -2442,14 +2442,14 @@ int psp_load_fw_list(struct psp_context *psp,
for (i = 0; i < ucode_count; ++i) {
ucode = ucode_list[i];
psp_print_fw_hdr(psp, ucode);
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
}
return ret;
 }
 
-static int psp_np_fw_load(struct psp_context *psp)
+static int psp_load_non_psp_fw(struct psp_context *psp)
 {
int i, ret;
struct amdgpu_firmware_info *ucode;
@@ -2488,7 +2488,7 @@ static int psp_np_fw_load(struct psp_context *psp)
 
psp_print_fw_hdr(psp, ucode);
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
 
@@ -2565,7 +2565,7 @@ static int psp_load_fw(struct amdgpu_device *adev)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2765,7 +2765,7 @@ static int psp_resume(void *handle)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2863,7 +2863,7 @@ int psp_update_vcn_sram(struct amdgpu_device *adev, int 
inst_idx,
ucode.mc_addr = cmd_gpu_addr;
ucode.ucode_size = cmd_size;
 
-   return psp_execute_np_fw_load(&adev->psp, &ucode);
+   return psp_execute_non_psp_fw_load(&adev->psp, &ucode);
 }
 
 int psp_ring_cmd_submit(struct psp_context *psp,
-- 
2.7.4

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


[PATCH 3/5] drm/amdkfd: Renaming dqm->packets to dqm->dpm

2021-07-15 Thread Oak Zeng
Renaming packets to dpm (device packet manager) to
reflect the real meaning of this variable.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  2 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 26 +++---
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 9e4a05e..c51402b 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1390,7 +1390,7 @@ int kfd_debugfs_hang_hws(struct kfd_dev *dev)
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->packets);
+   r = pm_debugfs_hang_hws(&dev->dqm->dpm);
if (!r)
r = dqm_debugfs_execute_queues(dev->dqm);
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 16a1713..f2984d3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -260,7 +260,7 @@ static int allocate_vmid(struct device_queue_manager *dqm,
 static int flush_texture_cache_nocpsch(struct kfd_dev *kdev,
struct qcm_process_device *qpd)
 {
-   const struct packet_manager_funcs *pmf = qpd->dqm->packets.pmf;
+   const struct packet_manager_funcs *pmf = qpd->dqm->dpm.pmf;
int ret;
 
if (!qpd->ib_kaddr)
@@ -1000,7 +1000,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
init_interrupts(dqm);

if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   return pm_init(&dqm->packets, dqm);
+   return pm_init(&dqm->dpm, dqm);
dqm->sched_running = true;
 
return 0;
@@ -1009,7 +1009,7 @@ static int start_nocpsch(struct device_queue_manager *dqm)
 static int stop_nocpsch(struct device_queue_manager *dqm)
 {
if (dqm->dev->device_info->asic_family == CHIP_HAWAII)
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->dpm, false);
dqm->sched_running = false;
 
return 0;
@@ -1124,7 +1124,7 @@ static int set_sched_resources(struct 
device_queue_manager *dqm)
"queue mask: 0x%8llX\n",
res.vmid_mask, res.queue_mask);
 
-   return pm_send_set_resources(&dqm->packets, &res);
+   return pm_send_set_resources(&dqm->dpm, &res);
 }
 
 static int initialize_cpsch(struct device_queue_manager *dqm)
@@ -1164,7 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
-   retval = pm_init(&dqm->packets, dqm);
+   retval = pm_init(&dqm->dpm, dqm);
if (retval)
goto fail_packet_manager_init;
 
@@ -1197,7 +1197,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
return 0;
 fail_allocate_vidmem:
 fail_set_sched_resources:
-   pm_uninit(&dqm->packets, false);
+   pm_uninit(&dqm->dpm, false);
 fail_packet_manager_init:
return retval;
 }
@@ -1213,10 +1213,10 @@ static int stop_cpsch(struct device_queue_manager *dqm)
dqm->sched_running = false;
dqm_unlock(dqm);
 
-   pm_release_ib(&dqm->packets);
+   pm_release_ib(&dqm->dpm);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
-   pm_uninit(&dqm->packets, hanging);
+   pm_uninit(&dqm->dpm, hanging);
 
return 0;
 }
@@ -1390,7 +1390,7 @@ static int map_queues_cpsch(struct device_queue_manager 
*dqm)
if (dqm->active_runlist)
return 0;
 
-   retval = pm_send_runlist(&dqm->packets, &dqm->queues);
+   retval = pm_send_runlist(&dqm->dpm, &dqm->queues);
pr_debug("%s sent runlist\n", __func__);
if (retval) {
pr_err("failed to execute runlist\n");
@@ -1416,13 +1416,13 @@ static int unmap_queues_cpsch(struct 
device_queue_manager *dqm,
if (!dqm->active_runlist)
return retval;
 
-   retval = pm_send_unmap_queue(&dqm->packets, KFD_QUEUE_TYPE_COMPUTE,
+   retval = pm_send_unmap_queue(&dqm->dpm, KFD_QUEUE_TYPE_COMPUTE,
filter, filter_param, false, 0);
if (retval)
return retval;
 
*dqm->fence_addr = KFD_FENCE_INIT;
-   pm_send_query_status(&dqm->packets, dqm->fence_gpu_addr,
+   pm_send_query_status(&dqm->dpm, dqm->fence_gpu_addr,
KFD_FENCE_COMPLETED);
/* should be timed out */
retval = amdkfd_fence_wait_timeout(dqm->fence_a

[PATCH 5/5] drm/amdkfd: Fix a concurrency issue during kfd recovery

2021-07-15 Thread Oak Zeng
start_cpsch and stop_cpsch can be called during kfd device
initialization or during gpu reset/recovery. So they can
run concurrently. Currently in start_cpsch and stop_cpsch,
pm_init and pm_uninit is not protected by the dpm lock.
Imagine such a case that user use packet manager's function
to submit a pm4 packet to hang hws (ie through command
cat /sys/class/kfd/kfd/topology/nodes/1/gpu_id | sudo tee
/sys/kernel/debug/kfd/hang_hws), while kfd device is under
device reset/recovery so packet manager can be not initialized.
There will be unpredictable protection fault in such case.

This patch moves pm_init/uninit inside the dpm lock and check
packet manager is initialized before using packet manager
function.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c   |  8 +---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 10 --
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c   |  3 +++
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index c51402b..adc2342 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1383,18 +1383,12 @@ void kgd2kfd_smi_event_throttle(struct kfd_dev *kfd, 
uint32_t throttle_bitmask)
  */
 int kfd_debugfs_hang_hws(struct kfd_dev *dev)
 {
-   int r = 0;
-
if (dev->dqm->sched_policy != KFD_SCHED_POLICY_HWS) {
pr_err("HWS is not enabled");
return -EINVAL;
}
 
-   r = pm_debugfs_hang_hws(&dev->dqm->dpm);
-   if (!r)
-   r = dqm_debugfs_execute_queues(dev->dqm);
-
-   return r;
+   return dqm_debugfs_execute_queues(dev->dqm);
 }
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index f2984d3..44136d2 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1164,6 +1164,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
retval = 0;
 
+   dqm_lock(dqm);
retval = pm_init(&dqm->dpm, dqm);
if (retval)
goto fail_packet_manager_init;
@@ -1186,7 +1187,6 @@ static int start_cpsch(struct device_queue_manager *dqm)
 
init_interrupts(dqm);
 
-   dqm_lock(dqm);
/* clear hang status when driver try to start the hw scheduler */
dqm->is_hws_hang = false;
dqm->is_resetting = false;
@@ -1199,6 +1199,7 @@ static int start_cpsch(struct device_queue_manager *dqm)
 fail_set_sched_resources:
pm_uninit(&dqm->dpm, false);
 fail_packet_manager_init:
+   dqm_unlock(dqm);
return retval;
 }
 
@@ -1211,12 +1212,12 @@ static int stop_cpsch(struct device_queue_manager *dqm)
unmap_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
hanging = dqm->is_hws_hang || dqm->is_resetting;
dqm->sched_running = false;
-   dqm_unlock(dqm);
 
pm_release_ib(&dqm->dpm);
 
kfd_gtt_sa_free(dqm->dev, dqm->fence_mem);
pm_uninit(&dqm->dpm, hanging);
+   dqm_unlock(dqm);
 
return 0;
 }
@@ -2104,6 +2105,11 @@ int dqm_debugfs_execute_queues(struct 
device_queue_manager *dqm)
int r = 0;
 
dqm_lock(dqm);
+   r = pm_debugfs_hang_hws(&dqm->dpm);
+   if (r) {
+   dqm_unlock(dqm);
+   return r;
+   }
dqm->active_runlist = true;
r = execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0);
dqm_unlock(dqm);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
index b130cc0..0123e64 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c
@@ -448,6 +448,9 @@ int pm_debugfs_hang_hws(struct packet_manager *pm)
uint32_t *buffer, size;
int r = 0;
 
+   if (!pm->priv_queue)
+   return -EBUSY;
+
size = pm->pmf->query_status_size;
mutex_lock(&pm->lock);
kq_acquire_packet_buffer(pm->priv_queue,
-- 
2.7.4

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


[PATCH 1/5] drm/amdgpu: Fix a printing message

2021-07-15 Thread Oak Zeng
The printing message "PSP loading VCN firmware" is mis-leading because
people might think driver is loading VCN firmware. Actually when this
message is printed, driver is just preparing some VCN ucode, not loading
VCN firmware yet. The actual VCN firmware loading will be in the PSP block
hw_init. Fix the printing message

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index 284bb42..1f8e902 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
@@ -119,7 +119,7 @@ static int vcn_v1_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 1.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
index 8af567c..ebe4f2b 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
@@ -122,7 +122,7 @@ static int vcn_v2_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 2.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index 888b17d..5741504 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
@@ -152,7 +152,7 @@ static int vcn_v2_5_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 2.5: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index c3580de..b81eae3 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -158,7 +158,7 @@ static int vcn_v3_0_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 3.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
-- 
2.7.4

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


[PATCH 0/5] MISC fixes

2021-07-15 Thread Oak Zeng
Oak Zeng (5):
  drm/amdgpu: Fix a printing message
  drm/amdgpu: Change a few function names
  drm/amdkfd: Renaming dqm->packets to dqm->dpm
  drm/amdkfd: Set priv_queue to NULL after it is freed
  drm/amdkfd: Fix a concurrency issue during kfd recovery

 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c| 16 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c|  8 +
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 36 +-
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.h  |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c|  4 +++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c  |  2 +-
 10 files changed, 40 insertions(+), 36 deletions(-)

-- 
2.7.4

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


[PATCH 2/3] drm/amdgpu: Fix a printing message

2021-07-14 Thread Oak Zeng
The printing message "PSP loading VCN firmware" is mis-leading because
people might think driver is loading VCN firmware. Actually when this
message is printed, driver is just preparing some VCN ucode, not loading
VCN firmware yet. The actual VCN firmware loading will be in the PSP block
hw_init. Fix the printing message

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index 284bb42..1f8e902 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
@@ -119,7 +119,7 @@ static int vcn_v1_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 1.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
index 8af567c..ebe4f2b 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
@@ -122,7 +122,7 @@ static int vcn_v2_0_sw_init(void *handle)
adev->firmware.ucode[AMDGPU_UCODE_ID_VCN].fw = adev->vcn.fw;
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), PAGE_SIZE);
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 2.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index 888b17d..5741504 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
@@ -152,7 +152,7 @@ static int vcn_v2_5_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 2.5: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c 
b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
index c3580de..b81eae3 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c
@@ -158,7 +158,7 @@ static int vcn_v3_0_sw_init(void *handle)
adev->firmware.fw_size +=
ALIGN(le32_to_cpu(hdr->ucode_size_bytes), 
PAGE_SIZE);
}
-   DRM_INFO("PSP loading VCN firmware\n");
+   DRM_INFO("VCN 3.0: Will use PSP to load VCN firmware\n");
}
 
r = amdgpu_vcn_resume(adev);
-- 
2.7.4

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


[PATCH 1/3] drm/amdkfd: Disallow debugfs to hang hws when GPU is resetting

2021-07-14 Thread Oak Zeng
If GPU is during a resetting cycle, writing to GPU can cause
unpredictable protection fault, see below call trace. Disallow using kfd debugfs
hang_hws to hang hws if GPU is resetting.

[12808.234114] general protection fault:  [#1] SMP NOPTI
[12808.234119] CPU: 13 PID: 6334 Comm: tee Tainted: G   OE
5.4.0-77-generic #86-Ubuntu
[12808.234121] Hardware name: ASUS System Product Name/Pro WS WRX80E-SAGE SE
WIFI, BIOS 0211 11/27/2020
[12808.234220] RIP: 0010:kq_submit_packet+0xd/0x50 [amdgpu]
[12808.234222] Code: 8b 45 d0 48 c7 00 00 00 00 00 b8 f4 ff ff ff eb df 66 66
2e 0f 1f 84 00 00 00 00 00 90 0f 1f 44 00 00 55 48 8b 17 48 8b 47 48 <48> 8b 52
08 48 89 e5 83 7a 20 08 74 14 8b 77 20 89 30 48 8b 47 10
[12808.234224] RSP: 0018:b0bf4954bdc0 EFLAGS: 00010216
[12808.234226] RAX: b0bf4a1a5a00 RBX: 99302895c0c8 RCX:

[12808.234227] RDX: c3156d43d3a04949 RSI: 0055 RDI:
99302584c300
[12808.234228] RBP: b0bf4954bdf8 R08: 0543 R09:
b0bf4a1a4230
[12808.234229] R10: 000a R11: f000 R12:

[12808.234230] R13: 99302895c0d8 R14: 7ffebb3d18f0 R15:
0005
[12808.234232] FS:  7f0d822ef580() GS:99307d34()
knlGS:
[12808.234233] CS:  0010 DS:  ES:  CR0: 80050033
[12808.234234] CR2: 7ffebb3d1908 CR3: 001efe1ec000 CR4:
00340ee0
[12808.234235] Call Trace:
[12808.234324]  ? pm_debugfs_hang_hws+0x71/0xd0 [amdgpu]
[12808.234408]  kfd_debugfs_hang_hws+0x2e/0x50 [amdgpu]
[12808.234494]  kfd_debugfs_hang_hws_write+0xb6/0xc0 [amdgpu]
[12808.234499]  full_proxy_write+0x5c/0x90
[12808.234502]  __vfs_write+0x1b/0x40
[12808.234504]  vfs_write+0xb9/0x1a0
[12808.234506]  ksys_write+0x67/0xe0
[12808.234508]  __x64_sys_write+0x1a/0x20
[12808.234511]  do_syscall_64+0x57/0x190
[12808.234514]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 9e4a05e..fc77d03 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1390,6 +1390,11 @@ int kfd_debugfs_hang_hws(struct kfd_dev *dev)
return -EINVAL;
}
 
+   if (dev->dqm->is_resetting) {
+   pr_err("HWS is already resetting, please wait for the current 
reset to finish\n");
+   return -EBUSY;
+   }
+
r = pm_debugfs_hang_hws(&dev->dqm->packets);
if (!r)
r = dqm_debugfs_execute_queues(dev->dqm);
-- 
2.7.4

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


[PATCH 3/3] drm/amdgpu: Change a few function names

2021-07-14 Thread Oak Zeng
Function name "psp_np_fw_load" is not proper as people don't
know _np_fw_ means "non psp firmware". Change the function
name to psp_load_non_psp_fw for better understanding. Same
thing for function psp_execute_np_fw_load.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index d9ddb2c..8d1e2b2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -2351,7 +2351,7 @@ static int psp_prep_load_ip_fw_cmd_buf(struct 
amdgpu_firmware_info *ucode,
return ret;
 }
 
-static int psp_execute_np_fw_load(struct psp_context *psp,
+static int psp_execute_non_psp_fw_load(struct psp_context *psp,
  struct amdgpu_firmware_info *ucode)
 {
int ret = 0;
@@ -2387,7 +2387,7 @@ static int psp_load_smu_fw(struct psp_context *psp)
}
}
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
 
if (ret)
DRM_ERROR("PSP load smu failed!\n");
@@ -2442,14 +2442,14 @@ int psp_load_fw_list(struct psp_context *psp,
for (i = 0; i < ucode_count; ++i) {
ucode = ucode_list[i];
psp_print_fw_hdr(psp, ucode);
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
}
return ret;
 }
 
-static int psp_np_fw_load(struct psp_context *psp)
+static int psp_load_non_psp_fw(struct psp_context *psp)
 {
int i, ret;
struct amdgpu_firmware_info *ucode;
@@ -2488,7 +2488,7 @@ static int psp_np_fw_load(struct psp_context *psp)
 
psp_print_fw_hdr(psp, ucode);
 
-   ret = psp_execute_np_fw_load(psp, ucode);
+   ret = psp_execute_non_psp_fw_load(psp, ucode);
if (ret)
return ret;
 
@@ -2565,7 +2565,7 @@ static int psp_load_fw(struct amdgpu_device *adev)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2765,7 +2765,7 @@ static int psp_resume(void *handle)
if (ret)
goto failed;
 
-   ret = psp_np_fw_load(psp);
+   ret = psp_load_non_psp_fw(psp);
if (ret)
goto failed;
 
@@ -2863,7 +2863,7 @@ int psp_update_vcn_sram(struct amdgpu_device *adev, int 
inst_idx,
ucode.mc_addr = cmd_gpu_addr;
ucode.ucode_size = cmd_size;
 
-   return psp_execute_np_fw_load(&adev->psp, &ucode);
+   return psp_execute_non_psp_fw_load(&adev->psp, &ucode);
 }
 
 int psp_ring_cmd_submit(struct psp_context *psp,
-- 
2.7.4

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


[PATCH 0/3] MISC fixes

2021-07-14 Thread Oak Zeng
Oak Zeng (3):
  drm/amdkfd: Disallow debugfs to hang hws when GPU is resetting
  drm/amdgpu: Fix a printing message
  drm/amdgpu: Change a few function names

 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device.c |  5 +
 6 files changed, 17 insertions(+), 12 deletions(-)

-- 
2.7.4

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


[PATCH] drm/amdkfd: Disallow debugfs to hang hws when GPU is resetting

2021-07-07 Thread Oak Zeng
If GPU is during a resetting cycle, writing to GPU can cause
unpredictable protection fault. Disallow using kfd debugfs
hang_hws to hang hws if GPU is resetting.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
index 9e4a05e..c380be9 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c
@@ -1390,6 +1390,11 @@ int kfd_debugfs_hang_hws(struct kfd_dev *dev)
return -EINVAL;
}
 
+   if (dev->dqm->is_resetting) {
+   pr_err("HWS is already under resetting, please wait the current 
reset to finish\n");
+   return -EBUSY;
+   }
+
r = pm_debugfs_hang_hws(&dev->dqm->packets);
if (!r)
r = dqm_debugfs_execute_queues(dev->dqm);
-- 
2.7.4

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


[PATCH] drm/amdgpu: Set ttm caching flags during bo allocation

2021-06-28 Thread Oak Zeng
The ttm caching flags (ttm_cached, ttm_write_combined etc) are
used to determine a buffer object's mapping attributes in both
CPU page table and GPU page table (when that buffer is also
accessed by GPU). Currently the ttm caching flags are set in
function amdgpu_ttm_io_mem_reserve which is called during
DRM_AMDGPU_GEM_MMAP ioctl. This has a problem since the GPU
mapping of the buffer object (ioctl DRM_AMDGPU_GEM_VA) can
happen earlier than the mmap time, thus the GPU page table
update code can't pick up the right ttm caching flags to
decide the right GPU page table attributes.

This patch moves the ttm caching flags setting to function
amdgpu_vram_mgr_new - this function is called during the
first step of a buffer object create (eg, DRM_AMDGPU_GEM_CREATE)
so the later both CPU and GPU mapping function calls will
pick up this flag for CPU/GPU page table set up.

Signed-off-by: Oak Zeng 
Suggested-by: Christian Koenig 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c  | 4 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 5 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 6297363..93acf6f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -607,10 +607,6 @@ static int amdgpu_ttm_io_mem_reserve(struct ttm_device 
*bdev,
 
mem->bus.offset += adev->gmc.aper_base;
mem->bus.is_iomem = true;
-   if (adev->gmc.xgmi.connected_to_cpu)
-   mem->bus.caching = ttm_cached;
-   else
-   mem->bus.caching = ttm_write_combined;
break;
default:
return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index a52e17e..6cb66eb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -454,6 +454,11 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager 
*man,
if (i == 1)
mem->placement |= TTM_PL_FLAG_CONTIGUOUS;
 
+   if (adev->gmc.xgmi.connected_to_cpu)
+   mem->bus.caching = ttm_cached;
+   else
+   mem->bus.caching = ttm_write_combined;
+
atomic64_add(vis_usage, &mgr->vis_usage);
mem->mm_node = nodes;
return 0;
-- 
2.7.4

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


[PATCH 2/4] drm/amdkfd: Don't create crat memory sub-table if node has no memory

2021-06-01 Thread Oak Zeng
In some configuration, there is CPU-only (no memory) numa node. Don't
create crat memory sub-table for such node.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 21 +++--
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index 56e6dff..420a312 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -1583,7 +1583,9 @@ static int kfd_fill_cu_for_cpu(int numa_node_id, int 
*avail_size,
  * @avail_size: Available size in the memory
  * @sub_type_hdr: Memory into which compute info will be filled in
  *
- * Return 0 if successful else return -ve value
+ * Return 0 if successful
+ * Return -ENOMEM if not enough space in caller allocated crat table
+ * Return -1 if this numa node has no memory
  */
 static int kfd_fill_mem_info_for_cpu(int numa_node_id, int *avail_size,
int proximity_domain,
@@ -1615,6 +1617,9 @@ static int kfd_fill_mem_info_for_cpu(int numa_node_id, 
int *avail_size,
mem_in_bytes += 
zone_managed_pages(&pgdat->node_zones[zone_type]);
mem_in_bytes <<= PAGE_SHIFT;
 
+   if (mem_in_bytes == 0)
+   return -1;
+
sub_type_hdr->length_low = lower_32_bits(mem_in_bytes);
sub_type_hdr->length_high = upper_32_bits(mem_in_bytes);
sub_type_hdr->proximity_domain = proximity_domain;
@@ -1742,15 +1747,19 @@ static int kfd_create_vcrat_image_cpu(void 
*pcrat_image, size_t *size)
ret = kfd_fill_mem_info_for_cpu(numa_node_id, &avail_size,
crat_table->num_domains,
(struct crat_subtype_memory *)sub_type_hdr);
-   if (ret < 0) {
+   if (ret == -ENOMEM) {
pr_err("fill mem for cpu failed\n");
return ret;
}
-   crat_table->length += sub_type_hdr->length;
-   crat_table->total_entries++;
 
-   sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
-   sub_type_hdr->length);
+   /* ret == -1: this node has no memory */
+   if (ret == 0) {
+   crat_table->length += sub_type_hdr->length;
+   crat_table->total_entries++;
+
+   sub_type_hdr = (typeof(sub_type_hdr))((char 
*)sub_type_hdr +
+   sub_type_hdr->length);
+   }
 
if (kfd_numa_node_to_apic_id(numa_node_id) != -1) {
/* Fill in Subtype: IO Link */
-- 
2.7.4

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


[PATCH 4/4] drm/amdkfd: Patch memory parameters for all CPU nodes

2021-06-01 Thread Oak Zeng
There can be more than one CPU nodes. Patch memory width
and clock info for all CPU nodes, instead of only the first
one.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index 9be66ba..e982829 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -1073,10 +1073,10 @@ int kfd_topology_init(void)
if (cpu_only_node) {
/* Add additional information to CPU only node created above */
down_write(&topology_lock);
-   kdev = list_first_entry(&topology_device_list,
-   struct kfd_topology_device, list);
+   list_for_each_entry(kdev, &topology_device_list, list) {
+   kfd_add_non_crat_information(kdev);
+   }
up_write(&topology_lock);
-   kfd_add_non_crat_information(kdev);
}
 
 err:
-- 
2.7.4

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


[PATCH 3/4] drm/amdkfd: Use simd_count to determine whether it is a GPU node

2021-06-01 Thread Oak Zeng
Previously we used cpu_cores_count==0 to determine whether a node
is a GPU node. This is not correct any more since we introduced
memory only numa node. For memory only numa node, cpu_cores_count
is also 0 but it is not a GPU node.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index dd7772c..87226d5 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -835,7 +835,7 @@ static int kfd_parse_subtype_mem(struct crat_subtype_memory 
*mem,
list_for_each_entry(dev, device_list, list) {
if (mem->proximity_domain == dev->proximity_domain) {
/* We're on GPU node */
-   if (dev->node_props.cpu_cores_count == 0) {
+   if (dev->node_props.simd_count != 0) {
/* APU */
if (mem->visibility_type == 0)
heap_type =
-- 
2.7.4

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


[PATCH 1/4] drm/amdkfd: Create node in kfd sysfs for memory only numa node

2021-06-01 Thread Oak Zeng
Previously kfd driver assumes all CPU numa nodes are associated
with system memory and there is no memory only numa node. This
is not true anymore for ALDEBARAN A+A set up. This patch creates
memory only node in kfd sysfs.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 73 ---
 1 file changed, 42 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index 3251fe2..56e6dff 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -827,8 +827,11 @@ static int kfd_parse_subtype_mem(struct 
crat_subtype_memory *mem,
uint32_t flags = 0;
uint32_t width;
 
-   pr_debug("Found memory entry in CRAT table with proximity_domain=%d\n",
-   mem->proximity_domain);
+   size_in_bytes =
+   ((uint64_t)mem->length_high << 32) +
+   mem->length_low;
+   pr_debug("Found memory entry in CRAT table with proximity_domain=%d, 
size %lld\n",
+   mem->proximity_domain, size_in_bytes);
list_for_each_entry(dev, device_list, list) {
if (mem->proximity_domain == dev->proximity_domain) {
/* We're on GPU node */
@@ -848,9 +851,6 @@ static int kfd_parse_subtype_mem(struct crat_subtype_memory 
*mem,
if (mem->flags & CRAT_MEM_FLAGS_NON_VOLATILE)
flags |= HSA_MEM_FLAGS_NON_VOLATILE;
 
-   size_in_bytes =
-   ((uint64_t)mem->length_high << 32) +
-   mem->length_low;
width = mem->width;
 
/* Multiple banks of the same type are aggregated into
@@ -1718,51 +1718,62 @@ static int kfd_create_vcrat_image_cpu(void 
*pcrat_image, size_t *size)
sub_type_hdr = (struct crat_subtype_generic *)(crat_table+1);
 
for_each_online_node(numa_node_id) {
+   pr_debug("numa node id %d\n", numa_node_id);
if (kfd_numa_node_to_apic_id(numa_node_id) == -1)
-   continue;
-
-   /* Fill in Subtype: Compute Unit */
-   ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
-   crat_table->num_domains,
-   (struct crat_subtype_computeunit *)sub_type_hdr);
-   if (ret < 0)
-   return ret;
-   crat_table->length += sub_type_hdr->length;
-   crat_table->total_entries++;
+   pr_debug("Numa node %d is a memory only numa node\n", 
numa_node_id);
+
+   if (kfd_numa_node_to_apic_id(numa_node_id) != -1) {
+   /* Fill in Subtype: Compute Unit */
+   ret = kfd_fill_cu_for_cpu(numa_node_id, &avail_size,
+   crat_table->num_domains,
+   (struct crat_subtype_computeunit 
*)sub_type_hdr);
+   if (ret < 0) {
+   pr_err("fill cu for cpu failed\n");
+   return ret;
+   }
+   crat_table->length += sub_type_hdr->length;
+   crat_table->total_entries++;
 
-   sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
-   sub_type_hdr->length);
+   sub_type_hdr = (typeof(sub_type_hdr))((char 
*)sub_type_hdr +
+   sub_type_hdr->length);
+   }
 
/* Fill in Subtype: Memory */
ret = kfd_fill_mem_info_for_cpu(numa_node_id, &avail_size,
crat_table->num_domains,
(struct crat_subtype_memory *)sub_type_hdr);
-   if (ret < 0)
+   if (ret < 0) {
+   pr_err("fill mem for cpu failed\n");
return ret;
+   }
crat_table->length += sub_type_hdr->length;
crat_table->total_entries++;
 
sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
sub_type_hdr->length);
 
-   /* Fill in Subtype: IO Link */
+   if (kfd_numa_node_to_apic_id(numa_node_id) != -1) {
+   /* Fill in Subtype: IO Link */
 #ifdef CONFIG_X86_64
-   ret = kfd_fill_iolink_info_for_cpu(numa_node_id, &avail_size,
-   &entries,
-   (struct crat_subtype_iolink *)sub_type_hdr);
-   if (ret < 0)
-   return ret;
+   ret =

[PATCH 2/4] drm/amdkfd: Don't create crat memory sub-table if node has no memory

2021-06-01 Thread Oak Zeng
In some configuration, there is CPU-only (no memory) numa node. Don't
create crat memory sub-table for such node.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 17 +++--
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index 56e6dff..dd7772c 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -1583,7 +1583,8 @@ static int kfd_fill_cu_for_cpu(int numa_node_id, int 
*avail_size,
  * @avail_size: Available size in the memory
  * @sub_type_hdr: Memory into which compute info will be filled in
  *
- * Return 0 if successful else return -ve value
+ * Return memory size in bytes if successful else return -ve value
+ * Returning 0 means this numa node has no memory
  */
 static int kfd_fill_mem_info_for_cpu(int numa_node_id, int *avail_size,
int proximity_domain,
@@ -1619,7 +1620,7 @@ static int kfd_fill_mem_info_for_cpu(int numa_node_id, 
int *avail_size,
sub_type_hdr->length_high = upper_32_bits(mem_in_bytes);
sub_type_hdr->proximity_domain = proximity_domain;
 
-   return 0;
+   return mem_in_bytes;
 }
 
 #ifdef CONFIG_X86_64
@@ -1746,11 +1747,15 @@ static int kfd_create_vcrat_image_cpu(void 
*pcrat_image, size_t *size)
pr_err("fill mem for cpu failed\n");
return ret;
}
-   crat_table->length += sub_type_hdr->length;
-   crat_table->total_entries++;
 
-   sub_type_hdr = (typeof(sub_type_hdr))((char *)sub_type_hdr +
-   sub_type_hdr->length);
+   /* ret == 0: this node has no memory */
+   if (ret > 0) {
+   crat_table->length += sub_type_hdr->length;
+   crat_table->total_entries++;
+
+   sub_type_hdr = (typeof(sub_type_hdr))((char 
*)sub_type_hdr +
+   sub_type_hdr->length);
+   }
 
if (kfd_numa_node_to_apic_id(numa_node_id) != -1) {
/* Fill in Subtype: IO Link */
-- 
2.7.4

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


[PATCH] drm/amdgpu: Quit RAS initialization earlier if RAS is disabled

2021-05-06 Thread Oak Zeng
If RAS is disabled through amdgpu_ras_enable kernel parameter,
we should quit the RAS initialization eariler to avoid initialization
of some RAS data structure such as sysfs etc.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index ebbe2c5..7e65b35 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -2155,7 +2155,7 @@ int amdgpu_ras_init(struct amdgpu_device *adev)
 
amdgpu_ras_check_supported(adev, &con->hw_supported,
&con->supported);
-   if (!con->hw_supported || (adev->asic_type == CHIP_VEGA10)) {
+   if (!adev->ras_features || (adev->asic_type == CHIP_VEGA10)) {
/* set gfx block ras context feature for VEGA20 Gaming
 * send ras disable cmd to ras ta during ras late init.
 */
-- 
2.7.4

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


[PATCH 4/4] Revert "drm/amdgpu: workaround the TMR MC address issue (v2)"

2021-04-01 Thread Oak Zeng
This reverts commit 34a33d4683cba7ba63c894132efb1998c0217631.
34a33d4683cba7ba63c894132efb1998c0217631 was a driver workaround
when PSP firmware was not ready. Now the PSP fw is ready so we
revert this driver workaround.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  9 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 10 --
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 21 ++---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 10 --
 4 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index bc374bc..59bbe59 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -209,15 +209,6 @@ struct amdgpu_gmc {
 */
u64 fb_start;
u64 fb_end;
-   /* In the case of use GART table for vmid0 FB access, [fb_start, fb_end]
-* will be squeezed to GART aperture. But we have a PSP FW issue to fix
-* for now. To temporarily workaround the PSP FW issue, added below two
-* variables to remember the original fb_start/end to re-enable FB
-* aperture to workaround the PSP FW issue. Will delete it after we
-* get a proper PSP FW fix.
-*/
-   u64 fb_start_original;
-   u64 fb_end_original;
unsignedvram_width;
u64 real_vram_size;
int vram_mtrr;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 123ab31..5298698 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -414,16 +414,6 @@ static int psp_tmr_init(struct psp_context *psp)
  AMDGPU_GEM_DOMAIN_VRAM,
  &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
 
-   /* workaround the tmr_mc_addr:
-* PSP requires an address in FB aperture. Right now driver produce
-* tmr_mc_addr in the GART aperture. Convert it back to FB aperture
-* for PSP. Will revert it after we get a fix from PSP FW.
-*/
-   if (psp->adev->asic_type == CHIP_ALDEBARAN) {
-   psp->tmr_mc_addr -= psp->adev->gmc.fb_start;
-   psp->tmr_mc_addr += psp->adev->gmc.fb_start_original;
-   }
-
return ret;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 9b78891..561b32e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -140,21 +140,12 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 * FB aperture and AGP aperture. Disable them.
 */
if (adev->gmc.pdb0_bo) {
-   if (adev->asic_type == CHIP_ALDEBARAN) {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 
adev->gmc.fb_end_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
adev->gmc.fb_start_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
adev->gmc.fb_start_original >> 18);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
adev->gmc.fb_end_original >> 18);
-   } else {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
0x00FF);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
0);
-   }
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 0x00FF);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 0);
}
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index d341d17..71914f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -47,8 +47,6 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
 
adev->gmc.fb_start = base;
adev->gmc.fb_end = top;
-   adev->gmc.fb_start_origi

[PATCH 2/4] drm/amdgpu: Calling address translation functions to simplify codes

2021-04-01 Thread Oak Zeng
Use amdgpu_gmc_vram_pa and amdgpu_gmc_vram_cpu_pa
to simplify codes. No logic change.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c   | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c| 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c  | 3 +--
 12 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 4c5c198..4f10c45 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -205,7 +205,6 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
struct drm_gem_object *gobj = NULL;
struct amdgpu_bo *abo = NULL;
int ret;
-   unsigned long tmp;
 
memset(&mode_cmd, 0, sizeof(mode_cmd));
mode_cmd.width = sizes->surface_width;
@@ -246,8 +245,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
 
info->fbops = &amdgpufb_ops;
 
-   tmp = amdgpu_bo_gpu_offset(abo) - adev->gmc.vram_start;
-   info->fix.smem_start = adev->gmc.aper_base + tmp;
+   info->fix.smem_start = amdgpu_gmc_vram_cpu_pa(adev, abo);
info->fix.smem_len = amdgpu_bo_size(abo);
info->screen_base = amdgpu_bo_kptr(abo);
info->screen_size = amdgpu_bo_size(abo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index ca16649..238082f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -641,8 +641,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
u64 vram_addr = adev->vm_manager.vram_base_offset -
adev->gmc.xgmi.physical_node_id * 
adev->gmc.xgmi.node_segment_size;
u64 vram_end = vram_addr + vram_size;
-   u64 gart_ptb_gpu_pa = amdgpu_bo_gpu_offset(adev->gart.bo) +
-   adev->vm_manager.vram_base_offset - adev->gmc.vram_start;
+   u64 gart_ptb_gpu_pa = amdgpu_gmc_vram_pa(adev, adev->gart.bo);
 
flags |= AMDGPU_PTE_VALID | AMDGPU_PTE_READABLE;
flags |= AMDGPU_PTE_WRITEABLE;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 5bb9856..9b78891 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -120,8 +120,7 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start +
-   adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_vram_pa(adev, adev->vram_scratch.robj);
WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
 (u32)(value >> 12));
WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
index 2aecc6a..ab41c8e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
@@ -165,8 +165,7 @@ static void gfxhub_v2_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start
-   + adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_vram_pa(adev, adev->vram_scratch.robj);
WREG32_SOC15(GC, 0, mmGCMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
 (u32)(value >> 12));
WREG32_SOC15(GC, 0, mmGCMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
index 410fd3a..4badd73 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
@@ -164,8 +164,7 @@ static void gfxhub_v2_1_init_system_aperture_regs(struct 
amdgpu_device *adev)
 max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start
-   + adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_vram_pa

[PATCH 1/4] drm/amdgpu: Introduce functions for vram physical addr calculation

2021-04-01 Thread Oak Zeng
Add one function to calculate BO's GPU physical address.
And another function to calculate BO's CPU physical address.

v2: Use functions vs macros (Christian)
Use more proper function names (Christian)

Signed-off-by: Oak Zeng 
Suggested-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 34 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  3 +++
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index b9d68fd..ca16649 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -665,3 +665,37 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
/* Requires gart_ptb_gpu_pa to be 4K aligned */
amdgpu_gmc_set_pte_pde(adev, adev->gmc.ptr_pdb0, i, gart_ptb_gpu_pa, 
flags);
 }
+
+/**
+ * amdgpu_gmc_vram_mc2pa - calculate vram buffer's physical address from MC
+ * address
+ *
+ * @adev: amdgpu_device pointer
+ * @mc_addr: MC address of buffer
+ */
+uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr)
+{
+   return mc_addr - adev->gmc.vram_start + 
adev->vm_manager.vram_base_offset;
+}
+/**
+ * amdgpu_gmc_vram_pa - calculate vram buffer object's physical address from
+ * GPU's view
+ *
+ * @adev: amdgpu_device pointer
+ * @bo: amdgpu buffer object
+ */
+uint64_t amdgpu_gmc_vram_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo)
+{
+   return amdgpu_gmc_vram_mc2pa(adev, amdgpu_bo_gpu_offset(bo));
+}
+/**
+ * amdgpu_gmc_vram_cpu_pa - calculate vram buffer object's physical address
+ * from CPU's view
+ *
+ * @adev: amdgpu_device pointer
+ * @bo: amdgpu buffer object
+ */
+uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo 
*bo)
+{
+   return amdgpu_bo_gpu_offset(bo) - adev->gmc.vram_start + 
adev->gmc.aper_base;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 7e248a4..bc374bc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -332,4 +332,7 @@ amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, 
int hub_type,
 void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev);
 
 void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
+uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
+uint64_t amdgpu_gmc_vram_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
+uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo 
*bo);
 #endif
-- 
2.7.4

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


[PATCH 4/4] Revert "drm/amdgpu: workaround the TMR MC address issue (v2)"

2021-04-01 Thread Oak Zeng
This reverts commit 34a33d4683cba7ba63c894132efb1998c0217631.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  9 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 10 --
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 21 ++---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 10 --
 4 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index bc374bc..59bbe59 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -209,15 +209,6 @@ struct amdgpu_gmc {
 */
u64 fb_start;
u64 fb_end;
-   /* In the case of use GART table for vmid0 FB access, [fb_start, fb_end]
-* will be squeezed to GART aperture. But we have a PSP FW issue to fix
-* for now. To temporarily workaround the PSP FW issue, added below two
-* variables to remember the original fb_start/end to re-enable FB
-* aperture to workaround the PSP FW issue. Will delete it after we
-* get a proper PSP FW fix.
-*/
-   u64 fb_start_original;
-   u64 fb_end_original;
unsignedvram_width;
u64 real_vram_size;
int vram_mtrr;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 123ab31..5298698 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -414,16 +414,6 @@ static int psp_tmr_init(struct psp_context *psp)
  AMDGPU_GEM_DOMAIN_VRAM,
  &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
 
-   /* workaround the tmr_mc_addr:
-* PSP requires an address in FB aperture. Right now driver produce
-* tmr_mc_addr in the GART aperture. Convert it back to FB aperture
-* for PSP. Will revert it after we get a fix from PSP FW.
-*/
-   if (psp->adev->asic_type == CHIP_ALDEBARAN) {
-   psp->tmr_mc_addr -= psp->adev->gmc.fb_start;
-   psp->tmr_mc_addr += psp->adev->gmc.fb_start_original;
-   }
-
return ret;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 9b78891..561b32e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -140,21 +140,12 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 * FB aperture and AGP aperture. Disable them.
 */
if (adev->gmc.pdb0_bo) {
-   if (adev->asic_type == CHIP_ALDEBARAN) {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 
adev->gmc.fb_end_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
adev->gmc.fb_start_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
adev->gmc.fb_start_original >> 18);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
adev->gmc.fb_end_original >> 18);
-   } else {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
0x00FF);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
0);
-   }
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 0x00FF);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 0);
}
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index d341d17..71914f0 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -47,8 +47,6 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
 
adev->gmc.fb_start = base;
adev->gmc.fb_end = top;
-   adev->gmc.fb_start_original = base;
-   adev->gmc.fb_end_original = top;
 
return base;
 }
@@ -126,10 +124,10 @@ static void mmhub_v1_7_init_system_aperture_regs(struct 

[PATCH 3/4] drm/amdgpu: Introduce new SETUP_TMR interface

2021-04-01 Thread Oak Zeng
This new interface passes both virtual and physical address
to PSP. It is backword compatible with old interface.

v2: use a function to simply tmr physical address calc (Lijo)

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 12 +---
 drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h | 11 ++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 9e769cf..123ab31 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -328,8 +328,12 @@ psp_cmd_submit_buf(struct psp_context *psp,
 
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
-uint64_t tmr_mc, uint32_t size)
+uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
 {
+   struct amdgpu_device *adev = psp->adev;
+   uint32_t size = amdgpu_bo_size(tmr_bo);
+   uint64_t tmr_pa = amdgpu_gmc_vram_pa(adev, tmr_bo);
+
if (amdgpu_sriov_vf(psp->adev))
cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
else
@@ -337,6 +341,9 @@ static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_size = size;
+   cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
 }
 
 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
@@ -466,8 +473,7 @@ static int psp_tmr_load(struct psp_context *psp)
if (!cmd)
return -ENOMEM;
 
-   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr,
-amdgpu_bo_size(psp->tmr_bo));
+   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h 
b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
index dd4d65f..96064c3 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
+++ b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
@@ -185,10 +185,19 @@ struct psp_gfx_cmd_setup_tmr
 uint32_tbuf_phy_addr_lo;   /* bits [31:0] of GPU Virtual 
address of TMR buffer (must be 4 KB aligned) */
 uint32_tbuf_phy_addr_hi;   /* bits [63:32] of GPU Virtual 
address of TMR buffer */
 uint32_tbuf_size;  /* buffer size in bytes (must be 
multiple of 4 KB) */
+union {
+   struct {
+   uint32_tsriov_enabled:1; /* whether the device runs 
under SR-IOV*/
+   uint32_tvirt_phy_addr:1; /* driver passes both virtual 
and physical address to PSP*/
+   uint32_treserved:30;
+   } bitfield;
+   uint32_ttmr_flags;
+};
+uint32_tsystem_phy_addr_lo;/* bits [31:0] of system 
physical address of TMR buffer (must be 4 KB aligned) */
+uint32_tsystem_phy_addr_hi;/* bits [63:32] of system 
physical address of TMR buffer */
 
 };
 
-
 /* FW types for GFX_CMD_ID_LOAD_IP_FW command. Limit 31. */
 enum psp_gfx_fw_type {
GFX_FW_TYPE_NONE= 0,/* */
-- 
2.7.4

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


[PATCH 3/4] Revert "drm/amdgpu: workaround the TMR MC address issue (v2)"

2021-03-30 Thread Oak Zeng
This reverts commit 34a33d4683cba7ba63c894132efb1998c0217631.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  9 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 10 --
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 21 ++---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 10 --
 4 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index b244298..5f53d4b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -209,15 +209,6 @@ struct amdgpu_gmc {
 */
u64 fb_start;
u64 fb_end;
-   /* In the case of use GART table for vmid0 FB access, [fb_start, fb_end]
-* will be squeezed to GART aperture. But we have a PSP FW issue to fix
-* for now. To temporarily workaround the PSP FW issue, added below two
-* variables to remember the original fb_start/end to re-enable FB
-* aperture to workaround the PSP FW issue. Will delete it after we
-* get a proper PSP FW fix.
-*/
-   u64 fb_start_original;
-   u64 fb_end_original;
unsignedvram_width;
u64 real_vram_size;
int vram_mtrr;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 9e769cf..c555fa7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -407,16 +407,6 @@ static int psp_tmr_init(struct psp_context *psp)
  AMDGPU_GEM_DOMAIN_VRAM,
  &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
 
-   /* workaround the tmr_mc_addr:
-* PSP requires an address in FB aperture. Right now driver produce
-* tmr_mc_addr in the GART aperture. Convert it back to FB aperture
-* for PSP. Will revert it after we get a fix from PSP FW.
-*/
-   if (psp->adev->asic_type == CHIP_ALDEBARAN) {
-   psp->tmr_mc_addr -= psp->adev->gmc.fb_start;
-   psp->tmr_mc_addr += psp->adev->gmc.fb_start_original;
-   }
-
return ret;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 8c0710c..a245e8a 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -140,21 +140,12 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 * FB aperture and AGP aperture. Disable them.
 */
if (adev->gmc.pdb0_bo) {
-   if (adev->asic_type == CHIP_ALDEBARAN) {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 
adev->gmc.fb_end_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
adev->gmc.fb_start_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
adev->gmc.fb_start_original >> 18);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
adev->gmc.fb_end_original >> 18);
-   } else {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
0x00FF);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
0);
-   }
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 0x00FF);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 0);
}
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index 2d8cf7f..7a1880d50 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -47,8 +47,6 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
 
adev->gmc.fb_start = base;
adev->gmc.fb_end = top;
-   adev->gmc.fb_start_original = base;
-   adev->gmc.fb_end_original = top;
 
return base;
 }
@@ -126,10 +124,10 @@ static void mmhub_v1_7_init_system_aperture_regs(struct 

[PATCH 2/4] drm/amdgpu: use macros to simplify codes

2021-03-30 Thread Oak Zeng
Use amdgpu_gmc_gpu_pa and amdgpu_gmc_cpu_pa
to simplify codes. No logic change.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c   | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c| 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c  | 3 +--
 12 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index 4c5c198..564446b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -205,7 +205,6 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
struct drm_gem_object *gobj = NULL;
struct amdgpu_bo *abo = NULL;
int ret;
-   unsigned long tmp;
 
memset(&mode_cmd, 0, sizeof(mode_cmd));
mode_cmd.width = sizes->surface_width;
@@ -246,8 +245,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
 
info->fbops = &amdgpufb_ops;
 
-   tmp = amdgpu_bo_gpu_offset(abo) - adev->gmc.vram_start;
-   info->fix.smem_start = adev->gmc.aper_base + tmp;
+   info->fix.smem_start = amdgpu_gmc_cpu_pa(adev, abo);
info->fix.smem_len = amdgpu_bo_size(abo);
info->screen_base = amdgpu_bo_kptr(abo);
info->screen_size = amdgpu_bo_size(abo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index b9d68fd..ca659e7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -641,8 +641,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
u64 vram_addr = adev->vm_manager.vram_base_offset -
adev->gmc.xgmi.physical_node_id * 
adev->gmc.xgmi.node_segment_size;
u64 vram_end = vram_addr + vram_size;
-   u64 gart_ptb_gpu_pa = amdgpu_bo_gpu_offset(adev->gart.bo) +
-   adev->vm_manager.vram_base_offset - adev->gmc.vram_start;
+   u64 gart_ptb_gpu_pa = amdgpu_gmc_gpu_pa(adev, adev->gart.bo);
 
flags |= AMDGPU_PTE_VALID | AMDGPU_PTE_READABLE;
flags |= AMDGPU_PTE_WRITEABLE;
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 5bb9856..8c0710c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -120,8 +120,7 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start +
-   adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_gpu_pa(adev, adev->vram_scratch.robj);
WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
 (u32)(value >> 12));
WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
index 2aecc6a..c2fa371c 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c
@@ -165,8 +165,7 @@ static void gfxhub_v2_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start
-   + adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_gpu_pa(adev, adev->vram_scratch.robj);
WREG32_SOC15(GC, 0, mmGCMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_LSB,
 (u32)(value >> 12));
WREG32_SOC15(GC, 0, mmGCMC_VM_SYSTEM_APERTURE_DEFAULT_ADDR_MSB,
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
index 410fd3a..9b575eb 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c
@@ -164,8 +164,7 @@ static void gfxhub_v2_1_init_system_aperture_regs(struct 
amdgpu_device *adev)
 max(adev->gmc.fb_end, adev->gmc.agp_end) >> 18);
 
/* Set default page address. */
-   value = adev->vram_scratch.gpu_addr - adev->gmc.vram_start
-   + adev->vm_manager.vram_base_offset;
+   value = amdgpu_gmc_gpu_pa(adev,

[PATCH 4/4] drm/amdgpu: Introduce new SETUP_TMR interface

2021-03-30 Thread Oak Zeng
This new interface passes both virtual and physical address
to PSP. It is backword compatible with old interface.

v2: use a macro to simply tmr physical address calc (Lijo)

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 12 +---
 drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h | 11 ++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c555fa7..77a9dd1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -328,8 +328,12 @@ psp_cmd_submit_buf(struct psp_context *psp,
 
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
-uint64_t tmr_mc, uint32_t size)
+uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
 {
+   struct amdgpu_device *adev = psp->adev;
+   uint32_t size = amdgpu_bo_size(tmr_bo);
+   uint64_t tmr_pa = amdgpu_gmc_gpu_pa(adev, tmr_bo);
+
if (amdgpu_sriov_vf(psp->adev))
cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
else
@@ -337,6 +341,9 @@ static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_size = size;
+   cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
 }
 
 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
@@ -456,8 +463,7 @@ static int psp_tmr_load(struct psp_context *psp)
if (!cmd)
return -ENOMEM;
 
-   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr,
-amdgpu_bo_size(psp->tmr_bo));
+   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h 
b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
index dd4d65f..96064c3 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
+++ b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
@@ -185,10 +185,19 @@ struct psp_gfx_cmd_setup_tmr
 uint32_tbuf_phy_addr_lo;   /* bits [31:0] of GPU Virtual 
address of TMR buffer (must be 4 KB aligned) */
 uint32_tbuf_phy_addr_hi;   /* bits [63:32] of GPU Virtual 
address of TMR buffer */
 uint32_tbuf_size;  /* buffer size in bytes (must be 
multiple of 4 KB) */
+union {
+   struct {
+   uint32_tsriov_enabled:1; /* whether the device runs 
under SR-IOV*/
+   uint32_tvirt_phy_addr:1; /* driver passes both virtual 
and physical address to PSP*/
+   uint32_treserved:30;
+   } bitfield;
+   uint32_ttmr_flags;
+};
+uint32_tsystem_phy_addr_lo;/* bits [31:0] of system 
physical address of TMR buffer (must be 4 KB aligned) */
+uint32_tsystem_phy_addr_hi;/* bits [63:32] of system 
physical address of TMR buffer */
 
 };
 
-
 /* FW types for GFX_CMD_ID_LOAD_IP_FW command. Limit 31. */
 enum psp_gfx_fw_type {
GFX_FW_TYPE_NONE= 0,/* */
-- 
2.7.4

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


[PATCH 1/4] drm/amdgpu: Macros for vram physical addr calculation

2021-03-30 Thread Oak Zeng
Add one macro to calculate BO's GPU physical address.
And another one to calculate BO's CPU physical address.

Signed-off-by: Oak Zeng 
Suggested-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 7e248a4..b244298 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -272,6 +272,9 @@ struct amdgpu_gmc {
 #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) 
(adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
 #define amdgpu_gmc_get_vm_pte(adev, mapping, flags) 
(adev)->gmc.gmc_funcs->get_vm_pte((adev), (mapping), (flags))
 #define amdgpu_gmc_get_vbios_fb_size(adev) 
(adev)->gmc.gmc_funcs->get_vbios_fb_size((adev))
+#define amdgpu_gmc_gpu_va2pa(adev, va) (va - (adev)->gmc.vram_start + 
(adev)->vm_manager.vram_base_offset)
+#define amdgpu_gmc_gpu_pa(adev, bo) amdgpu_gmc_gpu_va2pa(adev, 
amdgpu_bo_gpu_offset(bo))
+#define amdgpu_gmc_cpu_pa(adev, bo) (amdgpu_bo_gpu_offset(bo) - 
(adev)->gmc.vram_start + (adev)->gmc.aper_base)
 
 /**
  * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR
-- 
2.7.4

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


[PATCH 4/4] drm/amdgpu: Introduce new SETUP_TMR interface

2021-03-25 Thread Oak Zeng
This new interface passes both virtual and physical address
to PSP. It is backword compatible with old interface.

v2: use a macro to simply tmr physical address calc (Lijo)

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 12 +---
 drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h | 11 ++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 1005124..d224c53 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -331,8 +331,12 @@ psp_cmd_submit_buf(struct psp_context *psp,
 
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
-uint64_t tmr_mc, uint32_t size)
+uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
 {
+   struct amdgpu_device *adev = psp->adev;
+   uint32_t size = amdgpu_bo_size(tmr_bo);
+   uint64_t tmr_pa = amdgpu_gmc_gpu_pa(adev, tmr_bo);
+
if (amdgpu_sriov_vf(psp->adev))
cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
else
@@ -340,6 +344,9 @@ static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_size = size;
+   cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
 }
 
 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
@@ -459,8 +466,7 @@ static int psp_tmr_load(struct psp_context *psp)
if (!cmd)
return -ENOMEM;
 
-   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr,
-amdgpu_bo_size(psp->tmr_bo));
+   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h 
b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
index 8c1d0b5..edc5d75 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
+++ b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
@@ -170,10 +170,19 @@ struct psp_gfx_cmd_setup_tmr
 uint32_tbuf_phy_addr_lo;   /* bits [31:0] of GPU Virtual 
address of TMR buffer (must be 4 KB aligned) */
 uint32_tbuf_phy_addr_hi;   /* bits [63:32] of GPU Virtual 
address of TMR buffer */
 uint32_tbuf_size;  /* buffer size in bytes (must be 
multiple of 4 KB) */
+union {
+   struct {
+   uint32_tsriov_enabled:1; /* whether the device runs 
under SR-IOV*/
+   uint32_tvirt_phy_addr:1; /* driver passes both virtual 
and physical address to PSP*/
+   uint32_treserved:30;
+   } bitfield;
+   uint32_ttmr_flags;
+};
+uint32_tsystem_phy_addr_lo;/* bits [31:0] of system 
physical address of TMR buffer (must be 4 KB aligned) */
+uint32_tsystem_phy_addr_hi;/* bits [63:32] of system 
physical address of TMR buffer */
 
 };
 
-
 /* FW types for GFX_CMD_ID_LOAD_IP_FW command. Limit 31. */
 enum psp_gfx_fw_type {
GFX_FW_TYPE_NONE= 0,/* */
-- 
2.7.4

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


[PATCH 3/4] Revert "drm/amdgpu: workaround the TMR MC address issue (v2)"

2021-03-25 Thread Oak Zeng
This reverts commit 34a33d4683cba7ba63c894132efb1998c0217631.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  9 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 10 --
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 21 ++---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 10 --
 4 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 7cd9d34..a9e0bba 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -217,15 +217,6 @@ struct amdgpu_gmc {
 */
u64 fb_start;
u64 fb_end;
-   /* In the case of use GART table for vmid0 FB access, [fb_start, fb_end]
-* will be squeezed to GART aperture. But we have a PSP FW issue to fix
-* for now. To temporarily workaround the PSP FW issue, added below two
-* variables to remember the original fb_start/end to re-enable FB
-* aperture to workaround the PSP FW issue. Will delete it after we
-* get a proper PSP FW fix.
-*/
-   u64 fb_start_original;
-   u64 fb_end_original;
unsignedvram_width;
u64 real_vram_size;
int vram_mtrr;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 5c71c5c..1005124 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -410,16 +410,6 @@ static int psp_tmr_init(struct psp_context *psp)
  AMDGPU_GEM_DOMAIN_VRAM,
  &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
 
-   /* workaround the tmr_mc_addr:
-* PSP requires an address in FB aperture. Right now driver produce
-* tmr_mc_addr in the GART aperture. Convert it back to FB aperture
-* for PSP. Will revert it after we get a fix from PSP FW.
-*/
-   if (psp->adev->asic_type == CHIP_ALDEBARAN) {
-   psp->tmr_mc_addr -= psp->adev->gmc.fb_start;
-   psp->tmr_mc_addr += psp->adev->gmc.fb_start_original;
-   }
-
return ret;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 7beef4c..8c8f0d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -154,21 +154,12 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 * FB aperture and AGP aperture. Disable them.
 */
if (adev->gmc.pdb0_bo) {
-   if (adev->asic_type == CHIP_ALDEBARAN) {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 
adev->gmc.fb_end_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
adev->gmc.fb_start_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
adev->gmc.fb_start_original >> 18);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
adev->gmc.fb_end_original >> 18);
-   } else {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
0x00FF);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
0);
-   }
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 0x00FF);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 0);
}
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index 8862ac2..8bb36d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -51,8 +51,6 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
 
adev->gmc.fb_start = base;
adev->gmc.fb_end = top;
-   adev->gmc.fb_start_original = base;
-   adev->gmc.fb_end_original = top;
 
return base;
 }
@@ -148,10 +146,10 @@ static void mmhub_v1_7_init_system_aperture_regs(struct 

[PATCH 1/4] drm/amdgpu: Macros for vram physical addr calculation

2021-03-25 Thread Oak Zeng
Add one macro to calculate BO's GPU physical address.
And another one to calculate BO's CPU physical address.

Signed-off-by: Oak Zeng 
Suggested-by: Lijo Lazar 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 2ee8d1b..7cd9d34 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -283,6 +283,9 @@ struct amdgpu_gmc {
 #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) 
(adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
 #define amdgpu_gmc_get_vm_pte(adev, mapping, flags) 
(adev)->gmc.gmc_funcs->get_vm_pte((adev), (mapping), (flags))
 #define amdgpu_gmc_get_vbios_fb_size(adev) 
(adev)->gmc.gmc_funcs->get_vbios_fb_size((adev))
+#define amdgpu_gmc_gpu_va2pa(adev, va) (va - (adev)->gmc.vram_start + 
(adev)->vm_manager.vram_base_offset)
+#define amdgpu_gmc_gpu_pa(adev, bo) amdgpu_gmc_gpu_va2pa(adev, 
amdgpu_bo_gpu_offset(bo))
+#define amdgpu_gmc_cpu_pa(adev, bo) (amdgpu_bo_gpu_offset(bo) - 
(adev)->gmc.vram_start + (adev)->gmc.aper_base)
 
 /**
  * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR
-- 
2.7.4

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


[PATCH 2/4] drm/amdgpu: use macros to simplify codes

2021-03-25 Thread Oak Zeng
Use amdgpu_gmc_gpu_pa and amdgpu_gmc_cpu_pa
to simplify codes. No logic change.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c   | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c  | 4 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c  | 4 +---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c   | 3 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c| 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c  | 3 +--
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c  | 3 +--
 15 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 7357c1e..33581ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1831,8 +1831,7 @@ static int get_sg_table(struct amdgpu_device *adev,
goto out;
 
if (bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM) {
-   bus_addr = amdgpu_bo_gpu_offset(bo) - adev->gmc.vram_start
-  + adev->gmc.aper_base + offset;
+   bus_addr = amdgpu_gmc_cpu_pa(adev, bo) + offset;
aper_limit = adev->gmc.aper_base + adev->gmc.aper_size;
if (bus_addr + (chunks * page_size) > aper_limit) {
pr_err("sg: bus addr not inside pci aperture\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
index fd04a3a..dbeb774 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c
@@ -211,7 +211,6 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
struct drm_gem_object *gobj = NULL;
struct amdgpu_bo *abo = NULL;
int ret;
-   unsigned long tmp;
 
memset(&mode_cmd, 0, sizeof(mode_cmd));
mode_cmd.width = sizes->surface_width;
@@ -252,8 +251,7 @@ static int amdgpufb_create(struct drm_fb_helper *helper,
 
info->fbops = &amdgpufb_ops;
 
-   tmp = amdgpu_bo_gpu_offset(abo) - adev->gmc.vram_start;
-   info->fix.smem_start = adev->gmc.aper_base + tmp;
+   info->fix.smem_start = amdgpu_gmc_cpu_pa(adev, abo);
info->fix.smem_len = amdgpu_bo_size(abo);
info->screen_base = amdgpu_bo_kptr(abo);
info->screen_size = amdgpu_bo_size(abo);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 46a10c1..391d41f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -475,9 +475,7 @@ int amdgpu_gem_dgma_ioctl(struct drm_device *dev, void 
*data,
r = -EINVAL;
goto release_object;
}
-   args->addr = amdgpu_bo_gpu_offset(abo);
-   args->addr -= adev->gmc.vram_start;
-   args->addr += adev->gmc.aper_base;
+   args->addr = amdgpu_gmc_cpu_pa(adev, abo);
break;
default:
return -EINVAL;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index e6344a8..f02143a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -671,8 +671,7 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev)
u64 vram_addr = adev->vm_manager.vram_base_offset -
adev->gmc.xgmi.physical_node_id * 
adev->gmc.xgmi.node_segment_size;
u64 vram_end = vram_addr + vram_size;
-   u64 gart_ptb_gpu_pa = amdgpu_bo_gpu_offset(adev->gart.bo) +
-   adev->vm_manager.vram_base_offset - adev->gmc.vram_start;
+   u64 gart_ptb_gpu_pa = amdgpu_gmc_gpu_pa(adev, adev->gart.bo);
 
flags |= AMDGPU_PTE_VALID | AMDGPU_PTE_READABLE;
flags |= AMDGPU_PTE_WRITEABLE;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d1211ef..9c18e00 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2234,9 +2234,7 @@ static int amdgpu_ssg_init(struct amdgpu_device *adev)
 
init_completion(&adev->ssg.cmp);
 
-   res.start = adev->gmc.aper_base +
-   (amdgpu_bo_gpu_offset(adev->direct_gma.dgma_bo) -
-adev->gmc.vram_start);
+   res.start = amdgpu_gmc_cpu_pa(adev, adev->direct_gma.dgma_bo);
 

[PATCH 1/2] Revert "drm/amdgpu: workaround the TMR MC address issue (v2)"

2021-03-12 Thread Oak Zeng
This reverts commit 34a33d4683cba7ba63c894132efb1998c0217631.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  9 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 10 --
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c | 21 ++---
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 10 --
 4 files changed, 10 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
index 7e248a4..3ed8387 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
@@ -209,15 +209,6 @@ struct amdgpu_gmc {
 */
u64 fb_start;
u64 fb_end;
-   /* In the case of use GART table for vmid0 FB access, [fb_start, fb_end]
-* will be squeezed to GART aperture. But we have a PSP FW issue to fix
-* for now. To temporarily workaround the PSP FW issue, added below two
-* variables to remember the original fb_start/end to re-enable FB
-* aperture to workaround the PSP FW issue. Will delete it after we
-* get a proper PSP FW fix.
-*/
-   u64 fb_start_original;
-   u64 fb_end_original;
unsignedvram_width;
u64 real_vram_size;
int vram_mtrr;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index bae304b..cd3eda9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -407,16 +407,6 @@ static int psp_tmr_init(struct psp_context *psp)
  AMDGPU_GEM_DOMAIN_VRAM,
  &psp->tmr_bo, &psp->tmr_mc_addr, pptr);
 
-   /* workaround the tmr_mc_addr:
-* PSP requires an address in FB aperture. Right now driver produce
-* tmr_mc_addr in the GART aperture. Convert it back to FB aperture
-* for PSP. Will revert it after we get a fix from PSP FW.
-*/
-   if (psp->adev->asic_type == CHIP_ALDEBARAN) {
-   psp->tmr_mc_addr -= psp->adev->gmc.fb_start;
-   psp->tmr_mc_addr += psp->adev->gmc.fb_start_original;
-   }
-
return ret;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
index 5bb9856..91c43a6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c
@@ -141,21 +141,12 @@ static void gfxhub_v1_0_init_system_aperture_regs(struct 
amdgpu_device *adev)
 * FB aperture and AGP aperture. Disable them.
 */
if (adev->gmc.pdb0_bo) {
-   if (adev->asic_type == CHIP_ALDEBARAN) {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 
adev->gmc.fb_end_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
adev->gmc.fb_start_original >> 24);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
adev->gmc.fb_start_original >> 18);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
adev->gmc.fb_end_original >> 18);
-   } else {
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 
0x00FF);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
-   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
-   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 
0);
-   }
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_FB_LOCATION_BASE, 0x00FF);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_TOP, 0);
+   WREG32_SOC15(GC, 0, mmMC_VM_AGP_BOT, 0xFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_LOW_ADDR, 
0x3FFF);
+   WREG32_SOC15(GC, 0, mmMC_VM_SYSTEM_APERTURE_HIGH_ADDR, 0);
}
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index 29d7f50..0b056bc5 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -47,8 +47,6 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
 
adev->gmc.fb_start = base;
adev->gmc.fb_end = top;
-   adev->gmc.fb_start_original = base;
-   adev->gmc.fb_end_original = top;
 
return base;
 }
@@ -126,10 +124,10 @@ static void mmhub_v1_7_init_system_aperture_regs(struct 

[PATCH 2/2] drm/amdgpu: Introduce new SETUP_TMR interface

2021-03-12 Thread Oak Zeng
This new interface passes both virtual and physical address
to PSP. It is backword compatible with old interface.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 13 ++---
 drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h | 11 ++-
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index cd3eda9..99e1a3e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -328,8 +328,13 @@ psp_cmd_submit_buf(struct psp_context *psp,
 
 static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
 struct psp_gfx_cmd_resp *cmd,
-uint64_t tmr_mc, uint32_t size)
+uint64_t tmr_mc, struct amdgpu_bo *tmr_bo)
 {
+   struct amdgpu_device *adev = psp->adev;
+   uint32_t size = amdgpu_bo_size(tmr_bo);
+   uint64_t tmr_pa = amdgpu_bo_gpu_offset(tmr_bo) +
+   adev->vm_manager.vram_base_offset - adev->gmc.vram_start;
+
if (amdgpu_sriov_vf(psp->adev))
cmd->cmd_id = GFX_CMD_ID_SETUP_VMR;
else
@@ -337,6 +342,9 @@ static void psp_prep_tmr_cmd_buf(struct psp_context *psp,
cmd->cmd.cmd_setup_tmr.buf_phy_addr_lo = lower_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_phy_addr_hi = upper_32_bits(tmr_mc);
cmd->cmd.cmd_setup_tmr.buf_size = size;
+   cmd->cmd.cmd_setup_tmr.bitfield.virt_phy_addr = 1;
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_lo = lower_32_bits(tmr_pa);
+   cmd->cmd.cmd_setup_tmr.system_phy_addr_hi = upper_32_bits(tmr_pa);
 }
 
 static void psp_prep_load_toc_cmd_buf(struct psp_gfx_cmd_resp *cmd,
@@ -456,8 +464,7 @@ static int psp_tmr_load(struct psp_context *psp)
if (!cmd)
return -ENOMEM;
 
-   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr,
-amdgpu_bo_size(psp->tmr_bo));
+   psp_prep_tmr_cmd_buf(psp, cmd, psp->tmr_mc_addr, psp->tmr_bo);
DRM_INFO("reserve 0x%lx from 0x%llx for PSP TMR\n",
 amdgpu_bo_size(psp->tmr_bo), psp->tmr_mc_addr);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h 
b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
index a41b054..604a1c1 100644
--- a/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
+++ b/drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h
@@ -170,10 +170,19 @@ struct psp_gfx_cmd_setup_tmr
 uint32_tbuf_phy_addr_lo;   /* bits [31:0] of GPU Virtual 
address of TMR buffer (must be 4 KB aligned) */
 uint32_tbuf_phy_addr_hi;   /* bits [63:32] of GPU Virtual 
address of TMR buffer */
 uint32_tbuf_size;  /* buffer size in bytes (must be 
multiple of 4 KB) */
+union {
+   struct {
+   uint32_tsriov_enabled:1; /* whether the device runs 
under SR-IOV*/
+   uint32_tvirt_phy_addr:1; /* driver passes both virtual 
and physical address to PSP*/
+   uint32_treserved:30;
+   } bitfield;
+   uint32_ttmr_flags;
+};
+uint32_tsystem_phy_addr_lo;/* bits [31:0] of system 
physical address of TMR buffer (must be 4 KB aligned) */
+uint32_tsystem_phy_addr_hi;/* bits [63:32] of system 
physical address of TMR buffer */
 
 };
 
-
 /* FW types for GFX_CMD_ID_LOAD_IP_FW command. Limit 31. */
 enum psp_gfx_fw_type {
GFX_FW_TYPE_NONE= 0,/* */
-- 
2.7.4

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


[PATCH 2/2] drm/amdgpu: fix a few compiler warnings

2021-03-10 Thread Oak Zeng
1. make function mmhub_v1_7_setup_vm_pt_regs static
2. indent a if statement

Signed-off-by: Oak Zeng 
Reported-by: kernel test robot 
Reported-by: Dan Carpenter 
---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c  | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c 
b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c
index 3b4193c..8fca72e 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c
@@ -88,14 +88,14 @@ int gfxhub_v1_1_get_xgmi_info(struct amdgpu_device *adev)
adev->gmc.xgmi.num_physical_nodes = max_region + 1;
 
if (adev->gmc.xgmi.num_physical_nodes > max_num_physical_nodes)
-   return -EINVAL;
+   return -EINVAL;
 
adev->gmc.xgmi.physical_node_id =
REG_GET_FIELD(xgmi_lfb_cntl, MC_VM_XGMI_LFB_CNTL,
  PF_LFB_REGION);
 
if (adev->gmc.xgmi.physical_node_id > max_physical_node_id)
-   return -EINVAL;
+   return -EINVAL;
 
adev->gmc.xgmi.node_segment_size = seg_size;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
index ac74d66..29d7f50 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v1_7.c
@@ -53,7 +53,7 @@ static u64 mmhub_v1_7_get_fb_location(struct amdgpu_device 
*adev)
return base;
 }
 
-void mmhub_v1_7_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t vmid,
+static void mmhub_v1_7_setup_vm_pt_regs(struct amdgpu_device *adev, uint32_t 
vmid,
uint64_t page_table_base)
 {
struct amdgpu_vmhub *hub = &adev->vmhub[AMDGPU_MMHUB_0];
-- 
2.7.4

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


[PATCH 1/2] drm/amdgpu: fix compile error on architecture s390

2021-03-10 Thread Oak Zeng
ioremap_cache is not supported on some architecture
such as s390. Put the codes into a #ifdef to fix
some compile error reported by test robot.

Signed-off-by: Oak Zeng 
Reported-by: Kernel test robot 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 37751e7..1091585 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1817,7 +1817,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 
/* Change the size here instead of the init above so only lpfn is 
affected */
amdgpu_ttm_set_buffer_funcs_status(adev, false);
-#ifdef CONFIG_64BIT
+#ifdef CONFIG_X86
if (adev->gmc.xgmi.connected_to_cpu)
adev->mman.aper_base_kaddr = ioremap_cache(adev->gmc.aper_base,
adev->gmc.visible_vram_size);
-- 
2.7.4

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


[PATCH] drm/ttm: ioremap buffer according to TTM mem caching setting

2021-03-04 Thread Oak Zeng
If tbo.mem.bus.caching is cached, buffer is intended to be mapped
as cached from CPU. Map it with ioremap_cache.

This wasn't necessary before as device memory was never mapped
as cached from CPU side. It becomes necessary for aldebaran as
device memory is mapped cached from CPU.

Signed-off-by: Oak Zeng 
Reviewed-by: Christian Konig 
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c 
b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 031e581..7429464 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -91,6 +91,10 @@ static int ttm_resource_ioremap(struct ttm_device *bdev,
 
if (mem->bus.caching == ttm_write_combined)
addr = ioremap_wc(mem->bus.offset, bus_size);
+#ifdef CONFIG_X86
+   else if (mem->bus.caching == ttm_cached)
+   addr = ioremap_cache(mem->bus.offset, bus_size);
+#endif
else
addr = ioremap(mem->bus.offset, bus_size);
if (!addr) {
@@ -372,6 +376,11 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
if (mem->bus.caching == ttm_write_combined)
map->virtual = ioremap_wc(bo->mem.bus.offset + offset,
  size);
+#ifdef CONFIG_X86
+   else if (mem->bus.caching == ttm_cached)
+   map->virtual = ioremap_cache(bo->mem.bus.offset + 
offset,
+ size);
+#endif
else
map->virtual = ioremap(bo->mem.bus.offset + offset,
   size);
@@ -490,6 +499,11 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct 
dma_buf_map *map)
else if (mem->bus.caching == ttm_write_combined)
vaddr_iomem = ioremap_wc(mem->bus.offset,
 bo->base.size);
+   else if (mem->bus.caching == ttm_cached)
+#ifdef CONFIG_X86
+   vaddr_iomem = ioremap_cache(mem->bus.offset,
+ bo->base.size);
+#endif
else
vaddr_iomem = ioremap(mem->bus.offset, bo->base.size);
 
-- 
2.7.4

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


[PATCH] drm/ttm: ioremap buffer according to TTM mem caching setting

2021-03-03 Thread Oak Zeng
If tbo.mem.bus.caching is cached, buffer is intended to be mapped
as cached from CPU. Map it with ioremap_cache.

This wasn't necessary before as device memory was never mapped
as cached from CPU side. It becomes necessary for aldebaran as
device memory is mapped cached from CPU.

Signed-off-by: Oak Zeng 
Reviewed-by: Christian Konig 
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c 
b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 031e581..7c848e2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -91,6 +91,10 @@ static int ttm_resource_ioremap(struct ttm_device *bdev,
 
if (mem->bus.caching == ttm_write_combined)
addr = ioremap_wc(mem->bus.offset, bus_size);
+#ifdef __x86_64__
+   else if (mem->bus.caching == ttm_cached)
+   addr = ioremap_cache(mem->bus.offset, bus_size);
+#endif
else
addr = ioremap(mem->bus.offset, bus_size);
if (!addr) {
@@ -372,6 +376,11 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
if (mem->bus.caching == ttm_write_combined)
map->virtual = ioremap_wc(bo->mem.bus.offset + offset,
  size);
+#ifdef __x86_64__
+   else if (mem->bus.caching == ttm_cached)
+   map->virtual = ioremap_cache(bo->mem.bus.offset + 
offset,
+ size);
+#endif
else
map->virtual = ioremap(bo->mem.bus.offset + offset,
   size);
@@ -490,6 +499,11 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct 
dma_buf_map *map)
else if (mem->bus.caching == ttm_write_combined)
vaddr_iomem = ioremap_wc(mem->bus.offset,
 bo->base.size);
+   else if (mem->bus.caching == ttm_cached)
+#ifdef __x86_64__
+   vaddr_iomem = ioremap_cache(mem->bus.offset,
+ bo->base.size);
+#endif
else
vaddr_iomem = ioremap(mem->bus.offset, bo->base.size);
 
-- 
2.7.4

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


[PATCH] drm/ttm: ioremap buffer according to TTM mem caching setting

2021-03-01 Thread Oak Zeng
If tbo.mem.bus.caching is cached, buffer is intended to be mapped
as cached from CPU. Map it with ioremap_cache.

This wasn't necessary before as device memory was never mapped
as cached from CPU side. It becomes necessary for aldebaran as
device memory is mapped cached from CPU.

Signed-off-by: Oak Zeng 
Reviewed-by: Christian Konig 
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c 
b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 031e581..8c65a13 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -91,6 +91,8 @@ static int ttm_resource_ioremap(struct ttm_device *bdev,
 
if (mem->bus.caching == ttm_write_combined)
addr = ioremap_wc(mem->bus.offset, bus_size);
+   else if (mem->bus.caching == ttm_cached)
+   addr = ioremap_cache(mem->bus.offset, bus_size);
else
addr = ioremap(mem->bus.offset, bus_size);
if (!addr) {
@@ -372,6 +374,9 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
if (mem->bus.caching == ttm_write_combined)
map->virtual = ioremap_wc(bo->mem.bus.offset + offset,
  size);
+   else if (mem->bus.caching == ttm_cached)
+   map->virtual = ioremap_cache(bo->mem.bus.offset + 
offset,
+ size);
else
map->virtual = ioremap(bo->mem.bus.offset + offset,
   size);
@@ -490,6 +495,9 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct 
dma_buf_map *map)
else if (mem->bus.caching == ttm_write_combined)
vaddr_iomem = ioremap_wc(mem->bus.offset,
 bo->base.size);
+   else if (mem->bus.caching == ttm_cached)
+   vaddr_iomem = ioremap_cache(mem->bus.offset,
+ bo->base.size);
else
vaddr_iomem = ioremap(mem->bus.offset, bo->base.size);
 
-- 
2.7.4

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


[PATCH] drm/amdgpu: Use free system memory size for kfd memory accounting

2021-01-20 Thread Oak Zeng
With the current kfd memory accounting scheme, kfd applications
can use up to 15/16 of total system memory. For system which
has small total system memory size it leaves small system memory
for OS. For example, if the system has totally 16GB of system
memory, this scheme leave OS and non-kfd applications only 1GB
of system memory. In many cases, this leads to OOM killer.

This patch changed the KFD system memory accounting scheme.
15/16 of free system memory when kfd driver load. This deduct
the system memory that OS already use.

Signed-off-by: Oak Zeng 
Suggested-by: Philip Yang 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index b147d75..e059367 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -45,7 +45,7 @@ int amdgpu_amdkfd_init(void)
int ret;
 
si_meminfo(&si);
-   amdgpu_amdkfd_total_mem_size = si.totalram - si.totalhigh;
+   amdgpu_amdkfd_total_mem_size = si.freeram - si.freehigh;
amdgpu_amdkfd_total_mem_size *= si.mem_unit;
 
 #ifdef CONFIG_HSA_AMD
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 58c8739..44d362b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -97,7 +97,7 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)
uint64_t mem;
 
si_meminfo(&si);
-   mem = si.totalram - si.totalhigh;
+   mem = si.freeram - si.freehigh;
mem *= si.mem_unit;
 
spin_lock_init(&kfd_mem_limit.mem_limit_lock);
-- 
2.7.4

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


[PATCH] drm/amdgpu: use function pointer for gfxhub functions

2020-09-17 Thread Oak Zeng
gfxhub functions are now called from function pointers,
instead of from asic-specific functions.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h|  4 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c |  3 +-
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c   |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c  |  5 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h | 43 ++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.c   | 10 
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_0.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.c   | 13 +-
 drivers/gpu/drm/amd/amdgpu/gfxhub_v1_1.h   |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.c   | 24 +++---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_0.h   | 10 +---
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.c   | 27 +++
 drivers/gpu/drm/amd/amdgpu/gfxhub_v2_1.h   | 12 +
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 53 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  | 28 +---
 15 files changed, 155 insertions(+), 83 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 13f92de..0d8ace9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -104,6 +104,7 @@
 #include "amdgpu_mes.h"
 #include "amdgpu_umc.h"
 #include "amdgpu_mmhub.h"
+#include "amdgpu_gfxhub.h"
 #include "amdgpu_df.h"
 
 #define MAX_GPU_INSTANCE   16
@@ -884,6 +885,9 @@ struct amdgpu_device {
/* mmhub */
struct amdgpu_mmhub mmhub;
 
+   /* gfxhub */
+   struct amdgpu_gfxhubgfxhub;
+
/* gfx */
struct amdgpu_gfx   gfx;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
index df0aab0..1529815 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10.c
@@ -32,7 +32,6 @@
 #include "v10_structs.h"
 #include "nv.h"
 #include "nvd.h"
-#include "gfxhub_v2_0.h"
 
 enum hqd_dequeue_request_type {
NO_ACTION = 0,
@@ -753,7 +752,7 @@ static void set_vm_context_page_table_base(struct kgd_dev 
*kgd, uint32_t vmid,
}
 
/* SDMA is on gfxhub as well for Navi1* series */
-   gfxhub_v2_0_setup_vm_pt_regs(adev, vmid, page_table_base);
+   adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
 }
 
 const struct kfd2kgd_calls gfx_v10_kfd2kgd = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
index e12623a..b7ea20e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v10_3.c
@@ -31,7 +31,6 @@
 #include "v10_structs.h"
 #include "nv.h"
 #include "nvd.h"
-#include "gfxhub_v2_1.h"
 
 enum hqd_dequeue_request_type {
NO_ACTION = 0,
@@ -657,7 +656,7 @@ static void set_vm_context_page_table_base_v10_3(struct 
kgd_dev *kgd, uint32_t v
struct amdgpu_device *adev = get_amdgpu_device(kgd);
 
/* SDMA is on gfxhub as well for Navi1* series */
-   gfxhub_v2_1_setup_vm_pt_regs(adev, vmid, page_table_base);
+   adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
 }
 
 #if 0
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index e6aede7..b824582 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -36,9 +36,6 @@
 #include "v9_structs.h"
 #include "soc15.h"
 #include "soc15d.h"
-#include "mmhub_v1_0.h"
-#include "gfxhub_v1_0.h"
-
 
 enum hqd_dequeue_request_type {
NO_ACTION = 0,
@@ -703,7 +700,7 @@ void kgd_gfx_v9_set_vm_context_page_table_base(struct 
kgd_dev *kgd,
 
adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
 
-   gfxhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);
+   adev->gfxhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
 }
 
 const struct kfd2kgd_calls gfx_v9_kfd2kgd = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
new file mode 100644
index 000..66ebc2e
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfxhub.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2020 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 withou

[PATCH 2/2] drm/amdgpu: More accurate description of a function param

2020-09-11 Thread Oak Zeng
Add more accurate description of the pe parameter of function
amdgpu_vm_sdma_udpate and amdgpu_vm_cpu_update

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c  | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
index 39c704a..0786e755 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_cpu.c
@@ -59,7 +59,7 @@ static int amdgpu_vm_cpu_prepare(struct 
amdgpu_vm_update_params *p,
  *
  * @p: see amdgpu_vm_update_params definition
  * @bo: PD/PT to update
- * @pe: kmap addr of the page entry
+ * @pe: byte offset of the PDE/PTE, relative to start of PDB/PTB
  * @addr: dst addr to write into pe
  * @count: number of page entries to update
  * @incr: increase next addr by incr bytes
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
index 189d46e..db79057 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c
@@ -155,7 +155,7 @@ static void amdgpu_vm_sdma_copy_ptes(struct 
amdgpu_vm_update_params *p,
  *
  * @p: see amdgpu_vm_update_params definition
  * @bo: PD/PT to update
- * @pe: addr of the page entry
+ * @pe: byte offset of the PDE/PTE, relative to start of PDB/PTB
  * @addr: dst addr to write into pe
  * @count: number of page entries to update
  * @incr: increase next addr by incr bytes
@@ -187,7 +187,7 @@ static void amdgpu_vm_sdma_set_ptes(struct 
amdgpu_vm_update_params *p,
  *
  * @p: see amdgpu_vm_update_params definition
  * @bo: PD/PT to update
- * @pe: addr of the page entry
+ * @pe: byte offset of the PDE/PTE, relative to start of PDB/PTB
  * @addr: dst addr to write into pe
  * @count: number of page entries to update
  * @incr: increase next addr by incr bytes
-- 
2.7.4

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


[PATCH 1/2] drm/amdgpu: Add comment to function amdgpu_ttm_alloc_gart

2020-09-11 Thread Oak Zeng
Add comments to refect what function does

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 63e5414..8b70445 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1210,7 +1210,12 @@ static int amdgpu_ttm_backend_bind(struct ttm_tt *ttm,
 }
 
 /**
- * amdgpu_ttm_alloc_gart - Allocate GART memory for buffer object
+ * amdgpu_ttm_alloc_gart - Make sure buffer object is accessible either
+ * through AGP or GART aperture.
+ *
+ * If bo is accessible through AGP aperture, then use AGP aperture
+ * to access bo; otherwise allocate logical space in GART aperture
+ * and map bo to GART aperture.
  */
 int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 {
-- 
2.7.4

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


[PATCH] drm/amdgpu: Use function pointer for some mmhub functions

2020-08-11 Thread Oak Zeng
Add more function pointers to amdgpu_mmhub_funcs. ASIC specific
implementation of most mmhub functions are called from a general
function pointer, instead of calling different function for
different ASIC. Simplify the code by deleting duplicate functions

Change-Id: I65ba660c69b74c7e779190c4f92e9d7138f7c7d4
Signed-off-by: Oak Zeng 
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c| 21 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h  |  3 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mmhub.h  | 13 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 13 +++---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  | 48 ++
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c| 27 
 drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.h| 14 ---
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c| 25 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.h| 11 +
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c| 24 +++
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h| 12 --
 12 files changed, 94 insertions(+), 121 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
index 6529cac..b914434 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_arcturus.c
@@ -284,22 +284,6 @@ static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void 
*mqd,
return 0;
 }
 
-static void kgd_set_vm_context_page_table_base(struct kgd_dev *kgd, uint32_t 
vmid,
-   uint64_t page_table_base)
-{
-   struct amdgpu_device *adev = get_amdgpu_device(kgd);
-
-   if (!amdgpu_amdkfd_is_kfd_vmid(adev, vmid)) {
-   pr_err("trying to set page table base for wrong VMID %u\n",
-  vmid);
-   return;
-   }
-
-   mmhub_v9_4_setup_vm_pt_regs(adev, vmid, page_table_base);
-
-   gfxhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);
-}
-
 const struct kfd2kgd_calls arcturus_kfd2kgd = {
.program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings,
.set_pasid_vmid_mapping = kgd_gfx_v9_set_pasid_vmid_mapping,
@@ -318,7 +302,8 @@ const struct kfd2kgd_calls arcturus_kfd2kgd = {
.wave_control_execute = kgd_gfx_v9_wave_control_execute,
.address_watch_get_offset = kgd_gfx_v9_address_watch_get_offset,
.get_atc_vmid_pasid_mapping_info =
-   kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,
-   .set_vm_context_page_table_base = kgd_set_vm_context_page_table_base,
+   kgd_gfx_v9_get_atc_vmid_pasid_mapping_info,
+   .set_vm_context_page_table_base =
+   kgd_gfx_v9_set_vm_context_page_table_base,
.get_hive_id = amdgpu_amdkfd_get_hive_id,
 };
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index 032d3c8..7e11625 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -679,7 +679,7 @@ uint32_t kgd_gfx_v9_address_watch_get_offset(struct kgd_dev 
*kgd,
return 0;
 }
 
-static void kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd,
+void kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd,
uint32_t vmid, uint64_t page_table_base)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
@@ -690,7 +690,7 @@ static void 
kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd,
return;
}
 
-   mmhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);
+   adev->mmhub.funcs->setup_vm_pt_regs(adev, vmid, page_table_base);
 
gfxhub_v1_0_setup_vm_pt_regs(adev, vmid, page_table_base);
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h
index aedf67d..f098e88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.h
@@ -60,3 +60,6 @@ uint32_t kgd_gfx_v9_address_watch_get_offset(struct kgd_dev 
*kgd,
 
 bool kgd_gfx_v9_get_atc_vmid_pasid_mapping_info(struct kgd_dev *kgd,
uint8_t vmid, uint16_t *p_pasid);
+
+void kgd_gfx_v9_set_vm_context_page_table_base(struct kgd_dev *kgd,
+   uint32_t vmid, uint64_t page_table_base);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mmhub.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_mmhub.h
index e89fb35..0c43d7f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mmhub.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mmhub.h
@@ -27,6 +27,19 @@ struct amdgpu_mmhub_funcs {
void (*query_ras_error_count)(struct amdgpu_device *adev,
void *ras_error_status);
void (*reset_ras_error_count)(stru

[PATCH] drm/amdgpu: Print UTCL2 client ID on a gpuvm fault

2020-04-06 Thread Oak Zeng
UTCL2 client ID is useful information to get which
UTCL2 client caused the gpuvm fault. Print it out
for debug purpose

Change-Id: I733d0127b0ee53aa788f194cefa53cbb55b49c11
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
index 78d769e..94a6096 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
@@ -170,6 +170,9 @@ static int gmc_v10_0_process_interrupt(struct amdgpu_device 
*adev,
dev_err(adev->dev,
"GCVM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
status);
+   dev_err(adev->dev, "\t Faulty UTCL2 client ID: 0x%lx\n",
+   REG_GET_FIELD(status,
+   GCVM_L2_PROTECTION_FAULT_STATUS, CID));
dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",
REG_GET_FIELD(status,
GCVM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 8606f87..fecdbc4 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -362,6 +362,9 @@ static int gmc_v9_0_process_interrupt(struct amdgpu_device 
*adev,
dev_err(adev->dev,
"VM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
status);
+   dev_err(adev->dev, "\t Faulty UTCL2 client ID: 0x%lx\n",
+   REG_GET_FIELD(status,
+   VM_L2_PROTECTION_FAULT_STATUS, CID));
dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",
REG_GET_FIELD(status,
VM_L2_PROTECTION_FAULT_STATUS, MORE_FAULTS));
-- 
2.7.4

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


[PATCH] drm/amdgpu: Apply noretry setting for mmhub9.4

2019-11-22 Thread Oak Zeng
Config the translation retry behavior according to noretry
kernel parameter

Change-Id: I5b91ea77715137cf8cb84e258ccdfbb19c7a4ed1
Signed-off-by: Oak Zeng 
Suggested-by: Jay Cornwall 
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
index 753eea2..8599bfd 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
@@ -314,7 +314,8 @@ static void mmhub_v9_4_setup_vmid_config(struct 
amdgpu_device *adev, int hubid)
adev->vm_manager.block_size - 9);
/* Send no-retry XNACK on fault to suppress VM fault storm. */
tmp = REG_SET_FIELD(tmp, VML2VC0_VM_CONTEXT1_CNTL,
-   RETRY_PERMISSION_OR_INVALID_PAGE_FAULT, 0);
+   RETRY_PERMISSION_OR_INVALID_PAGE_FAULT,
+   !amdgpu_noretry);
WREG32_SOC15_OFFSET(MMHUB, 0, mmVML2VC0_VM_CONTEXT1_CNTL,
hubid * MMHUB_INSTANCE_REGISTER_OFFSET + i,
tmp);
@@ -905,4 +906,4 @@ static void mmhub_v9_4_query_ras_error_count(struct 
amdgpu_device *adev,
 const struct amdgpu_mmhub_funcs mmhub_v9_4_funcs = {
.ras_late_init = amdgpu_mmhub_ras_late_init,
.query_ras_error_count = mmhub_v9_4_query_ras_error_count,
-};
\ No newline at end of file
+};
-- 
2.7.4

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

[PATCH] drm/amdgpu: Apply noretry setting for gfx10 and mmhub9.4

2019-11-22 Thread Oak Zeng
Config the translation retry behavior according to noretry
kernel parameter

Change-Id: I5b91ea77715137cf8cb84e258ccdfbb19c7a4ed1
Signed-off-by: Oak Zeng 
Suggested-by: Jay Cornwall 
---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c  | 4 +++-
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 5 +++--
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
index 4d6df35..7435487 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c
@@ -1751,7 +1751,9 @@ static void gfx_v10_0_constants_init(struct amdgpu_device 
*adev)
for (i = 0; i < adev->vm_manager.id_mgr[AMDGPU_GFXHUB_0].num_ids; i++) {
nv_grbm_select(adev, 0, 0, 0, i);
/* CP and shaders */
-   WREG32_SOC15(GC, 0, mmSH_MEM_CONFIG, DEFAULT_SH_MEM_CONFIG);
+   tmp = REG_SET_FIELD(DEFAULT_SH_MEM_CONFIG, SH_MEM_CONFIG,
+   RETRY_MODE, amdgpu_noretry ? 2 : 0);
+   WREG32_SOC15(GC, 0, mmSH_MEM_CONFIG, tmp);
if (i != 0) {
tmp = REG_SET_FIELD(0, SH_MEM_BASES, PRIVATE_BASE,
(adev->gmc.private_aperture_start >> 48));
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c 
b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
index 753eea2..8599bfd 100644
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c
@@ -314,7 +314,8 @@ static void mmhub_v9_4_setup_vmid_config(struct 
amdgpu_device *adev, int hubid)
adev->vm_manager.block_size - 9);
/* Send no-retry XNACK on fault to suppress VM fault storm. */
tmp = REG_SET_FIELD(tmp, VML2VC0_VM_CONTEXT1_CNTL,
-   RETRY_PERMISSION_OR_INVALID_PAGE_FAULT, 0);
+   RETRY_PERMISSION_OR_INVALID_PAGE_FAULT,
+   !amdgpu_noretry);
WREG32_SOC15_OFFSET(MMHUB, 0, mmVML2VC0_VM_CONTEXT1_CNTL,
hubid * MMHUB_INSTANCE_REGISTER_OFFSET + i,
tmp);
@@ -905,4 +906,4 @@ static void mmhub_v9_4_query_ras_error_count(struct 
amdgpu_device *adev,
 const struct amdgpu_mmhub_funcs mmhub_v9_4_funcs = {
.ras_late_init = amdgpu_mmhub_ras_late_init,
.query_ras_error_count = mmhub_v9_4_query_ras_error_count,
-};
\ No newline at end of file
+};
-- 
2.7.4

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

[PATCH] drm/amdgpu: Fix num_doorbell calculation issue

2018-11-30 Thread Oak Zeng
When paging queue is enabled, it use the second page of doorbell.
The AMDGPU_DOORBELL64_MAX_ASSIGNMENT definition assumes all the
kernel doorbells are in the first page. So with paging queue enabled,
the total kernel doorbell range should be original num_doorbell plus
one page (0x400 in dword), not *2.

Change-Id: I62023bb91da33ca5532b22b263771b587b796d59
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 8eaa40e..c75badf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -539,10 +539,13 @@ static int amdgpu_device_doorbell_init(struct 
amdgpu_device *adev)
return -EINVAL;
 
/* For Vega, reserve and map two pages on doorbell BAR since SDMA
-* paging queue doorbell use the second page
+* paging queue doorbell use the second page. The
+* AMDGPU_DOORBELL64_MAX_ASSIGNMENT definition assumes all the
+* doorbells are in the first page. So with paging queue enabled,
+* the max num_doorbells should + 1 page (0x400 in dword)
 */
if (adev->asic_type >= CHIP_VEGA10)
-   adev->doorbell.num_doorbells *= 2;
+   adev->doorbell.num_doorbells += 0x400;
 
adev->doorbell.ptr = ioremap(adev->doorbell.base,
 adev->doorbell.num_doorbells *
-- 
2.7.4

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


[PATCH 3/8] drm/amdgpu: Vega10 doorbell index initialization

2018-11-26 Thread Oak Zeng
v2: Use enum definition instead of hardcoded value
v3: Remove unused enum definition

Change-Id: Ib72058337f0aa53adfc6c6aae5341a7cd665111a
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  | 14 --
 drivers/gpu/drm/amd/amdgpu/soc15.c   |  1 +
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 28 
 4 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 686652d..ea4dbcf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -434,20 +434,14 @@ typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
 * default non-graphics QWORD index is 0xe0 - 0xFF inclusive
 */
 
-   /* sDMA engines  reserved from 0xe0 -0xef  */
-   AMDGPU_DOORBELL64_sDMA_ENGINE0= 0xE0,
-   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xE1,
-   AMDGPU_DOORBELL64_sDMA_ENGINE1= 0xE8,
-   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xE9,
-
/* For vega10 sriov, the sdma doorbell must be fixed as follow
 * to keep the same setting with host driver, or it will
 * happen conflicts
 */
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0= 0xF0,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1= 0xF2,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
+   AMDGPU_DOORBELL64_sDMA_ENGINE0= 0xF0,
+   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
+   AMDGPU_DOORBELL64_sDMA_ENGINE1= 0xF2,
+   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
 
/* Interrupt handler */
AMDGPU_DOORBELL64_IH  = 0xF4,  /* For legacy 
interrupt ring buffer */
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 4cc0dcb..cae25dd 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -613,6 +613,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs =
.flush_hdp = &soc15_flush_hdp,
.invalidate_hdp = &soc15_invalidate_hdp,
.need_full_reset = &soc15_need_full_reset,
+   .init_doorbell_index = &vega10_doorbell_index_init,
 };
 
 static int soc15_common_early_init(void *handle)
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index f8ad780..d37c57d 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -58,4 +58,5 @@ void soc15_program_register_sequence(struct amdgpu_device 
*adev,
 int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
index c5c9b2b..422674b 100644
--- a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
@@ -56,4 +56,32 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
return 0;
 }
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL64_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL64_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL64_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL64_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL64_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL64_MEC_RING7;
+   adev->doorbell_index.userqueue_start = 
AMDGPU_DOORBELL64_USERQUEUE_START;
+   adev->doorbell_index.userqueue_end = AMDGPU_DOORBELL64_USERQUEUE_END;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL64_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = AMDGPU_DOORBELL64_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = AMDGPU_DOORBELL64_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL64_IH;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 
AMDGPU_DOORBELL64_UVD_RING0_1;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 
AMDGPU_DOORBELL64_UVD_RING2_3;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 
AMDGPU_DOORBELL64_UVD_RING4_5;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 
AMDGPU_DOORBELL64_UVD_RING6_7;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 
AMDGPU_DOORBELL64_VCE_RING0_1;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 
AMDGPU_DOORBELL64_VCE_RING2_3;
+ 

[PATCH 7/8] drm/amdgpu: Use asic specific doorbell index instead of macro definition

2018-11-26 Thread Oak Zeng
Change-Id: I84475efcfb482c474fccb133010abb5df5f4
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 27 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  | 10 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  |  8 
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 25 +
 drivers/gpu/drm/amd/amdgpu/tonga_ih.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c |  2 +-
 12 files changed, 36 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 1c1fed6..d693b804 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -181,25 +181,14 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 * process in case of 64-bit doorbells so we
 * can use each doorbell assignment twice.
 */
-   if (adev->asic_type == CHIP_VEGA10) {
-   gpu_resources.sdma_doorbell[0][i] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 + 
(i >> 1);
-   gpu_resources.sdma_doorbell[0][i+1] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 + 
0x200 + (i >> 1);
-   gpu_resources.sdma_doorbell[1][i] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 + 
(i >> 1);
-   gpu_resources.sdma_doorbell[1][i+1] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 + 
0x200 + (i >> 1);
-   } else {
-   gpu_resources.sdma_doorbell[0][i] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE0 + (i >> 
1);
-   gpu_resources.sdma_doorbell[0][i+1] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE0 + 0x200 
+ (i >> 1);
-   gpu_resources.sdma_doorbell[1][i] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE1 + (i >> 
1);
-   gpu_resources.sdma_doorbell[1][i+1] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE1 + 0x200 
+ (i >> 1);
-   }
+   gpu_resources.sdma_doorbell[0][i] =
+   adev->doorbell_index.sdma_engine0 + (i >> 1);
+   gpu_resources.sdma_doorbell[0][i+1] =
+   adev->doorbell_index.sdma_engine0 + 0x200 + (i 
>> 1);
+   gpu_resources.sdma_doorbell[1][i] =
+   adev->doorbell_index.sdma_engine1 + (i >> 1);
+   gpu_resources.sdma_doorbell[1][i+1] =
+   adev->doorbell_index.sdma_engine1 + 0x200 + (i 
>> 1);
}
/* Doorbells 0x0e0-0ff and 0x2e0-2ff are reserved for
 * SDMA, IH and VCN. So don't use them for the CP.
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index a8b1c9c..fdbc2c2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -532,7 +532,7 @@ static int amdgpu_device_doorbell_init(struct amdgpu_device 
*adev)
adev->doorbell.size = pci_resource_len(adev->pdev, 2);
 
adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / 
sizeof(u32),
-AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
+
adev->doorbell_index.max_assignment+1);
if (adev->doorbell.num_doorbells == 0)
return -EINVAL;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 6a70c0b..97a60da 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -250,7 +250,7 @@ int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev,
ring->adev = NULL;
ring->ring_obj = NULL;
ring->use_doorbell = true;
-   ring->doorbell_index = AMDGPU_DOORBELL_KIQ;
+   ring->doorbell_index = adev->doorbell_index.kiq;
 
r = amdgpu_gfx_kiq_acquire(adev, ring);
if (r)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c

[PATCH 3/8] drm/amdgpu: Vega10 doorbell index initialization

2018-11-26 Thread Oak Zeng
v2: Use enum definition instead of hardcoded value

Change-Id: Ib72058337f0aa53adfc6c6aae5341a7cd665111a
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/soc15.c   |  1 +
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 28 
 3 files changed, 30 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index 4cc0dcb..cae25dd 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -613,6 +613,7 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs =
.flush_hdp = &soc15_flush_hdp,
.invalidate_hdp = &soc15_invalidate_hdp,
.need_full_reset = &soc15_need_full_reset,
+   .init_doorbell_index = &vega10_doorbell_index_init,
 };
 
 static int soc15_common_early_init(void *handle)
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index f8ad780..d37c57d 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -58,4 +58,5 @@ void soc15_program_register_sequence(struct amdgpu_device 
*adev,
 int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
index c5c9b2b..9ba8e02 100644
--- a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
@@ -56,4 +56,32 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
return 0;
 }
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL64_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL64_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL64_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL64_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL64_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL64_MEC_RING7;
+   adev->doorbell_index.userqueue_start = 
AMDGPU_DOORBELL64_USERQUEUE_START;
+   adev->doorbell_index.userqueue_end = AMDGPU_DOORBELL64_USERQUEUE_END;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL64_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = 
AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = 
AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL64_IH;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 
AMDGPU_DOORBELL64_UVD_RING0_1;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 
AMDGPU_DOORBELL64_UVD_RING2_3;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 
AMDGPU_DOORBELL64_UVD_RING4_5;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 
AMDGPU_DOORBELL64_UVD_RING6_7;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 
AMDGPU_DOORBELL64_VCE_RING0_1;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 
AMDGPU_DOORBELL64_VCE_RING2_3;
+   adev->doorbell_index.uvd_vce.vce_ring4_5 = 
AMDGPU_DOORBELL64_VCE_RING4_5;
+   adev->doorbell_index.uvd_vce.vce_ring6_7 = 
AMDGPU_DOORBELL64_VCE_RING6_7;
+   /* In unit of dword doorbell */
+   adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT 
<< 1;
+}
 
-- 
2.7.4

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


[PATCH 1/8] drm/amdgpu: Add field in amdgpu_dev to hold reserved doorbell index

2018-11-26 Thread Oak Zeng
This is a preparation work to make reserved doorbell index per device,
instead of using a global macro definition. By doing this, we can easily
change doorbell layout for future ASICs while not affecting ASICs in
production.

Change-Id: If08e2bc9d0749748ed4083ba4eb32a4698763085
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 50 +
 1 file changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2c80453..b7ee4ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -813,6 +813,55 @@ struct amd_powerplay {
uint32_t pp_feature;
 };
 
+/* Reserved doorbells for amdgpu (including multimedia).
+ * KFD can use all the rest in the 2M doorbell bar.
+ * For asic before vega10, doorbell is 32-bit, so the
+ * index/offset is in dword. For vega10 and after, doorbell
+ * can be 64-bit, so the index defined is in qword.
+ */
+struct amdgpu_doorbell_index {
+   uint32_t kiq;
+   uint32_t mec_ring0;
+   uint32_t mec_ring1;
+   uint32_t mec_ring2;
+   uint32_t mec_ring3;
+   uint32_t mec_ring4;
+   uint32_t mec_ring5;
+   uint32_t mec_ring6;
+   uint32_t mec_ring7;
+   uint32_t userqueue_start;
+   uint32_t userqueue_end;
+   uint32_t gfx_ring0;
+   uint32_t sdma_engine0;
+   uint32_t sdma_engine1;
+   uint32_t sdma_engine2;
+   uint32_t sdma_engine3;
+   uint32_t sdma_engine4;
+   uint32_t sdma_engine5;
+   uint32_t sdma_engine6;
+   uint32_t sdma_engine7;
+   uint32_t ih;
+   union {
+   struct {
+   uint32_t vcn_ring0_1;
+   uint32_t vcn_ring2_3;
+   uint32_t vcn_ring4_5;
+   uint32_t vcn_ring6_7;
+   } vcn;
+   struct {
+   uint32_t uvd_ring0_1;
+   uint32_t uvd_ring2_3;
+   uint32_t uvd_ring4_5;
+   uint32_t uvd_ring6_7;
+   uint32_t vce_ring0_1;
+   uint32_t vce_ring2_3;
+   uint32_t vce_ring4_5;
+   uint32_t vce_ring6_7;
+   } uvd_vce;
+   };
+   uint32_t max_assignment;
+};
+
 #define AMDGPU_RESET_MAGIC_NUM 64
 struct amdgpu_device {
struct device   *dev;
@@ -1026,6 +1075,7 @@ struct amdgpu_device {
unsigned long last_mm_index;
boolin_gpu_reset;
struct mutex  lock_reset;
+   struct amdgpu_doorbell_index doorbell_index;
 };
 
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
-- 
2.7.4

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


[PATCH 5/8] drm/amdgpu: Doorbell layout for vega20 and future asic

2018-11-26 Thread Oak Zeng
v2: Use enum definition instead of hardcoded value

Change-Id: I04d22fb717ac50483c0835f160a2e860e344f358
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  | 50 
 drivers/gpu/drm/amd/amdgpu/soc15.c   | 22 +++-
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 33 ++
 4 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 719da32..2fc5713 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -392,6 +392,56 @@ struct amdgpu_doorbell {
u32 num_doorbells;  /* Number of doorbells actually 
reserved for amdgpu. */
 };
 
+typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
+{
+   /* Compute + GFX: 0~255 */
+   AMDGPU_VEGA20_DOORBELL_KIQ = 0x000,
+   AMDGPU_VEGA20_DOORBELL_HIQ = 0x001,
+   AMDGPU_VEGA20_DOORBELL_DIQ = 0x002,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING0   = 0x003,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING1   = 0x004,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING2   = 0x005,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING3   = 0x006,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING4   = 0x007,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING5   = 0x008,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING6   = 0x009,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING7   = 0x00A,
+   AMDGPU_VEGA20_DOORBELL_USERQUEUE_START = 0x00B,
+   AMDGPU_VEGA20_DOORBELL_USERQUEUE_END   = 0x08A,
+   AMDGPU_VEGA20_DOORBELL_GFX_RING0   = 0x08B,
+   /* SDMA:256~335*/
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0= 0x100,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE1= 0x10A,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE2= 0x114,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE3= 0x11E,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE4= 0x128,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE5= 0x132,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE6= 0x13C,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE7= 0x146,
+   /* IH: 376~391 */
+   AMDGPU_VEGA20_DOORBELL_IH  = 0x178,
+   /* MMSCH: 392~407
+* overlap the doorbell assignment with VCN as they are  mutually 
exclusive
+* VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
+*/
+   AMDGPU_VEGA20_DOORBELL64_VCN0_1  = 0x188, /* lower 32 
bits for VNC0 and upper 32 bits for VNC1 */
+   AMDGPU_VEGA20_DOORBELL64_VCN2_3  = 0x189,
+   AMDGPU_VEGA20_DOORBELL64_VCN4_5  = 0x18A,
+   AMDGPU_VEGA20_DOORBELL64_VCN6_7  = 0x18B,
+
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING0_1 = 0x188,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING2_3 = 0x189,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING4_5 = 0x18A,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING6_7 = 0x18B,
+
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING0_1 = 0x18C,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3 = 0x18D,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5 = 0x18E,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7 = 0x18F,
+   AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT= 0x18F,
+   AMDGPU_VEGA20_DOORBELL_INVALID   = 0x
+} AMDGPU_VEGA20_DOORBELL_ASSIGNMENT;
+
 /*
  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c 
b/drivers/gpu/drm/amd/amdgpu/soc15.c
index cae25dd..83624e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
@@ -616,6 +616,23 @@ static const struct amdgpu_asic_funcs soc15_asic_funcs =
.init_doorbell_index = &vega10_doorbell_index_init,
 };
 
+static const struct amdgpu_asic_funcs vega20_asic_funcs =
+{
+   .read_disabled_bios = &soc15_read_disabled_bios,
+   .read_bios_from_rom = &soc15_read_bios_from_rom,
+   .read_register = &soc15_read_register,
+   .reset = &soc15_asic_reset,
+   .set_vga_state = &soc15_vga_set_state,
+   .get_xclk = &soc15_get_xclk,
+   .set_uvd_clocks = &soc15_set_uvd_clocks,
+   .set_vce_clocks = &soc15_set_vce_clocks,
+   .get_config_memsize = &soc15_get_config_memsize,
+   .flush_hdp = &soc15_flush_hdp,
+   .invalidate_hdp = &soc15_invalidate_hdp,
+   .need_full_reset = &soc15_need_full_reset,
+   .init_doorbell_index = &vega20_doorbell_index_init,
+};
+
 static int soc15_common_early_init(void *handle)
 {
struct amdgpu_device *adev = (st

[PATCH 4/8] drm/amdgpu: Doorbell index initialization for ASICs before vega10

2018-11-26 Thread Oak Zeng
v2: Use enum definition instead of hardcoded number

Change-Id: Id64eb98f5b1c24b51eb2fd5a083086fc3515813d
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/cik.c |  1 +
 drivers/gpu/drm/amd/amdgpu/cik.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vi.c  | 19 +++
 drivers/gpu/drm/amd/amdgpu/vi.h  |  1 +
 4 files changed, 22 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/cik.c b/drivers/gpu/drm/amd/amdgpu/cik.c
index f41f5f5..71c50d8 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.c
+++ b/drivers/gpu/drm/amd/amdgpu/cik.c
@@ -1755,6 +1755,7 @@ static const struct amdgpu_asic_funcs cik_asic_funcs =
.flush_hdp = &cik_flush_hdp,
.invalidate_hdp = &cik_invalidate_hdp,
.need_full_reset = &cik_need_full_reset,
+   .init_doorbell_index = &legacy_doorbell_index_init,
 };
 
 static int cik_common_early_init(void *handle)
diff --git a/drivers/gpu/drm/amd/amdgpu/cik.h b/drivers/gpu/drm/amd/amdgpu/cik.h
index e49c6f1..54c625a 100644
--- a/drivers/gpu/drm/amd/amdgpu/cik.h
+++ b/drivers/gpu/drm/amd/amdgpu/cik.h
@@ -30,4 +30,5 @@ void cik_srbm_select(struct amdgpu_device *adev,
 u32 me, u32 pipe, u32 queue, u32 vmid);
 int cik_set_ip_blocks(struct amdgpu_device *adev);
 
+void legacy_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c b/drivers/gpu/drm/amd/amdgpu/vi.c
index 07880d3..ff2906c 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.c
+++ b/drivers/gpu/drm/amd/amdgpu/vi.c
@@ -955,6 +955,7 @@ static const struct amdgpu_asic_funcs vi_asic_funcs =
.flush_hdp = &vi_flush_hdp,
.invalidate_hdp = &vi_invalidate_hdp,
.need_full_reset = &vi_need_full_reset,
+   .init_doorbell_index = &legacy_doorbell_index_init,
 };
 
 #define CZ_REV_BRISTOL(rev) \
@@ -1712,3 +1713,21 @@ int vi_set_ip_blocks(struct amdgpu_device *adev)
 
return 0;
 }
+
+void legacy_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL_MEC_RING7;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = AMDGPU_DOORBELL_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = AMDGPU_DOORBELL_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL_IH;
+   adev->doorbell_index.max_assignment = AMDGPU_DOORBELL_MAX_ASSIGNMENT;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.h b/drivers/gpu/drm/amd/amdgpu/vi.h
index 0429fe3..8de0772 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.h
+++ b/drivers/gpu/drm/amd/amdgpu/vi.h
@@ -30,4 +30,5 @@ void vi_srbm_select(struct amdgpu_device *adev,
u32 me, u32 pipe, u32 queue, u32 vmid);
 int vi_set_ip_blocks(struct amdgpu_device *adev);
 
+void legacy_doorbell_index_init(struct amdgpu_device *adev);
 #endif
-- 
2.7.4

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


[PATCH 8/8] drm/amdgpu: Moved doorbell structures to seperate file

2018-11-26 Thread Oak Zeng
Move doorbell structures, enum definitions and helper functions
from amdgpu.h to amdgpu_doorbell.h. No functional change

Change-Id: I09f7b84869b6d3c688b7a2506ff78d62b3de23f5
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  | 227 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 249 +++
 2 files changed, 250 insertions(+), 226 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2fc5713..70342aa 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -81,6 +81,7 @@
 #include "amdgpu_job.h"
 #include "amdgpu_bo_list.h"
 #include "amdgpu_gem.h"
+#include "amdgpu_doorbell.h"
 
 #define MAX_GPU_INSTANCE   16
 
@@ -361,173 +362,6 @@ int amdgpu_fence_slab_init(void);
 void amdgpu_fence_slab_fini(void);
 
 /*
- * GPU doorbell structures, functions & helpers
- */
-typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
-{
-   AMDGPU_DOORBELL_KIQ = 0x000,
-   AMDGPU_DOORBELL_HIQ = 0x001,
-   AMDGPU_DOORBELL_DIQ = 0x002,
-   AMDGPU_DOORBELL_MEC_RING0   = 0x010,
-   AMDGPU_DOORBELL_MEC_RING1   = 0x011,
-   AMDGPU_DOORBELL_MEC_RING2   = 0x012,
-   AMDGPU_DOORBELL_MEC_RING3   = 0x013,
-   AMDGPU_DOORBELL_MEC_RING4   = 0x014,
-   AMDGPU_DOORBELL_MEC_RING5   = 0x015,
-   AMDGPU_DOORBELL_MEC_RING6   = 0x016,
-   AMDGPU_DOORBELL_MEC_RING7   = 0x017,
-   AMDGPU_DOORBELL_GFX_RING0   = 0x020,
-   AMDGPU_DOORBELL_sDMA_ENGINE0= 0x1E0,
-   AMDGPU_DOORBELL_sDMA_ENGINE1= 0x1E1,
-   AMDGPU_DOORBELL_IH  = 0x1E8,
-   AMDGPU_DOORBELL_MAX_ASSIGNMENT  = 0x3FF,
-   AMDGPU_DOORBELL_INVALID = 0x
-} AMDGPU_DOORBELL_ASSIGNMENT;
-
-struct amdgpu_doorbell {
-   /* doorbell mmio */
-   resource_size_t base;
-   resource_size_t size;
-   u32 __iomem *ptr;
-   u32 num_doorbells;  /* Number of doorbells actually 
reserved for amdgpu. */
-};
-
-typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
-{
-   /* Compute + GFX: 0~255 */
-   AMDGPU_VEGA20_DOORBELL_KIQ = 0x000,
-   AMDGPU_VEGA20_DOORBELL_HIQ = 0x001,
-   AMDGPU_VEGA20_DOORBELL_DIQ = 0x002,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING0   = 0x003,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING1   = 0x004,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING2   = 0x005,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING3   = 0x006,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING4   = 0x007,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING5   = 0x008,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING6   = 0x009,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING7   = 0x00A,
-   AMDGPU_VEGA20_DOORBELL_USERQUEUE_START = 0x00B,
-   AMDGPU_VEGA20_DOORBELL_USERQUEUE_END   = 0x08A,
-   AMDGPU_VEGA20_DOORBELL_GFX_RING0   = 0x08B,
-   /* SDMA:256~335*/
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0= 0x100,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE1= 0x10A,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE2= 0x114,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE3= 0x11E,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE4= 0x128,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE5= 0x132,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE6= 0x13C,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE7= 0x146,
-   /* IH: 376~391 */
-   AMDGPU_VEGA20_DOORBELL_IH  = 0x178,
-   /* MMSCH: 392~407
-* overlap the doorbell assignment with VCN as they are  mutually 
exclusive
-* VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
-*/
-   AMDGPU_VEGA20_DOORBELL64_VCN0_1  = 0x188, /* lower 32 
bits for VNC0 and upper 32 bits for VNC1 */
-   AMDGPU_VEGA20_DOORBELL64_VCN2_3  = 0x189,
-   AMDGPU_VEGA20_DOORBELL64_VCN4_5  = 0x18A,
-   AMDGPU_VEGA20_DOORBELL64_VCN6_7  = 0x18B,
-
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING0_1 = 0x188,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING2_3 = 0x189,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING4_5 = 0x18A,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING6_7 = 0x18B,
-
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING0_1 = 0x18C,
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3 = 0x18D,
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5 = 0x18E,
-   AMDGPU_

[PATCH 6/8] drm/amdgpu: Call doorbell index init on device initialization

2018-11-26 Thread Oak Zeng
Also call functioin amdgpu_device_doorbell_init after
amdgpu_device_ip_early_init because the former depends
on the later to set up asic-specific init_doorbell_index
function

Change-Id: I2f004bbbe2565035460686f4fc16e86b77a2a9b5
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index cb06e68..a8b1c9c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -513,6 +513,8 @@ void amdgpu_device_pci_config_reset(struct amdgpu_device 
*adev)
  */
 static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
 {
+   amdgpu_asic_init_doorbell_index(adev);
+
/* No doorbell on SI hardware generation */
if (adev->asic_type < CHIP_BONAIRE) {
adev->doorbell.base = 0;
@@ -2464,9 +2466,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
 
-   /* doorbell bar mapping */
-   amdgpu_device_doorbell_init(adev);
-
/* io port mapping */
for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
@@ -2485,6 +2484,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,
if (r)
return r;
 
+   /* doorbell bar mapping and doorbell index init*/
+   amdgpu_device_doorbell_init(adev);
+
/* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
/* this will fail for cards that aren't VGA class devices, just
 * ignore it */
-- 
2.7.4

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


[PATCH 2/8] drm/amdgpu: Add asic func interface to init doorbell index

2018-11-26 Thread Oak Zeng
Change-Id: I7e8a9c9dfd4f3bd0902679a1771c1a043ece2674
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index b7ee4ef..719da32 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -654,6 +654,8 @@ struct amdgpu_asic_funcs {
   struct amdgpu_ring *ring);
/* check if the asic needs a full reset of if soft reset will work */
bool (*need_full_reset)(struct amdgpu_device *adev);
+   /* initialize doorbell layout for specific asic*/
+   void (*init_doorbell_index)(struct amdgpu_device *adev);
 };
 
 /*
@@ -1212,6 +1214,7 @@ int emu_soc_asic_init(struct amdgpu_device *adev);
 #define amdgpu_asic_flush_hdp(adev, r) (adev)->asic_funcs->flush_hdp((adev), 
(r))
 #define amdgpu_asic_invalidate_hdp(adev, r) 
(adev)->asic_funcs->invalidate_hdp((adev), (r))
 #define amdgpu_asic_need_full_reset(adev) 
(adev)->asic_funcs->need_full_reset((adev))
+#define amdgpu_asic_init_doorbell_index(adev) 
(adev)->asic_funcs->init_doorbell_index((adev))
 
 /* Common functions */
 bool amdgpu_device_should_recover_gpu(struct amdgpu_device *adev);
-- 
2.7.4

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


[PATCH] drm/amdgpu: Moved doorbell structures to seperate file

2018-11-23 Thread Oak Zeng
Move doorbell structures, enum definitions and helper functions
from amdgpu.h to amdgpu_doorbell.h. No functional change

Change-Id: I09f7b84869b6d3c688b7a2506ff78d62b3de23f5
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  | 227 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 249 +++
 2 files changed, 250 insertions(+), 226 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index e4101b1..7fc32c7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -81,6 +81,7 @@
 #include "amdgpu_job.h"
 #include "amdgpu_bo_list.h"
 #include "amdgpu_gem.h"
+#include "amdgpu_doorbell.h"
 
 #define MAX_GPU_INSTANCE   16
 
@@ -361,173 +362,6 @@ int amdgpu_fence_slab_init(void);
 void amdgpu_fence_slab_fini(void);
 
 /*
- * GPU doorbell structures, functions & helpers
- */
-typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
-{
-   AMDGPU_DOORBELL_KIQ = 0x000,
-   AMDGPU_DOORBELL_HIQ = 0x001,
-   AMDGPU_DOORBELL_DIQ = 0x002,
-   AMDGPU_DOORBELL_MEC_RING0   = 0x010,
-   AMDGPU_DOORBELL_MEC_RING1   = 0x011,
-   AMDGPU_DOORBELL_MEC_RING2   = 0x012,
-   AMDGPU_DOORBELL_MEC_RING3   = 0x013,
-   AMDGPU_DOORBELL_MEC_RING4   = 0x014,
-   AMDGPU_DOORBELL_MEC_RING5   = 0x015,
-   AMDGPU_DOORBELL_MEC_RING6   = 0x016,
-   AMDGPU_DOORBELL_MEC_RING7   = 0x017,
-   AMDGPU_DOORBELL_GFX_RING0   = 0x020,
-   AMDGPU_DOORBELL_sDMA_ENGINE0= 0x1E0,
-   AMDGPU_DOORBELL_sDMA_ENGINE1= 0x1E1,
-   AMDGPU_DOORBELL_IH  = 0x1E8,
-   AMDGPU_DOORBELL_MAX_ASSIGNMENT  = 0x3FF,
-   AMDGPU_DOORBELL_INVALID = 0x
-} AMDGPU_DOORBELL_ASSIGNMENT;
-
-struct amdgpu_doorbell {
-   /* doorbell mmio */
-   resource_size_t base;
-   resource_size_t size;
-   u32 __iomem *ptr;
-   u32 num_doorbells;  /* Number of doorbells actually 
reserved for amdgpu. */
-};
-
-typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
-{
-   /* Compute + GFX: 0~255 */
-   AMDGPU_VEGA20_DOORBELL_KIQ = 0x000,
-   AMDGPU_VEGA20_DOORBELL_HIQ = 0x001,
-   AMDGPU_VEGA20_DOORBELL_DIQ = 0x002,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING0   = 0x003,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING1   = 0x004,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING2   = 0x005,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING3   = 0x006,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING4   = 0x007,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING5   = 0x008,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING6   = 0x009,
-   AMDGPU_VEGA20_DOORBELL_MEC_RING7   = 0x00A,
-   AMDGPU_VEGA20_DOORBELL_USERQUEUE_START = 0x00B,
-   AMDGPU_VEGA20_DOORBELL_USERQUEUE_END   = 0x08A,
-   AMDGPU_VEGA20_DOORBELL_GFX_RING0   = 0x08B,
-   /* SDMA:256~335*/
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0= 0x100,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE1= 0x10A,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE2= 0x114,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE3= 0x11E,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE4= 0x128,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE5= 0x132,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE6= 0x13C,
-   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE7= 0x146,
-   /* IH: 376~391 */
-   AMDGPU_VEGA20_DOORBELL_IH  = 0x178,
-   /* MMSCH: 392~407
-* overlap the doorbell assignment with VCN as they are  mutually 
exclusive
-* VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
-*/
-   AMDGPU_VEGA20_DOORBELL64_VCN0_1  = 0x188, /* lower 32 
bits for VNC0 and upper 32 bits for VNC1 */
-   AMDGPU_VEGA20_DOORBELL64_VCN2_3  = 0x189,
-   AMDGPU_VEGA20_DOORBELL64_VCN4_5  = 0x18A,
-   AMDGPU_VEGA20_DOORBELL64_VCN6_7  = 0x18B,
-
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING0_1 = 0x188,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING2_3 = 0x189,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING4_5 = 0x18A,
-   AMDGPU_VEGA20_DOORBELL64_UVD_RING6_7 = 0x18B,
-
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING0_1 = 0x18C,
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3 = 0x18D,
-   AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5 = 0x18E,
-   AMDGPU_

[PATCH 7/7] drm/amdgpu: Use new doorbell layout for vega20 and future asic

2018-11-21 Thread Oak Zeng
v2: Use enum definition instead of hardcoded value

Change-Id: I04d22fb717ac50483c0835f160a2e860e344f358
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h  | 50 
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   |  4 ++-
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 33 ++
 4 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index b7ee4ef..e4101b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -392,6 +392,56 @@ struct amdgpu_doorbell {
u32 num_doorbells;  /* Number of doorbells actually 
reserved for amdgpu. */
 };
 
+typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
+{
+   /* Compute + GFX: 0~255 */
+   AMDGPU_VEGA20_DOORBELL_KIQ = 0x000,
+   AMDGPU_VEGA20_DOORBELL_HIQ = 0x001,
+   AMDGPU_VEGA20_DOORBELL_DIQ = 0x002,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING0   = 0x003,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING1   = 0x004,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING2   = 0x005,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING3   = 0x006,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING4   = 0x007,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING5   = 0x008,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING6   = 0x009,
+   AMDGPU_VEGA20_DOORBELL_MEC_RING7   = 0x00A,
+   AMDGPU_VEGA20_DOORBELL_USERQUEUE_START = 0x00B,
+   AMDGPU_VEGA20_DOORBELL_USERQUEUE_END   = 0x08A,
+   AMDGPU_VEGA20_DOORBELL_GFX_RING0   = 0x08B,
+   /* SDMA:256~335*/
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0= 0x100,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE1= 0x10A,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE2= 0x114,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE3= 0x11E,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE4= 0x128,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE5= 0x132,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE6= 0x13C,
+   AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE7= 0x146,
+   /* IH: 376~391 */
+   AMDGPU_VEGA20_DOORBELL_IH  = 0x178,
+   /* MMSCH: 392~407
+* overlap the doorbell assignment with VCN as they are  mutually 
exclusive
+* VCE engine's doorbell is 32 bit and two VCE ring share one QWORD
+*/
+   AMDGPU_VEGA20_DOORBELL64_VCN0_1  = 0x188, /* lower 32 
bits for VNC0 and upper 32 bits for VNC1 */
+   AMDGPU_VEGA20_DOORBELL64_VCN2_3  = 0x189,
+   AMDGPU_VEGA20_DOORBELL64_VCN4_5  = 0x18A,
+   AMDGPU_VEGA20_DOORBELL64_VCN6_7  = 0x18B,
+
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING0_1 = 0x188,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING2_3 = 0x189,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING4_5 = 0x18A,
+   AMDGPU_VEGA20_DOORBELL64_UVD_RING6_7 = 0x18B,
+
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING0_1 = 0x18C,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3 = 0x18D,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5 = 0x18E,
+   AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7 = 0x18F,
+   AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT= 0x18F,
+   AMDGPU_VEGA20_DOORBELL_INVALID   = 0x
+} AMDGPU_VEGA20_DOORBELL_ASSIGNMENT;
+
 /*
  * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 3ffd8f5..19f2149 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -517,8 +517,10 @@ static int amdgpu_device_doorbell_init(struct 
amdgpu_device *adev)
vi_doorbell_index_init(adev);
else if (adev->asic_type == CHIP_VEGA10)
vega10_doorbell_index_init(adev);
-   else
+   else if (adev->asic_type == CHIP_VEGA12 || adev->asic_type == 
CHIP_RAVEN)
vega12_doorbell_index_init(adev);
+   else
+   vega20_doorbell_index_init(adev);
 
/* No doorbell on SI hardware generation */
if (adev->asic_type < CHIP_BONAIRE) {
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index 939c0e8..6ba0d26 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -60,4 +60,5 @@ int vega20_reg_base_init(struct amdgpu_device *adev);
 
 void vega10_doorbell_index_init(struct amdgpu_device *adev);
 void vega12_doorbell_index_init(struct amdgpu_device *adev);
+void vega20_doorbell_index_init(

[PATCH 6/7] drm/amdgpu: Use asic specific doorbell index instead of macro definition

2018-11-21 Thread Oak Zeng
Change-Id: I84475efcfb482c474fccb133010abb5df5f4
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 27 ---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c|  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  | 10 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  |  8 
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c |  2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 25 +
 drivers/gpu/drm/amd/amdgpu/tonga_ih.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c |  2 +-
 12 files changed, 36 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 1c1fed6..d693b804 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -181,25 +181,14 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 * process in case of 64-bit doorbells so we
 * can use each doorbell assignment twice.
 */
-   if (adev->asic_type == CHIP_VEGA10) {
-   gpu_resources.sdma_doorbell[0][i] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 + 
(i >> 1);
-   gpu_resources.sdma_doorbell[0][i+1] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0 + 
0x200 + (i >> 1);
-   gpu_resources.sdma_doorbell[1][i] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 + 
(i >> 1);
-   gpu_resources.sdma_doorbell[1][i+1] =
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1 + 
0x200 + (i >> 1);
-   } else {
-   gpu_resources.sdma_doorbell[0][i] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE0 + (i >> 
1);
-   gpu_resources.sdma_doorbell[0][i+1] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE0 + 0x200 
+ (i >> 1);
-   gpu_resources.sdma_doorbell[1][i] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE1 + (i >> 
1);
-   gpu_resources.sdma_doorbell[1][i+1] =
-   AMDGPU_DOORBELL64_sDMA_ENGINE1 + 0x200 
+ (i >> 1);
-   }
+   gpu_resources.sdma_doorbell[0][i] =
+   adev->doorbell_index.sdma_engine0 + (i >> 1);
+   gpu_resources.sdma_doorbell[0][i+1] =
+   adev->doorbell_index.sdma_engine0 + 0x200 + (i 
>> 1);
+   gpu_resources.sdma_doorbell[1][i] =
+   adev->doorbell_index.sdma_engine1 + (i >> 1);
+   gpu_resources.sdma_doorbell[1][i+1] =
+   adev->doorbell_index.sdma_engine1 + 0x200 + (i 
>> 1);
}
/* Doorbells 0x0e0-0ff and 0x2e0-2ff are reserved for
 * SDMA, IH and VCN. So don't use them for the CP.
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index a942a88..3ffd8f5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -537,7 +537,7 @@ static int amdgpu_device_doorbell_init(struct amdgpu_device 
*adev)
adev->doorbell.size = pci_resource_len(adev->pdev, 2);
 
adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / 
sizeof(u32),
-AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
+
adev->doorbell_index.max_assignment+1);
if (adev->doorbell.num_doorbells == 0)
return -EINVAL;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 6a70c0b..97a60da 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -250,7 +250,7 @@ int amdgpu_gfx_kiq_init_ring(struct amdgpu_device *adev,
ring->adev = NULL;
ring->ring_obj = NULL;
ring->use_doorbell = true;
-   ring->doorbell_index = AMDGPU_DOORBELL_KIQ;
+   ring->doorbell_index = adev->doorbell_index.kiq;
 
r = amdgpu_gfx_kiq_acquire(adev, ring);
if (r)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c

[PATCH 5/7] drm/amdgpu: Call doorbell index init on device initialization

2018-11-21 Thread Oak Zeng
Change-Id: I2f004bbbe2565035460686f4fc16e86b77a2a9b5
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index cb06e68..a942a88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -513,6 +513,13 @@ void amdgpu_device_pci_config_reset(struct amdgpu_device 
*adev)
  */
 static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
 {
+   if (adev->asic_type < CHIP_VEGA10)
+   vi_doorbell_index_init(adev);
+   else if (adev->asic_type == CHIP_VEGA10)
+   vega10_doorbell_index_init(adev);
+   else
+   vega12_doorbell_index_init(adev);
+
/* No doorbell on SI hardware generation */
if (adev->asic_type < CHIP_BONAIRE) {
adev->doorbell.base = 0;
-- 
2.7.4

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


[PATCH 2/7] drm/amdgpu: Vega10 doorbell index initialization

2018-11-21 Thread Oak Zeng
v2: Use enum definition instead of hardcoded value

Change-Id: Ib72058337f0aa53adfc6c6aae5341a7cd665111a
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 28 
 2 files changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index f8ad780..d37c57d 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -58,4 +58,5 @@ void soc15_program_register_sequence(struct amdgpu_device 
*adev,
 int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
index c5c9b2b..9ba8e02 100644
--- a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c
@@ -56,4 +56,32 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
return 0;
 }
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL64_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL64_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL64_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL64_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL64_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL64_MEC_RING7;
+   adev->doorbell_index.userqueue_start = 
AMDGPU_DOORBELL64_USERQUEUE_START;
+   adev->doorbell_index.userqueue_end = AMDGPU_DOORBELL64_USERQUEUE_END;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL64_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = 
AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = 
AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL64_IH;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 
AMDGPU_DOORBELL64_UVD_RING0_1;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 
AMDGPU_DOORBELL64_UVD_RING2_3;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 
AMDGPU_DOORBELL64_UVD_RING4_5;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 
AMDGPU_DOORBELL64_UVD_RING6_7;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 
AMDGPU_DOORBELL64_VCE_RING0_1;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 
AMDGPU_DOORBELL64_VCE_RING2_3;
+   adev->doorbell_index.uvd_vce.vce_ring4_5 = 
AMDGPU_DOORBELL64_VCE_RING4_5;
+   adev->doorbell_index.uvd_vce.vce_ring6_7 = 
AMDGPU_DOORBELL64_VCE_RING6_7;
+   /* In unit of dword doorbell */
+   adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT 
<< 1;
+}
 
-- 
2.7.4

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


[PATCH 4/7] drm/amdgpu: Doorbell index initialization for ASICs before vega10

2018-11-21 Thread Oak Zeng
v2: Use enum definition instead of hardcoded number

Change-Id: Id64eb98f5b1c24b51eb2fd5a083086fc3515813d
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vi.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vi_reg_init.c | 43 
 3 files changed, 45 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vi_reg_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 1cef9e1..ae29bf5 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,7 +63,7 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o vega12_reg_init.o
+   vega20_reg_init.o nbio_v7_4.o vega12_reg_init.o vi_reg_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.h b/drivers/gpu/drm/amd/amdgpu/vi.h
index 0429fe3..abcb52e 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.h
+++ b/drivers/gpu/drm/amd/amdgpu/vi.h
@@ -29,5 +29,5 @@
 void vi_srbm_select(struct amdgpu_device *adev,
u32 me, u32 pipe, u32 queue, u32 vmid);
 int vi_set_ip_blocks(struct amdgpu_device *adev);
-
+void vi_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vi_reg_init.c 
b/drivers/gpu/drm/amd/amdgpu/vi_reg_init.c
new file mode 100644
index 000..cdeb88d
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vi_reg_init.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vi_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL_MEC_RING7;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = AMDGPU_DOORBELL_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = AMDGPU_DOORBELL_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL_IH;
+   adev->doorbell_index.max_assignment = AMDGPU_DOORBELL_MAX_ASSIGNMENT;
+}
+
-- 
2.7.4

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


[PATCH 1/7] drm/amdgpu: Add field in amdgpu_dev to hold reserved doorbell index

2018-11-21 Thread Oak Zeng
This is a preparation work to make reserved doorbell index per device,
instead of using a global macro definition. By doing this, we can easily
change doorbell layout for future ASICs while not affecting ASICs in
production.

Change-Id: If08e2bc9d0749748ed4083ba4eb32a4698763085
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 50 +
 1 file changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2c80453..b7ee4ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -813,6 +813,55 @@ struct amd_powerplay {
uint32_t pp_feature;
 };
 
+/* Reserved doorbells for amdgpu (including multimedia).
+ * KFD can use all the rest in the 2M doorbell bar.
+ * For asic before vega10, doorbell is 32-bit, so the
+ * index/offset is in dword. For vega10 and after, doorbell
+ * can be 64-bit, so the index defined is in qword.
+ */
+struct amdgpu_doorbell_index {
+   uint32_t kiq;
+   uint32_t mec_ring0;
+   uint32_t mec_ring1;
+   uint32_t mec_ring2;
+   uint32_t mec_ring3;
+   uint32_t mec_ring4;
+   uint32_t mec_ring5;
+   uint32_t mec_ring6;
+   uint32_t mec_ring7;
+   uint32_t userqueue_start;
+   uint32_t userqueue_end;
+   uint32_t gfx_ring0;
+   uint32_t sdma_engine0;
+   uint32_t sdma_engine1;
+   uint32_t sdma_engine2;
+   uint32_t sdma_engine3;
+   uint32_t sdma_engine4;
+   uint32_t sdma_engine5;
+   uint32_t sdma_engine6;
+   uint32_t sdma_engine7;
+   uint32_t ih;
+   union {
+   struct {
+   uint32_t vcn_ring0_1;
+   uint32_t vcn_ring2_3;
+   uint32_t vcn_ring4_5;
+   uint32_t vcn_ring6_7;
+   } vcn;
+   struct {
+   uint32_t uvd_ring0_1;
+   uint32_t uvd_ring2_3;
+   uint32_t uvd_ring4_5;
+   uint32_t uvd_ring6_7;
+   uint32_t vce_ring0_1;
+   uint32_t vce_ring2_3;
+   uint32_t vce_ring4_5;
+   uint32_t vce_ring6_7;
+   } uvd_vce;
+   };
+   uint32_t max_assignment;
+};
+
 #define AMDGPU_RESET_MAGIC_NUM 64
 struct amdgpu_device {
struct device   *dev;
@@ -1026,6 +1075,7 @@ struct amdgpu_device {
unsigned long last_mm_index;
boolin_gpu_reset;
struct mutex  lock_reset;
+   struct amdgpu_doorbell_index doorbell_index;
 };
 
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
-- 
2.7.4

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


[PATCH 3/7] drm/amdgpu: Vega12 doorbell index initialization

2018-11-21 Thread Oak Zeng
v2: Changed file name for consistency

Change-Id: Ib2c570224321bb7002d2ed01f43ac70203e86f88
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile  |  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.h   |  1 +
 drivers/gpu/drm/amd/amdgpu/vega12_reg_init.c | 54 
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vega12_reg_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index f76bcb9..1cef9e1 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,7 +63,7 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o
+   vega20_reg_init.o nbio_v7_4.o vega12_reg_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index d37c57d..939c0e8 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -59,4 +59,5 @@ int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
 void vega10_doorbell_index_init(struct amdgpu_device *adev);
+void vega12_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega12_reg_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega12_reg_init.c
new file mode 100644
index 000..71622b5
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vega12_reg_init.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vega12_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
+   adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
+   adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
+   adev->doorbell_index.mec_ring2 = AMDGPU_DOORBELL64_MEC_RING2;
+   adev->doorbell_index.mec_ring3 = AMDGPU_DOORBELL64_MEC_RING3;
+   adev->doorbell_index.mec_ring4 = AMDGPU_DOORBELL64_MEC_RING4;
+   adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL64_MEC_RING5;
+   adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL64_MEC_RING6;
+   adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL64_MEC_RING7;
+   adev->doorbell_index.userqueue_start = 
AMDGPU_DOORBELL64_USERQUEUE_START;
+   adev->doorbell_index.userqueue_end = AMDGPU_DOORBELL64_USERQUEUE_END;
+   adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL64_GFX_RING0;
+   adev->doorbell_index.sdma_engine0 = AMDGPU_DOORBELL64_sDMA_ENGINE0;
+   adev->doorbell_index.sdma_engine1 = AMDGPU_DOORBELL64_sDMA_ENGINE1;
+   adev->doorbell_index.ih = AMDGPU_DOORBELL64_IH;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 
AMDGPU_DOORBELL64_UVD_RING0_1;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 
AMDGPU_DOORBELL64_UVD_RING2_3;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 
AMDGPU_DOORBELL64_UVD_RING4_5;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 
AMDGPU_DOORBELL64_UVD_RING6_7;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 
AMDGPU_DOORBELL64_VCE_RING0_1;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 
AMDGPU_DOORBELL64_VCE_RING2_3;
+   adev->doorbell_index.uvd_vce.vce_ring4_5 = 
AMDGPU_DOORBELL64_VCE_RING4_5;
+   adev->doorbell_index.uvd_vce.vce_ring6_7 = 
AMDGPU_DOORBELL64_VCE_RING6_7;
+   /* In unit of dword doorbell */
+   adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT 
<< 1;
+}
+
-- 
2.7.4

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


[PATCH 4/7] drm/amdgpu: Doorbell index initialization for ASICs before vega10

2018-11-21 Thread Oak Zeng
Change-Id: Id64eb98f5b1c24b51eb2fd5a083086fc3515813d
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile|  3 +-
 drivers/gpu/drm/amd/amdgpu/vi.h|  2 +-
 .../gpu/drm/amd/amdgpu/vi_doorbell_index_init.c| 43 ++
 3 files changed, 46 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vi_doorbell_index_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 96a4e1c..3ab8eba 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,7 +63,8 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o 
vega12_doorbell_index_init.o
+   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o 
vega12_doorbell_index_init.o \
+   vi_doorbell_index_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/vi.h b/drivers/gpu/drm/amd/amdgpu/vi.h
index 0429fe3..abcb52e 100644
--- a/drivers/gpu/drm/amd/amdgpu/vi.h
+++ b/drivers/gpu/drm/amd/amdgpu/vi.h
@@ -29,5 +29,5 @@
 void vi_srbm_select(struct amdgpu_device *adev,
u32 me, u32 pipe, u32 queue, u32 vmid);
 int vi_set_ip_blocks(struct amdgpu_device *adev);
-
+void vi_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vi_doorbell_index_init.c 
b/drivers/gpu/drm/amd/amdgpu/vi_doorbell_index_init.c
new file mode 100644
index 000..cae2ab6
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vi_doorbell_index_init.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vi_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = 0x00;
+   adev->doorbell_index.mec_ring0 = 0x10;
+   adev->doorbell_index.mec_ring1 = 0x11;
+   adev->doorbell_index.mec_ring2 = 0x12;
+   adev->doorbell_index.mec_ring3 = 0x13;
+   adev->doorbell_index.mec_ring4 = 0x14;
+   adev->doorbell_index.mec_ring5 = 0x15;
+   adev->doorbell_index.mec_ring6 = 0x16;
+   adev->doorbell_index.mec_ring7 = 0x17;
+   adev->doorbell_index.gfx_ring0 = 0x20;
+   adev->doorbell_index.sdma_engine0 = 0x1e0;
+   adev->doorbell_index.sdma_engine1 = 0x1e1;
+   adev->doorbell_index.ih = 0x1e8;
+   adev->doorbell_index.max_assignment = 0x3ff;
+}
+
-- 
2.7.4

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


[PATCH 7/7] drm/amdgpu: Use new doorbell layout for vega20 and future asic

2018-11-21 Thread Oak Zeng
Change-Id: I04d22fb717ac50483c0835f160a2e860e344f358
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile|  4 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  4 +-
 drivers/gpu/drm/amd/amdgpu/soc15.h |  1 +
 .../drm/amd/amdgpu/vega20_doorbell_index_init.c| 64 ++
 4 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vega20_doorbell_index_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 3ab8eba..b3b150b 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,8 +63,8 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o 
vega12_doorbell_index_init.o \
-   vi_doorbell_index_init.o
+   vega20_reg_init.o nbio_v7_4.o vi_doorbell_index_init.o 
vega10_doorbell_index_init.o \
+   vega12_doorbell_index_init.o vega20_doorbell_index_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 3ffd8f5..19f2149 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -517,8 +517,10 @@ static int amdgpu_device_doorbell_init(struct 
amdgpu_device *adev)
vi_doorbell_index_init(adev);
else if (adev->asic_type == CHIP_VEGA10)
vega10_doorbell_index_init(adev);
-   else
+   else if (adev->asic_type == CHIP_VEGA12 || adev->asic_type == 
CHIP_RAVEN)
vega12_doorbell_index_init(adev);
+   else
+   vega20_doorbell_index_init(adev);
 
/* No doorbell on SI hardware generation */
if (adev->asic_type < CHIP_BONAIRE) {
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index 939c0e8..6ba0d26 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -60,4 +60,5 @@ int vega20_reg_base_init(struct amdgpu_device *adev);
 
 void vega10_doorbell_index_init(struct amdgpu_device *adev);
 void vega12_doorbell_index_init(struct amdgpu_device *adev);
+void vega20_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega20_doorbell_index_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega20_doorbell_index_init.c
new file mode 100644
index 000..dcaef7f
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vega20_doorbell_index_init.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vega20_doorbell_index_init(struct amdgpu_device *adev)
+{
+   /* Compute + GFX: 0~255 */
+   adev->doorbell_index.kiq = 0x00;
+   adev->doorbell_index.mec_ring0 = 0x03;
+   adev->doorbell_index.mec_ring1 = 0x04;
+   adev->doorbell_index.mec_ring2 = 0x05;
+   adev->doorbell_index.mec_ring3 = 0x06;
+   adev->doorbell_index.mec_ring4 = 0x07;
+   adev->doorbell_index.mec_ring5 = 0x08;
+   adev->doorbell_index.mec_ring6 = 0x09;
+   adev->doorbell_index.mec_ring7 = 0x0a;
+   adev->doorbell_index.userqueue_start = 0x0b;
+   adev->doorbell_index.userqueue_end = 0x8a;
+   adev->doorbell_index.gfx_ring0 = 0x8b;
+   /* SDMA:256~335*/
+   adev->doorbell_index.sdma_engine0 = 0x100;
+   adev->doorbell_index.sdma_engine1 = 0x10a;
+   adev->doorbell_index.sdma_engine2 = 0x114;
+   adev->doorbell_index.sdma_engine3 = 0x11e;
+   adev->doorbell_index.sdma_engine4 = 0x1

[PATCH 6/7] drm/amdgpu: Use asic specific doorbell index instead of macro definition

2018-11-21 Thread Oak Zeng
Also deleted doorbell index macro definition

Change-Id: I84475efcfb482c474fccb133010abb5df5f4
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h| 106 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  27 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |   2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c|   2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c  |   2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c  |  10 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  |   8 +--
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c |   2 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  25 +++
 drivers/gpu/drm/amd/amdgpu/tonga_ih.c  |   2 +-
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c  |   4 +-
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c  |   4 +-
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c |   2 +-
 13 files changed, 36 insertions(+), 160 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index b7ee4ef..5cbd67a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -363,27 +363,6 @@ void amdgpu_fence_slab_fini(void);
 /*
  * GPU doorbell structures, functions & helpers
  */
-typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
-{
-   AMDGPU_DOORBELL_KIQ = 0x000,
-   AMDGPU_DOORBELL_HIQ = 0x001,
-   AMDGPU_DOORBELL_DIQ = 0x002,
-   AMDGPU_DOORBELL_MEC_RING0   = 0x010,
-   AMDGPU_DOORBELL_MEC_RING1   = 0x011,
-   AMDGPU_DOORBELL_MEC_RING2   = 0x012,
-   AMDGPU_DOORBELL_MEC_RING3   = 0x013,
-   AMDGPU_DOORBELL_MEC_RING4   = 0x014,
-   AMDGPU_DOORBELL_MEC_RING5   = 0x015,
-   AMDGPU_DOORBELL_MEC_RING6   = 0x016,
-   AMDGPU_DOORBELL_MEC_RING7   = 0x017,
-   AMDGPU_DOORBELL_GFX_RING0   = 0x020,
-   AMDGPU_DOORBELL_sDMA_ENGINE0= 0x1E0,
-   AMDGPU_DOORBELL_sDMA_ENGINE1= 0x1E1,
-   AMDGPU_DOORBELL_IH  = 0x1E8,
-   AMDGPU_DOORBELL_MAX_ASSIGNMENT  = 0x3FF,
-   AMDGPU_DOORBELL_INVALID = 0x
-} AMDGPU_DOORBELL_ASSIGNMENT;
-
 struct amdgpu_doorbell {
/* doorbell mmio */
resource_size_t base;
@@ -393,91 +372,6 @@ struct amdgpu_doorbell {
 };
 
 /*
- * 64bit doorbell, offset are in QWORD, occupy 2KB doorbell space
- */
-typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
-{
-   /*
-* All compute related doorbells: kiq, hiq, diq, traditional compute 
queue, user queue, should locate in
-* a continues range so that programming 
CP_MEC_DOORBELL_RANGE_LOWER/UPPER can cover this range.
-*  Compute related doorbells are allocated from 0x00 to 0x8a
-*/
-
-
-   /* kernel scheduling */
-   AMDGPU_DOORBELL64_KIQ = 0x00,
-
-   /* HSA interface queue and debug queue */
-   AMDGPU_DOORBELL64_HIQ = 0x01,
-   AMDGPU_DOORBELL64_DIQ = 0x02,
-
-   /* Compute engines */
-   AMDGPU_DOORBELL64_MEC_RING0   = 0x03,
-   AMDGPU_DOORBELL64_MEC_RING1   = 0x04,
-   AMDGPU_DOORBELL64_MEC_RING2   = 0x05,
-   AMDGPU_DOORBELL64_MEC_RING3   = 0x06,
-   AMDGPU_DOORBELL64_MEC_RING4   = 0x07,
-   AMDGPU_DOORBELL64_MEC_RING5   = 0x08,
-   AMDGPU_DOORBELL64_MEC_RING6   = 0x09,
-   AMDGPU_DOORBELL64_MEC_RING7   = 0x0a,
-
-   /* User queue doorbell range (128 doorbells) */
-   AMDGPU_DOORBELL64_USERQUEUE_START = 0x0b,
-   AMDGPU_DOORBELL64_USERQUEUE_END   = 0x8a,
-
-   /* Graphics engine */
-   AMDGPU_DOORBELL64_GFX_RING0   = 0x8b,
-
-   /*
-* Other graphics doorbells can be allocated here: from 0x8c to 0xdf
-* Graphics voltage island aperture 1
-* default non-graphics QWORD index is 0xe0 - 0xFF inclusive
-*/
-
-   /* sDMA engines  reserved from 0xe0 -0xef  */
-   AMDGPU_DOORBELL64_sDMA_ENGINE0= 0xE0,
-   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xE1,
-   AMDGPU_DOORBELL64_sDMA_ENGINE1= 0xE8,
-   AMDGPU_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xE9,
-
-   /* For vega10 sriov, the sdma doorbell must be fixed as follow
-* to keep the same setting with host driver, or it will
-* happen conflicts
-*/
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE0= 0xF0,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE0 = 0xF1,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_ENGINE1= 0xF2,
-   AMDGPU_VEGA10_DOORBELL64_sDMA_HI_PRI_ENGINE1 = 0xF3,
-
-   /* Interrupt handler */
-   AMDGPU_DOORBELL64_IH  = 0xF4,  /* For legacy 
inter

[PATCH 2/7] drm/amdgpu: Vega10 doorbell index initialization

2018-11-21 Thread Oak Zeng
Change-Id: Ib72058337f0aa53adfc6c6aae5341a7cd665111a
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile|  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.h |  1 +
 .../drm/amd/amdgpu/vega10_doorbell_index_init.c| 54 ++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vega10_doorbell_index_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index f76bcb9..61cea57 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,7 +63,7 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o
+   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index f8ad780..d37c57d 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -58,4 +58,5 @@ void soc15_program_register_sequence(struct amdgpu_device 
*adev,
 int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
+void vega10_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_doorbell_index_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_doorbell_index_init.c
new file mode 100644
index 000..e8216a3
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_doorbell_index_init.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vega10_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = 0x00;
+   adev->doorbell_index.mec_ring0 = 0x03;
+   adev->doorbell_index.mec_ring1 = 0x04;
+   adev->doorbell_index.mec_ring2 = 0x05;
+   adev->doorbell_index.mec_ring3 = 0x06;
+   adev->doorbell_index.mec_ring4 = 0x07;
+   adev->doorbell_index.mec_ring5 = 0x08;
+   adev->doorbell_index.mec_ring6 = 0x09;
+   adev->doorbell_index.mec_ring7 = 0x0a;
+   adev->doorbell_index.userqueue_start = 0x0b;
+   adev->doorbell_index.userqueue_end = 0x8a;
+   adev->doorbell_index.gfx_ring0 = 0x8b;
+   adev->doorbell_index.sdma_engine0 = 0xf0;
+   adev->doorbell_index.sdma_engine1 = 0xf2;
+   adev->doorbell_index.ih = 0xf4;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 0xf8;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 0xf9;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 0xfa;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 0xfb;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 0xfc;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 0xfd;
+   adev->doorbell_index.uvd_vce.vce_ring4_5 = 0xfe;
+   adev->doorbell_index.uvd_vce.vce_ring6_7 = 0xff;
+   /* In unit of dword doorbell */
+   adev->doorbell_index.max_assignment = 0xff << 1;
+}
+
-- 
2.7.4

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


[PATCH 5/7] drm/amdgpu: Call doorbell index init on device initialization

2018-11-21 Thread Oak Zeng
Change-Id: I2f004bbbe2565035460686f4fc16e86b77a2a9b5
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index cb06e68..a942a88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -513,6 +513,13 @@ void amdgpu_device_pci_config_reset(struct amdgpu_device 
*adev)
  */
 static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
 {
+   if (adev->asic_type < CHIP_VEGA10)
+   vi_doorbell_index_init(adev);
+   else if (adev->asic_type == CHIP_VEGA10)
+   vega10_doorbell_index_init(adev);
+   else
+   vega12_doorbell_index_init(adev);
+
/* No doorbell on SI hardware generation */
if (adev->asic_type < CHIP_BONAIRE) {
adev->doorbell.base = 0;
-- 
2.7.4

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


[PATCH 3/7] drm/amdgpu: Vega12 doorbell index initialization

2018-11-21 Thread Oak Zeng
Change-Id: Ib2c570224321bb7002d2ed01f43ac70203e86f88
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/Makefile|  2 +-
 drivers/gpu/drm/amd/amdgpu/soc15.h |  1 +
 .../drm/amd/amdgpu/vega12_doorbell_index_init.c| 54 ++
 3 files changed, 56 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/amd/amdgpu/vega12_doorbell_index_init.c

diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile 
b/drivers/gpu/drm/amd/amdgpu/Makefile
index 61cea57..96a4e1c 100644
--- a/drivers/gpu/drm/amd/amdgpu/Makefile
+++ b/drivers/gpu/drm/amd/amdgpu/Makefile
@@ -63,7 +63,7 @@ amdgpu-$(CONFIG_DRM_AMDGPU_SI)+= si.o gmc_v6_0.o gfx_v6_0.o 
si_ih.o si_dma.o dce
 
 amdgpu-y += \
vi.o mxgpu_vi.o nbio_v6_1.o soc15.o emu_soc.o mxgpu_ai.o nbio_v7_0.o 
vega10_reg_init.o \
-   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o
+   vega20_reg_init.o nbio_v7_4.o vega10_doorbell_index_init.o 
vega12_doorbell_index_init.o
 
 # add DF block
 amdgpu-y += \
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.h 
b/drivers/gpu/drm/amd/amdgpu/soc15.h
index d37c57d..939c0e8 100644
--- a/drivers/gpu/drm/amd/amdgpu/soc15.h
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.h
@@ -59,4 +59,5 @@ int vega10_reg_base_init(struct amdgpu_device *adev);
 int vega20_reg_base_init(struct amdgpu_device *adev);
 
 void vega10_doorbell_index_init(struct amdgpu_device *adev);
+void vega12_doorbell_index_init(struct amdgpu_device *adev);
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vega12_doorbell_index_init.c 
b/drivers/gpu/drm/amd/amdgpu/vega12_doorbell_index_init.c
new file mode 100644
index 000..43be474
--- /dev/null
+++ b/drivers/gpu/drm/amd/amdgpu/vega12_doorbell_index_init.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2018 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 "amdgpu.h"
+
+void vega12_doorbell_index_init(struct amdgpu_device *adev)
+{
+   adev->doorbell_index.kiq = 0x00;
+   adev->doorbell_index.mec_ring0 = 0x03;
+   adev->doorbell_index.mec_ring1 = 0x04;
+   adev->doorbell_index.mec_ring2 = 0x05;
+   adev->doorbell_index.mec_ring3 = 0x06;
+   adev->doorbell_index.mec_ring4 = 0x07;
+   adev->doorbell_index.mec_ring5 = 0x08;
+   adev->doorbell_index.mec_ring6 = 0x09;
+   adev->doorbell_index.mec_ring7 = 0x0a;
+   adev->doorbell_index.userqueue_start = 0x0b;
+   adev->doorbell_index.userqueue_end = 0x8a;
+   adev->doorbell_index.gfx_ring0 = 0x8b;
+   adev->doorbell_index.sdma_engine0 = 0xe0;
+   adev->doorbell_index.sdma_engine1 = 0xe8;
+   adev->doorbell_index.ih = 0xf4;
+   adev->doorbell_index.uvd_vce.uvd_ring0_1 = 0xf8;
+   adev->doorbell_index.uvd_vce.uvd_ring2_3 = 0xf9;
+   adev->doorbell_index.uvd_vce.uvd_ring4_5 = 0xfa;
+   adev->doorbell_index.uvd_vce.uvd_ring6_7 = 0xfb;
+   adev->doorbell_index.uvd_vce.vce_ring0_1 = 0xfc;
+   adev->doorbell_index.uvd_vce.vce_ring2_3 = 0xfd;
+   adev->doorbell_index.uvd_vce.vce_ring4_5 = 0xfe;
+   adev->doorbell_index.uvd_vce.vce_ring6_7 = 0xff;
+   /* In unit of dword doorbell */
+   adev->doorbell_index.max_assignment = 0xff << 1;
+}
+
-- 
2.7.4

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


[PATCH 1/7] drm/amdgpu: Add field in amdgpu_dev to hold reserved doorbell index

2018-11-21 Thread Oak Zeng
This is a preparation work to make reserved doorbell index per device,
instead of using a global macro definition. By doing this, we can easily
change doorbell layout for future ASICs while not affecting ASICs in
production.

Change-Id: If08e2bc9d0749748ed4083ba4eb32a4698763085
Signed-off-by: Oak Zeng 
Suggested-by: Felix Kuehling 
Suggested-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 50 +
 1 file changed, 50 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 2c80453..b7ee4ef 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -813,6 +813,55 @@ struct amd_powerplay {
uint32_t pp_feature;
 };
 
+/* Reserved doorbells for amdgpu (including multimedia).
+ * KFD can use all the rest in the 2M doorbell bar.
+ * For asic before vega10, doorbell is 32-bit, so the
+ * index/offset is in dword. For vega10 and after, doorbell
+ * can be 64-bit, so the index defined is in qword.
+ */
+struct amdgpu_doorbell_index {
+   uint32_t kiq;
+   uint32_t mec_ring0;
+   uint32_t mec_ring1;
+   uint32_t mec_ring2;
+   uint32_t mec_ring3;
+   uint32_t mec_ring4;
+   uint32_t mec_ring5;
+   uint32_t mec_ring6;
+   uint32_t mec_ring7;
+   uint32_t userqueue_start;
+   uint32_t userqueue_end;
+   uint32_t gfx_ring0;
+   uint32_t sdma_engine0;
+   uint32_t sdma_engine1;
+   uint32_t sdma_engine2;
+   uint32_t sdma_engine3;
+   uint32_t sdma_engine4;
+   uint32_t sdma_engine5;
+   uint32_t sdma_engine6;
+   uint32_t sdma_engine7;
+   uint32_t ih;
+   union {
+   struct {
+   uint32_t vcn_ring0_1;
+   uint32_t vcn_ring2_3;
+   uint32_t vcn_ring4_5;
+   uint32_t vcn_ring6_7;
+   } vcn;
+   struct {
+   uint32_t uvd_ring0_1;
+   uint32_t uvd_ring2_3;
+   uint32_t uvd_ring4_5;
+   uint32_t uvd_ring6_7;
+   uint32_t vce_ring0_1;
+   uint32_t vce_ring2_3;
+   uint32_t vce_ring4_5;
+   uint32_t vce_ring6_7;
+   } uvd_vce;
+   };
+   uint32_t max_assignment;
+};
+
 #define AMDGPU_RESET_MAGIC_NUM 64
 struct amdgpu_device {
struct device   *dev;
@@ -1026,6 +1075,7 @@ struct amdgpu_device {
unsigned long last_mm_index;
boolin_gpu_reset;
struct mutex  lock_reset;
+   struct amdgpu_doorbell_index doorbell_index;
 };
 
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
-- 
2.7.4

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


[PATCH 3/4] drm/amdkfd: Allocate SDMA queue on specif engine

2018-11-13 Thread Oak Zeng
From: Oak Zeng 

Change-Id: I32e0304cdf6ceeed12ea8d0af62f44e1ab20bffb
Signed-off-by: Oak Zeng 
Reviewd-by: Felix Kuehling 
---
 drivers/gpu/drm/amd/amdkfd/kfd_chardev.c   | 26 +--
 .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c  | 30 +++---
 2 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 5f4062b..37b02ea 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -143,7 +143,8 @@ static int kfd_ioctl_get_version(struct file *filep, struct 
kfd_process *p,
return 0;
 }
 
-static int set_queue_properties_from_user(struct queue_properties 
*q_properties,
+static int set_queue_properties_from_user(struct kfd_dev *dev,
+   struct queue_properties *q_properties,
struct kfd_ioctl_create_queue_args *args)
 {
if (args->queue_percentage > KFD_MAX_QUEUE_PERCENTAGE) {
@@ -213,12 +214,21 @@ static int set_queue_properties_from_user(struct 
queue_properties *q_properties,
q_properties->ctx_save_restore_area_size = args->ctx_save_restore_size;
q_properties->ctl_stack_size = args->ctl_stack_size;
if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE ||
-   args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL)
+   args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL) {
q_properties->type = KFD_QUEUE_TYPE_COMPUTE;
-   else if (args->queue_type == KFD_IOC_QUEUE_TYPE_SDMA)
+   } else if (args->queue_type == KFD_IOC_QUEUE_TYPE_SDMA) {
+   q_properties->sdma_engine_id =
+   dev->device_info->num_sdma_engines;
q_properties->type = KFD_QUEUE_TYPE_SDMA;
-   else
+   } else if (args->queue_type >= KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(0) &&
+   args->queue_type < KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(
+   dev->device_info->num_sdma_engines)) {
+   q_properties->sdma_engine_id =
+   args->queue_type - KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(0);
+   q_properties->type = KFD_QUEUE_TYPE_SDMA;
+   } else {
return -ENOTSUPP;
+   }
 
if (args->queue_type == KFD_IOC_QUEUE_TYPE_COMPUTE_AQL)
q_properties->format = KFD_QUEUE_FORMAT_AQL;
@@ -265,10 +275,6 @@ static int kfd_ioctl_create_queue(struct file *filep, 
struct kfd_process *p,
 
pr_debug("Creating queue ioctl\n");
 
-   err = set_queue_properties_from_user(&q_properties, args);
-   if (err)
-   return err;
-
pr_debug("Looking for gpu id 0x%x\n", args->gpu_id);
dev = kfd_device_by_id(args->gpu_id);
if (!dev) {
@@ -276,6 +282,10 @@ static int kfd_ioctl_create_queue(struct file *filep, 
struct kfd_process *p,
return -EINVAL;
}
 
+   err = set_queue_properties_from_user(dev, &q_properties, args);
+   if (err)
+   return err;
+
mutex_lock(&p->mutex);
 
pdd = kfd_bind_process_to_device(dev, p);
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index 7bf4bca..bc8f955 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -916,14 +916,34 @@ static int stop_nocpsch(struct device_queue_manager *dqm)
 }
 
 static int allocate_sdma_queue(struct device_queue_manager *dqm,
+   unsigned int sdma_engine_id,
unsigned int *sdma_queue_id)
 {
-   int bit;
+   int bit = -1;
 
if (dqm->sdma_bitmap == 0)
return -ENOMEM;
 
-   bit = __ffs64(dqm->sdma_bitmap);
+   /* If sdma_engine_id is valid,
+* allocate queue on specific engine
+*/
+   if (sdma_engine_id < get_num_sdma_engines(dqm)) {
+   unsigned int i;
+
+   for (i = sdma_engine_id; i < get_num_sdma_queues(dqm);
+   i += get_num_sdma_engines(dqm)) {
+   if (dqm->sdma_bitmap & (1<sdma_bitmap);
+   }
+
dqm->sdma_bitmap &= ~(1ULL << bit);
*sdma_queue_id = bit;
 
@@ -949,7 +969,8 @@ static int create_sdma_queue_nocpsch(struct 
device_queue_manager *dqm,
if (!mqd_mgr)
return -ENOMEM;
 
-   retval = allocate_sdma_queue(dqm, &q->sdma_id);
+   retval = allocate_sdma_queue(dqm, q->properties.sdma_engine_id,
+   &q->sdma_id);
if (retval)
return retval;
 
@@ -1168,7 +1189,8 @@ static int create_queue_cpsch(struct device_queue_manager 
*dqm, struct queue *q,
  

[PATCH 4/4] drm/amdkfd: Add sdma allocation debug message

2018-11-13 Thread Oak Zeng
From: Oak Zeng 

Change-Id: I47ec79eceac810f7031eaf88d267fc8370501c27
Signed-off-by: Oak Zeng 
Reviewd-by: Felix Kuehling 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index bc8f955..116afef 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -1197,6 +1197,9 @@ static int create_queue_cpsch(struct device_queue_manager 
*dqm, struct queue *q,
q->sdma_id / get_num_sdma_engines(dqm);
q->properties.sdma_engine_id =
q->sdma_id % get_num_sdma_engines(dqm);
+   pr_debug("SDMA id is:%d\n", q->sdma_id);
+   pr_debug("SDMA queue id: %d\n", q->properties.sdma_queue_id);
+   pr_debug("SDMA engine id: %d\n", q->properties.sdma_engine_id);
}
 
retval = allocate_doorbell(qpd, q);
-- 
2.7.4

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


[PATCH 1/4] drm/amdkfd: Use 64 bit sdma_bitmap

2018-11-13 Thread Oak Zeng
From: Oak Zeng 

Maximumly support 64 sdma queues

Change-Id: Ia34b81fe606f730cb0cddb5dfc833cfe8abcf776
Signed-off-by: Oak Zeng 
Reviewed-by: Felix Kuehling 
Reviewed-by: Alex Deucher 
---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 10 +-
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
index fb9d66e..7bf4bca 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -885,7 +885,7 @@ static int initialize_nocpsch(struct device_queue_manager 
*dqm)
}
 
dqm->vmid_bitmap = (1 << dqm->dev->vm_info.vmid_num_kfd) - 1;
-   dqm->sdma_bitmap = (1 << get_num_sdma_queues(dqm)) - 1;
+   dqm->sdma_bitmap = (1ULL << get_num_sdma_queues(dqm)) - 1;
 
return 0;
 }
@@ -923,8 +923,8 @@ static int allocate_sdma_queue(struct device_queue_manager 
*dqm,
if (dqm->sdma_bitmap == 0)
return -ENOMEM;
 
-   bit = ffs(dqm->sdma_bitmap) - 1;
-   dqm->sdma_bitmap &= ~(1 << bit);
+   bit = __ffs64(dqm->sdma_bitmap);
+   dqm->sdma_bitmap &= ~(1ULL << bit);
*sdma_queue_id = bit;
 
return 0;
@@ -935,7 +935,7 @@ static void deallocate_sdma_queue(struct 
device_queue_manager *dqm,
 {
if (sdma_queue_id >= get_num_sdma_queues(dqm))
return;
-   dqm->sdma_bitmap |= (1 << sdma_queue_id);
+   dqm->sdma_bitmap |= (1ULL << sdma_queue_id);
 }
 
 static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm,
@@ -1041,7 +1041,7 @@ static int initialize_cpsch(struct device_queue_manager 
*dqm)
dqm->queue_count = dqm->processes_count = 0;
dqm->sdma_queue_count = 0;
dqm->active_runlist = false;
-   dqm->sdma_bitmap = (1 << get_num_sdma_queues(dqm)) - 1;
+   dqm->sdma_bitmap = (1ULL << get_num_sdma_queues(dqm)) - 1;
 
INIT_WORK(&dqm->hw_exception_work, kfd_process_hw_exception);
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
index 70e38a2..2770f3e 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h
@@ -188,7 +188,7 @@ struct device_queue_manager {
unsigned inttotal_queue_count;
unsigned intnext_pipe_to_allocate;
unsigned int*allocated_queues;
-   unsigned intsdma_bitmap;
+   uint64_tsdma_bitmap;
unsigned intvmid_bitmap;
uint64_tpipelines_addr;
struct kfd_mem_obj  *pipeline_mem;
-- 
2.7.4

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


[PATCH 2/4] drm/amdkfd: Added more SDMA queue type

2018-11-13 Thread Oak Zeng
From: Oak Zeng 

The new types are used to allocate SDMA queue on specific
SDMA engine

Change-Id: Ica4cd7013eb86103a92cec2f74d96ac037b5ecbd
Signed-off-by: Oak Zeng 
Reviewd-by: Felix Kuehling 
---
 include/uapi/linux/kfd_ioctl.h | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/kfd_ioctl.h b/include/uapi/linux/kfd_ioctl.h
index b01eb50..8cc6e7d 100644
--- a/include/uapi/linux/kfd_ioctl.h
+++ b/include/uapi/linux/kfd_ioctl.h
@@ -35,9 +35,13 @@ struct kfd_ioctl_get_version_args {
 };
 
 /* For kfd_ioctl_create_queue_args.queue_type. */
-#define KFD_IOC_QUEUE_TYPE_COMPUTE 0
-#define KFD_IOC_QUEUE_TYPE_SDMA1
-#define KFD_IOC_QUEUE_TYPE_COMPUTE_AQL 2
+#define KFD_IOC_QUEUE_TYPE_COMPUTE 0x0
+#define KFD_IOC_QUEUE_TYPE_SDMA0x1
+#define KFD_IOC_QUEUE_TYPE_COMPUTE_AQL 0x2
+#define KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(e)  (0x1 + (e))
+#define KFD_IOC_QUEUE_TYPE_SDMA_AQL_ENGINE(e)  (0x2 + (e))
+#define KFD_IOC_QUEUE_TYPE_SDMA_ENGINE_MAX 
(KFD_IOC_QUEUE_TYPE_SDMA_ENGINE(0x))
+#define KFD_IOC_QUEUE_TYPE_SDMA_AQL_ENGINE_MAX 
(KFD_IOC_QUEUE_TYPE_SDMA_AQL_ENGINE(0x))
 
 #define KFD_MAX_QUEUE_PERCENTAGE   100
 #define KFD_MAX_QUEUE_PRIORITY 15
-- 
2.7.4

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


[PATCH] drm/amdgpu: Expose an IP function to get register offset

2018-10-30 Thread Oak Zeng
Expose get_reg_offset function of sdma_v4_0 for kfd to use

Change-Id: Ib687b390d6d3f8c8a35651e064e35aacf6722f98
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c   | 7 +++
 drivers/gpu/drm/amd/include/amd_shared.h | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c 
b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
index f35f578..1b6c591 100644
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c
@@ -206,6 +206,12 @@ static u32 sdma_v4_0_get_reg_offset(struct amdgpu_device 
*adev,
return 0;
 }
 
+static u32 sdma_v4_0_get_reg_offset_external(void *handle, u32 instance, u32 
offset)
+{
+   struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+   return sdma_v4_0_get_reg_offset(adev, instance, offset);
+}
+
 static unsigned sdma_v4_0_seq_to_irq_id(int seq_num)
 {
switch (seq_num) {
@@ -1746,6 +1752,7 @@ const struct amd_ip_funcs sdma_v4_0_ip_funcs = {
.set_clockgating_state = sdma_v4_0_set_clockgating_state,
.set_powergating_state = sdma_v4_0_set_powergating_state,
.get_clockgating_state = sdma_v4_0_get_clockgating_state,
+   .get_reg_offset = sdma_v4_0_get_reg_offset_external,
 };
 
 static const struct amdgpu_ring_funcs sdma_v4_0_ring_funcs = {
diff --git a/drivers/gpu/drm/amd/include/amd_shared.h 
b/drivers/gpu/drm/amd/include/amd_shared.h
index fc7fcb1..ab44fa8 100644
--- a/drivers/gpu/drm/amd/include/amd_shared.h
+++ b/drivers/gpu/drm/amd/include/amd_shared.h
@@ -173,6 +173,9 @@ struct amd_ip_funcs {
 enum amd_powergating_state state);
/* get current clockgating status */
void (*get_clockgating_state)(void *handle, u32 *flags);
+
+   /* get instance's register offset */
+   u32 (*get_reg_offset)(void *handle, u32 instance, u32 offset);
 };
 
 
-- 
2.7.4

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


[PATCH] drm/amdgpu: Added a few comments for gart

2018-10-24 Thread Oak Zeng
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index 9a212aa..6d11e17 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -259,6 +259,8 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t 
offset,
  * @offset: offset into the GPU's gart aperture
  * @pages: number of pages to bind
  * @dma_addr: DMA addresses of pages
+ * @flags: page table entry flags
+ * @dst: CPU address of the gart table
  *
  * Map the dma_addresses into GART entries (all asics).
  * Returns 0 for success, -EINVAL for failure.
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h
index 9ff6288..afa2e28 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.h
@@ -41,6 +41,7 @@ struct amdgpu_bo;
 
 struct amdgpu_gart {
struct amdgpu_bo*bo;
+   /* CPU kmapped address of gart table */
void*ptr;
unsignednum_gpu_pages;
unsignednum_cpu_pages;
-- 
2.7.4

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


[PATCH 1/2] drm/amdgpu: Moved fault hash table to amdgpu vm

2018-09-07 Thread Oak Zeng
In stead of share one fault hash table per device, make it
per vm. This can avoid inter-process lock issue when fault
hash table is full.

Change-Id: I5d1281b7c41eddc8e26113e010516557588d3708
Signed-off-by: Oak Zeng 
Suggested-by: Christian Konig 
Suggested-by: Felix Kuehling 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c |  75 
 drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h |  10 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 102 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  12 
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c |  38 +---
 5 files changed, 127 insertions(+), 110 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
index 06373d4..4ed8621 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
@@ -197,78 +197,3 @@ int amdgpu_ih_process(struct amdgpu_device *adev)
return IRQ_HANDLED;
 }
 
-/**
- * amdgpu_ih_add_fault - Add a page fault record
- *
- * @adev: amdgpu device pointer
- * @key: 64-bit encoding of PASID and address
- *
- * This should be called when a retry page fault interrupt is
- * received. If this is a new page fault, it will be added to a hash
- * table. The return value indicates whether this is a new fault, or
- * a fault that was already known and is already being handled.
- *
- * If there are too many pending page faults, this will fail. Retry
- * interrupts should be ignored in this case until there is enough
- * free space.
- *
- * Returns 0 if the fault was added, 1 if the fault was already known,
- * -ENOSPC if there are too many pending faults.
- */
-int amdgpu_ih_add_fault(struct amdgpu_device *adev, u64 key)
-{
-   unsigned long flags;
-   int r = -ENOSPC;
-
-   if (WARN_ON_ONCE(!adev->irq.ih.faults))
-   /* Should be allocated in _ih_sw_init on GPUs that
-* support retry faults and require retry filtering.
-*/
-   return r;
-
-   spin_lock_irqsave(&adev->irq.ih.faults->lock, flags);
-
-   /* Only let the hash table fill up to 50% for best performance */
-   if (adev->irq.ih.faults->count >= (1 << (AMDGPU_PAGEFAULT_HASH_BITS-1)))
-   goto unlock_out;
-
-   r = chash_table_copy_in(&adev->irq.ih.faults->hash, key, NULL);
-   if (!r)
-   adev->irq.ih.faults->count++;
-
-   /* chash_table_copy_in should never fail unless we're losing count */
-   WARN_ON_ONCE(r < 0);
-
-unlock_out:
-   spin_unlock_irqrestore(&adev->irq.ih.faults->lock, flags);
-   return r;
-}
-
-/**
- * amdgpu_ih_clear_fault - Remove a page fault record
- *
- * @adev: amdgpu device pointer
- * @key: 64-bit encoding of PASID and address
- *
- * This should be called when a page fault has been handled. Any
- * future interrupt with this key will be processed as a new
- * page fault.
- */
-void amdgpu_ih_clear_fault(struct amdgpu_device *adev, u64 key)
-{
-   unsigned long flags;
-   int r;
-
-   if (!adev->irq.ih.faults)
-   return;
-
-   spin_lock_irqsave(&adev->irq.ih.faults->lock, flags);
-
-   r = chash_table_remove(&adev->irq.ih.faults->hash, key, NULL);
-   if (!WARN_ON_ONCE(r < 0)) {
-   adev->irq.ih.faults->count--;
-   WARN_ON_ONCE(adev->irq.ih.faults->count < 0);
-   }
-
-   spin_unlock_irqrestore(&adev->irq.ih.faults->lock, flags);
-}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
index a23e1c0..f411ffb 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
@@ -32,13 +32,6 @@ struct amdgpu_device;
 #define AMDGPU_IH_CLIENTID_LEGACY 0
 #define AMDGPU_IH_CLIENTID_MAX SOC15_IH_CLIENTID_MAX
 
-#define AMDGPU_PAGEFAULT_HASH_BITS 8
-struct amdgpu_retryfault_hashtable {
-   DECLARE_CHASH_TABLE(hash, AMDGPU_PAGEFAULT_HASH_BITS, 8, 0);
-   spinlock_t  lock;
-   int count;
-};
-
 /*
  * R6xx+ IH ring
  */
@@ -57,7 +50,6 @@ struct amdgpu_ih_ring {
booluse_doorbell;
booluse_bus_addr;
dma_addr_t  rb_dma_addr; /* only used when use_bus_addr = 
true */
-   struct amdgpu_retryfault_hashtable *faults;
 };
 
 #define AMDGPU_IH_SRC_DATA_MAX_SIZE_DW 4
@@ -95,7 +87,5 @@ int amdgpu_ih_ring_init(struct amdgpu_device *adev, unsigned 
ring_size,
bool use_bus_addr);
 void amdgpu_ih_ring_fini(struct amdgpu_device *adev);
 int amdgpu_ih_process(struct amdgpu_device *adev);
-int amdgpu_ih_add_fault(struct amdgpu_device *adev, u64 key);
-void amdgpu_ih_clear_fault(struct amdgpu_device *adev, u64 key);
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 1d7e3c1..8b220e9 100644
--- 

[PATCH 2/2] drm/amdgpu: Deleted faults kfifo

2018-09-07 Thread Oak Zeng
With the change of making fault hash per vm, this is not needed
anymore.

Change-Id: I9427ff1786deaf1f5b7d121a6f7f75f00acfc9b7
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 ---
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c | 9 -
 3 files changed, 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 8b220e9..5767a95 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2802,7 +2802,6 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
goto error_free_root;
}
 
-   INIT_KFIFO(vm->faults);
vm->fault_credit = 16;
 
return 0;
@@ -2993,10 +2992,6 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct 
amdgpu_vm *vm)
 
amdgpu_amdkfd_gpuvm_destroy_cb(adev, vm);
 
-   /* Clear pending page faults from IH when the VM is destroyed */
-   while (kfifo_get(&vm->faults, &fault))
-   amdgpu_vm_clear_fault(vm->fault_hash, fault);
-
if (vm->pasid) {
unsigned long flags;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
index 6eb1da1..75842f1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h
@@ -225,9 +225,6 @@ struct amdgpu_vm {
/* Flag to indicate ATS support from PTE for GFX9 */
boolpte_support_ats;
 
-   /* Up to 128 pending retry page faults */
-   DECLARE_KFIFO(faults, u64, 128);
-
/* Limit non-retry fault storms */
unsigned intfault_credit;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_ih.c 
b/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
index acbe5a7..7f0ed91 100644
--- a/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/vega10_ih.c
@@ -265,7 +265,6 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device 
*adev)
return true;
}
 
-   /* Track retry faults in per-VM fault FIFO. */
spin_lock(&adev->vm_manager.pasid_lock);
vm = idr_find(&adev->vm_manager.pasid_idr, pasid);
addr = ((u64)(dw5 & 0xf) << 44) | ((u64)dw4 << 12);
@@ -285,14 +284,6 @@ static bool vega10_ih_prescreen_iv(struct amdgpu_device 
*adev)
goto ignore_iv;
}
}
-   /* No locking required with single writer and single reader */
-   r = kfifo_put(&vm->faults, key);
-   if (!r) {
-   /* FIFO is full. Ignore it until there is space */
-   amdgpu_vm_clear_fault(vm->fault_hash, key);
-   spin_unlock(&adev->vm_manager.pasid_lock);
-   goto ignore_iv;
-   }
 
spin_unlock(&adev->vm_manager.pasid_lock);
/* It's the first fault for this address, process it normally */
-- 
2.7.4

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


[PATCH 2/2] drm/amdkfd: Release an acquired process vm

2018-08-28 Thread Oak Zeng
For compute vm acquired from amdgpu, vm.pasid is managed
by kfd. Decouple pasid from such vm on process destroy
to avoid duplicate pasid release.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h|  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 19 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c| 20 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h|  1 +
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  |  4 +++-
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h   |  1 +
 9 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e1f6454..b414889 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -165,6 +165,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
 void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct kgd_dev *kgd, void *vm);
+void amdgpu_amdkfd_gpuvm_release_process_vm(struct kgd_dev *kgd, void *vm);
 uint32_t amdgpu_amdkfd_gpuvm_get_process_page_dir(void *vm);
 int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
struct kgd_dev *kgd, uint64_t va, uint64_t size,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
index ea79908..03a83d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
@@ -204,6 +204,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
index 19dd665..b2b9c5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
@@ -164,6 +164,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index 1db60aa..3722bbd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -201,6 +201,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 0980a1f..bc4413f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1117,6 +1117,25 @@ void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct 
kgd_dev *kgd, void *vm)
kfree(vm);
 }
 
+void amdgpu_amdkfd_gpuvm_release_process_vm(struct kgd_dev *kgd, void *vm)
+{
+   struct amdgpu_device *adev = get_amdgpu_device(kgd);
+struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
+
+   if (WARN_ON(!kgd || !vm))
+return;
+
+pr_debug("Releasing process vm %p\n", vm);
+
+/* The original pasid of amdgpu vm has already been
+ * released during making a amdgpu vm to a compute vm
+ * The current pasid is managed by kfd and will be
+ * released on kfd process destroy. Set amdgpu pasid
+ * to 0 to avoid duplica

[PATCH 1/2] drm/amdgpu: Set pasid for compute vm

2018-08-28 Thread Oak Zeng
To make a amdgpu vm to a compute vm, the old pasid will be freed and
replaced with a pasid managed by kfd. Kfd can't reuse original pasid
allocated by amdgpu because kfd uses different pasid policy with amdgpu.
For example, all graphic devices share one same pasid in a process.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h   |  6 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   | 33 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  4 +--
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  |  5 ++--
 6 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index a8418a3..e1f6454 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -155,11 +155,11 @@ uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev 
*kgd);
})
 
 /* GPUVM API */
-int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
-   void **process_info,
+int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int 
pasid,
+   void **vm, void **process_info,
struct dma_fence **ef);
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
-   struct file *filp,
+   struct file *filp, unsigned int pasid,
void **vm, void **process_info,
struct dma_fence **ef);
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 7eadc58..0980a1f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1003,8 +1003,8 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void 
**process_info,
return ret;
 }
 
-int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
- void **process_info,
+int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int 
pasid,
+ void **vm, void **process_info,
  struct dma_fence **ef)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
@@ -1016,7 +1016,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
return -ENOMEM;
 
/* Initialize AMDGPU part of the VM */
-   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, 0);
+   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, pasid);
if (ret) {
pr_err("Failed init vm ret %d\n", ret);
goto amdgpu_vm_init_fail;
@@ -1039,7 +1039,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
 }
 
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
-  struct file *filp,
+  struct file *filp, unsigned int 
pasid,
   void **vm, void **process_info,
   struct dma_fence **ef)
 {
@@ -1054,7 +1054,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
return -EINVAL;
 
/* Convert VM into a compute VM */
-   ret = amdgpu_vm_make_compute(adev, avm);
+   ret = amdgpu_vm_make_compute(adev, avm, pasid);
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 662aec5..d8a99f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2690,7 +2690,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
  * Returns:
  * 0 for success, -errno for errors.
  */
-int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
+int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, 
unsigned int pasid)
 {
bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
int r;
@@ -2702,7 +2702,20 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, 
struct amdgpu_vm *vm)
/* Sanity checks */
if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
r = -EINVAL;
-   goto error;
+   goto unreserve_bo;
+   }
+
+   if (pasid) {
+   unsigned long flags;
+
+   spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
+   r = idr_alloc(&adev->

[PATCH 1/2] drm/amdgpu: Set pasid for compute vm

2018-08-28 Thread Oak Zeng
To make a amdgpu vm to a compute vm, the old pasid will be freed and
replaced with a pasid managed by kfd. Kfd can't reuse original pasid
allocated by amdgpu because kfd uses different pasid policy with amdgpu.
For example, all graphic devices share one same pasid in a process.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h   |  6 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   | 33 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  4 +--
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  |  5 ++--
 6 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index a8418a3..e1f6454 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -155,11 +155,11 @@ uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev 
*kgd);
})
 
 /* GPUVM API */
-int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
-   void **process_info,
+int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int 
pasid,
+   void **vm, void **process_info,
struct dma_fence **ef);
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
-   struct file *filp,
+   struct file *filp, unsigned int pasid,
void **vm, void **process_info,
struct dma_fence **ef);
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 7eadc58..0980a1f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1003,8 +1003,8 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void 
**process_info,
return ret;
 }
 
-int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
- void **process_info,
+int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, unsigned int 
pasid,
+ void **vm, void **process_info,
  struct dma_fence **ef)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
@@ -1016,7 +1016,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
return -ENOMEM;
 
/* Initialize AMDGPU part of the VM */
-   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, 0);
+   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, pasid);
if (ret) {
pr_err("Failed init vm ret %d\n", ret);
goto amdgpu_vm_init_fail;
@@ -1039,7 +1039,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
 }
 
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
-  struct file *filp,
+  struct file *filp, unsigned int 
pasid,
   void **vm, void **process_info,
   struct dma_fence **ef)
 {
@@ -1054,7 +1054,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
return -EINVAL;
 
/* Convert VM into a compute VM */
-   ret = amdgpu_vm_make_compute(adev, avm);
+   ret = amdgpu_vm_make_compute(adev, avm, pasid);
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 662aec5..d8a99f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2690,7 +2690,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
  * Returns:
  * 0 for success, -errno for errors.
  */
-int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
+int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, 
unsigned int pasid)
 {
bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
int r;
@@ -2702,7 +2702,20 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, 
struct amdgpu_vm *vm)
/* Sanity checks */
if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
r = -EINVAL;
-   goto error;
+   goto unreserve_bo;
+   }
+
+   if (pasid) {
+   unsigned long flags;
+
+   spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
+   r = idr_alloc(&adev->

[PATCH 2/2] drm/amdkfd: Release an acquired process vm

2018-08-28 Thread Oak Zeng
For compute vm acquired from amdgpu, vm.pasid is managed
by kfd. Decouple pasid from such vm on process destroy
to avoid duplicate pasid release.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h|  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 26 +++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  |  4 +++-
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h   |  1 +
 7 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index e1f6454..b414889 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -165,6 +165,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
 void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct kgd_dev *kgd, void *vm);
+void amdgpu_amdkfd_gpuvm_release_process_vm(struct kgd_dev *kgd, void *vm);
 uint32_t amdgpu_amdkfd_gpuvm_get_process_page_dir(void *vm);
 int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
struct kgd_dev *kgd, uint64_t va, uint64_t size,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
index ea79908..03a83d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
@@ -204,6 +204,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
index 19dd665..b2b9c5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
@@ -164,6 +164,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index 1db60aa..3722bbd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -201,6 +201,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 0980a1f..6fd839c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1117,6 +1117,32 @@ void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct 
kgd_dev *kgd, void *vm)
kfree(vm);
 }
 
+void amdgpu_amdkfd_gpuvm_release_process_vm(struct kgd_dev *kgd, void *vm)
+{
+   struct amdgpu_device *adev = get_amdgpu_device(kgd);
+struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
+
+if (WARN_ON(!vm))
+return;
+
+pr_debug("Releasing process vm %p\n", vm);
+
+/* The original pasid of amdgpu vm has already been
+ * released during making a amdgpu vm to a compute vm
+ * The current pasid is managed by kfd and will be
+ * released on kfd process destroy. Set amdgpu pasid
+ * to 0 to avoid duplicate release.
+ */
+   if (avm->pasid) {
+   unsigned long flags;
+
+   spin_lock_

[PATCH 1/2] drm/amdgpu: Set pasid for compute vm

2018-08-27 Thread Oak Zeng
To make a amdgpu vm to a compute vm, the old pasid will be freed and
replaced with a pasid managed by kfd. Kfd can't reuse original pasid
allocated by amdgpu because kfd uses different pasid policy with amdgpu.
For example, all graphic devices share one same pasid in a process.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h   |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c |  7 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   | 33 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  4 +--
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  |  5 ++--
 6 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index a8418a3..2895ef5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -156,11 +156,12 @@ uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev 
*kgd);
 
 /* GPUVM API */
 int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
-   void **process_info,
+   void **process_info, unsigned int pasid,
struct dma_fence **ef);
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
struct file *filp,
void **vm, void **process_info,
+   unsigned int pasid,
struct dma_fence **ef);
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 7eadc58..d60940e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1004,7 +1004,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void 
**process_info,
 }
 
 int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
- void **process_info,
+ void **process_info, unsigned int 
pasid,
  struct dma_fence **ef)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
@@ -1016,7 +1016,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
return -ENOMEM;
 
/* Initialize AMDGPU part of the VM */
-   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, 0);
+   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, pasid);
if (ret) {
pr_err("Failed init vm ret %d\n", ret);
goto amdgpu_vm_init_fail;
@@ -1041,6 +1041,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
   struct file *filp,
   void **vm, void **process_info,
+  unsigned int pasid,
   struct dma_fence **ef)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
@@ -1054,7 +1055,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
return -EINVAL;
 
/* Convert VM into a compute VM */
-   ret = amdgpu_vm_make_compute(adev, avm);
+   ret = amdgpu_vm_make_compute(adev, avm, pasid);
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 662aec5..d8a99f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2690,7 +2690,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
  * Returns:
  * 0 for success, -errno for errors.
  */
-int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
+int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, 
unsigned int pasid)
 {
bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
int r;
@@ -2702,7 +2702,20 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, 
struct amdgpu_vm *vm)
/* Sanity checks */
if (!RB_EMPTY_ROOT(&vm->va.rb_root) || vm->root.entries) {
r = -EINVAL;
-   goto error;
+   goto unreserve_bo;
+   }
+
+   if (pasid) {
+   unsigned long flags;
+
+   spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
+   r = idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid, pasid + 1,
+ GFP_ATOMIC);
+   spin_unlock_irqr

[PATCH 2/2] drm/amdkfd: Release an acquired process vm

2018-08-27 Thread Oak Zeng
For compute vm acquired from amdgpu, vm.pasid is managed
by kfd. Decouple pasid from such vm on process destroy
to avoid duplicate pasid release.

Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h|  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 18 ++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c  |  4 +++-
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h   |  1 +
 7 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 2895ef5..5827734 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -166,6 +166,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
 void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct kgd_dev *kgd, void *vm);
+void amdgpu_amdkfd_gpuvm_release_process_vm(void *vm);
 uint32_t amdgpu_amdkfd_gpuvm_get_process_page_dir(void *vm);
 int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
struct kgd_dev *kgd, uint64_t va, uint64_t size,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
index ea79908..03a83d3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v7.c
@@ -204,6 +204,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
index 19dd665..b2b9c5f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v8.c
@@ -164,6 +164,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
index 1db60aa..3722bbd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c
@@ -201,6 +201,7 @@ static const struct kfd2kgd_calls kfd2kgd = {
.create_process_vm = amdgpu_amdkfd_gpuvm_create_process_vm,
.acquire_process_vm = amdgpu_amdkfd_gpuvm_acquire_process_vm,
.destroy_process_vm = amdgpu_amdkfd_gpuvm_destroy_process_vm,
+   .release_process_vm = amdgpu_amdkfd_gpuvm_release_process_vm,
.get_process_page_dir = amdgpu_amdkfd_gpuvm_get_process_page_dir,
.set_vm_context_page_table_base = set_vm_context_page_table_base,
.alloc_memory_of_gpu = amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index d60940e..7d1cdcd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1118,6 +1118,24 @@ void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct 
kgd_dev *kgd, void *vm)
kfree(vm);
 }
 
+void amdgpu_amdkfd_gpuvm_release_process_vm(void *vm)
+{
+struct amdgpu_vm *avm = (struct amdgpu_vm *)vm; 
+
+if (WARN_ON(!vm))
+return;   
+
+pr_debug("Releasing process vm %p\n", vm);
+
+/* The original pasid of amdgpu vm has already been
+ * released during making a amdgpu vm to a compute vm
+ * The current pasid is managed by kfd and will be
+ * released on kfd process destroy. Set amdgpu pasid
+ * to 0 to avoid duplicate release.
+ */
+avm->pasid = 0;
+}
+
 uint32_t amdgpu_amdkfd_gpuvm_get_process_page_dir(void *vm)
 {
struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c 
b/dr

[PATCH] drm/amdgpu: Set pasid for compute vm

2018-08-22 Thread Oak Zeng
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c |  8 
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c   | 20 +---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h   |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_process.c |  4 ++--
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h  |  4 ++--
 6 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index a8418a3..8939f54 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -157,11 +157,11 @@ uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev 
*kgd);
 /* GPUVM API */
 int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
void **process_info,
-   struct dma_fence **ef);
+   struct dma_fence **ef, unsigned int 
pasid);
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
struct file *filp,
void **vm, void **process_info,
-   struct dma_fence **ef);
+   struct dma_fence **ef, unsigned int 
pasid);
 void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev,
struct amdgpu_vm *vm);
 void amdgpu_amdkfd_gpuvm_destroy_process_vm(struct kgd_dev *kgd, void *vm);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 7eadc58..659c397 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1005,7 +1005,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void 
**process_info,
 
 int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev *kgd, void **vm,
  void **process_info,
- struct dma_fence **ef)
+ struct dma_fence **ef, unsigned int 
pasid)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
struct amdgpu_vm *new_vm;
@@ -1016,7 +1016,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
return -ENOMEM;
 
/* Initialize AMDGPU part of the VM */
-   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, 0);
+   ret = amdgpu_vm_init(adev, new_vm, AMDGPU_VM_CONTEXT_COMPUTE, pasid);
if (ret) {
pr_err("Failed init vm ret %d\n", ret);
goto amdgpu_vm_init_fail;
@@ -1041,7 +1041,7 @@ int amdgpu_amdkfd_gpuvm_create_process_vm(struct kgd_dev 
*kgd, void **vm,
 int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev *kgd,
   struct file *filp,
   void **vm, void **process_info,
-  struct dma_fence **ef)
+  struct dma_fence **ef, unsigned int 
pasid)
 {
struct amdgpu_device *adev = get_amdgpu_device(kgd);
struct drm_file *drm_priv = filp->private_data;
@@ -1054,7 +1054,7 @@ int amdgpu_amdkfd_gpuvm_acquire_process_vm(struct kgd_dev 
*kgd,
return -EINVAL;
 
/* Convert VM into a compute VM */
-   ret = amdgpu_vm_make_compute(adev, avm);
+   ret = amdgpu_vm_make_compute(adev, avm, pasid);
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 662aec5..0f6b304 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2690,7 +2690,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct 
amdgpu_vm *vm,
  * Returns:
  * 0 for success, -errno for errors.
  */
-int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm)
+int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm, 
unsigned int pasid)
 {
bool pte_support_ats = (adev->asic_type == CHIP_RAVEN);
int r;
@@ -2705,6 +2705,18 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, 
struct amdgpu_vm *vm)
goto error;
}
 
+   if (vm->pasid) {
+   unsigned long flags;
+
+   spin_lock_irqsave(&adev->vm_manager.pasid_lock, flags);
+   r = idr_alloc(&adev->vm_manager.pasid_idr, vm, pasid, pasid + 1,
+ GFP_ATOMIC);
+   spin_unlock_irqrestore(&adev->vm_manager.pasid_lock, flags);
+
+   if (r < 0)
+   goto error;
+   }
+
/* Check if PD needs to be reinitialized and do it before
 *

[PATCH] drm/amdgpu: Move IH clientid defs to separate file

2018-03-11 Thread Oak Zeng
This is preparation for sharing client ID definitions
between amdgpu and amdkfd

Change-Id: Ie0b7b14c9c2366fd896745a51b74a9ba97ee3224
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h | 43 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c  |  8 +--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/mxgpu_ai.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c |  8 +--
 drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c  |  2 +-
 drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c  |  4 +-
 drivers/gpu/drm/amd/amdgpu/vega10_ih.c |  4 +-
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c  |  8 +--
 drivers/gpu/drm/amd/include/soc15_ih_clientid.h| 70 ++
 drivers/gpu/drm/amd/powerplay/hwmgr/vega10_hwmgr.c |  6 +-
 12 files changed, 98 insertions(+), 67 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/soc15_ih_clientid.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
index b8a7dba..0e01f11 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
@@ -25,51 +25,12 @@
 #define __AMDGPU_IH_H__
 
 #include 
+#include "soc15_ih_clientid.h"
 
 struct amdgpu_device;
- /*
-  * vega10+ IH clients
- */
-enum amdgpu_ih_clientid
-{
-AMDGPU_IH_CLIENTID_IH  = 0x00,
-AMDGPU_IH_CLIENTID_ACP = 0x01,
-AMDGPU_IH_CLIENTID_ATHUB   = 0x02,
-AMDGPU_IH_CLIENTID_BIF = 0x03,
-AMDGPU_IH_CLIENTID_DCE = 0x04,
-AMDGPU_IH_CLIENTID_ISP = 0x05,
-AMDGPU_IH_CLIENTID_PCIE0   = 0x06,
-AMDGPU_IH_CLIENTID_RLC = 0x07,
-AMDGPU_IH_CLIENTID_SDMA0   = 0x08,
-AMDGPU_IH_CLIENTID_SDMA1   = 0x09,
-AMDGPU_IH_CLIENTID_SE0SH   = 0x0a,
-AMDGPU_IH_CLIENTID_SE1SH   = 0x0b,
-AMDGPU_IH_CLIENTID_SE2SH   = 0x0c,
-AMDGPU_IH_CLIENTID_SE3SH   = 0x0d,
-AMDGPU_IH_CLIENTID_SYSHUB  = 0x0e,
-AMDGPU_IH_CLIENTID_THM = 0x0f,
-AMDGPU_IH_CLIENTID_UVD = 0x10,
-AMDGPU_IH_CLIENTID_VCE0= 0x11,
-AMDGPU_IH_CLIENTID_VMC = 0x12,
-AMDGPU_IH_CLIENTID_XDMA= 0x13,
-AMDGPU_IH_CLIENTID_GRBM_CP = 0x14,
-AMDGPU_IH_CLIENTID_ATS = 0x15,
-AMDGPU_IH_CLIENTID_ROM_SMUIO= 0x16,
-AMDGPU_IH_CLIENTID_DF  = 0x17,
-AMDGPU_IH_CLIENTID_VCE1= 0x18,
-AMDGPU_IH_CLIENTID_PWR = 0x19,
-AMDGPU_IH_CLIENTID_UTCL2   = 0x1b,
-AMDGPU_IH_CLIENTID_EA  = 0x1c,
-AMDGPU_IH_CLIENTID_UTCL2LOG= 0x1d,
-AMDGPU_IH_CLIENTID_MP0 = 0x1e,
-AMDGPU_IH_CLIENTID_MP1 = 0x1f,
-
-AMDGPU_IH_CLIENTID_MAX,
-
-AMDGPU_IH_CLIENTID_VCN = AMDGPU_IH_CLIENTID_UVD
-};
 
 #define AMDGPU_IH_CLIENTID_LEGACY 0
+#define AMDGPU_IH_CLIENTID_MAX SOC15_IH_CLIENTID_MAX
 
 #define AMDGPU_PAGEFAULT_HASH_BITS 8
 struct amdgpu_retryfault_hashtable {
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
index d73bbb0..d1d2c27 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c
@@ -1261,23 +1261,23 @@ static int gfx_v9_0_sw_init(void *handle)
adev->gfx.mec.num_queue_per_pipe = 8;
 
/* KIQ event */
-   r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_GRBM_CP, 178, 
&adev->gfx.kiq.irq);
+   r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_GRBM_CP, 178, 
&adev->gfx.kiq.irq);
if (r)
return r;
 
/* EOP Event */
-   r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_GRBM_CP, 181, 
&adev->gfx.eop_irq);
+   r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_GRBM_CP, 181, 
&adev->gfx.eop_irq);
if (r)
return r;
 
/* Privileged reg */
-   r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_GRBM_CP, 184,
+   r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_GRBM_CP, 184,
  &adev->gfx.priv_reg_irq);
if (r)
return r;
 
/* Privileged inst */
-   r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_GRBM_CP, 185,
+   r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_GRBM_CP, 185,
  &adev->gfx.priv_inst_irq);
if (r)
return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c 
b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 67cd1fe..ebaacc6 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -863,9 +863,9 @@ static int gmc_v9_0_sw_init(void *handle)
}
 
/* This interrupt is VMC page fault.*/
-   r = amdgpu_irq_add_id(adev, AMDGPU_IH_CLIENTID_VMC, 0,
+   r = amdgpu_irq_add_id(adev, SOC15_IH_CLIENTID_VMC, 0,
&adev->gmc.vm_fault);
-

[PATCH] drm/amdgpu: Move IH clientid defs to separate file

2018-03-08 Thread Oak Zeng
This is preparation for sharing client ID definitions
between amdgpu and amdkfd

Change-Id: Ie0b7b14c9c2366fd896745a51b74a9ba97ee3224
Signed-off-by: Oak Zeng 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h  | 44 +--
 drivers/gpu/drm/amd/include/soc15_ih_clientid.h | 72 +
 2 files changed, 73 insertions(+), 43 deletions(-)
 create mode 100644 drivers/gpu/drm/amd/include/soc15_ih_clientid.h

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
index b8a7dba..62a9869 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.h
@@ -25,51 +25,9 @@
 #define __AMDGPU_IH_H__
 
 #include 
+#include "soc15_ih_clientid.h"
 
 struct amdgpu_device;
- /*
-  * vega10+ IH clients
- */
-enum amdgpu_ih_clientid
-{
-AMDGPU_IH_CLIENTID_IH  = 0x00,
-AMDGPU_IH_CLIENTID_ACP = 0x01,
-AMDGPU_IH_CLIENTID_ATHUB   = 0x02,
-AMDGPU_IH_CLIENTID_BIF = 0x03,
-AMDGPU_IH_CLIENTID_DCE = 0x04,
-AMDGPU_IH_CLIENTID_ISP = 0x05,
-AMDGPU_IH_CLIENTID_PCIE0   = 0x06,
-AMDGPU_IH_CLIENTID_RLC = 0x07,
-AMDGPU_IH_CLIENTID_SDMA0   = 0x08,
-AMDGPU_IH_CLIENTID_SDMA1   = 0x09,
-AMDGPU_IH_CLIENTID_SE0SH   = 0x0a,
-AMDGPU_IH_CLIENTID_SE1SH   = 0x0b,
-AMDGPU_IH_CLIENTID_SE2SH   = 0x0c,
-AMDGPU_IH_CLIENTID_SE3SH   = 0x0d,
-AMDGPU_IH_CLIENTID_SYSHUB  = 0x0e,
-AMDGPU_IH_CLIENTID_THM = 0x0f,
-AMDGPU_IH_CLIENTID_UVD = 0x10,
-AMDGPU_IH_CLIENTID_VCE0= 0x11,
-AMDGPU_IH_CLIENTID_VMC = 0x12,
-AMDGPU_IH_CLIENTID_XDMA= 0x13,
-AMDGPU_IH_CLIENTID_GRBM_CP = 0x14,
-AMDGPU_IH_CLIENTID_ATS = 0x15,
-AMDGPU_IH_CLIENTID_ROM_SMUIO= 0x16,
-AMDGPU_IH_CLIENTID_DF  = 0x17,
-AMDGPU_IH_CLIENTID_VCE1= 0x18,
-AMDGPU_IH_CLIENTID_PWR = 0x19,
-AMDGPU_IH_CLIENTID_UTCL2   = 0x1b,
-AMDGPU_IH_CLIENTID_EA  = 0x1c,
-AMDGPU_IH_CLIENTID_UTCL2LOG= 0x1d,
-AMDGPU_IH_CLIENTID_MP0 = 0x1e,
-AMDGPU_IH_CLIENTID_MP1 = 0x1f,
-
-AMDGPU_IH_CLIENTID_MAX,
-
-AMDGPU_IH_CLIENTID_VCN = AMDGPU_IH_CLIENTID_UVD
-};
-
-#define AMDGPU_IH_CLIENTID_LEGACY 0
 
 #define AMDGPU_PAGEFAULT_HASH_BITS 8
 struct amdgpu_retryfault_hashtable {
diff --git a/drivers/gpu/drm/amd/include/soc15_ih_clientid.h 
b/drivers/gpu/drm/amd/include/soc15_ih_clientid.h
new file mode 100644
index 000..e2e8c63
--- /dev/null
+++ b/drivers/gpu/drm/amd/include/soc15_ih_clientid.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2018 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.
+ *
+ */
+
+#ifndef __SOC15_IH_CLIENTID_H__
+#define __SOC15_IH_CLIENTID_H__
+
+ /*
+  * vega10+ IH clients
+ */
+enum amdgpu_ih_clientid {
+   AMDGPU_IH_CLIENTID_IH   = 0x00,
+   AMDGPU_IH_CLIENTID_ACP  = 0x01,
+   AMDGPU_IH_CLIENTID_ATHUB= 0x02,
+   AMDGPU_IH_CLIENTID_BIF  = 0x03,
+   AMDGPU_IH_CLIENTID_DCE  = 0x04,
+   AMDGPU_IH_CLIENTID_ISP  = 0x05,
+   AMDGPU_IH_CLIENTID_PCIE0= 0x06,
+   AMDGPU_IH_CLIENTID_RLC  = 0x07,
+   AMDGPU_IH_CLIENTID_SDMA0= 0x08,
+   AMDGPU_IH_CLIENTID_SDMA1= 0x09,
+   AMDGPU_IH_CLIENTID_SE0SH= 0x0a,
+   AMDGPU_IH_CLIENTID_SE1SH= 0x0b,
+   AMDGPU_IH_CLIENTID_SE2SH= 0x0c,
+   AMDGPU_IH_CLIENTID_SE3SH= 0x0d,
+   AMDGPU_IH_CLIENTID_SYSHUB   = 0x0e,
+   AMDGPU_IH_CLIENTID_THM  = 0x0f,
+   AMDGPU_IH_CLIENTID_UVD  = 0x10,
+   AMDGPU_IH_CLIENTID_VCE0 = 0x11,
+   AMDGPU_IH_CLIENTID_VMC  = 0x12,
+   AMDGPU_IH_CLIENTID_XDMA = 0x13,
+   AMDGPU_IH_CLIENTID_GRBM_CP  = 0x14,
+   AMDGPU_I

  1   2   >