4 * Copyright (C) 2001-2007 Tensilica Inc.
5 * Based on the Linux/Xtensa version of this header.
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <linux/types.h>
14 #include <asm/byteorder.h>
17 * swap functions to change byte order from little-endian to big-endian and
21 static inline unsigned short _swapw(unsigned short v)
23 return (v << 8) | (v >> 8);
26 static inline unsigned int _swapl(unsigned int v)
28 return (v << 24) | ((v & 0xff00) << 8) |
29 ((v >> 8) & 0xff00) | (v >> 24);
37 ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
39 ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
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))
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
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
57 * The macros don't do byte-swapping.
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)))
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))
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);
81 #define IO_SPACE_LIMIT ~0
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))
87 /* At this point the Xtensa doesn't provide byte swap instructions */
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)
104 # error processor byte order undefined!
109 * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
111 #define xlate_dev_mem_ptr(p) __va(p)
114 * Convert a virtual cached pointer to an uncached pointer
116 #define xlate_dev_kmem_ptr(p) p
118 #define MAP_NOCACHE (0)
119 #define MAP_WRCOMBINE (0)
120 #define MAP_WRBACK (0)
121 #define MAP_WRTHROUGH (0)
124 map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
126 return (void *)paddr;
130 * Take down a mapping set up by map_physmem().
132 static inline void unmap_physmem(void *vaddr, unsigned long flags)
136 static inline phys_addr_t virt_to_phys(void *vaddr)
138 return (phys_addr_t)((unsigned long)vaddr);
142 * Dummy function to keep U-Boot's cfi_flash.c driver happy.
144 static inline void sync(void)
148 #endif /* _XTENSA_IO_H */