Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp826942imc; Sun, 10 Mar 2019 23:36:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUgvP3j6xWthCpgapjfrMcOMPGPtiZ95Yq0mqOpMa8S6CFFbWR2/cqBpjcmnpJR8B7ylmu X-Received: by 2002:a17:902:1744:: with SMTP id i62mr32130835pli.24.1552286176149; Sun, 10 Mar 2019 23:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552286176; cv=none; d=google.com; s=arc-20160816; b=CsCxbmWJs1a580rRbU9qRLfjlv9kOdtDfUpHmyyMY//JB9Kp2yv1bgH2hn4Vja6BI/ ov4C9G6vMNKx5RCcmJdtB3WtT5Up7+2AF889BfkM6rN8QCTH96nFnIv7/aISR+i3wXql jeRoE2B7LWtiTiAdb7qd8ziBkJYMVIVfiFXAbqhN6vVKjCbmmhhtijGY1PhoIzX7M0Tw 9ofoOMGlKvCtYNEVhepcvgkDwu9LvSZH11SLgNIbj8y8qWO6DnCVlowMdGljP45K3ob0 hQ5Ne/8Efl6n3FErSwy9nEkMXCw2uQPtnQ3WpHCM6+RZdIL+y4LoojLScB5DV6Pe5N6p Dcbw== 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=f+ki+RHm8bATp1ofHYYCL2ZAEFt5qznqVhJ9CATWJrU=; b=cIpH5CCBsEX13CHGEq0ypOJ+LizZUTUpUvd4X/wg2gQYk50+waRapxP7demuwHkTyW dhJm8l27C1zmYeMtAz5R12FCtYdood3OISVe+oE/fBhCVjjuRaAMV4JtIz4Q6xr5T5bn 6M+T+kOE8/XGoiMRwbHsaI4JIw1GZ80nGJMltWTnWPqHE9xNZicD/1O2z00aIV6QHf8p cjUYC062cOBv0KM27/K8MXR4xz0VZ5JVfG6elGz4Z4+Puw8cqpRpOjSya3LREh4zpZg0 HxI5nOJmH+B5MuD0JUvEr5e06kRWInPHdfu8ccLc9UF2JT/A0jdEQ1V5TRCP3mqntlMT cVpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b="O6CKU/4c"; 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 n78si4459027pfi.243.2019.03.10.23.36.00; Sun, 10 Mar 2019 23:36:16 -0700 (PDT) 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="O6CKU/4c"; 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 S1726752AbfCKGfa (ORCPT + 99 others); Mon, 11 Mar 2019 02:35:30 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38243 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbfCKGf3 (ORCPT ); Mon, 11 Mar 2019 02:35:29 -0400 Received: by mail-pf1-f194.google.com with SMTP id n125so2987936pfn.5 for ; Sun, 10 Mar 2019 23:35:28 -0700 (PDT) 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=f+ki+RHm8bATp1ofHYYCL2ZAEFt5qznqVhJ9CATWJrU=; b=O6CKU/4cta4yFQEzxRYaFafoLQBdAbN1Bcen1gjpzzqz/hVM2Mneo3XAOtja/gEHfp gEC+A1LYJCjDxkGo9CfStyP3ZF5J0DBf0j86Hd9w7PhoJECI6aI20JmN11y3H4Jpv7FM sNMQvnOhbWumoZye8BIjvXEmeYzft9uzSn7FE= 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=f+ki+RHm8bATp1ofHYYCL2ZAEFt5qznqVhJ9CATWJrU=; b=lkSYcfsllhzxJYrkTOg//mO+t5dCucnbq4okAPhY4nhcKADIiMvX7DiZfR3shioAO3 kNda3c3SCNn/GgSrVnTL31F0hipQ2lRct1M6nhwWaEZWOS/gcYFzbnkNOFo9bUPAcR8b eUHhfriYP40PRAvM8zE66qqB61WEB4z+CyP3RLnMVLJ4Rlo59sCfgauvaDoGkhkvWwnQ qeou0VtueuxAnQsn27hmjG/QAn8IFPhGAcCyD2QeHLyRImarfuTp27HD0A1tzBfJEIwZ hui0ibjtGxWKFjXpzJ7fpu8g/i0a53DMIRK/XyvSUfKWzqfZPa1RmAtdcZ1ZpSc1KcU0 8bbA== X-Gm-Message-State: APjAAAVrGIATi0ONWMcAkq3XfEGbv3NZ70STEW2GLRfel3ekLZxufUu1 i6dQih8RRxN5AJNgTt38BMvC+w== X-Received: by 2002:aa7:8508:: with SMTP id v8mr31438204pfn.14.1552286128072; Sun, 10 Mar 2019 23:35:28 -0700 (PDT) Received: from pihsun-z840.tpe.corp.google.com ([2401:fa00:1:10:7889:7a43:f899:134c]) by smtp.googlemail.com with ESMTPSA id p5sm6573040pfn.154.2019.03.10.23.35.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 Mar 2019 23:35:27 -0700 (PDT) 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 v6 3/7] remoteproc: mt8183: add reserved memory manager API Date: Mon, 11 Mar 2019 14:34:54 +0800 Message-Id: <20190311063458.137473-4-pihsun@chromium.org> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog In-Reply-To: <20190311063458.137473-1-pihsun@chromium.org> References: <20190311063458.137473-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 v5: - No change. 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 a84d69ae6c53..c689a8cc41f0 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 dfda05051235..7625eede2e58 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.360.g471c308f928-goog