22 #ifndef __LINUX_MTD_MAP_H__
23 #define __LINUX_MTD_MAP_H__
25 #include <linux/types.h>
26 #include <linux/list.h>
27 #include <linux/string.h>
29 #include <linux/kernel.h>
31 #include <asm/unaligned.h>
33 #include <asm/barrier.h>
35 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
36 #define map_bankwidth(map) 1
37 #define map_bankwidth_is_1(map) (map_bankwidth(map) == 1)
38 #define map_bankwidth_is_large(map) (0)
39 #define map_words(map) (1)
40 #define MAX_MAP_BANKWIDTH 1
42 #define map_bankwidth_is_1(map) (0)
45 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_2
48 # define map_bankwidth(map) ((map)->bankwidth)
50 # define map_bankwidth(map) 2
51 # define map_bankwidth_is_large(map) (0)
52 # define map_words(map) (1)
54 #define map_bankwidth_is_2(map) (map_bankwidth(map) == 2)
55 #undef MAX_MAP_BANKWIDTH
56 #define MAX_MAP_BANKWIDTH 2
58 #define map_bankwidth_is_2(map) (0)
61 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_4
64 # define map_bankwidth(map) ((map)->bankwidth)
66 # define map_bankwidth(map) 4
67 # define map_bankwidth_is_large(map) (0)
68 # define map_words(map) (1)
70 #define map_bankwidth_is_4(map) (map_bankwidth(map) == 4)
71 #undef MAX_MAP_BANKWIDTH
72 #define MAX_MAP_BANKWIDTH 4
74 #define map_bankwidth_is_4(map) (0)
80 #define map_calc_words(map) ((map_bankwidth(map) + (sizeof(unsigned long)-1))/ sizeof(unsigned long))
82 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
85 # define map_bankwidth(map) ((map)->bankwidth)
86 # if BITS_PER_LONG < 64
87 # undef map_bankwidth_is_large
88 # define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
90 # define map_words(map) map_calc_words(map)
93 # define map_bankwidth(map) 8
94 # define map_bankwidth_is_large(map) (BITS_PER_LONG < 64)
95 # define map_words(map) map_calc_words(map)
97 #define map_bankwidth_is_8(map) (map_bankwidth(map) == 8)
98 #undef MAX_MAP_BANKWIDTH
99 #define MAX_MAP_BANKWIDTH 8
101 #define map_bankwidth_is_8(map) (0)
104 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_16
105 # ifdef map_bankwidth
106 # undef map_bankwidth
107 # define map_bankwidth(map) ((map)->bankwidth)
108 # undef map_bankwidth_is_large
109 # define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
111 # define map_words(map) map_calc_words(map)
113 # define map_bankwidth(map) 16
114 # define map_bankwidth_is_large(map) (1)
115 # define map_words(map) map_calc_words(map)
117 #define map_bankwidth_is_16(map) (map_bankwidth(map) == 16)
118 #undef MAX_MAP_BANKWIDTH
119 #define MAX_MAP_BANKWIDTH 16
121 #define map_bankwidth_is_16(map) (0)
124 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
125 # ifdef map_bankwidth
126 # undef map_bankwidth
127 # define map_bankwidth(map) ((map)->bankwidth)
128 # undef map_bankwidth_is_large
129 # define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
131 # define map_words(map) map_calc_words(map)
133 # define map_bankwidth(map) 32
134 # define map_bankwidth_is_large(map) (1)
135 # define map_words(map) map_calc_words(map)
137 #define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
138 #undef MAX_MAP_BANKWIDTH
139 #define MAX_MAP_BANKWIDTH 32
141 #define map_bankwidth_is_32(map) (0)
144 #ifndef map_bankwidth
145 #warning "No CONFIG_MTD_MAP_BANK_WIDTH_xx selected. No NOR chip support can work"
146 static inline int map_bankwidth(
void *
map)
151 #define map_bankwidth_is_large(map) (0)
152 #define map_words(map) (0)
153 #define MAX_MAP_BANKWIDTH 1
156 static inline int map_bankwidth_supported(
int w)
159 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
162 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_2
165 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_4
168 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
171 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_16
174 #ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
184 #define MAX_MAP_LONGS ( ((MAX_MAP_BANKWIDTH*8) + BITS_PER_LONG - 1) / BITS_PER_LONG )
212 #define NO_XIP (-1UL)
223 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS
266 #define ENABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 1); } while(0)
267 #define DISABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 0); } while(0)
269 #define INVALIDATE_CACHED_RANGE(map, from, size) \
270 do { if(map->inval_cache) map->inval_cache(map, from, size); } while(0)
277 if (val1.
x[i] != val2.
x[i])
289 r.
x[
i] = val1.
x[
i] & val2.
x[
i];
300 r.
x[
i] = val1.
x[
i] & ~val2.
x[
i];
311 r.
x[
i] = val1.
x[
i] | val2.
x[
i];
316 #define map_word_andequal(m, a, b, z) map_word_equal(m, z, map_word_and(m, a, b))
323 if (val1.
x[i] & val2.
x[i])
334 r.
x[0] = *(
unsigned char *)ptr;
339 #if BITS_PER_LONG >= 64
354 char *
dest = (
char *)&orig;
355 memcpy(dest+start, buf, len);
357 for (i=start; i < start+len; i++) {
359 #ifdef __LITTLE_ENDIAN
362 bitpos = (map_bankwidth(map)-1-
i)*8;
364 orig.
x[0] &= ~(0xff << bitpos);
365 orig.
x[0] |= buf[i-
start] << bitpos;
371 #if BITS_PER_LONG < 64
372 #define MAP_FF_LIMIT 4
374 #define MAP_FF_LIMIT 8
383 int bw = 8 * map_bankwidth(map);
384 r.
x[0] = (1 << bw) - 1;
392 static inline map_word inline_map_read(
struct map_info *map,
unsigned long ofs)
402 #if BITS_PER_LONG >= 64
414 static inline void inline_map_write(
struct map_info *map,
const map_word datum,
unsigned long ofs)
422 #if BITS_PER_LONG >= 64
431 static inline void inline_map_copy_from(
struct map_info *map,
void *to,
unsigned long from,
ssize_t len)
439 static inline void inline_map_copy_to(
struct map_info *map,
unsigned long to,
const void *from,
ssize_t len)
444 #ifdef CONFIG_MTD_COMPLEX_MAPPINGS
445 #define map_read(map, ofs) (map)->read(map, ofs)
446 #define map_copy_from(map, to, from, len) (map)->copy_from(map, to, from, len)
447 #define map_write(map, datum, ofs) (map)->write(map, datum, ofs)
448 #define map_copy_to(map, to, from, len) (map)->copy_to(map, to, from, len)
451 #define map_is_linear(map) (map->phys != NO_XIP)
454 #define map_read(map, ofs) inline_map_read(map, ofs)
455 #define map_copy_from(map, to, from, len) inline_map_copy_from(map, to, from, len)
456 #define map_write(map, datum, ofs) inline_map_write(map, datum, ofs)
457 #define map_copy_to(map, to, from, len) inline_map_copy_to(map, to, from, len)
460 #define simple_map_init(map) BUG_ON(!map_bankwidth_supported((map)->bankwidth))
461 #define map_is_linear(map) ({ (void)(map); 1; })