1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Freescale Layerscape MC I/O wrapper
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2013-2015 Freescale Semiconductor, Inc.
5*4882a593Smuzhiyun * Author: German Rivera <German.Rivera@freescale.com>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #include <fsl-mc/fsl_mc_sys.h>
11*4882a593Smuzhiyun #include <fsl-mc/fsl_mc_cmd.h>
12*4882a593Smuzhiyun #include <fsl-mc/fsl_dprc.h>
13*4882a593Smuzhiyun
dprc_get_container_id(struct fsl_mc_io * mc_io,uint32_t cmd_flags,int * container_id)14*4882a593Smuzhiyun int dprc_get_container_id(struct fsl_mc_io *mc_io,
15*4882a593Smuzhiyun uint32_t cmd_flags,
16*4882a593Smuzhiyun int *container_id)
17*4882a593Smuzhiyun {
18*4882a593Smuzhiyun struct mc_command cmd = { 0 };
19*4882a593Smuzhiyun int err;
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun /* prepare command */
22*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
23*4882a593Smuzhiyun cmd_flags,
24*4882a593Smuzhiyun 0);
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun /* send command to mc*/
27*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
28*4882a593Smuzhiyun if (err)
29*4882a593Smuzhiyun return err;
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun /* retrieve response parameters */
32*4882a593Smuzhiyun DPRC_RSP_GET_CONTAINER_ID(cmd, *container_id);
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun return 0;
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun
dprc_open(struct fsl_mc_io * mc_io,uint32_t cmd_flags,int container_id,uint16_t * token)37*4882a593Smuzhiyun int dprc_open(struct fsl_mc_io *mc_io,
38*4882a593Smuzhiyun uint32_t cmd_flags,
39*4882a593Smuzhiyun int container_id,
40*4882a593Smuzhiyun uint16_t *token)
41*4882a593Smuzhiyun {
42*4882a593Smuzhiyun struct mc_command cmd = { 0 };
43*4882a593Smuzhiyun int err;
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun /* prepare command */
46*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
47*4882a593Smuzhiyun 0);
48*4882a593Smuzhiyun DPRC_CMD_OPEN(cmd, container_id);
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun /* send command to mc*/
51*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
52*4882a593Smuzhiyun if (err)
53*4882a593Smuzhiyun return err;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun /* retrieve response parameters */
56*4882a593Smuzhiyun *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun return 0;
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
dprc_close(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token)61*4882a593Smuzhiyun int dprc_close(struct fsl_mc_io *mc_io,
62*4882a593Smuzhiyun uint32_t cmd_flags,
63*4882a593Smuzhiyun uint16_t token)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun struct mc_command cmd = { 0 };
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun /* prepare command */
68*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
69*4882a593Smuzhiyun token);
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* send command to mc*/
72*4882a593Smuzhiyun return mc_send_command(mc_io, &cmd);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
dprc_create_container(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,struct dprc_cfg * cfg,int * child_container_id,uint64_t * child_portal_paddr)75*4882a593Smuzhiyun int dprc_create_container(struct fsl_mc_io *mc_io,
76*4882a593Smuzhiyun uint32_t cmd_flags,
77*4882a593Smuzhiyun uint16_t token,
78*4882a593Smuzhiyun struct dprc_cfg *cfg,
79*4882a593Smuzhiyun int *child_container_id,
80*4882a593Smuzhiyun uint64_t *child_portal_paddr)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun struct mc_command cmd = { 0 };
83*4882a593Smuzhiyun int err;
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun /* prepare command */
86*4882a593Smuzhiyun DPRC_CMD_CREATE_CONTAINER(cmd, cfg);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
89*4882a593Smuzhiyun cmd_flags,
90*4882a593Smuzhiyun token);
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /* send command to mc*/
93*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
94*4882a593Smuzhiyun if (err)
95*4882a593Smuzhiyun return err;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /* retrieve response parameters */
98*4882a593Smuzhiyun DPRC_RSP_CREATE_CONTAINER(cmd, *child_container_id,
99*4882a593Smuzhiyun *child_portal_paddr);
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun return 0;
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun
dprc_destroy_container(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,int child_container_id)104*4882a593Smuzhiyun int dprc_destroy_container(struct fsl_mc_io *mc_io,
105*4882a593Smuzhiyun uint32_t cmd_flags,
106*4882a593Smuzhiyun uint16_t token,
107*4882a593Smuzhiyun int child_container_id)
108*4882a593Smuzhiyun {
109*4882a593Smuzhiyun struct mc_command cmd = { 0 };
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun /* prepare command */
112*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
113*4882a593Smuzhiyun cmd_flags,
114*4882a593Smuzhiyun token);
115*4882a593Smuzhiyun DPRC_CMD_DESTROY_CONTAINER(cmd, child_container_id);
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun /* send command to mc*/
118*4882a593Smuzhiyun return mc_send_command(mc_io, &cmd);
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun
dprc_reset_container(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,int child_container_id)121*4882a593Smuzhiyun int dprc_reset_container(struct fsl_mc_io *mc_io,
122*4882a593Smuzhiyun uint32_t cmd_flags,
123*4882a593Smuzhiyun uint16_t token,
124*4882a593Smuzhiyun int child_container_id)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun struct mc_command cmd = { 0 };
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun /* prepare command */
129*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
130*4882a593Smuzhiyun cmd_flags,
131*4882a593Smuzhiyun token);
132*4882a593Smuzhiyun DPRC_CMD_RESET_CONTAINER(cmd, child_container_id);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun /* send command to mc*/
135*4882a593Smuzhiyun return mc_send_command(mc_io, &cmd);
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
dprc_get_attributes(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,struct dprc_attributes * attr)138*4882a593Smuzhiyun int dprc_get_attributes(struct fsl_mc_io *mc_io,
139*4882a593Smuzhiyun uint32_t cmd_flags,
140*4882a593Smuzhiyun uint16_t token,
141*4882a593Smuzhiyun struct dprc_attributes *attr)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun struct mc_command cmd = { 0 };
144*4882a593Smuzhiyun int err;
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun /* prepare command */
147*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
148*4882a593Smuzhiyun cmd_flags,
149*4882a593Smuzhiyun token);
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun /* send command to mc*/
152*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
153*4882a593Smuzhiyun if (err)
154*4882a593Smuzhiyun return err;
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /* retrieve response parameters */
157*4882a593Smuzhiyun DPRC_RSP_GET_ATTRIBUTES(cmd, attr);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun return 0;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun
dprc_get_obj_count(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,int * obj_count)162*4882a593Smuzhiyun int dprc_get_obj_count(struct fsl_mc_io *mc_io,
163*4882a593Smuzhiyun uint32_t cmd_flags,
164*4882a593Smuzhiyun uint16_t token,
165*4882a593Smuzhiyun int *obj_count)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun struct mc_command cmd = { 0 };
168*4882a593Smuzhiyun int err;
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /* prepare command */
171*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
172*4882a593Smuzhiyun cmd_flags,
173*4882a593Smuzhiyun token);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /* send command to mc*/
176*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
177*4882a593Smuzhiyun if (err)
178*4882a593Smuzhiyun return err;
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /* retrieve response parameters */
181*4882a593Smuzhiyun DPRC_RSP_GET_OBJ_COUNT(cmd, *obj_count);
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun return 0;
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun
dprc_get_obj(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,int obj_index,struct dprc_obj_desc * obj_desc)186*4882a593Smuzhiyun int dprc_get_obj(struct fsl_mc_io *mc_io,
187*4882a593Smuzhiyun uint32_t cmd_flags,
188*4882a593Smuzhiyun uint16_t token,
189*4882a593Smuzhiyun int obj_index,
190*4882a593Smuzhiyun struct dprc_obj_desc *obj_desc)
191*4882a593Smuzhiyun {
192*4882a593Smuzhiyun struct mc_command cmd = { 0 };
193*4882a593Smuzhiyun int err;
194*4882a593Smuzhiyun
195*4882a593Smuzhiyun /* prepare command */
196*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
197*4882a593Smuzhiyun cmd_flags,
198*4882a593Smuzhiyun token);
199*4882a593Smuzhiyun DPRC_CMD_GET_OBJ(cmd, obj_index);
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun /* send command to mc*/
202*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
203*4882a593Smuzhiyun if (err)
204*4882a593Smuzhiyun return err;
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun /* retrieve response parameters */
207*4882a593Smuzhiyun DPRC_RSP_GET_OBJ(cmd, obj_desc);
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun return 0;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun
dprc_get_res_count(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,char * type,int * res_count)212*4882a593Smuzhiyun int dprc_get_res_count(struct fsl_mc_io *mc_io,
213*4882a593Smuzhiyun uint32_t cmd_flags,
214*4882a593Smuzhiyun uint16_t token,
215*4882a593Smuzhiyun char *type,
216*4882a593Smuzhiyun int *res_count)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun struct mc_command cmd = { 0 };
219*4882a593Smuzhiyun int err;
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun *res_count = 0;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun /* prepare command */
224*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
225*4882a593Smuzhiyun cmd_flags,
226*4882a593Smuzhiyun token);
227*4882a593Smuzhiyun DPRC_CMD_GET_RES_COUNT(cmd, type);
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun /* send command to mc*/
230*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
231*4882a593Smuzhiyun if (err)
232*4882a593Smuzhiyun return err;
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun /* retrieve response parameters */
235*4882a593Smuzhiyun DPRC_RSP_GET_RES_COUNT(cmd, *res_count);
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun return 0;
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun
dprc_get_res_ids(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,char * type,struct dprc_res_ids_range_desc * range_desc)240*4882a593Smuzhiyun int dprc_get_res_ids(struct fsl_mc_io *mc_io,
241*4882a593Smuzhiyun uint32_t cmd_flags,
242*4882a593Smuzhiyun uint16_t token,
243*4882a593Smuzhiyun char *type,
244*4882a593Smuzhiyun struct dprc_res_ids_range_desc *range_desc)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun struct mc_command cmd = { 0 };
247*4882a593Smuzhiyun int err;
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun /* prepare command */
250*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
251*4882a593Smuzhiyun cmd_flags,
252*4882a593Smuzhiyun token);
253*4882a593Smuzhiyun DPRC_CMD_GET_RES_IDS(cmd, range_desc, type);
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun /* send command to mc*/
256*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
257*4882a593Smuzhiyun if (err)
258*4882a593Smuzhiyun return err;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /* retrieve response parameters */
261*4882a593Smuzhiyun DPRC_RSP_GET_RES_IDS(cmd, range_desc);
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun return 0;
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun
dprc_get_obj_region(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,char * obj_type,int obj_id,uint8_t region_index,struct dprc_region_desc * region_desc)266*4882a593Smuzhiyun int dprc_get_obj_region(struct fsl_mc_io *mc_io,
267*4882a593Smuzhiyun uint32_t cmd_flags,
268*4882a593Smuzhiyun uint16_t token,
269*4882a593Smuzhiyun char *obj_type,
270*4882a593Smuzhiyun int obj_id,
271*4882a593Smuzhiyun uint8_t region_index,
272*4882a593Smuzhiyun struct dprc_region_desc *region_desc)
273*4882a593Smuzhiyun {
274*4882a593Smuzhiyun struct mc_command cmd = { 0 };
275*4882a593Smuzhiyun int err;
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun /* prepare command */
278*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
279*4882a593Smuzhiyun cmd_flags,
280*4882a593Smuzhiyun token);
281*4882a593Smuzhiyun DPRC_CMD_GET_OBJ_REGION(cmd, obj_type, obj_id, region_index);
282*4882a593Smuzhiyun
283*4882a593Smuzhiyun /* send command to mc*/
284*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
285*4882a593Smuzhiyun if (err)
286*4882a593Smuzhiyun return err;
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /* retrieve response parameters */
289*4882a593Smuzhiyun DPRC_RSP_GET_OBJ_REGION(cmd, region_desc);
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun return 0;
292*4882a593Smuzhiyun }
293*4882a593Smuzhiyun
dprc_connect(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,const struct dprc_endpoint * endpoint1,const struct dprc_endpoint * endpoint2,const struct dprc_connection_cfg * cfg)294*4882a593Smuzhiyun int dprc_connect(struct fsl_mc_io *mc_io,
295*4882a593Smuzhiyun uint32_t cmd_flags,
296*4882a593Smuzhiyun uint16_t token,
297*4882a593Smuzhiyun const struct dprc_endpoint *endpoint1,
298*4882a593Smuzhiyun const struct dprc_endpoint *endpoint2,
299*4882a593Smuzhiyun const struct dprc_connection_cfg *cfg)
300*4882a593Smuzhiyun {
301*4882a593Smuzhiyun struct mc_command cmd = { 0 };
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun /* prepare command */
304*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
305*4882a593Smuzhiyun cmd_flags,
306*4882a593Smuzhiyun token);
307*4882a593Smuzhiyun DPRC_CMD_CONNECT(cmd, endpoint1, endpoint2, cfg);
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun /* send command to mc*/
310*4882a593Smuzhiyun return mc_send_command(mc_io, &cmd);
311*4882a593Smuzhiyun }
312*4882a593Smuzhiyun
dprc_disconnect(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,const struct dprc_endpoint * endpoint)313*4882a593Smuzhiyun int dprc_disconnect(struct fsl_mc_io *mc_io,
314*4882a593Smuzhiyun uint32_t cmd_flags,
315*4882a593Smuzhiyun uint16_t token,
316*4882a593Smuzhiyun const struct dprc_endpoint *endpoint)
317*4882a593Smuzhiyun {
318*4882a593Smuzhiyun struct mc_command cmd = { 0 };
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun /* prepare command */
321*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
322*4882a593Smuzhiyun cmd_flags,
323*4882a593Smuzhiyun token);
324*4882a593Smuzhiyun DPRC_CMD_DISCONNECT(cmd, endpoint);
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun /* send command to mc*/
327*4882a593Smuzhiyun return mc_send_command(mc_io, &cmd);
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun
dprc_get_connection(struct fsl_mc_io * mc_io,uint32_t cmd_flags,uint16_t token,const struct dprc_endpoint * endpoint1,struct dprc_endpoint * endpoint2,int * state)330*4882a593Smuzhiyun int dprc_get_connection(struct fsl_mc_io *mc_io,
331*4882a593Smuzhiyun uint32_t cmd_flags,
332*4882a593Smuzhiyun uint16_t token,
333*4882a593Smuzhiyun const struct dprc_endpoint *endpoint1,
334*4882a593Smuzhiyun struct dprc_endpoint *endpoint2,
335*4882a593Smuzhiyun int *state)
336*4882a593Smuzhiyun {
337*4882a593Smuzhiyun struct mc_command cmd = { 0 };
338*4882a593Smuzhiyun int err;
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun /* prepare command */
341*4882a593Smuzhiyun cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
342*4882a593Smuzhiyun cmd_flags,
343*4882a593Smuzhiyun token);
344*4882a593Smuzhiyun DPRC_CMD_GET_CONNECTION(cmd, endpoint1);
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /* send command to mc*/
347*4882a593Smuzhiyun err = mc_send_command(mc_io, &cmd);
348*4882a593Smuzhiyun if (err)
349*4882a593Smuzhiyun return err;
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun /* retrieve response parameters */
352*4882a593Smuzhiyun DPRC_RSP_GET_CONNECTION(cmd, endpoint2, *state);
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun return 0;
355*4882a593Smuzhiyun }
356