1 /* Copyright 2013-2015 Freescale Semiconductor Inc.
2  *
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5  * * Redistributions of source code must retain the above copyright
6  * notice, this list of conditions and the following disclaimer.
7  * * Redistributions in binary form must reproduce the above copyright
8  * notice, this list of conditions and the following disclaimer in the
9  * documentation and/or other materials provided with the distribution.
10  * * Neither the name of the above-listed copyright holders nor the
11  * names of any contributors may be used to endorse or promote products
12  * derived from this software without specific prior written permission.
13  *
14  *
15  * ALTERNATIVELY, this software may be distributed under the terms of the
16  * GNU General Public License ("GPL") as published by the Free Software
17  * Foundation, either version 2 of that License or (at your option) any
18  * later version.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef __FSL_DPMCP_H
33 #define __FSL_DPMCP_H
34 
35 /* Data Path Management Command Portal API
36  * Contains initialization APIs and runtime control APIs for DPMCP
37  */
38 
39 struct fsl_mc_io;
40 
41 /**
42  * dpmcp_open() - Open a control session for the specified object.
43  * @mc_io:	Pointer to MC portal's I/O object
44  * @dpmcp_id:	DPMCP unique ID
45  * @token:	Returned token; use in subsequent API calls
46  *
47  * This function can be used to open a control session for an
48  * already created object; an object may have been declared in
49  * the DPL or by calling the dpmcp_create function.
50  * This function returns a unique authentication token,
51  * associated with the specific object ID and the specific MC
52  * portal; this token must be used in all subsequent commands for
53  * this specific object
54  *
55  * Return:	'0' on Success; Error code otherwise.
56  */
57 int dpmcp_open(struct fsl_mc_io *mc_io, int dpmcp_id, uint16_t *token);
58 
59 /* Get portal ID from pool */
60 #define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
61 
62 /**
63  * dpmcp_close() - Close the control session of the object
64  * @mc_io:	Pointer to MC portal's I/O object
65  * @token:	Token of DPMCP object
66  *
67  * After this function is called, no further operations are
68  * allowed on the object without opening a new control session.
69  *
70  * Return:	'0' on Success; Error code otherwise.
71  */
72 int dpmcp_close(struct fsl_mc_io *mc_io, uint16_t token);
73 
74 /**
75  * struct dpmcp_cfg() - Structure representing DPMCP configuration
76  * @portal_id:	Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID
77  *		from pool
78  */
79 struct dpmcp_cfg {
80 	int portal_id;
81 };
82 
83 /**
84  * dpmcp_create() - Create the DPMCP object.
85  * @mc_io:	Pointer to MC portal's I/O object
86  * @cfg:	Configuration structure
87  * @token:	Returned token; use in subsequent API calls
88  *
89  * Create the DPMCP object, allocate required resources and
90  * perform required initialization.
91  *
92  * The object can be created either by declaring it in the
93  * DPL file, or by calling this function.
94  * This function returns a unique authentication token,
95  * associated with the specific object ID and the specific MC
96  * portal; this token must be used in all subsequent calls to
97  * this specific object. For objects that are created using the
98  * DPL file, call dpmcp_open function to get an authentication
99  * token first.
100  *
101  * Return:	'0' on Success; Error code otherwise.
102  */
103 int dpmcp_create(struct fsl_mc_io	*mc_io,
104 		 const struct dpmcp_cfg	*cfg,
105 		uint16_t		*token);
106 
107 /**
108  * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
109  * @mc_io:	Pointer to MC portal's I/O object
110  * @token:	Token of DPMCP object
111  *
112  * Return:	'0' on Success; error code otherwise.
113  */
114 int dpmcp_destroy(struct fsl_mc_io *mc_io, uint16_t token);
115 
116 /**
117  * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
118  * @mc_io:	Pointer to MC portal's I/O object
119  * @token:	Token of DPMCP object
120  *
121  * Return:	'0' on Success; Error code otherwise.
122  */
123 int dpmcp_reset(struct fsl_mc_io *mc_io, uint16_t token);
124 
125 /* IRQ */
126 /*!
127  * @name dpmcp IRQ Index and Events
128  */
129 #define DPMCP_IRQ_INDEX                             0
130 /*!< Irq index */
131 #define DPMCP_IRQ_EVENT_CMD_DONE                    0x00000001
132 /*!< irq event - Indicates that the link state changed */
133 /* @} */
134 
135 /**
136  * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
137  * @mc_io:	Pointer to MC portal's I/O object
138  * @token:	Token of DPMCP object
139  * @irq_index:	Identifies the interrupt index to configure
140  * @irq_addr:	Address that must be written to
141  *				signal a message-based interrupt
142  * @irq_val:	Value to write into irq_addr address
143  * @user_irq_id: A user defined number associated with this IRQ
144  *
145  * Return:	'0' on Success; Error code otherwise.
146  */
147 int dpmcp_set_irq(struct fsl_mc_io	*mc_io,
148 		  uint16_t		token,
149 		 uint8_t		irq_index,
150 		 uint64_t		irq_addr,
151 		 uint32_t		irq_val,
152 		 int			user_irq_id);
153 
154 /**
155  * dpmcp_get_irq() - Get IRQ information from the DPMCP.
156  * @mc_io:	Pointer to MC portal's I/O object
157  * @token:	Token of DPMCP object
158  * @irq_index:	The interrupt index to configure
159  * @type:	Interrupt type: 0 represents message interrupt
160  *				type (both irq_addr and irq_val are valid)
161  * @irq_addr:	Returned address that must be written to
162  *				signal the message-based interrupt
163  * @irq_val:	Value to write into irq_addr address
164  * @user_irq_id: A user defined number associated with this IRQ
165  *
166  * Return:	'0' on Success; Error code otherwise.
167  */
168 int dpmcp_get_irq(struct fsl_mc_io	*mc_io,
169 		  uint16_t		token,
170 		 uint8_t		irq_index,
171 		 int			*type,
172 		 uint64_t		*irq_addr,
173 		 uint32_t		*irq_val,
174 		 int			*user_irq_id);
175 
176 /**
177  * dpmcp_set_irq_enable() - Set overall interrupt state.
178  * @mc_io:	Pointer to MC portal's I/O object
179  * @token:	Token of DPMCP object
180  * @irq_index:	The interrupt index to configure
181  * @en:	Interrupt state - enable = 1, disable = 0
182  *
183  * Allows GPP software to control when interrupts are generated.
184  * Each interrupt can have up to 32 causes.  The enable/disable control's the
185  * overall interrupt state. if the interrupt is disabled no causes will cause
186  * an interrupt.
187  *
188  * Return:	'0' on Success; Error code otherwise.
189  */
190 int dpmcp_set_irq_enable(struct fsl_mc_io	*mc_io,
191 			 uint16_t		token,
192 			uint8_t			irq_index,
193 			uint8_t			en);
194 
195 /**
196  * dpmcp_get_irq_enable() - Get overall interrupt state
197  * @mc_io:	Pointer to MC portal's I/O object
198  * @token:	Token of DPMCP object
199  * @irq_index:	The interrupt index to configure
200  * @en:		Returned interrupt state - enable = 1, disable = 0
201  *
202  * Return:	'0' on Success; Error code otherwise.
203  */
204 int dpmcp_get_irq_enable(struct fsl_mc_io	*mc_io,
205 			 uint16_t		token,
206 			uint8_t			irq_index,
207 			uint8_t			*en);
208 
209 /**
210  * dpmcp_set_irq_mask() - Set interrupt mask.
211  * @mc_io:	Pointer to MC portal's I/O object
212  * @token:	Token of DPMCP object
213  * @irq_index:	The interrupt index to configure
214  * @mask:	Event mask to trigger interrupt;
215  *			each bit:
216  *				0 = ignore event
217  *				1 = consider event for asserting IRQ
218  *
219  * Every interrupt can have up to 32 causes and the interrupt model supports
220  * masking/unmasking each cause independently
221  *
222  * Return:	'0' on Success; Error code otherwise.
223  */
224 int dpmcp_set_irq_mask(struct fsl_mc_io	*mc_io,
225 		       uint16_t		token,
226 		      uint8_t		irq_index,
227 		      uint32_t		mask);
228 
229 /**
230  * dpmcp_get_irq_mask() - Get interrupt mask.
231  * @mc_io:	Pointer to MC portal's I/O object
232  * @token:	Token of DPMCP object
233  * @irq_index:	The interrupt index to configure
234  * @mask:	Returned event mask to trigger interrupt
235  *
236  * Every interrupt can have up to 32 causes and the interrupt model supports
237  * masking/unmasking each cause independently
238  *
239  * Return:	'0' on Success; Error code otherwise.
240  */
241 int dpmcp_get_irq_mask(struct fsl_mc_io	*mc_io,
242 		       uint16_t		token,
243 		      uint8_t		irq_index,
244 		      uint32_t		*mask);
245 
246 /**
247  * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
248  *
249  * @mc_io:	Pointer to MC portal's I/O object
250  * @token:	Token of DPMCP object
251  * @irq_index:	The interrupt index to configure
252  * @status:	Returned interrupts status - one bit per cause:
253  *			0 = no interrupt pending
254  *			1 = interrupt pending
255  *
256  * Return:	'0' on Success; Error code otherwise.
257  */
258 int dpmcp_get_irq_status(struct fsl_mc_io	*mc_io,
259 			 uint16_t		token,
260 			uint8_t			irq_index,
261 			uint32_t		*status);
262 
263 /**
264  * dpmcp_clear_irq_status() - Clear a pending interrupt's status
265  *
266  * @mc_io:	Pointer to MC portal's I/O object
267  * @token:	Token of DPMCP object
268  * @irq_index:	The interrupt index to configure
269  * @status:	Bits to clear (W1C) - one bit per cause:
270  *					0 = don't change
271  *					1 = clear status bit
272  *
273  * Return:	'0' on Success; Error code otherwise.
274  */
275 int dpmcp_clear_irq_status(struct fsl_mc_io	*mc_io,
276 			   uint16_t		token,
277 			  uint8_t		irq_index,
278 			  uint32_t		status);
279 
280 /**
281  * struct dpmcp_attr - Structure representing DPMCP attributes
282  * @id:		DPMCP object ID
283  * @version:	DPMCP version
284  */
285 struct dpmcp_attr {
286 	int id;
287 	/**
288 	 * struct version - Structure representing DPMCP version
289 	 * @major:	DPMCP major version
290 	 * @minor:	DPMCP minor version
291 	 */
292 	struct {
293 		uint16_t major;
294 		uint16_t minor;
295 	} version;
296 };
297 
298 /**
299  * dpmcp_get_attributes - Retrieve DPMCP attributes.
300  *
301  * @mc_io:	Pointer to MC portal's I/O object
302  * @token:	Token of DPMCP object
303  * @attr:	Returned object's attributes
304  *
305  * Return:	'0' on Success; Error code otherwise.
306  */
307 int dpmcp_get_attributes(struct fsl_mc_io	*mc_io,
308 			 uint16_t		token,
309 			struct dpmcp_attr	*attr);
310 
311 #endif /* __FSL_DPMCP_H */
312