]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/fsl-mc/bus/dpmcp.c
Merge tag 'gvt-next-2017-02-24' of https://github.com/01org/gvt-linux into drm-intel...
[karo-tx-linux.git] / drivers / staging / fsl-mc / bus / dpmcp.c
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  * 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 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
34
35 #include "dpmcp.h"
36 #include "dpmcp-cmd.h"
37
38 /**
39  * dpmcp_open() - Open a control session for the specified object.
40  * @mc_io:      Pointer to MC portal's I/O object
41  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
42  * @dpmcp_id:   DPMCP unique ID
43  * @token:      Returned token; use in subsequent API calls
44  *
45  * This function can be used to open a control session for an
46  * already created object; an object may have been declared in
47  * the DPL or by calling the dpmcp_create function.
48  * This function returns a unique authentication token,
49  * associated with the specific object ID and the specific MC
50  * portal; this token must be used in all subsequent commands for
51  * this specific object
52  *
53  * Return:      '0' on Success; Error code otherwise.
54  */
55 int dpmcp_open(struct fsl_mc_io *mc_io,
56                u32 cmd_flags,
57                int dpmcp_id,
58                u16 *token)
59 {
60         struct mc_command cmd = { 0 };
61         struct dpmcp_cmd_open *cmd_params;
62         int err;
63
64         /* prepare command */
65         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
66                                           cmd_flags, 0);
67         cmd_params = (struct dpmcp_cmd_open *)cmd.params;
68         cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
69
70         /* send command to mc*/
71         err = mc_send_command(mc_io, &cmd);
72         if (err)
73                 return err;
74
75         /* retrieve response parameters */
76         *token = mc_cmd_hdr_read_token(&cmd);
77
78         return err;
79 }
80
81 /**
82  * dpmcp_close() - Close the control session of the object
83  * @mc_io:      Pointer to MC portal's I/O object
84  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
85  * @token:      Token of DPMCP object
86  *
87  * After this function is called, no further operations are
88  * allowed on the object without opening a new control session.
89  *
90  * Return:      '0' on Success; Error code otherwise.
91  */
92 int dpmcp_close(struct fsl_mc_io *mc_io,
93                 u32 cmd_flags,
94                 u16 token)
95 {
96         struct mc_command cmd = { 0 };
97
98         /* prepare command */
99         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
100                                           cmd_flags, token);
101
102         /* send command to mc*/
103         return mc_send_command(mc_io, &cmd);
104 }
105
106 /**
107  * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
108  * @mc_io:      Pointer to MC portal's I/O object
109  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
110  * @token:      Token of DPMCP object
111  *
112  * Return:      '0' on Success; Error code otherwise.
113  */
114 int dpmcp_reset(struct fsl_mc_io *mc_io,
115                 u32 cmd_flags,
116                 u16 token)
117 {
118         struct mc_command cmd = { 0 };
119
120         /* prepare command */
121         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
122                                           cmd_flags, token);
123
124         /* send command to mc*/
125         return mc_send_command(mc_io, &cmd);
126 }
127
128 /**
129  * dpmcp_get_api_version - Get Data Path Management Command Portal API version
130  * @mc_io:      Pointer to Mc portal's I/O object
131  * @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
132  * @major_ver:  Major version of Data Path Management Command Portal API
133  * @minor_ver:  Minor version of Data Path Management Command Portal API
134  *
135  * Return:      '0' on Success; Error code otherwise.
136  */
137 int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
138                           u32 cmd_flags,
139                           u16 *major_ver,
140                           u16 *minor_ver)
141 {
142         struct mc_command cmd = { 0 };
143         int err;
144
145         /* prepare command */
146         cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
147                                           cmd_flags, 0);
148
149         /* send command to mc */
150         err = mc_send_command(mc_io, &cmd);
151         if (err)
152                 return err;
153
154         /* retrieve response parameters */
155         mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
156
157         return 0;
158 }