Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp269441imp; Thu, 21 Feb 2019 00:50:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IbfT/Ocw/+x+7/q4Gg0/YL1qqjl6/8a7ZrKx+qzBQQdZ+Vu2ytz0Bj8N+wnbL09nrXnF5Wm X-Received: by 2002:a63:2c8c:: with SMTP id s134mr33800088pgs.269.1550739007316; Thu, 21 Feb 2019 00:50:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550739007; cv=none; d=google.com; s=arc-20160816; b=tZOahFCE9m5lgY/vsJAufPJHbSPAjV8wSI9cNDNAOm15mFH9Q/z/vTS4NReZgnTSm6 lpHIS81N1JuSK5YqTGeQy7z7kUp0U6Kn4yvgG2GJh8DZ4+IDShdia26g5R3rzko4PQYN 4t35z6QrR81ljbQOLfYdb6fYg91cbioLGegWxzJVoeYlVTdbDHIocA3ZfjFP2J8hp1zz d4ujaufDxTbhxQBE5TKKedIniwbUOLpt19aUUM4tCGJ1qDJVAlpoLPrmVreCLQp+I++l KLkPIQ/vJQcrUXARwH0d+G6zijT8m4amYr+RUz7S6wudtc+YR5IoThQtKIMXjPX13QNg mcAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=Px+db7f7uMwYVRSzBolgafHC1+PpTUWWcoFxgLgxjKQ=; b=A+yUnnVTPKYjHVcRHv5j9pQtZpARdS2tsHs4M0Mqk9UUCYtijR72XModJM/x50Xn8H xT/s15MKBR8sja2kym1Q4I7za83bNzWgcET0atRJOA7LBzuW1JDSOx785VIJzxXd8aNk q7zG+/C937MgDCaq/Qsw+Isjbef1b4aEdYJOLPIcD162Husrzm5QeKZO30T/imHTGNkJ SI3Hgq1HGy1BqY4BtY2T4LMdsO0qEvDt+cvNvNl+cYUfYcYTQOdgCh03/v59I5rZ/Qa3 R0hUyYaWp5dL/jCAkJLgjWcIp93xEHPARI53YcvqeqyCdKu/E7ygRGtYTjGne66vtlEN bV6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=THBIdfvG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z3si15395984pgr.90.2019.02.21.00.49.51; Thu, 21 Feb 2019 00:50:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=THBIdfvG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727433AbfBUIsv (ORCPT + 99 others); Thu, 21 Feb 2019 03:48:51 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36185 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbfBUIsv (ORCPT ); Thu, 21 Feb 2019 03:48:51 -0500 Received: by mail-pg1-f195.google.com with SMTP id r124so13456903pgr.3 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=AvlTBw4XXf23oO6DDrFfbf6yvyefpccGUefMHtD0ubOlxNnw/JR/FQkk2iDKbDSTor 3Pgt2+FTWxqwMFReqhK9GCB5xaTh8CI0cjsyWAsHljKpnXzF4Em+P8pyyFCCmuvhZt7Q 6gcjMkDsBfFd72gZDOHri1VnvRMwUAaXK0XQn90Lhl8jE17KMLRYnQ4rZpB41VkkQCFb F/Gf1AvDTIca7Wlf1y7rGhL+Wxs8n7H/iqzzQT1nwz/h6J254dJDgceNutCU60PiGOHI 47UOisf5iI6jnTFQvsueBaLYOWOt/ly9KxK9z49UI3+L7ndFIfLJINQz8fxmGW/S7lly WIEQ== X-Gm-Message-State: AHQUAuaNuJ0PDeIac+lr24uG1dfVqlVICIIxsXiNAlKf2AdQTmhuFfTy em3mCZ/3EtlVZjFalFXW6dIUog== 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 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.21.0.rc0.258.g878e2cd30e-goog