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.
17 #include "DxeCpuIoLibInternal.h"
20 // Globle varible to cache pointer to CpuIo protocol.
22 STATIC EFI_CPU_IO_PROTOCOL
*mCpuIo
= NULL
;
25 The constructor function caches the pointer to CpuIo protocol.
27 The constructor function locates CpuIo protocol from protocol database.
28 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
30 @param ImageHandle The firmware allocated handle for the EFI image.
31 @param SystemTable A pointer to the EFI System Table.
33 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
39 IN EFI_HANDLE ImageHandle
,
40 IN EFI_SYSTEM_TABLE
*SystemTable
45 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
46 ASSERT_EFI_ERROR (Status
);
52 Reads registers in the EFI CPU I/O space.
54 Reads the I/O port specified by Port with registers width specified by Width.
55 The read value 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.
62 @return Data read from registers in the EFI CPU I/O space.
69 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
75 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
76 ASSERT_EFI_ERROR (Status
);
82 Writes registers in the EFI CPU I/O space.
84 Writes the I/O port specified by Port with registers width and value specified by Width
85 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
86 This function must guarantee that all I/O read and write operations are serialized.
88 @param Port The base address of the I/O operation.
89 The caller is responsible for aligning the Address if required.
90 @param Width The width of the I/O operation.
91 @param Data The value to write to the I/O port.
93 @return The paramter of Data.
100 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
106 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
107 ASSERT_EFI_ERROR (Status
);
113 Reads memory-mapped registers in the EFI system memory space.
115 Reads the MMIO registers specified by Address with registers width specified by Width.
116 The read value 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.
123 @return Data read from registers in the EFI system memory space.
130 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
136 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
137 ASSERT_EFI_ERROR (Status
);
143 Writes memory-mapped registers in the EFI system memory space.
145 Writes the MMIO registers specified by Address with registers width and value specified by Width
146 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
147 This function must guarantee that all MMIO read and write operations are serialized.
149 @param Address The MMIO register to read.
150 The caller is responsible for aligning the Address if required.
151 @param Width The width of the I/O operation.
153 @return Data read from registers in the EFI system memory space.
160 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
166 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
167 ASSERT_EFI_ERROR (Status
);
173 Reads an 8-bit I/O port.
175 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
176 This function must guarantee that all I/O read and write operations are
179 If 8-bit I/O port operations are not supported, then ASSERT().
181 @param Port The I/O port to read.
183 @return The value read.
192 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
196 Writes an 8-bit I/O port.
198 Writes the 8-bit I/O port specified by Port with the value specified by Value
199 and returns Value. This function must guarantee that all I/O read and write
200 operations are serialized.
202 If 8-bit I/O port operations are not supported, then ASSERT().
204 @param Port The I/O port to write.
205 @param Value The value to write to the I/O port.
207 @return The value written the I/O port.
217 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
221 Reads a 16-bit I/O port.
223 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
224 This function must guarantee that all I/O read and write operations are
227 If 16-bit I/O port operations are not supported, then ASSERT().
229 @param Port The I/O port to read.
231 @return The value read.
241 // Make sure Port is aligned on a 16-bit boundary.
243 ASSERT ((Port
& 1) == 0);
244 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
248 Writes a 16-bit I/O port.
250 Writes the 16-bit I/O port specified by Port with the value specified by Value
251 and returns Value. This function must guarantee that all I/O read and write
252 operations are serialized.
254 If 16-bit I/O port operations are not supported, then ASSERT().
256 @param Port The I/O port to write.
257 @param Value The value to write to the I/O port.
259 @return The value written the I/O port.
270 // Make sure Port is aligned on a 16-bit boundary.
272 ASSERT ((Port
& 1) == 0);
273 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
277 Reads a 32-bit I/O port.
279 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
280 This function must guarantee that all I/O read and write operations are
283 If 32-bit I/O port operations are not supported, then ASSERT().
285 @param Port The I/O port to read.
287 @return The value read.
297 // Make sure Port is aligned on a 32-bit boundary.
299 ASSERT ((Port
& 3) == 0);
300 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
304 Writes a 32-bit I/O port.
306 Writes the 32-bit I/O port specified by Port with the value specified by Value
307 and returns Value. This function must guarantee that all I/O read and write
308 operations are serialized.
310 If 32-bit I/O port operations are not supported, then ASSERT().
312 @param Port The I/O port to write.
313 @param Value The value to write to the I/O port.
315 @return The value written the I/O port.
326 // Make sure Port is aligned on a 32-bit boundary.
328 ASSERT ((Port
& 3) == 0);
329 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
333 Reads a 64-bit I/O port.
335 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
336 This function must guarantee that all I/O read and write operations are
339 If 64-bit I/O port operations are not supported, then ASSERT().
341 @param Port The I/O port to read.
343 @return The value read.
353 // Make sure Port is aligned on a 64-bit boundary.
355 ASSERT ((Port
& 7) == 0);
356 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
360 Writes a 64-bit I/O port.
362 Writes the 64-bit I/O port specified by Port with the value specified by Value
363 and returns Value. This function must guarantee that all I/O read and write
364 operations are serialized.
366 If 64-bit I/O port operations are not supported, then ASSERT().
368 @param Port The I/O port to write.
369 @param Value The value to write to the I/O port.
371 @return The value written the I/O port.
382 // Make sure Port is aligned on a 64-bit boundary.
384 ASSERT ((Port
& 7) == 0);
385 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
389 Reads an 8-bit MMIO register.
391 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
392 returned. This function must guarantee that all MMIO read and write
393 operations are serialized.
395 If 8-bit MMIO register operations are not supported, then ASSERT().
397 @param Address The MMIO register to read.
399 @return The value read.
408 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
412 Writes an 8-bit MMIO register.
414 Writes the 8-bit MMIO register specified by Address with the value specified
415 by Value and returns Value. This function must guarantee that all MMIO read
416 and write operations are serialized.
418 If 8-bit MMIO register operations are not supported, then ASSERT().
420 @param Address The MMIO register to write.
421 @param Value The value to write to the MMIO register.
431 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
435 Reads a 16-bit MMIO register.
437 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
438 returned. This function must guarantee that all MMIO read and write
439 operations are serialized.
441 If 16-bit MMIO register operations are not supported, then ASSERT().
443 @param Address The MMIO register to read.
445 @return The value read.
455 // Make sure Address is aligned on a 16-bit boundary.
457 ASSERT ((Address
& 1) == 0);
458 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
462 Writes a 16-bit MMIO register.
464 Writes the 16-bit MMIO register specified by Address with the value specified
465 by Value and returns Value. This function must guarantee that all MMIO read
466 and write operations are serialized.
468 If 16-bit MMIO register operations are not supported, then ASSERT().
470 @param Address The MMIO register to write.
471 @param Value The value to write to the MMIO register.
482 // Make sure Address is aligned on a 16-bit boundary.
484 ASSERT ((Address
& 1) == 0);
485 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
489 Reads a 32-bit MMIO register.
491 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
492 returned. This function must guarantee that all MMIO read and write
493 operations are serialized.
495 If 32-bit MMIO register operations are not supported, then ASSERT().
497 @param Address The MMIO register to read.
499 @return The value read.
509 // Make sure Address is aligned on a 32-bit boundary.
511 ASSERT ((Address
& 3) == 0);
512 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
516 Writes a 32-bit MMIO register.
518 Writes the 32-bit MMIO register specified by Address with the value specified
519 by Value and returns Value. This function must guarantee that all MMIO read
520 and write operations are serialized.
522 If 32-bit MMIO register operations are not supported, then ASSERT().
524 @param Address The MMIO register to write.
525 @param Value The value to write to the MMIO register.
536 // Make sure Address is aligned on a 32-bit boundary.
538 ASSERT ((Address
& 3) == 0);
539 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
543 Reads a 64-bit MMIO register.
545 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
546 returned. This function must guarantee that all MMIO read and write
547 operations are serialized.
549 If 64-bit MMIO register operations are not supported, then ASSERT().
551 @param Address The MMIO register to read.
553 @return The value read.
563 // Make sure Address is aligned on a 64-bit boundary.
565 ASSERT ((Address
& 7) == 0);
566 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
570 Writes a 64-bit MMIO register.
572 Writes the 64-bit MMIO register specified by Address with the value specified
573 by Value and returns Value. This function must guarantee that all MMIO read
574 and write operations are serialized.
576 If 64-bit MMIO register operations are not supported, then ASSERT().
578 @param Address The MMIO register to write.
579 @param Value The value to write to the MMIO register.
590 // Make sure Address is aligned on a 64-bit boundary.
592 ASSERT ((Address
& 7) == 0);
593 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);