From patchwork Sun May 29 14:56:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 9139807 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 02A8E60757 for ; Sun, 29 May 2016 14:56:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E794D1FF21 for ; Sun, 29 May 2016 14:56:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAE8528187; Sun, 29 May 2016 14:56:26 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 78AD21FF21 for ; Sun, 29 May 2016 14:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752680AbcE2O4J (ORCPT ); Sun, 29 May 2016 10:56:09 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35440 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752316AbcE2O4H (ORCPT ); Sun, 29 May 2016 10:56:07 -0400 Received: by mail-wm0-f66.google.com with SMTP id e3so14816405wme.2; Sun, 29 May 2016 07:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=zaXYg4+gJrc0KAaAW+OE0chMwfnxiVIP7FQMCkmAcdU=; b=hX+R25Q/sqZ6S96tZW/YQwfiNkS0Evd160V2tnMEYyNaTOsVMxEet21CsaYHXhv+0n OfQf/K3ATZTv0atLIjFIesaxf6uQKCLuJ/G2AkVh/qry5tYUZ4DLAau1PuRyadiZyKiF +Nzdkzl4omLCjLLBBqVo5EyoupbCl+9vQOTQ+uPLWgGExXrwirj3y0JNMMIbRUaEobFh /+04yfrV2HMhIS3S7U3kbMNm3EbHV0g7fmLYlmDCTzumt9Isk0rZUDIjAryr6s0g4tAF PEAXFbVtgp+iJnkeqcjwD0LfYNUuctyIMbroiBoecsVFdmz56vQq4YDBrmS6GHoKcRQS Vo4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=zaXYg4+gJrc0KAaAW+OE0chMwfnxiVIP7FQMCkmAcdU=; b=WOl8P/pe6jHVYR8cF5mCcEHN9dYHFWPFSPv48aYLyPgtYz7SCjPwnRf7WbYJg3Djet GOIrLyOo+f7dLvt2lnxAjBGg27IEC2evcHZqeHC0hA4fn9tLWdK6/D2/em9fkelEKUJn quTdvXDn1pmd+b900F7PnhfM82BN1AC16vxmHAbwK6EuVdFFVH8m14Vr8rpB3oO8dObt mD3zh2yo+iAqoWF1eoIiQE0NtFLO4Oi3PGMzKAfNlih9KN67qmYTE+l0ZQIlmEqbMTdr Rb44vrz24BNw782unYAQDsjkG6usqQ+FlvY9o2RBb4ZLuiwSh1fOwEAEQ4aK13sc2Tq7 Tq9Q== X-Gm-Message-State: ALyK8tJclRjwFJFhPCQ1TtpRRTuCZqNKCl+elJ87Qo83pqljuTUt93mGhruBPCHlSPBq4A== X-Received: by 10.28.31.213 with SMTP id f204mr6589384wmf.69.1464533764938; Sun, 29 May 2016 07:56:04 -0700 (PDT) Received: from [192.168.1.10] ([46.249.74.23]) by smtp.googlemail.com with ESMTPSA id v5sm12922932wjv.36.2016.05.29.07.56.03 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 29 May 2016 07:56:04 -0700 (PDT) From: Ivaylo Dimitrov Subject: dma_declare_coherent_memory fails for RAM allocated memory To: LKML , brian.starkey@arm.com, Greg Kroah-Hartman Cc: "linux-omap@vger.kernel.org" , sebastian Reichel , =?UTF-8?Q?Pali_Roh=c3=a1r?= , Tony Lindgren Message-ID: <574B0302.3010809@gmail.com> Date: Sun, 29 May 2016 17:56:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi, When trying to declare and use DT reserved memory region on ARM (OMAP3), dma_declare_coherent_memory() fails in memremap(). This is from today's master: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1 at kernel/memremap.c:111 memremap+0x118/0x194 memremap attempted on ram 0x8f800000 size: 0x700000 Modules linked in: CPU: 0 PID: 1 Comm: swapper Not tainted 4.6.0+ #15 Hardware name: Nokia RX-51 board [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (__warn+0xcc/0xf8) [] (__warn) from [] (warn_slowpath_fmt+0x34/0x44) [] (warn_slowpath_fmt) from [] (memremap+0x118/0x194) [] (memremap) from [] (dma_init_coherent_memory+0x48/0x104) [] (dma_init_coherent_memory) from [] (dma_declare_coherent_memory+0x2c/0x68) [] (dma_declare_coherent_memory) from [] (rmem_omapfb_device_init+0x34/0x64) [] (rmem_omapfb_device_init) from [] (of_reserved_mem_device_init+0x94/0xd8) [] (of_reserved_mem_device_init) from [] (omapdss_init_of+0xe4/0x154) [] (omapdss_init_of) from [] (customize_machine+0x20/0x44) [] (customize_machine) from [] (do_one_initcall+0xac/0x158) [] (do_one_initcall) from [] (kernel_init_freeable+0xf8/0x1c8) [] (kernel_init_freeable) from [] (kernel_init+0x8/0x110) [] (kernel_init) from [] (ret_from_fork+0x14/0x3c) ---[ end trace 73a8c076df72166b ]--- omapfb: dma_declare_coherent_memory failed The failing code looks like: . . . static int rmem_omapfb_device_init(struct reserved_mem *rmem, struct device *dev) { int dma; if (rmem->priv) return 0; dma = dma_declare_coherent_memory(&omap_fb_device.dev, rmem->base, rmem->base, rmem->size, DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE); if (!(dma & DMA_MEMORY_MAP)) { pr_err("omapfb: dma_declare_coherent_memory failed\n"); return -ENOMEM; } else rmem->priv = omap_fb_device.dev.dma_mem; return 0; } static void rmem_omapfb_device_release(struct reserved_mem *rmem, struct device *dev) { dma_release_declared_memory(&omap_fb_device.dev); } static const struct reserved_mem_ops rmem_omapfb_ops = { .device_init = rmem_omapfb_device_init, .device_release = rmem_omapfb_device_release, }; static int __init rmem_omapfb_setup(struct reserved_mem *rmem) { rmem->ops = &rmem_omapfb_ops; pr_info("omapfb: reserved %d bytes at %pa\n", rmem->size, &rmem->base); return 0; } RESERVEDMEM_OF_DECLARE(dss, "ti,omapfb-memsize", rmem_omapfb_setup); It turns out that dma_init_coherent_memory calls memremap with MEMREMAP_WC flag, which is disallowed for RAM IIUC. I quickly hacked some code to fix the issue, but as memremap API is relatively new(esp to me), I wonder if this is the correct way to go: Does the above code looks sane? How to fix the problem if not? Thanks, Ivo --- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index bdf28f7..04b1687 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -32,8 +33,12 @@ static bool dma_init_coherent_memory( if (!size) goto out; - if (flags & DMA_MEMORY_MAP) - mem_base = memremap(phys_addr, size, MEMREMAP_WC); + if (flags & DMA_MEMORY_MAP) { + unsigned long map_type = memblock_is_map_memory(phys_addr) ? + MEMREMAP_WB : MEMREMAP_WC; + + mem_base = memremap(phys_addr, size, map_type); + } else mem_base = ioremap(phys_addr, size); if (!mem_base)