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.
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.
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.
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.
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 the I/O port.
162 return MmioWrite8 (InternalGetMemoryMapAddress (Port
), Data
);
166 Writes a 16-bit I/O port.
168 Writes the 16-bit I/O port specified by Port with the value specified by Value
169 and returns Value. This function must guarantee that all I/O read and write
170 operations are serialized.
172 @param Port The I/O port to write.
173 @param Value The value to write to the I/O port.
175 @return The value written the I/O port.
185 return MmioWrite16 (InternalGetMemoryMapAddress (Port
), Data
);
189 Writes a 32-bit I/O port.
191 Writes the 32-bit I/O port specified by Port with the value specified by Value
192 and returns Value. This function must guarantee that all I/O read and write
193 operations are serialized.
195 @param Port The I/O port to write.
196 @param Value The value to write to the I/O port.
198 @return The value written the I/O port.
208 return MmioWrite32 (InternalGetMemoryMapAddress (Port
), Data
);
212 Writes a 64-bit I/O port.
214 Writes the 64-bit I/O port specified by Port with the value specified by Value
215 and returns Value. This function must guarantee that all I/O read and write
216 operations are serialized.
218 If 64-bit I/O port operations are not supported, then ASSERT().
220 @param Port The I/O port to write.
221 @param Value The value to write to the I/O port.
223 @return The value written the I/O port.
238 Reads a 8-bit MMIO register.
240 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
241 returned. This function must guarantee that all MMIO read and write
242 operations are serialized.
244 @param Address The MMIO register to read.
246 @return The value read.
260 Data
= *((volatile UINT8
*) Address
);
267 Reads a 16-bit MMIO register.
269 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
270 returned. This function must guarantee that all MMIO read and write
271 operations are serialized.
273 @param Address The MMIO register to read.
275 @return The value read.
287 // Make sure that Address is 16-bit aligned.
289 ASSERT ((Address
& 1) == 0);
294 Data
= *((volatile UINT16
*) Address
);
301 Reads a 32-bit MMIO register.
303 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
304 returned. This function must guarantee that all MMIO read and write
305 operations are serialized.
307 @param Address The MMIO register to read.
309 @return The value read.
321 // Make sure that Address is 32-bit aligned.
323 ASSERT ((Address
& 3) == 0);
328 Data
= *((volatile UINT32
*) Address
);
335 Reads a 64-bit MMIO register.
337 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
338 returned. This function must guarantee that all MMIO read and write
339 operations are serialized.
341 @param Address The MMIO register to read.
343 @return The value read.
355 // Make sure that Address is 64-bit aligned.
357 ASSERT ((Address
& 7) == 0);
362 Data
= *((volatile UINT64
*) Address
);
370 Writes a 8-bit MMIO register.
372 Writes the 8-bit MMIO register specified by Address with the value specified
373 by Value and returns Value. This function must guarantee that all MMIO read
374 and write operations are serialized.
376 @param Address The MMIO register to write.
377 @param Data The value to write to the MMIO register.
379 @return The value written the memory address.
392 *((volatile UINT8
*) Address
) = Data
;
399 Writes a 16-bit MMIO register.
401 Writes the 16-bit MMIO register specified by Address with the value specified
402 by Value and returns Value. This function must guarantee that all MMIO read
403 and write operations are serialized.
405 @param Address The MMIO register to write.
406 @param Data The value to write to the MMIO register.
408 @return The value written the memory address.
419 // Make sure that Address is 16-bit aligned.
421 ASSERT ((Address
& 1) == 0);
426 *((volatile UINT16
*) Address
) = Data
;
433 Writes a 32-bit MMIO register.
435 Writes the 32-bit MMIO register specified by Address with the value specified
436 by Value and returns Value. This function must guarantee that all MMIO read
437 and write operations are serialized.
439 @param Address The MMIO register to write.
440 @param Data The value to write to the MMIO register.
442 @return The value written the memory address.
453 // Make sure that Address is 32-bit aligned.
455 ASSERT ((Address
& 3) == 0);
460 *((volatile UINT32
*) Address
) = Data
;
467 Writes a 64-bit MMIO register.
469 Writes the 64-bit MMIO register specified by Address with the value specified
470 by Value and returns Value. This function must guarantee that all MMIO read
471 and write operations are serialized.
473 @param Address The MMIO register to write.
474 @param Data The value to write to the MMIO register.
476 @return The value written the memory address.
487 // Make sure that Address is 64-bit aligned.
489 ASSERT ((Address
& 7) == 0);
494 *((volatile UINT64
*) Address
) = Data
;