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 Reads a 8-bit I/O port.
26 Reads the 8-bit I/O port specified by Port. The 8-bit read value is returned.
27 This function must guarantee that all I/O read and write operations are
30 @param Port The I/O port to read.
32 @return The value read.
44 // Add the 64MB aligned IO Port space to the IO address
46 Address
= MAP_PORT_BASE_TO_MEM (Port
);
47 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
49 return MmioRead8 (Address
);
53 Reads a 16-bit I/O port.
55 Reads the 16-bit I/O port specified by Port. The 16-bit read value is returned.
56 This function must guarantee that all I/O read and write operations are
59 @param Port The I/O port to read.
61 @return The value read.
73 // Add the 64MB aligned IO Port space to the IO address
75 Address
= MAP_PORT_BASE_TO_MEM (Port
);
76 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
78 return MmioRead16 (Address
);
82 Reads a 32-bit I/O port.
84 Reads the 32-bit I/O port specified by Port. The 32-bit read value is returned.
85 This function must guarantee that all I/O read and write operations are
88 @param Port The I/O port to read.
90 @return The value read.
102 // Add the 64MB aligned IO Port space to the IO address
104 Address
= MAP_PORT_BASE_TO_MEM (Port
);
105 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
107 return MmioRead32 (Address
);
111 Reads a 64-bit I/O port.
113 Reads the 64-bit I/O port specified by Port. The 64-bit read value is returned.
114 This function must guarantee that all I/O read and write operations are
117 If 64-bit I/O port operations are not supported, then ASSERT().
119 @param Port The I/O port to read.
121 @return The value read.
135 Writes a 8-bit I/O port.
137 Writes the 8-bit I/O port specified by Port with the value specified by Value
138 and returns Value. This function must guarantee that all I/O read and write
139 operations are serialized.
141 @param Port The I/O port to write.
142 @param Value The value to write to the I/O port.
144 @return The value written the I/O port.
157 // Add the 64MB aligned IO Port space to the IO address
159 Address
= MAP_PORT_BASE_TO_MEM (Port
);
160 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
162 return MmioWrite8 (Address
, 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.
188 // Add the 64MB aligned IO Port space to the IO address
190 Address
= MAP_PORT_BASE_TO_MEM (Port
);
191 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
193 return MmioWrite16 (Address
, Data
);
197 Writes a 32-bit I/O port.
199 Writes the 32-bit I/O port specified by Port with the value specified by Value
200 and returns Value. This function must guarantee that all I/O read and write
201 operations are serialized.
203 @param Port The I/O port to write.
204 @param Value The value to write to the I/O port.
206 @return The value written the I/O port.
219 // Add the 64MB aligned IO Port space to the IO address
221 Address
= MAP_PORT_BASE_TO_MEM (Port
);
222 Address
+= PcdGet64(PcdIoBlockBaseAddressForIpf
);
224 return MmioWrite32 (Address
, Data
);
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().
236 @param Port The I/O port to write.
237 @param Value The value to write to the I/O port.
239 @return The value written the I/O port.
254 Reads a 8-bit MMIO register.
256 Reads the 8-bit MMIO register specified by Address. The 8-bit read value is
257 returned. This function must guarantee that all MMIO read and write
258 operations are serialized.
260 @param Address The MMIO register to read.
262 @return The value read.
276 Data
= *((volatile UINT8
*) Address
);
283 Reads a 16-bit MMIO register.
285 Reads the 16-bit MMIO register specified by Address. The 16-bit read value is
286 returned. This function must guarantee that all MMIO read and write
287 operations are serialized.
289 @param Address The MMIO register to read.
291 @return The value read.
305 Data
= *((volatile UINT16
*) Address
);
312 Reads a 32-bit MMIO register.
314 Reads the 32-bit MMIO register specified by Address. The 32-bit read value is
315 returned. This function must guarantee that all MMIO read and write
316 operations are serialized.
318 @param Address The MMIO register to read.
320 @return The value read.
334 Data
= *((volatile UINT32
*) Address
);
341 Reads a 64-bit MMIO register.
343 Reads the 64-bit MMIO register specified by Address. The 64-bit read value is
344 returned. This function must guarantee that all MMIO read and write
345 operations are serialized.
347 @param Address The MMIO register to read.
349 @return The value read.
363 Data
= *((volatile UINT64
*) Address
);
371 Writes a 8-bit MMIO register.
373 Writes the 8-bit MMIO register specified by Address with the value specified
374 by Value and returns Value. This function must guarantee that all MMIO read
375 and write operations are serialized.
377 @param Address The MMIO register to write.
378 @param Data The value to write to the MMIO register.
380 @return The value written the memory address.
393 *((volatile UINT8
*) Address
) = Data
;
400 Writes a 16-bit MMIO register.
402 Writes the 16-bit MMIO register specified by Address with the value specified
403 by Value and returns Value. This function must guarantee that all MMIO read
404 and write operations are serialized.
406 @param Address The MMIO register to write.
407 @param Data The value to write to the MMIO register.
409 @return The value written the memory address.
422 *((volatile UINT16
*) Address
) = Data
;
429 Writes a 32-bit MMIO register.
431 Writes the 32-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 @param Address The MMIO register to write.
436 @param Data The value to write to the MMIO register.
438 @return The value written the memory address.
451 *((volatile UINT32
*) Address
) = Data
;
458 Writes a 64-bit MMIO register.
460 Writes the 64-bit MMIO register specified by Address with the value specified
461 by Value and returns Value. This function must guarantee that all MMIO read
462 and write operations are serialized.
464 @param Address The MMIO register to write.
465 @param Data The value to write to the MMIO register.
467 @return The value written the memory address.
480 *((volatile UINT64
*) Address
) = Data
;