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