From patchwork Mon Dec 30 13:19:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 3419371 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 71127C02DC for ; Mon, 30 Dec 2013 13:20:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AC51E200F2 for ; Mon, 30 Dec 2013 13:20:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AEF0E20109 for ; Mon, 30 Dec 2013 13:20:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755570Ab3L3NUN (ORCPT ); Mon, 30 Dec 2013 08:20:13 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:49930 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755052Ab3L3NUF (ORCPT ); Mon, 30 Dec 2013 08:20:05 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id rBUDJXf7012599; Mon, 30 Dec 2013 07:19:33 -0600 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBUDJXna029573; Mon, 30 Dec 2013 07:19:33 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Mon, 30 Dec 2013 07:19:33 -0600 Received: from deskari.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBUDJS3R024087; Mon, 30 Dec 2013 07:19:31 -0600 From: Tomi Valkeinen To: Ivaylo Dimitrov , Vaibhav Hiremath , , , CC: Tony Lindgren , Tomi Valkeinen Subject: [PATCH 1/2] ARM: omapfb: add coherent dma memory support Date: Mon, 30 Dec 2013 15:19:09 +0200 Message-ID: <1388409550-10720-2-git-send-email-tomi.valkeinen@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1388409550-10720-1-git-send-email-tomi.valkeinen@ti.com> References: <1388409550-10720-1-git-send-email-tomi.valkeinen@ti.com> MIME-Version: 1.0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 The omapfb driver uses dma_alloc to reserve memory for the framebuffers. However, on some use cases, even when CMA is in use, it's quite probable that omapfb fails to allocate the fb, either due to not enough free dma memory, fragmented dma memory, or CMA failing to make enough contiguous space. This patch adds a kernel cmdline parameter 'omapfb_vram' which can be used to give the size of a memory area reserved exclusively for omapfb, and optionally a physical address where the memory area is reserved. The memory area is reserved with memblock, and assigned to omapfb with dma_declare_coherent_memory. The dma_alloc function will first try to allocate the fb from the coherent memory area, and if that fails, it'll use the normal method of allocation. Signed-off-by: Tomi Valkeinen Cc: Ivaylo Dimitrov Acked-by: Tony Lindgren --- arch/arm/mach-omap2/common.c | 1 + arch/arm/mach-omap2/common.h | 2 ++ arch/arm/mach-omap2/fb.c | 77 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-omap2/common.c b/arch/arm/mach-omap2/common.c index 2dabb9ecb986..9beecded0380 100644 --- a/arch/arm/mach-omap2/common.c +++ b/arch/arm/mach-omap2/common.c @@ -33,4 +33,5 @@ void __init omap_reserve(void) omap_dsp_reserve_sdram_memblock(); omap_secure_ram_reserve_memblock(); omap_barrier_reserve_memblock(); + omap_fb_reserve_memblock(); } diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h index e30ef6797c63..21afdc0fe15e 100644 --- a/arch/arm/mach-omap2/common.h +++ b/arch/arm/mach-omap2/common.h @@ -304,6 +304,8 @@ extern void omap_reserve(void); struct omap_hwmod; extern int omap_dss_reset(struct omap_hwmod *); +extern void omap_fb_reserve_memblock(void); + /* SoC specific clock initializer */ extern int (*omap_clk_init)(void); diff --git a/arch/arm/mach-omap2/fb.c b/arch/arm/mach-omap2/fb.c index 26e28e94f625..80630329e508 100644 --- a/arch/arm/mach-omap2/fb.c +++ b/arch/arm/mach-omap2/fb.c @@ -30,9 +30,11 @@ #include #include +#include #include "soc.h" #include "display.h" +#include "common.h" #ifdef CONFIG_OMAP2_VRFB @@ -106,10 +108,83 @@ static struct platform_device omap_fb_device = { .num_resources = 0, }; +static phys_addr_t omapfb_mem_base __initdata; +static phys_addr_t omapfb_mem_size __initdata; + +static int __init early_omapfb_vram(char *p) +{ + omapfb_mem_size = memparse(p, &p); + + if (!omapfb_mem_size) { + pr_err("omapfb: bad size for 'omapfb_vram' param\n"); + return 0; + } + + if (*p == '@') { + omapfb_mem_base = memparse(p + 1, NULL); + + if (!omapfb_mem_base) { + pr_err("omapfb: bad addr for 'omapfb_vram' param\n"); + omapfb_mem_size = 0; + return 0; + } + } + + return 0; +} +early_param("omapfb_vram", early_omapfb_vram); + +void __init omap_fb_reserve_memblock(void) +{ + int r; + + if (!omapfb_mem_size) + return; + + if (omapfb_mem_base) { + r = memblock_reserve(omapfb_mem_base, omapfb_mem_size); + + if (r) { + pr_err("omapfb: memblock_reserve failed: %d\n", r); + return; + } + } else { + omapfb_mem_base = memblock_alloc(omapfb_mem_size, SZ_1M); + + if (!omapfb_mem_base) { + pr_err("omapfb: memblock_alloc failed\n"); + return; + } + } + + memblock_free(omapfb_mem_base, omapfb_mem_size); + memblock_remove(omapfb_mem_base, omapfb_mem_size); + + pr_info("omapfb: reserved %pa bytes at %pa\n", + &omapfb_mem_size, &omapfb_mem_base); +} + int __init omap_init_fb(void) { - return platform_device_register(&omap_fb_device); + int r; + + r = platform_device_register(&omap_fb_device); + + if (r) + return r; + + if (!omapfb_mem_base) + return 0; + + r = dma_declare_coherent_memory(&omap_fb_device.dev, + omapfb_mem_base, omapfb_mem_base, + omapfb_mem_size, DMA_MEMORY_MAP); + if (!(r & DMA_MEMORY_MAP)) + pr_err("omapfb: dma_declare_coherent_memory failed\n"); + + return 0; } + #else int __init omap_init_fb(void) { return 0; } #endif