From patchwork Tue Jul 20 22:24:02 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 59385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F13BB70B9 for ; Wed, 21 Jul 2010 08:42:00 +1000 (EST) Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.72 #1 (Red Hat Linux)) id 1ObLU0-00084r-Jo; Tue, 20 Jul 2010 22:40:16 +0000 Received: from smtp1.linux-foundation.org ([140.211.169.13]) by bombadil.infradead.org with esmtps (Exim 4.72 #1 (Red Hat Linux)) id 1ObLTy-00083Q-AT; Tue, 20 Jul 2010 22:40:15 +0000 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id o6KMUktQ015865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 20 Jul 2010 15:39:43 -0700 Received: from localhost.localdomain (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with ESMTP id o6KMO2dm021391; Tue, 20 Jul 2010 15:24:02 -0700 Message-Id: <201007202224.o6KMO2dm021391@imap1.linux-foundation.org> Subject: [patch 4/4] mtdpart: memory accessor interface for MTD layer To: dwmw2@infradead.org From: akpm@linux-foundation.org Date: Tue, 20 Jul 2010 15:24:02 -0700 MIME-Version: 1.0 X-Spam-Status: No, hits=-3.496 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20100720_184014_579943_BED11F77 X-CRM114-Status: GOOD ( 20.58 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.3.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: sudhakar.raj@ti.com, khilman@deeprootsystems.com, david-b@pacbell.net, linux-mtd@lists.infradead.org, cbouatmailru@gmail.com, akpm@linux-foundation.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Sudhakar Rajashekhara Implement a memory accessor interface in the MTD layer which enables the kernel to access flash data. This patch adds two new members to the mtd_partition structure, a function handler which will be called during setup of the partition and an argument to be passed to this setup function. Example: +static struct mtd_partition spi_flash_partitions[] = { + [0] = { + .name = "U-Boot", + .offset = 0, + .size = SZ_256K, + .mask_flags = MTD_WRITEABLE, + }, + [1] = { + .name = "U-Boot Environment", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_64K, + .mask_flags = MTD_WRITEABLE, + }, + [2] = { + .name = "Linux", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_7M, + .mask_flags = 0, + }, + [3] = { + .name = "MAC Address", + .offset = MTDPART_OFS_NXTBLK, + .size = SZ_64K, + .mask_flags = 0, + .setup = davinci_get_mac_addr, + .context = (void *)0, + }, +}; The davinci_get_mac_addr function reads the MAC address from offset ZERO of last MTD partition. Signed-off-by: Sudhakar Rajashekhara Acked-by: Kevin Hilman Cc: David Brownell Cc: David Woodhouse Cc: Anton Vorontsov Signed-off-by: Andrew Morton --- drivers/mtd/mtdpart.c | 40 +++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 3 ++ 2 files changed, 43 insertions(+) diff -puN drivers/mtd/mtdpart.c~mtdpart-memory-accessor-interface-for-mtd-layer drivers/mtd/mtdpart.c --- a/drivers/mtd/mtdpart.c~mtdpart-memory-accessor-interface-for-mtd-layer +++ a/drivers/mtd/mtdpart.c @@ -26,6 +26,7 @@ static LIST_HEAD(mtd_partitions); struct mtd_part { struct mtd_info mtd; struct mtd_info *master; + struct memory_accessor macc; uint64_t offset; struct list_head list; }; @@ -327,6 +328,39 @@ int del_mtd_partitions(struct mtd_info * } EXPORT_SYMBOL(del_mtd_partitions); +/* + * This lets other kernel code access the flash data. For example, it + * might hold a board's Ethernet address, or board-specific calibration + * data generated on the manufacturing floor. + */ +static ssize_t mtd_macc_read(struct memory_accessor *macc, char *buf, + off_t offset, size_t count) +{ + struct mtd_part *part = container_of(macc, struct mtd_part, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (part_read((struct mtd_info *)part, offset, count, + &retlen, buf) == 0) + ret = retlen; + + return ret; +} + +static ssize_t mtd_macc_write(struct memory_accessor *macc, const char *buf, + off_t offset, size_t count) +{ + struct mtd_part *part = container_of(macc, struct mtd_part, macc); + ssize_t ret = -EIO; + size_t retlen; + + if (part_write((struct mtd_info *)part, offset, count, + &retlen, buf) == 0) + ret = retlen; + + return ret; +} + static struct mtd_part *add_one_partition(struct mtd_info *master, const struct mtd_partition *part, int partno, uint64_t cur_offset) @@ -364,6 +398,9 @@ static struct mtd_part *add_one_partitio slave->mtd.read = part_read; slave->mtd.write = part_write; + slave->macc.read = mtd_macc_read; + slave->macc.write = mtd_macc_write; + if (master->panic_write) slave->mtd.panic_write = part_panic_write; @@ -428,6 +465,9 @@ static struct mtd_part *add_one_partitio printk(KERN_NOTICE "0x%012llx-0x%012llx : \"%s\"\n", (unsigned long long)slave->offset, (unsigned long long)(slave->offset + slave->mtd.size), slave->mtd.name); + if (part->setup) + part->setup(&slave->macc, (void *)part->context); + /* let's do some sanity checks */ if (slave->offset >= master->size) { /* let's register it anyway to preserve ordering */ diff -puN include/linux/mtd/partitions.h~mtdpart-memory-accessor-interface-for-mtd-layer include/linux/mtd/partitions.h --- a/include/linux/mtd/partitions.h~mtdpart-memory-accessor-interface-for-mtd-layer +++ a/include/linux/mtd/partitions.h @@ -10,6 +10,7 @@ #define MTD_PARTITIONS_H #include +#include /* @@ -40,6 +41,8 @@ struct mtd_partition { uint64_t offset; /* offset within the master MTD space */ uint32_t mask_flags; /* master MTD flags to mask out for this partition */ struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/ + void (*setup)(struct memory_accessor *, void *context); + void *context; }; #define MTDPART_OFS_NXTBLK (-2)