hpi6205.c 65 KB

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