hpi6205.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  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 subsys_delete_adapter(struct hpi_message *phm,
  126. 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_message *phm, struct hpi_response *phr)
  173. {
  174. switch (phm->function) {
  175. case HPI_SUBSYS_CREATE_ADAPTER:
  176. subsys_create_adapter(phm, phr);
  177. break;
  178. case HPI_SUBSYS_DELETE_ADAPTER:
  179. subsys_delete_adapter(phm, phr);
  180. break;
  181. default:
  182. phr->error = HPI_ERROR_INVALID_FUNC;
  183. break;
  184. }
  185. }
  186. static void control_message(struct hpi_adapter_obj *pao,
  187. struct hpi_message *phm, struct hpi_response *phr)
  188. {
  189. struct hpi_hw_obj *phw = pao->priv;
  190. u16 pending_cache_error = 0;
  191. switch (phm->function) {
  192. case HPI_CONTROL_GET_STATE:
  193. if (pao->has_control_cache) {
  194. rmb(); /* make sure we see updates DMAed from DSP */
  195. if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
  196. break;
  197. } else if (phm->u.c.attribute == HPI_METER_PEAK) {
  198. pending_cache_error =
  199. HPI_ERROR_CONTROL_CACHING;
  200. }
  201. }
  202. hw_message(pao, phm, phr);
  203. if (pending_cache_error && !phr->error)
  204. phr->error = pending_cache_error;
  205. break;
  206. case HPI_CONTROL_GET_INFO:
  207. hw_message(pao, phm, phr);
  208. break;
  209. case HPI_CONTROL_SET_STATE:
  210. hw_message(pao, phm, phr);
  211. if (pao->has_control_cache)
  212. hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
  213. phr);
  214. break;
  215. default:
  216. phr->error = HPI_ERROR_INVALID_FUNC;
  217. break;
  218. }
  219. }
  220. static void adapter_message(struct hpi_adapter_obj *pao,
  221. struct hpi_message *phm, struct hpi_response *phr)
  222. {
  223. switch (phm->function) {
  224. default:
  225. hw_message(pao, phm, phr);
  226. break;
  227. }
  228. }
  229. static void outstream_message(struct hpi_adapter_obj *pao,
  230. struct hpi_message *phm, struct hpi_response *phr)
  231. {
  232. if (phm->obj_index >= HPI_MAX_STREAMS) {
  233. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  234. HPI_DEBUG_LOG(WARNING,
  235. "Message referencing invalid stream %d "
  236. "on adapter index %d\n", phm->obj_index,
  237. phm->adapter_index);
  238. return;
  239. }
  240. switch (phm->function) {
  241. case HPI_OSTREAM_WRITE:
  242. outstream_write(pao, phm, phr);
  243. break;
  244. case HPI_OSTREAM_GET_INFO:
  245. outstream_get_info(pao, phm, phr);
  246. break;
  247. case HPI_OSTREAM_HOSTBUFFER_ALLOC:
  248. outstream_host_buffer_allocate(pao, phm, phr);
  249. break;
  250. case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
  251. outstream_host_buffer_get_info(pao, phm, phr);
  252. break;
  253. case HPI_OSTREAM_HOSTBUFFER_FREE:
  254. outstream_host_buffer_free(pao, phm, phr);
  255. break;
  256. case HPI_OSTREAM_START:
  257. outstream_start(pao, phm, phr);
  258. break;
  259. case HPI_OSTREAM_OPEN:
  260. outstream_open(pao, phm, phr);
  261. break;
  262. case HPI_OSTREAM_RESET:
  263. outstream_reset(pao, phm, phr);
  264. break;
  265. default:
  266. hw_message(pao, phm, phr);
  267. break;
  268. }
  269. }
  270. static void instream_message(struct hpi_adapter_obj *pao,
  271. struct hpi_message *phm, struct hpi_response *phr)
  272. {
  273. if (phm->obj_index >= HPI_MAX_STREAMS) {
  274. phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
  275. HPI_DEBUG_LOG(WARNING,
  276. "Message referencing invalid stream %d "
  277. "on adapter index %d\n", phm->obj_index,
  278. phm->adapter_index);
  279. return;
  280. }
  281. switch (phm->function) {
  282. case HPI_ISTREAM_READ:
  283. instream_read(pao, phm, phr);
  284. break;
  285. case HPI_ISTREAM_GET_INFO:
  286. instream_get_info(pao, phm, phr);
  287. break;
  288. case HPI_ISTREAM_HOSTBUFFER_ALLOC:
  289. instream_host_buffer_allocate(pao, phm, phr);
  290. break;
  291. case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
  292. instream_host_buffer_get_info(pao, phm, phr);
  293. break;
  294. case HPI_ISTREAM_HOSTBUFFER_FREE:
  295. instream_host_buffer_free(pao, phm, phr);
  296. break;
  297. case HPI_ISTREAM_START:
  298. instream_start(pao, phm, phr);
  299. break;
  300. default:
  301. hw_message(pao, phm, phr);
  302. break;
  303. }
  304. }
  305. /*****************************************************************************/
  306. /** Entry point to this HPI backend
  307. * All calls to the HPI start here
  308. */
  309. void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
  310. {
  311. struct hpi_adapter_obj *pao = NULL;
  312. /* subsytem messages are processed by every HPI.
  313. * All other messages are ignored unless the adapter index matches
  314. * an adapter in the HPI
  315. */
  316. /* HPI_DEBUG_LOG(DEBUG, "HPI Obj=%d, Func=%d\n", phm->wObject,
  317. phm->wFunction); */
  318. /* if Dsp has crashed then do not communicate with it any more */
  319. if (phm->object != HPI_OBJ_SUBSYSTEM) {
  320. pao = hpi_find_adapter(phm->adapter_index);
  321. if (!pao) {
  322. HPI_DEBUG_LOG(DEBUG,
  323. " %d,%d refused, for another HPI?\n",
  324. phm->object, phm->function);
  325. return;
  326. }
  327. if ((pao->dsp_crashed >= 10)
  328. && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
  329. /* allow last resort debug read even after crash */
  330. hpi_init_response(phr, phm->object, phm->function,
  331. HPI_ERROR_DSP_HARDWARE);
  332. HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n",
  333. phm->object, phm->function);
  334. return;
  335. }
  336. }
  337. /* Init default response */
  338. if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
  339. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  340. HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
  341. switch (phm->type) {
  342. case HPI_TYPE_MESSAGE:
  343. switch (phm->object) {
  344. case HPI_OBJ_SUBSYSTEM:
  345. subsys_message(phm, phr);
  346. break;
  347. case HPI_OBJ_ADAPTER:
  348. adapter_message(pao, phm, phr);
  349. break;
  350. case HPI_OBJ_CONTROLEX:
  351. case HPI_OBJ_CONTROL:
  352. control_message(pao, phm, phr);
  353. break;
  354. case HPI_OBJ_OSTREAM:
  355. outstream_message(pao, phm, phr);
  356. break;
  357. case HPI_OBJ_ISTREAM:
  358. instream_message(pao, phm, phr);
  359. break;
  360. default:
  361. hw_message(pao, phm, phr);
  362. break;
  363. }
  364. break;
  365. default:
  366. phr->error = HPI_ERROR_INVALID_TYPE;
  367. break;
  368. }
  369. }
  370. /*****************************************************************************/
  371. /* SUBSYSTEM */
  372. /** Create an adapter object and initialise it based on resource information
  373. * passed in in the message
  374. * *** NOTE - you cannot use this function AND the FindAdapters function at the
  375. * same time, the application must use only one of them to get the adapters ***
  376. */
  377. static void subsys_create_adapter(struct hpi_message *phm,
  378. struct hpi_response *phr)
  379. {
  380. /* create temp adapter obj, because we don't know what index yet */
  381. struct hpi_adapter_obj ao;
  382. u32 os_error_code;
  383. u16 err;
  384. HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
  385. memset(&ao, 0, sizeof(ao));
  386. ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
  387. if (!ao.priv) {
  388. HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
  389. phr->error = HPI_ERROR_MEMORY_ALLOC;
  390. return;
  391. }
  392. ao.pci = *phm->u.s.resource.r.pci;
  393. err = create_adapter_obj(&ao, &os_error_code);
  394. if (err) {
  395. delete_adapter_obj(&ao);
  396. if (err >= HPI_ERROR_BACKEND_BASE) {
  397. phr->error = HPI_ERROR_DSP_BOOTLOAD;
  398. phr->specific_error = err;
  399. } else {
  400. phr->error = err;
  401. }
  402. phr->u.s.data = os_error_code;
  403. return;
  404. }
  405. phr->u.s.adapter_type = ao.adapter_type;
  406. phr->u.s.adapter_index = ao.index;
  407. phr->error = 0;
  408. }
  409. /** delete an adapter - required by WDM driver */
  410. static void subsys_delete_adapter(struct hpi_message *phm,
  411. struct hpi_response *phr)
  412. {
  413. struct hpi_adapter_obj *pao;
  414. struct hpi_hw_obj *phw;
  415. pao = hpi_find_adapter(phm->obj_index);
  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. /* no need to clean up as SubSysCreateAdapter */
  473. /* calls DeleteAdapter on error. */
  474. return err;
  475. HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
  476. /* allow boot load even if mem alloc wont work */
  477. if (!phw->p_interface_buffer)
  478. return HPI_ERROR_MEMORY_ALLOC;
  479. interface = phw->p_interface_buffer;
  480. /* make sure the DSP has started ok */
  481. if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
  482. HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
  483. return HPI6205_ERROR_6205_INIT_FAILED;
  484. }
  485. /* Note that *pao, *phw are zeroed after allocation,
  486. * so pointers and flags are NULL by default.
  487. * Allocate bus mastering control cache buffer and tell the DSP about it
  488. */
  489. if (interface->control_cache.number_of_controls) {
  490. u8 *p_control_cache_virtual;
  491. err = hpios_locked_mem_alloc(&phw->h_control_cache,
  492. interface->control_cache.size_in_bytes,
  493. pao->pci.pci_dev);
  494. if (!err)
  495. err = hpios_locked_mem_get_virt_addr(&phw->
  496. h_control_cache,
  497. (void *)&p_control_cache_virtual);
  498. if (!err) {
  499. memset(p_control_cache_virtual, 0,
  500. interface->control_cache.size_in_bytes);
  501. phw->p_cache =
  502. hpi_alloc_control_cache(interface->
  503. control_cache.number_of_controls,
  504. interface->control_cache.size_in_bytes,
  505. p_control_cache_virtual);
  506. if (!phw->p_cache)
  507. err = HPI_ERROR_MEMORY_ALLOC;
  508. }
  509. if (!err) {
  510. err = hpios_locked_mem_get_phys_addr(&phw->
  511. h_control_cache, &phys_addr);
  512. interface->control_cache.physical_address32 =
  513. phys_addr;
  514. }
  515. if (!err)
  516. pao->has_control_cache = 1;
  517. else {
  518. if (hpios_locked_mem_valid(&phw->h_control_cache))
  519. hpios_locked_mem_free(&phw->h_control_cache);
  520. pao->has_control_cache = 0;
  521. }
  522. }
  523. send_dsp_command(phw, H620_HIF_IDLE);
  524. {
  525. struct hpi_message hm;
  526. struct hpi_response hr;
  527. u32 max_streams;
  528. HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
  529. memset(&hm, 0, sizeof(hm));
  530. hm.type = HPI_TYPE_MESSAGE;
  531. hm.size = sizeof(hm);
  532. hm.object = HPI_OBJ_ADAPTER;
  533. hm.function = HPI_ADAPTER_GET_INFO;
  534. hm.adapter_index = 0;
  535. memset(&hr, 0, sizeof(hr));
  536. hr.size = sizeof(hr);
  537. err = message_response_sequence(pao, &hm, &hr);
  538. if (err) {
  539. HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
  540. err);
  541. return err;
  542. }
  543. if (hr.error)
  544. return hr.error;
  545. pao->adapter_type = hr.u.ax.info.adapter_type;
  546. pao->index = hr.u.ax.info.adapter_index;
  547. max_streams =
  548. hr.u.ax.info.num_outstreams +
  549. hr.u.ax.info.num_instreams;
  550. hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams,
  551. 65536, pao->pci.pci_dev);
  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 SubSysDeleteAdapter,
  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;
  570. int i;
  571. phw = pao->priv;
  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(0x5600):
  1079. case HPI_ADAPTER_FAMILY_ASI(0x6500):
  1080. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
  1081. break;
  1082. case HPI_ADAPTER_FAMILY_ASI(0x8800):
  1083. boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
  1084. break;
  1085. default:
  1086. break;
  1087. }
  1088. /* reset DSP by writing a 1 to the WARMRESET bit */
  1089. temp = C6205_HDCR_WARMRESET;
  1090. iowrite32(temp, phw->prHDCR);
  1091. hpios_delay_micro_seconds(1000);
  1092. /* check that PCI i/f was configured by EEPROM */
  1093. temp = ioread32(phw->prHSR);
  1094. if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
  1095. C6205_HSR_EEREAD)
  1096. return HPI6205_ERROR_6205_EEPROM;
  1097. temp |= 0x04;
  1098. /* disable PINTA interrupt */
  1099. iowrite32(temp, phw->prHSR);
  1100. /* check control register reports PCI boot mode */
  1101. temp = ioread32(phw->prHDCR);
  1102. if (!(temp & C6205_HDCR_PCIBOOT))
  1103. return HPI6205_ERROR_6205_REG;
  1104. /* try writing a few numbers to the DSP page register */
  1105. /* and reading them back. */
  1106. temp = 3;
  1107. iowrite32(temp, phw->prDSPP);
  1108. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1109. return HPI6205_ERROR_6205_DSPPAGE;
  1110. temp = 2;
  1111. iowrite32(temp, phw->prDSPP);
  1112. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1113. return HPI6205_ERROR_6205_DSPPAGE;
  1114. temp = 1;
  1115. iowrite32(temp, phw->prDSPP);
  1116. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1117. return HPI6205_ERROR_6205_DSPPAGE;
  1118. /* reset DSP page to the correct number */
  1119. temp = 0;
  1120. iowrite32(temp, phw->prDSPP);
  1121. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1122. return HPI6205_ERROR_6205_DSPPAGE;
  1123. phw->dsp_page = 0;
  1124. /* release 6713 from reset before 6205 is bootloaded.
  1125. This ensures that the EMIF is inactive,
  1126. and the 6713 HPI gets the correct bootmode etc
  1127. */
  1128. if (boot_code_id[1] != 0) {
  1129. /* DSP 1 is a C6713 */
  1130. /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
  1131. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
  1132. hpios_delay_micro_seconds(100);
  1133. /* Reset the 6713 #1 - revB */
  1134. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  1135. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1136. boot_loader_read_mem32(pao, 0, 0);
  1137. hpios_delay_micro_seconds(100);
  1138. /* Release C6713 from reset - revB */
  1139. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
  1140. hpios_delay_micro_seconds(100);
  1141. }
  1142. for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
  1143. /* is there a DSP to load? */
  1144. if (boot_code_id[dsp] == 0)
  1145. continue;
  1146. err = boot_loader_config_emif(pao, dsp);
  1147. if (err)
  1148. return err;
  1149. err = boot_loader_test_internal_memory(pao, dsp);
  1150. if (err)
  1151. return err;
  1152. err = boot_loader_test_external_memory(pao, dsp);
  1153. if (err)
  1154. return err;
  1155. err = boot_loader_test_pld(pao, dsp);
  1156. if (err)
  1157. return err;
  1158. /* write the DSP code down into the DSPs memory */
  1159. dsp_code.ps_dev = pao->pci.pci_dev;
  1160. err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
  1161. pos_error_code);
  1162. if (err)
  1163. return err;
  1164. while (1) {
  1165. u32 length;
  1166. u32 address;
  1167. u32 type;
  1168. u32 *pcode;
  1169. err = hpi_dsp_code_read_word(&dsp_code, &length);
  1170. if (err)
  1171. break;
  1172. if (length == 0xFFFFFFFF)
  1173. break; /* end of code */
  1174. err = hpi_dsp_code_read_word(&dsp_code, &address);
  1175. if (err)
  1176. break;
  1177. err = hpi_dsp_code_read_word(&dsp_code, &type);
  1178. if (err)
  1179. break;
  1180. err = hpi_dsp_code_read_block(length, &dsp_code,
  1181. &pcode);
  1182. if (err)
  1183. break;
  1184. for (i = 0; i < (int)length; i++) {
  1185. boot_loader_write_mem32(pao, dsp, address,
  1186. *pcode);
  1187. /* dummy read every 4 words */
  1188. /* for 6205 advisory 1.4.4 */
  1189. if (i % 4 == 0)
  1190. boot_loader_read_mem32(pao, dsp,
  1191. address);
  1192. pcode++;
  1193. address += 4;
  1194. }
  1195. }
  1196. if (err) {
  1197. hpi_dsp_code_close(&dsp_code);
  1198. return err;
  1199. }
  1200. /* verify code */
  1201. hpi_dsp_code_rewind(&dsp_code);
  1202. while (1) {
  1203. u32 length = 0;
  1204. u32 address = 0;
  1205. u32 type = 0;
  1206. u32 *pcode = NULL;
  1207. u32 data = 0;
  1208. hpi_dsp_code_read_word(&dsp_code, &length);
  1209. if (length == 0xFFFFFFFF)
  1210. break; /* end of code */
  1211. hpi_dsp_code_read_word(&dsp_code, &address);
  1212. hpi_dsp_code_read_word(&dsp_code, &type);
  1213. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  1214. for (i = 0; i < (int)length; i++) {
  1215. data = boot_loader_read_mem32(pao, dsp,
  1216. address);
  1217. if (data != *pcode) {
  1218. err = 0;
  1219. break;
  1220. }
  1221. pcode++;
  1222. address += 4;
  1223. }
  1224. if (err)
  1225. break;
  1226. }
  1227. hpi_dsp_code_close(&dsp_code);
  1228. if (err)
  1229. return err;
  1230. }
  1231. /* After bootloading all DSPs, start DSP0 running
  1232. * The DSP0 code will handle starting and synchronizing with its slaves
  1233. */
  1234. if (phw->p_interface_buffer) {
  1235. /* we need to tell the card the physical PCI address */
  1236. u32 physicalPC_iaddress;
  1237. struct bus_master_interface *interface =
  1238. phw->p_interface_buffer;
  1239. u32 host_mailbox_address_on_dsp;
  1240. u32 physicalPC_iaddress_verify = 0;
  1241. int time_out = 10;
  1242. /* set ack so we know when DSP is ready to go */
  1243. /* (dwDspAck will be changed to HIF_RESET) */
  1244. interface->dsp_ack = H620_HIF_UNKNOWN;
  1245. wmb(); /* ensure ack is written before dsp writes back */
  1246. err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
  1247. &physicalPC_iaddress);
  1248. /* locate the host mailbox on the DSP. */
  1249. host_mailbox_address_on_dsp = 0x80000000;
  1250. while ((physicalPC_iaddress != physicalPC_iaddress_verify)
  1251. && time_out--) {
  1252. boot_loader_write_mem32(pao, 0,
  1253. host_mailbox_address_on_dsp,
  1254. physicalPC_iaddress);
  1255. physicalPC_iaddress_verify =
  1256. boot_loader_read_mem32(pao, 0,
  1257. host_mailbox_address_on_dsp);
  1258. }
  1259. }
  1260. HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
  1261. /* enable interrupts */
  1262. temp = ioread32(phw->prHSR);
  1263. temp &= ~(u32)C6205_HSR_INTAM;
  1264. iowrite32(temp, phw->prHSR);
  1265. /* start code running... */
  1266. temp = ioread32(phw->prHDCR);
  1267. temp |= (u32)C6205_HDCR_DSPINT;
  1268. iowrite32(temp, phw->prHDCR);
  1269. /* give the DSP 10ms to start up */
  1270. hpios_delay_micro_seconds(10000);
  1271. return err;
  1272. }
  1273. /*****************************************************************************/
  1274. /* Bootloader utility functions */
  1275. static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  1276. u32 address)
  1277. {
  1278. struct hpi_hw_obj *phw = pao->priv;
  1279. u32 data = 0;
  1280. __iomem u32 *p_data;
  1281. if (dsp_index == 0) {
  1282. /* DSP 0 is always C6205 */
  1283. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1284. /* BAR1 register access */
  1285. p_data = pao->pci.ap_mem_base[1] +
  1286. (address & 0x007fffff) /
  1287. sizeof(*pao->pci.ap_mem_base[1]);
  1288. /* HPI_DEBUG_LOG(WARNING,
  1289. "BAR1 access %08x\n", dwAddress); */
  1290. } else {
  1291. u32 dw4M_page = address >> 22L;
  1292. if (dw4M_page != phw->dsp_page) {
  1293. phw->dsp_page = dw4M_page;
  1294. /* *INDENT OFF* */
  1295. iowrite32(phw->dsp_page, phw->prDSPP);
  1296. /* *INDENT-ON* */
  1297. }
  1298. address &= 0x3fffff; /* address within 4M page */
  1299. /* BAR0 memory access */
  1300. p_data = pao->pci.ap_mem_base[0] +
  1301. address / sizeof(u32);
  1302. }
  1303. data = ioread32(p_data);
  1304. } else if (dsp_index == 1) {
  1305. /* DSP 1 is a C6713 */
  1306. u32 lsb;
  1307. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1308. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1309. lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
  1310. data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
  1311. data = (data << 16) | (lsb & 0xFFFF);
  1312. }
  1313. return data;
  1314. }
  1315. static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
  1316. int dsp_index, u32 address, u32 data)
  1317. {
  1318. struct hpi_hw_obj *phw = pao->priv;
  1319. __iomem u32 *p_data;
  1320. /* u32 dwVerifyData=0; */
  1321. if (dsp_index == 0) {
  1322. /* DSP 0 is always C6205 */
  1323. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1324. /* BAR1 - DSP register access using */
  1325. /* Non-prefetchable PCI access */
  1326. p_data = pao->pci.ap_mem_base[1] +
  1327. (address & 0x007fffff) /
  1328. sizeof(*pao->pci.ap_mem_base[1]);
  1329. } else {
  1330. /* BAR0 access - all of DSP memory using */
  1331. /* pre-fetchable PCI access */
  1332. u32 dw4M_page = address >> 22L;
  1333. if (dw4M_page != phw->dsp_page) {
  1334. phw->dsp_page = dw4M_page;
  1335. /* *INDENT-OFF* */
  1336. iowrite32(phw->dsp_page, phw->prDSPP);
  1337. /* *INDENT-ON* */
  1338. }
  1339. address &= 0x3fffff; /* address within 4M page */
  1340. p_data = pao->pci.ap_mem_base[0] +
  1341. address / sizeof(u32);
  1342. }
  1343. iowrite32(data, p_data);
  1344. } else if (dsp_index == 1) {
  1345. /* DSP 1 is a C6713 */
  1346. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1347. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1348. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1349. boot_loader_read_mem32(pao, 0, 0);
  1350. boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
  1351. boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
  1352. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1353. boot_loader_read_mem32(pao, 0, 0);
  1354. }
  1355. }
  1356. static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
  1357. {
  1358. if (dsp_index == 0) {
  1359. u32 setting;
  1360. /* DSP 0 is always C6205 */
  1361. /* Set the EMIF */
  1362. /* memory map of C6205 */
  1363. /* 00000000-0000FFFF 16Kx32 internal program */
  1364. /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
  1365. /* EMIF config */
  1366. /*------------ */
  1367. /* Global EMIF control */
  1368. boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
  1369. #define WS_OFS 28
  1370. #define WST_OFS 22
  1371. #define WH_OFS 20
  1372. #define RS_OFS 16
  1373. #define RST_OFS 8
  1374. #define MTYPE_OFS 4
  1375. #define RH_OFS 0
  1376. /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
  1377. setting = 0x00000030;
  1378. boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
  1379. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1380. 0x01800008))
  1381. return HPI6205_ERROR_DSP_EMIF;
  1382. /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
  1383. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1384. /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
  1385. /* WST should be 71, but 63 is max possible */
  1386. setting =
  1387. (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
  1388. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1389. (2L << MTYPE_OFS);
  1390. boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
  1391. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1392. 0x01800004))
  1393. return HPI6205_ERROR_DSP_EMIF;
  1394. /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
  1395. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1396. /* plenty of wait states */
  1397. setting =
  1398. (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
  1399. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1400. (2L << MTYPE_OFS);
  1401. boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
  1402. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1403. 0x01800010))
  1404. return HPI6205_ERROR_DSP_EMIF;
  1405. /* EMIF CE3 setup - 32 bit async. */
  1406. /* This is the PLD on the ASI5000 cards only */
  1407. setting =
  1408. (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
  1409. (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
  1410. (2L << MTYPE_OFS);
  1411. boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
  1412. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1413. 0x01800014))
  1414. return HPI6205_ERROR_DSP_EMIF;
  1415. /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
  1416. /* need to use this else DSP code crashes? */
  1417. boot_loader_write_mem32(pao, dsp_index, 0x01800018,
  1418. 0x07117000);
  1419. /* EMIF SDRAM Refresh Timing */
  1420. /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
  1421. boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
  1422. 0x00000410);
  1423. } else if (dsp_index == 1) {
  1424. /* test access to the C6713s HPI registers */
  1425. u32 write_data = 0, read_data = 0, i = 0;
  1426. /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
  1427. write_data = 1;
  1428. boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
  1429. boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
  1430. /* C67 HPI is on lower 16bits of 32bit EMIF */
  1431. read_data =
  1432. 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
  1433. if (write_data != read_data) {
  1434. HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
  1435. read_data);
  1436. return HPI6205_ERROR_C6713_HPIC;
  1437. }
  1438. /* HPIA - walking ones test */
  1439. write_data = 1;
  1440. for (i = 0; i < 32; i++) {
  1441. boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
  1442. write_data);
  1443. boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
  1444. (write_data >> 16));
  1445. read_data =
  1446. 0xFFFF & boot_loader_read_mem32(pao, 0,
  1447. HPIAL_ADDR);
  1448. read_data =
  1449. read_data | ((0xFFFF &
  1450. boot_loader_read_mem32(pao, 0,
  1451. HPIAH_ADDR))
  1452. << 16);
  1453. if (read_data != write_data) {
  1454. HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
  1455. write_data, read_data);
  1456. return HPI6205_ERROR_C6713_HPIA;
  1457. }
  1458. write_data = write_data << 1;
  1459. }
  1460. /* setup C67x PLL
  1461. * ** C6713 datasheet says we cannot program PLL from HPI,
  1462. * and indeed if we try to set the PLL multiply from the HPI,
  1463. * the PLL does not seem to lock, so we enable the PLL and
  1464. * use the default multiply of x 7, which for a 27MHz clock
  1465. * gives a DSP speed of 189MHz
  1466. */
  1467. /* bypass PLL */
  1468. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
  1469. hpios_delay_micro_seconds(1000);
  1470. /* EMIF = 189/3=63MHz */
  1471. boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
  1472. /* peri = 189/2 */
  1473. boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
  1474. /* cpu = 189/1 */
  1475. boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
  1476. hpios_delay_micro_seconds(1000);
  1477. /* ** SGT test to take GPO3 high when we start the PLL */
  1478. /* and low when the delay is completed */
  1479. /* FSX0 <- '1' (GPO3) */
  1480. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
  1481. /* PLL not bypassed */
  1482. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
  1483. hpios_delay_micro_seconds(1000);
  1484. /* FSX0 <- '0' (GPO3) */
  1485. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
  1486. /* 6205 EMIF CE1 resetup - 32 bit async. */
  1487. /* Now 6713 #1 is running at 189MHz can reduce waitstates */
  1488. boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
  1489. (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
  1490. (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
  1491. (2L << MTYPE_OFS));
  1492. hpios_delay_micro_seconds(1000);
  1493. /* check that we can read one of the PLL registers */
  1494. /* PLL should not be bypassed! */
  1495. if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
  1496. != 0x0001) {
  1497. return HPI6205_ERROR_C6713_PLL;
  1498. }
  1499. /* setup C67x EMIF (note this is the only use of
  1500. BAR1 via BootLoader_WriteMem32) */
  1501. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
  1502. 0x000034A8);
  1503. /* EMIF CE0 setup - 2Mx32 Sync DRAM
  1504. 31..28 Wr setup
  1505. 27..22 Wr strobe
  1506. 21..20 Wr hold
  1507. 19..16 Rd setup
  1508. 15..14 -
  1509. 13..8 Rd strobe
  1510. 7..4 MTYPE 0011 Sync DRAM 32bits
  1511. 3 Wr hold MSB
  1512. 2..0 Rd hold
  1513. */
  1514. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
  1515. 0x00000030);
  1516. /* EMIF SDRAM Extension
  1517. 0x00
  1518. 31-21 0000b 0000b 000b
  1519. 20 WR2RD = 2cycles-1 = 1b
  1520. 19-18 WR2DEAC = 3cycle-1 = 10b
  1521. 17 WR2WR = 2cycle-1 = 1b
  1522. 16-15 R2WDQM = 4cycle-1 = 11b
  1523. 14-12 RD2WR = 6cycles-1 = 101b
  1524. 11-10 RD2DEAC = 4cycle-1 = 11b
  1525. 9 RD2RD = 2cycle-1 = 1b
  1526. 8-7 THZP = 3cycle-1 = 10b
  1527. 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
  1528. 4 TRRD = 2cycle = 0b (tRRD = 14ns)
  1529. 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
  1530. 1 CAS latency = 3cyc = 1b
  1531. (for Micron 2M32-7 operating at 100MHz)
  1532. */
  1533. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
  1534. 0x001BDF29);
  1535. /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
  1536. 31 - 0b -
  1537. 30 SDBSZ 1b 4 bank
  1538. 29..28 SDRSZ 00b 11 row address pins
  1539. 27..26 SDCSZ 01b 8 column address pins
  1540. 25 RFEN 1b refersh enabled
  1541. 24 INIT 1b init SDRAM!
  1542. 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
  1543. 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
  1544. 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
  1545. 11..0 - 0000b 0000b 0000b
  1546. */
  1547. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
  1548. 0x47116000);
  1549. /* SDRAM refresh timing
  1550. Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
  1551. */
  1552. boot_loader_write_mem32(pao, dsp_index,
  1553. C6713_EMIF_SDRAMTIMING, 0x00000410);
  1554. hpios_delay_micro_seconds(1000);
  1555. } else if (dsp_index == 2) {
  1556. /* DSP 2 is a C6713 */
  1557. }
  1558. return 0;
  1559. }
  1560. static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
  1561. u32 start_address, u32 length)
  1562. {
  1563. u32 i = 0, j = 0;
  1564. u32 test_addr = 0;
  1565. u32 test_data = 0, data = 0;
  1566. length = 1000;
  1567. /* for 1st word, test each bit in the 32bit word, */
  1568. /* dwLength specifies number of 32bit words to test */
  1569. /*for(i=0; i<dwLength; i++) */
  1570. i = 0;
  1571. {
  1572. test_addr = start_address + i * 4;
  1573. test_data = 0x00000001;
  1574. for (j = 0; j < 32; j++) {
  1575. boot_loader_write_mem32(pao, dsp_index, test_addr,
  1576. test_data);
  1577. data = boot_loader_read_mem32(pao, dsp_index,
  1578. test_addr);
  1579. if (data != test_data) {
  1580. HPI_DEBUG_LOG(VERBOSE,
  1581. "Memtest error details "
  1582. "%08x %08x %08x %i\n", test_addr,
  1583. test_data, data, dsp_index);
  1584. return 1; /* error */
  1585. }
  1586. test_data = test_data << 1;
  1587. } /* for(j) */
  1588. } /* for(i) */
  1589. /* for the next 100 locations test each location, leaving it as zero */
  1590. /* write a zero to the next word in memory before we read */
  1591. /* the previous write to make sure every memory location is unique */
  1592. for (i = 0; i < 100; i++) {
  1593. test_addr = start_address + i * 4;
  1594. test_data = 0xA5A55A5A;
  1595. boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
  1596. boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
  1597. data = boot_loader_read_mem32(pao, dsp_index, test_addr);
  1598. if (data != test_data) {
  1599. HPI_DEBUG_LOG(VERBOSE,
  1600. "Memtest error details "
  1601. "%08x %08x %08x %i\n", test_addr, test_data,
  1602. data, dsp_index);
  1603. return 1; /* error */
  1604. }
  1605. /* leave location as zero */
  1606. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1607. }
  1608. /* zero out entire memory block */
  1609. for (i = 0; i < length; i++) {
  1610. test_addr = start_address + i * 4;
  1611. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1612. }
  1613. return 0;
  1614. }
  1615. static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
  1616. int dsp_index)
  1617. {
  1618. int err = 0;
  1619. if (dsp_index == 0) {
  1620. /* DSP 0 is a C6205 */
  1621. /* 64K prog mem */
  1622. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1623. 0x10000);
  1624. if (!err)
  1625. /* 64K data mem */
  1626. err = boot_loader_test_memory(pao, dsp_index,
  1627. 0x80000000, 0x10000);
  1628. } else if (dsp_index == 1) {
  1629. /* DSP 1 is a C6713 */
  1630. /* 192K internal mem */
  1631. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1632. 0x30000);
  1633. if (!err)
  1634. /* 64K internal mem / L2 cache */
  1635. err = boot_loader_test_memory(pao, dsp_index,
  1636. 0x00030000, 0x10000);
  1637. }
  1638. if (err)
  1639. return HPI6205_ERROR_DSP_INTMEM;
  1640. else
  1641. return 0;
  1642. }
  1643. static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
  1644. int dsp_index)
  1645. {
  1646. u32 dRAM_start_address = 0;
  1647. u32 dRAM_size = 0;
  1648. if (dsp_index == 0) {
  1649. /* only test for SDRAM if an ASI5000 card */
  1650. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1651. /* DSP 0 is always C6205 */
  1652. dRAM_start_address = 0x00400000;
  1653. dRAM_size = 0x200000;
  1654. /*dwDRAMinc=1024; */
  1655. } else
  1656. return 0;
  1657. } else if (dsp_index == 1) {
  1658. /* DSP 1 is a C6713 */
  1659. dRAM_start_address = 0x80000000;
  1660. dRAM_size = 0x200000;
  1661. /*dwDRAMinc=1024; */
  1662. }
  1663. if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
  1664. dRAM_size))
  1665. return HPI6205_ERROR_DSP_EXTMEM;
  1666. return 0;
  1667. }
  1668. static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
  1669. {
  1670. u32 data = 0;
  1671. if (dsp_index == 0) {
  1672. /* only test for DSP0 PLD on ASI5000 card */
  1673. if (pao->pci.pci_dev->subsystem_device == 0x5000) {
  1674. /* PLD is located at CE3=0x03000000 */
  1675. data = boot_loader_read_mem32(pao, dsp_index,
  1676. 0x03000008);
  1677. if ((data & 0xF) != 0x5)
  1678. return HPI6205_ERROR_DSP_PLD;
  1679. data = boot_loader_read_mem32(pao, dsp_index,
  1680. 0x0300000C);
  1681. if ((data & 0xF) != 0xA)
  1682. return HPI6205_ERROR_DSP_PLD;
  1683. }
  1684. } else if (dsp_index == 1) {
  1685. /* DSP 1 is a C6713 */
  1686. if (pao->pci.pci_dev->subsystem_device == 0x8700) {
  1687. /* PLD is located at CE1=0x90000000 */
  1688. data = boot_loader_read_mem32(pao, dsp_index,
  1689. 0x90000010);
  1690. if ((data & 0xFF) != 0xAA)
  1691. return HPI6205_ERROR_DSP_PLD;
  1692. /* 8713 - LED on */
  1693. boot_loader_write_mem32(pao, dsp_index, 0x90000000,
  1694. 0x02);
  1695. }
  1696. }
  1697. return 0;
  1698. }
  1699. /** Transfer data to or from DSP
  1700. nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
  1701. */
  1702. static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
  1703. u32 data_size, int operation)
  1704. {
  1705. struct hpi_hw_obj *phw = pao->priv;
  1706. u32 data_transferred = 0;
  1707. u16 err = 0;
  1708. u32 temp2;
  1709. struct bus_master_interface *interface = phw->p_interface_buffer;
  1710. if (!p_data)
  1711. return HPI_ERROR_INVALID_DATA_POINTER;
  1712. data_size &= ~3L; /* round data_size down to nearest 4 bytes */
  1713. /* make sure state is IDLE */
  1714. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
  1715. return HPI_ERROR_DSP_HARDWARE;
  1716. while (data_transferred < data_size) {
  1717. u32 this_copy = data_size - data_transferred;
  1718. if (this_copy > HPI6205_SIZEOF_DATA)
  1719. this_copy = HPI6205_SIZEOF_DATA;
  1720. if (operation == H620_HIF_SEND_DATA)
  1721. memcpy((void *)&interface->u.b_data[0],
  1722. &p_data[data_transferred], this_copy);
  1723. interface->transfer_size_in_bytes = this_copy;
  1724. /* DSP must change this back to nOperation */
  1725. interface->dsp_ack = H620_HIF_IDLE;
  1726. send_dsp_command(phw, operation);
  1727. temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
  1728. HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
  1729. HPI6205_TIMEOUT - temp2, this_copy);
  1730. if (!temp2) {
  1731. /* timed out */
  1732. HPI_DEBUG_LOG(ERROR,
  1733. "Timed out waiting for " "state %d got %d\n",
  1734. operation, interface->dsp_ack);
  1735. break;
  1736. }
  1737. if (operation == H620_HIF_GET_DATA)
  1738. memcpy(&p_data[data_transferred],
  1739. (void *)&interface->u.b_data[0], this_copy);
  1740. data_transferred += this_copy;
  1741. }
  1742. if (interface->dsp_ack != operation)
  1743. HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
  1744. interface->dsp_ack, operation);
  1745. /* err=HPI_ERROR_DSP_HARDWARE; */
  1746. send_dsp_command(phw, H620_HIF_IDLE);
  1747. return err;
  1748. }
  1749. /* wait for up to timeout_us microseconds for the DSP
  1750. to signal state by DMA into dwDspAck
  1751. */
  1752. static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
  1753. {
  1754. struct bus_master_interface *interface = phw->p_interface_buffer;
  1755. int t = timeout_us / 4;
  1756. rmb(); /* ensure interface->dsp_ack is up to date */
  1757. while ((interface->dsp_ack != state) && --t) {
  1758. hpios_delay_micro_seconds(4);
  1759. rmb(); /* DSP changes dsp_ack by DMA */
  1760. }
  1761. /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
  1762. return t * 4;
  1763. }
  1764. /* set the busmaster interface to cmd, then interrupt the DSP */
  1765. static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
  1766. {
  1767. struct bus_master_interface *interface = phw->p_interface_buffer;
  1768. u32 r;
  1769. interface->host_cmd = cmd;
  1770. wmb(); /* DSP gets state by DMA, make sure it is written to memory */
  1771. /* before we interrupt the DSP */
  1772. r = ioread32(phw->prHDCR);
  1773. r |= (u32)C6205_HDCR_DSPINT;
  1774. iowrite32(r, phw->prHDCR);
  1775. r &= ~(u32)C6205_HDCR_DSPINT;
  1776. iowrite32(r, phw->prHDCR);
  1777. }
  1778. static unsigned int message_count;
  1779. static u16 message_response_sequence(struct hpi_adapter_obj *pao,
  1780. struct hpi_message *phm, struct hpi_response *phr)
  1781. {
  1782. u32 time_out, time_out2;
  1783. struct hpi_hw_obj *phw = pao->priv;
  1784. struct bus_master_interface *interface = phw->p_interface_buffer;
  1785. u16 err = 0;
  1786. message_count++;
  1787. if (phm->size > sizeof(interface->u)) {
  1788. phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
  1789. phr->specific_error = sizeof(interface->u);
  1790. phr->size = sizeof(struct hpi_response_header);
  1791. HPI_DEBUG_LOG(ERROR,
  1792. "message len %d too big for buffer %zd \n", phm->size,
  1793. sizeof(interface->u));
  1794. return 0;
  1795. }
  1796. /* Assume buffer of type struct bus_master_interface
  1797. is allocated "noncacheable" */
  1798. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1799. HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
  1800. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1801. }
  1802. memcpy(&interface->u.message_buffer, phm, phm->size);
  1803. /* signal we want a response */
  1804. send_dsp_command(phw, H620_HIF_GET_RESP);
  1805. time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
  1806. if (!time_out2) {
  1807. HPI_DEBUG_LOG(ERROR,
  1808. "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
  1809. message_count, interface->dsp_ack);
  1810. } else {
  1811. HPI_DEBUG_LOG(VERBOSE,
  1812. "(%u) transition to GET_RESP after %u\n",
  1813. message_count, HPI6205_TIMEOUT - time_out2);
  1814. }
  1815. /* spin waiting on HIF interrupt flag (end of msg process) */
  1816. time_out = HPI6205_TIMEOUT;
  1817. /* read the result */
  1818. if (time_out) {
  1819. if (interface->u.response_buffer.size <= phr->size)
  1820. memcpy(phr, &interface->u.response_buffer,
  1821. interface->u.response_buffer.size);
  1822. else {
  1823. HPI_DEBUG_LOG(ERROR,
  1824. "response len %d too big for buffer %d\n",
  1825. interface->u.response_buffer.size, phr->size);
  1826. memcpy(phr, &interface->u.response_buffer,
  1827. sizeof(struct hpi_response_header));
  1828. phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
  1829. phr->specific_error =
  1830. interface->u.response_buffer.size;
  1831. phr->size = sizeof(struct hpi_response_header);
  1832. }
  1833. }
  1834. /* set interface back to idle */
  1835. send_dsp_command(phw, H620_HIF_IDLE);
  1836. if (!time_out || !time_out2) {
  1837. HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
  1838. return HPI6205_ERROR_MSG_RESP_TIMEOUT;
  1839. }
  1840. /* special case for adapter close - */
  1841. /* wait for the DSP to indicate it is idle */
  1842. if (phm->function == HPI_ADAPTER_CLOSE) {
  1843. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1844. HPI_DEBUG_LOG(DEBUG,
  1845. "Timeout waiting for idle "
  1846. "(on adapter_close)\n");
  1847. return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1848. }
  1849. }
  1850. err = hpi_validate_response(phm, phr);
  1851. return err;
  1852. }
  1853. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1854. struct hpi_response *phr)
  1855. {
  1856. u16 err = 0;
  1857. hpios_dsplock_lock(pao);
  1858. err = message_response_sequence(pao, phm, phr);
  1859. /* maybe an error response */
  1860. if (err) {
  1861. /* something failed in the HPI/DSP interface */
  1862. if (err >= HPI_ERROR_BACKEND_BASE) {
  1863. phr->error = HPI_ERROR_DSP_COMMUNICATION;
  1864. phr->specific_error = err;
  1865. } else {
  1866. phr->error = err;
  1867. }
  1868. pao->dsp_crashed++;
  1869. /* just the header of the response is valid */
  1870. phr->size = sizeof(struct hpi_response_header);
  1871. goto err;
  1872. } else
  1873. pao->dsp_crashed = 0;
  1874. if (phr->error != 0) /* something failed in the DSP */
  1875. goto err;
  1876. switch (phm->function) {
  1877. case HPI_OSTREAM_WRITE:
  1878. case HPI_ISTREAM_ANC_WRITE:
  1879. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1880. phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
  1881. break;
  1882. case HPI_ISTREAM_READ:
  1883. case HPI_OSTREAM_ANC_READ:
  1884. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1885. phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
  1886. break;
  1887. case HPI_CONTROL_SET_STATE:
  1888. if (phm->object == HPI_OBJ_CONTROLEX
  1889. && phm->u.cx.attribute == HPI_COBRANET_SET_DATA)
  1890. err = hpi6205_transfer_data(pao,
  1891. phm->u.cx.u.cobranet_bigdata.pb_data,
  1892. phm->u.cx.u.cobranet_bigdata.byte_count,
  1893. H620_HIF_SEND_DATA);
  1894. break;
  1895. case HPI_CONTROL_GET_STATE:
  1896. if (phm->object == HPI_OBJ_CONTROLEX
  1897. && phm->u.cx.attribute == HPI_COBRANET_GET_DATA)
  1898. err = hpi6205_transfer_data(pao,
  1899. phm->u.cx.u.cobranet_bigdata.pb_data,
  1900. phr->u.cx.u.cobranet_data.byte_count,
  1901. H620_HIF_GET_DATA);
  1902. break;
  1903. }
  1904. phr->error = err;
  1905. err:
  1906. hpios_dsplock_unlock(pao);
  1907. return;
  1908. }