From patchwork Mon Jun 9 12:38:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 4321661 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 54F9C9F433 for ; Mon, 9 Jun 2014 12:36:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6EF3020270 for ; Mon, 9 Jun 2014 12:36:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7FBFB2026C for ; Mon, 9 Jun 2014 12:36:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754499AbaFIMgl (ORCPT ); Mon, 9 Jun 2014 08:36:41 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:47965 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752662AbaFIMgk (ORCPT ); Mon, 9 Jun 2014 08:36:40 -0400 Received: by mail-pa0-f48.google.com with SMTP id bj1so704967pad.7 for ; Mon, 09 Jun 2014 05:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:in-reply-to:references:subject; bh=fSi6qCQTTOivpKBSbdvOBZhNIHuKZpdPlCRmfPEhYuE=; b=mSDP/lpLQ8cQ4AVxpBOueIcOo6fc5k6g5yC/C0LT390GD73kA05gF4yaui1Qupx4Dp K9oJjmxEQk7te2mF4aQJjxK10VjFKVKLBWL8bPxtyO0R0CBFMX9au6PCdeq25Q1HCKWU dLmRpTsDAzRCbKR8liOZhyKmRag6sq1lY7rK4v1CjH9iN1fKKxY/J58xiZBr0xo0hmK7 qUvn0cVN2CyN5tilBJ4rMvlAmQjxHrB9ZNfCVOkAuYMZyLQjaH5cehGRGtLYNMFIm9c8 /CeBXHk520wW+tEBCOGQkwleBa2YM7HNvHbR/LMfPL4L+b4T7wioBZHETxezcvr9AjNX aouQ== X-Received: by 10.68.225.74 with SMTP id ri10mr4284049pbc.116.1402317400398; Mon, 09 Jun 2014 05:36:40 -0700 (PDT) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by mx.google.com with ESMTPSA id bc4sm63944687pbb.2.2014.06.09.05.36.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jun 2014 05:36:39 -0700 (PDT) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: Magnus Damm , horms@verge.net.au Date: Mon, 09 Jun 2014 21:38:45 +0900 Message-Id: <20140609123845.31532.36468.sendpatchset@w520> In-Reply-To: <20140609123837.31532.85914.sendpatchset@w520> References: <20140609123837.31532.85914.sendpatchset@w520> Subject: [PATCH 01/02] ARM: shmobile: Add shared R-Car Gen2 CMA reservation code Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Magnus Damm Add R-Car Gen2 CMA memory reservation code that can be shared between multiple SoCs and boards. At this point r8a7790 and r8a7791 are supported. The top 256MiB of the legacy 32-bit physical memory space is assigned to a separate CMA area that may be assigned to various devices later on. Signed-off-by: Magnus Damm --- arch/arm/mach-shmobile/include/mach/rcar-gen2.h | 1 arch/arm/mach-shmobile/setup-r8a7790.c | 1 arch/arm/mach-shmobile/setup-r8a7791.c | 1 arch/arm/mach-shmobile/setup-rcar-gen2.c | 79 +++++++++++++++++++++++ 4 files changed, 82 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 0001/arch/arm/mach-shmobile/include/mach/rcar-gen2.h +++ work/arch/arm/mach-shmobile/include/mach/rcar-gen2.h 2014-06-09 20:51:34.000000000 +0900 @@ -4,5 +4,6 @@ void rcar_gen2_timer_init(void); #define MD(nr) BIT(nr) u32 rcar_gen2_read_mode_pins(void); +void rcar_gen2_reserve(void); #endif /* __ASM_RCAR_GEN2_H__ */ --- 0001/arch/arm/mach-shmobile/setup-r8a7790.c +++ work/arch/arm/mach-shmobile/setup-r8a7790.c 2014-06-09 21:02:30.000000000 +0900 @@ -319,6 +319,7 @@ DT_MACHINE_START(R8A7790_DT, "Generic R8 .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_late = shmobile_init_late, + .reserve = rcar_gen2_reserve, .dt_compat = r8a7790_boards_compat_dt, MACHINE_END #endif /* CONFIG_USE_OF */ --- 0001/arch/arm/mach-shmobile/setup-r8a7791.c +++ work/arch/arm/mach-shmobile/setup-r8a7791.c 2014-06-09 21:02:37.000000000 +0900 @@ -218,6 +218,7 @@ DT_MACHINE_START(R8A7791_DT, "Generic R8 .init_early = shmobile_init_delay, .init_time = rcar_gen2_timer_init, .init_late = shmobile_init_late, + .reserve = rcar_gen2_reserve, .dt_compat = r8a7791_boards_compat_dt, MACHINE_END #endif /* CONFIG_USE_OF */ --- 0001/arch/arm/mach-shmobile/setup-rcar-gen2.c +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c 2014-06-09 21:01:33.000000000 +0900 @@ -20,8 +20,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -110,3 +113,79 @@ void __init rcar_gen2_timer_init(void) #endif clocksource_of_init(); } + +struct memory_reserve_config { + u64 reserved; + u64 base, size; +}; + +static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname, + int depth, void *data) +{ + char *type = of_get_flat_dt_prop(node, "device_type", NULL); + __be32 *reg, *endp; + unsigned long l; + struct memory_reserve_config *mrc = data; + u64 lpae_start = (u64)1 << 32; + + /* We are scanning "memory" nodes only */ + if (type == NULL) { + /* + * The longtrail doesn't have a device_type on the + * /memory node, so look for the node called /memory@0. + */ + if (depth != 1 || strcmp(uname, "memory@0") != 0) + return 0; + } else if (strcmp(type, "memory") != 0) + return 0; + + reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); + if (reg == NULL) + reg = of_get_flat_dt_prop(node, "reg", &l); + if (reg == NULL) + return 0; + + endp = reg + (l / sizeof(__be32)); + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { + u64 base, size; + + base = dt_mem_next_cell(dt_root_addr_cells, ®); + size = dt_mem_next_cell(dt_root_size_cells, ®); + + if (base >= lpae_start) + continue; + + if ((base + size) >= lpae_start) + size = lpae_start - base; + + if (size < mrc->reserved) + continue; + + if (base < mrc->base) + continue; + + /* keep the area at top near the 32-bit legacy limit */ + mrc->base = base + size - mrc->reserved; + mrc->size = mrc->reserved; + } + + return 0; +} + +struct cma *rcar_gen2_dma_contiguous; + +void __init rcar_gen2_reserve(void) +{ + struct memory_reserve_config mrc; + + /* reserve 256 MiB at the top of the physical legacy 32-bit space */ + memset(&mrc, 0, sizeof(mrc)); + mrc.reserved = SZ_256M; + + of_scan_flat_dt(rcar_gen2_scan_mem, &mrc); +#ifdef CONFIG_DMA_CMA + if (mrc.size) + dma_contiguous_reserve_area(mrc.size, mrc.base, 0, + &rcar_gen2_dma_contiguous); +#endif +}