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