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