2 I/O Library instance based on EFI_CPU_IO2_PROTOCOL.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 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.
15 #include "DxeCpuIo2LibInternal.h"
18 // Globle varible to cache pointer to CpuIo2 protocol.
20 EFI_CPU_IO2_PROTOCOL
*mCpuIo
= NULL
;
23 The constructor function caches the pointer to CpuIo2 protocol.
25 The constructor function locates CpuIo2 protocol from protocol database.
26 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
28 @param ImageHandle The firmware allocated handle for the EFI image.
29 @param SystemTable A pointer to the EFI System Table.
31 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
37 IN EFI_HANDLE ImageHandle
,
38 IN EFI_SYSTEM_TABLE
*SystemTable
43 Status
= gBS
->LocateProtocol (&gEfiCpuIo2ProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
44 ASSERT_EFI_ERROR (Status
);
50 Reads registers in the EFI CPU I/O space.
52 Reads the I/O port specified by Port with registers width specified by Width.
53 The read value is returned. If such operations are not supported, then ASSERT().
54 This function must guarantee that all I/O read and write operations are serialized.
56 @param Port The base address of the I/O operation.
57 The caller is responsible for aligning the Address if required.
58 @param Width The width of the I/O operation.
60 @return Data read from registers in the EFI CPU I/O space.
67 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
73 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
74 ASSERT_EFI_ERROR (Status
);
80 Writes registers in the EFI CPU I/O space.
82 Writes the I/O port specified by Port with registers width and value specified by Width
83 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
84 This function must guarantee that all I/O read and write operations are serialized.
86 @param Port The base address of the I/O operation.
87 The caller is responsible for aligning the Address if required.
88 @param Width The width of the I/O operation.
89 @param Data The value to write to the I/O port.
91 @return The paramter of Data.
98 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
104 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
105 ASSERT_EFI_ERROR (Status
);
111 Reads memory-mapped registers in the EFI system memory space.
113 Reads the MMIO registers specified by Address with registers width specified by Width.
114 The read value is returned. If such operations are not supported, then ASSERT().
115 This function must guarantee that all MMIO read and write operations are serialized.
117 @param Address The MMIO register to read.
118 The caller is responsible for aligning the Address if required.
119 @param Width The width of the I/O operation.
121 @return Data read from registers in the EFI system memory space.
128 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
134 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
135 ASSERT_EFI_ERROR (Status
);
141 Writes memory-mapped registers in the EFI system memory space.
143 Writes the MMIO registers specified by Address with registers width and value specified by Width
144 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
145 This function must guarantee that all MMIO read and write operations are serialized.
147 @param Address The MMIO register to read.
148 The caller is responsible for aligning the Address if required.
149 @param Width The width of the I/O operation.
150 @param Data The value to write to the I/O port.
152 @return Data read from registers in the EFI system memory space.
159 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
165 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
166 ASSERT_EFI_ERROR (Status
);
172 Reads an 8-bit I/O port.
174 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
175 This function must guarantee that all I/O read and write operations are
178 If 8-bit I/O port operations are not supported, then ASSERT().
180 @param Port The I/O port to read.
182 @return The value read.
191 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
195 Writes an 8-bit I/O port.
197 Writes the 8-bit I/O port specified by Port with the value specified by Value
198 and returns Value. This function must guarantee that all I/O read and write
199 operations are serialized.
201 If 8-bit I/O port operations are not supported, then ASSERT().
203 @param Port The I/O port to write.
204 @param Value The value to write to the I/O port.
206 @return The value written the I/O port.
216 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
220 Reads a 16-bit I/O port.
222 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
223 This function must guarantee that all I/O read and write operations are
226 If Port is not aligned on a 16-bit boundary, then ASSERT().
228 If 16-bit I/O port operations are not supported, then ASSERT().
230 @param Port The I/O port to read.
232 @return The value read.
242 // Make sure Port is aligned on a 16-bit boundary.
244 ASSERT ((Port
& 1) == 0);
245 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
249 Writes a 16-bit I/O port.
251 Writes the 16-bit I/O port specified by Port with the value specified by Value
252 and returns Value. This function must guarantee that all I/O read and write
253 operations are serialized.
255 If Port is not aligned on a 16-bit boundary, then ASSERT().
257 If 16-bit I/O port operations are not supported, then ASSERT().
259 @param Port The I/O port to write.
260 @param Value The value to write to the I/O port.
262 @return The value written the I/O port.
273 // Make sure Port is aligned on a 16-bit boundary.
275 ASSERT ((Port
& 1) == 0);
276 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
280 Reads a 32-bit I/O port.
282 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
283 This function must guarantee that all I/O read and write operations are
286 If Port is not aligned on a 32-bit boundary, then ASSERT().
288 If 32-bit I/O port operations are not supported, then ASSERT().
290 @param Port The I/O port to read.
292 @return The value read.
302 // Make sure Port is aligned on a 32-bit boundary.
304 ASSERT ((Port
& 3) == 0);
305 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
309 Writes a 32-bit I/O port.
311 Writes the 32-bit I/O port specified by Port with the value specified by Value
312 and returns Value. This function must guarantee that all I/O read and write
313 operations are serialized.
315 If Port is not aligned on a 32-bit boundary, then ASSERT().
317 If 32-bit I/O port operations are not supported, then ASSERT().
319 @param Port The I/O port to write.
320 @param Value The value to write to the I/O port.
322 @return The value written the I/O port.
333 // Make sure Port is aligned on a 32-bit boundary.
335 ASSERT ((Port
& 3) == 0);
336 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
340 Reads a 64-bit I/O port.
342 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
343 This function must guarantee that all I/O read and write operations are
346 If Port is not aligned on a 64-bit boundary, then ASSERT().
348 If 64-bit I/O port operations are not supported, then ASSERT().
350 @param Port The I/O port to read.
352 @return The value read.
362 // Make sure Port is aligned on a 64-bit boundary.
364 ASSERT ((Port
& 7) == 0);
365 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
369 Writes a 64-bit I/O port.
371 Writes the 64-bit I/O port specified by Port with the value specified by Value
372 and returns Value. This function must guarantee that all I/O read and write
373 operations are serialized.
375 If Port is not aligned on a 64-bit boundary, then ASSERT().
377 If 64-bit I/O port operations are not supported, then ASSERT().
379 @param Port The I/O port to write.
380 @param Value The value to write to the I/O port.
382 @return The value written the I/O port.
393 // Make sure Port is aligned on a 64-bit boundary.
395 ASSERT ((Port
& 7) == 0);
396 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
400 Reads an 8-bit MMIO register.
402 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
403 returned. This function must guarantee that all MMIO read and write
404 operations are serialized.
406 If 8-bit MMIO register operations are not supported, then ASSERT().
408 @param Address The MMIO register to read.
410 @return The value read.
419 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
423 Writes an 8-bit MMIO register.
425 Writes the 8-bit MMIO register specified by Address with the value specified
426 by Value and returns Value. This function must guarantee that all MMIO read
427 and write operations are serialized.
429 If 8-bit MMIO register operations are not supported, then ASSERT().
431 @param Address The MMIO register to write.
432 @param Value The value to write to the MMIO register.
442 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
446 Reads a 16-bit MMIO register.
448 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
449 returned. This function must guarantee that all MMIO read and write
450 operations are serialized.
452 If Address is not aligned on a 16-bit boundary, then ASSERT().
454 If 16-bit MMIO register operations are not supported, then ASSERT().
456 @param Address The MMIO register to read.
458 @return The value read.
468 // Make sure Address is aligned on a 16-bit boundary.
470 ASSERT ((Address
& 1) == 0);
471 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
475 Writes a 16-bit MMIO register.
477 Writes the 16-bit MMIO register specified by Address with the value specified
478 by Value and returns Value. This function must guarantee that all MMIO read
479 and write operations are serialized.
481 If Address is not aligned on a 16-bit boundary, then ASSERT().
483 If 16-bit MMIO register operations are not supported, then ASSERT().
485 @param Address The MMIO register to write.
486 @param Value The value to write to the MMIO register.
497 // Make sure Address is aligned on a 16-bit boundary.
499 ASSERT ((Address
& 1) == 0);
500 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
504 Reads a 32-bit MMIO register.
506 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
507 returned. This function must guarantee that all MMIO read and write
508 operations are serialized.
510 If Address is not aligned on a 32-bit boundary, then ASSERT().
512 If 32-bit MMIO register operations are not supported, then ASSERT().
514 @param Address The MMIO register to read.
516 @return The value read.
526 // Make sure Address is aligned on a 32-bit boundary.
528 ASSERT ((Address
& 3) == 0);
529 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
533 Writes a 32-bit MMIO register.
535 Writes the 32-bit MMIO register specified by Address with the value specified
536 by Value and returns Value. This function must guarantee that all MMIO read
537 and write operations are serialized.
539 If Address is not aligned on a 32-bit boundary, then ASSERT().
541 If 32-bit MMIO register operations are not supported, then ASSERT().
543 @param Address The MMIO register to write.
544 @param Value The value to write to the MMIO register.
555 // Make sure Address is aligned on a 32-bit boundary.
557 ASSERT ((Address
& 3) == 0);
558 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
562 Reads a 64-bit MMIO register.
564 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
565 returned. This function must guarantee that all MMIO read and write
566 operations are serialized.
568 If Address is not aligned on a 64-bit boundary, then ASSERT().
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 Address is not aligned on a 64-bit boundary, then ASSERT().
599 If 64-bit MMIO register operations are not supported, then ASSERT().
601 @param Address The MMIO register to write.
602 @param Value The value to write to the MMIO register.
613 // Make sure Address is aligned on a 64-bit boundary.
615 ASSERT ((Address
& 7) == 0);
616 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);