hpi6205.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205
  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_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. static
  311. void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  312. struct hpi_response *phr)
  313. {
  314. if (pao && (pao->dsp_crashed >= 10)
  315. && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
  316. /* allow last resort debug read even after crash */
  317. hpi_init_response(phr, phm->object, phm->function,
  318. HPI_ERROR_DSP_HARDWARE);
  319. HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object,
  320. phm->function);
  321. return;
  322. }
  323. /* Init default response */
  324. if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
  325. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  326. HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
  327. switch (phm->type) {
  328. case HPI_TYPE_REQUEST:
  329. switch (phm->object) {
  330. case HPI_OBJ_SUBSYSTEM:
  331. subsys_message(pao, phm, phr);
  332. break;
  333. case HPI_OBJ_ADAPTER:
  334. adapter_message(pao, phm, phr);
  335. break;
  336. case HPI_OBJ_CONTROL:
  337. control_message(pao, phm, phr);
  338. break;
  339. case HPI_OBJ_OSTREAM:
  340. outstream_message(pao, phm, phr);
  341. break;
  342. case HPI_OBJ_ISTREAM:
  343. instream_message(pao, phm, phr);
  344. break;
  345. default:
  346. hw_message(pao, phm, phr);
  347. break;
  348. }
  349. break;
  350. default:
  351. phr->error = HPI_ERROR_INVALID_TYPE;
  352. break;
  353. }
  354. }
  355. void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
  356. {
  357. struct hpi_adapter_obj *pao = NULL;
  358. if (phm->object != HPI_OBJ_SUBSYSTEM) {
  359. /* normal messages must have valid adapter index */
  360. pao = hpi_find_adapter(phm->adapter_index);
  361. } else {
  362. /* subsys messages don't address an adapter */
  363. _HPI_6205(NULL, phm, phr);
  364. return;
  365. }
  366. if (pao)
  367. _HPI_6205(pao, phm, phr);
  368. else
  369. hpi_init_response(phr, phm->object, phm->function,
  370. HPI_ERROR_BAD_ADAPTER_NUMBER);
  371. }
  372. /*****************************************************************************/
  373. /* SUBSYSTEM */
  374. /** Create an adapter object and initialise it based on resource information
  375. * passed in in the message
  376. * *** NOTE - you cannot use this function AND the FindAdapters function at the
  377. * same time, the application must use only one of them to get the adapters ***
  378. */
  379. static void subsys_create_adapter(struct hpi_message *phm,
  380. struct hpi_response *phr)
  381. {
  382. /* create temp adapter obj, because we don't know what index yet */
  383. struct hpi_adapter_obj ao;
  384. u32 os_error_code;
  385. u16 err;
  386. HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
  387. memset(&ao, 0, sizeof(ao));
  388. ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
  389. if (!ao.priv) {
  390. HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
  391. phr->error = HPI_ERROR_MEMORY_ALLOC;
  392. return;
  393. }
  394. ao.pci = *phm->u.s.resource.r.pci;
  395. err = create_adapter_obj(&ao, &os_error_code);
  396. if (err) {
  397. delete_adapter_obj(&ao);
  398. if (err >= HPI_ERROR_BACKEND_BASE) {
  399. phr->error = HPI_ERROR_DSP_BOOTLOAD;
  400. phr->specific_error = err;
  401. } else {
  402. phr->error = err;
  403. }
  404. phr->u.s.data = os_error_code;
  405. return;
  406. }
  407. phr->u.s.adapter_type = ao.type;
  408. phr->u.s.adapter_index = ao.index;
  409. phr->error = 0;
  410. }
  411. /** delete an adapter - required by WDM driver */
  412. static void adapter_delete(struct hpi_adapter_obj *pao,
  413. struct hpi_message *phm, struct hpi_response *phr)
  414. {
  415. struct hpi_hw_obj *phw;
  416. if (!pao) {
  417. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  418. return;
  419. }
  420. phw = pao->priv;
  421. /* reset adapter h/w */
  422. /* Reset C6713 #1 */
  423. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  424. /* reset C6205 */
  425. iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
  426. delete_adapter_obj(pao);
  427. hpi_delete_adapter(pao);
  428. phr->error = 0;
  429. }
  430. /** Create adapter object
  431. allocate buffers, bootload DSPs, initialise control cache
  432. */
  433. static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
  434. u32 *pos_error_code)
  435. {
  436. struct hpi_hw_obj *phw = pao->priv;
  437. struct bus_master_interface *interface;
  438. u32 phys_addr;
  439. int i;
  440. u16 err;
  441. /* init error reporting */
  442. pao->dsp_crashed = 0;
  443. for (i = 0; i < HPI_MAX_STREAMS; i++)
  444. phw->flag_outstream_just_reset[i] = 1;
  445. /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
  446. phw->prHSR =
  447. pao->pci.ap_mem_base[1] +
  448. C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
  449. phw->prHDCR =
  450. pao->pci.ap_mem_base[1] +
  451. C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
  452. phw->prDSPP =
  453. pao->pci.ap_mem_base[1] +
  454. C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
  455. pao->has_control_cache = 0;
  456. if (hpios_locked_mem_alloc(&phw->h_locked_mem,
  457. sizeof(struct bus_master_interface),
  458. pao->pci.pci_dev))
  459. phw->p_interface_buffer = NULL;
  460. else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
  461. (void *)&phw->p_interface_buffer))
  462. phw->p_interface_buffer = NULL;
  463. HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
  464. phw->p_interface_buffer);
  465. if (phw->p_interface_buffer) {
  466. memset((void *)phw->p_interface_buffer, 0,
  467. sizeof(struct bus_master_interface));
  468. phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
  469. }
  470. err = adapter_boot_load_dsp(pao, pos_error_code);
  471. if (err) {
  472. HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");
  473. /* no need to clean up as SubSysCreateAdapter */
  474. /* calls DeleteAdapter on error. */
  475. return err;
  476. }
  477. HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
  478. /* allow boot load even if mem alloc wont work */
  479. if (!phw->p_interface_buffer)
  480. return HPI_ERROR_MEMORY_ALLOC;
  481. interface = phw->p_interface_buffer;
  482. /* make sure the DSP has started ok */
  483. if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
  484. HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
  485. return HPI6205_ERROR_6205_INIT_FAILED;
  486. }
  487. /* Note that *pao, *phw are zeroed after allocation,
  488. * so pointers and flags are NULL by default.
  489. * Allocate bus mastering control cache buffer and tell the DSP about it
  490. */
  491. if (interface->control_cache.number_of_controls) {
  492. u8 *p_control_cache_virtual;
  493. err = hpios_locked_mem_alloc(&phw->h_control_cache,
  494. interface->control_cache.size_in_bytes,
  495. pao->pci.pci_dev);
  496. if (!err)
  497. err = hpios_locked_mem_get_virt_addr(&phw->
  498. h_control_cache,
  499. (void *)&p_control_cache_virtual);
  500. if (!err) {
  501. memset(p_control_cache_virtual, 0,
  502. interface->control_cache.size_in_bytes);
  503. phw->p_cache =
  504. hpi_alloc_control_cache(interface->
  505. control_cache.number_of_controls,
  506. interface->control_cache.size_in_bytes,
  507. p_control_cache_virtual);
  508. if (!phw->p_cache)
  509. err = HPI_ERROR_MEMORY_ALLOC;
  510. }
  511. if (!err) {
  512. err = hpios_locked_mem_get_phys_addr(&phw->
  513. h_control_cache, &phys_addr);
  514. interface->control_cache.physical_address32 =
  515. phys_addr;
  516. }
  517. if (!err)
  518. pao->has_control_cache = 1;
  519. else {
  520. if (hpios_locked_mem_valid(&phw->h_control_cache))
  521. hpios_locked_mem_free(&phw->h_control_cache);
  522. pao->has_control_cache = 0;
  523. }
  524. }
  525. send_dsp_command(phw, H620_HIF_IDLE);
  526. {
  527. struct hpi_message hm;
  528. struct hpi_response hr;
  529. u32 max_streams;
  530. HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
  531. memset(&hm, 0, sizeof(hm));
  532. /* wAdapterIndex == version == 0 */
  533. hm.type = HPI_TYPE_REQUEST;
  534. hm.size = sizeof(hm);
  535. hm.object = HPI_OBJ_ADAPTER;
  536. hm.function = HPI_ADAPTER_GET_INFO;
  537. memset(&hr, 0, sizeof(hr));
  538. hr.size = sizeof(hr);
  539. err = message_response_sequence(pao, &hm, &hr);
  540. if (err) {
  541. HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
  542. err);
  543. return err;
  544. }
  545. if (hr.error)
  546. return hr.error;
  547. pao->type = hr.u.ax.info.adapter_type;
  548. pao->index = hr.u.ax.info.adapter_index;
  549. max_streams =
  550. hr.u.ax.info.num_outstreams +
  551. hr.u.ax.info.num_instreams;
  552. HPI_DEBUG_LOG(VERBOSE,
  553. "got adapter info type %x index %d serial %d\n",
  554. hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
  555. hr.u.ax.info.serial_number);
  556. }
  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. }