hpi6205.c 68 KB

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