hpi6205.c 64 KB

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