Skip to contentSkip to conversation

drm/amdgpu/vcn: Move RDECODE_* to amdgpu_vcn.h

PATCH Superseded Benjamin Cheng 2 participants 4 messages Apr 8

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 drm/amdgpu/vcn: Move RDECODE_* to amdgpu_vcn.h

These defines can be shared.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 3 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 3 ---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 3 ---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 3 ---
 4 files changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +3 -0
index 82624b44e661..fd9657ae6c37 100644
@@ -57,6 +57,9 @@
 #define VCN_DEC_SW_CMD_REG_WRITE	0x0000000b
 #define VCN_DEC_SW_CMD_REG_WAIT		0x0000000c
 
+#define RDECODE_MSG_CREATE		0x00000000
+#define RDECODE_MESSAGE_CREATE		0x00000001
+
 #define VCN_ENC_CMD_NO_OP		0x00000000
 #define VCN_ENC_CMD_END 		0x00000001
 #define VCN_ENC_CMD_IB			0x00000002
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0 -3
index 6fb4fcdbba4f..0e8eb4f671c0 100644
@@ -58,9 +58,6 @@
 #define VCN_INSTANCES_SIENNA_CICHLID				2
 #define DEC_SW_RING_ENABLED					FALSE
 
-#define RDECODE_MSG_CREATE					0x00000000
-#define RDECODE_MESSAGE_CREATE					0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_3_0[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_STATUS),
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0 -3
index 5dec92691f73..00abac9c7fd7 100644
@@ -50,9 +50,6 @@
 
 #define VCN_HARVEST_MMSCH								0
 
-#define RDECODE_MSG_CREATE							0x00000000
-#define RDECODE_MESSAGE_CREATE							0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_4_0[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_STATUS),
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0 -3
index 1f6a22983c0d..cbbc02d68695 100644
@@ -50,9 +50,6 @@
 
 #define VCN_HARVEST_MMSCH							0
 
-#define RDECODE_MSG_CREATE							0x00000000
-#define RDECODE_MESSAGE_CREATE						0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_4_0_5[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_STATUS),
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 2/3 drm/amdgpu/vcn4.0.5: Remove unused define

As part of the previous cleanup, this was noticed to never be used.

---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 --
 1 file changed, 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0 -2
index cbbc02d68695..a204a0f5c44d 100644
@@ -48,8 +48,6 @@
 #define VCN1_VID_SOC_ADDRESS_3_0					(0x48300 + 0x38000)
 #define VCN1_AON_SOC_ADDRESS_3_0					(0x48000 + 0x38000)
 
-#define VCN_HARVEST_MMSCH							0
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_4_0_5[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_STATUS),
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 3/3 drm/amdgpu/vcn: Factor out vcn_v{3,4}_0_dec_msg

In reply to Benjamin Cheng

Both vcn_v3_0 and vcn_v4_0 use the same interface, so unify the code.

---
v2: Moved RDECODE_* defines to header in patch #1.

 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 100 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |   5 ++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 102 +-----------------------
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 101 +----------------------
 4 files changed, 109 insertions(+), 199 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +100 -0
index 03d95dca93d7..76d6b0071bd5 100644
@@ -1641,3 +1641,103 @@ void amdgpu_vcn_print_ip_state(struct amdgpu_ip_block *ip_block, struct drm_prin
 		}
 	}
 }
