hpi6205.c 65 KB

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