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.
13 Module Name: IoLibIpf.c
18 // Include common header file for this module.
20 #include "CommonHeader.h"
22 #define MAP_PORT_BASE_TO_MEM(_Port) \
23 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
26 Reads a 8-bit I/O port.
28 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
29 This function must guarantee that all I/O read and write operations are
32 @param Port The I/O port to read.
34 @return The value read.
46 // Add the 64MB aligned IO Port space to the IO address
48 Address
= MAP_PORT_BASE_TO_MEM (Port
);
49 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
51 return MmioRead8 (Address
);
55 Reads a 16-bit I/O port.
57 Reads the 16-bit I/O port specified by Port. The 16-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.
75 // Add the 64MB aligned IO Port space to the IO address
77 Address
= MAP_PORT_BASE_TO_MEM (Port
);
78 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
80 return MmioRead16 (Address
);
84 Reads a 32-bit I/O port.
86 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
87 This function must guarantee that all I/O read and write operations are
90 @param Port The I/O port to read.
92 @return The value read.
104 // Add the 64MB aligned IO Port space to the IO address
106 Address
= MAP_PORT_BASE_TO_MEM (Port
);
107 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
109 return MmioRead32 (Address
);
113 Reads a 64-bit I/O port.
115 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
116 This function must guarantee that all I/O read and write operations are
119 If 64-bit I/O port operations are not supported, then ASSERT().
121 @param Port The I/O port to read.
123 @return The value read.
137 Writes a 8-bit I/O port.
139 Writes the 8-bit I/O port specified by Port with the value specified by Value
140 and returns Value. This function must guarantee that all I/O read and write
141 operations are serialized.
143 @param Port The I/O port to write.
144 @param Value The value to write to the I/O port.
146 @return The value written the I/O port.
159 // Add the 64MB aligned IO Port space to the IO address
161 Address
= MAP_PORT_BASE_TO_MEM (Port
);
162 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
164 return MmioWrite8 (Address
, 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 the I/O port.
190 // Add the 64MB aligned IO Port space to the IO address
192 Address
= MAP_PORT_BASE_TO_MEM (Port
);
193 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
195 return MmioWrite16 (Address
, Data
);
199 Writes a 32-bit I/O port.
201 Writes the 32-bit I/O port specified by Port with the value specified by Value
202 and returns Value. This function must guarantee that all I/O read and write
203 operations are serialized.
205 @param Port The I/O port to write.
206 @param Value The value to write to the I/O port.
208 @return The value written the I/O port.
221 // Add the 64MB aligned IO Port space to the IO address
223 Address
= MAP_PORT_BASE_TO_MEM (Port
);
224 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
226 return MmioWrite32 (Address
, Data
);
230 Writes a 64-bit I/O port.
232 Writes the 64-bit I/O port specified by Port with the value specified by Value
233 and returns Value. This function must guarantee that all I/O read and write
234 operations are serialized.
236 If 64-bit I/O port operations are not supported, then ASSERT().
238 @param Port The I/O port to write.
239 @param Value The value to write to the I/O port.
241 @return The value written the I/O port.
256 Reads a 8-bit MMIO register.
258 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
259 returned. This function must guarantee that all MMIO read and write
260 operations are serialized.
262 @param Address The MMIO register to read.
264 @return The value read.
278 Data
= *((volatile UINT8
*) Address
);
285 Reads a 16-bit MMIO register.
287 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
288 returned. This function must guarantee that all MMIO read and write
289 operations are serialized.
291 @param Address The MMIO register to read.
293 @return The value read.
307 Data
= *((volatile UINT16
*) Address
);
314 Reads a 32-bit MMIO register.
316 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
317 returned. This function must guarantee that all MMIO read and write
318 operations are serialized.
320 @param Address The MMIO register to read.
322 @return The value read.
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.
365 Data
= *((volatile UINT64
*) Address
);
373 Writes a 8-bit MMIO register.
375 Writes the 8-bit MMIO register specified by Address with the value specified
376 by Value and returns Value. This function must guarantee that all MMIO read
377 and write operations are serialized.
379 @param Address The MMIO register to write.
380 @param Data The value to write to the MMIO register.
382 @return The value written the memory address.
395 *((volatile UINT8
*) Address
) = Data
;
402 Writes a 16-bit MMIO register.
404 Writes the 16-bit MMIO register specified by Address with the value specified
405 by Value and returns Value. This function must guarantee that all MMIO read
406 and write operations are serialized.
408 @param Address The MMIO register to write.
409 @param Data The value to write to the MMIO register.
411 @return The value written the memory address.
424 *((volatile UINT16
*) Address
) = Data
;
431 Writes a 32-bit MMIO register.
433 Writes the 32-bit MMIO register specified by Address with the value specified
434 by Value and returns Value. This function must guarantee that all MMIO read
435 and write operations are serialized.
437 @param Address The MMIO register to write.
438 @param Data The value to write to the MMIO register.
440 @return The value written the memory address.
453 *((volatile UINT32
*) Address
) = Data
;
460 Writes a 64-bit MMIO register.
462 Writes the 64-bit MMIO register specified by Address with the value specified
463 by Value and returns Value. This function must guarantee that all MMIO read
464 and write operations are serialized.
466 @param Address The MMIO register to write.
467 @param Data The value to write to the MMIO register.
469 @return The value written the memory address.
482 *((volatile UINT64
*) Address
) = Data
;