From patchwork Fri Feb 21 17:03:09 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: 322953 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 5AC592C0320 for ; Sat, 22 Feb 2014 04:04:36 +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 1WGtWM-0008P6-QS; Fri, 21 Feb 2014 17:04:19 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WGtWL-00026A-5H; Fri, 21 Feb 2014 17:04:17 +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 1WGtWI-000251-Be for linux-mtd@lists.infradead.org; Fri, 21 Feb 2014 17:04:15 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp2.macqel.be (Postfix) with ESMTP id 7758E168B63; Fri, 21 Feb 2014 18:03:38 +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 cgBvjbYDeVl0; Fri, 21 Feb 2014 18:03:36 +0100 (CET) Received: from perdita.MACQEL (perdita.macqel [10.1.40.53]) by smtp2.macqel.be (Postfix) with ESMTP id 51CFE168B62; Fri, 21 Feb 2014 18:03:36 +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 s1LH3WfW006336; Fri, 21 Feb 2014 18:03:35 +0100 Received: (from p6@localhost) by perdita.MACQEL (8.14.4/8.14.4/Submit) id s1LH3WfT006327; Fri, 21 Feb 2014 18:03:32 +0100 X-Authentication-Warning: perdita.MACQEL: p6 set sender to phdm@macq.eu using -f From: phdm@macq.eu To: dwmw2@infradead.org, computersforpeace@gmail.com, linux-mtd@lists.infradead.org Subject: [PATCH] mtd: allow mmap for ram devices in memory address space. Date: Fri, 21 Feb 2014 18:03:09 +0100 Message-Id: <1393002189-6293-1-git-send-email-phdm@macq.eu> X-Mailer: git-send-email 1.7.5.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140221_120414_636847_C6717196 X-CRM114-Status: GOOD ( 14.15 ) 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 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 From: Philippe De Muyter 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 --- drivers/mtd/chips/map_ram.c | 2 +- drivers/mtd/mtdchar.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 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..00eac7a 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -1112,13 +1112,23 @@ 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; + loff_t offset = vma->vm_pgoff << PAGE_SHIFT; + loff_t len = vma->vm_end - vma->vm_start; + if (offset > mtd->size - len) + return (unsigned long) -EINVAL; + if (mtd->_get_unmapped_area) { + phys_addr_t start; + + start = mtd->_get_unmapped_area(mtd, len, offset, vma->vm_flags); + return vm_iomap_memory(vma, start, len); + } /* 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*/) { + struct map_info *map = mtd->priv; #ifdef pgprot_noncached if (file->f_flags & O_DSYNC || map->phys >= __pa(high_memory)) vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);