| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 1 | /* | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 2 |  * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu> | 
 | 3 |  * Copyright (C) 2007-2009 PetaLogix | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 4 |  * Copyright (C) 2006 Atmark Techno, Inc. | 
 | 5 |  * | 
 | 6 |  * This file is subject to the terms and conditions of the GNU General Public | 
 | 7 |  * License. See the file "COPYING" in the main directory of this archive | 
 | 8 |  * for more details. | 
 | 9 |  */ | 
 | 10 |  | 
 | 11 | #ifndef _ASM_MICROBLAZE_IO_H | 
 | 12 | #define _ASM_MICROBLAZE_IO_H | 
 | 13 |  | 
 | 14 | #include <asm/byteorder.h> | 
 | 15 | #include <asm/page.h> | 
 | 16 | #include <linux/types.h> | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 17 | #include <linux/mm.h>          /* Get struct page {...} */ | 
| Michal Simek | 2ddafea | 2010-01-14 15:40:11 +0100 | [diff] [blame] | 18 | #include <asm-generic/iomap.h> | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 19 |  | 
| Michal Simek | a6475c1 | 2010-01-18 15:27:10 +0100 | [diff] [blame] | 20 | #ifndef CONFIG_PCI | 
 | 21 | #define _IO_BASE	0 | 
 | 22 | #define _ISA_MEM_BASE	0 | 
 | 23 | #define PCI_DRAM_OFFSET	0 | 
 | 24 | #else | 
 | 25 | #define _IO_BASE	isa_io_base | 
 | 26 | #define _ISA_MEM_BASE	isa_mem_base | 
 | 27 | #define PCI_DRAM_OFFSET	pci_dram_offset | 
 | 28 | #endif | 
 | 29 |  | 
 | 30 | extern unsigned long isa_io_base; | 
 | 31 | extern unsigned long pci_io_base; | 
 | 32 | extern unsigned long pci_dram_offset; | 
 | 33 |  | 
 | 34 | extern resource_size_t isa_mem_base; | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 35 |  | 
 | 36 | #define IO_SPACE_LIMIT (0xFFFFFFFF) | 
 | 37 |  | 
 | 38 | static inline unsigned char __raw_readb(const volatile void __iomem *addr) | 
 | 39 | { | 
 | 40 | 	return *(volatile unsigned char __force *)addr; | 
 | 41 | } | 
 | 42 | static inline unsigned short __raw_readw(const volatile void __iomem *addr) | 
 | 43 | { | 
 | 44 | 	return *(volatile unsigned short __force *)addr; | 
 | 45 | } | 
 | 46 | static inline unsigned int __raw_readl(const volatile void __iomem *addr) | 
 | 47 | { | 
 | 48 | 	return *(volatile unsigned int __force *)addr; | 
 | 49 | } | 
 | 50 | static inline unsigned long __raw_readq(const volatile void __iomem *addr) | 
 | 51 | { | 
 | 52 | 	return *(volatile unsigned long __force *)addr; | 
 | 53 | } | 
 | 54 | static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr) | 
 | 55 | { | 
 | 56 | 	*(volatile unsigned char __force *)addr = v; | 
 | 57 | } | 
 | 58 | static inline void __raw_writew(unsigned short v, volatile void __iomem *addr) | 
 | 59 | { | 
 | 60 | 	*(volatile unsigned short __force *)addr = v; | 
 | 61 | } | 
 | 62 | static inline void __raw_writel(unsigned int v, volatile void __iomem *addr) | 
 | 63 | { | 
 | 64 | 	*(volatile unsigned int __force *)addr = v; | 
 | 65 | } | 
 | 66 | static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr) | 
 | 67 | { | 
 | 68 | 	*(volatile unsigned long __force *)addr = v; | 
 | 69 | } | 
 | 70 |  | 
 | 71 | /* | 
 | 72 |  * read (readb, readw, readl, readq) and write (writeb, writew, | 
 | 73 |  * writel, writeq) accessors are for PCI and thus littel endian. | 
 | 74 |  * Linux 2.4 for Microblaze had this wrong. | 
 | 75 |  */ | 
 | 76 | static inline unsigned char readb(const volatile void __iomem *addr) | 
 | 77 | { | 
 | 78 | 	return *(volatile unsigned char __force *)addr; | 
 | 79 | } | 
 | 80 | static inline unsigned short readw(const volatile void __iomem *addr) | 
 | 81 | { | 
 | 82 | 	return le16_to_cpu(*(volatile unsigned short __force *)addr); | 
 | 83 | } | 
 | 84 | static inline unsigned int readl(const volatile void __iomem *addr) | 
 | 85 | { | 
 | 86 | 	return le32_to_cpu(*(volatile unsigned int __force *)addr); | 
 | 87 | } | 
 | 88 | static inline void writeb(unsigned char v, volatile void __iomem *addr) | 
 | 89 | { | 
 | 90 | 	*(volatile unsigned char __force *)addr = v; | 
 | 91 | } | 
 | 92 | static inline void writew(unsigned short v, volatile void __iomem *addr) | 
 | 93 | { | 
 | 94 | 	*(volatile unsigned short __force *)addr = cpu_to_le16(v); | 
 | 95 | } | 
 | 96 | static inline void writel(unsigned int v, volatile void __iomem *addr) | 
 | 97 | { | 
 | 98 | 	*(volatile unsigned int __force *)addr = cpu_to_le32(v); | 
 | 99 | } | 
 | 100 |  | 
 | 101 | /* ioread and iowrite variants. thease are for now same as __raw_ | 
 | 102 |  * variants of accessors. we might check for endianess in the feature | 
 | 103 |  */ | 
 | 104 | #define ioread8(addr)		__raw_readb((u8 *)(addr)) | 
 | 105 | #define ioread16(addr)		__raw_readw((u16 *)(addr)) | 
 | 106 | #define ioread32(addr)		__raw_readl((u32 *)(addr)) | 
 | 107 | #define iowrite8(v, addr)	__raw_writeb((u8)(v), (u8 *)(addr)) | 
 | 108 | #define iowrite16(v, addr)	__raw_writew((u16)(v), (u16 *)(addr)) | 
 | 109 | #define iowrite32(v, addr)	__raw_writel((u32)(v), (u32 *)(addr)) | 
 | 110 |  | 
