From patchwork Thu Feb 21 08:47:26 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: 10823285 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 1997815AC for ; Thu, 21 Feb 2019 08:48:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 085562F7C8 for ; Thu, 21 Feb 2019 08:48:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F04802FFB0; Thu, 21 Feb 2019 08:48:51 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ABB32F7C8 for ; Thu, 21 Feb 2019 08:48:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727401AbfBUIsv (ORCPT ); Thu, 21 Feb 2019 03:48:51 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46676 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727399AbfBUIsu (ORCPT ); Thu, 21 Feb 2019 03:48:50 -0500 Received: by mail-pg1-f194.google.com with SMTP id 196so1576953pgf.13 for ; Thu, 21 Feb 2019 00:48:50 -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=Px+db7f7uMwYVRSzBolgafHC1+PpTUWWcoFxgLgxjKQ=; b=THBIdfvGqIgkoZXDdEcbKFs53SMkoTm9vQ4uyrfTScUufutz8EMNe1SKdwpPlpbKB8 Bf25JeeVXsJ/UyVRqswePG52y+LL8aF8irCrh9gJXl1SbFUnLuTryIwoJiguEMGMwG0j not+b1GljwYFqiXzRZGTXoEjGz7CIlGiwnonc= 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=Px+db7f7uMwYVRSzBolgafHC1+PpTUWWcoFxgLgxjKQ=; b=fgjcglQ56KXLEY98pRVYF5FoRiNF70kNIWfr89gKk5Yh3vLbIB9qguyl1BtwF1XJOR VzvbO7FKnbL7ZewKrPCi39v0mGJ3J0bvtGZjDHfvdD2YDDXRj/N0ol9z+oyxWJXvjeN7 C+pCOYE+t1eUk8X+rwv9zPHJiWaYZC3LK6gdwTXeXKfiA3zGfxDyx56d7o9HvatLWxrM hV5mWhibS9xPiJtP/7VmmC4yX2BmQOqdkE0dNmUlVSbYWXs3zHYmn5jWoWwxcaw0Jcbz jZEKbkfplS1CZhqX5QXYt8biiCxv7T8+cteS/ZTiP3J/4Bpa0og54wuuEgLxZvKs7JXR 94rQ== X-Gm-Message-State: AHQUAuYJJ8XkJwCvSiU65Pgoiv2ExouWYvYrwv+OBbITGsNySiCrcEDx 191p5KmeNXQi5kJjc002WTILxQ== X-Google-Smtp-Source: AHgI3IYX8B/NVsuEhmhWKdh4jo4EZZoYqf//7+Hm15c4TqYnhyRw1noiVANi6V5H7dahIQlVrNnQrw== X-Received: by 2002:a62:f51d:: with SMTP id n29mr31990636pfh.21.1550738930083; Thu, 21 Feb 2019 00:48:50 -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 b4sm23154027pgq.57.2019.02.21.00.48.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Feb 2019 00:48:49 -0800 (PST) From: Pi-Hsun Shih Cc: Pi-Hsun Shih , Erin Lo , Ohad Ben-Cohen , Bjorn Andersson , Matthias Brugger , Nicolas Boichat , linux-remoteproc@vger.kernel.org (open list:REMOTE PROCESSOR (REMOTEPROC) SUBSYSTEM), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-mediatek@lists.infradead.org (moderated list:ARM/Mediatek SoC support), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 3/6] remoteproc: mt8183: add reserved memory manager API Date: Thu, 21 Feb 2019 16:47:26 +0800 Message-Id: <20190221084729.101784-4-pihsun@chromium.org> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: <20190221084729.101784-1-pihsun@chromium.org> References: <20190221084729.101784-1-pihsun@chromium.org> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Erin Lo Add memory table mapping API for other driver to lookup reserved physical and virtual memory Signed-off-by: Erin Lo --- Changes from v4: - New patch. --- drivers/remoteproc/mtk_scp.c | 110 ++++++++++++++++++++++++++ include/linux/platform_data/mtk_scp.h | 20 +++++ 2 files changed, 130 insertions(+) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index a84d69ae6c531b..c689a8cc41f092 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -331,6 +331,112 @@ void *scp_mapping_dm_addr(struct platform_device *pdev, u32 mem_addr) } EXPORT_SYMBOL_GPL(scp_mapping_dm_addr); +#if SCP_RESERVED_MEM +phys_addr_t scp_mem_base_phys; +phys_addr_t scp_mem_base_virt; +phys_addr_t scp_mem_size; + +static struct scp_reserve_mblock scp_reserve_mblock[] = { + { + .num = SCP_ISP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x1400000, /*20MB*/ + }, +}; + +static int scp_reserve_mem_init(struct mtk_scp *scp) +{ + enum scp_reserve_mem_id_t id; + phys_addr_t accumlate_memory_size = 0; + + scp_mem_base_phys = (phys_addr_t) (scp->phys_addr + MAX_CODE_SIZE); + scp_mem_size = (phys_addr_t) (scp->dram_size - MAX_CODE_SIZE); + + dev_info(scp->dev, + "phys:0x%llx - 0x%llx (0x%llx)\n", + scp_mem_base_phys, + scp_mem_base_phys + scp_mem_size, + scp_mem_size); + accumlate_memory_size = 0; + for (id = 0; id < SCP_NUMS_MEM_ID; id++) { + scp_reserve_mblock[id].start_phys = + scp_mem_base_phys + accumlate_memory_size; + accumlate_memory_size += scp_reserve_mblock[id].size; + dev_info(scp->dev, + "[reserve_mem:%d]: phys:0x%llx - 0x%llx (0x%llx)\n", + id, + scp_reserve_mblock[id].start_phys, + scp_reserve_mblock[id].start_phys + scp_reserve_mblock[id].size, + scp_reserve_mblock[id].size); + } + return 0; +} + +static int scp_reserve_memory_ioremap(struct mtk_scp *scp) +{ + enum scp_reserve_mem_id_t id; + phys_addr_t accumlate_memory_size = 0; + + scp_mem_base_virt = (phys_addr_t)(size_t)ioremap_wc(scp_mem_base_phys, scp_mem_size); + + dev_info(scp->dev, + "virt:0x%llx - 0x%llx (0x%llx)\n", + (phys_addr_t)scp_mem_base_virt, + (phys_addr_t)scp_mem_base_virt + (phys_addr_t)scp_mem_size, + scp_mem_size); + for (id = 0; id < SCP_NUMS_MEM_ID; id++) { + scp_reserve_mblock[id].start_virt = + scp_mem_base_virt + accumlate_memory_size; + accumlate_memory_size += scp_reserve_mblock[id].size; + } + /* the reserved memory should be larger then expected memory + * or scp_reserve_mblock does not match dts + */ + WARN_ON(accumlate_memory_size > scp_mem_size); +#ifdef DEBUG + for (id = 0; id < NUMS_MEM_ID; id++) { + dev_info(scp->dev, + "[mem_reserve-%d] phys:0x%llx,virt:0x%llx,size:0x%llx\n", + id, + scp_get_reserve_mem_phys(id), + scp_get_reserve_mem_virt(id), + scp_get_reserve_mem_size(id)); + } +#endif + return 0; +} +phys_addr_t scp_get_reserve_mem_phys(enum scp_reserve_mem_id_t id) +{ + if (id >= SCP_NUMS_MEM_ID) { + pr_err("[SCP] no reserve memory for %d", id); + return 0; + } else + return scp_reserve_mblock[id].start_phys; +} +EXPORT_SYMBOL_GPL(scp_get_reserve_mem_phys); + +phys_addr_t scp_get_reserve_mem_virt(enum scp_reserve_mem_id_t id) +{ + if (id >= SCP_NUMS_MEM_ID) { + pr_err("[SCP] no reserve memory for %d", id); + return 0; + } else + return scp_reserve_mblock[id].start_virt; +} +EXPORT_SYMBOL_GPL(scp_get_reserve_mem_virt); + +phys_addr_t scp_get_reserve_mem_size(enum scp_reserve_mem_id_t id) +{ + if (id >= SCP_NUMS_MEM_ID) { + pr_err("[SCP] no reserve memory for %d", id); + return 0; + } else + return scp_reserve_mblock[id].size; +} +EXPORT_SYMBOL_GPL(scp_get_reserve_mem_size); +#endif + static int scp_map_memory_region(struct mtk_scp *scp) { struct device_node *node; @@ -358,6 +464,10 @@ static int scp_map_memory_region(struct mtk_scp *scp) return -EBUSY; } +#if SCP_RESERVED_MEM + scp_reserve_mem_init(scp); + scp_reserve_memory_ioremap(scp); +#endif return 0; } diff --git a/include/linux/platform_data/mtk_scp.h b/include/linux/platform_data/mtk_scp.h index dfda0505123563..7625eede2e5832 100644 --- a/include/linux/platform_data/mtk_scp.h +++ b/include/linux/platform_data/mtk_scp.h @@ -132,4 +132,24 @@ unsigned int scp_get_venc_hw_capa(struct platform_device *pdev); void *scp_mapping_dm_addr(struct platform_device *pdev, u32 mem_addr); +#define SCP_RESERVED_MEM (1) +#if SCP_RESERVED_MEM +/* scp reserve memory ID definition*/ +enum scp_reserve_mem_id_t { + SCP_ISP_MEM_ID, + SCP_NUMS_MEM_ID, +}; + +struct scp_reserve_mblock { + enum scp_reserve_mem_id_t num; + u64 start_phys; + u64 start_virt; + u64 size; +}; + +extern phys_addr_t scp_get_reserve_mem_phys(enum scp_reserve_mem_id_t id); +extern phys_addr_t scp_get_reserve_mem_virt(enum scp_reserve_mem_id_t id); +extern phys_addr_t scp_get_reserve_mem_size(enum scp_reserve_mem_id_t id); +#endif + #endif /* _MTK_SCP_H */