include/spd_bin.h: Add SPD IO layer
[coreboot2.git] / src / include / arch-generic / io.h
blob5874fc8425f8d383d88225fe9e03a68dedeb75eb
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 /*
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__
17 #include <stdint.h>
18 #include <stddef.h>
19 #include <endian.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;
57 while (count--)
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;
64 while (count--)
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;
71 while (count--)
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;
78 while (count--)
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;
85 while (count--)
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;
92 while (count--)
93 *buf++ = read32(__io(port));
96 #endif