RTEMS  5.0.0
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  */
53 static inline void 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() eieio()
63 #define iobarrier_r() eieio()
64 #define iobarrier_w() eieio()
65 
66 /*
67  * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
68  */
69 static 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 
77 static 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 
82 static 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 
91 static 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 
99 static 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 
105 static 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 static inline uint32_t in_le32(const volatile uint32_t *addr)
111 {
112  uint32_t ret;
113 
114  __asm__ __volatile__("lwbrx %0,0,%1; eieio" : "=r" (ret) :
115  "r" (addr), "m" (*addr));
116  return ret;
117 }
118 
119 static inline uint32_t in_be32(const volatile uint32_t *addr)
120 {
121  uint32_t ret;
122 
123  __asm__ __volatile__("lwz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
124  return ret;
125 }
126 
127 static inline void out_le32(volatile uint32_t *addr, uint32_t val)
128 {
129  __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
130  "r" (val), "r" (addr));
131 }
132 
133 static inline void out_be32(volatile uint32_t *addr, uint32_t val)
134 {
135  __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
136 }
137 
138 #endif /* ASM */
139 #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.