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