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: 10823299 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 75BC6184E for ; Thu, 21 Feb 2019 08:49:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60F112EDDF for ; Thu, 21 Feb 2019 08:49:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 550C12EDE6; Thu, 21 Feb 2019 08:49:43 +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 DF5432EDDF for ; Thu, 21 Feb 2019 08:49:42 +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=QAMG0gRGxQvHsRFRIJq8eDxhcGIRsiZ4MTJsbMGH+ww=; b=NQyoyd6q+ksenr 4U/PZp/xj8Wwmcj6Q+wJeSOtPpEQHaUssgKZxN1gTYN7uaZtGCOILHAVALF0EKJu1qbto2iFrAJgP dzzHMjPNpLF/mxzi5N+SKj63TrF58fp0ln/xyxsQAchiRvaNm6sRbn8E4fNGgu9ny6oO73p9DYYLE 1kbAOgj4QIuicLMQrvsZUY4qse0DavN79lzKisQNMdJvJMZl7iq5zOqOCnaF1mxr7kwqWXO8BtOZi fVXJibpWRS97Lagf36phsN+xddKYuPzMOP9Z7QjBS1zSiRh+ZePy5x/go3rp/0MsMRXWTixPm0qjj P71r7TpLfKKO7gBdnqkg==; 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 1gwk2u-0007Z6-9Q; Thu, 21 Feb 2019 08:49:32 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwk2E-0006l3-My for linux-mediatek@lists.infradead.org; Thu, 21 Feb 2019 08:49:04 +0000 Received: by mail-pg1-x542.google.com with SMTP id s198so13461651pgs.2 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=uY8H7WecoYbyQ+/U7T22O2vrMEextGNhJ3KTk4pYgGp6uHN0tfif0leFOqvL4sMd1Y j+VOWkr58bARB5CSM0FncBHZBOlAMAM7SbyMYOG79qm+Puh53TAh8pIvCZAFjaLKgZPy RJN6TRhDmFHcYJ+UWEVFifEtLpsZbH6gdQEWwSD9t1qmfIDpTnUknOEOy91EiJ4Icqwo t1mfzmFKBxkhjgej057hELGq8txA3t1ABdgqIWFcAGmQR5TaSSiNjZT+aSAsZFUnAY5+ DmSOE3PEZKyig+QLpDrgnsl3IGJsOCqoJmHjGxgbGtvuexZm5GHtX6mY5Ng1voQ+GY7D 8l2g== X-Gm-Message-State: AHQUAubkn6yqYinnwyHwUp4kathIxRFVTNppUW3mqtcn5Kd0RqKSbc3S NtQQ1IvZvZ1aR+QDQM2EfzhvmA== 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 To: 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190221_004851_052092_A6FE9FF7 X-CRM114-Status: GOOD ( 12.74 ) 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 , Nicolas Boichat , 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 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 */