Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 2 | /* |
| 3 | * IO header file |
| 4 | * |
| 5 | * Copyright (C) 2001-2007 Tensilica Inc. |
| 6 | * Based on the Linux/Xtensa version of this header. |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _XTENSA_IO_H |
| 10 | #define _XTENSA_IO_H |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <asm/byteorder.h> |
| 14 | |
Jiaxun Yang | b121cb8 | 2024-06-18 14:56:03 +0100 | [diff] [blame^] | 15 | #include <asm/addrspace.h> |
| 16 | |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 17 | /* |
| 18 | * swap functions to change byte order from little-endian to big-endian and |
| 19 | * vice versa. |
| 20 | */ |
| 21 | |
| 22 | static inline unsigned short _swapw(unsigned short v) |
| 23 | { |
| 24 | return (v << 8) | (v >> 8); |
| 25 | } |
| 26 | |
| 27 | static inline unsigned int _swapl(unsigned int v) |
| 28 | { |
| 29 | return (v << 24) | ((v & 0xff00) << 8) | |
| 30 | ((v >> 8) & 0xff00) | (v >> 24); |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | * Generic I/O |
| 35 | */ |
| 36 | |
| 37 | #define readb(addr) \ |
| 38 | ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; }) |
| 39 | #define readw(addr) \ |
| 40 | ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; }) |
| 41 | #define readl(addr) \ |
| 42 | ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; }) |
| 43 | #define writeb(b, addr) (void)((*(volatile unsigned char *)(addr)) = (b)) |
| 44 | #define writew(b, addr) (void)((*(volatile unsigned short *)(addr)) = (b)) |
| 45 | #define writel(b, addr) (void)((*(volatile unsigned int *)(addr)) = (b)) |
| 46 | |
| 47 | #define __raw_readb readb |
| 48 | #define __raw_readw readw |
| 49 | #define __raw_readl readl |
| 50 | #define __raw_writeb writeb |
| 51 | #define __raw_writew writew |
| 52 | #define __raw_writel writel |
| 53 | |
| 54 | /* These are the definitions for the x86 IO instructions |
| 55 | * inb/inw/inl/outb/outw/outl, the "string" versions |
| 56 | * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions |
| 57 | * inb_p/inw_p/... |
| 58 | * The macros don't do byte-swapping. |
| 59 | */ |
| 60 | |
| 61 | #define inb(port) readb((u8 *)((port))) |
| 62 | #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port))) |
| 63 | #define inw(port) readw((u16 *)((port))) |
| 64 | #define outw(val, port) writew((val), (u16 *)((unsigned long)(port))) |
| 65 | #define inl(port) readl((u32 *)((port))) |
| 66 | #define outl(val, port) writel((val), (u32 *)((unsigned long)(port))) |
| 67 | |
| 68 | #define inb_p(port) inb((port)) |
| 69 | #define outb_p(val, port) outb((val), (port)) |
| 70 | #define inw_p(port) inw((port)) |
| 71 | #define outw_p(val, port) outw((val), (port)) |
| 72 | #define inl_p(port) inl((port)) |
| 73 | #define outl_p(val, port) outl((val), (port)) |
| 74 | |
| 75 | void insb(unsigned long port, void *dst, unsigned long count); |
| 76 | void insw(unsigned long port, void *dst, unsigned long count); |
| 77 | void insl(unsigned long port, void *dst, unsigned long count); |
| 78 | void outsb(unsigned long port, const void *src, unsigned long count); |
| 79 | void outsw(unsigned long port, const void *src, unsigned long count); |
| 80 | void outsl(unsigned long port, const void *src, unsigned long count); |
Igor Prusov | 3433f53 | 2023-11-14 14:02:53 +0300 | [diff] [blame] | 81 | #define insb insb |
| 82 | #define insw insw |
| 83 | #define insl insl |
| 84 | #define outsb outsb |
| 85 | #define outsw outsw |
| 86 | #define outsl outsl |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 87 | |
| 88 | #define IO_SPACE_LIMIT ~0 |
| 89 | |
| 90 | #define memset_io(a, b, c) memset((void *)(a), (b), (c)) |
| 91 | #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) |
| 92 | #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) |
| 93 | |
| 94 | /* At this point the Xtensa doesn't provide byte swap instructions */ |
| 95 | |
| 96 | #ifdef __XTENSA_EB__ |
| 97 | # define in_8(addr) (*(u8 *)(addr)) |
| 98 | # define in_le16(addr) _swapw(*(u16 *)(addr)) |
| 99 | # define in_le32(addr) _swapl(*(u32 *)(addr)) |
| 100 | # define out_8(b, addr) *(u8 *)(addr) = (b) |
| 101 | # define out_le16(b, addr) *(u16 *)(addr) = _swapw(b) |
| 102 | # define out_le32(b, addr) *(u32 *)(addr) = _swapl(b) |
| 103 | #elif defined(__XTENSA_EL__) |
| 104 | # define in_8(addr) (*(u8 *)(addr)) |
| 105 | # define in_le16(addr) (*(u16 *)(addr)) |
| 106 | # define in_le32(addr) (*(u32 *)(addr)) |
| 107 | # define out_8(b, addr) *(u8 *)(addr) = (b) |
| 108 | # define out_le16(b, addr) *(u16 *)(addr) = (b) |
| 109 | # define out_le32(b, addr) *(u32 *)(addr) = (b) |
| 110 | #else |
| 111 | # error processor byte order undefined! |
| 112 | #endif |
| 113 | |
| 114 | |
| 115 | /* |
| 116 | * Convert a physical pointer to a virtual kernel pointer for /dev/mem access |
| 117 | */ |
| 118 | #define xlate_dev_mem_ptr(p) __va(p) |
| 119 | |
| 120 | /* |
| 121 | * Convert a virtual cached pointer to an uncached pointer |
| 122 | */ |
| 123 | #define xlate_dev_kmem_ptr(p) p |
| 124 | |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 125 | /* |
| 126 | * Dummy function to keep U-Boot's cfi_flash.c driver happy. |
| 127 | */ |
| 128 | static inline void sync(void) |
| 129 | { |
Jiaxun Yang | b121cb8 | 2024-06-18 14:56:03 +0100 | [diff] [blame^] | 130 | } |
| 131 | |
| 132 | #if XCHAL_HAVE_PTP_MMU |
| 133 | static inline void *phys_to_virt(phys_addr_t paddr) |
| 134 | { |
| 135 | if (paddr >= CFG_SYS_IO_BASE) |
| 136 | return (void *)(unsigned long)paddr; |
| 137 | |
| 138 | if (paddr < CFG_MAX_MEM_MAPPED) |
| 139 | return (void *)(unsigned long)MEMADDR(paddr); |
| 140 | |
| 141 | return NULL; |
| 142 | } |
| 143 | |
| 144 | #define phys_to_virt phys_to_virt |
| 145 | |
| 146 | static inline phys_addr_t virt_to_phys(void *vaddr) |
| 147 | { |
| 148 | unsigned long addr = (unsigned long)vaddr; |
| 149 | |
| 150 | if (addr >= CFG_SYS_IO_BASE) |
| 151 | return addr; |
| 152 | |
| 153 | if (addr >= CFG_SYS_SDRAM_BASE && addr < MEMADDR(CFG_MAX_MEM_MAPPED)) |
| 154 | return PHYSADDR(addr); |
| 155 | |
| 156 | return 0; |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 157 | } |
| 158 | |
Jiaxun Yang | b121cb8 | 2024-06-18 14:56:03 +0100 | [diff] [blame^] | 159 | #define virt_to_phys virt_to_phys |
| 160 | #endif /* XCHAL_HAVE_PTP_MMU */ |
| 161 | |
Paul Burton | 8333ca4 | 2017-09-14 15:05:09 -0700 | [diff] [blame] | 162 | #include <asm-generic/io.h> |
| 163 | |
Chris Zankel | 1387dab | 2016-08-10 18:36:44 +0300 | [diff] [blame] | 164 | #endif /* _XTENSA_IO_H */ |