From: Feifei Xu <[email protected]>

Add a lookup helper to pass a MEM_RESERVED_REGION_ID and receive the
region's start address and size.

A static amdgpu_discovery_mem_reserved_region_name() helper is also
introduced so debug output can refer to regions by symbolic name rather
than raw IDs.

Signed-off-by: Feifei Xu <[email protected]>
Reviewed-by: Hawking Zhang <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 55 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h |  4 ++
 2 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 4d55933f033cc..5d94453e85c6e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -2391,6 +2391,23 @@ int amdgpu_discovery_get_nps_info(struct amdgpu_device 
*adev,
        return 0;
 }
 
+static const char *amdgpu_discovery_mem_reserved_region_name(u32 id)
+{
+       switch (id) {
+       case NO_RESERVED_REGION_ID:             return "NO_RESERVED_REGION";
+       case PRE_OS_DISP_FW_REGION_ID:          return "PRE_OS_DISP_FW";
+       case MASTER_DIE_UMF_REGION_ID:          return "MASTER_DIE_UMF";
+       case DCC_META_DATA_REGION_ID:           return "DCC_META_DATA";
+       case VM_PAGE_FAULT_REGION_ID:           return "VM_PAGE_FAULT";
+       case G7_PSTATE_APERTURE1_ID:            return "G7_PSTATE_APERTURE1";
+       case G7_PSTATE_APERTURE2_ID:            return "G7_PSTATE_APERTURE2";
+       case G7_PSTATE_MIRROR_REGION_ID:        return "G7_PSTATE_MIRROR";
+       case G7_TRAINING_DATA_REGION_ID:        return "G7_TRAINING_DATA";
+       case SPECIFIC_PURPOSE_REGION_ID:        return "SPECIFIC_PURPOSE";
+       default:                                return "UNKNOWN";
+       }
+}
+
 /*
  * Resolve the MEM_RESERVED_INFO table from the IP discovery binary and
  * cache it in adev->discovery.mem_reserved_table.
@@ -2428,6 +2445,44 @@ int amdgpu_discovery_get_mem_reserved_info_table(struct 
amdgpu_device *adev)
        return 0;
 }
 
+/**
+ * Query mem_reserved_info by region ID
+ *
+ * @reserved_region_id: MEM_RESERVED_REGION_ID to look up
+ * @info:  pass NULL to skip
+ */
+int amdgpu_discovery_get_mem_reserved_region_by_id(struct amdgpu_device *adev,
+                                                  u32 reserved_region_id,
+                                                  struct mem_reserved_info 
*info)
+{
+       struct mem_reserved_info_table_v1_0 *table;
+       u32 list_num, i;
+
+       if (!adev->discovery.mem_reserved_table)
+               return -ENOENT;
+
+       table = adev->discovery.mem_reserved_table;
+       list_num = min_t(u32, le32_to_cpu(table->list_num), MAX_MEM_REGION_NUM);
+
+       for (i = 0; i < list_num; i++) {
+               if (le32_to_cpu(table->list[i].reserved_region_id) != 
reserved_region_id)
+                       continue;
+
+               if (info) {
+                       info->reserved_region_id = reserved_region_id;
+                       info->reserved_region_size =
+                               
le64_to_cpu(table->list[i].reserved_region_size);
+                       info->reserved_region_start =
+                               
le64_to_cpu(table->list[i].reserved_region_start);
+               }
+               dev_dbg(adev->dev, "Found reserved region: %s (id=%u)\n",
+                       
amdgpu_discovery_mem_reserved_region_name(reserved_region_id),
+                       reserved_region_id);
+               return 0;
+       }
+       return -ENOENT;
+}
+
 static int amdgpu_discovery_set_common_ip_blocks(struct amdgpu_device *adev)
 {
        /* what IP to use for this? */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
index 070b404c1944c..2cd00cc4ed363 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.h
@@ -63,4 +63,8 @@ void amdgpu_discovery_sysfs_early_fini(struct pci_dev *pdev);
 
 int amdgpu_discovery_get_mem_reserved_info_table(struct amdgpu_device *adev);
 
+int amdgpu_discovery_get_mem_reserved_region_by_id(struct amdgpu_device *adev,
+                                                  u32 reserved_region_id,
+                                                  struct mem_reserved_info 
*info);
+
 #endif /* __AMDGPU_DISCOVERY__ */
-- 
2.55.0

Reply via email to