2 Common I/O Library routines.
4 Copyright (c) 2006 - 2007, 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 common header file for this module.
18 #include "BaseIoLibIntrinsicInternal.h"
20 #define MAP_PORT_BASE_TO_MEM(_Port) \
21 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
24 Translates I/O port address to memory address.
26 This function translates I/O port address to memory address by adding the 64MB
27 aligned I/O Port space to the I/O address.
28 If I/O Port space base is not 64MB aligned, then ASSERT ().
30 @param Port The I/O port to read.
32 @return The memory address.
36 InternalGetMemoryMapAddress (
41 UINTN IoBlockBaseAddress
;
43 Address
= MAP_PORT_BASE_TO_MEM (Port
);
44 IoBlockBaseAddress
= PcdGet64(PcdIoBlockBaseAddressForIpf
);
47 // Make sure that the I/O Port space base is 64MB aligned.
49 ASSERT ((IoBlockBaseAddress
& 0x3ffffff) == 0);
50 Address
+= IoBlockBaseAddress
;
56 Reads a 8-bit I/O port.
58 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
59 This function must guarantee that all I/O read and write operations are
62 @param Port The I/O port to read.
64 @return The value read from Port.
73 return MmioRead8 (InternalGetMemoryMapAddress (Port
));
77 Reads a 16-bit I/O port.
79 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
80 This function must guarantee that all I/O read and write operations are
83 @param Port The I/O port to read.
85 @return The value read from Port.
94 return MmioRead16 (InternalGetMemoryMapAddress (Port
));
98 Reads a 32-bit I/O port.
100 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
101 This function must guarantee that all I/O read and write operations are
104 @param Port The I/O port to read.
106 @return The value read from Port.
115 return MmioRead32 (InternalGetMemoryMapAddress (Port
));
119 Reads a 64-bit I/O port.
121 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
122 This function must guarantee that all I/O read and write operations are
125 If 64-bit I/O port operations are not supported, then ASSERT().
127 @param Port The I/O port to read.
129 @return The value read from Port.
143 Writes a 8-bit I/O port.
145 Writes the 8-bit I/O port specified by Port with the value specified by Value
146 and returns Value. This function must guarantee that all I/O read and write
147 operations are serialized.
149 @param Port The I/O port to write.
150 @param Value The value to write to the I/O port.
152 @return The value written to the I/O port. It equals to the
153 input Value instead of the actual value read back from
164 return MmioWrite8 (InternalGetMemoryMapAddress (Port
), Data
);
168 Writes a 16-bit I/O port.
170 Writes the 16-bit I/O port specified by Port with the value specified by Value
171 and returns Value. This function must guarantee that all I/O read and write
172 operations are serialized.
174 @param Port The I/O port to write.
175 @param Value The value to write to the I/O port.
177 @return The value written to the I/O port. It equals to the
178 input Value instead of the actual value read back from
189 return MmioWrite16 (InternalGetMemoryMapAddress (Port
), Data
);
193 Writes a 32-bit I/O port.
195 Writes the 32-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 @param Port The I/O port to write.
200 @param Value The value to write to the I/O port.
202 @return The value written to the I/O port. It equals to the
203 input Value instead of the actual value read back from
214 return MmioWrite32 (InternalGetMemoryMapAddress (Port
), Data
);
218 Writes a 64-bit I/O port.
220 Writes the 64-bit I/O port specified by Port with the value specified by Value
221 and returns Value. This function must guarantee that all I/O read and write
222 operations are serialized.
224 If 64-bit I/O port operations are not supported, then ASSERT().
226 @param Port The I/O port to write.
227 @param Value The value to write to the I/O port.
229 @return The value written to the I/O port. It equals to the
230 input Value instead of the actual value read back from
246 Reads a 8-bit MMIO register.
248 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
249 returned. This function must guarantee that all MMIO read and write
250 operations are serialized.
252 @param Address The MMIO register to read.
254 @return The value read from Address.
268 Data
= *((volatile UINT8
*) Address
);
275 Reads a 16-bit MMIO register.
277 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
278 returned. This function must guarantee that all MMIO read and write
279 operations are serialized.
281 @param Address The MMIO register to read.
283 @return The value read from Address.
295 // Make sure that Address is 16-bit aligned.
297 ASSERT ((Address
& 1) == 0);
302 Data
= *((volatile UINT16
*) Address
);
309 Reads a 32-bit MMIO register.
311 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
312 returned. This function must guarantee that all MMIO read and write
313 operations are serialized.
315 @param Address The MMIO register to read.
317 @return The value read from Address.
329 // Make sure that Address is 32-bit aligned.
331 ASSERT ((Address
& 3) == 0);
336 Data
= *((volatile UINT32
*) Address
);
343 Reads a 64-bit MMIO register.
345 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
346 returned. This function must guarantee that all MMIO read and write
347 operations are serialized.
349 @param Address The MMIO register to read.
351 @return The value read from Address.
363 // Make sure that Address is 64-bit aligned.
365 ASSERT ((Address
& 7) == 0);
370 Data
= *((volatile UINT64
*) Address
);
378 Writes a 8-bit MMIO register.
380 Writes the 8-bit MMIO register specified by Address with the value specified
381 by Value and returns Value. This function must guarantee that all MMIO read
382 and write operations are serialized.
384 @param Address The MMIO register to write.
385 @param Data The value to write to the MMIO register.
387 @return The value written to the Mmio. It equals to the
388 input Value instead of the actual value read back from
402 *((volatile UINT8
*) Address
) = Data
;
409 Writes a 16-bit MMIO register.
411 Writes the 16-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 @param Address The MMIO register to write.
416 @param Data The value to write to the MMIO register.
418 @return The value written to the Mmio. It equals to the
419 input Value instead of the actual value read back from
431 // Make sure that Address is 16-bit aligned.
433 ASSERT ((Address
& 1) == 0);
438 *((volatile UINT16
*) Address
) = Data
;
445 Writes a 32-bit MMIO register.
447 Writes the 32-bit MMIO register specified by Address with the value specified
448 by Value and returns Value. This function must guarantee that all MMIO read
449 and write operations are serialized.
451 @param Address The MMIO register to write.
452 @param Data The value to write to the MMIO register.
454 @return The value written to the Mmio. It equals to the
455 input Value instead of the actual value read back from
467 // Make sure that Address is 32-bit aligned.
469 ASSERT ((Address
& 3) == 0);
474 *((volatile UINT32
*) Address
) = Data
;
481 Writes a 64-bit MMIO register.
483 Writes the 64-bit MMIO register specified by Address with the value specified
484 by Value and returns Value. This function must guarantee that all MMIO read
485 and write operations are serialized.
487 @param Address The MMIO register to write.
488 @param Data The value to write to the MMIO register.
490 @return The value written to the Mmio. It equals to the
491 input Value instead of the actual value read back from
503 // Make sure that Address is 64-bit aligned.
505 ASSERT ((Address
& 7) == 0);
510 *((volatile UINT64
*) Address
) = Data
;