1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __SOUND_SOC_SST_DSP_PRIV_H
18#define __SOUND_SOC_SST_DSP_PRIV_H
19
20#include <linux/kernel.h>
21#include <linux/types.h>
22#include <linux/interrupt.h>
23#include <linux/firmware.h>
24
25struct sst_mem_block;
26struct sst_module;
27struct sst_fw;
28
29
30#define DSP_DRAM_ADDR_OFFSET 0x400000
31
32
33
34
35struct sst_ops {
36
37 void (*boot)(struct sst_dsp *);
38 void (*reset)(struct sst_dsp *);
39 int (*wake)(struct sst_dsp *);
40 void (*sleep)(struct sst_dsp *);
41 void (*stall)(struct sst_dsp *);
42
43
44 void (*write)(void __iomem *addr, u32 offset, u32 value);
45 u32 (*read)(void __iomem *addr, u32 offset);
46 void (*write64)(void __iomem *addr, u32 offset, u64 value);
47 u64 (*read64)(void __iomem *addr, u32 offset);
48
49
50 void (*ram_read)(struct sst_dsp *sst, void *dest, void __iomem *src,
51 size_t bytes);
52 void (*ram_write)(struct sst_dsp *sst, void __iomem *dest, void *src,
53 size_t bytes);
54
55 void (*dump)(struct sst_dsp *);
56
57
58 irqreturn_t (*irq_handler)(int irq, void *context);
59
60
61 int (*init)(struct sst_dsp *sst, struct sst_pdata *pdata);
62 void (*free)(struct sst_dsp *sst);
63
64
65 int (*parse_fw)(struct sst_fw *sst_fw);
66};
67
68
69
70
71struct sst_addr {
72 u32 lpe_base;
73 u32 shim_offset;
74 u32 iram_offset;
75 u32 dram_offset;
76 u32 dsp_iram_offset;
77 u32 dsp_dram_offset;
78 void __iomem *lpe;
79 void __iomem *shim;
80 void __iomem *pci_cfg;
81 void __iomem *fw_ext;
82};
83
84
85
86
87struct sst_mailbox {
88 void __iomem *in_base;
89 void __iomem *out_base;
90 size_t in_size;
91 size_t out_size;
92};
93
94
95
96
97enum sst_mem_type {
98 SST_MEM_IRAM = 0,
99 SST_MEM_DRAM = 1,
100 SST_MEM_ANY = 2,
101 SST_MEM_CACHE= 3,
102};
103
104
105
106
107
108
109
110
111struct sst_fw {
112 struct sst_dsp *dsp;
113
114
115 dma_addr_t dmable_fw_paddr;
116 void *dma_buf;
117 u32 size;
118
119
120 struct list_head list;
121 struct list_head module_list;
122
123 void *private;
124};
125
126
127
128
129
130
131
132struct sst_module_template {
133 u32 id;
134 u32 entry;
135 u32 scratch_size;
136 u32 persistent_size;
137};
138
139
140
141
142struct sst_block_allocator {
143 u32 id;
144 u32 offset;
145 int size;
146 enum sst_mem_type type;
147};
148
149
150
151
152
153struct sst_module_runtime {
154 struct sst_dsp *dsp;
155 int id;
156 struct sst_module *module;
157
158 u32 persistent_offset;
159 void *private;
160
161 struct list_head list;
162 struct list_head block_list;
163};
164
165
166
167
168
169
170struct sst_module_runtime_context {
171 dma_addr_t dma_buffer;
172 u32 *buffer;
173};
174
175
176
177
178
179
180
181
182struct sst_module {
183 struct sst_dsp *dsp;
184 struct sst_fw *sst_fw;
185
186
187 u32 id;
188 u32 entry;
189 s32 offset;
190 u32 size;
191 u32 scratch_size;
192 u32 persistent_size;
193 enum sst_mem_type type;
194 u32 data_offset;
195 void *data;
196
197
198 u32 usage_count;
199 void *private;
200
201
202 struct list_head block_list;
203 struct list_head list;
204 struct list_head list_fw;
205 struct list_head runtime_list;
206};
207
208
209
210
211struct sst_block_ops {
212 int (*enable)(struct sst_mem_block *block);
213 int (*disable)(struct sst_mem_block *block);
214};
215
216
217
218
219
220
221
222struct sst_mem_block {
223 struct sst_dsp *dsp;
224 struct sst_module *module;
225
226
227 u32 offset;
228 u32 size;
229 u32 index;
230 enum sst_mem_type type;
231 struct sst_block_ops *ops;
232
233
234 u32 bytes_used;
235 void *private;
236 int users;
237
238
239 struct list_head module_list;
240 struct list_head list;
241};
242
243
244
245
246struct sst_dsp {
247
248
249 struct sst_dsp_device *sst_dev;
250 spinlock_t spinlock;
251 struct mutex mutex;
252 struct device *dev;
253 struct device *dma_dev;
254 void *thread_context;
255 int irq;
256 u32 id;
257
258
259 struct list_head used_block_list;
260 struct list_head free_block_list;
261
262
263 struct sst_ops *ops;
264
265
266 struct dentry *debugfs_root;
267
268
269 struct sst_addr addr;
270
271
272 struct sst_mailbox mailbox;
273
274
275 struct list_head module_list;
276 struct list_head fw_list;
277
278
279 struct list_head scratch_block_list;
280 u32 scratch_offset;
281 u32 scratch_size;
282
283
284 struct sst_pdata *pdata;
285
286
287 struct sst_dma *dma;
288 bool fw_use_dma;
289};
290
291
292static inline void sst_dsp_write(struct sst_dsp *sst, void *src,
293 u32 dest_offset, size_t bytes)
294{
295 sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes);
296}
297
298static inline void sst_dsp_read(struct sst_dsp *sst, void *dest,
299 u32 src_offset, size_t bytes)
300{
301 sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes);
302}
303
304static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst)
305{
306 return sst->thread_context;
307}
308
309
310struct sst_fw *sst_fw_new(struct sst_dsp *dsp,
311 const struct firmware *fw, void *private);
312void sst_fw_free(struct sst_fw *sst_fw);
313void sst_fw_free_all(struct sst_dsp *dsp);
314int sst_fw_reload(struct sst_fw *sst_fw);
315void sst_fw_unload(struct sst_fw *sst_fw);
316
317
318struct sst_module *sst_module_new(struct sst_fw *sst_fw,
319 struct sst_module_template *template, void *private);
320void sst_module_free(struct sst_module *module);
321struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id);
322int sst_module_alloc_blocks(struct sst_module *module);
323int sst_module_free_blocks(struct sst_module *module);
324
325
326struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module,
327 int id, void *private);
328void sst_module_runtime_free(struct sst_module_runtime *runtime);
329struct sst_module_runtime *sst_module_runtime_get_from_id(
330 struct sst_module *module, u32 id);
331int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime,
332 int offset);
333int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime);
334int sst_module_runtime_save(struct sst_module_runtime *runtime,
335 struct sst_module_runtime_context *context);
336int sst_module_runtime_restore(struct sst_module_runtime *runtime,
337 struct sst_module_runtime_context *context);
338
339
340int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba,
341 struct list_head *block_list);
342int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list);
343
344
345int sst_block_alloc_scratch(struct sst_dsp *dsp);
346void sst_block_free_scratch(struct sst_dsp *dsp);
347
348
349struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset,
350 u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index,
351 void *private);
352void sst_mem_block_unregister_all(struct sst_dsp *dsp);
353
354
355int sst_dma_new(struct sst_dsp *sst);
356void sst_dma_free(struct sst_dma *dma);
357
358u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset,
359 enum sst_mem_type type);
360#endif
361