1 /******************************************************************************
3 * Copyright (C) 2014 - 2016 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.
43 * MODIFICATION HISTORY:
45 * Ver Who Date Changes
46 * ----- -------- -------- -----------------------------------------------
47 * 5.00 pkp 05/29/14 First release
48 * 6.00 mus 08/19/16 Remove checking of __LITTLE_ENDIAN__ flag for
51 ******************************************************************************/
53 #ifndef XIL_IO_H /* prevent circular inclusions */
54 #define XIL_IO_H /* by using protection macros */
60 /***************************** Include Files *********************************/
62 #include "xil_types.h"
63 #include "xil_printf.h"
65 #if defined (__MICROBLAZE__)
66 #include "mb_interface.h"
68 #include "xpseudo_asm.h"
71 /************************** Function Prototypes ******************************/
72 u16 Xil_EndianSwap16(u16 Data);
73 u32 Xil_EndianSwap32(u32 Data);
75 /***************** Macros (Inline Functions) Definitions *********************/
77 #if defined (__MICROBLAZE__)
78 # define INST_SYNC mbar(0)
79 # define DATA_SYNC mbar(1)
81 # define SYNCHRONIZE_IO dmb()
82 # define INST_SYNC isb()
83 # define DATA_SYNC dsb()
86 # define SYNCHRONIZE_IO
93 #if defined (__GNUC__) || defined (__ICCARM__) || defined (__MICROBLAZE__)
96 #define INLINE __inline
99 /*****************************************************************************/
102 * Performs an input operation for an 8-bit memory location by reading from the
103 * specified address and returning the Value read from that address.
105 * @param Addr contains the address to perform the input operation
108 * @return The Value read from the specified input address.
112 ******************************************************************************/
113 static INLINE u8 Xil_In8(UINTPTR Addr)
115 return *(volatile u8 *) Addr;
118 /*****************************************************************************/
121 * Performs an input operation for a 16-bit memory location by reading from the
122 * specified address and returning the Value read from that address.
124 * @param Addr contains the address to perform the input operation
127 * @return The Value read from the specified input address.
131 ******************************************************************************/
132 static INLINE u16 Xil_In16(UINTPTR Addr)
134 return *(volatile u16 *) Addr;
137 /*****************************************************************************/
140 * Performs an input operation for a 32-bit memory location by reading from the
141 * specified address and returning the Value read from that address.
143 * @param Addr contains the address to perform the input operation
146 * @return The Value read from the specified input address.
150 ******************************************************************************/
151 static INLINE u32 Xil_In32(UINTPTR Addr)
153 return *(volatile u32 *) Addr;
156 /*****************************************************************************/
159 * Performs an input operation for a 64-bit memory location by reading the
160 * specified Value to the the specified address.
162 * @param OutAddress contains the address to perform the output operation
164 * @param Value contains the Value to be output at the specified address.
170 ******************************************************************************/
171 static INLINE u64 Xil_In64(UINTPTR Addr)
173 return *(volatile u64 *) Addr;
176 /*****************************************************************************/
179 * Performs an output operation for an 8-bit memory location by writing the
180 * specified Value to the the specified address.
182 * @param Addr contains the address to perform the output operation
184 * @param Value contains the Value to be output at the specified address.
190 ******************************************************************************/
191 static INLINE void Xil_Out8(UINTPTR Addr, u8 Value)
193 volatile u8 *LocalAddr = (volatile u8 *)Addr;
197 /*****************************************************************************/
200 * Performs an output operation for a 16-bit memory location by writing the
201 * specified Value to the the specified address.
203 * @param Addr contains the address to perform the output operation
205 * @param Value contains the Value to be output at the specified address.
211 ******************************************************************************/
212 static INLINE void Xil_Out16(UINTPTR Addr, u16 Value)
214 volatile u16 *LocalAddr = (volatile u16 *)Addr;
218 /*****************************************************************************/
221 * Performs an output operation for a 32-bit memory location by writing the
222 * specified Value to the the specified address.
224 * @param Addr contains the address to perform the output operation
226 * @param Value contains the Value to be output at the specified address.
232 ******************************************************************************/
233 static INLINE void Xil_Out32(UINTPTR Addr, u32 Value)
235 volatile u32 *LocalAddr = (volatile u32 *)Addr;
239 /*****************************************************************************/
242 * Performs an output operation for a 64-bit memory location by writing the
243 * specified Value to the the specified address.
245 * @param Addr contains the address to perform the output operation
247 * @param Value contains the Value to be output at the specified address.
253 ******************************************************************************/
254 static INLINE void Xil_Out64(UINTPTR Addr, u64 Value)
256 volatile u64 *LocalAddr = (volatile u64 *)Addr;
260 #if defined (__MICROBLAZE__)
261 #ifdef __LITTLE_ENDIAN__
262 # define Xil_In16LE Xil_In16
263 # define Xil_In32LE Xil_In32
264 # define Xil_Out16LE Xil_Out16
265 # define Xil_Out32LE Xil_Out32
266 # define Xil_Htons Xil_EndianSwap16
267 # define Xil_Htonl Xil_EndianSwap32
268 # define Xil_Ntohs Xil_EndianSwap16
269 # define Xil_Ntohl Xil_EndianSwap32
271 # define Xil_In16BE Xil_In16
272 # define Xil_In32BE Xil_In32
273 # define Xil_Out16BE Xil_Out16
274 # define Xil_Out32BE Xil_Out32
275 # define Xil_Htons(Data) (Data)
276 # define Xil_Htonl(Data) (Data)
277 # define Xil_Ntohs(Data) (Data)
278 # define Xil_Ntohl(Data) (Data)
281 # define Xil_In16LE Xil_In16
282 # define Xil_In32LE Xil_In32
283 # define Xil_Out16LE Xil_Out16
284 # define Xil_Out32LE Xil_Out32
285 # define Xil_Htons Xil_EndianSwap16
286 # define Xil_Htonl Xil_EndianSwap32
287 # define Xil_Ntohs Xil_EndianSwap16
288 # define Xil_Ntohl Xil_EndianSwap32
291 #if defined (__MICROBLAZE__)
292 #ifdef __LITTLE_ENDIAN__
293 static INLINE u16 Xil_In16BE(UINTPTR Addr)
295 static INLINE u16 Xil_In16LE(UINTPTR Addr)
298 static INLINE u16 Xil_In16BE(UINTPTR Addr)
301 u16 value = Xil_In16(Addr);
302 return Xil_EndianSwap16(value);
305 #if defined (__MICROBLAZE__)
306 #ifdef __LITTLE_ENDIAN__
307 static INLINE u32 Xil_In32BE(UINTPTR Addr)
309 static INLINE u32 Xil_In32LE(UINTPTR Addr)
312 static INLINE u32 Xil_In32BE(UINTPTR Addr)
315 u16 value = Xil_In32(Addr);
316 return Xil_EndianSwap32(value);
319 #if defined (__MICROBLAZE__)
320 #ifdef __LITTLE_ENDIAN__
321 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
323 static INLINE void Xil_Out16LE(UINTPTR Addr, u16 Value)
326 static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
329 Value = Xil_EndianSwap16(Value);
330 Xil_Out16(Addr, Value);
333 #if defined (__MICROBLAZE__)
334 #ifdef __LITTLE_ENDIAN__
335 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
337 static INLINE void Xil_Out32LE(UINTPTR Addr, u32 Value)
340 static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
343 Value = Xil_EndianSwap32(Value);
344 Xil_Out32(Addr, Value);
351 #endif /* end of protection macro */