hpi6205.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Hardware Programming Interface (HPI) for AudioScience
  15. ASI50xx, AS51xx, ASI6xxx, ASI87xx ASI89xx series adapters.
  16. These PCI and PCIe bus adapters are based on a
  17. TMS320C6205 PCI bus mastering DSP,
  18. and (except ASI50xx) TI TMS320C6xxx floating point DSP
  19. Exported function:
  20. void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
  21. (C) Copyright AudioScience Inc. 1998-2010
  22. *******************************************************************************/
  23. #define SOURCEFILE_NAME "hpi6205.c"
  24. #include "hpi_internal.h"
  25. #include "hpimsginit.h"
  26. #include "hpidebug.h"
  27. #include "hpi6205.h"
  28. #include "hpidspcd.h"
  29. #include "hpicmn.h"
  30. /*****************************************************************************/
  31. /* HPI6205 specific error codes */
  32. #define HPI6205_ERROR_BASE 1000 /* not actually used anywhere */
  33. /* operational/messaging errors */
  34. #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
  35. #define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
  36. /* initialization/bootload errors */
  37. #define HPI6205_ERROR_6205_NO_IRQ 1002
  38. #define HPI6205_ERROR_6205_INIT_FAILED 1003
  39. #define HPI6205_ERROR_6205_REG 1006
  40. #define HPI6205_ERROR_6205_DSPPAGE 1007
  41. #define HPI6205_ERROR_C6713_HPIC 1009
  42. #define HPI6205_ERROR_C6713_HPIA 1010
  43. #define HPI6205_ERROR_C6713_PLL 1011
  44. #define HPI6205_ERROR_DSP_INTMEM 1012
  45. #define HPI6205_ERROR_DSP_EXTMEM 1013
  46. #define HPI6205_ERROR_DSP_PLD 1014
  47. #define HPI6205_ERROR_6205_EEPROM 1017
  48. #define HPI6205_ERROR_DSP_EMIF1 1018
  49. #define HPI6205_ERROR_DSP_EMIF2 1019
  50. #define HPI6205_ERROR_DSP_EMIF3 1020
  51. #define HPI6205_ERROR_DSP_EMIF4 1021
  52. /*****************************************************************************/
  53. /* for C6205 PCI i/f */
  54. /* Host Status Register (HSR) bitfields */
  55. #define C6205_HSR_INTSRC 0x01
  56. #define C6205_HSR_INTAVAL 0x02
  57. #define C6205_HSR_INTAM 0x04
  58. #define C6205_HSR_CFGERR 0x08
  59. #define C6205_HSR_EEREAD 0x10
  60. /* Host-to-DSP Control Register (HDCR) bitfields */
  61. #define C6205_HDCR_WARMRESET 0x01
  62. #define C6205_HDCR_DSPINT 0x02
  63. #define C6205_HDCR_PCIBOOT 0x04
  64. /* DSP Page Register (DSPP) bitfields, */
  65. /* defines 4 Mbyte page that BAR0 points to */
  66. #define C6205_DSPP_MAP1 0x400
  67. /* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
  68. * BAR1 maps to non-prefetchable 8 Mbyte memory block
  69. * of DSP memory mapped registers (starting at 0x01800000).
  70. * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
  71. * needs to be added to the BAR1 base address set in the PCI config reg
  72. */
  73. #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
  74. #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
  75. #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
  76. #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
  77. /* used to control LED (revA) and reset C6713 (revB) */
  78. #define C6205_BAR0_TIMER1_CTL (0x01980000L)
  79. /* For first 6713 in CE1 space, using DA17,16,2 */
  80. #define HPICL_ADDR 0x01400000L
  81. #define HPICH_ADDR 0x01400004L
  82. #define HPIAL_ADDR 0x01410000L
  83. #define HPIAH_ADDR 0x01410004L
  84. #define HPIDIL_ADDR 0x01420000L
  85. #define HPIDIH_ADDR 0x01420004L
  86. #define HPIDL_ADDR 0x01430000L
  87. #define HPIDH_ADDR 0x01430004L
  88. #define C6713_EMIF_GCTL 0x01800000
  89. #define C6713_EMIF_CE1 0x01800004
  90. #define C6713_EMIF_CE0 0x01800008
  91. #define C6713_EMIF_CE2 0x01800010
  92. #define C6713_EMIF_CE3 0x01800014
  93. #define C6713_EMIF_SDRAMCTL 0x01800018
  94. #define C6713_EMIF_SDRAMTIMING 0x0180001C
  95. #define C6713_EMIF_SDRAMEXT 0x01800020
  96. struct hpi_hw_obj {
  97. /* PCI registers */
  98. __iomem u32 *prHSR;
  99. __iomem u32 *prHDCR;
  100. __iomem u32 *prDSPP;
  101. u32 dsp_page;
  102. struct consistent_dma_area h_locked_mem;
  103. struct bus_master_interface *p_interface_buffer;
  104. u16 flag_outstream_just_reset[HPI_MAX_STREAMS];
  105. /* a non-NULL handle means there is an HPI allocated buffer */
  106. struct consistent_dma_area instream_host_buffers[HPI_MAX_STREAMS];
  107. struct consistent_dma_area outstream_host_buffers[HPI_MAX_STREAMS];
  108. /* non-zero size means a buffer exists, may be external */
  109. u32 instream_host_buffer_size[HPI_MAX_STREAMS];
  110. u32 outstream_host_buffer_size[HPI_MAX_STREAMS];
  111. struct consistent_dma_area h_control_cache;
  112. struct hpi_control_cache *p_cache;
  113. };
  114. /*****************************************************************************/
  115. /* local prototypes */
  116. #define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
  117. static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us);
  118. static void send_dsp_command(struct hpi_hw_obj *phw, int cmd);
  119. static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  120. u32 *pos_error_code);
  121. static u16 message_response_sequence(struct hpi_adapter_obj *pao,
  122. struct hpi_message *phm, struct hpi_response *phr);
  123. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  124. struct hpi_response *phr);
  125. #define HPI6205_TIMEOUT 1000000
  126. static void subsys_create_adapter(struct hpi_message *phm,
  127. struct hpi_response *phr);
  128. static void adapter_delete(struct hpi_adapter_obj *pao,
  129. struct hpi_message *phm, struct hpi_response *phr);
  130. static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
  131. u32 *pos_error_code);
  132. static void delete_adapter_obj(struct hpi_adapter_obj *pao);
  133. static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  134. struct hpi_message *phm, struct hpi_response *phr);
  135. static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  136. struct hpi_message *phm, struct hpi_response *phr);
  137. static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
  138. struct hpi_message *phm, struct hpi_response *phr);
  139. static void outstream_write(struct hpi_adapter_obj *pao,
  140. struct hpi_message *phm, struct hpi_response *phr);
  141. static void outstream_get_info(struct hpi_adapter_obj *pao,
  142. struct hpi_message *phm, struct hpi_response *phr);
  143. static void outstream_start(struct hpi_adapter_obj *pao,
  144. struct hpi_message *phm, struct hpi_response *phr);
  145. static void outstream_open(struct hpi_adapter_obj *pao,
  146. struct hpi_message *phm, struct hpi_response *phr);
  147. static void outstream_reset(struct hpi_adapter_obj *pao,
  148. struct hpi_message *phm, struct hpi_response *phr);
  149. static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  150. struct hpi_message *phm, struct hpi_response *phr);
  151. static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  152. struct hpi_message *phm, struct hpi_response *phr);
  153. static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
  154. struct hpi_message *phm, struct hpi_response *phr);
  155. static void instream_read(struct hpi_adapter_obj *pao,
  156. struct hpi_message *phm, struct hpi_response *phr);
  157. static void instream_get_info(struct hpi_adapter_obj *pao,
  158. struct hpi_message *phm, struct hpi_response *phr);
  159. static void instream_start(struct hpi_adapter_obj *pao,
  160. struct hpi_message *phm, struct hpi_response *phr);
  161. static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  162. u32 address);
  163. static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
  164. int dsp_index, u32 address, u32 data);
  165. static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
  166. int dsp_index);
  167. static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
  168. u32 address, u32 length);
  169. static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
  170. int dsp_index);
  171. static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
  172. int dsp_index);
  173. static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
  174. /*****************************************************************************/
  175. static void subsys_message(struct hpi_adapter_obj *pao,
  176. struct hpi_message *phm, struct hpi_response *phr)
  177. {
  178. switch (phm->function) {
  179. case HPI_SUBSYS_CREATE_ADAPTER:
  180. subsys_create_adapter(phm, phr);
  181. break;
  182. default:
  183. phr->error = HPI_ERROR_INVALID_FUNC;
  184. break;
  185. }
  186. }
  187. static void control_message(struct hpi_adapter_obj *pao,
  188. struct hpi_message *phm, struct hpi_response *phr)
  189. {
  190. struct hpi_hw_obj *phw = pao->priv;
  191. u16 pending_cache_error = 0;
  192. switch (phm->function) {
  193. case HPI_CONTROL_GET_STATE:
  194. if (pao->has_control_cache) {
  195. rmb(); /* make sure we see updates DMAed from DSP */
  196. if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
  197. break;
  198. } else if (phm->u.c.attribute == HPI_METER_PEAK) {
  199. pending_cache_error =
  200. HPI_ERROR_CONTROL_CACHING;
  201. }
  202. }
  203. hw_message(pao, phm, phr);
  204. if (pending_cache_error && !phr->error)
  205. phr->error = pending_cache_error;
  206. break;
  207. case HPI_CONTROL_GET_INFO:
  208. hw_message(pao, phm, phr);
  209. break;
  210. case HPI_CONTROL_SET_STATE:
  211. hw_message(pao, phm, phr);
  212. if (pao->has_control_cache)
  213. hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
  214. phr);
  215. break;
  216. default:
  217. phr->error = HPI_ERROR_INVALID_FUNC;
  218. break;
  219. }
  220. }
  221. static void adapter_message(struct hpi_adapter_obj *pao,
  222. struct hpi_message *phm, struct hpi_response *phr)
  223. {
  224. switch (phm->function) {
  225. case HPI_ADAPTER_DELETE:
  226. adapter_delete(pao, phm, phr);
  227. break;
  228. default:
  229. hw_message(pao, phm, phr);
  230. break;
  231. }
  232. }
  233. static void outstream_message(struct hpi_adapter_obj *pao,
  234. struct hpi_message *phm, struct hpi_response *phr)
  235. {
  236. if (phm->obj_index >= HPI_MAX_STREAMS) {
  237. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  238. HPI_DEBUG_LOG(WARNING,
  239. "Message referencing invalid stream %d "
  240. "on adapter index %d\n", phm->obj_index,
  241. phm->adapter_index);
  242. return;
  243. }
  244. switch (phm->function) {
  245. case HPI_OSTREAM_WRITE:
  246. outstream_write(pao, phm, phr);
  247. break;
  248. case HPI_OSTREAM_GET_INFO:
  249. outstream_get_info(pao, phm, phr);
  250. break;
  251. case HPI_OSTREAM_HOSTBUFFER_ALLOC:
  252. outstream_host_buffer_allocate(pao, phm, phr);
  253. break;
  254. case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
  255. outstream_host_buffer_get_info(pao, phm, phr);
  256. break;
  257. case HPI_OSTREAM_HOSTBUFFER_FREE:
  258. outstream_host_buffer_free(pao, phm, phr);
  259. break;
  260. case HPI_OSTREAM_START:
  261. outstream_start(pao, phm, phr);
  262. break;
  263. case HPI_OSTREAM_OPEN:
  264. outstream_open(pao, phm, phr);
  265. break;
  266. case HPI_OSTREAM_RESET:
  267. outstream_reset(pao, phm, phr);
  268. break;
  269. default:
  270. hw_message(pao, phm, phr);
  271. break;
  272. }
  273. }
  274. static void instream_message(struct hpi_adapter_obj *pao,
  275. struct hpi_message *phm, struct hpi_response *phr)
  276. {
  277. if (phm->obj_index >= HPI_MAX_STREAMS) {
  278. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  279. HPI_DEBUG_LOG(WARNING,
  280. "Message referencing invalid stream %d "
  281. "on adapter index %d\n", phm->obj_index,
  282. phm->adapter_index);
  283. return;
  284. }
  285. switch (phm->function) {
  286. case HPI_ISTREAM_READ:
  287. instream_read(pao, phm, phr);
  288. break;
  289. case HPI_ISTREAM_GET_INFO:
  290. instream_get_info(pao, phm, phr);
  291. break;
  292. case HPI_ISTREAM_HOSTBUFFER_ALLOC:
  293. instream_host_buffer_allocate(pao, phm, phr);
  294. break;
  295. case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
  296. instream_host_buffer_get_info(pao, phm, phr);
  297. break;
  298. case HPI_ISTREAM_HOSTBUFFER_FREE:
  299. instream_host_buffer_free(pao, phm, phr);
  300. break;
  301. case HPI_ISTREAM_START:
  302. instream_start(pao, phm, phr);
  303. break;
  304. default:
  305. hw_message(pao, phm, phr);
  306. break;
  307. }
  308. }
  309. /*****************************************************************************/
  310. /** Entry point to this HPI backend
  311. * All calls to the HPI start here
  312. */
  313. static
  314. void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  315. struct hpi_response *phr)
  316. {
  317. if (pao && (pao->dsp_crashed >= 10)
  318. && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
  319. /* allow last resort debug read even after crash */
  320. hpi_init_response(phr, phm->object, phm->function,
  321. HPI_ERROR_DSP_HARDWARE);
  322. HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object,
  323. phm->function);
  324. return;
  325. }
  326. /* Init default response */
  327. if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
  328. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  329. HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
  330. switch (phm->type) {
  331. case HPI_TYPE_REQUEST:
  332. switch (phm->object) {
  333. case HPI_OBJ_SUBSYSTEM:
  334. subsys_message(pao, phm, phr);
  335. break;
  336. case HPI_OBJ_ADAPTER:
  337. adapter_message(pao, phm, phr);
  338. break;
  339. case HPI_OBJ_CONTROL:
  340. control_message(pao, phm, phr);
  341. break;
  342. case HPI_OBJ_OSTREAM:
  343. outstream_message(pao, phm, phr);
  344. break;
  345. case HPI_OBJ_ISTREAM:
  346. instream_message(pao, phm, phr);
  347. break;
  348. default:
  349. hw_message(pao, phm, phr);
  350. break;
  351. }
  352. break;
  353. default:
  354. phr->error = HPI_ERROR_INVALID_TYPE;
  355. break;
  356. }
  357. }
  358. void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
  359. {
  360. struct hpi_adapter_obj *pao = NULL;
  361. if (phm->object != HPI_OBJ_SUBSYSTEM) {
  362. /* normal messages must have valid adapter index */
  363. pao = hpi_find_adapter(phm->adapter_index);
  364. } else {
  365. /* subsys messages don't address an adapter */
  366. _HPI_6205(NULL, phm, phr);
  367. return;
  368. }
  369. if (pao)
  370. _HPI_6205(pao, phm, phr);
  371. else
  372. hpi_init_response(phr, phm->object, phm->function,
  373. HPI_ERROR_BAD_ADAPTER_NUMBER);
  374. }
  375. /*****************************************************************************/
  376. /* SUBSYSTEM */
  377. /** Create an adapter object and initialise it based on resource information
  378. * passed in in the message
  379. * *** NOTE - you cannot use this function AND the FindAdapters function at the
  380. * same time, the application must use only one of them to get the adapters ***
  381. */
  382. static void subsys_create_adapter(struct hpi_message *phm,
  383. struct hpi_response *phr)
  384. {
  385. /* create temp adapter obj, because we don't know what index yet */
  386. struct hpi_adapter_obj ao;
  387. u32 os_error_code;
  388. u16 err;
  389. HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
  390. memset(&ao, 0, sizeof(ao));
  391. ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
  392. if (!ao.priv) {
  393. HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
  394. phr->error = HPI_ERROR_MEMORY_ALLOC;
  395. return;
  396. }
  397. ao.pci = *phm->u.s.resource.r.pci;
  398. err = create_adapter_obj(&ao, &os_error_code);
  399. if (err) {
  400. delete_adapter_obj(&ao);
  401. if (err >= HPI_ERROR_BACKEND_BASE) {
  402. phr->error = HPI_ERROR_DSP_BOOTLOAD;
  403. phr->specific_error = err;
  404. } else {
  405. phr->error = err;
  406. }
  407. phr->u.s.data = os_error_code;
  408. return;
  409. }
  410. phr->u.s.adapter_type = ao.type;
  411. phr->u.s.adapter_index = ao.index;
  412. phr->error = 0;
  413. }
  414. /** delete an adapter - required by WDM driver */
  415. static void adapter_delete(struct hpi_adapter_obj *pao,
  416. struct hpi_message *phm, struct hpi_response *phr)
  417. {
  418. struct hpi_hw_obj *phw;
  419. if (!pao) {
  420. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  421. return;
  422. }
  423. phw = pao->priv;
  424. /* reset adapter h/w */
  425. /* Reset C6713 #1 */
  426. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  427. /* reset C6205 */
  428. iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
  429. delete_adapter_obj(pao);
  430. hpi_delete_adapter(pao);
  431. phr->error = 0;
  432. }
  433. /** Create adapter object
  434. allocate buffers, bootload DSPs, initialise control cache
  435. */
  436. static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
  437. u32 *pos_error_code)
  438. {
  439. struct hpi_hw_obj *phw = pao->priv;
  440. struct bus_master_interface *interface;
  441. u32 phys_addr;
  442. int i;
  443. u16 err;
  444. /* init error reporting */
  445. pao->dsp_crashed = 0;
  446. for (i = 0; i < HPI_MAX_STREAMS; i++)
  447. phw->flag_outstream_just_reset[i] = 1;
  448. /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
  449. phw->prHSR =
  450. pao->pci.ap_mem_base[1] +
  451. C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
  452. phw->prHDCR =
  453. pao->pci.ap_mem_base[1] +
  454. C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
  455. phw->prDSPP =
  456. pao->pci.ap_mem_base[1] +
  457. C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
  458. pao->has_control_cache = 0;
  459. if (hpios_locked_mem_alloc(&phw->h_locked_mem,
  460. sizeof(struct bus_master_interface),
  461. pao->pci.pci_dev))
  462. phw->p_interface_buffer = NULL;
  463. else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
  464. (void *)&phw->p_interface_buffer))
  465. phw->p_interface_buffer = NULL;
  466. HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
  467. phw->p_interface_buffer);
  468. if (phw->p_interface_buffer) {
  469. memset((void *)phw->p_interface_buffer, 0,
  470. sizeof(struct bus_master_interface));
  471. phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
  472. }
  473. err = adapter_boot_load_dsp(pao, pos_error_code);
  474. if (err) {
  475. HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");
  476. /* no need to clean up as SubSysCreateAdapter */
  477. /* calls DeleteAdapter on error. */
  478. return err;
  479. }
  480. HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
  481. /* allow boot load even if mem alloc wont work */
  482. if (!phw->p_interface_buffer)
  483. return HPI_ERROR_MEMORY_ALLOC;
  484. interface = phw->p_interface_buffer;
  485. /* make sure the DSP has started ok */
  486. if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
  487. HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
  488. return HPI6205_ERROR_6205_INIT_FAILED;
  489. }
  490. /* Note that *pao, *phw are zeroed after allocation,
  491. * so pointers and flags are NULL by default.
  492. * Allocate bus mastering control cache buffer and tell the DSP about it
  493. */
  494. if (interface->control_cache.number_of_controls) {
  495. u8 *p_control_cache_virtual;
  496. err = hpios_locked_mem_alloc(&phw->h_control_cache,
  497. interface->control_cache.size_in_bytes,
  498. pao->pci.pci_dev);
  499. if (!err)
  500. err = hpios_locked_mem_get_virt_addr(&phw->
  501. h_control_cache,
  502. (void *)&p_control_cache_virtual);
  503. if (!err) {
  504. memset(p_control_cache_virtual, 0,
  505. interface->control_cache.size_in_bytes);
  506. phw->p_cache =
  507. hpi_alloc_control_cache(interface->
  508. control_cache.number_of_controls,
  509. interface->control_cache.size_in_bytes,
  510. p_control_cache_virtual);
  511. if (!phw->p_cache)
  512. err = HPI_ERROR_MEMORY_ALLOC;
  513. }
  514. if (!err) {
  515. err = hpios_locked_mem_get_phys_addr(&phw->
  516. h_control_cache, &phys_addr);
  517. interface->control_cache.physical_address32 =
  518. phys_addr;
  519. }
  520. if (!err)
  521. pao->has_control_cache = 1;
  522. else {
  523. if (hpios_locked_mem_valid(&phw->h_control_cache))
  524. hpios_locked_mem_free(&phw->h_control_cache);
  525. pao->has_control_cache = 0;
  526. }
  527. }
  528. send_dsp_command(phw, H620_HIF_IDLE);
  529. {
  530. struct hpi_message hm;
  531. struct hpi_response hr;
  532. u32 max_streams;
  533. HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
  534. memset(&hm, 0, sizeof(hm));
  535. /* wAdapterIndex == version == 0 */
  536. hm.type = HPI_TYPE_REQUEST;
  537. hm.size = sizeof(hm);
  538. hm.object = HPI_OBJ_ADAPTER;
  539. hm.function = HPI_ADAPTER_GET_INFO;
  540. memset(&hr, 0, sizeof(hr));
  541. hr.size = sizeof(hr);
  542. err = message_response_sequence(pao, &hm, &hr);
  543. if (err) {
  544. HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
  545. err);
  546. return err;
  547. }
  548. if (hr.error)
  549. return hr.error;
  550. pao->type = hr.u.ax.info.adapter_type;
  551. pao->index = hr.u.ax.info.adapter_index;
  552. max_streams =
  553. hr.u.ax.info.num_outstreams +
  554. hr.u.ax.info.num_instreams;
  555. HPI_DEBUG_LOG(VERBOSE,
  556. "got adapter info type %x index %d serial %d\n",
  557. hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
  558. hr.u.ax.info.serial_number);
  559. }
  560. if (phw->p_cache)
  561. phw->p_cache->adap_idx = pao->index;
  562. HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
  563. return hpi_add_adapter(pao);
  564. }
  565. /** Free memory areas allocated by adapter
  566. * this routine is called from AdapterDelete,
  567. * and SubSysCreateAdapter if duplicate index
  568. */
  569. static void delete_adapter_obj(struct hpi_adapter_obj *pao)
  570. {
  571. struct hpi_hw_obj *phw = pao->priv;
  572. int i;
  573. if (hpios_locked_mem_valid(&phw->h_control_cache)) {
  574. hpios_locked_mem_free(&phw->h_control_cache);
  575. hpi_free_control_cache(phw->p_cache);
  576. }
  577. if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
  578. hpios_locked_mem_free(&phw->h_locked_mem);
  579. phw->p_interface_buffer = NULL;
  580. }
  581. for (i = 0; i < HPI_MAX_STREAMS; i++)
  582. if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
  583. hpios_locked_mem_free(&phw->instream_host_buffers[i]);
  584. /*?phw->InStreamHostBuffers[i] = NULL; */
  585. phw->instream_host_buffer_size[i] = 0;
  586. }
  587. for (i = 0; i < HPI_MAX_STREAMS; i++)
  588. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
  589. hpios_locked_mem_free(&phw->outstream_host_buffers
  590. [i]);
  591. phw->outstream_host_buffer_size[i] = 0;
  592. }
  593. kfree(phw);
  594. }
  595. /*****************************************************************************/
  596. /* Adapter functions */
  597. /*****************************************************************************/
  598. /* OutStream Host buffer functions */
  599. /** Allocate or attach buffer for busmastering
  600. */
  601. static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  602. struct hpi_message *phm, struct hpi_response *phr)
  603. {
  604. u16 err = 0;
  605. u32 command = phm->u.d.u.buffer.command;
  606. struct hpi_hw_obj *phw = pao->priv;
  607. struct bus_master_interface *interface = phw->p_interface_buffer;
  608. hpi_init_response(phr, phm->object, phm->function, 0);
  609. if (command == HPI_BUFFER_CMD_EXTERNAL
  610. || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
  611. /* ALLOC phase, allocate a buffer with power of 2 size,
  612. get its bus address for PCI bus mastering
  613. */
  614. phm->u.d.u.buffer.buffer_size =
  615. roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
  616. /* return old size and allocated size,
  617. so caller can detect change */
  618. phr->u.d.u.stream_info.data_available =
  619. phw->outstream_host_buffer_size[phm->obj_index];
  620. phr->u.d.u.stream_info.buffer_size =
  621. phm->u.d.u.buffer.buffer_size;
  622. if (phw->outstream_host_buffer_size[phm->obj_index] ==
  623. phm->u.d.u.buffer.buffer_size) {
  624. /* Same size, no action required */
  625. return;
  626. }
  627. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  628. obj_index]))
  629. hpios_locked_mem_free(&phw->outstream_host_buffers
  630. [phm->obj_index]);
  631. err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
  632. [phm->obj_index], phm->u.d.u.buffer.buffer_size,
  633. pao->pci.pci_dev);
  634. if (err) {
  635. phr->error = HPI_ERROR_INVALID_DATASIZE;
  636. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  637. return;
  638. }
  639. err = hpios_locked_mem_get_phys_addr
  640. (&phw->outstream_host_buffers[phm->obj_index],
  641. &phm->u.d.u.buffer.pci_address);
  642. /* get the phys addr into msg for single call alloc caller
  643. * needs to do this for split alloc (or use the same message)
  644. * return the phy address for split alloc in the respose too
  645. */
  646. phr->u.d.u.stream_info.auxiliary_data_available =
  647. phm->u.d.u.buffer.pci_address;
  648. if (err) {
  649. hpios_locked_mem_free(&phw->outstream_host_buffers
  650. [phm->obj_index]);
  651. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  652. phr->error = HPI_ERROR_MEMORY_ALLOC;
  653. return;
  654. }
  655. }
  656. if (command == HPI_BUFFER_CMD_EXTERNAL
  657. || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
  658. /* GRANT phase. Set up the BBM status, tell the DSP about
  659. the buffer so it can start using BBM.
  660. */
  661. struct hpi_hostbuffer_status *status;
  662. if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
  663. buffer_size - 1)) {
  664. HPI_DEBUG_LOG(ERROR,
  665. "Buffer size must be 2^N not %d\n",
  666. phm->u.d.u.buffer.buffer_size);
  667. phr->error = HPI_ERROR_INVALID_DATASIZE;
  668. return;
  669. }
  670. phw->outstream_host_buffer_size[phm->obj_index] =
  671. phm->u.d.u.buffer.buffer_size;
  672. status = &interface->outstream_host_buffer_status[phm->
  673. obj_index];
  674. status->samples_processed = 0;
  675. status->stream_state = HPI_STATE_STOPPED;
  676. status->dsp_index = 0;
  677. status->host_index = status->dsp_index;
  678. status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
  679. status->auxiliary_data_available = 0;
  680. hw_message(pao, phm, phr);
  681. if (phr->error
  682. && hpios_locked_mem_valid(&phw->
  683. outstream_host_buffers[phm->obj_index])) {
  684. hpios_locked_mem_free(&phw->outstream_host_buffers
  685. [phm->obj_index]);
  686. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  687. }
  688. }
  689. }
  690. static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  691. struct hpi_message *phm, struct hpi_response *phr)
  692. {
  693. struct hpi_hw_obj *phw = pao->priv;
  694. struct bus_master_interface *interface = phw->p_interface_buffer;
  695. struct hpi_hostbuffer_status *status;
  696. u8 *p_bbm_data;
  697. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  698. obj_index])) {
  699. if (hpios_locked_mem_get_virt_addr(&phw->
  700. outstream_host_buffers[phm->obj_index],
  701. (void *)&p_bbm_data)) {
  702. phr->error = HPI_ERROR_INVALID_OPERATION;
  703. return;
  704. }
  705. status = &interface->outstream_host_buffer_status[phm->
  706. obj_index];
  707. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  708. HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
  709. phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
  710. phr->u.d.u.hostbuffer_info.p_status = status;
  711. } else {
  712. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  713. HPI_OSTREAM_HOSTBUFFER_GET_INFO,
  714. HPI_ERROR_INVALID_OPERATION);
  715. }
  716. }
  717. static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
  718. struct hpi_message *phm, struct hpi_response *phr)
  719. {
  720. struct hpi_hw_obj *phw = pao->priv;
  721. u32 command = phm->u.d.u.buffer.command;
  722. if (phw->outstream_host_buffer_size[phm->obj_index]) {
  723. if (command == HPI_BUFFER_CMD_EXTERNAL
  724. || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
  725. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  726. hw_message(pao, phm, phr);
  727. /* Tell adapter to stop using the host buffer. */
  728. }
  729. if (command == HPI_BUFFER_CMD_EXTERNAL
  730. || command == HPI_BUFFER_CMD_INTERNAL_FREE)
  731. hpios_locked_mem_free(&phw->outstream_host_buffers
  732. [phm->obj_index]);
  733. }
  734. /* Should HPI_ERROR_INVALID_OPERATION be returned
  735. if no host buffer is allocated? */
  736. else
  737. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  738. HPI_OSTREAM_HOSTBUFFER_FREE, 0);
  739. }
  740. static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)
  741. {
  742. return status->size_in_bytes - (status->host_index -
  743. status->dsp_index);
  744. }
  745. static void outstream_write(struct hpi_adapter_obj *pao,
  746. struct hpi_message *phm, struct hpi_response *phr)
  747. {
  748. struct hpi_hw_obj *phw = pao->priv;
  749. struct bus_master_interface *interface = phw->p_interface_buffer;
  750. struct hpi_hostbuffer_status *status;
  751. u32 space_available;
  752. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  753. /* there is no BBM buffer, write via message */
  754. hw_message(pao, phm, phr);
  755. return;
  756. }
  757. hpi_init_response(phr, phm->object, phm->function, 0);
  758. status = &interface->outstream_host_buffer_status[phm->obj_index];
  759. space_available = outstream_get_space_available(status);
  760. if (space_available < phm->u.d.u.data.data_size) {
  761. phr->error = HPI_ERROR_INVALID_DATASIZE;
  762. return;
  763. }
  764. /* HostBuffers is used to indicate host buffer is internally allocated.
  765. otherwise, assumed external, data written externally */
  766. if (phm->u.d.u.data.pb_data
  767. && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  768. obj_index])) {
  769. u8 *p_bbm_data;
  770. u32 l_first_write;
  771. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  772. if (hpios_locked_mem_get_virt_addr(&phw->
  773. outstream_host_buffers[phm->obj_index],
  774. (void *)&p_bbm_data)) {
  775. phr->error = HPI_ERROR_INVALID_OPERATION;
  776. return;
  777. }
  778. /* either all data,
  779. or enough to fit from current to end of BBM buffer */
  780. l_first_write =
  781. min(phm->u.d.u.data.data_size,
  782. status->size_in_bytes -
  783. (status->host_index & (status->size_in_bytes - 1)));
  784. memcpy(p_bbm_data +
  785. (status->host_index & (status->size_in_bytes - 1)),
  786. p_app_data, l_first_write);
  787. /* remaining data if any */
  788. memcpy(p_bbm_data, p_app_data + l_first_write,
  789. phm->u.d.u.data.data_size - l_first_write);
  790. }
  791. /*
  792. * This version relies on the DSP code triggering an OStream buffer
  793. * update immediately following a SET_FORMAT call. The host has
  794. * already written data into the BBM buffer, but the DSP won't know
  795. * about it until dwHostIndex is adjusted.
  796. */
  797. if (phw->flag_outstream_just_reset[phm->obj_index]) {
  798. /* Format can only change after reset. Must tell DSP. */
  799. u16 function = phm->function;
  800. phw->flag_outstream_just_reset[phm->obj_index] = 0;
  801. phm->function = HPI_OSTREAM_SET_FORMAT;
  802. hw_message(pao, phm, phr); /* send the format to the DSP */
  803. phm->function = function;
  804. if (phr->error)
  805. return;
  806. }
  807. status->host_index += phm->u.d.u.data.data_size;
  808. }
  809. static void outstream_get_info(struct hpi_adapter_obj *pao,
  810. struct hpi_message *phm, struct hpi_response *phr)
  811. {
  812. struct hpi_hw_obj *phw = pao->priv;
  813. struct bus_master_interface *interface = phw->p_interface_buffer;
  814. struct hpi_hostbuffer_status *status;
  815. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  816. hw_message(pao, phm, phr);
  817. return;
  818. }
  819. hpi_init_response(phr, phm->object, phm->function, 0);
  820. status = &interface->outstream_host_buffer_status[phm->obj_index];
  821. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  822. phr->u.d.u.stream_info.samples_transferred =
  823. status->samples_processed;
  824. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  825. phr->u.d.u.stream_info.data_available =
  826. status->size_in_bytes - outstream_get_space_available(status);
  827. phr->u.d.u.stream_info.auxiliary_data_available =
  828. status->auxiliary_data_available;
  829. }
  830. static void outstream_start(struct hpi_adapter_obj *pao,
  831. struct hpi_message *phm, struct hpi_response *phr)
  832. {
  833. hw_message(pao, phm, phr);
  834. }
  835. static void outstream_reset(struct hpi_adapter_obj *pao,
  836. struct hpi_message *phm, struct hpi_response *phr)
  837. {
  838. struct hpi_hw_obj *phw = pao->priv;
  839. phw->flag_outstream_just_reset[phm->obj_index] = 1;
  840. hw_message(pao, phm, phr);
  841. }
  842. static void outstream_open(struct hpi_adapter_obj *pao,
  843. struct hpi_message *phm, struct hpi_response *phr)
  844. {
  845. outstream_reset(pao, phm, phr);
  846. }
  847. /*****************************************************************************/
  848. /* InStream Host buffer functions */
  849. static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  850. struct hpi_message *phm, struct hpi_response *phr)
  851. {
  852. u16 err = 0;
  853. u32 command = phm->u.d.u.buffer.command;
  854. struct hpi_hw_obj *phw = pao->priv;
  855. struct bus_master_interface *interface = phw->p_interface_buffer;
  856. hpi_init_response(phr, phm->object, phm->function, 0);
  857. if (command == HPI_BUFFER_CMD_EXTERNAL
  858. || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
  859. phm->u.d.u.buffer.buffer_size =
  860. roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
  861. phr->u.d.u.stream_info.data_available =
  862. phw->instream_host_buffer_size[phm->obj_index];
  863. phr->u.d.u.stream_info.buffer_size =
  864. phm->u.d.u.buffer.buffer_size;
  865. if (phw->instream_host_buffer_size[phm->obj_index] ==
  866. phm->u.d.u.buffer.buffer_size) {
  867. /* Same size, no action required */
  868. return;
  869. }
  870. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  871. obj_index]))
  872. hpios_locked_mem_free(&phw->instream_host_buffers
  873. [phm->obj_index]);
  874. err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
  875. obj_index], phm->u.d.u.buffer.buffer_size,
  876. pao->pci.pci_dev);
  877. if (err) {
  878. phr->error = HPI_ERROR_INVALID_DATASIZE;
  879. phw->instream_host_buffer_size[phm->obj_index] = 0;
  880. return;
  881. }
  882. err = hpios_locked_mem_get_phys_addr
  883. (&phw->instream_host_buffers[phm->obj_index],
  884. &phm->u.d.u.buffer.pci_address);
  885. /* get the phys addr into msg for single call alloc. Caller
  886. needs to do this for split alloc so return the phy address */
  887. phr->u.d.u.stream_info.auxiliary_data_available =
  888. phm->u.d.u.buffer.pci_address;
  889. if (err) {
  890. hpios_locked_mem_free(&phw->instream_host_buffers
  891. [phm->obj_index]);
  892. phw->instream_host_buffer_size[phm->obj_index] = 0;
  893. phr->error = HPI_ERROR_MEMORY_ALLOC;
  894. return;
  895. }
  896. }
  897. if (command == HPI_BUFFER_CMD_EXTERNAL
  898. || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
  899. struct hpi_hostbuffer_status *status;
  900. if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
  901. buffer_size - 1)) {
  902. HPI_DEBUG_LOG(ERROR,
  903. "Buffer size must be 2^N not %d\n",
  904. phm->u.d.u.buffer.buffer_size);
  905. phr->error = HPI_ERROR_INVALID_DATASIZE;
  906. return;
  907. }
  908. phw->instream_host_buffer_size[phm->obj_index] =
  909. phm->u.d.u.buffer.buffer_size;
  910. status = &interface->instream_host_buffer_status[phm->
  911. obj_index];
  912. status->samples_processed = 0;
  913. status->stream_state = HPI_STATE_STOPPED;
  914. status->dsp_index = 0;
  915. status->host_index = status->dsp_index;
  916. status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
  917. status->auxiliary_data_available = 0;
  918. hw_message(pao, phm, phr);
  919. if (phr->error
  920. && hpios_locked_mem_valid(&phw->
  921. instream_host_buffers[phm->obj_index])) {
  922. hpios_locked_mem_free(&phw->instream_host_buffers
  923. [phm->obj_index]);
  924. phw->instream_host_buffer_size[phm->obj_index] = 0;
  925. }
  926. }
  927. }
  928. static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  929. struct hpi_message *phm, struct hpi_response *phr)
  930. {
  931. struct hpi_hw_obj *phw = pao->priv;
  932. struct bus_master_interface *interface = phw->p_interface_buffer;
  933. struct hpi_hostbuffer_status *status;
  934. u8 *p_bbm_data;
  935. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  936. obj_index])) {
  937. if (hpios_locked_mem_get_virt_addr(&phw->
  938. instream_host_buffers[phm->obj_index],
  939. (void *)&p_bbm_data)) {
  940. phr->error = HPI_ERROR_INVALID_OPERATION;
  941. return;
  942. }
  943. status = &interface->instream_host_buffer_status[phm->
  944. obj_index];
  945. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  946. HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
  947. phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
  948. phr->u.d.u.hostbuffer_info.p_status = status;
  949. } else {
  950. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  951. HPI_ISTREAM_HOSTBUFFER_GET_INFO,
  952. HPI_ERROR_INVALID_OPERATION);
  953. }
  954. }
  955. static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
  956. struct hpi_message *phm, struct hpi_response *phr)
  957. {
  958. struct hpi_hw_obj *phw = pao->priv;
  959. u32 command = phm->u.d.u.buffer.command;
  960. if (phw->instream_host_buffer_size[phm->obj_index]) {
  961. if (command == HPI_BUFFER_CMD_EXTERNAL
  962. || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
  963. phw->instream_host_buffer_size[phm->obj_index] = 0;
  964. hw_message(pao, phm, phr);
  965. }
  966. if (command == HPI_BUFFER_CMD_EXTERNAL
  967. || command == HPI_BUFFER_CMD_INTERNAL_FREE)
  968. hpios_locked_mem_free(&phw->instream_host_buffers
  969. [phm->obj_index]);
  970. } else {
  971. /* Should HPI_ERROR_INVALID_OPERATION be returned
  972. if no host buffer is allocated? */
  973. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  974. HPI_ISTREAM_HOSTBUFFER_FREE, 0);
  975. }
  976. }
  977. static void instream_start(struct hpi_adapter_obj *pao,
  978. struct hpi_message *phm, struct hpi_response *phr)
  979. {
  980. hw_message(pao, phm, phr);
  981. }
  982. static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
  983. {
  984. return status->dsp_index - status->host_index;
  985. }
  986. static void instream_read(struct hpi_adapter_obj *pao,
  987. struct hpi_message *phm, struct hpi_response *phr)
  988. {
  989. struct hpi_hw_obj *phw = pao->priv;
  990. struct bus_master_interface *interface = phw->p_interface_buffer;
  991. struct hpi_hostbuffer_status *status;
  992. u32 data_available;
  993. u8 *p_bbm_data;
  994. u32 l_first_read;
  995. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  996. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  997. hw_message(pao, phm, phr);
  998. return;
  999. }
  1000. hpi_init_response(phr, phm->object, phm->function, 0);
  1001. status = &interface->instream_host_buffer_status[phm->obj_index];
  1002. data_available = instream_get_bytes_available(status);
  1003. if (data_available < phm->u.d.u.data.data_size) {
  1004. phr->error = HPI_ERROR_INVALID_DATASIZE;
  1005. return;
  1006. }
  1007. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  1008. obj_index])) {
  1009. if (hpios_locked_mem_get_virt_addr(&phw->
  1010. instream_host_buffers[phm->obj_index],
  1011. (void *)&p_bbm_data)) {
  1012. phr->error = HPI_ERROR_INVALID_OPERATION;
  1013. return;
  1014. }
  1015. /* either all data,
  1016. or enough to fit from current to end of BBM buffer */
  1017. l_first_read =
  1018. min(phm->u.d.u.data.data_size,
  1019. status->size_in_bytes -
  1020. (status->host_index & (status->size_in_bytes - 1)));
  1021. memcpy(p_app_data,
  1022. p_bbm_data +
  1023. (status->host_index & (status->size_in_bytes - 1)),
  1024. l_first_read);
  1025. /* remaining data if any */
  1026. memcpy(p_app_data + l_first_read, p_bbm_data,
  1027. phm->u.d.u.data.data_size - l_first_read);
  1028. }
  1029. status->host_index += phm->u.d.u.data.data_size;
  1030. }
  1031. static void instream_get_info(struct hpi_adapter_obj *pao,
  1032. struct hpi_message *phm, struct hpi_response *phr)
  1033. {
  1034. struct hpi_hw_obj *phw = pao->priv;
  1035. struct bus_master_interface *interface = phw->p_interface_buffer;
  1036. struct hpi_hostbuffer_status *status;
  1037. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  1038. hw_message(pao, phm, phr);
  1039. return;
  1040. }
  1041. status = &interface->instream_host_buffer_status[phm->obj_index];
  1042. hpi_init_response(phr, phm->object, phm->function, 0);
  1043. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  1044. phr->u.d.u.stream_info.samples_transferred =
  1045. status->samples_processed;
  1046. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  1047. phr->u.d.u.stream_info.data_available =
  1048. instream_get_bytes_available(status);
  1049. phr->u.d.u.stream_info.auxiliary_data_available =
  1050. status->auxiliary_data_available;
  1051. }
  1052. /*****************************************************************************/
  1053. /* LOW-LEVEL */
  1054. #define HPI6205_MAX_FILES_TO_LOAD 2
  1055. static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  1056. u32 *pos_error_code)
  1057. {
  1058. struct hpi_hw_obj *phw = pao->priv;
  1059. struct dsp_code dsp_code;
  1060. u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
  1061. u32 temp;
  1062. int dsp = 0, i = 0;
  1063. u16 err = 0;
  1064. boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
  1065. boot_code_id[1] = pao->pci.pci_dev->subsystem_device;
  1066. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id[1]);
  1067. /* fix up cases where bootcode id[1] != subsys id */
  1068. switch (boot_code_id[1]) {
  1069. case HPI_ADAPTER_FAMILY_ASI(0x5000):
  1070. boot_code_id[0] = boot_code_id[1];
  1071. boot_code_id[1] = 0;
  1072. break;
  1073. case HPI_ADAPTER_FAMILY_ASI(0x5300):
  1074. case HPI_ADAPTER_FAMILY_ASI(0x5400):
  1075. case HPI_ADAPTER_FAMILY_ASI(0x6300):
  1076. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
  1077. break;
  1078. case HPI_ADAPTER_FAMILY_ASI(0x5500):
  1079. case HPI_ADAPTER_FAMILY_ASI(0x5600):
  1080. case HPI_ADAPTER_FAMILY_ASI(0x6500):
  1081. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
  1082. break;
  1083. case HPI_ADAPTER_FAMILY_ASI(0x8800):
  1084. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
  1085. break;
  1086. default:
  1087. break;
  1088. }
  1089. /* reset DSP by writing a 1 to the WARMRESET bit */
  1090. temp = C6205_HDCR_WARMRESET;
  1091. iowrite32(temp, phw->prHDCR);
  1092. hpios_delay_micro_seconds(1000);
  1093. /* check that PCI i/f was configured by EEPROM */
  1094. temp = ioread32(phw->prHSR);
  1095. if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
  1096. C6205_HSR_EEREAD)
  1097. return HPI6205_ERROR_6205_EEPROM;
  1098. temp |= 0x04;
  1099. /* disable PINTA interrupt */
  1100. iowrite32(temp, phw->prHSR);
  1101. /* check control register reports PCI boot mode */
  1102. temp = ioread32(phw->prHDCR);
  1103. if (!(temp & C6205_HDCR_PCIBOOT))
  1104. return HPI6205_ERROR_6205_REG;
  1105. /* try writing a few numbers to the DSP page register */
  1106. /* and reading them back. */
  1107. temp = 3;
  1108. iowrite32(temp, phw->prDSPP);
  1109. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1110. return HPI6205_ERROR_6205_DSPPAGE;
  1111. temp = 2;
  1112. iowrite32(temp, phw->prDSPP);
  1113. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1114. return HPI6205_ERROR_6205_DSPPAGE;
  1115. temp = 1;
  1116. iowrite32(temp, phw->prDSPP);
  1117. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1118. return HPI6205_ERROR_6205_DSPPAGE;
  1119. /* reset DSP page to the correct number */
  1120. temp = 0;
  1121. iowrite32(temp, phw->prDSPP);
  1122. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1123. return HPI6205_ERROR_6205_DSPPAGE;
  1124. phw->dsp_page = 0;
  1125. /* release 6713 from reset before 6205 is bootloaded.
  1126. This ensures that the EMIF is inactive,
  1127. and the 6713 HPI gets the correct bootmode etc
  1128. */
  1129. if (boot_code_id[1] != 0) {
  1130. /* DSP 1 is a C6713 */
  1131. /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
  1132. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
  1133. hpios_delay_micro_seconds(100);
  1134. /* Reset the 6713 #1 - revB */
  1135. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  1136. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1137. boot_loader_read_mem32(pao, 0, 0);
  1138. hpios_delay_micro_seconds(100);
  1139. /* Release C6713 from reset - revB */
  1140. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
  1141. hpios_delay_micro_seconds(100);
  1142. }
  1143. for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
  1144. /* is there a DSP to load? */
  1145. if (boot_code_id[dsp] == 0)
  1146. continue;
  1147. err = boot_loader_config_emif(pao, dsp);
  1148. if (err)
  1149. return err;
  1150. err = boot_loader_test_internal_memory(pao, dsp);
  1151. if (err)
  1152. return err;
  1153. err = boot_loader_test_external_memory(pao, dsp);
  1154. if (err)
  1155. return err;
  1156. err = boot_loader_test_pld(pao, dsp);
  1157. if (err)
  1158. return err;
  1159. /* write the DSP code down into the DSPs memory */
  1160. err = hpi_dsp_code_open(boot_code_id[dsp], pao->pci.pci_dev,
  1161. &dsp_code, pos_error_code);
  1162. if (err)
  1163. return err;
  1164. while (1) {
  1165. u32 length;
  1166. u32 address;
  1167. u32 type;
  1168. u32 *pcode;
  1169. err = hpi_dsp_code_read_word(&dsp_code, &length);
  1170. if (err)
  1171. break;
  1172. if (length == 0xFFFFFFFF)
  1173. break; /* end of code */
  1174. err = hpi_dsp_code_read_word(&dsp_code, &address);
  1175. if (err)
  1176. break;
  1177. err = hpi_dsp_code_read_word(&dsp_code, &type);
  1178. if (err)
  1179. break;
  1180. err = hpi_dsp_code_read_block(length, &dsp_code,
  1181. &pcode);
  1182. if (err)
  1183. break;
  1184. for (i = 0; i < (int)length; i++) {
  1185. boot_loader_write_mem32(pao, dsp, address,
  1186. *pcode);
  1187. /* dummy read every 4 words */
  1188. /* for 6205 advisory 1.4.4 */
  1189. if (i % 4 == 0)
  1190. boot_loader_read_mem32(pao, dsp,
  1191. address);
  1192. pcode++;
  1193. address += 4;
  1194. }
  1195. }
  1196. if (err) {
  1197. hpi_dsp_code_close(&dsp_code);
  1198. return err;
  1199. }
  1200. /* verify code */
  1201. hpi_dsp_code_rewind(&dsp_code);
  1202. while (1) {
  1203. u32 length = 0;
  1204. u32 address = 0;
  1205. u32 type = 0;
  1206. u32 *pcode = NULL;
  1207. u32 data = 0;
  1208. hpi_dsp_code_read_word(&dsp_code, &length);
  1209. if (length == 0xFFFFFFFF)
  1210. break; /* end of code */
  1211. hpi_dsp_code_read_word(&dsp_code, &address);
  1212. hpi_dsp_code_read_word(&dsp_code, &type);
  1213. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  1214. for (i = 0; i < (int)length; i++) {
  1215. data = boot_loader_read_mem32(pao, dsp,
  1216. address);
  1217. if (data != *pcode) {
  1218. err = 0;
  1219. break;
  1220. }
  1221. pcode++;
  1222. address += 4;
  1223. }
  1224. if (err)
  1225. break;
  1226. }
  1227. hpi_dsp_code_close(&dsp_code);
  1228. if (err)
  1229. return err;
  1230. }
  1231. /* After bootloading all DSPs, start DSP0 running
  1232. * The DSP0 code will handle starting and synchronizing with its slaves
  1233. */
  1234. if (phw->p_interface_buffer) {
  1235. /* we need to tell the card the physical PCI address */
  1236. u32 physicalPC_iaddress;
  1237. struct bus_master_interface *interface =
  1238. phw->p_interface_buffer;
  1239. u32 host_mailbox_address_on_dsp;
  1240. u32 physicalPC_iaddress_verify = 0;
  1241. int time_out = 10;
  1242. /* set ack so we know when DSP is ready to go */
  1243. /* (dwDspAck will be changed to HIF_RESET) */
  1244. interface->dsp_ack = H620_HIF_UNKNOWN;
  1245. wmb(); /* ensure ack is written before dsp writes back */
  1246. err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
  1247. &physicalPC_iaddress);
  1248. /* locate the host mailbox on the DSP. */
  1249. host_mailbox_address_on_dsp = 0x80000000;
  1250. while ((physicalPC_iaddress != physicalPC_iaddress_verify)
  1251. && time_out--) {
  1252. boot_loader_write_mem32(pao, 0,
  1253. host_mailbox_address_on_dsp,
  1254. physicalPC_iaddress);
  1255. physicalPC_iaddress_verify =
  1256. boot_loader_read_mem32(pao, 0,
  1257. host_mailbox_address_on_dsp);
  1258. }
  1259. }
  1260. HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
  1261. /* enable interrupts */
  1262. temp = ioread32(phw->prHSR);
  1263. temp &= ~(u32)C6205_HSR_INTAM;
  1264. iowrite32(temp, phw->prHSR);
  1265. /* start code running... */
  1266. temp = ioread32(phw->prHDCR);
  1267. temp |= (u32)C6205_HDCR_DSPINT;
  1268. iowrite32(temp, phw->prHDCR);
  1269. /* give the DSP 10ms to start up */
  1270. hpios_delay_micro_seconds(10000);
  1271. return err;
  1272. }
  1273. /*****************************************************************************/
  1274. /* Bootloader utility functions */
  1275. static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  1276. u32 address)
  1277. {
  1278. struct hpi_hw_obj *phw = pao->priv;
  1279. u32 data = 0;
  1280. __iomem u32 *p_data;
  1281. if (dsp_index == 0) {
  1282. /* DSP 0 is always C6205 */
  1283. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1284. /* BAR1 register access */
  1285. p_data = pao->pci.ap_mem_base[1] +
  1286. (address & 0x007fffff) /
  1287. sizeof(*pao->pci.ap_mem_base[1]);
  1288. /* HPI_DEBUG_LOG(WARNING,
  1289. "BAR1 access %08x\n", dwAddress); */
  1290. } else {
  1291. u32 dw4M_page = address >> 22L;
  1292. if (dw4M_page != phw->dsp_page) {
  1293. phw->dsp_page = dw4M_page;
  1294. /* *INDENT OFF* */
  1295. iowrite32(phw->dsp_page, phw->prDSPP);
  1296. /* *INDENT-ON* */
  1297. }
  1298. address &= 0x3fffff; /* address within 4M page */
  1299. /* BAR0 memory access */
  1300. p_data = pao->pci.ap_mem_base[0] +
  1301. address / sizeof(u32);
  1302. }
  1303. data = ioread32(p_data);
  1304. } else if (dsp_index == 1) {
  1305. /* DSP 1 is a C6713 */
  1306. u32 lsb;
  1307. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1308. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1309. lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
  1310. data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
  1311. data = (data << 16) | (lsb & 0xFFFF);
  1312. }
  1313. return data;
  1314. }
  1315. static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
  1316. int dsp_index, u32 address, u32 data)
  1317. {
  1318. struct hpi_hw_obj *phw = pao->priv;
  1319. __iomem u32 *p_data;
  1320. /* u32 dwVerifyData=0; */
  1321. if (dsp_index == 0) {
  1322. /* DSP 0 is always C6205 */
  1323. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1324. /* BAR1 - DSP register access using */
  1325. /* Non-prefetchable PCI access */
  1326. p_data = pao->pci.ap_mem_base[1] +
  1327. (address & 0x007fffff) /
  1328. sizeof(*pao->pci.ap_mem_base[1]);
  1329. } else {
  1330. /* BAR0 access - all of DSP memory using */
  1331. /* pre-fetchable PCI access */
  1332. u32 dw4M_page = address >> 22L;
  1333. if (dw4M_page != phw->dsp_page) {
  1334. phw->dsp_page = dw4M_page;
  1335. /* *INDENT-OFF* */
  1336. iowrite32(phw->dsp_page, phw->prDSPP);
  1337. /* *INDENT-ON* */
  1338. }
  1339. address &= 0x3fffff; /* address within 4M page */
  1340. p_data = pao->pci.ap_mem_base[0] +
  1341. address / sizeof(u32);
  1342. }
  1343. iowrite32(data, p_data);
  1344. } else if (dsp_index == 1) {
  1345. /* DSP 1 is a C6713 */
  1346. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1347. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1348. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1349. boot_loader_read_mem32(pao, 0, 0);
  1350. boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
  1351. boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
  1352. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1353. boot_loader_read_mem32(pao, 0, 0);
  1354. }
  1355. }
  1356. static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
  1357. {
  1358. if (dsp_index == 0) {
  1359. u32 setting;
  1360. /* DSP 0 is always C6205 */
  1361. /* Set the EMIF */
  1362. /* memory map of C6205 */
  1363. /* 00000000-0000FFFF 16Kx32 internal program */
  1364. /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
  1365. /* EMIF config */
  1366. /*------------ */
  1367. /* Global EMIF control */
  1368. boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
  1369. #define WS_OFS 28
  1370. #define WST_OFS 22
  1371. #define WH_OFS 20
  1372. #define RS_OFS 16
  1373. #define RST_OFS 8
  1374. #define MTYPE_OFS 4
  1375. #define RH_OFS 0
  1376. /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
  1377. setting = 0x00000030;
  1378. boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
  1379. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1380. 0x01800008))
  1381. return HPI6205_ERROR_DSP_EMIF1;
  1382. /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
  1383. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1384. /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
  1385. /* WST should be 71, but 63 is max possible */
  1386. setting =
  1387. (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
  1388. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1389. (2L << MTYPE_OFS);
  1390. boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
  1391. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1392. 0x01800004))
  1393. return HPI6205_ERROR_DSP_EMIF2;
  1394. /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
  1395. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1396. /* plenty of wait states */
  1397. setting =
  1398. (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
  1399. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1400. (2L << MTYPE_OFS);
  1401. boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
  1402. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1403. 0x01800010))
  1404. return HPI6205_ERROR_DSP_EMIF3;
  1405. /* EMIF CE3 setup - 32 bit async. */
  1406. /* This is the PLD on the ASI5000 cards only */
  1407. setting =
  1408. (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
  1409. (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
  1410. (2L << MTYPE_OFS);
  1411. boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
  1412. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1413. 0x01800014))
  1414. return HPI6205_ERROR_DSP_EMIF4;
  1415. /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
  1416. /* need to use this else DSP code crashes? */
  1417. boot_loader_write_mem32(pao, dsp_index, 0x01800018,
  1418. 0x07117000);
  1419. /* EMIF SDRAM Refresh Timing */
  1420. /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
  1421. boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
  1422. 0x00000410);
  1423. } else if (dsp_index == 1) {
  1424. /* test access to the C6713s HPI registers */
  1425. u32 write_data = 0, read_data = 0, i = 0;
  1426. /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
  1427. write_data = 1;
  1428. boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
  1429. boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
  1430. /* C67 HPI is on lower 16bits of 32bit EMIF */
  1431. read_data =
  1432. 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
  1433. if (write_data != read_data) {
  1434. HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
  1435. read_data);
  1436. return HPI6205_ERROR_C6713_HPIC;
  1437. }
  1438. /* HPIA - walking ones test */
  1439. write_data = 1;
  1440. for (i = 0; i < 32; i++) {
  1441. boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
  1442. write_data);
  1443. boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
  1444. (write_data >> 16));
  1445. read_data =
  1446. 0xFFFF & boot_loader_read_mem32(pao, 0,
  1447. HPIAL_ADDR);
  1448. read_data =
  1449. read_data | ((0xFFFF &
  1450. boot_loader_read_mem32(pao, 0,
  1451. HPIAH_ADDR))
  1452. << 16);
  1453. if (read_data != write_data) {
  1454. HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
  1455. write_data, read_data);
  1456. return HPI6205_ERROR_C6713_HPIA;
  1457. }
  1458. write_data = write_data << 1;
  1459. }
  1460. /* setup C67x PLL
  1461. * ** C6713 datasheet says we cannot program PLL from HPI,
  1462. * and indeed if we try to set the PLL multiply from the HPI,
  1463. * the PLL does not seem to lock, so we enable the PLL and
  1464. * use the default multiply of x 7, which for a 27MHz clock
  1465. * gives a DSP speed of 189MHz
  1466. */
  1467. /* bypass PLL */
  1468. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
  1469. hpios_delay_micro_seconds(1000);
  1470. /* EMIF = 189/3=63MHz */
  1471. boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
  1472. /* peri = 189/2 */
  1473. boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
  1474. /* cpu = 189/1 */
  1475. boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
  1476. hpios_delay_micro_seconds(1000);
  1477. /* ** SGT test to take GPO3 high when we start the PLL */
  1478. /* and low when the delay is completed */
  1479. /* FSX0 <- '1' (GPO3) */
  1480. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
  1481. /* PLL not bypassed */
  1482. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
  1483. hpios_delay_micro_seconds(1000);
  1484. /* FSX0 <- '0' (GPO3) */
  1485. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
  1486. /* 6205 EMIF CE1 resetup - 32 bit async. */
  1487. /* Now 6713 #1 is running at 189MHz can reduce waitstates */
  1488. boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
  1489. (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
  1490. (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
  1491. (2L << MTYPE_OFS));
  1492. hpios_delay_micro_seconds(1000);
  1493. /* check that we can read one of the PLL registers */
  1494. /* PLL should not be bypassed! */
  1495. if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
  1496. != 0x0001) {
  1497. return HPI6205_ERROR_C6713_PLL;
  1498. }
  1499. /* setup C67x EMIF (note this is the only use of
  1500. BAR1 via BootLoader_WriteMem32) */
  1501. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
  1502. 0x000034A8);
  1503. /* EMIF CE0 setup - 2Mx32 Sync DRAM
  1504. 31..28 Wr setup
  1505. 27..22 Wr strobe
  1506. 21..20 Wr hold
  1507. 19..16 Rd setup
  1508. 15..14 -
  1509. 13..8 Rd strobe
  1510. 7..4 MTYPE 0011 Sync DRAM 32bits
  1511. 3 Wr hold MSB
  1512. 2..0 Rd hold
  1513. */
  1514. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
  1515. 0x00000030);
  1516. /* EMIF SDRAM Extension
  1517. 0x00
  1518. 31-21 0000b 0000b 000b
  1519. 20 WR2RD = 2cycles-1 = 1b
  1520. 19-18 WR2DEAC = 3cycle-1 = 10b
  1521. 17 WR2WR = 2cycle-1 = 1b
  1522. 16-15 R2WDQM = 4cycle-1 = 11b
  1523. 14-12 RD2WR = 6cycles-1 = 101b
  1524. 11-10 RD2DEAC = 4cycle-1 = 11b
  1525. 9 RD2RD = 2cycle-1 = 1b
  1526. 8-7 THZP = 3cycle-1 = 10b
  1527. 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
  1528. 4 TRRD = 2cycle = 0b (tRRD = 14ns)
  1529. 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
  1530. 1 CAS latency = 3cyc = 1b
  1531. (for Micron 2M32-7 operating at 100MHz)
  1532. */
  1533. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
  1534. 0x001BDF29);
  1535. /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
  1536. 31 - 0b -
  1537. 30 SDBSZ 1b 4 bank
  1538. 29..28 SDRSZ 00b 11 row address pins
  1539. 27..26 SDCSZ 01b 8 column address pins
  1540. 25 RFEN 1b refersh enabled
  1541. 24 INIT 1b init SDRAM!
  1542. 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
  1543. 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
  1544. 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
  1545. 11..0 - 0000b 0000b 0000b
  1546. */
  1547. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
  1548. 0x47116000);
  1549. /* SDRAM refresh timing
  1550. Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
  1551. */
  1552. boot_loader_write_mem32(pao, dsp_index,
  1553. C6713_EMIF_SDRAMTIMING, 0x00000410);
  1554. hpios_delay_micro_seconds(1000);
  1555. } else if (dsp_index == 2) {
  1556. /* DSP 2 is a C6713 */
  1557. }
  1558. return 0;
  1559. }
  1560. static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
  1561. u32 start_address, u32 length)
  1562. {
  1563. u32 i = 0, j = 0;
  1564. u32 test_addr = 0;
  1565. u32 test_data = 0, data = 0;
  1566. length = 1000;
  1567. /* for 1st word, test each bit in the 32bit word, */
  1568. /* dwLength specifies number of 32bit words to test */
  1569. /*for(i=0; i<dwLength; i++) */
  1570. i = 0;
  1571. {
  1572. test_addr = start_address + i * 4;
  1573. test_data = 0x00000001;
  1574. for (j = 0; j < 32; j++) {
  1575. boot_loader_write_mem32(pao, dsp_index, test_addr,
  1576. test_data);
  1577. data = boot_loader_read_mem32(pao, dsp_index,
  1578. test_addr);
  1579. if (data != test_data) {
  1580. HPI_DEBUG_LOG(VERBOSE,
  1581. "Memtest error details "
  1582. "%08x %08x %08x %i\n", test_addr,
  1583. test_data, data, dsp_index);
  1584. return 1; /* error */
  1585. }
  1586. test_data = test_data << 1;
  1587. } /* for(j) */
  1588. } /* for(i) */
  1589. /* for the next 100 locations test each location, leaving it as zero */
  1590. /* write a zero to the next word in memory before we read */
  1591. /* the previous write to make sure every memory location is unique */
  1592. for (i = 0; i < 100; i++) {
  1593. test_addr = start_address + i * 4;
  1594. test_data = 0xA5A55A5A;
  1595. boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
  1596. boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
  1597. data = boot_loader_read_mem32(pao, dsp_index, test_addr);
  1598. if (data != test_data) {
  1599. HPI_DEBUG_LOG(VERBOSE,
  1600. "Memtest error details "
  1601. "%08x %08x %08x %i\n", test_addr, test_data,
  1602. data, dsp_index);
  1603. return 1; /* error */
  1604. }
  1605. /* leave location as zero */
  1606. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1607. }
  1608. /* zero out entire memory block */
  1609. for (i = 0; i < length; i++) {
  1610. test_addr = start_address + i * 4;
  1611. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1612. }
  1613. return 0;
  1614. }
  1615. static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
  1616. int dsp_index)
  1617. {
  1618. int err = 0;
  1619. if (dsp_index == 0) {
  1620. /* DSP 0 is a C6205 */
  1621. /* 64K prog mem */
  1622. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1623. 0x10000);
  1624. if (!err)
  1625. /* 64K data mem */
  1626. err = boot_loader_test_memory(pao, dsp_index,
  1627. 0x80000000, 0x10000);
  1628. } else if (dsp_index == 1) {
  1629. /* DSP 1 is a C6713 */
  1630. /* 192K internal mem */
  1631. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1632. 0x30000);
  1633. if (!err)
  1634. /* 64K internal mem / L2 cache */
  1635. err = boot_loader_test_memory(pao, dsp_index,
  1636. 0x00030000, 0x10000);
  1637. }
  1638. if (err)
  1639. return HPI6205_ERROR_DSP_INTMEM;
  1640. else
  1641. return 0;
  1642. }
  1643. static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
  1644. int dsp_index)
  1645. {
  1646. u32 dRAM_start_address = 0;
  1647. u32 dRAM_size = 0;
  1648. if (dsp_index == 0) {
  1649. /* only test for SDRAM if an ASI5000 card */
  1650. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1651. /* DSP 0 is always C6205 */
  1652. dRAM_start_address = 0x00400000;
  1653. dRAM_size = 0x200000;
  1654. /*dwDRAMinc=1024; */
  1655. } else
  1656. return 0;
  1657. } else if (dsp_index == 1) {
  1658. /* DSP 1 is a C6713 */
  1659. dRAM_start_address = 0x80000000;
  1660. dRAM_size = 0x200000;
  1661. /*dwDRAMinc=1024; */
  1662. }
  1663. if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
  1664. dRAM_size))
  1665. return HPI6205_ERROR_DSP_EXTMEM;
  1666. return 0;
  1667. }
  1668. static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
  1669. {
  1670. u32 data = 0;
  1671. if (dsp_index == 0) {
  1672. /* only test for DSP0 PLD on ASI5000 card */
  1673. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1674. /* PLD is located at CE3=0x03000000 */
  1675. data = boot_loader_read_mem32(pao, dsp_index,
  1676. 0x03000008);
  1677. if ((data & 0xF) != 0x5)
  1678. return HPI6205_ERROR_DSP_PLD;
  1679. data = boot_loader_read_mem32(pao, dsp_index,
  1680. 0x0300000C);
  1681. if ((data & 0xF) != 0xA)
  1682. return HPI6205_ERROR_DSP_PLD;
  1683. }
  1684. } else if (dsp_index == 1) {
  1685. /* DSP 1 is a C6713 */
  1686. if (pao->pci.pci_dev->subsystem_device == 0x8700) {
  1687. /* PLD is located at CE1=0x90000000 */
  1688. data = boot_loader_read_mem32(pao, dsp_index,
  1689. 0x90000010);
  1690. if ((data & 0xFF) != 0xAA)
  1691. return HPI6205_ERROR_DSP_PLD;
  1692. /* 8713 - LED on */
  1693. boot_loader_write_mem32(pao, dsp_index, 0x90000000,
  1694. 0x02);
  1695. }
  1696. }
  1697. return 0;
  1698. }
  1699. /** Transfer data to or from DSP
  1700. nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
  1701. */
  1702. static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
  1703. u32 data_size, int operation)
  1704. {
  1705. struct hpi_hw_obj *phw = pao->priv;
  1706. u32 data_transferred = 0;
  1707. u16 err = 0;
  1708. u32 temp2;
  1709. struct bus_master_interface *interface = phw->p_interface_buffer;
  1710. if (!p_data)
  1711. return HPI_ERROR_INVALID_DATA_POINTER;
  1712. data_size &= ~3L; /* round data_size down to nearest 4 bytes */
  1713. /* make sure state is IDLE */
  1714. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
  1715. return HPI_ERROR_DSP_HARDWARE;
  1716. while (data_transferred < data_size) {
  1717. u32 this_copy = data_size - data_transferred;
  1718. if (this_copy > HPI6205_SIZEOF_DATA)
  1719. this_copy = HPI6205_SIZEOF_DATA;
  1720. if (operation == H620_HIF_SEND_DATA)
  1721. memcpy((void *)&interface->u.b_data[0],
  1722. &p_data[data_transferred], this_copy);
  1723. interface->transfer_size_in_bytes = this_copy;
  1724. /* DSP must change this back to nOperation */
  1725. interface->dsp_ack = H620_HIF_IDLE;
  1726. send_dsp_command(phw, operation);
  1727. temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
  1728. HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
  1729. HPI6205_TIMEOUT - temp2, this_copy);
  1730. if (!temp2) {
  1731. /* timed out */
  1732. HPI_DEBUG_LOG(ERROR,
  1733. "Timed out waiting for " "state %d got %d\n",
  1734. operation, interface->dsp_ack);
  1735. break;
  1736. }
  1737. if (operation == H620_HIF_GET_DATA)
  1738. memcpy(&p_data[data_transferred],
  1739. (void *)&interface->u.b_data[0], this_copy);
  1740. data_transferred += this_copy;
  1741. }
  1742. if (interface->dsp_ack != operation)
  1743. HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
  1744. interface->dsp_ack, operation);
  1745. /* err=HPI_ERROR_DSP_HARDWARE; */
  1746. send_dsp_command(phw, H620_HIF_IDLE);
  1747. return err;
  1748. }
  1749. /* wait for up to timeout_us microseconds for the DSP
  1750. to signal state by DMA into dwDspAck
  1751. */
  1752. static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
  1753. {
  1754. struct bus_master_interface *interface = phw->p_interface_buffer;
  1755. int t = timeout_us / 4;
  1756. rmb(); /* ensure interface->dsp_ack is up to date */
  1757. while ((interface->dsp_ack != state) && --t) {
  1758. hpios_delay_micro_seconds(4);
  1759. rmb(); /* DSP changes dsp_ack by DMA */
  1760. }
  1761. /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
  1762. return t * 4;
  1763. }
  1764. /* set the busmaster interface to cmd, then interrupt the DSP */
  1765. static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
  1766. {
  1767. struct bus_master_interface *interface = phw->p_interface_buffer;
  1768. u32 r;
  1769. interface->host_cmd = cmd;
  1770. wmb(); /* DSP gets state by DMA, make sure it is written to memory */
  1771. /* before we interrupt the DSP */
  1772. r = ioread32(phw->prHDCR);
  1773. r |= (u32)C6205_HDCR_DSPINT;
  1774. iowrite32(r, phw->prHDCR);
  1775. r &= ~(u32)C6205_HDCR_DSPINT;
  1776. iowrite32(r, phw->prHDCR);
  1777. }
  1778. static unsigned int message_count;
  1779. static u16 message_response_sequence(struct hpi_adapter_obj *pao,
  1780. struct hpi_message *phm, struct hpi_response *phr)
  1781. {
  1782. u32 time_out, time_out2;
  1783. struct hpi_hw_obj *phw = pao->priv;
  1784. struct bus_master_interface *interface = phw->p_interface_buffer;
  1785. u16 err = 0;
  1786. message_count++;
  1787. if (phm->size > sizeof(interface->u.message_buffer)) {
  1788. phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
  1789. phr->specific_error = sizeof(interface->u.message_buffer);
  1790. phr->size = sizeof(struct hpi_response_header);
  1791. HPI_DEBUG_LOG(ERROR,
  1792. "message len %d too big for buffer %zd \n", phm->size,
  1793. sizeof(interface->u.message_buffer));
  1794. return 0;
  1795. }
  1796. /* Assume buffer of type struct bus_master_interface
  1797. is allocated "noncacheable" */
  1798. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1799. HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
  1800. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1801. }
  1802. memcpy(&interface->u.message_buffer, phm, phm->size);
  1803. /* signal we want a response */
  1804. send_dsp_command(phw, H620_HIF_GET_RESP);
  1805. time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
  1806. if (!time_out2) {
  1807. HPI_DEBUG_LOG(ERROR,
  1808. "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
  1809. message_count, interface->dsp_ack);
  1810. } else {
  1811. HPI_DEBUG_LOG(VERBOSE,
  1812. "(%u) transition to GET_RESP after %u\n",
  1813. message_count, HPI6205_TIMEOUT - time_out2);
  1814. }
  1815. /* spin waiting on HIF interrupt flag (end of msg process) */
  1816. time_out = HPI6205_TIMEOUT;
  1817. /* read the result */
  1818. if (time_out) {
  1819. if (interface->u.response_buffer.response.size <= phr->size)
  1820. memcpy(phr, &interface->u.response_buffer,
  1821. interface->u.response_buffer.response.size);
  1822. else {
  1823. HPI_DEBUG_LOG(ERROR,
  1824. "response len %d too big for buffer %d\n",
  1825. interface->u.response_buffer.response.size,
  1826. phr->size);
  1827. memcpy(phr, &interface->u.response_buffer,
  1828. sizeof(struct hpi_response_header));
  1829. phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1830. phr->specific_error =
  1831. interface->u.response_buffer.response.size;
  1832. phr->size = sizeof(struct hpi_response_header);
  1833. }
  1834. }
  1835. /* set interface back to idle */
  1836. send_dsp_command(phw, H620_HIF_IDLE);
  1837. if (!time_out || !time_out2) {
  1838. HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
  1839. return HPI6205_ERROR_MSG_RESP_TIMEOUT;
  1840. }
  1841. /* special case for adapter close - */
  1842. /* wait for the DSP to indicate it is idle */
  1843. if (phm->function == HPI_ADAPTER_CLOSE) {
  1844. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1845. HPI_DEBUG_LOG(DEBUG,
  1846. "Timeout waiting for idle "
  1847. "(on adapter_close)\n");
  1848. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1849. }
  1850. }
  1851. err = hpi_validate_response(phm, phr);
  1852. return err;
  1853. }
  1854. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1855. struct hpi_response *phr)
  1856. {
  1857. u16 err = 0;
  1858. hpios_dsplock_lock(pao);
  1859. err = message_response_sequence(pao, phm, phr);
  1860. /* maybe an error response */
  1861. if (err) {
  1862. /* something failed in the HPI/DSP interface */
  1863. if (err >= HPI_ERROR_BACKEND_BASE) {
  1864. phr->error = HPI_ERROR_DSP_COMMUNICATION;
  1865. phr->specific_error = err;
  1866. } else {
  1867. phr->error = err;
  1868. }
  1869. pao->dsp_crashed++;
  1870. /* just the header of the response is valid */
  1871. phr->size = sizeof(struct hpi_response_header);
  1872. goto err;
  1873. } else
  1874. pao->dsp_crashed = 0;
  1875. if (phr->error != 0) /* something failed in the DSP */
  1876. goto err;
  1877. switch (phm->function) {
  1878. case HPI_OSTREAM_WRITE:
  1879. case HPI_ISTREAM_ANC_WRITE:
  1880. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1881. phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
  1882. break;
  1883. case HPI_ISTREAM_READ:
  1884. case HPI_OSTREAM_ANC_READ:
  1885. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1886. phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
  1887. break;
  1888. }
  1889. phr->error = err;
  1890. err:
  1891. hpios_dsplock_unlock(pao);
  1892. return;
  1893. }