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