1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /*
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 *
5 */
6 #include <linux/kernel.h>
7 #include <linux/fsl/mc.h>
8
9 #include "fsl-mc-private.h"
10
11 /**
12 * dpmcp_open() - Open a control session for the specified object.
13 * @mc_io: Pointer to MC portal's I/O object
14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
15 * @dpmcp_id: DPMCP unique ID
16 * @token: Returned token; use in subsequent API calls
17 *
18 * This function can be used to open a control session for an
19 * already created object; an object may have been declared in
20 * the DPL or by calling the dpmcp_create function.
21 * This function returns a unique authentication token,
22 * associated with the specific object ID and the specific MC
23 * portal; this token must be used in all subsequent commands for
24 * this specific object
25 *
26 * Return: '0' on Success; Error code otherwise.
27 */
dpmcp_open(struct fsl_mc_io * mc_io,u32 cmd_flags,int dpmcp_id,u16 * token)28 int dpmcp_open(struct fsl_mc_io *mc_io,
29 u32 cmd_flags,
30 int dpmcp_id,
31 u16 *token)
32 {
33 struct fsl_mc_command cmd = { 0 };
34 struct dpmcp_cmd_open *cmd_params;
35 int err;
36
37 /* prepare command */
38 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
39 cmd_flags, 0);
40 cmd_params = (struct dpmcp_cmd_open *)cmd.params;
41 cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
42
43 /* send command to mc*/
44 err = mc_send_command(mc_io, &cmd);
45 if (err)
46 return err;
47
48 /* retrieve response parameters */
49 *token = mc_cmd_hdr_read_token(&cmd);
50
51 return err;
52 }
53
54 /**
55 * dpmcp_close() - Close the control session of the object
56 * @mc_io: Pointer to MC portal's I/O object
57 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
58 * @token: Token of DPMCP object
59 *
60 * After this function is called, no further operations are
61 * allowed on the object without opening a new control session.
62 *
63 * Return: '0' on Success; Error code otherwise.
64 */
dpmcp_close(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)65 int dpmcp_close(struct fsl_mc_io *mc_io,
66 u32 cmd_flags,
67 u16 token)
68 {
69 struct fsl_mc_command cmd = { 0 };
70
71 /* prepare command */
72 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
73 cmd_flags, token);
74
75 /* send command to mc*/
76 return mc_send_command(mc_io, &cmd);
77 }
78
79 /**
80 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
81 * @mc_io: Pointer to MC portal's I/O object
82 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
83 * @token: Token of DPMCP object
84 *
85 * Return: '0' on Success; Error code otherwise.
86 */
dpmcp_reset(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)87 int dpmcp_reset(struct fsl_mc_io *mc_io,
88 u32 cmd_flags,
89 u16 token)
90 {
91 struct fsl_mc_command cmd = { 0 };
92
93 /* prepare command */
94 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
95 cmd_flags, token);
96
97 /* send command to mc*/
98 return mc_send_command(mc_io, &cmd);
99 }
100