From patchwork Thu Jan 31 09:31:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pi-Hsun Shih X-Patchwork-Id: 10790213 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0652491E for ; Thu, 31 Jan 2019 09:33:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02F7630801 for ; Thu, 31 Jan 2019 09:33:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB46830858; Thu, 31 Jan 2019 09:33:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25CF930801 for ; Thu, 31 Jan 2019 09:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bN5BQVeDvsBrA+BPWdD5rO/PtjshcqY21pnysWapHV8=; b=cxc9rFQtUxxdru rOn/KzBNRl0ZYbJ4sH74qiDESw0FMyL1ocAkJAMh4ZU2x0quWWVkji1ud9SBC9ed+D0IWEzDX17Hy yWeIPR/6ovm8pCBP1jBKpkKyzrh0iY+l8ZJWG3bkQnNUB/ifU/izBATbE0oXoxqAm7+CF7PLIBpAR MU1C6gXQg65btezMUWBrCPhD58TZby/SIkBGYUpTrz7KNg/TaBA3WV654ctPdU0REB+kF1P73AnMY JStVHE4jOcGbFqiY2ixumOO+0XPUzN9pfa+SmbFlGwXkmb5nQ5t3QwYJZbqjH3c3as76ME9M1QGMB gNb/5egFVgSJpFCEkD3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gp8is-0002tI-HB; Thu, 31 Jan 2019 09:33:26 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gp8hZ-0001jN-QB for linux-mediatek@lists.infradead.org; Thu, 31 Jan 2019 09:32:31 +0000 Received: by mail-pg1-x541.google.com with SMTP id j10so1131679pga.1 for ; Thu, 31 Jan 2019 01:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KYayTLAIjqbiHgbKVBbyF73pC5IYaCQpN6ywaeYZLhk=; b=X9j8cW90LeK2WsQyDgUHYwTnO3OihBXBDRBqlI7Tc1CJ7NuruPbmi0DTo3FNQbQjxd 0Gqb9vHPSR0CiPBhAHp9kpfvZieAkc5G70SYXUvPzJLvsRVh2KLKU1WkrQUJPrGiWKJu 5C0X0oGn/kMpST7Ljlsom3sMiPKw/nM7X0gJo= 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:mime-version:content-transfer-encoding; bh=KYayTLAIjqbiHgbKVBbyF73pC5IYaCQpN6ywaeYZLhk=; b=pstDa0LSDIYlik17Lctl8TpZTo7ygtXOH6+4fD8ei+cwMpUGH/LObPO6qekprDcjMC XPnEKd1xO/493Hw0tO/ILDgotAnKCobz29NlB1AawjpDQObskhCBJrtjln8wflut/Tl0 FaaziR+lJrhVejf5xeynfF7MYkLzBGnCbGwVGvRYBBRievCYqCrUzEwj4GE3QkEv4sC8 IWHm+gblsn8MKP0wHMVvP/w5tlSybAAQspBbCn1PX82xcaW1y3P6ibxWjlsVV+6rWgFo 6HApJRcrU1QL9L0PiZO33wcyCgX6cKwr3yXe+B9e/J/pb5jM0cLZr9v8taHO92NtjRKz vYpA== X-Gm-Message-State: AJcUukdI7YHhnPFUmXFEWOpc0Bs82eN+8rCEcUzENbrbYsLWd2XhZZuf 1xhfzIXXj/MMPPBx+QXWoLfauQ== X-Google-Smtp-Source: ALg8bN7DUK6LyOrUOEcGJ7vtN8iZZyAFdTD0HIW3jW/LZF6c5e+10zrYeAmDej9RsedLjCe1N5g6fQ== X-Received: by 2002:a63:f717:: with SMTP id x23mr31147048pgh.317.1548927125228; Thu, 31 Jan 2019 01:32:05 -0800 (PST) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id w184sm4531197pgd.34.2019.01.31.01.32.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 01:32:04 -0800 (PST) From: Pi-Hsun Shih To: Subject: [PATCH v4 6/6] remoteproc/mediatek: Load ELF instead of bin file for mtk_scp. Date: Thu, 31 Jan 2019 17:31:31 +0800 Message-Id: <20190131093131.245531-7-pihsun@chromium.org> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog In-Reply-To: <20190131093131.245531-1-pihsun@chromium.org> References: <20190131093131.245531-1-pihsun@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190131_013205_950975_FE819752 X-CRM114-Status: GOOD ( 14.70 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ohad Ben-Cohen , Erin Lo , "open list:REMOTE PROCESSOR REMOTEPROC SUBSYSTEM" , open list , Bjorn Andersson , "moderated list:ARM/Mediatek SoC support" , Pi-Hsun Shih , Matthias Brugger , "moderated list:ARM/Mediatek SoC support" Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP For better flexibility on loading firmware image, change firmware load for mtk_scp from a plain binary file to ELF format instead. Signed-off-by: Pi-Hsun Shih --- Changes from v3: - New patch to load ELF instead of plain bin file. --- drivers/remoteproc/mtk_common.h | 2 ++ drivers/remoteproc/mtk_scp.c | 59 ++++++++++++++++++++++++++++++-- drivers/remoteproc/mtk_scp_ipi.c | 11 ++++-- 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h index 7efe2e7374e5ec..dffca9fbea9f1e 100644 --- a/drivers/remoteproc/mtk_common.h +++ b/drivers/remoteproc/mtk_common.h @@ -73,4 +73,6 @@ struct share_obj { u8 share_buf[288]; }; +void scp_memcpy_aligned(void *dst, const void *src, unsigned int len); + #endif diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index c0375119c53289..314ae3f8a82cf7 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -140,6 +140,62 @@ static irqreturn_t scp_irq_handler(int irq, void *priv) return IRQ_HANDLED; } +int scp_elf_load_segments(struct rproc *rproc, const struct firmware *fw) +{ + struct device *dev = &rproc->dev; + struct elf32_hdr *ehdr; + struct elf32_phdr *phdr; + int i, ret = 0; + const u8 *elf_data = fw->data; + + ehdr = (struct elf32_hdr *)elf_data; + phdr = (struct elf32_phdr *)(elf_data + ehdr->e_phoff); + + /* go through the available ELF segments */ + for (i = 0; i < ehdr->e_phnum; i++, phdr++) { + u32 da = phdr->p_paddr; + u32 memsz = phdr->p_memsz; + u32 filesz = phdr->p_filesz; + 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 (filesz > memsz) { + dev_err(dev, "bad phdr filesz 0x%x memsz 0x%x\n", + filesz, memsz); + ret = -EINVAL; + break; + } + + if (offset + filesz > fw->size) { + dev_err(dev, "truncated fw: need 0x%x avail 0x%zx\n", + offset + filesz, fw->size); + ret = -EINVAL; + break; + } + + /* grab the kernel address for this device address */ + ptr = rproc_da_to_va(rproc, da, memsz); + if (!ptr) { + dev_err(dev, "bad phdr da 0x%x mem 0x%x\n", da, memsz); + ret = -EINVAL; + break; + } + + /* put the segment where the remote processor expects it */ + if (phdr->p_filesz) + scp_memcpy_aligned(ptr, elf_data + phdr->p_offset, + filesz); + } + + return ret; +} + static int mtk_scp_load(struct rproc *rproc, const struct firmware *fw) { const struct mtk_scp *scp = rproc->priv; @@ -157,8 +213,7 @@ static int mtk_scp_load(struct rproc *rproc, const struct firmware *fw) writel(0x0, scp->reg_base + MT8183_SCP_SRAM_PDN); - memcpy(scp->sram_base, fw->data, fw->size); - return ret; + return scp_elf_load_segments(rproc, fw); } static int mtk_scp_start(struct rproc *rproc) diff --git a/drivers/remoteproc/mtk_scp_ipi.c b/drivers/remoteproc/mtk_scp_ipi.c index 1026089335a5c3..b6b248c9da50ac 100644 --- a/drivers/remoteproc/mtk_scp_ipi.c +++ b/drivers/remoteproc/mtk_scp_ipi.c @@ -55,7 +55,13 @@ void scp_ipi_unregister(struct platform_device *pdev, enum scp_ipi_id id) } EXPORT_SYMBOL_GPL(scp_ipi_unregister); -static void memcpy_aligned(void *dst, const void *src, unsigned int len) +/* + * Copy src to dst, where dst is in SCP SRAM region. + * Since AP access of SCP SRAM don't support byte write, this always write a + * full word at a time, and may cause some extra bytes to be written at the + * beginning & ending of dst. + */ +void scp_memcpy_aligned(void *dst, const void *src, unsigned int len) { void *ptr; u32 val; @@ -80,6 +86,7 @@ static void memcpy_aligned(void *dst, const void *src, unsigned int len) writel_relaxed(val, dst + i); } } +EXPORT_SYMBOL_GPL(scp_memcpy_aligned); int scp_ipi_send(struct platform_device *pdev, enum scp_ipi_id id, @@ -117,7 +124,7 @@ int scp_ipi_send(struct platform_device *pdev, } } while (readl(scp->reg_base + MT8183_HOST_TO_SCP)); - memcpy_aligned(send_obj->share_buf, buf, len); + scp_memcpy_aligned(send_obj->share_buf, buf, len); send_obj->len = len; send_obj->id = id;