1 /* 2 * IO header file 3 * 4 * Copyright (C) 2001-2007 Tensilica Inc. 5 * Based on the Linux/Xtensa version of this header. 6 * 7 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #ifndef _XTENSA_IO_H 11 #define _XTENSA_IO_H 12 13 #include <linux/types.h> 14 #include <asm/byteorder.h> 15 16 /* 17 * swap functions to change byte order from little-endian to big-endian and 18 * vice versa. 19 */ 20 21 static inline unsigned short _swapw(unsigned short v) 22 { 23 return (v << 8) | (v >> 8); 24 } 25 26 static inline unsigned int _swapl(unsigned int v) 27 { 28 return (v << 24) | ((v & 0xff00) << 8) | 29 ((v >> 8) & 0xff00) | (v >> 24); 30 } 31 32 /* 33 * Generic I/O 34 */ 35 36 #define readb(addr) \ 37 ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; }) 38 #define readw(addr) \ 39 ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; }) 40 #define readl(addr) \ 41 ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; }) 42 #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b)) 43 #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b)) 44 #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b)) 45 46 #define __raw_readb readb 47 #define __raw_readw readw 48 #define __raw_readl readl 49 #define __raw_writeb writeb 50 #define __raw_writew writew 51 #define __raw_writel writel 52 53 /* These are the definitions for the x86 IO instructions 54 * inb/inw/inl/outb/outw/outl, the "string" versions 55 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions 56 * inb_p/inw_p/... 57 * The macros don't do byte-swapping. 58 */ 59 60 #define inb(port) readb((u8 *)((port))) 61 #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port))) 62 #define inw(port) readw((u16 *)((port))) 63 #define outw(val, port) writew((val), (u16 *)((unsigned long)(port))) 64 #define inl(port) readl((u32 *)((port))) 65 #define outl(val, port) writel((val), (u32 *)((unsigned long)(port))) 66 67 #define inb_p(port) inb((port)) 68 #define outb_p(val, port) outb((val), (port)) 69 #define inw_p(port) inw((port)) 70 #define outw_p(val, port) outw((val), (port)) 71 #define inl_p(port) inl((port)) 72 #define outl_p(val, port) outl((val), (port)) 73 74 void insb(unsigned long port, void *dst, unsigned long count); 75 void insw(unsigned long port, void *dst, unsigned long count); 76 void insl(unsigned long port, void *dst, unsigned long count); 77 void outsb(unsigned long port, const void *src, unsigned long count); 78 void outsw(unsigned long port, const void *src, unsigned long count); 79 void outsl(unsigned long port, const void *src, unsigned long count); 80 81 #define IO_SPACE_LIMIT ~0 82 83 #define memset_io(a, b, c) memset((void *)(a), (b), (c)) 84 #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) 85 #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) 86 87 /* At this point the Xtensa doesn't provide byte swap instructions */ 88 89 #ifdef __XTENSA_EB__ 90 # define in_8(addr) (*(u8 *)(addr)) 91 # define in_le16(addr) _swapw(*(u16 *)(addr)) 92 # define in_le32(addr) _swapl(*(u32 *)(addr)) 93 # define out_8(b, addr) *(u8 *)(addr) = (b) 94 # define out_le16(b, addr) *(u16 *)(addr) = _swapw(b) 95 # define out_le32(b, addr) *(u32 *)(addr) = _swapl(b) 96 #elif defined(__XTENSA_EL__) 97 # define in_8(addr) (*(u8 *)(addr)) 98 # define in_le16(addr) (*(u16 *)(addr)) 99 # define in_le32(addr) (*(u32 *)(addr)) 100 # define out_8(b, addr) *(u8 *)(addr) = (b) 101 # define out_le16(b, addr) *(u16 *)(addr) = (b) 102 # define out_le32(b, addr) *(u32 *)(addr) = (b) 103 #else 104 # error processor byte order undefined! 105 #endif 106 107 108 /* 109 * Convert a physical pointer to a virtual kernel pointer for /dev/mem access 110 */ 111 #define xlate_dev_mem_ptr(p) __va(p) 112 113 /* 114 * Convert a virtual cached pointer to an uncached pointer 115 */ 116 #define xlate_dev_kmem_ptr(p) p 117 118 /* 119 * Dummy function to keep U-Boot's cfi_flash.c driver happy. 120 */ 121 static inline void sync(void) 122 { 123 } 124 125 #include <asm-generic/io.h> 126 127 #endif /* _XTENSA_IO_H */ 128