From patchwork Thu Jul 9 11:58:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 11654313 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04920913 for ; Thu, 9 Jul 2020 11:59:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E103B20774 for ; Thu, 9 Jul 2020 11:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zDb2DpIw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727831AbgGIL7C (ORCPT ); Thu, 9 Jul 2020 07:59:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727121AbgGIL7B (ORCPT ); Thu, 9 Jul 2020 07:59:01 -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 53573C08C5DC for ; Thu, 9 Jul 2020 04:59:01 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id w3so1504848wmi.4 for ; Thu, 09 Jul 2020 04:59:01 -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=60WfY+m9rAT3c40Anjh0dgZrb+4tb57pCpohXHwky7M=; b=zDb2DpIwU3L53HsRgS/+PlDUuvCyut3NQ0S0RlY9MO5td14XWI1SaXbeH+esMYCy6s gUQLS9rpt2yFJPaeIegIjMQpzHhlpb/XxMEwpwT7NuIEzRhkk3ysklzzGlrYG5F2RG0j WK+T7uIhP8tEX4GB0Bm11CLRNR/u2RNJH3GFsdLrP3/s7kKnwEUMYBMMcME6MRhL6HL6 Y1DJ1WkGFUbkKS1c/P5nredeIfPvacuDQdSsq63syyPbX7TptFrcrP3+XPyPiDscPu9b ygc6yeCh6idE/5y+yU87lpNfEhazSM1ssMNsSIYCItfHzbp7hZjxQf4vNXTLdo/1iOiU /UlA== 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=60WfY+m9rAT3c40Anjh0dgZrb+4tb57pCpohXHwky7M=; b=dUcTXZYFYU+0hHBzUf7bwmWi5aTuUcg08jydn3pSDPFsdZYnGmM50YRZV+S/i3Tphe 3N9LFFKoe/POESPV2rLk/oUnwH+qVDVzrcB90N1zSpImqnqiLVbLQLrFXZ9VXjWJaYlR sy71kXMjdUgsNhg2YmYlFrDfOeQQwsE/Y6AYxgUhvJ1dVFJdyOg++PHd9hUPAc+ALrHa Sm9EznTeqStX5DjNddek1v1bak90jfmNS5tOdaJdrHAiA3RTfGSMTQ+tm1cj6OWClaUx DTHwQngVTXsFnoxGJM6kYnPBjRheeKZp7G0YKGDo/H3OxUTqnARAx2Oz3OUJmRCio1Hs gRBA== X-Gm-Message-State: AOAM530izTt+gNUTRju7kyh7J+U0kAhn46l6/2qzLhaSDDr565ew67RX lkQNVcZKG1cb3eMEVjZ/K9I0mMt+5s/33Q== X-Google-Smtp-Source: ABdhPJyzYeDIv9/PuYMDhLwugLRuG7CeYqHSYkqVlbtq7TwVD/kt5RVit16Iai60khSTCyyzgUw0FA== X-Received: by 2002:a1c:bb03:: with SMTP id l3mr13183337wmf.24.1594295939797; Thu, 09 Jul 2020 04:58:59 -0700 (PDT) Received: from localhost.localdomain (212-5-158-112.ip.btc-net.bg. [212.5.158.112]) by smtp.gmail.com with ESMTPSA id v7sm5140737wrp.45.2020.07.09.04.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:58:59 -0700 (PDT) From: Stanimir Varbanov To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Elliot Berman , Stanimir Varbanov Subject: [PATCH 1/2] firmware: qcom_scm: Add memory protect virtual address ranges Date: Thu, 9 Jul 2020 14:58:28 +0300 Message-Id: <20200709115829.8194-2-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200709115829.8194-1-stanimir.varbanov@linaro.org> References: <20200709115829.8194-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 --- 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..a73870255c2e 100644 --- a/drivers/firmware/qcom_scm.c +++ b/drivers/firmware/qcom_scm.c @@ -864,6 +864,30 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, } EXPORT_SYMBOL(qcom_scm_assign_mem); +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); + /** * qcom_scm_ocmem_lock_available() - is OCMEM lock/unlock interface available */ 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..19b5188d17f4 100644 --- a/include/linux/qcom_scm.h +++ b/include/linux/qcom_scm.h @@ -81,7 +81,9 @@ 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 int qcom_scm_mem_protect_video_var(u32 cp_start, u32 cp_size, + u32 cp_nonpixel_start, + u32 cp_nonpixel_size); 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); @@ -131,6 +133,10 @@ static inline int qcom_scm_iommu_secure_ptbl_init(u64 addr, u32 size, u32 spare) 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; } +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 bool qcom_scm_ocmem_lock_available(void) { return false; } static inline int qcom_scm_ocmem_lock(enum qcom_scm_ocmem_client id, u32 offset, From patchwork Thu Jul 9 11:58:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 11654311 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3133714F6 for ; Thu, 9 Jul 2020 11:59:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1819B20774 for ; Thu, 9 Jul 2020 11:59:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fJwRQNTM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727858AbgGIL7E (ORCPT ); Thu, 9 Jul 2020 07:59:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727849AbgGIL7D (ORCPT ); Thu, 9 Jul 2020 07:59:03 -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 541ACC08C5DC for ; Thu, 9 Jul 2020 04:59:03 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id o8so1486142wmh.4 for ; Thu, 09 Jul 2020 04:59:03 -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=fJwRQNTMBNmDim0Hlmq+EPHYf0L4aBACOkST0gdSFrk5ErnIkYtEB6/X33rf5PshRF K0O3M6MDvxUYCzL+61sx+/KSk5FF0dFEaHzQI/xnr7d7KosigyuAyWaG7sVkscIdlCnC FqrRS/kRnZKMljSgJobQJZ89JG/r7secpKDZYPw8yajO9CImC8gR1il7ci9S9DScqS2x ndRlrzW2AlEqaZDjzM5QPReEe/KwiAqBw0LPGogK3gOV0+NkN70WXEvzuKB3TkRnOluy AS6abkq+IV2uTmwQw6OAHqOIqi0CUteOCManHQT660YL+U8z1J82XaykeEottgD5GG/u zAvg== 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=fufx8KNsG9fjPWMMrnzwImPzjTuItsvIlX+A/3QOLdtX1XIdGWJiwhw5duM1Ior5Ur 65Peu2XLnXCrHwHdIOeGPeM9qYhbWgSEBVDIVoPxG02oX3NP6gP1blwwMsKdQwR3lDUX +vPHNAJ6PwpwZlcNjpwjOIU6QbQUfnIQ4mD3YSVFiwX7wKkVSUuz305N5otWTQ7L+kUe 8dcZvIQ1T+1Cm3lslaeL+GgizzuXkDvf925Oo+4jgdzElrjfQpPF4biGS5ZpzUP+j/Lh rGeTtGqjlWo8t48GiJFEHVp7KvlYCnrXaDb1wHbCnoEk1lABpjJbcw6y5isJ1FjlTd+j J9IQ== X-Gm-Message-State: AOAM531h+ywcRToMb5DCAJrEibzMqDWtpcTeGe+HJxuwML4tD7w0P1AE uFNT/xGCiZ4cqtLeVqqzA4aD6I4uy4tGnw== X-Google-Smtp-Source: ABdhPJxU3M6MXPX7D0iPepfCyWsGPL+DqDWriB9veEsCLFC0X3m8qTWeyIx/dja2bs9QTgd6OmVe+A== X-Received: by 2002:a1c:f407:: with SMTP id z7mr13705700wma.8.1594295941743; Thu, 09 Jul 2020 04:59:01 -0700 (PDT) Received: from localhost.localdomain (212-5-158-112.ip.btc-net.bg. [212.5.158.112]) by smtp.gmail.com with ESMTPSA id v7sm5140737wrp.45.2020.07.09.04.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 04:59:01 -0700 (PDT) From: Stanimir Varbanov To: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: Andy Gross , Bjorn Andersson , Elliot Berman , Stanimir Varbanov Subject: [PATCH 2/2] venus: firmware: Set virtual address ranges Date: Thu, 9 Jul 2020 14:58:29 +0300 Message-Id: <20200709115829.8194-3-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200709115829.8194-1-stanimir.varbanov@linaro.org> References: <20200709115829.8194-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(-) 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)