sst.h 15 KB

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