hpi6205.c 64 KB

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