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