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_DPRC_H
33 #define _FSL_DPRC_H
34 
35 /* Data Path Resource Container API
36  * Contains DPRC API for managing and querying DPAA resources
37  */
38 
39 struct fsl_mc_io;
40 
41 /**
42  * Set this value as the icid value in dprc_cfg structure when creating a
43  * container, in case the ICID is not selected by the user and should be
44  * allocated by the DPRC from the pool of ICIDs.
45  */
46 #define DPRC_GET_ICID_FROM_POOL			(uint16_t)(~(0))
47 
48 /**
49  * Set this value as the portal_id value in dprc_cfg structure when creating a
50  * container, in case the portal ID is not specifically selected by the
51  * user and should be allocated by the DPRC from the pool of portal ids.
52  */
53 #define DPRC_GET_PORTAL_ID_FROM_POOL	(int)(~(0))
54 
55 /**
56  * dprc_open() - Open DPRC object for use
57  * @mc_io:	Pointer to MC portal's I/O object
58  * @container_id: Container ID to open
59  * @token:	Returned token of DPRC object
60  *
61  * Return:	'0' on Success; Error code otherwise.
62  *
63  * @warning	Required before any operation on the object.
64  */
65 int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token);
66 
67 /**
68  * dprc_close() - Close the control session of the object
69  * @mc_io:	Pointer to MC portal's I/O object
70  * @token:	Token of DPRC object
71  *
72  * After this function is called, no further operations are
73  * allowed on the object without opening a new control session.
74  *
75  * Return:	'0' on Success; Error code otherwise.
76  */
77 int dprc_close(struct fsl_mc_io *mc_io, uint16_t token);
78 
79 /**
80  * Container general options
81  *
82  * These options may be selected at container creation by the container creator
83  * and can be retrieved using dprc_get_attributes()
84  */
85 
86 /* Spawn Policy Option allowed - Indicates that the new container is allowed
87  * to spawn and have its own child containers.
88  */
89 #define DPRC_CFG_OPT_SPAWN_ALLOWED		0x00000001
90 
91 /* General Container allocation policy - Indicates that the new container is
92  * allowed to allocate requested resources from its parent container; if not
93  * set, the container is only allowed to use resources in its own pools; Note
94  * that this is a container's global policy, but the parent container may
95  * override it and set specific quota per resource type.
96  */
97 #define DPRC_CFG_OPT_ALLOC_ALLOWED		0x00000002
98 
99 /* Object initialization allowed - software context associated with this
100  * container is allowed to invoke object initialization operations.
101  */
102 #define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED	0x00000004
103 
104 /* Topology change allowed - software context associated with this
105  * container is allowed to invoke topology operations, such as attach/detach
106  * of network objects.
107  */
108 #define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED	0x00000008
109 
110 /* IOMMU bypass - indicates whether objects of this container are permitted
111  * to bypass the IOMMU.
112  */
113 #define DPRC_CFG_OPT_IOMMU_BYPASS		0x00000010
114 
115 /* AIOP - Indicates that container belongs to AIOP.  */
116 #define DPRC_CFG_OPT_AIOP			0x00000020
117 
118 /**
119  * struct dprc_cfg - Container configuration options
120  * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
121  *		ICID value is allocated by the DPRC
122  * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
123  *		portal ID is allocated by the DPRC
124  * @options: Combination of 'DPRC_CFG_OPT_<X>' options
125  */
126 struct dprc_cfg {
127 	uint16_t icid;
128 	int portal_id;
129 	uint64_t options;
130 };
131 
132 /**
133  * dprc_create_container() - Create child container
134  * @mc_io:	Pointer to MC portal's I/O object
135  * @token:	Token of DPRC object
136  * @cfg:	Child container configuration
137  * @child_container_id:	Returned child container ID
138  * @child_portal_paddr:	Returned base physical address of the
139  *					child portal
140  *
141  * Return:	'0' on Success; Error code otherwise.
142  */
143 int dprc_create_container(struct fsl_mc_io	*mc_io,
144 			  uint16_t		token,
145 			  struct dprc_cfg	*cfg,
146 			  int			*child_container_id,
147 			  uint64_t		*child_portal_paddr);
148 
149 /**
150  * dprc_destroy_container() - Destroy child container.
151  * @mc_io:	Pointer to MC portal's I/O object
152  * @token:	Token of DPRC object
153  * @child_container_id:	ID of the container to destroy
154  *
155  * This function terminates the child container, so following this call the
156  * child container ID becomes invalid.
157  *
158  * Notes:
159  * - All resources and objects of the destroyed container are returned to the
160  * parent container or destroyed if were created be the destroyed container.
161  * - This function destroy all the child containers of the specified
162  *   container prior to destroying the container itself.
163  *
164  * warning: Only the parent container is allowed to destroy a child policy
165  *		Container 0 can't be destroyed
166  *
167  * Return:	'0' on Success; Error code otherwise.
168  *
169  */
170 int dprc_destroy_container(struct fsl_mc_io	*mc_io,
171 			   uint16_t		token,
172 			   int			child_container_id);
173 
174 /**
175  * dprc_reset_container - Reset child container.
176  * @mc_io:	Pointer to MC portal's I/O object
177  * @token:	Token of DPRC object
178  * @child_container_id:	ID of the container to reset
179  *
180  * In case a software context crashes or becomes non-responsive, the parent
181  * may wish to reset its resources container before the software context is
182  * restarted.
183  *
184  * This routine informs all objects assigned to the child container that the
185  * container is being reset, so they may perform any cleanup operations that are
186  * needed. All objects handles that were owned by the child container shall be
187  * closed.
188  *
189  * Note that such request may be submitted even if the child software context
190  * has not crashed, but the resulting object cleanup operations will not be
191  * aware of that.
192  *
193  * Return:	'0' on Success; Error code otherwise.
194  */
195 int dprc_reset_container(struct fsl_mc_io *mc_io,
196 			 uint16_t token,
197 			 int child_container_id);
198 
199 /* IRQ */
200 
201 /* Number of dprc's IRQs */
202 #define DPRC_NUM_OF_IRQS		1
203 
204 /* Object irq events */
205 
206 /* IRQ event - Indicates that a new object assigned to the container */
207 #define DPRC_IRQ_EVENT_OBJ_ADDED		0x00000001
208 /* IRQ event - Indicates that an object was unassigned from the container */
209 #define DPRC_IRQ_EVENT_OBJ_REMOVED		0x00000002
210 /* IRQ event - Indicates that resources assigned to the container */
211 #define DPRC_IRQ_EVENT_RES_ADDED		0x00000004
212 /* IRQ event - Indicates that resources unassigned from the container */
213 #define DPRC_IRQ_EVENT_RES_REMOVED		0x00000008
214 /* IRQ event - Indicates that one of the descendant containers that opened by
215  * this container is destroyed
216  */
217 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED	0x00000010
218 
219 /* IRQ event - Indicates that on one of the container's opened object is
220  * destroyed
221  */
222 #define DPRC_IRQ_EVENT_OBJ_DESTROYED		0x00000020
223 
224 /* Irq event - Indicates that object is created at the container */
225 #define DPRC_IRQ_EVENT_OBJ_CREATED		0x00000040
226 
227 /**
228  * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
229  * @mc_io:	Pointer to MC portal's I/O object
230  * @token:	Token of DPRC object
231  * @irq_index:	Identifies the interrupt index to configure
232  * @irq_addr:	Address that must be written to
233  *			signal a message-based interrupt
234  * @irq_val:	Value to write into irq_addr address
235  * @user_irq_id: Returned a user defined number associated with this IRQ
236  *
237  * Return:	'0' on Success; Error code otherwise.
238  */
239 int dprc_set_irq(struct fsl_mc_io	*mc_io,
240 		 uint16_t		token,
241 		 uint8_t		irq_index,
242 		 uint64_t		irq_addr,
243 		 uint32_t		irq_val,
244 		 int			user_irq_id);
245 
246 /**
247  * dprc_get_irq() - Get IRQ information from the DPRC.
248  * @mc_io:	Pointer to MC portal's I/O object
249  * @token:	Token of DPRC object
250  * @irq_index:	The interrupt index to configure
251  * @type:	Returned interrupt type: 0 represents message interrupt
252  *			type (both irq_addr and irq_val are valid)
253  * @irq_addr:	Returned address that must be written to
254  *			signal the message-based interrupt
255  * @irq_val:	Value to write into irq_addr address
256  * @user_irq_id: A user defined number associated with this IRQ
257  *
258  * Return:	'0' on Success; Error code otherwise.
259  */
260 int dprc_get_irq(struct fsl_mc_io	*mc_io,
261 		 uint16_t		token,
262 		 uint8_t		irq_index,
263 		 int			*type,
264 		 uint64_t		*irq_addr,
265 		 uint32_t		*irq_val,
266 		 int			*user_irq_id);
267 
268 /**
269  * dprc_set_irq_enable() - Set overall interrupt state.
270  * @mc_io:	Pointer to MC portal's I/O object
271  * @token:	Token of DPRC object
272  * @irq_index:	The interrupt index to configure
273  * @en:		Interrupt state - enable = 1, disable = 0
274  *
275  * Allows GPP software to control when interrupts are generated.
276  * Each interrupt can have up to 32 causes.  The enable/disable control's the
277  * overall interrupt state. if the interrupt is disabled no causes will cause
278  * an interrupt.
279  *
280  * Return:	'0' on Success; Error code otherwise.
281  */
282 int dprc_set_irq_enable(struct fsl_mc_io	*mc_io,
283 			uint16_t		token,
284 			uint8_t			irq_index,
285 			uint8_t			en);
286 
287 /**
288  * dprc_get_irq_enable() - Get overall interrupt state.
289  * @mc_io:	Pointer to MC portal's I/O object
290  * @token:	Token of DPRC object
291  * @irq_index:  The interrupt index to configure
292  * @en:		Returned interrupt state - enable = 1, disable = 0
293  *
294  * Return:	'0' on Success; Error code otherwise.
295  */
296 int dprc_get_irq_enable(struct fsl_mc_io	*mc_io,
297 			uint16_t		token,
298 			uint8_t			irq_index,
299 			uint8_t			*en);
300 
301 /**
302  * dprc_set_irq_mask() - Set interrupt mask.
303  * @mc_io:	Pointer to MC portal's I/O object
304  * @token:	Token of DPRC object
305  * @irq_index:	The interrupt index to configure
306  * @mask:	event mask to trigger interrupt;
307  *			each bit:
308  *				0 = ignore event
309  *				1 = consider event for asserting irq
310  *
311  * Every interrupt can have up to 32 causes and the interrupt model supports
312  * masking/unmasking each cause independently
313  *
314  * Return:	'0' on Success; Error code otherwise.
315  */
316 int dprc_set_irq_mask(struct fsl_mc_io	*mc_io,
317 		      uint16_t		token,
318 		      uint8_t		irq_index,
319 		      uint32_t		mask);
320 
321 /**
322  * dprc_get_irq_mask() - Get interrupt mask.
323  * @mc_io:	Pointer to MC portal's I/O object
324  * @token:	Token of DPRC object
325  * @irq_index:	The interrupt index to configure
326  * @mask:	Returned event mask to trigger interrupt
327  *
328  * Every interrupt can have up to 32 causes and the interrupt model supports
329  * masking/unmasking each cause independently
330  *
331  * Return:	'0' on Success; Error code otherwise.
332  */
333 int dprc_get_irq_mask(struct fsl_mc_io	*mc_io,
334 		      uint16_t		token,
335 		      uint8_t		irq_index,
336 		      uint32_t		*mask);
337 
338 /**
339  * dprc_get_irq_status() - Get the current status of any pending interrupts.
340  * @mc_io:	Pointer to MC portal's I/O object
341  * @token:	Token of DPRC object
342  * @irq_index:	The interrupt index to configure
343  * @status:	Returned interrupts status - one bit per cause:
344  *			0 = no interrupt pending
345  *			1 = interrupt pending
346  *
347  * Return:	'0' on Success; Error code otherwise.
348  */
349 int dprc_get_irq_status(struct fsl_mc_io	*mc_io,
350 			uint16_t		token,
351 			uint8_t			irq_index,
352 			uint32_t		*status);
353 
354 /**
355  * dprc_clear_irq_status() - Clear a pending interrupt's status
356  * @mc_io:	Pointer to MC portal's I/O object
357  * @token:	Token of DPRC object
358  * @irq_index:	The interrupt index to configure
359  * @status:	bits to clear (W1C) - one bit per cause:
360  *					0 = don't change
361  *					1 = clear status bit
362  *
363  * Return:	'0' on Success; Error code otherwise.
364  */
365 int dprc_clear_irq_status(struct fsl_mc_io	*mc_io,
366 			  uint16_t		token,
367 			  uint8_t		irq_index,
368 			  uint32_t		status);
369 
370 /**
371  * struct dprc_attributes - Container attributes
372  * @container_id: Container's ID
373  * @icid: Container's ICID
374  * @portal_id: Container's portal ID
375  * @options: Container's options as set at container's creation
376  * @version: DPRC version
377  */
378 struct dprc_attributes {
379 	int container_id;
380 	uint16_t icid;
381 	int portal_id;
382 	uint64_t options;
383 	/**
384 	 * struct version - DPRC version
385 	 * @major: DPRC major version
386 	 * @minor: DPRC minor version
387 	 */
388 	struct {
389 		uint16_t major;
390 		uint16_t minor;
391 	} version;
392 };
393 
394 /**
395  * dprc_get_attributes() - Obtains container attributes
396  * @mc_io:	Pointer to MC portal's I/O object
397  * @token:	Token of DPRC object
398  * @attributes	Returned container attributes
399  *
400  * Return:     '0' on Success; Error code otherwise.
401  */
402 int dprc_get_attributes(struct fsl_mc_io	*mc_io,
403 			uint16_t		token,
404 			struct dprc_attributes	*attributes);
405 
406 /**
407  * dprc_set_res_quota() - Set allocation policy for a specific resource/object
408  *		type in a child container
409  * @mc_io:	Pointer to MC portal's I/O object
410  * @token:	Token of DPRC object
411  * @child_container_id:	ID of the child container
412  * @type:	Resource/object type
413  * @quota:	Sets the maximum number of resources of	the selected type
414  *		that the child container is allowed to allocate from its parent;
415  *		when quota is set to -1, the policy is the same as container's
416  *		general policy.
417  *
418  * Allocation policy determines whether or not a container may allocate
419  * resources from its parent. Each container has a 'global' allocation policy
420  * that is set when the container is created.
421  *
422  * This function sets allocation policy for a specific resource type.
423  * The default policy for all resource types matches the container's 'global'
424  * allocation policy.
425  *
426  * Return:	'0' on Success; Error code otherwise.
427  *
428  * @warning	Only the parent container is allowed to change a child policy.
429  */
430 int dprc_set_res_quota(struct fsl_mc_io	*mc_io,
431 		       uint16_t		token,
432 		       int		child_container_id,
433 		       char		*type,
434 		       uint16_t		quota);
435 
436 /**
437  * dprc_get_res_quota() - Gets the allocation policy of a specific
438  *		resource/object type in a child container
439  * @mc_io:	Pointer to MC portal's I/O object
440  * @token:	Token of DPRC object
441  * @child_container_id;	ID of the child container
442  * @type:	resource/object type
443  * @quota:	Returnes the maximum number of resources of the selected type
444  *		that the child container is allowed to allocate from the parent;
445  *		when quota is set to -1, the policy is the same as container's
446  *		general policy.
447  *
448  * Return:	'0' on Success; Error code otherwise.
449  */
450 int dprc_get_res_quota(struct fsl_mc_io	*mc_io,
451 		       uint16_t		token,
452 		       int		child_container_id,
453 		       char		*type,
454 		       uint16_t		*quota);
455 
456 /* Resource request options */
457 
458 /* Explicit resource ID request - The requested objects/resources
459  * are explicit and sequential (in case of resources).
460  * The base ID is given at res_req at base_align field
461  */
462 #define DPRC_RES_REQ_OPT_EXPLICIT		0x00000001
463 
464 /* Aligned resources request - Relevant only for resources
465  * request (and not objects). Indicates that resources base ID should be
466  * sequential and aligned to the value given at dprc_res_req base_align field
467  */
468 #define DPRC_RES_REQ_OPT_ALIGNED		0x00000002
469 
470 /* Plugged Flag - Relevant only for object assignment request.
471  * Indicates that after all objects assigned. An interrupt will be invoked at
472  * the relevant GPP. The assigned object will be marked as plugged.
473  * plugged objects can't be assigned from their container
474  */
475 #define DPRC_RES_REQ_OPT_PLUGGED		0x00000004
476 
477 /**
478  * struct dprc_res_req - Resource request descriptor, to be used in assignment
479  *			or un-assignment of resources and objects.
480  * @type: Resource/object type: Represent as a NULL terminated string.
481  *	This string may received by using dprc_get_pool() to get resource
482  *	type and dprc_get_obj() to get object type;
483  *	Note: it is not possible to assign/un-assign DPRC objects
484  * @num: Number of resources
485  * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
486  * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
487  *		is set at option), this field represents the required base ID
488  *		for resource allocation; In case of aligned assignment
489  *		(DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
490  *		indicates the required alignment for the resource ID(s) -
491  *		use 0 if there is no alignment or explicit ID requirements
492  */
493 struct dprc_res_req {
494 	char type[16];
495 	uint32_t num;
496 	uint32_t options;
497 	int id_base_align;
498 };
499 
500 /**
501  * dprc_assign() - Assigns objects or resource to a child container.
502  * @mc_io:	Pointer to MC portal's I/O object
503  * @token:	Token of DPRC object
504  * @container_id: ID of the child container
505  * @res_req:	Describes the type and amount of resources to
506  *			assign to the given container
507  *
508  * Assignment is usually done by a parent (this DPRC) to one of its child
509  * containers.
510  *
511  * According to the DPRC allocation policy, the assigned resources may be taken
512  * (allocated) from the container's ancestors, if not enough resources are
513  * available in the container itself.
514  *
515  * The type of assignment depends on the dprc_res_req options, as follows:
516  * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
517  *   the explicit base ID specified at the id_base_align field of res_req.
518  * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
519  *   aligned to the value given at id_base_align field of res_req.
520  * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
521  *   and indicates that the object must be set to the plugged state.
522  *
523  * A container may use this function with its own ID in order to change a
524  * object state to plugged or unplugged.
525  *
526  * If IRQ information has been set in the child DPRC, it will signal an
527  * interrupt following every change in its object assignment.
528  *
529  * Return:	'0' on Success; Error code otherwise.
530  */
531 int dprc_assign(struct fsl_mc_io	*mc_io,
532 		uint16_t		token,
533 		int			container_id,
534 		struct dprc_res_req	*res_req);
535 
536 /**
537  * dprc_unassign() - Un-assigns objects or resources from a child container
538  *		and moves them into this (parent) DPRC.
539  * @mc_io:	Pointer to MC portal's I/O object
540  * @token:	Token of DPRC object
541  * @child_container_id:	ID of the child container
542  * @res_req:	Describes the type and amount of resources to un-assign from
543  *		the child container
544  *
545  * Un-assignment of objects can succeed only if the object is not in the
546  * plugged or opened state.
547  *
548  * Return:	'0' on Success; Error code otherwise.
549  */
550 int dprc_unassign(struct fsl_mc_io	*mc_io,
551 		  uint16_t		token,
552 		  int			child_container_id,
553 		  struct dprc_res_req	*res_req);
554 
555 /**
556  * dprc_get_pool_count() - Get the number of dprc's pools
557  * @mc_io:	Pointer to MC portal's I/O object
558  * @token:	Token of DPRC object
559  * @pool_count:	Returned number of resource pools in the dprc
560  *
561  * Return:	'0' on Success; Error code otherwise.
562  */
563 int dprc_get_pool_count(struct fsl_mc_io	*mc_io,
564 			uint16_t		token,
565 			int			*pool_count);
566 
567 /**
568  * dprc_get_pool() - Get the type (string) of a certain dprc's pool
569  * @mc_io:	Pointer to MC portal's I/O object
570  * @token:	Token of DPRC object
571  * @pool_index;	Index of the pool to be queried (< pool_count)
572  * @type:	The type of the pool
573  *
574  * The pool types retrieved one by one by incrementing
575  * pool_index up to (not including) the value of pool_count returned
576  * from dprc_get_pool_count(). dprc_get_pool_count() must
577  * be called prior to dprc_get_pool().
578  *
579  * Return:	'0' on Success; Error code otherwise.
580  */
581 int dprc_get_pool(struct fsl_mc_io	*mc_io,
582 		  uint16_t		token,
583 		  int			pool_index,
584 		  char			*type);
585 
586 /**
587  * dprc_get_obj_count() - Obtains the number of objects in the DPRC
588  * @mc_io:	Pointer to MC portal's I/O object
589  * @token:	Token of DPRC object
590  * @obj_count:	Number of objects assigned to the DPRC
591  *
592  * Return:	'0' on Success; Error code otherwise.
593  */
594 int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count);
595 
596 /* Objects Attributes Flags */
597 
598 /* Opened state - Indicates that an object is open by at least one owner */
599 #define DPRC_OBJ_STATE_OPEN		0x00000001
600 /* Plugged state - Indicates that the object is plugged */
601 #define DPRC_OBJ_STATE_PLUGGED		0x00000002
602 
603 /**
604  * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
605  * @type: Type of object: NULL terminated string
606  * @id: ID of logical object resource
607  * @vendor: Object vendor identifier
608  * @ver_major: Major version number
609  * @ver_minor:  Minor version number
610  * @irq_count: Number of interrupts supported by the object
611  * @region_count: Number of mappable regions supported by the object
612  * @state: Object state: combination of DPRC_OBJ_STATE_ states
613  */
614 struct dprc_obj_desc {
615 	char type[16];
616 	int id;
617 	uint16_t vendor;
618 	uint16_t ver_major;
619 	uint16_t ver_minor;
620 	uint8_t irq_count;
621 	uint8_t region_count;
622 	uint32_t state;
623 };
624 
625 /**
626  * dprc_get_obj() - Get general information on an object
627  * @mc_io:	Pointer to MC portal's I/O object
628  * @token:	Token of DPRC object
629  * @obj_index:	Index of the object to be queried (< obj_count)
630  * @obj_desc:	Returns the requested object descriptor
631  *
632  * The object descriptors are retrieved one by one by incrementing
633  * obj_index up to (not including) the value of obj_count returned
634  * from dprc_get_obj_count(). dprc_get_obj_count() must
635  * be called prior to dprc_get_obj().
636  *
637  * Return:	'0' on Success; Error code otherwise.
638  */
639 int dprc_get_obj(struct fsl_mc_io	*mc_io,
640 		 uint16_t		token,
641 		 int			obj_index,
642 		 struct dprc_obj_desc	*obj_desc);
643 
644 /**
645  * dprc_get_res_count() - Obtains the number of free resources that are assigned
646  *		to this container, by pool type
647  * @mc_io:	Pointer to MC portal's I/O object
648  * @token:	Token of DPRC object
649  * @type:	pool type
650  * @res_count:	Returned number of free resources of the given
651  *			resource type that are assigned to this DPRC
652  *
653  * Return:	'0' on Success; Error code otherwise.
654  */
655 int dprc_get_res_count(struct fsl_mc_io	*mc_io,
656 		       uint16_t		token,
657 		       char		*type,
658 		       int		*res_count);
659 
660 /**
661  * enum dprc_iter_status - Iteration status
662  * @DPRC_ITER_STATUS_FIRST: Perform first iteration
663  * @DPRC_ITER_STATUS_MORE: Indicates more/next iteration is needed
664  * @DPRC_ITER_STATUS_LAST: Indicates last iteration
665  */
666 enum dprc_iter_status {
667 	DPRC_ITER_STATUS_FIRST = 0,
668 	DPRC_ITER_STATUS_MORE = 1,
669 	DPRC_ITER_STATUS_LAST = 2
670 };
671 
672 /**
673  * struct dprc_res_ids_range_desc - Resource ID range descriptor
674  * @base_id: Base resource ID of this range
675  * @last_id: Last resource ID of this range
676  * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
677  *	first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
678  *	additional iterations are needed, until the returned marker is
679  *	DPRC_ITER_STATUS_LAST
680  */
681 struct dprc_res_ids_range_desc {
682 	int base_id;
683 	int last_id;
684 	enum dprc_iter_status iter_status;
685 };
686 
687 /**
688  * dprc_get_res_ids() - Obtains IDs of free resources in the container
689  * @mc_io:	Pointer to MC portal's I/O object
690  * @token:	Token of DPRC object
691  * @type:	pool type
692  * @range_desc:	range descriptor
693  *
694  * Return:	'0' on Success; Error code otherwise.
695  */
696 int dprc_get_res_ids(struct fsl_mc_io			*mc_io,
697 		     uint16_t				token,
698 		     char				*type,
699 		     struct dprc_res_ids_range_desc	*range_desc);
700 
701 /**
702  * dprc_get_portal_paddr() - Get the physical address of MC portals
703  * @mc_io:	Pointer to MC portal's I/O object
704  * @token:	Token of DPRC object
705  * @portal_id:	MC portal ID
706  * @portal_addr: The physical address of the MC portal ID
707  *
708  * Return:	'0' on Success; Error code otherwise.
709  */
710 int dprc_get_portal_paddr(struct fsl_mc_io	*mc_io,
711 			  uint16_t		token,
712 			  int			portal_id,
713 			  uint64_t		*portal_addr);
714 
715 /**
716  * struct dprc_region_desc - Mappable region descriptor
717  * @base_paddr: Region base physical address
718  * @size: Region size (in bytes)
719  */
720 struct dprc_region_desc {
721 	uint64_t base_paddr;
722 	uint32_t size;
723 };
724 
725 /**
726  * dprc_get_obj_region() - Get region information for a specified object.
727  * @mc_io:	Pointer to MC portal's I/O object
728  * @token:	Token of DPRC object
729  * @obj_type;	Object type as returned in dprc_get_obj()
730  * @obj_id:	Unique object instance as returned in dprc_get_obj()
731  * @region_index: The specific region to query
732  * @region_desc:  Returns the requested region descriptor
733  *
734  * Return:	'0' on Success; Error code otherwise.
735  */
736 int dprc_get_obj_region(struct fsl_mc_io	*mc_io,
737 			uint16_t		token,
738 			char			*obj_type,
739 			int			obj_id,
740 			uint8_t			region_index,
741 			struct dprc_region_desc	*region_desc);
742 
743 /**
744  * struct dprc_endpoint - Endpoint description for link connect/disconnect
745  *			operations
746  * @type: Endpoint object type: NULL terminated string
747  * @id: Endpoint object ID
748  * @interface_id: Interface ID; should be set for endpoints with multiple
749  *		interfaces ("dpsw", "dpdmux"); for others, always set to 0
750  */
751 struct dprc_endpoint {
752 	char type[16];
753 	int id;
754 	int interface_id;
755 };
756 
757 /**
758  * dprc_connect() - Connect two endpoints to create a network link between them
759  * @mc_io:	Pointer to MC portal's I/O object
760  * @token:	Token of DPRC object
761  * @endpoint1:	Endpoint 1 configuration parameters
762  * @endpoint2:	Endpoint 2 configuration parameters
763  *
764  * Return:	'0' on Success; Error code otherwise.
765  */
766 int dprc_connect(struct fsl_mc_io		*mc_io,
767 		 uint16_t			token,
768 		 const struct dprc_endpoint	*endpoint1,
769 		 const struct dprc_endpoint	*endpoint2);
770 
771 /**
772  * dprc_disconnect() - Disconnect one endpoint to remove its network connection
773  * @mc_io:	Pointer to MC portal's I/O object
774  * @token:	Token of DPRC object
775  * @endpoint:	Endpoint configuration parameters
776  *
777  * Return:	'0' on Success; Error code otherwise.
778  */
779 int dprc_disconnect(struct fsl_mc_io		*mc_io,
780 		    uint16_t			token,
781 		    const struct dprc_endpoint	*endpoint);
782 
783 /**
784 * dprc_get_connection() - Get connected endpoint and link status if connection
785 *			exists.
786 * @mc_io		Pointer to MC portal's I/O object
787 * @token		Token of DPRC object
788 * @endpoint1	Endpoint 1 configuration parameters
789 * @endpoint2	Returned endpoint 2 configuration parameters
790 * @state:	Returned link state: 1 - link is up, 0 - link is down
791 *
792 * Return:     '0' on Success; -ENAVAIL if connection does not exist.
793 */
794 int dprc_get_connection(struct fsl_mc_io		*mc_io,
795 			uint16_t			token,
796 			const struct dprc_endpoint	*endpoint1,
797 			struct dprc_endpoint		*endpoint2,
798 			int				*state);
799 
800 #endif /* _FSL_DPRC_H */
801 
802