hpi6205.c 64 KB

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