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
;
43 ReturnReg
= EsalCall (
44 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
45 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
55 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
60 Writes registers in the EFI CPU I/O space.
62 Writes the I/O port specified by Port with registers width and value specified by Width
63 and Data respectively. Data is returned. If such operations are not supported, then ASSERT().
64 This function must guarantee that all I/O read and write operations are serialized.
66 @param Port The base address of the I/O operation.
67 The caller is responsible for aligning the Address if required.
68 @param Width The width of the I/O operation.
69 @param Data The value to write to the I/O port.
71 @return The paramter of Data.
78 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
82 SAL_RETURN_REGS ReturnReg
;
84 ReturnReg
= EsalCall (
85 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
86 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
96 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
101 Reads memory-mapped registers in the EFI system memory space.
103 Reads the MMIO registers specified by Address with registers width specified by Width.
104 The read value is returned. If such operations are not supported, then ASSERT().
105 This function must guarantee that all MMIO read and write operations are serialized.
107 @param Address The MMIO register to read.
108 The caller is responsible for aligning the Address if required.
109 @param Width The width of the I/O operation.
111 @return Data read from registers in the EFI system memory space.
118 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
121 SAL_RETURN_REGS ReturnReg
;
126 ReturnReg
= EsalCall (
127 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
128 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
138 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
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.
152 @param Data The value to write to memory-mapped registers
154 @return Data read from registers in the EFI system memory space.
161 IN EFI_CPU_IO_PROTOCOL_WIDTH Width
,
165 SAL_RETURN_REGS ReturnReg
;
167 ReturnReg
= EsalCall (
168 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_LO
,
169 EFI_EXTENDED_SAL_BASE_IO_SERVICES_PROTOCOL_GUID_HI
,
179 ASSERT (ReturnReg
.Status
== EFI_SAL_SUCCESS
);
184 Reads an 8-bit I/O port.
186 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
187 This function must guarantee that all I/O read and write operations are
190 If 8-bit I/O port operations are not supported, then ASSERT().
192 @param Port The I/O port to read.
194 @return The value read.
203 return (UINT8
)IoReadWorker (Port
, EfiCpuIoWidthUint8
);
207 Writes an 8-bit I/O port.
209 Writes the 8-bit I/O port specified by Port with the value specified by Value
210 and returns Value. This function must guarantee that all I/O read and write
211 operations are serialized.
213 If 8-bit I/O port operations are not supported, then ASSERT().
215 @param Port The I/O port to write.
216 @param Value The value to write to the I/O port.
218 @return The value written the I/O port.
228 return (UINT8
)IoWriteWorker (Port
, EfiCpuIoWidthUint8
, Value
);
232 Reads a 16-bit I/O port.
234 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
235 This function must guarantee that all I/O read and write operations are
238 If 16-bit I/O port operations are not supported, then ASSERT().
240 @param Port The I/O port to read.
242 @return The value read.
252 // Make sure Port is aligned on a 16-bit boundary.
254 ASSERT ((Port
& 1) == 0);
255 return (UINT16
)IoReadWorker (Port
, EfiCpuIoWidthUint16
);
259 Writes a 16-bit I/O port.
261 Writes the 16-bit I/O port specified by Port with the value specified by Value
262 and returns Value. This function must guarantee that all I/O read and write
263 operations are serialized.
265 If 16-bit I/O port operations are not supported, then ASSERT().
267 @param Port The I/O port to write.
268 @param Value The value to write to the I/O port.
270 @return The value written the I/O port.
281 // Make sure Port is aligned on a 16-bit boundary.
283 ASSERT ((Port
& 1) == 0);
284 return (UINT16
)IoWriteWorker (Port
, EfiCpuIoWidthUint16
, Value
);
288 Reads a 32-bit I/O port.
290 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
291 This function must guarantee that all I/O read and write operations are
294 If 32-bit I/O port operations are not supported, then ASSERT().
296 @param Port The I/O port to read.
298 @return The value read.
308 // Make sure Port is aligned on a 32-bit boundary.
310 ASSERT ((Port
& 3) == 0);
311 return (UINT32
)IoReadWorker (Port
, EfiCpuIoWidthUint32
);
315 Writes a 32-bit I/O port.
317 Writes the 32-bit I/O port specified by Port with the value specified by Value
318 and returns Value. This function must guarantee that all I/O read and write
319 operations are serialized.
321 If 32-bit I/O port operations are not supported, then ASSERT().
323 @param Port The I/O port to write.
324 @param Value The value to write to the I/O port.
326 @return The value written the I/O port.
337 // Make sure Port is aligned on a 32-bit boundary.
339 ASSERT ((Port
& 3) == 0);
340 return (UINT32
)IoWriteWorker (Port
, EfiCpuIoWidthUint32
, Value
);
344 Reads a 64-bit I/O port.
346 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
347 This function must guarantee that all I/O read and write operations are
350 If 64-bit I/O port operations are not supported, then ASSERT().
352 @param Port The I/O port to read.
354 @return The value read.
364 // Make sure Port is aligned on a 64-bit boundary.
366 ASSERT ((Port
& 7) == 0);
367 return IoReadWorker (Port
, EfiCpuIoWidthUint64
);
371 Writes a 64-bit I/O port.
373 Writes the 64-bit I/O port specified by Port with the value specified by Value
374 and returns Value. This function must guarantee that all I/O read and write
375 operations are serialized.
377 If 64-bit I/O port operations are not supported, then ASSERT().
379 @param Port The I/O port to write.
380 @param Value The value to write to the I/O port.
382 @return The value written the I/O port.
393 // Make sure Port is aligned on a 64-bit boundary.
395 ASSERT ((Port
& 7) == 0);
396 return IoWriteWorker (Port
, EfiCpuIoWidthUint64
, Value
);
400 Reads an 8-bit MMIO register.
402 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
403 returned. This function must guarantee that all MMIO read and write
404 operations are serialized.
406 If 8-bit MMIO register operations are not supported, then ASSERT().
408 @param Address The MMIO register to read.
410 @return The value read.
419 return (UINT8
)MmioReadWorker (Address
, EfiCpuIoWidthUint8
);
423 Writes an 8-bit MMIO register.
425 Writes the 8-bit MMIO register specified by Address with the value specified
426 by Value and returns Value. This function must guarantee that all MMIO read
427 and write operations are serialized.
429 If 8-bit MMIO register operations are not supported, then ASSERT().
431 @param Address The MMIO register to write.
432 @param Value The value to write to the MMIO register.
442 return (UINT8
)MmioWriteWorker (Address
, EfiCpuIoWidthUint8
, Value
);
446 Reads a 16-bit MMIO register.
448 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
449 returned. This function must guarantee that all MMIO read and write
450 operations are serialized.
452 If 16-bit MMIO register operations are not supported, then ASSERT().
454 @param Address The MMIO register to read.
456 @return The value read.
466 // Make sure Address is aligned on a 16-bit boundary.
468 ASSERT ((Address
& 1) == 0);
469 return (UINT16
)MmioReadWorker (Address
, EfiCpuIoWidthUint16
);
473 Writes a 16-bit MMIO register.
475 Writes the 16-bit MMIO register specified by Address with the value specified
476 by Value and returns Value. This function must guarantee that all MMIO read
477 and write operations are serialized.
479 If 16-bit MMIO register operations are not supported, then ASSERT().
481 @param Address The MMIO register to write.
482 @param Value The value to write to the MMIO register.
493 // Make sure Address is aligned on a 16-bit boundary.
495 ASSERT ((Address
& 1) == 0);
496 return (UINT16
)MmioWriteWorker (Address
, EfiCpuIoWidthUint16
, Value
);
500 Reads a 32-bit MMIO register.
502 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
503 returned. This function must guarantee that all MMIO read and write
504 operations are serialized.
506 If 32-bit MMIO register operations are not supported, then ASSERT().
508 @param Address The MMIO register to read.
510 @return The value read.
520 // Make sure Address is aligned on a 32-bit boundary.
522 ASSERT ((Address
& 3) == 0);
523 return (UINT32
)MmioReadWorker (Address
, EfiCpuIoWidthUint32
);
527 Writes a 32-bit MMIO register.
529 Writes the 32-bit MMIO register specified by Address with the value specified
530 by Value and returns Value. This function must guarantee that all MMIO read
531 and write operations are serialized.
533 If 32-bit MMIO register operations are not supported, then ASSERT().
535 @param Address The MMIO register to write.
536 @param Value The value to write to the MMIO register.
547 // Make sure Address is aligned on a 32-bit boundary.
549 ASSERT ((Address
& 3) == 0);
550 return (UINT32
)MmioWriteWorker (Address
, EfiCpuIoWidthUint32
, Value
);
554 Reads a 64-bit MMIO register.
556 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
557 returned. This function must guarantee that all MMIO read and write
558 operations are serialized.
560 If 64-bit MMIO register operations are not supported, then ASSERT().
562 @param Address The MMIO register to read.
564 @return The value read.
574 // Make sure Address is aligned on a 64-bit boundary.
576 ASSERT ((Address
& 7) == 0);
577 return (UINT64
)MmioReadWorker (Address
, EfiCpuIoWidthUint64
);
581 Writes a 64-bit MMIO register.
583 Writes the 64-bit MMIO register specified by Address with the value specified
584 by Value and returns Value. This function must guarantee that all MMIO read
585 and write operations are serialized.
587 If 64-bit MMIO register operations are not supported, then ASSERT().
589 @param Address The MMIO register to write.
590 @param Value The value to write to the MMIO register.
601 // Make sure Address is aligned on a 64-bit boundary.
603 ASSERT ((Address
& 7) == 0);
604 return (UINT64
)MmioWriteWorker (Address
, EfiCpuIoWidthUint64
, Value
);