mtd/include/linux/mtd map.h,1.38,1.39

David Woodhouse dwmw2 at infradead.org
Fri Jul 9 12:53:48 EDT 2004


Update of /home/cvs/mtd/include/linux/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv7792/include/linux/mtd

Modified Files:
	map.h 
Log Message:
Update new geometry mess

Index: map.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/mtd/map.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- map.h	8 Jul 2004 15:25:51 -0000	1.38
+++ map.h	9 Jul 2004 16:53:45 -0000	1.39
@@ -8,6 +8,7 @@
 #include <linux/config.h>
 #include <linux/types.h>
 #include <linux/list.h>
+#include <asm/unaligned.h>
 #include <asm/system.h>
 #include <asm/io.h>
 
@@ -95,10 +96,18 @@
 
 #if MAX_MAP_BANKWIDTH > (BITS_PER_LONG / 8)
 #define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
+#define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
 #else
 #define map_bankwidth_is_large(map) (0)
+#define map_words(map) (1)
 #endif
 
+#define MAX_MAP_LONGS ( ((MAX_MAP_BANKWIDTH*8) + BITS_PER_LONG - 1) / BITS_PER_LONG )
+
+typedef union {
+	unsigned long x[MAX_MAP_LONGS];
+} map_word;
+
 /* The map stuff is very simple. You fill in your struct map_info with
    a handful of routines for accessing the device, making sure they handle
    paging etc. correctly if your device needs it. Then you pass it off
@@ -132,10 +141,10 @@
 		      */
 
 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS
-	struct map_word (*read)(struct map_info *, unsigned long);
+	map_word (*read)(struct map_info *, unsigned long);
 	void (*copy_from)(struct map_info *, void *, unsigned long, ssize_t);
 
-	void (*write)(struct map_info *, struct map_word, unsigned long);
+	void (*write)(struct map_info *, const map_word, unsigned long);
 	void (*copy_to)(struct map_info *, unsigned long, const void *, ssize_t);
 
 	/* We can perhaps put in 'point' and 'unpoint' methods, if we really
@@ -179,22 +188,39 @@
 #define INVALIDATE_CACHED_RANGE(map, from, size) \
 	do { if(map->inval_cache) map->inval_cache(map, from, size); } while(0)
 
-#define MAX_MAP_LONGS ( ((MAX_MAP_BANKWIDTH*8) + BITS_PER_LONG - 1) / BITS_PER_LONG )
 
-typedef struct {
-	unsigned long x[MAX_MAP_LONGS];
-} map_word;
-
-static inline int map_word_equal(map_word val1, map_word val2)
+static inline int map_word_equal(struct map_info *map, map_word val1, map_word val2)
 {
 	int i;
-	for (i=0; i<MAX_MAP_LONGS; i++) {
+	for (i=0; i<map_words(map); i++) {
 		if (val1.x[i] != val2.x[i])
 			return 0;
 	}
 	return 1;
 }
 
+static inline map_word map_word_load(struct map_info *map, const void *ptr)
+{
+	map_word r;
+
+	if (map_bankwidth_is_1(map))
+		r.x[0] = *(unsigned char *)ptr;
+	else if (map_bankwidth_is_2(map))
+		r.x[0] = get_unaligned((uint16_t *)ptr);
+	else if (map_bankwidth_is_4(map))
+		r.x[0] = get_unaligned((uint32_t *)ptr);
+#if BITS_PER_LONG >= 64
+	else if (map_bankwidth_is_8(map))
+		r.x[0] = get_unaligned((uint64_t *)ptr);
+#endif
+	else if (map_bankwidth_is_large(map))
+		memcpy(r.x, ptr, map->bankwidth);
+
+	return r;
+}
+
+
+
 static inline map_word inline_map_read(struct map_info *map, unsigned long ofs)
 {
 	map_word r;
@@ -210,7 +236,7 @@
 		r.x[0] = __raw_readq(map->virt + ofs);
 #endif
 	else if (map_bankwidth_is_large(map))
-		memcpy_fromio(r.x, map->virt+ofs, map->bankwidth/8);
+		memcpy_fromio(r.x, map->virt+ofs, map->bankwidth);
 
 	return r;
 }
@@ -228,7 +254,7 @@
 		__raw_writeq(datum.x[0], map->virt + ofs);
 #endif
 	else if (map_bankwidth_is_large(map))
-		memcpy_toio(map->virt+ofs, datum.x, map->bankwidth/8);
+		memcpy_toio(map->virt+ofs, datum.x, map->bankwidth);
 	mb();
 }
 





More information about the linux-mtd-cvs mailing list