diff options
author | Alex Deucher <alexander.deucher@amd.com> | 2021-01-07 16:48:01 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2021-02-26 17:23:49 -0500 |
commit | f35e9bdb06fbfa8a6fe9d25390fbee2ee5e7a329 (patch) | |
tree | 5bbef73cba8d9fbe8962ff07149f45fe810ed806 /drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | |
parent | 3b246e8b6a97b7786f49433effea2aff39e58166 (diff) | |
download | lwn-f35e9bdb06fbfa8a6fe9d25390fbee2ee5e7a329.tar.gz lwn-f35e9bdb06fbfa8a6fe9d25390fbee2ee5e7a329.zip |
drm/amdgpu: add INFO ioctl support for querying video caps (v4)
We currently hardcode these in mesa, but querying them from
the kernel makes more sense since there may be board specific
limitations that the kernel driver is better suited to
determining.
Userpace patches that use this interface:
https://gitlab.freedesktop.org/leoliu/drm/-/commits/info_video_caps
https://gitlab.freedesktop.org/leoliu/mesa/-/commits/info_video_caps
v2: reorder the codecs to better align with mesa
v3: add max_pixels_per_frame to handle the portrait case, squash in
memory leak fix
v4: drop extra break
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Leo Liu <leo.liu@amd.com> (v2)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index cf81ade31703..9f35e8a6c421 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -982,6 +982,63 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) min_t(u64, size, sizeof(ras_mask))) ? -EFAULT : 0; } + case AMDGPU_INFO_VIDEO_CAPS: { + const struct amdgpu_video_codecs *codecs; + struct drm_amdgpu_info_video_caps *caps; + int r; + + switch (info->video_cap.type) { + case AMDGPU_INFO_VIDEO_CAPS_DECODE: + r = amdgpu_asic_query_video_codecs(adev, false, &codecs); + if (r) + return -EINVAL; + break; + case AMDGPU_INFO_VIDEO_CAPS_ENCODE: + r = amdgpu_asic_query_video_codecs(adev, true, &codecs); + if (r) + return -EINVAL; + break; + default: + DRM_DEBUG_KMS("Invalid request %d\n", + info->video_cap.type); + return -EINVAL; + } + + caps = kzalloc(sizeof(*caps), GFP_KERNEL); + if (!caps) + return -ENOMEM; + + for (i = 0; i < codecs->codec_count; i++) { + int idx = codecs->codec_array[i].codec_type; + + switch (idx) { + case AMDGPU_VIDEO_CODEC_TYPE_MPEG2: + case AMDGPU_VIDEO_CODEC_TYPE_MPEG4: + case AMDGPU_VIDEO_CODEC_TYPE_MPEG4_AVC: + case AMDGPU_VIDEO_CODEC_TYPE_VC1: + case AMDGPU_VIDEO_CODEC_TYPE_HEVC: + case AMDGPU_VIDEO_CODEC_TYPE_JPEG: + case AMDGPU_VIDEO_CODEC_TYPE_VP9: + case AMDGPU_VIDEO_CODEC_TYPE_AV1: + caps->codec_info[idx].valid = 1; + caps->codec_info[idx].max_width = + codecs->codec_array[i].max_width; + caps->codec_info[idx].max_height = + codecs->codec_array[i].max_height; + caps->codec_info[idx].max_pixels_per_frame = + codecs->codec_array[i].max_pixels_per_frame; + caps->codec_info[idx].max_level = + codecs->codec_array[i].max_level; + break; + default: + break; + } + } + r = copy_to_user(out, caps, + min((size_t)size, sizeof(*caps))) ? -EFAULT : 0; + kfree(caps); + return r; + } default: DRM_DEBUG_KMS("Invalid request %d\n", info->query); return -EINVAL; |