RTEMS 7.0-rc1
Loading...
Searching...
No Matches
io.h
1/* SPDX-License-Identifier: GPL-2.0+-with-RTEMS-exception */
2
3/*
4 * io.h
5 *
6 * This file contains inline implementation of function to
7 * deal with IO.
8 *
9 * It is a stripped down version of linux ppc file...
10 *
11 * Copyright (C) 1999 Eric Valette (eric.valette@free.fr)
12 * Canon Centre Recherche France.
13 *
14 * The license and distribution terms for this file may be
15 * found in the file LICENSE in this distribution or at
16 * http://www.rtems.org/license/LICENSE.
17 */
18#ifndef _LIBCPU_IO_H
19#define _LIBCPU_IO_H
20
21
22#define PREP_ISA_IO_BASE 0x80000000
23#define PREP_ISA_MEM_BASE 0xc0000000
24#define PREP_PCI_DRAM_OFFSET 0x80000000
25
26#define CHRP_ISA_IO_BASE 0xfe000000
27#define CHRP_ISA_MEM_BASE 0xfd000000
28#define CHRP_PCI_DRAM_OFFSET 0x00000000
29
30/* _IO_BASE, _ISA_MEM_BASE, PCI_DRAM_OFFSET are now defined by bsp.h */
31
32#ifndef ASM
33
34#include <bsp.h> /* for _IO_BASE & friends */
35#include <stdint.h>
36
37/* NOTE: The use of these macros is DISCOURAGED.
38 * you should consider e.g. using in_xxx / out_xxx
39 * with a device specific base address that is
40 * defined by the BSP. This makes drivers easier
41 * to port.
42 */
43#define inb(port) in_8((uint8_t *)((port)+_IO_BASE))
44#define outb(val, port) out_8((uint8_t *)((port)+_IO_BASE), (val))
45#define inw(port) in_le16((uint16_t *)((port)+_IO_BASE))
46#define outw(val, port) out_le16((uint16_t *)((port)+_IO_BASE), (val))
47#define inl(port) in_le32((uint32_t *)((port)+_IO_BASE))
48#define outl(val, port) out_le32((uint32_t *)((port)+_IO_BASE), (val))
49
50/*
51 * Enforce In-order Execution of I/O:
52 * Acts as a barrier to ensure all previous I/O accesses have
53 * completed before any further ones are issued.
54 */
55static inline void io_eieio(void)
56{
57 __asm__ __volatile__ ("eieio");
58}
59
60
61/* Enforce in-order execution of data I/O.
62 * No distinction between read/write on PPC; use eieio for all three.
63 */
64#define iobarrier_rw() io_eieio()
65#define iobarrier_r() io_eieio()
66#define iobarrier_w() io_eieio()
67
68/*
69 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
70 */
71static inline uint8_t in_8(const volatile uint8_t *addr)
72{
73 uint8_t ret;
74
75 __asm__ __volatile__("lbz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
76 return ret;
77}
78
79static inline void out_8(volatile uint8_t *addr, uint8_t val)
80{
81 __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
82}
83
84static inline uint16_t in_le16(const volatile uint16_t *addr)
85{
86 uint16_t ret;
87
88 __asm__ __volatile__("lhbrx %0,0,%1; eieio" : "=r" (ret) :
89 "r" (addr), "m" (*addr));
90 return ret;
91}
92
93static inline uint16_t in_be16(const volatile uint16_t *addr)
94{
95 uint16_t ret;
96
97 __asm__ __volatile__("lhz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
98 return ret;
99}
100
101static inline void out_le16(volatile uint16_t *addr, uint16_t val)
102{
103 __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
104 "r" (val), "r" (addr));
105}
106
107static inline void out_be16(volatile uint16_t *addr, uint16_t val)
108{
109 __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
110}
111
112#ifndef in_le32
113static inline uint32_t in_le32(const volatile uint32_t *addr)
114{
115 uint32_t ret;
116
117 __asm__ __volatile__("lwbrx %0,0,%1; eieio" : "=r" (ret) :
118 "r" (addr), "m" (*addr));
119 return ret;
120}
121#endif
122
123#ifndef in_be32
124static inline uint32_t in_be32(const volatile uint32_t *addr)
125{
126 uint32_t ret;
127
128 __asm__ __volatile__("lwz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
129 return ret;
130}
131#endif
132
133#ifndef out_le32
134static inline void out_le32(volatile uint32_t *addr, uint32_t val)
135{
136 __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
137 "r" (val), "r" (addr));
138}
139#endif
140
141#ifndef out_be32
142static inline void out_be32(volatile uint32_t *addr, uint32_t val)
143{
144 __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
145}
146#endif
147
148#endif /* ASM */
149#endif /* _LIBCPU_IO_H */