Bogdan Purcareata | 203e2de | 2018-01-17 18:36:44 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
Stuart Yoder | 363b0cb | 2016-10-26 11:20:28 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2013-2016 Freescale Semiconductor Inc. |
Ramiro Oliveira | f86a180 | 2016-09-30 15:01:21 +0100 | [diff] [blame] | 4 | * |
Ramiro Oliveira | f86a180 | 2016-09-30 15:01:21 +0100 | [diff] [blame] | 5 | */ |
Laurentiu Tudor | 409acdd | 2017-06-27 17:41:32 +0300 | [diff] [blame] | 6 | #include <linux/kernel.h> |
Bogdan Purcareata | 6bd067c | 2018-02-05 08:07:42 -0600 | [diff] [blame] | 7 | #include <linux/fsl/mc.h> |
| 8 | |
Bogdan Purcareata | 39d14e4 | 2018-01-16 15:19:04 +0200 | [diff] [blame] | 9 | #include "fsl-mc-private.h" |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 10 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 11 | /** |
| 12 | * dprc_open() - Open DPRC object for use |
| 13 | * @mc_io: Pointer to MC portal's I/O object |
| 14 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 15 | * @container_id: Container ID to open |
| 16 | * @token: Returned token of DPRC object |
| 17 | * |
| 18 | * Return: '0' on Success; Error code otherwise. |
| 19 | * |
| 20 | * @warning Required before any operation on the object. |
| 21 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 22 | int dprc_open(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 23 | u32 cmd_flags, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 24 | int container_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 25 | u16 *token) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 26 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 27 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 28 | struct dprc_cmd_open *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 29 | int err; |
| 30 | |
| 31 | /* prepare command */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 32 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 33 | 0); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 34 | cmd_params = (struct dprc_cmd_open *)cmd.params; |
| 35 | cmd_params->container_id = cpu_to_le32(container_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 36 | |
| 37 | /* send command to mc*/ |
| 38 | err = mc_send_command(mc_io, &cmd); |
| 39 | if (err) |
| 40 | return err; |
| 41 | |
| 42 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 43 | *token = mc_cmd_hdr_read_token(&cmd); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 44 | |
| 45 | return 0; |
| 46 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 47 | EXPORT_SYMBOL_GPL(dprc_open); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 48 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 49 | /** |
| 50 | * dprc_close() - Close the control session of the object |
| 51 | * @mc_io: Pointer to MC portal's I/O object |
| 52 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 53 | * @token: Token of DPRC object |
| 54 | * |
| 55 | * After this function is called, no further operations are |
| 56 | * allowed on the object without opening a new control session. |
| 57 | * |
| 58 | * Return: '0' on Success; Error code otherwise. |
| 59 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 60 | int dprc_close(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 61 | u32 cmd_flags, |
| 62 | u16 token) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 63 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 64 | struct fsl_mc_command cmd = { 0 }; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 65 | |
| 66 | /* prepare command */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 67 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 68 | token); |
| 69 | |
| 70 | /* send command to mc*/ |
| 71 | return mc_send_command(mc_io, &cmd); |
| 72 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 73 | EXPORT_SYMBOL_GPL(dprc_close); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 74 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 75 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 76 | * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt. |
| 77 | * @mc_io: Pointer to MC portal's I/O object |
| 78 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 79 | * @token: Token of DPRC object |
| 80 | * @irq_index: Identifies the interrupt index to configure |
| 81 | * @irq_cfg: IRQ configuration |
| 82 | * |
| 83 | * Return: '0' on Success; Error code otherwise. |
| 84 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 85 | int dprc_set_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 86 | u32 cmd_flags, |
| 87 | u16 token, |
| 88 | u8 irq_index, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 89 | struct dprc_irq_cfg *irq_cfg) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 90 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 91 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 92 | struct dprc_cmd_set_irq *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 93 | |
| 94 | /* prepare command */ |
| 95 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 96 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 97 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 98 | cmd_params = (struct dprc_cmd_set_irq *)cmd.params; |
| 99 | cmd_params->irq_val = cpu_to_le32(irq_cfg->val); |
| 100 | cmd_params->irq_index = irq_index; |
| 101 | cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr); |
| 102 | cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 103 | |
| 104 | /* send command to mc*/ |
| 105 | return mc_send_command(mc_io, &cmd); |
| 106 | } |
| 107 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 108 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 109 | * dprc_set_irq_enable() - Set overall interrupt state. |
| 110 | * @mc_io: Pointer to MC portal's I/O object |
| 111 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 112 | * @token: Token of DPRC object |
| 113 | * @irq_index: The interrupt index to configure |
| 114 | * @en: Interrupt state - enable = 1, disable = 0 |
| 115 | * |
| 116 | * Allows GPP software to control when interrupts are generated. |
| 117 | * Each interrupt can have up to 32 causes. The enable/disable control's the |
| 118 | * overall interrupt state. if the interrupt is disabled no causes will cause |
| 119 | * an interrupt. |
| 120 | * |
| 121 | * Return: '0' on Success; Error code otherwise. |
| 122 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 123 | int dprc_set_irq_enable(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 124 | u32 cmd_flags, |
| 125 | u16 token, |
| 126 | u8 irq_index, |
| 127 | u8 en) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 128 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 129 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 130 | struct dprc_cmd_set_irq_enable *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 131 | |
| 132 | /* prepare command */ |
| 133 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 134 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 135 | cmd_params = (struct dprc_cmd_set_irq_enable *)cmd.params; |
| 136 | cmd_params->enable = en & DPRC_ENABLE; |
| 137 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 138 | |
| 139 | /* send command to mc*/ |
| 140 | return mc_send_command(mc_io, &cmd); |
| 141 | } |
| 142 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 143 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 144 | * dprc_set_irq_mask() - Set interrupt mask. |
| 145 | * @mc_io: Pointer to MC portal's I/O object |
| 146 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 147 | * @token: Token of DPRC object |
| 148 | * @irq_index: The interrupt index to configure |
| 149 | * @mask: event mask to trigger interrupt; |
| 150 | * each bit: |
| 151 | * 0 = ignore event |
| 152 | * 1 = consider event for asserting irq |
| 153 | * |
| 154 | * Every interrupt can have up to 32 causes and the interrupt model supports |
| 155 | * masking/unmasking each cause independently |
| 156 | * |
| 157 | * Return: '0' on Success; Error code otherwise. |
| 158 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 159 | int dprc_set_irq_mask(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 160 | u32 cmd_flags, |
| 161 | u16 token, |
| 162 | u8 irq_index, |
| 163 | u32 mask) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 164 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 165 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 166 | struct dprc_cmd_set_irq_mask *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 167 | |
| 168 | /* prepare command */ |
| 169 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 170 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 171 | cmd_params = (struct dprc_cmd_set_irq_mask *)cmd.params; |
| 172 | cmd_params->mask = cpu_to_le32(mask); |
| 173 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 174 | |
| 175 | /* send command to mc*/ |
| 176 | return mc_send_command(mc_io, &cmd); |
| 177 | } |
| 178 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 179 | /** |
| 180 | * dprc_get_irq_status() - Get the current status of any pending interrupts. |
| 181 | * @mc_io: Pointer to MC portal's I/O object |
| 182 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 183 | * @token: Token of DPRC object |
| 184 | * @irq_index: The interrupt index to configure |
| 185 | * @status: Returned interrupts status - one bit per cause: |
| 186 | * 0 = no interrupt pending |
| 187 | * 1 = interrupt pending |
| 188 | * |
| 189 | * Return: '0' on Success; Error code otherwise. |
| 190 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 191 | int dprc_get_irq_status(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 192 | u32 cmd_flags, |
| 193 | u16 token, |
| 194 | u8 irq_index, |
| 195 | u32 *status) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 196 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 197 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 198 | struct dprc_cmd_get_irq_status *cmd_params; |
| 199 | struct dprc_rsp_get_irq_status *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 200 | int err; |
| 201 | |
| 202 | /* prepare command */ |
| 203 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 204 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 205 | cmd_params = (struct dprc_cmd_get_irq_status *)cmd.params; |
| 206 | cmd_params->status = cpu_to_le32(*status); |
| 207 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 208 | |
| 209 | /* send command to mc*/ |
| 210 | err = mc_send_command(mc_io, &cmd); |
| 211 | if (err) |
| 212 | return err; |
| 213 | |
| 214 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 215 | rsp_params = (struct dprc_rsp_get_irq_status *)cmd.params; |
| 216 | *status = le32_to_cpu(rsp_params->status); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 221 | /** |
| 222 | * dprc_clear_irq_status() - Clear a pending interrupt's status |
| 223 | * @mc_io: Pointer to MC portal's I/O object |
| 224 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 225 | * @token: Token of DPRC object |
| 226 | * @irq_index: The interrupt index to configure |
| 227 | * @status: bits to clear (W1C) - one bit per cause: |
| 228 | * 0 = don't change |
| 229 | * 1 = clear status bit |
| 230 | * |
| 231 | * Return: '0' on Success; Error code otherwise. |
| 232 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 233 | int dprc_clear_irq_status(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 234 | u32 cmd_flags, |
| 235 | u16 token, |
| 236 | u8 irq_index, |
| 237 | u32 status) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 238 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 239 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 240 | struct dprc_cmd_clear_irq_status *cmd_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 241 | |
| 242 | /* prepare command */ |
| 243 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 244 | cmd_flags, token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 245 | cmd_params = (struct dprc_cmd_clear_irq_status *)cmd.params; |
| 246 | cmd_params->status = cpu_to_le32(status); |
| 247 | cmd_params->irq_index = irq_index; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 248 | |
| 249 | /* send command to mc*/ |
| 250 | return mc_send_command(mc_io, &cmd); |
| 251 | } |
| 252 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 253 | /** |
| 254 | * dprc_get_attributes() - Obtains container attributes |
| 255 | * @mc_io: Pointer to MC portal's I/O object |
| 256 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 257 | * @token: Token of DPRC object |
| 258 | * @attributes Returned container attributes |
| 259 | * |
| 260 | * Return: '0' on Success; Error code otherwise. |
| 261 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 262 | int dprc_get_attributes(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 263 | u32 cmd_flags, |
| 264 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 265 | struct dprc_attributes *attr) |
| 266 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 267 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 268 | struct dprc_rsp_get_attributes *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 269 | int err; |
| 270 | |
| 271 | /* prepare command */ |
| 272 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 273 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 274 | token); |
| 275 | |
| 276 | /* send command to mc*/ |
| 277 | err = mc_send_command(mc_io, &cmd); |
| 278 | if (err) |
| 279 | return err; |
| 280 | |
| 281 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 282 | rsp_params = (struct dprc_rsp_get_attributes *)cmd.params; |
| 283 | attr->container_id = le32_to_cpu(rsp_params->container_id); |
| 284 | attr->icid = le16_to_cpu(rsp_params->icid); |
| 285 | attr->options = le32_to_cpu(rsp_params->options); |
| 286 | attr->portal_id = le32_to_cpu(rsp_params->portal_id); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 291 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 292 | * dprc_get_obj_count() - Obtains the number of objects in the DPRC |
| 293 | * @mc_io: Pointer to MC portal's I/O object |
| 294 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 295 | * @token: Token of DPRC object |
| 296 | * @obj_count: Number of objects assigned to the DPRC |
| 297 | * |
| 298 | * Return: '0' on Success; Error code otherwise. |
| 299 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 300 | int dprc_get_obj_count(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 301 | u32 cmd_flags, |
| 302 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 303 | int *obj_count) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 304 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 305 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 306 | struct dprc_rsp_get_obj_count *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 307 | int err; |
| 308 | |
| 309 | /* prepare command */ |
| 310 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 311 | cmd_flags, token); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 312 | |
| 313 | /* send command to mc*/ |
| 314 | err = mc_send_command(mc_io, &cmd); |
| 315 | if (err) |
| 316 | return err; |
| 317 | |
| 318 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 319 | rsp_params = (struct dprc_rsp_get_obj_count *)cmd.params; |
| 320 | *obj_count = le32_to_cpu(rsp_params->obj_count); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 321 | |
| 322 | return 0; |
| 323 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 324 | EXPORT_SYMBOL_GPL(dprc_get_obj_count); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 325 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 326 | /** |
| 327 | * dprc_get_obj() - Get general information on an object |
| 328 | * @mc_io: Pointer to MC portal's I/O object |
| 329 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 330 | * @token: Token of DPRC object |
| 331 | * @obj_index: Index of the object to be queried (< obj_count) |
| 332 | * @obj_desc: Returns the requested object descriptor |
| 333 | * |
| 334 | * The object descriptors are retrieved one by one by incrementing |
| 335 | * obj_index up to (not including) the value of obj_count returned |
| 336 | * from dprc_get_obj_count(). dprc_get_obj_count() must |
| 337 | * be called prior to dprc_get_obj(). |
| 338 | * |
| 339 | * Return: '0' on Success; Error code otherwise. |
| 340 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 341 | int dprc_get_obj(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 342 | u32 cmd_flags, |
| 343 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 344 | int obj_index, |
Laurentiu Tudor | 0cf9f50 | 2017-06-27 17:41:24 +0300 | [diff] [blame] | 345 | struct fsl_mc_obj_desc *obj_desc) |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 346 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 347 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 348 | struct dprc_cmd_get_obj *cmd_params; |
| 349 | struct dprc_rsp_get_obj *rsp_params; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 350 | int err; |
| 351 | |
| 352 | /* prepare command */ |
| 353 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 354 | cmd_flags, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 355 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 356 | cmd_params = (struct dprc_cmd_get_obj *)cmd.params; |
| 357 | cmd_params->obj_index = cpu_to_le32(obj_index); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 358 | |
| 359 | /* send command to mc*/ |
| 360 | err = mc_send_command(mc_io, &cmd); |
| 361 | if (err) |
| 362 | return err; |
| 363 | |
| 364 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 365 | rsp_params = (struct dprc_rsp_get_obj *)cmd.params; |
| 366 | obj_desc->id = le32_to_cpu(rsp_params->id); |
| 367 | obj_desc->vendor = le16_to_cpu(rsp_params->vendor); |
| 368 | obj_desc->irq_count = rsp_params->irq_count; |
| 369 | obj_desc->region_count = rsp_params->region_count; |
| 370 | obj_desc->state = le32_to_cpu(rsp_params->state); |
| 371 | obj_desc->ver_major = le16_to_cpu(rsp_params->version_major); |
| 372 | obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor); |
| 373 | obj_desc->flags = le16_to_cpu(rsp_params->flags); |
| 374 | strncpy(obj_desc->type, rsp_params->type, 16); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 375 | obj_desc->type[15] = '\0'; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 376 | strncpy(obj_desc->label, rsp_params->label, 16); |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 377 | obj_desc->label[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 378 | return 0; |
| 379 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 380 | EXPORT_SYMBOL_GPL(dprc_get_obj); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 381 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 382 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 383 | * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt. |
| 384 | * @mc_io: Pointer to MC portal's I/O object |
| 385 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 386 | * @token: Token of DPRC object |
| 387 | * @obj_type: Type of the object to set its IRQ |
| 388 | * @obj_id: ID of the object to set its IRQ |
| 389 | * @irq_index: The interrupt index to configure |
| 390 | * @irq_cfg: IRQ configuration |
| 391 | * |
| 392 | * Return: '0' on Success; Error code otherwise. |
| 393 | */ |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 394 | int dprc_set_obj_irq(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 395 | u32 cmd_flags, |
| 396 | u16 token, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 397 | char *obj_type, |
| 398 | int obj_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 399 | u8 irq_index, |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 400 | struct dprc_irq_cfg *irq_cfg) |
| 401 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 402 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 403 | struct dprc_cmd_set_obj_irq *cmd_params; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 404 | |
| 405 | /* prepare command */ |
| 406 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ, |
| 407 | cmd_flags, |
| 408 | token); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 409 | cmd_params = (struct dprc_cmd_set_obj_irq *)cmd.params; |
| 410 | cmd_params->irq_val = cpu_to_le32(irq_cfg->val); |
| 411 | cmd_params->irq_index = irq_index; |
| 412 | cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr); |
| 413 | cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num); |
| 414 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 415 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 416 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 417 | |
| 418 | /* send command to mc*/ |
| 419 | return mc_send_command(mc_io, &cmd); |
| 420 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 421 | EXPORT_SYMBOL_GPL(dprc_set_obj_irq); |
J. German Rivera | 1ee695f | 2015-09-23 16:11:03 -0500 | [diff] [blame] | 422 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 423 | /** |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 424 | * dprc_get_obj_region() - Get region information for a specified object. |
| 425 | * @mc_io: Pointer to MC portal's I/O object |
| 426 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 427 | * @token: Token of DPRC object |
| 428 | * @obj_type; Object type as returned in dprc_get_obj() |
| 429 | * @obj_id: Unique object instance as returned in dprc_get_obj() |
| 430 | * @region_index: The specific region to query |
| 431 | * @region_desc: Returns the requested region descriptor |
| 432 | * |
| 433 | * Return: '0' on Success; Error code otherwise. |
| 434 | */ |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 435 | int dprc_get_obj_region(struct fsl_mc_io *mc_io, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 436 | u32 cmd_flags, |
| 437 | u16 token, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 438 | char *obj_type, |
| 439 | int obj_id, |
J. German Rivera | ba72f25 | 2015-09-25 11:21:01 -0500 | [diff] [blame] | 440 | u8 region_index, |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 441 | struct dprc_region_desc *region_desc) |
| 442 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 443 | struct fsl_mc_command cmd = { 0 }; |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 444 | struct dprc_cmd_get_obj_region *cmd_params; |
| 445 | struct dprc_rsp_get_obj_region *rsp_params; |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 446 | u16 major_ver, minor_ver; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 447 | int err; |
| 448 | |
| 449 | /* prepare command */ |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 450 | err = dprc_get_api_version(mc_io, 0, |
| 451 | &major_ver, |
| 452 | &minor_ver); |
| 453 | if (err) |
| 454 | return err; |
| 455 | |
| 456 | /** |
| 457 | * MC API version 6.3 introduced a new field to the region |
| 458 | * descriptor: base_address. If the older API is in use then the base |
| 459 | * address is set to zero to indicate it needs to be obtained elsewhere |
| 460 | * (typically the device tree). |
| 461 | */ |
| 462 | if (major_ver > 6 || (major_ver == 6 && minor_ver >= 3)) |
| 463 | cmd.header = |
| 464 | mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG_V2, |
| 465 | cmd_flags, token); |
| 466 | else |
| 467 | cmd.header = |
| 468 | mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG, |
| 469 | cmd_flags, token); |
| 470 | |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 471 | cmd_params = (struct dprc_cmd_get_obj_region *)cmd.params; |
| 472 | cmd_params->obj_id = cpu_to_le32(obj_id); |
| 473 | cmd_params->region_index = region_index; |
| 474 | strncpy(cmd_params->obj_type, obj_type, 16); |
| 475 | cmd_params->obj_type[15] = '\0'; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 476 | |
| 477 | /* send command to mc*/ |
| 478 | err = mc_send_command(mc_io, &cmd); |
| 479 | if (err) |
| 480 | return err; |
| 481 | |
| 482 | /* retrieve response parameters */ |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 483 | rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params; |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 484 | region_desc->base_offset = le64_to_cpu(rsp_params->base_offset); |
Ioana Radulescu | 9989b59 | 2016-06-22 16:40:52 -0500 | [diff] [blame] | 485 | region_desc->size = le32_to_cpu(rsp_params->size); |
Roy Pledge | dde2137 | 2019-04-05 14:41:11 +0000 | [diff] [blame] | 486 | if (major_ver > 6 || (major_ver == 6 && minor_ver >= 3)) |
| 487 | region_desc->base_address = le64_to_cpu(rsp_params->base_addr); |
| 488 | else |
| 489 | region_desc->base_address = 0; |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 490 | |
| 491 | return 0; |
| 492 | } |
Laurentiu Tudor | c9d57ea | 2017-11-17 15:38:29 +0200 | [diff] [blame] | 493 | EXPORT_SYMBOL_GPL(dprc_get_obj_region); |
J. German Rivera | 31c8896 | 2015-03-05 19:29:09 -0600 | [diff] [blame] | 494 | |
J. German Rivera | e9bf3f2 | 2015-09-24 14:26:54 -0500 | [diff] [blame] | 495 | /** |
Ioana Ciornei | decd3d0 | 2016-10-26 11:20:34 -0500 | [diff] [blame] | 496 | * dprc_get_api_version - Get Data Path Resource Container API version |
| 497 | * @mc_io: Pointer to Mc portal's I/O object |
| 498 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 499 | * @major_ver: Major version of Data Path Resource Container API |
| 500 | * @minor_ver: Minor version of Data Path Resource Container API |
| 501 | * |
| 502 | * Return: '0' on Success; Error code otherwise. |
| 503 | */ |
| 504 | int dprc_get_api_version(struct fsl_mc_io *mc_io, |
| 505 | u32 cmd_flags, |
| 506 | u16 *major_ver, |
| 507 | u16 *minor_ver) |
| 508 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 509 | struct fsl_mc_command cmd = { 0 }; |
Ioana Ciornei | decd3d0 | 2016-10-26 11:20:34 -0500 | [diff] [blame] | 510 | int err; |
| 511 | |
| 512 | /* prepare command */ |
| 513 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION, |
| 514 | cmd_flags, 0); |
| 515 | |
| 516 | /* send command to mc */ |
| 517 | err = mc_send_command(mc_io, &cmd); |
| 518 | if (err) |
| 519 | return err; |
| 520 | |
| 521 | /* retrieve response parameters */ |
| 522 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * dprc_get_container_id - Get container ID associated with a given portal. |
| 529 | * @mc_io: Pointer to Mc portal's I/O object |
| 530 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 531 | * @container_id: Requested container id |
| 532 | * |
| 533 | * Return: '0' on Success; Error code otherwise. |
| 534 | */ |
| 535 | int dprc_get_container_id(struct fsl_mc_io *mc_io, |
| 536 | u32 cmd_flags, |
| 537 | int *container_id) |
| 538 | { |
Ioana Ciornei | 5b04ced | 2018-03-15 12:05:31 -0500 | [diff] [blame] | 539 | struct fsl_mc_command cmd = { 0 }; |
Ioana Ciornei | decd3d0 | 2016-10-26 11:20:34 -0500 | [diff] [blame] | 540 | int err; |
| 541 | |
| 542 | /* prepare command */ |
| 543 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID, |
| 544 | cmd_flags, |
| 545 | 0); |
| 546 | |
| 547 | /* send command to mc*/ |
| 548 | err = mc_send_command(mc_io, &cmd); |
| 549 | if (err) |
| 550 | return err; |
| 551 | |
| 552 | /* retrieve response parameters */ |
| 553 | *container_id = (int)mc_cmd_read_object_id(&cmd); |
| 554 | |
| 555 | return 0; |
| 556 | } |
Ioana Ciornei | 1ac210d | 2019-10-31 01:18:29 +0200 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * dprc_get_connection() - Get connected endpoint and link status if connection |
| 560 | * exists. |
| 561 | * @mc_io: Pointer to MC portal's I/O object |
| 562 | * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' |
| 563 | * @token: Token of DPRC object |
| 564 | * @endpoint1: Endpoint 1 configuration parameters |
| 565 | * @endpoint2: Returned endpoint 2 configuration parameters |
| 566 | * @state: Returned link state: |
| 567 | * 1 - link is up; |
| 568 | * 0 - link is down; |
| 569 | * -1 - no connection (endpoint2 information is irrelevant) |
| 570 | * |
| 571 | * Return: '0' on Success; -ENOTCONN if connection does not exist. |
| 572 | */ |
| 573 | int dprc_get_connection(struct fsl_mc_io *mc_io, |
| 574 | u32 cmd_flags, |
| 575 | u16 token, |
| 576 | const struct dprc_endpoint *endpoint1, |
| 577 | struct dprc_endpoint *endpoint2, |
| 578 | int *state) |
| 579 | { |
| 580 | struct dprc_cmd_get_connection *cmd_params; |
| 581 | struct dprc_rsp_get_connection *rsp_params; |
| 582 | struct fsl_mc_command cmd = { 0 }; |
| 583 | int err, i; |
| 584 | |
| 585 | /* prepare command */ |
| 586 | cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION, |
| 587 | cmd_flags, |
| 588 | token); |
| 589 | cmd_params = (struct dprc_cmd_get_connection *)cmd.params; |
| 590 | cmd_params->ep1_id = cpu_to_le32(endpoint1->id); |
| 591 | cmd_params->ep1_interface_id = cpu_to_le16(endpoint1->if_id); |
| 592 | for (i = 0; i < 16; i++) |
| 593 | cmd_params->ep1_type[i] = endpoint1->type[i]; |
| 594 | |
| 595 | /* send command to mc */ |
| 596 | err = mc_send_command(mc_io, &cmd); |
| 597 | if (err) |
| 598 | return -ENOTCONN; |
| 599 | |
| 600 | /* retrieve response parameters */ |
| 601 | rsp_params = (struct dprc_rsp_get_connection *)cmd.params; |
| 602 | endpoint2->id = le32_to_cpu(rsp_params->ep2_id); |
| 603 | endpoint2->if_id = le16_to_cpu(rsp_params->ep2_interface_id); |
| 604 | *state = le32_to_cpu(rsp_params->state); |
| 605 | for (i = 0; i < 16; i++) |
| 606 | endpoint2->type[i] = rsp_params->ep2_type[i]; |
| 607 | |
| 608 | return 0; |
| 609 | } |