blob: bfeb34bfa45210659e788ba62bfb8742d0624723 [file] [log] [blame]
Channagoud Kadabieb6e9e72015-06-13 10:48:30 -07001/* Copyright (c) 2012,2015 The Linux Foundation. All rights reserved.
Deepa Dinamanie9ded132012-11-27 15:03:38 -08002 *
Deepa Dinamani9d470af2012-06-29 18:27:17 -07003 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
Deepa Dinamanie9ded132012-11-27 15:03:38 -08006 * * 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 Dinamani9d470af2012-06-29 18:27:17 -070015 *
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#ifndef __PLATFORM_MSM_SHARED_BAM_H
30#define __PLATFORM_MSM_SHARED_BAM_H
31
32#include <stdint.h>
33#include <compiler.h>
34
Aparna Mallavarapu31a4dd82014-04-22 20:09:32 +053035#if BAM_V170
36#define BAM_IRQ_SRCS(x, n) (0x00003000 + 0x1000 * (n) + (x))
37#define BAM_IRQ_SRCS_MSK(x, n) (0x00003004 + 0x1000 * (n) + (x))
38#define BAM_IRQ_SRCS_UNMASKED(x) (0x00003018 + (x))
39#define BAM_TRUST_REG(x) (0x00002000 + (x))
40#define BAM_P_CTRLn(n, x) (0x00013000 + 0x1000 * (n) + (x))
41#define BAM_P_RSTn(n, x) (0x00013000 + 0x4 + 0x1000 * (n) + (x))
42#define BAM_P_IRQ_STTSn(n, x) (0x00013000 + 0x10 + 0x1000 * (n) + (x))
43#define BAM_P_IRQ_CLRn(n, x) (0x00013000 + 0x14 + 0x1000 * (n) + (x))
44#define BAM_P_IRQ_ENn(n, x) (0x00013000 + 0x18 + 0x1000 * (n) + (x))
45#define BAM_P_TRUST_REGn(n, x) (0x2020 + 0x4* (n) + (x))
46#define BAM_P_SW_OFSTSn(n, x) (0x00013800 + 0x1000 * (n) + (x))
47#define BAM_P_EVNT_REGn(n, x) (0x00013818 + 0x1000 * (n) + (x))
48#define BAM_P_DESC_FIFO_ADDRn(n, x) (0x0001381C + 0x1000 * (n) + (x))
49#define BAM_P_FIFO_SIZESn(n, x) (0x00013820 + 0x1000 * (n) + (x))
50#else
51#define BAM_IRQ_SRCS(x, n) (0x00000800 + (0x80 * (n)) + (x))
52#define BAM_IRQ_SRCS_MSK(x, n) (0x00000804 + (0x80 * (n)) + (x))
53#define BAM_IRQ_SRCS_UNMASKED(x) (0x00000030 + (x))
54#define BAM_TRUST_REG(x) (0x00000070 + (x))
55#define BAM_P_CTRLn(n, x) (0x00001000 + 0x1000 * (n) + (x))
56#define BAM_P_RSTn(n, x) (0x00001000 + 0x4 + 0x1000 * (n) + (x))
57#define BAM_P_IRQ_STTSn(n, x) (0x00001000 + 0x10 + 0x1000 * (n) + (x))
58#define BAM_P_IRQ_CLRn(n, x) (0x00001000 + 0x14 + 0x1000 * (n) + (x))
59#define BAM_P_IRQ_ENn(n, x) (0x00001000 + 0x18 + 0x1000 * (n) + (x))
60#define BAM_P_TRUST_REGn(n, x) (0x00001000 + 0x30 + 0x1000 * (n) + (x))
61#define BAM_P_SW_OFSTSn(n, x) (0x00001800 + 0x1000 * (n) + (x))
62#define BAM_P_EVNT_REGn(n, x) (0x00001818 + 0x1000 * (n) + (x))
63#define BAM_P_DESC_FIFO_ADDRn(n, x) (0x0000181C + 0x1000 * (n) + (x))
64#define BAM_P_FIFO_SIZESn(n, x) (0x00001820 + 0x1000 * (n) + (x))
65#endif
66
Deepa Dinamani9d470af2012-06-29 18:27:17 -070067#define BAM_DESC_SIZE 8
68#define BAM_CE_SIZE 16
69#define BAM_MAX_DESC_DATA_LEN 0xFFFF
Deepa Dinamani62df2c72012-12-19 17:17:58 -080070#define BAM_NDP_MAX_DESC_DATA_LEN 0x7FFF
Deepa Dinamani9d470af2012-06-29 18:27:17 -070071#define BAM_DATA_READ 0
72#define BAM_DATA_WRITE 1
73
Deepa Dinamani9d470af2012-06-29 18:27:17 -070074#define BAM_DESC_CNT_TRSHLD_REG(x) (0x0008 + (x))
75#define COUNT_TRESHOLD_MASK 0xFF
Deepa Dinamani9d470af2012-06-29 18:27:17 -070076#define BAM_IRQ_MASK (1 << 31)
77#define P_IRQ_MASK (1)
78
Deepa Dinamani9d470af2012-06-29 18:27:17 -070079#define BAM_IRQ_STTS(x) (0x00000014 + (x))
Deepa Dinamani9d470af2012-06-29 18:27:17 -070080
81#define BAM_IRQ_EN_REG(x) (0x001C + (x))
82#define BAM_TIMER_EN_MASK (1 << 4)
83/* Available only in BAM-Lite */
84#define BAM_EMPTY_EN_MASK (1 << 3)
85#define BAM_ERROR_EN_MASK (1 << 2)
86/* Available only in BAM */
87#define BAM_HRESP_ERR_EN_MASK (1 << 1)
88
Deepa Dinamani9d470af2012-06-29 18:27:17 -070089#define BAM_EE_MASK (7 << 0)
90#define BAM_RESET_BLK_MASK (1 << 7)
91#define BAM_LOCK_EE_CTRL_MASK (1 << 13)
92
Deepa Dinamani9d470af2012-06-29 18:27:17 -070093#define P_SYS_MODE_MASK (1 << 5)
94/* 1: Producer mode 0: Consumer mode */
95#define P_DIRECTION_SHIFT 3
Deepa Dinamania0407ea2013-07-09 12:51:45 -070096#define P_LOCK_GRP_SHIFT 16
Deepa Dinamani9d470af2012-06-29 18:27:17 -070097#define P_ENABLE (1 << 1)
98
Deepa Dinamani9d470af2012-06-29 18:27:17 -070099#define P_DESC_FIFO_PEER_OFST_MASK 0xFF
100
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700101
102/* Flags for descriptors */
103#define BAM_DESC_INT_FLAG (1 << 7)
104#define BAM_DESC_EOT_FLAG (1 << 6)
105#define BAM_DESC_EOB_FLAG (1 << 5)
106#define BAM_DESC_NWD_FLAG (1 << 4)
107#define BAM_DESC_CMD_FLAG (1 << 3)
108#define BAM_DESC_LOCK_FLAG (1 << 2)
109#define BAM_DESC_UNLOCK_FLAG (1 << 1)
110
Aparna Mallavarapu31a4dd82014-04-22 20:09:32 +0530111/* Pipe Interrupt masks */
112enum p_int_type
113{
114 P_PRCSD_DESC_EN_MASK = 1,
115 P_OUT_OF_DESC_EN_MASK = (1 << 3),
116 P_ERR_EN_MASK = (1 << 4),
117 P_TRNSFR_END_EN_MASK = (1 << 5)
118};
119
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700120enum bam_ce_cmd_t{
121 CE_WRITE_TYPE = 0,
122 CE_READ_TYPE = 1
123};
124
125/* result type */
126typedef enum {
127 BAM_RESULT_SUCCESS = 0,
128 BAM_RESULT_FAILURE = 1,
129 BAM_RESULT_TIMEOUT = 2
130} bam_result_t;
131
132
133/* Enum to define the BAM type:
134 * BAM2BAM:Producer BAM to Consumer BAM.
135 * SYS2BAM:Producer System to Consumer BAM.
136 * BAM2SYS:Producer BAM to Consumer System.
137 */
138enum bam_transaction_type {
139 SYS2BAM,
140 BAM2SYS,
141 BAM2BAM,
142};
143
144/* Enum to define BAM mode:
145 * SPS:Use BAM pipes.
146 * DIRECT:Pipes are disabled.
147 * LEGACY:BAM is not used.
148 */
149enum bam_mode {
150 SPS,
151 DIRECT,
152 LEGACY,
153};
154
155/* Enum to define BAM pipe states:
156 * ENABLED:Producer and Consumer pipes are enabled.
157 * HALT:Consumer pipe is halted. (Preferred type)
158 * FULL_HALT:Both Producer and Consumer pipes are halted.
159 */
160enum bam_pipe_state {
161 ENABLED,
162 HALT,
163 FULL_HALT,
164};
165
166enum bam_type {
167 BAM_LITE,
168 BAM,
169};
170
171/* Structure to define BAM descriptors that describe the data
172 * descriptors written to the data FIFO.
173 * addr:Descriptor address.
174 * size:Each descriptor is 8 bytes. Size of the descriptor fifo must
175 * contain an integer number of Descriptors.
176 */
177struct bam_desc {
178 uint32_t addr;
179 uint16_t size;
180 uint8_t reserved;
181 uint8_t flags;
182} __PACKED;
183
184struct bam_desc_fifo {
185 struct bam_desc *head;
186 struct bam_desc *current;
187 uint16_t size;
188 uint16_t offset;
189};
190
191/* Structure to define BAM pipes
192 * pipe_state: BAM pipe states.
193 * trans_type: BAM tranaction type.
194 * evt_gen_threshold: This register configures the threshold value for
195 * Read/Write event generation by the BAM
196 * towards another BAM.
197 * fifo: Circular fifo associated with this pipe.
198 * num_pipe: Number of pipes used in this bam.
199 * pipe: Pipe number for this pipe.
200 * spi_num: SPI number for the BAM interrupt.
201 * int_mode: Specifies the pipe mode.
202 * 1: Interrupt mode
203 * 0: Polling mode
204 */
205struct bam_pipe {
206 enum bam_pipe_state state;
207 enum bam_transaction_type trans_type;
208 struct bam_desc_fifo fifo;
209 uint16_t evt_gen_threshold;
210 uint8_t pipe_num;
211 uint8_t spi_num;
212 uint8_t int_mode;
213 uint8_t initialized;
Deepa Dinamania0407ea2013-07-09 12:51:45 -0700214 uint8_t lock_grp;
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700215};
216
217/* Structure to define a BAM instance being used
218 * base:Base address for the BAM.
219 * type:BAM type.
220 * mode:BAM mode.
221 * pipe_pair:The pipe pairs to be used to access the BAM.
222 * threshold:This Register holds a threshold value for the
223 * counter summing the Size of the Descriptors Provided.
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800224 * ee:Execution Environment for the BAM.
225 * desc_len: Max desc length for the current BAM.
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700226 */
227struct bam_instance {
228 uint32_t base;
229 enum bam_type type;
230 enum bam_mode mode;
231 uint8_t num_of_pipes;
232 struct bam_pipe pipe[3];
233 uint16_t threshold;
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800234 uint32_t ee;
235 uint16_t max_desc_len;
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700236 void (*callback)(int);
237};
238
239/* Command element(CE) structure*/
240struct cmd_element {
241 uint32_t addr_n_cmd;
242 uint32_t reg_data;
243 uint32_t reg_mask;
244 uint32_t reserve;
245} __PACKED;
246
247void bam_init(struct bam_instance *bam);
248void bam_sys_pipe_init(struct bam_instance *bam,
249 uint8_t pipe_num);
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700250int bam_pipe_fifo_init(struct bam_instance *bam,
251 uint8_t pipe_num);
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700252struct cmd_element* bam_add_cmd_element(struct cmd_element *ptr,
253 uint32_t addr,
254 uint32_t data,
255 enum bam_ce_cmd_t cmd_type);
256int bam_add_desc(struct bam_instance *bam,
257 unsigned int pipe_num,
258 unsigned char *data_ptr,
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700259 unsigned int data_len,
260 unsigned flags);
261int bam_add_one_desc(struct bam_instance *bam,
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700262 unsigned int pipe_num,
263 unsigned char*,
264 uint32_t len,
265 uint8_t flags);
266void bam_sys_gen_event(struct bam_instance *bam,
267 uint8_t pipe_num,
268 unsigned int num_desc);
269int bam_wait_for_interrupt(struct bam_instance *bam,
270 uint8_t pipe_num,
271 enum p_int_type interrupt);
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700272void bam_read_offset_update(struct bam_instance *bam, unsigned int pipe_num);
Deepa Dinamani87feab82012-10-04 14:28:05 -0700273void bam_pipe_reset(struct bam_instance *bam,
274 uint8_t pipe_num);
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700275
276#endif