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.
37 IN EFI_HANDLE ImageHandle
,
38 IN EFI_SYSTEM_TABLE
*SystemTable
43 Status
= gBS
->LocateProtocol (&gEfiCpuIoProtocolGuid
, 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.
151 @return Data read from registers in the EFI system memory space.
158 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
164 Status
= mCpuIo
->Mem
.Write (mCpuIo
, Width
, Address
, 1, &Data
);
165 ASSERT_EFI_ERROR (Status
);
171 Reads an 8-bit I/O port.
173 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
174 This function must guarantee that all I/O read and write operations are
177 If 8-bit I/O port operations are not supported, then ASSERT().
179 @param Port The I/O port to read.
181 @return The value read.
190 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
194 Writes an 8-bit I/O port.
196 Writes the 8-bit I/O port specified by Port with the value specified by Value
197 and returns Value. This function must guarantee that all I/O read and write
198 operations are serialized.
200 If 8-bit I/O port operations are not supported, then ASSERT().
202 @param Port The I/O port to write.
203 @param Value The value to write to the I/O port.
205 @return The value written the I/O port.
215 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
219 Reads a 16-bit I/O port.
221 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
222 This function must guarantee that all I/O read and write operations are
225 If 16-bit I/O port operations are not supported, then ASSERT().
227 @param Port The I/O port to read.
229 @return The value read.
239 // Make sure Port is aligned on a 16-bit boundary.
241 ASSERT ((Port
& 1) == 0);
242 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
246 Writes a 16-bit I/O port.
248 Writes the 16-bit I/O port specified by Port with the value specified by Value
249 and returns Value. This function must guarantee that all I/O read and write
250 operations are serialized.
252 If 16-bit I/O port operations are not supported, then ASSERT().
254 @param Port The I/O port to write.
255 @param Value The value to write to the I/O port.
257 @return The value written the I/O port.
268 // Make sure Port is aligned on a 16-bit boundary.
270 ASSERT ((Port
& 1) == 0);
271 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
275 Reads a 32-bit I/O port.
277 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
278 This function must guarantee that all I/O read and write operations are
281 If 32-bit I/O port operations are not supported, then ASSERT().
283 @param Port The I/O port to read.
285 @return The value read.
295 // Make sure Port is aligned on a 32-bit boundary.
297 ASSERT ((Port
& 3) == 0);
298 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
302 Writes a 32-bit I/O port.
304 Writes the 32-bit I/O port specified by Port with the value specified by Value
305 and returns Value. This function must guarantee that all I/O read and write
306 operations are serialized.
308 If 32-bit I/O port operations are not supported, then ASSERT().
310 @param Port The I/O port to write.
311 @param Value The value to write to the I/O port.
313 @return The value written the I/O port.
324 // Make sure Port is aligned on a 32-bit boundary.
326 ASSERT ((Port
& 3) == 0);
327 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
331 Reads a 64-bit I/O port.
333 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
334 This function must guarantee that all I/O read and write operations are
337 If 64-bit I/O port operations are not supported, then ASSERT().
339 @param Port The I/O port to read.
341 @return The value read.
351 // Make sure Port is aligned on a 64-bit boundary.
353 ASSERT ((Port
& 7) == 0);
354 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
358 Writes a 64-bit I/O port.
360 Writes the 64-bit I/O port specified by Port with the value specified by Value
361 and returns Value. This function must guarantee that all I/O read and write
362 operations are serialized.
364 If 64-bit I/O port operations are not supported, then ASSERT().
366 @param Port The I/O port to write.
367 @param Value The value to write to the I/O port.
369 @return The value written the I/O port.
380 // Make sure Port is aligned on a 64-bit boundary.
382 ASSERT ((Port
& 7) == 0);
383 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
387 Reads an 8-bit MMIO register.
389 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
390 returned. This function must guarantee that all MMIO read and write
391 operations are serialized.
393 If 8-bit MMIO register operations are not supported, then ASSERT().
395 @param Address The MMIO register to read.
397 @return The value read.
406 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
410 Writes an 8-bit MMIO register.
412 Writes the 8-bit MMIO register specified by Address with the value specified
413 by Value and returns Value. This function must guarantee that all MMIO read
414 and write operations are serialized.
416 If 8-bit MMIO register operations are not supported, then ASSERT().
418 @param Address The MMIO register to write.
419 @param Value The value to write to the MMIO register.
429 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
433 Reads a 16-bit MMIO register.
435 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
436 returned. This function must guarantee that all MMIO read and write
437 operations are serialized.
439 If 16-bit MMIO register operations are not supported, then ASSERT().
441 @param Address The MMIO register to read.
443 @return The value read.
453 // Make sure Address is aligned on a 16-bit boundary.
455 ASSERT ((Address
& 1) == 0);
456 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
460 Writes a 16-bit MMIO register.
462 Writes the 16-bit MMIO register specified by Address with the value specified
463 by Value and returns Value. This function must guarantee that all MMIO read
464 and write operations are serialized.
466 If 16-bit MMIO register operations are not supported, then ASSERT().
468 @param Address The MMIO register to write.
469 @param Value The value to write to the MMIO register.
480 // Make sure Address is aligned on a 16-bit boundary.
482 ASSERT ((Address
& 1) == 0);
483 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
487 Reads a 32-bit MMIO register.
489 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
490 returned. This function must guarantee that all MMIO read and write
491 operations are serialized.
493 If 32-bit MMIO register operations are not supported, then ASSERT().
495 @param Address The MMIO register to read.
497 @return The value read.
507 // Make sure Address is aligned on a 32-bit boundary.
509 ASSERT ((Address
& 3) == 0);
510 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
514 Writes a 32-bit MMIO register.
516 Writes the 32-bit MMIO register specified by Address with the value specified
517 by Value and returns Value. This function must guarantee that all MMIO read
518 and write operations are serialized.
520 If 32-bit MMIO register operations are not supported, then ASSERT().
522 @param Address The MMIO register to write.
523 @param Value The value to write to the MMIO register.
534 // Make sure Address is aligned on a 32-bit boundary.
536 ASSERT ((Address
& 3) == 0);
537 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
541 Reads a 64-bit MMIO register.
543 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
544 returned. This function must guarantee that all MMIO read and write
545 operations are serialized.
547 If 64-bit MMIO register operations are not supported, then ASSERT().
549 @param Address The MMIO register to read.
551 @return The value read.
561 // Make sure Address is aligned on a 64-bit boundary.
563 ASSERT ((Address
& 7) == 0);
564 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
568 Writes a 64-bit MMIO register.
570 Writes the 64-bit MMIO register specified by Address with the value specified
571 by Value and returns Value. This function must guarantee that all MMIO read
572 and write operations are serialized.
574 If 64-bit MMIO register operations are not supported, then ASSERT().
576 @param Address The MMIO register to write.
577 @param Value The value to write to the MMIO register.
588 // Make sure Address is aligned on a 64-bit boundary.
590 ASSERT ((Address
& 7) == 0);
591 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);