Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1559548imm; Tue, 22 May 2018 06:03:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq7WMPlIlXOoSSeTBDdxdIvwrr2pmPIWYrwjgLKo9D6IiGnM/MCrRojWfcF3trtPkGh8rIR X-Received: by 2002:a63:2bc4:: with SMTP id r187-v6mr18985776pgr.231.1526994228147; Tue, 22 May 2018 06:03:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526994228; cv=none; d=google.com; s=arc-20160816; b=ViAncTEJi+rrd6dDHKHweejQujMsIP+aHIviA90+olM8IdWrDRkShZ01VISbpsH3Si NX/TSBDeVLdDoH6Xg5VJjtb6iv+rQ9OXalmi6c7al4J/KUikg2/oQ/QTPQQjXuBEOISq Bya9ym89A7SMC1Jhzr4klGv3oLx1od/DbE7Xza1c/2kn++2FrJJ1SbEGrio0XnIbNkiO edYfxQCMaIqrmkwBSxLm3kXYd6tV5tc7YrMEry492OwvMtP6SF4TJqwJ3fPakOvtSZ2D HrRD02Jg6LodwoOOcZ15VQjltPBpU2p8AiHakIWMNvoV1wHVkjk3eiO6w7BpcYtyK8LR eUSg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:dkim-signature :arc-authentication-results; bh=f0aL4BCGdrn7qdpjr3AUO2SAaLtCnwWzJmKyuvBkixQ=; b=LU/oGjoa/dbrKfHoqEDHI0MBMDsUqPb1IYafHq5ZHYPdeiETK8/Tnxqq5IAT8wjd5u AKKPYZHDQeR9KHbYBdMu0yNqPTOMkT/ajeDma+iaCBG01wKYVqyLz+pn5/RPOGEdQib7 gK70pDyXgWIdVjz1/cbj8ikOIrH/fsnSmVP18pFmsAkbKcMcBjpeZ0+OeXPxZ8kgAkvO +nqxDv16bLEbO+DfbhoQx0ouqbBqXmu1Q9SvM7Hnvb/C4Hq5VSWMEcvaPan4bxJyvw+u 3bHo5HbfOV4jVpwU1tvxmru6PNJn49k46hupS8WebCiyUucT+2f0dDvKZhdkTSWkIDoQ CeHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eyAc316s; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p67-v6si15694625pfp.72.2018.05.22.06.03.27; Tue, 22 May 2018 06:03:48 -0700 (PDT) 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=@linaro.org header.s=google header.b=eyAc316s; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751532AbeEVNDF (ORCPT + 99 others); Tue, 22 May 2018 09:03:05 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35706 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751503AbeEVNC7 (ORCPT ); Tue, 22 May 2018 09:02:59 -0400 Received: by mail-wm0-f67.google.com with SMTP id o78-v6so33463285wmg.0 for ; Tue, 22 May 2018 06:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=f0aL4BCGdrn7qdpjr3AUO2SAaLtCnwWzJmKyuvBkixQ=; b=eyAc316s4H7CuhcDxOJx4VGGUvwCgGOpcbMRjZZrgwV2UgAo/1GV5b9YpYUhMuaypS VP9LkpgeO2H+BXK8FqvbMoEd5KSdcMLOyEoZsJeZCCD6cZgpZgyoO9iYTr9cfRqbK5ys 3PBlAE0gWfwQY6D19W6djt8Qh2zn+zCNsyG2o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=f0aL4BCGdrn7qdpjr3AUO2SAaLtCnwWzJmKyuvBkixQ=; b=HXjQRqQcackrHRul5cT93N5hOybbtUHZA8vpEpO6/uoZ466S/kEBo61BHE3VWqUAmJ JAc7VRVML/Ks2fevD1yhw/ofiZWgPwiNSk0nz4GTwqX1UsHWaKme5TTmr8peS62xe5Ux LmGiltJqZUNQYUn0R/N+wqzpg6I6RMCl49Iu/e0Z9XNQ+72dlL5sL8uZtKCrkuGId64c Crslhzgs88VocsI5c/pjA6HEq+Z1Nok+IqmDVjs7GB0ri88MLlumE03udGOSoh0TGjNe +DGVD80v7L4sfQXYIdWYTDNLIcQSOW39dHa4QTaTLEsslbfnJUPcdkKD3Q86Aqk1v+j0 krGw== X-Gm-Message-State: ALKqPwcH54aYuLXmp6OUbu5BbZ/dmQ/QAPqwRSLEe7zE4EHZ4r6kGiYC krppqLi5SdyyMfJoYBVaAP21yQ== X-Received: by 2002:a1c:911:: with SMTP id 17-v6mr1059720wmj.5.1526994177369; Tue, 22 May 2018 06:02:57 -0700 (PDT) Received: from [192.168.27.209] ([37.157.136.206]) by smtp.googlemail.com with ESMTPSA id z17-v6sm364280wrm.8.2018.05.22.06.02.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 06:02:56 -0700 (PDT) From: Stanimir Varbanov Subject: Re: [PATCH 4/4] media: venus: add PIL support To: Vikash Garodia , hverkuil@xs4all.nl, mchehab@kernel.org, andy.gross@linaro.org, bjorn.andersson@linaro.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, acourbot@google.com References: <1526556740-25494-1-git-send-email-vgarodia@codeaurora.org> <1526556740-25494-5-git-send-email-vgarodia@codeaurora.org> Message-ID: <3822394c-b304-15c3-c978-ee39589308eb@linaro.org> Date: Tue, 22 May 2018 16:02:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1526556740-25494-5-git-send-email-vgarodia@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vikash, On 05/17/2018 02:32 PM, Vikash Garodia wrote: > This adds support to load the video firmware > and bring ARM9 out of reset. This is useful > for platforms which does not have trustzone > to reset the ARM9. > > Signed-off-by: Vikash Garodia > --- > .../devicetree/bindings/media/qcom,venus.txt | 8 +- > drivers/media/platform/qcom/venus/core.c | 67 +++++++-- > drivers/media/platform/qcom/venus/core.h | 6 + > drivers/media/platform/qcom/venus/firmware.c | 163 +++++++++++++++++---- > drivers/media/platform/qcom/venus/firmware.h | 10 +- > 5 files changed, 217 insertions(+), 37 deletions(-) > > diff --git a/Documentation/devicetree/bindings/media/qcom,venus.txt b/Documentation/devicetree/bindings/media/qcom,venus.txt > index 00d0d1b..0ff0f2d 100644 > --- a/Documentation/devicetree/bindings/media/qcom,venus.txt > +++ b/Documentation/devicetree/bindings/media/qcom,venus.txt for this change in DT binding you have to cc devicetree ML. And probably it could be separate patch. > @@ -53,7 +53,7 @@ > > * Subnodes > The Venus video-codec node must contain two subnodes representing > -video-decoder and video-encoder. > +video-decoder and video-encoder, one optional firmware subnode. > > Every of video-encoder or video-decoder subnode should have: > > @@ -79,6 +79,8 @@ Every of video-encoder or video-decoder subnode should have: > power domain which is responsible for collapsing > and restoring power to the subcore. > > +The firmware sub node must contain the iommus specifiers for ARM9. > + > * An Example > video-codec@1d00000 { > compatible = "qcom,msm8916-venus"; > @@ -105,4 +107,8 @@ Every of video-encoder or video-decoder subnode should have: > clock-names = "core"; > power-domains = <&mmcc VENUS_CORE1_GDSC>; > }; > + firmware { venus-firmware > + compatible = "qcom,venus-pil-no-tz"; this should be following the other subnodes compatible names: compatible = "venus-firmware"; > + iommus = <&apps_smmu 0x10b2 0x0>; > + } > }; > diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c > index 1308488..16910558 100644 > --- a/drivers/media/platform/qcom/venus/core.c > +++ b/drivers/media/platform/qcom/venus/core.c > @@ -22,6 +22,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -30,6 +31,7 @@ > #include "vdec.h" > #include "venc.h" > #include "firmware.h" > +#include "hfi_venus.h" > > static void venus_event_notify(struct venus_core *core, u32 event) > { > @@ -76,7 +78,7 @@ static void venus_sys_error_handler(struct work_struct *work) > hfi_core_deinit(core, true); > hfi_destroy(core); > mutex_lock(&core->lock); > - venus_shutdown(core->dev); > + venus_shutdown(core); > > pm_runtime_put_sync(core->dev); > > @@ -84,7 +86,7 @@ static void venus_sys_error_handler(struct work_struct *work) > > pm_runtime_get_sync(core->dev); > > - ret |= venus_boot(core->dev, core->res->fwname); > + ret |= venus_boot(core); > > ret |= hfi_core_resume(core, true); > > @@ -179,6 +181,20 @@ static u32 to_v4l2_codec_type(u32 codec) > } > } > > +static int store_firmware_dev(struct device *dev, void *data) > +{ > + struct venus_core *core; > + > + core = (struct venus_core *)data; > + if (!core) > + return -EINVAL; > + > + if (of_device_is_compatible(dev->of_node, "qcom,venus-pil-no-tz")) > + core->fw.dev = dev; > + > + return 0; > +} > + > static int venus_enumerate_codecs(struct venus_core *core, u32 type) > { > const struct hfi_inst_ops dummy_ops = {}; > @@ -229,6 +245,7 @@ static int venus_probe(struct platform_device *pdev) > struct device *dev = &pdev->dev; > struct venus_core *core; > struct resource *r; > + struct iommu_domain *iommu_domain; > int ret; > > core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL); > @@ -279,7 +296,14 @@ static int venus_probe(struct platform_device *pdev) > if (ret < 0) > goto err_runtime_disable; > > - ret = venus_boot(dev, core->res->fwname); > + ret = of_platform_populate(dev->of_node, NULL, NULL, dev); > + if (ret) > + goto err_runtime_disable; > + > + /* Attempt to register child devices */ This comment is wrong, the child devices are created by of_platform_populate above. > + ret = device_for_each_child(dev, core, store_firmware_dev); Why we need these complex gymnastics to get struct device pointer when that could be done in venus_firmware .probe method? I think the answer is because you want to avoid having venus-firmware.ko (because you have to have separate struct device for iommu SID). In that case it would be better to make venus-firmware.ko. > + > + ret = venus_boot(core); > if (ret) > goto err_runtime_disable; > > @@ -303,14 +327,17 @@ static int venus_probe(struct platform_device *pdev) > if (ret) > goto err_core_deinit; > > - ret = of_platform_populate(dev->of_node, NULL, NULL, dev); > + ret = pm_runtime_put_sync(dev); > if (ret) > goto err_dev_unregister; > > - ret = pm_runtime_put_sync(dev); > - if (ret) > + iommu_domain = iommu_get_domain_for_dev(dev); > + if (!iommu_domain) > goto err_dev_unregister; > > + iommu_domain->geometry.aperture_start = VENUS_FW_MEM_SIZE; > + iommu_domain->geometry.aperture_end = VENUS_MAX_MEM_REGION; I don't think that is needed for this struct device (Venus DT node struct device). And also why aperture_start is on 6th MB? I think that this iommu domain is for venus_non_secure iommu context_bank. Those geometry parameters are checked/used only from dma-iommu.c. They are checked before entering on venus_probe and only when geometry.force_aperture is true. So updating those params here doesn't make any sense to iommu? > + > return 0; > > err_dev_unregister: > @@ -318,7 +345,7 @@ static int venus_probe(struct platform_device *pdev) > err_core_deinit: > hfi_core_deinit(core, false); > err_venus_shutdown: > - venus_shutdown(dev); > + venus_shutdown(core); > err_runtime_disable: > pm_runtime_set_suspended(dev); > pm_runtime_disable(dev); > @@ -339,7 +366,7 @@ static int venus_remove(struct platform_device *pdev) > WARN_ON(ret); > > hfi_destroy(core); > - venus_shutdown(dev); > + venus_shutdown(core); > of_platform_depopulate(dev); > > pm_runtime_put_sync(dev); > @@ -483,7 +510,29 @@ static __maybe_unused int venus_runtime_resume(struct device *dev) > .pm = &venus_pm_ops, > }, > }; > -module_platform_driver(qcom_venus_driver); > + > +static int __init venus_init(void) > +{ > + int ret; > + > + ret = platform_driver_register(&qcom_video_firmware_driver); > + if (ret) > + return ret; I think that this shouldn't be here, it is clear that firmware loader code should be on separate device/driver (even outside of venus DT node). > + > + ret = platform_driver_register(&qcom_venus_driver); > + if (ret) > + platform_driver_unregister(&qcom_video_firmware_driver); > + > + return ret; > +} > +module_init(venus_init); > + > +static void __exit venus_exit(void) > +{ > + platform_driver_unregister(&qcom_venus_driver); > + platform_driver_unregister(&qcom_video_firmware_driver); > +} > +module_exit(venus_exit); > > MODULE_ALIAS("platform:qcom-venus"); > MODULE_DESCRIPTION("Qualcomm Venus video encoder and decoder driver"); > diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h > index 85e66e2..68fc8af 100644 > --- a/drivers/media/platform/qcom/venus/core.h > +++ b/drivers/media/platform/qcom/venus/core.h > @@ -80,6 +80,11 @@ struct venus_caps { > bool valid; > }; > > +struct video_firmware { > + struct device *dev; > + dma_addr_t iova; > + struct iommu_domain *iommu_domain; > +}; > /** > * struct venus_core - holds core parameters valid for all instances > * > @@ -124,6 +129,7 @@ struct venus_core { > struct device *dev; > struct device *dev_dec; > struct device *dev_enc; > + struct video_firmware fw; > struct mutex lock; > struct list_head instances; > atomic_t insts_count; > diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c > index 8f25375..614c805 100644 > --- a/drivers/media/platform/qcom/venus/firmware.c > +++ b/drivers/media/platform/qcom/venus/firmware.c > @@ -12,8 +12,12 @@ > * > */ > > +#include > +#include > +#include > #include > #include > +#include > #include > #include > #include > @@ -27,8 +31,10 @@ > #include "firmware.h" > #include "hfi_venus_io.h" > > -#define VENUS_PAS_ID 9 > -#define VENUS_FW_MEM_SIZE (6 * SZ_1M) > +static const struct of_device_id firmware_dt_match[] = { > + { .compatible = "qcom,venus-pil-no-tz" }, > + { } > +}; > > void venus_reset_hw(struct venus_core *core) > { > @@ -53,40 +59,37 @@ void venus_reset_hw(struct venus_core *core) > /* Bring Arm9 out of reset */ > writel_relaxed(0, reg_base + WRAPPER_A9SS_SW_RESET); > } > -int venus_boot(struct device *dev, const char *fwname) > +EXPORT_SYMBOL_GPL(venus_reset_hw); > + > +int venus_load_fw(struct device *dev, const char *fwname, > + phys_addr_t *mem_phys, size_t *mem_size) > { > const struct firmware *mdt; > struct device_node *node; > - phys_addr_t mem_phys; > struct resource r; > ssize_t fw_size; > - size_t mem_size; > void *mem_va; > int ret; > > - if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) || !qcom_scm_is_available()) > - return -EPROBE_DEFER; > - > node = of_parse_phandle(dev->of_node, "memory-region", 0); > if (!node) { > dev_err(dev, "no memory-region specified\n"); > return -EINVAL; > } > - > ret = of_address_to_resource(node, 0, &r); > if (ret) > return ret; > > - mem_phys = r.start; > - mem_size = resource_size(&r); > + *mem_phys = r.start; > + *mem_size = resource_size(&r); > > - if (mem_size < VENUS_FW_MEM_SIZE) > + if (*mem_size < VENUS_FW_MEM_SIZE) > return -EINVAL; > > - mem_va = memremap(r.start, mem_size, MEMREMAP_WC); > + mem_va = memremap(r.start, *mem_size, MEMREMAP_WC); > if (!mem_va) { > dev_err(dev, "unable to map memory region: %pa+%zx\n", > - &r.start, mem_size); > + &r.start, *mem_size); > return -ENOMEM; > } > > @@ -101,24 +104,134 @@ int venus_boot(struct device *dev, const char *fwname) > goto err_unmap; > } > > - ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID, mem_va, mem_phys, > - mem_size, NULL); > + ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID, mem_va, *mem_phys, > + *mem_size, NULL); > > release_firmware(mdt); > > - if (ret) > - goto err_unmap; > - > - ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID); > - if (ret) > - goto err_unmap; > - > err_unmap: > memunmap(mem_va); > return ret; > } > > -int venus_shutdown(struct device *dev) > +int venus_boot_noTZ(struct venus_core *core, phys_addr_t mem_phys, > + size_t mem_size) > { > - return qcom_scm_pas_shutdown(VENUS_PAS_ID); > + struct iommu_domain *iommu; > + struct device *dev; > + int ret; > + > + if (!core->fw.dev) > + return -EPROBE_DEFER; > + > + dev = core->fw.dev; > + > + iommu = iommu_domain_alloc(&platform_bus_type); > + if (!iommu) { > + dev_err(dev, "Failed to allocate iommu domain\n"); > + return -ENOMEM; > + } > + > + iommu->geometry.aperture_start = 0x0; > + iommu->geometry.aperture_end = VENUS_FW_MEM_SIZE; The same comment for geometry params as for venus_probe is valid here. > + > + ret = iommu_attach_device(iommu, dev); > + if (ret) { > + dev_err(dev, "could not attach device\n"); > + goto err_attach; > + } > + > + ret = iommu_map(iommu, core->fw.iova, mem_phys, mem_size, > + IOMMU_READ|IOMMU_WRITE|IOMMU_PRIV); iova is not initialized and is zero, maybe we don't need that variable in the venus_firmware structure? > + if (ret) { > + dev_err(dev, "could not map video firmware region\n"); > + goto err_map; > + } > + core->fw.iommu_domain = iommu; > + venus_reset_hw(core); > + > + return 0; > + > +err_map: > + iommu_detach_device(iommu, dev); > +err_attach: > + iommu_domain_free(iommu); > + return ret; > } > + > +int venus_shutdown_noTZ(struct venus_core *core) > +{ > + struct iommu_domain *iommu; > + u32 reg; > + struct device *dev = core->fw.dev; > + void __iomem *reg_base = core->base; > + > + /* Assert the reset to ARM9 */ > + reg = readl_relaxed(reg_base + WRAPPER_A9SS_SW_RESET); > + reg |= BIT(4); > + writel_relaxed(reg, reg_base + WRAPPER_A9SS_SW_RESET); > + > + /* Make sure reset is asserted before the mapping is removed */ > + mb(); > + > + iommu = core->fw.iommu_domain; > + > + iommu_unmap(iommu, core->fw.iova, VENUS_FW_MEM_SIZE); > + iommu_detach_device(iommu, dev); > + iommu_domain_free(iommu); check iommu APIs for errors. -- regards, Stan