14baa9922SRussell King /* 24baa9922SRussell King * arch/arm/include/asm/io.h 34baa9922SRussell King * 44baa9922SRussell King * Copyright (C) 1996-2000 Russell King 54baa9922SRussell King * 64baa9922SRussell King * This program is free software; you can redistribute it and/or modify 74baa9922SRussell King * it under the terms of the GNU General Public License version 2 as 84baa9922SRussell King * published by the Free Software Foundation. 94baa9922SRussell King * 104baa9922SRussell King * Modifications: 114baa9922SRussell King * 16-Sep-1996 RMK Inlined the inx/outx functions & optimised for both 124baa9922SRussell King * constant addresses and variable addresses. 134baa9922SRussell King * 04-Dec-1997 RMK Moved a lot of this stuff to the new architecture 144baa9922SRussell King * specific IO header files. 154baa9922SRussell King * 27-Mar-1999 PJB Second parameter of memcpy_toio is const.. 164baa9922SRussell King * 04-Apr-1999 PJB Added check_signature. 174baa9922SRussell King * 12-Dec-1999 RMK More cleanups 184baa9922SRussell King * 18-Jun-2000 RMK Removed virt_to_* and friends definitions 194baa9922SRussell King * 05-Oct-2004 BJD Moved memory string functions to use void __iomem 204baa9922SRussell King */ 214baa9922SRussell King #ifndef __ASM_ARM_IO_H 224baa9922SRussell King #define __ASM_ARM_IO_H 234baa9922SRussell King 244baa9922SRussell King #ifdef __KERNEL__ 254baa9922SRussell King 264baa9922SRussell King #include <linux/types.h> 274baa9922SRussell King #include <asm/byteorder.h> 284baa9922SRussell King #include <asm/memory.h> 2979f64dbfSCatalin Marinas #include <asm/system.h> 304baa9922SRussell King 314baa9922SRussell King /* 324baa9922SRussell King * ISA I/O bus memory addresses are 1:1 with the physical address. 334baa9922SRussell King */ 344baa9922SRussell King #define isa_virt_to_bus virt_to_phys 354baa9922SRussell King #define isa_page_to_bus page_to_phys 364baa9922SRussell King #define isa_bus_to_virt phys_to_virt 374baa9922SRussell King 384baa9922SRussell King /* 394baa9922SRussell King * Generic IO read/write. These perform native-endian accesses. Note 404baa9922SRussell King * that some architectures will want to re-define __raw_{read,write}w. 414baa9922SRussell King */ 424baa9922SRussell King extern void __raw_writesb(void __iomem *addr, const void *data, int bytelen); 434baa9922SRussell King extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen); 444baa9922SRussell King extern void __raw_writesl(void __iomem *addr, const void *data, int longlen); 454baa9922SRussell King 464baa9922SRussell King extern void __raw_readsb(const void __iomem *addr, void *data, int bytelen); 474baa9922SRussell King extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen); 484baa9922SRussell King extern void __raw_readsl(const void __iomem *addr, void *data, int longlen); 494baa9922SRussell King 504baa9922SRussell King #define __raw_writeb(v,a) (__chk_io_ptr(a), *(volatile unsigned char __force *)(a) = (v)) 514baa9922SRussell King #define __raw_writew(v,a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v)) 524baa9922SRussell King #define __raw_writel(v,a) (__chk_io_ptr(a), *(volatile unsigned int __force *)(a) = (v)) 534baa9922SRussell King 544baa9922SRussell King #define __raw_readb(a) (__chk_io_ptr(a), *(volatile unsigned char __force *)(a)) 554baa9922SRussell King #define __raw_readw(a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a)) 564baa9922SRussell King #define __raw_readl(a) (__chk_io_ptr(a), *(volatile unsigned int __force *)(a)) 574baa9922SRussell King 584baa9922SRussell King /* 594baa9922SRussell King * Architecture ioremap implementation. 604baa9922SRussell King */ 614baa9922SRussell King #define MT_DEVICE 0 624baa9922SRussell King #define MT_DEVICE_NONSHARED 1 634baa9922SRussell King #define MT_DEVICE_CACHED 2 64db5b7169SRussell King #define MT_DEVICE_WC 3 654baa9922SRussell King /* 66db5b7169SRussell King * types 4 onwards can be found in asm/mach/map.h and are undefined 674baa9922SRussell King * for ioremap 684baa9922SRussell King */ 694baa9922SRussell King 704baa9922SRussell King /* 714baa9922SRussell King * __arm_ioremap takes CPU physical address. 724baa9922SRussell King * __arm_ioremap_pfn takes a Page Frame Number and an offset into that page 7331aa8fd6SRussell King * The _caller variety takes a __builtin_return_address(0) value for 7431aa8fd6SRussell King * /proc/vmalloc to use - and should only be used in non-inline functions. 754baa9922SRussell King */ 7631aa8fd6SRussell King extern void __iomem *__arm_ioremap_pfn_caller(unsigned long, unsigned long, 7731aa8fd6SRussell King size_t, unsigned int, void *); 7831aa8fd6SRussell King extern void __iomem *__arm_ioremap_caller(unsigned long, size_t, unsigned int, 7931aa8fd6SRussell King void *); 8031aa8fd6SRussell King 814baa9922SRussell King extern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int); 824baa9922SRussell King extern void __iomem *__arm_ioremap(unsigned long, size_t, unsigned int); 834baa9922SRussell King extern void __iounmap(volatile void __iomem *addr); 844baa9922SRussell King 854baa9922SRussell King /* 864baa9922SRussell King * Bad read/write accesses... 874baa9922SRussell King */ 884baa9922SRussell King extern void __readwrite_bug(const char *fn); 894baa9922SRussell King 904baa9922SRussell King /* 910560cf5aSRussell King * A typesafe __io() helper 920560cf5aSRussell King */ 930560cf5aSRussell King static inline void __iomem *__typesafe_io(unsigned long addr) 940560cf5aSRussell King { 950560cf5aSRussell King return (void __iomem *)addr; 960560cf5aSRussell King } 970560cf5aSRussell King 98c1928022SRussell King /* IO barriers */ 99c1928022SRussell King #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE 100c1928022SRussell King #define __iormb() rmb() 101c1928022SRussell King #define __iowmb() wmb() 102c1928022SRussell King #else 103c1928022SRussell King #define __iormb() do { } while (0) 104c1928022SRussell King #define __iowmb() do { } while (0) 105c1928022SRussell King #endif 106c1928022SRussell King 1070560cf5aSRussell King /* 1084baa9922SRussell King * Now, pick up the machine-defined IO definitions 1094baa9922SRussell King */ 110a09e64fbSRussell King #include <mach/io.h> 1114baa9922SRussell King 1124baa9922SRussell King /* 113*04e1c838SRussell King * This is the limit of PC card/PCI/ISA IO space, which is by default 114*04e1c838SRussell King * 64K if we have PC card, PCI or ISA support. Otherwise, default to 115*04e1c838SRussell King * zero to prevent ISA/PCI drivers claiming IO space (and potentially 116*04e1c838SRussell King * oopsing.) 117*04e1c838SRussell King * 118*04e1c838SRussell King * Only set this larger if you really need inb() et.al. to operate over 119*04e1c838SRussell King * a larger address space. Note that SOC_COMMON ioremaps each sockets 120*04e1c838SRussell King * IO space area, and so inb() et.al. must be defined to operate as per 121*04e1c838SRussell King * readb() et.al. on such platforms. 122*04e1c838SRussell King */ 123*04e1c838SRussell King #ifndef IO_SPACE_LIMIT 124*04e1c838SRussell King #if defined(CONFIG_PCMCIA_SOC_COMMON) || defined(CONFIG_PCMCIA_SOC_COMMON_MODULE) 125*04e1c838SRussell King #define IO_SPACE_LIMIT ((resource_size_t)0xffffffff) 126*04e1c838SRussell King #elif defined(CONFIG_PCI) || defined(CONFIG_ISA) || defined(CONFIG_PCCARD) 127*04e1c838SRussell King #define IO_SPACE_LIMIT ((resource_size_t)0xffff) 128*04e1c838SRussell King #else 129*04e1c838SRussell King #define IO_SPACE_LIMIT ((resource_size_t)0) 130*04e1c838SRussell King #endif 131*04e1c838SRussell King #endif 132*04e1c838SRussell King 133*04e1c838SRussell King /* 1344baa9922SRussell King * IO port access primitives 1354baa9922SRussell King * ------------------------- 1364baa9922SRussell King * 1374baa9922SRussell King * The ARM doesn't have special IO access instructions; all IO is memory 1384baa9922SRussell King * mapped. Note that these are defined to perform little endian accesses 1394baa9922SRussell King * only. Their primary purpose is to access PCI and ISA peripherals. 1404baa9922SRussell King * 1414baa9922SRussell King * Note that for a big endian machine, this implies that the following 1424baa9922SRussell King * big endian mode connectivity is in place, as described by numerous 1434baa9922SRussell King * ARM documents: 1444baa9922SRussell King * 1454baa9922SRussell King * PCI: D0-D7 D8-D15 D16-D23 D24-D31 1464baa9922SRussell King * ARM: D24-D31 D16-D23 D8-D15 D0-D7 1474baa9922SRussell King * 1484baa9922SRussell King * The machine specific io.h include defines __io to translate an "IO" 1494baa9922SRussell King * address to a memory address. 1504baa9922SRussell King * 1514baa9922SRussell King * Note that we prevent GCC re-ordering or caching values in expressions 1524baa9922SRussell King * by introducing sequence points into the in*() definitions. Note that 1534baa9922SRussell King * __raw_* do not guarantee this behaviour. 1544baa9922SRussell King * 1554baa9922SRussell King * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space. 1564baa9922SRussell King */ 1574baa9922SRussell King #ifdef __io 158c1928022SRussell King #define outb(v,p) ({ __iowmb(); __raw_writeb(v,__io(p)); }) 159c1928022SRussell King #define outw(v,p) ({ __iowmb(); __raw_writew((__force __u16) \ 160c1928022SRussell King cpu_to_le16(v),__io(p)); }) 161c1928022SRussell King #define outl(v,p) ({ __iowmb(); __raw_writel((__force __u32) \ 162c1928022SRussell King cpu_to_le32(v),__io(p)); }) 1634baa9922SRussell King 164c1928022SRussell King #define inb(p) ({ __u8 __v = __raw_readb(__io(p)); __iormb(); __v; }) 1654baa9922SRussell King #define inw(p) ({ __u16 __v = le16_to_cpu((__force __le16) \ 166c1928022SRussell King __raw_readw(__io(p))); __iormb(); __v; }) 1674baa9922SRussell King #define inl(p) ({ __u32 __v = le32_to_cpu((__force __le32) \ 168c1928022SRussell King __raw_readl(__io(p))); __iormb(); __v; }) 1694baa9922SRussell King 1704baa9922SRussell King #define outsb(p,d,l) __raw_writesb(__io(p),d,l) 1714baa9922SRussell King #define outsw(p,d,l) __raw_writesw(__io(p),d,l) 1724baa9922SRussell King #define outsl(p,d,l) __raw_writesl(__io(p),d,l) 1734baa9922SRussell King 1744baa9922SRussell King #define insb(p,d,l) __raw_readsb(__io(p),d,l) 1754baa9922SRussell King #define insw(p,d,l) __raw_readsw(__io(p),d,l) 1764baa9922SRussell King #define insl(p,d,l) __raw_readsl(__io(p),d,l) 1774baa9922SRussell King #endif 1784baa9922SRussell King 1794baa9922SRussell King #define outb_p(val,port) outb((val),(port)) 1804baa9922SRussell King #define outw_p(val,port) outw((val),(port)) 1814baa9922SRussell King #define outl_p(val,port) outl((val),(port)) 1824baa9922SRussell King #define inb_p(port) inb((port)) 1834baa9922SRussell King #define inw_p(port) inw((port)) 1844baa9922SRussell King #define inl_p(port) inl((port)) 1854baa9922SRussell King 1864baa9922SRussell King #define outsb_p(port,from,len) outsb(port,from,len) 1874baa9922SRussell King #define outsw_p(port,from,len) outsw(port,from,len) 1884baa9922SRussell King #define outsl_p(port,from,len) outsl(port,from,len) 1894baa9922SRussell King #define insb_p(port,to,len) insb(port,to,len) 1904baa9922SRussell King #define insw_p(port,to,len) insw(port,to,len) 1914baa9922SRussell King #define insl_p(port,to,len) insl(port,to,len) 1924baa9922SRussell King 1934baa9922SRussell King /* 1944baa9922SRussell King * String version of IO memory access ops: 1954baa9922SRussell King */ 1964baa9922SRussell King extern void _memcpy_fromio(void *, const volatile void __iomem *, size_t); 1974baa9922SRussell King extern void _memcpy_toio(volatile void __iomem *, const void *, size_t); 1984baa9922SRussell King extern void _memset_io(volatile void __iomem *, int, size_t); 1994baa9922SRussell King 2004baa9922SRussell King #define mmiowb() 2014baa9922SRussell King 2024baa9922SRussell King /* 2034baa9922SRussell King * Memory access primitives 2044baa9922SRussell King * ------------------------ 2054baa9922SRussell King * 2064baa9922SRussell King * These perform PCI memory accesses via an ioremap region. They don't 2074baa9922SRussell King * take an address as such, but a cookie. 2084baa9922SRussell King * 2094baa9922SRussell King * Again, this are defined to perform little endian accesses. See the 2104baa9922SRussell King * IO port primitives for more information. 2114baa9922SRussell King */ 2124baa9922SRussell King #ifdef __mem_pci 213e936771aSCatalin Marinas #define readb_relaxed(c) ({ u8 __v = __raw_readb(__mem_pci(c)); __v; }) 214e936771aSCatalin Marinas #define readw_relaxed(c) ({ u16 __v = le16_to_cpu((__force __le16) \ 2154baa9922SRussell King __raw_readw(__mem_pci(c))); __v; }) 216e936771aSCatalin Marinas #define readl_relaxed(c) ({ u32 __v = le32_to_cpu((__force __le32) \ 2174baa9922SRussell King __raw_readl(__mem_pci(c))); __v; }) 218e936771aSCatalin Marinas 219e936771aSCatalin Marinas #define writeb_relaxed(v,c) ((void)__raw_writeb(v,__mem_pci(c))) 220e936771aSCatalin Marinas #define writew_relaxed(v,c) ((void)__raw_writew((__force u16) \ 221e936771aSCatalin Marinas cpu_to_le16(v),__mem_pci(c))) 222e936771aSCatalin Marinas #define writel_relaxed(v,c) ((void)__raw_writel((__force u32) \ 223e936771aSCatalin Marinas cpu_to_le32(v),__mem_pci(c))) 224e936771aSCatalin Marinas 225b92b3612SRussell King #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; }) 226b92b3612SRussell King #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; }) 227b92b3612SRussell King #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; }) 228b92b3612SRussell King 229b92b3612SRussell King #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); }) 230b92b3612SRussell King #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); }) 231b92b3612SRussell King #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); }) 232b92b3612SRussell King 2334baa9922SRussell King #define readsb(p,d,l) __raw_readsb(__mem_pci(p),d,l) 2344baa9922SRussell King #define readsw(p,d,l) __raw_readsw(__mem_pci(p),d,l) 2354baa9922SRussell King #define readsl(p,d,l) __raw_readsl(__mem_pci(p),d,l) 2364baa9922SRussell King 2374baa9922SRussell King #define writesb(p,d,l) __raw_writesb(__mem_pci(p),d,l) 2384baa9922SRussell King #define writesw(p,d,l) __raw_writesw(__mem_pci(p),d,l) 2394baa9922SRussell King #define writesl(p,d,l) __raw_writesl(__mem_pci(p),d,l) 2404baa9922SRussell King 2414baa9922SRussell King #define memset_io(c,v,l) _memset_io(__mem_pci(c),(v),(l)) 2424baa9922SRussell King #define memcpy_fromio(a,c,l) _memcpy_fromio((a),__mem_pci(c),(l)) 2434baa9922SRussell King #define memcpy_toio(c,a,l) _memcpy_toio(__mem_pci(c),(a),(l)) 2444baa9922SRussell King 2454baa9922SRussell King #elif !defined(readb) 2464baa9922SRussell King 2474baa9922SRussell King #define readb(c) (__readwrite_bug("readb"),0) 2484baa9922SRussell King #define readw(c) (__readwrite_bug("readw"),0) 2494baa9922SRussell King #define readl(c) (__readwrite_bug("readl"),0) 2504baa9922SRussell King #define writeb(v,c) __readwrite_bug("writeb") 2514baa9922SRussell King #define writew(v,c) __readwrite_bug("writew") 2524baa9922SRussell King #define writel(v,c) __readwrite_bug("writel") 2534baa9922SRussell King 2544baa9922SRussell King #define check_signature(io,sig,len) (0) 2554baa9922SRussell King 2564baa9922SRussell King #endif /* __mem_pci */ 2574baa9922SRussell King 2584baa9922SRussell King /* 2594baa9922SRussell King * ioremap and friends. 2604baa9922SRussell King * 2614baa9922SRussell King * ioremap takes a PCI memory address, as specified in 2624baa9922SRussell King * Documentation/IO-mapping.txt. 2634baa9922SRussell King * 2644baa9922SRussell King */ 2654baa9922SRussell King #ifndef __arch_ioremap 26628257f7fSRussell King #define __arch_ioremap __arm_ioremap 26728257f7fSRussell King #define __arch_iounmap __iounmap 26828257f7fSRussell King #endif 26928257f7fSRussell King 2704baa9922SRussell King #define ioremap(cookie,size) __arch_ioremap((cookie), (size), MT_DEVICE) 2714baa9922SRussell King #define ioremap_nocache(cookie,size) __arch_ioremap((cookie), (size), MT_DEVICE) 2724baa9922SRussell King #define ioremap_cached(cookie,size) __arch_ioremap((cookie), (size), MT_DEVICE_CACHED) 2731ad77a87SLennert Buytenhek #define ioremap_wc(cookie,size) __arch_ioremap((cookie), (size), MT_DEVICE_WC) 274a0b7bd08SRussell King #define iounmap __arch_iounmap 2754baa9922SRussell King 2764baa9922SRussell King /* 2774baa9922SRussell King * io{read,write}{8,16,32} macros 2784baa9922SRussell King */ 2794baa9922SRussell King #ifndef ioread8 280b92b3612SRussell King #define ioread8(p) ({ unsigned int __v = __raw_readb(p); __iormb(); __v; }) 281b92b3612SRussell King #define ioread16(p) ({ unsigned int __v = le16_to_cpu((__force __le16)__raw_readw(p)); __iormb(); __v; }) 282b92b3612SRussell King #define ioread32(p) ({ unsigned int __v = le32_to_cpu((__force __le32)__raw_readl(p)); __iormb(); __v; }) 2834baa9922SRussell King 284b92b3612SRussell King #define iowrite8(v,p) ({ __iowmb(); (void)__raw_writeb(v, p); }) 285b92b3612SRussell King #define iowrite16(v,p) ({ __iowmb(); (void)__raw_writew((__force __u16)cpu_to_le16(v), p); }) 286b92b3612SRussell King #define iowrite32(v,p) ({ __iowmb(); (void)__raw_writel((__force __u32)cpu_to_le32(v), p); }) 2874baa9922SRussell King 2884baa9922SRussell King #define ioread8_rep(p,d,c) __raw_readsb(p,d,c) 2894baa9922SRussell King #define ioread16_rep(p,d,c) __raw_readsw(p,d,c) 2904baa9922SRussell King #define ioread32_rep(p,d,c) __raw_readsl(p,d,c) 2914baa9922SRussell King 2924baa9922SRussell King #define iowrite8_rep(p,s,c) __raw_writesb(p,s,c) 2934baa9922SRussell King #define iowrite16_rep(p,s,c) __raw_writesw(p,s,c) 2944baa9922SRussell King #define iowrite32_rep(p,s,c) __raw_writesl(p,s,c) 2954baa9922SRussell King 2964baa9922SRussell King extern void __iomem *ioport_map(unsigned long port, unsigned int nr); 2974baa9922SRussell King extern void ioport_unmap(void __iomem *addr); 2984baa9922SRussell King #endif 2994baa9922SRussell King 3004baa9922SRussell King struct pci_dev; 3014baa9922SRussell King 3024baa9922SRussell King extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen); 3034baa9922SRussell King extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr); 3044baa9922SRussell King 3054baa9922SRussell King /* 3064baa9922SRussell King * can the hardware map this into one segment or not, given no other 3074baa9922SRussell King * constraints. 3084baa9922SRussell King */ 3094baa9922SRussell King #define BIOVEC_MERGEABLE(vec1, vec2) \ 3104baa9922SRussell King ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2))) 3114baa9922SRussell King 3124baa9922SRussell King #ifdef CONFIG_MMU 3134baa9922SRussell King #define ARCH_HAS_VALID_PHYS_ADDR_RANGE 3144baa9922SRussell King extern int valid_phys_addr_range(unsigned long addr, size_t size); 3154baa9922SRussell King extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size); 316087aaffcSNicolas Pitre extern int devmem_is_allowed(unsigned long pfn); 3174baa9922SRussell King #endif 3184baa9922SRussell King 3194baa9922SRussell King /* 3204baa9922SRussell King * Convert a physical pointer to a virtual kernel pointer for /dev/mem 3214baa9922SRussell King * access 3224baa9922SRussell King */ 3234baa9922SRussell King #define xlate_dev_mem_ptr(p) __va(p) 3244baa9922SRussell King 3254baa9922SRussell King /* 3264baa9922SRussell King * Convert a virtual cached pointer to an uncached pointer 3274baa9922SRussell King */ 3284baa9922SRussell King #define xlate_dev_kmem_ptr(p) p 3294baa9922SRussell King 3304baa9922SRussell King /* 3314baa9922SRussell King * Register ISA memory and port locations for glibc iopl/inb/outb 3324baa9922SRussell King * emulation. 3334baa9922SRussell King */ 3344baa9922SRussell King extern void register_isa_ports(unsigned int mmio, unsigned int io, 3354baa9922SRussell King unsigned int io_shift); 3364baa9922SRussell King 3374baa9922SRussell King #endif /* __KERNEL__ */ 3384baa9922SRussell King #endif /* __ASM_ARM_IO_H */ 339