From patchwork Tue Jul 2 06:05: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: 11027269 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 6924F112C for ; Tue, 2 Jul 2019 06:07:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5BE28837 for ; Tue, 2 Jul 2019 06:07:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4322D28892; Tue, 2 Jul 2019 06:07:23 +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 C453128837 for ; Tue, 2 Jul 2019 06:07:22 +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=Av/us7QG5vVucmgkqgnhJhx5UMMfxAPuUVlJu82+yFI=; b=toyrUpf3XswHP1 Ez1cvCYNngqxu7aqJhPkJm5HIN9jsi21XlN6skqaAIhIeZi6ynlpqbekGz40YHBzGUNA00WLfdTm1 CCXIOpYUey77YDtnRJj0IpsohYz2dowTYXlVxNKW27V2MMzgst7T9oNJr7qtP6T6R+Mq1RgbyAooV Nz/vFZIRR6jtP3yWGqNgNXhfFUPMbVNXCtrqXewsOaowvXMkmg2Pr0ve3wz2lPJMHXuGnaB9cD+xA 1fIiUHym+etul+A8YL/hSAvx7XrVcKIUi44F+DCQAT7uWH3g3gDZVsgxNZT47TmG5UnVN2UGbQoUt At14Ue3HTpt0TpErxBhA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiBwo-0007Xi-D1; Tue, 02 Jul 2019 06:07:22 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiBvn-0006im-8f for linux-arm-kernel@lists.infradead.org; Tue, 02 Jul 2019 06:06:22 +0000 Received: by mail-pl1-x643.google.com with SMTP id c14so8582138plo.0 for ; Mon, 01 Jul 2019 23:06:18 -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+qwNdpkLhTiFrkWUJVHYpMRWEdjA0jqw7a7E26sy2s=; b=HqLIwp8hSSFmANzPX71hwsXwai4KAw4wcgL8O5mg2nDaY6AUAT8mxVkO5wI1d0CQJI DkzOFz53lCG6RO1jFPU8kx8JB8+cMIy1viW8qQk8uw9TWWBH/kpJbKdl6vGOTAu7pn3V BOpM5OJCjTc2u+oVnxWtneZ+lO3P/D387MdS8= 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+qwNdpkLhTiFrkWUJVHYpMRWEdjA0jqw7a7E26sy2s=; b=BXFa2v5JZ/4/y5ghyg1h4vIF4kNuvO8wtcz6fyMxCkx22JM7vKT4SMRBPwMG97C2bc fiMf7p2U5Gx4jykZwU8/Z8NT3HBA6fY+Tx4WfcPrnLbjVtvOeS4Jg4QEMWfwYuUqHbef oFqzG8Px949sg9mevbUwgiiFsk7RNJQSOZaWtSGLiPi7Qk3XUjB0IQTQFgiyQvlpElh2 7IR88Rkmp2A2u+oaSBiXnoVCGgOZm2XeMs+UG5Je7vMSDCWOLmSqw/oXprbseyEfTixV bcCXshlfrMB+1rBMuG8Pw9qTLJDFOQLlDuGfHfvE2vnnMUdvYWkb0zva0/0V/vlqcnUD dPXw== X-Gm-Message-State: APjAAAU6i/W1jPcAI6BEFknnA8fMUHT2aZeCEGXpGaIupkz2bbPr+oAJ NHI0w6ZGFpieG6h7p0ylHOeUzA== X-Google-Smtp-Source: APXvYqyjcyu7v/6GCI9p7Uso3jKN/1N3i50cBUY8zitkRMyW72rOcN5WtX2PILBElh1tjlLpM1kCIw== X-Received: by 2002:a17:902:b20d:: with SMTP id t13mr31728687plr.229.1562047578017; Mon, 01 Jul 2019 23:06:18 -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 d1sm10284013pgd.50.2019.07.01.23.06.15 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 23:06:17 -0700 (PDT) From: Pi-Hsun Shih To: Subject: [PATCH v12 3/5] remoteproc: mt8183: add reserved memory manager API Date: Tue, 2 Jul 2019 14:05:26 +0800 Message-Id: <20190702060546.222934-4-pihsun@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190702060546.222934-1-pihsun@chromium.org> References: <20190702060546.222934-1-pihsun@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190701_230619_540992_651ED741 X-CRM114-Status: GOOD ( 12.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 Signed-off-by: Pi-Hsun Shih --- 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 | 136 ++++++++++++++++++++++++++ include/linux/platform_data/mtk_scp.h | 24 +++++ 2 files changed, 160 insertions(+) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index d98cf385b055..fd56c32da29a 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -352,6 +352,138 @@ 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 = 0x200000, /*2MB*/ + }, + { + .num = SCP_ISP_MEM2_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x800000, /*8MB*/ + }, + { + .num = SCP_DIP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x900000, /*9MB*/ + }, + { + .num = SCP_MDP_MEM_ID, + .start_phys = 0x0, + .start_virt = 0x0, + .size = 0x600000, /*6MB*/ + }, + { + .num = SCP_FD_MEM_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 = (phys_addr_t) (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); +#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; @@ -379,6 +511,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 b81ac5c7d320..96e56fdd0917 100644 --- a/include/linux/platform_data/mtk_scp.h +++ b/include/linux/platform_data/mtk_scp.h @@ -138,4 +138,28 @@ 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_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 */