2 Common I/O Library routines.
4 Copyright (c) 2006 - 2008, 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.
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 an 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 If 8-bit I/O port operations are not supported, then ASSERT().
63 @param Port The I/O port to read.
65 @return The value read.
74 return MmioRead8 (InternalGetMemoryMapAddress (Port
));
78 Reads a 16-bit I/O port.
80 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
81 This function must guarantee that all I/O read and write operations are
84 If 16-bit I/O port operations are not supported, then ASSERT().
85 If Port is not aligned on a 16-bit boundary, then ASSERT().
87 @param Port The I/O port to read.
89 @return The value read.
98 return MmioRead16 (InternalGetMemoryMapAddress (Port
));
102 Reads a 32-bit I/O port.
104 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
105 This function must guarantee that all I/O read and write operations are
108 If 32-bit I/O port operations are not supported, then ASSERT().
109 If Port is not aligned on a 32-bit boundary, then ASSERT().
111 @param Port The I/O port to read.
113 @return The value read.
122 return MmioRead32 (InternalGetMemoryMapAddress (Port
));
126 Reads a 64-bit I/O port.
128 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
129 This function must guarantee that all I/O read and write operations are
132 If 64-bit I/O port operations are not supported, then ASSERT().
133 If Port is not aligned on a 64-bit boundary, then ASSERT().
135 @param Port The I/O port to read.
137 @return The value read.
151 Writes an 8-bit I/O port.
153 Writes the 8-bit I/O port specified by Port with the value specified by Value
154 and returns Value. This function must guarantee that all I/O read and write
155 operations are serialized.
157 If 8-bit I/O port operations are not supported, then ASSERT().
159 @param Port The I/O port to write.
160 @param Value The value to write to the I/O port.
162 @return The value written the I/O port.
172 return MmioWrite8 (InternalGetMemoryMapAddress (Port
), Value
);
176 Writes a 16-bit I/O port.
178 Writes the 16-bit I/O port specified by Port with the value specified by Value
179 and returns Value. This function must guarantee that all I/O read and write
180 operations are serialized.
182 If 16-bit I/O port operations are not supported, then ASSERT().
183 If Port is not aligned on a 16-bit boundary, then ASSERT().
185 @param Port The I/O port to write.
186 @param Value The value to write to the I/O port.
188 @return The value written the I/O port.
198 return MmioWrite16 (InternalGetMemoryMapAddress (Port
), Value
);
202 Writes a 32-bit I/O port.
204 Writes the 32-bit I/O port specified by Port with the value specified by Value
205 and returns Value. This function must guarantee that all I/O read and write
206 operations are serialized.
208 If 32-bit I/O port operations are not supported, then ASSERT().
209 If Port is not aligned on a 32-bit boundary, 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 MmioWrite32 (InternalGetMemoryMapAddress (Port
), Value
);
228 Writes a 64-bit I/O port.
230 Writes the 64-bit I/O port specified by Port with the value specified by Value
231 and returns Value. This function must guarantee that all I/O read and write
232 operations are serialized.
234 If 64-bit I/O port operations are not supported, then ASSERT().
235 If Port is not aligned on a 64-bit boundary, then ASSERT().
237 @param Port The I/O port to write.
238 @param Value The value to write to the I/O port.
240 @return The value written the I/O port.
255 Reads an 8-bit MMIO register.
257 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
258 returned. This function must guarantee that all MMIO read and write
259 operations are serialized.
261 If 8-bit MMIO register operations are not supported, then ASSERT().
263 @param Address The MMIO register to read.
265 @return The value read.
279 Data
= *((volatile UINT8
*) Address
);
286 Reads a 16-bit MMIO register.
288 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
289 returned. This function must guarantee that all MMIO read and write
290 operations are serialized.
292 If 16-bit MMIO register operations are not supported, then ASSERT().
293 If Address is not aligned on a 16-bit boundary, then ASSERT().
295 @param Address The MMIO register to read.
297 @return The value read.
309 // Make sure that Address is 16-bit aligned.
311 ASSERT ((Address
& 1) == 0);
316 Data
= *((volatile UINT16
*) Address
);
323 Reads a 32-bit MMIO register.
325 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
326 returned. This function must guarantee that all MMIO read and write
327 operations are serialized.
329 If 32-bit MMIO register operations are not supported, then ASSERT().
330 If Address is not aligned on a 32-bit boundary, then ASSERT().
332 @param Address The MMIO register to read.
334 @return The value read.
346 // Make sure that Address is 32-bit aligned.
348 ASSERT ((Address
& 3) == 0);
353 Data
= *((volatile UINT32
*) Address
);
360 Reads a 64-bit MMIO register.
362 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
363 returned. This function must guarantee that all MMIO read and write
364 operations are serialized.
366 If 64-bit MMIO register operations are not supported, then ASSERT().
367 If Address is not aligned on a 64-bit boundary, then ASSERT().
369 @param Address The MMIO register to read.
371 @return The value read.
383 // Make sure that Address is 64-bit aligned.
385 ASSERT ((Address
& 7) == 0);
390 Data
= *((volatile UINT64
*) Address
);
398 Writes an 8-bit MMIO register.
400 Writes the 8-bit MMIO register specified by Address with the value specified
401 by Value and returns Value. This function must guarantee that all MMIO read
402 and write operations are serialized.
404 If 8-bit MMIO register operations are not supported, then ASSERT().
406 @param Address The MMIO register to write.
407 @param Value The value to write to the MMIO register.
422 *((volatile UINT8
*) Address
) = Value
;
429 Writes a 16-bit MMIO register.
431 Writes the 16-bit MMIO register specified by Address with the value specified
432 by Value and returns Value. This function must guarantee that all MMIO read
433 and write operations are serialized.
435 If 16-bit MMIO register operations are not supported, then ASSERT().
436 If Address is not aligned on a 16-bit boundary, then ASSERT().
438 @param Address The MMIO register to write.
439 @param Value The value to write to the MMIO register.
452 // Make sure that Address is 16-bit aligned.
454 ASSERT ((Address
& 1) == 0);
459 *((volatile UINT16
*) Address
) = Value
;
466 Writes a 32-bit MMIO register.
468 Writes the 32-bit MMIO register specified by Address with the value specified
469 by Value and returns Value. This function must guarantee that all MMIO read
470 and write operations are serialized.
472 If 32-bit MMIO register operations are not supported, then ASSERT().
473 If Address is not aligned on a 32-bit boundary, then ASSERT().
475 @param Address The MMIO register to write.
476 @param Value The value to write to the MMIO register.
489 // Make sure that Address is 32-bit aligned.
491 ASSERT ((Address
& 3) == 0);
496 *((volatile UINT32
*) Address
) = Value
;
503 Writes a 64-bit MMIO register.
505 Writes the 64-bit MMIO register specified by Address with the value specified
506 by Value and returns Value. This function must guarantee that all MMIO read
507 and write operations are serialized.
509 If 64-bit MMIO register operations are not supported, then ASSERT().
510 If Address is not aligned on a 64-bit boundary, then ASSERT().
512 @param Address The MMIO register to write.
513 @param Value The value to write to the MMIO register.
524 // Make sure that Address is 64-bit aligned.
526 ASSERT ((Address
& 7) == 0);
531 *((volatile UINT64
*) Address
) = Value
;