sst.h 15 KB

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