]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/include/xdevcfg.h
FreeRTOS source updates:
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / include / xdevcfg.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xdevcfg.h
36 * @addtogroup devcfg_v3_1
37 * @{
38 * @details
39 *
40 * The is the main header file for the Device Configuration Interface of the Zynq
41 * device. The device configuration interface has three main functionality.
42 *  1. AXI-PCAP
43 *  2. Security Policy
44 *  3. XADC
45 * This current version of the driver supports only the AXI-PCAP and Security
46 * Policy blocks. There is a separate driver for XADC.
47 *
48 * AXI-PCAP is used for download/upload an encrypted or decrypted bitstream.
49 * DMA embedded in the AXI PCAP provides the master interface to
50 * the Device configuration block for any DMA transfers. The data transfer can
51 * take place between the Tx/RxFIFOs of AXI-PCAP and memory (on chip
52 * RAM/DDR/peripheral memory).
53 *
54 * The current driver only supports the downloading the FPGA bitstream and
55 * readback of the decrypted image (sort of loopback).
56 * The driver does not know what information needs to be written to the FPGA to
57 * readback FPGA configuration register or memory data. The application above the
58 * driver should take care of creating the data that needs to be downloaded to
59 * the FPGA so that the bitstream can be readback.
60 * This driver also does not support the reading of the internal registers of the
61 * PCAP. The driver has no knowledge of the PCAP internals.
62 *
63 * <b> Initialization and Configuration </b>
64 *
65 * The device driver enables higher layer software (e.g., an application) to
66 * communicate with the Device Configuration device.
67 *
68 * XDcfg_CfgInitialize() API is used to initialize the Device Configuration
69 * Interface. The user needs to first call the XDcfg_LookupConfig() API which
70 * returns the Configuration structure pointer which is passed as a parameter to
71 * the XDcfg_CfgInitialize() API.
72 *
73 * <b>Interrupts</b>
74 * The Driver implements an interrupt handler to support the interrupts provided
75 * by this interface.
76 *
77 * <b> Threads </b>
78 *
79 * This driver is not thread safe. Any needs for threads or thread mutual
80 * exclusion must be satisfied by the layer above this driver.
81 *
82 * <b> Asserts </b>
83 *
84 * Asserts are used within all Xilinx drivers to enforce constraints on argument
85 * values. Asserts can be turned off on a system-wide basis by defining, at
86 * compile time, the NDEBUG identifier. By default, asserts are turned on and it
87 * is recommended that users leave asserts on during development.
88 *
89 * <b> Building the driver </b>
90 *
91 * The XDcfg driver is composed of several source files. This allows the user
92 * to build and link only those parts of the driver that are necessary.
93 *
94 * <br><br>
95 *
96 * <pre>
97 * MODIFICATION HISTORY:
98 *
99 * Ver   Who Date     Changes
100 * ----- --- -------- ---------------------------------------------
101 * 1.00a hvm 02/07/11 First release
102 * 2.00a nm  05/31/12 Updated the driver for CR 660835 so that input length for
103 *                    source/destination to the XDcfg_InitiateDma, XDcfg_Transfer
104 *                    APIs is words (32 bit) and not bytes.
105 *                    Updated the notes for XDcfg_InitiateDma/XDcfg_Transfer APIs
106 *                    to add information that 2 LSBs of the Source/Destination
107 *                    address when equal to 2\92b01 indicate the last DMA command
108 *                    of an overall transfer.
109 *                    Destination Address passed to this API for secure transfers
110 *                    instead of using 0xFFFFFFFF for CR 662197. This issue was
111 *                    resulting in the failure of secure transfers of
112 *                    non-bitstream images.
113 * 2.01a nm  07/07/12 Updated the XDcfg_IntrClear function to directly
114 *                    set the mask instead of oring it with the
115 *                    value read from the interrupt status register
116 *                    Added defines for the PS Version bits,
117 *                    removed the FIFO Flush bits from the
118 *                    Miscellaneous Control Reg.
119 *                    Added XDcfg_GetPsVersion, XDcfg_SelectIcapInterface
120 *                    and XDcfg_SelectPcapInterface APIs for CR 643295
121 *                    The user has to call the XDcfg_SelectIcapInterface API
122 *                    for the PL reconfiguration using AXI HwIcap.
123 *                    Updated the XDcfg_Transfer API to clear the
124 *                    QUARTER_PCAP_RATE_EN bit in the control register for
125 *                    non secure writes for CR 675543.
126 * 2.02a nm  01/31/13 Fixed CR# 679335.
127 *                    Added Setting and Clearing the internal PCAP loopback.
128 *                    Removed code for enabling/disabling AES engine as BootROM
129 *                    locks down this setting.
130 *                    Fixed CR# 681976.
131 *                    Skip Checking the PCFG_INIT in case of non-secure DMA
132 *                    loopback.
133 *                    Fixed CR# 699558.
134 *                    XDcfg_Transfer fails to transfer data in loopback mode.
135 *                    Fixed CR# 701348.
136 *                    Peripheral test fails with  Running
137 *                    DcfgSelfTestExample() in SECURE bootmode.
138 * 2.03a nm  04/19/13 Fixed CR# 703728.
139 *                    Updated the register definitions as per the latest TRM
140 *                    version UG585 (v1.4) November 16, 2012.
141 * 3.0   adk 10/12/13 Updated as per the New Tcl API's
142 * 3.0   kpc 21/02/14 Added function prototype for XDcfg_ClearControlRegister
143 * </pre>
144 *
145 ******************************************************************************/
146 #ifndef XDCFG_H         /* prevent circular inclusions */
147 #define XDCFG_H         /* by using protection macros */
148
149 /***************************** Include Files *********************************/
150
151 #include "xdevcfg_hw.h"
152 #include "xstatus.h"
153 #include "xil_assert.h"
154
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158
159 /************************** Constant Definitions *****************************/
160
161 /* Types of PCAP transfers */
162
163 #define XDCFG_NON_SECURE_PCAP_WRITE             1
164 #define XDCFG_SECURE_PCAP_WRITE                 2
165 #define XDCFG_PCAP_READBACK                     3
166 #define XDCFG_CONCURRENT_SECURE_READ_WRITE      4
167 #define XDCFG_CONCURRENT_NONSEC_READ_WRITE      5
168
169
170 /**************************** Type Definitions *******************************/
171 /**
172 * The handler data type allows the user to define a callback function to
173 * respond to interrupt events in the system. This function is executed
174 * in interrupt context, so amount of processing should be minimized.
175 *
176 * @param        CallBackRef is the callback reference passed in by the upper
177 *               layer when setting the callback functions, and passed back to
178 *               the upper layer when the callback is invoked. Its type is
179 *               unimportant to the driver component, so it is a void pointer.
180 * @param        Status is the Interrupt status of the XDcfg device.
181 */
182 typedef void (*XDcfg_IntrHandler) (void *CallBackRef, u32 Status);
183
184 /**
185  * This typedef contains configuration information for the device.
186  */
187 typedef struct {
188         u16 DeviceId;           /**< Unique ID of device */
189         u32 BaseAddr;           /**< Base address of the device */
190 } XDcfg_Config;
191
192 /**
193  * The XDcfg driver instance data.
194  */
195 typedef struct {
196         XDcfg_Config Config;    /**< Hardware Configuration */
197         u32 IsReady;            /**< Device is initialized and ready */
198         u32 IsStarted;          /**< Device Configuration Interface
199                                   * is running
200                                   */
201         XDcfg_IntrHandler StatusHandler;  /* Event handler function */
202         void *CallBackRef;      /* Callback reference for event handler */
203 } XDcfg;
204
205 /****************************************************************************/
206 /**
207 *
208 * Unlock the Device Config Interface block.
209 *
210 * @param        InstancePtr is a pointer to the instance of XDcfg driver.
211 *
212 * @return       None.
213 *
214 * @note         C-style signature:
215 *               void XDcfg_Unlock(XDcfg* InstancePtr)
216 *
217 *****************************************************************************/
218 #define XDcfg_Unlock(InstancePtr)                                       \
219         XDcfg_WriteReg((InstancePtr)->Config.BaseAddr,                  \
220         XDCFG_UNLOCK_OFFSET, XDCFG_UNLOCK_DATA)
221
222
223
224 /****************************************************************************/
225 /**
226 *
227 * Get the version number of the PS from the Miscellaneous Control Register.
228 *
229 * @param        InstancePtr is a pointer to the instance of XDcfg driver.
230 *
231 * @return       Version of the PS.
232 *
233 * @note         C-style signature:
234 *               void XDcfg_GetPsVersion(XDcfg* InstancePtr)
235 *
236 *****************************************************************************/
237 #define XDcfg_GetPsVersion(InstancePtr)                                 \
238         ((XDcfg_ReadReg((InstancePtr)->Config.BaseAddr,                 \
239                         XDCFG_MCTRL_OFFSET)) &                          \
240                         XDCFG_MCTRL_PCAP_PS_VERSION_MASK) >>            \
241                         XDCFG_MCTRL_PCAP_PS_VERSION_SHIFT
242
243
244
245 /****************************************************************************/
246 /**
247 *
248 * Read the multiboot config register value.
249 *
250 * @param        InstancePtr is a pointer to the instance of XDcfg driver.
251 *
252 * @return       None.
253 *
254 * @note         C-style signature:
255 *               u32 XDcfg_ReadMultiBootConfig(XDcfg* InstancePtr)
256 *
257 *****************************************************************************/
258 #define XDcfg_ReadMultiBootConfig(InstancePtr)                  \
259         XDcfg_ReadReg((InstancePtr)->Config.BaseAddr +          \
260                         XDCFG_MULTIBOOT_ADDR_OFFSET)
261
262
263 /****************************************************************************/
264 /**
265 *
266 * Selects ICAP interface for reconfiguration after the initial configuration
267 * of the PL.
268 *
269 * @param        InstancePtr is a pointer to the instance of XDcfg driver.
270 *
271 * @return       None.
272 *
273 * @note         C-style signature:
274 *               void XDcfg_SelectIcapInterface(XDcfg* InstancePtr)
275 *
276 *****************************************************************************/
277 #define XDcfg_SelectIcapInterface(InstancePtr)                            \
278         XDcfg_WriteReg((InstancePtr)->Config.BaseAddr, XDCFG_CTRL_OFFSET,   \
279         ((XDcfg_ReadReg((InstancePtr)->Config.BaseAddr, XDCFG_CTRL_OFFSET)) \
280         & ( ~XDCFG_CTRL_PCAP_PR_MASK)))
281
282 /****************************************************************************/
283 /**
284 *
285 * Selects PCAP interface for reconfiguration after the initial configuration
286 * of the PL.
287 *
288 * @param        InstancePtr is a pointer to the instance of XDcfg driver.
289 *
290 * @return       None.
291 *
292 * @note         C-style signature:
293 *               void XDcfg_SelectPcapInterface(XDcfg* InstancePtr)
294 *
295 *****************************************************************************/
296 #define XDcfg_SelectPcapInterface(InstancePtr)                             \
297         XDcfg_WriteReg((InstancePtr)->Config.BaseAddr, XDCFG_CTRL_OFFSET,    \
298         ((XDcfg_ReadReg((InstancePtr)->Config.BaseAddr, XDCFG_CTRL_OFFSET))  \
299         | XDCFG_CTRL_PCAP_PR_MASK))
300
301
302
303 /************************** Function Prototypes ******************************/
304
305 /*
306  * Lookup configuration in xdevcfg_sinit.c.
307  */
308 XDcfg_Config *XDcfg_LookupConfig(u16 DeviceId);
309
310 /*
311  * Selftest function in xdevcfg_selftest.c
312  */
313 int XDcfg_SelfTest(XDcfg *InstancePtr);
314
315 /*
316  * Interface functions in xdevcfg.c
317  */
318 int XDcfg_CfgInitialize(XDcfg *InstancePtr,
319                          XDcfg_Config *ConfigPtr, u32 EffectiveAddress);
320
321 void XDcfg_EnablePCAP(XDcfg *InstancePtr);
322
323 void XDcfg_DisablePCAP(XDcfg *InstancePtr);
324
325 void XDcfg_SetControlRegister(XDcfg *InstancePtr, u32 Mask);
326
327 void XDcfg_ClearControlRegister(XDcfg *InstancePtr, u32 Mask);
328
329 u32 XDcfg_GetControlRegister(XDcfg *InstancePtr);
330
331 void XDcfg_SetLockRegister(XDcfg *InstancePtr, u32 Data);
332
333 u32 XDcfg_GetLockRegister(XDcfg *InstancePtr);
334
335 void XDcfg_SetConfigRegister(XDcfg *InstancePtr, u32 Data);
336
337 u32 XDcfg_GetConfigRegister(XDcfg *InstancePtr);
338
339 void XDcfg_SetStatusRegister(XDcfg *InstancePtr, u32 Data);
340
341 u32 XDcfg_GetStatusRegister(XDcfg *InstancePtr);
342
343 void XDcfg_SetRomShadowRegister(XDcfg *InstancePtr, u32 Data);
344
345 u32 XDcfg_GetSoftwareIdRegister(XDcfg *InstancePtr);
346
347 void XDcfg_SetMiscControlRegister(XDcfg *InstancePtr, u32 Mask);
348
349 u32 XDcfg_GetMiscControlRegister(XDcfg *InstancePtr);
350
351 u32 XDcfg_IsDmaBusy(XDcfg *InstancePtr);
352
353 void XDcfg_InitiateDma(XDcfg *InstancePtr, u32 SourcePtr, u32 DestPtr,
354                                 u32 SrcWordLength, u32 DestWordLength);
355
356 u32 XDcfg_Transfer(XDcfg *InstancePtr,
357                                 void *SourcePtr, u32 SrcWordLength,
358                                 void *DestPtr, u32 DestWordLength,
359                                 u32 TransferType);
360
361 /*
362  * Interrupt related function prototypes implemented in xdevcfg_intr.c
363  */
364 void XDcfg_IntrEnable(XDcfg *InstancePtr, u32 Mask);
365
366 void XDcfg_IntrDisable(XDcfg *InstancePtr, u32 Mask);
367
368 u32 XDcfg_IntrGetEnabled(XDcfg *InstancePtr);
369
370 u32 XDcfg_IntrGetStatus(XDcfg *InstancePtr);
371
372 void XDcfg_IntrClear(XDcfg *InstancePtr, u32 Mask);
373
374 void XDcfg_InterruptHandler(XDcfg *InstancePtr);
375
376 void XDcfg_SetHandler(XDcfg *InstancePtr, void *CallBackFunc,
377                                 void *CallBackRef);
378
379 #ifdef __cplusplus
380 }
381 #endif
382
383 #endif  /* end of protection macro */
384 /** @} */