RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
20#define PREP_ISA_IO_BASE 0x80000000
21#define PREP_ISA_MEM_BASE 0xc0000000
22#define PREP_PCI_DRAM_OFFSET 0x80000000
23
24#define CHRP_ISA_IO_BASE 0xfe000000
25#define CHRP_ISA_MEM_BASE 0xfd000000
26#define CHRP_PCI_DRAM_OFFSET 0x00000000
27
28/* _IO_BASE, _ISA_MEM_BASE, PCI_DRAM_OFFSET are now defined by bsp.h */
29
30#ifndef ASM
31
32#include <bsp.h> /* for _IO_BASE & friends */
33#include <stdint.h>
34
35/* NOTE: The use of these macros is DISCOURAGED.
36 * you should consider e.g. using in_xxx / out_xxx
37 * with a device specific base address that is
38 * defined by the BSP. This makes drivers easier
39 * to port.
40 */
41#define inb(port) in_8((uint8_t *)((port)+_IO_BASE))
42#define outb(val, port) out_8((uint8_t *)((port)+_IO_BASE), (val))
43#define inw(port) in_le16((uint16_t *)((port)+_IO_BASE))
44#define outw(val, port) out_le16((uint16_t *)((port)+_IO_BASE), (val))
45#define inl(port) in_le32((uint32_t *)((port)+_IO_BASE))
46#define outl(val, port) out_le32((uint32_t *)((port)+_IO_BASE), (val))
47
48/*
49 * Enforce In-order Execution of I/O:
50 * Acts as a barrier to ensure all previous I/O accesses have
51 * completed before any further ones are issued.
52 */
53static inline void io_eieio(void)
54{
55 __asm__ __volatile__ ("eieio");
56}
57
58
59/* Enforce in-order execution of data I/O.
60 * No distinction between read/write on PPC; use eieio for all three.
61 */
62#define iobarrier_rw() io_eieio()
63#define iobarrier_r() io_eieio()
64#define iobarrier_w() io_eieio()
65
66/*
67 * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
68 */
69static inline uint8_t in_8(const volatile uint8_t *addr)
70{
71 uint8_t ret;
72
73 __asm__ __volatile__("lbz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
74 return ret;
75}
76
77static inline void out_8(volatile uint8_t *addr, uint8_t val)
78{
79 __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
80}
81
82static inline uint16_t in_le16(const volatile uint16_t *addr)
83{
84 uint16_t ret;
85
86 __asm__ __volatile__("lhbrx %0,0,%1; eieio" : "=r" (ret) :
87 "r" (addr), "m" (*addr));
88 return ret;
89}
90
91static inline uint16_t in_be16(const volatile uint16_t *addr)
92{
93 uint16_t ret;
94
95 __asm__ __volatile__("lhz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
96 return ret;
97}
98
99static inline void out_le16(volatile uint16_t *addr, uint16_t val)
100{
101 __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
102 "r" (val), "r" (addr));
103}
104
105static inline void out_be16(volatile uint16_t *addr, uint16_t val)
106{
107 __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
108}
109
110#ifndef in_le32
111static inline uint32_t in_le32(const volatile uint32_t *addr)
112{
113 uint32_t ret;
114
115 __asm__ __volatile__("lwbrx %0,0,%1; eieio" : "=r" (ret) :
116 "r" (addr), "m" (*addr));
117 return ret;
118}
119#endif
120
121#ifndef in_be32
122static inline uint32_t in_be32(const volatile uint32_t *addr)
123{
124 uint32_t ret;
125
126 __asm__ __volatile__("lwz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
127 return ret;
128}
129#endif
130
131#ifndef out_le32
132static inline void out_le32(volatile uint32_t *addr, uint32_t val)
133{
134 __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
135 "r" (val), "r" (addr));
136}
137#endif
138
139#ifndef out_be32
140static inline void out_be32(volatile uint32_t *addr, uint32_t val)
141{
142 __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
143}
144#endif
145
146#endif /* ASM */
147#endif /* _LIBCPU_IO_H */
register struct Per_CPU_Control *_SPARC_Per_CPU_current __asm__("g6")
The pointer to the current per-CPU control is available via register g6.