hpi6205.c 66 KB

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