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