2 Common I/O Library routines.
4 Copyright (c) 2006 - 2008, 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.
16 #include "BaseIoLibIntrinsicInternal.h"
17 #include <Library/PcdLib.h>
19 #define MAP_PORT_BASE_TO_MEM(_Port) \
20 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
23 Translates I/O port address to memory address.
25 This function translates I/O port address to memory address by adding the 64MB
26 aligned I/O Port space to the I/O address.
27 If I/O Port space base is not 64MB aligned, then ASSERT ().
29 @param Port The I/O port to read.
31 @return The memory address.
35 InternalGetMemoryMapAddress (
40 UINTN IoBlockBaseAddress
;
42 Address
= MAP_PORT_BASE_TO_MEM (Port
);
43 IoBlockBaseAddress
= PcdGet64(PcdIoBlockBaseAddressForIpf
);
46 // Make sure that the I/O Port space base is 64MB aligned.
48 ASSERT ((IoBlockBaseAddress
& 0x3ffffff) == 0);
49 Address
+= IoBlockBaseAddress
;
55 Reads a 8-bit I/O port.
57 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
58 This function must guarantee that all I/O read and write operations are
61 @param Port The I/O port to read.
63 @return The value read from Port.
72 return MmioRead8 (InternalGetMemoryMapAddress (Port
));
76 Reads a 16-bit I/O port.
78 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
79 This function must guarantee that all I/O read and write operations are
82 @param Port The I/O port to read.
84 @return The value read from Port.
93 return MmioRead16 (InternalGetMemoryMapAddress (Port
));
97 Reads a 32-bit I/O port.
99 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
100 This function must guarantee that all I/O read and write operations are
103 @param Port The I/O port to read.
105 @return The value read from Port.
114 return MmioRead32 (InternalGetMemoryMapAddress (Port
));
118 Reads a 64-bit I/O port.
120 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
121 This function must guarantee that all I/O read and write operations are
124 If 64-bit I/O port operations are not supported, then ASSERT().
126 @param Port The I/O port to read.
128 @return The value read from Port.
142 Writes a 8-bit I/O port.
144 Writes the 8-bit I/O port specified by Port with the value specified by Value
145 and returns Value. This function must guarantee that all I/O read and write
146 operations are serialized.
148 @param Port The I/O port to write.
149 @param Data The value to write to the I/O port.
151 @return The value written to the I/O port. It equals to the
152 input Value instead of the actual value read back from
163 return MmioWrite8 (InternalGetMemoryMapAddress (Port
), Data
);
167 Writes a 16-bit I/O port.
169 Writes the 16-bit I/O port specified by Port with the value specified by Value
170 and returns Value. This function must guarantee that all I/O read and write
171 operations are serialized.
173 @param Port The I/O port to write.
174 @param Data The value to write to the I/O port.
176 @return The value written to the I/O port. It equals to the
177 input Value instead of the actual value read back from
188 return MmioWrite16 (InternalGetMemoryMapAddress (Port
), Data
);
192 Writes a 32-bit I/O port.
194 Writes the 32-bit I/O port specified by Port with the value specified by Value
195 and returns Value. This function must guarantee that all I/O read and write
196 operations are serialized.
198 @param Port The I/O port to write.
199 @param Data The value to write to the I/O port.
201 @return The value written to the I/O port. It equals to the
202 input Value instead of the actual value read back from
213 return MmioWrite32 (InternalGetMemoryMapAddress (Port
), Data
);
217 Writes a 64-bit I/O port.
219 Writes the 64-bit I/O port specified by Port with the value specified by Value
220 and returns Value. This function must guarantee that all I/O read and write
221 operations are serialized.
223 If 64-bit I/O port operations are not supported, then ASSERT().
225 @param Port The I/O port to write.
226 @param Value The value to write to the I/O port.
228 @return The value written to the I/O port. It equals to the
229 input Value instead of the actual value read back from
245 Reads a 8-bit MMIO register.
247 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
248 returned. This function must guarantee that all MMIO read and write
249 operations are serialized.
251 @param Address The MMIO register to read.
253 @return The value read from Address.
267 Data
= *((volatile UINT8
*) Address
);
274 Reads a 16-bit MMIO register.
276 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
277 returned. This function must guarantee that all MMIO read and write
278 operations are serialized.
280 @param Address The MMIO register to read.
282 @return The value read from Address.
294 // Make sure that Address is 16-bit aligned.
296 ASSERT ((Address
& 1) == 0);
301 Data
= *((volatile UINT16
*) Address
);
308 Reads a 32-bit MMIO register.
310 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
311 returned. This function must guarantee that all MMIO read and write
312 operations are serialized.
314 @param Address The MMIO register to read.
316 @return The value read from Address.
328 // Make sure that Address is 32-bit aligned.
330 ASSERT ((Address
& 3) == 0);
335 Data
= *((volatile UINT32
*) Address
);
342 Reads a 64-bit MMIO register.
344 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
345 returned. This function must guarantee that all MMIO read and write
346 operations are serialized.
348 @param Address The MMIO register to read.
350 @return The value read from Address.
362 // Make sure that Address is 64-bit aligned.
364 ASSERT ((Address
& 7) == 0);
369 Data
= *((volatile UINT64
*) Address
);
377 Writes a 8-bit MMIO register.
379 Writes the 8-bit MMIO register specified by Address with the value specified
380 by Value and returns Value. This function must guarantee that all MMIO read
381 and write operations are serialized.
383 @param Address The MMIO register to write.
384 @param Data The value to write to the MMIO register.
386 @return The value written to the Mmio. It equals to the
387 input Value instead of the actual value read back from
401 *((volatile UINT8
*) Address
) = Data
;
408 Writes a 16-bit MMIO register.
410 Writes the 16-bit MMIO register specified by Address with the value specified
411 by Value and returns Value. This function must guarantee that all MMIO read
412 and write operations are serialized.
414 @param Address The MMIO register to write.
415 @param Data The value to write to the MMIO register.
417 @return The value written to the Mmio. It equals to the
418 input Value instead of the actual value read back from
430 // Make sure that Address is 16-bit aligned.
432 ASSERT ((Address
& 1) == 0);
437 *((volatile UINT16
*) Address
) = Data
;
444 Writes a 32-bit MMIO register.
446 Writes the 32-bit MMIO register specified by Address with the value specified
447 by Value and returns Value. This function must guarantee that all MMIO read
448 and write operations are serialized.
450 @param Address The MMIO register to write.
451 @param Data The value to write to the MMIO register.
453 @return The value written to the Mmio. It equals to the
454 input Value instead of the actual value read back from
466 // Make sure that Address is 32-bit aligned.
468 ASSERT ((Address
& 3) == 0);
473 *((volatile UINT32
*) Address
) = Data
;
480 Writes a 64-bit MMIO register.
482 Writes the 64-bit MMIO register specified by Address with the value specified
483 by Value and returns Value. This function must guarantee that all MMIO read
484 and write operations are serialized.
486 @param Address The MMIO register to write.
487 @param Data The value to write to the MMIO register.
489 @return The value written to the Mmio. It equals to the
490 input Value instead of the actual value read back from
502 // Make sure that Address is 64-bit aligned.
504 ASSERT ((Address
& 7) == 0);
509 *((volatile UINT64
*) Address
) = Data
;