1 /* 2 * Copyright (c) 2014-2016 François Tigeot 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _ASM_IO_H_ 28 #define _ASM_IO_H_ 29 30 #include <machine/pmap.h> 31 #include <vm/pmap.h> 32 #include <vm/vm.h> 33 34 #include <linux/types.h> 35 #include <asm/page.h> 36 37 #define ioread8(addr) *(volatile uint8_t *)((char *)addr) 38 #define ioread16(addr) *(volatile uint16_t *)((char *)addr) 39 #define ioread32(addr) *(volatile uint32_t *)((char *)addr) 40 41 #define iowrite8(data, addr) \ 42 do { \ 43 *(volatile uint8_t *)((char *)addr) = data; \ 44 } while (0) 45 46 #define iowrite16(data, addr) \ 47 do { \ 48 *(volatile uint16_t *)((char *)addr) = data; \ 49 } while (0) 50 51 #define iowrite32(data, addr) \ 52 do { \ 53 *(volatile uint32_t *)((char *)addr) = data; \ 54 } while (0) 55 56 #include <linux/vmalloc.h> 57 58 /* ioremap function family: map bus addresses into CPU space */ 59 60 struct iomap { 61 vm_paddr_t paddr; 62 int npages; 63 void *pmap_addr; 64 SLIST_ENTRY(iomap) im_iomaps; 65 }; 66 67 struct iomap *__ioremap_common(unsigned long phys_addr, unsigned long size); 68 69 static inline void *ioremap_nocache(resource_size_t phys_addr, unsigned long size) 70 { 71 struct iomap *imp; 72 73 imp = __ioremap_common(phys_addr, size); 74 imp->pmap_addr = pmap_mapdev_uncacheable(phys_addr, size); 75 return imp->pmap_addr; 76 } 77 78 static inline void __iomem *ioremap_wc(resource_size_t phys_addr, unsigned long size) 79 { 80 struct iomap *imp; 81 82 imp = __ioremap_common(phys_addr, size); 83 imp->pmap_addr = pmap_mapdev_attr(phys_addr, size, PAT_WRITE_COMBINING); 84 return imp->pmap_addr; 85 } 86 87 static inline void __iomem *ioremap(resource_size_t offset, unsigned long size) 88 { 89 return ioremap_nocache(offset, size); 90 } 91 92 void iounmap(void __iomem *ptr); 93 94 /* XXX these should have volatile */ 95 #define memset_io(a, b, c) memset((a), (b), (c)) 96 #define memcpy_fromio(a, b, c) memcpy((a), (b), (c)) 97 #define memcpy_toio(a, b, c) memcpy((a), (b), (c)) 98 99 #define mmiowb cpu_sfence 100 101 #endif /* _ASM_IO_H_ */ 102