Skip to contentSkip to conversation

drm/amdgpu: update mem rsv table

PATCH In review Alex Deucher 2 participants 4 messages Nov 5 – Nov 17

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu: update mem rsv table

From: Frank Min <[email protected]>

1. enlarge table number into 8
2. add table id filed in table info

---
 drivers/gpu/drm/amd/include/discovery.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/include/discovery.h +2 -1
index f5629a4ad04a1..0ed270406208b 100644
@@ -45,8 +45,9 @@ typedef enum {
 	VCN_INFO,
 	MALL_INFO,
 	NPS_INFO,
+	RSV_TABLE,
 	MEM_RESERVED_INFO,
-	TOTAL_TABLES = 7
+	TOTAL_TABLES = 8
 } table;
 
 #pragma pack(1)
Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu: update table info retrieval from discovery binary

From: Frank Min <[email protected]>

Update table info retrieval from discovery binary to align with discovery table update.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 47 +++++++++++++------
 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +33 -14
index 79a2b1268b23a..351a1e61f525e 100644
@@ -604,18 +604,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
 					 uint16_t table_id)
 {
 	struct binary_header *bhdr = (struct binary_header *)discovery_bin;
-	struct binary_header_v2 *bhdrv2;
-
-	switch (bhdr->version_major) {
-	case 2:
-		bhdrv2 = (struct binary_header_v2 *)discovery_bin;
-		return &bhdrv2->table_list[table_id];
-	case 1:
+	struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
+	uint16_t version = le16_to_cpu(bhdr->version_major);
+	uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
+	struct table_info *table_list;
+	uint16_t num_tables, i;
+	size_t table_offset;
+
+	switch (version) {
 	case 0:
-		return &bhdr->table_list[table_id];
+	case 1:
+		table_list = bhdr->table_list;
+		num_tables = ARRAY_SIZE(bhdr->table_list);
+		break;
+	case 2:
+		table_list = bhdrv2->table_list;
+		num_tables = le16_to_cpu(bhdrv2->num_tables);
+		break;
 	default:
 		return NULL;
 	}
+
+	table_offset = (uint8_t *)table_list - discovery_bin;
+	if (table_offset + num_tables * sizeof(*table_list) > binary_size)
+		return NULL;
+
+	for (i = 0; i < num_tables; i++)
+		if (le16_to_cpu(table_list[i].table_id) == table_id)
+			return &table_list[i];
+
+	return NULL;
 }
 
 static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
@@ -628,8 +646,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
 	*info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
 							 table_id);
 	if (!*info) {
-		dev_err(adev->dev, "Invalid ip discovery table version %d\n",
-			bhdr->version_major);
+		dev_err(adev->dev, "Not found table for header version %d table id %d\n",
+			bhdr->version_major, table_id);
 		return -EINVAL;
 	}
 
@@ -640,15 +658,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
 					uint8_t *discovery_bin,
 					uint16_t table_id)
 {
-	int r, act_val, exp_val, table_size;
+	int act_val, exp_val, table_size;
 	uint16_t offset, checksum;
 	struct table_info *info;
 	bool check_table = true;
 	char *table_name;
 
-	r = amdgpu_discovery_get_table_info(adev, &info, table_id);
-	if (r)
-		return r;
+	info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
+	if (!info)
+		return 0;
+
 	offset = le16_to_cpu(info->offset);
 	checksum = le16_to_cpu(info->checksum);
 
Signature · 1 line
2.56.0
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: update table info retrieval from discovery binary

Quoted 8 lines · Alex Deucher

From: Frank Min <[email protected]>

Update table info retrieval from discovery binary to align with discovery table update.

Series is:

Quoted 88 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 47 +++++++++++++------
 1 file changed, 33 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +33 -15
index 79a2b1268b23a..351a1e61f525e 100644
@@ -604,18 +604,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *discovery_bin,
                                         uint16_t table_id)
 {
        struct binary_header *bhdr = (struct binary_header *)discovery_bin;
-       struct binary_header_v2 *bhdrv2;
-
-       switch (bhdr->version_major) {
-       case 2:
-               bhdrv2 = (struct binary_header_v2 *)discovery_bin;
-               return &bhdrv2->table_list[table_id];
-       case 1:
+       struct binary_header_v2 *bhdrv2 = (struct binary_header_v2 *)discovery_bin;
+       uint16_t version = le16_to_cpu(bhdr->version_major);
+       uint16_t binary_size = le16_to_cpu(bhdr->binary_size);
+       struct table_info *table_list;
+       uint16_t num_tables, i;
+       size_t table_offset;
+
+       switch (version) {
        case 0:
-               return &bhdr->table_list[table_id];
+       case 1:
+               table_list = bhdr->table_list;
+               num_tables = ARRAY_SIZE(bhdr->table_list);
+               break;
+       case 2:
+               table_list = bhdrv2->table_list;
+               num_tables = le16_to_cpu(bhdrv2->num_tables);
+               break;
        default:
                return NULL;
        }
+
+       table_offset = (uint8_t *)table_list - discovery_bin;
+       if (table_offset + num_tables * sizeof(*table_list) > binary_size)
+               return NULL;
+
+       for (i = 0; i < num_tables; i++)
+               if (le16_to_cpu(table_list[i].table_id) == table_id)
+                       return &table_list[i];
+
+       return NULL;
 }
 
 static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
@@ -628,8 +646,8 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev,
        *info = amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin,
                                                         table_id);
        if (!*info) {
-               dev_err(adev->dev, "Invalid ip discovery table version %d\n",
-                       bhdr->version_major);
+               dev_err(adev->dev, "Not found table for header version %d table id %d\n",
+                       bhdr->version_major, table_id);
                return -EINVAL;
        }
 
@@ -640,15 +658,16 @@ static int amdgpu_discovery_table_check(struct amdgpu_device *adev,
                                        uint8_t *discovery_bin,
                                        uint16_t table_id)
 {
-       int r, act_val, exp_val, table_size;
+       int act_val, exp_val, table_size;
        uint16_t offset, checksum;
        struct table_info *info;
        bool check_table = true;
        char *table_name;
 
-       r = amdgpu_discovery_get_table_info(adev, &info, table_id);
-       if (r)
-               return r;
+       info = amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_id);
+       if (!info)
+               return 0;
+
        offset = le16_to_cpu(info->offset);
        checksum = le16_to_cpu(info->checksum);
 
--

2.56.0

#3 lore raw
In reply to Alex Deucher

ping?

Quoted 30 lines · Alex Deucher

From: Frank Min <[email protected]>

1. enlarge table number into 8
2. add table id filed in table info

---
 drivers/gpu/drm/amd/include/discovery.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/include/discovery.h +2 -2
index f5629a4ad04a1..0ed270406208b 100644
@@ -45,8 +45,9 @@ typedef enum {
        VCN_INFO,
        MALL_INFO,
        NPS_INFO,
+       RSV_TABLE,
        MEM_RESERVED_INFO,
-       TOTAL_TABLES = 7
+       TOTAL_TABLES = 8
 } table;
 
 #pragma pack(1)
--

2.56.0