From patchwork Thu Jun 4 13:53:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11588045 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8821F739 for ; Thu, 4 Jun 2020 13:53:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D83320829 for ; Thu, 4 Jun 2020 13:53:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="bTpVL1yf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728950AbgFDNxw (ORCPT ); Thu, 4 Jun 2020 09:53:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728854AbgFDNxc (ORCPT ); Thu, 4 Jun 2020 09:53:32 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCD43C08C5C1 for ; Thu, 4 Jun 2020 06:53:30 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id j10so6188087wrw.8 for ; Thu, 04 Jun 2020 06:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fs26md6QbBGAquJwpk095GGSGBX/m/yeaPP+lwPf4x8=; b=bTpVL1yfwhHL564oV9oXTuVi5bwYohXzTpcKvqoytnCDbbMUIAeZsrdq92E0qwRRSg UfSDj3lzKt+diIWgtJqYc2UKsOBY/ArWO+KMdr64+3lR8Puu98hTn/h1lbs8pZD3z0a5 6ShQ9QS2p4Zr3km9dLUyszhnICzksvQjbCrHKAfOpH8DBiP7RsMzrXzBw1bJT3KiwTm3 9xZUp0uS871oMpIXbSrQ/0KnqXJ/ZEg8yRFTESmOv1jd2O4crFzKduVGLDXRc8vcZgCD uUtou4MeMzMCIRxtSYLva3dOgaRLMh0YBcvkdPYbchEEWfISZiUqH0diRmCqtZ42LoKm G+jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fs26md6QbBGAquJwpk095GGSGBX/m/yeaPP+lwPf4x8=; b=QcZf1TFqSJsPZYTxWZgeGsWy4lFzHvu9jBHZQND6Kr759KGRm7fbXqnSDOApDH8Ary osQkwFBHpcXBWbZAfYUX1bIuBbGDv54gs6wKueBJUBGJTOXP1DAjwPdwha0cWSaOzREU j6tYYK4/xkNEEUYCnY/pD04dKK3+Bk5FgE+Vqd25CpD39otE8Ne8LMpEjihxeLJLH1XG KKoZWbOXS8UwPgsqnOGb33mXoycotzJxPPbQ7CI6GGYlyIFq3mn5+Uhk71vVa//O1QK8 Os4XzCVdpV/FJAXRJhdWpmPNXfGi+FPA3FYPQgKy+cHkOTJjkaWt2SKGM0eEsWKK1uU1 mPIA== X-Gm-Message-State: AOAM530eXRv/AvlQQpKrN4VikVb69+tOdg1AhGTw8K5AqPohxwjKZbjq 7bvTiErKDM+K3NF2XQRANkp1TxKsk15KAg== X-Google-Smtp-Source: ABdhPJwqpOH22rRrTWj54Pu3JjP2wensOE1kRwQ6BI5hptsY6t27TXlnHJBKfdM8GJs/L3uqecz/Pw== X-Received: by 2002:a5d:4dc9:: with SMTP id f9mr4441675wru.407.1591278809353; Thu, 04 Jun 2020 06:53:29 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:22:5867:d2c6:75f4]) by smtp.gmail.com with ESMTPSA id i74sm8185599wri.49.2020.06.04.06.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:53:28 -0700 (PDT) From: Neil Armstrong To: hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 1/5] media: videodev2: add Compressed Framebuffer pixel formats Date: Thu, 4 Jun 2020 15:53:13 +0200 Message-Id: <20200604135317.9235-2-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200604135317.9235-1-narmstrong@baylibre.com> References: <20200604135317.9235-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Maxime Jourdan Add two generic Compressed Framebuffer pixel formats to be used with a modifier when imported back in another subsystem like DRM/KMS. These pixel formats represents generic 8bits and 10bits compressed buffers with a vendor specific layout. These are aligned with the DRM_FORMAT_YUV420_8BIT and DRM_FORMAT_YUV420_10BIT used to describe the underlying compressed buffers used for ARM Framebuffer Compression. In the Amlogic case, the compression is different but the underlying buffer components is the same. Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- drivers/media/v4l2-core/v4l2-ioctl.c | 2 ++ include/uapi/linux/videodev2.h | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 2322f08a98be..8f14adfd5bc5 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1447,6 +1447,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_PIX_FMT_S5C_UYVY_JPG: descr = "S5C73MX interleaved UYVY/JPEG"; break; case V4L2_PIX_FMT_MT21C: descr = "Mediatek Compressed Format"; break; case V4L2_PIX_FMT_SUNXI_TILED_NV12: descr = "Sunxi Tiled NV12 Format"; break; + case V4L2_PIX_FMT_YUV420_8BIT: descr = "Compressed YUV 4:2:0 8-bit Format"; break; + case V4L2_PIX_FMT_YUV420_10BIT: descr = "Compressed YUV 4:2:0 10-bit Format"; break; default: if (fmt->description[0]) return; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index c3a1cf1c507f..90b9949acb8a 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -705,6 +705,15 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_FWHT v4l2_fourcc('F', 'W', 'H', 'T') /* Fast Walsh Hadamard Transform (vicodec) */ #define V4L2_PIX_FMT_FWHT_STATELESS v4l2_fourcc('S', 'F', 'W', 'H') /* Stateless FWHT (vicodec) */ +/* + * Compressed Luminance+Chrominance meta-formats + * In these formats, the component ordering is specified (Y, followed by U + * then V), but the exact Linear layout is undefined. + * These formats can only be used with a non-Linear modifier. + */ +#define V4L2_PIX_FMT_YUV420_8BIT v4l2_fourcc('Y', 'U', '0', '8') /* 1-plane YUV 4:2:0 8-bit */ +#define V4L2_PIX_FMT_YUV420_10BIT v4l2_fourcc('Y', 'U', '1', '0') /* 1-plane YUV 4:2:0 10-bit */ + /* Vendor-specific formats */ #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */ From patchwork Thu Jun 4 13:53:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11588035 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DD54739 for ; Thu, 4 Jun 2020 13:53:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66FC9207D8 for ; Thu, 4 Jun 2020 13:53:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="XyuF7akh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbgFDNxd (ORCPT ); Thu, 4 Jun 2020 09:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728896AbgFDNxc (ORCPT ); Thu, 4 Jun 2020 09:53:32 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87334C08C5C1 for ; Thu, 4 Jun 2020 06:53:32 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id r9so5325149wmh.2 for ; Thu, 04 Jun 2020 06:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WTN9hKVRvS3SB3HTMfGE7UGBs+9KNxbyg3Yusfgv+rE=; b=XyuF7akhxZYqkjEdda9jL2OlbN0kGPXJPHJ0ss5AJZFIm7yaqkJ70UFt397DKdBTTy LkysXfSu9XsXPGq1ID7H1auU1t3o5k0fJr+9ipc5zC1uDNIVS9a6lO7HiJSMM5ke/Vyh U4IPCGpq3r09LTUCHE/F46tvaQJWRMqsdWCzlzPW6KYO/505VDb/T7Q42z23eGQE7z6Z 72ekSvLROK+9p6ZCe38kEP+yGRvhGpOsD8lrv4WBaqHrAnYrxmr2Tn9T2oRvMg/H8LnU igUmQBOWOMLCuTbzTJ8RUUrZiJqr3vm3VVIfo/NiZePI42xwckDiJmy4cK4CdbrEplxc 4BPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WTN9hKVRvS3SB3HTMfGE7UGBs+9KNxbyg3Yusfgv+rE=; b=UDEopkjMc87mgCvS3zegZKB6Kbe1OchkdTqTd4EB95NTZ5LJVQwa6Ztf4m4IyMvT1P cuMusIwv7VlDRWZqlpW1wecfWCBeR4wQLhkVmLJ1ks5KQHytmr0p6V+L9H8VGgmxjmpr dxl1f/WEjf+7wQYfN6oIbePMcpEmIuNGUAUsS7ZCDch3wi5Ti45vbWT44BJRpGQG1zEm 5XIvMche25mXc9T9hWJa3Mflx/BF/gn6eiKOERw1mGlN/Dl2HFyogMt1CUdtJ70QvsEp PsqM4CC6CzNfZJkp9ECOMUprHdPSh7gi4QgCR1SvrwJMQ7BkimvPy6sWdm8h5589wyAz VHRQ== X-Gm-Message-State: AOAM531Y6I+TdeFwgI4V82dezsI9UplxFaDujG6hmhO1gudY206zQZMH DtHXMedb/nH+l+VSfDOU9n6wJw== X-Google-Smtp-Source: ABdhPJwd9WGnr6Q/FV1RFyKfSIpbxLo2wXPQ8ohJw62dgXc/LSq0+CrfVHbTBTa4n1Fkmh1H7CwwIg== X-Received: by 2002:a1c:9d53:: with SMTP id g80mr4410607wme.13.1591278811002; Thu, 04 Jun 2020 06:53:31 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:22:5867:d2c6:75f4]) by smtp.gmail.com with ESMTPSA id i74sm8185599wri.49.2020.06.04.06.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:53:30 -0700 (PDT) From: Neil Armstrong To: hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 2/5] media: meson: vdec: handle bitdepth on source change Date: Thu, 4 Jun 2020 15:53:14 +0200 Message-Id: <20200604135317.9235-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200604135317.9235-1-narmstrong@baylibre.com> References: <20200604135317.9235-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Maxime Jourdan In order to handle Compressed Framebuffer support, we need to handle the switch between 8bit and 10bit frame output. This handles the bitdepth in the codec amvdec_src_change() call to handle a source change/decode resume when the stream bitdepth changes. Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- drivers/staging/media/meson/vdec/codec_h264.c | 3 ++- drivers/staging/media/meson/vdec/codec_vp9.c | 3 ++- drivers/staging/media/meson/vdec/vdec.h | 1 + drivers/staging/media/meson/vdec/vdec_helpers.c | 10 ++++++---- drivers/staging/media/meson/vdec/vdec_helpers.h | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/staging/media/meson/vdec/codec_h264.c b/drivers/staging/media/meson/vdec/codec_h264.c index c61128fc4bb9..d53c9a464bde 100644 --- a/drivers/staging/media/meson/vdec/codec_h264.c +++ b/drivers/staging/media/meson/vdec/codec_h264.c @@ -353,7 +353,8 @@ static void codec_h264_src_change(struct amvdec_session *sess) frame_width, frame_height, crop_right, crop_bottom); codec_h264_set_par(sess); - amvdec_src_change(sess, frame_width, frame_height, h264->max_refs + 5); + amvdec_src_change(sess, frame_width, frame_height, + h264->max_refs + 5, 8); } /* diff --git a/drivers/staging/media/meson/vdec/codec_vp9.c b/drivers/staging/media/meson/vdec/codec_vp9.c index 897f5d7a6aad..4c6a644ab1a7 100644 --- a/drivers/staging/media/meson/vdec/codec_vp9.c +++ b/drivers/staging/media/meson/vdec/codec_vp9.c @@ -2132,7 +2132,8 @@ static irqreturn_t codec_vp9_threaded_isr(struct amvdec_session *sess) codec_vp9_fetch_rpm(sess); if (codec_vp9_process_rpm(vp9)) { - amvdec_src_change(sess, vp9->width, vp9->height, 16); + amvdec_src_change(sess, vp9->width, vp9->height, 16, + vp9->is_10bit ? 10 : 8); /* No frame is actually processed */ vp9->cur_frame = NULL; diff --git a/drivers/staging/media/meson/vdec/vdec.h b/drivers/staging/media/meson/vdec/vdec.h index f95445ac0658..e3e4af73447a 100644 --- a/drivers/staging/media/meson/vdec/vdec.h +++ b/drivers/staging/media/meson/vdec/vdec.h @@ -234,6 +234,7 @@ struct amvdec_session { u32 width; u32 height; u32 colorspace; + u32 bitdepth; u8 ycbcr_enc; u8 quantization; u8 xfer_func; diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index 7f07a9175815..eed7a929c5d0 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -436,7 +436,7 @@ void amvdec_set_par_from_dar(struct amvdec_session *sess, EXPORT_SYMBOL_GPL(amvdec_set_par_from_dar); void amvdec_src_change(struct amvdec_session *sess, u32 width, - u32 height, u32 dpb_size) + u32 height, u32 dpb_size, u32 bitdepth) { static const struct v4l2_event ev = { .type = V4L2_EVENT_SOURCE_CHANGE, @@ -451,7 +451,8 @@ void amvdec_src_change(struct amvdec_session *sess, u32 width, if (sess->streamon_cap && sess->width == width && sess->height == height && - dpb_size <= sess->num_dst_bufs) { + dpb_size <= sess->num_dst_bufs && + sess->bitdepth == bitdepth) { sess->fmt_out->codec_ops->resume(sess); return; } @@ -460,9 +461,10 @@ void amvdec_src_change(struct amvdec_session *sess, u32 width, sess->width = width; sess->height = height; sess->status = STATUS_NEEDS_RESUME; + sess->bitdepth = bitdepth; - dev_dbg(sess->core->dev, "Res. changed (%ux%u), DPB size %u\n", - width, height, dpb_size); + dev_dbg(sess->core->dev, "Res. changed (%ux%u), DPB %u, bitdepth %u\n", + width, height, dpb_size, bitdepth); v4l2_event_queue_fh(&sess->fh, &ev); } EXPORT_SYMBOL_GPL(amvdec_src_change); diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h index cfaed52ab526..f059cf195cca 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.h +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h @@ -76,9 +76,10 @@ void amvdec_set_par_from_dar(struct amvdec_session *sess, * @width: picture width detected by the hardware * @height: picture height detected by the hardware * @dpb_size: Decoded Picture Buffer size (= amount of buffers for decoding) + * @bitdepth: Bit depth (usually 10 or 8) of the coded content */ void amvdec_src_change(struct amvdec_session *sess, u32 width, - u32 height, u32 dpb_size); + u32 height, u32 dpb_size, u32 bitdepth); /** * amvdec_abort() - Abort the current decoding session From patchwork Thu Jun 4 13:53:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11588039 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9186390 for ; Thu, 4 Jun 2020 13:53:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7356B207D8 for ; Thu, 4 Jun 2020 13:53:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="FjgCGe7h" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728919AbgFDNxg (ORCPT ); Thu, 4 Jun 2020 09:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728808AbgFDNxf (ORCPT ); Thu, 4 Jun 2020 09:53:35 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA21C08C5C0 for ; Thu, 4 Jun 2020 06:53:34 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id f185so5726843wmf.3 for ; Thu, 04 Jun 2020 06:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+BSw9RksbOmCX0ZiZaPq1aouN2XnZSd2sB8Ac6JkINs=; b=FjgCGe7hkzS3/mzxrmhspP75KvYPTn74cr+q/XOubxsiXcIa51+V1mFZhPk60V5h4b SELKDRXZ6u5XyDDYJ9dWRMhYXJEXj7xsdpKT747vV9Aw7xNNQUjH5qUaNBBe4UGn3Ypa 58XafZtYVrEogQZm0CmV//h+MEKYVJJKLGO86pT48Js9WX10i4i/ekraB55kyJ2lnL4L RrzoTFjQO3zK1PyyKWJhM4gV7ajnUyTs6KI34PmKFX+O1BAZiTIek3BZt93f9SGU+vkK 2DBuun9mkK+kHiCdg+5MI/vhdQmH9vyNHA6+Lv6t4uJREwuwQSwZc238lw6sLXpYLEuB Lpzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+BSw9RksbOmCX0ZiZaPq1aouN2XnZSd2sB8Ac6JkINs=; b=M7zRXeRMufiy18FLAkagFyYy3JP7dtlVqj7E7wyHUFz5R+JRvz+Ff3MEEBJHMs6Ud3 IoYF/asd3Smx7ki/2MSdkWei5y3krR+8jwV3LNfbXC/Kwr5sQQRsxe61bBcNOhxzKsqg bF9FNQF9FT2dvkky66R83ghLizdMGnem37OCOYuKqSSSlOP4OIr434l4nevjjmhRtydz 5xAEaTSTliJmOxPNgzu0LEXp8+6oiDyzHNxkJS/oTvKDu3GHRalxLIS/Losi+T90nGxi ZCWp8jU3dp4aNxUe80EbNG6iDmS9ArerB1EXEpx04uUPXFbMYF6ujBK/m4VXXpsqX3Pn OhIA== X-Gm-Message-State: AOAM533gma6j9lQZDQ2GORitlu9bYvZKTBpYu6gp3SODylzzGiBp3giE VZP8GOYEd/jP/OGd5qIpzefc5g== X-Google-Smtp-Source: ABdhPJxL1i8fyC6k2QOVONJR/UbQHuoBJHrZumYxlKfi1W617c7BWZnFVAOQBYJZ+p6dKi+wb5hZ4Q== X-Received: by 2002:a7b:c358:: with SMTP id l24mr4402485wmj.13.1591278812670; Thu, 04 Jun 2020 06:53:32 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:22:5867:d2c6:75f4]) by smtp.gmail.com with ESMTPSA id i74sm8185599wri.49.2020.06.04.06.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:53:31 -0700 (PDT) From: Neil Armstrong To: hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 3/5] media: meson: vdec: update compressed buffer helpers Date: Thu, 4 Jun 2020 15:53:15 +0200 Message-Id: <20200604135317.9235-4-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200604135317.9235-1-narmstrong@baylibre.com> References: <20200604135317.9235-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Maxime Jourdan The actual compressed buffer helpers were very basic and only used to enabled downsampling when decoding a 10bit stream. Update and rename these helpers to handle the complete compressed buffer output buffer size and alignment for 8bit and 10bit streams. Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- .../media/meson/vdec/codec_hevc_common.c | 28 ++++++++++++--- drivers/staging/media/meson/vdec/codec_vp9.c | 7 ++-- .../staging/media/meson/vdec/vdec_helpers.c | 35 +++++++++++++------ .../staging/media/meson/vdec/vdec_helpers.h | 8 +++-- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/drivers/staging/media/meson/vdec/codec_hevc_common.c b/drivers/staging/media/meson/vdec/codec_hevc_common.c index 0315cc0911cd..c9bf67aa2668 100644 --- a/drivers/staging/media/meson/vdec/codec_hevc_common.c +++ b/drivers/staging/media/meson/vdec/codec_hevc_common.c @@ -30,8 +30,11 @@ const u16 vdec_hevc_parser_cmd[] = { void codec_hevc_setup_decode_head(struct amvdec_session *sess, int is_10bit) { struct amvdec_core *core = sess->core; - u32 body_size = amvdec_am21c_body_size(sess->width, sess->height); - u32 head_size = amvdec_am21c_head_size(sess->width, sess->height); + u32 use_mmu = codec_hevc_use_mmu(core->platform->revision, + sess->pixfmt_cap, is_10bit); + u32 body_size = amvdec_amfbc_body_size(sess->width, sess->height, + is_10bit, use_mmu); + u32 head_size = amvdec_amfbc_head_size(sess->width, sess->height); if (!codec_hevc_use_fbc(sess->pixfmt_cap, is_10bit)) { /* Enable 2-plane reference read mode */ @@ -154,7 +157,12 @@ void codec_hevc_free_fbc_buffers(struct amvdec_session *sess, struct codec_hevc_common *comm) { struct device *dev = sess->core->dev; - u32 am21_size = amvdec_am21c_size(sess->width, sess->height); + u32 use_mmu = codec_hevc_use_mmu(sess->core->platform->revision, + sess->pixfmt_cap, + sess->bitdepth == 10 ? 1 : 0); + u32 am21_size = amvdec_amfbc_size(sess->width, sess->height, + sess->bitdepth == 10 ? 1 : 0, + use_mmu); int i; for (i = 0; i < MAX_REF_PIC_NUM; ++i) { @@ -173,7 +181,12 @@ static int codec_hevc_alloc_fbc_buffers(struct amvdec_session *sess, { struct device *dev = sess->core->dev; struct v4l2_m2m_buffer *buf; - u32 am21_size = amvdec_am21c_size(sess->width, sess->height); + u32 use_mmu = codec_hevc_use_mmu(sess->core->platform->revision, + sess->pixfmt_cap, + sess->bitdepth == 10 ? 1 : 0); + u32 am21_size = amvdec_amfbc_size(sess->width, sess->height, + sess->bitdepth == 10 ? 1 : 0, + use_mmu); v4l2_m2m_for_each_dst_buf(sess->m2m_ctx, buf) { u32 idx = buf->vb.vb2_buf.index; @@ -280,7 +293,12 @@ void codec_hevc_fill_mmu_map(struct amvdec_session *sess, struct codec_hevc_common *comm, struct vb2_buffer *vb) { - u32 size = amvdec_am21c_size(sess->width, sess->height); + u32 use_mmu = codec_hevc_use_mmu(sess->core->platform->revision, + sess->pixfmt_cap, + sess->bitdepth == 10 ? 1 : 0); + u32 size = amvdec_amfbc_size(sess->width, sess->height, + sess->bitdepth == 10 ? 1 : 0, + use_mmu); u32 nb_pages = size / PAGE_SIZE; u32 *mmu_map = comm->mmu_map_vaddr; u32 first_page; diff --git a/drivers/staging/media/meson/vdec/codec_vp9.c b/drivers/staging/media/meson/vdec/codec_vp9.c index 4c6a644ab1a7..a810c50f3a39 100644 --- a/drivers/staging/media/meson/vdec/codec_vp9.c +++ b/drivers/staging/media/meson/vdec/codec_vp9.c @@ -1147,6 +1147,8 @@ static void codec_vp9_set_mc(struct amvdec_session *sess, struct codec_vp9 *vp9) { struct amvdec_core *core = sess->core; + u32 use_mmu = codec_hevc_use_mmu(core->platform->revision, + sess->pixfmt_cap, vp9->is_10bit); u32 scale = 0; u32 sz; int i; @@ -1166,8 +1168,9 @@ static void codec_vp9_set_mc(struct amvdec_session *sess, vp9->frame_refs[i]->height != vp9->height) scale = 1; - sz = amvdec_am21c_body_size(vp9->frame_refs[i]->width, - vp9->frame_refs[i]->height); + sz = amvdec_amfbc_body_size(vp9->frame_refs[i]->width, + vp9->frame_refs[i]->height, + vp9->is_10bit, use_mmu); amvdec_write_dos(core, VP9D_MPP_REFINFO_DATA, vp9->frame_refs[i]->width); diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index eed7a929c5d0..320cac1ed03e 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -50,32 +50,47 @@ void amvdec_write_parser(struct amvdec_core *core, u32 reg, u32 val) } EXPORT_SYMBOL_GPL(amvdec_write_parser); -/* 4 KiB per 64x32 block */ -u32 amvdec_am21c_body_size(u32 width, u32 height) +/* AMFBC body is made out of 64x32 blocks with varying block size */ +u32 amvdec_amfbc_body_size(u32 width, u32 height, u32 is_10bit, u32 use_mmu) { u32 width_64 = ALIGN(width, 64) / 64; u32 height_32 = ALIGN(height, 32) / 32; + u32 blk_size = 4096; - return SZ_4K * width_64 * height_32; + if (!is_10bit) { + if (use_mmu) + blk_size = 3200; + else + blk_size = 3072; + } + + return blk_size * width_64 * height_32; } -EXPORT_SYMBOL_GPL(amvdec_am21c_body_size); +EXPORT_SYMBOL_GPL(amvdec_amfbc_body_size); /* 32 bytes per 128x64 block */ -u32 amvdec_am21c_head_size(u32 width, u32 height) +u32 amvdec_amfbc_head_size(u32 width, u32 height) { u32 width_128 = ALIGN(width, 128) / 128; u32 height_64 = ALIGN(height, 64) / 64; return 32 * width_128 * height_64; } -EXPORT_SYMBOL_GPL(amvdec_am21c_head_size); +EXPORT_SYMBOL_GPL(amvdec_amfbc_head_size); + +u32 amvdec_amfbc_size(u32 width, u32 height, u32 is_10bit, u32 use_mmu) +{ + return ALIGN(amvdec_amfbc_body_size(width, height, is_10bit, use_mmu) + + amvdec_amfbc_head_size(width, height), SZ_64K); +} +EXPORT_SYMBOL_GPL(amvdec_amfbc_size); -u32 amvdec_am21c_size(u32 width, u32 height) +u32 amvdec_is_dst_fbc(struct amvdec_session *sess) { - return ALIGN(amvdec_am21c_body_size(width, height) + - amvdec_am21c_head_size(width, height), SZ_64K); + return sess->pixfmt_cap == V4L2_PIX_FMT_YUV420_8BIT || + sess->pixfmt_cap == V4L2_PIX_FMT_YUV420_10BIT; } -EXPORT_SYMBOL_GPL(amvdec_am21c_size); +EXPORT_SYMBOL_GPL(amvdec_is_dst_fbc); static int canvas_alloc(struct amvdec_session *sess, u8 *canvas_id) { diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.h b/drivers/staging/media/meson/vdec/vdec_helpers.h index f059cf195cca..c1666125fe4c 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.h +++ b/drivers/staging/media/meson/vdec/vdec_helpers.h @@ -27,9 +27,11 @@ void amvdec_clear_dos_bits(struct amvdec_core *core, u32 reg, u32 val); u32 amvdec_read_parser(struct amvdec_core *core, u32 reg); void amvdec_write_parser(struct amvdec_core *core, u32 reg, u32 val); -u32 amvdec_am21c_body_size(u32 width, u32 height); -u32 amvdec_am21c_head_size(u32 width, u32 height); -u32 amvdec_am21c_size(u32 width, u32 height); +/* Helpers for the Amlogic compressed framebuffer format */ +u32 amvdec_amfbc_body_size(u32 width, u32 height, u32 is_10bit, u32 use_mmu); +u32 amvdec_amfbc_head_size(u32 width, u32 height); +u32 amvdec_amfbc_size(u32 width, u32 height, u32 is_10bit, u32 use_mmu); +u32 amvdec_is_dst_fbc(struct amvdec_session *sess); /** * amvdec_dst_buf_done_idx() - Signal that a buffer is done decoding From patchwork Thu Jun 4 13:53:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11588043 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E548D14F6 for ; Thu, 4 Jun 2020 13:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE0E720823 for ; Thu, 4 Jun 2020 13:53:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="SQ09LMb+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728937AbgFDNxn (ORCPT ); Thu, 4 Jun 2020 09:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728914AbgFDNxg (ORCPT ); Thu, 4 Jun 2020 09:53:36 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B09BFC08C5C3 for ; Thu, 4 Jun 2020 06:53:35 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id r15so5720080wmh.5 for ; Thu, 04 Jun 2020 06:53:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qIT7c2oqfX1dSt07GW6kZ3aWJcY6gqtFPD+/6G9C5xg=; b=SQ09LMb+H0DI40E9jW+JuSyMI8/9Kx4mI5GDMSzBJtzMiZTPtZy0Hrc4vGk7IeUBnp 4dWbQ653AY5f7X8uKkjS2oI1u9xzQKJ3pqaArLeWGXKXCKI3ZqXS0nGafiTFRLByrxPA 5y8q3QkkiMB7fwyc/ex9kn3mmQvX87Xqe3RMYNavHVsQeJVdLU6WA5Tk61sEm2yeBqmm EDf7pGfmvKyFmMNq2vupTmUpXo02GnddLU1gi2DRkQ/6czsa1PjPeZbX2a3OcR8aSUlf TUQgD4fngYeiQHhvxO+1PmNYZiC2aXEc2/UoKhVyttCSiMY4npPPdYDk9MkggDa+UX1+ 8t2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qIT7c2oqfX1dSt07GW6kZ3aWJcY6gqtFPD+/6G9C5xg=; b=FcAdwiMCjaMe5vBQxU63bUpNoDZwV4YFH5q4AJveV1gVR9IkS8wIhsWZTiuXYlN3XN xZ9b/5/tUB4l4aCAF6Z/AcOSh2dS0RdCsM8t2QDiMBboUjNAOr64fHY57jNZDTz9HOHE wK6QAA7ypenag5cL2CPI4RDP9MO6ODXWadJUlMedYP5ozS1RWX54N52MzhOMi8Wvf9aH 7jWwgj0dR2J4FOypfaxU20GgdEK9EuYqJJrLq2oIt5tKl8mO6NGMGc1uPKEZRj9JMLRZ Cen5luI1reWCPw3oMUHxLOFFgz9shB8lnnQkooV0DfKdYcozKTgMLXvoiGe3OsT90v4/ NPng== X-Gm-Message-State: AOAM531/JkviRiglbBafFPbpL7ye/49bR/w97VmJ+IXKq3kk33mHVOMU CKS5ri1regAOEWo8NAyqk1TlzQ== X-Google-Smtp-Source: ABdhPJyASWiMzktejXB41WYV4E54kbk5Ya8KhvN6w7LAwaQwuz7yYg0AKdW7mufmckku0K+tjmsWPg== X-Received: by 2002:a1c:6884:: with SMTP id d126mr4116671wmc.121.1591278814224; Thu, 04 Jun 2020 06:53:34 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:22:5867:d2c6:75f4]) by smtp.gmail.com with ESMTPSA id i74sm8185599wri.49.2020.06.04.06.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:53:33 -0700 (PDT) From: Neil Armstrong To: hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 4/5] media: meson: vdec: add support for compressed output for VP9 decoder Date: Thu, 4 Jun 2020 15:53:16 +0200 Message-Id: <20200604135317.9235-5-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200604135317.9235-1-narmstrong@baylibre.com> References: <20200604135317.9235-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Maxime Jourdan Add the necessary changes to decode VP9 8bit and 10bit streams into compressed buffers to be imported back into DRM/KMS using a modifier. On GXL/GXM platforms, the VP9 decoder will output a basic Framebuffer Compressed layout, with a memory saving option when decoding 8bit to better align the compressed macroblocks. This layout includes the buffer content and an header desscribing the compressed buffer. On G12A and later, the VP9 decoder will output "Scatter" layout, meaning the header buffer will contain references to the internal memory decoder workspace and frame memory to construct a compressed framebuffer. The compressed layout has been described in the DRM Modifier patchset at [1]. [1] https://patchwork.freedesktop.org/series/73722/#rev7 Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- .../media/meson/vdec/codec_hevc_common.c | 112 ++++++------------ .../media/meson/vdec/codec_hevc_common.h | 13 +- drivers/staging/media/meson/vdec/codec_vp9.c | 19 +-- 3 files changed, 47 insertions(+), 97 deletions(-) diff --git a/drivers/staging/media/meson/vdec/codec_hevc_common.c b/drivers/staging/media/meson/vdec/codec_hevc_common.c index c9bf67aa2668..73dae40b3319 100644 --- a/drivers/staging/media/meson/vdec/codec_hevc_common.c +++ b/drivers/staging/media/meson/vdec/codec_hevc_common.c @@ -42,9 +42,17 @@ void codec_hevc_setup_decode_head(struct amvdec_session *sess, int is_10bit) return; } + /* enable mem saving mode for 8-bit */ + if (!is_10bit) + amvdec_write_dos_bits(core, HEVC_SAO_CTRL5, BIT(9)); + else + amvdec_clear_dos_bits(core, HEVC_SAO_CTRL5, BIT(9)); + if (codec_hevc_use_mmu(core->platform->revision, sess->pixfmt_cap, is_10bit)) amvdec_write_dos(core, HEVCD_MPP_DECOMP_CTL1, BIT(4)); + else if (!is_10bit) + amvdec_write_dos(core, HEVCD_MPP_DECOMP_CTL1, BIT(3)); else amvdec_write_dos(core, HEVCD_MPP_DECOMP_CTL1, 0); @@ -76,7 +84,7 @@ static void codec_hevc_setup_buffers_gxbb(struct amvdec_session *sess, idx = vb->index; - if (codec_hevc_use_downsample(sess->pixfmt_cap, is_10bit)) + if (codec_hevc_use_fbc(sess->pixfmt_cap, is_10bit)) buf_y_paddr = comm->fbc_buffer_paddr[idx]; else buf_y_paddr = vb2_dma_contig_plane_dma_addr(vb, 0); @@ -117,7 +125,6 @@ static void codec_hevc_setup_buffers_gxl(struct amvdec_session *sess, { struct amvdec_core *core = sess->core; struct v4l2_m2m_buffer *buf; - u32 revision = core->platform->revision; u32 pixfmt_cap = sess->pixfmt_cap; int i; @@ -130,9 +137,7 @@ static void codec_hevc_setup_buffers_gxl(struct amvdec_session *sess, dma_addr_t buf_uv_paddr = 0; u32 idx = vb->index; - if (codec_hevc_use_mmu(revision, pixfmt_cap, is_10bit)) - buf_y_paddr = comm->mmu_header_paddr[idx]; - else if (codec_hevc_use_downsample(pixfmt_cap, is_10bit)) + if (codec_hevc_use_downsample(pixfmt_cap, is_10bit)) buf_y_paddr = comm->fbc_buffer_paddr[idx]; else buf_y_paddr = vb2_dma_contig_plane_dma_addr(vb, 0); @@ -173,6 +178,14 @@ void codec_hevc_free_fbc_buffers(struct amvdec_session *sess, comm->fbc_buffer_vaddr[i] = NULL; } } + + if (comm->mmu_map_vaddr) { + dma_free_coherent(dev, MMU_MAP_SIZE, + comm->mmu_map_vaddr, + comm->mmu_map_paddr); + comm->mmu_map_vaddr = NULL; + } + } EXPORT_SYMBOL_GPL(codec_hevc_free_fbc_buffers); @@ -205,79 +218,29 @@ static int codec_hevc_alloc_fbc_buffers(struct amvdec_session *sess, return 0; } -void codec_hevc_free_mmu_headers(struct amvdec_session *sess, - struct codec_hevc_common *comm) -{ - struct device *dev = sess->core->dev; - int i; - - for (i = 0; i < MAX_REF_PIC_NUM; ++i) { - if (comm->mmu_header_vaddr[i]) { - dma_free_coherent(dev, MMU_COMPRESS_HEADER_SIZE, - comm->mmu_header_vaddr[i], - comm->mmu_header_paddr[i]); - comm->mmu_header_vaddr[i] = NULL; - } - } - - if (comm->mmu_map_vaddr) { - dma_free_coherent(dev, MMU_MAP_SIZE, - comm->mmu_map_vaddr, - comm->mmu_map_paddr); - comm->mmu_map_vaddr = NULL; - } -} -EXPORT_SYMBOL_GPL(codec_hevc_free_mmu_headers); - -static int codec_hevc_alloc_mmu_headers(struct amvdec_session *sess, - struct codec_hevc_common *comm) -{ - struct device *dev = sess->core->dev; - struct v4l2_m2m_buffer *buf; - - comm->mmu_map_vaddr = dma_alloc_coherent(dev, MMU_MAP_SIZE, - &comm->mmu_map_paddr, - GFP_KERNEL); - if (!comm->mmu_map_vaddr) - return -ENOMEM; - - v4l2_m2m_for_each_dst_buf(sess->m2m_ctx, buf) { - u32 idx = buf->vb.vb2_buf.index; - dma_addr_t paddr; - void *vaddr = dma_alloc_coherent(dev, MMU_COMPRESS_HEADER_SIZE, - &paddr, GFP_KERNEL); - if (!vaddr) { - codec_hevc_free_mmu_headers(sess, comm); - return -ENOMEM; - } - - comm->mmu_header_vaddr[idx] = vaddr; - comm->mmu_header_paddr[idx] = paddr; - } - - return 0; -} - int codec_hevc_setup_buffers(struct amvdec_session *sess, struct codec_hevc_common *comm, int is_10bit) { struct amvdec_core *core = sess->core; + struct device *dev = core->dev; int ret; - if (codec_hevc_use_downsample(sess->pixfmt_cap, is_10bit)) { - ret = codec_hevc_alloc_fbc_buffers(sess, comm); - if (ret) - return ret; + if (codec_hevc_use_mmu(core->platform->revision, + sess->pixfmt_cap, is_10bit)) { + comm->mmu_map_vaddr = dma_alloc_coherent(dev, MMU_MAP_SIZE, + &comm->mmu_map_paddr, + GFP_KERNEL); + if (!comm->mmu_map_vaddr) + return -ENOMEM; } if (codec_hevc_use_mmu(core->platform->revision, - sess->pixfmt_cap, is_10bit)) { - ret = codec_hevc_alloc_mmu_headers(sess, comm); - if (ret) { - codec_hevc_free_fbc_buffers(sess, comm); + sess->pixfmt_cap, is_10bit) || + codec_hevc_use_downsample(sess->pixfmt_cap, is_10bit)) { + ret = codec_hevc_alloc_fbc_buffers(sess, comm); + if (ret) return ret; - } } if (core->platform->revision == VDEC_REVISION_GXBB) @@ -291,24 +254,19 @@ EXPORT_SYMBOL_GPL(codec_hevc_setup_buffers); void codec_hevc_fill_mmu_map(struct amvdec_session *sess, struct codec_hevc_common *comm, - struct vb2_buffer *vb) + struct vb2_buffer *vb, + u32 is_10bit) { u32 use_mmu = codec_hevc_use_mmu(sess->core->platform->revision, - sess->pixfmt_cap, - sess->bitdepth == 10 ? 1 : 0); - u32 size = amvdec_amfbc_size(sess->width, sess->height, - sess->bitdepth == 10 ? 1 : 0, + sess->pixfmt_cap, is_10bit); + u32 size = amvdec_amfbc_size(sess->width, sess->height, is_10bit, use_mmu); u32 nb_pages = size / PAGE_SIZE; u32 *mmu_map = comm->mmu_map_vaddr; u32 first_page; u32 i; - if (sess->pixfmt_cap == V4L2_PIX_FMT_NV12M) - first_page = comm->fbc_buffer_paddr[vb->index] >> PAGE_SHIFT; - else - first_page = vb2_dma_contig_plane_dma_addr(vb, 0) >> PAGE_SHIFT; - + first_page = comm->fbc_buffer_paddr[vb->index] >> PAGE_SHIFT; for (i = 0; i < nb_pages; ++i) mmu_map[i] = first_page + i; } diff --git a/drivers/staging/media/meson/vdec/codec_hevc_common.h b/drivers/staging/media/meson/vdec/codec_hevc_common.h index 88e4379ba1ee..5a3c6520940f 100644 --- a/drivers/staging/media/meson/vdec/codec_hevc_common.h +++ b/drivers/staging/media/meson/vdec/codec_hevc_common.h @@ -22,9 +22,6 @@ struct codec_hevc_common { void *fbc_buffer_vaddr[MAX_REF_PIC_NUM]; dma_addr_t fbc_buffer_paddr[MAX_REF_PIC_NUM]; - void *mmu_header_vaddr[MAX_REF_PIC_NUM]; - dma_addr_t mmu_header_paddr[MAX_REF_PIC_NUM]; - void *mmu_map_vaddr; dma_addr_t mmu_map_paddr; }; @@ -32,14 +29,15 @@ struct codec_hevc_common { /* Returns 1 if we must use framebuffer compression */ static inline int codec_hevc_use_fbc(u32 pixfmt, int is_10bit) { - /* TOFIX: Handle Amlogic Compressed buffer for 8bit also */ - return is_10bit; + return pixfmt == V4L2_PIX_FMT_YUV420_8BIT || + pixfmt == V4L2_PIX_FMT_YUV420_10BIT || + is_10bit; } /* Returns 1 if we are decoding 10-bit but outputting 8-bit NV12 */ static inline int codec_hevc_use_downsample(u32 pixfmt, int is_10bit) { - return is_10bit; + return pixfmt == V4L2_PIX_FMT_NV12M && is_10bit; } /* Returns 1 if we are decoding using the IOMMU */ @@ -66,6 +64,7 @@ int codec_hevc_setup_buffers(struct amvdec_session *sess, void codec_hevc_fill_mmu_map(struct amvdec_session *sess, struct codec_hevc_common *comm, - struct vb2_buffer *vb); + struct vb2_buffer *vb, + u32 is_10bit); #endif diff --git a/drivers/staging/media/meson/vdec/codec_vp9.c b/drivers/staging/media/meson/vdec/codec_vp9.c index a810c50f3a39..e193a2f9de9f 100644 --- a/drivers/staging/media/meson/vdec/codec_vp9.c +++ b/drivers/staging/media/meson/vdec/codec_vp9.c @@ -458,12 +458,6 @@ struct codec_vp9 { struct list_head ref_frames_list; u32 frames_num; - /* In case of downsampling (decoding with FBC but outputting in NV12M), - * we need to allocate additional buffers for FBC. - */ - void *fbc_buffer_vaddr[MAX_REF_PIC_NUM]; - dma_addr_t fbc_buffer_paddr[MAX_REF_PIC_NUM]; - int ref_frame_map[REF_FRAMES]; int next_ref_frame_map[REF_FRAMES]; struct vp9_frame *frame_refs[REFS_PER_FRAME]; @@ -901,11 +895,8 @@ static void codec_vp9_set_sao(struct amvdec_session *sess, buf_y_paddr = vb2_dma_contig_plane_dma_addr(vb, 0); - if (codec_hevc_use_fbc(sess->pixfmt_cap, vp9->is_10bit)) { - val = amvdec_read_dos(core, HEVC_SAO_CTRL5) & ~0xff0200; - amvdec_write_dos(core, HEVC_SAO_CTRL5, val); + if (codec_hevc_use_fbc(sess->pixfmt_cap, vp9->is_10bit)) amvdec_write_dos(core, HEVC_CM_BODY_START_ADDR, buf_y_paddr); - } if (sess->pixfmt_cap == V4L2_PIX_FMT_NV12M) { buf_y_paddr = @@ -921,7 +912,7 @@ static void codec_vp9_set_sao(struct amvdec_session *sess, if (codec_hevc_use_mmu(core->platform->revision, sess->pixfmt_cap, vp9->is_10bit)) { amvdec_write_dos(core, HEVC_CM_HEADER_START_ADDR, - vp9->common.mmu_header_paddr[vb->index]); + vb2_dma_contig_plane_dma_addr(vb, 0)); /* use HEVC_CM_HEADER_START_ADDR */ amvdec_write_dos_bits(core, HEVC_SAO_CTRL5, BIT(10)); } @@ -956,7 +947,8 @@ static void codec_vp9_set_sao(struct amvdec_session *sess, val &= ~0x3; if (!codec_hevc_use_fbc(sess->pixfmt_cap, vp9->is_10bit)) val |= BIT(0); /* disable cm compression */ - /* TOFIX: Handle Amlogic Framebuffer compression */ + else if (amvdec_is_dst_fbc(sess)) + val |= BIT(1); /* Disable double write */ } amvdec_write_dos(core, HEVC_SAO_CTRL1, val); @@ -1286,7 +1278,8 @@ static void codec_vp9_process_frame(struct amvdec_session *sess) if (codec_hevc_use_mmu(core->platform->revision, sess->pixfmt_cap, vp9->is_10bit)) codec_hevc_fill_mmu_map(sess, &vp9->common, - &vp9->cur_frame->vbuf->vb2_buf); + &vp9->cur_frame->vbuf->vb2_buf, + vp9->is_10bit); intra_only = param->p.show_frame ? 0 : param->p.intra_only; From patchwork Thu Jun 4 13:53:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 11588041 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9573C90 for ; Thu, 4 Jun 2020 13:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A09E20772 for ; Thu, 4 Jun 2020 13:53:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="kUvM5lhA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728934AbgFDNxm (ORCPT ); Thu, 4 Jun 2020 09:53:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728921AbgFDNxh (ORCPT ); Thu, 4 Jun 2020 09:53:37 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88969C08C5C1 for ; Thu, 4 Jun 2020 06:53:37 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id x13so6206296wrv.4 for ; Thu, 04 Jun 2020 06:53:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lGj2UMyH8lsz5cePu8qdjRLQp4Cv58ojSEdB01leLf4=; b=kUvM5lhA0X5A2xJgJf7Kx6ruICrlB1Lu2504upwpyDnwS32Swa5tp1GIls0pD9VZoo 8bLhHT+Q0pojf5xrwFfO0+nESF089bvwl3TbvCNKxyg86ytL8urGhj3NTLKIbilWTTbY qb+iYcoIpGXUWad0EyS4IyE58Wgg3NB2qij5dVL/CWjgPJdfycgL5rOUqU2x/nhqGOZA cy7vkUybM5STb8o64YfRtWFvYWjMhUTJZpqs1BhdjYKiMZmMc+oa0qINif1NtiKtLmCr WSPCRxYJuVzURhrZVwrwIHQ64e7xDUfPHP2DxUeF3+QB04lYG42va4p1rGSugGdjv/WB tS6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lGj2UMyH8lsz5cePu8qdjRLQp4Cv58ojSEdB01leLf4=; b=eGrldYe94cdfNEZKy9LIAL9J/03ztVRVmLWKLn0b8lv0/TMjtYgg5sA8u/X2X46KcA 0+MCw9GpiN7Iq+ppx2XONf2+3USTUFmDZLls3uWJmKzXn6Uo5aDP5Ezt8FDzj7c8wt1T XseGzXzJkY8FXdDShoX/drPU/F9QzMmR9c/JKvdQyv/gwWLkWjcOdx+SusHQA3kpzo+R ryjcWf/3H6kRe2J5LLHLi7XF3QZSrzzGa74+k2pn2JgEWrsOkKy2eU1Mu/bEzZ/9hByE D67ouX3NtiRWYRWooSqhZdIkTaoDHzummSn7BNHnFKeF4xZ8d3ZcljFDthc3RgK340jd 2J9g== X-Gm-Message-State: AOAM532LjdWuTgXU0U7gpIDnr2+vE8BAcrScozBRzNtXqThXDeC0kC7L utCAGPBYfAcG7bBeoJsK1Xi/CQ== X-Google-Smtp-Source: ABdhPJyMzfHyb8pTAQmMxPrEsEYW71XUGUiF6xOTjuUJnnxbQaZcY7he/oHRn21BXafwxPrX8dtpRA== X-Received: by 2002:adf:f6ce:: with SMTP id y14mr4801259wrp.90.1591278816084; Thu, 04 Jun 2020 06:53:36 -0700 (PDT) Received: from bender.baylibre.local ([2a01:e35:2ec0:82b0:22:5867:d2c6:75f4]) by smtp.gmail.com with ESMTPSA id i74sm8185599wri.49.2020.06.04.06.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2020 06:53:35 -0700 (PDT) From: Neil Armstrong To: hverkuil-cisco@xs4all.nl Cc: linux-media@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 5/5] media: meson: vdec: handle compressed output pixel format negociation with consumer Date: Thu, 4 Jun 2020 15:53:17 +0200 Message-Id: <20200604135317.9235-6-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200604135317.9235-1-narmstrong@baylibre.com> References: <20200604135317.9235-1-narmstrong@baylibre.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Maxime Jourdan Add the necessary to add support for negociating the compressed buffer pixel format with the V4L2 M2M consumer, and allocating the right buffers in this case. Until a proper mechanism exists to pass a modifier along the pixel format, only the generic V4L2_PIX_FMT_YUV420_8BIT and V4L2_PIX_FMT_YUV420_10BIT format are passed in v4l2_pix_format_mplane struct for consumer. Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- .../media/meson/vdec/codec_hevc_common.c | 1 - drivers/staging/media/meson/vdec/vdec.c | 46 +++++++++++++++++++ drivers/staging/media/meson/vdec/vdec.h | 3 ++ .../staging/media/meson/vdec/vdec_helpers.c | 23 ++++++++++ .../staging/media/meson/vdec/vdec_platform.c | 9 ++-- 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/meson/vdec/codec_hevc_common.c b/drivers/staging/media/meson/vdec/codec_hevc_common.c index 73dae40b3319..78fada7b8fa9 100644 --- a/drivers/staging/media/meson/vdec/codec_hevc_common.c +++ b/drivers/staging/media/meson/vdec/codec_hevc_common.c @@ -10,7 +10,6 @@ #include "vdec_helpers.h" #include "hevc_regs.h" -#define MMU_COMPRESS_HEADER_SIZE 0x48000 #define MMU_MAP_SIZE 0x4800 const u16 vdec_hevc_parser_cmd[] = { diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c index 3040136ceb77..9fb075f69cb9 100644 --- a/drivers/staging/media/meson/vdec/vdec.c +++ b/drivers/staging/media/meson/vdec/vdec.c @@ -192,6 +192,7 @@ static int vdec_queue_setup(struct vb2_queue *q, unsigned int *num_buffers, { struct amvdec_session *sess = vb2_get_drv_priv(q); u32 output_size = amvdec_get_output_size(sess); + u32 revision = sess->core->platform->revision; if (*num_planes) { switch (q->type) { @@ -215,6 +216,12 @@ static int vdec_queue_setup(struct vb2_queue *q, unsigned int *num_buffers, sizes[2] < output_size / 4) return -EINVAL; break; + case V4L2_PIX_FMT_YUV420_8BIT: + case V4L2_PIX_FMT_YUV420_10BIT: + if (*num_planes != 1 || + sizes[0] < MMU_COMPRESS_HEADER_SIZE) + return -EINVAL; + break; default: return -EINVAL; } @@ -244,6 +251,24 @@ static int vdec_queue_setup(struct vb2_queue *q, unsigned int *num_buffers, sizes[2] = output_size / 4; *num_planes = 3; break; + case V4L2_PIX_FMT_YUV420_8BIT: + if (revision >= VDEC_REVISION_G12A) + sizes[0] = MMU_COMPRESS_HEADER_SIZE; + else + sizes[0] = amvdec_amfbc_size(sess->width, + sess->height, + 0, 0); + *num_planes = 1; + break; + case V4L2_PIX_FMT_YUV420_10BIT: + if (revision >= VDEC_REVISION_G12A) + sizes[0] = MMU_COMPRESS_HEADER_SIZE; + else + sizes[0] = amvdec_amfbc_size(sess->width, + sess->height, + 1, 0); + *num_planes = 1; + break; default: return -EINVAL; } @@ -496,6 +521,7 @@ vdec_try_fmt_common(struct amvdec_session *sess, u32 size, struct v4l2_plane_pix_format *pfmt = pixmp->plane_fmt; const struct amvdec_format *fmts = sess->core->platform->formats; const struct amvdec_format *fmt_out = NULL; + u32 revision = sess->core->platform->revision; u32 output_size = 0; memset(pfmt[0].reserved, 0, sizeof(pfmt[0].reserved)); @@ -548,6 +574,26 @@ vdec_try_fmt_common(struct amvdec_session *sess, u32 size, pfmt[2].sizeimage = output_size / 2; pfmt[2].bytesperline = ALIGN(pixmp->width, 32) / 2; pixmp->num_planes = 3; + } else if (pixmp->pixelformat == V4L2_PIX_FMT_YUV420_8BIT) { + if (revision >= VDEC_REVISION_G12A) { + pfmt[0].sizeimage = MMU_COMPRESS_HEADER_SIZE; + } else { + pfmt[0].sizeimage = + amvdec_amfbc_size(pixmp->width, + pixmp->height, 0, 0); + pfmt[0].bytesperline = pixmp->width; + } + pixmp->num_planes = 1; + } else if (pixmp->pixelformat == V4L2_PIX_FMT_YUV420_10BIT) { + if (revision >= VDEC_REVISION_G12A) { + pfmt[0].sizeimage = MMU_COMPRESS_HEADER_SIZE; + } else { + pfmt[0].sizeimage = + amvdec_amfbc_size(pixmp->width, + pixmp->height, 1, 0); + pfmt[0].bytesperline = pixmp->width; + } + pixmp->num_planes = 1; } } diff --git a/drivers/staging/media/meson/vdec/vdec.h b/drivers/staging/media/meson/vdec/vdec.h index e3e4af73447a..1412054a70c4 100644 --- a/drivers/staging/media/meson/vdec/vdec.h +++ b/drivers/staging/media/meson/vdec/vdec.h @@ -17,6 +17,9 @@ #include "vdec_platform.h" +/* MMU header size for codecs using the IOMMU + FBC */ +#define MMU_COMPRESS_HEADER_SIZE 0x48000 + /* 32 buffers in 3-plane YUV420 */ #define MAX_CANVAS (32 * 3) diff --git a/drivers/staging/media/meson/vdec/vdec_helpers.c b/drivers/staging/media/meson/vdec/vdec_helpers.c index 320cac1ed03e..7166605b89ae 100644 --- a/drivers/staging/media/meson/vdec/vdec_helpers.c +++ b/drivers/staging/media/meson/vdec/vdec_helpers.c @@ -299,6 +299,22 @@ static void dst_buf_done(struct amvdec_session *sess, vbuf->vb2_buf.planes[1].bytesused = output_size / 4; vbuf->vb2_buf.planes[2].bytesused = output_size / 4; break; + case V4L2_PIX_FMT_YUV420_8BIT: + if (sess->core->platform->revision >= VDEC_REVISION_G12A) + vbuf->vb2_buf.planes[0].bytesused = + MMU_COMPRESS_HEADER_SIZE; + else + vbuf->vb2_buf.planes[0].bytesused = + amvdec_amfbc_size(sess->width, sess->height, 0, 0); + break; + case V4L2_PIX_FMT_YUV420_10BIT: + if (sess->core->platform->revision >= VDEC_REVISION_G12A) + vbuf->vb2_buf.planes[0].bytesused = + MMU_COMPRESS_HEADER_SIZE; + else + vbuf->vb2_buf.planes[0].bytesused = + amvdec_amfbc_size(sess->width, sess->height, 1, 0); + break; } vbuf->vb2_buf.timestamp = timestamp; @@ -478,6 +494,13 @@ void amvdec_src_change(struct amvdec_session *sess, u32 width, sess->status = STATUS_NEEDS_RESUME; sess->bitdepth = bitdepth; + if (sess->pixfmt_cap == V4L2_PIX_FMT_YUV420_8BIT && + bitdepth == 10) + sess->pixfmt_cap = V4L2_PIX_FMT_YUV420_10BIT; + else if (sess->pixfmt_cap == V4L2_PIX_FMT_YUV420_10BIT && + bitdepth == 8) + sess->pixfmt_cap = V4L2_PIX_FMT_YUV420_8BIT; + dev_dbg(sess->core->dev, "Res. changed (%ux%u), DPB %u, bitdepth %u\n", width, height, dpb_size, bitdepth); v4l2_event_queue_fh(&sess->fh, &ev); diff --git a/drivers/staging/media/meson/vdec/vdec_platform.c b/drivers/staging/media/meson/vdec/vdec_platform.c index eabbebab2da2..efc090d2a3bb 100644 --- a/drivers/staging/media/meson/vdec/vdec_platform.c +++ b/drivers/staging/media/meson/vdec/vdec_platform.c @@ -61,7 +61,8 @@ static const struct amvdec_format vdec_formats_gxl[] = { .vdec_ops = &vdec_hevc_ops, .codec_ops = &codec_vp9_ops, .firmware_path = "meson/vdec/gxl_vp9.bin", - .pixfmts_cap = { V4L2_PIX_FMT_NV12M, 0 }, + .pixfmts_cap = { V4L2_PIX_FMT_NV12M, V4L2_PIX_FMT_YUV420_8BIT, + V4L2_PIX_FMT_YUV420_10BIT, 0 }, .flags = V4L2_FMT_FLAG_COMPRESSED | V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -149,7 +150,8 @@ static const struct amvdec_format vdec_formats_g12a[] = { .vdec_ops = &vdec_hevc_ops, .codec_ops = &codec_vp9_ops, .firmware_path = "meson/vdec/g12a_vp9.bin", - .pixfmts_cap = { V4L2_PIX_FMT_NV12M, 0 }, + .pixfmts_cap = { V4L2_PIX_FMT_NV12M, V4L2_PIX_FMT_YUV420_8BIT, + V4L2_PIX_FMT_YUV420_10BIT, 0 }, .flags = V4L2_FMT_FLAG_COMPRESSED | V4L2_FMT_FLAG_DYN_RESOLUTION, }, { @@ -199,7 +201,8 @@ static const struct amvdec_format vdec_formats_sm1[] = { .vdec_ops = &vdec_hevc_ops, .codec_ops = &codec_vp9_ops, .firmware_path = "meson/vdec/sm1_vp9_mmu.bin", - .pixfmts_cap = { V4L2_PIX_FMT_NV12M, 0 }, + .pixfmts_cap = { V4L2_PIX_FMT_NV12M, V4L2_PIX_FMT_YUV420_8BIT, + V4L2_PIX_FMT_YUV420_10BIT, 0 }, .flags = V4L2_FMT_FLAG_COMPRESSED | V4L2_FMT_FLAG_DYN_RESOLUTION, }, {