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