1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * sst.h - Intel SST Driver for audio engine
5 * Copyright (C) 2008-14 Intel Corporation
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14 * Common private declarations for SST
19 #include <linux/firmware.h>
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
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
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
37 extern const struct dev_pm_ops intel_sst_pm;
50 #define SST_BLOCK_TIMEOUT 1000
52 #define FW_SIGNATURE_SIZE 4
53 #define FW_NAME_SIZE 32
56 enum 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 */
67 SST_CUSTOM_INFO = 7, /* consists of FW binary information */
70 /* SST shim registers to structure mapping */
107 union config_status_reg_mrfld {
110 u64 lpe_reset_vector:1;
127 union interrupt_reg_mrfld {
129 u64 done_interrupt:1;
130 u64 busy_interrupt:1;
136 union sst_imr_reg_mrfld {
138 u64 done_interrupt:1;
139 u64 busy_interrupt:1;
146 * struct sst_block - This structure is used to block a user/fw data call to another
149 * @condition: condition for blocking check
150 * @ret_code: ret code when block is released
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
166 struct list_head node;
170 * struct stream_info - structure that holds the stream information
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
186 unsigned int resume_status;
187 unsigned int resume_prev;
189 struct snd_sst_alloc_mrfld alloc_param;
192 void (*period_elapsed)(void *pcm_substream);
197 void *compr_cb_param;
198 void (*compr_cb)(void *compr_cb_param);
200 void *drain_cb_param;
201 void (*drain_notify)(void *drain_cb_param);
204 unsigned int pipe_id;
205 unsigned int task_id;
208 #define SST_FW_SIGN "$SST"
209 #define SST_FW_LIB_SIGN "$LIB"
212 * struct sst_fw_header - FW file headers
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
220 struct sst_fw_header {
221 unsigned char signature[FW_SIGNATURE_SIZE];
229 * struct fw_module_header - module header in FW
231 * @signature: module signature
232 * @mod_size: size of module
233 * @blocks: block count
235 * @entry_point: module netry point
237 struct fw_module_header {
238 unsigned char signature[FW_SIGNATURE_SIZE];
246 * struct fw_block_info - block header for FW
248 * @type: block ram type I/D
249 * @size: size of block
250 * @ram_offset: offset in ram
252 struct fw_block_info {
253 enum sst_ram_type type;
259 struct sst_runtime_param {
260 struct snd_sst_runtime_params param;
264 struct scatterlist *src;
265 struct scatterlist *dst;
270 struct sst_memcpy_list {
271 struct list_head memcpylist;
278 /*Firmware Module Information*/
279 enum sst_lib_dwnld_status {
280 SST_LIB_NOT_FOUND = 0,
285 struct 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*/
295 * Structure for managing the Library Region(1.5MB)
296 * in DDR in Merrifield
299 phys_addr_t current_base;
310 void *iram; /* allocated via kvmalloc() */
311 void *dram; /* allocated via kvmalloc() */
312 void *sram; /* allocated via kvmalloc() */
313 void *ddr; /* allocated via kvmalloc() */
317 * struct intel_sst_drv - driver ops
319 * @sst_state : current sst device state
320 * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
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
351 struct intel_sst_drv {
357 void __iomem *mailbox;
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;
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;
384 volatile long unsigned pvt_id;
385 struct mutex sst_lock;
386 unsigned int stream_cnt;
387 unsigned int csr_value;
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;
397 struct list_head memcpy_list;
398 struct sst_ipc_reg ipc_reg;
399 struct sst_mem_mgr lib_mem_mgr;
401 * Holder for firmware name. Due to async call it needs to be
402 * persistent till worker thread gets called
404 char firmware_name[FW_NAME_SIZE];
406 struct snd_sst_fw_version fw_version;
407 struct sst_fw_save *fw_save;
410 /* misc definitions */
411 #define FW_DWNL_ID 0x01
413 struct 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);
430 int sst_realloc_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
431 int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int id);
432 int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int id);
433 int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int id);
434 int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int id);
435 int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
436 int sst_send_byte_stream_mrfld(struct intel_sst_drv *ctx,
437 struct snd_sst_bytes_v2 *sbytes);
438 int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
439 int sst_set_metadata(int str_id, char *params);
440 int sst_get_stream(struct intel_sst_drv *sst_drv_ctx,
441 struct snd_sst_params *str_param);
442 int sst_get_stream_allocated(struct intel_sst_drv *ctx,
443 struct snd_sst_params *str_param,
444 struct snd_sst_lib_download **lib_dnld);
445 int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
446 int str_id, bool partial_drain);
447 int sst_post_message_mrfld(struct intel_sst_drv *ctx,
448 struct ipc_post *msg, bool sync);
449 void sst_process_reply_mrfld(struct intel_sst_drv *ctx, struct ipc_post *msg);
450 int sst_start_mrfld(struct intel_sst_drv *ctx);
451 int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *ctx);
452 void intel_sst_clear_intr_mrfld(struct intel_sst_drv *ctx);
454 int sst_load_fw(struct intel_sst_drv *ctx);
455 int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
456 void sst_post_download_mrfld(struct intel_sst_drv *ctx);
457 int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
458 void sst_memcpy_free_resources(struct intel_sst_drv *ctx);
460 int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
461 struct sst_block *block);
462 int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
463 struct sst_block *block);
464 int sst_create_ipc_msg(struct ipc_post **arg, bool large);
465 int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
466 void sst_clean_stream(struct stream_info *stream);
467 int intel_sst_register_compress(struct intel_sst_drv *sst);
468 int intel_sst_remove_compress(struct intel_sst_drv *sst);
469 void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
470 int sst_send_sync_msg(int ipc, int str_id);
471 int sst_get_num_channel(struct snd_sst_params *str_param);
472 int sst_get_sfreq(struct snd_sst_params *str_param);
473 int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
474 void sst_restore_fw_context(void);
475 struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
476 u32 msg_id, u32 drv_id);
477 int 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);
480 int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
481 int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
482 u32 drv_id, u32 ipc, void *data, u32 size);
483 int sst_request_firmware_async(struct intel_sst_drv *ctx);
484 int sst_driver_ops(struct intel_sst_drv *sst);
485 struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
486 void sst_firmware_load_cb(const struct firmware *fw, void *context);
487 int 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);
492 void sst_process_pending_msg(struct work_struct *work);
493 int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx);
494 int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
495 struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
497 int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
499 u32 relocate_imr_addr_mrfld(u32 base_addr);
500 void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
501 struct ipc_post *msg);
502 int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
503 int sst_shim_write(void __iomem *addr, int offset, int value);
504 u32 sst_shim_read(void __iomem *addr, int offset);
505 u64 sst_reg_read64(void __iomem *addr, int offset);
506 int sst_shim_write64(void __iomem *addr, int offset, u64 value);
507 u64 sst_shim_read64(void __iomem *addr, int offset);
508 void sst_set_fw_state_locked(
509 struct intel_sst_drv *sst_drv_ctx, int sst_state);
510 void sst_fill_header_mrfld(union ipc_header_mrfld *header,
511 int msg, int task_id, int large, int drv_id);
512 void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
513 int pipe_id, int len);
515 int sst_register(struct device *);
516 int sst_unregister(struct device *);
518 int sst_alloc_drv_context(struct intel_sst_drv **ctx,
519 struct device *dev, unsigned int dev_id);
520 int sst_context_init(struct intel_sst_drv *ctx);
521 void sst_context_cleanup(struct intel_sst_drv *ctx);
522 void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
523 void memcpy32_toio(void __iomem *dst, const void *src, int count);
524 void memcpy32_fromio(void *dst, const void __iomem *src, int count);