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 // Globle varible to cache pointer to CpuIo protocol.
20 STATIC EFI_CPU_IO_PROTOCOL
*mCpuIo
= NULL
;
23 The constructor function caches the pointer to CpuIo protocol.
25 The constructor function locates CpuIo 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.
36 IN EFI_HANDLE ImageHandle
,
37 IN EFI_SYSTEM_TABLE
*SystemTable
42 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, NULL
, (VOID
**) &mCpuIo
);
43 ASSERT_EFI_ERROR (Status
);
49 Reads registers in the EFI CPU I/O space.
51 Reads the I/O port specified by Port with registers width specified by Width.
52 The read value is returned. If such operations are not supported, then ASSERT().
53 This function must guarantee that all I/O read and write operations are serialized.
55 @param Port The base address of the I/O operation.
56 The caller is responsible for aligning the Address if required.
57 @param Width The width of the I/O operation.
59 @return Data read from registers in the EFI CPU I/O space.
66 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
72 Status
= mCpuIo
->Io
.Read (mCpuIo
, Width
, Port
, 1, &Data
);
73 ASSERT_EFI_ERROR (Status
);
79 Writes registers in the EFI CPU I/O space.
81 Writes the I/O port specified by Port with registers width and value specified by Width
82 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
83 This function must guarantee that all I/O read and write operations are serialized.
85 @param Port The base address of the I/O operation.
86 The caller is responsible for aligning the Address if required.
87 @param Width The width of the I/O operation.
88 @param Data The value to write to the I/O port.
90 @return The paramter of Data.
97 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
103 Status
= mCpuIo
->Io
.Write (mCpuIo
, Width
, Port
, 1, &Data
);
104 ASSERT_EFI_ERROR (Status
);
110 Reads memory-mapped registers in the EFI system memory space.
112 Reads the MMIO registers specified by Address with registers width specified by Width.
113 The read value is returned. If such operations are not supported, then ASSERT().
114 This function must guarantee that all MMIO read and write operations are serialized.
116 @param Address The MMIO register to read.
117 The caller is responsible for aligning the Address if required.
118 @param Width The width of the I/O operation.
120 @return Data read from registers in the EFI system memory space.
127 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
133 Status
= mCpuIo
->Mem
.Read (mCpuIo
, Width
, Address
, 1, &Data
);
134 ASSERT_EFI_ERROR (Status
);
140 Writes memory-mapped registers in the EFI system memory space.
142 Writes the MMIO registers specified by Address with registers width and value specified by Width
143 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
144 This function must guarantee that all MMIO read and write operations are serialized.
146 @param Address The MMIO register to read.
147 The caller is responsible for aligning the Address if required.
148 @param Width The width of the I/O operation.
150 @return Data read from registers in the EFI system memory space.
157 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
163 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
164 ASSERT_EFI_ERROR (Status
);
170 Reads an 8-bit I/O port.
172 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
173 This function must guarantee that all I/O read and write operations are
176 If 8-bit I/O port operations are not supported, then ASSERT().
178 @param Port The I/O port to read.
180 @return The value read.
189 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
193 Writes an 8-bit I/O port.
195 Writes the 8-bit I/O port specified by Port with the value specified by Value
196 and returns Value. This function must guarantee that all I/O read and write
197 operations are serialized.
199 If 8-bit I/O port operations are not supported, then ASSERT().
201 @param Port The I/O port to write.
202 @param Value The value to write to the I/O port.
204 @return The value written the I/O port.
214 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
218 Reads a 16-bit I/O port.
220 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
221 This function must guarantee that all I/O read and write operations are
224 If 16-bit I/O port operations are not supported, then ASSERT().
226 @param Port The I/O port to read.
228 @return The value read.
238 // Make sure Port is aligned on a 16-bit boundary.
240 ASSERT ((Port
& 1) == 0);
241 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
245 Writes a 16-bit I/O port.
247 Writes the 16-bit I/O port specified by Port with the value specified by Value
248 and returns Value. This function must guarantee that all I/O read and write
249 operations are serialized.
251 If 16-bit I/O port operations are not supported, then ASSERT().
253 @param Port The I/O port to write.
254 @param Value The value to write to the I/O port.
256 @return The value written the I/O port.
267 // Make sure Port is aligned on a 16-bit boundary.
269 ASSERT ((Port
& 1) == 0);
270 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
274 Reads a 32-bit I/O port.
276 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
277 This function must guarantee that all I/O read and write operations are
280 If 32-bit I/O port operations are not supported, then ASSERT().
282 @param Port The I/O port to read.
284 @return The value read.
294 // Make sure Port is aligned on a 32-bit boundary.
296 ASSERT ((Port
& 3) == 0);
297 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
301 Writes a 32-bit I/O port.
303 Writes the 32-bit I/O port specified by Port with the value specified by Value
304 and returns Value. This function must guarantee that all I/O read and write
305 operations are serialized.
307 If 32-bit I/O port operations are not supported, then ASSERT().
309 @param Port The I/O port to write.
310 @param Value The value to write to the I/O port.
312 @return The value written the I/O port.
323 // Make sure Port is aligned on a 32-bit boundary.
325 ASSERT ((Port
& 3) == 0);
326 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
330 Reads a 64-bit I/O port.
332 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
333 This function must guarantee that all I/O read and write operations are
336 If 64-bit I/O port operations are not supported, then ASSERT().
338 @param Port The I/O port to read.
340 @return The value read.
350 // Make sure Port is aligned on a 64-bit boundary.
352 ASSERT ((Port
& 7) == 0);
353 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
357 Writes a 64-bit I/O port.
359 Writes the 64-bit I/O port specified by Port with the value specified by Value
360 and returns Value. This function must guarantee that all I/O read and write
361 operations are serialized.
363 If 64-bit I/O port operations are not supported, then ASSERT().
365 @param Port The I/O port to write.
366 @param Value The value to write to the I/O port.
368 @return The value written the I/O port.
379 // Make sure Port is aligned on a 64-bit boundary.
381 ASSERT ((Port
& 7) == 0);
382 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
386 Reads an 8-bit MMIO register.
388 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
389 returned. This function must guarantee that all MMIO read and write
390 operations are serialized.
392 If 8-bit MMIO register operations are not supported, then ASSERT().
394 @param Address The MMIO register to read.
396 @return The value read.
405 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
409 Writes an 8-bit MMIO register.
411 Writes the 8-bit MMIO register specified by Address with the value specified
412 by Value and returns Value. This function must guarantee that all MMIO read
413 and write operations are serialized.
415 If 8-bit MMIO register operations are not supported, then ASSERT().
417 @param Address The MMIO register to write.
418 @param Value The value to write to the MMIO register.
428 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
432 Reads a 16-bit MMIO register.
434 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
435 returned. This function must guarantee that all MMIO read and write
436 operations are serialized.
438 If 16-bit MMIO register operations are not supported, then ASSERT().
440 @param Address The MMIO register to read.
442 @return The value read.
452 // Make sure Address is aligned on a 16-bit boundary.
454 ASSERT ((Address
& 1) == 0);
455 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
459 Writes a 16-bit MMIO register.
461 Writes the 16-bit MMIO register specified by Address with the value specified
462 by Value and returns Value. This function must guarantee that all MMIO read
463 and write operations are serialized.
465 If 16-bit MMIO register operations are not supported, then ASSERT().
467 @param Address The MMIO register to write.
468 @param Value The value to write to the MMIO register.
479 // Make sure Address is aligned on a 16-bit boundary.
481 ASSERT ((Address
& 1) == 0);
482 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
486 Reads a 32-bit MMIO register.
488 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
489 returned. This function must guarantee that all MMIO read and write
490 operations are serialized.
492 If 32-bit MMIO register operations are not supported, then ASSERT().
494 @param Address The MMIO register to read.
496 @return The value read.
506 // Make sure Address is aligned on a 32-bit boundary.
508 ASSERT ((Address
& 3) == 0);
509 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
513 Writes a 32-bit MMIO register.
515 Writes the 32-bit MMIO register specified by Address with the value specified
516 by Value and returns Value. This function must guarantee that all MMIO read
517 and write operations are serialized.
519 If 32-bit MMIO register operations are not supported, then ASSERT().
521 @param Address The MMIO register to write.
522 @param Value The value to write to the MMIO register.
533 // Make sure Address is aligned on a 32-bit boundary.
535 ASSERT ((Address
& 3) == 0);
536 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
540 Reads a 64-bit MMIO register.
542 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
543 returned. This function must guarantee that all MMIO read and write
544 operations are serialized.
546 If 64-bit MMIO register operations are not supported, then ASSERT().
548 @param Address The MMIO register to read.
550 @return The value read.
560 // Make sure Address is aligned on a 64-bit boundary.
562 ASSERT ((Address
& 7) == 0);
563 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
567 Writes a 64-bit MMIO register.
569 Writes the 64-bit MMIO register specified by Address with the value specified
570 by Value and returns Value. This function must guarantee that all MMIO read
571 and write operations are serialized.
573 If 64-bit MMIO register operations are not supported, then ASSERT().
575 @param Address The MMIO register to write.
576 @param Value The value to write to the MMIO register.
587 // Make sure Address is aligned on a 64-bit boundary.
589 ASSERT ((Address
& 7) == 0);
590 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);