1 | /** @file
|
---|
2 | Common I/O Library routines.
|
---|
3 |
|
---|
4 | Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions of the BSD License
|
---|
7 | which accompanies this distribution. The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php.
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include "BaseIoLibIntrinsicInternal.h"
|
---|
16 |
|
---|
17 | /**
|
---|
18 | Reads a 64-bit I/O port.
|
---|
19 |
|
---|
20 | Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
|
---|
21 | This function must guarantee that all I/O read and write operations are
|
---|
22 | serialized.
|
---|
23 |
|
---|
24 | If 64-bit I/O port operations are not supported, then ASSERT().
|
---|
25 | If Port is not aligned on a 64-bit boundary, then ASSERT().
|
---|
26 |
|
---|
27 | @param Port The I/O port to read.
|
---|
28 |
|
---|
29 | @return The value read.
|
---|
30 |
|
---|
31 | **/
|
---|
32 | UINT64
|
---|
33 | EFIAPI
|
---|
34 | IoRead64 (
|
---|
35 | IN UINTN Port
|
---|
36 | )
|
---|
37 | {
|
---|
38 | ASSERT (FALSE);
|
---|
39 | return 0;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | Writes a 64-bit I/O port.
|
---|
44 |
|
---|
45 | Writes the 64-bit I/O port specified by Port with the value specified by Value
|
---|
46 | and returns Value. This function must guarantee that all I/O read and write
|
---|
47 | operations are serialized.
|
---|
48 |
|
---|
49 | If 64-bit I/O port operations are not supported, then ASSERT().
|
---|
50 | If Port is not aligned on a 64-bit boundary, then ASSERT().
|
---|
51 |
|
---|
52 | @param Port The I/O port to write.
|
---|
53 | @param Value The value to write to the I/O port.
|
---|
54 |
|
---|
55 | @return The value written the I/O port.
|
---|
56 |
|
---|
57 | **/
|
---|
58 | UINT64
|
---|
59 | EFIAPI
|
---|
60 | IoWrite64 (
|
---|
61 | IN UINTN Port,
|
---|
62 | IN UINT64 Value
|
---|
63 | )
|
---|
64 | {
|
---|
65 | ASSERT (FALSE);
|
---|
66 | return 0;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | /**
|
---|
71 | Reads an 8-bit MMIO register.
|
---|
72 |
|
---|
73 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
|
---|
74 | returned. This function must guarantee that all MMIO read and write
|
---|
75 | operations are serialized.
|
---|
76 |
|
---|
77 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
---|
78 |
|
---|
79 | @param Address The MMIO register to read.
|
---|
80 |
|
---|
81 | @return The value read.
|
---|
82 |
|
---|
83 | **/
|
---|
84 | UINT8
|
---|
85 | EFIAPI
|
---|
86 | MmioRead8 (
|
---|
87 | IN UINTN Address
|
---|
88 | )
|
---|
89 | {
|
---|
90 | UINT8 Value;
|
---|
91 |
|
---|
92 | MemoryFence ();
|
---|
93 | Value = *(volatile UINT8*)Address;
|
---|
94 | MemoryFence ();
|
---|
95 |
|
---|
96 | return Value;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | Writes an 8-bit MMIO register.
|
---|
101 |
|
---|
102 | Writes the 8-bit MMIO register specified by Address with the value specified
|
---|
103 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
104 | and write operations are serialized.
|
---|
105 |
|
---|
106 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
---|
107 |
|
---|
108 | @param Address The MMIO register to write.
|
---|
109 | @param Value The value to write to the MMIO register.
|
---|
110 |
|
---|
111 | @return Value.
|
---|
112 |
|
---|
113 | **/
|
---|
114 | UINT8
|
---|
115 | EFIAPI
|
---|
116 | MmioWrite8 (
|
---|
117 | IN UINTN Address,
|
---|
118 | IN UINT8 Value
|
---|
119 | )
|
---|
120 | {
|
---|
121 | MemoryFence ();
|
---|
122 | *(volatile UINT8*)Address = Value;
|
---|
123 | MemoryFence ();
|
---|
124 |
|
---|
125 | return Value;
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | Reads a 16-bit MMIO register.
|
---|
130 |
|
---|
131 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
|
---|
132 | returned. This function must guarantee that all MMIO read and write
|
---|
133 | operations are serialized.
|
---|
134 |
|
---|
135 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
---|
136 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
137 |
|
---|
138 | @param Address The MMIO register to read.
|
---|
139 |
|
---|
140 | @return The value read.
|
---|
141 |
|
---|
142 | **/
|
---|
143 | UINT16
|
---|
144 | EFIAPI
|
---|
145 | MmioRead16 (
|
---|
146 | IN UINTN Address
|
---|
147 | )
|
---|
148 | {
|
---|
149 | UINT16 Value;
|
---|
150 |
|
---|
151 | ASSERT ((Address & 1) == 0);
|
---|
152 |
|
---|
153 | MemoryFence ();
|
---|
154 | Value = *(volatile UINT16*)Address;
|
---|
155 | MemoryFence ();
|
---|
156 |
|
---|
157 | return Value;
|
---|
158 | }
|
---|
159 |
|
---|
160 | /**
|
---|
161 | Writes a 16-bit MMIO register.
|
---|
162 |
|
---|
163 | Writes the 16-bit MMIO register specified by Address with the value specified
|
---|
164 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
165 | and write operations are serialized.
|
---|
166 |
|
---|
167 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
---|
168 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
169 |
|
---|
170 | @param Address The MMIO register to write.
|
---|
171 | @param Value The value to write to the MMIO register.
|
---|
172 |
|
---|
173 | @return Value.
|
---|
174 |
|
---|
175 | **/
|
---|
176 | UINT16
|
---|
177 | EFIAPI
|
---|
178 | MmioWrite16 (
|
---|
179 | IN UINTN Address,
|
---|
180 | IN UINT16 Value
|
---|
181 | )
|
---|
182 | {
|
---|
183 | ASSERT ((Address & 1) == 0);
|
---|
184 |
|
---|
185 | MemoryFence ();
|
---|
186 | *(volatile UINT16*)Address = Value;
|
---|
187 | MemoryFence ();
|
---|
188 |
|
---|
189 | return Value;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /**
|
---|
193 | Reads a 32-bit MMIO register.
|
---|
194 |
|
---|
195 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
|
---|
196 | returned. This function must guarantee that all MMIO read and write
|
---|
197 | operations are serialized.
|
---|
198 |
|
---|
199 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
---|
200 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
201 |
|
---|
202 | @param Address The MMIO register to read.
|
---|
203 |
|
---|
204 | @return The value read.
|
---|
205 |
|
---|
206 | **/
|
---|
207 | UINT32
|
---|
208 | EFIAPI
|
---|
209 | MmioRead32 (
|
---|
210 | IN UINTN Address
|
---|
211 | )
|
---|
212 | {
|
---|
213 | UINT32 Value;
|
---|
214 |
|
---|
215 | ASSERT ((Address & 3) == 0);
|
---|
216 |
|
---|
217 | MemoryFence ();
|
---|
218 | Value = *(volatile UINT32*)Address;
|
---|
219 | MemoryFence ();
|
---|
220 |
|
---|
221 | return Value;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /**
|
---|
225 | Writes a 32-bit MMIO register.
|
---|
226 |
|
---|
227 | Writes the 32-bit MMIO register specified by Address with the value specified
|
---|
228 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
229 | and write operations are serialized.
|
---|
230 |
|
---|
231 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
---|
232 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
233 |
|
---|
234 | @param Address The MMIO register to write.
|
---|
235 | @param Value The value to write to the MMIO register.
|
---|
236 |
|
---|
237 | @return Value.
|
---|
238 |
|
---|
239 | **/
|
---|
240 | UINT32
|
---|
241 | EFIAPI
|
---|
242 | MmioWrite32 (
|
---|
243 | IN UINTN Address,
|
---|
244 | IN UINT32 Value
|
---|
245 | )
|
---|
246 | {
|
---|
247 | ASSERT ((Address & 3) == 0);
|
---|
248 |
|
---|
249 | MemoryFence ();
|
---|
250 | *(volatile UINT32*)Address = Value;
|
---|
251 | MemoryFence ();
|
---|
252 |
|
---|
253 | return Value;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /**
|
---|
257 | Reads a 64-bit MMIO register.
|
---|
258 |
|
---|
259 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
|
---|
260 | returned. This function must guarantee that all MMIO read and write
|
---|
261 | operations are serialized.
|
---|
262 |
|
---|
263 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
---|
264 | If Address is not aligned on a 64-bit boundary, then ASSERT().
|
---|
265 |
|
---|
266 | @param Address The MMIO register to read.
|
---|
267 |
|
---|
268 | @return The value read.
|
---|
269 |
|
---|
270 | **/
|
---|
271 | UINT64
|
---|
272 | EFIAPI
|
---|
273 | MmioRead64 (
|
---|
274 | IN UINTN Address
|
---|
275 | )
|
---|
276 | {
|
---|
277 | UINT64 Value;
|
---|
278 |
|
---|
279 | ASSERT ((Address & 7) == 0);
|
---|
280 |
|
---|
281 | MemoryFence ();
|
---|
282 | Value = *(volatile UINT64*)Address;
|
---|
283 | MemoryFence ();
|
---|
284 |
|
---|
285 | return Value;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /**
|
---|
289 | Writes a 64-bit MMIO register.
|
---|
290 |
|
---|
291 | Writes the 64-bit MMIO register specified by Address with the value specified
|
---|
292 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
293 | and write operations are serialized.
|
---|
294 |
|
---|
295 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
---|
296 | If Address is not aligned on a 64-bit boundary, then ASSERT().
|
---|
297 |
|
---|
298 | @param Address The MMIO register to write.
|
---|
299 | @param Value The value to write to the MMIO register.
|
---|
300 |
|
---|
301 | **/
|
---|
302 | UINT64
|
---|
303 | EFIAPI
|
---|
304 | MmioWrite64 (
|
---|
305 | IN UINTN Address,
|
---|
306 | IN UINT64 Value
|
---|
307 | )
|
---|
308 | {
|
---|
309 | ASSERT ((Address & 7) == 0);
|
---|
310 |
|
---|
311 | MemoryFence ();
|
---|
312 | *(volatile UINT64*)Address = Value;
|
---|
313 | MemoryFence ();
|
---|
314 |
|
---|
315 | return Value;
|
---|
316 | }
|
---|
317 |
|
---|