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