Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp145429pxa; Fri, 21 Aug 2020 03:43:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyr2HH011CJInb/Fbj6Cp7cv2BWJvq07Dlk2ts9xBIDbqVFIBAoxFuTC1zr0rmj0M++s9WI X-Received: by 2002:a05:6402:1ca6:: with SMTP id cz6mr2110903edb.310.1598006618830; Fri, 21 Aug 2020 03:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598006618; cv=none; d=google.com; s=arc-20160816; b=VTICa9vBI7R64umcsQ2k5a9UhSiJlkIrKYjmx6wi/SJnpOAbxbE6rP0f8tJFUMne+0 Nlit2Hvytk5YpLRe/qciWTxgHQKP+uZdxTNka8C7JwHbrUzXHOs9fohnsumuHBFXk+4d WfMOV9l6HJgC84zILdJdZNCQTehqidbTnWPmLzJmI5ynmO78+ipWEwu3qLBjvogypQvs V2Bhe8mSXuMaUi6Fhe6VW0lgeRMlsp35l76nFyMf2VEjbttUw9TCePkp1VVomWwTQodv DXgDTRP/a3QF/r6BMv4+s5H5FJC22ovozskyi7av9+gLJchrWd1BeHAO41bCmdQGW1Vg 6olg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Byvzby1llxcruzsj3OyuSTWoxQgTt17xzrKtgbxngX8=; b=Omt6hmPmj10gU1qgWFB0dEgJ/NwVRvdiPrjWuFbzy9K+nnev8/jBMQYOeJONHX6XLd Co+tk9HrO03sL9NnscQBIgaLSN/4rccOFuGt4pkm1gZG6r63m3wden+/Nnq1N50Ubq0v YHkJd49n2h4DffXbj0QPUSHJ1ik177DRSYDZxYvmI4ZWkLE7E6Ws4TWEUiKOW/L/jzqN DonuPBV8H5B+ovx5z6q7Az9Q+3s2xizuvfSA3nebw8Ozidt7H97PWn6qMzNcZub6iosr BQyDdHThsAIprY/G41xu2rNBrwpYSks6S1uj2TssuwFttc5GGWE3JHP2BspxEfjZ9Xv3 /L/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V2xwG4HN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f8si877256edy.251.2020.08.21.03.43.14; Fri, 21 Aug 2020 03:43:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=V2xwG4HN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728670AbgHUKkB (ORCPT + 99 others); Fri, 21 Aug 2020 06:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbgHUKfs (ORCPT ); Fri, 21 Aug 2020 06:35:48 -0400 Received: from mail-ot1-x341.google.com (mail-ot1-x341.google.com [IPv6:2607:f8b0:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00FEFC061385 for ; Fri, 21 Aug 2020 03:35:48 -0700 (PDT) Received: by mail-ot1-x341.google.com with SMTP id z18so1199912otk.6 for ; Fri, 21 Aug 2020 03:35:47 -0700 (PDT) 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; bh=Byvzby1llxcruzsj3OyuSTWoxQgTt17xzrKtgbxngX8=; b=V2xwG4HNtfiwcTEvM+eOUgJtUT4hqHMmCb944VuZ7yrG29MjfY6fz9c3sxBeEEZVp2 P0s9hcx/LY0NfbaBe4Pn++Lvu+J/gW2NSftHgmLlXCh1WsYuynORV/D9mxeC8PC6yEIw C1reXI2nSvv+GSmQWUMNPyZyTmMgJSGFbINk4= 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; bh=Byvzby1llxcruzsj3OyuSTWoxQgTt17xzrKtgbxngX8=; b=jr7ngU1Q+xYVROP6uATO6iGqQD7aTSVwqHWIaYe/ZvwCmdSAyaqE2Bc6y+nNzh/ygT Z3EEs6mGLmYQJSc/jsxqQxs9P8P1Senucn9vkoT8PsQjhCuJ2q3YYfpDnK0MbBQxrqGN 67n1kmhtVHNvb29Bkd3xkpMyrV6I5IBenyCVilbaTfFt//8ch6+6cSurV8aDam8avnJ0 uy0ljowQ676ApryC7LvtdPRrY/mNO9xFNC5xz+chBMUNxwkKpg41g6PDjrW0vhI7xvoC 9Aqe5Ycqw5BKM6A92abf4JMVXgeU+Cpl4IKDJ9/+w6/6uAzLU/Hts08ud2u8tGlX+6KY e6KA== X-Gm-Message-State: AOAM530RIcUmEODMDyvG5PsQqLwtALK3VHVoyR7Xe0oQNpXZD4VXigOS CGgzU8gQnw0HpOEh1pdXUjeZigPCGh8mBO9f X-Received: by 2002:a9d:7443:: with SMTP id p3mr1477681otk.80.1598006146766; Fri, 21 Aug 2020 03:35:46 -0700 (PDT) Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com. [209.85.210.50]) by smtp.gmail.com with ESMTPSA id z6sm331965oot.18.2020.08.21.03.35.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2020 03:35:45 -0700 (PDT) Received: by mail-ot1-f50.google.com with SMTP id e11so1209849otk.4 for ; Fri, 21 Aug 2020 03:35:45 -0700 (PDT) X-Received: by 2002:a9d:5f0c:: with SMTP id f12mr1361858oti.141.1598006145135; Fri, 21 Aug 2020 03:35:45 -0700 (PDT) MIME-Version: 1.0 References: <20200713060842.471356-1-acourbot@chromium.org> <20200713060842.471356-4-acourbot@chromium.org> In-Reply-To: From: Alexandre Courbot Date: Fri, 21 Aug 2020 19:35:34 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 03/16] media: mtk-vcodec: add SCP firmware ops To: Ezequiel Garcia Cc: Tiffany Lin , Andrew-CT Chen , Hans Verkuil , Yunfei Dong , Maoguang Meng , linux-media , "moderated list:ARM/Mediatek SoC support" , devicetree , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 11:09 PM Ezequiel Garcia wrote: > > On Mon, 27 Jul 2020 at 06:06, Alexandre Courbot wrote: > > > > On Thu, Jul 23, 2020 at 6:40 AM Ezequiel Garcia > > wrote: > > > > > > On Mon, 13 Jul 2020 at 03:09, Alexandre Courbot wrote: > > > > > > > > From: Yunfei Dong > > > > > > > > Add support for communicating with the SCP firmware, which will be used > > > > by MT8183. > > > > > > > > Signed-off-by: Yunfei Dong > > > > [acourbot: refactor, cleanup and split] > > > > Co-developed-by: Alexandre Courbot > > > > Signed-off-by: Alexandre Courbot > > > > Acked-by: Tiffany Lin > > > > --- > > > > drivers/media/platform/Kconfig | 1 + > > > > .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 3 + > > > > .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 3 + > > > > .../media/platform/mtk-vcodec/mtk_vcodec_fw.c | 56 +++++++++++++++++++ > > > > .../media/platform/mtk-vcodec/mtk_vcodec_fw.h | 2 + > > > > 5 files changed, 65 insertions(+) > > > > > > > > diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig > > > > index c57ee78fa99d..f0dbe048efea 100644 > > > > --- a/drivers/media/platform/Kconfig > > > > +++ b/drivers/media/platform/Kconfig > > > > @@ -256,6 +256,7 @@ config VIDEO_MEDIATEK_VCODEC > > > > select VIDEOBUF2_DMA_CONTIG > > > > select V4L2_MEM2MEM_DEV > > > > select VIDEO_MEDIATEK_VPU > > > > + select MTK_SCP > > > > help > > > > Mediatek video codec driver provides HW capability to > > > > encode and decode in a range of video formats > > > > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c > > > > index 4f07a5fcce7f..5b5765b98e57 100644 > > > > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c > > > > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c > > > > @@ -225,6 +225,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) > > > > if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", > > > > &rproc_phandle)) { > > > > fw_type = VPU; > > > > + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", > > > > + &rproc_phandle)) { > > > > + fw_type = SCP; > > > > } else { > > > > mtk_v4l2_err("Could not get vdec IPI device"); > > > > return -ENODEV; > > > > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c > > > > index 4340ea10afd0..42530cd01a30 100644 > > > > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c > > > > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c > > > > @@ -233,6 +233,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) > > > > if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vpu", > > > > &rproc_phandle)) { > > > > fw_type = VPU; > > > > + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", > > > > + &rproc_phandle)) { > > > > + fw_type = SCP; > > > > } else { > > > > mtk_v4l2_err("Could not get venc IPI device"); > > > > return -ENODEV; > > > > diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c > > > > index 967bb100a990..f2a62ea62fc6 100644 > > > > --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c > > > > +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_fw.c > > > > @@ -19,6 +19,7 @@ struct mtk_vcodec_fw { > > > > enum mtk_vcodec_fw_type type; > > > > const struct mtk_vcodec_fw_ops *ops; > > > > struct platform_device *pdev; > > > > + struct mtk_scp *scp; > > > > }; > > > > > > > > static int mtk_vcodec_vpu_load_firmware(struct mtk_vcodec_fw *fw) > > > > @@ -71,6 +72,48 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vpu_msg = { > > > > .ipi_send = mtk_vcodec_vpu_ipi_send, > > > > }; > > > > > > > > +static int mtk_vcodec_scp_load_firmware(struct mtk_vcodec_fw *fw) > > > > +{ > > > > + return rproc_boot(scp_get_rproc(fw->scp)); > > > > +} > > > > + > > > > +static unsigned int mtk_vcodec_scp_get_vdec_capa(struct mtk_vcodec_fw *fw) > > > > +{ > > > > + return scp_get_vdec_hw_capa(fw->scp); > > > > +} > > > > + > > > > +static unsigned int mtk_vcodec_scp_get_venc_capa(struct mtk_vcodec_fw *fw) > > > > +{ > > > > + return scp_get_venc_hw_capa(fw->scp); > > > > +} > > > > + > > > > +static void *mtk_vcodec_vpu_scp_dm_addr(struct mtk_vcodec_fw *fw, > > > > + u32 dtcm_dmem_addr) > > > > +{ > > > > + return scp_mapping_dm_addr(fw->scp, dtcm_dmem_addr); > > > > +} > > > > + > > > > +static int mtk_vcodec_scp_set_ipi_register(struct mtk_vcodec_fw *fw, int id, > > > > + mtk_vcodec_ipi_handler handler, const char *name, void *priv) > > > > +{ > > > > + return scp_ipi_register(fw->scp, id, handler, priv); > > > > +} > > > > + > > > > +static int mtk_vcodec_scp_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf, > > > > + unsigned int len, unsigned int wait) > > > > +{ > > > > + return scp_ipi_send(fw->scp, id, buf, len, wait); > > > > +} > > > > + > > > > +static const struct mtk_vcodec_fw_ops mtk_vcodec_rproc_msg = { > > > > + .load_firmware = mtk_vcodec_scp_load_firmware, > > > > + .get_vdec_capa = mtk_vcodec_scp_get_vdec_capa, > > > > + .get_venc_capa = mtk_vcodec_scp_get_venc_capa, > > > > + .map_dm_addr = mtk_vcodec_vpu_scp_dm_addr, > > > > + .ipi_register = mtk_vcodec_scp_set_ipi_register, > > > > + .ipi_send = mtk_vcodec_scp_ipi_send, > > > > +}; > > > > + > > > > static void mtk_vcodec_reset_handler(void *priv) > > > > { > > > > struct mtk_vcodec_dev *dev = priv; > > > > @@ -94,6 +137,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, > > > > const struct mtk_vcodec_fw_ops *ops; > > > > struct mtk_vcodec_fw *fw; > > > > struct platform_device *fw_pdev = NULL; > > > > + struct mtk_scp *scp = NULL; > > > > > > > > switch (type) { > > > > case VPU: > > > > @@ -106,6 +150,14 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, > > > > vpu_wdt_reg_handler(fw_pdev, mtk_vcodec_reset_handler, > > > > dev, rst_id); > > > > break; > > > > + case SCP: > > > > + ops = &mtk_vcodec_rproc_msg; > > > > + scp = scp_get(dev->plat_dev); > > > > + if (!scp) { > > > > + mtk_v4l2_err("could not get vdec scp handle"); > > > > + return ERR_PTR(-EPROBE_DEFER); > > > > > > I suspect the EPROBE_DEFER should be returned by scp_get > > > itself instead. > > > > scp_get() is a function of of mtk_scp remoteproc driver, so even if we > > decide this is desirable (which I am not convinced, as the current > > code leaves the freedom to decide how the absence of SCP should be > > interpreted to the driver) this is beyond the scope of this series. > > > > How can the consumer decide if it should defer probing or not? Fair point. Looking at the code of scp_get(), the only failure points are of_parse_phandle() and of_find_device_by_node(), which both return NULL upon failure. So I cannot think of a way that could make scp_get() decide to return EPROBE_DEFER vs. another error code, which is probably why it just returns NULL for the moment. Now that means that the code above also has no reason to make that decision, and EPROBE_DEFER is probably not valid for all cases. For now I don't see how we could improve this however. > > > > > > > > + } > > > > + break; > > > > default: > > > > mtk_v4l2_err("invalid vcodec fw type"); > > > > return ERR_PTR(-EINVAL); > > > > @@ -118,6 +170,7 @@ struct mtk_vcodec_fw *mtk_vcodec_fw_select(struct mtk_vcodec_dev *dev, > > > > fw->type = type; > > > > fw->ops = ops; > > > > fw->pdev = fw_pdev; > > > > + fw->scp = scp; > > > > > > > > return fw; > > > > } > > > > @@ -129,6 +182,9 @@ void mtk_vcodec_fw_release(struct mtk_vcodec_fw *fw) > > > > case VPU: > > > > put_device(&fw->pdev->dev); > > > > break; > > > > + case SCP: > > > > + scp_put(fw->scp); > > > > > > Interestingly scp_put is a wrapper around put_device :-) > > > Perhaps not a reason to violate the layering. > > > > I don't see what is wrong with the current code? If SCP is in use, we > > use SCP functions to manage it. If in the future SCP involves in such > > a way that we need to do more than a put_device(), we are covered. Or > > am I missing something? > > Oh, nothing wrong. I just found it interesting that scp_put was > just wrapping put_device. Nothing to fix really. > > Thanks! > Ezequiel