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