1 /******************************************************************************
3 * Copyright (C) 2015 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 /*****************************************************************************/
36 * This is the header file for implementation of IPIPSU driver.
37 * Inter Processor Interrupt (IPI) is used for communication between
38 * different processors on ZynqMP SoC. Each IPI register set has Trigger, Status
39 * and Observation registers for communication between processors. Each IPI path
40 * has a 32 byte buffer associated with it and these buffers are located in the
41 * XPPU RAM. This driver supports the following operations:
43 * - Trigger IPIs to CPUs on the SoC
44 * - Write and Read Message buffers
45 * - Read the status of Observation Register to get status of Triggered IPI
46 * - Enable/Disable IPIs from selected Masters
47 * - Read the Status register to get the source of an incoming IPI
49 * <b>Initialization</b>
50 * The config data for the driver is loaded and is based on the HW build. The
51 * XIpiPsu_Config data structure contains all the data related to the
52 * IPI driver instance and also teh available Target CPUs.
54 * <b>Sending an IPI</b>
55 * The following steps can be followed to send an IPI:
56 * - Write the Message into Message Buffer using XIpiPsu_WriteMessage()
57 * - Trigger IPI using XIpiPsu_TriggerIpi()
58 * - Wait for Ack using XIpiPsu_PollForAck()
59 * - Read response using XIpiPsu_ReadMessage()
61 * @note XIpiPsu_GetObsStatus() before sending an IPI to ensure that the
62 * previous IPI was serviced by the target
64 * <b>Receiving an IPI</b>
65 * To receive an IPI, the following sequence can be followed:
66 * - Register an interrupt handler for the IPIs interrupt ID
67 * - Enable the required sources using XIpiPsu_InterruptEnable()
68 * - In the interrupt handler, Check for source using XIpiPsu_GetInterruptStatus
69 * - Read the message form source using XIpiPsu_ReadMessage()
70 * - Write the response using XIpiPsu_WriteMessage()
71 * - Ack the IPI using XIpiPsu_ClearInterruptStatus()
73 * @note XIpiPsu_Reset can be used at startup to clear the status and
77 /*****************************************************************************/
82 /***************************** Include Files *********************************/
85 #include "xipipsu_hw.h"
87 /************************** Constant Definitions *****************************/
88 #define XIPIPSU_BUF_TYPE_MSG (0x00000001U)
89 #define XIPIPSU_BUF_TYPE_RESP (0x00000002U)
90 #define XIPIPSU_MAX_MSG_LEN XIPIPSU_MSG_BUF_SIZE
91 /**************************** Type Definitions *******************************/
93 * Data structure used to refer IPI Targets
96 u32 Mask; /**< Bit Mask for the target */
97 u32 BufferIndex; /**< Buffer Index used for calculating buffer address */
101 * This typedef contains configuration information for the device.
104 u32 DeviceId; /**< Unique ID of device */
105 u32 BaseAddress; /**< Base address of the device */
106 u32 BitMask; /**< BitMask to be used to identify this CPU */
107 u32 BufferIndex; /**< Index of the IPI Message Buffer */
108 u32 IntId; /**< Interrupt ID on GIC **/
109 u32 TargetCount; /**< Number of available IPI Targets */
110 XIpiPsu_Target TargetList[XIPIPSU_MAX_TARGETS] ; /** < List of IPI Targets */
114 * The XIpiPsu driver instance data. The user is required to allocate a
115 * variable of this type for each IPI device in the system. A pointer
116 * to a variable of this type is then passed to the driver API functions.
119 XIpiPsu_Config Config; /**< Configuration structure */
120 u32 IsReady; /**< Device is initialized and ready */
121 u32 Options; /**< Options set in the device */
124 /***************** Macros (Inline Functions) Definitions *********************/
127 * Read the register specified by the base address and offset
129 * @param BaseAddress is the base address of the IPI instance
130 * @param RegOffset is the offset of the register relative to base
132 * @return Value of the specified register
135 * u32 XIpiPsu_ReadReg(u32 BaseAddress, u32 RegOffset)
137 *****************************************************************************/
139 #define XIpiPsu_ReadReg(BaseAddress, RegOffset) \
140 Xil_In32((BaseAddress) + (RegOffset))
142 /****************************************************************************/
145 * Write a value into a register specified by base address and offset
147 * @param BaseAddress is the base address of the IPI instance
148 * @param RegOffset is the offset of the register relative to base
149 * @param Data is a 32-bit value that is to be written into the specified register
153 * void XIpiPsu_WriteReg(u32 BaseAddress, u32 RegOffset, u32 Data)
155 *****************************************************************************/
157 #define XIpiPsu_WriteReg(BaseAddress, RegOffset, Data) \
158 Xil_Out32(((BaseAddress) + (RegOffset)), (Data))
160 /****************************************************************************/
163 * Enable interrupts specified in <i>Mask</i>. The corresponding interrupt for
164 * each bit set to 1 in <i>Mask</i>, will be enabled.
166 * @param InstancePtr is a pointer to the instance to be worked on.
167 * @param Mask contains a bit mask of interrupts to enable. The mask can
168 * be formed using a set of bitwise or'd values of individual CPU masks
172 * void XIpiPsu_InterruptEnable(XIpiPsu *InstancePtr, u32 Mask)
174 *****************************************************************************/
175 #define XIpiPsu_InterruptEnable(InstancePtr, Mask) \
176 XIpiPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
177 XIPIPSU_IER_OFFSET, \
178 ((Mask) & XIPIPSU_ALL_MASK));
180 /****************************************************************************/
183 * Disable interrupts specified in <i>Mask</i>. The corresponding interrupt for
184 * each bit set to 1 in <i>Mask</i>, will be disabled.
186 * @param InstancePtr is a pointer to the instance to be worked on.
187 * @param Mask contains a bit mask of interrupts to disable. The mask can
188 * be formed using a set of bitwise or'd values of individual CPU masks
192 * void XIpiPsu_InterruptDisable(XIpiPsu *InstancePtr, u32 Mask)
194 *****************************************************************************/
195 #define XIpiPsu_InterruptDisable(InstancePtr, Mask) \
196 XIpiPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
197 XIPIPSU_IDR_OFFSET, \
198 ((Mask) & XIPIPSU_ALL_MASK));
199 /****************************************************************************/
202 * Get the <i>STATUS REGISTER</i> of the current IPI instance.
204 * @param InstancePtr is a pointer to the instance to be worked on.
205 * @return Returns the Interrupt Status register(ISR) contents
206 * @note User needs to parse this 32-bit value to check the source CPU
208 * u32 XIpiPsu_GetInterruptStatus(XIpiPsu *InstancePtr)
210 *****************************************************************************/
211 #define XIpiPsu_GetInterruptStatus(InstancePtr) \
212 XIpiPsu_ReadReg((InstancePtr)->Config.BaseAddress, \
214 /****************************************************************************/
217 * Clear the <i>STATUS REGISTER</i> of the current IPI instance.
218 * The corresponding interrupt status for
219 * each bit set to 1 in <i>Mask</i>, will be cleared
221 * @param InstancePtr is a pointer to the instance to be worked on.
222 * @param Mask corresponding to the source CPU*
224 * @note This function should be used after handling the IPI.
225 * Clearing the status will automatically clear the corresponding bit in
226 * OBSERVATION register of Source CPU
228 * void XIpiPsu_ClearInterruptStatus(XIpiPsu *InstancePtr, u32 Mask)
230 *****************************************************************************/
232 #define XIpiPsu_ClearInterruptStatus(InstancePtr, Mask) \
233 XIpiPsu_WriteReg((InstancePtr)->Config.BaseAddress, \
234 XIPIPSU_ISR_OFFSET, \
235 ((Mask) & XIPIPSU_ALL_MASK));
236 /****************************************************************************/
239 * Get the <i>OBSERVATION REGISTER</i> of the current IPI instance.
241 * @param InstancePtr is a pointer to the instance to be worked on.
242 * @return Returns the Observation register(OBS) contents
243 * @note User needs to parse this 32-bit value to check the status of
246 * u32 XIpiPsu_GetObsStatus(XIpiPsu *InstancePtr)
248 *****************************************************************************/
249 #define XIpiPsu_GetObsStatus(InstancePtr) \
250 XIpiPsu_ReadReg((InstancePtr)->Config.BaseAddress, \
252 /****************************************************************************/
253 /************************** Function Prototypes *****************************/
255 /* Static lookup function implemented in xipipsu_sinit.c */
257 XIpiPsu_Config *XIpiPsu_LookupConfig(u32 DeviceId);
259 /* Interface Functions implemented in xipipsu.c */
261 XStatus XIpiPsu_CfgInitialize(XIpiPsu *InstancePtr, XIpiPsu_Config * CfgPtr,
262 UINTPTR EffectiveAddress);
264 void XIpiPsu_Reset(XIpiPsu *InstancePtr);
266 XStatus XIpiPsu_TriggerIpi(XIpiPsu *InstancePtr, u32 DestCpuMask);
268 XStatus XIpiPsu_PollForAck(XIpiPsu *InstancePtr, u32 DestCpuMask,
271 XStatus XIpiPsu_ReadMessage(XIpiPsu *InstancePtr, u32 SrcCpuMask, u32 *MsgPtr,
272 u32 MsgLength, u8 BufType);
274 XStatus XIpiPsu_WriteMessage(XIpiPsu *InstancePtr, u32 DestCpuMask, u32 *MsgPtr,
275 u32 MsgLength, u8 BufType);
277 #endif /* XIPIPSU_H_ */