Mayank Grover | 20fdd88 | 2016-10-25 16:53:30 +0530 | [diff] [blame^] | 1 | /* Copyright (c) 2012,2016 The Linux Foundation. All rights reserved. |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2 | * |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 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 |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <bam.h> |
| 30 | #include <reg.h> |
| 31 | #include <debug.h> |
| 32 | #include <stdlib.h> |
Deepa Dinamani | 62df2c7 | 2012-12-19 17:17:58 -0800 | [diff] [blame] | 33 | #include <arch/ops.h> |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 34 | #include <platform.h> |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 35 | #include <platform/interrupts.h> |
| 36 | #include <platform/iomap.h> |
| 37 | #include <platform/irqs.h> |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 38 | #include <pow2.h> |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 39 | |
| 40 | #define HLOS_EE_INDEX 0 |
| 41 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 42 | /* Resets pipe registers and state machines */ |
Deepa Dinamani | 87feab8 | 2012-10-04 14:28:05 -0700 | [diff] [blame] | 43 | void bam_pipe_reset(struct bam_instance *bam, |
| 44 | uint8_t pipe_num) |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 45 | { |
| 46 | /* Start sw reset of the pipe to be allocated */ |
| 47 | writel(1, BAM_P_RSTn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 48 | |
| 49 | /* No delay required */ |
| 50 | |
| 51 | /* Stop sw reset of the pipe to be allocated */ |
| 52 | writel(0, BAM_P_RSTn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 53 | } |
| 54 | |
| 55 | static enum handler_return bam_interrupt_handler(void* arg) |
| 56 | { |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* A blocking function that waits till an interrupt is signalled. |
| 61 | * bam : BAM instance for the descriptors to be queued. |
| 62 | * pipe_num : pipe number for the descriptors to be queued. |
| 63 | * interrupt: interrupt to wait for. |
| 64 | */ |
| 65 | int bam_wait_for_interrupt(struct bam_instance *bam, |
| 66 | uint8_t pipe_num, |
| 67 | enum p_int_type interrupt) |
| 68 | { |
| 69 | uint32_t val; |
| 70 | |
| 71 | while (1) |
| 72 | { |
| 73 | /* Wait for a interrupt on the right pipe */ |
| 74 | do{ |
| 75 | /* Determine the pipe causing the interrupt */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 76 | val = readl(BAM_IRQ_SRCS(bam->base, bam->ee)); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 77 | /* Flush out the right most global interrupt bit */ |
| 78 | } while (!((val & 0x7FFF) & (1 << bam->pipe[pipe_num].pipe_num))); |
| 79 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 80 | /* Check the interrupt type */ |
| 81 | /* Read interrupt status register */ |
| 82 | val = readl(BAM_P_IRQ_STTSn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 83 | |
| 84 | /* Check for error */ |
| 85 | if (val & P_ERR_EN_MASK) |
| 86 | goto bam_wait_int_error; |
| 87 | |
| 88 | if (val & interrupt) |
| 89 | { |
| 90 | /* Correct interrupt was fired. */ |
| 91 | /* Clear the other interrupts */ |
| 92 | val = P_OUT_OF_DESC_EN_MASK | P_PRCSD_DESC_EN_MASK | P_TRNSFR_END_EN_MASK; |
| 93 | writel (val, BAM_P_IRQ_CLRn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 94 | return BAM_RESULT_SUCCESS; |
| 95 | } |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | bam_wait_int_error: |
| 99 | |
Sundarajan Srinivasan | 802a9ec | 2013-07-11 16:02:57 -0700 | [diff] [blame] | 100 | dprintf(CRITICAL, "Unexpected interrupt : val %u\n", val); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 101 | return BAM_RESULT_FAILURE; |
| 102 | } |
| 103 | |
| 104 | /* Enable BAM and pipe level interrupts */ |
| 105 | void bam_enable_interrupts(struct bam_instance *bam, uint8_t pipe_num) |
| 106 | { |
| 107 | |
| 108 | uint32_t int_mask = P_ERR_EN_MASK | P_OUT_OF_DESC_EN_MASK | |
Sundarajan Srinivasan | 802a9ec | 2013-07-11 16:02:57 -0700 | [diff] [blame] | 109 | P_PRCSD_DESC_EN_MASK; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 110 | uint32_t val; |
| 111 | |
Deepa Dinamani | 5f68e84 | 2013-05-14 16:46:08 -0700 | [diff] [blame] | 112 | /* Leave BAM error interrupts disabled. */ |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 113 | /* Enable the interrupts for the pipe by enabling the relevant bits |
| 114 | * in the BAM_PIPE_INTERRUPT_ENABLE register. |
| 115 | */ |
| 116 | writel(int_mask, |
| 117 | BAM_P_IRQ_ENn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 118 | |
| 119 | /* Enable pipe interrups */ |
| 120 | /* Do read-modify-write */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 121 | val = readl(BAM_IRQ_SRCS_MSK(bam->base, bam->ee)); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 122 | writel((1 << bam->pipe[pipe_num].pipe_num) | val, |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 123 | BAM_IRQ_SRCS_MSK(bam->base, bam->ee)); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 124 | |
| 125 | /* Unmask the QGIC interrupts only in the case of |
| 126 | * interrupt based transfer. |
| 127 | * Use polling othwerwise. |
| 128 | */ |
| 129 | if (bam->pipe[pipe_num].int_mode) |
| 130 | { |
| 131 | /* Register interrupt handler */ |
| 132 | register_int_handler(bam->pipe[pipe_num].spi_num, bam_interrupt_handler, 0); |
| 133 | |
| 134 | /* Unmask the interrupt */ |
| 135 | unmask_interrupt(bam->pipe[pipe_num].spi_num); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /* Reset and initialize the bam module */ |
| 140 | void bam_init(struct bam_instance *bam) |
| 141 | { |
Channagoud Kadabi | 6d3efd1 | 2015-08-19 18:11:44 -0700 | [diff] [blame] | 142 | /* bam is initialized by TZ, so nothing needs to be done here */ |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* Funtion to setup a simple fifo structure. |
| 146 | * Note: Addr should be 8 byte aligned. |
| 147 | * bam : BAM instance for the descriptors to be queued. |
| 148 | * pipe_num : pipe number for the descriptors to be queued. |
| 149 | */ |
| 150 | int bam_pipe_fifo_init(struct bam_instance *bam, |
| 151 | uint8_t pipe_num) |
| 152 | { |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 153 | if (bam->pipe[pipe_num].fifo.size > 0x7FFF) |
| 154 | { |
| 155 | dprintf(CRITICAL, |
| 156 | "Size exceeds max size for a descriptor(0x7FFF)\n"); |
| 157 | return BAM_RESULT_FAILURE; |
| 158 | } |
| 159 | |
| 160 | /* Check if fifo start is 8-byte alligned */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 161 | ASSERT(!((uint32_t)PA((addr_t)bam->pipe[pipe_num].fifo.head & 0x7))); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 162 | |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 163 | /* Check if fifo size is a power of 2. |
| 164 | * The circular fifo logic in lk expects this. |
| 165 | */ |
| 166 | ASSERT(ispow2(bam->pipe[pipe_num].fifo.size)); |
| 167 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 168 | bam->pipe[pipe_num].fifo.current = bam->pipe[pipe_num].fifo.head; |
| 169 | |
| 170 | /* Set the descriptor buffer size. Must be a multiple of 8 */ |
| 171 | writel(bam->pipe[pipe_num].fifo.size * BAM_DESC_SIZE, |
| 172 | BAM_P_FIFO_SIZESn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 173 | |
| 174 | /* Write descriptors FIFO base addr must be 8-byte aligned */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 175 | /* Needs a physical address conversion as we are setting up |
| 176 | * the base of the FIFO for the BAM state machine. |
| 177 | */ |
| 178 | writel((uint32_t)PA((addr_t)bam->pipe[pipe_num].fifo.head), |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 179 | BAM_P_DESC_FIFO_ADDRn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 180 | |
| 181 | /* Initialize FIFO offset for the first read */ |
| 182 | bam->pipe[pipe_num].fifo.offset = BAM_DESC_SIZE; |
| 183 | |
Deepa Dinamani | a0407ea | 2013-07-09 12:51:45 -0700 | [diff] [blame] | 184 | writel(P_ENABLE | readl(BAM_P_CTRLn(bam->pipe[pipe_num].pipe_num, bam->base)), |
| 185 | BAM_P_CTRLn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 186 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 187 | /* Everything is set. |
| 188 | * Flag pipe init done. |
| 189 | */ |
| 190 | bam->pipe[pipe_num].initialized = 1; |
| 191 | |
| 192 | return BAM_RESULT_SUCCESS; |
| 193 | } |
| 194 | |
| 195 | void bam_sys_pipe_init(struct bam_instance *bam, |
| 196 | uint8_t pipe_num) |
| 197 | { |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 198 | /* Reset the pipe to be allocated */ |
| 199 | bam_pipe_reset(bam, pipe_num); |
| 200 | |
| 201 | /* Enable minimal interrupts */ |
| 202 | bam_enable_interrupts(bam, pipe_num); |
| 203 | |
| 204 | /* Pipe event threshold register is not relevant in sys modes */ |
| 205 | |
| 206 | /* Enable pipe in system mode and set the direction */ |
Deepa Dinamani | a0407ea | 2013-07-09 12:51:45 -0700 | [diff] [blame] | 207 | writel(P_SYS_MODE_MASK | bam->pipe[pipe_num].lock_grp << P_LOCK_GRP_SHIFT | |
| 208 | (bam->pipe[pipe_num].trans_type << P_DIRECTION_SHIFT), |
| 209 | BAM_P_CTRLn(bam->pipe[pipe_num].pipe_num, bam->base)); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 210 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 211 | /* Mark the pipe FIFO as uninitialized. */ |
| 212 | bam->pipe[pipe_num].initialized = 0; |
| 213 | } |
| 214 | |
| 215 | /* Function to notify written descriptors to BAM. |
| 216 | * bam : BAM instance for the descriptors to be queued. |
| 217 | * pipe_num : pipe number for the descriptors to be queued. |
| 218 | * num_desc : number of the descriptors. |
| 219 | * fifo : Circular FIFO used for the descriptors. |
| 220 | */ |
| 221 | void bam_sys_gen_event(struct bam_instance *bam, |
| 222 | uint8_t pipe_num, |
| 223 | unsigned int num_desc) |
| 224 | { |
| 225 | uint32_t val = 0; |
| 226 | |
| 227 | if (num_desc >= bam->pipe[pipe_num].fifo.size) { |
| 228 | dprintf(CRITICAL, |
| 229 | "Max allowed desc is one less than the fifo length\n"); |
| 230 | return; |
| 231 | } |
| 232 | |
Sundarajan Srinivasan | 024bda5 | 2014-02-27 16:48:48 -0800 | [diff] [blame] | 233 | /* bits 0:15 of BAM_P_EVNT_REGn denotes the offset. We read the offset, |
| 234 | * and update the offset to notify BAM HW that new descriptors have been written |
| 235 | */ |
| 236 | val = readl(BAM_P_EVNT_REGn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 237 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 238 | /* Update the fifo peer offset */ |
Sundarajan Srinivasan | 024bda5 | 2014-02-27 16:48:48 -0800 | [diff] [blame] | 239 | val += (num_desc) * BAM_DESC_SIZE; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 240 | val &= (bam->pipe[pipe_num].fifo.size * BAM_DESC_SIZE - 1); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 241 | |
| 242 | writel(val, BAM_P_EVNT_REGn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 243 | } |
| 244 | |
| 245 | /* Function to read the updates for FIFO offsets. |
| 246 | * bam : BAM that uses the FIFO. |
| 247 | * pipe : BAM pipe that uses the FIFO. |
Sundarajan Srinivasan | 024bda5 | 2014-02-27 16:48:48 -0800 | [diff] [blame] | 248 | * return : void. |
| 249 | * Note : As per IPCAT This register denotes the pointer Offset of the first un-Acknowledged Descriptor. |
| 250 | * This register is only used by the Software. After receiving an interrupt, software reads this register |
| 251 | * in order to know what descriptors has been processed. Although being Writable, Software |
| 252 | * should never write to this register. |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 253 | */ |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 254 | void bam_read_offset_update(struct bam_instance *bam, unsigned int pipe_num) |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 255 | { |
| 256 | uint32_t offset; |
| 257 | |
| 258 | offset = readl(BAM_P_SW_OFSTSn(bam->pipe[pipe_num].pipe_num, bam->base)); |
| 259 | offset &= 0xFFFF; |
| 260 | |
Deepa Dinamani | 9c59ac6 | 2012-12-03 10:51:59 -0800 | [diff] [blame] | 261 | dprintf(SPEW, "Offset value is %d \n", offset); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /* Function to get the next desc address. |
| 265 | * Keeps track of circular properties of the FIFO |
| 266 | * and returns the appropriate address. |
| 267 | */ |
| 268 | static struct bam_desc* fifo_getnext(struct bam_desc_fifo *fifo, |
| 269 | struct bam_desc* desc) |
| 270 | { |
| 271 | uint16_t offset; |
| 272 | |
| 273 | offset = desc - fifo->head; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 274 | |
| 275 | if (offset == (fifo->size - 1)) |
| 276 | return fifo->head; |
| 277 | else |
| 278 | return desc + 1; |
| 279 | } |
| 280 | |
| 281 | /* Function to add BAM descriptors for a given fifo. |
| 282 | * bam : BAM instance to be used. |
Mayank Grover | 20fdd88 | 2016-10-25 16:53:30 +0530 | [diff] [blame^] | 283 | * data_ptr : Physical memory address for data transfer. |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 284 | * data_len : Length of the data_ptr. |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 285 | * flags : Flags to be set on the last desc added. |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 286 | * |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 287 | * Note: This function also notifies the BAM about the added descriptors. |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 288 | */ |
| 289 | int bam_add_desc(struct bam_instance *bam, |
| 290 | unsigned int pipe_num, |
| 291 | unsigned char *data_ptr, |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 292 | unsigned int data_len, |
| 293 | unsigned flags) |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 294 | { |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 295 | int bam_ret = BAM_RESULT_SUCCESS; |
| 296 | unsigned int len = data_len; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 297 | unsigned int desc_len; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 298 | unsigned int n = 0; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 299 | unsigned int desc_flags; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 300 | |
Deepa Dinamani | 9c59ac6 | 2012-12-03 10:51:59 -0800 | [diff] [blame] | 301 | dprintf(SPEW, "Data length for BAM transfer is %u\n", data_len); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 302 | |
| 303 | if (data_ptr == NULL || len == 0) |
| 304 | { |
| 305 | dprintf(CRITICAL, "Wrong params for BAM transfer \n"); |
| 306 | bam_ret = BAM_RESULT_FAILURE; |
| 307 | goto bam_add_desc_error; |
| 308 | } |
| 309 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 310 | /* Check if we have enough space in FIFO */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 311 | if (len > (unsigned)bam->pipe[pipe_num].fifo.size * bam->max_desc_len) |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 312 | { |
| 313 | dprintf(CRITICAL, "Data transfer exceeds desc fifo length.\n"); |
| 314 | bam_ret = BAM_RESULT_FAILURE; |
| 315 | goto bam_add_desc_error; |
| 316 | } |
| 317 | |
| 318 | while (len) |
| 319 | { |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 320 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 321 | /* There are only 16 bits to write data length. |
| 322 | * If more bits are needed, create more |
| 323 | * descriptors. |
| 324 | */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 325 | if (len > bam->max_desc_len) |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 326 | { |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 327 | desc_len = bam->max_desc_len; |
| 328 | len -= bam->max_desc_len; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 329 | desc_flags = 0; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 330 | } |
| 331 | else |
| 332 | { |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 333 | desc_len = len; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 334 | len = 0; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 335 | /* Set correct flags on the last desc. */ |
| 336 | desc_flags = flags; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 339 | /* Write descriptor */ |
| 340 | bam_add_one_desc(bam, pipe_num, data_ptr, desc_len, desc_flags); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 341 | |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 342 | data_ptr += bam->max_desc_len; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 343 | n++; |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 346 | |
| 347 | /* Create a read/write event to notify the periperal of the added desc. */ |
| 348 | bam_sys_gen_event(bam, pipe_num, n); |
| 349 | |
| 350 | bam_add_desc_error: |
| 351 | |
| 352 | return bam_ret; |
| 353 | } |
| 354 | |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 355 | /* Function to add a BAM descriptor for a given fifo. |
| 356 | * bam : BAM instance to be used. |
| 357 | * data_ptr : Memory address for data transfer. |
| 358 | * data_len : Length of the data_ptr. |
| 359 | * flags : Flags to be set on the desc added. |
| 360 | * |
| 361 | * Note: This function does not notify the BAM about the added descriptor. |
| 362 | */ |
| 363 | int bam_add_one_desc(struct bam_instance *bam, |
| 364 | unsigned int pipe_num, |
| 365 | unsigned char* data_ptr, |
| 366 | uint32_t len, |
| 367 | uint8_t flags) |
| 368 | { |
| 369 | |
| 370 | struct bam_desc *desc = bam->pipe[pipe_num].fifo.current; |
| 371 | int bam_ret = BAM_RESULT_SUCCESS; |
| 372 | |
| 373 | if (data_ptr == NULL || len == 0) |
| 374 | { |
| 375 | dprintf(CRITICAL, "Wrong params for BAM transfer \n"); |
| 376 | bam_ret = BAM_RESULT_FAILURE; |
| 377 | goto bam_add_one_desc_error; |
| 378 | } |
| 379 | |
| 380 | /* Check if the FIFO is allocated for the pipe */ |
| 381 | if (!bam->pipe[pipe_num].initialized) |
| 382 | { |
| 383 | dprintf(CRITICAL, "Please allocate the FIFO for the BAM pipe %d\n", |
| 384 | bam->pipe[pipe_num].pipe_num); |
| 385 | bam_ret = BAM_RESULT_FAILURE; |
| 386 | goto bam_add_one_desc_error; |
| 387 | } |
| 388 | |
| 389 | if ((flags & BAM_DESC_LOCK_FLAG) && (flags & BAM_DESC_UNLOCK_FLAG)) |
| 390 | { |
| 391 | dprintf(CRITICAL, "Can't lock and unlock in the same desc\n"); |
| 392 | bam_ret = BAM_RESULT_FAILURE; |
| 393 | goto bam_add_one_desc_error; |
| 394 | } |
| 395 | |
| 396 | /* Setting EOT flag on a CMD desc is not valid */ |
| 397 | if ((flags & BAM_DESC_EOT_FLAG) && (flags & BAM_DESC_CMD_FLAG)) |
| 398 | { |
| 399 | dprintf(CRITICAL, "EOT flag set on the CMD desc\n"); |
| 400 | bam_ret = BAM_RESULT_FAILURE; |
| 401 | goto bam_add_one_desc_error; |
| 402 | } |
| 403 | |
| 404 | /* Check for the length of the desc. */ |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 405 | if (len > bam->max_desc_len) |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 406 | { |
| 407 | dprintf(CRITICAL, "len of the desc exceeds max length" |
Deepa Dinamani | e9ded13 | 2012-11-27 15:03:38 -0800 | [diff] [blame] | 408 | " %d > %d\n", len, bam->max_desc_len); |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 409 | bam_ret = BAM_RESULT_FAILURE; |
| 410 | goto bam_add_one_desc_error; |
| 411 | } |
| 412 | |
Deepa Dinamani | 62df2c7 | 2012-12-19 17:17:58 -0800 | [diff] [blame] | 413 | desc->flags = flags; |
| 414 | desc->addr = (uint32_t)data_ptr; |
| 415 | desc->size = (uint16_t)len; |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 416 | desc->reserved = 0; |
| 417 | |
Deepa Dinamani | 62df2c7 | 2012-12-19 17:17:58 -0800 | [diff] [blame] | 418 | arch_clean_invalidate_cache_range((addr_t) desc, BAM_DESC_SIZE); |
| 419 | |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 420 | /* Update the FIFO to point to the head */ |
| 421 | bam->pipe[pipe_num].fifo.current = fifo_getnext(&bam->pipe[pipe_num].fifo, desc); |
| 422 | |
| 423 | bam_add_one_desc_error: |
| 424 | return bam_ret; |
| 425 | } |
| 426 | |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 427 | struct cmd_element* bam_add_cmd_element(struct cmd_element *ptr, |
| 428 | uint32_t reg_addr, |
| 429 | uint32_t value, |
| 430 | enum bam_ce_cmd_t cmd_type) |
| 431 | { |
| 432 | /* Write cmd type. |
| 433 | * Also, write the register address. |
| 434 | */ |
Deepa Dinamani | e5ccd6c | 2012-08-16 11:41:06 -0700 | [diff] [blame] | 435 | ptr->addr_n_cmd = (reg_addr & ~(0xFF000000)) | (cmd_type << 24); |
Deepa Dinamani | 9d470af | 2012-06-29 18:27:17 -0700 | [diff] [blame] | 436 | |
| 437 | /* Do not mask any of the addr bits by default */ |
| 438 | ptr->reg_mask = 0xFFFFFFFF; |
| 439 | |
| 440 | /* Write the value to be written */ |
| 441 | ptr->reg_data = value; |
| 442 | |
| 443 | /* Return the address to add the next element to */ |
| 444 | return ptr + 1; |
| 445 | } |