Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  sst.h - Intel SST Driver for audio engine
0004  *
0005  *  Copyright (C) 2008-14 Intel Corporation
0006  *  Authors:    Vinod Koul <vinod.koul@intel.com>
0007  *      Harsha Priya <priya.harsha@intel.com>
0008  *      Dharageswari R <dharageswari.r@intel.com>
0009  *      KP Jeeja <jeeja.kp@intel.com>
0010  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0011  *
0012  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0013  *
0014  *  Common private declarations for SST
0015  */
0016 #ifndef __SST_H__
0017 #define __SST_H__
0018 
0019 #include <linux/firmware.h>
0020 
0021 /* driver names */
0022 #define SST_DRV_NAME "intel_sst_driver"
0023 #define SST_MRFLD_PCI_ID 0x119A
0024 #define SST_BYT_ACPI_ID 0x80860F28
0025 #define SST_CHV_ACPI_ID 0x808622A8
0026 
0027 #define SST_SUSPEND_DELAY 2000
0028 #define FW_CONTEXT_MEM (64*1024)
0029 #define SST_ICCM_BOUNDARY 4
0030 #define SST_CONFIG_SSP_SIGN 0x7ffe8001
0031 
0032 #define MRFLD_FW_VIRTUAL_BASE 0xC0000000
0033 #define MRFLD_FW_DDR_BASE_OFFSET 0x0
0034 #define MRFLD_FW_FEATURE_BASE_OFFSET 0x4
0035 #define MRFLD_FW_BSS_RESET_BIT 0
0036 
0037 /* SST Shim register map */
0038 #define SST_CSR         0x00
0039 #define SST_ISRX        0x18
0040 #define SST_IMRX        0x28
0041 #define SST_IPCX        0x38 /* IPC IA -> SST */
0042 #define SST_IPCD        0x40 /* IPC SST -> IA */
0043 
0044 extern const struct dev_pm_ops intel_sst_pm;
0045 enum sst_states {
0046     SST_FW_LOADING = 1,
0047     SST_FW_RUNNING,
0048     SST_RESET,
0049     SST_SHUTDOWN,
0050 };
0051 
0052 enum sst_algo_ops {
0053     SST_SET_ALGO = 0,
0054     SST_GET_ALGO = 1,
0055 };
0056 
0057 #define SST_BLOCK_TIMEOUT   1000
0058 
0059 #define FW_SIGNATURE_SIZE   4
0060 #define FW_NAME_SIZE        32
0061 
0062 /* stream states */
0063 enum sst_stream_states {
0064     STREAM_UN_INIT  = 0,    /* Freed/Not used stream */
0065     STREAM_RUNNING  = 1,    /* Running */
0066     STREAM_PAUSED   = 2,    /* Paused stream */
0067     STREAM_INIT = 3,    /* stream init, waiting for data */
0068 };
0069 
0070 enum sst_ram_type {
0071     SST_IRAM    = 1,
0072     SST_DRAM    = 2,
0073     SST_DDR = 5,
0074     SST_CUSTOM_INFO = 7,    /* consists of FW binary information */
0075 };
0076 
0077 /* SST shim registers to structure mapping */
0078 union interrupt_reg {
0079     struct {
0080         u64 done_interrupt:1;
0081         u64 busy_interrupt:1;
0082         u64 rsvd:62;
0083     } part;
0084     u64 full;
0085 };
0086 
0087 union sst_pisr_reg {
0088     struct {
0089         u32 pssp0:1;
0090         u32 pssp1:1;
0091         u32 rsvd0:3;
0092         u32 dmac:1;
0093         u32 rsvd1:26;
0094     } part;
0095     u32 full;
0096 };
0097 
0098 union sst_pimr_reg {
0099     struct {
0100         u32 ssp0:1;
0101         u32 ssp1:1;
0102         u32 rsvd0:3;
0103         u32 dmac:1;
0104         u32 rsvd1:10;
0105         u32 ssp0_sc:1;
0106         u32 ssp1_sc:1;
0107         u32 rsvd2:3;
0108         u32 dmac_sc:1;
0109         u32 rsvd3:10;
0110     } part;
0111     u32 full;
0112 };
0113 
0114 union config_status_reg_mrfld {
0115     struct {
0116         u64 lpe_reset:1;
0117         u64 lpe_reset_vector:1;
0118         u64 runstall:1;
0119         u64 pwaitmode:1;
0120         u64 clk_sel:3;
0121         u64 rsvd2:1;
0122         u64 sst_clk:3;
0123         u64 xt_snoop:1;
0124         u64 rsvd3:4;
0125         u64 clk_sel1:6;
0126         u64 clk_enable:3;
0127         u64 rsvd4:6;
0128         u64 slim0baseclk:1;
0129         u64 rsvd:32;
0130     } part;
0131     u64 full;
0132 };
0133 
0134 union interrupt_reg_mrfld {
0135     struct {
0136         u64 done_interrupt:1;
0137         u64 busy_interrupt:1;
0138         u64 rsvd:62;
0139     } part;
0140     u64 full;
0141 };
0142 
0143 union sst_imr_reg_mrfld {
0144     struct {
0145         u64 done_interrupt:1;
0146         u64 busy_interrupt:1;
0147         u64 rsvd:62;
0148     } part;
0149     u64 full;
0150 };
0151 
0152 /**
0153  * struct sst_block - This structure is used to block a user/fw data call to another
0154  * fw/user call
0155  *
0156  * @condition: condition for blocking check
0157  * @ret_code: ret code when block is released
0158  * @data: data ptr
0159  * @size: size of data
0160  * @on: block condition
0161  * @msg_id: msg_id = msgid in mfld/ctp, mrfld = NULL
0162  * @drv_id: str_id in mfld/ctp, = drv_id in mrfld
0163  * @node: list head node
0164  */
0165 struct sst_block {
0166     bool    condition;
0167     int ret_code;
0168     void    *data;
0169     u32     size;
0170     bool    on;
0171     u32     msg_id;
0172     u32     drv_id;
0173     struct list_head node;
0174 };
0175 
0176 /**
0177  * struct stream_info - structure that holds the stream information
0178  *
0179  * @status : stream current state
0180  * @prev : stream prev state
0181  * @resume_status : stream current state to restore on resume
0182  * @resume_prev : stream prev state to restore on resume
0183  * @lock : stream mutex for protecting state
0184  * @alloc_param : parameters used for stream (re-)allocation
0185  * @pcm_substream : PCM substream
0186  * @period_elapsed : PCM period elapsed callback
0187  * @sfreq : stream sampling freq
0188  * @cumm_bytes : cummulative bytes decoded
0189  */
0190 struct stream_info {
0191     unsigned int        status;
0192     unsigned int        prev;
0193     unsigned int        resume_status;
0194     unsigned int        resume_prev;
0195     struct mutex        lock;
0196     struct snd_sst_alloc_mrfld alloc_param;
0197 
0198     void            *pcm_substream;
0199     void (*period_elapsed)(void *pcm_substream);
0200 
0201     unsigned int        sfreq;
0202     u32         cumm_bytes;
0203 
0204     void            *compr_cb_param;
0205     void (*compr_cb)(void *compr_cb_param);
0206 
0207     void            *drain_cb_param;
0208     void (*drain_notify)(void *drain_cb_param);
0209 
0210     unsigned int        num_ch;
0211     unsigned int        pipe_id;
0212     unsigned int        task_id;
0213 };
0214 
0215 #define SST_FW_SIGN "$SST"
0216 #define SST_FW_LIB_SIGN "$LIB"
0217 
0218 /**
0219  * struct sst_fw_header - FW file headers
0220  *
0221  * @signature : FW signature
0222  * @file_size: size of fw image
0223  * @modules : # of modules
0224  * @file_format : version of header format
0225  * @reserved : reserved fields
0226  */
0227 struct sst_fw_header {
0228     unsigned char signature[FW_SIGNATURE_SIZE];
0229     u32 file_size;
0230     u32 modules;
0231     u32 file_format;
0232     u32 reserved[4];
0233 };
0234 
0235 /**
0236  * struct fw_module_header - module header in FW
0237  *
0238  * @signature: module signature
0239  * @mod_size: size of module
0240  * @blocks: block count
0241  * @type: block type
0242  * @entry_point: module netry point
0243  */
0244 struct fw_module_header {
0245     unsigned char signature[FW_SIGNATURE_SIZE];
0246     u32 mod_size;
0247     u32 blocks;
0248     u32 type;
0249     u32 entry_point;
0250 };
0251 
0252 /**
0253  * struct fw_block_info - block header for FW
0254  *
0255  * @type: block ram type I/D
0256  * @size: size of block
0257  * @ram_offset: offset in ram
0258  */
0259 struct fw_block_info {
0260     enum sst_ram_type   type;
0261     u32         size;
0262     u32         ram_offset;
0263     u32         rsvd;
0264 };
0265 
0266 struct sst_runtime_param {
0267     struct snd_sst_runtime_params param;
0268 };
0269 
0270 struct sst_sg_list {
0271     struct scatterlist *src;
0272     struct scatterlist *dst;
0273     int list_len;
0274     unsigned int sg_idx;
0275 };
0276 
0277 struct sst_memcpy_list {
0278     struct list_head memcpylist;
0279     void *dstn;
0280     const void *src;
0281     u32 size;
0282     bool is_io;
0283 };
0284 
0285 /*Firmware Module Information*/
0286 enum sst_lib_dwnld_status {
0287     SST_LIB_NOT_FOUND = 0,
0288     SST_LIB_FOUND,
0289     SST_LIB_DOWNLOADED,
0290 };
0291 
0292 struct sst_module_info {
0293     const char *name; /*Library name*/
0294     u32 id; /*Module ID*/
0295     u32 entry_pt; /*Module entry point*/
0296     u8  status; /*module status*/
0297     u8  rsvd1;
0298     u16 rsvd2;
0299 };
0300 
0301 /*
0302  * Structure for managing the Library Region(1.5MB)
0303  * in DDR in Merrifield
0304  */
0305 struct sst_mem_mgr {
0306     phys_addr_t current_base;
0307     int avail;
0308     unsigned int count;
0309 };
0310 
0311 struct sst_ipc_reg {
0312     int ipcx;
0313     int ipcd;
0314 };
0315 
0316 struct sst_fw_save {
0317     void *iram; /* allocated via kvmalloc() */
0318     void *dram; /* allocated via kvmalloc() */
0319     void *sram; /* allocated via kvmalloc() */
0320     void *ddr;  /* allocated via kvmalloc() */
0321 };
0322 
0323 /**
0324  * struct intel_sst_drv - driver ops
0325  *
0326  * @sst_state : current sst device state
0327  * @dev_id : device identifier, pci_id for pci devices and acpi_id for acpi
0328  *       devices
0329  * @shim : SST shim pointer
0330  * @mailbox : SST mailbox pointer
0331  * @iram : SST IRAM pointer
0332  * @dram : SST DRAM pointer
0333  * @pdata : SST info passed as a part of pci platform data
0334  * @shim_phy_add : SST shim phy addr
0335  * @ipc_dispatch_list : ipc messages dispatched
0336  * @rx_list : to copy the process_reply/process_msg from DSP
0337  * @ipc_post_msg_wq : wq to post IPC messages context
0338  * @mad_ops : MAD driver operations registered
0339  * @mad_wq : MAD driver wq
0340  * @post_msg_wq : wq to post IPC messages
0341  * @streams : sst stream contexts
0342  * @list_lock : sst driver list lock (deprecated)
0343  * @ipc_spin_lock : spin lock to handle audio shim access and ipc queue
0344  * @block_lock : spin lock to add block to block_list and assign pvt_id
0345  * @rx_msg_lock : spin lock to handle the rx messages from the DSP
0346  * @scard_ops : sst card ops
0347  * @pci : sst pci device struture
0348  * @dev : pointer to current device struct
0349  * @sst_lock : sst device lock
0350  * @pvt_id : sst private id
0351  * @stream_cnt : total sst active stream count
0352  * @pb_streams : total active pb streams
0353  * @cp_streams : total active cp streams
0354  * @audio_start : audio status
0355  * @qos     : PM Qos struct
0356  * firmware_name : Firmware / Library name
0357  */
0358 struct intel_sst_drv {
0359     int         sst_state;
0360     int         irq_num;
0361     unsigned int        dev_id;
0362     void __iomem        *ddr;
0363     void __iomem        *shim;
0364     void __iomem        *mailbox;
0365     void __iomem        *iram;
0366     void __iomem        *dram;
0367     unsigned int        mailbox_add;
0368     unsigned int        iram_base;
0369     unsigned int        dram_base;
0370     unsigned int        shim_phy_add;
0371     unsigned int        iram_end;
0372     unsigned int        dram_end;
0373     unsigned int        ddr_end;
0374     unsigned int        ddr_base;
0375     unsigned int        mailbox_recv_offset;
0376     struct list_head        block_list;
0377     struct list_head    ipc_dispatch_list;
0378     struct sst_platform_info *pdata;
0379     struct list_head    rx_list;
0380     struct work_struct      ipc_post_msg_wq;
0381     wait_queue_head_t   wait_queue;
0382     struct workqueue_struct *post_msg_wq;
0383     unsigned int        tstamp;
0384     /* str_id 0 is not used */
0385     struct stream_info  streams[MAX_NUM_STREAMS+1];
0386     spinlock_t      ipc_spin_lock;
0387     spinlock_t              block_lock;
0388     spinlock_t      rx_msg_lock;
0389     struct pci_dev      *pci;
0390     struct device       *dev;
0391     volatile long unsigned      pvt_id;
0392     struct mutex            sst_lock;
0393     unsigned int        stream_cnt;
0394     unsigned int        csr_value;
0395     void            *fw_in_mem;
0396     struct sst_sg_list  fw_sg_list, library_list;
0397     struct intel_sst_ops    *ops;
0398     struct sst_info     info;
0399     struct pm_qos_request   *qos;
0400     unsigned int        use_dma;
0401     unsigned int        use_lli;
0402     atomic_t        fw_clear_context;
0403     bool            lib_dwnld_reqd;
0404     struct list_head    memcpy_list;
0405     struct sst_ipc_reg  ipc_reg;
0406     struct sst_mem_mgr      lib_mem_mgr;
0407     /*
0408      * Holder for firmware name. Due to async call it needs to be
0409      * persistent till worker thread gets called
0410      */
0411     char firmware_name[FW_NAME_SIZE];
0412 
0413     struct snd_sst_fw_version fw_version;
0414     struct sst_fw_save  *fw_save;
0415 };
0416 
0417 /* misc definitions */
0418 #define FW_DWNL_ID 0x01
0419 
0420 struct intel_sst_ops {
0421     irqreturn_t (*interrupt)(int, void *);
0422     irqreturn_t (*irq_thread)(int, void *);
0423     void (*clear_interrupt)(struct intel_sst_drv *ctx);
0424     int (*start)(struct intel_sst_drv *ctx);
0425     int (*reset)(struct intel_sst_drv *ctx);
0426     void (*process_reply)(struct intel_sst_drv *ctx, struct ipc_post *msg);
0427     int (*post_message)(struct intel_sst_drv *ctx,
0428             struct ipc_post *msg, bool sync);
0429     void (*process_message)(struct ipc_post *msg);
0430     void (*set_bypass)(bool set);
0431     int (*save_dsp_context)(struct intel_sst_drv *sst);
0432     void (*restore_dsp_context)(void);
0433     int (*alloc_stream)(struct intel_sst_drv *ctx, void *params);
0434     void (*post_download)(struct intel_sst_drv *sst);
0435 };
0436 
0437 int sst_realloc_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0438 int sst_pause_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0439 int sst_resume_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0440 int sst_drop_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0441 int sst_free_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0442 int sst_start_stream(struct intel_sst_drv *sst_drv_ctx, int str_id);
0443 int sst_send_byte_stream_mrfld(struct intel_sst_drv *sst_drv_ctx,
0444             struct snd_sst_bytes_v2 *bytes);
0445 int sst_set_stream_param(int str_id, struct snd_sst_params *str_param);
0446 int sst_set_metadata(int str_id, char *params);
0447 int sst_get_stream(struct intel_sst_drv *ctx,
0448         struct snd_sst_params *str_param);
0449 int sst_get_stream_allocated(struct intel_sst_drv *ctx,
0450         struct snd_sst_params *str_param,
0451         struct snd_sst_lib_download **lib_dnld);
0452 int sst_drain_stream(struct intel_sst_drv *sst_drv_ctx,
0453         int str_id, bool partial_drain);
0454 int sst_post_message_mrfld(struct intel_sst_drv *sst_drv_ctx,
0455         struct ipc_post *ipc_msg, bool sync);
0456 void sst_process_reply_mrfld(struct intel_sst_drv *sst_drv_ctx, struct ipc_post *msg);
0457 int sst_start_mrfld(struct intel_sst_drv *sst_drv_ctx);
0458 int intel_sst_reset_dsp_mrfld(struct intel_sst_drv *sst_drv_ctx);
0459 void intel_sst_clear_intr_mrfld(struct intel_sst_drv *sst_drv_ctx);
0460 
0461 int sst_load_fw(struct intel_sst_drv *sst_drv_ctx);
0462 int sst_load_library(struct snd_sst_lib_download *lib, u8 ops);
0463 void sst_post_download_mrfld(struct intel_sst_drv *ctx);
0464 int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx);
0465 void sst_memcpy_free_resources(struct intel_sst_drv *sst_drv_ctx);
0466 
0467 int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
0468                 struct sst_block *block);
0469 int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
0470             struct sst_block *block);
0471 int sst_create_ipc_msg(struct ipc_post **arg, bool large);
0472 int free_stream_context(struct intel_sst_drv *ctx, unsigned int str_id);
0473 void sst_clean_stream(struct stream_info *stream);
0474 int intel_sst_register_compress(struct intel_sst_drv *sst);
0475 int intel_sst_remove_compress(struct intel_sst_drv *sst);
0476 void sst_cdev_fragment_elapsed(struct intel_sst_drv *ctx, int str_id);
0477 int sst_send_sync_msg(int ipc, int str_id);
0478 int sst_get_num_channel(struct snd_sst_params *str_param);
0479 int sst_get_sfreq(struct snd_sst_params *str_param);
0480 int sst_alloc_stream_mrfld(struct intel_sst_drv *sst_drv_ctx, void *params);
0481 void sst_restore_fw_context(void);
0482 struct sst_block *sst_create_block(struct intel_sst_drv *ctx,
0483                 u32 msg_id, u32 drv_id);
0484 int sst_create_block_and_ipc_msg(struct ipc_post **arg, bool large,
0485         struct intel_sst_drv *sst_drv_ctx, struct sst_block **block,
0486         u32 msg_id, u32 drv_id);
0487 int sst_free_block(struct intel_sst_drv *ctx, struct sst_block *freed);
0488 int sst_wake_up_block(struct intel_sst_drv *ctx, int result,
0489         u32 drv_id, u32 ipc, void *data, u32 size);
0490 int sst_request_firmware_async(struct intel_sst_drv *ctx);
0491 int sst_driver_ops(struct intel_sst_drv *sst);
0492 struct sst_platform_info *sst_get_acpi_driver_data(const char *hid);
0493 void sst_firmware_load_cb(const struct firmware *fw, void *context);
0494 int sst_prepare_and_post_msg(struct intel_sst_drv *sst,
0495         int task_id, int ipc_msg, int cmd_id, int pipe_id,
0496         size_t mbox_data_len, const void *mbox_data, void **data,
0497         bool large, bool fill_dsp, bool sync, bool response);
0498 
0499 void sst_process_pending_msg(struct work_struct *work);
0500 int sst_assign_pvt_id(struct intel_sst_drv *drv);
0501 int sst_validate_strid(struct intel_sst_drv *sst_drv_ctx, int str_id);
0502 struct stream_info *get_stream_info(struct intel_sst_drv *sst_drv_ctx,
0503         int str_id);
0504 int get_stream_id_mrfld(struct intel_sst_drv *sst_drv_ctx,
0505         u32 pipe_id);
0506 u32 relocate_imr_addr_mrfld(u32 base_addr);
0507 void sst_add_to_dispatch_list_and_post(struct intel_sst_drv *sst,
0508                     struct ipc_post *msg);
0509 int sst_pm_runtime_put(struct intel_sst_drv *sst_drv);
0510 int sst_shim_write(void __iomem *addr, int offset, int value);
0511 u32 sst_shim_read(void __iomem *addr, int offset);
0512 u64 sst_reg_read64(void __iomem *addr, int offset);
0513 int sst_shim_write64(void __iomem *addr, int offset, u64 value);
0514 u64 sst_shim_read64(void __iomem *addr, int offset);
0515 void sst_set_fw_state_locked(
0516         struct intel_sst_drv *sst_drv_ctx, int sst_state);
0517 void sst_fill_header_mrfld(union ipc_header_mrfld *header,
0518                 int msg, int task_id, int large, int drv_id);
0519 void sst_fill_header_dsp(struct ipc_dsp_hdr *dsp, int msg,
0520                     int pipe_id, int len);
0521 
0522 int sst_register(struct device *);
0523 int sst_unregister(struct device *);
0524 
0525 int sst_alloc_drv_context(struct intel_sst_drv **ctx,
0526         struct device *dev, unsigned int dev_id);
0527 int sst_context_init(struct intel_sst_drv *ctx);
0528 void sst_context_cleanup(struct intel_sst_drv *ctx);
0529 void sst_configure_runtime_pm(struct intel_sst_drv *ctx);
0530 void memcpy32_toio(void __iomem *dst, const void *src, int count);
0531 void memcpy32_fromio(void *dst, const void __iomem *src, int count);
0532 
0533 #endif