/** * radeon_vce_cs_parse - parse and validate the command stream * * @p: parser context * */ int radeon_vce_cs_parse(struct radeon_cs_parser *p) { uint32_t handle = 0; bool destroy = false; int i, r; while (p->idx < p->chunks[p->chunk_ib_idx].length_dw) { uint32_t len = radeon_get_ib_value(p, p->idx); uint32_t cmd = radeon_get_ib_value(p, p->idx + 1); if ((len < 8) || (len & 3)) { DRM_ERROR("invalid VCE command length (%d)!\n", len); return -EINVAL; } switch (cmd) { case 0x00000001: // session handle = radeon_get_ib_value(p, p->idx + 2); break; case 0x00000002: // task info case 0x01000001: // create case 0x04000001: // config extension case 0x04000002: // pic control case 0x04000005: // rate control case 0x04000007: // motion estimation case 0x04000008: // rdo break; case 0x03000001: // encode r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9); if (r) return r; r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11); if (r) return r; break; case 0x02000001: // destroy destroy = true; break; case 0x05000001: // context buffer case 0x05000004: // video bitstream buffer case 0x05000005: // feedback buffer r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2); if (r) return r; break; default: DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); return -EINVAL; } p->idx += len / 4; } if (destroy) { /* IB contains a destroy msg, free the handle */ for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0); return 0; } /* create or encode, validate the handle */ for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) { if (atomic_read(&p->rdev->vce.handles[i]) == handle) return 0; } /* handle not found try to alloc a new one */ for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) { if (!atomic_cmpxchg(&p->rdev->vce.handles[i], 0, handle)) { p->rdev->vce.filp[i] = p->filp; return 0; } } DRM_ERROR("No more free VCE handles!\n"); return -EINVAL; }
/** * radeon_vce_cs_parse - parse and validate the command stream * * @p: parser context * */ int radeon_vce_cs_parse(struct radeon_cs_parser *p) { int session_idx = -1; bool destroyed = false; uint32_t tmp, handle = 0; uint32_t *size = &tmp; int i, r; while (p->idx < p->chunks[p->chunk_ib_idx].length_dw) { uint32_t len = radeon_get_ib_value(p, p->idx); uint32_t cmd = radeon_get_ib_value(p, p->idx + 1); if ((len < 8) || (len & 3)) { DRM_ERROR("invalid VCE command length (%d)!\n", len); return -EINVAL; } if (destroyed) { DRM_ERROR("No other command allowed after destroy!\n"); return -EINVAL; } switch (cmd) { case 0x00000001: // session handle = radeon_get_ib_value(p, p->idx + 2); session_idx = radeon_vce_validate_handle(p, handle); if (session_idx < 0) return session_idx; size = &p->rdev->vce.img_size[session_idx]; break; case 0x00000002: // task info break; case 0x01000001: // create *size = radeon_get_ib_value(p, p->idx + 8) * radeon_get_ib_value(p, p->idx + 10) * 8 * 3 / 2; break; case 0x04000001: // config extension case 0x04000002: // pic control case 0x04000005: // rate control case 0x04000007: // motion estimation case 0x04000008: // rdo break; case 0x03000001: // encode r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9, *size); if (r) return r; r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11, *size / 3); if (r) return r; break; case 0x02000001: // destroy destroyed = true; break; case 0x05000001: // context buffer r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, *size * 2); if (r) return r; break; case 0x05000004: // video bitstream buffer tmp = radeon_get_ib_value(p, p->idx + 4); r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, tmp); if (r) return r; break; case 0x05000005: // feedback buffer r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2, 4096); if (r) return r; break; default: DRM_ERROR("invalid VCE command (0x%x)!\n", cmd); return -EINVAL; } if (session_idx == -1) { DRM_ERROR("no session command at start of IB\n"); return -EINVAL; } p->idx += len / 4; } if (destroyed) { /* IB contains a destroy msg, free the handle */ for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0); } return 0; }