hpi6205.c 64 KB

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