From patchwork Wed Nov 8 18:05:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10048907 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 93D2B60247 for ; Wed, 8 Nov 2017 18:06:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AC4C297F4 for ; Wed, 8 Nov 2017 18:06:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CDC2297F8; Wed, 8 Nov 2017 18:06:14 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable 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 22760297F4 for ; Wed, 8 Nov 2017 18:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751856AbdKHSGB (ORCPT ); Wed, 8 Nov 2017 13:06:01 -0500 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:49530 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751852AbdKHSF6 (ORCPT ); Wed, 8 Nov 2017 13:05:58 -0500 X-Originating-IP: 158.255.198.50 Received: from w540.lan (host-50-static-198-255-158.hosts-appwifi.wifix.org [158.255.198.50]) (Authenticated sender: jacopo@jmondi.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 84DECFB8C1; Wed, 8 Nov 2017 19:05:53 +0100 (CET) From: Jacopo Mondi To: ysato@users.sourceforge.jp, dalias@libc.org, laurent.pinchart@ideasonboard.com Cc: Jacopo Mondi , linux-sh@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] sh: migor: Reserve memory block for CEU Date: Wed, 8 Nov 2017 19:05:46 +0100 Message-Id: <1510164346-21134-1-git-send-email-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.7.4 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A memory region for CEU video buffer has to be reserved during machine initialization. Originally, it was allocated through DMA API helpers and stored in the second IORESOURCE_MEM entry, to be later remapped by the CEU driver with a call to 'dma_declare_coherent_memory()' As Linux does not allow anymore to remap system RAM regions with 'memremap' function, sh_mobile_ceu driver fails when trying to remap the memory area: WARN_ONCE(1, "memremap attempted on ram %pa size: %#lx\n", &offset, (unsigned long) size) from 'memremap()' function in kernel/memremap.c To avoid hitting that WARN_ONCE() and have memory successfully remapped, reserve a region using '.mv_mem_reserve' member of SH's 'struct sh_machine_vector' to make sure memory is reserved early enough, and removed from the available system RAM. This is similar to what happens on ARM architecture with 'arm_memblock_steal()' function. Suggested-by: Laurent Pinchart Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- arch/sh/boards/mach-migor/setup.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/arch/sh/boards/mach-migor/setup.c b/arch/sh/boards/mach-migor/setup.c index 0bcbe58..080627c 100644 --- a/arch/sh/boards/mach-migor/setup.c +++ b/arch/sh/boards/mach-migor/setup.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,9 @@ * 0x18000000 8GB 8 NAND Flash (K9K8G08U0A) */ +#define CEU_BUFFER_MEMORY_SIZE (4 << 20) +static phys_addr_t ceu_dma_membase; + static struct smc91x_platdata smc91x_info = { .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT, }; @@ -501,6 +505,8 @@ extern char migor_sdram_leave_end; static int __init migor_devices_setup(void) { + struct resource *r = &migor_ceu_device.resource[2]; + /* register board specific self-refresh code */ sh_mobile_register_self_refresh(SUSP_SH_STANDBY | SUSP_SH_SF, &migor_sdram_enter_start, @@ -632,8 +638,6 @@ static int __init migor_devices_setup(void) #endif __raw_writew(__raw_readw(PORT_MSELCRB) | 0x2000, PORT_MSELCRB); /* D15->D8 */ - platform_resource_setup_memory(&migor_ceu_device, "ceu", 4 << 20); - /* SIU: Port B */ gpio_request(GPIO_FN_SIUBOLR, NULL); gpio_request(GPIO_FN_SIUBOBT, NULL); @@ -647,6 +651,12 @@ static int __init migor_devices_setup(void) */ __raw_writew(__raw_readw(PORT_MSELCRA) | 1, PORT_MSELCRA); + /* Setup additional memory resources for Migo-R */ + r->flags = IORESOURCE_MEM; + r->start = ceu_dma_membase; + r->end = r->start + CEU_BUFFER_MEMORY_SIZE - 1; + r->name = "ceu"; + i2c_register_board_info(0, migor_i2c_devices, ARRAY_SIZE(migor_i2c_devices)); @@ -665,10 +675,24 @@ static int migor_mode_pins(void) return MODE_PIN0 | MODE_PIN1 | MODE_PIN5; } +/* Reserve a portion of memory for CEU buffers */ +static void __init migor_mv_mem_reserve(void) +{ + phys_addr_t phys; + phys_addr_t size = CEU_BUFFER_MEMORY_SIZE; + + phys = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_ALLOC_ANYWHERE); + memblock_free(phys, size); + memblock_remove(phys, size); + + ceu_dma_membase = phys; +} + /* * The Machine Vector */ static struct sh_machine_vector mv_migor __initmv = { .mv_name = "Migo-R", .mv_mode_pins = migor_mode_pins, + .mv_mem_reserve = migor_mv_mem_reserve, };