From patchwork Sat Dec 19 01:40:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Damm X-Patchwork-Id: 7889101 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3B5E4BEEE5 for ; Sat, 19 Dec 2015 01:38:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1D7CB204AF for ; Sat, 19 Dec 2015 01:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9940F204AD for ; Sat, 19 Dec 2015 01:38:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752371AbbLSBiX (ORCPT ); Fri, 18 Dec 2015 20:38:23 -0500 Received: from mail-pf0-f178.google.com ([209.85.192.178]:35533 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751478AbbLSBiW (ORCPT ); Fri, 18 Dec 2015 20:38:22 -0500 Received: by mail-pf0-f178.google.com with SMTP id v86so57172252pfa.2 for ; Fri, 18 Dec 2015 17:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:date:message-id:subject; bh=I2rQ0xKF3wHJELpwXLA+6pd+q2CMf5708rT2c3tj6vw=; b=MyaGhNNL59X93aRjRsMsQ204HMx98+Qqa8ioCnapWarsuzjx9a/tiSEmot6vOD7Eu+ gw4xvtnXeEBk3ENw4CxD8OISVYSVuDmIpyy+mkznQn3p5arrWm1U++5BJ8SyJAxEX4BZ CghFrcmjvoVcQSbNWJod/prJ/0LO12GSPruuxUtb1+APVGz/Ayiop/EKZ/YOp9HMcmhy WVff9izPCGX9yVY2eMSFlxBQS0KRNv2TE09c3b5lQp9y1a1tqJLlkTk95nBU6IpiXis2 JmyC/CL+FhyjHk4LZMwM08X07CDiPNIIjktufVRd9xgpcidKfvDXnTrxqRG8hD4hEARc SWDQ== X-Received: by 10.98.75.10 with SMTP id y10mr9879261pfa.86.1450489101820; Fri, 18 Dec 2015 17:38:21 -0800 (PST) Received: from [127.0.0.1] (s214090.ppp.asahi-net.or.jp. [220.157.214.90]) by smtp.gmail.com with ESMTPSA id rt6sm24758811pab.17.2015.12.18.17.38.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Dec 2015 17:38:20 -0800 (PST) From: Magnus Damm To: linux-sh@vger.kernel.org Cc: horms+renesas@verge.net.au, Magnus Damm , laurent.pinchart+renesas@ideasonboard.com, geert+renesas@glider.be Date: Sat, 19 Dec 2015 10:40:05 +0900 Message-Id: <20151219014005.6274.87661.sendpatchset@little-apple> Subject: [PATCH/RFC] ARM: shmobile: LPAE memory bank CMA assignment prototype Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 This prototype patch extends the kernel to also reserve CMA memory in the top memory bank on R-Car Gen2 boards and ties this larger CMA area to the DU device for testing purpose. This top portion of the memory requires 40-bits addressing support in bus master devices including LPAE for the ARM CPU cores. The patch assigns a 512 MiB CMA area to the DU device that may be used with the IPMMU hardware to perform 40-bit bus master access. Without IPMMU the DU hardware only supports 32-bit addresses. Tested on r8a7791 Koelsch HDMI output using the modetest utility: # modetest -M rcar-du -s 33:1024x768@AR24 Not for upstream merge. Not-Yet-Signed-off-by: Magnus Damm --- arch/arm/mach-shmobile/setup-rcar-gen2.c | 33 ++++++++- drivers/staging/board/Makefile | 1 drivers/staging/board/rcar-gen2.c | 104 ++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 4 deletions(-) -- 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/setup-rcar-gen2.c +++ work/arch/arm/mach-shmobile/setup-rcar-gen2.c 2015-12-19 09:38:09.750513000 +0900 @@ -136,14 +136,14 @@ struct memory_reserve_config { u64 base, size; }; -static int __init rcar_gen2_scan_mem(unsigned long node, const char *uname, - int depth, void *data) +static int __init __rcar_gen2_scan_mem(unsigned long node, const char *uname, + int depth, void *data, + u64 lpae_start) { const char *type = of_get_flat_dt_prop(node, "device_type", NULL); const __be32 *reg, *endp; int l; struct memory_reserve_config *mrc = data; - u64 lpae_start = 1ULL << 32; /* We are scanning "memory" nodes only */ if (type == NULL || strcmp(type, "memory")) @@ -182,6 +182,20 @@ static int __init rcar_gen2_scan_mem(uns return 0; } +static int __init rcar_gen2_scan_mem_legacy(unsigned long node, + const char *uname, + int depth, void *data) +{ + return __rcar_gen2_scan_mem(node, uname, depth, data, 1ULL << 32); +} + +static int __init rcar_gen2_scan_mem_lpae(unsigned long node, + const char *uname, + int depth, void *data) +{ + return __rcar_gen2_scan_mem(node, uname, depth, data, 1ULL << 40); +} + struct cma *rcar_gen2_dma_contiguous; void __init rcar_gen2_reserve(void) @@ -192,7 +206,18 @@ void __init rcar_gen2_reserve(void) memset(&mrc, 0, sizeof(mrc)); mrc.reserved = SZ_256M; - of_scan_flat_dt(rcar_gen2_scan_mem, &mrc); + of_scan_flat_dt(rcar_gen2_scan_mem_legacy, &mrc); +#ifdef CONFIG_DMA_CMA + if (mrc.size && memblock_is_region_memory(mrc.base, mrc.size)) + dma_contiguous_reserve_area(mrc.size, mrc.base, 0, + &rcar_gen2_dma_contiguous, true); +#endif + + /* reserve 512 MiB at the top of the 40-bit memory space */ + memset(&mrc, 0, sizeof(mrc)); + mrc.reserved = SZ_512M; + + of_scan_flat_dt(rcar_gen2_scan_mem_lpae, &mrc); #ifdef CONFIG_DMA_CMA if (mrc.size && memblock_is_region_memory(mrc.base, mrc.size)) dma_contiguous_reserve_area(mrc.size, mrc.base, 0, --- 0001/drivers/staging/board/Makefile +++ work/drivers/staging/board/Makefile 2015-12-18 17:46:31.030513000 +0900 @@ -1,3 +1,4 @@ obj-y := board.o obj-$(CONFIG_ARCH_EMEV2) += kzm9d.o obj-$(CONFIG_ARCH_R8A7740) += armadillo800eva.o +obj-$(CONFIG_ARCH_RCAR_GEN2) += rcar-gen2.o --- /dev/null +++ work/drivers/staging/board/rcar-gen2.c 2015-12-19 10:07:35.820513000 +0900 @@ -0,0 +1,104 @@ +/* Staging board support for R-Car Gen2. Enable not-yet-DT-capable bits here. */ + +#include +#include +#include +#include +#include +#include +#include "board.h" +#include "../../../mm/cma.h" + +#if defined(CONFIG_CMA) && defined(CONFIG_DMA_CMA) + +static struct cma *largest_cma_area; + +static int cma_assign_bus_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct device *dev = data; + const struct device_node *node = dev->of_node; + + if (action == BUS_NOTIFY_BIND_DRIVER) { + if (of_device_is_compatible(node, "renesas,du-r8a7790") || + of_device_is_compatible(node, "renesas,du-r8a7791") || + of_device_is_compatible(node, "renesas,du-r8a7793") || + of_device_is_compatible(node, "renesas,du-r8a7794")) { + + pr_info("Board Staging: Assigning CMA to %s\n", + of_node_full_name(node)); + dev_set_cma_area(dev, largest_cma_area); + } + } + + return 0; +} + +static struct notifier_block cma_assign_nb = { + .notifier_call = cma_assign_bus_notifier, +}; + +struct cma *find_largest_nondefault_cma(void) +{ + unsigned long largest_size; + int k, largest_idx; + + largest_size = 0; + largest_idx = -ENOENT; + + for (k = 0; k < cma_area_count; k++) { + if (&cma_areas[k] == dma_contiguous_default_area) + continue; + + if (cma_get_size(&cma_areas[k]) > largest_size) { + largest_size = cma_get_size(&cma_areas[k]); + largest_idx = k; + } + } + + if (largest_idx != -ENOENT) + return &cma_areas[largest_idx]; + + return NULL; +} + +static void __init board_staging_init(void) +{ + struct cma *target; + phys_addr_t cma_base; + + target = find_largest_nondefault_cma(); + + if (target) { + cma_base = cma_get_base(target); + + pr_info("Board Staging: Located CMA at " + "%pa, size %ld MiB\n", &cma_base, + (unsigned long)cma_get_size(target) / SZ_1M); + + largest_cma_area = target; + bus_register_notifier(&platform_bus_type, &cma_assign_nb); + } +} +#else +static inline void __init board_staging_init(void) {} +#endif + +static int __init runtime_board_check(void) +{ + if (of_machine_is_compatible("renesas,r8a7790")) + board_staging_init(); + + if (of_machine_is_compatible("renesas,r8a7791")) + board_staging_init(); + + if (of_machine_is_compatible("renesas,r8a7793")) + board_staging_init(); + + if (of_machine_is_compatible("renesas,r8a7794")) + board_staging_init(); + + return 0; +} + +arch_initcall(runtime_board_check)