1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of the above-listed copyright holders nor the
11 * names of any contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
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
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.
32 #include "../include/mc-sys.h"
33 #include "../include/mc-cmd.h"
36 #include "dpmcp-cmd.h"
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
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
53 * Return: '0' on Success; Error code otherwise.
55 int dpmcp_open(struct fsl_mc_io *mc_io,
60 struct mc_command cmd = { 0 };
61 struct dpmcp_cmd_open *cmd_params;
65 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
67 cmd_params = (struct dpmcp_cmd_open *)cmd.params;
68 cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
70 /* send command to mc*/
71 err = mc_send_command(mc_io, &cmd);
75 /* retrieve response parameters */
76 *token = mc_cmd_hdr_read_token(&cmd);
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
87 * After this function is called, no further operations are
88 * allowed on the object without opening a new control session.
90 * Return: '0' on Success; Error code otherwise.
92 int dpmcp_close(struct fsl_mc_io *mc_io,
96 struct mc_command cmd = { 0 };
99 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
102 /* send command to mc*/
103 return mc_send_command(mc_io, &cmd);
107 * dpmcp_create() - Create the DPMCP object.
108 * @mc_io: Pointer to MC portal's I/O object
109 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
110 * @cfg: Configuration structure
111 * @token: Returned token; use in subsequent API calls
113 * Create the DPMCP object, allocate required resources and
114 * perform required initialization.
116 * The object can be created either by declaring it in the
117 * DPL file, or by calling this function.
118 * This function returns a unique authentication token,
119 * associated with the specific object ID and the specific MC
120 * portal; this token must be used in all subsequent calls to
121 * this specific object. For objects that are created using the
122 * DPL file, call dpmcp_open function to get an authentication
125 * Return: '0' on Success; Error code otherwise.
127 int dpmcp_create(struct fsl_mc_io *mc_io,
129 const struct dpmcp_cfg *cfg,
132 struct mc_command cmd = { 0 };
133 struct dpmcp_cmd_create *cmd_params;
137 /* prepare command */
138 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
140 cmd_params = (struct dpmcp_cmd_create *)cmd.params;
141 cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
143 /* send command to mc*/
144 err = mc_send_command(mc_io, &cmd);
148 /* retrieve response parameters */
149 *token = mc_cmd_hdr_read_token(&cmd);
155 * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
156 * @mc_io: Pointer to MC portal's I/O object
157 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
158 * @token: Token of DPMCP object
160 * Return: '0' on Success; error code otherwise.
162 int dpmcp_destroy(struct fsl_mc_io *mc_io,
166 struct mc_command cmd = { 0 };
168 /* prepare command */
169 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
172 /* send command to mc*/
173 return mc_send_command(mc_io, &cmd);
177 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
178 * @mc_io: Pointer to MC portal's I/O object
179 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
180 * @token: Token of DPMCP object
182 * Return: '0' on Success; Error code otherwise.
184 int dpmcp_reset(struct fsl_mc_io *mc_io,
188 struct mc_command cmd = { 0 };
190 /* prepare command */
191 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
194 /* send command to mc*/
195 return mc_send_command(mc_io, &cmd);
199 * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
200 * @mc_io: Pointer to MC portal's I/O object
201 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
202 * @token: Token of DPMCP object
203 * @irq_index: Identifies the interrupt index to configure
204 * @irq_cfg: IRQ configuration
206 * Return: '0' on Success; Error code otherwise.
208 int dpmcp_set_irq(struct fsl_mc_io *mc_io,
212 struct dpmcp_irq_cfg *irq_cfg)
214 struct mc_command cmd = { 0 };
215 struct dpmcp_cmd_set_irq *cmd_params;
217 /* prepare command */
218 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
220 cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
221 cmd_params->irq_index = irq_index;
222 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
223 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
224 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
226 /* send command to mc*/
227 return mc_send_command(mc_io, &cmd);
231 * dpmcp_get_irq() - Get IRQ information from the DPMCP.
232 * @mc_io: Pointer to MC portal's I/O object
233 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
234 * @token: Token of DPMCP object
235 * @irq_index: The interrupt index to configure
236 * @type: Interrupt type: 0 represents message interrupt
237 * type (both irq_addr and irq_val are valid)
238 * @irq_cfg: IRQ attributes
240 * Return: '0' on Success; Error code otherwise.
242 int dpmcp_get_irq(struct fsl_mc_io *mc_io,
247 struct dpmcp_irq_cfg *irq_cfg)
249 struct mc_command cmd = { 0 };
250 struct dpmcp_cmd_get_irq *cmd_params;
251 struct dpmcp_rsp_get_irq *rsp_params;
254 /* prepare command */
255 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
257 cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
258 cmd_params->irq_index = irq_index;
260 /* send command to mc*/
261 err = mc_send_command(mc_io, &cmd);
265 /* retrieve response parameters */
266 rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
267 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
268 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
269 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
270 *type = le32_to_cpu(rsp_params->type);
275 * dpmcp_set_irq_enable() - Set overall interrupt state.
276 * @mc_io: Pointer to MC portal's I/O object
277 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
278 * @token: Token of DPMCP object
279 * @irq_index: The interrupt index to configure
280 * @en: Interrupt state - enable = 1, disable = 0
282 * Allows GPP software to control when interrupts are generated.
283 * Each interrupt can have up to 32 causes. The enable/disable control's the
284 * overall interrupt state. if the interrupt is disabled no causes will cause
287 * Return: '0' on Success; Error code otherwise.
289 int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
295 struct mc_command cmd = { 0 };
296 struct dpmcp_cmd_set_irq_enable *cmd_params;
298 /* prepare command */
299 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
301 cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
302 cmd_params->enable = en & DPMCP_ENABLE;
303 cmd_params->irq_index = irq_index;
305 /* send command to mc*/
306 return mc_send_command(mc_io, &cmd);
310 * dpmcp_get_irq_enable() - Get overall interrupt state
311 * @mc_io: Pointer to MC portal's I/O object
312 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
313 * @token: Token of DPMCP object
314 * @irq_index: The interrupt index to configure
315 * @en: Returned interrupt state - enable = 1, disable = 0
317 * Return: '0' on Success; Error code otherwise.
319 int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
325 struct mc_command cmd = { 0 };
326 struct dpmcp_cmd_get_irq_enable *cmd_params;
327 struct dpmcp_rsp_get_irq_enable *rsp_params;
330 /* prepare command */
331 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
333 cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
334 cmd_params->irq_index = irq_index;
336 /* send command to mc*/
337 err = mc_send_command(mc_io, &cmd);
341 /* retrieve response parameters */
342 rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
343 *en = rsp_params->enabled & DPMCP_ENABLE;
348 * dpmcp_set_irq_mask() - Set interrupt mask.
349 * @mc_io: Pointer to MC portal's I/O object
350 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
351 * @token: Token of DPMCP object
352 * @irq_index: The interrupt index to configure
353 * @mask: Event mask to trigger interrupt;
356 * 1 = consider event for asserting IRQ
358 * Every interrupt can have up to 32 causes and the interrupt model supports
359 * masking/unmasking each cause independently
361 * Return: '0' on Success; Error code otherwise.
363 int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
369 struct mc_command cmd = { 0 };
370 struct dpmcp_cmd_set_irq_mask *cmd_params;
372 /* prepare command */
373 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
375 cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
376 cmd_params->mask = cpu_to_le32(mask);
377 cmd_params->irq_index = irq_index;
379 /* send command to mc*/
380 return mc_send_command(mc_io, &cmd);
384 * dpmcp_get_irq_mask() - Get interrupt mask.
385 * @mc_io: Pointer to MC portal's I/O object
386 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
387 * @token: Token of DPMCP object
388 * @irq_index: The interrupt index to configure
389 * @mask: Returned event mask to trigger interrupt
391 * Every interrupt can have up to 32 causes and the interrupt model supports
392 * masking/unmasking each cause independently
394 * Return: '0' on Success; Error code otherwise.
396 int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
402 struct mc_command cmd = { 0 };
403 struct dpmcp_cmd_get_irq_mask *cmd_params;
404 struct dpmcp_rsp_get_irq_mask *rsp_params;
408 /* prepare command */
409 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
411 cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
412 cmd_params->irq_index = irq_index;
414 /* send command to mc*/
415 err = mc_send_command(mc_io, &cmd);
419 /* retrieve response parameters */
420 rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
421 *mask = le32_to_cpu(rsp_params->mask);
427 * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
429 * @mc_io: Pointer to MC portal's I/O object
430 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
431 * @token: Token of DPMCP object
432 * @irq_index: The interrupt index to configure
433 * @status: Returned interrupts status - one bit per cause:
434 * 0 = no interrupt pending
435 * 1 = interrupt pending
437 * Return: '0' on Success; Error code otherwise.
439 int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
445 struct mc_command cmd = { 0 };
446 struct dpmcp_cmd_get_irq_status *cmd_params;
447 struct dpmcp_rsp_get_irq_status *rsp_params;
450 /* prepare command */
451 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
453 cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
454 cmd_params->status = cpu_to_le32(*status);
455 cmd_params->irq_index = irq_index;
457 /* send command to mc*/
458 err = mc_send_command(mc_io, &cmd);
462 /* retrieve response parameters */
463 rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
464 *status = le32_to_cpu(rsp_params->status);
470 * dpmcp_get_attributes - Retrieve DPMCP attributes.
472 * @mc_io: Pointer to MC portal's I/O object
473 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
474 * @token: Token of DPMCP object
475 * @attr: Returned object's attributes
477 * Return: '0' on Success; Error code otherwise.
479 int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
482 struct dpmcp_attr *attr)
484 struct mc_command cmd = { 0 };
485 struct dpmcp_rsp_get_attributes *rsp_params;
488 /* prepare command */
489 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
492 /* send command to mc*/
493 err = mc_send_command(mc_io, &cmd);
497 /* retrieve response parameters */
498 rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
499 attr->id = le32_to_cpu(rsp_params->id);
500 attr->version.major = le16_to_cpu(rsp_params->version_major);
501 attr->version.minor = le16_to_cpu(rsp_params->version_minor);