+
+int amdgpu_vcn_dec_msg_limit_sched(struct amdgpu_cs_parser *p,
+				   struct amdgpu_job *job, uint64_t addr,
+				   int (*limit_sched)(struct amdgpu_cs_parser *,
+						      struct amdgpu_job *))
+{
+	struct ttm_operation_ctx ctx = { false, false };
+	struct amdgpu_device *adev = p->adev;
+	struct amdgpu_bo_va_mapping *map;
+	uint32_t *msg, num_buffers, len_dw;
+	struct amdgpu_bo *bo;
+	uint64_t start, end;
+	unsigned int i;
+	void *ptr;
+	int r;
+
+	addr &= AMDGPU_GMC_HOLE_MASK;
+	r = amdgpu_cs_find_mapping(p, addr, &bo, &map);
+	if (r) {
+		DRM_ERROR("Can't find BO for addr 0x%08llx\n", addr);
+		return r;
+	}
+
+	start = map->start * AMDGPU_GPU_PAGE_SIZE;
+	end = (map->last + 1) * AMDGPU_GPU_PAGE_SIZE;
+	if (addr & 0x7) {
+		DRM_ERROR("VCN messages must be 8 byte aligned!\n");
+		return -EINVAL;
+	}
+
+	if (end - addr < 16) {
+		DRM_ERROR("VCN messages must be at least 4 DWORDs!\n");
+		return -EINVAL;
+	}
+
+	bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+	amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
+	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
+	if (r) {
+		DRM_ERROR("Failed validating the VCN message BO (%d)!\n", r);
+		return r;
+	}
+
+	r = amdgpu_bo_kmap(bo, &ptr);
+	if (r) {
+		DRM_ERROR("Failed mapping the VCN message (%d)!\n", r);
+		return r;
+	}
+
+	msg = ptr + addr - start;
+
+	if (msg[1] > end - addr) {
+		DRM_ERROR("VCN message header does not fit in BO!\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	if (msg[3] != RDECODE_MSG_CREATE)
+		goto out;
+
+	len_dw = msg[1] / 4;
+	num_buffers = msg[2];
+
+	/* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */
+	if (num_buffers > len_dw || 6 + num_buffers * 4 > len_dw) {
+		DRM_ERROR("VCN message has too many buffers!\n");
+		r = -EINVAL;
+		goto out;
+	}
+
+	for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {
+		uint32_t offset, size, *create;
+
+		if (msg[0] != RDECODE_MESSAGE_CREATE)
+			continue;
+
+		offset = msg[1];
+		size = msg[2];
+
+		if (size < 4 || offset + size > end - addr) {
+			DRM_ERROR("VCN message buffer exceeds BO bounds!\n");
+			r = -EINVAL;
+			goto out;
+		}
+
+		create = ptr + addr + offset - start;
+
+		/* H264, HEVC and VP9 can run on any instance */
+		if (create[0] == 0x7 || create[0] == 0x10 || create[0] == 0x11)
+			continue;
+
+		r = limit_sched(p, job);
+		if (r)
+			goto out;
+	}
+
+out:
+	amdgpu_bo_kunmap(bo);
+	return r;
+}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +5 -0
index fd9657ae6c37..29ddd7bbc835 100644
@@ -573,4 +573,9 @@ void amdgpu_vcn_print_ip_state(struct amdgpu_ip_block *ip_block, struct drm_prin
 void amdgpu_vcn_get_profile(struct amdgpu_device *adev);
 void amdgpu_vcn_put_profile(struct amdgpu_device *adev);
 
+int amdgpu_vcn_dec_msg_limit_sched(struct amdgpu_cs_parser *p, struct amdgpu_job *job,
+				   uint64_t addr,
+				   int (*limit_sched)(struct amdgpu_cs_parser *,
+						      struct amdgpu_job *));
+
 #endif
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +2 -100

114 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +2 -99

113 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#3 lore raw
In reply to Benjamin Cheng
Quoted 15 lines · Benjamin Cheng

These defines can be shared.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 3 +++
 drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c   | 3 ---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c   | 3 ---
 drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 3 ---
 4 files changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +0 -0
index 82624b44e661..fd9657ae6c37 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h line 62

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +3 -0
@@ -57,6 +57,9 @@
 #define VCN_DEC_SW_CMD_REG_WRITE	0x0000000b
 #define VCN_DEC_SW_CMD_REG_WAIT		0x0000000c
 
+#define RDECODE_MSG_CREATE		0x00000000
+#define RDECODE_MESSAGE_CREATE		0x00000001
+

As soon as it is in some header it should probably have an VCN_ prefix.

Regards,
Christian.

Quoted 45 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +0 -0
 #define VCN_ENC_CMD_NO_OP		0x00000000
 #define VCN_ENC_CMD_END 		0x00000001
 #define VCN_ENC_CMD_IB			0x00000002
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0 -3
index 6fb4fcdbba4f..0e8eb4f671c0 100644
@@ -58,9 +58,6 @@
 #define VCN_INSTANCES_SIENNA_CICHLID				2
 #define DEC_SW_RING_ENABLED					FALSE
 
-#define RDECODE_MSG_CREATE					0x00000000
-#define RDECODE_MESSAGE_CREATE					0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_3_0[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, mmUVD_STATUS),
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0 -3
index 5dec92691f73..00abac9c7fd7 100644
@@ -50,9 +50,6 @@
 
 #define VCN_HARVEST_MMSCH								0
 
-#define RDECODE_MSG_CREATE							0x00000000
-#define RDECODE_MESSAGE_CREATE							0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_4_0[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_STATUS),
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0 -3
index 1f6a22983c0d..cbbc02d68695 100644
@@ -50,9 +50,6 @@
 
 #define VCN_HARVEST_MMSCH							0
 
-#define RDECODE_MSG_CREATE							0x00000000
-#define RDECODE_MESSAGE_CREATE						0x00000001
-
 static const struct amdgpu_hwip_reg_entry vcn_reg_list_4_0_5[] = {
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_POWER_STATUS),
 	SOC15_REG_ENTRY_STR(VCN, 0, regUVD_STATUS),