Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5744084imm; Tue, 18 Sep 2018 15:00:57 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYenOx2f1MpiQagiAsDJrgiRwkl878W4/v8xxPYESW0st1iLaYlX0doFCQLV0Wm6tGfTnWV X-Received: by 2002:a63:610:: with SMTP id 16-v6mr28978646pgg.96.1537308057731; Tue, 18 Sep 2018 15:00:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537308057; cv=none; d=google.com; s=arc-20160816; b=YEevmvoq6OUKWKcAew+OMjq7W9IaBWuooXcgh0tlHNcAuQjfpEg/x+FUEu1HOTb7qD /7DuCE6vaoE5bS1z+T16ET7H2NF/f+fLunSRaprkOZdFdG6YLkbNab8/XaNtYqX82KFu 3Rc2PZoeHuE6eh4TRaBUcW869iB+qASX1JayGSCmjDj96ZP3azuN/KO2bcAvjK/EAkaH TsN4O3M1iIYtvFgQ56I7Dxz8zryLvDCDkRA/8I2N1tXrLFis3lxRJgTQv2kL7cO7r5zC oNeyD0abN+OXTVuQP/BrpQ8vhnL5KmpqPG8iEfEQCv7HoOI2p8y0rMJHthZrcMM4kdDc yzdQ== 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; bh=8VA93GgmL7Q+p185VanFhNufh9EHlYmK59rdHOSgNdo=; b=D9HsFvmGi67dyfHO1CO3Y8+SgANrobCtBNsatBKMfchz9sKQwoncddTlnbeR+GuhlT 1O209iE07kdoIm5wNLzCjxSFIUrrOBIFiHr+IEm1Jm2wrpvmPHH3bHJL6XPfjtnNCDIw gm6GOTJIZNmtqKrDDRP9kQtq+zLYA/7jql2TyPT7Rg1nwdKZ323wob1Von1dJ7CwzRuD 5ahcxCqf2xT7qpcR5ut55W1jg5sQXfGijl1j4mnFiTt7unf+Nc+bapTO4W+/VS58P/v4 MWTEqLcVeSjIV28WpXvbuEWtwpGVOK/YIP2jiFV7ImhcIHGbbar/UzPOGc1mf4aF8hDj D/6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=mWYtC15n; dkim=pass header.i=@codeaurora.org header.s=default header.b=QFkpo5va; 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 gn12si19134108plb.147.2018.09.18.15.00.42; Tue, 18 Sep 2018 15:00:57 -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=mWYtC15n; dkim=pass header.i=@codeaurora.org header.s=default header.b=QFkpo5va; 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 S1730746AbeISDel (ORCPT + 99 others); Tue, 18 Sep 2018 23:34:41 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:47138 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730260AbeISDek (ORCPT ); Tue, 18 Sep 2018 23:34:40 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 974AB607F4; Tue, 18 Sep 2018 22:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1537308002; bh=WtzHi7H25SJ0cJr/VYkNoStYNCO3AIb6PsDbgolddc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mWYtC15nKqXkDzy1B2pw8LADpvzi0sTtiA2KsBJJU/ty8ETeNn5E1mfYAI434qBVv CjLiDR3AcP/KmeksSO7dapFUz8gXgte3ImYsJE0bM6okS+nQOrEjWOQ+OTVoowrj4P s3mbuh8bK7RHsQjMlsvPaK/Qdz0ajkiS9/ZMYNes= 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 84EE660C6C; Tue, 18 Sep 2018 21:59:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1537307999; bh=WtzHi7H25SJ0cJr/VYkNoStYNCO3AIb6PsDbgolddc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QFkpo5vai4F2YXfcv8zPYLknb8/BAnGORfRA9DAQVMxhAH5/4WbwNH42HIqXMO8Km +gDM7dA9dm4JLnTUBgHfFaCdhSceBaD60SFODDxTr6ScBWtkAjQAVXMPXysmgWI7Z5 OzIwUM9ytVrLyxFLvChm/FyYrKkvFkGQsE2L/SII= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 84EE660C6C 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: stanimir.varbanov@linaro.org, hverkuil@xs4all.nl, mchehab@kernel.org, robh@kernel.org, mark.rutland@arm.com, andy.gross@linaro.org, arnd@arndb.de, 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, devicetree@vger.kernel.org, acourbot@chromium.org, vgarodia@codeaurora.org Subject: [PATCH v8 4/5] venus: firmware: add no TZ boot and shutdown routine Date: Wed, 19 Sep 2018 03:29:12 +0530 Message-Id: <1537307954-9729-5-git-send-email-vgarodia@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1537307954-9729-1-git-send-email-vgarodia@codeaurora.org> References: <1537307954-9729-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. An iommu domain is associated and managed with the firmware device. Signed-off-by: Vikash Garodia --- drivers/media/platform/qcom/venus/core.c | 6 +- drivers/media/platform/qcom/venus/core.h | 1 + drivers/media/platform/qcom/venus/firmware.c | 96 +++++++++++++++++++++++- drivers/media/platform/qcom/venus/firmware.h | 2 +- drivers/media/platform/qcom/venus/hfi_venus_io.h | 1 + 5 files changed, 98 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 440f25f..3bd3b8a 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); @@ -327,7 +327,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); @@ -348,7 +348,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); venus_firmware_deinit(core); diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 6f2c82d..baaa1cc 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -132,6 +132,7 @@ struct venus_core { struct device *dev_enc; struct video_firmware { struct device *dev; + struct iommu_domain *iommu_domain; } fw; bool no_tz; struct mutex lock; diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index a251707..3cf9313 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,56 @@ static int venus_load_fw(struct venus_core *core, const char *fwname, return ret; } +static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys, + size_t mem_size) +{ + struct iommu_domain *iommu; + struct device *dev; + int ret; + + dev = core->fw.dev; + if (!dev) + return -EPROBE_DEFER; + + iommu = core->fw.iommu_domain; + + 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"); + return ret; + } + + venus_reset_cpu(core); + + return 0; +} + +static int venus_shutdown_no_tz(struct venus_core *core) +{ + struct iommu_domain *iommu; + size_t unmapped; + u32 reg; + struct device *dev = core->fw.dev; + void __iomem *base = core->base; + + /* Assert the reset to ARM9 */ + reg = readl_relaxed(base + WRAPPER_A9SS_SW_RESET); + reg |= WRAPPER_A9SS_SW_RESET_BIT; + writel_relaxed(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"); + + return 0; +} + int venus_boot(struct venus_core *core) { struct device *dev = core->dev; @@ -139,17 +190,30 @@ int venus_boot(struct venus_core *core) return -EINVAL; } - return qcom_scm_pas_auth_and_reset(VENUS_PAS_ID); + if (core->no_tz) + ret = venus_boot_no_tz(core, mem_phys, mem_size); + else + ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID); + + return ret; } -int venus_shutdown(struct device *dev) +int venus_shutdown(struct venus_core *core) { - return qcom_scm_pas_shutdown(VENUS_PAS_ID); + int ret; + + if (core->no_tz) + ret = venus_shutdown_no_tz(core); + else + ret = qcom_scm_pas_shutdown(VENUS_PAS_ID); + + return ret; } int venus_firmware_init(struct venus_core *core) { struct platform_device_info info; + struct iommu_domain *iommu_dom; struct platform_device *pdev; struct device_node *np; int ret; @@ -172,19 +236,36 @@ int venus_firmware_init(struct venus_core *core) pdev->dev.of_node = np; - ret = of_dma_configure(&pdev->dev, np); + ret = of_dma_configure(&pdev->dev, np, true); if (ret) { dev_err(core->dev, "dma configure fail\n"); goto err_unregister; } core->fw.dev = &pdev->dev; + + iommu_dom = iommu_domain_alloc(&platform_bus_type); + if (!iommu_dom) { + dev_err(core->fw.dev, "Failed to allocate iommu domain\n"); + ret = -ENOMEM; + goto err_unregister; + } + + ret = iommu_attach_device(iommu_dom, core->fw.dev); + if (ret) { + dev_err(core->fw.dev, "could not attach device\n"); + goto err_iommu_free; + } + core->no_tz = true; + core->fw.iommu_domain = iommu_dom; of_node_put(np); return 0; +err_iommu_free: + iommu_domain_free(iommu_dom); err_unregister: platform_device_unregister(pdev); of_node_put(np); @@ -193,8 +274,15 @@ int venus_firmware_init(struct venus_core *core) void venus_firmware_deinit(struct venus_core *core) { + struct iommu_domain *iommu; + if (!core->fw.dev) return; + iommu = core->fw.iommu_domain; + + iommu_detach_device(iommu, core->fw.dev); + iommu_domain_free(iommu); + platform_device_unregister(to_platform_device(core->fw.dev)); } diff --git a/drivers/media/platform/qcom/venus/firmware.h b/drivers/media/platform/qcom/venus/firmware.h index fd7edf0..119a9a4 100644 --- a/drivers/media/platform/qcom/venus/firmware.h +++ b/drivers/media/platform/qcom/venus/firmware.h @@ -19,7 +19,7 @@ int venus_firmware_init(struct venus_core *core); void venus_firmware_deinit(struct venus_core *core); 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(struct venus_core *core, bool suspend); static inline int venus_set_hw_state_suspend(struct venus_core *core) diff --git a/drivers/media/platform/qcom/venus/hfi_venus_io.h b/drivers/media/platform/qcom/venus/hfi_venus_io.h index d69f51b..ef0c72a 100644 --- a/drivers/media/platform/qcom/venus/hfi_venus_io.h +++ b/drivers/media/platform/qcom/venus/hfi_venus_io.h @@ -119,6 +119,7 @@ #define WRAPPER_NONPIX_START_ADDR (WRAPPER_BASE + 0x1030) #define WRAPPER_NONPIX_END_ADDR (WRAPPER_BASE + 0x1034) #define WRAPPER_A9SS_SW_RESET (WRAPPER_BASE + 0x3000) +#define WRAPPER_A9SS_SW_RESET_BIT BIT(4) /* Venus 4xx */ #define WRAPPER_VCODEC0_MMCC_POWER_STATUS (WRAPPER_BASE + 0x90) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project