sst.h 15 KB

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