2 I/O Library basic function implementation and worker functions.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 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.
15 #include "DxeIoLibEsalInternal.h"
18 Reads registers in the EFI CPU I/O space.
20 Reads the I/O port specified by Port with registers width specified by Width.
21 The read value is returned. If such operations are not supported, then ASSERT().
22 This function must guarantee that all I/O read and write operations are serialized.
24 @param Port The base address of the I/O operation.
25 The caller is responsible for aligning the Address if required.
26 @param Width The width of the I/O operation.
28 @return Data read from registers in the EFI CPU I/O space.
35 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
38 SAL_RETURN_REGS ReturnReg
;
41 ReturnReg
= EsalCall (
42 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
43 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
53 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
58 Writes registers in the EFI CPU I/O space.
60 Writes the I/O port specified by Port with registers width and value specified by Width
61 and Data respectively. Data 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.
67 @param Data The value to write to the I/O port.
69 @return The paramter of Data.
76 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
80 SAL_RETURN_REGS ReturnReg
;
82 ReturnReg
= EsalCall (
83 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
84 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
94 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
99 Reads memory-mapped registers in the EFI system memory space.
101 Reads the MMIO registers specified by Address with registers width specified by Width.
102 The read value is returned. If such operations are not supported, then ASSERT().
103 This function must guarantee that all MMIO read and write operations are serialized.
105 @param Address The MMIO register to read.
106 The caller is responsible for aligning the Address if required.
107 @param Width The width of the I/O operation.
109 @return Data read from registers in the EFI system memory space.
116 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
119 SAL_RETURN_REGS ReturnReg
;
122 ReturnReg
= EsalCall (
123 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
124 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
134 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
139 Writes memory-mapped registers in the EFI system memory space.
141 Writes the MMIO registers specified by Address with registers width and value specified by Width
142 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
143 This function must guarantee that all MMIO read and write operations are serialized.
145 @param Address The MMIO register to read.
146 The caller is responsible for aligning the Address if required.
147 @param Width The width of the I/O operation.
148 @param Data The value to write to memory-mapped registers
150 @return Data read from registers in the EFI system memory space.
157 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
161 SAL_RETURN_REGS ReturnReg
;
163 ReturnReg
= EsalCall (
164 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
165 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
175 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
180 Reads an 8-bit I/O port.
182 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
183 This function must guarantee that all I/O read and write operations are
186 If 8-bit I/O port operations are not supported, then ASSERT().
188 @param Port The I/O port to read.
190 @return The value read.
199 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
203 Writes an 8-bit I/O port.
205 Writes the 8-bit I/O port specified by Port with the value specified by Value
206 and returns Value. This function must guarantee that all I/O read and write
207 operations are serialized.
209 If 8-bit I/O port operations are not supported, then ASSERT().
211 @param Port The I/O port to write.
212 @param Value The value to write to the I/O port.
214 @return The value written the I/O port.
224 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
228 Reads a 16-bit I/O port.
230 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
231 This function must guarantee that all I/O read and write operations are
234 If 16-bit I/O port operations are not supported, then ASSERT().
236 @param Port The I/O port to read.
238 @return The value read.
248 // Make sure Port is aligned on a 16-bit boundary.
250 ASSERT ((Port
& 1) == 0);
251 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
255 Writes a 16-bit I/O port.
257 Writes the 16-bit I/O port specified by Port with the value specified by Value
258 and returns Value. This function must guarantee that all I/O read and write
259 operations are serialized.
261 If 16-bit I/O port operations are not supported, then ASSERT().
263 @param Port The I/O port to write.
264 @param Value The value to write to the I/O port.
266 @return The value written the I/O port.
277 // Make sure Port is aligned on a 16-bit boundary.
279 ASSERT ((Port
& 1) == 0);
280 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
284 Reads a 32-bit I/O port.
286 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
287 This function must guarantee that all I/O read and write operations are
290 If 32-bit I/O port operations are not supported, then ASSERT().
292 @param Port The I/O port to read.
294 @return The value read.
304 // Make sure Port is aligned on a 32-bit boundary.
306 ASSERT ((Port
& 3) == 0);
307 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
311 Writes a 32-bit I/O port.
313 Writes the 32-bit I/O port specified by Port with the value specified by Value
314 and returns Value. This function must guarantee that all I/O read and write
315 operations are serialized.
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 64-bit I/O port operations are not supported, then ASSERT().
348 @param Port The I/O port to read.
350 @return The value read.
360 // Make sure Port is aligned on a 64-bit boundary.
362 ASSERT ((Port
& 7) == 0);
363 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
367 Writes a 64-bit I/O port.
369 Writes the 64-bit I/O port specified by Port with the value specified by Value
370 and returns Value. This function must guarantee that all I/O read and write
371 operations are serialized.
373 If 64-bit I/O port operations are not supported, then ASSERT().
375 @param Port The I/O port to write.
376 @param Value The value to write to the I/O port.
378 @return The value written the I/O port.
389 // Make sure Port is aligned on a 64-bit boundary.
391 ASSERT ((Port
& 7) == 0);
392 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
396 Reads an 8-bit MMIO register.
398 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
399 returned. This function must guarantee that all MMIO read and write
400 operations are serialized.
402 If 8-bit MMIO register operations are not supported, then ASSERT().
404 @param Address The MMIO register to read.
406 @return The value read.
415 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
419 Writes an 8-bit MMIO register.
421 Writes the 8-bit MMIO register specified by Address with the value specified
422 by Value and returns Value. This function must guarantee that all MMIO read
423 and write operations are serialized.
425 If 8-bit MMIO register operations are not supported, then ASSERT().
427 @param Address The MMIO register to write.
428 @param Value The value to write to the MMIO register.
438 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
442 Reads a 16-bit MMIO register.
444 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
445 returned. This function must guarantee that all MMIO read and write
446 operations are serialized.
448 If 16-bit MMIO register operations are not supported, then ASSERT().
450 @param Address The MMIO register to read.
452 @return The value read.
462 // Make sure Address is aligned on a 16-bit boundary.
464 ASSERT ((Address
& 1) == 0);
465 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
469 Writes a 16-bit MMIO register.
471 Writes the 16-bit MMIO register specified by Address with the value specified
472 by Value and returns Value. This function must guarantee that all MMIO read
473 and write operations are serialized.
475 If 16-bit MMIO register operations are not supported, then ASSERT().
477 @param Address The MMIO register to write.
478 @param Value The value to write to the MMIO register.
489 // Make sure Address is aligned on a 16-bit boundary.
491 ASSERT ((Address
& 1) == 0);
492 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
496 Reads a 32-bit MMIO register.
498 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
499 returned. This function must guarantee that all MMIO read and write
500 operations are serialized.
502 If 32-bit MMIO register operations are not supported, then ASSERT().
504 @param Address The MMIO register to read.
506 @return The value read.
516 // Make sure Address is aligned on a 32-bit boundary.
518 ASSERT ((Address
& 3) == 0);
519 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
523 Writes a 32-bit MMIO register.
525 Writes the 32-bit MMIO register specified by Address with the value specified
526 by Value and returns Value. This function must guarantee that all MMIO read
527 and write operations are serialized.
529 If 32-bit MMIO register operations are not supported, then ASSERT().
531 @param Address The MMIO register to write.
532 @param Value The value to write to the MMIO register.
543 // Make sure Address is aligned on a 32-bit boundary.
545 ASSERT ((Address
& 3) == 0);
546 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
550 Reads a 64-bit MMIO register.
552 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
553 returned. This function must guarantee that all MMIO read and write
554 operations are serialized.
556 If 64-bit MMIO register operations are not supported, then ASSERT().
558 @param Address The MMIO register to read.
560 @return The value read.
570 // Make sure Address is aligned on a 64-bit boundary.
572 ASSERT ((Address
& 7) == 0);
573 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
577 Writes a 64-bit MMIO register.
579 Writes the 64-bit MMIO register specified by Address with the value specified
580 by Value and returns Value. This function must guarantee that all MMIO read
581 and write operations are serialized.
583 If 64-bit MMIO register operations are not supported, then ASSERT().
585 @param Address The MMIO register to write.
586 @param Value The value to write to the MMIO register.
597 // Make sure Address is aligned on a 64-bit boundary.
599 ASSERT ((Address
& 7) == 0);
600 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);