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