| John Linn | 7a325aa | 2010-04-07 11:03:15 +0200 | [diff] [blame] | 111 | #define ioread16be(addr)	__raw_readw((u16 *)(addr)) | 
 | 112 | #define ioread32be(addr)	__raw_readl((u32 *)(addr)) | 
 | 113 | #define iowrite16be(v, addr)	__raw_writew((u16)(v), (u16 *)(addr)) | 
 | 114 | #define iowrite32be(v, addr)	__raw_writel((u32)(v), (u32 *)(addr)) | 
 | 115 |  | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 116 | /* These are the definitions for the x86 IO instructions | 
 | 117 |  * inb/inw/inl/outb/outw/outl, the "string" versions | 
 | 118 |  * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions | 
 | 119 |  * inb_p/inw_p/... | 
 | 120 |  * The macros don't do byte-swapping. | 
 | 121 |  */ | 
 | 122 | #define inb(port)		readb((u8 *)((port))) | 
 | 123 | #define outb(val, port)		writeb((val), (u8 *)((unsigned long)(port))) | 
 | 124 | #define inw(port)		readw((u16 *)((port))) | 
 | 125 | #define outw(val, port)		writew((val), (u16 *)((unsigned long)(port))) | 
 | 126 | #define inl(port)		readl((u32 *)((port))) | 
 | 127 | #define outl(val, port)		writel((val), (u32 *)((unsigned long)(port))) | 
 | 128 |  | 
 | 129 | #define inb_p(port)		inb((port)) | 
 | 130 | #define outb_p(val, port)	outb((val), (port)) | 
 | 131 | #define inw_p(port)		inw((port)) | 
 | 132 | #define outw_p(val, port)	outw((val), (port)) | 
 | 133 | #define inl_p(port)		inl((port)) | 
 | 134 | #define outl_p(val, port)	outl((val), (port)) | 
 | 135 |  | 
 | 136 | #define memset_io(a, b, c)	memset((void *)(a), (b), (c)) | 
 | 137 | #define memcpy_fromio(a, b, c)	memcpy((a), (void *)(b), (c)) | 
 | 138 | #define memcpy_toio(a, b, c)	memcpy((void *)(a), (b), (c)) | 
 | 139 |  | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 140 | #ifdef CONFIG_MMU | 
 | 141 |  | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 142 | #define phys_to_virt(addr)	((void *)__phys_to_virt(addr)) | 
 | 143 | #define virt_to_phys(addr)	((unsigned long)__virt_to_phys(addr)) | 
 | 144 | #define virt_to_bus(addr)	((unsigned long)__virt_to_phys(addr)) | 
 | 145 |  | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 146 | #define page_to_bus(page)	(page_to_phys(page)) | 
 | 147 | #define bus_to_virt(addr)	(phys_to_virt(addr)) | 
 | 148 |  | 
 | 149 | extern void iounmap(void *addr); | 
 | 150 | /*extern void *__ioremap(phys_addr_t address, unsigned long size, | 
 | 151 | 		unsigned long flags);*/ | 
 | 152 | extern void __iomem *ioremap(phys_addr_t address, unsigned long size); | 
 | 153 | #define ioremap_writethrough(addr, size) ioremap((addr), (size)) | 
 | 154 | #define ioremap_nocache(addr, size)      ioremap((addr), (size)) | 
 | 155 | #define ioremap_fullcache(addr, size)    ioremap((addr), (size)) | 
 | 156 |  | 
 | 157 | #else /* CONFIG_MMU */ | 
 | 158 |  | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 159 | /** | 
 | 160 |  *	virt_to_phys - map virtual addresses to physical | 
 | 161 |  *	@address: address to remap | 
 | 162 |  * | 
 | 163 |  *	The returned physical address is the physical (CPU) mapping for | 
 | 164 |  *	the memory address given. It is only valid to use this function on | 
 | 165 |  *	addresses directly mapped or allocated via kmalloc. | 
 | 166 |  * | 
 | 167 |  *	This function does not give bus mappings for DMA transfers. In | 
 | 168 |  *	almost all conceivable cases a device driver should not be using | 
 | 169 |  *	this function | 
 | 170 |  */ | 
 | 171 | static inline unsigned long __iomem virt_to_phys(volatile void *address) | 
 | 172 | { | 
 | 173 | 	return __pa((unsigned long)address); | 
 | 174 | } | 
 | 175 |  | 
 | 176 | #define virt_to_bus virt_to_phys | 
 | 177 |  | 
 | 178 | /** | 
 | 179 |  *	phys_to_virt - map physical address to virtual | 
 | 180 |  *	@address: address to remap | 
 | 181 |  * | 
 | 182 |  *	The returned virtual address is a current CPU mapping for | 
 | 183 |  *	the memory address given. It is only valid to use this function on | 
 | 184 |  *	addresses that have a kernel mapping | 
 | 185 |  * | 
 | 186 |  *	This function does not handle bus mappings for DMA transfers. In | 
 | 187 |  *	almost all conceivable cases a device driver should not be using | 
 | 188 |  *	this function | 
 | 189 |  */ | 
 | 190 | static inline void *phys_to_virt(unsigned long address) | 
 | 191 | { | 
 | 192 | 	return (void *)__va(address); | 
 | 193 | } | 
 | 194 |  | 
 | 195 | #define bus_to_virt(a) phys_to_virt(a) | 
 | 196 |  | 
 | 197 | static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size, | 
 | 198 | 			unsigned long flags) | 
 | 199 | { | 
 | 200 | 	return (void *)address; | 
 | 201 | } | 
 | 202 |  | 
 | 203 | #define ioremap(physaddr, size)	((void __iomem *)(unsigned long)(physaddr)) | 
 | 204 | #define iounmap(addr)		((void)0) | 
 | 205 | #define ioremap_nocache(physaddr, size)	ioremap(physaddr, size) | 
 | 206 |  | 
