4 #include <asm/page.h> /* for __va, __pa */
6 #include <asm-generic/iomap.h>
7 #include <linux/kernel.h>
9 struct cris_io_operations
11 u32 (*read_mem
)(void *addr
, int size
);
12 void (*write_mem
)(u32 val
, int size
, void *addr
);
13 u32 (*read_io
)(u32 port
, void *addr
, int size
, int count
);
14 void (*write_io
)(u32 port
, void *addr
, int size
, int count
);
18 extern struct cris_io_operations
*cris_iops
;
20 #define cris_iops ((struct cris_io_operations*)NULL)
24 * Change virtual addresses to physical addresses and vv.
27 static inline unsigned long virt_to_phys(volatile void * address
)
32 static inline void * phys_to_virt(unsigned long address
)
37 extern void __iomem
* __ioremap(unsigned long offset
, unsigned long size
, unsigned long flags
);
38 extern void __iomem
* __ioremap_prot(unsigned long phys_addr
, unsigned long size
, pgprot_t prot
);
40 static inline void __iomem
* ioremap (unsigned long offset
, unsigned long size
)
42 return __ioremap(offset
, size
, 0);
45 extern void iounmap(volatile void * __iomem addr
);
47 extern void __iomem
* ioremap_nocache(unsigned long offset
, unsigned long size
);
50 * IO bus memory addresses are also 1:1 with the physical address
52 #define virt_to_bus virt_to_phys
53 #define bus_to_virt phys_to_virt
56 * readX/writeX() are used to access memory mapped devices. On some
57 * architectures the memory mapped IO stuff needs to be accessed
58 * differently. On the CRIS architecture, we just read/write the
59 * memory location directly.
62 #define PCI_SPACE(x) ((((unsigned)(x)) & 0x10000000) == 0x10000000)
64 #define PCI_SPACE(x) 0
66 static inline unsigned char readb(const volatile void __iomem
*addr
)
68 if (PCI_SPACE(addr
) && cris_iops
)
69 return cris_iops
->read_mem((void*)addr
, 1);
71 return *(volatile unsigned char __force
*) addr
;
73 static inline unsigned short readw(const volatile void __iomem
*addr
)
75 if (PCI_SPACE(addr
) && cris_iops
)
76 return cris_iops
->read_mem((void*)addr
, 2);
78 return *(volatile unsigned short __force
*) addr
;
80 static inline unsigned int readl(const volatile void __iomem
*addr
)
82 if (PCI_SPACE(addr
) && cris_iops
)
83 return cris_iops
->read_mem((void*)addr
, 4);
85 return *(volatile unsigned int __force
*) addr
;
87 #define readb_relaxed(addr) readb(addr)
88 #define readw_relaxed(addr) readw(addr)
89 #define readl_relaxed(addr) readl(addr)
90 #define __raw_readb readb
91 #define __raw_readw readw
92 #define __raw_readl readl
94 static inline void writeb(unsigned char b
, volatile void __iomem
*addr
)
96 if (PCI_SPACE(addr
) && cris_iops
)
97 cris_iops
->write_mem(b
, 1, (void*)addr
);
99 *(volatile unsigned char __force
*) addr
= b
;
101 static inline void writew(unsigned short b
, volatile void __iomem
*addr
)
103 if (PCI_SPACE(addr
) && cris_iops
)
104 cris_iops
->write_mem(b
, 2, (void*)addr
);
106 *(volatile unsigned short __force
*) addr
= b
;
108 static inline void writel(unsigned int b
, volatile void __iomem
*addr
)
110 if (PCI_SPACE(addr
) && cris_iops
)
111 cris_iops
->write_mem(b
, 4, (void*)addr
);
113 *(volatile unsigned int __force
*) addr
= b
;
115 #define __raw_writeb writeb
116 #define __raw_writew writew
117 #define __raw_writel writel
121 #define memset_io(a,b,c) memset((void *)(a),(b),(c))
122 #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
123 #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
126 /* I/O port access. Normally there is no I/O space on CRIS but when
127 * Cardbus/PCI is enabled the request is passed through the bridge.
130 #define IO_SPACE_LIMIT 0xffff
131 #define inb(port) (cris_iops ? cris_iops->read_io(port,NULL,1,1) : 0)
132 #define inw(port) (cris_iops ? cris_iops->read_io(port,NULL,2,1) : 0)
133 #define inl(port) (cris_iops ? cris_iops->read_io(port,NULL,4,1) : 0)
134 #define insb(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,1,count) : 0)
135 #define insw(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,2,count) : 0)
136 #define insl(port,addr,count) (cris_iops ? cris_iops->read_io(port,addr,4,count) : 0)
137 static inline void outb(unsigned char data
, unsigned int port
)
140 cris_iops
->write_io(port
, (void *) &data
, 1, 1);
142 static inline void outw(unsigned short data
, unsigned int port
)
145 cris_iops
->write_io(port
, (void *) &data
, 2, 1);
147 static inline void outl(unsigned int data
, unsigned int port
)
150 cris_iops
->write_io(port
, (void *) &data
, 4, 1);
152 static inline void outsb(unsigned int port
, const void *addr
,
156 cris_iops
->write_io(port
, (void *)addr
, 1, count
);
158 static inline void outsw(unsigned int port
, const void *addr
,
162 cris_iops
->write_io(port
, (void *)addr
, 2, count
);
164 static inline void outsl(unsigned int port
, const void *addr
,
168 cris_iops
->write_io(port
, (void *)addr
, 4, count
);
171 #define inb_p(port) inb(port)
172 #define outb_p(val, port) outb((val), (port))
175 * Convert a physical pointer to a virtual kernel pointer for /dev/mem
178 #define xlate_dev_mem_ptr(p) __va(p)
181 * Convert a virtual cached pointer to an uncached pointer
183 #define xlate_dev_kmem_ptr(p) p