hpi6205.c 66 KB

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