1 /******************************************************************************
3 * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This file contains the interface for the general IO component, which
38 * encapsulates the Input/Output functions for processors that do not
39 * require any special I/O handling.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -------------------------------------------------------
46 * 3.00a hbm 07/28/09 Initial release
47 * 3.00a hbm 07/21/10 Added Xil_EndianSwap32/16, Xil_Htonl/s, Xil_Ntohl/s
48 * 3.03a sdm 08/18/11 Added INST_SYNC and DATA_SYNC macros.
49 * 3.07a asa 08/31/12 Added xil_printf.h include
50 * 5.4 sk 01/14/16 Changed xil_io() and xil_out() functions to static inline
57 * This file may contain architecture-dependent items.
59 ******************************************************************************/
61 #ifndef XIL_IO_H /* prevent circular inclusions */
62 #define XIL_IO_H /* by using protection macros */
68 /***************************** Include Files *********************************/
70 #include "xil_types.h"
71 #include "mb_interface.h"
72 #include "xil_printf.h"
74 /************************** Constant Definitions *****************************/
76 /**************************** Function Prototypes ****************************/
78 static inline u8 Xil_In8(UINTPTR Addr);
79 static inline u16 Xil_In16(UINTPTR Addr);
80 static inline u32 Xil_In32(UINTPTR Addr);
82 static inline void Xil_Out8(UINTPTR Addr, u8 Value);
83 static inline void Xil_Out16(UINTPTR Addr, u16 Value);
84 static inline void Xil_Out32(UINTPTR Addr, u32 Value);
86 /***************** Macros (Inline Functions) Definitions *********************/
88 /*****************************************************************************/
91 * Perform an input operation for an 8-bit memory location by reading from the
92 * specified address and returning the value read from that address.
94 * @param Addr contains the address to perform the input operation at.
96 * @return The value read from the specified input address.
100 ******************************************************************************/
101 static inline u8 Xil_In8(UINTPTR Addr) {
102 return *(volatile u8 *)Addr;
105 /*****************************************************************************/
108 * Perform an input operation for a 16-bit memory location by reading from the
109 * specified address and returning the value read from that address.
111 * @param Addr contains the address to perform the input operation at.
113 * @return The value read from the specified input address.
117 ******************************************************************************/
118 static inline u16 Xil_In16(UINTPTR Addr) {
119 return *(volatile u16 *)Addr;
122 /*****************************************************************************/
125 * Performs an input operation for a 32-bit memory location by reading from the
126 * specified address and returning the Value read from that address.
128 * @param Addr contains the address to perform the input operation at.
130 * @return The value read from the specified input address.
134 ******************************************************************************/
135 static inline u32 Xil_In32(UINTPTR Addr) {
136 return *(volatile u32 *)Addr;
140 /*****************************************************************************/
143 * Perform an output operation for an 8-bit memory location by writing the
144 * specified value to the specified address.
146 * @param Addr contains the address to perform the output operation at.
147 * @param value contains the value to be output at the specified address.
153 ******************************************************************************/
154 static inline void Xil_Out8(UINTPTR Addr, u8 Value) {
155 volatile u8 *LocalAddr = (u8 *)Addr;
159 /*****************************************************************************/
162 * Perform an output operation for a 16-bit memory location by writing the
163 * specified value to the specified address.
165 * @param Addr contains the address to perform the output operation at.
166 * @param value contains the value to be output at the specified address.
172 ******************************************************************************/
173 static inline void Xil_Out16(UINTPTR Addr, u16 Value) {
174 volatile u16 *LocalAddr = (u16 *)Addr;
178 /*****************************************************************************/
181 * Perform an output operation for a 32-bit memory location by writing the
182 * specified value to the specified address.
184 * @param addr contains the address to perform the output operation at.
185 * @param value contains the value to be output at the specified address.
191 ******************************************************************************/
192 static inline void Xil_Out32(UINTPTR Addr, u32 Value) {
193 volatile u32 *LocalAddr = (u32 *)Addr;
198 # define INST_SYNC mbar(0)
199 # define DATA_SYNC mbar(1)
203 #endif /* __GNUC__ */
206 * The following macros allow optimized I/O operations for memory mapped I/O.
207 * It should be noted that macros cannot be used if synchronization of the I/O
208 * operation is needed as it will likely break some code.
213 extern u16 Xil_EndianSwap16(u16 Data);
214 extern u32 Xil_EndianSwap32(u32 Data);
216 #ifndef __LITTLE_ENDIAN__
217 extern u16 Xil_In16LE(UINTPTR Addr);
218 extern u32 Xil_In32LE(UINTPTR Addr);
219 extern void Xil_Out16LE(UINTPTR Addr, u16 Value);
220 extern void Xil_Out32LE(UINTPTR Addr, u32 Value);
224 * Perform an big-endian input operation for a 16-bit memory location
225 * by reading from the specified address and returning the value read from
228 * @param addr contains the address to perform the input operation at.
230 * @return The value read from the specified input address with the
231 * proper endianness. The return value has the same endianness
232 * as that of the processor, i.e. if the processor is
233 * little-engian, the return value is the byte-swapped value read
238 ******************************************************************************/
239 #define Xil_In16BE(Addr) Xil_In16((Addr))
243 * Perform a big-endian input operation for a 32-bit memory location
244 * by reading from the specified address and returning the value read from
247 * @param Addr contains the address to perform the input operation at.
249 * @return The value read from the specified input address with the
250 * proper endianness. The return value has the same endianness
251 * as that of the processor, i.e. if the processor is
252 * little-engian, the return value is the byte-swapped value read
258 ******************************************************************************/
259 #define Xil_In32BE(Addr) Xil_In32((Addr))
261 /*****************************************************************************/
264 * Perform a big-endian output operation for a 16-bit memory location
265 * by writing the specified value to the specified address.
267 * @param Addr contains the address to perform the output operation at.
268 * @param Value contains the value to be output at the specified address.
269 * The value has the same endianness as that of the processor.
270 * If the processor is little-endian, the byte-swapped value is
271 * written to the address.
278 ******************************************************************************/
279 #define Xil_Out16BE(Addr, Value) Xil_Out16((Addr), (Value))
281 /*****************************************************************************/
284 * Perform a big-endian output operation for a 32-bit memory location
285 * by writing the specified value to the specified address.
287 * @param Addr contains the address to perform the output operation at.
288 * @param Value contains the value to be output at the specified address.
289 * The value has the same endianness as that of the processor.
290 * If the processor is little-endian, the byte-swapped value is
291 * written to the address.
297 ******************************************************************************/
298 #define Xil_Out32BE(Addr, Value) Xil_Out32((Addr), (Value))
300 #define Xil_Htonl(Data) (Data)
301 #define Xil_Htons(Data) (Data)
302 #define Xil_Ntohl(Data) (Data)
303 #define Xil_Ntohs(Data) (Data)
307 extern u16 Xil_In16BE(UINTPTR Addr);
308 extern u32 Xil_In32BE(UINTPTR Addr);
309 extern void Xil_Out16BE(UINTPTR Addr, u16 Value);
310 extern void Xil_Out32BE(UINTPTR Addr, u32 Value);
312 #define Xil_In16LE(Addr) Xil_In16((Addr))
313 #define Xil_In32LE(Addr) Xil_In32((Addr))
314 #define Xil_Out16LE(Addr, Value) Xil_Out16((Addr), (Value))
315 #define Xil_Out32LE(Addr, Value) Xil_Out32((Addr), (Value))
318 /*****************************************************************************/
321 * Convert a 32-bit number from host byte order to network byte order.
323 * @param Data the 32-bit number to be converted.
325 * @return The converted 32-bit number in network byte order.
329 ******************************************************************************/
330 #define Xil_Htonl(Data) Xil_EndianSwap32((Data))
332 /*****************************************************************************/
335 * Convert a 16-bit number from host byte order to network byte order.
337 * @param Data the 16-bit number to be converted.
339 * @return The converted 16-bit number in network byte order.
343 ******************************************************************************/
344 #define Xil_Htons(Data) Xil_EndianSwap16((Data))
346 /*****************************************************************************/
349 * Convert a 32-bit number from network byte order to host byte order.
351 * @param Value the 32-bit number to be converted.
353 * @return The converted 32-bit number in host byte order.
357 ******************************************************************************/
358 #define Xil_Ntohl(Data) Xil_EndianSwap32((Data))
360 /*****************************************************************************/
363 * Convert a 16-bit number from network byte order to host byte order.
365 * @param Value the 16-bit number to be converted.
367 * @return The converted 16-bit number in host byte order.
371 ******************************************************************************/
372 #define Xil_Ntohs(Data) Xil_EndianSwap16((Data))
380 #endif /* end of protection macro */