skl-messages.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  1. /*
  2. * skl-message.c - HDA DSP interface for FW registration, Pipe and Module
  3. * configurations
  4. *
  5. * Copyright (C) 2015 Intel Corp
  6. * Author:Rafal Redzimski <rafal.f.redzimski@intel.com>
  7. * Jeeja KP <jeeja.kp@intel.com>
  8. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as version 2, as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #include <linux/slab.h>
  20. #include <linux/pci.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <uapi/sound/skl-tplg-interface.h>
  24. #include "skl-sst-dsp.h"
  25. #include "cnl-sst-dsp.h"
  26. #include "skl-sst-ipc.h"
  27. #include "skl.h"
  28. #include "../common/sst-dsp.h"
  29. #include "../common/sst-dsp-priv.h"
  30. #include "skl-topology.h"
  31. static int skl_alloc_dma_buf(struct device *dev,
  32. struct snd_dma_buffer *dmab, size_t size)
  33. {
  34. struct hdac_bus *bus = dev_get_drvdata(dev);
  35. if (!bus)
  36. return -ENODEV;
  37. return bus->io_ops->dma_alloc_pages(bus, SNDRV_DMA_TYPE_DEV, size, dmab);
  38. }
  39. static int skl_free_dma_buf(struct device *dev, struct snd_dma_buffer *dmab)
  40. {
  41. struct hdac_bus *bus = dev_get_drvdata(dev);
  42. if (!bus)
  43. return -ENODEV;
  44. bus->io_ops->dma_free_pages(bus, dmab);
  45. return 0;
  46. }
  47. #define SKL_ASTATE_PARAM_ID 4
  48. void skl_dsp_set_astate_cfg(struct skl_sst *ctx, u32 cnt, void *data)
  49. {
  50. struct skl_ipc_large_config_msg msg = {0};
  51. msg.large_param_id = SKL_ASTATE_PARAM_ID;
  52. msg.param_data_size = (cnt * sizeof(struct skl_astate_param) +
  53. sizeof(cnt));
  54. skl_ipc_set_large_config(&ctx->ipc, &msg, data);
  55. }
  56. #define NOTIFICATION_PARAM_ID 3
  57. #define NOTIFICATION_MASK 0xf
  58. /* disable notfication for underruns/overruns from firmware module */
  59. void skl_dsp_enable_notification(struct skl_sst *ctx, bool enable)
  60. {
  61. struct notification_mask mask;
  62. struct skl_ipc_large_config_msg msg = {0};
  63. mask.notify = NOTIFICATION_MASK;
  64. mask.enable = enable;
  65. msg.large_param_id = NOTIFICATION_PARAM_ID;
  66. msg.param_data_size = sizeof(mask);
  67. skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)&mask);
  68. }
  69. static int skl_dsp_setup_spib(struct device *dev, unsigned int size,
  70. int stream_tag, int enable)
  71. {
  72. struct hdac_bus *bus = dev_get_drvdata(dev);
  73. struct hdac_stream *stream = snd_hdac_get_stream(bus,
  74. SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
  75. struct hdac_ext_stream *estream;
  76. if (!stream)
  77. return -EINVAL;
  78. estream = stream_to_hdac_ext_stream(stream);
  79. /* enable/disable SPIB for this hdac stream */
  80. snd_hdac_ext_stream_spbcap_enable(bus, enable, stream->index);
  81. /* set the spib value */
  82. snd_hdac_ext_stream_set_spib(bus, estream, size);
  83. return 0;
  84. }
  85. static int skl_dsp_prepare(struct device *dev, unsigned int format,
  86. unsigned int size, struct snd_dma_buffer *dmab)
  87. {
  88. struct hdac_bus *bus = dev_get_drvdata(dev);
  89. struct hdac_ext_stream *estream;
  90. struct hdac_stream *stream;
  91. struct snd_pcm_substream substream;
  92. int ret;
  93. if (!bus)
  94. return -ENODEV;
  95. memset(&substream, 0, sizeof(substream));
  96. substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
  97. estream = snd_hdac_ext_stream_assign(bus, &substream,
  98. HDAC_EXT_STREAM_TYPE_HOST);
  99. if (!estream)
  100. return -ENODEV;
  101. stream = hdac_stream(estream);
  102. /* assign decouple host dma channel */
  103. ret = snd_hdac_dsp_prepare(stream, format, size, dmab);
  104. if (ret < 0)
  105. return ret;
  106. skl_dsp_setup_spib(dev, size, stream->stream_tag, true);
  107. return stream->stream_tag;
  108. }
  109. static int skl_dsp_trigger(struct device *dev, bool start, int stream_tag)
  110. {
  111. struct hdac_bus *bus = dev_get_drvdata(dev);
  112. struct hdac_stream *stream;
  113. if (!bus)
  114. return -ENODEV;
  115. stream = snd_hdac_get_stream(bus,
  116. SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
  117. if (!stream)
  118. return -EINVAL;
  119. snd_hdac_dsp_trigger(stream, start);
  120. return 0;
  121. }
  122. static int skl_dsp_cleanup(struct device *dev,
  123. struct snd_dma_buffer *dmab, int stream_tag)
  124. {
  125. struct hdac_bus *bus = dev_get_drvdata(dev);
  126. struct hdac_stream *stream;
  127. struct hdac_ext_stream *estream;
  128. if (!bus)
  129. return -ENODEV;
  130. stream = snd_hdac_get_stream(bus,
  131. SNDRV_PCM_STREAM_PLAYBACK, stream_tag);
  132. if (!stream)
  133. return -EINVAL;
  134. estream = stream_to_hdac_ext_stream(stream);
  135. skl_dsp_setup_spib(dev, 0, stream_tag, false);
  136. snd_hdac_ext_stream_release(estream, HDAC_EXT_STREAM_TYPE_HOST);
  137. snd_hdac_dsp_cleanup(stream, dmab);
  138. return 0;
  139. }
  140. static struct skl_dsp_loader_ops skl_get_loader_ops(void)
  141. {
  142. struct skl_dsp_loader_ops loader_ops;
  143. memset(&loader_ops, 0, sizeof(struct skl_dsp_loader_ops));
  144. loader_ops.alloc_dma_buf = skl_alloc_dma_buf;
  145. loader_ops.free_dma_buf = skl_free_dma_buf;
  146. return loader_ops;
  147. };
  148. static struct skl_dsp_loader_ops bxt_get_loader_ops(void)
  149. {
  150. struct skl_dsp_loader_ops loader_ops;
  151. memset(&loader_ops, 0, sizeof(loader_ops));
  152. loader_ops.alloc_dma_buf = skl_alloc_dma_buf;
  153. loader_ops.free_dma_buf = skl_free_dma_buf;
  154. loader_ops.prepare = skl_dsp_prepare;
  155. loader_ops.trigger = skl_dsp_trigger;
  156. loader_ops.cleanup = skl_dsp_cleanup;
  157. return loader_ops;
  158. };
  159. static const struct skl_dsp_ops dsp_ops[] = {
  160. {
  161. .id = 0x9d70,
  162. .num_cores = 2,
  163. .loader_ops = skl_get_loader_ops,
  164. .init = skl_sst_dsp_init,
  165. .init_fw = skl_sst_init_fw,
  166. .cleanup = skl_sst_dsp_cleanup
  167. },
  168. {
  169. .id = 0x9d71,
  170. .num_cores = 2,
  171. .loader_ops = skl_get_loader_ops,
  172. .init = skl_sst_dsp_init,
  173. .init_fw = skl_sst_init_fw,
  174. .cleanup = skl_sst_dsp_cleanup
  175. },
  176. {
  177. .id = 0x5a98,
  178. .num_cores = 2,
  179. .loader_ops = bxt_get_loader_ops,
  180. .init = bxt_sst_dsp_init,
  181. .init_fw = bxt_sst_init_fw,
  182. .cleanup = bxt_sst_dsp_cleanup
  183. },
  184. {
  185. .id = 0x3198,
  186. .num_cores = 2,
  187. .loader_ops = bxt_get_loader_ops,
  188. .init = bxt_sst_dsp_init,
  189. .init_fw = bxt_sst_init_fw,
  190. .cleanup = bxt_sst_dsp_cleanup
  191. },
  192. {
  193. .id = 0x9dc8,
  194. .num_cores = 4,
  195. .loader_ops = bxt_get_loader_ops,
  196. .init = cnl_sst_dsp_init,
  197. .init_fw = cnl_sst_init_fw,
  198. .cleanup = cnl_sst_dsp_cleanup
  199. },
  200. };
  201. const struct skl_dsp_ops *skl_get_dsp_ops(int pci_id)
  202. {
  203. int i;
  204. for (i = 0; i < ARRAY_SIZE(dsp_ops); i++) {
  205. if (dsp_ops[i].id == pci_id)
  206. return &dsp_ops[i];
  207. }
  208. return NULL;
  209. }
  210. int skl_init_dsp(struct skl *skl)
  211. {
  212. void __iomem *mmio_base;
  213. struct hdac_bus *bus = skl_to_bus(skl);
  214. struct skl_dsp_loader_ops loader_ops;
  215. int irq = bus->irq;
  216. const struct skl_dsp_ops *ops;
  217. struct skl_dsp_cores *cores;
  218. int ret;
  219. /* enable ppcap interrupt */
  220. snd_hdac_ext_bus_ppcap_enable(bus, true);
  221. snd_hdac_ext_bus_ppcap_int_enable(bus, true);
  222. /* read the BAR of the ADSP MMIO */
  223. mmio_base = pci_ioremap_bar(skl->pci, 4);
  224. if (mmio_base == NULL) {
  225. dev_err(bus->dev, "ioremap error\n");
  226. return -ENXIO;
  227. }
  228. ops = skl_get_dsp_ops(skl->pci->device);
  229. if (!ops) {
  230. ret = -EIO;
  231. goto unmap_mmio;
  232. }
  233. loader_ops = ops->loader_ops();
  234. ret = ops->init(bus->dev, mmio_base, irq,
  235. skl->fw_name, loader_ops,
  236. &skl->skl_sst);
  237. if (ret < 0)
  238. goto unmap_mmio;
  239. skl->skl_sst->dsp_ops = ops;
  240. cores = &skl->skl_sst->cores;
  241. cores->count = ops->num_cores;
  242. cores->state = kcalloc(cores->count, sizeof(*cores->state), GFP_KERNEL);
  243. if (!cores->state) {
  244. ret = -ENOMEM;
  245. goto unmap_mmio;
  246. }
  247. cores->usage_count = kcalloc(cores->count, sizeof(*cores->usage_count),
  248. GFP_KERNEL);
  249. if (!cores->usage_count) {
  250. ret = -ENOMEM;
  251. goto free_core_state;
  252. }
  253. dev_dbg(bus->dev, "dsp registration status=%d\n", ret);
  254. return 0;
  255. free_core_state:
  256. kfree(cores->state);
  257. unmap_mmio:
  258. iounmap(mmio_base);
  259. return ret;
  260. }
  261. int skl_free_dsp(struct skl *skl)
  262. {
  263. struct hdac_bus *bus = skl_to_bus(skl);
  264. struct skl_sst *ctx = skl->skl_sst;
  265. /* disable ppcap interrupt */
  266. snd_hdac_ext_bus_ppcap_int_enable(bus, false);
  267. ctx->dsp_ops->cleanup(bus->dev, ctx);
  268. kfree(ctx->cores.state);
  269. kfree(ctx->cores.usage_count);
  270. if (ctx->dsp->addr.lpe)
  271. iounmap(ctx->dsp->addr.lpe);
  272. return 0;
  273. }
  274. /*
  275. * In the case of "suspend_active" i.e, the Audio IP being active
  276. * during system suspend, immediately excecute any pending D0i3 work
  277. * before suspending. This is needed for the IP to work in low power
  278. * mode during system suspend. In the case of normal suspend, cancel
  279. * any pending D0i3 work.
  280. */
  281. int skl_suspend_late_dsp(struct skl *skl)
  282. {
  283. struct skl_sst *ctx = skl->skl_sst;
  284. struct delayed_work *dwork;
  285. if (!ctx)
  286. return 0;
  287. dwork = &ctx->d0i3.work;
  288. if (dwork->work.func) {
  289. if (skl->supend_active)
  290. flush_delayed_work(dwork);
  291. else
  292. cancel_delayed_work_sync(dwork);
  293. }
  294. return 0;
  295. }
  296. int skl_suspend_dsp(struct skl *skl)
  297. {
  298. struct skl_sst *ctx = skl->skl_sst;
  299. struct hdac_bus *bus = skl_to_bus(skl);
  300. int ret;
  301. /* if ppcap is not supported return 0 */
  302. if (!bus->ppcap)
  303. return 0;
  304. ret = skl_dsp_sleep(ctx->dsp);
  305. if (ret < 0)
  306. return ret;
  307. /* disable ppcap interrupt */
  308. snd_hdac_ext_bus_ppcap_int_enable(bus, false);
  309. snd_hdac_ext_bus_ppcap_enable(bus, false);
  310. return 0;
  311. }
  312. int skl_resume_dsp(struct skl *skl)
  313. {
  314. struct skl_sst *ctx = skl->skl_sst;
  315. struct hdac_bus *bus = skl_to_bus(skl);
  316. int ret;
  317. /* if ppcap is not supported return 0 */
  318. if (!bus->ppcap)
  319. return 0;
  320. /* enable ppcap interrupt */
  321. snd_hdac_ext_bus_ppcap_enable(bus, true);
  322. snd_hdac_ext_bus_ppcap_int_enable(bus, true);
  323. /* check if DSP 1st boot is done */
  324. if (skl->skl_sst->is_first_boot == true)
  325. return 0;
  326. /*
  327. * Disable dynamic clock and power gating during firmware
  328. * and library download
  329. */
  330. ctx->enable_miscbdcge(ctx->dev, false);
  331. ctx->clock_power_gating(ctx->dev, false);
  332. ret = skl_dsp_wake(ctx->dsp);
  333. ctx->enable_miscbdcge(ctx->dev, true);
  334. ctx->clock_power_gating(ctx->dev, true);
  335. if (ret < 0)
  336. return ret;
  337. skl_dsp_enable_notification(skl->skl_sst, false);
  338. if (skl->cfg.astate_cfg != NULL) {
  339. skl_dsp_set_astate_cfg(skl->skl_sst, skl->cfg.astate_cfg->count,
  340. skl->cfg.astate_cfg);
  341. }
  342. return ret;
  343. }
  344. enum skl_bitdepth skl_get_bit_depth(int params)
  345. {
  346. switch (params) {
  347. case 8:
  348. return SKL_DEPTH_8BIT;
  349. case 16:
  350. return SKL_DEPTH_16BIT;
  351. case 24:
  352. return SKL_DEPTH_24BIT;
  353. case 32:
  354. return SKL_DEPTH_32BIT;
  355. default:
  356. return SKL_DEPTH_INVALID;
  357. }
  358. }
  359. /*
  360. * Each module in DSP expects a base module configuration, which consists of
  361. * PCM format information, which we calculate in driver and resource values
  362. * which are read from widget information passed through topology binary
  363. * This is send when we create a module with INIT_INSTANCE IPC msg
  364. */
  365. static void skl_set_base_module_format(struct skl_sst *ctx,
  366. struct skl_module_cfg *mconfig,
  367. struct skl_base_cfg *base_cfg)
  368. {
  369. struct skl_module *module = mconfig->module;
  370. struct skl_module_res *res = &module->resources[mconfig->res_idx];
  371. struct skl_module_iface *fmt = &module->formats[mconfig->fmt_idx];
  372. struct skl_module_fmt *format = &fmt->inputs[0].fmt;
  373. base_cfg->audio_fmt.number_of_channels = format->channels;
  374. base_cfg->audio_fmt.s_freq = format->s_freq;
  375. base_cfg->audio_fmt.bit_depth = format->bit_depth;
  376. base_cfg->audio_fmt.valid_bit_depth = format->valid_bit_depth;
  377. base_cfg->audio_fmt.ch_cfg = format->ch_cfg;
  378. dev_dbg(ctx->dev, "bit_depth=%x valid_bd=%x ch_config=%x\n",
  379. format->bit_depth, format->valid_bit_depth,
  380. format->ch_cfg);
  381. base_cfg->audio_fmt.channel_map = format->ch_map;
  382. base_cfg->audio_fmt.interleaving = format->interleaving_style;
  383. base_cfg->cps = res->cps;
  384. base_cfg->ibs = res->ibs;
  385. base_cfg->obs = res->obs;
  386. base_cfg->is_pages = res->is_pages;
  387. }
  388. /*
  389. * Copies copier capabilities into copier module and updates copier module
  390. * config size.
  391. */
  392. static void skl_copy_copier_caps(struct skl_module_cfg *mconfig,
  393. struct skl_cpr_cfg *cpr_mconfig)
  394. {
  395. if (mconfig->formats_config.caps_size == 0)
  396. return;
  397. memcpy(cpr_mconfig->gtw_cfg.config_data,
  398. mconfig->formats_config.caps,
  399. mconfig->formats_config.caps_size);
  400. cpr_mconfig->gtw_cfg.config_length =
  401. (mconfig->formats_config.caps_size) / 4;
  402. }
  403. #define SKL_NON_GATEWAY_CPR_NODE_ID 0xFFFFFFFF
  404. /*
  405. * Calculate the gatewat settings required for copier module, type of
  406. * gateway and index of gateway to use
  407. */
  408. static u32 skl_get_node_id(struct skl_sst *ctx,
  409. struct skl_module_cfg *mconfig)
  410. {
  411. union skl_connector_node_id node_id = {0};
  412. union skl_ssp_dma_node ssp_node = {0};
  413. struct skl_pipe_params *params = mconfig->pipe->p_params;
  414. switch (mconfig->dev_type) {
  415. case SKL_DEVICE_BT:
  416. node_id.node.dma_type =
  417. (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
  418. SKL_DMA_I2S_LINK_OUTPUT_CLASS :
  419. SKL_DMA_I2S_LINK_INPUT_CLASS;
  420. node_id.node.vindex = params->host_dma_id +
  421. (mconfig->vbus_id << 3);
  422. break;
  423. case SKL_DEVICE_I2S:
  424. node_id.node.dma_type =
  425. (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
  426. SKL_DMA_I2S_LINK_OUTPUT_CLASS :
  427. SKL_DMA_I2S_LINK_INPUT_CLASS;
  428. ssp_node.dma_node.time_slot_index = mconfig->time_slot;
  429. ssp_node.dma_node.i2s_instance = mconfig->vbus_id;
  430. node_id.node.vindex = ssp_node.val;
  431. break;
  432. case SKL_DEVICE_DMIC:
  433. node_id.node.dma_type = SKL_DMA_DMIC_LINK_INPUT_CLASS;
  434. node_id.node.vindex = mconfig->vbus_id +
  435. (mconfig->time_slot);
  436. break;
  437. case SKL_DEVICE_HDALINK:
  438. node_id.node.dma_type =
  439. (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
  440. SKL_DMA_HDA_LINK_OUTPUT_CLASS :
  441. SKL_DMA_HDA_LINK_INPUT_CLASS;
  442. node_id.node.vindex = params->link_dma_id;
  443. break;
  444. case SKL_DEVICE_HDAHOST:
  445. node_id.node.dma_type =
  446. (SKL_CONN_SOURCE == mconfig->hw_conn_type) ?
  447. SKL_DMA_HDA_HOST_OUTPUT_CLASS :
  448. SKL_DMA_HDA_HOST_INPUT_CLASS;
  449. node_id.node.vindex = params->host_dma_id;
  450. break;
  451. default:
  452. node_id.val = 0xFFFFFFFF;
  453. break;
  454. }
  455. return node_id.val;
  456. }
  457. static void skl_setup_cpr_gateway_cfg(struct skl_sst *ctx,
  458. struct skl_module_cfg *mconfig,
  459. struct skl_cpr_cfg *cpr_mconfig)
  460. {
  461. u32 dma_io_buf;
  462. struct skl_module_res *res;
  463. int res_idx = mconfig->res_idx;
  464. struct skl *skl = get_skl_ctx(ctx->dev);
  465. cpr_mconfig->gtw_cfg.node_id = skl_get_node_id(ctx, mconfig);
  466. if (cpr_mconfig->gtw_cfg.node_id == SKL_NON_GATEWAY_CPR_NODE_ID) {
  467. cpr_mconfig->cpr_feature_mask = 0;
  468. return;
  469. }
  470. if (skl->nr_modules) {
  471. res = &mconfig->module->resources[mconfig->res_idx];
  472. cpr_mconfig->gtw_cfg.dma_buffer_size = res->dma_buffer_size;
  473. goto skip_buf_size_calc;
  474. } else {
  475. res = &mconfig->module->resources[res_idx];
  476. }
  477. switch (mconfig->hw_conn_type) {
  478. case SKL_CONN_SOURCE:
  479. if (mconfig->dev_type == SKL_DEVICE_HDAHOST)
  480. dma_io_buf = res->ibs;
  481. else
  482. dma_io_buf = res->obs;
  483. break;
  484. case SKL_CONN_SINK:
  485. if (mconfig->dev_type == SKL_DEVICE_HDAHOST)
  486. dma_io_buf = res->obs;
  487. else
  488. dma_io_buf = res->ibs;
  489. break;
  490. default:
  491. dev_warn(ctx->dev, "wrong connection type: %d\n",
  492. mconfig->hw_conn_type);
  493. return;
  494. }
  495. cpr_mconfig->gtw_cfg.dma_buffer_size =
  496. mconfig->dma_buffer_size * dma_io_buf;
  497. /* fallback to 2ms default value */
  498. if (!cpr_mconfig->gtw_cfg.dma_buffer_size) {
  499. if (mconfig->hw_conn_type == SKL_CONN_SOURCE)
  500. cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * res->obs;
  501. else
  502. cpr_mconfig->gtw_cfg.dma_buffer_size = 2 * res->ibs;
  503. }
  504. skip_buf_size_calc:
  505. cpr_mconfig->cpr_feature_mask = 0;
  506. cpr_mconfig->gtw_cfg.config_length = 0;
  507. skl_copy_copier_caps(mconfig, cpr_mconfig);
  508. }
  509. #define DMA_CONTROL_ID 5
  510. #define DMA_I2S_BLOB_SIZE 21
  511. int skl_dsp_set_dma_control(struct skl_sst *ctx, u32 *caps,
  512. u32 caps_size, u32 node_id)
  513. {
  514. struct skl_dma_control *dma_ctrl;
  515. struct skl_ipc_large_config_msg msg = {0};
  516. int err = 0;
  517. /*
  518. * if blob size zero, then return
  519. */
  520. if (caps_size == 0)
  521. return 0;
  522. msg.large_param_id = DMA_CONTROL_ID;
  523. msg.param_data_size = sizeof(struct skl_dma_control) + caps_size;
  524. dma_ctrl = kzalloc(msg.param_data_size, GFP_KERNEL);
  525. if (dma_ctrl == NULL)
  526. return -ENOMEM;
  527. dma_ctrl->node_id = node_id;
  528. /*
  529. * NHLT blob may contain additional configs along with i2s blob.
  530. * firmware expects only the i2s blob size as the config_length.
  531. * So fix to i2s blob size.
  532. * size in dwords.
  533. */
  534. dma_ctrl->config_length = DMA_I2S_BLOB_SIZE;
  535. memcpy(dma_ctrl->config_data, caps, caps_size);
  536. err = skl_ipc_set_large_config(&ctx->ipc, &msg, (u32 *)dma_ctrl);
  537. kfree(dma_ctrl);
  538. return err;
  539. }
  540. EXPORT_SYMBOL_GPL(skl_dsp_set_dma_control);
  541. static void skl_setup_out_format(struct skl_sst *ctx,
  542. struct skl_module_cfg *mconfig,
  543. struct skl_audio_data_format *out_fmt)
  544. {
  545. struct skl_module *module = mconfig->module;
  546. struct skl_module_iface *fmt = &module->formats[mconfig->fmt_idx];
  547. struct skl_module_fmt *format = &fmt->outputs[0].fmt;
  548. out_fmt->number_of_channels = (u8)format->channels;
  549. out_fmt->s_freq = format->s_freq;
  550. out_fmt->bit_depth = format->bit_depth;
  551. out_fmt->valid_bit_depth = format->valid_bit_depth;
  552. out_fmt->ch_cfg = format->ch_cfg;
  553. out_fmt->channel_map = format->ch_map;
  554. out_fmt->interleaving = format->interleaving_style;
  555. out_fmt->sample_type = format->sample_type;
  556. dev_dbg(ctx->dev, "copier out format chan=%d fre=%d bitdepth=%d\n",
  557. out_fmt->number_of_channels, format->s_freq, format->bit_depth);
  558. }
  559. /*
  560. * DSP needs SRC module for frequency conversion, SRC takes base module
  561. * configuration and the target frequency as extra parameter passed as src
  562. * config
  563. */
  564. static void skl_set_src_format(struct skl_sst *ctx,
  565. struct skl_module_cfg *mconfig,
  566. struct skl_src_module_cfg *src_mconfig)
  567. {
  568. struct skl_module *module = mconfig->module;
  569. struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx];
  570. struct skl_module_fmt *fmt = &iface->outputs[0].fmt;
  571. skl_set_base_module_format(ctx, mconfig,
  572. (struct skl_base_cfg *)src_mconfig);
  573. src_mconfig->src_cfg = fmt->s_freq;
  574. }
  575. /*
  576. * DSP needs updown module to do channel conversion. updown module take base
  577. * module configuration and channel configuration
  578. * It also take coefficients and now we have defaults applied here
  579. */
  580. static void skl_set_updown_mixer_format(struct skl_sst *ctx,
  581. struct skl_module_cfg *mconfig,
  582. struct skl_up_down_mixer_cfg *mixer_mconfig)
  583. {
  584. struct skl_module *module = mconfig->module;
  585. struct skl_module_iface *iface = &module->formats[mconfig->fmt_idx];
  586. struct skl_module_fmt *fmt = &iface->outputs[0].fmt;
  587. skl_set_base_module_format(ctx, mconfig,
  588. (struct skl_base_cfg *)mixer_mconfig);
  589. mixer_mconfig->out_ch_cfg = fmt->ch_cfg;
  590. mixer_mconfig->ch_map = fmt->ch_map;
  591. }
  592. /*
  593. * 'copier' is DSP internal module which copies data from Host DMA (HDA host
  594. * dma) or link (hda link, SSP, PDM)
  595. * Here we calculate the copier module parameters, like PCM format, output
  596. * format, gateway settings
  597. * copier_module_config is sent as input buffer with INIT_INSTANCE IPC msg
  598. */
  599. static void skl_set_copier_format(struct skl_sst *ctx,
  600. struct skl_module_cfg *mconfig,
  601. struct skl_cpr_cfg *cpr_mconfig)
  602. {
  603. struct skl_audio_data_format *out_fmt = &cpr_mconfig->out_fmt;
  604. struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)cpr_mconfig;
  605. skl_set_base_module_format(ctx, mconfig, base_cfg);
  606. skl_setup_out_format(ctx, mconfig, out_fmt);
  607. skl_setup_cpr_gateway_cfg(ctx, mconfig, cpr_mconfig);
  608. }
  609. /*
  610. * Algo module are DSP pre processing modules. Algo module take base module
  611. * configuration and params
  612. */
  613. static void skl_set_algo_format(struct skl_sst *ctx,
  614. struct skl_module_cfg *mconfig,
  615. struct skl_algo_cfg *algo_mcfg)
  616. {
  617. struct skl_base_cfg *base_cfg = (struct skl_base_cfg *)algo_mcfg;
  618. skl_set_base_module_format(ctx, mconfig, base_cfg);
  619. if (mconfig->formats_config.caps_size == 0)
  620. return;
  621. memcpy(algo_mcfg->params,
  622. mconfig->formats_config.caps,
  623. mconfig->formats_config.caps_size);
  624. }
  625. /*
  626. * Mic select module allows selecting one or many input channels, thus
  627. * acting as a demux.
  628. *
  629. * Mic select module take base module configuration and out-format
  630. * configuration
  631. */
  632. static void skl_set_base_outfmt_format(struct skl_sst *ctx,
  633. struct skl_module_cfg *mconfig,
  634. struct skl_base_outfmt_cfg *base_outfmt_mcfg)
  635. {
  636. struct skl_audio_data_format *out_fmt = &base_outfmt_mcfg->out_fmt;
  637. struct skl_base_cfg *base_cfg =
  638. (struct skl_base_cfg *)base_outfmt_mcfg;
  639. skl_set_base_module_format(ctx, mconfig, base_cfg);
  640. skl_setup_out_format(ctx, mconfig, out_fmt);
  641. }
  642. static u16 skl_get_module_param_size(struct skl_sst *ctx,
  643. struct skl_module_cfg *mconfig)
  644. {
  645. u16 param_size;
  646. switch (mconfig->m_type) {
  647. case SKL_MODULE_TYPE_COPIER:
  648. param_size = sizeof(struct skl_cpr_cfg);
  649. param_size += mconfig->formats_config.caps_size;
  650. return param_size;
  651. case SKL_MODULE_TYPE_SRCINT:
  652. return sizeof(struct skl_src_module_cfg);
  653. case SKL_MODULE_TYPE_UPDWMIX:
  654. return sizeof(struct skl_up_down_mixer_cfg);
  655. case SKL_MODULE_TYPE_ALGO:
  656. param_size = sizeof(struct skl_base_cfg);
  657. param_size += mconfig->formats_config.caps_size;
  658. return param_size;
  659. case SKL_MODULE_TYPE_BASE_OUTFMT:
  660. case SKL_MODULE_TYPE_MIC_SELECT:
  661. case SKL_MODULE_TYPE_KPB:
  662. return sizeof(struct skl_base_outfmt_cfg);
  663. default:
  664. /*
  665. * return only base cfg when no specific module type is
  666. * specified
  667. */
  668. return sizeof(struct skl_base_cfg);
  669. }
  670. return 0;
  671. }
  672. /*
  673. * DSP firmware supports various modules like copier, SRC, updown etc.
  674. * These modules required various parameters to be calculated and sent for
  675. * the module initialization to DSP. By default a generic module needs only
  676. * base module format configuration
  677. */
  678. static int skl_set_module_format(struct skl_sst *ctx,
  679. struct skl_module_cfg *module_config,
  680. u16 *module_config_size,
  681. void **param_data)
  682. {
  683. u16 param_size;
  684. param_size = skl_get_module_param_size(ctx, module_config);
  685. *param_data = kzalloc(param_size, GFP_KERNEL);
  686. if (NULL == *param_data)
  687. return -ENOMEM;
  688. *module_config_size = param_size;
  689. switch (module_config->m_type) {
  690. case SKL_MODULE_TYPE_COPIER:
  691. skl_set_copier_format(ctx, module_config, *param_data);
  692. break;
  693. case SKL_MODULE_TYPE_SRCINT:
  694. skl_set_src_format(ctx, module_config, *param_data);
  695. break;
  696. case SKL_MODULE_TYPE_UPDWMIX:
  697. skl_set_updown_mixer_format(ctx, module_config, *param_data);
  698. break;
  699. case SKL_MODULE_TYPE_ALGO:
  700. skl_set_algo_format(ctx, module_config, *param_data);
  701. break;
  702. case SKL_MODULE_TYPE_BASE_OUTFMT:
  703. case SKL_MODULE_TYPE_MIC_SELECT:
  704. case SKL_MODULE_TYPE_KPB:
  705. skl_set_base_outfmt_format(ctx, module_config, *param_data);
  706. break;
  707. default:
  708. skl_set_base_module_format(ctx, module_config, *param_data);
  709. break;
  710. }
  711. dev_dbg(ctx->dev, "Module type=%d config size: %d bytes\n",
  712. module_config->id.module_id, param_size);
  713. print_hex_dump_debug("Module params:", DUMP_PREFIX_OFFSET, 8, 4,
  714. *param_data, param_size, false);
  715. return 0;
  716. }
  717. static int skl_get_queue_index(struct skl_module_pin *mpin,
  718. struct skl_module_inst_id id, int max)
  719. {
  720. int i;
  721. for (i = 0; i < max; i++) {
  722. if (mpin[i].id.module_id == id.module_id &&
  723. mpin[i].id.instance_id == id.instance_id)
  724. return i;
  725. }
  726. return -EINVAL;
  727. }
  728. /*
  729. * Allocates queue for each module.
  730. * if dynamic, the pin_index is allocated 0 to max_pin.
  731. * In static, the pin_index is fixed based on module_id and instance id
  732. */
  733. static int skl_alloc_queue(struct skl_module_pin *mpin,
  734. struct skl_module_cfg *tgt_cfg, int max)
  735. {
  736. int i;
  737. struct skl_module_inst_id id = tgt_cfg->id;
  738. /*
  739. * if pin in dynamic, find first free pin
  740. * otherwise find match module and instance id pin as topology will
  741. * ensure a unique pin is assigned to this so no need to
  742. * allocate/free
  743. */
  744. for (i = 0; i < max; i++) {
  745. if (mpin[i].is_dynamic) {
  746. if (!mpin[i].in_use &&
  747. mpin[i].pin_state == SKL_PIN_UNBIND) {
  748. mpin[i].in_use = true;
  749. mpin[i].id.module_id = id.module_id;
  750. mpin[i].id.instance_id = id.instance_id;
  751. mpin[i].id.pvt_id = id.pvt_id;
  752. mpin[i].tgt_mcfg = tgt_cfg;
  753. return i;
  754. }
  755. } else {
  756. if (mpin[i].id.module_id == id.module_id &&
  757. mpin[i].id.instance_id == id.instance_id &&
  758. mpin[i].pin_state == SKL_PIN_UNBIND) {
  759. mpin[i].tgt_mcfg = tgt_cfg;
  760. return i;
  761. }
  762. }
  763. }
  764. return -EINVAL;
  765. }
  766. static void skl_free_queue(struct skl_module_pin *mpin, int q_index)
  767. {
  768. if (mpin[q_index].is_dynamic) {
  769. mpin[q_index].in_use = false;
  770. mpin[q_index].id.module_id = 0;
  771. mpin[q_index].id.instance_id = 0;
  772. mpin[q_index].id.pvt_id = 0;
  773. }
  774. mpin[q_index].pin_state = SKL_PIN_UNBIND;
  775. mpin[q_index].tgt_mcfg = NULL;
  776. }
  777. /* Module state will be set to unint, if all the out pin state is UNBIND */
  778. static void skl_clear_module_state(struct skl_module_pin *mpin, int max,
  779. struct skl_module_cfg *mcfg)
  780. {
  781. int i;
  782. bool found = false;
  783. for (i = 0; i < max; i++) {
  784. if (mpin[i].pin_state == SKL_PIN_UNBIND)
  785. continue;
  786. found = true;
  787. break;
  788. }
  789. if (!found)
  790. mcfg->m_state = SKL_MODULE_INIT_DONE;
  791. return;
  792. }
  793. /*
  794. * A module needs to be instanataited in DSP. A mdoule is present in a
  795. * collection of module referred as a PIPE.
  796. * We first calculate the module format, based on module type and then
  797. * invoke the DSP by sending IPC INIT_INSTANCE using ipc helper
  798. */
  799. int skl_init_module(struct skl_sst *ctx,
  800. struct skl_module_cfg *mconfig)
  801. {
  802. u16 module_config_size = 0;
  803. void *param_data = NULL;
  804. int ret;
  805. struct skl_ipc_init_instance_msg msg;
  806. dev_dbg(ctx->dev, "%s: module_id = %d instance=%d\n", __func__,
  807. mconfig->id.module_id, mconfig->id.pvt_id);
  808. if (mconfig->pipe->state != SKL_PIPE_CREATED) {
  809. dev_err(ctx->dev, "Pipe not created state= %d pipe_id= %d\n",
  810. mconfig->pipe->state, mconfig->pipe->ppl_id);
  811. return -EIO;
  812. }
  813. ret = skl_set_module_format(ctx, mconfig,
  814. &module_config_size, &param_data);
  815. if (ret < 0) {
  816. dev_err(ctx->dev, "Failed to set module format ret=%d\n", ret);
  817. return ret;
  818. }
  819. msg.module_id = mconfig->id.module_id;
  820. msg.instance_id = mconfig->id.pvt_id;
  821. msg.ppl_instance_id = mconfig->pipe->ppl_id;
  822. msg.param_data_size = module_config_size;
  823. msg.core_id = mconfig->core_id;
  824. msg.domain = mconfig->domain;
  825. ret = skl_ipc_init_instance(&ctx->ipc, &msg, param_data);
  826. if (ret < 0) {
  827. dev_err(ctx->dev, "Failed to init instance ret=%d\n", ret);
  828. kfree(param_data);
  829. return ret;
  830. }
  831. mconfig->m_state = SKL_MODULE_INIT_DONE;
  832. kfree(param_data);
  833. return ret;
  834. }
  835. static void skl_dump_bind_info(struct skl_sst *ctx, struct skl_module_cfg
  836. *src_module, struct skl_module_cfg *dst_module)
  837. {
  838. dev_dbg(ctx->dev, "%s: src module_id = %d src_instance=%d\n",
  839. __func__, src_module->id.module_id, src_module->id.pvt_id);
  840. dev_dbg(ctx->dev, "%s: dst_module=%d dst_instance=%d\n", __func__,
  841. dst_module->id.module_id, dst_module->id.pvt_id);
  842. dev_dbg(ctx->dev, "src_module state = %d dst module state = %d\n",
  843. src_module->m_state, dst_module->m_state);
  844. }
  845. /*
  846. * On module freeup, we need to unbind the module with modules
  847. * it is already bind.
  848. * Find the pin allocated and unbind then using bind_unbind IPC
  849. */
  850. int skl_unbind_modules(struct skl_sst *ctx,
  851. struct skl_module_cfg *src_mcfg,
  852. struct skl_module_cfg *dst_mcfg)
  853. {
  854. int ret;
  855. struct skl_ipc_bind_unbind_msg msg;
  856. struct skl_module_inst_id src_id = src_mcfg->id;
  857. struct skl_module_inst_id dst_id = dst_mcfg->id;
  858. int in_max = dst_mcfg->module->max_input_pins;
  859. int out_max = src_mcfg->module->max_output_pins;
  860. int src_index, dst_index, src_pin_state, dst_pin_state;
  861. skl_dump_bind_info(ctx, src_mcfg, dst_mcfg);
  862. /* get src queue index */
  863. src_index = skl_get_queue_index(src_mcfg->m_out_pin, dst_id, out_max);
  864. if (src_index < 0)
  865. return 0;
  866. msg.src_queue = src_index;
  867. /* get dst queue index */
  868. dst_index = skl_get_queue_index(dst_mcfg->m_in_pin, src_id, in_max);
  869. if (dst_index < 0)
  870. return 0;
  871. msg.dst_queue = dst_index;
  872. src_pin_state = src_mcfg->m_out_pin[src_index].pin_state;
  873. dst_pin_state = dst_mcfg->m_in_pin[dst_index].pin_state;
  874. if (src_pin_state != SKL_PIN_BIND_DONE ||
  875. dst_pin_state != SKL_PIN_BIND_DONE)
  876. return 0;
  877. msg.module_id = src_mcfg->id.module_id;
  878. msg.instance_id = src_mcfg->id.pvt_id;
  879. msg.dst_module_id = dst_mcfg->id.module_id;
  880. msg.dst_instance_id = dst_mcfg->id.pvt_id;
  881. msg.bind = false;
  882. ret = skl_ipc_bind_unbind(&ctx->ipc, &msg);
  883. if (!ret) {
  884. /* free queue only if unbind is success */
  885. skl_free_queue(src_mcfg->m_out_pin, src_index);
  886. skl_free_queue(dst_mcfg->m_in_pin, dst_index);
  887. /*
  888. * check only if src module bind state, bind is
  889. * always from src -> sink
  890. */
  891. skl_clear_module_state(src_mcfg->m_out_pin, out_max, src_mcfg);
  892. }
  893. return ret;
  894. }
  895. static void fill_pin_params(struct skl_audio_data_format *pin_fmt,
  896. struct skl_module_fmt *format)
  897. {
  898. pin_fmt->number_of_channels = format->channels;
  899. pin_fmt->s_freq = format->s_freq;
  900. pin_fmt->bit_depth = format->bit_depth;
  901. pin_fmt->valid_bit_depth = format->valid_bit_depth;
  902. pin_fmt->ch_cfg = format->ch_cfg;
  903. pin_fmt->sample_type = format->sample_type;
  904. pin_fmt->channel_map = format->ch_map;
  905. pin_fmt->interleaving = format->interleaving_style;
  906. }
  907. #define CPR_SINK_FMT_PARAM_ID 2
  908. /*
  909. * Once a module is instantiated it need to be 'bind' with other modules in
  910. * the pipeline. For binding we need to find the module pins which are bind
  911. * together
  912. * This function finds the pins and then sends bund_unbind IPC message to
  913. * DSP using IPC helper
  914. */
  915. int skl_bind_modules(struct skl_sst *ctx,
  916. struct skl_module_cfg *src_mcfg,
  917. struct skl_module_cfg *dst_mcfg)
  918. {
  919. int ret = 0;
  920. struct skl_ipc_bind_unbind_msg msg;
  921. int in_max = dst_mcfg->module->max_input_pins;
  922. int out_max = src_mcfg->module->max_output_pins;
  923. int src_index, dst_index;
  924. struct skl_module_fmt *format;
  925. struct skl_cpr_pin_fmt pin_fmt;
  926. struct skl_module *module;
  927. struct skl_module_iface *fmt;
  928. skl_dump_bind_info(ctx, src_mcfg, dst_mcfg);
  929. if (src_mcfg->m_state < SKL_MODULE_INIT_DONE ||
  930. dst_mcfg->m_state < SKL_MODULE_INIT_DONE)
  931. return 0;
  932. src_index = skl_alloc_queue(src_mcfg->m_out_pin, dst_mcfg, out_max);
  933. if (src_index < 0)
  934. return -EINVAL;
  935. msg.src_queue = src_index;
  936. dst_index = skl_alloc_queue(dst_mcfg->m_in_pin, src_mcfg, in_max);
  937. if (dst_index < 0) {
  938. skl_free_queue(src_mcfg->m_out_pin, src_index);
  939. return -EINVAL;
  940. }
  941. /*
  942. * Copier module requires the separate large_config_set_ipc to
  943. * configure the pins other than 0
  944. */
  945. if (src_mcfg->m_type == SKL_MODULE_TYPE_COPIER && src_index > 0) {
  946. pin_fmt.sink_id = src_index;
  947. module = src_mcfg->module;
  948. fmt = &module->formats[src_mcfg->fmt_idx];
  949. /* Input fmt is same as that of src module input cfg */
  950. format = &fmt->inputs[0].fmt;
  951. fill_pin_params(&(pin_fmt.src_fmt), format);
  952. format = &fmt->outputs[src_index].fmt;
  953. fill_pin_params(&(pin_fmt.dst_fmt), format);
  954. ret = skl_set_module_params(ctx, (void *)&pin_fmt,
  955. sizeof(struct skl_cpr_pin_fmt),
  956. CPR_SINK_FMT_PARAM_ID, src_mcfg);
  957. if (ret < 0)
  958. goto out;
  959. }
  960. msg.dst_queue = dst_index;
  961. dev_dbg(ctx->dev, "src queue = %d dst queue =%d\n",
  962. msg.src_queue, msg.dst_queue);
  963. msg.module_id = src_mcfg->id.module_id;
  964. msg.instance_id = src_mcfg->id.pvt_id;
  965. msg.dst_module_id = dst_mcfg->id.module_id;
  966. msg.dst_instance_id = dst_mcfg->id.pvt_id;
  967. msg.bind = true;
  968. ret = skl_ipc_bind_unbind(&ctx->ipc, &msg);
  969. if (!ret) {
  970. src_mcfg->m_state = SKL_MODULE_BIND_DONE;
  971. src_mcfg->m_out_pin[src_index].pin_state = SKL_PIN_BIND_DONE;
  972. dst_mcfg->m_in_pin[dst_index].pin_state = SKL_PIN_BIND_DONE;
  973. return ret;
  974. }
  975. out:
  976. /* error case , if IPC fails, clear the queue index */
  977. skl_free_queue(src_mcfg->m_out_pin, src_index);
  978. skl_free_queue(dst_mcfg->m_in_pin, dst_index);
  979. return ret;
  980. }
  981. static int skl_set_pipe_state(struct skl_sst *ctx, struct skl_pipe *pipe,
  982. enum skl_ipc_pipeline_state state)
  983. {
  984. dev_dbg(ctx->dev, "%s: pipe_state = %d\n", __func__, state);
  985. return skl_ipc_set_pipeline_state(&ctx->ipc, pipe->ppl_id, state);
  986. }
  987. /*
  988. * A pipeline is a collection of modules. Before a module in instantiated a
  989. * pipeline needs to be created for it.
  990. * This function creates pipeline, by sending create pipeline IPC messages
  991. * to FW
  992. */
  993. int skl_create_pipeline(struct skl_sst *ctx, struct skl_pipe *pipe)
  994. {
  995. int ret;
  996. dev_dbg(ctx->dev, "%s: pipe_id = %d\n", __func__, pipe->ppl_id);
  997. ret = skl_ipc_create_pipeline(&ctx->ipc, pipe->memory_pages,
  998. pipe->pipe_priority, pipe->ppl_id,
  999. pipe->lp_mode);
  1000. if (ret < 0) {
  1001. dev_err(ctx->dev, "Failed to create pipeline\n");
  1002. return ret;
  1003. }
  1004. pipe->state = SKL_PIPE_CREATED;
  1005. return 0;
  1006. }
  1007. /*
  1008. * A pipeline needs to be deleted on cleanup. If a pipeline is running, then
  1009. * pause the pipeline first and then delete it
  1010. * The pipe delete is done by sending delete pipeline IPC. DSP will stop the
  1011. * DMA engines and releases resources
  1012. */
  1013. int skl_delete_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
  1014. {
  1015. int ret;
  1016. dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
  1017. /* If pipe is started, do stop the pipe in FW. */
  1018. if (pipe->state >= SKL_PIPE_STARTED) {
  1019. ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
  1020. if (ret < 0) {
  1021. dev_err(ctx->dev, "Failed to stop pipeline\n");
  1022. return ret;
  1023. }
  1024. pipe->state = SKL_PIPE_PAUSED;
  1025. }
  1026. /* If pipe was not created in FW, do not try to delete it */
  1027. if (pipe->state < SKL_PIPE_CREATED)
  1028. return 0;
  1029. ret = skl_ipc_delete_pipeline(&ctx->ipc, pipe->ppl_id);
  1030. if (ret < 0) {
  1031. dev_err(ctx->dev, "Failed to delete pipeline\n");
  1032. return ret;
  1033. }
  1034. pipe->state = SKL_PIPE_INVALID;
  1035. return ret;
  1036. }
  1037. /*
  1038. * A pipeline is also a scheduling entity in DSP which can be run, stopped
  1039. * For processing data the pipe need to be run by sending IPC set pipe state
  1040. * to DSP
  1041. */
  1042. int skl_run_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
  1043. {
  1044. int ret;
  1045. dev_dbg(ctx->dev, "%s: pipe = %d\n", __func__, pipe->ppl_id);
  1046. /* If pipe was not created in FW, do not try to pause or delete */
  1047. if (pipe->state < SKL_PIPE_CREATED)
  1048. return 0;
  1049. /* Pipe has to be paused before it is started */
  1050. ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
  1051. if (ret < 0) {
  1052. dev_err(ctx->dev, "Failed to pause pipe\n");
  1053. return ret;
  1054. }
  1055. pipe->state = SKL_PIPE_PAUSED;
  1056. ret = skl_set_pipe_state(ctx, pipe, PPL_RUNNING);
  1057. if (ret < 0) {
  1058. dev_err(ctx->dev, "Failed to start pipe\n");
  1059. return ret;
  1060. }
  1061. pipe->state = SKL_PIPE_STARTED;
  1062. return 0;
  1063. }
  1064. /*
  1065. * Stop the pipeline by sending set pipe state IPC
  1066. * DSP doesnt implement stop so we always send pause message
  1067. */
  1068. int skl_stop_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
  1069. {
  1070. int ret;
  1071. dev_dbg(ctx->dev, "In %s pipe=%d\n", __func__, pipe->ppl_id);
  1072. /* If pipe was not created in FW, do not try to pause or delete */
  1073. if (pipe->state < SKL_PIPE_PAUSED)
  1074. return 0;
  1075. ret = skl_set_pipe_state(ctx, pipe, PPL_PAUSED);
  1076. if (ret < 0) {
  1077. dev_dbg(ctx->dev, "Failed to stop pipe\n");
  1078. return ret;
  1079. }
  1080. pipe->state = SKL_PIPE_PAUSED;
  1081. return 0;
  1082. }
  1083. /*
  1084. * Reset the pipeline by sending set pipe state IPC this will reset the DMA
  1085. * from the DSP side
  1086. */
  1087. int skl_reset_pipe(struct skl_sst *ctx, struct skl_pipe *pipe)
  1088. {
  1089. int ret;
  1090. /* If pipe was not created in FW, do not try to pause or delete */
  1091. if (pipe->state < SKL_PIPE_PAUSED)
  1092. return 0;
  1093. ret = skl_set_pipe_state(ctx, pipe, PPL_RESET);
  1094. if (ret < 0) {
  1095. dev_dbg(ctx->dev, "Failed to reset pipe ret=%d\n", ret);
  1096. return ret;
  1097. }
  1098. pipe->state = SKL_PIPE_RESET;
  1099. return 0;
  1100. }
  1101. /* Algo parameter set helper function */
  1102. int skl_set_module_params(struct skl_sst *ctx, u32 *params, int size,
  1103. u32 param_id, struct skl_module_cfg *mcfg)
  1104. {
  1105. struct skl_ipc_large_config_msg msg;
  1106. msg.module_id = mcfg->id.module_id;
  1107. msg.instance_id = mcfg->id.pvt_id;
  1108. msg.param_data_size = size;
  1109. msg.large_param_id = param_id;
  1110. return skl_ipc_set_large_config(&ctx->ipc, &msg, params);
  1111. }
  1112. int skl_get_module_params(struct skl_sst *ctx, u32 *params, int size,
  1113. u32 param_id, struct skl_module_cfg *mcfg)
  1114. {
  1115. struct skl_ipc_large_config_msg msg;
  1116. msg.module_id = mcfg->id.module_id;
  1117. msg.instance_id = mcfg->id.pvt_id;
  1118. msg.param_data_size = size;
  1119. msg.large_param_id = param_id;
  1120. return skl_ipc_get_large_config(&ctx->ipc, &msg, params);
  1121. }