From patchwork Fri Mar 7 13:54:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe De Muyter X-Patchwork-Id: 327981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 5BE962C009C for ; Sat, 8 Mar 2014 00:55:34 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLvFF-0000Q6-2t; Fri, 07 Mar 2014 13:55:25 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLvFD-0001ZO-Hr; Fri, 07 Mar 2014 13:55:23 +0000 Received: from smtp2.macqel.be ([109.135.2.61]) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WLvF9-0001YG-Si for linux-mtd@lists.infradead.org; Fri, 07 Mar 2014 13:55:21 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp2.macqel.be (Postfix) with ESMTP id BDC94130D97; Fri, 7 Mar 2014 14:54:56 +0100 (CET) X-Virus-Scanned: amavisd-new at macqel.be Received: from smtp2.macqel.be ([127.0.0.1]) by localhost (mail.macqel.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OGxVjrNpJlGK; Fri, 7 Mar 2014 14:54:53 +0100 (CET) Received: from perdita.MACQEL (perdita.macqel [10.1.40.53]) by smtp2.macqel.be (Postfix) with ESMTP id BFF76130D8D; Fri, 7 Mar 2014 14:54:53 +0100 (CET) Received: from perdita.MACQEL (localhost [127.0.0.1]) by perdita.MACQEL (8.14.4/8.14.4/SuSE Linux 0.8) with ESMTP id s27DspV8017212; Fri, 7 Mar 2014 14:54:53 +0100 Received: (from p6@localhost) by perdita.MACQEL (8.14.4/8.14.4/Submit) id s27DspLJ017203; Fri, 7 Mar 2014 14:54:51 +0100 X-Authentication-Warning: perdita.MACQEL: p6 set sender to phdm@macq.eu using -f From: Philippe De Muyter To: linux-mtd@lists.infradead.org Subject: [PATCH v3] mtd: mtdchar: allow mmap for ram devices in memory address space. Date: Fri, 7 Mar 2014 14:54:39 +0100 Message-Id: <1394200479-17168-1-git-send-email-phdm@macqel.be> X-Mailer: git-send-email 1.7.5.3 In-Reply-To: <1394189058-12711-1-git-send-email-phdm@macqel.be> References: <1394189058-12711-1-git-send-email-phdm@macqel.be> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140307_085520_157667_140AEF7C X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: David Howells , Markus Niebel , Brian Norris X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org use mtd_get_unmapped_area, as asked by an ancient comment, to get the physical address (if any) in memory of the mtd device. Therefore, mapram_unmapped_area had to be changed to return the physical address, not the virtual one, For the NOMMU case, that makes no difference, but for the MMU case, it is needed by mapram_unmapped_area to implement mmap. Signed-off-by: Philippe De Muyter Cc: David Howells Cc: Markus Niebel Cc: Brian Norris --- v3: avoid duplicating test done by mtd_get_unmapped_area drivers/mtd/chips/map_ram.c | 2 +- drivers/mtd/mtdchar.c | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c index 991c2a1..e93d147 100644 --- a/drivers/mtd/chips/map_ram.c +++ b/drivers/mtd/chips/map_ram.c @@ -92,7 +92,7 @@ static unsigned long mapram_unmapped_area(struct mtd_info *mtd, unsigned long flags) { struct map_info *map = mtd->priv; - return (unsigned long) map->virt + offset; + return (unsigned long) map->phys + offset; } static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 2147e73..5956246 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -1112,20 +1112,16 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma) #ifdef CONFIG_MMU struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; - struct map_info *map = mtd->priv; - - /* This is broken because it assumes the MTD device is map-based - and that mtd->priv is a valid struct map_info. It should be - replaced with something that uses the mtd_get_unmapped_area() - operation properly. */ - if (0 /*mtd->type == MTD_RAM || mtd->type == MTD_ROM*/) { -#ifdef pgprot_noncached - if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory)) - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); -#endif - return vm_iomap_memory(vma, map->phys, map->size); - } - return -ENODEV; + loff_t offset = vma->vm_pgoff << PAGE_SHIFT; + loff_t len = vma->vm_end - vma->vm_start; + phys_addr_t start; + + start = mtd_get_unmapped_area(mtd, len, offset, vma->vm_flags); + if (start == -EOPNOTSUPP) + return -ENODEV; + if (start == -EINVAL) + return -EINVAL; + return vm_iomap_memory(vma, start, len); #else return vma->vm_flags & VM_SHARED ? 0 : -EACCES; #endif