]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | I/O Library. This file has compiler specifics for GCC as there is no\r | |
3 | ANSI C standard for doing IO.\r | |
4 | \r | |
5 | GCC - uses EFIAPI assembler. __asm__ calls GAS. __volatile__ makes sure the\r | |
6 | compiler puts the assembler in this exact location. The complex GNUC\r | |
7 | operations are not optimzed. It would be possible to also write these\r | |
8 | with EFIAPI assembler.\r | |
9 | \r | |
10 | We don't advocate putting compiler specifics in libraries or drivers but there\r | |
11 | is no other way to make this work.\r | |
12 | \r | |
13 | Copyright (c) 2006 - 2007, Intel Corporation<BR>\r | |
14 | All rights reserved. This program and the accompanying materials\r | |
15 | are licensed and made available under the terms and conditions of the BSD License\r | |
16 | which accompanies this distribution. The full text of the license may be found at\r | |
17 | http://opensource.org/licenses/bsd-license.php\r | |
18 | \r | |
19 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
20 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
21 | \r | |
e1f414b6 | 22 | **/\r |
23 | \r | |
1efcc4ae | 24 | \r |
f734a10a | 25 | #include "BaseIoLibIntrinsicInternal.h"\r |
e1f414b6 | 26 | \r |
27 | /**\r | |
28 | Reads an 8-bit MMIO register.\r | |
29 | \r | |
30 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is\r | |
31 | returned. This function must guarantee that all MMIO read and write\r | |
32 | operations are serialized.\r | |
33 | \r | |
34 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
35 | \r | |
36 | @param Address The MMIO register to read.\r | |
37 | \r | |
2281e7a9 | 38 | @return The value read.\r |
e1f414b6 | 39 | \r |
40 | **/\r | |
41 | UINT8\r | |
42 | EFIAPI\r | |
43 | MmioRead8 (\r | |
44 | IN UINTN Address\r | |
45 | )\r | |
46 | {\r | |
47 | return *(volatile UINT8*)Address;\r | |
48 | }\r | |
49 | \r | |
50 | /**\r | |
51 | Writes an 8-bit MMIO register.\r | |
52 | \r | |
53 | Writes the 8-bit MMIO register specified by Address with the value specified\r | |
54 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
55 | and write operations are serialized.\r | |
56 | \r | |
57 | If 8-bit MMIO register operations are not supported, then ASSERT().\r | |
58 | \r | |
59 | @param Address The MMIO register to write.\r | |
60 | @param Value The value to write to the MMIO register.\r | |
2281e7a9 | 61 | \r |
62 | @return Value.\r | |
e1f414b6 | 63 | \r |
64 | **/\r | |
65 | UINT8\r | |
66 | EFIAPI\r | |
67 | MmioWrite8 (\r | |
68 | IN UINTN Address,\r | |
69 | IN UINT8 Value\r | |
70 | )\r | |
71 | {\r | |
72 | return *(volatile UINT8*)Address = Value;\r | |
73 | }\r | |
74 | \r | |
75 | /**\r | |
76 | Reads a 16-bit MMIO register.\r | |
77 | \r | |
78 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is\r | |
79 | returned. This function must guarantee that all MMIO read and write\r | |
80 | operations are serialized.\r | |
81 | \r | |
82 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 83 | If Address is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 84 | \r |
85 | @param Address The MMIO register to read.\r | |
86 | \r | |
2281e7a9 | 87 | @return The value read.\r |
e1f414b6 | 88 | \r |
89 | **/\r | |
90 | UINT16\r | |
91 | EFIAPI\r | |
92 | MmioRead16 (\r | |
93 | IN UINTN Address\r | |
94 | )\r | |
95 | {\r | |
96 | ASSERT ((Address & 1) == 0);\r | |
97 | return *(volatile UINT16*)Address;\r | |
98 | }\r | |
99 | \r | |
100 | /**\r | |
101 | Writes a 16-bit MMIO register.\r | |
102 | \r | |
103 | Writes the 16-bit MMIO register specified by Address with the value specified\r | |
104 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
105 | and write operations are serialized.\r | |
106 | \r | |
107 | If 16-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 108 | If Address is not aligned on a 16-bit boundary, then ASSERT().\r |
e1f414b6 | 109 | \r |
110 | @param Address The MMIO register to write.\r | |
111 | @param Value The value to write to the MMIO register.\r | |
2281e7a9 | 112 | \r |
113 | @return Value.\r | |
e1f414b6 | 114 | \r |
115 | **/\r | |
116 | UINT16\r | |
117 | EFIAPI\r | |
118 | MmioWrite16 (\r | |
119 | IN UINTN Address,\r | |
120 | IN UINT16 Value\r | |
121 | )\r | |
122 | {\r | |
123 | ASSERT ((Address & 1) == 0);\r | |
124 | return *(volatile UINT16*)Address = Value;\r | |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | Reads a 32-bit MMIO register.\r | |
129 | \r | |
130 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is\r | |
131 | returned. This function must guarantee that all MMIO read and write\r | |
132 | operations are serialized.\r | |
133 | \r | |
134 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 135 | If Address is not aligned on a 32-bit boundary, then ASSERT().\r |
e1f414b6 | 136 | \r |
137 | @param Address The MMIO register to read.\r | |
138 | \r | |
2281e7a9 | 139 | @return The value read.\r |
e1f414b6 | 140 | \r |
141 | **/\r | |
142 | UINT32\r | |
143 | EFIAPI\r | |
144 | MmioRead32 (\r | |
145 | IN UINTN Address\r | |
146 | )\r | |
147 | {\r | |
148 | ASSERT ((Address & 3) == 0);\r | |
149 | return *(volatile UINT32*)Address;\r | |
150 | }\r | |
151 | \r | |
152 | /**\r | |
153 | Writes a 32-bit MMIO register.\r | |
154 | \r | |
155 | Writes the 32-bit MMIO register specified by Address with the value specified\r | |
156 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
157 | and write operations are serialized.\r | |
158 | \r | |
159 | If 32-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 160 | If Address is not aligned on a 32-bit boundary, then ASSERT().\r |
e1f414b6 | 161 | \r |
162 | @param Address The MMIO register to write.\r | |
163 | @param Value The value to write to the MMIO register.\r | |
2281e7a9 | 164 | \r |
165 | @return Value.\r | |
e1f414b6 | 166 | \r |
167 | **/\r | |
168 | UINT32\r | |
169 | EFIAPI\r | |
170 | MmioWrite32 (\r | |
171 | IN UINTN Address,\r | |
172 | IN UINT32 Value\r | |
173 | )\r | |
174 | {\r | |
175 | ASSERT ((Address & 3) == 0);\r | |
176 | return *(volatile UINT32*)Address = Value;\r | |
177 | }\r | |
178 | \r | |
179 | /**\r | |
180 | Reads a 64-bit MMIO register.\r | |
181 | \r | |
182 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is\r | |
183 | returned. This function must guarantee that all MMIO read and write\r | |
184 | operations are serialized.\r | |
185 | \r | |
186 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 187 | If Address is not aligned on a 64-bit boundary, then ASSERT().\r |
e1f414b6 | 188 | \r |
189 | @param Address The MMIO register to read.\r | |
190 | \r | |
2281e7a9 | 191 | @return The value read.\r |
e1f414b6 | 192 | \r |
193 | **/\r | |
194 | UINT64\r | |
195 | EFIAPI\r | |
196 | MmioRead64 (\r | |
197 | IN UINTN Address\r | |
198 | )\r | |
199 | {\r | |
200 | ASSERT ((Address & 7) == 0);\r | |
201 | return *(volatile UINT64*)Address;\r | |
202 | }\r | |
203 | \r | |
204 | /**\r | |
205 | Writes a 64-bit MMIO register.\r | |
206 | \r | |
207 | Writes the 64-bit MMIO register specified by Address with the value specified\r | |
208 | by Value and returns Value. This function must guarantee that all MMIO read\r | |
209 | and write operations are serialized.\r | |
210 | \r | |
211 | If 64-bit MMIO register operations are not supported, then ASSERT().\r | |
2281e7a9 | 212 | If Address is not aligned on a 64-bit boundary, then ASSERT().\r |
e1f414b6 | 213 | \r |
214 | @param Address The MMIO register to write.\r | |
215 | @param Value The value to write to the MMIO register.\r | |
216 | \r | |
217 | **/\r | |
218 | UINT64\r | |
219 | EFIAPI\r | |
220 | MmioWrite64 (\r | |
221 | IN UINTN Address,\r | |
222 | IN UINT64 Value\r | |
223 | )\r | |
224 | {\r | |
225 | ASSERT ((Address & 7) == 0);\r | |
226 | return *(volatile UINT64*)Address = Value;\r | |
227 | }\r | |
228 | \r | |
229 | \r | |
230 | \r | |
231 | /**\r | |
232 | Reads an 8-bit I/O port.\r | |
233 | \r | |
234 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
235 | This function must guarantee that all I/O read and write operations are\r | |
236 | serialized.\r | |
237 | \r | |
238 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
239 | \r | |
240 | @param Port The I/O port to read.\r | |
241 | \r | |
38bbd3d9 | 242 | @return The value read from Port.\r |
e1f414b6 | 243 | \r |
244 | **/\r | |
245 | __inline__\r | |
2281e7a9 | 246 | /**\r |
247 | Reads an 8-bit I/O port.\r | |
248 | \r | |
249 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.\r | |
250 | This function must guarantee that all I/O read and write operations are\r | |
251 | serialized.\r | |
252 | \r | |
253 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
254 | \r | |
255 | @param Port The I/O port to read.\r | |
256 | \r | |
257 | @return The value read.\r | |
258 | \r | |
259 | **/\r | |
e1f414b6 | 260 | UINT8\r |
261 | EFIAPI\r | |
262 | IoRead8 (\r | |
263 | IN UINTN Port\r | |
264 | )\r | |
265 | {\r | |
266 | UINT8 Data;\r | |
267 | \r | |
268 | __asm__ __volatile__ ("inb %w1,%b0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
269 | return Data;\r | |
270 | }\r | |
271 | \r | |
272 | /**\r | |
273 | Writes an 8-bit I/O port.\r | |
274 | \r | |
275 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
276 | and returns Value. This function must guarantee that all I/O read and write\r | |
277 | operations are serialized.\r | |
278 | \r | |
279 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
280 | \r | |
281 | @param Port The I/O port to write.\r | |
282 | @param Value The value to write to the I/O port.\r | |
283 | \r | |
38bbd3d9 | 284 | @return The value written to the I/O port. It equals to the\r |
285 | input Value instead of the actual value read back from\r | |
286 | the I/O port.\r | |
e1f414b6 | 287 | \r |
288 | **/\r | |
289 | __inline__\r | |
2281e7a9 | 290 | /**\r |
291 | Writes an 8-bit I/O port.\r | |
292 | \r | |
293 | Writes the 8-bit I/O port specified by Port with the value specified by Value\r | |
294 | and returns Value. This function must guarantee that all I/O read and write\r | |
295 | operations are serialized.\r | |
296 | \r | |
297 | If 8-bit I/O port operations are not supported, then ASSERT().\r | |
298 | \r | |
299 | @param Port The I/O port to write.\r | |
300 | @param Value The value to write to the I/O port.\r | |
301 | \r | |
302 | @return The value written the I/O port.\r | |
303 | \r | |
304 | **/\r | |
e1f414b6 | 305 | UINT8\r |
306 | EFIAPI\r | |
307 | IoWrite8 (\r | |
308 | IN UINTN Port,\r | |
309 | IN UINT8 Value\r | |
310 | )\r | |
311 | {\r | |
312 | __asm__ __volatile__ ("outb %b0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
313 | return Value;;\r | |
314 | }\r | |
315 | \r | |
316 | /**\r | |
317 | Reads a 16-bit I/O port.\r | |
318 | \r | |
319 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
320 | This function must guarantee that all I/O read and write operations are\r | |
321 | serialized.\r | |
322 | \r | |
323 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
324 | \r | |
325 | @param Port The I/O port to read.\r | |
326 | \r | |
38bbd3d9 | 327 | @return The value read from Port.\r |
e1f414b6 | 328 | \r |
329 | **/\r | |
330 | __inline__\r | |
2281e7a9 | 331 | /**\r |
332 | Reads a 16-bit I/O port.\r | |
333 | \r | |
334 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.\r | |
335 | This function must guarantee that all I/O read and write operations are\r | |
336 | serialized.\r | |
337 | \r | |
338 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
339 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r | |
340 | \r | |
341 | @param Port The I/O port to read.\r | |
342 | \r | |
343 | @return The value read.\r | |
344 | \r | |
345 | **/\r | |
e1f414b6 | 346 | UINT16\r |
347 | EFIAPI\r | |
348 | IoRead16 (\r | |
349 | IN UINTN Port\r | |
350 | )\r | |
351 | {\r | |
352 | UINT16 Data;\r | |
353 | \r | |
354 | ASSERT ((Port & 1) == 0);\r | |
355 | __asm__ __volatile__ ("inw %w1,%w0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
356 | return Data;\r | |
357 | }\r | |
358 | \r | |
359 | /**\r | |
360 | Writes a 16-bit I/O port.\r | |
361 | \r | |
362 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
363 | and returns Value. This function must guarantee that all I/O read and write\r | |
364 | operations are serialized.\r | |
365 | \r | |
366 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
367 | \r | |
368 | @param Port The I/O port to write.\r | |
369 | @param Value The value to write to the I/O port.\r | |
370 | \r | |
38bbd3d9 | 371 | @return The value written to the I/O port. It equals to the\r |
372 | input Value instead of the actual value read back from\r | |
373 | the I/O port.\r | |
e1f414b6 | 374 | \r |
375 | **/\r | |
376 | __inline__\r | |
2281e7a9 | 377 | /**\r |
378 | Writes a 16-bit I/O port.\r | |
379 | \r | |
380 | Writes the 16-bit I/O port specified by Port with the value specified by Value\r | |
381 | and returns Value. This function must guarantee that all I/O read and write\r | |
382 | operations are serialized.\r | |
383 | \r | |
384 | If 16-bit I/O port operations are not supported, then ASSERT().\r | |
385 | If Port is not aligned on a 16-bit boundary, then ASSERT().\r | |
386 | \r | |
387 | @param Port The I/O port to write.\r | |
388 | @param Value The value to write to the I/O port.\r | |
389 | \r | |
390 | @return The value written the I/O port.\r | |
391 | \r | |
392 | **/\r | |
e1f414b6 | 393 | UINT16\r |
394 | EFIAPI\r | |
395 | IoWrite16 (\r | |
396 | IN UINTN Port,\r | |
397 | IN UINT16 Value\r | |
398 | )\r | |
399 | {\r | |
400 | ASSERT ((Port & 1) == 0);\r | |
401 | __asm__ __volatile__ ("outw %w0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
402 | return Value;;\r | |
403 | }\r | |
404 | \r | |
405 | /**\r | |
406 | Reads a 32-bit I/O port.\r | |
407 | \r | |
408 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
409 | This function must guarantee that all I/O read and write operations are\r | |
410 | serialized.\r | |
411 | \r | |
412 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
413 | \r | |
414 | @param Port The I/O port to read.\r | |
415 | \r | |
38bbd3d9 | 416 | @return The value read from Port.\r |
e1f414b6 | 417 | \r |
418 | **/\r | |
419 | __inline__\r | |
2281e7a9 | 420 | /**\r |
421 | Reads a 32-bit I/O port.\r | |
422 | \r | |
423 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.\r | |
424 | This function must guarantee that all I/O read and write operations are\r | |
425 | serialized.\r | |
426 | \r | |
427 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
428 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r | |
429 | \r | |
430 | @param Port The I/O port to read.\r | |
431 | \r | |
432 | @return The value read.\r | |
433 | \r | |
434 | **/\r | |
e1f414b6 | 435 | UINT32\r |
436 | EFIAPI\r | |
437 | IoRead32 (\r | |
438 | IN UINTN Port\r | |
439 | )\r | |
440 | {\r | |
441 | UINT32 Data;\r | |
442 | \r | |
443 | ASSERT ((Port & 3) == 0);\r | |
444 | __asm__ __volatile__ ("inl %w1,%0" : "=a" (Data) : "d" ((UINT16)Port));\r | |
445 | return Data;\r | |
446 | }\r | |
447 | \r | |
448 | /**\r | |
449 | Writes a 32-bit I/O port.\r | |
450 | \r | |
451 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
452 | and returns Value. This function must guarantee that all I/O read and write\r | |
453 | operations are serialized.\r | |
454 | \r | |
455 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
456 | \r | |
457 | @param Port The I/O port to write.\r | |
458 | @param Value The value to write to the I/O port.\r | |
459 | \r | |
38bbd3d9 | 460 | @return The value written to the I/O port. It equals to the\r |
461 | input Value instead of the actual value read back from\r | |
462 | the I/O port.\r | |
e1f414b6 | 463 | \r |
464 | **/\r | |
465 | __inline__\r | |
2281e7a9 | 466 | /**\r |
467 | Writes a 32-bit I/O port.\r | |
468 | \r | |
469 | Writes the 32-bit I/O port specified by Port with the value specified by Value\r | |
470 | and returns Value. This function must guarantee that all I/O read and write\r | |
471 | operations are serialized.\r | |
472 | \r | |
473 | If 32-bit I/O port operations are not supported, then ASSERT().\r | |
474 | If Port is not aligned on a 32-bit boundary, then ASSERT().\r | |
475 | \r | |
476 | @param Port The I/O port to write.\r | |
477 | @param Value The value to write to the I/O port.\r | |
478 | \r | |
479 | @return The value written the I/O port.\r | |
480 | \r | |
481 | **/\r | |
e1f414b6 | 482 | UINT32\r |
483 | EFIAPI\r | |
484 | IoWrite32 (\r | |
485 | IN UINTN Port,\r | |
2281e7a9 | 486 | IN UINT32 Value\r |
e1f414b6 | 487 | )\r |
488 | {\r | |
489 | ASSERT ((Port & 3) == 0);\r | |
490 | __asm__ __volatile__ ("outl %0,%w1" : : "a" (Value), "d" ((UINT16)Port));\r | |
491 | return Value;\r | |
492 | }\r | |
493 | \r |