From patchwork Thu Aug 15 07:16:27 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: 11095121 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 DF4DB184E for ; Thu, 15 Aug 2019 07:17:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C894F2887B for ; Thu, 15 Aug 2019 07:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC90928884; Thu, 15 Aug 2019 07:17:03 +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 305162887B for ; Thu, 15 Aug 2019 07:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730708AbfHOHQy (ORCPT ); Thu, 15 Aug 2019 03:16:54 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33479 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730707AbfHOHQx (ORCPT ); Thu, 15 Aug 2019 03:16:53 -0400 Received: by mail-pg1-f196.google.com with SMTP id n190so960770pgn.0 for ; Thu, 15 Aug 2019 00:16:53 -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=is5RwojRZFxE56Whf/8DzaPViTsrNm4eSE18nn1ZEcU=; b=gn3lZuhgsTJrYpLva3LODqalEcB3sUWMo2I8Dm7UHJo7SfNc2jL8wUIoUZxgTm6OLs aQSJvZxNRD/g2WMdwPiNa4fyRinVwt5g9Ww1Ce6oNukDs7QXWMxIAtM+ibVIF5L/5upL vQBqVRtvZLeGAs53k+YYUv1FiBKqLZg6M0WP4= 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=is5RwojRZFxE56Whf/8DzaPViTsrNm4eSE18nn1ZEcU=; b=il1DJk7iTIwKIL5W0JWv1NTuTncRNzRdoi+SXpfJGaScc9N2qFU93iaGnA/sWCnXZc ke/9Q/hG3BwglvNioC1DG5t1aXa39p5ZcxLgV4TOfxSQ8IEmJSBzI9ECxJCYF2NKEg87 P4qv6zt9ui5gHxWsCLwWLmn3nuMhd6kvglc3bZR2VGpq85O/V1ZTpeK/CCHfJ74Pf0IT e2DXQCN+guBE5ypsr7URkkokdws7r3XD1Qtddw1qhBp46lIT8/B6wbSbkPcm2KNhq1Ma /N6YNa8MK2cTlfkMKRe6eFScd++wQgtxg7J5l2n4ziipP+8hLJBkbWQGvlK4yXDovylZ JP+g== X-Gm-Message-State: APjAAAUgyAu9HVyDQteiSOq/k3RwjwQIW9uXZDTCRkJzsK0z0F2v65S7 uCDkAK9LEGZmkeUKAglvPXGSig== X-Google-Smtp-Source: APXvYqzFOwq0R2YbfMEvsFvCBDrMwzJ7II/R93Zbbm8nTwjjVOpf9Xcs4pgWM8QfVjZVp2YvDzPWqA== X-Received: by 2002:a62:b515:: with SMTP id y21mr4067165pfe.213.1565853412713; Thu, 15 Aug 2019 00:16:52 -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 v6sm1768727pff.78.2019.08.15.00.16.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 15 Aug 2019 00:16:52 -0700 (PDT) From: Pi-Hsun Shih Cc: Pi-Hsun Shih , Erin Lo , Ohad Ben-Cohen , Bjorn Andersson , Matthias Brugger , 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 v16 3/5] remoteproc: mt8183: add reserved memory manager API Date: Thu, 15 Aug 2019 15:16:27 +0800 Message-Id: <20190815071635.168671-4-pihsun@chromium.org> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog In-Reply-To: <20190815071635.168671-1-pihsun@chromium.org> References: <20190815071635.168671-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 Signed-off-by: Pi-Hsun Shih --- Changes from v15: - No change. Changes from v14: - Fix a typo in variable name in DEBUG section. Changes from v13: - Add one more reserved region. - Rename scp_get_reserve_* to scp_get_reserved_*. - Minor fixes addressing comment. Changes from v12: - Reformat a line to fit 80 character width. Changes from v11: - No change. Changes from v10: - Fix some type mismatch warnings when printing debug messages. Changes from v9: - No change. Changes from v8: - Add more reserved regions for camera ISP. Changes from v7, v6, v5: - No change. Changes from v4: - New patch. --- drivers/remoteproc/mtk_scp.c | 145 +++++++++++++++++++++++++++++ include/linux/remoteproc/mtk_scp.h | 25 +++++ 2 files changed, 170 insertions(+) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index 2e4fa3e41f84..ae820a35bd52 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -366,11 +366,142 @@ void *scp_mapping_dm_addr(struct platform_device *pdev, u32 mem_addr) } EXPORT_SYMBOL_GPL(scp_mapping_dm_addr); +#if SCP_RESERVED_MEM +static phys_addr_t scp_mem_base_phys; +static phys_addr_t scp_mem_base_virt; +static size_t scp_mem_size; + +static struct scp_reserve_mblock scp_reserve_mblock[] = { + { + .num = SCP_ISP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x200000, /*2MB*/ + }, + { + .num = SCP_ISP_MEM2_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x800000, /*8MB*/ + }, + { + .num = SCP_MDP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x600000, /*6MB*/ + }, + { + .num = SCP_DIP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x900000, /*9MB*/ + }, + { + .num = SCP_FD_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x100000, /*1MB*/ + }, + { + .num = SCP_FD_MEM2_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x100000, /*1MB*/ + }, +}; + +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 = scp->dram_size - MAX_CODE_SIZE; + + dev_info(scp->dev, + "phys:0x%llx - 0x%llx (0x%llx)\n", + (unsigned long long)scp_mem_base_phys, + (unsigned long long)(scp_mem_base_phys + scp_mem_size), + (unsigned long long)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, + (unsigned long long)scp_reserve_mblock[id].start_phys, + (unsigned long long)(scp_reserve_mblock[id].start_phys + + scp_reserve_mblock[id].size), + (unsigned long long)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", + (unsigned long long)scp_mem_base_virt, + (unsigned long long)(scp_mem_base_virt + scp_mem_size), + (unsigned long long)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); + return 0; +} +phys_addr_t scp_get_reserved_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; + } + return scp_reserve_mblock[id].start_phys; +} +EXPORT_SYMBOL_GPL(scp_get_reserved_mem_phys); + +phys_addr_t scp_get_reserved_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; + } + return scp_reserve_mblock[id].start_virt; +} +EXPORT_SYMBOL_GPL(scp_get_reserved_mem_virt); + +size_t scp_get_reserved_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; + } + return scp_reserve_mblock[id].size; +} +EXPORT_SYMBOL_GPL(scp_get_reserved_mem_size); +#endif + static int scp_map_memory_region(struct mtk_scp *scp) { struct device_node *node; struct resource r; int ret; +#ifdef DEBUG + enum scp_reserve_mem_id_t id; +#endif node = of_parse_phandle(scp->dev->of_node, "memory-region", 0); if (!node) { @@ -393,6 +524,20 @@ 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); +#ifdef DEBUG + for (id = 0; id < SCP_NUMS_MEM_ID; id++) { + dev_info(scp->dev, + "[mem_reserve-%d] phys:0x%llx,virt:0x%llx,size:0x%llx\n", + id, + scp_get_reserved_mem_phys(id), + scp_get_reserved_mem_virt(id), + scp_get_reserved_mem_size(id)); + } +#endif +#endif return 0; } diff --git a/include/linux/remoteproc/mtk_scp.h b/include/linux/remoteproc/mtk_scp.h index b80d8e3f7959..707556f6b899 100644 --- a/include/linux/remoteproc/mtk_scp.h +++ b/include/linux/remoteproc/mtk_scp.h @@ -138,4 +138,29 @@ 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_ISP_MEM2_ID, + SCP_MDP_MEM_ID, + SCP_DIP_MEM_ID, + SCP_FD_MEM_ID, + SCP_FD_MEM2_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_reserved_mem_phys(enum scp_reserve_mem_id_t id); +extern phys_addr_t scp_get_reserved_mem_virt(enum scp_reserve_mem_id_t id); +extern size_t scp_get_reserved_mem_size(enum scp_reserve_mem_id_t id); +#endif + #endif /* _MTK_SCP_H */