ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / map_funcs.c
1 /*
2  * $Id: map_funcs.c,v 1.2 2003/05/21 15:15:07 dwmw2 Exp $
3  *
4  * Out-of-line map I/O functions for simple maps when CONFIG_COMPLEX_MAPPINGS
5  * is enabled.
6  */
7
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/config.h>
11 #include <linux/types.h>
12 #include <linux/string.h>
13 #include <asm/io.h>
14
15 #include <linux/mtd/map.h>
16 #include <linux/mtd/cfi.h>
17
18 static u8 simple_map_read8(struct map_info *map, unsigned long ofs)
19 {
20         return __raw_readb(map->virt + ofs);
21 }
22
23 static u16 simple_map_read16(struct map_info *map, unsigned long ofs)
24 {
25         return __raw_readw(map->virt + ofs);
26 }
27
28 static u32 simple_map_read32(struct map_info *map, unsigned long ofs)
29 {
30         return __raw_readl(map->virt + ofs);
31 }
32
33 static u64 simple_map_read64(struct map_info *map, unsigned long ofs)
34 {
35 #ifndef CONFIG_MTD_CFI_B8 /* 64-bit mappings */
36         BUG();
37         return 0;
38 #else
39         return __raw_readll(map->virt + ofs);
40 #endif
41 }
42
43 static void simple_map_write8(struct map_info *map, u8 datum, unsigned long ofs)
44 {
45         __raw_writeb(datum, map->virt + ofs);
46         mb();
47 }
48
49 static void simple_map_write16(struct map_info *map, u16 datum, unsigned long ofs)
50 {
51         __raw_writew(datum, map->virt + ofs);
52         mb();
53 }
54
55 static void simple_map_write32(struct map_info *map, u32 datum, unsigned long ofs)
56 {
57         __raw_writel(datum, map->virt + ofs);
58         mb();
59 }
60
61 static void simple_map_write64(struct map_info *map, u64 datum, unsigned long ofs)
62 {
63 #ifndef CONFIG_MTD_CFI_B8 /* 64-bit mappings */
64         BUG();
65 #else
66         __raw_writell(datum, map->virt + ofs);
67         mb();
68 #endif /* CFI_B8 */
69 }
70
71 static void simple_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
72 {
73         memcpy_fromio(to, map->virt + from, len);
74 }
75
76 static void simple_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
77 {
78         memcpy_toio(map->virt + to, from, len);
79 }
80
81 void simple_map_init(struct map_info *map)
82 {
83         map->read8 = simple_map_read8;
84         map->read16 = simple_map_read16;
85         map->read32 = simple_map_read32;
86         map->read64 = simple_map_read64;
87         map->write8 = simple_map_write8;
88         map->write16 = simple_map_write16;
89         map->write32 = simple_map_write32;
90         map->write64 = simple_map_write64;
91         map->copy_from = simple_map_copy_from;
92         map->copy_to = simple_map_copy_to;
93 }
94
95 EXPORT_SYMBOL(simple_map_init);
96 MODULE_LICENSE("GPL");