From patchwork Mon Nov 16 08:44:11 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: 11907777 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 4AF09C55ABD for ; Mon, 16 Nov 2020 08:45:18 +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 D452522409 for ; Mon, 16 Nov 2020 08:45:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uT0aruEK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="GXgOGre7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D452522409 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-arm-kernel-bounces+linux-arm-kernel=archiver.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=RcVA9N11TQHzo9GNBReShq/TcOuoWKzgQGGpALtk1po=; b=uT0aruEKgct4M8Ysz4wUbRw98 Acnho6YFhAskKpG4zYaz24iJebIluuoV35SHxl0hvPPYWI+/r0hT7j7RvCn+6uXDaxOBVLLpxEiNO lsX1mEHdGdOxvgBE0zFFgXfSkdS/1d/HCpzToMcoTFppXgvBeco12l1hN7C+GrH9ShOVlE94HsiF8 pe0/khHwqdnQzBQtAeD/vM9/2BUxkkSAJ+fBQbJJ5KCo6djG3oZ/dpsUmtwTYQaShlv2os5izBdBW pF4ecIkJ5/53vYgzZPVzss2ibKonhX3qRnMZOxCv22bAX+u6+NlTW9cR5yAlntl8y5pTE2NPakQAp Z/Tqm+tlg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea80-00042p-Hg; Mon, 16 Nov 2020 08:44:48 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea7q-000404-Iv for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 08:44:40 +0000 Received: by mail-qt1-x849.google.com with SMTP id i39so9722193qtb.1 for ; Mon, 16 Nov 2020 00:44:36 -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=U1SYL24RcTv9N7iT3p8Gk3jg0reoXyBjPpMVxH+Yb2c=; b=GXgOGre7Vz7fMb34bNE5Fnr0Fuz4xu004X0MvPHy3/ZVL+bYlIvBjrV+j3YFiM1CTK mJkoYwcw3HaG/wFWu+8a8eNgFdyZ+lugSDUKxpy2+KE2NszFF0T4QCsaW2mRSU0o1cr0 L4JjnBcgjutYdsDlHwx8ar2SgdZzcFlAMC8payn3TF3SmxFFyMHRpVKYKwva/yq8awSr wVcZ3GEscUwsETAU+tAXkq1+65Jv1of7kB0ZGMYWCVf5FwPvBffxwIrF+WOJpVYS0v3R 7yr57qXUpXc/ywOqBLbco3E3QgGAYb4X9rQf2/4JaE+1hQFmMa8LP0vowZgbRmzD8ypy 08bw== 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=U1SYL24RcTv9N7iT3p8Gk3jg0reoXyBjPpMVxH+Yb2c=; b=dyeMtlFDomXSAMReQNb274zw85LgdQ0iobRMif9lZ/CrpxGx9M18jpqLCpNb5I+e15 HsUfJOnEcvQSLACedJJEMhN8ZTQsHGmf+2Xnlcudm2wPBqctprxB9fnqiJWhelZ628SH rxNVB2tMsDV2KTotAsIiGJCfA4dqy4CnsGWO8sRuj+IVJ/og0HdzbrgCGUXL3/HBvJi5 T36OHqHbRy84ulxSGjSSQpHoNfZLR2dd2pGaeA1Soug57K5oHSbgOurmOM1MeoNTvYUd yb8qcF9H2/V0djCB6/YYzOv3EIkmQp6rLG16OHJZJfLDpOta40Pb4CEaNDL1zRcUxRZR jnNw== X-Gm-Message-State: AOAM530ml4lLwKFrnSVA5mOP8SIq/cefw0pVM+EN8RVbOP5bkffNQkLo 1mNrXvQloAzKGZjuMdqfURYhkRspcXZN X-Google-Smtp-Source: ABdhPJzhbiY6OL3SEP4f5SvcBbQqzn20Wueip3Hg4YPjnhhPTZC1kw4E3QbluKfoOYm2U9VaaZ7MgAacn1oH X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:a0c:a8c4:: with SMTP id h4mr404502qvc.58.1605516275666; Mon, 16 Nov 2020 00:44:35 -0800 (PST) Date: Mon, 16 Nov 2020 16:44:11 +0800 In-Reply-To: <20201116084413.3312631-1-tzungbi@google.com> Message-Id: <20201116084413.3312631-2-tzungbi@google.com> Mime-Version: 1.0 References: <20201116084413.3312631-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH v2 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-20201116_034438_731865_809AC908 X-CRM114-Status: GOOD ( 13.57 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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 Reviewed-by: Mathieu Poirier --- 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 a1e23b5f19b9..0abbeb62cf43 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 scp->cpu_addr + offset; } From patchwork Mon Nov 16 08:44:12 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: 11907779 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 75550C63697 for ; Mon, 16 Nov 2020 08:45:31 +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 BD2D921D93 for ; Mon, 16 Nov 2020 08:45:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GbZZX6qy"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="kehch9xJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD2D921D93 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-arm-kernel-bounces+linux-arm-kernel=archiver.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=0O34zEEOGDJrIwsAZiMULfPad2mU9vcKUWSKK2IZesQ=; b=GbZZX6qyHGkjsP1nYX5NLDIDz 0Y7ObJgsx10+f6R3B7ILlLfiUMBOXzFMPWhpykVDYpCLKw/DrRXdxvj/9KH17xpNrYFAfm28XYKXf PmixBMRMrtcsQOVjcTVz0cBzKNNBuChDJMFH8ixYr53NecT/KMe01tWi8aoWcM8CGLrxzzpVi1sSv cs2Jr3U4UGQksxADLJiHvQmOG1QCJ0CiqVtO+VwDuoUdky03D3PY8WLqokmGbsySWhq6NdZrl8lKV C6uvoJDdFNneYHYL6eUy/ZKMl4SNPnDYsmKun0IRZk7VcpaqDZeRJA0zI6YWO2nNOGm+SpsytdDUC 60chXyTFw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea8C-00047Z-Gk; Mon, 16 Nov 2020 08:45:00 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea7v-00041e-GT for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 08:44:44 +0000 Received: by mail-pg1-x54a.google.com with SMTP id p21so2080848pgb.11 for ; Mon, 16 Nov 2020 00:44:41 -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=U3Gi1qahwlJP98+q+DzLZd9zkdZHDpsmepdISgH+9NE=; b=kehch9xJroI7LjWkkrpaK2y/pA8zVVNmlv6bS9Hbia0MVnrY0lfoB8heEZAxrT4eQq fqe9MOaa7/zAwhOHo+YXMJR5NKRvjqcmt5RB+q7UMvH19i1c4vR4w+S5FAVQugwZRgeN oODQ4xY8Xf0tbfWP08c2BW/dkJzdrkSJwhd91t+4DTd494czrp0MNGsUV940AjKk4FIF 0HuTUm9j5cKpr1eghbwhADpRLMY7r1JHk469OR3d5F7XJQb5YIApr8NFeNLukci6Jz9l MdR2MBIPLn629hut04JnPig15lPf9BOIL6yaC/vjblJddFywFtcVD8he0amkWpjrkDyl XyDQ== 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=U3Gi1qahwlJP98+q+DzLZd9zkdZHDpsmepdISgH+9NE=; b=sqRh8LbGQdDjLVK5BaV1lYPy+78H4xnFnZGJPICWCUnQYJN+W2gDp5uVn0PGJ4iOKg UUZ6rp1/cJ7MeTlhIa7g1dwT0fCbdQZ4ysmJZXpy0mmh3WAfJjEyJ/MKtuEh+YW+VLVc XjsUCrd37q25Rx74tO83RuJ0SnEYq5UEk9UbJk1xYTL6u1gvvOwlkremw+Qbqd5FcPps CGz7Ce+MnzKSCUyKqkRzPTOY/vtuhVDbcxU9SVekmFxxoX3LYCdzDuDLrniQxKILiIiK 3le4WFjDDntOVlMo0PR29x0PfjGliOxeQHunvOnvh3jRITWXue00C757E2twIkavNfgr zaGQ== X-Gm-Message-State: AOAM531SNu2RNYlckyQ9hE43W+HCNjDm7v+Jq+1fhcmyzj0ieee4Wdpj 1mOmkVoUkWaQwGpPC4UTUS5uiAZa2VwU X-Google-Smtp-Source: ABdhPJxg+Z8Zu9B3dSqceVno3+Brgq9ObO149i6jMRBUlUkXml8qKyHkCmVunSfSYifJf7XSVOpNenMRFqPo X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:a17:902:a503:b029:d8:e685:3e58 with SMTP id s3-20020a170902a503b02900d8e6853e58mr5843637plq.68.1605516279549; Mon, 16 Nov 2020 00:44:39 -0800 (PST) Date: Mon, 16 Nov 2020 16:44:12 +0800 In-Reply-To: <20201116084413.3312631-1-tzungbi@google.com> Message-Id: <20201116084413.3312631-3-tzungbi@google.com> Mime-Version: 1.0 References: <20201116084413.3312631-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH v2 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-20201116_034443_672119_70743306 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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 Reviewed-by: Mathieu Poirier --- 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 0abbeb62cf43..74ed675f61a6 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 Mon Nov 16 08:44:13 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: 11907773 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,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 33371C4742C for ; Mon, 16 Nov 2020 08:45:43 +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 B4E39208C7 for ; Mon, 16 Nov 2020 08:45:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J6prtqU6"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="i/S6gd7T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4E39208C7 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-arm-kernel-bounces+linux-arm-kernel=archiver.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=zluTGXz3ixrN7w1uTHUoyT94TvXIUHwfJLkkNYwt+ow=; b=J6prtqU6AkwkFcxoFUUHhefcs OaFxuXJYdB5HS/g10SQgy4zmwZFGcz2GVHSJhBoatIJgSGHsD3qQv5jl9+W8F08W0YxYxln0Qe0dt COwyR733Pe/bR09xpMWYarYmkn2paP7ADpfC6iemqHmc6SjXrTxpUiK2atyUBIie5+HZdhu60Dcaj 9LcuKjtYYrqRhKMbOOACIG08hvDgrbJlDq1f4KgITJnQeR6TiAhItxEOMhA7xsHkPMCEWJ9tGLEfH 8foCNmG2mKd78oysFCyMYxkADgBwNajLI0rEuaFo74uIVPIwXfd/DWKn9hRGs+cGZYZw+JCMWr8SC E2IVv83GQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea8K-0004Bf-TO; Mon, 16 Nov 2020 08:45:08 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kea7z-00042V-1F for linux-arm-kernel@lists.infradead.org; Mon, 16 Nov 2020 08:44:49 +0000 Received: by mail-qk1-x74a.google.com with SMTP id s9so11129904qks.2 for ; Mon, 16 Nov 2020 00:44:44 -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=A53CN07MXASBO5jvUKHBpKj9L55WcyFviEc+clg6PhA=; b=i/S6gd7Tg9y5CTA6qeQQf0oOlqA9kbS65lJTOiCbv103fuKCJpXUBCIDaWMlvpxWwT UY3lrD8Btcvct2pd+Fgy15hCeUxRCDKlebTAJFjM+oeWZ/5eS4fSNUBOoML10d03tGcT 1l6YL/RDauxZpDKIcpffN45aoc4V2LDp6zK71sZDeDvT0OcCFx6euf6MJXGLlYMqAc2R pkqNQWrrKBkURv4OnmYI4nYOwGx7rIgWaecbQbrnkH47bebB3qfbzgGOnXJAOfREIvBw dQ7yYlQwG2eVxIpiOzWEAgJUvzZJQPFuOLamobP8hO5Iq1Dde3JThNyDqrMIor+QI2B+ f6sg== 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=A53CN07MXASBO5jvUKHBpKj9L55WcyFviEc+clg6PhA=; b=RIL5ZzOOF0zRMiA5mf9ktu01Ee6PtPwcWs58gn+ixS0xSGolMJoRSJomdj7cuHV4LE qbNJ/6UaZEwvhgRFbF7BmWobybCbSZeFvGtvfHW76x6OWb/bkA5dt7XW3yyvwtbpX4to /lYtjxdSffLQA5c6iWuj4oxencrsc0kL0wwM+cy5eD3ORLtY7jmTF4+Qx5+zQg09B+lW idSr+iP3DMPkZBxgSUcf3FJ+F2Q83bmIPdatM52ojpKMucpJU85RmBCBh84U9MN3y7av 4dSr5O03OFddmXixvmdDg3OwLbZgzOdgGhhRx+INp7RCGEhd3znZaJ5Vy/clfE/WEBTB g/rw== X-Gm-Message-State: AOAM530OtBa4UqUyW+jz6oD24MOKW+UPY17PydMTVmTEGc9qQthO7CoX W773xQMK719+WwdCFNOgQDxhrD44eN75 X-Google-Smtp-Source: ABdhPJw38q3RH4TOjkGa40R3bWJx8iEXJezrd8qKsUYOP6fmVJWIttlc3MpvyHhW9eW1ykc9wTiFoTSO8eqZ X-Received: from tzungbi-z840.tpe.corp.google.com ([2401:fa00:1:b:725a:fff:fe41:c6a5]) (user=tzungbi job=sendgmr) by 2002:a0c:b648:: with SMTP id q8mr14586186qvf.33.1605516282945; Mon, 16 Nov 2020 00:44:42 -0800 (PST) Date: Mon, 16 Nov 2020 16:44:13 +0800 In-Reply-To: <20201116084413.3312631-1-tzungbi@google.com> Message-Id: <20201116084413.3312631-4-tzungbi@google.com> Mime-Version: 1.0 References: <20201116084413.3312631-1-tzungbi@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH v2 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-20201116_034447_183921_78BCA89B X-CRM114-Status: GOOD ( 18.23 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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. 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 74ed675f61a6..0ea3427cddc6 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) {