Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp5849800ybx; Sun, 10 Nov 2019 23:03:05 -0800 (PST) X-Google-Smtp-Source: APXvYqx8VEtPQGD2EnxORHkhDhV5h7IVZVG2enHwyKQpC/PgtZovYG0vDZYVN67V+L87fDZs+avD X-Received: by 2002:a17:906:4d91:: with SMTP id s17mr14872981eju.156.1573455785045; Sun, 10 Nov 2019 23:03:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573455785; cv=none; d=google.com; s=arc-20160816; b=haO+O0SmsRx/5gEejf7PRxF+1FTTIZQMBfrai35JANDdQVSyt44D8CaseCdEqft3Mc r5N08uomSqWhTqqlulNM91uh8IjREsPV4jlWdUaUns1z8VW71p7ZqmMaWxsIxwGHj5/b QIRdROryUQQyLWO+tCmBRgbG3Zn/Uazc+Enigp8/Nb29M3VgEzIMYPLnfK+pwQWKfrnd OLdCok9uVK8GFmouyzRzIm0SULKboBeLaaW3wg9WSeuZ5fz/dTEXxU7zIAmrhmuGeNy+ wp1zouZhXo9nJ0XJ+fpcVJ+ZkxEe8/29cxOVOKO3Y0uqjNIpewJr6BFAmLJQdccGg3dx NErw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=F3TxF+AJbjTFe9CSJ0NILNUnMGyyn7tR/jfpwQuTY6o=; b=ZZVlcaB6racdnUpen+GXG6GkjoqhAL5yidHngK7n7SBkxhi6jo/Y5TcGrlveysgcXS naEDbt7aS0LFGdN1xPduOIvjJmS1xmVmhAzUpW64n0ndYTgusQHY5dLrgmOyZwfZacO6 kzAKOW/LZgkQn5iVv0D4IilGBZE3nPaiL7TafnrdD3PTjeo7K9ixgIyWCHg2W7L+TFIF Iz8U6nK/Z3JA8NPgOSmsRR7SNMkMq415cYHLhBMBc9julMhCHfkcGKb0HWHIlJSgJqgM AK7gUWJlGgOWt/4fNv+C/4RGT+ZKN9brmxlWbRBQCLPk6RgRYBlvkwW0dFV6h552/Kve FOFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YMByG+QA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a11si12914974edj.143.2019.11.10.23.02.38; Sun, 10 Nov 2019 23:03:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YMByG+QA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbfKKHBe (ORCPT + 99 others); Mon, 11 Nov 2019 02:01:34 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:46106 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726360AbfKKHBd (ORCPT ); Mon, 11 Nov 2019 02:01:33 -0500 Received: by mail-ed1-f67.google.com with SMTP id x11so11057080eds.13 for ; Sun, 10 Nov 2019 23:01:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=F3TxF+AJbjTFe9CSJ0NILNUnMGyyn7tR/jfpwQuTY6o=; b=YMByG+QA9BSSONXzijgH3lT/HJSfJ63osPgOWzCWCYvhB/KtuJhyoZum3mgB+NjmrG rJWRy9UXVTVCcWOm/sEn21bSpo0SlcT++UxUxkrfFLaNJgvrQEbXDbDcFcFKygsgPy+6 Vcou70IW3wEv489ErEOzEfURMA/ZBjdNOisUM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=F3TxF+AJbjTFe9CSJ0NILNUnMGyyn7tR/jfpwQuTY6o=; b=I9eWaP6WL7oV0awOTyuDyrDAaH2pR79zZ2/O0JUGBA4PzGvG3bMwWDUjgwIeqVz8VP vSfGS8pk+PhR2lJVpXcsJggX5oQETHuQZgSEixuQIkN7vbQtBFgA0rs4046IjwPYEpo7 YZvTd3rJYgL+XqHrjADUdQCRCEDIo64LBSy0WORS1KHhL1FJHcu7/nj7jzt9WIqoFXOW nz/8buk8aF93ex71zcfobSGRJk4CqNEMf/6dsLs0XxZzpmx9HEPkstHh7ZcSOvQcGoDx ebntZGiMo+wy6hbfXSJtBN8UaoSsMaxO4Bt9jiyMJhyCreZICvHcFwXYqbY2G94HY7tS gwEQ== X-Gm-Message-State: APjAAAWwHndk5wO/zrN4NZ0n1wMikTJL/PVCqoi6ycQ9ZTBGD+cGEyGB 2qJH6y2id4PckHAR4lA8xMwR+URIYQm+Uw== X-Received: by 2002:a17:906:494d:: with SMTP id f13mr21465392ejt.250.1573455691206; Sun, 10 Nov 2019 23:01:31 -0800 (PST) Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com. [209.85.221.51]) by smtp.gmail.com with ESMTPSA id o59sm525892eda.80.2019.11.10.23.01.29 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Nov 2019 23:01:30 -0800 (PST) Received: by mail-wr1-f51.google.com with SMTP id f2so13290311wrs.11 for ; Sun, 10 Nov 2019 23:01:29 -0800 (PST) X-Received: by 2002:a05:6000:1206:: with SMTP id e6mr5641649wrx.113.1573455687257; Sun, 10 Nov 2019 23:01:27 -0800 (PST) MIME-Version: 1.0 References: <20191017084033.28299-1-xia.jiang@mediatek.com> <20191017084033.28299-6-xia.jiang@mediatek.com> <20191023103945.GA41089@chromium.org> <1571906317.6254.64.camel@mhfsdcap03> <1572229558.27439.6.camel@mhfsdcap03> In-Reply-To: <1572229558.27439.6.camel@mhfsdcap03> From: Tomasz Figa Date: Mon, 11 Nov 2019 16:01:13 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 5/5] media: platform: Add jpeg dec/enc feature To: Xia Jiang Cc: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Rick Chang , Linux Media Mailing List , linux-devicetree , Linux Kernel Mailing List , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , "moderated list:ARM/Mediatek SoC support" , Marek Szyprowski , srv_heupstream Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xia, On Mon, Oct 28, 2019 at 11:26 AM Xia Jiang wrote: > > On Thu, 2019-10-24 at 18:23 +0900, Tomasz Figa wrote: > > On Thu, Oct 24, 2019 at 5:38 PM Xia Jiang wrot= e: > > > > > > On Wed, 2019-10-23 at 19:39 +0900, Tomasz Figa wrote: > > > > Hi Xia, > > > > > > > > On Thu, Oct 17, 2019 at 04:40:38PM +0800, Xia Jiang wrote: > > > > > Add mtk jpeg encode v4l2 driver based on jpeg decode, because tha= t jpeg > > > > > decode and encode have great similarities with function operation= . > > > > > > > > > > Signed-off-by: Xia Jiang > > > > > --- > > > > > v4: split mtk_jpeg_try_fmt_mplane() to two functions, one for enc= oder, > > > > > one for decoder. > > > > > split mtk_jpeg_set_default_params() to two functions, one for > > > > > encoder, one for decoder. > > > > > add cropping support for encoder in g/s_selection ioctls. > > > > > change exif mode support by using V4L2_JPEG_ACTIVE_MARKER_APP= 1. > > > > > change MTK_JPEG_MAX_WIDTH/MTK_JPEG_MAX_HEIGH from 8192 to 655= 35 by > > > > > specification. > > > > > move width shifting operation behind aligning operation in > > > > > mtk_jpeg_try_enc_fmt_mplane() for bug fix. > > > > > fix user abuseing data_offset issue for DMABUF in > > > > > mtk_jpeg_set_enc_src(). > > > > > fix kbuild warings: change MTK_JPEG_MIN_HEIGHT/MTK_JPEG_MAX_H= EIGHT > > > > > and MTK_JPEG_MIN_WIDTH/MTK_JPEG_MAX_WIDTH= from > > > > > 'int' type to 'unsigned int' type. > > > > > fix msleadingly indented of 'else'. > > > > > > > > > > v3: delete Change-Id. > > > > > only test once handler->error after the last v4l2_ctrl_new_st= d(). > > > > > seperate changes of v4l2-ctrls.c and v4l2-controls.h to new p= atch. > > > > > > > > > > v2: fix compliance test fail, check created buffer size in driver= . > > > > > --- > > > > > drivers/media/platform/mtk-jpeg/Makefile | 5 +- > > > > > .../media/platform/mtk-jpeg/mtk_jpeg_core.c | 731 ++++++++++++= +++--- > > > > > .../media/platform/mtk-jpeg/mtk_jpeg_core.h | 123 ++- > > > > > .../media/platform/mtk-jpeg/mtk_jpeg_dec_hw.h | 7 +- > > > > > .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.c | 175 +++++ > > > > > .../media/platform/mtk-jpeg/mtk_jpeg_enc_hw.h | 60 ++ > > > > > .../platform/mtk-jpeg/mtk_jpeg_enc_reg.h | 49 ++ > > > > > 7 files changed, 1004 insertions(+), 146 deletions(-) > > > > > create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_= hw.c > > > > > create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_= hw.h > > > > > create mode 100644 drivers/media/platform/mtk-jpeg/mtk_jpeg_enc_= reg.h > > > > > > > > > > > > > First of all, thanks for the patch! > > > > > > > > Please check my comments below. > > > > > > > > My general feeling about this code is that the encoder hardware blo= ck is > > > > completely orthogonal from the decoder block and there is very litt= le code > > > > reuse from the original decoder driver. > > > > > > > > Moreover, a lot of existing code now needs if (decoder) { ... } els= e {... } > > > > segments, which complicates the code. > > > > > > > > Would it perhaps make sense to instead create a separate mtk-jpeg-e= nc > > > > driver? > > > > > > > Dear Tomasz, > > > > > > Thanks for your comments. > > > > > > My reasons about the architecture of jpeg enc driver are as follows: > > > > > > The first internal design and realization of jpeg enc driver was a > > > separate driver, but found that mtk_jpeg_core.c and mtk_jpeg_enc_core= .c > > > have lots of reuse.Because that the core.c mainly contains realizati= on > > > of v4L2 ioctl functions and some logic which are high similarity betw= een > > > encoder and decoder. > > > > > > The jpeg encoder and decoder are two independent hardwares exactly, s= o > > > the code about hardware specification(register setting) are > > > separated(mtk_jpeg_enc_hw.c and mtk_jpeg_dec_hw.c). > > > > > > As for 17 existing code segments contain if(decoder){} else {}, they = are > > > not complicated IMHO.The complicated(multilayer nested) functions are > > > separated in V4 version as Hans recommendation. > > > > > > By the way,the upstreamed module s5p-jpeg > > > (https://elixir.bootlin.com/linux/latest/source/drivers/media/platfor= m/s5p-jpeg/jpeg-core.c#L1998) also use encoder and decoder mode in the comm= on core.c, but their encoder and decoder are the same hardware.Maybe our jp= eg enc and dec are designed into one hardware in the future.In that case th= e current architecture is more compatible. > > > > > > So I prefer the current design. > > > > > > > Would you be able to give some numbers to show the code reuse to > > justify using the same driver? From my observation, a new driver would > > result in a significantly cleaner code. If there is a further hardware > > architecture change, that would likely require another driver, because > > it wouldn't be compatible with existing programming model anyway. > > > > Regardless of that, if we end up with reusing the same driver, I'd > > like you to fix the issues existing in the current base before adding > > the encoder functionality. > Dear Tomasz, > I've counted about 1000 lines of code that can be reused.The reused code > is 75 percent of the original code. > > If you agree to reuse the same driver,I will fix the issues existing in > the current driver. Sorry, I was out of the office. Okay, let's reuse the driver. I guess the hardware programming part itself is smaller than the V4L2 boiler plate needed for it and that's where the 1000 lines of code comes from. The first step I'd suggest then would be running the latest v4l2-compliance, from the master branch of v4l2-utils [1] and making sure there are no issues. Then check if any comments I posted to the new code added by your patch apply to the existing code as well and fixing those issues in a prerequisite patches, at the beginning of the series. [1] https://git.linuxtv.org/v4l-utils.git/ Best regards, Tomasz