From patchwork Wed Jan 9 08:46:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 155055 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp458186jaa; Wed, 9 Jan 2019 00:46:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN4DLVj0Nn1BODjKYFUIoidxzMH7/5UdvlHINpf+4MhdAci2XPnwLiCMm7f3Hm+OGnZQqNTU X-Received: by 2002:a63:fd0a:: with SMTP id d10mr4626520pgh.164.1547023604378; Wed, 09 Jan 2019 00:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547023604; cv=none; d=google.com; s=arc-20160816; b=KwWLxGIZ9EUtvBS4NW1EeH0c7PFVpZ3/vrQJK7IHB4n/YQFvj1VeT2Bs4vva/gvJBL 6QxM3WA64WyLbMRPHyO93N/CS2wOeHTQ7twzJzhf3KahYEqcbxdwjlaZiXxwy6YvovV0 E88c7iZ5Tmf0DLiKToXX+x11ce0bbMsFyA4r/nuTrlc2pUvngkfSab2bWzgVvbWN1SBb q/8T4tsJkraAnwCN5yDOsNzR2Y6be1sBNQsHaTUVIFeA/zBto9Kjm3us3283D38mS9iR WPmdmE1yVv8TC0+cmXADb4cWFEWxNZQ2HfuQhRWG1J3FVeHvqWsV4ntuSbiM5bVgTK8z s36A== 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=p1aYYfe1Sbab/wTQ6/YLONvNDQbV1Er7aklVEWsbHqk=; b=h7e1H0kahGidHCEQ6v29Iv/ScGT7IqMjhH9EJUku3EyK5Phyv7zdz6J/Eu0nEZjIqD ioWk8guDp3i/0+6+JSLacMpcmH0aeQ63JriLbBk8fbFE0FfMLm74zCY1PBfpKvwBp3lW ab04M96C4wpyykFFkeGMMFS6lKDZx/u+epDcW2vMhxnjH90MhaQ1SwJ+tqR4CyamAjGg Aei5PXGqFm9i5opKwd+JkHxnQ/tHSL405GeP8TlshNPhmrdAKBi7oDApg/KuCjbl3LKL q5OK+fBsi0tFWBc2AMqQQoYoTmKlLswyLbjIjRqJB1pNchA3W6GyU2SCXMaHmmORFlr/ C1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZK8nXvpA; 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 go15si22245162plb.219.2019.01.09.00.46.44; Wed, 09 Jan 2019 00:46:44 -0800 (PST) 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=ZK8nXvpA; 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 S1729987AbfAIIqm (ORCPT + 31 others); Wed, 9 Jan 2019 03:46:42 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39152 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728138AbfAIIql (ORCPT ); Wed, 9 Jan 2019 03:46:41 -0500 Received: by mail-wm1-f65.google.com with SMTP id f81so7195246wmd.4 for ; Wed, 09 Jan 2019 00:46:40 -0800 (PST) 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=p1aYYfe1Sbab/wTQ6/YLONvNDQbV1Er7aklVEWsbHqk=; b=ZK8nXvpAcgp/j15jB2W2ghuu0K+Z22ZSigBYJpOMqJjWm+N+YDQi+SbINhaXpRbhjl +fGHLlrM1NcR8/dBpQ7EGZtwxKMoc5+lH3ianAvG7aRIL+E5ePjuj8Iv91AtFgjCUxUl +lAccnywHODSJ5Omiak+1B2JbrY4jJjuwzWqo= 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=p1aYYfe1Sbab/wTQ6/YLONvNDQbV1Er7aklVEWsbHqk=; b=sezD42Twct0PDgs8bE/WX/CunBSIh0W7/13Q3JwO1jvVGiQcTtb5wpDR83vfO1sUIQ iUDeFYsBs78a8/DNeZ2jP/D8sXNPAWn4v5FHUwtqaBeLBzRNIp7YDazcI+UuLt92K8A0 L+r1Hfa1L9vJWcafXd23sftqWeD75nnl4liM9QGg1k7X+y/OaVtiLlgc1hha2hrGCqcw U571UCl5i9VOfD9lmurjiOIhoyO3vpSmIzuIKVBZE1iwM+mRtOWDs6UlorUciIz9b++q WDANe4FWnfMNUk8XVv6bTgIoha2g89UUe7i2UUG4fmemfAQjTqEzdYEGalBI/p9K3DgE 2gWQ== X-Gm-Message-State: AJcUuke7RmUc6tarrGW10zfokAUO78jDxHCYg5wdkRlDz/dhIGhGe+/d AEYlJy2OQDZTMlorrs3qyPtf0g== X-Received: by 2002:a1c:4807:: with SMTP id v7mr4770489wma.53.1547023599117; Wed, 09 Jan 2019 00:46:39 -0800 (PST) Received: from localhost.localdomain ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id n82sm12776455wma.42.2019.01.09.00.46.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Jan 2019 00:46:38 -0800 (PST) From: Stanimir Varbanov To: linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vikash Garodia , Tomasz Figa , Alexandre Courbot , Malathi Gottam , Stanimir Varbanov Subject: [PATCH 1/4] venus: firmware: check fw size against DT memory region size Date: Wed, 9 Jan 2019 10:46:13 +0200 Message-Id: <20190109084616.17162-2-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190109084616.17162-1-stanimir.varbanov@linaro.org> References: <20190109084616.17162-1-stanimir.varbanov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By historical reasons we defined firmware memory size to be 6MB even that the firmware size for all supported Venus versions is 5MBs. Correct that by compare the required firmware size returned from mdt loader and the one provided by DT reserved memory region. We proceed further if the required firmware size is smaller than provided by DT memory region. Signed-off-by: Stanimir Varbanov --- drivers/media/platform/qcom/venus/core.h | 1 + drivers/media/platform/qcom/venus/firmware.c | 54 +++++++++++--------- 2 files changed, 31 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h index 6382cea29185..79c7e816c706 100644 --- a/drivers/media/platform/qcom/venus/core.h +++ b/drivers/media/platform/qcom/venus/core.h @@ -134,6 +134,7 @@ struct venus_core { struct video_firmware { struct device *dev; struct iommu_domain *iommu_domain; + size_t mapped_mem_size; } fw; struct mutex lock; struct list_head instances; diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c index c29acfd70c1b..6b509ffd022a 100644 --- a/drivers/media/platform/qcom/venus/firmware.c +++ b/drivers/media/platform/qcom/venus/firmware.c @@ -35,14 +35,15 @@ static void venus_reset_cpu(struct venus_core *core) { + u32 fw_size = core->fw.mapped_mem_size; void __iomem *base = core->base; writel(0, base + WRAPPER_FW_START_ADDR); - writel(VENUS_FW_MEM_SIZE, base + WRAPPER_FW_END_ADDR); + writel(fw_size, base + WRAPPER_FW_END_ADDR); writel(0, base + WRAPPER_CPA_START_ADDR); - writel(VENUS_FW_MEM_SIZE, base + WRAPPER_CPA_END_ADDR); - writel(VENUS_FW_MEM_SIZE, base + WRAPPER_NONPIX_START_ADDR); - writel(VENUS_FW_MEM_SIZE, base + WRAPPER_NONPIX_END_ADDR); + writel(fw_size, base + WRAPPER_CPA_END_ADDR); + writel(fw_size, base + WRAPPER_NONPIX_START_ADDR); + writel(fw_size, base + WRAPPER_NONPIX_END_ADDR); writel(0x0, base + WRAPPER_CPU_CGC_DIS); writel(0x0, base + WRAPPER_CPU_CLOCK_CONFIG); @@ -74,6 +75,9 @@ static int venus_load_fw(struct venus_core *core, const char *fwname, void *mem_va; int ret; + *mem_phys = 0; + *mem_size = 0; + dev = core->dev; node = of_parse_phandle(dev->of_node, "memory-region", 0); if (!node) { @@ -85,28 +89,30 @@ static int venus_load_fw(struct venus_core *core, const char *fwname, if (ret) return ret; + ret = request_firmware(&mdt, fwname, dev); + if (ret < 0) + return ret; + + fw_size = qcom_mdt_get_size(mdt); + if (fw_size < 0) { + ret = fw_size; + goto err_release_fw; + } + *mem_phys = r.start; *mem_size = resource_size(&r); - if (*mem_size < VENUS_FW_MEM_SIZE) - return -EINVAL; + if (*mem_size < fw_size || fw_size > VENUS_FW_MEM_SIZE) { + ret = -EINVAL; + goto err_release_fw; + } 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); - return -ENOMEM; - } - - ret = request_firmware(&mdt, fwname, dev); - if (ret < 0) - goto err_unmap; - - fw_size = qcom_mdt_get_size(mdt); - if (fw_size < 0) { - ret = fw_size; - release_firmware(mdt); - goto err_unmap; + ret = -ENOMEM; + goto err_release_fw; } if (core->use_tz) @@ -116,10 +122,9 @@ static int venus_load_fw(struct venus_core *core, const char *fwname, ret = qcom_mdt_load_no_init(dev, mdt, fwname, VENUS_PAS_ID, mem_va, *mem_phys, *mem_size, NULL); - release_firmware(mdt); - -err_unmap: memunmap(mem_va); +err_release_fw: + release_firmware(mdt); return ret; } @@ -135,6 +140,7 @@ static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys, return -EPROBE_DEFER; iommu = core->fw.iommu_domain; + core->fw.mapped_mem_size = mem_size; ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size, IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV); @@ -151,7 +157,7 @@ static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys, static int venus_shutdown_no_tz(struct venus_core *core) { struct iommu_domain *iommu; - size_t unmapped; + size_t unmapped, mapped = core->fw.mapped_mem_size; u32 reg; struct device *dev = core->fw.dev; void __iomem *base = core->base; @@ -166,8 +172,8 @@ static int venus_shutdown_no_tz(struct venus_core *core) iommu = core->fw.iommu_domain; - unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, VENUS_FW_MEM_SIZE); - if (unmapped != VENUS_FW_MEM_SIZE) + unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped); + if (unmapped != mapped) dev_err(dev, "failed to unmap firmware\n"); return 0;