aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Meng2018-10-15 04:21:16 -0500
committerSimon Glass2018-11-14 11:16:27 -0600
commit3bf9a8e8460f69022c85f30860911067e4aebca3 (patch)
tree7eb6577c4cf2a185851f8a4e52bf2cf0780f2af1
parent2895c4b7d65e1a65f7d8804126f91ee91e8e2481 (diff)
downloadu-boot-3bf9a8e8460f69022c85f30860911067e4aebca3.tar.gz
u-boot-3bf9a8e8460f69022c85f30860911067e4aebca3.tar.xz
u-boot-3bf9a8e8460f69022c85f30860911067e4aebca3.zip
x86: Implement arch-specific io accessor routines
At present the generic io{read,write}{8,16,32} routines only support MMIO access. With architecture like x86 that has a separate IO space, these routines cannot be used to access I/O ports. Implement x86-specific version to support both PIO and MMIO access, so that drivers for multiple architectures can use these accessors without the need to know whether it's MMIO or PIO. These are ported from Linux kernel lib/iomap.c, with slight changes. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--arch/Kconfig1
-rw-r--r--arch/x86/include/asm/io.h66
2 files changed, 67 insertions, 0 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index 1f2f407d64..e822a0b27e 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -120,6 +120,7 @@ config X86
120 select CREATE_ARCH_SYMLINK 120 select CREATE_ARCH_SYMLINK
121 select DM 121 select DM
122 select DM_PCI 122 select DM_PCI
123 select HAVE_ARCH_IOMAP
123 select HAVE_PRIVATE_LIBGCC 124 select HAVE_PRIVATE_LIBGCC
124 select OF_CONTROL 125 select OF_CONTROL
125 select PCI 126 select PCI
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index c05c6bf8a2..81def0afd3 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -241,6 +241,72 @@ static inline void sync(void)
241#define __iormb() dmb() 241#define __iormb() dmb()
242#define __iowmb() dmb() 242#define __iowmb() dmb()
243 243
244/*
245 * Read/write from/to an (offsettable) iomem cookie. It might be a PIO
246 * access or a MMIO access, these functions don't care. The info is
247 * encoded in the hardware mapping set up by the mapping functions
248 * (or the cookie itself, depending on implementation and hw).
249 *
250 * The generic routines don't assume any hardware mappings, and just
251 * encode the PIO/MMIO as part of the cookie. They coldly assume that
252 * the MMIO IO mappings are not in the low address range.
253 *
254 * Architectures for which this is not true can't use this generic
255 * implementation and should do their own copy.
256 */
257
258/*
259 * We assume that all the low physical PIO addresses (0-0xffff) always
260 * PIO. That means we can do some sanity checks on the low bits, and
261 * don't need to just take things for granted.
262 */
263#define PIO_RESERVED 0x10000UL
264
265/*
266 * Ugly macros are a way of life.
267 */
268#define IO_COND(addr, is_pio, is_mmio) do { \
269 unsigned long port = (unsigned long __force)addr; \
270 if (port >= PIO_RESERVED) { \
271 is_mmio; \
272 } else { \
273 is_pio; \
274 } \
275} while (0)
276
277static inline u8 ioread8(const volatile void __iomem *addr)
278{
279 IO_COND(addr, return inb(port), return readb(addr));
280 return 0xff;
281}
282
283static inline u16 ioread16(const volatile void __iomem *addr)
284{
285 IO_COND(addr, return inw(port), return readw(addr));
286 return 0xffff;
287}
288
289static inline u32 ioread32(const volatile void __iomem *addr)
290{
291 IO_COND(addr, return inl(port), return readl(addr));
292 return 0xffffffff;
293}
294
295static inline void iowrite8(u8 value, volatile void __iomem *addr)
296{
297 IO_COND(addr, outb(value, port), writeb(value, addr));
298}
299
300static inline void iowrite16(u16 value, volatile void __iomem *addr)
301{
302 IO_COND(addr, outw(value, port), writew(value, addr));
303}
304
305static inline void iowrite32(u32 value, volatile void __iomem *addr)
306{
307 IO_COND(addr, outl(value, port), writel(value, addr));
308}
309
244#include <asm-generic/io.h> 310#include <asm-generic/io.h>
245 311
246#endif /* _ASM_IO_H */ 312#endif /* _ASM_IO_H */