| Michal Simek | dc95be1 | 2009-05-26 16:30:16 +0200 | [diff] [blame] | 207 | #endif /* CONFIG_MMU */ | 
 | 208 |  | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 209 | /* | 
 | 210 |  * Convert a physical pointer to a virtual kernel pointer for /dev/mem | 
 | 211 |  * access | 
 | 212 |  */ | 
 | 213 | #define xlate_dev_mem_ptr(p)	__va(p) | 
 | 214 |  | 
 | 215 | /* | 
 | 216 |  * Convert a virtual cached pointer to an uncached pointer | 
 | 217 |  */ | 
 | 218 | #define xlate_dev_kmem_ptr(p)	p | 
 | 219 |  | 
 | 220 | /* | 
 | 221 |  * Big Endian | 
 | 222 |  */ | 
 | 223 | #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a)) | 
 | 224 | #define out_be16(a, v) __raw_writew((v), (a)) | 
 | 225 |  | 
 | 226 | #define in_be32(a) __raw_readl((const void __iomem __force *)(a)) | 
 | 227 | #define in_be16(a) __raw_readw(a) | 
 | 228 |  | 
| Julie Zhu | afc26cb | 2009-07-27 11:45:32 -0600 | [diff] [blame] | 229 | #define writel_be(v, a)	out_be32((__force unsigned *)a, v) | 
 | 230 | #define readl_be(a)	in_be32((__force unsigned *)a) | 
 | 231 |  | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 232 | /* | 
 | 233 |  * Little endian | 
 | 234 |  */ | 
 | 235 |  | 
| Steven J. Magnani | 83b4d17 | 2010-02-22 09:25:42 -0600 | [diff] [blame] | 236 | #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a)) | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 237 | #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a)) | 
 | 238 |  | 
 | 239 | #define in_le32(a) __le32_to_cpu(__raw_readl(a)) | 
 | 240 | #define in_le16(a) __le16_to_cpu(__raw_readw(a)) | 
 | 241 |  | 
 | 242 | /* Byte ops */ | 
 | 243 | #define out_8(a, v) __raw_writeb((v), (a)) | 
 | 244 | #define in_8(a) __raw_readb(a) | 
 | 245 |  | 
| Michal Simek | ac2e7c9 | 2010-08-17 11:48:36 +0200 | [diff] [blame] | 246 | #define mmiowb() | 
 | 247 |  | 
| Michal Simek | 2ddafea | 2010-01-14 15:40:11 +0100 | [diff] [blame] | 248 | #define ioport_map(port, nr)	((void __iomem *)(port)) | 
 | 249 | #define ioport_unmap(addr) | 
| Michal Simek | 2c572c2 | 2009-03-27 14:25:33 +0100 | [diff] [blame] | 250 |  | 
 | 251 | #endif /* _ASM_MICROBLAZE_IO_H */ |