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>
30 * DSP Operations exported by platform Audio DSP driver.
33 /* DSP core boot / reset */
34 void (*boot
)(struct sst_dsp
*);
35 void (*reset
)(struct sst_dsp
*);
38 void (*write
)(void __iomem
*addr
, u32 offset
, u32 value
);
39 u32 (*read
)(void __iomem
*addr
, u32 offset
);
40 void (*write64
)(void __iomem
*addr
, u32 offset
, u64 value
);
41 u64 (*read64
)(void __iomem
*addr
, u32 offset
);
44 void (*ram_read
)(struct sst_dsp
*sst
, void *dest
, void __iomem
*src
,
46 void (*ram_write
)(struct sst_dsp
*sst
, void __iomem
*dest
, void *src
,
49 void (*dump
)(struct sst_dsp
*);
52 irqreturn_t (*irq_handler
)(int irq
, void *context
);
54 /* SST init and free */
55 int (*init
)(struct sst_dsp
*sst
, struct sst_pdata
*pdata
);
56 void (*free
)(struct sst_dsp
*sst
);
58 /* FW module parser/loader */
59 int (*parse_fw
)(struct sst_fw
*sst_fw
);
63 * Audio DSP memory offsets and addresses.
72 void __iomem
*pci_cfg
;
77 * Audio DSP Mailbox configuration.
80 void __iomem
*in_base
;
81 void __iomem
*out_base
;
87 * Audio DSP Firmware data types.
90 SST_DATA_M
= 0, /* module block data */
91 SST_DATA_P
= 1, /* peristant data (text, data) */
92 SST_DATA_S
= 2, /* scratch data (usually buffers) */
96 * Audio DSP memory block types.
106 * Audio DSP Generic Firmware File.
108 * SST Firmware files can consist of 1..N modules. This generic structure is
109 * used to manage each firmware file and it's modules regardless of SST firmware
110 * type. A SST driver may load multiple FW files.
115 /* base addresses of FW file data */
116 dma_addr_t dmable_fw_paddr
; /* physical address of fw data */
117 void *dma_buf
; /* virtual address of fw data */
118 u32 size
; /* size of fw data */
121 struct list_head list
; /* DSP list of FW */
122 struct list_head module_list
; /* FW list of modules */
124 void *private; /* core doesn't touch this */
128 * Audio DSP Generic Module data.
130 * This is used to dsecribe any sections of persistent (text and data) and
131 * scratch (buffers) of module data in ADSP memory space.
133 struct sst_module_data
{
135 enum sst_mem_type type
; /* destination memory type */
136 enum sst_data_type data_type
; /* type of module data */
138 u32 size
; /* size in bytes */
139 int32_t offset
; /* offset in FW file */
140 u32 data_offset
; /* offset in ADSP memory space */
141 void *data
; /* module data */
145 * Audio DSP Generic Module Template.
147 * Used to define and register a new FW module. This data is extracted from
148 * FW module header information.
150 struct sst_module_template
{
152 u32 entry
; /* entry point */
153 struct sst_module_data s
; /* scratch data */
154 struct sst_module_data p
; /* peristant data */
158 * Audio DSP Generic Module.
160 * Each Firmware file can consist of 1..N modules. A module can span multiple
161 * ADSP memory blocks. The simplest FW will be a file with 1 module.
165 struct sst_fw
*sst_fw
; /* parent FW we belong too */
167 /* module configuration */
169 u32 entry
; /* module entry point */
170 u32 offset
; /* module offset in firmware file */
171 u32 size
; /* module size */
172 struct sst_module_data s
; /* scratch data */
173 struct sst_module_data p
; /* peristant data */
176 u32 usage_count
; /* can be unloaded if count == 0 */
177 void *private; /* core doesn't touch this */
180 struct list_head block_list
; /* Module list of blocks in use */
181 struct list_head list
; /* DSP list of modules */
182 struct list_head list_fw
; /* FW list of modules */
186 * SST Memory Block operations.
188 struct sst_block_ops
{
189 int (*enable
)(struct sst_mem_block
*block
);
190 int (*disable
)(struct sst_mem_block
*block
);
194 * SST Generic Memory Block.
196 * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be
199 struct sst_mem_block
{
201 struct sst_module
*module
; /* module that uses this block */
204 u32 offset
; /* offset from base */
205 u32 size
; /* block size */
206 u32 index
; /* block index 0..N */
207 enum sst_mem_type type
; /* block memory type IRAM/DRAM */
208 struct sst_block_ops
*ops
; /* block operations, if any */
211 enum sst_data_type data_type
; /* data type held in this block */
212 u32 bytes_used
; /* bytes in use by modules */
213 void *private; /* generic core does not touch this */
214 int users
; /* number of modules using this block */
217 struct list_head module_list
; /* Module list of blocks */
218 struct list_head list
; /* Map list of free/used blocks */
222 * Generic SST Shim Interface.
227 struct sst_dsp_device
*sst_dev
;
228 spinlock_t spinlock
; /* IPC locking */
229 struct mutex mutex
; /* DSP FW lock */
231 struct device
*dma_dev
;
232 void *thread_context
;
236 /* list of free and used ADSP memory blocks */
237 struct list_head used_block_list
;
238 struct list_head free_block_list
;
244 struct dentry
*debugfs_root
;
247 struct sst_addr addr
;
250 struct sst_mailbox mailbox
;
252 /* SST FW files loaded and their modules */
253 struct list_head module_list
;
254 struct list_head fw_list
;
257 struct sst_pdata
*pdata
;
264 /* Size optimised DRAM/IRAM memcpy */
265 static inline void sst_dsp_write(struct sst_dsp
*sst
, void *src
,
266 u32 dest_offset
, size_t bytes
)
268 sst
->ops
->ram_write(sst
, sst
->addr
.lpe
+ dest_offset
, src
, bytes
);
271 static inline void sst_dsp_read(struct sst_dsp
*sst
, void *dest
,
272 u32 src_offset
, size_t bytes
)
274 sst
->ops
->ram_read(sst
, dest
, sst
->addr
.lpe
+ src_offset
, bytes
);
277 static inline void *sst_dsp_get_thread_context(struct sst_dsp
*sst
)
279 return sst
->thread_context
;
282 /* Create/Free FW files - can contain multiple modules */
283 struct sst_fw
*sst_fw_new(struct sst_dsp
*dsp
,
284 const struct firmware
*fw
, void *private);
285 void sst_fw_free(struct sst_fw
*sst_fw
);
286 void sst_fw_free_all(struct sst_dsp
*dsp
);
288 /* Create/Free firmware modules */
289 struct sst_module
*sst_module_new(struct sst_fw
*sst_fw
,
290 struct sst_module_template
*template, void *private);
291 void sst_module_free(struct sst_module
*sst_module
);
292 int sst_module_insert(struct sst_module
*sst_module
);
293 int sst_module_remove(struct sst_module
*sst_module
);
294 int sst_module_insert_fixed_block(struct sst_module
*module
,
295 struct sst_module_data
*data
);
296 struct sst_module
*sst_module_get_from_id(struct sst_dsp
*dsp
, u32 id
);
298 /* allocate/free pesistent/scratch memory regions managed by drv */
299 struct sst_module
*sst_mem_block_alloc_scratch(struct sst_dsp
*dsp
);
300 void sst_mem_block_free_scratch(struct sst_dsp
*dsp
,
301 struct sst_module
*scratch
);
302 int sst_block_module_remove(struct sst_module
*module
);
304 /* Register the DSPs memory blocks - would be nice to read from ACPI */
305 struct sst_mem_block
*sst_mem_block_register(struct sst_dsp
*dsp
, u32 offset
,
306 u32 size
, enum sst_mem_type type
, struct sst_block_ops
*ops
, u32 index
,
308 void sst_mem_block_unregister_all(struct sst_dsp
*dsp
);