]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/scugic_v3_2/src/xscugic.h
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / scugic_v3_2 / src / xscugic.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 2015 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 xscugic.h
36 * @addtogroup scugic_v3_1
37 * @{
38 * @details
39 *
40 * The generic interrupt controller driver component.
41 *
42 * The interrupt controller driver uses the idea of priority for the various
43 * handlers. Priority is an integer within the range of 1 and 31 inclusive with
44 * default of 1 being the highest priority interrupt source. The priorities
45 * of the various sources can be dynamically altered as needed through
46 * hardware configuration.
47 *
48 * The generic interrupt controller supports the following
49 * features:
50 *
51 *   - specific individual interrupt enabling/disabling
52 *   - specific individual interrupt acknowledging
53 *   - attaching specific callback function to handle interrupt source
54 *   - assigning desired priority to interrupt source if default is not
55 *     acceptable.
56 *
57 * Details about connecting the interrupt handler of the driver are contained
58 * in the source file specific to interrupt processing, xscugic_intr.c.
59 *
60 * This driver is intended to be RTOS and processor independent.  It works with
61 * physical addresses only.  Any needs for dynamic memory management, threads
62 * or thread mutual exclusion, virtual memory, or cache control must be
63 * satisfied by the layer above this driver.
64 *
65 * <b>Interrupt Vector Tables</b>
66 *
67 * The device ID of the interrupt controller device is used by the driver as a
68 * direct index into the configuration data table. The user should populate the
69 * vector table with handlers and callbacks at run-time using the
70 * XScuGic_Connect() and XScuGic_Disconnect() functions.
71 *
72 * Each vector table entry corresponds to a device that can generate an
73 * interrupt. Each entry contains an interrupt handler function and an
74 * argument to be passed to the handler when an interrupt occurs.  The
75 * user must use XScuGic_Connect() when the interrupt handler takes an
76 * argument other than the base address.
77 *
78 * <b>Nested Interrupts Processing</b>
79 *
80 * Nested interrupts are not supported by this driver.
81 *
82 * NOTE:
83 * The generic interrupt controller is not a part of the snoop control unit
84 * as indicated by the prefix "scu" in the name of the driver.
85 * It is an independent module in APU.
86 *
87 * <pre>
88 * MODIFICATION HISTORY:
89 *
90 * Ver   Who  Date     Changes
91 * ----- ---- -------- ---------------------------------------------------------
92 * 1.00a drg  01/19/00 First release
93 * 1.01a sdm  11/09/11 The XScuGic and XScuGic_Config structures have changed.
94 *                     The HandlerTable (of type XScuGic_VectorTableEntry) is
95 *                     moved to XScuGic_Config structure from XScuGic structure.
96 *
97 *                     The "Config" entry in XScuGic structure is made as
98 *                     pointer for better efficiency.
99 *
100 *                     A new file named as xscugic_hw.c is now added. It is
101 *                     to implement low level driver routines without using
102 *                     any xscugic instance pointer. They are useful when the
103 *                     user wants to use xscugic through device id or
104 *                     base address. The driver routines provided are explained
105 *                     below.
106 *                     XScuGic_DeviceInitialize that takes device id as
107 *                     argument and initializes the device (without calling
108 *                     XScuGic_CfgInitialize).
109 *                     XScuGic_DeviceInterruptHandler that takes device id
110 *                     as argument and calls appropriate handlers from the
111 *                     HandlerTable.
112 *                     XScuGic_RegisterHandler that registers a new handler
113 *                     by taking xscugic hardware base address as argument.
114 *                     LookupConfigByBaseAddress is used to return the
115 *                     corresponding config structure from XScuGic_ConfigTable
116 *                     based on the scugic base address passed.
117 * 1.02a sdm  12/20/11 Removed AckBeforeService from the XScuGic_Config
118 *                     structure.
119 * 1.03a srt  02/27/13 Moved Offset calculation macros from *.c and *_hw.c to
120 *                     *_hw.h
121 *                     Added APIs
122 *                       - XScuGic_SetPriTrigTypeByDistAddr()
123 *                       - XScuGic_GetPriTrigTypeByDistAddr()
124 *                     (CR 702687)
125 *                       Added support to direct interrupts to the appropriate CPU. Earlier
126 *                         interrupts were directed to CPU1 (hard coded). Now depending
127 *                         upon the CPU selected by the user (xparameters.h), interrupts
128 *                         will be directed to the relevant CPU. This fixes CR 699688.
129 * 1.04a hk   05/04/13 Assigned EffectiveAddr to CpuBaseAddress in
130 *                         XScuGic_CfgInitialize. Fix for CR#704400 to remove warnings.
131 *                         Moved functions XScuGic_SetPriTrigTypeByDistAddr and
132 *             XScuGic_GetPriTrigTypeByDistAddr to xscugic_hw.c.
133 *                         This is fix for CR#705621.
134 * 1.05a hk   06/26/13 Modified tcl to export external interrupts correctly to
135 *                     xparameters.h. Fix for CR's 690505, 708928 & 719359.
136 * 2.0   adk  12/10/13 Updated as per the New Tcl API's
137 * 2.1   adk  25/04/14 Fixed the CR:789373 changes are made in the driver tcl file.
138 * 3.00  kvn  02/13/15 Modified code for MISRA-C:2012 compliance.
139 * 3.2   asa  02/29/16 Modified DistributorInit function for Zynq AMP case. The
140 *                         distributor is left uninitialized for Zynq AMP. It is assumed
141 *             that the distributor will be initialized by Linux master. However
142 *             for CortexR5 case, the earlier code is left unchanged where the
143 *             the interrupt processor target registers in the distributor is
144 *             initialized with the corresponding CPU ID on which the application
145 *             built over the scugic driver runs.
146 *             These changes fix CR#937243.
147 *
148 * </pre>
149 *
150 ******************************************************************************/
151
152 #ifndef XSCUGIC_H /* prevent circular inclusions */
153 #define XSCUGIC_H /* by using protection macros */
154
155 #ifdef __cplusplus
156 extern "C" {
157 #endif
158
159
160 /***************************** Include Files *********************************/
161
162 #include "xstatus.h"
163 #include "xil_io.h"
164 #include "xscugic_hw.h"
165 #include "xil_exception.h"
166
167 /************************** Constant Definitions *****************************/
168
169
170 /**************************** Type Definitions *******************************/
171
172 /* The following data type defines each entry in an interrupt vector table.
173  * The callback reference is the base address of the interrupting device
174  * for the low level driver and an instance pointer for the high level driver.
175  */
176 typedef struct
177 {
178         Xil_InterruptHandler Handler;
179         void *CallBackRef;
180 } XScuGic_VectorTableEntry;
181
182 /**
183  * This typedef contains configuration information for the device.
184  */
185 typedef struct
186 {
187         u16 DeviceId;           /**< Unique ID  of device */
188         u32 CpuBaseAddress;     /**< CPU Interface Register base address */
189         u32 DistBaseAddress;    /**< Distributor Register base address */
190         XScuGic_VectorTableEntry HandlerTable[XSCUGIC_MAX_NUM_INTR_INPUTS];/**<
191                                  Vector table of interrupt handlers */
192 } XScuGic_Config;
193
194 /**
195  * The XScuGic driver instance data. The user is required to allocate a
196  * variable of this type for every intc device in the system. A pointer
197  * to a variable of this type is then passed to the driver API functions.
198  */
199 typedef struct
200 {
201         XScuGic_Config *Config;  /**< Configuration table entry */
202         u32 IsReady;             /**< Device is initialized and ready */
203         u32 UnhandledInterrupts; /**< Intc Statistics */
204 } XScuGic;
205
206 /***************** Macros (Inline Functions) Definitions *********************/
207
208 /****************************************************************************/
209 /**
210 *
211 * Write the given CPU Interface register
212 *
213 * @param    InstancePtr is a pointer to the instance to be worked on.
214 * @param    RegOffset is the register offset to be written
215 * @param    Data is the 32-bit value to write to the register
216 *
217 * @return   None.
218 *
219 * @note
220 * C-style signature:
221 *    void XScuGic_CPUWriteReg(XScuGic *InstancePtr, u32 RegOffset, u32 Data)
222 *
223 *****************************************************************************/
224 #define XScuGic_CPUWriteReg(InstancePtr, RegOffset, Data) \
225 (XScuGic_WriteReg(((InstancePtr)->Config->CpuBaseAddress), (RegOffset), \
226                                         ((u32)(Data))))
227
228 /****************************************************************************/
229 /**
230 *
231 * Read the given CPU Interface register
232 *
233 * @param    InstancePtr is a pointer to the instance to be worked on.
234 * @param    RegOffset is the register offset to be read
235 *
236 * @return   The 32-bit value of the register
237 *
238 * @note
239 * C-style signature:
240 *    u32 XScuGic_CPUReadReg(XScuGic *InstancePtr, u32 RegOffset)
241 *
242 *****************************************************************************/
243 #define XScuGic_CPUReadReg(InstancePtr, RegOffset) \
244         (XScuGic_ReadReg(((InstancePtr)->Config->CpuBaseAddress), (RegOffset)))
245
246 /****************************************************************************/
247 /**
248 *
249 * Write the given Distributor Interface register
250 *
251 * @param    InstancePtr is a pointer to the instance to be worked on.
252 * @param    RegOffset is the register offset to be written
253 * @param    Data is the 32-bit value to write to the register
254 *
255 * @return   None.
256 *
257 * @note
258 * C-style signature:
259 *    void XScuGic_DistWriteReg(XScuGic *InstancePtr, u32 RegOffset, u32 Data)
260 *
261 *****************************************************************************/
262 #define XScuGic_DistWriteReg(InstancePtr, RegOffset, Data) \
263 (XScuGic_WriteReg(((InstancePtr)->Config->DistBaseAddress), (RegOffset), \
264                                         ((u32)(Data))))
265
266 /****************************************************************************/
267 /**
268 *
269 * Read the given Distributor Interface register
270 *
271 * @param    InstancePtr is a pointer to the instance to be worked on.
272 * @param    RegOffset is the register offset to be read
273 *
274 * @return   The 32-bit value of the register
275 *
276 * @note
277 * C-style signature:
278 *    u32 XScuGic_DistReadReg(XScuGic *InstancePtr, u32 RegOffset)
279 *
280 *****************************************************************************/
281 #define XScuGic_DistReadReg(InstancePtr, RegOffset) \
282 (XScuGic_ReadReg(((InstancePtr)->Config->DistBaseAddress), (RegOffset)))
283
284 /************************** Function Prototypes ******************************/
285
286 /*
287  * Required functions in xscugic.c
288  */
289
290 s32  XScuGic_Connect(XScuGic *InstancePtr, u32 Int_Id,
291                         Xil_InterruptHandler Handler, void *CallBackRef);
292 void XScuGic_Disconnect(XScuGic *InstancePtr, u32 Int_Id);
293
294 void XScuGic_Enable(XScuGic *InstancePtr, u32 Int_Id);
295 void XScuGic_Disable(XScuGic *InstancePtr, u32 Int_Id);
296
297 s32  XScuGic_CfgInitialize(XScuGic *InstancePtr, XScuGic_Config *ConfigPtr,
298                                                         u32 EffectiveAddr);
299
300 s32  XScuGic_SoftwareIntr(XScuGic *InstancePtr, u32 Int_Id, u32 Cpu_Id);
301
302 void XScuGic_GetPriorityTriggerType(XScuGic *InstancePtr, u32 Int_Id,
303                                         u8 *Priority, u8 *Trigger);
304 void XScuGic_SetPriorityTriggerType(XScuGic *InstancePtr, u32 Int_Id,
305                                         u8 Priority, u8 Trigger);
306 void XScuGic_InterruptMaptoCpu(XScuGic *InstancePtr, u8 Cpu_Id, u32 Int_Id);
307 /*
308  * Initialization functions in xscugic_sinit.c
309  */
310 XScuGic_Config *XScuGic_LookupConfig(u16 DeviceId);
311
312 /*
313  * Interrupt functions in xscugic_intr.c
314  */
315 void XScuGic_InterruptHandler(XScuGic *InstancePtr);
316
317 /*
318  * Self-test functions in xscugic_selftest.c
319  */
320 s32  XScuGic_SelfTest(XScuGic *InstancePtr);
321
322 #ifdef __cplusplus
323 }
324 #endif
325
326 #endif            /* end of protection macro */
327 /** @} */