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