1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel Smart Sound Technology
5 * Copyright (C) 2013, Intel Corporation. All rights reserved.
8 #ifndef __SOUND_SOC_SST_DSP_PRIV_H
9 #define __SOUND_SOC_SST_DSP_PRIV_H
11 #include <linux/kernel.h>
12 #include <linux/types.h>
13 #include <linux/interrupt.h>
14 #include <linux/firmware.h>
16 #include "../skylake/skl-sst-dsp.h"
22 /* do we need to remove or keep */
23 #define DSP_DRAM_ADDR_OFFSET 0x400000
26 * DSP Operations exported by platform Audio DSP driver.
29 /* DSP core boot / reset */
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
*);
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
);
43 void (*ram_read
)(struct sst_dsp
*sst
, void *dest
, void __iomem
*src
,
45 void (*ram_write
)(struct sst_dsp
*sst
, void __iomem
*dest
, void *src
,
48 void (*dump
)(struct sst_dsp
*);
51 irqreturn_t (*irq_handler
)(int irq
, void *context
);
53 /* SST init and free */
54 int (*init
)(struct sst_dsp
*sst
, struct sst_pdata
*pdata
);
55 void (*free
)(struct sst_dsp
*sst
);
57 /* FW module parser/loader */
58 int (*parse_fw
)(struct sst_fw
*sst_fw
);
62 * Audio DSP memory offsets and addresses.
77 void __iomem
*pci_cfg
;
82 * Audio DSP Mailbox configuration.
85 void __iomem
*in_base
;
86 void __iomem
*out_base
;
92 * Audio DSP memory block types.
102 * Audio DSP Generic Firmware File.
104 * SST Firmware files can consist of 1..N modules. This generic structure is
105 * used to manage each firmware file and it's modules regardless of SST firmware
106 * type. A SST driver may load multiple FW files.
111 /* base addresses of FW file data */
112 dma_addr_t dmable_fw_paddr
; /* physical address of fw data */
113 void *dma_buf
; /* virtual address of fw data */
114 u32 size
; /* size of fw data */
117 struct list_head list
; /* DSP list of FW */
118 struct list_head module_list
; /* FW list of modules */
120 void *private; /* core doesn't touch this */
124 * Audio DSP Generic Module Template.
126 * Used to define and register a new FW module. This data is extracted from
127 * FW module header information.
129 struct sst_module_template
{
131 u32 entry
; /* entry point */
137 * Block Allocator - Used to allocate blocks of DSP memory.
139 struct sst_block_allocator
{
143 enum sst_mem_type type
;
147 * Runtime Module Instance - A module object can be instantiated multiple
148 * times within the DSP FW.
150 struct sst_module_runtime
{
153 struct sst_module
*module
; /* parent module we belong too */
155 u32 persistent_offset
; /* private memory offset */
158 struct list_head list
;
159 struct list_head block_list
; /* list of blocks used */
163 * Runtime Module Context - The runtime context must be manually stored by the
164 * driver prior to enter S3 and restored after leaving S3. This should really be
165 * part of the memory context saved by the enter D3 message IPC ???
167 struct sst_module_runtime_context
{
168 dma_addr_t dma_buffer
;
173 * Audio DSP Module State
175 enum sst_module_state
{
176 SST_MODULE_STATE_UNLOADED
= 0, /* default state */
177 SST_MODULE_STATE_LOADED
,
178 SST_MODULE_STATE_INITIALIZED
, /* and inactive */
179 SST_MODULE_STATE_ACTIVE
,
183 * Audio DSP Generic Module.
185 * Each Firmware file can consist of 1..N modules. A module can span multiple
186 * ADSP memory blocks. The simplest FW will be a file with 1 module. A module
187 * can be instantiated multiple times in the DSP.
191 struct sst_fw
*sst_fw
; /* parent FW we belong too */
193 /* module configuration */
195 u32 entry
; /* module entry point */
196 s32 offset
; /* module offset in firmware file */
197 u32 size
; /* module size */
198 u32 scratch_size
; /* global scratch memory required */
199 u32 persistent_size
; /* private memory required */
200 enum sst_mem_type type
; /* destination memory type */
201 u32 data_offset
; /* offset in ADSP memory space */
202 void *data
; /* module data */
205 u32 usage_count
; /* can be unloaded if count == 0 */
206 void *private; /* core doesn't touch this */
209 struct list_head block_list
; /* Module list of blocks in use */
210 struct list_head list
; /* DSP list of modules */
211 struct list_head list_fw
; /* FW list of modules */
212 struct list_head runtime_list
; /* list of runtime module objects*/
215 enum sst_module_state state
;
219 * SST Memory Block operations.
221 struct sst_block_ops
{
222 int (*enable
)(struct sst_mem_block
*block
);
223 int (*disable
)(struct sst_mem_block
*block
);
227 * SST Generic Memory Block.
229 * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
232 struct sst_mem_block
{
234 struct sst_module
*module
; /* module that uses this block */
237 u32 offset
; /* offset from base */
238 u32 size
; /* block size */
239 u32 index
; /* block index 0..N */
240 enum sst_mem_type type
; /* block memory type IRAM/DRAM */
241 const struct sst_block_ops
*ops
;/* block operations, if any */
244 u32 bytes_used
; /* bytes in use by modules */
245 void *private; /* generic core does not touch this */
246 int users
; /* number of modules using this block */
249 struct list_head module_list
; /* Module list of blocks */
250 struct list_head list
; /* Map list of free/used blocks */
254 * Generic SST Shim Interface.
258 /* Shared for all platforms */
261 struct sst_dsp_device
*sst_dev
;
262 spinlock_t spinlock
; /* IPC locking */
263 struct mutex mutex
; /* DSP FW lock */
265 struct device
*dma_dev
;
266 void *thread_context
;
274 struct dentry
*debugfs_root
;
277 struct sst_addr addr
;
280 struct sst_mailbox mailbox
;
284 /* list of free and used ADSP memory blocks */
285 struct list_head used_block_list
;
286 struct list_head free_block_list
;
288 /* SST FW files loaded and their modules */
289 struct list_head module_list
;
290 struct list_head fw_list
;
293 struct list_head scratch_block_list
;
298 struct sst_pdata
*pdata
;
308 /* To allocate CL dma buffers */
309 struct skl_dsp_loader_ops dsp_ops
;
310 struct skl_dsp_fw_ops fw_ops
;
312 struct skl_cl_dev cl_dev
;
314 const struct firmware
*fw
;
315 struct snd_dma_buffer dmab
;
318 /* Size optimised DRAM/IRAM memcpy */
319 static inline void sst_dsp_write(struct sst_dsp
*sst
, void *src
,
320 u32 dest_offset
, size_t bytes
)
322 sst
->ops
->ram_write(sst
, sst
->addr
.lpe
+ dest_offset
, src
, bytes
);
325 static inline void sst_dsp_read(struct sst_dsp
*sst
, void *dest
,
326 u32 src_offset
, size_t bytes
)
328 sst
->ops
->ram_read(sst
, dest
, sst
->addr
.lpe
+ src_offset
, bytes
);
331 static inline void *sst_dsp_get_thread_context(struct sst_dsp
*sst
)
333 return sst
->thread_context
;
336 /* Create/Free FW files - can contain multiple modules */
337 struct sst_fw
*sst_fw_new(struct sst_dsp
*dsp
,
338 const struct firmware
*fw
, void *private);
339 void sst_fw_free(struct sst_fw
*sst_fw
);
340 void sst_fw_free_all(struct sst_dsp
*dsp
);
341 int sst_fw_reload(struct sst_fw
*sst_fw
);
342 void sst_fw_unload(struct sst_fw
*sst_fw
);
344 /* Create/Free firmware modules */
345 struct sst_module
*sst_module_new(struct sst_fw
*sst_fw
,
346 struct sst_module_template
*template, void *private);
347 void sst_module_free(struct sst_module
*module
);
348 struct sst_module
*sst_module_get_from_id(struct sst_dsp
*dsp
, u32 id
);
349 int sst_module_alloc_blocks(struct sst_module
*module
);
350 int sst_module_free_blocks(struct sst_module
*module
);
352 /* Create/Free firmware module runtime instances */
353 struct sst_module_runtime
*sst_module_runtime_new(struct sst_module
*module
,
354 int id
, void *private);
355 void sst_module_runtime_free(struct sst_module_runtime
*runtime
);
356 struct sst_module_runtime
*sst_module_runtime_get_from_id(
357 struct sst_module
*module
, u32 id
);
358 int sst_module_runtime_alloc_blocks(struct sst_module_runtime
*runtime
,
360 int sst_module_runtime_free_blocks(struct sst_module_runtime
*runtime
);
361 int sst_module_runtime_save(struct sst_module_runtime
*runtime
,
362 struct sst_module_runtime_context
*context
);
363 int sst_module_runtime_restore(struct sst_module_runtime
*runtime
,
364 struct sst_module_runtime_context
*context
);
366 /* generic block allocation */
367 int sst_alloc_blocks(struct sst_dsp
*dsp
, struct sst_block_allocator
*ba
,
368 struct list_head
*block_list
);
369 int sst_free_blocks(struct sst_dsp
*dsp
, struct list_head
*block_list
);
371 /* scratch allocation */
372 int sst_block_alloc_scratch(struct sst_dsp
*dsp
);
373 void sst_block_free_scratch(struct sst_dsp
*dsp
);
375 /* Register the DSPs memory blocks - would be nice to read from ACPI */
376 struct 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);
379 void sst_mem_block_unregister_all(struct sst_dsp
*dsp
);
381 u32
sst_dsp_get_offset(struct sst_dsp
*dsp
, u32 offset
,
382 enum sst_mem_type type
);