|
|
1.1 root 1: /*
2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * The contents of this file constitute Original Code as defined in and
7: * are subject to the Apple Public Source License Version 1.1 (the
8: * "License"). You may not use this file except in compliance with the
9: * License. Please obtain a copy of the License at
10: * http://www.apple.com/publicsource and read it before using this file.
11: *
12: * This Original Code and all software distributed under the License are
13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17: * License for the specific language governing rights and limitations
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22:
23: #ifndef _I82557INLINE_H
24: #define _I82557INLINE_H
25:
26: //---------------------------------------------------------------------------
27: // CSR macros.
28:
29: #define CSR_VALUE(name, x) (((x) & name ## _MASK) >> name ## _SHIFT)
30: #define CSR_FIELD(name, x) (((x) << name ## _SHIFT) & name ## _MASK)
31: #define CSR_MASK(name, x) ((x) << name ## _SHIFT)
32: #define BIT(x) (1 << (x))
33:
34: //---------------------------------------------------------------------------
35: // Flush write buffers.
36:
37: #ifdef __ppc__
38: #define IOSync() __asm__ ("eieio")
39: #else
40: #define IOSync()
41: #endif
42:
43: //---------------------------------------------------------------------------
44: // CSR read & write.
45:
46: #ifdef __BIG_ENDIAN__
47:
48: #ifdef __ppc__
49:
50: static inline
51: UInt8
52: OSReadLE8(volatile void * base)
53: {
54: return *(volatile UInt8 *)base;
55: }
56:
57: static inline
58: UInt16
59: OSReadLE16(volatile void * base)
60: {
61: UInt16 result;
62: __asm__ volatile("lhbrx %0, 0, %1"
63: : "=r" (result)
64: : "r" (base)
65: : "r0");
66: return result;
67: }
68:
69: static inline
70: UInt32
71: OSReadLE32(volatile void * base)
72: {
73: UInt32 result;
74: __asm__ volatile("lwbrx %0, 0, %1"
75: : "=r" (result)
76: : "r" (base)
77: : "r0");
78: return result;
79: }
80:
81: static inline
82: void
83: OSWriteLE8(volatile void * base, UInt8 data)
84: {
85: *(volatile UInt8 *)base = data;
86: IOSync();
87: }
88:
89: static inline
90: void
91: OSWriteLE16(volatile void * base, UInt16 data)
92: {
93: __asm__ volatile("sthbrx %0, 0, %1"
94: :
95: : "r" (data), "r" (base)
96: : "r0");
97: IOSync();
98: }
99:
100: static inline
101: void
102: OSWriteLE32(volatile void * base, UInt32 data)
103: {
104: __asm__ volatile("stwbrx %0, 0, %1"
105: :
106: : "r" (data), "r" (base)
107: : "r0" );
108: IOSync();
109: }
110:
111: #else
112: #error Unknown big-endian processor type
113: #endif /* __ppc__ */
114:
115: #else /* little endian processor */
116:
117: static inline
118: UInt8
119: OSReadLE8(volatile void * base)
120: {
121: return *(volatile UInt8 *)base;
122: }
123:
124: static inline
125: UInt16
126: OSReadLE16(volatile void * base)
127: {
128: return *(volatile UInt16 *)base;
129: }
130:
131: static inline
132: UInt32
133: OSReadLE32(volatile void * base)
134: {
135: return *(volatile UInt32 *)base;
136: }
137:
138: static inline
139: void
140: OSWriteLE8(volatile void * base, UInt8 data)
141: {
142: *(volatile UInt8 *)base = data;
143: }
144:
145: static inline
146: void
147: OSWriteLE16(volatile void * base, UInt16 data)
148: {
149: *(volatile UInt16 *)base = data;
150: }
151:
152: static inline
153: void
154: OSWriteLE32(volatile void * base, UInt32 data)
155: {
156: *(volatile UInt32 *)base = data;
157: }
158:
159: #endif /* __BIG_ENDIAN__ */
160:
161: //---------------------------------------------------------------------------
162: // Set/clear bit(s) macros.
163:
164: #define __SET(n) \
165: static inline void \
166: OSSetLE##n(volatile void * base, UInt##n bit) \
167: { \
168: OSWriteLE##n(base, (OSReadLE##n(base) | (bit))); \
169: }
170:
171: #define __CLR(n) \
172: static inline void \
173: OSClearLE##n(volatile void * base, UInt##n bit) \
174: { \
175: OSWriteLE##n(base, (OSReadLE##n(base) & ~(bit))); \
176: }
177:
178: __SET(8)
179: __SET(16)
180: __SET(32)
181:
182: __CLR(8)
183: __CLR(16)
184: __CLR(32)
185:
186: #endif /* !_I82557INLINE_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.