Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Intel Smart Sound Technology |
| 3 | * |
| 4 | * Copyright (C) 2013, Intel Corporation. All rights reserved. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 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 | struct sst_mem_block; |
| 26 | struct sst_module; |
| 27 | struct sst_fw; |
| 28 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 29 | /* do we need to remove or keep */ |
| 30 | #define DSP_DRAM_ADDR_OFFSET 0x400000 |
| 31 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 32 | /* |
| 33 | * DSP Operations exported by platform Audio DSP driver. |
| 34 | */ |
| 35 | struct sst_ops { |
| 36 | /* DSP core boot / reset */ |
| 37 | void (*boot)(struct sst_dsp *); |
| 38 | void (*reset)(struct sst_dsp *); |
Liam Girdwood | d96c53a | 2014-10-29 15:40:28 +0000 | [diff] [blame] | 39 | int (*wake)(struct sst_dsp *); |
| 40 | void (*sleep)(struct sst_dsp *); |
| 41 | void (*stall)(struct sst_dsp *); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 42 | |
| 43 | /* Shim IO */ |
| 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); |
| 48 | |
| 49 | /* DSP I/DRAM IO */ |
| 50 | void (*ram_read)(struct sst_dsp *sst, void *dest, void __iomem *src, |
| 51 | size_t bytes); |
| 52 | void (*ram_write)(struct sst_dsp *sst, void __iomem *dest, void *src, |
| 53 | size_t bytes); |
| 54 | |
| 55 | void (*dump)(struct sst_dsp *); |
| 56 | |
| 57 | /* IRQ handlers */ |
| 58 | irqreturn_t (*irq_handler)(int irq, void *context); |
| 59 | |
| 60 | /* SST init and free */ |
| 61 | int (*init)(struct sst_dsp *sst, struct sst_pdata *pdata); |
| 62 | void (*free)(struct sst_dsp *sst); |
| 63 | |
| 64 | /* FW module parser/loader */ |
| 65 | int (*parse_fw)(struct sst_fw *sst_fw); |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * Audio DSP memory offsets and addresses. |
| 70 | */ |
| 71 | struct sst_addr { |
| 72 | u32 lpe_base; |
| 73 | u32 shim_offset; |
| 74 | u32 iram_offset; |
| 75 | u32 dram_offset; |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 76 | u32 dsp_iram_offset; |
| 77 | u32 dsp_dram_offset; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 78 | void __iomem *lpe; |
| 79 | void __iomem *shim; |
| 80 | void __iomem *pci_cfg; |
| 81 | void __iomem *fw_ext; |
| 82 | }; |
| 83 | |
| 84 | /* |
| 85 | * Audio DSP Mailbox configuration. |
| 86 | */ |
| 87 | struct sst_mailbox { |
| 88 | void __iomem *in_base; |
| 89 | void __iomem *out_base; |
| 90 | size_t in_size; |
| 91 | size_t out_size; |
| 92 | }; |
| 93 | |
| 94 | /* |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 95 | * Audio DSP memory block types. |
| 96 | */ |
| 97 | enum sst_mem_type { |
| 98 | SST_MEM_IRAM = 0, |
| 99 | SST_MEM_DRAM = 1, |
| 100 | SST_MEM_ANY = 2, |
| 101 | SST_MEM_CACHE= 3, |
| 102 | }; |
| 103 | |
| 104 | /* |
| 105 | * Audio DSP Generic Firmware File. |
| 106 | * |
| 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. |
| 110 | */ |
| 111 | struct sst_fw { |
| 112 | struct sst_dsp *dsp; |
| 113 | |
| 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 */ |
| 118 | |
| 119 | /* lists */ |
| 120 | struct list_head list; /* DSP list of FW */ |
| 121 | struct list_head module_list; /* FW list of modules */ |
| 122 | |
| 123 | void *private; /* core doesn't touch this */ |
| 124 | }; |
| 125 | |
| 126 | /* |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 127 | * Audio DSP Generic Module Template. |
| 128 | * |
| 129 | * Used to define and register a new FW module. This data is extracted from |
| 130 | * FW module header information. |
| 131 | */ |
| 132 | struct sst_module_template { |
| 133 | u32 id; |
| 134 | u32 entry; /* entry point */ |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 135 | u32 scratch_size; |
| 136 | u32 persistent_size; |
| 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Block Allocator - Used to allocate blocks of DSP memory. |
| 141 | */ |
| 142 | struct sst_block_allocator { |
| 143 | u32 id; |
| 144 | u32 offset; |
| 145 | int size; |
| 146 | enum sst_mem_type type; |
| 147 | }; |
| 148 | |
| 149 | /* |
| 150 | * Runtime Module Instance - A module object can be instanciated multiple |
| 151 | * times within the DSP FW. |
| 152 | */ |
| 153 | struct sst_module_runtime { |
| 154 | struct sst_dsp *dsp; |
| 155 | int id; |
| 156 | struct sst_module *module; /* parent module we belong too */ |
| 157 | |
| 158 | u32 persistent_offset; /* private memory offset */ |
| 159 | void *private; |
| 160 | |
| 161 | struct list_head list; |
| 162 | struct list_head block_list; /* list of blocks used */ |
| 163 | }; |
| 164 | |
| 165 | /* |
| 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 ??? |
| 169 | */ |
| 170 | struct sst_module_runtime_context { |
| 171 | dma_addr_t dma_buffer; |
| 172 | u32 *buffer; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | /* |
Lu, Han | 9449d39 | 2015-03-10 10:41:20 +0800 | [diff] [blame] | 176 | * Audio DSP Module State |
| 177 | */ |
| 178 | enum sst_module_state { |
| 179 | SST_MODULE_STATE_UNLOADED = 0, /* default state */ |
| 180 | SST_MODULE_STATE_LOADED, |
| 181 | SST_MODULE_STATE_INITIALIZED, /* and inactive */ |
| 182 | SST_MODULE_STATE_ACTIVE, |
| 183 | }; |
| 184 | |
| 185 | /* |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 186 | * Audio DSP Generic Module. |
| 187 | * |
| 188 | * Each Firmware file can consist of 1..N modules. A module can span multiple |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 189 | * ADSP memory blocks. The simplest FW will be a file with 1 module. A module |
| 190 | * can be instanciated multiple times in the DSP. |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 191 | */ |
| 192 | struct sst_module { |
| 193 | struct sst_dsp *dsp; |
| 194 | struct sst_fw *sst_fw; /* parent FW we belong too */ |
| 195 | |
| 196 | /* module configuration */ |
| 197 | u32 id; |
| 198 | u32 entry; /* module entry point */ |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 199 | s32 offset; /* module offset in firmware file */ |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 200 | u32 size; /* module size */ |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 201 | u32 scratch_size; /* global scratch memory required */ |
| 202 | u32 persistent_size; /* private memory required */ |
| 203 | enum sst_mem_type type; /* destination memory type */ |
| 204 | u32 data_offset; /* offset in ADSP memory space */ |
| 205 | void *data; /* module data */ |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 206 | |
| 207 | /* runtime */ |
| 208 | u32 usage_count; /* can be unloaded if count == 0 */ |
| 209 | void *private; /* core doesn't touch this */ |
| 210 | |
| 211 | /* lists */ |
| 212 | struct list_head block_list; /* Module list of blocks in use */ |
| 213 | struct list_head list; /* DSP list of modules */ |
| 214 | struct list_head list_fw; /* FW list of modules */ |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 215 | struct list_head runtime_list; /* list of runtime module objects*/ |
Lu, Han | 9449d39 | 2015-03-10 10:41:20 +0800 | [diff] [blame] | 216 | |
| 217 | /* state */ |
| 218 | enum sst_module_state state; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | /* |
| 222 | * SST Memory Block operations. |
| 223 | */ |
| 224 | struct sst_block_ops { |
| 225 | int (*enable)(struct sst_mem_block *block); |
| 226 | int (*disable)(struct sst_mem_block *block); |
| 227 | }; |
| 228 | |
| 229 | /* |
| 230 | * SST Generic Memory Block. |
| 231 | * |
| 232 | * SST ADP memory has multiple IRAM and DRAM blocks. Some ADSP blocks can be |
| 233 | * power gated. |
| 234 | */ |
| 235 | struct sst_mem_block { |
| 236 | struct sst_dsp *dsp; |
| 237 | struct sst_module *module; /* module that uses this block */ |
| 238 | |
| 239 | /* block config */ |
| 240 | u32 offset; /* offset from base */ |
| 241 | u32 size; /* block size */ |
| 242 | u32 index; /* block index 0..N */ |
| 243 | enum sst_mem_type type; /* block memory type IRAM/DRAM */ |
| 244 | struct sst_block_ops *ops; /* block operations, if any */ |
| 245 | |
| 246 | /* block status */ |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 247 | u32 bytes_used; /* bytes in use by modules */ |
| 248 | void *private; /* generic core does not touch this */ |
| 249 | int users; /* number of modules using this block */ |
| 250 | |
| 251 | /* block lists */ |
| 252 | struct list_head module_list; /* Module list of blocks */ |
| 253 | struct list_head list; /* Map list of free/used blocks */ |
| 254 | }; |
| 255 | |
| 256 | /* |
| 257 | * Generic SST Shim Interface. |
| 258 | */ |
| 259 | struct sst_dsp { |
| 260 | |
Subhransu S. Prusty | f7c765e | 2015-07-03 16:04:04 +0530 | [diff] [blame] | 261 | /* Shared for all platforms */ |
| 262 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 263 | /* runtime */ |
| 264 | struct sst_dsp_device *sst_dev; |
| 265 | spinlock_t spinlock; /* IPC locking */ |
| 266 | struct mutex mutex; /* DSP FW lock */ |
| 267 | struct device *dev; |
Liam Girdwood | 10df350 | 2014-05-02 16:56:31 +0100 | [diff] [blame] | 268 | struct device *dma_dev; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 269 | void *thread_context; |
| 270 | int irq; |
| 271 | u32 id; |
| 272 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 273 | /* operations */ |
| 274 | struct sst_ops *ops; |
| 275 | |
| 276 | /* debug FS */ |
| 277 | struct dentry *debugfs_root; |
| 278 | |
| 279 | /* base addresses */ |
| 280 | struct sst_addr addr; |
| 281 | |
| 282 | /* mailbox */ |
| 283 | struct sst_mailbox mailbox; |
| 284 | |
Subhransu S. Prusty | f7c765e | 2015-07-03 16:04:04 +0530 | [diff] [blame] | 285 | /* HSW/Byt data */ |
| 286 | |
| 287 | /* list of free and used ADSP memory blocks */ |
| 288 | struct list_head used_block_list; |
| 289 | struct list_head free_block_list; |
| 290 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 291 | /* SST FW files loaded and their modules */ |
| 292 | struct list_head module_list; |
| 293 | struct list_head fw_list; |
| 294 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 295 | /* scratch buffer */ |
| 296 | struct list_head scratch_block_list; |
| 297 | u32 scratch_offset; |
| 298 | u32 scratch_size; |
| 299 | |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 300 | /* platform data */ |
| 301 | struct sst_pdata *pdata; |
| 302 | |
| 303 | /* DMA FW loading */ |
| 304 | struct sst_dma *dma; |
| 305 | bool fw_use_dma; |
Subhransu S. Prusty | b81fd26 | 2015-07-09 21:38:54 +0530 | [diff] [blame^] | 306 | |
| 307 | /* SKL data */ |
| 308 | |
| 309 | u32 intr_status; |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | /* Size optimised DRAM/IRAM memcpy */ |
| 313 | static inline void sst_dsp_write(struct sst_dsp *sst, void *src, |
| 314 | u32 dest_offset, size_t bytes) |
| 315 | { |
| 316 | sst->ops->ram_write(sst, sst->addr.lpe + dest_offset, src, bytes); |
| 317 | } |
| 318 | |
| 319 | static inline void sst_dsp_read(struct sst_dsp *sst, void *dest, |
| 320 | u32 src_offset, size_t bytes) |
| 321 | { |
| 322 | sst->ops->ram_read(sst, dest, sst->addr.lpe + src_offset, bytes); |
| 323 | } |
| 324 | |
| 325 | static inline void *sst_dsp_get_thread_context(struct sst_dsp *sst) |
| 326 | { |
| 327 | return sst->thread_context; |
| 328 | } |
| 329 | |
| 330 | /* Create/Free FW files - can contain multiple modules */ |
| 331 | struct sst_fw *sst_fw_new(struct sst_dsp *dsp, |
| 332 | const struct firmware *fw, void *private); |
| 333 | void sst_fw_free(struct sst_fw *sst_fw); |
| 334 | void sst_fw_free_all(struct sst_dsp *dsp); |
Liam Girdwood | 555f8a80 | 2014-05-05 17:31:37 +0100 | [diff] [blame] | 335 | int sst_fw_reload(struct sst_fw *sst_fw); |
| 336 | void sst_fw_unload(struct sst_fw *sst_fw); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 337 | |
| 338 | /* Create/Free firmware modules */ |
| 339 | struct sst_module *sst_module_new(struct sst_fw *sst_fw, |
| 340 | struct sst_module_template *template, void *private); |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 341 | void sst_module_free(struct sst_module *module); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 342 | struct sst_module *sst_module_get_from_id(struct sst_dsp *dsp, u32 id); |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 343 | int sst_module_alloc_blocks(struct sst_module *module); |
| 344 | int sst_module_free_blocks(struct sst_module *module); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 345 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 346 | /* Create/Free firmware module runtime instances */ |
| 347 | struct sst_module_runtime *sst_module_runtime_new(struct sst_module *module, |
| 348 | int id, void *private); |
| 349 | void sst_module_runtime_free(struct sst_module_runtime *runtime); |
| 350 | struct sst_module_runtime *sst_module_runtime_get_from_id( |
| 351 | struct sst_module *module, u32 id); |
| 352 | int sst_module_runtime_alloc_blocks(struct sst_module_runtime *runtime, |
| 353 | int offset); |
| 354 | int sst_module_runtime_free_blocks(struct sst_module_runtime *runtime); |
| 355 | int sst_module_runtime_save(struct sst_module_runtime *runtime, |
| 356 | struct sst_module_runtime_context *context); |
| 357 | int sst_module_runtime_restore(struct sst_module_runtime *runtime, |
| 358 | struct sst_module_runtime_context *context); |
| 359 | |
| 360 | /* generic block allocation */ |
| 361 | int sst_alloc_blocks(struct sst_dsp *dsp, struct sst_block_allocator *ba, |
| 362 | struct list_head *block_list); |
| 363 | int sst_free_blocks(struct sst_dsp *dsp, struct list_head *block_list); |
| 364 | |
| 365 | /* scratch allocation */ |
| 366 | int sst_block_alloc_scratch(struct sst_dsp *dsp); |
| 367 | void sst_block_free_scratch(struct sst_dsp *dsp); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 368 | |
| 369 | /* Register the DSPs memory blocks - would be nice to read from ACPI */ |
| 370 | struct sst_mem_block *sst_mem_block_register(struct sst_dsp *dsp, u32 offset, |
| 371 | u32 size, enum sst_mem_type type, struct sst_block_ops *ops, u32 index, |
| 372 | void *private); |
| 373 | void sst_mem_block_unregister_all(struct sst_dsp *dsp); |
| 374 | |
Liam Girdwood | e9600bc | 2014-10-28 17:37:12 +0000 | [diff] [blame] | 375 | /* Create/Free DMA resources */ |
| 376 | int sst_dma_new(struct sst_dsp *sst); |
| 377 | void sst_dma_free(struct sst_dma *dma); |
| 378 | |
| 379 | u32 sst_dsp_get_offset(struct sst_dsp *dsp, u32 offset, |
| 380 | enum sst_mem_type type); |
Mark Brown | a4b1299 | 2014-03-12 23:04:35 +0000 | [diff] [blame] | 381 | #endif |