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_DECODE
= 3, /* stream is in decoding only state */
69 STREAM_INIT
= 4, /* stream init, waiting for data */
70 STREAM_RESET
= 5, /* force reset on recovery */
77 SST_CUSTOM_INFO
= 7, /* consists of FW binary information */
80 /* SST shim registers to structure mapping */
117 union config_status_reg_mrfld
{
120 u64 lpe_reset_vector
:1;
137 union interrupt_reg_mrfld
{
139 u64 done_interrupt
:1;
140 u64 busy_interrupt
:1;
146 union sst_imr_reg_mrfld
{
148 u64 done_interrupt
:1;
149 u64 busy_interrupt
:1;
156 * struct sst_block - This structure is used to block a user/fw data call to another
159 * @condition: condition for blocking check
160 * @ret_code: ret code when block is released
162 * @size: size of data
163 * @on: block condition
164 * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
165 * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
166 * @node: list head node
176 struct list_head node
;
180 * struct stream_info - structure that holds the stream information
182 * @status : stream current state
183 * @prev : stream prev state
184 * @ops : stream operation pb/cp/drm...
185 * @bufs: stream buffer list
186 * @lock : stream mutex for protecting state
187 * @pcm_substream : PCM substream
188 * @period_elapsed : PCM period elapsed callback
189 * @sfreq : stream sampling freq
190 * @str_type : stream type
191 * @cumm_bytes : cummulative bytes decoded
192 * @str_type : stream type
193 * @src : stream source
202 void (*period_elapsed
)(void *pcm_substream
);
207 void *compr_cb_param
;
208 void (*compr_cb
)(void *compr_cb_param
);
210 void *drain_cb_param
;
211 void (*drain_notify
)(void *drain_cb_param
);
214 unsigned int pipe_id
;
216 unsigned int task_id
;
219 #define SST_FW_SIGN "$SST"
220 #define SST_FW_LIB_SIGN "$LIB"
223 * struct sst_fw_header - FW file headers
225 * @signature : FW signature
226 * @file_size: size of fw image
227 * @modules : # of modules
228 * @file_format : version of header format
229 * @reserved : reserved fields
231 struct sst_fw_header
{
232 unsigned char signature
[FW_SIGNATURE_SIZE
];
240 * struct fw_module_header - module header in FW
242 * @signature: module signature
243 * @mod_size: size of module
244 * @blocks: block count
246 * @entry_point: module netry point
248 struct fw_module_header
{
249 unsigned char signature
[FW_SIGNATURE_SIZE
];
257 * struct fw_block_info - block header for FW
259 * @type: block ram type I/D
260 * @size: size of block
261 * @ram_offset: offset in ram
263 struct fw_block_info
{
264 enum sst_ram_type type
;
270 struct sst_runtime_param
{
271 struct snd_sst_runtime_params param
;
275 struct scatterlist
*src
;
276 struct scatterlist
*dst
;
281 struct sst_memcpy_list
{
282 struct list_head memcpylist
;
289 /*Firmware Module Information*/
290 enum sst_lib_dwnld_status
{
291 SST_LIB_NOT_FOUND
= 0,
296 struct sst_module_info
{
297 const char *name
; /*Library name*/
298 u32 id
; /*Module ID*/
299 u32 entry_pt
; /*Module entry point*/
300 u8 status
; /*module status*/
306 * Structure for managing the Library Region(1.5MB)
307 * in DDR in Merrifield
310 phys_addr_t current_base
;
320 struct sst_shim_regs64
{
348 * struct intel_sst_drv - driver ops
350 * @sst_state : current sst device state
351 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
353 * @shim : SST shim pointer
354 * @mailbox : SST mailbox pointer
355 * @iram : SST IRAM pointer
356 * @dram : SST DRAM pointer
357 * @pdata : SST info passed as a part of pci platform data
358 * @shim_phy_add : SST shim phy addr
359 * @shim_regs64: Struct to save shim registers
360 * @ipc_dispatch_list : ipc messages dispatched
361 * @rx_list : to copy the process_reply/process_msg from DSP
362 * @ipc_post_msg_wq : wq to post IPC messages context
363 * @mad_ops : MAD driver operations registered
364 * @mad_wq : MAD driver wq
365 * @post_msg_wq : wq to post IPC messages
366 * @streams : sst stream contexts
367 * @list_lock : sst driver list lock (deprecated)
368 * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
369 * @block_lock : spin lock to add block to block_list and assign pvt_id
370 * @rx_msg_lock : spin lock to handle the rx messages from the DSP
371 * @scard_ops : sst card ops
372 * @pci : sst pci device struture
373 * @dev : pointer to current device struct
374 * @sst_lock : sst device lock
375 * @pvt_id : sst private id
376 * @stream_cnt : total sst active stream count
377 * @pb_streams : total active pb streams
378 * @cp_streams : total active cp streams
379 * @audio_start : audio status
380 * @qos : PM Qos struct
381 * firmware_name : Firmware / Library name
383 struct intel_sst_drv
{
389 void __iomem
*mailbox
;
392 unsigned int mailbox_add
;
393 unsigned int iram_base
;
394 unsigned int dram_base
;
395 unsigned int shim_phy_add
;
396 unsigned int iram_end
;
397 unsigned int dram_end
;
398 unsigned int ddr_end
;
399 unsigned int ddr_base
;
400 unsigned int mailbox_recv_offset
;
401 struct sst_shim_regs64
*shim_regs64
;
402 struct list_head block_list
;
403 struct list_head ipc_dispatch_list
;
404 struct sst_platform_info
*pdata
;
405 struct list_head rx_list
;
406 struct work_struct ipc_post_msg_wq
;
407 wait_queue_head_t wait_queue
;
408 struct workqueue_struct
*post_msg_wq
;
410 /* str_id 0 is not used */
411 struct stream_info streams
[MAX_NUM_STREAMS
+1];
412 spinlock_t ipc_spin_lock
;
413 spinlock_t block_lock
;
414 spinlock_t rx_msg_lock
;
417 volatile long unsigned pvt_id
;
418 struct mutex sst_lock
;
419 unsigned int stream_cnt
;
420 unsigned int csr_value
;
422 struct sst_sg_list fw_sg_list
, library_list
;
423 struct intel_sst_ops
*ops
;
424 struct sst_info info
;
425 struct pm_qos_request
*qos
;
426 unsigned int use_dma
;
427 unsigned int use_lli
;
428 atomic_t fw_clear_context
;
430 struct list_head memcpy_list
;
431 struct sst_ipc_reg ipc_reg
;
432 struct sst_mem_mgr lib_mem_mgr
;
434 * Holder for firmware name. Due to async call it needs to be
435 * persistent till worker thread gets called
437 char firmware_name
[FW_NAME_SIZE
];
439 struct sst_fw_save
*fw_save
;
442 /* misc definitions */
443 #define FW_DWNL_ID 0x01
445 struct intel_sst_ops
{
446 irqreturn_t (*interrupt
)(int, void *);
447 irqreturn_t (*irq_thread
)(int, void *);
448 void (*clear_interrupt
)(struct intel_sst_drv
*ctx
);
449 int (*start
)(struct intel_sst_drv
*ctx
);
450 int (*reset
)(struct intel_sst_drv
*ctx
);
451 void (*process_reply
)(struct intel_sst_drv
*ctx
, struct ipc_post
*msg
);
452 int (*post_message
)(struct intel_sst_drv
*ctx
,
453 struct ipc_post
*msg
, bool sync
);
454 void (*process_message
)(struct ipc_post
*msg
);
455 void (*set_bypass
)(bool set
);
456 int (*save_dsp_context
)(struct intel_sst_drv
*sst
);
457 void (*restore_dsp_context
)(void);
458 int (*alloc_stream
)(struct intel_sst_drv
*ctx
, void *params
);
459 void (*post_download
)(struct intel_sst_drv
*sst
);
462 int sst_pause_stream(struct intel_sst_drv
*sst_drv_ctx
, int id
);
463 int sst_resume_stream(struct intel_sst_drv
*sst_drv_ctx
, int id
);
464 int sst_drop_stream(struct intel_sst_drv
*sst_drv_ctx
, int id
);
465 int sst_free_stream(struct intel_sst_drv
*sst_drv_ctx
, int id
);
466 int sst_start_stream(struct intel_sst_drv
*sst_drv_ctx
, int str_id
);
467 int sst_send_byte_stream_mrfld(struct intel_sst_drv
*ctx
,
468 struct snd_sst_bytes_v2
*sbytes
);
469 int sst_set_stream_param(int str_id
, struct snd_sst_params
*str_param
);
470 int sst_set_metadata(int str_id
, char *params
);
471 int sst_get_stream(struct intel_sst_drv
*sst_drv_ctx
,
472 struct snd_sst_params
*str_param
);
473 int sst_get_stream_allocated(struct intel_sst_drv
*ctx
,
474 struct snd_sst_params
*str_param
,
475 struct snd_sst_lib_download
**lib_dnld
);
476 int sst_drain_stream(struct intel_sst_drv
*sst_drv_ctx
,
477 int str_id
, bool partial_drain
);
478 int sst_post_message_mrfld(struct intel_sst_drv
*ctx
,
479 struct ipc_post
*msg
, bool sync
);
480 void sst_process_reply_mrfld(struct intel_sst_drv
*ctx
, struct ipc_post
*msg
);
481 int sst_start_mrfld(struct intel_sst_drv
*ctx
);
482 int intel_sst_reset_dsp_mrfld(struct intel_sst_drv
*ctx
);
483 void intel_sst_clear_intr_mrfld(struct intel_sst_drv
*ctx
);
485 int sst_load_fw(struct intel_sst_drv
*ctx
);
486 int sst_load_library(struct snd_sst_lib_download
*lib
, u8 ops
);
487 void sst_post_download_mrfld(struct intel_sst_drv
*ctx
);
488 int sst_get_block_stream(struct intel_sst_drv
*sst_drv_ctx
);
489 void sst_memcpy_free_resources(struct intel_sst_drv
*ctx
);
491 int sst_wait_interruptible(struct intel_sst_drv
*sst_drv_ctx
,
492 struct sst_block
*block
);
493 int sst_wait_timeout(struct intel_sst_drv
*sst_drv_ctx
,
494 struct sst_block
*block
);
495 int sst_create_ipc_msg(struct ipc_post
**arg
, bool large
);
496 int free_stream_context(struct intel_sst_drv
*ctx
, unsigned int str_id
);
497 void sst_clean_stream(struct stream_info
*stream
);
498 int intel_sst_register_compress(struct intel_sst_drv
*sst
);
499 int intel_sst_remove_compress(struct intel_sst_drv
*sst
);
500 void sst_cdev_fragment_elapsed(struct intel_sst_drv
*ctx
, int str_id
);
501 int sst_send_sync_msg(int ipc
, int str_id
);
502 int sst_get_num_channel(struct snd_sst_params
*str_param
);
503 int sst_get_sfreq(struct snd_sst_params
*str_param
);
504 int sst_alloc_stream_mrfld(struct intel_sst_drv
*sst_drv_ctx
, void *params
);
505 void sst_restore_fw_context(void);
506 struct sst_block
*sst_create_block(struct intel_sst_drv
*ctx
,
507 u32 msg_id
, u32 drv_id
);
508 int sst_create_block_and_ipc_msg(struct ipc_post
**arg
, bool large
,
509 struct intel_sst_drv
*sst_drv_ctx
, struct sst_block
**block
,
510 u32 msg_id
, u32 drv_id
);
511 int sst_free_block(struct intel_sst_drv
*ctx
, struct sst_block
*freed
);
512 int sst_wake_up_block(struct intel_sst_drv
*ctx
, int result
,
513 u32 drv_id
, u32 ipc
, void *data
, u32 size
);
514 int sst_request_firmware_async(struct intel_sst_drv
*ctx
);
515 int sst_driver_ops(struct intel_sst_drv
*sst
);
516 struct sst_platform_info
*sst_get_acpi_driver_data(const char *hid
);
517 void sst_firmware_load_cb(const struct firmware
*fw
, void *context
);
518 int sst_prepare_and_post_msg(struct intel_sst_drv
*sst
,
519 int task_id
, int ipc_msg
, int cmd_id
, int pipe_id
,
520 size_t mbox_data_len
, const void *mbox_data
, void **data
,
521 bool large
, bool fill_dsp
, bool sync
, bool response
);
523 void sst_process_pending_msg(struct work_struct
*work
);
524 int sst_assign_pvt_id(struct intel_sst_drv
*sst_drv_ctx
);
525 void sst_init_stream(struct stream_info
*stream
,
526 int codec
, int sst_id
, int ops
, u8 slot
);
527 int sst_validate_strid(struct intel_sst_drv
*sst_drv_ctx
, int str_id
);
528 struct stream_info
*get_stream_info(struct intel_sst_drv
*sst_drv_ctx
,
530 int get_stream_id_mrfld(struct intel_sst_drv
*sst_drv_ctx
,
532 u32
relocate_imr_addr_mrfld(u32 base_addr
);
533 void sst_add_to_dispatch_list_and_post(struct intel_sst_drv
*sst
,
534 struct ipc_post
*msg
);
535 int sst_pm_runtime_put(struct intel_sst_drv
*sst_drv
);
536 int sst_shim_write(void __iomem
*addr
, int offset
, int value
);
537 u32
sst_shim_read(void __iomem
*addr
, int offset
);
538 u64
sst_reg_read64(void __iomem
*addr
, int offset
);
539 int sst_shim_write64(void __iomem
*addr
, int offset
, u64 value
);
540 u64
sst_shim_read64(void __iomem
*addr
, int offset
);
541 void sst_set_fw_state_locked(
542 struct intel_sst_drv
*sst_drv_ctx
, int sst_state
);
543 void sst_fill_header_mrfld(union ipc_header_mrfld
*header
,
544 int msg
, int task_id
, int large
, int drv_id
);
545 void sst_fill_header_dsp(struct ipc_dsp_hdr
*dsp
, int msg
,
546 int pipe_id
, int len
);
548 int sst_register(struct device
*);
549 int sst_unregister(struct device
*);
551 int sst_alloc_drv_context(struct intel_sst_drv
**ctx
,
552 struct device
*dev
, unsigned int dev_id
);
553 int sst_context_init(struct intel_sst_drv
*ctx
);
554 void sst_context_cleanup(struct intel_sst_drv
*ctx
);
555 void sst_configure_runtime_pm(struct intel_sst_drv
*ctx
);
556 void memcpy32_toio(void __iomem
*dst
, const void *src
, int count
);
557 void memcpy32_fromio(void *dst
, const void __iomem
*src
, int count
);