3 Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 High-level Io/Mmio functions.
23 #include "DxeCpuIoLibInternal.h"
26 // Globle varible to cache pointer to CpuIo protocol.
28 STATIC EFI_CPU_IO_PROTOCOL
*mCpuIo
= NULL
;
31 The constructor function caches the pointer to CpuIo protocol.
33 The constructor function locates CpuIo protocol from protocol database.
34 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
36 @param ImageHandle The firmware allocated handle for the EFI image.
37 @param SystemTable A pointer to the EFI System Table.
39 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
45 IN EFI_HANDLE ImageHandle
,
46 IN EFI_SYSTEM_TABLE
*SystemTable
51 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
52 ASSERT_EFI_ERROR (Status
);
58 Reads registers in the EFI CPU I/O space.
60 Reads the I/O port specified by Port with registers width specified by Width.
61 The read value is returned. If such operations are not supported, then ASSERT().
62 This function must guarantee that all I/O read and write operations are serialized.
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.
68 @return Data read from registers in the EFI CPU I/O space.
75 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
81 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
82 ASSERT_EFI_ERROR (Status
);
88 Writes registers in the EFI CPU I/O space.
90 Writes the I/O port specified by Port with registers width and value specified by Width
91 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
92 This function must guarantee that all I/O read and write operations are serialized.
94 @param Port The base address of the I/O operation.
95 The caller is responsible for aligning the Address if required.
96 @param Width The width of the I/O operation.
97 @param Data The value to write to the I/O port.
99 @return The paramter of Data.
106 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
112 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
113 ASSERT_EFI_ERROR (Status
);
119 Reads memory-mapped registers in the EFI system memory space.
121 Reads the MMIO registers specified by Address with registers width specified by Width.
122 The read value is returned. If such operations are not supported, then ASSERT().
123 This function must guarantee that all MMIO read and write operations are serialized.
125 @param Address The MMIO register to read.
126 The caller is responsible for aligning the Address if required.
127 @param Width The width of the I/O operation.
129 @return Data read from registers in the EFI system memory space.
136 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
142 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
143 ASSERT_EFI_ERROR (Status
);
149 Writes memory-mapped registers in the EFI system memory space.
151 Writes the MMIO registers specified by Address with registers width and value specified by Width
152 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
153 This function must guarantee that all MMIO read and write operations are serialized.
155 @param Address The MMIO register to read.
156 The caller is responsible for aligning the Address if required.
157 @param Width The width of the I/O operation.
159 @return Data read from registers in the EFI system memory space.
166 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
172 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
173 ASSERT_EFI_ERROR (Status
);
179 Reads an 8-bit I/O port.
181 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
182 This function must guarantee that all I/O read and write operations are
185 If 8-bit I/O port operations are not supported, then ASSERT().
187 @param Port The I/O port to read.
189 @return The value read.
198 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
202 Writes an 8-bit I/O port.
204 Writes the 8-bit I/O port specified by Port with the value specified by Value
205 and returns Value. This function must guarantee that all I/O read and write
206 operations are serialized.
208 If 8-bit I/O port operations are not supported, then ASSERT().
210 @param Port The I/O port to write.
211 @param Value The value to write to the I/O port.
213 @return The value written the I/O port.
223 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
227 Reads a 16-bit I/O port.
229 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
230 This function must guarantee that all I/O read and write operations are
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 16-bit I/O port operations are not supported, then ASSERT().
262 @param Port The I/O port to write.
263 @param Value The value to write to the I/O port.
265 @return The value written the I/O port.
276 // Make sure Port is aligned on a 16-bit boundary.
278 ASSERT ((Port
& 1) == 0);
279 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
283 Reads a 32-bit I/O port.
285 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
286 This function must guarantee that all I/O read and write operations are
289 If 32-bit I/O port operations are not supported, then ASSERT().
291 @param Port The I/O port to read.
293 @return The value read.
303 // Make sure Port is aligned on a 32-bit boundary.
305 ASSERT ((Port
& 3) == 0);
306 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
310 Writes a 32-bit I/O port.
312 Writes the 32-bit I/O port specified by Port with the value specified by Value
313 and returns Value. This function must guarantee that all I/O read and write
314 operations are serialized.
316 If 32-bit I/O port operations are not supported, then ASSERT().
318 @param Port The I/O port to write.
319 @param Value The value to write to the I/O port.
321 @return The value written the I/O port.
332 // Make sure Port is aligned on a 32-bit boundary.
334 ASSERT ((Port
& 3) == 0);
335 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
339 Reads a 64-bit I/O port.
341 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
342 This function must guarantee that all I/O read and write operations are
345 If 64-bit I/O port operations are not supported, then ASSERT().
347 @param Port The I/O port to read.
349 @return The value read.
359 // Make sure Port is aligned on a 64-bit boundary.
361 ASSERT ((Port
& 7) == 0);
362 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
366 Writes a 64-bit I/O port.
368 Writes the 64-bit I/O port specified by Port with the value specified by Value
369 and returns Value. This function must guarantee that all I/O read and write
370 operations are serialized.
372 If 64-bit I/O port operations are not supported, then ASSERT().
374 @param Port The I/O port to write.
375 @param Value The value to write to the I/O port.
377 @return The value written the I/O port.
388 // Make sure Port is aligned on a 64-bit boundary.
390 ASSERT ((Port
& 7) == 0);
391 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
395 Reads an 8-bit MMIO register.
397 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
398 returned. This function must guarantee that all MMIO read and write
399 operations are serialized.
401 If 8-bit MMIO register operations are not supported, then ASSERT().
403 @param Address The MMIO register to read.
405 @return The value read.
414 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
418 Writes an 8-bit MMIO register.
420 Writes the 8-bit MMIO register specified by Address with the value specified
421 by Value and returns Value. This function must guarantee that all MMIO read
422 and write operations are serialized.
424 If 8-bit MMIO register operations are not supported, then ASSERT().
426 @param Address The MMIO register to write.
427 @param Value The value to write to the MMIO register.
437 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
441 Reads a 16-bit MMIO register.
443 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
444 returned. This function must guarantee that all MMIO read and write
445 operations are serialized.
447 If 16-bit MMIO register operations are not supported, then ASSERT().
449 @param Address The MMIO register to read.
451 @return The value read.
461 // Make sure Address is aligned on a 16-bit boundary.
463 ASSERT ((Address
& 1) == 0);
464 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
468 Writes a 16-bit MMIO register.
470 Writes the 16-bit MMIO register specified by Address with the value specified
471 by Value and returns Value. This function must guarantee that all MMIO read
472 and write operations are serialized.
474 If 16-bit MMIO register operations are not supported, then ASSERT().
476 @param Address The MMIO register to write.
477 @param Value The value to write to the MMIO register.
488 // Make sure Address is aligned on a 16-bit boundary.
490 ASSERT ((Address
& 1) == 0);
491 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
495 Reads a 32-bit MMIO register.
497 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
498 returned. This function must guarantee that all MMIO read and write
499 operations are serialized.
501 If 32-bit MMIO register operations are not supported, then ASSERT().
503 @param Address The MMIO register to read.
505 @return The value read.
515 // Make sure Address is aligned on a 32-bit boundary.
517 ASSERT ((Address
& 3) == 0);
518 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
522 Writes a 32-bit MMIO register.
524 Writes the 32-bit MMIO register specified by Address with the value specified
525 by Value and returns Value. This function must guarantee that all MMIO read
526 and write operations are serialized.
528 If 32-bit MMIO register operations are not supported, then ASSERT().
530 @param Address The MMIO register to write.
531 @param Value The value to write to the MMIO register.
542 // Make sure Address is aligned on a 32-bit boundary.
544 ASSERT ((Address
& 3) == 0);
545 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
549 Reads a 64-bit MMIO register.
551 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
552 returned. This function must guarantee that all MMIO read and write
553 operations are serialized.
555 If 64-bit MMIO register operations are not supported, then ASSERT().
557 @param Address The MMIO register to read.
559 @return The value read.
569 // Make sure Address is aligned on a 64-bit boundary.
571 ASSERT ((Address
& 7) == 0);
572 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
576 Writes a 64-bit MMIO register.
578 Writes the 64-bit MMIO register specified by Address with the value specified
579 by Value and returns Value. This function must guarantee that all MMIO read
580 and write operations are serialized.
582 If 64-bit MMIO register operations are not supported, then ASSERT().
584 @param Address The MMIO register to write.
585 @param Value The value to write to the MMIO register.
596 // Make sure Address is aligned on a 64-bit boundary.
598 ASSERT ((Address
& 7) == 0);
599 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);