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