GNU Linux-libre 4.14.266-gnu1
[releases.git] / drivers / staging / fsl-mc / bus / dprc.h
1 /*
2  * Copyright 2013-2016 Freescale Semiconductor Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the above-listed copyright holders nor the
12  * names of any contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 #ifndef _FSL_DPRC_H
34 #define _FSL_DPRC_H
35
36 /*
37  * Data Path Resource Container API
38  * Contains DPRC API for managing and querying DPAA resources
39  */
40
41 struct fsl_mc_io;
42 struct fsl_mc_obj_desc;
43
44 int dprc_open(struct fsl_mc_io *mc_io,
45               u32 cmd_flags,
46               int container_id,
47               u16 *token);
48
49 int dprc_close(struct fsl_mc_io *mc_io,
50                u32 cmd_flags,
51                u16 token);
52
53 /* IRQ */
54
55 /* IRQ index */
56 #define DPRC_IRQ_INDEX          0
57
58 /* Number of dprc's IRQs */
59 #define DPRC_NUM_OF_IRQS        1
60
61 /* DPRC IRQ events */
62
63 /* IRQ event - Indicates that a new object added to the container */
64 #define DPRC_IRQ_EVENT_OBJ_ADDED                0x00000001
65 /* IRQ event - Indicates that an object was removed from the container */
66 #define DPRC_IRQ_EVENT_OBJ_REMOVED              0x00000002
67 /* IRQ event - Indicates that resources added to the container */
68 #define DPRC_IRQ_EVENT_RES_ADDED                0x00000004
69 /* IRQ event - Indicates that resources removed from the container */
70 #define DPRC_IRQ_EVENT_RES_REMOVED              0x00000008
71 /*
72  * IRQ event - Indicates that one of the descendant containers that opened by
73  * this container is destroyed
74  */
75 #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED      0x00000010
76
77 /*
78  * IRQ event - Indicates that on one of the container's opened object is
79  * destroyed
80  */
81 #define DPRC_IRQ_EVENT_OBJ_DESTROYED            0x00000020
82
83 /* Irq event - Indicates that object is created at the container */
84 #define DPRC_IRQ_EVENT_OBJ_CREATED              0x00000040
85
86 /**
87  * struct dprc_irq_cfg - IRQ configuration
88  * @paddr:      Address that must be written to signal a message-based interrupt
89  * @val:        Value to write into irq_addr address
90  * @irq_num:    A user defined number associated with this IRQ
91  */
92 struct dprc_irq_cfg {
93              phys_addr_t paddr;
94              u32 val;
95              int irq_num;
96 };
97
98 int dprc_set_irq(struct fsl_mc_io *mc_io,
99                  u32 cmd_flags,
100                  u16 token,
101                  u8 irq_index,
102                  struct dprc_irq_cfg *irq_cfg);
103
104 int dprc_get_irq(struct fsl_mc_io *mc_io,
105                  u32 cmd_flags,
106                  u16 token,
107                  u8 irq_index,
108                  int *type,
109                  struct dprc_irq_cfg *irq_cfg);
110
111 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
112                         u32 cmd_flags,
113                         u16 token,
114                         u8 irq_index,
115                         u8 en);
116
117 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
118                         u32 cmd_flags,
119                         u16 token,
120                         u8 irq_index,
121                         u8 *en);
122
123 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
124                       u32 cmd_flags,
125                       u16 token,
126                       u8 irq_index,
127                       u32 mask);
128
129 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
130                       u32 cmd_flags,
131                       u16 token,
132                       u8 irq_index,
133                       u32 *mask);
134
135 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
136                         u32 cmd_flags,
137                         u16 token,
138                         u8 irq_index,
139                         u32 *status);
140
141 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
142                           u32 cmd_flags,
143                           u16 token,
144                           u8 irq_index,
145                           u32 status);
146
147 /**
148  * struct dprc_attributes - Container attributes
149  * @container_id: Container's ID
150  * @icid: Container's ICID
151  * @portal_id: Container's portal ID
152  * @options: Container's options as set at container's creation
153  */
154 struct dprc_attributes {
155         int container_id;
156         u16 icid;
157         int portal_id;
158         u64 options;
159 };
160
161 int dprc_get_attributes(struct fsl_mc_io *mc_io,
162                         u32 cmd_flags,
163                         u16 token,
164                         struct dprc_attributes *attributes);
165
166 int dprc_get_obj_count(struct fsl_mc_io *mc_io,
167                        u32 cmd_flags,
168                        u16 token,
169                        int *obj_count);
170
171 int dprc_get_obj(struct fsl_mc_io *mc_io,
172                  u32 cmd_flags,
173                  u16 token,
174                  int obj_index,
175                  struct fsl_mc_obj_desc *obj_desc);
176
177 int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
178                       u32 cmd_flags,
179                       u16 token,
180                       char *obj_type,
181                       int obj_id,
182                       struct fsl_mc_obj_desc *obj_desc);
183
184 int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
185                      u32 cmd_flags,
186                      u16 token,
187                      char *obj_type,
188                      int obj_id,
189                      u8 irq_index,
190                      struct dprc_irq_cfg *irq_cfg);
191
192 int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
193                      u32 cmd_flags,
194                      u16 token,
195                      char *obj_type,
196                      int obj_id,
197                      u8 irq_index,
198                      int *type,
199                      struct dprc_irq_cfg *irq_cfg);
200
201 int dprc_get_res_count(struct fsl_mc_io *mc_io,
202                        u32 cmd_flags,
203                        u16 token,
204                        char *type,
205                        int *res_count);
206
207 /**
208  * enum dprc_iter_status - Iteration status
209  * @DPRC_ITER_STATUS_FIRST: Perform first iteration
210  * @DPRC_ITER_STATUS_MORE: Indicates more/next iteration is needed
211  * @DPRC_ITER_STATUS_LAST: Indicates last iteration
212  */
213 enum dprc_iter_status {
214         DPRC_ITER_STATUS_FIRST = 0,
215         DPRC_ITER_STATUS_MORE = 1,
216         DPRC_ITER_STATUS_LAST = 2
217 };
218
219 /* Region flags */
220 /* Cacheable - Indicates that region should be mapped as cacheable */
221 #define DPRC_REGION_CACHEABLE   0x00000001
222
223 /**
224  * enum dprc_region_type - Region type
225  * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
226  * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
227  */
228 enum dprc_region_type {
229         DPRC_REGION_TYPE_MC_PORTAL,
230         DPRC_REGION_TYPE_QBMAN_PORTAL
231 };
232
233 /**
234  * struct dprc_region_desc - Mappable region descriptor
235  * @base_offset: Region offset from region's base address.
236  *      For DPMCP and DPRC objects, region base is offset from SoC MC portals
237  *      base address; For DPIO, region base is offset from SoC QMan portals
238  *      base address
239  * @size: Region size (in bytes)
240  * @flags: Region attributes
241  * @type: Portal region type
242  */
243 struct dprc_region_desc {
244         u32 base_offset;
245         u32 size;
246         u32 flags;
247         enum dprc_region_type type;
248 };
249
250 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
251                         u32 cmd_flags,
252                         u16 token,
253                         char *obj_type,
254                         int obj_id,
255                         u8 region_index,
256                         struct dprc_region_desc *region_desc);
257
258 int dprc_get_api_version(struct fsl_mc_io *mc_io,
259                          u32 cmd_flags,
260                          u16 *major_ver,
261                          u16 *minor_ver);
262
263 int dprc_get_container_id(struct fsl_mc_io *mc_io,
264                           u32 cmd_flags,
265                           int *container_id);
266
267 #endif /* _FSL_DPRC_H */
268