3 The implementation of I/O operation for this library instance
4 are based on EFI_CPU_IO_PROTOCOL.
6 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
7 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php.
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "SmmCpuIoLibInternal.h"
22 Reads registers in the EFI CPU I/O space.
24 Reads the I/O port specified by Port with registers width specified by Width.
25 The read value is returned. If such operations are not supported, then ASSERT().
26 This function must guarantee that all I/O read and write operations are serialized.
28 @param Port The base address of the I/O operation.
29 The caller is responsible for aligning the Address if required.
30 @param Width The width of the I/O operation.
32 @return Data read from registers in the EFI CPU I/O space.
39 IN EFI_SMM_IO_WIDTH Width
45 Status
= gSmst
->SmmIo
.Io
.Read (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
46 ASSERT_EFI_ERROR (Status
);
52 Writes registers in the EFI CPU I/O space.
54 Writes the I/O port specified by Port with registers width and value specified by Width
55 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
56 This function must guarantee that all I/O read and write operations are serialized.
58 @param Port The base address of the I/O operation.
59 The caller is responsible for aligning the Address if required.
60 @param Width The width of the I/O operation.
61 @param Data The value to write to the I/O port.
63 @return The parameter of Data.
70 IN EFI_SMM_IO_WIDTH Width
,
76 Status
= gSmst
->SmmIo
.Io
.Write (&gSmst
->SmmIo
, Width
, Port
, 1, &Data
);
77 ASSERT_EFI_ERROR (Status
);
83 Reads memory-mapped registers in the EFI system memory space.
85 Reads the MMIO registers specified by Address with registers width specified by Width.
86 The read value is returned. If such operations are not supported, then ASSERT().
87 This function must guarantee that all MMIO read and write operations are serialized.
89 @param Address The MMIO register to read.
90 The caller is responsible for aligning the Address if required.
91 @param Width The width of the I/O operation.
93 @return Data read from registers in the EFI system memory space.
100 IN EFI_SMM_IO_WIDTH Width
106 Status
= gSmst
->SmmIo
.Mem
.Read (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
107 ASSERT_EFI_ERROR (Status
);
113 Writes memory-mapped registers in the EFI system memory space.
115 Writes the MMIO registers specified by Address with registers width and value specified by Width
116 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
117 This function must guarantee that all MMIO read and write operations are serialized.
119 @param Address The MMIO register to read.
120 The caller is responsible for aligning the Address if required.
121 @param Width The width of the I/O operation.
122 @param Data The value to write to the I/O port.
124 @return Data read from registers in the EFI system memory space.
131 IN EFI_SMM_IO_WIDTH Width
,
137 Status
= gSmst
->SmmIo
.Mem
.Write (&gSmst
->SmmIo
, Width
, Address
, 1, &Data
);
138 ASSERT_EFI_ERROR (Status
);
144 Reads an 8-bit I/O port.
146 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
147 This function must guarantee that all I/O read and write operations are
150 If 8-bit I/O port operations are not supported, then ASSERT().
152 @param Port The I/O port to read.
154 @return The value read.
163 return (UINT8
)IoReadWorker (Port
, SMM_IO_UINT8
);
167 Writes an 8-bit I/O port.
169 Writes the 8-bit I/O port specified by Port with the value specified by Value
170 and returns Value. This function must guarantee that all I/O read and write
171 operations are serialized.
173 If 8-bit I/O port operations are not supported, then ASSERT().
175 @param Port The I/O port to write.
176 @param Value The value to write to the I/O port.
178 @return The value written the I/O port.
188 return (UINT8
)IoWriteWorker (Port
, SMM_IO_UINT8
, Value
);
192 Reads a 16-bit I/O port.
194 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
195 This function must guarantee that all I/O read and write operations are
198 If Port is not aligned on a 16-bit boundary, then ASSERT().
200 If 16-bit I/O port operations are not supported, then ASSERT().
202 @param Port The I/O port to read.
204 @return The value read.
214 // Make sure Port is aligned on a 16-bit boundary.
216 ASSERT ((Port
& 1) == 0);
217 return (UINT16
)IoReadWorker (Port
, SMM_IO_UINT16
);
221 Writes a 16-bit I/O port.
223 Writes the 16-bit I/O port specified by Port with the value specified by Value
224 and returns Value. This function must guarantee that all I/O read and write
225 operations are serialized.
227 If Port is not aligned on a 16-bit boundary, then ASSERT().
229 If 16-bit I/O port operations are not supported, then ASSERT().
231 @param Port The I/O port to write.
232 @param Value The value to write to the I/O port.
234 @return The value written the I/O port.
245 // Make sure Port is aligned on a 16-bit boundary.
247 ASSERT ((Port
& 1) == 0);
248 return (UINT16
)IoWriteWorker (Port
, SMM_IO_UINT16
, Value
);
252 Reads a 32-bit I/O port.
254 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
255 This function must guarantee that all I/O read and write operations are
258 If Port is not aligned on a 32-bit boundary, then ASSERT().
260 If 32-bit I/O port operations are not supported, then ASSERT().
262 @param Port The I/O port to read.
264 @return The value read.
274 // Make sure Port is aligned on a 32-bit boundary.
276 ASSERT ((Port
& 3) == 0);
277 return (UINT32
)IoReadWorker (Port
, SMM_IO_UINT32
);
281 Writes a 32-bit I/O port.
283 Writes the 32-bit I/O port specified by Port with the value specified by Value
284 and returns Value. This function must guarantee that all I/O read and write
285 operations are serialized.
287 If Port is not aligned on a 32-bit boundary, then ASSERT().
289 If 32-bit I/O port operations are not supported, then ASSERT().
291 @param Port The I/O port to write.
292 @param Value The value to write to the I/O port.
294 @return The value written the I/O port.
305 // Make sure Port is aligned on a 32-bit boundary.
307 ASSERT ((Port
& 3) == 0);
308 return (UINT32
)IoWriteWorker (Port
, SMM_IO_UINT32
, Value
);
312 Reads a 64-bit I/O port.
314 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
315 This function must guarantee that all I/O read and write operations are
318 If Port is not aligned on a 64-bit boundary, then ASSERT().
320 If 64-bit I/O port operations are not supported, then ASSERT().
322 @param Port The I/O port to read.
324 @return The value read.
334 // Make sure Port is aligned on a 64-bit boundary.
336 ASSERT ((Port
& 7) == 0);
337 return IoReadWorker (Port
, SMM_IO_UINT64
);
341 Writes a 64-bit I/O port.
343 Writes the 64-bit I/O port specified by Port with the value specified by Value
344 and returns Value. This function must guarantee that all I/O read and write
345 operations are serialized.
347 If Port is not aligned on a 64-bit boundary, then ASSERT().
349 If 64-bit I/O port operations are not supported, then ASSERT().
351 @param Port The I/O port to write.
352 @param Value The value to write to the I/O port.
354 @return The value written the I/O port.
365 // Make sure Port is aligned on a 64-bit boundary.
367 ASSERT ((Port
& 7) == 0);
368 return IoWriteWorker (Port
, SMM_IO_UINT64
, Value
);
372 Reads an 8-bit I/O port fifo into a block of memory.
374 Reads the 8-bit I/O fifo port specified by Port.
375 The port is read Count times, and the read data is
376 stored in the provided Buffer.
378 This function must guarantee that all I/O read and write operations are
381 If 8-bit I/O port operations are not supported, then ASSERT().
383 @param Port The I/O port to read.
384 @param Count The number of times to read I/O port.
385 @param Buffer The buffer to store the read data into.
398 Buffer8
= (UINT8
*)Buffer
;
399 while (Count
-- > 0) {
400 *Buffer8
++ = IoRead8 (Port
);
405 Writes a block of memory into an 8-bit I/O port fifo.
407 Writes the 8-bit I/O fifo port specified by Port.
408 The port is written Count times, and the write data is
409 retrieved from the provided Buffer.
411 This function must guarantee that all I/O write and write operations are
414 If 8-bit I/O port operations are not supported, then ASSERT().
416 @param Port The I/O port to write.
417 @param Count The number of times to write I/O port.
418 @param Buffer The buffer to retrieve the write data from.
431 Buffer8
= (UINT8
*)Buffer
;
432 while (Count
-- > 0) {
433 IoWrite8 (Port
, *Buffer8
++);
438 Reads a 16-bit I/O port fifo into a block of memory.
440 Reads the 16-bit I/O fifo port specified by Port.
441 The port is read Count times, and the read data is
442 stored in the provided Buffer.
444 This function must guarantee that all I/O read and write operations are
447 If 16-bit I/O port operations are not supported, then ASSERT().
449 @param Port The I/O port to read.
450 @param Count The number of times to read I/O port.
451 @param Buffer The buffer to store the read data into.
465 // Make sure Port is aligned on a 16-bit boundary.
467 ASSERT ((Port
& 1) == 0);
468 Buffer16
= (UINT16
*)Buffer
;
469 while (Count
-- > 0) {
470 *Buffer16
++ = IoRead16 (Port
);
475 Writes a block of memory into a 16-bit I/O port fifo.
477 Writes the 16-bit I/O fifo port specified by Port.
478 The port is written Count times, and the write data is
479 retrieved from the provided Buffer.
481 This function must guarantee that all I/O write and write operations are
484 If 16-bit I/O port operations are not supported, then ASSERT().
486 @param Port The I/O port to write.
487 @param Count The number of times to write I/O port.
488 @param Buffer The buffer to retrieve the write data from.
502 // Make sure Port is aligned on a 16-bit boundary.
504 ASSERT ((Port
& 1) == 0);
505 Buffer16
= (UINT16
*)Buffer
;
506 while (Count
-- > 0) {
507 IoWrite16 (Port
, *Buffer16
++);
512 Reads a 32-bit I/O port fifo into a block of memory.
514 Reads the 32-bit I/O fifo port specified by Port.
515 The port is read Count times, and the read data is
516 stored in the provided Buffer.
518 This function must guarantee that all I/O read and write operations are
521 If 32-bit I/O port operations are not supported, then ASSERT().
523 @param Port The I/O port to read.
524 @param Count The number of times to read I/O port.
525 @param Buffer The buffer to store the read data into.
539 // Make sure Port is aligned on a 32-bit boundary.
541 ASSERT ((Port
& 3) == 0);
542 Buffer32
= (UINT32
*)Buffer
;
543 while (Count
-- > 0) {
544 *Buffer32
++ = IoRead32 (Port
);
549 Writes a block of memory into a 32-bit I/O port fifo.
551 Writes the 32-bit I/O fifo port specified by Port.
552 The port is written Count times, and the write data is
553 retrieved from the provided Buffer.
555 This function must guarantee that all I/O write and write operations are
558 If 32-bit I/O port operations are not supported, then ASSERT().
560 @param Port The I/O port to write.
561 @param Count The number of times to write I/O port.
562 @param Buffer The buffer to retrieve the write data from.
576 // Make sure Port is aligned on a 32-bit boundary.
578 ASSERT ((Port
& 3) == 0);
579 Buffer32
= (UINT32
*)Buffer
;
580 while (Count
-- > 0) {
581 IoWrite32 (Port
, *Buffer32
++);
586 Reads an 8-bit MMIO register.
588 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
589 returned. This function must guarantee that all MMIO read and write
590 operations are serialized.
592 If 8-bit MMIO register operations are not supported, then ASSERT().
594 @param Address The MMIO register to read.
596 @return The value read.
605 return (UINT8
)MmioReadWorker (Address
, SMM_IO_UINT8
);
609 Writes an 8-bit MMIO register.
611 Writes the 8-bit MMIO register specified by Address with the value specified
612 by Value and returns Value. This function must guarantee that all MMIO read
613 and write operations are serialized.
615 If 8-bit MMIO register operations are not supported, then ASSERT().
617 @param Address The MMIO register to write.
618 @param Value The value to write to the MMIO register.
628 return (UINT8
)MmioWriteWorker (Address
, SMM_IO_UINT8
, Value
);
632 Reads a 16-bit MMIO register.
634 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
635 returned. This function must guarantee that all MMIO read and write
636 operations are serialized.
638 If Address is not aligned on a 16-bit boundary, then ASSERT().
640 If 16-bit MMIO register operations are not supported, then ASSERT().
642 @param Address The MMIO register to read.
644 @return The value read.
654 // Make sure Address is aligned on a 16-bit boundary.
656 ASSERT ((Address
& 1) == 0);
657 return (UINT16
)MmioReadWorker (Address
, SMM_IO_UINT16
);
661 Writes a 16-bit MMIO register.
663 Writes the 16-bit MMIO register specified by Address with the value specified
664 by Value and returns Value. This function must guarantee that all MMIO read
665 and write operations are serialized.
667 If Address is not aligned on a 16-bit boundary, then ASSERT().
669 If 16-bit MMIO register operations are not supported, then ASSERT().
671 @param Address The MMIO register to write.
672 @param Value The value to write to the MMIO register.
683 // Make sure Address is aligned on a 16-bit boundary.
685 ASSERT ((Address
& 1) == 0);
686 return (UINT16
)MmioWriteWorker (Address
, SMM_IO_UINT16
, Value
);
690 Reads a 32-bit MMIO register.
692 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
693 returned. This function must guarantee that all MMIO read and write
694 operations are serialized.
696 If Address is not aligned on a 32-bit boundary, then ASSERT().
698 If 32-bit MMIO register operations are not supported, then ASSERT().
700 @param Address The MMIO register to read.
702 @return The value read.
712 // Make sure Address is aligned on a 32-bit boundary.
714 ASSERT ((Address
& 3) == 0);
715 return (UINT32
)MmioReadWorker (Address
, SMM_IO_UINT32
);
719 Writes a 32-bit MMIO register.
721 Writes the 32-bit MMIO register specified by Address with the value specified
722 by Value and returns Value. This function must guarantee that all MMIO read
723 and write operations are serialized.
725 If Address is not aligned on a 32-bit boundary, then ASSERT().
727 If 32-bit MMIO register operations are not supported, then ASSERT().
729 @param Address The MMIO register to write.
730 @param Value The value to write to the MMIO register.
741 // Make sure Address is aligned on a 32-bit boundary.
743 ASSERT ((Address
& 3) == 0);
744 return (UINT32
)MmioWriteWorker (Address
, SMM_IO_UINT32
, Value
);
748 Reads a 64-bit MMIO register.
750 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
751 returned. This function must guarantee that all MMIO read and write
752 operations are serialized.
754 If Address is not aligned on a 64-bit boundary, then ASSERT().
756 If 64-bit MMIO register operations are not supported, then ASSERT().
758 @param Address The MMIO register to read.
760 @return The value read.
770 // Make sure Address is aligned on a 64-bit boundary.
772 ASSERT ((Address
& 7) == 0);
773 return (UINT64
)MmioReadWorker (Address
, SMM_IO_UINT64
);
777 Writes a 64-bit MMIO register.
779 Writes the 64-bit MMIO register specified by Address with the value specified
780 by Value and returns Value. This function must guarantee that all MMIO read
781 and write operations are serialized.
783 If Address is not aligned on a 64-bit boundary, then ASSERT().
785 If 64-bit MMIO register operations are not supported, then ASSERT().
787 @param Address The MMIO register to write.
788 @param Value The value to write to the MMIO register.
799 // Make sure Address is aligned on a 64-bit boundary.
801 ASSERT ((Address
& 7) == 0);
802 return (UINT64
)MmioWriteWorker (Address
, SMM_IO_UINT64
, Value
);