Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1003789imm; Fri, 1 Jun 2018 13:28:09 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIaBHVnnwRUeDCpyxQ01ty1WKfMirc6KyXFuJg/igwKwb7PN/XOe/NHljuk5Kr8W1v4s8TX X-Received: by 2002:a17:902:7688:: with SMTP id m8-v6mr9420028pll.54.1527884889506; Fri, 01 Jun 2018 13:28:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527884889; cv=none; d=google.com; s=arc-20160816; b=fK8f4RAlnIno18u00grS+DtH+VgwLH+2gKqt0KzDEQM0CGdGTyw31u1Mt52B5sYqqb NDjJDVrULDARy1pS7YzBvMImUTea45h/LntCUMm3okTqKSUbrrPzFJbvOSHMYPFRy0gu 774WNffeUw9ly8rYyHcgLiIapQAH3gx1mvzf2bWGXn/cjtm2o7BOgAWV3vgbfzw73y83 9BYQU0Mm3+N2/I7qnBNXWMiZsLiyqNKIpxgRjeAhOaudqEgniFD6ilNbEFKA13FqU2EQ oKnn1VlKAMU2BFP+/VqvaDg64OmiXoTxeAnazOU8NEnplqddcOuhxwXXzhNr+hXqz/kR EgtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=ubxJZwDQOjHjLqKiIWTmBtcQBzupvsaa0BFJifRaNUs=; b=HXvhPu0dHLCL4RDpxZRt6UpKjckeO0hCIA008HTKijW8yryzM9nD+6mLGCoh+6c7Hr ImTEtc5GnFrOP2mgy/nitSjnwS1V5nTQ4X5M3LWlx3wb80J5Czb4Bd+hGghuRq85lYHE nQ5ZtkLURNVmQ1mK3V8ClNAmvDQTptG9tAMKtX+PX9vtlquNMX2kYdhyTHqx28CMa+6x oYlszzgeVI6GiCAhEOD4FXmmG4Dw01Wlgzy5XDWBowTXMSuHGXyWUSrw8dY3nHfHmwep vd+tPr+NRpVWvKYS9pX5bC5Cw5SggU8yL4Aj86GJlg8vTQqgVSWVEw2FUawwgtrfDvzd i4IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=FcF7c6P1; dkim=pass header.i=@codeaurora.org header.s=default header.b=RRJUAmrx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i133-v6si14225873pgc.351.2018.06.01.13.27.55; Fri, 01 Jun 2018 13:28:09 -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=@codeaurora.org header.s=default header.b=FcF7c6P1; dkim=pass header.i=@codeaurora.org header.s=default header.b=RRJUAmrx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753688AbeFAU1N (ORCPT + 99 others); Fri, 1 Jun 2018 16:27:13 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54730 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753652AbeFAU1H (ORCPT ); Fri, 1 Jun 2018 16:27:07 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 166336075A; Fri, 1 Jun 2018 20:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527884827; bh=UXTb8u92fUryjw0YRAYEA4l9/QgFinMkwYeTIqJg9Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FcF7c6P1FFuwVgZJKo39/csdD07ejxutUmrKxemHt/dGyEqZVz4CX1wileocZf4Fp 1B0eXHYVjbssXgqhlO9XQXvPW+CQHZeXnQ4klMIIRclSBzQHP2q/FOP2zTXoQ3g8s4 y/3BWoAmKZvvepeno2YHbTTPZM4Tar6Ef8jvJHXI= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from vgarodia-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vgarodia@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 11E1A60795; Fri, 1 Jun 2018 20:26:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527884822; bh=UXTb8u92fUryjw0YRAYEA4l9/QgFinMkwYeTIqJg9Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RRJUAmrxkT0Mw/6XQusJpnG9EMojBE+MyU5q0EylUdFTwFST/TdvVnd+LQHYAZhWr uKLF/nk2Ziyddr/NtfSLnGatXKfBWwJCxVRixF3oiZzLC9GS8kVL3IxhlMz3VXijrF kB+ntLPDOOJN/WcWqmTh3qClrZsWXw29/jIDLKSA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 11E1A60795 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vgarodia@codeaurora.org From: Vikash Garodia To: hverkuil@xs4all.nl, mchehab@kernel.org, robh@kernel.org, mark.rutland@arm.com, andy.gross@linaro.org, bjorn.andersson@linaro.org, stanimir.varbanov@linaro.org Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, devicetree@vger.kernel.org, vgarodia@codeaurora.org, acourbot@chromium.org Subject: [PATCH v2 4/5] media: venus: add no TZ boot and shutdown routine Date: Sat, 2 Jun 2018 01:56:07 +0530 Message-Id: <1527884768-22392-5-git-send-email-vgarodia@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527884768-22392-1-git-send-email-vgarodia@codeaurora.org> References: <1527884768-22392-1-git-send-email-vgarodia@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Video hardware is mainly comprised of vcodec subsystem and video control subsystem. Video control has ARM9 which executes the video firmware instructions whereas vcodec does the video frame processing. This change adds support to load the video firmware and bring ARM9 out of reset for platforms which does not have trustzone. Signed-off-by: Vikash Garodia --- drivers/media/platform/qcom/venus/core.c | 6 +- drivers/media/platform/qcom/venus/core.h | 5 ++ drivers/media/platform/qcom/venus/firmware.c | 86 ++++++++++++++++++++++++++-- drivers/media/platform/qcom/venus/firmware.h | 7 ++- 4 files changed, 94 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 9a95f9a..101612b 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -76,7 +76,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); @@ -318,7 +318,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 +339,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); diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index e7bfb63..f04e25e 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -85,6 +85,10 @@ struct venus_caps { bool valid; }; +struct video_firmware { + struct device *dev; + struct iommu_domain *iommu_domain; +}; /** * struct venus_core - holds core parameters valid for all instances * @@ -129,6 +133,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 cb7f48ef..058d544 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -12,8 +12,10 @@ * */ +#include #include #include +#include #include #include #include @@ -27,9 +29,6 @@ #include "firmware.h" #include "hfi_venus_io.h" -#define VENUS_PAS_ID 9 -#define VENUS_FW_MEM_SIZE (6 * SZ_1M) - static void venus_reset_hw(struct venus_core *core) { void __iomem *reg_base = core->base; @@ -125,7 +124,7 @@ static int venus_load_fw(struct device *dev, const char *fwname, } if (qcom_scm_is_available()) ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID, mem_va, - *mem_phys, *mem_size, NULL); + *mem_phys, *mem_size); else ret = qcom_mdt_load_no_init(dev, mdt, fwname, VENUS_PAS_ID, mem_va, *mem_phys, *mem_size, NULL); @@ -136,6 +135,77 @@ static int venus_load_fw(struct device *dev, const char *fwname, memunmap(mem_va); return ret; } + +int venus_boot_noTZ(struct venus_core *core, phys_addr_t mem_phys, + size_t mem_size) +{ + 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; + } + + ret = iommu_attach_device(iommu, dev); + if (ret) { + dev_err(dev, "could not attach device\n"); + goto err_attach; + } + + ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size, + IOMMU_READ|IOMMU_WRITE|IOMMU_PRIV); + 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; + size_t unmapped = 0; + 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; + + unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, VENUS_FW_MEM_SIZE); + if (unmapped != VENUS_FW_MEM_SIZE) + dev_err(dev, "failed to unmap firmware\n"); + + iommu_detach_device(iommu, dev); + iommu_domain_free(iommu); + + return 0; +} + int venus_boot(struct venus_core *core) { phys_addr_t mem_phys; @@ -156,16 +226,20 @@ int venus_boot(struct venus_core *core) if (qcom_scm_is_available()) ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID); + else + ret = venus_boot_noTZ(core, mem_phys, mem_size); return ret; } -EXPORT_SYMBOL_GPL(venus_boot); -int venus_shutdown(struct device *dev) +int venus_shutdown(struct venus_core *core) { int ret = 0; if (qcom_scm_is_available()) ret = qcom_scm_pas_shutdown(VENUS_PAS_ID); + else + ret = venus_shutdown_noTZ(core); + return ret; } diff --git a/drivers/media/platform/qcom/venus/firmware.h b/drivers/media/platform/qcom/venus/firmware.h index 0916826..67fdd89 100644 --- a/drivers/media/platform/qcom/venus/firmware.h +++ b/drivers/media/platform/qcom/venus/firmware.h @@ -14,10 +14,15 @@ #ifndef __VENUS_FIRMWARE_H__ #define __VENUS_FIRMWARE_H__ +#define VENUS_PAS_ID 9 +#define VENUS_FW_START_ADDR 0x0 +#define VENUS_FW_MEM_SIZE (6 * SZ_1M) +#define VENUS_MAX_MEM_REGION 0xE0000000 + struct device; int venus_boot(struct venus_core *core); -int venus_shutdown(struct device *dev); +int venus_shutdown(struct venus_core *core); int venus_set_hw_state(enum tzbsp_video_state, struct venus_core *core); #endif -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project