From patchwork Mon Aug 17 08:27:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 250645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 651DCC433E4 for ; Mon, 17 Aug 2020 08:28:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43EBB20658 for ; Mon, 17 Aug 2020 08:28:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="I1AE04mm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728105AbgHQI2R (ORCPT ); Mon, 17 Aug 2020 04:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728509AbgHQI1u (ORCPT ); Mon, 17 Aug 2020 04:27:50 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C4F1C061344 for ; Mon, 17 Aug 2020 01:27:49 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id d190so12517282wmd.4 for ; Mon, 17 Aug 2020 01:27:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dHHx8tCCD/f7cY2UrgoF5DI2HEp6u7sbKILLzlEPxJo=; b=I1AE04mm3Cu7IVOIi8qpjZg6MCi5n70hUykAwGaeJFE7bwTb1gQIAVIHzAEv+Y5Omw RgkVQw4b5L5iE8LKIL7w01TK18n0Ok1yjMshCjuYyWy0LDrw0ZsaQo8TfFAmVNpxY1tH Jm+2/+r+1CQygJMbY13/L1uQGIz5EhYgNSN3Il0PbNQnO13KFO4TlExBROgkRBXhTCJF joeA2bowB5XNZJKTSt/puj/2resoPZsPs33XpWLXO0gzTkPQoMru2iaMbszx+kjWKAwe vx/b2t17P5kYM0HlbPra4N5Pxr/TZ/Do62wZQDPDy1P1yYu2JTZAAMWYEKaS4Pv9d6hH DWgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dHHx8tCCD/f7cY2UrgoF5DI2HEp6u7sbKILLzlEPxJo=; b=f+4lWLsH0hnkRPo4BbPMFUg8tZ4R/4AcGYvV3D9woN0dXTUin6O7ksCnk1dtUK/t2n oiqd2dyAhbTcJZQ9A8VPppcTe4eDy41hOWBK5lUk/HmI0r6I6JISdhrsTsngdqApnEF+ mHJNRT4Ne36W+akLa94mKJJ3/jjx2+tLgYA0OuNv6LXSxU5RzvOaPMBqmhqH8XfU9mAX QRdCHEqP24s6e97CgmEKl016Yy03JRfD55Llv+fQLZsZ2F+WRoO2fHP2Pab4ruxnJBYt HeBjLjuJ5fiHmotNKPXi4UYF1DOSTioXELPA4QlA/NLnXbUyYU1FhoZkLNP59WUSMPki EUkg== X-Gm-Message-State: AOAM531aY2La4w3wjkHqGYNh4sXd9I7pyUNB7d7fNF/eJZaWc1iU+mYf 2r9023hA8BKjQBgRVswlbAYbUD0UP4HMwMrl X-Google-Smtp-Source: ABdhPJygsWhnExsJ/xP1fb11YBvOMxcj7El2Fr8xMQQ66XknjoVoYJbBPz4hWT/idFpM2qhQ3mVQ2A== X-Received: by 2002:a05:600c:202:: with SMTP id 2mr12754388wmi.147.1597652868062; Mon, 17 Aug 2020 01:27:48 -0700 (PDT) Received: from localhost.localdomain ([195.24.90.54]) by smtp.gmail.com with ESMTPSA id h5sm33270888wrc.97.2020.08.17.01.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 01:27:47 -0700 (PDT) From: Stanimir Varbanov To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Elliot Berman , Andy Gross , Bjorn Andersson , Stanimir Varbanov Subject: [PATCH v2 1/2] firmware: qcom_scm: Add memory protect virtual address ranges Date: Mon, 17 Aug 2020 11:27:22 +0300 Message-Id: <20200817082723.17458-2-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200817082723.17458-1-stanimir.varbanov@linaro.org> References: <20200817082723.17458-1-stanimir.varbanov@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This adds a new SCM memprotect command to set virtual address ranges. Signed-off-by: Stanimir Varbanov Acked-by: Bjorn Andersson --- drivers/firmware/qcom_scm.c | 24 ++++++++++++++++++++++++ drivers/firmware/qcom_scm.h | 1 + include/linux/qcom_scm.h | 8 +++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c index 0e7233a20f34..dec8dc42a6bc 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -757,6 +757,30 @@ int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) } EXPORT_SYMBOL(qcom_scm_iommu_secure_ptbl_init); +int qcom_scm_mem_protect_video_var(u32 cp_start, u32 cp_size, + u32 cp_nonpixel_start, + u32 cp_nonpixel_size) +{ + int ret; + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_VIDEO_VAR, + .arginfo = QCOM_SCM_ARGS(4, QCOM_SCM_VAL, QCOM_SCM_VAL, + QCOM_SCM_VAL, QCOM_SCM_VAL), + .args[0] = cp_start, + .args[1] = cp_size, + .args[2] = cp_nonpixel_start, + .args[3] = cp_nonpixel_size, + .owner = ARM_SMCCC_OWNER_SIP, + }; + struct qcom_scm_res res; + + ret = qcom_scm_call(__scm->dev, &desc, &res); + + return ret ? : res.result[0]; +} +EXPORT_SYMBOL(qcom_scm_mem_protect_video_var); + static int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region, size_t mem_sz, phys_addr_t src, size_t src_sz, phys_addr_t dest, size_t dest_sz) diff --git a/drivers/firmware/qcom_scm.h b/drivers/firmware/qcom_scm.h index d9ed670da222..14da834ac593 100644 --- a/drivers/firmware/qcom_scm.h +++ b/drivers/firmware/qcom_scm.h @@ -97,6 +97,7 @@ extern int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc, #define QCOM_SCM_MP_RESTORE_SEC_CFG 0x02 #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_SIZE 0x03 #define QCOM_SCM_MP_IOMMU_SECURE_PTBL_INIT 0x04 +#define QCOM_SCM_MP_VIDEO_VAR 0x08 #define QCOM_SCM_MP_ASSIGN 0x16 #define QCOM_SCM_SVC_OCMEM 0x0f diff --git a/include/linux/qcom_scm.h b/include/linux/qcom_scm.h index 3d6a24697761..ba45537f688b 100644 --- a/include/linux/qcom_scm.h +++ b/include/linux/qcom_scm.h @@ -77,11 +77,13 @@ extern bool qcom_scm_restore_sec_cfg_available(void); extern int qcom_scm_restore_sec_cfg(u32 device_id, u32 spare); extern int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size); extern int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare); +extern int qcom_scm_mem_protect_video_var(u32 cp_start, u32 cp_size, + u32 cp_nonpixel_start, + u32 cp_nonpixel_size); extern int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, unsigned int *src, const struct qcom_scm_vmperm *newvm, unsigned int dest_cnt); - extern bool qcom_scm_ocmem_lock_available(void); extern int qcom_scm_ocmem_lock(enum qcom_scm_ocmem_client id, u32 offset, u32 size, u32 mode); @@ -128,6 +130,10 @@ static inline int qcom_scm_iommu_secure_ptbl_size(u32 spare, size_t *size) { return -ENODEV; } static inline int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) { return -ENODEV; } +extern inline int qcom_scm_mem_protect_video_var(u32 cp_start, u32 cp_size, + u32 cp_nonpixel_start, + u32 cp_nonpixel_size) + { return -ENODEV; } static inline int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, unsigned int *src, const struct qcom_scm_vmperm *newvm, unsigned int dest_cnt) { return -ENODEV; } From patchwork Mon Aug 17 08:27:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 247782 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp2433177ilo; Mon, 17 Aug 2020 01:28:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2Wio11Mq4y/VnhKBLxPrfOfTGFd3KWvoqAQh4DifFHfzuPS3Loc2reV7P0wVED8YwTRI7 X-Received: by 2002:a17:906:1f15:: with SMTP id w21mr13609785ejj.152.1597652899087; Mon, 17 Aug 2020 01:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597652899; cv=none; d=google.com; s=arc-20160816; b=MGXgIp8/54PLQuqC6cuiSxnTCwXiLPTdu3r8mNVnwYHWiVgWKWXtz5SzP1q1CGbO6Z 2cMrvsZHfbWmXsLkRegFfYzgGCDCZ9YHqFLiDQ7tS00UFQwkjc6Qrlf0tGNIb7SOCmmS XeQhyk4ZVHeK9Lmc+Q0Xt2im8wTxnlEZt2188IN5lIB6S1vBLQ/6wAHVip0i4VmFFOvN tyXawlwdrNXfxh+OghgBF8S16WVMhLKRSsnmaiW6ST0gmqBQXGYLS9v7us/GJHUm2edc RGG7o4Bpq8/gYIsSatyAf/JWZ0ImlsweijbkOaILlqn/7z2zhwcM+H3RNz5+tKpnwS+Z f7Gw== 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:dkim-signature; bh=zcfJN5PzuB9k5TgpYnzCkxNELSw0Z0tfL9cbkN0RIAE=; b=UleRGLdvnP7ilowtPWH1EU96t+bhxuRP4YMwt98bf1ybuycmHKXqpfulyXugaY8k7+ ihFyi1yl8/TVksrFou8Zi642nsYTYqpH3RtOGJDmkNODQWAnGiclj7asfVBloUbYj/fS yw4ckVFbUqdqb7XE+CfiPyvivAPxfOTPsRVYDEoVbffxYCTUaJ+ZtDBnv2QV1Fw4+vcj qji2ymXddX3gOePLqcjVt9HZ64jsn6/Gg/YqfcVmJo/4JcTFMSy41RUT6XYGeL81WlQ2 pApd6FjpPUc9MXsA4uFpILjq56mFKNhSQ7HRZRuSW9GKA8Umb/eezEyiYyumqEOhlhcl ByeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fjZxmbWL; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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. [23.128.96.18]) by mx.google.com with ESMTP id p6si10558322ejd.617.2020.08.17.01.28.18; Mon, 17 Aug 2020 01:28:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-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=@linaro.org header.s=google header.b=fjZxmbWL; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S1728216AbgHQI2R (ORCPT + 15 others); Mon, 17 Aug 2020 04:28:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728179AbgHQI1w (ORCPT ); Mon, 17 Aug 2020 04:27:52 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C176C061347 for ; Mon, 17 Aug 2020 01:27:52 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 184so13175887wmb.0 for ; Mon, 17 Aug 2020 01:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zcfJN5PzuB9k5TgpYnzCkxNELSw0Z0tfL9cbkN0RIAE=; b=fjZxmbWLVWfR0iLLGuf/88YpQ0F2ZWyj7hbPvHooli1oXIM6NFVLeWiKy4eFCCf3R6 HlhMr6GJD25u01TrOyorJfS+sRXj3vuQWiTv92F6rd5H47VJ/+1GAel98ubeckHKxs8t +4n6xG+DWmYKXWf7C6skUSR5clsn/GzFBH9yij4am2tu+0Xh5G24UnQr2zAMgGsMA7po UVAN8vRgdfnxCppv2Kc8DQGr2XDlXVlPk7zTfFlM+8ZyHNOSVlaTLadlJKLuNi/Dbh/R cKOvVIiuiu12B1dFUu0ajdGrIXLIhK7OUW3asQ7OQklM/RwlNDmoYD8BQ9QfxUr5gEi9 sfKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zcfJN5PzuB9k5TgpYnzCkxNELSw0Z0tfL9cbkN0RIAE=; b=Z5X2vFCQpiVUvrjo0Xd+sV3BixK5V03nEqTBgPupNnCD16CcbefU7mR14oAXaTbJ02 z7d+0tYD0sZbRdS2URLHyvYnDqoOuGfK3XfcZbfkRTJeJYyjiRlkVYDEl+S87jZuXb2P 9yAXRosne0e4Pr0pvNjnw46uIB6Zxab9IeVHnN5BBoAmZHywiZlMnGefIfJq8Bj+Rrv4 da3fM8tTsfOsnImk/HcB+WAmiTcWQRXcun9x1TaZY2XyTTEzd2mJz/xztm3M+hLcMVwK 1H5Ekg8vQxX9wTCTttmgDTBI+fvN/IouTji1CsgNt8XSyOsIHytyt9+96gVr0fWcgiV6 XOeg== X-Gm-Message-State: AOAM5319QhJjgw64oEwhqHAjwHRMm0rGecLaA4IKU2CyuPHd0D/CoNiJ CoC15OlOvqdpwwf4tIPXcbrWzkeBC1FiCrOQ X-Received: by 2002:a1c:bcd6:: with SMTP id m205mr13252078wmf.47.1597652870880; Mon, 17 Aug 2020 01:27:50 -0700 (PDT) Received: from localhost.localdomain ([195.24.90.54]) by smtp.gmail.com with ESMTPSA id h5sm33270888wrc.97.2020.08.17.01.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 01:27:50 -0700 (PDT) From: Stanimir Varbanov To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Elliot Berman , Andy Gross , Bjorn Andersson , Stanimir Varbanov Subject: [PATCH v2 2/2] venus: firmware: Set virtual address ranges Date: Mon, 17 Aug 2020 11:27:23 +0300 Message-Id: <20200817082723.17458-3-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200817082723.17458-1-stanimir.varbanov@linaro.org> References: <20200817082723.17458-1-stanimir.varbanov@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org In order to boot some of the new Venus firmware versions TZ call to set virtual address ranges is needed. Add virtual address ranges for CP and CP_NONPIX in resource structure and use them when loading and booting the firmware on remote processor. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/core.c | 4 ++++ drivers/media/platform/qcom/venus/core.h | 4 ++++ drivers/media/platform/qcom/venus/firmware.c | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c index 203c6538044f..5f8f7b72731c 100644 --- a/drivers/media/platform/qcom/venus/core.c +++ b/drivers/media/platform/qcom/venus/core.c @@ -527,6 +527,10 @@ static const struct venus_resources sdm845_res_v2 = { .vmem_size = 0, .vmem_addr = 0, .dma_mask = 0xe0000000 - 1, + .cp_start = 0, + .cp_size = 0x70800000, + .cp_nonpixel_start = 0x1000000, + .cp_nonpixel_size = 0x24800000, .fwname = "qcom/venus-5.2/venus.mdt", }; diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 7118612673c9..8c88516e4694 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -68,6 +68,10 @@ struct venus_resources { unsigned int vmem_id; u32 vmem_size; u32 vmem_addr; + u32 cp_start; + u32 cp_size; + u32 cp_nonpixel_start; + u32 cp_nonpixel_size; const char *fwname; }; diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index 8801a6a7543d..ac906ffc608f 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -181,6 +181,7 @@ static int venus_shutdown_no_tz(struct venus_core *core) int venus_boot(struct venus_core *core) { struct device *dev = core->dev; + const struct venus_resources *res = core->res; phys_addr_t mem_phys; size_t mem_size; int ret; @@ -200,7 +201,22 @@ int venus_boot(struct venus_core *core) else ret = venus_boot_no_tz(core, mem_phys, mem_size); - return ret; + if (ret) + return ret; + + if (core->use_tz && res->cp_size) { + ret = qcom_scm_mem_protect_video_var(res->cp_start, + res->cp_size, + res->cp_nonpixel_start, + res->cp_nonpixel_size); + if (ret) { + dev_err(dev, "set virtual address ranges fail (%d)\n", + ret); + return ret; + } + } + + return 0; } int venus_shutdown(struct venus_core *core)