3 The implementation of I/O operation for this library instance
4 are based on EFI_CPU_IO_PROTOCOL.
6 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "DxeCpuIoLibInternal.h"
23 // Globle varible to cache pointer to CpuIo protocol.
25 EFI_CPU_IO_PROTOCOL
*mCpuIo
= NULL
;
28 The constructor function caches the pointer to CpuIo protocol.
30 The constructor function locates CpuIo protocol from protocol database.
31 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
33 @param ImageHandle The firmware allocated handle for the EFI image.
34 @param SystemTable A pointer to the EFI System Table.
36 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
48 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
49 ASSERT_EFI_ERROR (Status
);
55 Reads registers in the EFI CPU I/O space.
57 Reads the I/O port specified by Port with registers width specified by Width.
58 The read value is returned. If such operations are not supported, then ASSERT().
59 This function must guarantee that all I/O read and write operations are serialized.
61 @param Port The base address of the I/O operation.
62 The caller is responsible for aligning the Address if required.
63 @param Width The width of the I/O operation.
65 @return Data read from registers in the EFI CPU I/O space.
72 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
78 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
79 ASSERT_EFI_ERROR (Status
);
85 Writes registers in the EFI CPU I/O space.
87 Writes the I/O port specified by Port with registers width and value specified by Width
88 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
89 This function must guarantee that all I/O read and write operations are serialized.
91 @param Port The base address of the I/O operation.
92 The caller is responsible for aligning the Address if required.
93 @param Width The width of the I/O operation.
94 @param Data The value to write to the I/O port.
96 @return The parameter of Data.
103 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
109 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
110 ASSERT_EFI_ERROR (Status
);
116 Reads memory-mapped registers in the EFI system memory space.
118 Reads the MMIO registers specified by Address with registers width specified by Width.
119 The read value is returned. If such operations are not supported, then ASSERT().
120 This function must guarantee that all MMIO read and write operations are serialized.
122 @param Address The MMIO register to read.
123 The caller is responsible for aligning the Address if required.
124 @param Width The width of the I/O operation.
126 @return Data read from registers in the EFI system memory space.
133 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
139 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
140 ASSERT_EFI_ERROR (Status
);
146 Writes memory-mapped registers in the EFI system memory space.
148 Writes the MMIO registers specified by Address with registers width and value specified by Width
149 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
150 This function must guarantee that all MMIO read and write operations are serialized.
152 @param Address The MMIO register to read.
153 The caller is responsible for aligning the Address if required.
154 @param Width The width of the I/O operation.
155 @param Data The value to write to the I/O port.
157 @return Data read from registers in the EFI system memory space.
164 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
170 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
171 ASSERT_EFI_ERROR (Status
);
177 Reads an 8-bit I/O port.
179 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
180 This function must guarantee that all I/O read and write operations are
183 If 8-bit I/O port operations are not supported, then ASSERT().
185 @param Port The I/O port to read.
187 @return The value read.
196 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
200 Writes an 8-bit I/O port.
202 Writes the 8-bit I/O port specified by Port with the value specified by Value
203 and returns Value. This function must guarantee that all I/O read and write
204 operations are serialized.
206 If 8-bit I/O port operations are not supported, then ASSERT().
208 @param Port The I/O port to write.
209 @param Value The value to write to the I/O port.
211 @return The value written the I/O port.
221 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
225 Reads a 16-bit I/O port.
227 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
228 This function must guarantee that all I/O read and write operations are
231 If Port is not aligned on a 16-bit boundary, then ASSERT().
233 If 16-bit I/O port operations are not supported, then ASSERT().
235 @param Port The I/O port to read.
237 @return The value read.
247 // Make sure Port is aligned on a 16-bit boundary.
249 ASSERT ((Port
& 1) == 0);
250 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
254 Writes a 16-bit I/O port.
256 Writes the 16-bit I/O port specified by Port with the value specified by Value
257 and returns Value. This function must guarantee that all I/O read and write
258 operations are serialized.
260 If Port is not aligned on a 16-bit boundary, then ASSERT().
262 If 16-bit I/O port operations are not supported, then ASSERT().
264 @param Port The I/O port to write.
265 @param Value The value to write to the I/O port.
267 @return The value written the I/O port.
278 // Make sure Port is aligned on a 16-bit boundary.
280 ASSERT ((Port
& 1) == 0);
281 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
285 Reads a 32-bit I/O port.
287 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
288 This function must guarantee that all I/O read and write operations are
291 If Port is not aligned on a 32-bit boundary, then ASSERT().
293 If 32-bit I/O port operations are not supported, then ASSERT().
295 @param Port The I/O port to read.
297 @return The value read.
307 // Make sure Port is aligned on a 32-bit boundary.
309 ASSERT ((Port
& 3) == 0);
310 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
314 Writes a 32-bit I/O port.
316 Writes the 32-bit I/O port specified by Port with the value specified by Value
317 and returns Value. This function must guarantee that all I/O read and write
318 operations are serialized.
320 If Port is not aligned on a 32-bit boundary, then ASSERT().
322 If 32-bit I/O port operations are not supported, then ASSERT().
324 @param Port The I/O port to write.
325 @param Value The value to write to the I/O port.
327 @return The value written the I/O port.
338 // Make sure Port is aligned on a 32-bit boundary.
340 ASSERT ((Port
& 3) == 0);
341 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
345 Reads a 64-bit I/O port.
347 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
348 This function must guarantee that all I/O read and write operations are
351 If Port is not aligned on a 64-bit boundary, then ASSERT().
353 If 64-bit I/O port operations are not supported, then ASSERT().
355 @param Port The I/O port to read.
357 @return The value read.
367 // Make sure Port is aligned on a 64-bit boundary.
369 ASSERT ((Port
& 7) == 0);
370 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
374 Writes a 64-bit I/O port.
376 Writes the 64-bit I/O port specified by Port with the value specified by Value
377 and returns Value. This function must guarantee that all I/O read and write
378 operations are serialized.
380 If Port is not aligned on a 64-bit boundary, then ASSERT().
382 If 64-bit I/O port operations are not supported, then ASSERT().
384 @param Port The I/O port to write.
385 @param Value The value to write to the I/O port.
387 @return The value written the I/O port.
398 // Make sure Port is aligned on a 64-bit boundary.
400 ASSERT ((Port
& 7) == 0);
401 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
405 Reads an 8-bit MMIO register.
407 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
408 returned. This function must guarantee that all MMIO read and write
409 operations are serialized.
411 If 8-bit MMIO register operations are not supported, then ASSERT().
413 @param Address The MMIO register to read.
415 @return The value read.
424 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
428 Writes an 8-bit MMIO register.
430 Writes the 8-bit MMIO register specified by Address with the value specified
431 by Value and returns Value. This function must guarantee that all MMIO read
432 and write operations are serialized.
434 If 8-bit MMIO register operations are not supported, then ASSERT().
436 @param Address The MMIO register to write.
437 @param Value The value to write to the MMIO register.
447 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
451 Reads a 16-bit MMIO register.
453 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
454 returned. This function must guarantee that all MMIO read and write
455 operations are serialized.
457 If Address is not aligned on a 16-bit boundary, then ASSERT().
459 If 16-bit MMIO register operations are not supported, then ASSERT().
461 @param Address The MMIO register to read.
463 @return The value read.
473 // Make sure Address is aligned on a 16-bit boundary.
475 ASSERT ((Address
& 1) == 0);
476 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
480 Writes a 16-bit MMIO register.
482 Writes the 16-bit MMIO register specified by Address with the value specified
483 by Value and returns Value. This function must guarantee that all MMIO read
484 and write operations are serialized.
486 If Address is not aligned on a 16-bit boundary, then ASSERT().
488 If 16-bit MMIO register operations are not supported, then ASSERT().
490 @param Address The MMIO register to write.
491 @param Value The value to write to the MMIO register.
502 // Make sure Address is aligned on a 16-bit boundary.
504 ASSERT ((Address
& 1) == 0);
505 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
509 Reads a 32-bit MMIO register.
511 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
512 returned. This function must guarantee that all MMIO read and write
513 operations are serialized.
515 If Address is not aligned on a 32-bit boundary, then ASSERT().
517 If 32-bit MMIO register operations are not supported, then ASSERT().
519 @param Address The MMIO register to read.
521 @return The value read.
531 // Make sure Address is aligned on a 32-bit boundary.
533 ASSERT ((Address
& 3) == 0);
534 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
538 Writes a 32-bit MMIO register.
540 Writes the 32-bit MMIO register specified by Address with the value specified
541 by Value and returns Value. This function must guarantee that all MMIO read
542 and write operations are serialized.
544 If Address is not aligned on a 32-bit boundary, then ASSERT().
546 If 32-bit MMIO register operations are not supported, then ASSERT().
548 @param Address The MMIO register to write.
549 @param Value The value to write to the MMIO register.
560 // Make sure Address is aligned on a 32-bit boundary.
562 ASSERT ((Address
& 3) == 0);
563 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
567 Reads a 64-bit MMIO register.
569 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
570 returned. This function must guarantee that all MMIO read and write
571 operations are serialized.
573 If Address is not aligned on a 64-bit boundary, then ASSERT().
575 If 64-bit MMIO register operations are not supported, then ASSERT().
577 @param Address The MMIO register to read.
579 @return The value read.
589 // Make sure Address is aligned on a 64-bit boundary.
591 ASSERT ((Address
& 7) == 0);
592 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
596 Writes a 64-bit MMIO register.
598 Writes the 64-bit MMIO register specified by Address with the value specified
599 by Value and returns Value. This function must guarantee that all MMIO read
600 and write operations are serialized.
602 If Address is not aligned on a 64-bit boundary, then ASSERT().
604 If 64-bit MMIO register operations are not supported, then ASSERT().
606 @param Address The MMIO register to write.
607 @param Value The value to write to the MMIO register.
618 // Make sure Address is aligned on a 64-bit boundary.
620 ASSERT ((Address
& 7) == 0);
621 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);