hpi6205.c 67 KB

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