]> git.saurik.com Git - apple/xnu.git/blob - iokit/Drivers/network/drvIntel82557/i82557Inline.h
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Drivers / network / drvIntel82557 / i82557Inline.h
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 #include <libkern/OSByteOrder.h>
27 #include <libkern/OSAtomic.h>
28
29 //---------------------------------------------------------------------------
30 // CSR macros.
31
32 #define CSR_VALUE(name, x) (((x) & name ## _MASK) >> name ## _SHIFT)
33 #define CSR_FIELD(name, x) (((x) << name ## _SHIFT) & name ## _MASK)
34 #define CSR_MASK(name, x) ((x) << name ## _SHIFT)
35 #define BIT(x) (1 << (x))
36
37 #define IOSync() OSSynchronizeIO()
38
39 //---------------------------------------------------------------------------
40 // CSR read & write.
41
42 static inline
43 UInt8
44 OSReadLE8(volatile void * base)
45 {
46 return *(volatile UInt8 *)base;
47 }
48
49 static inline
50 UInt16
51 OSReadLE16(volatile void * base)
52 {
53 return OSReadLittleInt16(base, 0);
54 }
55
56 static inline
57 UInt32
58 OSReadLE32(volatile void * base)
59 {
60 return OSReadLittleInt32(base, 0);
61 }
62
63 static inline
64 void
65 OSWriteLE8(volatile void * base, UInt8 data)
66 {
67 *(volatile UInt8 *)base = data;
68 IOSync();
69 }
70
71 static inline
72 void
73 OSWriteLE16(volatile void * base, UInt16 data)
74 {
75 OSWriteLittleInt16(base, 0, data);
76 IOSync();
77 }
78
79 static inline
80 void
81 OSWriteLE32(volatile void * base, UInt32 data)
82 {
83 OSWriteLittleInt32(base, 0, data);
84 IOSync();
85 }
86
87 //---------------------------------------------------------------------------
88 // Set/clear bit(s) macros.
89
90 #define __SET(n) \
91 static inline void \
92 OSSetLE##n(volatile void * base, UInt##n bit) \
93 { \
94 OSWriteLE##n(base, (OSReadLE##n(base) | (bit))); \
95 }
96
97 #define __CLR(n) \
98 static inline void \
99 OSClearLE##n(volatile void * base, UInt##n bit) \
100 { \
101 OSWriteLE##n(base, (OSReadLE##n(base) & ~(bit))); \
102 }
103
104 __SET(8)
105 __SET(16)
106 __SET(32)
107
108 __CLR(8)
109 __CLR(16)
110 __CLR(32)
111
112 #endif /* !_I82557INLINE_H */