hpi6205.c 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229
  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_MESSAGE:
  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_CONTROLEX:
  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.adapter_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 = (struct hpi_hw_obj *)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. hm.type = HPI_TYPE_MESSAGE;
  533. hm.size = sizeof(hm);
  534. hm.object = HPI_OBJ_ADAPTER;
  535. hm.function = HPI_ADAPTER_GET_INFO;
  536. hm.adapter_index = 0;
  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->adapter_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. hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams,
  553. 65536, pao->pci.pci_dev);
  554. HPI_DEBUG_LOG(VERBOSE,
  555. "got adapter info type %x index %d serial %d\n",
  556. hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
  557. hr.u.ax.info.serial_number);
  558. }
  559. pao->open = 0; /* upon creation the adapter is closed */
  560. if (phw->p_cache)
  561. phw->p_cache->adap_idx = pao->index;
  562. HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
  563. return hpi_add_adapter(pao);
  564. }
  565. /** Free memory areas allocated by adapter
  566. * this routine is called from AdapterDelete,
  567. * and SubSysCreateAdapter if duplicate index
  568. */
  569. static void delete_adapter_obj(struct hpi_adapter_obj *pao)
  570. {
  571. struct hpi_hw_obj *phw = pao->priv;
  572. int i;
  573. if (hpios_locked_mem_valid(&phw->h_control_cache)) {
  574. hpios_locked_mem_free(&phw->h_control_cache);
  575. hpi_free_control_cache(phw->p_cache);
  576. }
  577. if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
  578. hpios_locked_mem_free(&phw->h_locked_mem);
  579. phw->p_interface_buffer = NULL;
  580. }
  581. for (i = 0; i < HPI_MAX_STREAMS; i++)
  582. if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
  583. hpios_locked_mem_free(&phw->instream_host_buffers[i]);
  584. /*?phw->InStreamHostBuffers[i] = NULL; */
  585. phw->instream_host_buffer_size[i] = 0;
  586. }
  587. for (i = 0; i < HPI_MAX_STREAMS; i++)
  588. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
  589. hpios_locked_mem_free(&phw->outstream_host_buffers
  590. [i]);
  591. phw->outstream_host_buffer_size[i] = 0;
  592. }
  593. hpios_locked_mem_unprepare(pao->pci.pci_dev);
  594. kfree(phw);
  595. }
  596. /*****************************************************************************/
  597. /* Adapter functions */
  598. /*****************************************************************************/
  599. /* OutStream Host buffer functions */
  600. /** Allocate or attach buffer for busmastering
  601. */
  602. static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  603. struct hpi_message *phm, struct hpi_response *phr)
  604. {
  605. u16 err = 0;
  606. u32 command = phm->u.d.u.buffer.command;
  607. struct hpi_hw_obj *phw = pao->priv;
  608. struct bus_master_interface *interface = phw->p_interface_buffer;
  609. hpi_init_response(phr, phm->object, phm->function, 0);
  610. if (command == HPI_BUFFER_CMD_EXTERNAL
  611. || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
  612. /* ALLOC phase, allocate a buffer with power of 2 size,
  613. get its bus address for PCI bus mastering
  614. */
  615. phm->u.d.u.buffer.buffer_size =
  616. roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
  617. /* return old size and allocated size,
  618. so caller can detect change */
  619. phr->u.d.u.stream_info.data_available =
  620. phw->outstream_host_buffer_size[phm->obj_index];
  621. phr->u.d.u.stream_info.buffer_size =
  622. phm->u.d.u.buffer.buffer_size;
  623. if (phw->outstream_host_buffer_size[phm->obj_index] ==
  624. phm->u.d.u.buffer.buffer_size) {
  625. /* Same size, no action required */
  626. return;
  627. }
  628. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  629. obj_index]))
  630. hpios_locked_mem_free(&phw->outstream_host_buffers
  631. [phm->obj_index]);
  632. err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
  633. [phm->obj_index], phm->u.d.u.buffer.buffer_size,
  634. pao->pci.pci_dev);
  635. if (err) {
  636. phr->error = HPI_ERROR_INVALID_DATASIZE;
  637. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  638. return;
  639. }
  640. err = hpios_locked_mem_get_phys_addr
  641. (&phw->outstream_host_buffers[phm->obj_index],
  642. &phm->u.d.u.buffer.pci_address);
  643. /* get the phys addr into msg for single call alloc caller
  644. * needs to do this for split alloc (or use the same message)
  645. * return the phy address for split alloc in the respose too
  646. */
  647. phr->u.d.u.stream_info.auxiliary_data_available =
  648. phm->u.d.u.buffer.pci_address;
  649. if (err) {
  650. hpios_locked_mem_free(&phw->outstream_host_buffers
  651. [phm->obj_index]);
  652. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  653. phr->error = HPI_ERROR_MEMORY_ALLOC;
  654. return;
  655. }
  656. }
  657. if (command == HPI_BUFFER_CMD_EXTERNAL
  658. || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
  659. /* GRANT phase. Set up the BBM status, tell the DSP about
  660. the buffer so it can start using BBM.
  661. */
  662. struct hpi_hostbuffer_status *status;
  663. if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
  664. buffer_size - 1)) {
  665. HPI_DEBUG_LOG(ERROR,
  666. "Buffer size must be 2^N not %d\n",
  667. phm->u.d.u.buffer.buffer_size);
  668. phr->error = HPI_ERROR_INVALID_DATASIZE;
  669. return;
  670. }
  671. phw->outstream_host_buffer_size[phm->obj_index] =
  672. phm->u.d.u.buffer.buffer_size;
  673. status = &interface->outstream_host_buffer_status[phm->
  674. obj_index];
  675. status->samples_processed = 0;
  676. status->stream_state = HPI_STATE_STOPPED;
  677. status->dSP_index = 0;
  678. status->host_index = status->dSP_index;
  679. status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
  680. status->auxiliary_data_available = 0;
  681. hw_message(pao, phm, phr);
  682. if (phr->error
  683. && hpios_locked_mem_valid(&phw->
  684. outstream_host_buffers[phm->obj_index])) {
  685. hpios_locked_mem_free(&phw->outstream_host_buffers
  686. [phm->obj_index]);
  687. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  688. }
  689. }
  690. }
  691. static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  692. struct hpi_message *phm, struct hpi_response *phr)
  693. {
  694. struct hpi_hw_obj *phw = pao->priv;
  695. struct bus_master_interface *interface = phw->p_interface_buffer;
  696. struct hpi_hostbuffer_status *status;
  697. u8 *p_bbm_data;
  698. if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  699. obj_index])) {
  700. if (hpios_locked_mem_get_virt_addr(&phw->
  701. outstream_host_buffers[phm->obj_index],
  702. (void *)&p_bbm_data)) {
  703. phr->error = HPI_ERROR_INVALID_OPERATION;
  704. return;
  705. }
  706. status = &interface->outstream_host_buffer_status[phm->
  707. obj_index];
  708. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  709. HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
  710. phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
  711. phr->u.d.u.hostbuffer_info.p_status = status;
  712. } else {
  713. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  714. HPI_OSTREAM_HOSTBUFFER_GET_INFO,
  715. HPI_ERROR_INVALID_OPERATION);
  716. }
  717. }
  718. static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
  719. struct hpi_message *phm, struct hpi_response *phr)
  720. {
  721. struct hpi_hw_obj *phw = pao->priv;
  722. u32 command = phm->u.d.u.buffer.command;
  723. if (phw->outstream_host_buffer_size[phm->obj_index]) {
  724. if (command == HPI_BUFFER_CMD_EXTERNAL
  725. || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
  726. phw->outstream_host_buffer_size[phm->obj_index] = 0;
  727. hw_message(pao, phm, phr);
  728. /* Tell adapter to stop using the host buffer. */
  729. }
  730. if (command == HPI_BUFFER_CMD_EXTERNAL
  731. || command == HPI_BUFFER_CMD_INTERNAL_FREE)
  732. hpios_locked_mem_free(&phw->outstream_host_buffers
  733. [phm->obj_index]);
  734. }
  735. /* Should HPI_ERROR_INVALID_OPERATION be returned
  736. if no host buffer is allocated? */
  737. else
  738. hpi_init_response(phr, HPI_OBJ_OSTREAM,
  739. HPI_OSTREAM_HOSTBUFFER_FREE, 0);
  740. }
  741. static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)
  742. {
  743. return status->size_in_bytes - (status->host_index -
  744. status->dSP_index);
  745. }
  746. static void outstream_write(struct hpi_adapter_obj *pao,
  747. struct hpi_message *phm, struct hpi_response *phr)
  748. {
  749. struct hpi_hw_obj *phw = pao->priv;
  750. struct bus_master_interface *interface = phw->p_interface_buffer;
  751. struct hpi_hostbuffer_status *status;
  752. u32 space_available;
  753. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  754. /* there is no BBM buffer, write via message */
  755. hw_message(pao, phm, phr);
  756. return;
  757. }
  758. hpi_init_response(phr, phm->object, phm->function, 0);
  759. status = &interface->outstream_host_buffer_status[phm->obj_index];
  760. space_available = outstream_get_space_available(status);
  761. if (space_available < phm->u.d.u.data.data_size) {
  762. phr->error = HPI_ERROR_INVALID_DATASIZE;
  763. return;
  764. }
  765. /* HostBuffers is used to indicate host buffer is internally allocated.
  766. otherwise, assumed external, data written externally */
  767. if (phm->u.d.u.data.pb_data
  768. && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  769. obj_index])) {
  770. u8 *p_bbm_data;
  771. u32 l_first_write;
  772. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  773. if (hpios_locked_mem_get_virt_addr(&phw->
  774. outstream_host_buffers[phm->obj_index],
  775. (void *)&p_bbm_data)) {
  776. phr->error = HPI_ERROR_INVALID_OPERATION;
  777. return;
  778. }
  779. /* either all data,
  780. or enough to fit from current to end of BBM buffer */
  781. l_first_write =
  782. min(phm->u.d.u.data.data_size,
  783. status->size_in_bytes -
  784. (status->host_index & (status->size_in_bytes - 1)));
  785. memcpy(p_bbm_data +
  786. (status->host_index & (status->size_in_bytes - 1)),
  787. p_app_data, l_first_write);
  788. /* remaining data if any */
  789. memcpy(p_bbm_data, p_app_data + l_first_write,
  790. phm->u.d.u.data.data_size - l_first_write);
  791. }
  792. /*
  793. * This version relies on the DSP code triggering an OStream buffer
  794. * update immediately following a SET_FORMAT call. The host has
  795. * already written data into the BBM buffer, but the DSP won't know
  796. * about it until dwHostIndex is adjusted.
  797. */
  798. if (phw->flag_outstream_just_reset[phm->obj_index]) {
  799. /* Format can only change after reset. Must tell DSP. */
  800. u16 function = phm->function;
  801. phw->flag_outstream_just_reset[phm->obj_index] = 0;
  802. phm->function = HPI_OSTREAM_SET_FORMAT;
  803. hw_message(pao, phm, phr); /* send the format to the DSP */
  804. phm->function = function;
  805. if (phr->error)
  806. return;
  807. }
  808. status->host_index += phm->u.d.u.data.data_size;
  809. }
  810. static void outstream_get_info(struct hpi_adapter_obj *pao,
  811. struct hpi_message *phm, struct hpi_response *phr)
  812. {
  813. struct hpi_hw_obj *phw = pao->priv;
  814. struct bus_master_interface *interface = phw->p_interface_buffer;
  815. struct hpi_hostbuffer_status *status;
  816. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  817. hw_message(pao, phm, phr);
  818. return;
  819. }
  820. hpi_init_response(phr, phm->object, phm->function, 0);
  821. status = &interface->outstream_host_buffer_status[phm->obj_index];
  822. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  823. phr->u.d.u.stream_info.samples_transferred =
  824. status->samples_processed;
  825. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  826. phr->u.d.u.stream_info.data_available =
  827. status->size_in_bytes - outstream_get_space_available(status);
  828. phr->u.d.u.stream_info.auxiliary_data_available =
  829. status->auxiliary_data_available;
  830. }
  831. static void outstream_start(struct hpi_adapter_obj *pao,
  832. struct hpi_message *phm, struct hpi_response *phr)
  833. {
  834. hw_message(pao, phm, phr);
  835. }
  836. static void outstream_reset(struct hpi_adapter_obj *pao,
  837. struct hpi_message *phm, struct hpi_response *phr)
  838. {
  839. struct hpi_hw_obj *phw = pao->priv;
  840. phw->flag_outstream_just_reset[phm->obj_index] = 1;
  841. hw_message(pao, phm, phr);
  842. }
  843. static void outstream_open(struct hpi_adapter_obj *pao,
  844. struct hpi_message *phm, struct hpi_response *phr)
  845. {
  846. outstream_reset(pao, phm, phr);
  847. }
  848. /*****************************************************************************/
  849. /* InStream Host buffer functions */
  850. static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  851. struct hpi_message *phm, struct hpi_response *phr)
  852. {
  853. u16 err = 0;
  854. u32 command = phm->u.d.u.buffer.command;
  855. struct hpi_hw_obj *phw = pao->priv;
  856. struct bus_master_interface *interface = phw->p_interface_buffer;
  857. hpi_init_response(phr, phm->object, phm->function, 0);
  858. if (command == HPI_BUFFER_CMD_EXTERNAL
  859. || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
  860. phm->u.d.u.buffer.buffer_size =
  861. roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
  862. phr->u.d.u.stream_info.data_available =
  863. phw->instream_host_buffer_size[phm->obj_index];
  864. phr->u.d.u.stream_info.buffer_size =
  865. phm->u.d.u.buffer.buffer_size;
  866. if (phw->instream_host_buffer_size[phm->obj_index] ==
  867. phm->u.d.u.buffer.buffer_size) {
  868. /* Same size, no action required */
  869. return;
  870. }
  871. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  872. obj_index]))
  873. hpios_locked_mem_free(&phw->instream_host_buffers
  874. [phm->obj_index]);
  875. err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
  876. obj_index], phm->u.d.u.buffer.buffer_size,
  877. pao->pci.pci_dev);
  878. if (err) {
  879. phr->error = HPI_ERROR_INVALID_DATASIZE;
  880. phw->instream_host_buffer_size[phm->obj_index] = 0;
  881. return;
  882. }
  883. err = hpios_locked_mem_get_phys_addr
  884. (&phw->instream_host_buffers[phm->obj_index],
  885. &phm->u.d.u.buffer.pci_address);
  886. /* get the phys addr into msg for single call alloc. Caller
  887. needs to do this for split alloc so return the phy address */
  888. phr->u.d.u.stream_info.auxiliary_data_available =
  889. phm->u.d.u.buffer.pci_address;
  890. if (err) {
  891. hpios_locked_mem_free(&phw->instream_host_buffers
  892. [phm->obj_index]);
  893. phw->instream_host_buffer_size[phm->obj_index] = 0;
  894. phr->error = HPI_ERROR_MEMORY_ALLOC;
  895. return;
  896. }
  897. }
  898. if (command == HPI_BUFFER_CMD_EXTERNAL
  899. || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
  900. struct hpi_hostbuffer_status *status;
  901. if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
  902. buffer_size - 1)) {
  903. HPI_DEBUG_LOG(ERROR,
  904. "Buffer size must be 2^N not %d\n",
  905. phm->u.d.u.buffer.buffer_size);
  906. phr->error = HPI_ERROR_INVALID_DATASIZE;
  907. return;
  908. }
  909. phw->instream_host_buffer_size[phm->obj_index] =
  910. phm->u.d.u.buffer.buffer_size;
  911. status = &interface->instream_host_buffer_status[phm->
  912. obj_index];
  913. status->samples_processed = 0;
  914. status->stream_state = HPI_STATE_STOPPED;
  915. status->dSP_index = 0;
  916. status->host_index = status->dSP_index;
  917. status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
  918. status->auxiliary_data_available = 0;
  919. hw_message(pao, phm, phr);
  920. if (phr->error
  921. && hpios_locked_mem_valid(&phw->
  922. instream_host_buffers[phm->obj_index])) {
  923. hpios_locked_mem_free(&phw->instream_host_buffers
  924. [phm->obj_index]);
  925. phw->instream_host_buffer_size[phm->obj_index] = 0;
  926. }
  927. }
  928. }
  929. static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  930. struct hpi_message *phm, struct hpi_response *phr)
  931. {
  932. struct hpi_hw_obj *phw = pao->priv;
  933. struct bus_master_interface *interface = phw->p_interface_buffer;
  934. struct hpi_hostbuffer_status *status;
  935. u8 *p_bbm_data;
  936. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  937. obj_index])) {
  938. if (hpios_locked_mem_get_virt_addr(&phw->
  939. instream_host_buffers[phm->obj_index],
  940. (void *)&p_bbm_data)) {
  941. phr->error = HPI_ERROR_INVALID_OPERATION;
  942. return;
  943. }
  944. status = &interface->instream_host_buffer_status[phm->
  945. obj_index];
  946. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  947. HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
  948. phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
  949. phr->u.d.u.hostbuffer_info.p_status = status;
  950. } else {
  951. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  952. HPI_ISTREAM_HOSTBUFFER_GET_INFO,
  953. HPI_ERROR_INVALID_OPERATION);
  954. }
  955. }
  956. static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
  957. struct hpi_message *phm, struct hpi_response *phr)
  958. {
  959. struct hpi_hw_obj *phw = pao->priv;
  960. u32 command = phm->u.d.u.buffer.command;
  961. if (phw->instream_host_buffer_size[phm->obj_index]) {
  962. if (command == HPI_BUFFER_CMD_EXTERNAL
  963. || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
  964. phw->instream_host_buffer_size[phm->obj_index] = 0;
  965. hw_message(pao, phm, phr);
  966. }
  967. if (command == HPI_BUFFER_CMD_EXTERNAL
  968. || command == HPI_BUFFER_CMD_INTERNAL_FREE)
  969. hpios_locked_mem_free(&phw->instream_host_buffers
  970. [phm->obj_index]);
  971. } else {
  972. /* Should HPI_ERROR_INVALID_OPERATION be returned
  973. if no host buffer is allocated? */
  974. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  975. HPI_ISTREAM_HOSTBUFFER_FREE, 0);
  976. }
  977. }
  978. static void instream_start(struct hpi_adapter_obj *pao,
  979. struct hpi_message *phm, struct hpi_response *phr)
  980. {
  981. hw_message(pao, phm, phr);
  982. }
  983. static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
  984. {
  985. return status->dSP_index - status->host_index;
  986. }
  987. static void instream_read(struct hpi_adapter_obj *pao,
  988. struct hpi_message *phm, struct hpi_response *phr)
  989. {
  990. struct hpi_hw_obj *phw = pao->priv;
  991. struct bus_master_interface *interface = phw->p_interface_buffer;
  992. struct hpi_hostbuffer_status *status;
  993. u32 data_available;
  994. u8 *p_bbm_data;
  995. u32 l_first_read;
  996. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  997. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  998. hw_message(pao, phm, phr);
  999. return;
  1000. }
  1001. hpi_init_response(phr, phm->object, phm->function, 0);
  1002. status = &interface->instream_host_buffer_status[phm->obj_index];
  1003. data_available = instream_get_bytes_available(status);
  1004. if (data_available < phm->u.d.u.data.data_size) {
  1005. phr->error = HPI_ERROR_INVALID_DATASIZE;
  1006. return;
  1007. }
  1008. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  1009. obj_index])) {
  1010. if (hpios_locked_mem_get_virt_addr(&phw->
  1011. instream_host_buffers[phm->obj_index],
  1012. (void *)&p_bbm_data)) {
  1013. phr->error = HPI_ERROR_INVALID_OPERATION;
  1014. return;
  1015. }
  1016. /* either all data,
  1017. or enough to fit from current to end of BBM buffer */
  1018. l_first_read =
  1019. min(phm->u.d.u.data.data_size,
  1020. status->size_in_bytes -
  1021. (status->host_index & (status->size_in_bytes - 1)));
  1022. memcpy(p_app_data,
  1023. p_bbm_data +
  1024. (status->host_index & (status->size_in_bytes - 1)),
  1025. l_first_read);
  1026. /* remaining data if any */
  1027. memcpy(p_app_data + l_first_read, p_bbm_data,
  1028. phm->u.d.u.data.data_size - l_first_read);
  1029. }
  1030. status->host_index += phm->u.d.u.data.data_size;
  1031. }
  1032. static void instream_get_info(struct hpi_adapter_obj *pao,
  1033. struct hpi_message *phm, struct hpi_response *phr)
  1034. {
  1035. struct hpi_hw_obj *phw = pao->priv;
  1036. struct bus_master_interface *interface = phw->p_interface_buffer;
  1037. struct hpi_hostbuffer_status *status;
  1038. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  1039. hw_message(pao, phm, phr);
  1040. return;
  1041. }
  1042. status = &interface->instream_host_buffer_status[phm->obj_index];
  1043. hpi_init_response(phr, phm->object, phm->function, 0);
  1044. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  1045. phr->u.d.u.stream_info.samples_transferred =
  1046. status->samples_processed;
  1047. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  1048. phr->u.d.u.stream_info.data_available =
  1049. instream_get_bytes_available(status);
  1050. phr->u.d.u.stream_info.auxiliary_data_available =
  1051. status->auxiliary_data_available;
  1052. }
  1053. /*****************************************************************************/
  1054. /* LOW-LEVEL */
  1055. #define HPI6205_MAX_FILES_TO_LOAD 2
  1056. static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  1057. u32 *pos_error_code)
  1058. {
  1059. struct hpi_hw_obj *phw = pao->priv;
  1060. struct dsp_code dsp_code;
  1061. u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
  1062. u32 temp;
  1063. int dsp = 0, i = 0;
  1064. u16 err = 0;
  1065. boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
  1066. boot_code_id[1] = pao->pci.pci_dev->subsystem_device;
  1067. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id[1]);
  1068. /* fix up cases where bootcode id[1] != subsys id */
  1069. switch (boot_code_id[1]) {
  1070. case HPI_ADAPTER_FAMILY_ASI(0x5000):
  1071. boot_code_id[0] = boot_code_id[1];
  1072. boot_code_id[1] = 0;
  1073. break;
  1074. case HPI_ADAPTER_FAMILY_ASI(0x5300):
  1075. case HPI_ADAPTER_FAMILY_ASI(0x5400):
  1076. case HPI_ADAPTER_FAMILY_ASI(0x6300):
  1077. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
  1078. break;
  1079. case HPI_ADAPTER_FAMILY_ASI(0x5500):
  1080. case HPI_ADAPTER_FAMILY_ASI(0x5600):
  1081. case HPI_ADAPTER_FAMILY_ASI(0x6500):
  1082. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
  1083. break;
  1084. case HPI_ADAPTER_FAMILY_ASI(0x8800):
  1085. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
  1086. break;
  1087. default:
  1088. break;
  1089. }
  1090. /* reset DSP by writing a 1 to the WARMRESET bit */
  1091. temp = C6205_HDCR_WARMRESET;
  1092. iowrite32(temp, phw->prHDCR);
  1093. hpios_delay_micro_seconds(1000);
  1094. /* check that PCI i/f was configured by EEPROM */
  1095. temp = ioread32(phw->prHSR);
  1096. if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
  1097. C6205_HSR_EEREAD)
  1098. return HPI6205_ERROR_6205_EEPROM;
  1099. temp |= 0x04;
  1100. /* disable PINTA interrupt */
  1101. iowrite32(temp, phw->prHSR);
  1102. /* check control register reports PCI boot mode */
  1103. temp = ioread32(phw->prHDCR);
  1104. if (!(temp & C6205_HDCR_PCIBOOT))
  1105. return HPI6205_ERROR_6205_REG;
  1106. /* try writing a few numbers to the DSP page register */
  1107. /* and reading them back. */
  1108. temp = 3;
  1109. iowrite32(temp, phw->prDSPP);
  1110. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1111. return HPI6205_ERROR_6205_DSPPAGE;
  1112. temp = 2;
  1113. iowrite32(temp, phw->prDSPP);
  1114. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1115. return HPI6205_ERROR_6205_DSPPAGE;
  1116. temp = 1;
  1117. iowrite32(temp, phw->prDSPP);
  1118. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1119. return HPI6205_ERROR_6205_DSPPAGE;
  1120. /* reset DSP page to the correct number */
  1121. temp = 0;
  1122. iowrite32(temp, phw->prDSPP);
  1123. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1124. return HPI6205_ERROR_6205_DSPPAGE;
  1125. phw->dsp_page = 0;
  1126. /* release 6713 from reset before 6205 is bootloaded.
  1127. This ensures that the EMIF is inactive,
  1128. and the 6713 HPI gets the correct bootmode etc
  1129. */
  1130. if (boot_code_id[1] != 0) {
  1131. /* DSP 1 is a C6713 */
  1132. /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
  1133. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
  1134. hpios_delay_micro_seconds(100);
  1135. /* Reset the 6713 #1 - revB */
  1136. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  1137. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1138. boot_loader_read_mem32(pao, 0, 0);
  1139. hpios_delay_micro_seconds(100);
  1140. /* Release C6713 from reset - revB */
  1141. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
  1142. hpios_delay_micro_seconds(100);
  1143. }
  1144. for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
  1145. /* is there a DSP to load? */
  1146. if (boot_code_id[dsp] == 0)
  1147. continue;
  1148. err = boot_loader_config_emif(pao, dsp);
  1149. if (err)
  1150. return err;
  1151. err = boot_loader_test_internal_memory(pao, dsp);
  1152. if (err)
  1153. return err;
  1154. err = boot_loader_test_external_memory(pao, dsp);
  1155. if (err)
  1156. return err;
  1157. err = boot_loader_test_pld(pao, dsp);
  1158. if (err)
  1159. return err;
  1160. /* write the DSP code down into the DSPs memory */
  1161. dsp_code.ps_dev = pao->pci.pci_dev;
  1162. err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
  1163. pos_error_code);
  1164. if (err)
  1165. return err;
  1166. while (1) {
  1167. u32 length;
  1168. u32 address;
  1169. u32 type;
  1170. u32 *pcode;
  1171. err = hpi_dsp_code_read_word(&dsp_code, &length);
  1172. if (err)
  1173. break;
  1174. if (length == 0xFFFFFFFF)
  1175. break; /* end of code */
  1176. err = hpi_dsp_code_read_word(&dsp_code, &address);
  1177. if (err)
  1178. break;
  1179. err = hpi_dsp_code_read_word(&dsp_code, &type);
  1180. if (err)
  1181. break;
  1182. err = hpi_dsp_code_read_block(length, &dsp_code,
  1183. &pcode);
  1184. if (err)
  1185. break;
  1186. for (i = 0; i < (int)length; i++) {
  1187. boot_loader_write_mem32(pao, dsp, address,
  1188. *pcode);
  1189. /* dummy read every 4 words */
  1190. /* for 6205 advisory 1.4.4 */
  1191. if (i % 4 == 0)
  1192. boot_loader_read_mem32(pao, dsp,
  1193. address);
  1194. pcode++;
  1195. address += 4;
  1196. }
  1197. }
  1198. if (err) {
  1199. hpi_dsp_code_close(&dsp_code);
  1200. return err;
  1201. }
  1202. /* verify code */
  1203. hpi_dsp_code_rewind(&dsp_code);
  1204. while (1) {
  1205. u32 length = 0;
  1206. u32 address = 0;
  1207. u32 type = 0;
  1208. u32 *pcode = NULL;
  1209. u32 data = 0;
  1210. hpi_dsp_code_read_word(&dsp_code, &length);
  1211. if (length == 0xFFFFFFFF)
  1212. break; /* end of code */
  1213. hpi_dsp_code_read_word(&dsp_code, &address);
  1214. hpi_dsp_code_read_word(&dsp_code, &type);
  1215. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  1216. for (i = 0; i < (int)length; i++) {
  1217. data = boot_loader_read_mem32(pao, dsp,
  1218. address);
  1219. if (data != *pcode) {
  1220. err = 0;
  1221. break;
  1222. }
  1223. pcode++;
  1224. address += 4;
  1225. }
  1226. if (err)
  1227. break;
  1228. }
  1229. hpi_dsp_code_close(&dsp_code);
  1230. if (err)
  1231. return err;
  1232. }
  1233. /* After bootloading all DSPs, start DSP0 running
  1234. * The DSP0 code will handle starting and synchronizing with its slaves
  1235. */
  1236. if (phw->p_interface_buffer) {
  1237. /* we need to tell the card the physical PCI address */
  1238. u32 physicalPC_iaddress;
  1239. struct bus_master_interface *interface =
  1240. phw->p_interface_buffer;
  1241. u32 host_mailbox_address_on_dsp;
  1242. u32 physicalPC_iaddress_verify = 0;
  1243. int time_out = 10;
  1244. /* set ack so we know when DSP is ready to go */
  1245. /* (dwDspAck will be changed to HIF_RESET) */
  1246. interface->dsp_ack = H620_HIF_UNKNOWN;
  1247. wmb(); /* ensure ack is written before dsp writes back */
  1248. err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
  1249. &physicalPC_iaddress);
  1250. /* locate the host mailbox on the DSP. */
  1251. host_mailbox_address_on_dsp = 0x80000000;
  1252. while ((physicalPC_iaddress != physicalPC_iaddress_verify)
  1253. && time_out--) {
  1254. boot_loader_write_mem32(pao, 0,
  1255. host_mailbox_address_on_dsp,
  1256. physicalPC_iaddress);
  1257. physicalPC_iaddress_verify =
  1258. boot_loader_read_mem32(pao, 0,
  1259. host_mailbox_address_on_dsp);
  1260. }
  1261. }
  1262. HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
  1263. /* enable interrupts */
  1264. temp = ioread32(phw->prHSR);
  1265. temp &= ~(u32)C6205_HSR_INTAM;
  1266. iowrite32(temp, phw->prHSR);
  1267. /* start code running... */
  1268. temp = ioread32(phw->prHDCR);
  1269. temp |= (u32)C6205_HDCR_DSPINT;
  1270. iowrite32(temp, phw->prHDCR);
  1271. /* give the DSP 10ms to start up */
  1272. hpios_delay_micro_seconds(10000);
  1273. return err;
  1274. }
  1275. /*****************************************************************************/
  1276. /* Bootloader utility functions */
  1277. static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  1278. u32 address)
  1279. {
  1280. struct hpi_hw_obj *phw = pao->priv;
  1281. u32 data = 0;
  1282. __iomem u32 *p_data;
  1283. if (dsp_index == 0) {
  1284. /* DSP 0 is always C6205 */
  1285. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1286. /* BAR1 register access */
  1287. p_data = pao->pci.ap_mem_base[1] +
  1288. (address & 0x007fffff) /
  1289. sizeof(*pao->pci.ap_mem_base[1]);
  1290. /* HPI_DEBUG_LOG(WARNING,
  1291. "BAR1 access %08x\n", dwAddress); */
  1292. } else {
  1293. u32 dw4M_page = address >> 22L;
  1294. if (dw4M_page != phw->dsp_page) {
  1295. phw->dsp_page = dw4M_page;
  1296. /* *INDENT OFF* */
  1297. iowrite32(phw->dsp_page, phw->prDSPP);
  1298. /* *INDENT-ON* */
  1299. }
  1300. address &= 0x3fffff; /* address within 4M page */
  1301. /* BAR0 memory access */
  1302. p_data = pao->pci.ap_mem_base[0] +
  1303. address / sizeof(u32);
  1304. }
  1305. data = ioread32(p_data);
  1306. } else if (dsp_index == 1) {
  1307. /* DSP 1 is a C6713 */
  1308. u32 lsb;
  1309. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1310. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1311. lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
  1312. data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
  1313. data = (data << 16) | (lsb & 0xFFFF);
  1314. }
  1315. return data;
  1316. }
  1317. static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
  1318. int dsp_index, u32 address, u32 data)
  1319. {
  1320. struct hpi_hw_obj *phw = pao->priv;
  1321. __iomem u32 *p_data;
  1322. /* u32 dwVerifyData=0; */
  1323. if (dsp_index == 0) {
  1324. /* DSP 0 is always C6205 */
  1325. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1326. /* BAR1 - DSP register access using */
  1327. /* Non-prefetchable PCI access */
  1328. p_data = pao->pci.ap_mem_base[1] +
  1329. (address & 0x007fffff) /
  1330. sizeof(*pao->pci.ap_mem_base[1]);
  1331. } else {
  1332. /* BAR0 access - all of DSP memory using */
  1333. /* pre-fetchable PCI access */
  1334. u32 dw4M_page = address >> 22L;
  1335. if (dw4M_page != phw->dsp_page) {
  1336. phw->dsp_page = dw4M_page;
  1337. /* *INDENT-OFF* */
  1338. iowrite32(phw->dsp_page, phw->prDSPP);
  1339. /* *INDENT-ON* */
  1340. }
  1341. address &= 0x3fffff; /* address within 4M page */
  1342. p_data = pao->pci.ap_mem_base[0] +
  1343. address / sizeof(u32);
  1344. }
  1345. iowrite32(data, p_data);
  1346. } else if (dsp_index == 1) {
  1347. /* DSP 1 is a C6713 */
  1348. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1349. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1350. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1351. boot_loader_read_mem32(pao, 0, 0);
  1352. boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
  1353. boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
  1354. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1355. boot_loader_read_mem32(pao, 0, 0);
  1356. }
  1357. }
  1358. static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
  1359. {
  1360. if (dsp_index == 0) {
  1361. u32 setting;
  1362. /* DSP 0 is always C6205 */
  1363. /* Set the EMIF */
  1364. /* memory map of C6205 */
  1365. /* 00000000-0000FFFF 16Kx32 internal program */
  1366. /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
  1367. /* EMIF config */
  1368. /*------------ */
  1369. /* Global EMIF control */
  1370. boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
  1371. #define WS_OFS 28
  1372. #define WST_OFS 22
  1373. #define WH_OFS 20
  1374. #define RS_OFS 16
  1375. #define RST_OFS 8
  1376. #define MTYPE_OFS 4
  1377. #define RH_OFS 0
  1378. /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
  1379. setting = 0x00000030;
  1380. boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
  1381. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1382. 0x01800008))
  1383. return HPI6205_ERROR_DSP_EMIF;
  1384. /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
  1385. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1386. /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
  1387. /* WST should be 71, but 63 is max possible */
  1388. setting =
  1389. (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
  1390. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1391. (2L << MTYPE_OFS);
  1392. boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
  1393. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1394. 0x01800004))
  1395. return HPI6205_ERROR_DSP_EMIF;
  1396. /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
  1397. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1398. /* plenty of wait states */
  1399. setting =
  1400. (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
  1401. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1402. (2L << MTYPE_OFS);
  1403. boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
  1404. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1405. 0x01800010))
  1406. return HPI6205_ERROR_DSP_EMIF;
  1407. /* EMIF CE3 setup - 32 bit async. */
  1408. /* This is the PLD on the ASI5000 cards only */
  1409. setting =
  1410. (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
  1411. (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
  1412. (2L << MTYPE_OFS);
  1413. boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
  1414. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1415. 0x01800014))
  1416. return HPI6205_ERROR_DSP_EMIF;
  1417. /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
  1418. /* need to use this else DSP code crashes? */
  1419. boot_loader_write_mem32(pao, dsp_index, 0x01800018,
  1420. 0x07117000);
  1421. /* EMIF SDRAM Refresh Timing */
  1422. /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
  1423. boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
  1424. 0x00000410);
  1425. } else if (dsp_index == 1) {
  1426. /* test access to the C6713s HPI registers */
  1427. u32 write_data = 0, read_data = 0, i = 0;
  1428. /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
  1429. write_data = 1;
  1430. boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
  1431. boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
  1432. /* C67 HPI is on lower 16bits of 32bit EMIF */
  1433. read_data =
  1434. 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
  1435. if (write_data != read_data) {
  1436. HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
  1437. read_data);
  1438. return HPI6205_ERROR_C6713_HPIC;
  1439. }
  1440. /* HPIA - walking ones test */
  1441. write_data = 1;
  1442. for (i = 0; i < 32; i++) {
  1443. boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
  1444. write_data);
  1445. boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
  1446. (write_data >> 16));
  1447. read_data =
  1448. 0xFFFF & boot_loader_read_mem32(pao, 0,
  1449. HPIAL_ADDR);
  1450. read_data =
  1451. read_data | ((0xFFFF &
  1452. boot_loader_read_mem32(pao, 0,
  1453. HPIAH_ADDR))
  1454. << 16);
  1455. if (read_data != write_data) {
  1456. HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
  1457. write_data, read_data);
  1458. return HPI6205_ERROR_C6713_HPIA;
  1459. }
  1460. write_data = write_data << 1;
  1461. }
  1462. /* setup C67x PLL
  1463. * ** C6713 datasheet says we cannot program PLL from HPI,
  1464. * and indeed if we try to set the PLL multiply from the HPI,
  1465. * the PLL does not seem to lock, so we enable the PLL and
  1466. * use the default multiply of x 7, which for a 27MHz clock
  1467. * gives a DSP speed of 189MHz
  1468. */
  1469. /* bypass PLL */
  1470. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
  1471. hpios_delay_micro_seconds(1000);
  1472. /* EMIF = 189/3=63MHz */
  1473. boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
  1474. /* peri = 189/2 */
  1475. boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
  1476. /* cpu = 189/1 */
  1477. boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
  1478. hpios_delay_micro_seconds(1000);
  1479. /* ** SGT test to take GPO3 high when we start the PLL */
  1480. /* and low when the delay is completed */
  1481. /* FSX0 <- '1' (GPO3) */
  1482. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
  1483. /* PLL not bypassed */
  1484. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
  1485. hpios_delay_micro_seconds(1000);
  1486. /* FSX0 <- '0' (GPO3) */
  1487. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
  1488. /* 6205 EMIF CE1 resetup - 32 bit async. */
  1489. /* Now 6713 #1 is running at 189MHz can reduce waitstates */
  1490. boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
  1491. (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
  1492. (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
  1493. (2L << MTYPE_OFS));
  1494. hpios_delay_micro_seconds(1000);
  1495. /* check that we can read one of the PLL registers */
  1496. /* PLL should not be bypassed! */
  1497. if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
  1498. != 0x0001) {
  1499. return HPI6205_ERROR_C6713_PLL;
  1500. }
  1501. /* setup C67x EMIF (note this is the only use of
  1502. BAR1 via BootLoader_WriteMem32) */
  1503. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
  1504. 0x000034A8);
  1505. /* EMIF CE0 setup - 2Mx32 Sync DRAM
  1506. 31..28 Wr setup
  1507. 27..22 Wr strobe
  1508. 21..20 Wr hold
  1509. 19..16 Rd setup
  1510. 15..14 -
  1511. 13..8 Rd strobe
  1512. 7..4 MTYPE 0011 Sync DRAM 32bits
  1513. 3 Wr hold MSB
  1514. 2..0 Rd hold
  1515. */
  1516. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
  1517. 0x00000030);
  1518. /* EMIF SDRAM Extension
  1519. 0x00
  1520. 31-21 0000b 0000b 000b
  1521. 20 WR2RD = 2cycles-1 = 1b
  1522. 19-18 WR2DEAC = 3cycle-1 = 10b
  1523. 17 WR2WR = 2cycle-1 = 1b
  1524. 16-15 R2WDQM = 4cycle-1 = 11b
  1525. 14-12 RD2WR = 6cycles-1 = 101b
  1526. 11-10 RD2DEAC = 4cycle-1 = 11b
  1527. 9 RD2RD = 2cycle-1 = 1b
  1528. 8-7 THZP = 3cycle-1 = 10b
  1529. 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
  1530. 4 TRRD = 2cycle = 0b (tRRD = 14ns)
  1531. 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
  1532. 1 CAS latency = 3cyc = 1b
  1533. (for Micron 2M32-7 operating at 100MHz)
  1534. */
  1535. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
  1536. 0x001BDF29);
  1537. /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
  1538. 31 - 0b -
  1539. 30 SDBSZ 1b 4 bank
  1540. 29..28 SDRSZ 00b 11 row address pins
  1541. 27..26 SDCSZ 01b 8 column address pins
  1542. 25 RFEN 1b refersh enabled
  1543. 24 INIT 1b init SDRAM!
  1544. 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
  1545. 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
  1546. 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
  1547. 11..0 - 0000b 0000b 0000b
  1548. */
  1549. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
  1550. 0x47116000);
  1551. /* SDRAM refresh timing
  1552. Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
  1553. */
  1554. boot_loader_write_mem32(pao, dsp_index,
  1555. C6713_EMIF_SDRAMTIMING, 0x00000410);
  1556. hpios_delay_micro_seconds(1000);
  1557. } else if (dsp_index == 2) {
  1558. /* DSP 2 is a C6713 */
  1559. }
  1560. return 0;
  1561. }
  1562. static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
  1563. u32 start_address, u32 length)
  1564. {
  1565. u32 i = 0, j = 0;
  1566. u32 test_addr = 0;
  1567. u32 test_data = 0, data = 0;
  1568. length = 1000;
  1569. /* for 1st word, test each bit in the 32bit word, */
  1570. /* dwLength specifies number of 32bit words to test */
  1571. /*for(i=0; i<dwLength; i++) */
  1572. i = 0;
  1573. {
  1574. test_addr = start_address + i * 4;
  1575. test_data = 0x00000001;
  1576. for (j = 0; j < 32; j++) {
  1577. boot_loader_write_mem32(pao, dsp_index, test_addr,
  1578. test_data);
  1579. data = boot_loader_read_mem32(pao, dsp_index,
  1580. test_addr);
  1581. if (data != test_data) {
  1582. HPI_DEBUG_LOG(VERBOSE,
  1583. "Memtest error details "
  1584. "%08x %08x %08x %i\n", test_addr,
  1585. test_data, data, dsp_index);
  1586. return 1; /* error */
  1587. }
  1588. test_data = test_data << 1;
  1589. } /* for(j) */
  1590. } /* for(i) */
  1591. /* for the next 100 locations test each location, leaving it as zero */
  1592. /* write a zero to the next word in memory before we read */
  1593. /* the previous write to make sure every memory location is unique */
  1594. for (i = 0; i < 100; i++) {
  1595. test_addr = start_address + i * 4;
  1596. test_data = 0xA5A55A5A;
  1597. boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
  1598. boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
  1599. data = boot_loader_read_mem32(pao, dsp_index, test_addr);
  1600. if (data != test_data) {
  1601. HPI_DEBUG_LOG(VERBOSE,
  1602. "Memtest error details "
  1603. "%08x %08x %08x %i\n", test_addr, test_data,
  1604. data, dsp_index);
  1605. return 1; /* error */
  1606. }
  1607. /* leave location as zero */
  1608. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1609. }
  1610. /* zero out entire memory block */
  1611. for (i = 0; i < length; i++) {
  1612. test_addr = start_address + i * 4;
  1613. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1614. }
  1615. return 0;
  1616. }
  1617. static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
  1618. int dsp_index)
  1619. {
  1620. int err = 0;
  1621. if (dsp_index == 0) {
  1622. /* DSP 0 is a C6205 */
  1623. /* 64K prog mem */
  1624. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1625. 0x10000);
  1626. if (!err)
  1627. /* 64K data mem */
  1628. err = boot_loader_test_memory(pao, dsp_index,
  1629. 0x80000000, 0x10000);
  1630. } else if (dsp_index == 1) {
  1631. /* DSP 1 is a C6713 */
  1632. /* 192K internal mem */
  1633. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1634. 0x30000);
  1635. if (!err)
  1636. /* 64K internal mem / L2 cache */
  1637. err = boot_loader_test_memory(pao, dsp_index,
  1638. 0x00030000, 0x10000);
  1639. }
  1640. if (err)
  1641. return HPI6205_ERROR_DSP_INTMEM;
  1642. else
  1643. return 0;
  1644. }
  1645. static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
  1646. int dsp_index)
  1647. {
  1648. u32 dRAM_start_address = 0;
  1649. u32 dRAM_size = 0;
  1650. if (dsp_index == 0) {
  1651. /* only test for SDRAM if an ASI5000 card */
  1652. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1653. /* DSP 0 is always C6205 */
  1654. dRAM_start_address = 0x00400000;
  1655. dRAM_size = 0x200000;
  1656. /*dwDRAMinc=1024; */
  1657. } else
  1658. return 0;
  1659. } else if (dsp_index == 1) {
  1660. /* DSP 1 is a C6713 */
  1661. dRAM_start_address = 0x80000000;
  1662. dRAM_size = 0x200000;
  1663. /*dwDRAMinc=1024; */
  1664. }
  1665. if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
  1666. dRAM_size))
  1667. return HPI6205_ERROR_DSP_EXTMEM;
  1668. return 0;
  1669. }
  1670. static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
  1671. {
  1672. u32 data = 0;
  1673. if (dsp_index == 0) {
  1674. /* only test for DSP0 PLD on ASI5000 card */
  1675. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1676. /* PLD is located at CE3=0x03000000 */
  1677. data = boot_loader_read_mem32(pao, dsp_index,
  1678. 0x03000008);
  1679. if ((data & 0xF) != 0x5)
  1680. return HPI6205_ERROR_DSP_PLD;
  1681. data = boot_loader_read_mem32(pao, dsp_index,
  1682. 0x0300000C);
  1683. if ((data & 0xF) != 0xA)
  1684. return HPI6205_ERROR_DSP_PLD;
  1685. }
  1686. } else if (dsp_index == 1) {
  1687. /* DSP 1 is a C6713 */
  1688. if (pao->pci.pci_dev->subsystem_device == 0x8700) {
  1689. /* PLD is located at CE1=0x90000000 */
  1690. data = boot_loader_read_mem32(pao, dsp_index,
  1691. 0x90000010);
  1692. if ((data & 0xFF) != 0xAA)
  1693. return HPI6205_ERROR_DSP_PLD;
  1694. /* 8713 - LED on */
  1695. boot_loader_write_mem32(pao, dsp_index, 0x90000000,
  1696. 0x02);
  1697. }
  1698. }
  1699. return 0;
  1700. }
  1701. /** Transfer data to or from DSP
  1702. nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
  1703. */
  1704. static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
  1705. u32 data_size, int operation)
  1706. {
  1707. struct hpi_hw_obj *phw = pao->priv;
  1708. u32 data_transferred = 0;
  1709. u16 err = 0;
  1710. u32 temp2;
  1711. struct bus_master_interface *interface = phw->p_interface_buffer;
  1712. if (!p_data)
  1713. return HPI_ERROR_INVALID_DATA_POINTER;
  1714. data_size &= ~3L; /* round data_size down to nearest 4 bytes */
  1715. /* make sure state is IDLE */
  1716. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
  1717. return HPI_ERROR_DSP_HARDWARE;
  1718. while (data_transferred < data_size) {
  1719. u32 this_copy = data_size - data_transferred;
  1720. if (this_copy > HPI6205_SIZEOF_DATA)
  1721. this_copy = HPI6205_SIZEOF_DATA;
  1722. if (operation == H620_HIF_SEND_DATA)
  1723. memcpy((void *)&interface->u.b_data[0],
  1724. &p_data[data_transferred], this_copy);
  1725. interface->transfer_size_in_bytes = this_copy;
  1726. /* DSP must change this back to nOperation */
  1727. interface->dsp_ack = H620_HIF_IDLE;
  1728. send_dsp_command(phw, operation);
  1729. temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
  1730. HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
  1731. HPI6205_TIMEOUT - temp2, this_copy);
  1732. if (!temp2) {
  1733. /* timed out */
  1734. HPI_DEBUG_LOG(ERROR,
  1735. "Timed out waiting for " "state %d got %d\n",
  1736. operation, interface->dsp_ack);
  1737. break;
  1738. }
  1739. if (operation == H620_HIF_GET_DATA)
  1740. memcpy(&p_data[data_transferred],
  1741. (void *)&interface->u.b_data[0], this_copy);
  1742. data_transferred += this_copy;
  1743. }
  1744. if (interface->dsp_ack != operation)
  1745. HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
  1746. interface->dsp_ack, operation);
  1747. /* err=HPI_ERROR_DSP_HARDWARE; */
  1748. send_dsp_command(phw, H620_HIF_IDLE);
  1749. return err;
  1750. }
  1751. /* wait for up to timeout_us microseconds for the DSP
  1752. to signal state by DMA into dwDspAck
  1753. */
  1754. static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
  1755. {
  1756. struct bus_master_interface *interface = phw->p_interface_buffer;
  1757. int t = timeout_us / 4;
  1758. rmb(); /* ensure interface->dsp_ack is up to date */
  1759. while ((interface->dsp_ack != state) && --t) {
  1760. hpios_delay_micro_seconds(4);
  1761. rmb(); /* DSP changes dsp_ack by DMA */
  1762. }
  1763. /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
  1764. return t * 4;
  1765. }
  1766. /* set the busmaster interface to cmd, then interrupt the DSP */
  1767. static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
  1768. {
  1769. struct bus_master_interface *interface = phw->p_interface_buffer;
  1770. u32 r;
  1771. interface->host_cmd = cmd;
  1772. wmb(); /* DSP gets state by DMA, make sure it is written to memory */
  1773. /* before we interrupt the DSP */
  1774. r = ioread32(phw->prHDCR);
  1775. r |= (u32)C6205_HDCR_DSPINT;
  1776. iowrite32(r, phw->prHDCR);
  1777. r &= ~(u32)C6205_HDCR_DSPINT;
  1778. iowrite32(r, phw->prHDCR);
  1779. }
  1780. static unsigned int message_count;
  1781. static u16 message_response_sequence(struct hpi_adapter_obj *pao,
  1782. struct hpi_message *phm, struct hpi_response *phr)
  1783. {
  1784. u32 time_out, time_out2;
  1785. struct hpi_hw_obj *phw = pao->priv;
  1786. struct bus_master_interface *interface = phw->p_interface_buffer;
  1787. u16 err = 0;
  1788. message_count++;
  1789. if (phm->size > sizeof(interface->u)) {
  1790. phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
  1791. phr->specific_error = sizeof(interface->u);
  1792. phr->size = sizeof(struct hpi_response_header);
  1793. HPI_DEBUG_LOG(ERROR,
  1794. "message len %d too big for buffer %zd \n", phm->size,
  1795. sizeof(interface->u));
  1796. return 0;
  1797. }
  1798. /* Assume buffer of type struct bus_master_interface
  1799. is allocated "noncacheable" */
  1800. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1801. HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
  1802. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1803. }
  1804. memcpy(&interface->u.message_buffer, phm, phm->size);
  1805. /* signal we want a response */
  1806. send_dsp_command(phw, H620_HIF_GET_RESP);
  1807. time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
  1808. if (!time_out2) {
  1809. HPI_DEBUG_LOG(ERROR,
  1810. "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
  1811. message_count, interface->dsp_ack);
  1812. } else {
  1813. HPI_DEBUG_LOG(VERBOSE,
  1814. "(%u) transition to GET_RESP after %u\n",
  1815. message_count, HPI6205_TIMEOUT - time_out2);
  1816. }
  1817. /* spin waiting on HIF interrupt flag (end of msg process) */
  1818. time_out = HPI6205_TIMEOUT;
  1819. /* read the result */
  1820. if (time_out) {
  1821. if (interface->u.response_buffer.size <= phr->size)
  1822. memcpy(phr, &interface->u.response_buffer,
  1823. interface->u.response_buffer.size);
  1824. else {
  1825. HPI_DEBUG_LOG(ERROR,
  1826. "response len %d too big for buffer %d\n",
  1827. interface->u.response_buffer.size, phr->size);
  1828. memcpy(phr, &interface->u.response_buffer,
  1829. sizeof(struct hpi_response_header));
  1830. phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1831. phr->specific_error =
  1832. interface->u.response_buffer.size;
  1833. phr->size = sizeof(struct hpi_response_header);
  1834. }
  1835. }
  1836. /* set interface back to idle */
  1837. send_dsp_command(phw, H620_HIF_IDLE);
  1838. if (!time_out || !time_out2) {
  1839. HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
  1840. return HPI6205_ERROR_MSG_RESP_TIMEOUT;
  1841. }
  1842. /* special case for adapter close - */
  1843. /* wait for the DSP to indicate it is idle */
  1844. if (phm->function == HPI_ADAPTER_CLOSE) {
  1845. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1846. HPI_DEBUG_LOG(DEBUG,
  1847. "Timeout waiting for idle "
  1848. "(on adapter_close)\n");
  1849. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1850. }
  1851. }
  1852. err = hpi_validate_response(phm, phr);
  1853. return err;
  1854. }
  1855. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1856. struct hpi_response *phr)
  1857. {
  1858. u16 err = 0;
  1859. hpios_dsplock_lock(pao);
  1860. err = message_response_sequence(pao, phm, phr);
  1861. /* maybe an error response */
  1862. if (err) {
  1863. /* something failed in the HPI/DSP interface */
  1864. if (err >= HPI_ERROR_BACKEND_BASE) {
  1865. phr->error = HPI_ERROR_DSP_COMMUNICATION;
  1866. phr->specific_error = err;
  1867. } else {
  1868. phr->error = err;
  1869. }
  1870. pao->dsp_crashed++;
  1871. /* just the header of the response is valid */
  1872. phr->size = sizeof(struct hpi_response_header);
  1873. goto err;
  1874. } else
  1875. pao->dsp_crashed = 0;
  1876. if (phr->error != 0) /* something failed in the DSP */
  1877. goto err;
  1878. switch (phm->function) {
  1879. case HPI_OSTREAM_WRITE:
  1880. case HPI_ISTREAM_ANC_WRITE:
  1881. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1882. phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
  1883. break;
  1884. case HPI_ISTREAM_READ:
  1885. case HPI_OSTREAM_ANC_READ:
  1886. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1887. phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
  1888. break;
  1889. case HPI_CONTROL_SET_STATE:
  1890. if (phm->object == HPI_OBJ_CONTROLEX
  1891. && phm->u.cx.attribute == HPI_COBRANET_SET_DATA)
  1892. err = hpi6205_transfer_data(pao,
  1893. phm->u.cx.u.cobranet_bigdata.pb_data,
  1894. phm->u.cx.u.cobranet_bigdata.byte_count,
  1895. H620_HIF_SEND_DATA);
  1896. break;
  1897. case HPI_CONTROL_GET_STATE:
  1898. if (phm->object == HPI_OBJ_CONTROLEX
  1899. && phm->u.cx.attribute == HPI_COBRANET_GET_DATA)
  1900. err = hpi6205_transfer_data(pao,
  1901. phm->u.cx.u.cobranet_bigdata.pb_data,
  1902. phr->u.cx.u.cobranet_data.byte_count,
  1903. H620_HIF_GET_DATA);
  1904. break;
  1905. }
  1906. phr->error = err;
  1907. err:
  1908. hpios_dsplock_unlock(pao);
  1909. return;
  1910. }