blob: ae673ab6bcb0b67b5998b0b43c3a4368c429d9ca [file] [log] [blame]
Deepa Dinamanie9ded132012-11-27 15:03:38 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2 *
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
35#define BAM_DESC_SIZE 8
36#define BAM_CE_SIZE 16
37#define BAM_MAX_DESC_DATA_LEN 0xFFFF
Deepa Dinamani62df2c72012-12-19 17:17:58 -080038#define BAM_NDP_MAX_DESC_DATA_LEN 0x7FFF
Deepa Dinamani9d470af2012-06-29 18:27:17 -070039#define BAM_DATA_READ 0
40#define BAM_DATA_WRITE 1
41
42#define BAM_CTRL_REG(x) (0x0000 + (x))
43#define BAM_SW_RST_BIT_MASK 1
44#define BAM_ENABLE_BIT_MASK (1 << 1)
45
46#define BAM_DESC_CNT_TRSHLD_REG(x) (0x0008 + (x))
47#define COUNT_TRESHOLD_MASK 0xFF
Deepa Dinamanie9ded132012-11-27 15:03:38 -080048#define BAM_IRQ_SRCS(x, n) (0x00000800 + (0x80 * (n)) + (x))
49#define BAM_IRQ_SRCS_MSK(x, n) (0x00000804 + (0x80 * (n)) + (x))
Deepa Dinamani9d470af2012-06-29 18:27:17 -070050#define BAM_IRQ_MASK (1 << 31)
51#define P_IRQ_MASK (1)
52
53/* Pipe Interrupt masks */
54enum p_int_type
55{
56 P_PRCSD_DESC_EN_MASK = 1,
57 P_OUT_OF_DESC_EN_MASK = (1 << 3),
58 P_ERR_EN_MASK = (1 << 4),
59 P_TRNSFR_END_EN_MASK = (1 << 5)
60};
61
62#define BAM_IRQ_STTS(x) (0x00000014 + (x))
63#define BAM_IRQ_SRCS_UNMASKED(x) (0x00000030 + (x))
64
65#define BAM_IRQ_EN_REG(x) (0x001C + (x))
66#define BAM_TIMER_EN_MASK (1 << 4)
67/* Available only in BAM-Lite */
68#define BAM_EMPTY_EN_MASK (1 << 3)
69#define BAM_ERROR_EN_MASK (1 << 2)
70/* Available only in BAM */
71#define BAM_HRESP_ERR_EN_MASK (1 << 1)
72
73#define BAM_TRUST_REG(x) (0x00000070 + (x))
74#define BAM_EE_MASK (7 << 0)
75#define BAM_RESET_BLK_MASK (1 << 7)
76#define BAM_LOCK_EE_CTRL_MASK (1 << 13)
77
78#define BAM_CNFG_BITS(x) (0x0000007C + (x))
79
80#define BAM_P_CTRLn(n, x) (0x00001000 + 0x1000 * (n) + (x))
81#define P_SYS_MODE_MASK (1 << 5)
82/* 1: Producer mode 0: Consumer mode */
83#define P_DIRECTION_SHIFT 3
Deepa Dinamania0407ea2013-07-09 12:51:45 -070084#define P_LOCK_GRP_SHIFT 16
Deepa Dinamani9d470af2012-06-29 18:27:17 -070085#define P_ENABLE (1 << 1)
86
87#define BAM_P_RSTn(n, x) (0x00001000 + 0x4 + 0x1000 * (n) + (x))
88#define BAM_P_IRQ_STTSn(n, x) (0x00001000 + 0x10 + 0x1000 * (n) + (x))
89#define BAM_P_IRQ_CLRn(n, x) (0x00001000 + 0x14 + 0x1000 * (n) + (x))
90#define BAM_P_IRQ_ENn(n, x) (0x00001000 + 0x18 + 0x1000 * (n) + (x))
91#define BAM_P_TRUST_REGn(n, x) (0x00001000 + 0x30 + 0x1000 * (n) + (x))
92#define BAM_P_SW_OFSTSn(n, x) (0x00001800 + 0x1000 * (n) + (x))
93#define BAM_P_EVNT_REGn(n, x) (0x00001818 + 0x1000 * (n) + (x))
94#define P_DESC_FIFO_PEER_OFST_MASK 0xFF
95
96#define BAM_P_DESC_FIFO_ADDRn(n, x) (0x0000181C + 0x1000 * (n) + (x))
97#define BAM_P_FIFO_SIZESn(n, x) (0x00001820 + 0x1000 * (n) + (x))
98
99/* Flags for descriptors */
100#define BAM_DESC_INT_FLAG (1 << 7)
101#define BAM_DESC_EOT_FLAG (1 << 6)
102#define BAM_DESC_EOB_FLAG (1 << 5)
103#define BAM_DESC_NWD_FLAG (1 << 4)
104#define BAM_DESC_CMD_FLAG (1 << 3)
105#define BAM_DESC_LOCK_FLAG (1 << 2)
106#define BAM_DESC_UNLOCK_FLAG (1 << 1)
107
108enum bam_ce_cmd_t{
109 CE_WRITE_TYPE = 0,
110 CE_READ_TYPE = 1
111};
112
113/* result type */
114typedef enum {
115 BAM_RESULT_SUCCESS = 0,
116 BAM_RESULT_FAILURE = 1,
117 BAM_RESULT_TIMEOUT = 2
118} bam_result_t;
119
120
121/* Enum to define the BAM type:
122 * BAM2BAM:Producer BAM to Consumer BAM.
123 * SYS2BAM:Producer System to Consumer BAM.
124 * BAM2SYS:Producer BAM to Consumer System.
125 */
126enum bam_transaction_type {
127 SYS2BAM,
128 BAM2SYS,
129 BAM2BAM,
130};
131
132/* Enum to define BAM mode:
133 * SPS:Use BAM pipes.
134 * DIRECT:Pipes are disabled.
135 * LEGACY:BAM is not used.
136 */
137enum bam_mode {
138 SPS,
139 DIRECT,
140 LEGACY,
141};
142
143/* Enum to define BAM pipe states:
144 * ENABLED:Producer and Consumer pipes are enabled.
145 * HALT:Consumer pipe is halted. (Preferred type)
146 * FULL_HALT:Both Producer and Consumer pipes are halted.
147 */
148enum bam_pipe_state {
149 ENABLED,
150 HALT,
151 FULL_HALT,
152};
153
154enum bam_type {
155 BAM_LITE,
156 BAM,
157};
158
159/* Structure to define BAM descriptors that describe the data
160 * descriptors written to the data FIFO.
161 * addr:Descriptor address.
162 * size:Each descriptor is 8 bytes. Size of the descriptor fifo must
163 * contain an integer number of Descriptors.
164 */
165struct bam_desc {
166 uint32_t addr;
167 uint16_t size;
168 uint8_t reserved;
169 uint8_t flags;
170} __PACKED;
171
172struct bam_desc_fifo {
173 struct bam_desc *head;
174 struct bam_desc *current;
175 uint16_t size;
176 uint16_t offset;
177};
178
179/* Structure to define BAM pipes
180 * pipe_state: BAM pipe states.
181 * trans_type: BAM tranaction type.
182 * evt_gen_threshold: This register configures the threshold value for
183 * Read/Write event generation by the BAM
184 * towards another BAM.
185 * fifo: Circular fifo associated with this pipe.
186 * num_pipe: Number of pipes used in this bam.
187 * pipe: Pipe number for this pipe.
188 * spi_num: SPI number for the BAM interrupt.
189 * int_mode: Specifies the pipe mode.
190 * 1: Interrupt mode
191 * 0: Polling mode
192 */
193struct bam_pipe {
194 enum bam_pipe_state state;
195 enum bam_transaction_type trans_type;
196 struct bam_desc_fifo fifo;
197 uint16_t evt_gen_threshold;
198 uint8_t pipe_num;
199 uint8_t spi_num;
200 uint8_t int_mode;
201 uint8_t initialized;
Deepa Dinamania0407ea2013-07-09 12:51:45 -0700202 uint8_t lock_grp;
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700203};
204
205/* Structure to define a BAM instance being used
206 * base:Base address for the BAM.
207 * type:BAM type.
208 * mode:BAM mode.
209 * pipe_pair:The pipe pairs to be used to access the BAM.
210 * threshold:This Register holds a threshold value for the
211 * counter summing the Size of the Descriptors Provided.
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800212 * ee:Execution Environment for the BAM.
213 * desc_len: Max desc length for the current BAM.
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700214 */
215struct bam_instance {
216 uint32_t base;
217 enum bam_type type;
218 enum bam_mode mode;
219 uint8_t num_of_pipes;
220 struct bam_pipe pipe[3];
221 uint16_t threshold;
Deepa Dinamanie9ded132012-11-27 15:03:38 -0800222 uint32_t ee;
223 uint16_t max_desc_len;
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700224 void (*callback)(int);
225};
226
227/* Command element(CE) structure*/
228struct cmd_element {
229 uint32_t addr_n_cmd;
230 uint32_t reg_data;
231 uint32_t reg_mask;
232 uint32_t reserve;
233} __PACKED;
234
235void bam_init(struct bam_instance *bam);
236void bam_sys_pipe_init(struct bam_instance *bam,
237 uint8_t pipe_num);
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700238int bam_pipe_fifo_init(struct bam_instance *bam,
239 uint8_t pipe_num);
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700240struct cmd_element* bam_add_cmd_element(struct cmd_element *ptr,
241 uint32_t addr,
242 uint32_t data,
243 enum bam_ce_cmd_t cmd_type);
244int bam_add_desc(struct bam_instance *bam,
245 unsigned int pipe_num,
246 unsigned char *data_ptr,
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700247 unsigned int data_len,
248 unsigned flags);
249int bam_add_one_desc(struct bam_instance *bam,
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700250 unsigned int pipe_num,
251 unsigned char*,
252 uint32_t len,
253 uint8_t flags);
254void bam_sys_gen_event(struct bam_instance *bam,
255 uint8_t pipe_num,
256 unsigned int num_desc);
257int bam_wait_for_interrupt(struct bam_instance *bam,
258 uint8_t pipe_num,
259 enum p_int_type interrupt);
Deepa Dinamanie5ccd6c2012-08-16 11:41:06 -0700260void bam_read_offset_update(struct bam_instance *bam, unsigned int pipe_num);
Deepa Dinamani87feab82012-10-04 14:28:05 -0700261void bam_pipe_reset(struct bam_instance *bam,
262 uint8_t pipe_num);
Deepa Dinamani9d470af2012-06-29 18:27:17 -0700263
264#endif