2 * sst.h - Intel SST Driver for audio engine
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 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
20 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 * Common private declarations for SST
27 #include <linux/firmware.h>
30 #define SST_DRV_NAME "intel_sst_driver"
31 #define SST_MRFLD_PCI_ID 0x119A
32 #define SST_BYT_ACPI_ID 0x80860F28
33 #define SST_CHV_ACPI_ID 0x808622A8
35 #define SST_SUSPEND_DELAY 2000
36 #define FW_CONTEXT_MEM (64*1024)
37 #define SST_ICCM_BOUNDARY 4
38 #define SST_CONFIG_SSP_SIGN 0x7ffe8001
40 #define MRFLD_FW_VIRTUAL_BASE 0xC0000000
41 #define MRFLD_FW_DDR_BASE_OFFSET 0x0
42 #define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
43 #define MRFLD_FW_BSS_RESET_BIT 0
45 extern const struct dev_pm_ops intel_sst_pm;
58 #define SST_BLOCK_TIMEOUT 1000
60 #define FW_SIGNATURE_SIZE 4
61 #define FW_NAME_SIZE 32
64 enum sst_stream_states {
65 STREAM_UN_INIT = 0, /* Freed/Not used stream */
66 STREAM_RUNNING = 1, /* Running */
67 STREAM_PAUSED = 2, /* Paused stream */
68 STREAM_INIT = 3, /* stream init, waiting for data */
75 SST_CUSTOM_INFO = 7, /* consists of FW binary information */
78 /* SST shim registers to structure mapping */
115 union config_status_reg_mrfld {
118 u64 lpe_reset_vector:1;
135 union interrupt_reg_mrfld {
137 u64 done_interrupt:1;
138 u64 busy_interrupt:1;
144 union sst_imr_reg_mrfld {
146 u64 done_interrupt:1;
147 u64 busy_interrupt:1;
154 * struct sst_block - This structure is used to block a user/fw data call to another
157 * @condition: condition for blocking check
158 * @ret_code: ret code when block is released
160 * @size: size of data
161 * @on: block condition
162 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
163 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
164 * @node: list head node
174 struct list_head node;
178 * struct stream_info - structure that holds the stream information
180 * @status : stream current state
181 * @prev : stream prev state
182 * @resume_status : stream current state to restore on resume
183 * @resume_prev : stream prev state to restore on resume
184 * @lock : stream mutex for protecting state
185 * @alloc_param : parameters used for stream (re-)allocation
186 * @pcm_substream : PCM substream
187 * @period_elapsed : PCM period elapsed callback
188 * @sfreq : stream sampling freq
189 * @cumm_bytes : cummulative bytes decoded
194 unsigned int resume_status;
195 unsigned int resume_prev;
197 struct snd_sst_alloc_mrfld alloc_param;
200 void (*period_elapsed)(void *pcm_substream);
205 void *compr_cb_param;
206 void (*compr_cb)(void *compr_cb_param);
208 void *drain_cb_param;
209 void (*drain_notify)(void *drain_cb_param);
212 unsigned int pipe_id;
213 unsigned int task_id;
216 #define SST_FW_SIGN "$SST"
217 #define SST_FW_LIB_SIGN "$LIB"
220 * struct sst_fw_header - FW file headers
222 * @signature : FW signature
223 * @file_size: size of fw image
224 * @modules : # of modules
225 * @file_format : version of header format
226 * @reserved : reserved fields
228 struct sst_fw_header {
229 unsigned char signature[FW_SIGNATURE_SIZE];
237 * struct fw_module_header - module header in FW
239 * @signature: module signature
240 * @mod_size: size of module
241 * @blocks: block count
243 * @entry_point: module netry point
245 struct fw_module_header {
246 unsigned char signature[FW_SIGNATURE_SIZE];
254 * struct fw_block_info - block header for FW
256 * @type: block ram type I/D
257 * @size: size of block
258 * @ram_offset: offset in ram
260 struct fw_block_info {
261 enum sst_ram_type type;
267 struct sst_runtime_param {
268 struct snd_sst_runtime_params param;
272 struct scatterlist *src;
273 struct scatterlist *dst;
278 struct sst_memcpy_list {
279 struct list_head memcpylist;
286 /*Firmware Module Information*/
287 enum sst_lib_dwnld_status {
288 SST_LIB_NOT_FOUND = 0,
293 struct sst_module_info {
294 const char *name; /*Library name*/
295 u32 id; /*Module ID*/
296 u32 entry_pt; /*Module entry point*/
297 u8 status; /*module status*/
303 * Structure for managing the Library Region(1.5MB)
304 * in DDR in Merrifield
307 phys_addr_t current_base;
318 void *iram; /* allocated via kvmalloc() */
319 void *dram; /* allocated via kvmalloc() */
320 void *sram; /* allocated via kvmalloc() */
321 void *ddr; /* allocated via kvmalloc() */
325 * struct intel_sst_drv - driver ops
327 * @sst_state : current sst device state
328 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
330 * @shim : SST shim pointer
331 * @mailbox : SST mailbox pointer
332 * @iram : SST IRAM pointer
333 * @dram : SST DRAM pointer
334 * @pdata : SST info passed as a part of pci platform data
335 * @shim_phy_add : SST shim phy addr
336 * @ipc_dispatch_list : ipc messages dispatched
337 * @rx_list : to copy the process_reply/process_msg from DSP
338 * @ipc_post_msg_wq : wq to post IPC messages context
339 * @mad_ops : MAD driver operations registered
340 * @mad_wq : MAD driver wq
341 * @post_msg_wq : wq to post IPC messages
342 * @streams : sst stream contexts
343 * @list_lock : sst driver list lock (deprecated)
344 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
345 * @block_lock : spin lock to add block to block_list and assign pvt_id
346 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
347 * @scard_ops : sst card ops
348 * @pci : sst pci device struture
349 * @dev : pointer to current device struct
350 * @sst_lock : sst device lock
351 * @pvt_id : sst private id
352 * @stream_cnt : total sst active stream count
353 * @pb_streams : total active pb streams
354 * @cp_streams : total active cp streams
355 * @audio_start : audio status
356 * @qos : PM Qos struct
357 * firmware_name : Firmware / Library name
359 struct intel_sst_drv {
365 void __iomem *mailbox;
368 unsigned int mailbox_add;
369 unsigned int iram_base;
370 unsigned int dram_base;
371 unsigned int shim_phy_add;
372 unsigned int iram_end;
373 unsigned int dram_end;
374 unsigned int ddr_end;
375 unsigned int ddr_base;
376 unsigned int mailbox_recv_offset;
377 struct list_head block_list;
378 struct list_head ipc_dispatch_list;
379 struct sst_platform_info *pdata;
380 struct list_head rx_list;
381 struct work_struct ipc_post_msg_wq;
382 wait_queue_head_t wait_queue;
383 struct workqueue_struct *post_msg_wq;
385 /* str_id 0 is not used */
386 struct stream_info streams[MAX_NUM_STREAMS+1];
387 spinlock_t ipc_spin_lock;
388 spinlock_t block_lock;
389 spinlock_t rx_msg_lock;
392 volatile long unsigned pvt_id;
393 struct mutex sst_lock;
394 unsigned int stream_cnt;
395 unsigned int csr_value;
397 struct sst_sg_list fw_sg_list, library_list;
398 struct intel_sst_ops *ops;
399 struct sst_info info;
400 struct pm_qos_request *qos;
401 unsigned int use_dma;
402 unsigned int use_lli;
403 atomic_t fw_clear_context;
405 struct list_head memcpy_list;
406 struct sst_ipc_reg ipc_reg;
407 struct sst_mem_mgr lib_mem_mgr;
409 * Holder for firmware name. Due to async call it needs to be
410 * persistent till worker thread gets called
412 char firmware_name[FW_NAME_SIZE];
414 struct snd_sst_fw_version fw_version;
415 struct sst_fw_save *fw_save;
418 /* misc definitions */
419 #define FW_DWNL_ID 0x01
421 struct intel_sst_ops {
422 irqreturn_t (*interrupt)(int, void *);
423 irqreturn_t (*irq_thread)(int, void *);
424 void (*clear_interrupt)(struct intel_sst_drv *ctx);
425 int (*start)(struct intel_sst_drv *ctx);
426 int (*reset)(struct intel_sst_drv *ctx);
427 void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
428 int (*post_message)(struct intel_sst_drv *ctx,
429 struct ipc_post *msg, bool sync);
430 void (*process_message)(struct ipc_post *msg);
431 void (*set_bypass)(bool set);
432 int (*save_dsp_context)(struct intel_sst_drv *sst);
433 void (*restore_dsp_context)(void);
434 int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
435 void (*post_download)(struct intel_sst_drv *sst);
438 int sst_realloc_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
439 int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
440 int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
441 int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
442 int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
443 int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
444 int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
445 struct snd_sst_bytes_v2 *sbytes);
446 int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
447 int sst_set_metadata(int str_id, char *params);
448 int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
449 struct snd_sst_params *str_param);
450 int sst_get_stream_allocated(struct intel_sst_drv *ctx,
451 struct snd_sst_params *str_param,
452 struct snd_sst_lib_download **lib_dnld);
453 int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
454 int str_id, bool partial_drain);
455 int sst_post_message_mrfld(struct intel_sst_drv *ctx,
456 struct ipc_post *msg, bool sync);
457 void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
458 int sst_start_mrfld(struct intel_sst_drv *ctx);
459 int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
460 void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
462 int sst_load_fw(struct intel_sst_drv *ctx);
463 int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
464 void sst_post_download_mrfld(struct intel_sst_drv *ctx);
465 int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
466 void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
468 int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
469 struct sst_block *block);
470 int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
471 struct sst_block *block);
472 int sst_create_ipc_msg(struct ipc_post **arg, bool large);
473 int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
474 void sst_clean_stream(struct stream_info *stream);
475 int intel_sst_register_compress(struct intel_sst_drv *sst);
476 int intel_sst_remove_compress(struct intel_sst_drv *sst);
477 void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
478 int sst_send_sync_msg(int ipc, int str_id);
479 int sst_get_num_channel(struct snd_sst_params *str_param);
480 int sst_get_sfreq(struct snd_sst_params *str_param);
481 int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
482 void sst_restore_fw_context(void);
483 struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
484 u32 msg_id, u32 drv_id);
485 int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
486 struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
487 u32 msg_id, u32 drv_id);
488 int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
489 int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
490 u32 drv_id, u32 ipc, void *data, u32 size);
491 int sst_request_firmware_async(struct intel_sst_drv *ctx);
492 int sst_driver_ops(struct intel_sst_drv *sst);
493 struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
494 void sst_firmware_load_cb(const struct firmware *fw, void *context);
495 int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
496 int task_id, int ipc_msg, int cmd_id, int pipe_id,
497 size_t mbox_data_len, const void *mbox_data, void **data,
498 bool large, bool fill_dsp, bool sync, bool response);
500 void sst_process_pending_msg(struct work_struct *work);
501 int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
502 int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
503 struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
505 int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
507 u32 relocate_imr_addr_mrfld(u32 base_addr);
508 void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
509 struct ipc_post *msg);
510 int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
511 int sst_shim_write(void __iomem *addr, int offset, int value);
512 u32 sst_shim_read(void __iomem *addr, int offset);
513 u64 sst_reg_read64(void __iomem *addr, int offset);
514 int sst_shim_write64(void __iomem *addr, int offset, u64 value);
515 u64 sst_shim_read64(void __iomem *addr, int offset);
516 void sst_set_fw_state_locked(
517 struct intel_sst_drv *sst_drv_ctx, int sst_state);
518 void sst_fill_header_mrfld(union ipc_header_mrfld *header,
519 int msg, int task_id, int large, int drv_id);
520 void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
521 int pipe_id, int len);
523 int sst_register(struct device *);
524 int sst_unregister(struct device *);
526 int sst_alloc_drv_context(struct intel_sst_drv **ctx,
527 struct device *dev, unsigned int dev_id);
528 int sst_context_init(struct intel_sst_drv *ctx);
529 void sst_context_cleanup(struct intel_sst_drv *ctx);
530 void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
531 void memcpy32_toio(void __iomem *dst, const void *src, int count);
532 void memcpy32_fromio(void *dst, const void __iomem *src, int count);