1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * I/O device access primitives. Simplified based on related U-Boot code,
5 * which is in turn based on early versions from the Linux kernel:
7 * Copyright (C) 1996-2000 Russell King
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #ifndef __ARCH_GENERIC_IO_H__
15 #define __ARCH_GENERIC_IO_H__
20 #include <arch/mmio.h>
22 #define __io(a) (void *)(uintptr_t)(CONFIG_PCI_IOBASE + a)
24 static inline void outb(uint8_t value
, uint16_t port
)
26 write8(__io(port
), value
);
29 static inline void outw(uint16_t value
, uint16_t port
)
31 write16(__io(port
), cpu_to_le16(value
));
34 static inline void outl(uint32_t value
, uint16_t port
)
36 write32(__io(port
), cpu_to_le32(value
));
39 static inline uint8_t inb(uint16_t port
)
41 return read8(__io(port
));
44 static inline uint16_t inw(uint16_t port
)
46 return le16_to_cpu(read16(__io(port
)));
49 static inline uint32_t inl(uint16_t port
)
51 return le32_to_cpu(read32(__io(port
)));
54 static inline void outsb(uint16_t port
, const void *addr
, unsigned long count
)
56 uint8_t *buf
= (uint8_t *)addr
;
58 write8(__io(port
), *buf
++);
61 static inline void outsw(uint16_t port
, const void *addr
, unsigned long count
)
63 uint16_t *buf
= (uint16_t *)addr
;
65 write16(__io(port
), *buf
++);
68 static inline void outsl(uint16_t port
, const void *addr
, unsigned long count
)
70 uint32_t *buf
= (uint32_t *)addr
;
72 write32(__io(port
), *buf
++);
75 static inline void insb(uint16_t port
, void *addr
, unsigned long count
)
77 uint8_t *buf
= (uint8_t *)addr
;
79 *buf
++ = read8(__io(port
));
82 static inline void insw(uint16_t port
, void *addr
, unsigned long count
)
84 uint16_t *buf
= (uint16_t *)addr
;
86 *buf
++ = read16(__io(port
));
89 static inline void insl(uint16_t port
, void *addr
, unsigned long count
)
91 uint32_t *buf
= (uint32_t *)addr
;
93 *buf
++ = read32(__io(port
));