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
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.
18 #include "DxeCpuIoLibInternal.h"
21 // Globle varible to cache pointer to CpuIo protocol.
23 STATIC EFI_CPU_IO_PROTOCOL
*mCpuIo
= NULL
;
24 STATIC EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL
*mPciRootBridgeIo
= NULL
;
27 The constructor function caches the pointer to CpuIo protocol.
29 The constructor function locates CpuIo protocol from protocol database.
30 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
32 @param ImageHandle The firmware allocated handle for the EFI image.
33 @param SystemTable A pointer to the EFI System Table.
35 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
41 IN EFI_HANDLE ImageHandle
,
42 IN EFI_SYSTEM_TABLE
*SystemTable
47 Status
= gBS
->LocateProtocol (&gEfiPciRootBridgeIoProtocolGuid
, NULL
, &mPciRootBridgeIo
);
48 if (EFI_ERROR (Status
)) {
49 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, &mCpuIo
);
51 ASSERT_EFI_ERROR (Status
);
57 Reads registers in the EFI CPU I/O space.
59 Reads the I/O port specified by Port with registers width specified by Width.
60 The read value is returned. If such operations are not supported, then ASSERT().
61 This function must guarantee that all I/O read and write operations are serialized.
63 @param Port The base address of the I/O operation.
64 The caller is responsible for aligning the Address if required.
65 @param Width The width of the I/O operation.
67 @return Data read from registers in the EFI CPU I/O space.
74 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
80 if (mPciRootBridgeIo
!= NULL
) {
81 Status
= mPciRootBridgeIo
->Io
.Read (mPciRootBridgeIo
, Width
, Port
, 1, &Data
);
83 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
85 ASSERT_EFI_ERROR (Status
);
91 Writes registers in the EFI CPU I/O space.
93 Writes the I/O port specified by Port with registers width and value specified by Width
94 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
95 This function must guarantee that all I/O read and write operations are serialized.
97 @param Port The base address of the I/O operation.
98 The caller is responsible for aligning the Address if required.
99 @param Width The width of the I/O operation.
100 @param Data The value to write to the I/O port.
102 @return The paramter of Data.
109 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
115 if (mPciRootBridgeIo
!= NULL
) {
116 Status
= mPciRootBridgeIo
->Io
.Write (mPciRootBridgeIo
, Width
, Port
, 1, &Data
);
118 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
120 ASSERT_EFI_ERROR (Status
);
126 Reads memory-mapped registers in the EFI system memory space.
128 Reads the MMIO registers specified by Address with registers width specified by Width.
129 The read value is returned. If such operations are not supported, then ASSERT().
130 This function must guarantee that all MMIO read and write operations are serialized.
132 @param Address The MMIO register to read.
133 The caller is responsible for aligning the Address if required.
134 @param Width The width of the I/O operation.
136 @return Data read from registers in the EFI system memory space.
143 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
149 if (mPciRootBridgeIo
!= NULL
) {
150 Status
= mPciRootBridgeIo
->Mem
.Read (mPciRootBridgeIo
, Width
, Address
, 1, &Data
);
152 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
154 ASSERT_EFI_ERROR (Status
);
160 Writes memory-mapped registers in the EFI system memory space.
162 Writes the MMIO registers specified by Address with registers width and value specified by Width
163 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
164 This function must guarantee that all MMIO read and write operations are serialized.
166 @param Address The MMIO register to read.
167 The caller is responsible for aligning the Address if required.
168 @param Width The width of the I/O operation.
170 @return Data read from registers in the EFI system memory space.
177 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
183 if (mPciRootBridgeIo
!= NULL
) {
184 Status
= mPciRootBridgeIo
->Mem
.Write (mPciRootBridgeIo
, Width
, Address
, 1, &Data
);
186 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
188 ASSERT_EFI_ERROR (Status
);
194 Reads an 8-bit I/O port.
196 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
197 This function must guarantee that all I/O read and write operations are
200 If 8-bit I/O port operations are not supported, then ASSERT().
202 @param Port The I/O port to read.
204 @return The value read.
213 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
217 Writes an 8-bit I/O port.
219 Writes the 8-bit I/O port specified by Port with the value specified by Value
220 and returns Value. This function must guarantee that all I/O read and write
221 operations are serialized.
223 If 8-bit I/O port operations are not supported, then ASSERT().
225 @param Port The I/O port to write.
226 @param Value The value to write to the I/O port.
228 @return The value written the I/O port.
238 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
242 Reads a 16-bit I/O port.
244 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
245 This function must guarantee that all I/O read and write operations are
248 If 16-bit I/O port operations are not supported, then ASSERT().
250 @param Port The I/O port to read.
252 @return The value read.
262 // Make sure Port is aligned on a 16-bit boundary.
264 ASSERT ((Port
& 1) == 0);
265 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
269 Writes a 16-bit I/O port.
271 Writes the 16-bit I/O port specified by Port with the value specified by Value
272 and returns Value. This function must guarantee that all I/O read and write
273 operations are serialized.
275 If 16-bit I/O port operations are not supported, then ASSERT().
277 @param Port The I/O port to write.
278 @param Value The value to write to the I/O port.
280 @return The value written the I/O port.
291 // Make sure Port is aligned on a 16-bit boundary.
293 ASSERT ((Port
& 1) == 0);
294 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
298 Reads a 32-bit I/O port.
300 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
301 This function must guarantee that all I/O read and write operations are
304 If 32-bit I/O port operations are not supported, then ASSERT().
306 @param Port The I/O port to read.
308 @return The value read.
318 // Make sure Port is aligned on a 32-bit boundary.
320 ASSERT ((Port
& 3) == 0);
321 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
325 Writes a 32-bit I/O port.
327 Writes the 32-bit I/O port specified by Port with the value specified by Value
328 and returns Value. This function must guarantee that all I/O read and write
329 operations are serialized.
331 If 32-bit I/O port operations are not supported, then ASSERT().
333 @param Port The I/O port to write.
334 @param Value The value to write to the I/O port.
336 @return The value written the I/O port.
347 // Make sure Port is aligned on a 32-bit boundary.
349 ASSERT ((Port
& 3) == 0);
350 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
354 Reads a 64-bit I/O port.
356 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
357 This function must guarantee that all I/O read and write operations are
360 If 64-bit I/O port operations are not supported, then ASSERT().
362 @param Port The I/O port to read.
364 @return The value read.
374 // Make sure Port is aligned on a 64-bit boundary.
376 ASSERT ((Port
& 7) == 0);
377 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
381 Writes a 64-bit I/O port.
383 Writes the 64-bit I/O port specified by Port with the value specified by Value
384 and returns Value. This function must guarantee that all I/O read and write
385 operations are serialized.
387 If 64-bit I/O port operations are not supported, then ASSERT().
389 @param Port The I/O port to write.
390 @param Value The value to write to the I/O port.
392 @return The value written the I/O port.
403 // Make sure Port is aligned on a 64-bit boundary.
405 ASSERT ((Port
& 7) == 0);
406 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
410 Reads an 8-bit MMIO register.
412 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
413 returned. This function must guarantee that all MMIO read and write
414 operations are serialized.
416 If 8-bit MMIO register operations are not supported, then ASSERT().
418 @param Address The MMIO register to read.
420 @return The value read.
429 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
433 Writes an 8-bit MMIO register.
435 Writes the 8-bit MMIO register specified by Address with the value specified
436 by Value and returns Value. This function must guarantee that all MMIO read
437 and write operations are serialized.
439 If 8-bit MMIO register operations are not supported, then ASSERT().
441 @param Address The MMIO register to write.
442 @param Value The value to write to the MMIO register.
452 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
456 Reads a 16-bit MMIO register.
458 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
459 returned. This function must guarantee that all MMIO read and write
460 operations are serialized.
462 If 16-bit MMIO register operations are not supported, then ASSERT().
464 @param Address The MMIO register to read.
466 @return The value read.
476 // Make sure Address is aligned on a 16-bit boundary.
478 ASSERT ((Address
& 1) == 0);
479 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
483 Writes a 16-bit MMIO register.
485 Writes the 16-bit MMIO register specified by Address with the value specified
486 by Value and returns Value. This function must guarantee that all MMIO read
487 and write operations are serialized.
489 If 16-bit MMIO register operations are not supported, then ASSERT().
491 @param Address The MMIO register to write.
492 @param Value The value to write to the MMIO register.
503 // Make sure Address is aligned on a 16-bit boundary.
505 ASSERT ((Address
& 1) == 0);
506 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
510 Reads a 32-bit MMIO register.
512 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
513 returned. This function must guarantee that all MMIO read and write
514 operations are serialized.
516 If 32-bit MMIO register operations are not supported, then ASSERT().
518 @param Address The MMIO register to read.
520 @return The value read.
530 // Make sure Address is aligned on a 32-bit boundary.
532 ASSERT ((Address
& 3) == 0);
533 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
537 Writes a 32-bit MMIO register.
539 Writes the 32-bit MMIO register specified by Address with the value specified
540 by Value and returns Value. This function must guarantee that all MMIO read
541 and write operations are serialized.
543 If 32-bit MMIO register operations are not supported, then ASSERT().
545 @param Address The MMIO register to write.
546 @param Value The value to write to the MMIO register.
557 // Make sure Address is aligned on a 32-bit boundary.
559 ASSERT ((Address
& 3) == 0);
560 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
564 Reads a 64-bit MMIO register.
566 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
567 returned. This function must guarantee that all MMIO read and write
568 operations are serialized.
570 If 64-bit MMIO register operations are not supported, then ASSERT().
572 @param Address The MMIO register to read.
574 @return The value read.
584 // Make sure Address is aligned on a 64-bit boundary.
586 ASSERT ((Address
& 7) == 0);
587 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
591 Writes a 64-bit MMIO register.
593 Writes the 64-bit MMIO register specified by Address with the value specified
594 by Value and returns Value. This function must guarantee that all MMIO read
595 and write operations are serialized.
597 If 64-bit MMIO register operations are not supported, then ASSERT().
599 @param Address The MMIO register to write.
600 @param Value The value to write to the MMIO register.
611 // Make sure Address is aligned on a 64-bit boundary.
613 ASSERT ((Address
& 7) == 0);
614 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);