From patchwork Fri Nov 13 07:02:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11902629 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 6AEF6697 for ; Fri, 13 Nov 2020 07:02:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C8E320B80 for ; Fri, 13 Nov 2020 07:02:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="olzR4ONS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Fgm+y0VD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C8E320B80 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GG8/xmPFUgLbeRpFqOT35aItIeUl9mHfwXXGd+SrXBM=; b=olzR4ONS2QHh1YFDHGzMSAYbh 3infgAnmxmd5y5IwDIiCiKwYLRS8ivtsmh1Azr+JaewjO6rgeVGhgU/V8gJSuixUNSemyXXqG47n2 DQ0dt0tQHbgMXpFukIimmTkwFJeaHu+RvvTH9Dao9fQ06ufDy0LsLf18/jsNxIpvsvfCmkVe7X1SH JlN/x4kloTL4W7lCGtr4ie8OI9GAd3rMdcMnn202GpnGR7ZiTr3C3AlSzFTfdLbeVaf0QKVAGXqVA iOXzlPMoMLl8uvLnqe9AuNp0frXvE2PysxysKZHA2YoKfsnoDOeZJecteNf5WapLo2+p4WIVDMSQU ROm2GTNUw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6J-000214-4Z; Fri, 13 Nov 2020 07:02:27 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6G-0001zd-8n for linux-mediatek@lists.infradead.org; Fri, 13 Nov 2020 07:02:25 +0000 Received: by mail-qv1-xf49.google.com with SMTP id m11so5003619qvu.6 for ; Thu, 12 Nov 2020 23:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=j5FOq3cPnWx/ENlFWQJtCdT3iUWxaQSgARSmLQ/sveE=; b=Fgm+y0VDBaeJl/93SSK4CkaNMA6QyIKahE2AcZJ1HXnZvwJtDFGUkNd6vJCgbvvfim eTsss/fi86Tru4W4xfM+EIRy8o2NSgC8IIqnIb1sqQQl4Ilbsl3qnTztXnhT8ftAGfn0 H08qp1Sczclyd85gDGA++xeTo0K1Ywq2quqvwVe8Be2ExaMNtwq9QPa48gPgwYz0huwk aiDlllSUNgpuIsOZNW+pZKiKKwgzn3UX3ebhIhk+D1OLezmA51eITU8PRiXwNy+FeGJx TROnFAU/UTApCIFvMJ0IW1qOAUfyl5emoQHIm5k3IaBHgwgtVngI4ns+7fRV3Vb4NI17 /BfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=j5FOq3cPnWx/ENlFWQJtCdT3iUWxaQSgARSmLQ/sveE=; b=qdBnEhWdL5qNa63pFidRWMuRNvzmbY2QhZKhvMBwmF/58sQxl8/tJ9NrdM8e2CVy/q lVvYWanhx7j7uF0nGCA0xiQgsGErbbvKB2No7ttWBQ6oKbbYhtfDiLDLQmFexVPMZUIV wcy61n18nDVJQMcMAvLrF++IOXcI5OmpDPthZvYfqV39IsZJMQlmtzL0dP6zb31n1N0T zHS9LAPJr3eN8X8MIZ9KYBMN+DlIrFdsAMMJGoTCl5K6qfSURXMSzVfha/wyeNHvPxrP MkWnBkYuKVNG53dm1De4C3WetCmMPZCEDz9A3/OXkcN+0vWq8wFbKbCo5MtTO6+LMU6v W+bA== X-Gm-Message-State: AOAM532KCb0ULZub/h0Avcnhs+Na2Zr7Mrp4hTvXGTDN0cvogeeE/C1M rXExaQmwalQ3Ek16ndqf0FzbTLz1gY2V X-Google-Smtp-Source: ABdhPJy9eyFdefDqQi/665Hf0+8tbnO1qV+pedR+tnbIbh/u/9XgvyubpCvZ5r8O0m68VORkzGMOkKJ94m/t X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:ad4:5483:: with SMTP id q3mr1020720qvy.24.1605250940904; Thu, 12 Nov 2020 23:02:20 -0800 (PST) Date: Fri, 13 Nov 2020 15:02:05 +0800 In-Reply-To: <20201113070207.836613-1-tzungbi@google.com> Message-Id: <20201113070207.836613-2-tzungbi@google.com> Mime-Version: 1.0 References: <20201113070207.836613-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH 1/3] remoteproc/mediatek: fix boundary check From: Tzung-Bi Shih To: ohad@wizery.com, bjorn.andersson@linaro.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_020224_370457_D68C1685 X-CRM114-Status: GOOD ( 11.59 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:f49 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-remoteproc@vger.kernel.org, tzungbi@google.com, linux-mediatek@lists.infradead.org, pihsun@chromium.org, matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org It is valid if offset+length == sram_size. For example, sram_size=100, offset=99, length=1. Accessing offset 99 with length 1 is valid. Signed-off-by: Tzung-Bi Shih --- drivers/remoteproc/mtk_scp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 577cbd5d421e..7ba00305009a 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -408,11 +408,11 @@ static void *scp_da_to_va(struct rproc *rproc, u64 da, size_t len) if (da < scp->sram_size) { offset = da; - if (offset >= 0 && (offset + len) < scp->sram_size) + if (offset >= 0 && (offset + len) <= scp->sram_size) return (void __force *)scp->sram_base + offset; } else if (scp->dram_size) { offset = da - scp->dma_addr; - if (offset >= 0 && (offset + len) < scp->dram_size) + if (offset >= 0 && (offset + len) <= scp->dram_size) return (void __force *)scp->cpu_addr + offset; } From patchwork Fri Nov 13 07:02:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11902635 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 08F06921 for ; Fri, 13 Nov 2020 07:02:41 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8B1520B80 for ; Fri, 13 Nov 2020 07:02:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Xtb0LBi+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vVZ4pBXY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8B1520B80 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8zhyGyRY80piYIZUphdQnEQKWcOwg/wcMeGsmJWCRTs=; b=Xtb0LBi+i0FTaUIsHGy73JoO1 PVlVmHIc/ckgoUYnS+aMMgGrHNoHrh3q4JbqzgBb3G3/wG8SUWGUu2M59jNOLCuOb0PDvnUCJZdTp KfoNYQj5oAu226CfkxeLcKutcasY3bOlnO7Ud/L77Od06Xg2XnYxYEl6XCWGKfeRQxnvxlgEkmKiC lz3aXJjCJ185OXiJ+A9MdhNprIUGJU/P7QizyqJ+EQ8BO+ywPGN26ZBLuKT9TNwrL4ca+IwMONJgK E4SJ1CWkwr2fyJ09YpWXWsHnHlYe5AfAjv8bPp9yjd/foocF10avDIhT0e+CN+H8F3ArcjUWxcZm1 qXmzuyWqQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6U-00024X-J4; Fri, 13 Nov 2020 07:02:38 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6J-00020q-VX for linux-mediatek@lists.infradead.org; Fri, 13 Nov 2020 07:02:29 +0000 Received: by mail-pl1-x649.google.com with SMTP id w15so5369744plq.17 for ; Thu, 12 Nov 2020 23:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=od5RzXQQDUYNdgHqpNLuL0ghCcmfAozESYAcDCe7NAo=; b=vVZ4pBXYbM3nzNUI1cLnpzMC29BCXXpYtA5AMN+l263aJDpnRb2tDK+Ts1e7ULWBvH L0NPUQTsoBc01RAQPpDr7iqR+uWyyn4oNauHZU55d1UHPgMzxVPDFe7JjBUCvWz+/yVI 935k29j8WUY2NO/EY38KYEFBIWOiBBEiVQ1JOglwOy7oNuI+dz6472ixF/ShVRqnchlu mM8/dfep+ArTnx1ih6xHVBBBizLe7na/YmTjvZ2FkhNKOhqU0DctIDs84mZwOgbzXHVS xWy3Qqh2YbAMwCAd1aVjjfATU6mqQ3tNcQ0FEsnJ3cPgfhQZnve17bfRDJE/x8FXpetc ZrsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=od5RzXQQDUYNdgHqpNLuL0ghCcmfAozESYAcDCe7NAo=; b=UWCdOutO6CU9gVYhLXGAJOkzs1bk+X1CUWuZ0FcP/IU/PLCsdgxxfLqO8GBSvxK7Ui YQ5EuKn5EwqbGXN0mjhszE8UKYk5UQpcAXYYirUMVRsr9Cb3j0tWfOPPS3ksJMqzz6Yu WkL6dmSeRzQIQ2BfejrN4/bDjtEROJR3Cy8mUxnB7VhWzYMwY++Dp40P2A33Bc0hJf+R fD86++cL1PdWNbUDttKUt1j+EPKEyi+qkUj0pc0hCZ1cF1Il+kefk5td1E6sMR/eghJH UolP3/CaUsE7waItojOIkrkMp0I287L5gp2DUeceuwvKEJv0FgoVp4zdA/RhPjCduHs4 BBow== X-Gm-Message-State: AOAM530ixcLo8knb3UzmiNg+6KN5bGfDBD+A2oXhZ7i1vwnlWzYkJthm XQjMsXY/NaYtc9MQ/StWSlxgnezFAHw3 X-Google-Smtp-Source: ABdhPJwTrEoI2V870amcgehFqHWitjg4WqLqzPkOKYCxwyxo0RZHFnPV/ysQuGnhBWchSZF6+jQjlqEeiqca X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:aa7:9e4e:0:b029:18b:7623:7cdb with SMTP id z14-20020aa79e4e0000b029018b76237cdbmr790147pfq.45.1605250944835; Thu, 12 Nov 2020 23:02:24 -0800 (PST) Date: Fri, 13 Nov 2020 15:02:06 +0800 In-Reply-To: <20201113070207.836613-1-tzungbi@google.com> Message-Id: <20201113070207.836613-3-tzungbi@google.com> Mime-Version: 1.0 References: <20201113070207.836613-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH 2/3] remoteproc/mediatek: skip if filesz is 0 From: Tzung-Bi Shih To: ohad@wizery.com, bjorn.andersson@linaro.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_020228_131255_8A574025 X-CRM114-Status: GOOD ( 13.08 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:649 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-remoteproc@vger.kernel.org, tzungbi@google.com, linux-mediatek@lists.infradead.org, pihsun@chromium.org, matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org The main purpose of the loop is to load the memory to the SCP SRAM. If filesz is 0, can go to next program header directly. We don't need to try to validate the FW binary for those filesz==0 segments. Signed-off-by: Tzung-Bi Shih --- drivers/remoteproc/mtk_scp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 7ba00305009a..60ba4cece074 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -234,12 +234,14 @@ static int scp_elf_load_segments(struct rproc *rproc, const struct firmware *fw) u32 offset = phdr->p_offset; void __iomem *ptr; - if (phdr->p_type != PT_LOAD) - continue; - dev_dbg(dev, "phdr: type %d da 0x%x memsz 0x%x filesz 0x%x\n", phdr->p_type, da, memsz, filesz); + if (phdr->p_type != PT_LOAD) + continue; + if (!filesz) + continue; + if (filesz > memsz) { dev_err(dev, "bad phdr filesz 0x%x memsz 0x%x\n", filesz, memsz); @@ -263,9 +265,7 @@ static int scp_elf_load_segments(struct rproc *rproc, const struct firmware *fw) } /* put the segment where the remote processor expects it */ - if (phdr->p_filesz) - scp_memcpy_aligned(ptr, elf_data + phdr->p_offset, - filesz); + scp_memcpy_aligned(ptr, elf_data + phdr->p_offset, filesz); } return ret; From patchwork Fri Nov 13 07:02:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tzung-Bi Shih X-Patchwork-Id: 11902637 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 9D455921 for ; Fri, 13 Nov 2020 07:02:44 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3FF8620B80 for ; Fri, 13 Nov 2020 07:02:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="h4wkHlzW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="kvbaWn8T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FF8620B80 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=GWbhq1m25hnGBgawN5Iqeu2YX9q0oCOSEBZ/KuLzmlA=; b=h4wkHlzWdip4oq49Y53LlQ9NE XenSoaxg5nWDbhuMv+PZzqCmZpxozOtCvUAPlqTDI0A+VItpH5FEE7CVoxfkSoZVDiPg7HfoI+KF2 AYNrxcBz0HrAPz6+HWpHtjoFmUOHoIwhYx6f27JiGijYr1FMpX+PSGreBU/lUUvMrWYDjabcb0eJ8 DMVjWP7+91wAUcxrlrinrCFBMHPH3bJr1euFzwjrLgtYZjNTXPQCX0lJobj8O0ROQLv0sHye7Bf3d ldhxD4rwc9FDXLQ6wnaqgRTaT1h1JN+tn02e/FByEakrspGK4ROuu6Q7xqIy3TVUHm/csRu8l++Cp c8WdY4Abg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6Y-00025W-Ag; Fri, 13 Nov 2020 07:02:42 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdT6N-000220-R4 for linux-mediatek@lists.infradead.org; Fri, 13 Nov 2020 07:02:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id w8so9400522ybj.14 for ; Thu, 12 Nov 2020 23:02:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=KvPsPLQiA3J/ICPhBCOBZKmQ9l/RY+N6rBWXD1vxO1k=; b=kvbaWn8T7Am7Uf08B5wsbwLdCAihTEC//+EKBw9cvtRXjqWFW87Ncth52qdSjQv0yE To9eSNI/KOIubMc/Wf/EsHlvBEtna19kH9uycdn6S8UkDgpyNxPZdi6TogksY5gEIKxg jKCbnD5sRKDDZWqYkkejxloJNsgijndMvrEnTPbBCvHEW92vi/TO8vJ3Gwt5geZFd6ql Y5xF1lyT2YovN1uv4tC7NTYiAbdZrDSSIwRzIjL5Mk0tf8fq1jwtCdCp2/hOmLmmMc+t fmuwiZEgnBKXZOVVm1w6sC3Oo0pEEEPTlu7cruopHjmwtws656tpdhOOpWrTBXvKbPd3 weCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KvPsPLQiA3J/ICPhBCOBZKmQ9l/RY+N6rBWXD1vxO1k=; b=sk85HzdyVzGtRJ47odai2TRjOhh2eH8DQHFil+Sr9UN3uoHxavWp+qSIkTk5IEiYLP S09bZo2Rwjp3LkwEAt9MYRIWomkAozRb1Wx1kDUjCeNkGJoi9UB2p4UiY7mdUPrIcxIr kz9xrEyvfOkAFLImKCmpgm1Ja8rgCG/YxBO5XO4ZyTKCfTtDQiepctdYhN9+3kbnxCgn Yu6ZxQNNZ2u1tbzeDlcilMuTHgXUaJjG5+A68xNm8C1a+Ymr5qRT2INb1VhJOUuew9P9 0y/IS9Snqb7YdMgXirmAS4dNRICciWQ+1vP21QZVUrO7iEeWFE02B6sdBM55Bp2QAFY0 iGeg== X-Gm-Message-State: AOAM533Xx8yjToQKwo9BcjaIcJef26na75RslyDL/vgw/7tFDfDBW2Dh z/ZblvWgvglJLeo4Xr9Eny612cHjixgp X-Google-Smtp-Source: ABdhPJwbbPEv9MHXFOI3knNNSs9fzqwySa2PCJnM6BXBhbtes93vbVSN29Gi68W+LJeiRCUWteeU/M8sx3p/ X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:a25:9d08:: with SMTP id i8mr995320ybp.2.1605250948538; Thu, 12 Nov 2020 23:02:28 -0800 (PST) Date: Fri, 13 Nov 2020 15:02:07 +0800 In-Reply-To: <20201113070207.836613-1-tzungbi@google.com> Message-Id: <20201113070207.836613-4-tzungbi@google.com> Mime-Version: 1.0 References: <20201113070207.836613-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH 3/3] remoteproc/mediatek: read IPI buffer offset from FW From: Tzung-Bi Shih To: ohad@wizery.com, bjorn.andersson@linaro.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201113_020231_934195_4ABDF73F X-CRM114-Status: GOOD ( 16.67 ) X-Spam-Score: -7.7 (-------) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-7.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:b4a listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -7.5 USER_IN_DEF_DKIM_WL From: address is in the default DKIM white-list -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.0 DKIMWL_WL_MED DKIMwl.org - Medium trust sender X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-remoteproc@vger.kernel.org, tzungbi@google.com, linux-mediatek@lists.infradead.org, pihsun@chromium.org, matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org Reads the IPI buffer offset from the FW binary. The information resides in addr of .ipi_buffer section. Moves scp_ipi_init() to scp_load() phase. The IPI buffer can be initialized only if the offset is clear. To backward compatible to MT8183 SCP, specify the offset in the board specific mtk_scp_of_data. Signed-off-by: Tzung-Bi Shih --- drivers/remoteproc/mtk_scp.c | 73 ++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 60ba4cece074..80ab5a30ea47 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -21,7 +21,7 @@ #include "remoteproc_internal.h" #define MAX_CODE_SIZE 0x500000 -#define SCP_FW_END 0x7C000 +#define SECTION_NAME_IPI_BUFFER ".ipi_buffer" /** * scp_get() - get a reference to SCP. @@ -119,16 +119,24 @@ static void scp_ipi_handler(struct mtk_scp *scp) wake_up(&scp->ack_wq); } -static int scp_ipi_init(struct mtk_scp *scp) +static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp, + const struct firmware *fw, + size_t *offset); + +static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw) { - size_t send_offset = SCP_FW_END - sizeof(struct mtk_share_obj); - size_t recv_offset = send_offset - sizeof(struct mtk_share_obj); + int ret; + size_t offset; + + ret = scp_elf_read_ipi_buf_addr(scp, fw, &offset); + if (ret) + return ret; + dev_info(scp->dev, "IPI buf addr %#010zx\n", offset); - /* shared buffer initialization */ - scp->recv_buf = - (struct mtk_share_obj __iomem *)(scp->sram_base + recv_offset); - scp->send_buf = - (struct mtk_share_obj __iomem *)(scp->sram_base + send_offset); + scp->recv_buf = (struct mtk_share_obj __iomem *) + (scp->sram_base + offset); + scp->send_buf = (struct mtk_share_obj __iomem *) + (scp->sram_base + offset + sizeof(*scp->recv_buf)); memset_io(scp->recv_buf, 0, sizeof(*scp->recv_buf)); memset_io(scp->send_buf, 0, sizeof(*scp->send_buf)); @@ -271,6 +279,32 @@ static int scp_elf_load_segments(struct rproc *rproc, const struct firmware *fw) return ret; } +static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp, + const struct firmware *fw, + size_t *offset) +{ + struct elf32_hdr *ehdr; + struct elf32_shdr *shdr, *shdr_strtab; + int i; + const u8 *elf_data = fw->data; + const char *strtab; + + ehdr = (struct elf32_hdr *)elf_data; + shdr = (struct elf32_shdr *)(elf_data + ehdr->e_shoff); + shdr_strtab = shdr + ehdr->e_shstrndx; + strtab = (const char *)(elf_data + shdr_strtab->sh_offset); + + for (i = 0; i < ehdr->e_shnum; i++, shdr++) { + if (strcmp(strtab + shdr->sh_name, + SECTION_NAME_IPI_BUFFER) == 0) { + *offset = shdr->sh_addr; + return 0; + } + } + + return -ENOENT; +} + static int mt8183_scp_before_load(struct mtk_scp *scp) { /* Clear SCP to host interrupt */ @@ -350,11 +384,15 @@ static int scp_load(struct rproc *rproc, const struct firmware *fw) ret = scp->data->scp_before_load(scp); if (ret < 0) - return ret; + goto leave; ret = scp_elf_load_segments(rproc, fw); - clk_disable_unprepare(scp->clk); + if (ret) + goto leave; + ret = scp_ipi_init(scp, fw); +leave: + clk_disable_unprepare(scp->clk); return ret; } @@ -680,19 +718,6 @@ static int scp_probe(struct platform_device *pdev) goto release_dev_mem; } - ret = clk_prepare_enable(scp->clk); - if (ret) { - dev_err(dev, "failed to enable clocks\n"); - goto release_dev_mem; - } - - ret = scp_ipi_init(scp); - clk_disable_unprepare(scp->clk); - if (ret) { - dev_err(dev, "Failed to init ipi\n"); - goto release_dev_mem; - } - /* register SCP initialization IPI */ ret = scp_ipi_register(scp, SCP_IPI_INIT, scp_init_ipi_handler, scp); if (ret) {