blob: b65b9c0d87503ecf52bfcd335dd45bc9ec518023 [file] [log] [blame]
Vinod Koul163d2082014-10-16 20:00:13 +05301/*
2 * sst.h - Intel SST Driver for audio engine
3 *
4 * Copyright (C) 2008-14 Intel Corporation
5 * Authors: Vinod Koul <vinod.koul@intel.com>
6 * Harsha Priya <priya.harsha@intel.com>
7 * Dharageswari R <dharageswari.r@intel.com>
8 * KP Jeeja <jeeja.kp@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 *
22 * Common private declarations for SST
23 */
24#ifndef __SST_H__
25#define __SST_H__
26
27#include <linux/firmware.h>
28
29/* driver names */
30#define SST_DRV_NAME "intel_sst_driver"
31#define SST_MRFLD_PCI_ID 0x119A
32
33#define SST_SUSPEND_DELAY 2000
34#define FW_CONTEXT_MEM (64*1024)
35#define SST_ICCM_BOUNDARY 4
36#define SST_CONFIG_SSP_SIGN 0x7ffe8001
37
38#define MRFLD_FW_VIRTUAL_BASE 0xC0000000
39#define MRFLD_FW_DDR_BASE_OFFSET 0x0
40#define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
41#define MRFLD_FW_BSS_RESET_BIT 0
42
43enum sst_states {
44 SST_FW_LOADING = 1,
45 SST_FW_RUNNING,
46 SST_RESET,
47 SST_SHUTDOWN,
48};
49
50enum sst_algo_ops {
51 SST_SET_ALGO = 0,
52 SST_GET_ALGO = 1,
53};
54
55#define SST_BLOCK_TIMEOUT 1000
56
57#define FW_SIGNATURE_SIZE 4
58
59/* stream states */
60enum sst_stream_states {
61 STREAM_UN_INIT = 0, /* Freed/Not used stream */
62 STREAM_RUNNING = 1, /* Running */
63 STREAM_PAUSED = 2, /* Paused stream */
64 STREAM_DECODE = 3, /* stream is in decoding only state */
65 STREAM_INIT = 4, /* stream init, waiting for data */
66 STREAM_RESET = 5, /* force reset on recovery */
67};
68
69enum sst_ram_type {
70 SST_IRAM = 1,
71 SST_DRAM = 2,
72 SST_DDR = 5,
73 SST_CUSTOM_INFO = 7, /* consists of FW binary information */
74};
75
76/* SST shim registers to structure mapping */
77union interrupt_reg {
78 struct {
79 u64 done_interrupt:1;
80 u64 busy_interrupt:1;
81 u64 rsvd:62;
82 } part;
83 u64 full;
84};
85
86union sst_pisr_reg {
87 struct {
88 u32 pssp0:1;
89 u32 pssp1:1;
90 u32 rsvd0:3;
91 u32 dmac:1;
92 u32 rsvd1:26;
93 } part;
94 u32 full;
95};
96
97union sst_pimr_reg {
98 struct {
99 u32 ssp0:1;
100 u32 ssp1:1;
101 u32 rsvd0:3;
102 u32 dmac:1;
103 u32 rsvd1:10;
104 u32 ssp0_sc:1;
105 u32 ssp1_sc:1;
106 u32 rsvd2:3;
107 u32 dmac_sc:1;
108 u32 rsvd3:10;
109 } part;
110 u32 full;
111};
112
113union config_status_reg_mrfld {
114 struct {
115 u64 lpe_reset:1;
116 u64 lpe_reset_vector:1;
117 u64 runstall:1;
118 u64 pwaitmode:1;
119 u64 clk_sel:3;
120 u64 rsvd2:1;
121 u64 sst_clk:3;
122 u64 xt_snoop:1;
123 u64 rsvd3:4;
124 u64 clk_sel1:6;
125 u64 clk_enable:3;
126 u64 rsvd4:6;
127 u64 slim0baseclk:1;
128 u64 rsvd:32;
129 } part;
130 u64 full;
131};
132
133union interrupt_reg_mrfld {
134 struct {
135 u64 done_interrupt:1;
136 u64 busy_interrupt:1;
137 u64 rsvd:62;
138 } part;
139 u64 full;
140};
141
142union sst_imr_reg_mrfld {
143 struct {
144 u64 done_interrupt:1;
145 u64 busy_interrupt:1;
146 u64 rsvd:62;
147 } part;
148 u64 full;
149};
150
151/**
152 * struct sst_block - This structure is used to block a user/fw data call to another
153 * fw/user call
154 *
155 * @condition: condition for blocking check
156 * @ret_code: ret code when block is released
157 * @data: data ptr
158 * @size: size of data
159 * @on: block condition
160 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
161 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
162 * @node: list head node
163 */
164struct sst_block {
165 bool condition;
166 int ret_code;
167 void *data;
168 u32 size;
169 bool on;
170 u32 msg_id;
171 u32 drv_id;
172 struct list_head node;
173};
174
175/**
176 * struct stream_info - structure that holds the stream information
177 *
178 * @status : stream current state
179 * @prev : stream prev state
180 * @ops : stream operation pb/cp/drm...
181 * @bufs: stream buffer list
182 * @lock : stream mutex for protecting state
183 * @pcm_substream : PCM substream
184 * @period_elapsed : PCM period elapsed callback
185 * @sfreq : stream sampling freq
186 * @str_type : stream type
187 * @cumm_bytes : cummulative bytes decoded
188 * @str_type : stream type
189 * @src : stream source
190 */
191struct stream_info {
192 unsigned int status;
193 unsigned int prev;
194 unsigned int ops;
195 struct mutex lock;
196
197 void *pcm_substream;
198 void (*period_elapsed)(void *pcm_substream);
199
200 unsigned int sfreq;
201 u32 cumm_bytes;
202
203 void *compr_cb_param;
204 void (*compr_cb)(void *compr_cb_param);
205
206 void *drain_cb_param;
207 void (*drain_notify)(void *drain_cb_param);
208
209 unsigned int num_ch;
210 unsigned int pipe_id;
211 unsigned int str_id;
212 unsigned int task_id;
213};
214
215#define SST_FW_SIGN "$SST"
216#define SST_FW_LIB_SIGN "$LIB"
217
218/**
219 * struct sst_fw_header - FW file headers
220 *
221 * @signature : FW signature
222 * @file_size: size of fw image
223 * @modules : # of modules
224 * @file_format : version of header format
225 * @reserved : reserved fields
226 */
227struct sst_fw_header {
228 unsigned char signature[FW_SIGNATURE_SIZE];
229 u32 file_size;
230 u32 modules;
231 u32 file_format;
232 u32 reserved[4];
233};
234
235/**
236 * struct fw_module_header - module header in FW
237 *
238 * @signature: module signature
239 * @mod_size: size of module
240 * @blocks: block count
241 * @type: block type
242 * @entry_point: module netry point
243 */
244struct fw_module_header {
245 unsigned char signature[FW_SIGNATURE_SIZE];
246 u32 mod_size;
247 u32 blocks;
248 u32 type;
249 u32 entry_point;
250};
251
252/**
253 * struct fw_block_info - block header for FW
254 *
255 * @type: block ram type I/D
256 * @size: size of block
257 * @ram_offset: offset in ram
258 */
259struct fw_block_info {
260 enum sst_ram_type type;
261 u32 size;
262 u32 ram_offset;
263 u32 rsvd;
264};
265
266struct sst_runtime_param {
267 struct snd_sst_runtime_params param;
268};
269
270struct sst_sg_list {
271 struct scatterlist *src;
272 struct scatterlist *dst;
273 int list_len;
274 unsigned int sg_idx;
275};
276
277struct sst_memcpy_list {
278 struct list_head memcpylist;
279 void *dstn;
280 const void *src;
281 u32 size;
282 bool is_io;
283};
284
285/*Firmware Module Information*/
286enum sst_lib_dwnld_status {
287 SST_LIB_NOT_FOUND = 0,
288 SST_LIB_FOUND,
289 SST_LIB_DOWNLOADED,
290};
291
292struct sst_module_info {
293 const char *name; /*Library name*/
294 u32 id; /*Module ID*/
295 u32 entry_pt; /*Module entry point*/
296 u8 status; /*module status*/
297 u8 rsvd1;
298 u16 rsvd2;
299};
300
301/*
302 * Structure for managing the Library Region(1.5MB)
303 * in DDR in Merrifield
304 */
305struct sst_mem_mgr {
306 phys_addr_t current_base;
307 int avail;
308 unsigned int count;
309};
310
311struct sst_ipc_reg {
312 int ipcx;
313 int ipcd;
314};
315
316struct sst_shim_regs64 {
317 u64 csr;
318 u64 pisr;
319 u64 pimr;
320 u64 isrx;
321 u64 isrd;
322 u64 imrx;
323 u64 imrd;
324 u64 ipcx;
325 u64 ipcd;
326 u64 isrsc;
327 u64 isrlpesc;
328 u64 imrsc;
329 u64 imrlpesc;
330 u64 ipcsc;
331 u64 ipclpesc;
332 u64 clkctl;
333 u64 csr2;
334};
335
336/**
337 * struct intel_sst_drv - driver ops
338 *
339 * @sst_state : current sst device state
Subhransu S. Prusty39581032014-10-24 13:49:46 +0530340 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
341 * devices
Vinod Koul163d2082014-10-16 20:00:13 +0530342 * @shim : SST shim pointer
343 * @mailbox : SST mailbox pointer
344 * @iram : SST IRAM pointer
345 * @dram : SST DRAM pointer
346 * @pdata : SST info passed as a part of pci platform data
347 * @shim_phy_add : SST shim phy addr
348 * @shim_regs64: Struct to save shim registers
349 * @ipc_dispatch_list : ipc messages dispatched
350 * @rx_list : to copy the process_reply/process_msg from DSP
351 * @ipc_post_msg_wq : wq to post IPC messages context
352 * @mad_ops : MAD driver operations registered
353 * @mad_wq : MAD driver wq
354 * @post_msg_wq : wq to post IPC messages
355 * @streams : sst stream contexts
356 * @list_lock : sst driver list lock (deprecated)
357 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
358 * @block_lock : spin lock to add block to block_list and assign pvt_id
359 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
360 * @scard_ops : sst card ops
361 * @pci : sst pci device struture
362 * @dev : pointer to current device struct
363 * @sst_lock : sst device lock
364 * @pvt_id : sst private id
365 * @stream_cnt : total sst active stream count
366 * @pb_streams : total active pb streams
367 * @cp_streams : total active cp streams
368 * @audio_start : audio status
369 * @qos : PM Qos struct
370 * firmware_name : Firmware / Library name
371 */
372struct intel_sst_drv {
373 int sst_state;
374 int irq_num;
Subhransu S. Prusty39581032014-10-24 13:49:46 +0530375 unsigned int dev_id;
Vinod Koul163d2082014-10-16 20:00:13 +0530376 void __iomem *ddr;
377 void __iomem *shim;
378 void __iomem *mailbox;
379 void __iomem *iram;
380 void __iomem *dram;
381 unsigned int mailbox_add;
382 unsigned int iram_base;
383 unsigned int dram_base;
384 unsigned int shim_phy_add;
385 unsigned int iram_end;
386 unsigned int dram_end;
387 unsigned int ddr_end;
388 unsigned int ddr_base;
389 unsigned int mailbox_recv_offset;
390 struct sst_shim_regs64 *shim_regs64;
391 struct list_head block_list;
392 struct list_head ipc_dispatch_list;
393 struct sst_platform_info *pdata;
394 struct list_head rx_list;
395 struct work_struct ipc_post_msg_wq;
396 wait_queue_head_t wait_queue;
397 struct workqueue_struct *post_msg_wq;
398 unsigned int tstamp;
399 /* str_id 0 is not used */
400 struct stream_info streams[MAX_NUM_STREAMS+1];
401 spinlock_t ipc_spin_lock;
402 spinlock_t block_lock;
403 spinlock_t rx_msg_lock;
404 struct pci_dev *pci;
405 struct device *dev;
406 volatile long unsigned pvt_id;
407 struct mutex sst_lock;
408 unsigned int stream_cnt;
409 unsigned int csr_value;
410 void *fw_in_mem;
411 struct sst_sg_list fw_sg_list, library_list;
412 struct intel_sst_ops *ops;
413 struct sst_info info;
414 struct pm_qos_request *qos;
415 unsigned int use_dma;
416 unsigned int use_lli;
417 atomic_t fw_clear_context;
418 bool lib_dwnld_reqd;
419 struct list_head memcpy_list;
420 struct sst_ipc_reg ipc_reg;
421 struct sst_mem_mgr lib_mem_mgr;
422 /*
423 * Holder for firmware name. Due to async call it needs to be
424 * persistent till worker thread gets called
425 */
426 char firmware_name[20];
427};
428
429/* misc definitions */
430#define FW_DWNL_ID 0x01
431
432struct intel_sst_ops {
433 irqreturn_t (*interrupt)(int, void *);
434 irqreturn_t (*irq_thread)(int, void *);
435 void (*clear_interrupt)(struct intel_sst_drv *ctx);
436 int (*start)(struct intel_sst_drv *ctx);
437 int (*reset)(struct intel_sst_drv *ctx);
438 void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
439 int (*post_message)(struct intel_sst_drv *ctx,
440 struct ipc_post *msg, bool sync);
441 void (*process_message)(struct ipc_post *msg);
442 void (*set_bypass)(bool set);
443 int (*save_dsp_context)(struct intel_sst_drv *sst);
444 void (*restore_dsp_context)(void);
445 int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
446 void (*post_download)(struct intel_sst_drv *sst);
447};
448
449int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
450int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
451int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
452int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
453int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
454int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
455 struct snd_sst_bytes_v2 *sbytes);
456int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
457int sst_set_metadata(int str_id, char *params);
458int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
459 struct snd_sst_params *str_param);
460int sst_get_stream_allocated(struct intel_sst_drv *ctx,
461 struct snd_sst_params *str_param,
462 struct snd_sst_lib_download **lib_dnld);
463int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
464 int str_id, bool partial_drain);
465int sst_post_message_mrfld(struct intel_sst_drv *ctx,
466 struct ipc_post *msg, bool sync);
467void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
468int sst_start_mrfld(struct intel_sst_drv *ctx);
469int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
470void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
471
472int sst_load_fw(struct intel_sst_drv *ctx);
473int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
474void sst_post_download_mrfld(struct intel_sst_drv *ctx);
475int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
476void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
477
478int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
479 struct sst_block *block);
480int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
481 struct sst_block *block);
482int sst_create_ipc_msg(struct ipc_post **arg, bool large);
483int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
484void sst_clean_stream(struct stream_info *stream);
485int intel_sst_register_compress(struct intel_sst_drv *sst);
486int intel_sst_remove_compress(struct intel_sst_drv *sst);
487void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
488int sst_send_sync_msg(int ipc, int str_id);
489int sst_get_num_channel(struct snd_sst_params *str_param);
490int sst_get_sfreq(struct snd_sst_params *str_param);
491int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
492void sst_restore_fw_context(void);
493struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
494 u32 msg_id, u32 drv_id);
495int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
496 struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
497 u32 msg_id, u32 drv_id);
498int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
499int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
500 u32 drv_id, u32 ipc, void *data, u32 size);
501int sst_request_firmware_async(struct intel_sst_drv *ctx);
502int sst_driver_ops(struct intel_sst_drv *sst);
503struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
504void sst_firmware_load_cb(const struct firmware *fw, void *context);
505int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
506 int task_id, int ipc_msg, int cmd_id, int pipe_id,
507 size_t mbox_data_len, const void *mbox_data, void **data,
508 bool large, bool fill_dsp, bool sync, bool response);
509
510void sst_save_shim64(struct intel_sst_drv *ctx, void __iomem *shim,
511 struct sst_shim_regs64 *shim_regs);
512void sst_process_pending_msg(struct work_struct *work);
513int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
514void sst_init_stream(struct stream_info *stream,
515 int codec, int sst_id, int ops, u8 slot);
516int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
517struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
518 int str_id);
519int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
520 u32 pipe_id);
521u32 relocate_imr_addr_mrfld(u32 base_addr);
522void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
523 struct ipc_post *msg);
524int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
525int sst_shim_write(void __iomem *addr, int offset, int value);
526u32 sst_shim_read(void __iomem *addr, int offset);
527u64 sst_reg_read64(void __iomem *addr, int offset);
528int sst_shim_write64(void __iomem *addr, int offset, u64 value);
529u64 sst_shim_read64(void __iomem *addr, int offset);
530void sst_set_fw_state_locked(
531 struct intel_sst_drv *sst_drv_ctx, int sst_state);
532void sst_fill_header_mrfld(union ipc_header_mrfld *header,
533 int msg, int task_id, int large, int drv_id);
534void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
535 int pipe_id, int len);
536
537int sst_register(struct device *);
538int sst_unregister(struct device *);
539
540#endif