2 * Intel Smart Sound Technology
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #ifndef __SOUND_SOC_SST_DSP_PRIV_H
18 #define __SOUND_SOC_SST_DSP_PRIV_H
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/interrupt.h>
23 #include <linux/firmware.h>
29 /* do we need to remove or keep */
30 #define DSP_DRAM_ADDR_OFFSET 0x400000
33 * DSP Operations exported by platform Audio DSP driver.
36 /* DSP core boot / reset */
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
*);
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
);
50 void (*ram_read
)(struct sst_dsp
*sst
, void *dest
, void __iomem
*src
,
52 void (*ram_write
)(struct sst_dsp
*sst
, void __iomem
*dest
, void *src
,
55 void (*dump
)(struct sst_dsp
*);
58 irqreturn_t (*irq_handler
)(int irq
, void *context
);
60 /* SST init and free */
61 int (*init
)(struct sst_dsp
*sst
, struct sst_pdata
*pdata
);
62 void (*free
)(struct sst_dsp
*sst
);
64 /* FW module parser/loader */
65 int (*parse_fw
)(struct sst_fw
*sst_fw
);
69 * Audio DSP memory offsets and addresses.
80 void __iomem
*pci_cfg
;
85 * Audio DSP Mailbox configuration.
88 void __iomem
*in_base
;
89 void __iomem
*out_base
;
95 * Audio DSP memory block types.
105 * Audio DSP Generic Firmware File.
107 * SST Firmware files can consist of 1..N modules. This generic structure is
108 * used to manage each firmware file and it's modules regardless of SST firmware
109 * type. A SST driver may load multiple FW files.
114 /* base addresses of FW file data */
115 dma_addr_t dmable_fw_paddr
; /* physical address of fw data */
116 void *dma_buf
; /* virtual address of fw data */
117 u32 size
; /* size of fw data */
120 struct list_head list
; /* DSP list of FW */
121 struct list_head module_list
; /* FW list of modules */
123 void *private; /* core doesn't touch this */
127 * Audio DSP Generic Module Template.
129 * Used to define and register a new FW module. This data is extracted from
130 * FW module header information.
132 struct sst_module_template
{
134 u32 entry
; /* entry point */
140 * Block Allocator - Used to allocate blocks of DSP memory.
142 struct sst_block_allocator
{
146 enum sst_mem_type type
;
150 * Runtime Module Instance - A module object can be instanciated multiple
151 * times within the DSP FW.
153 struct sst_module_runtime
{
156 struct sst_module
*module
; /* parent module we belong too */
158 u32 persistent_offset
; /* private memory offset */
161 struct list_head list
;
162 struct list_head block_list
; /* list of blocks used */
166 * Runtime Module Context - The runtime context must be manually stored by the
167 * driver prior to enter S3 and restored after leaving S3. This should really be
168 * part of the memory context saved by the enter D3 message IPC ???
170 struct sst_module_runtime_context
{
171 dma_addr_t dma_buffer
;
176 * Audio DSP Generic Module.
178 * Each Firmware file can consist of 1..N modules. A module can span multiple
179 * ADSP memory blocks. The simplest FW will be a file with 1 module. A module
180 * can be instanciated multiple times in the DSP.
184 struct sst_fw
*sst_fw
; /* parent FW we belong too */
186 /* module configuration */
188 u32 entry
; /* module entry point */
189 s32 offset
; /* module offset in firmware file */
190 u32 size
; /* module size */
191 u32 scratch_size
; /* global scratch memory required */
192 u32 persistent_size
; /* private memory required */
193 enum sst_mem_type type
; /* destination memory type */
194 u32 data_offset
; /* offset in ADSP memory space */
195 void *data
; /* module data */
198 u32 usage_count
; /* can be unloaded if count == 0 */
199 void *private; /* core doesn't touch this */
202 struct list_head block_list
; /* Module list of blocks in use */
203 struct list_head list
; /* DSP list of modules */
204 struct list_head list_fw
; /* FW list of modules */
205 struct list_head runtime_list
; /* list of runtime module objects*/
209 * SST Memory Block operations.
211 struct sst_block_ops
{
212 int (*enable
)(struct sst_mem_block
*block
);
213 int (*disable
)(struct sst_mem_block
*block
);
217 * SST Generic Memory Block.
219 * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
222 struct sst_mem_block
{
224 struct sst_module
*module
; /* module that uses this block */
227 u32 offset
; /* offset from base */
228 u32 size
; /* block size */
229 u32 index
; /* block index 0..N */
230 enum sst_mem_type type
; /* block memory type IRAM/DRAM */
231 struct sst_block_ops
*ops
; /* block operations, if any */
234 u32 bytes_used
; /* bytes in use by modules */
235 void *private; /* generic core does not touch this */
236 int users
; /* number of modules using this block */
239 struct list_head module_list
; /* Module list of blocks */
240 struct list_head list
; /* Map list of free/used blocks */
244 * Generic SST Shim Interface.
249 struct sst_dsp_device
*sst_dev
;
250 spinlock_t spinlock
; /* IPC locking */
251 struct mutex mutex
; /* DSP FW lock */
253 struct device
*dma_dev
;
254 void *thread_context
;
258 /* list of free and used ADSP memory blocks */
259 struct list_head used_block_list
;
260 struct list_head free_block_list
;
266 struct dentry
*debugfs_root
;
269 struct sst_addr addr
;
272 struct sst_mailbox mailbox
;
274 /* SST FW files loaded and their modules */
275 struct list_head module_list
;
276 struct list_head fw_list
;
279 struct list_head scratch_block_list
;
284 struct sst_pdata
*pdata
;
291 /* Size optimised DRAM/IRAM memcpy */
292 static inline void sst_dsp_write(struct sst_dsp
*sst
, void *src
,
293 u32 dest_offset
, size_t bytes
)
295 sst
->ops
->ram_write(sst
, sst
->addr
.lpe
+ dest_offset
, src
, bytes
);
298 static inline void sst_dsp_read(struct sst_dsp
*sst
, void *dest
,
299 u32 src_offset
, size_t bytes
)
301 sst
->ops
->ram_read(sst
, dest
, sst
->addr
.lpe
+ src_offset
, bytes
);
304 static inline void *sst_dsp_get_thread_context(struct sst_dsp
*sst
)
306 return sst
->thread_context
;
309 /* Create/Free FW files - can contain multiple modules */
310 struct sst_fw
*sst_fw_new(struct sst_dsp
*dsp
,
311 const struct firmware
*fw
, void *private);
312 void sst_fw_free(struct sst_fw
*sst_fw
);
313 void sst_fw_free_all(struct sst_dsp
*dsp
);
314 int sst_fw_reload(struct sst_fw
*sst_fw
);
315 void sst_fw_unload(struct sst_fw
*sst_fw
);
317 /* Create/Free firmware modules */
318 struct sst_module
*sst_module_new(struct sst_fw
*sst_fw
,
319 struct sst_module_template
*template, void *private);
320 void sst_module_free(struct sst_module
*module
);
321 struct sst_module
*sst_module_get_from_id(struct sst_dsp
*dsp
, u32 id
);
322 int sst_module_alloc_blocks(struct sst_module
*module
);
323 int sst_module_free_blocks(struct sst_module
*module
);
325 /* Create/Free firmware module runtime instances */
326 struct sst_module_runtime
*sst_module_runtime_new(struct sst_module
*module
,
327 int id
, void *private);
328 void sst_module_runtime_free(struct sst_module_runtime
*runtime
);
329 struct sst_module_runtime
*sst_module_runtime_get_from_id(
330 struct sst_module
*module
, u32 id
);
331 int sst_module_runtime_alloc_blocks(struct sst_module_runtime
*runtime
,
333 int sst_module_runtime_free_blocks(struct sst_module_runtime
*runtime
);
334 int sst_module_runtime_save(struct sst_module_runtime
*runtime
,
335 struct sst_module_runtime_context
*context
);
336 int sst_module_runtime_restore(struct sst_module_runtime
*runtime
,
337 struct sst_module_runtime_context
*context
);
339 /* generic block allocation */
340 int sst_alloc_blocks(struct sst_dsp
*dsp
, struct sst_block_allocator
*ba
,
341 struct list_head
*block_list
);
342 int sst_free_blocks(struct sst_dsp
*dsp
, struct list_head
*block_list
);
344 /* scratch allocation */
345 int sst_block_alloc_scratch(struct sst_dsp
*dsp
);
346 void sst_block_free_scratch(struct sst_dsp
*dsp
);
348 /* Register the DSPs memory blocks - would be nice to read from ACPI */
349 struct 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
,
352 void sst_mem_block_unregister_all(struct sst_dsp
*dsp
);
354 /* Create/Free DMA resources */
355 int sst_dma_new(struct sst_dsp
*sst
);
356 void sst_dma_free(struct sst_dma
*dma
);
358 u32
sst_dsp_get_offset(struct sst_dsp
*dsp
, u32 offset
,
359 enum sst_mem_type type
);