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