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"
35 #include "dpmcp-cmd.h"
38 * dpmcp_open() - Open a control session for the specified object.
39 * @mc_io: Pointer to MC portal's I/O object
40 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
41 * @dpmcp_id: DPMCP unique ID
42 * @token: Returned token; use in subsequent API calls
44 * This function can be used to open a control session for an
45 * already created object; an object may have been declared in
46 * the DPL or by calling the dpmcp_create function.
47 * This function returns a unique authentication token,
48 * associated with the specific object ID and the specific MC
49 * portal; this token must be used in all subsequent commands for
50 * this specific object
52 * Return: '0' on Success; Error code otherwise.
54 int dpmcp_open(struct fsl_mc_io *mc_io,
59 struct mc_command cmd = { 0 };
60 struct dpmcp_cmd_open *cmd_params;
64 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
66 cmd_params = (struct dpmcp_cmd_open *)cmd.params;
67 cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
69 /* send command to mc*/
70 err = mc_send_command(mc_io, &cmd);
74 /* retrieve response parameters */
75 *token = mc_cmd_hdr_read_token(&cmd);
81 * dpmcp_close() - Close the control session of the object
82 * @mc_io: Pointer to MC portal's I/O object
83 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
84 * @token: Token of DPMCP object
86 * After this function is called, no further operations are
87 * allowed on the object without opening a new control session.
89 * Return: '0' on Success; Error code otherwise.
91 int dpmcp_close(struct fsl_mc_io *mc_io,
95 struct mc_command cmd = { 0 };
98 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
101 /* send command to mc*/
102 return mc_send_command(mc_io, &cmd);
106 * dpmcp_create() - Create the DPMCP object.
107 * @mc_io: Pointer to MC portal's I/O object
108 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
109 * @cfg: Configuration structure
110 * @token: Returned token; use in subsequent API calls
112 * Create the DPMCP object, allocate required resources and
113 * perform required initialization.
115 * The object can be created either by declaring it in the
116 * DPL file, or by calling this function.
117 * This function returns a unique authentication token,
118 * associated with the specific object ID and the specific MC
119 * portal; this token must be used in all subsequent calls to
120 * this specific object. For objects that are created using the
121 * DPL file, call dpmcp_open function to get an authentication
124 * Return: '0' on Success; Error code otherwise.
126 int dpmcp_create(struct fsl_mc_io *mc_io,
128 const struct dpmcp_cfg *cfg,
131 struct mc_command cmd = { 0 };
132 struct dpmcp_cmd_create *cmd_params;
136 /* prepare command */
137 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
139 cmd_params = (struct dpmcp_cmd_create *)cmd.params;
140 cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
142 /* send command to mc*/
143 err = mc_send_command(mc_io, &cmd);
147 /* retrieve response parameters */
148 *token = mc_cmd_hdr_read_token(&cmd);
154 * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
155 * @mc_io: Pointer to MC portal's I/O object
156 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
157 * @token: Token of DPMCP object
159 * Return: '0' on Success; error code otherwise.
161 int dpmcp_destroy(struct fsl_mc_io *mc_io,
165 struct mc_command cmd = { 0 };
167 /* prepare command */
168 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
171 /* send command to mc*/
172 return mc_send_command(mc_io, &cmd);
176 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
177 * @mc_io: Pointer to MC portal's I/O object
178 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
179 * @token: Token of DPMCP object
181 * Return: '0' on Success; Error code otherwise.
183 int dpmcp_reset(struct fsl_mc_io *mc_io,
187 struct mc_command cmd = { 0 };
189 /* prepare command */
190 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
193 /* send command to mc*/
194 return mc_send_command(mc_io, &cmd);
198 * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
199 * @mc_io: Pointer to MC portal's I/O object
200 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
201 * @token: Token of DPMCP object
202 * @irq_index: Identifies the interrupt index to configure
203 * @irq_cfg: IRQ configuration
205 * Return: '0' on Success; Error code otherwise.
207 int dpmcp_set_irq(struct fsl_mc_io *mc_io,
211 struct dpmcp_irq_cfg *irq_cfg)
213 struct mc_command cmd = { 0 };
214 struct dpmcp_cmd_set_irq *cmd_params;
216 /* prepare command */
217 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
219 cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
220 cmd_params->irq_index = irq_index;
221 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
222 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
223 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
225 /* send command to mc*/
226 return mc_send_command(mc_io, &cmd);
230 * dpmcp_get_irq() - Get IRQ information from the DPMCP.
231 * @mc_io: Pointer to MC portal's I/O object
232 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
233 * @token: Token of DPMCP object
234 * @irq_index: The interrupt index to configure
235 * @type: Interrupt type: 0 represents message interrupt
236 * type (both irq_addr and irq_val are valid)
237 * @irq_cfg: IRQ attributes
239 * Return: '0' on Success; Error code otherwise.
241 int dpmcp_get_irq(struct fsl_mc_io *mc_io,
246 struct dpmcp_irq_cfg *irq_cfg)
248 struct mc_command cmd = { 0 };
249 struct dpmcp_cmd_get_irq *cmd_params;
250 struct dpmcp_rsp_get_irq *rsp_params;
253 /* prepare command */
254 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
256 cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
257 cmd_params->irq_index = irq_index;
259 /* send command to mc*/
260 err = mc_send_command(mc_io, &cmd);
264 /* retrieve response parameters */
265 rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
266 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
267 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
268 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
269 *type = le32_to_cpu(rsp_params->type);
274 * dpmcp_set_irq_enable() - Set overall interrupt state.
275 * @mc_io: Pointer to MC portal's I/O object
276 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
277 * @token: Token of DPMCP object
278 * @irq_index: The interrupt index to configure
279 * @en: Interrupt state - enable = 1, disable = 0
281 * Allows GPP software to control when interrupts are generated.
282 * Each interrupt can have up to 32 causes. The enable/disable control's the
283 * overall interrupt state. if the interrupt is disabled no causes will cause
286 * Return: '0' on Success; Error code otherwise.
288 int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
294 struct mc_command cmd = { 0 };
295 struct dpmcp_cmd_set_irq_enable *cmd_params;
297 /* prepare command */
298 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
300 cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
301 cmd_params->enable = en & DPMCP_ENABLE;
302 cmd_params->irq_index = irq_index;
304 /* send command to mc*/
305 return mc_send_command(mc_io, &cmd);
309 * dpmcp_get_irq_enable() - Get overall interrupt state
310 * @mc_io: Pointer to MC portal's I/O object
311 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
312 * @token: Token of DPMCP object
313 * @irq_index: The interrupt index to configure
314 * @en: Returned interrupt state - enable = 1, disable = 0
316 * Return: '0' on Success; Error code otherwise.
318 int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
324 struct mc_command cmd = { 0 };
325 struct dpmcp_cmd_get_irq_enable *cmd_params;
326 struct dpmcp_rsp_get_irq_enable *rsp_params;
329 /* prepare command */
330 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
332 cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
333 cmd_params->irq_index = irq_index;
335 /* send command to mc*/
336 err = mc_send_command(mc_io, &cmd);
340 /* retrieve response parameters */
341 rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
342 *en = rsp_params->enabled & DPMCP_ENABLE;
347 * dpmcp_set_irq_mask() - Set interrupt mask.
348 * @mc_io: Pointer to MC portal's I/O object
349 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
350 * @token: Token of DPMCP object
351 * @irq_index: The interrupt index to configure
352 * @mask: Event mask to trigger interrupt;
355 * 1 = consider event for asserting IRQ
357 * Every interrupt can have up to 32 causes and the interrupt model supports
358 * masking/unmasking each cause independently
360 * Return: '0' on Success; Error code otherwise.
362 int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
368 struct mc_command cmd = { 0 };
369 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);