2 Common I/O Library routines.
4 Copyright (c) 2006, 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
17 #define BIT63 0x8000000000000000ULL
19 #define MAP_PORT_BASE_TO_MEM(_Port) \
20 ((((_Port) & 0xfffc) << 10) | ((_Port) & 0x0fff))
23 Reads a 8-bit I/O port.
25 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
26 This function must guarantee that all I/O read and write operations are
29 @param Port The I/O port to read.
31 @return The value read.
43 // Add the 64MB aligned IO Port space to the IO address
45 Address
= MAP_PORT_BASE_TO_MEM (Port
);
46 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
48 return MmioRead8 (Address
);
52 Reads a 16-bit I/O port.
54 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
55 This function must guarantee that all I/O read and write operations are
58 @param Port The I/O port to read.
60 @return The value read.
72 // Add the 64MB aligned IO Port space to the IO address
74 Address
= MAP_PORT_BASE_TO_MEM (Port
);
75 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
77 return MmioRead16 (Address
);
81 Reads a 32-bit I/O port.
83 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
84 This function must guarantee that all I/O read and write operations are
87 @param Port The I/O port to read.
89 @return The value read.
101 // Add the 64MB aligned IO Port space to the IO address
103 Address
= MAP_PORT_BASE_TO_MEM (Port
);
104 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
106 return MmioRead32 (Address
);
110 Reads a 64-bit I/O port.
112 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
113 This function must guarantee that all I/O read and write operations are
116 If 64-bit I/O port operations are not supported, then ASSERT().
118 @param Port The I/O port to read.
120 @return The value read.
134 Writes a 8-bit I/O port.
136 Writes the 8-bit I/O port specified by Port with the value specified by Value
137 and returns Value. This function must guarantee that all I/O read and write
138 operations are serialized.
140 @param Port The I/O port to write.
141 @param Value The value to write to the I/O port.
143 @return The value written the I/O port.
156 // Add the 64MB aligned IO Port space to the IO address
158 Address
= MAP_PORT_BASE_TO_MEM (Port
);
159 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
161 return MmioWrite8 (Address
, Data
);
165 Writes a 16-bit I/O port.
167 Writes the 16-bit I/O port specified by Port with the value specified by Value
168 and returns Value. This function must guarantee that all I/O read and write
169 operations are serialized.
171 @param Port The I/O port to write.
172 @param Value The value to write to the I/O port.
174 @return The value written the I/O port.
187 // Add the 64MB aligned IO Port space to the IO address
189 Address
= MAP_PORT_BASE_TO_MEM (Port
);
190 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
192 return MmioWrite16 (Address
, Data
);
196 Writes a 32-bit I/O port.
198 Writes the 32-bit I/O port specified by Port with the value specified by Value
199 and returns Value. This function must guarantee that all I/O read and write
200 operations are serialized.
202 @param Port The I/O port to write.
203 @param Value The value to write to the I/O port.
205 @return The value written the I/O port.
218 // Add the 64MB aligned IO Port space to the IO address
220 Address
= MAP_PORT_BASE_TO_MEM (Port
);
221 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
223 return MmioWrite32 (Address
, Data
);
227 Writes a 64-bit I/O port.
229 Writes the 64-bit I/O port specified by Port with the value specified by Value
230 and returns Value. This function must guarantee that all I/O read and write
231 operations are serialized.
233 If 64-bit I/O port operations are not supported, then ASSERT().
235 @param Port The I/O port to write.
236 @param Value The value to write to the I/O port.
238 @return The value written the I/O port.
253 Reads a 8-bit MMIO register.
255 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
256 returned. This function must guarantee that all MMIO read and write
257 operations are serialized.
259 @param Address The MMIO register to read.
261 @return The value read.
275 Data
= *((volatile UINT8
*) Address
);
282 Reads a 16-bit MMIO register.
284 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
285 returned. This function must guarantee that all MMIO read and write
286 operations are serialized.
288 @param Address The MMIO register to read.
290 @return The value read.
304 Data
= *((volatile UINT16
*) Address
);
311 Reads a 32-bit MMIO register.
313 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
314 returned. This function must guarantee that all MMIO read and write
315 operations are serialized.
317 @param Address The MMIO register to read.
319 @return The value read.
333 Data
= *((volatile UINT32
*) Address
);
340 Reads a 64-bit MMIO register.
342 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
343 returned. This function must guarantee that all MMIO read and write
344 operations are serialized.
346 @param Address The MMIO register to read.
348 @return The value read.
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.
421 *((volatile UINT16
*) Address
) = Data
;
428 Writes a 32-bit MMIO register.
430 Writes the 32-bit MMIO register specified by Address with the value specified
431 by Value and returns Value. This function must guarantee that all MMIO read
432 and write operations are serialized.
434 @param Address The MMIO register to write.
435 @param Data The value to write to the MMIO register.
437 @return The value written the memory address.
450 *((volatile UINT32
*) Address
) = Data
;
457 Writes a 64-bit MMIO register.
459 Writes the 64-bit MMIO register specified by Address with the value specified
460 by Value and returns Value. This function must guarantee that all MMIO read
461 and write operations are serialized.
463 @param Address The MMIO register to write.
464 @param Data The value to write to the MMIO register.
466 @return The value written the memory address.
479 *((volatile UINT64
*) Address
) = Data
;