xref: /rk3399_rockchip-uboot/drivers/net/fsl-mc/dpmng.c (revision 7b3bd9a7988a8b4c8ba22a52b4927e8e59819b12)
1*7b3bd9a7SJ. German Rivera /* Copyright 2014 Freescale Semiconductor Inc.
2*7b3bd9a7SJ. German Rivera  *
3*7b3bd9a7SJ. German Rivera  * SPDX-License-Identifier:	GPL-2.0+
4*7b3bd9a7SJ. German Rivera  */
5*7b3bd9a7SJ. German Rivera #include <fsl-mc/fsl_mc_sys.h>
6*7b3bd9a7SJ. German Rivera #include <fsl-mc/fsl_mc_cmd.h>
7*7b3bd9a7SJ. German Rivera #include <fsl-mc/fsl_dpmng.h>
8*7b3bd9a7SJ. German Rivera #include "fsl_dpmng_cmd.h"
9*7b3bd9a7SJ. German Rivera 
10*7b3bd9a7SJ. German Rivera int mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)
11*7b3bd9a7SJ. German Rivera {
12*7b3bd9a7SJ. German Rivera 	struct mc_command cmd = { 0 };
13*7b3bd9a7SJ. German Rivera 	int err;
14*7b3bd9a7SJ. German Rivera 
15*7b3bd9a7SJ. German Rivera 	/* prepare command */
16*7b3bd9a7SJ. German Rivera 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION,
17*7b3bd9a7SJ. German Rivera 					  MC_CMD_PRI_LOW, 0);
18*7b3bd9a7SJ. German Rivera 
19*7b3bd9a7SJ. German Rivera 	/* send command to mc*/
20*7b3bd9a7SJ. German Rivera 	err = mc_send_command(mc_io, &cmd);
21*7b3bd9a7SJ. German Rivera 	if (err)
22*7b3bd9a7SJ. German Rivera 		return err;
23*7b3bd9a7SJ. German Rivera 
24*7b3bd9a7SJ. German Rivera 	/* retrieve response parameters */
25*7b3bd9a7SJ. German Rivera 	DPMNG_RSP_GET_VERSION(cmd, mc_ver_info);
26*7b3bd9a7SJ. German Rivera 
27*7b3bd9a7SJ. German Rivera 	return 0;
28*7b3bd9a7SJ. German Rivera }
29*7b3bd9a7SJ. German Rivera 
30*7b3bd9a7SJ. German Rivera int dpmng_reset_aiop(struct fsl_mc_io *mc_io, int container_id,
31*7b3bd9a7SJ. German Rivera 		     int aiop_tile_id)
32*7b3bd9a7SJ. German Rivera {
33*7b3bd9a7SJ. German Rivera 	struct mc_command cmd = { 0 };
34*7b3bd9a7SJ. German Rivera 
35*7b3bd9a7SJ. German Rivera 	/* prepare command */
36*7b3bd9a7SJ. German Rivera 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_RESET_AIOP,
37*7b3bd9a7SJ. German Rivera 					  MC_CMD_PRI_LOW, 0);
38*7b3bd9a7SJ. German Rivera 	DPMNG_CMD_RESET_AIOP(cmd, container_id, aiop_tile_id);
39*7b3bd9a7SJ. German Rivera 
40*7b3bd9a7SJ. German Rivera 	/* send command to mc*/
41*7b3bd9a7SJ. German Rivera 	return mc_send_command(mc_io, &cmd);
42*7b3bd9a7SJ. German Rivera }
43*7b3bd9a7SJ. German Rivera 
44*7b3bd9a7SJ. German Rivera int dpmng_load_aiop(struct fsl_mc_io *mc_io,
45*7b3bd9a7SJ. German Rivera 		    int container_id,
46*7b3bd9a7SJ. German Rivera 		    int aiop_tile_id,
47*7b3bd9a7SJ. German Rivera 		    uint64_t img_iova,
48*7b3bd9a7SJ. German Rivera 		    uint32_t img_size)
49*7b3bd9a7SJ. German Rivera {
50*7b3bd9a7SJ. German Rivera 	struct mc_command cmd = { 0 };
51*7b3bd9a7SJ. German Rivera 
52*7b3bd9a7SJ. German Rivera 	/* prepare command */
53*7b3bd9a7SJ. German Rivera 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_LOAD_AIOP,
54*7b3bd9a7SJ. German Rivera 					  MC_CMD_PRI_LOW,
55*7b3bd9a7SJ. German Rivera 					  0);
56*7b3bd9a7SJ. German Rivera 	DPMNG_CMD_LOAD_AIOP(cmd, container_id, aiop_tile_id, img_size,
57*7b3bd9a7SJ. German Rivera 			    img_iova);
58*7b3bd9a7SJ. German Rivera 
59*7b3bd9a7SJ. German Rivera 	/* send command to mc*/
60*7b3bd9a7SJ. German Rivera 	return mc_send_command(mc_io, &cmd);
61*7b3bd9a7SJ. German Rivera }
62*7b3bd9a7SJ. German Rivera 
63*7b3bd9a7SJ. German Rivera int dpmng_run_aiop(struct fsl_mc_io *mc_io,
64*7b3bd9a7SJ. German Rivera 		   int container_id,
65*7b3bd9a7SJ. German Rivera 		   int aiop_tile_id,
66*7b3bd9a7SJ. German Rivera 		   const struct dpmng_aiop_run_cfg *cfg)
67*7b3bd9a7SJ. German Rivera {
68*7b3bd9a7SJ. German Rivera 	struct mc_command cmd = { 0 };
69*7b3bd9a7SJ. German Rivera 
70*7b3bd9a7SJ. German Rivera 	/* prepare command */
71*7b3bd9a7SJ. German Rivera 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_RUN_AIOP,
72*7b3bd9a7SJ. German Rivera 					  MC_CMD_PRI_LOW,
73*7b3bd9a7SJ. German Rivera 					  0);
74*7b3bd9a7SJ. German Rivera 	DPMNG_CMD_RUN_AIOP(cmd, container_id, aiop_tile_id, cfg);
75*7b3bd9a7SJ. German Rivera 
76*7b3bd9a7SJ. German Rivera 	/* send command to mc*/
77*7b3bd9a7SJ. German Rivera 	return mc_send_command(mc_io, &cmd);
78*7b3bd9a7SJ. German Rivera }
79*7b3bd9a7SJ. German Rivera 
80*7b3bd9a7SJ. German Rivera int dpmng_reset_mc_portal(struct fsl_mc_io *mc_io)
81*7b3bd9a7SJ. German Rivera {
82*7b3bd9a7SJ. German Rivera 	struct mc_command cmd = { 0 };
83*7b3bd9a7SJ. German Rivera 
84*7b3bd9a7SJ. German Rivera 	/* prepare command */
85*7b3bd9a7SJ. German Rivera 	cmd.header = mc_encode_cmd_header(DPMNG_CMDID_RESET_MC_PORTAL,
86*7b3bd9a7SJ. German Rivera 					  MC_CMD_PRI_LOW,
87*7b3bd9a7SJ. German Rivera 					  0);
88*7b3bd9a7SJ. German Rivera 
89*7b3bd9a7SJ. German Rivera 	/* send command to mc*/
90*7b3bd9a7SJ. German Rivera 	return mc_send_command(mc_io, &cmd);
91*7b3bd9a7SJ. German Rivera }
92