1 | /** @file
|
---|
2 | I/O Library. The implementations are based on EFI_PEI_SERVICE->CpuIo interface.
|
---|
3 |
|
---|
4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include <PiPei.h>
|
---|
12 |
|
---|
13 | #include <Library/IoLib.h>
|
---|
14 | #include <Library/DebugLib.h>
|
---|
15 | #include <Library/BaseLib.h>
|
---|
16 | #include <Library/PeiServicesTablePointerLib.h>
|
---|
17 |
|
---|
18 | /**
|
---|
19 | Reads registers in the EFI CPU I/O space.
|
---|
20 |
|
---|
21 | Reads the I/O port specified by Port with registers width specified by Width.
|
---|
22 | The port is read Count times, and the read data is stored in the provided Buffer.
|
---|
23 |
|
---|
24 | This function must guarantee that all I/O read and write operations are serialized.
|
---|
25 | If such operations are not supported, then ASSERT().
|
---|
26 |
|
---|
27 | @param Port The base address of the I/O operation.
|
---|
28 | The caller is responsible for aligning the Address if required.
|
---|
29 | @param Width The width of the I/O operation.
|
---|
30 | @param Count The number of times to read I/O port.
|
---|
31 | @param Buffer The buffer to store the read data into.
|
---|
32 |
|
---|
33 | **/
|
---|
34 | VOID
|
---|
35 | EFIAPI
|
---|
36 | IoReadFifoWorker (
|
---|
37 | IN UINTN Port,
|
---|
38 | IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
|
---|
39 | IN UINTN Count,
|
---|
40 | IN VOID *Buffer
|
---|
41 | )
|
---|
42 | {
|
---|
43 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
44 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
45 | EFI_STATUS Status;
|
---|
46 |
|
---|
47 | PeiServices = GetPeiServicesTablePointer ();
|
---|
48 | CpuIo = (*PeiServices)->CpuIo;
|
---|
49 | ASSERT (CpuIo != NULL);
|
---|
50 |
|
---|
51 | Status = CpuIo->Io.Read (PeiServices, CpuIo, Width, Port, Count, Buffer);
|
---|
52 | ASSERT_EFI_ERROR (Status);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | Writes registers in the EFI CPU I/O space.
|
---|
57 |
|
---|
58 | Writes the I/O port specified by Port with registers width specified by Width.
|
---|
59 | The port is written Count times, and the write data is retrieved from the provided Buffer.
|
---|
60 |
|
---|
61 | This function must guarantee that all I/O read and write operations are serialized.
|
---|
62 | If such operations are not supported, then ASSERT().
|
---|
63 |
|
---|
64 | @param Port The base address of the I/O operation.
|
---|
65 | The caller is responsible for aligning the Address if required.
|
---|
66 | @param Width The width of the I/O operation.
|
---|
67 | @param Count The number of times to write I/O port.
|
---|
68 | @param Buffer The buffer to store the read data into.
|
---|
69 |
|
---|
70 | **/
|
---|
71 | VOID
|
---|
72 | EFIAPI
|
---|
73 | IoWriteFifoWorker (
|
---|
74 | IN UINTN Port,
|
---|
75 | IN EFI_PEI_CPU_IO_PPI_WIDTH Width,
|
---|
76 | IN UINTN Count,
|
---|
77 | IN VOID *Buffer
|
---|
78 | )
|
---|
79 | {
|
---|
80 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
81 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
82 | EFI_STATUS Status;
|
---|
83 |
|
---|
84 | PeiServices = GetPeiServicesTablePointer ();
|
---|
85 | CpuIo = (*PeiServices)->CpuIo;
|
---|
86 | ASSERT (CpuIo != NULL);
|
---|
87 |
|
---|
88 | Status = CpuIo->Io.Write (PeiServices, CpuIo, Width, Port, Count, Buffer);
|
---|
89 | ASSERT_EFI_ERROR (Status);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | Reads an 8-bit I/O port.
|
---|
94 |
|
---|
95 | Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
|
---|
96 | This function must guarantee that all I/O read and write operations are
|
---|
97 | serialized.
|
---|
98 |
|
---|
99 | If 8-bit I/O port operations are not supported, then ASSERT().
|
---|
100 |
|
---|
101 | @param Port The I/O port to read.
|
---|
102 |
|
---|
103 | @return The value read.
|
---|
104 |
|
---|
105 | **/
|
---|
106 | UINT8
|
---|
107 | EFIAPI
|
---|
108 | IoRead8 (
|
---|
109 | IN UINTN Port
|
---|
110 | )
|
---|
111 | {
|
---|
112 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
113 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
114 |
|
---|
115 | PeiServices = GetPeiServicesTablePointer ();
|
---|
116 | CpuIo = (*PeiServices)->CpuIo;
|
---|
117 | ASSERT (CpuIo != NULL);
|
---|
118 |
|
---|
119 | return CpuIo->IoRead8 (PeiServices, CpuIo, (UINT64)Port);
|
---|
120 | }
|
---|
121 |
|
---|
122 | /**
|
---|
123 | Writes an 8-bit I/O port.
|
---|
124 |
|
---|
125 | Writes the 8-bit I/O port specified by Port with the value specified by Value
|
---|
126 | and returns Value. This function must guarantee that all I/O read and write
|
---|
127 | operations are serialized.
|
---|
128 |
|
---|
129 | If 8-bit I/O port operations are not supported, then ASSERT().
|
---|
130 |
|
---|
131 | @param Port The I/O port to write.
|
---|
132 | @param Value The value to write to the I/O port.
|
---|
133 |
|
---|
134 | @return The value written the I/O port.
|
---|
135 |
|
---|
136 | **/
|
---|
137 | UINT8
|
---|
138 | EFIAPI
|
---|
139 | IoWrite8 (
|
---|
140 | IN UINTN Port,
|
---|
141 | IN UINT8 Value
|
---|
142 | )
|
---|
143 | {
|
---|
144 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
145 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
146 |
|
---|
147 | PeiServices = GetPeiServicesTablePointer ();
|
---|
148 | CpuIo = (*PeiServices)->CpuIo;
|
---|
149 | ASSERT (CpuIo != NULL);
|
---|
150 |
|
---|
151 | CpuIo->IoWrite8 (PeiServices, CpuIo, (UINT64)Port, Value);
|
---|
152 | return Value;
|
---|
153 | }
|
---|
154 |
|
---|
155 | /**
|
---|
156 | Reads a 16-bit I/O port.
|
---|
157 |
|
---|
158 | Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
|
---|
159 | This function must guarantee that all I/O read and write operations are
|
---|
160 | serialized.
|
---|
161 |
|
---|
162 | If 16-bit I/O port operations are not supported, then ASSERT().
|
---|
163 | If Port is not aligned on a 16-bit boundary, then ASSERT().
|
---|
164 |
|
---|
165 | @param Port The I/O port to read.
|
---|
166 |
|
---|
167 | @return The value read.
|
---|
168 |
|
---|
169 | **/
|
---|
170 | UINT16
|
---|
171 | EFIAPI
|
---|
172 | IoRead16 (
|
---|
173 | IN UINTN Port
|
---|
174 | )
|
---|
175 | {
|
---|
176 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
177 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
178 |
|
---|
179 | PeiServices = GetPeiServicesTablePointer ();
|
---|
180 | CpuIo = (*PeiServices)->CpuIo;
|
---|
181 | ASSERT (CpuIo != NULL);
|
---|
182 | //
|
---|
183 | // Make sure Port is aligned on a 16-bit boundary.
|
---|
184 | //
|
---|
185 | ASSERT ((Port & 1) == 0);
|
---|
186 | return CpuIo->IoRead16 (PeiServices, CpuIo, (UINT64)Port);
|
---|
187 | }
|
---|
188 |
|
---|
189 | /**
|
---|
190 | Writes a 16-bit I/O port.
|
---|
191 |
|
---|
192 | Writes the 16-bit I/O port specified by Port with the value specified by Value
|
---|
193 | and returns Value. This function must guarantee that all I/O read and write
|
---|
194 | operations are serialized.
|
---|
195 |
|
---|
196 | If 16-bit I/O port operations are not supported, then ASSERT().
|
---|
197 | If Port is not aligned on a 16-bit boundary, then ASSERT().
|
---|
198 |
|
---|
199 | @param Port The I/O port to write.
|
---|
200 | @param Value The value to write to the I/O port.
|
---|
201 |
|
---|
202 | @return The value written the I/O port.
|
---|
203 |
|
---|
204 | **/
|
---|
205 | UINT16
|
---|
206 | EFIAPI
|
---|
207 | IoWrite16 (
|
---|
208 | IN UINTN Port,
|
---|
209 | IN UINT16 Value
|
---|
210 | )
|
---|
211 | {
|
---|
212 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
213 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
214 |
|
---|
215 | PeiServices = GetPeiServicesTablePointer ();
|
---|
216 | CpuIo = (*PeiServices)->CpuIo;
|
---|
217 | ASSERT (CpuIo != NULL);
|
---|
218 | //
|
---|
219 | // Make sure Port is aligned on a 16-bit boundary.
|
---|
220 | //
|
---|
221 | ASSERT ((Port & 1) == 0);
|
---|
222 | CpuIo->IoWrite16 (PeiServices, CpuIo, (UINT64)Port, Value);
|
---|
223 | return Value;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | Reads a 32-bit I/O port.
|
---|
228 |
|
---|
229 | Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
|
---|
230 | This function must guarantee that all I/O read and write operations are
|
---|
231 | serialized.
|
---|
232 |
|
---|
233 | If 32-bit I/O port operations are not supported, then ASSERT().
|
---|
234 | If Port is not aligned on a 32-bit boundary, then ASSERT().
|
---|
235 |
|
---|
236 | @param Port The I/O port to read.
|
---|
237 |
|
---|
238 | @return The value read.
|
---|
239 |
|
---|
240 | **/
|
---|
241 | UINT32
|
---|
242 | EFIAPI
|
---|
243 | IoRead32 (
|
---|
244 | IN UINTN Port
|
---|
245 | )
|
---|
246 | {
|
---|
247 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
248 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
249 |
|
---|
250 | PeiServices = GetPeiServicesTablePointer ();
|
---|
251 | CpuIo = (*PeiServices)->CpuIo;
|
---|
252 | ASSERT (CpuIo != NULL);
|
---|
253 | //
|
---|
254 | // Make sure Port is aligned on a 32-bit boundary.
|
---|
255 | //
|
---|
256 | ASSERT ((Port & 3) == 0);
|
---|
257 | return CpuIo->IoRead32 (PeiServices, CpuIo, (UINT64)Port);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | Writes a 32-bit I/O port.
|
---|
262 |
|
---|
263 | Writes the 32-bit I/O port specified by Port with the value specified by Value
|
---|
264 | and returns Value. This function must guarantee that all I/O read and write
|
---|
265 | operations are serialized.
|
---|
266 |
|
---|
267 | If 32-bit I/O port operations are not supported, then ASSERT().
|
---|
268 | If Port is not aligned on a 32-bit boundary, then ASSERT().
|
---|
269 |
|
---|
270 | @param Port The I/O port to write.
|
---|
271 | @param Value The value to write to the I/O port.
|
---|
272 |
|
---|
273 | @return The value written the I/O port.
|
---|
274 |
|
---|
275 | **/
|
---|
276 | UINT32
|
---|
277 | EFIAPI
|
---|
278 | IoWrite32 (
|
---|
279 | IN UINTN Port,
|
---|
280 | IN UINT32 Value
|
---|
281 | )
|
---|
282 | {
|
---|
283 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
284 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
285 |
|
---|
286 | PeiServices = GetPeiServicesTablePointer ();
|
---|
287 | CpuIo = (*PeiServices)->CpuIo;
|
---|
288 | ASSERT (CpuIo != NULL);
|
---|
289 | //
|
---|
290 | // Make sure Port is aligned on a 32-bit boundary.
|
---|
291 | //
|
---|
292 | ASSERT ((Port & 3) == 0);
|
---|
293 | CpuIo->IoWrite32 (PeiServices, CpuIo, (UINT64)Port, Value);
|
---|
294 | return Value;
|
---|
295 | }
|
---|
296 |
|
---|
297 | /**
|
---|
298 | Reads a 64-bit I/O port.
|
---|
299 |
|
---|
300 | Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
|
---|
301 | This function must guarantee that all I/O read and write operations are
|
---|
302 | serialized.
|
---|
303 |
|
---|
304 | If 64-bit I/O port operations are not supported, then ASSERT().
|
---|
305 | If Port is not aligned on a 64-bit boundary, then ASSERT().
|
---|
306 |
|
---|
307 | @param Port The I/O port to read.
|
---|
308 |
|
---|
309 | @return The value read.
|
---|
310 |
|
---|
311 | **/
|
---|
312 | UINT64
|
---|
313 | EFIAPI
|
---|
314 | IoRead64 (
|
---|
315 | IN UINTN Port
|
---|
316 | )
|
---|
317 | {
|
---|
318 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
319 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
320 |
|
---|
321 | PeiServices = GetPeiServicesTablePointer ();
|
---|
322 | CpuIo = (*PeiServices)->CpuIo;
|
---|
323 | ASSERT (CpuIo != NULL);
|
---|
324 | //
|
---|
325 | // Make sure Port is aligned on a 64-bit boundary.
|
---|
326 | //
|
---|
327 | ASSERT ((Port & 7) == 0);
|
---|
328 | return CpuIo->IoRead64 (PeiServices, CpuIo, (UINT64)Port);
|
---|
329 | }
|
---|
330 |
|
---|
331 | /**
|
---|
332 | Writes a 64-bit I/O port.
|
---|
333 |
|
---|
334 | Writes the 64-bit I/O port specified by Port with the value specified by Value
|
---|
335 | and returns Value. This function must guarantee that all I/O read and write
|
---|
336 | operations are serialized.
|
---|
337 |
|
---|
338 | If 64-bit I/O port operations are not supported, then ASSERT().
|
---|
339 | If Port is not aligned on a 64-bit boundary, then ASSERT().
|
---|
340 |
|
---|
341 | @param Port The I/O port to write.
|
---|
342 | @param Value The value to write to the I/O port.
|
---|
343 |
|
---|
344 | @return The value written the I/O port.
|
---|
345 |
|
---|
346 | **/
|
---|
347 | UINT64
|
---|
348 | EFIAPI
|
---|
349 | IoWrite64 (
|
---|
350 | IN UINTN Port,
|
---|
351 | IN UINT64 Value
|
---|
352 | )
|
---|
353 | {
|
---|
354 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
355 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
356 |
|
---|
357 | PeiServices = GetPeiServicesTablePointer ();
|
---|
358 | CpuIo = (*PeiServices)->CpuIo;
|
---|
359 | ASSERT (CpuIo != NULL);
|
---|
360 | //
|
---|
361 | // Make sure Port is aligned on a 64-bit boundary.
|
---|
362 | //
|
---|
363 | ASSERT ((Port & 7) == 0);
|
---|
364 | CpuIo->IoWrite64 (PeiServices, CpuIo, (UINT64)Port, Value);
|
---|
365 | return Value;
|
---|
366 | }
|
---|
367 |
|
---|
368 | /**
|
---|
369 | Reads an 8-bit I/O port fifo into a block of memory.
|
---|
370 |
|
---|
371 | Reads the 8-bit I/O fifo port specified by Port.
|
---|
372 | The port is read Count times, and the read data is
|
---|
373 | stored in the provided Buffer.
|
---|
374 |
|
---|
375 | This function must guarantee that all I/O read and write operations are
|
---|
376 | serialized.
|
---|
377 |
|
---|
378 | If 8-bit I/O port operations are not supported, then ASSERT().
|
---|
379 |
|
---|
380 | @param Port The I/O port to read.
|
---|
381 | @param Count The number of times to read I/O port.
|
---|
382 | @param Buffer The buffer to store the read data into.
|
---|
383 |
|
---|
384 | **/
|
---|
385 | VOID
|
---|
386 | EFIAPI
|
---|
387 | IoReadFifo8 (
|
---|
388 | IN UINTN Port,
|
---|
389 | IN UINTN Count,
|
---|
390 | OUT VOID *Buffer
|
---|
391 | )
|
---|
392 | {
|
---|
393 | IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint8, Count, Buffer);
|
---|
394 | }
|
---|
395 |
|
---|
396 | /**
|
---|
397 | Writes a block of memory into an 8-bit I/O port fifo.
|
---|
398 |
|
---|
399 | Writes the 8-bit I/O fifo port specified by Port.
|
---|
400 | The port is written Count times, and the write data is
|
---|
401 | retrieved from the provided Buffer.
|
---|
402 |
|
---|
403 | This function must guarantee that all I/O write and write operations are
|
---|
404 | serialized.
|
---|
405 |
|
---|
406 | If 8-bit I/O port operations are not supported, then ASSERT().
|
---|
407 |
|
---|
408 | @param Port The I/O port to write.
|
---|
409 | @param Count The number of times to write I/O port.
|
---|
410 | @param Buffer The buffer to retrieve the write data from.
|
---|
411 |
|
---|
412 | **/
|
---|
413 | VOID
|
---|
414 | EFIAPI
|
---|
415 | IoWriteFifo8 (
|
---|
416 | IN UINTN Port,
|
---|
417 | IN UINTN Count,
|
---|
418 | IN VOID *Buffer
|
---|
419 | )
|
---|
420 | {
|
---|
421 | IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint8, Count, Buffer);
|
---|
422 | }
|
---|
423 |
|
---|
424 | /**
|
---|
425 | Reads a 16-bit I/O port fifo into a block of memory.
|
---|
426 |
|
---|
427 | Reads the 16-bit I/O fifo port specified by Port.
|
---|
428 | The port is read Count times, and the read data is
|
---|
429 | stored in the provided Buffer.
|
---|
430 |
|
---|
431 | This function must guarantee that all I/O read and write operations are
|
---|
432 | serialized.
|
---|
433 |
|
---|
434 | If 16-bit I/O port operations are not supported, then ASSERT().
|
---|
435 |
|
---|
436 | @param Port The I/O port to read.
|
---|
437 | @param Count The number of times to read I/O port.
|
---|
438 | @param Buffer The buffer to store the read data into.
|
---|
439 |
|
---|
440 | **/
|
---|
441 | VOID
|
---|
442 | EFIAPI
|
---|
443 | IoReadFifo16 (
|
---|
444 | IN UINTN Port,
|
---|
445 | IN UINTN Count,
|
---|
446 | OUT VOID *Buffer
|
---|
447 | )
|
---|
448 | {
|
---|
449 | //
|
---|
450 | // Make sure Port is aligned on a 16-bit boundary.
|
---|
451 | //
|
---|
452 | ASSERT ((Port & 1) == 0);
|
---|
453 | IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint16, Count, Buffer);
|
---|
454 | }
|
---|
455 |
|
---|
456 | /**
|
---|
457 | Writes a block of memory into a 16-bit I/O port fifo.
|
---|
458 |
|
---|
459 | Writes the 16-bit I/O fifo port specified by Port.
|
---|
460 | The port is written Count times, and the write data is
|
---|
461 | retrieved from the provided Buffer.
|
---|
462 |
|
---|
463 | This function must guarantee that all I/O write and write operations are
|
---|
464 | serialized.
|
---|
465 |
|
---|
466 | If 16-bit I/O port operations are not supported, then ASSERT().
|
---|
467 |
|
---|
468 | @param Port The I/O port to write.
|
---|
469 | @param Count The number of times to write I/O port.
|
---|
470 | @param Buffer The buffer to retrieve the write data from.
|
---|
471 |
|
---|
472 | **/
|
---|
473 | VOID
|
---|
474 | EFIAPI
|
---|
475 | IoWriteFifo16 (
|
---|
476 | IN UINTN Port,
|
---|
477 | IN UINTN Count,
|
---|
478 | IN VOID *Buffer
|
---|
479 | )
|
---|
480 | {
|
---|
481 | //
|
---|
482 | // Make sure Port is aligned on a 16-bit boundary.
|
---|
483 | //
|
---|
484 | ASSERT ((Port & 1) == 0);
|
---|
485 | IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint16, Count, Buffer);
|
---|
486 | }
|
---|
487 |
|
---|
488 | /**
|
---|
489 | Reads a 32-bit I/O port fifo into a block of memory.
|
---|
490 |
|
---|
491 | Reads the 32-bit I/O fifo port specified by Port.
|
---|
492 | The port is read Count times, and the read data is
|
---|
493 | stored in the provided Buffer.
|
---|
494 |
|
---|
495 | This function must guarantee that all I/O read and write operations are
|
---|
496 | serialized.
|
---|
497 |
|
---|
498 | If 32-bit I/O port operations are not supported, then ASSERT().
|
---|
499 |
|
---|
500 | @param Port The I/O port to read.
|
---|
501 | @param Count The number of times to read I/O port.
|
---|
502 | @param Buffer The buffer to store the read data into.
|
---|
503 |
|
---|
504 | **/
|
---|
505 | VOID
|
---|
506 | EFIAPI
|
---|
507 | IoReadFifo32 (
|
---|
508 | IN UINTN Port,
|
---|
509 | IN UINTN Count,
|
---|
510 | OUT VOID *Buffer
|
---|
511 | )
|
---|
512 | {
|
---|
513 | //
|
---|
514 | // Make sure Port is aligned on a 32-bit boundary.
|
---|
515 | //
|
---|
516 | ASSERT ((Port & 3) == 0);
|
---|
517 | IoReadFifoWorker (Port, EfiPeiCpuIoWidthFifoUint32, Count, Buffer);
|
---|
518 | }
|
---|
519 |
|
---|
520 | /**
|
---|
521 | Writes a block of memory into a 32-bit I/O port fifo.
|
---|
522 |
|
---|
523 | Writes the 32-bit I/O fifo port specified by Port.
|
---|
524 | The port is written Count times, and the write data is
|
---|
525 | retrieved from the provided Buffer.
|
---|
526 |
|
---|
527 | This function must guarantee that all I/O write and write operations are
|
---|
528 | serialized.
|
---|
529 |
|
---|
530 | If 32-bit I/O port operations are not supported, then ASSERT().
|
---|
531 |
|
---|
532 | @param Port The I/O port to write.
|
---|
533 | @param Count The number of times to write I/O port.
|
---|
534 | @param Buffer The buffer to retrieve the write data from.
|
---|
535 |
|
---|
536 | **/
|
---|
537 | VOID
|
---|
538 | EFIAPI
|
---|
539 | IoWriteFifo32 (
|
---|
540 | IN UINTN Port,
|
---|
541 | IN UINTN Count,
|
---|
542 | IN VOID *Buffer
|
---|
543 | )
|
---|
544 | {
|
---|
545 | //
|
---|
546 | // Make sure Port is aligned on a 32-bit boundary.
|
---|
547 | //
|
---|
548 | ASSERT ((Port & 3) == 0);
|
---|
549 | IoWriteFifoWorker (Port, EfiPeiCpuIoWidthFifoUint32, Count, Buffer);
|
---|
550 | }
|
---|
551 |
|
---|
552 | /**
|
---|
553 | Reads an 8-bit MMIO register.
|
---|
554 |
|
---|
555 | Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
|
---|
556 | returned. This function must guarantee that all MMIO read and write
|
---|
557 | operations are serialized.
|
---|
558 |
|
---|
559 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
---|
560 |
|
---|
561 | @param Address The MMIO register to read.
|
---|
562 |
|
---|
563 | @return The value read.
|
---|
564 |
|
---|
565 | **/
|
---|
566 | UINT8
|
---|
567 | EFIAPI
|
---|
568 | MmioRead8 (
|
---|
569 | IN UINTN Address
|
---|
570 | )
|
---|
571 | {
|
---|
572 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
573 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
574 |
|
---|
575 | PeiServices = GetPeiServicesTablePointer ();
|
---|
576 | CpuIo = (*PeiServices)->CpuIo;
|
---|
577 | ASSERT (CpuIo != NULL);
|
---|
578 |
|
---|
579 | return CpuIo->MemRead8 (PeiServices, CpuIo, (UINT64)Address);
|
---|
580 | }
|
---|
581 |
|
---|
582 | /**
|
---|
583 | Writes an 8-bit MMIO register.
|
---|
584 |
|
---|
585 | Writes the 8-bit MMIO register specified by Address with the value specified
|
---|
586 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
587 | and write operations are serialized.
|
---|
588 |
|
---|
589 | If 8-bit MMIO register operations are not supported, then ASSERT().
|
---|
590 |
|
---|
591 | @param Address The MMIO register to write.
|
---|
592 | @param Value The value to write to the MMIO register.
|
---|
593 |
|
---|
594 | @return Value.
|
---|
595 |
|
---|
596 | **/
|
---|
597 | UINT8
|
---|
598 | EFIAPI
|
---|
599 | MmioWrite8 (
|
---|
600 | IN UINTN Address,
|
---|
601 | IN UINT8 Value
|
---|
602 | )
|
---|
603 | {
|
---|
604 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
605 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
606 |
|
---|
607 | PeiServices = GetPeiServicesTablePointer ();
|
---|
608 | CpuIo = (*PeiServices)->CpuIo;
|
---|
609 | ASSERT (CpuIo != NULL);
|
---|
610 |
|
---|
611 | CpuIo->MemWrite8 (PeiServices, CpuIo, (UINT64)Address, Value);
|
---|
612 | return Value;
|
---|
613 | }
|
---|
614 |
|
---|
615 | /**
|
---|
616 | Reads a 16-bit MMIO register.
|
---|
617 |
|
---|
618 | Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
|
---|
619 | returned. This function must guarantee that all MMIO read and write
|
---|
620 | operations are serialized.
|
---|
621 |
|
---|
622 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
---|
623 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
624 |
|
---|
625 | @param Address The MMIO register to read.
|
---|
626 |
|
---|
627 | @return The value read.
|
---|
628 |
|
---|
629 | **/
|
---|
630 | UINT16
|
---|
631 | EFIAPI
|
---|
632 | MmioRead16 (
|
---|
633 | IN UINTN Address
|
---|
634 | )
|
---|
635 | {
|
---|
636 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
637 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
638 |
|
---|
639 | PeiServices = GetPeiServicesTablePointer ();
|
---|
640 | CpuIo = (*PeiServices)->CpuIo;
|
---|
641 | ASSERT (CpuIo != NULL);
|
---|
642 | //
|
---|
643 | // Make sure Address is aligned on a 16-bit boundary.
|
---|
644 | //
|
---|
645 | ASSERT ((Address & 1) == 0);
|
---|
646 | return CpuIo->MemRead16 (PeiServices, CpuIo, (UINT64)Address);
|
---|
647 | }
|
---|
648 |
|
---|
649 | /**
|
---|
650 | Writes a 16-bit MMIO register.
|
---|
651 |
|
---|
652 | Writes the 16-bit MMIO register specified by Address with the value specified
|
---|
653 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
654 | and write operations are serialized.
|
---|
655 |
|
---|
656 | If 16-bit MMIO register operations are not supported, then ASSERT().
|
---|
657 | If Address is not aligned on a 16-bit boundary, then ASSERT().
|
---|
658 |
|
---|
659 | @param Address The MMIO register to write.
|
---|
660 | @param Value The value to write to the MMIO register.
|
---|
661 |
|
---|
662 | @return Value.
|
---|
663 |
|
---|
664 | **/
|
---|
665 | UINT16
|
---|
666 | EFIAPI
|
---|
667 | MmioWrite16 (
|
---|
668 | IN UINTN Address,
|
---|
669 | IN UINT16 Value
|
---|
670 | )
|
---|
671 | {
|
---|
672 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
673 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
674 |
|
---|
675 | PeiServices = GetPeiServicesTablePointer ();
|
---|
676 | CpuIo = (*PeiServices)->CpuIo;
|
---|
677 | ASSERT (CpuIo != NULL);
|
---|
678 | //
|
---|
679 | // Make sure Address is aligned on a 16-bit boundary.
|
---|
680 | //
|
---|
681 | ASSERT ((Address & 1) == 0);
|
---|
682 | CpuIo->MemWrite16 (PeiServices, CpuIo, (UINT64)Address, Value);
|
---|
683 | return Value;
|
---|
684 | }
|
---|
685 |
|
---|
686 | /**
|
---|
687 | Reads a 32-bit MMIO register.
|
---|
688 |
|
---|
689 | Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
|
---|
690 | returned. This function must guarantee that all MMIO read and write
|
---|
691 | operations are serialized.
|
---|
692 |
|
---|
693 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
---|
694 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
695 |
|
---|
696 | @param Address The MMIO register to read.
|
---|
697 |
|
---|
698 | @return The value read.
|
---|
699 |
|
---|
700 | **/
|
---|
701 | UINT32
|
---|
702 | EFIAPI
|
---|
703 | MmioRead32 (
|
---|
704 | IN UINTN Address
|
---|
705 | )
|
---|
706 | {
|
---|
707 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
708 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
709 |
|
---|
710 | PeiServices = GetPeiServicesTablePointer ();
|
---|
711 | CpuIo = (*PeiServices)->CpuIo;
|
---|
712 | ASSERT (CpuIo != NULL);
|
---|
713 | //
|
---|
714 | // Make sure Address is aligned on a 32-bit boundary.
|
---|
715 | //
|
---|
716 | ASSERT ((Address & 3) == 0);
|
---|
717 | return CpuIo->MemRead32 (PeiServices, CpuIo, (UINT64)Address);
|
---|
718 | }
|
---|
719 |
|
---|
720 | /**
|
---|
721 | Writes a 32-bit MMIO register.
|
---|
722 |
|
---|
723 | Writes the 32-bit MMIO register specified by Address with the value specified
|
---|
724 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
725 | and write operations are serialized.
|
---|
726 |
|
---|
727 | If 32-bit MMIO register operations are not supported, then ASSERT().
|
---|
728 | If Address is not aligned on a 32-bit boundary, then ASSERT().
|
---|
729 |
|
---|
730 | @param Address The MMIO register to write.
|
---|
731 | @param Value The value to write to the MMIO register.
|
---|
732 |
|
---|
733 | @return Value.
|
---|
734 |
|
---|
735 | **/
|
---|
736 | UINT32
|
---|
737 | EFIAPI
|
---|
738 | MmioWrite32 (
|
---|
739 | IN UINTN Address,
|
---|
740 | IN UINT32 Value
|
---|
741 | )
|
---|
742 | {
|
---|
743 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
744 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
745 |
|
---|
746 | PeiServices = GetPeiServicesTablePointer ();
|
---|
747 | CpuIo = (*PeiServices)->CpuIo;
|
---|
748 | ASSERT (CpuIo != NULL);
|
---|
749 | //
|
---|
750 | // Make sure Address is aligned on a 32-bit boundary.
|
---|
751 | //
|
---|
752 | ASSERT ((Address & 3) == 0);
|
---|
753 | CpuIo->MemWrite32 (PeiServices, CpuIo, (UINT64)Address, Value);
|
---|
754 | return Value;
|
---|
755 | }
|
---|
756 |
|
---|
757 | /**
|
---|
758 | Reads a 64-bit MMIO register.
|
---|
759 |
|
---|
760 | Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
|
---|
761 | returned. This function must guarantee that all MMIO read and write
|
---|
762 | operations are serialized.
|
---|
763 |
|
---|
764 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
---|
765 | If Address is not aligned on a 64-bit boundary, then ASSERT().
|
---|
766 |
|
---|
767 | @param Address The MMIO register to read.
|
---|
768 |
|
---|
769 | @return The value read.
|
---|
770 |
|
---|
771 | **/
|
---|
772 | UINT64
|
---|
773 | EFIAPI
|
---|
774 | MmioRead64 (
|
---|
775 | IN UINTN Address
|
---|
776 | )
|
---|
777 | {
|
---|
778 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
779 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
780 |
|
---|
781 | PeiServices = GetPeiServicesTablePointer ();
|
---|
782 | CpuIo = (*PeiServices)->CpuIo;
|
---|
783 | ASSERT (CpuIo != NULL);
|
---|
784 | //
|
---|
785 | // Make sure Address is aligned on a 64-bit boundary.
|
---|
786 | //
|
---|
787 | ASSERT ((Address & (sizeof (UINT64) - 1)) == 0);
|
---|
788 | return CpuIo->MemRead64 (PeiServices, CpuIo, (UINT64)Address);
|
---|
789 | }
|
---|
790 |
|
---|
791 | /**
|
---|
792 | Writes a 64-bit MMIO register.
|
---|
793 |
|
---|
794 | Writes the 64-bit MMIO register specified by Address with the value specified
|
---|
795 | by Value and returns Value. This function must guarantee that all MMIO read
|
---|
796 | and write operations are serialized.
|
---|
797 |
|
---|
798 | If 64-bit MMIO register operations are not supported, then ASSERT().
|
---|
799 | If Address is not aligned on a 64-bit boundary, then ASSERT().
|
---|
800 |
|
---|
801 | @param Address The MMIO register to write.
|
---|
802 | @param Value The value to write to the MMIO register.
|
---|
803 |
|
---|
804 | **/
|
---|
805 | UINT64
|
---|
806 | EFIAPI
|
---|
807 | MmioWrite64 (
|
---|
808 | IN UINTN Address,
|
---|
809 | IN UINT64 Value
|
---|
810 | )
|
---|
811 | {
|
---|
812 | CONST EFI_PEI_SERVICES **PeiServices;
|
---|
813 | EFI_PEI_CPU_IO_PPI *CpuIo;
|
---|
814 |
|
---|
815 | PeiServices = GetPeiServicesTablePointer ();
|
---|
816 | CpuIo = (*PeiServices)->CpuIo;
|
---|
817 | ASSERT (CpuIo != NULL);
|
---|
818 | //
|
---|
819 | // Make sure Address is aligned on a 64-bit boundary.
|
---|
820 | //
|
---|
821 | ASSERT ((Address & 7) == 0);
|
---|
822 | CpuIo->MemWrite64 (PeiServices, CpuIo, (UINT64)Address, Value);
|
---|
823 | return Value;
|
---|
824 | }
|
---|