Debian Codegraph @

src/include/arch-generic/io.h

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
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:
6 *
7 * Copyright (C) 1996-2000 Russell King
8 *
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.
12 */
13
14 #ifndef __ARCH_GENERIC_IO_H__
15 #define __ARCH_GENERIC_IO_H__
16
17 #include <stdint.h>
18 #include <stddef.h>
19 #include <endian.h>
20 #include <arch/mmio.h>
21
22 /*
23 * The memory address of a memory-mapped translator that lets the
24 * CPU communicate with peripheral devices over PCI I/O space.
25 */
26 extern uintptr_t io_port_mmio_base;
27 #define __io(a) (void *)(io_port_mmio_base + a)
28
29 static inline void outb(uint8_t value, uint16_t port)
30 {
31 write8(__io(port), value);
32 }
33
34 static inline void outw(uint16_t value, uint16_t port)
35 {
36 write16(__io(port), cpu_to_le16(value));
37 }
38
39 static inline void outl(uint32_t value, uint16_t port)
40 {
41 write32(__io(port), cpu_to_le32(value));
42 }
43
44 static inline uint8_t inb(uint16_t port)
45 {
46 return read8(__io(port));
47 }
48
49 static inline uint16_t inw(uint16_t port)
50 {
51 return le16_to_cpu(read16(__io(port)));
52 }
53
54 static inline uint32_t inl(uint16_t port)
55 {
56 return le32_to_cpu(read32(__io(port)));
57 }
58
59 static inline void outsb(uint16_t port, const void *addr, unsigned long count)
60 {
61 uint8_t *buf = (uint8_t *)addr;
62 while (count--)
63 write8(__io(port), *buf++);
64 }
65
66 static inline void outsw(uint16_t port, const void *addr, unsigned long count)
67 {
68 uint16_t *buf = (uint16_t *)addr;
69 while (count--)
70 write16(__io(port), *buf++);
71 }
72
73 static inline void outsl(uint16_t port, const void *addr, unsigned long count)
74 {
75 uint32_t *buf = (uint32_t *)addr;
76 while (count--)
77 write32(__io(port), *buf++);
78 }
79
80 static inline void insb(uint16_t port, void *addr, unsigned long count)
81 {
82 uint8_t *buf = (uint8_t *)addr;
83 while (count--)
84 *buf++ = read8(__io(port));
85 }
86
87 static inline void insw(uint16_t port, void *addr, unsigned long count)
88 {
89 uint16_t *buf = (uint16_t *)addr;
90 while (count--)
91 *buf++ = read16(__io(port));
92 }
93
94 static inline void insl(uint16_t port, void *addr, unsigned long count)
95 {
96 uint32_t *buf = (uint32_t *)addr;
97 while (count--)
98 *buf++ = read32(__io(port));
99 }
100
101 #endif