hpi6205.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331
  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 long outstream_get_space_available(struct hpi_hostbuffer_status
  802. *status)
  803. {
  804. return status->size_in_bytes - ((long)(status->host_index) -
  805. (long)(status->dSP_index));
  806. }
  807. static void outstream_write(struct hpi_adapter_obj *pao,
  808. struct hpi_message *phm, struct hpi_response *phr)
  809. {
  810. struct hpi_hw_obj *phw = pao->priv;
  811. struct bus_master_interface *interface = phw->p_interface_buffer;
  812. struct hpi_hostbuffer_status *status;
  813. long space_available;
  814. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  815. /* there is no BBM buffer, write via message */
  816. hw_message(pao, phm, phr);
  817. return;
  818. }
  819. hpi_init_response(phr, phm->object, phm->function, 0);
  820. status = &interface->outstream_host_buffer_status[phm->obj_index];
  821. if (phw->flag_outstream_just_reset[phm->obj_index]) {
  822. /* Format can only change after reset. Must tell DSP. */
  823. u16 function = phm->function;
  824. phw->flag_outstream_just_reset[phm->obj_index] = 0;
  825. phm->function = HPI_OSTREAM_SET_FORMAT;
  826. hw_message(pao, phm, phr); /* send the format to the DSP */
  827. phm->function = function;
  828. if (phr->error)
  829. return;
  830. }
  831. #if 1
  832. if (phw->flag_outstream_just_reset[phm->obj_index]) {
  833. /* First OutStremWrite() call following reset will write data to the
  834. adapter's buffers, reducing delay before stream can start
  835. */
  836. int partial_write = 0;
  837. unsigned int original_size = 0;
  838. /* Send the first buffer to the DSP the old way. */
  839. /* Limit size of first transfer - */
  840. /* expect that this will not usually be triggered. */
  841. if (phm->u.d.u.data.data_size > HPI6205_SIZEOF_DATA) {
  842. partial_write = 1;
  843. original_size = phm->u.d.u.data.data_size;
  844. phm->u.d.u.data.data_size = HPI6205_SIZEOF_DATA;
  845. }
  846. /* write it */
  847. phm->function = HPI_OSTREAM_WRITE;
  848. hw_message(pao, phm, phr);
  849. /* update status information that the DSP would typically
  850. * update (and will update next time the DSP
  851. * buffer update task reads data from the host BBM buffer)
  852. */
  853. status->auxiliary_data_available = phm->u.d.u.data.data_size;
  854. status->host_index += phm->u.d.u.data.data_size;
  855. status->dSP_index += phm->u.d.u.data.data_size;
  856. /* if we did a full write, we can return from here. */
  857. if (!partial_write)
  858. return;
  859. /* tweak buffer parameters and let the rest of the */
  860. /* buffer land in internal BBM buffer */
  861. phm->u.d.u.data.data_size =
  862. original_size - HPI6205_SIZEOF_DATA;
  863. phm->u.d.u.data.pb_data += HPI6205_SIZEOF_DATA;
  864. }
  865. #endif
  866. space_available = outstream_get_space_available(status);
  867. if (space_available < (long)phm->u.d.u.data.data_size) {
  868. phr->error = HPI_ERROR_INVALID_DATASIZE;
  869. return;
  870. }
  871. /* HostBuffers is used to indicate host buffer is internally allocated.
  872. otherwise, assumed external, data written externally */
  873. if (phm->u.d.u.data.pb_data
  874. && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
  875. obj_index])) {
  876. u8 *p_bbm_data;
  877. long l_first_write;
  878. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  879. if (hpios_locked_mem_get_virt_addr(&phw->
  880. outstream_host_buffers[phm->obj_index],
  881. (void *)&p_bbm_data)) {
  882. phr->error = HPI_ERROR_INVALID_OPERATION;
  883. return;
  884. }
  885. /* either all data,
  886. or enough to fit from current to end of BBM buffer */
  887. l_first_write =
  888. min(phm->u.d.u.data.data_size,
  889. status->size_in_bytes -
  890. (status->host_index & (status->size_in_bytes - 1)));
  891. memcpy(p_bbm_data +
  892. (status->host_index & (status->size_in_bytes - 1)),
  893. p_app_data, l_first_write);
  894. /* remaining data if any */
  895. memcpy(p_bbm_data, p_app_data + l_first_write,
  896. phm->u.d.u.data.data_size - l_first_write);
  897. }
  898. status->host_index += phm->u.d.u.data.data_size;
  899. }
  900. static void outstream_get_info(struct hpi_adapter_obj *pao,
  901. struct hpi_message *phm, struct hpi_response *phr)
  902. {
  903. struct hpi_hw_obj *phw = pao->priv;
  904. struct bus_master_interface *interface = phw->p_interface_buffer;
  905. struct hpi_hostbuffer_status *status;
  906. if (!phw->outstream_host_buffer_size[phm->obj_index]) {
  907. hw_message(pao, phm, phr);
  908. return;
  909. }
  910. hpi_init_response(phr, phm->object, phm->function, 0);
  911. status = &interface->outstream_host_buffer_status[phm->obj_index];
  912. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  913. phr->u.d.u.stream_info.samples_transferred =
  914. status->samples_processed;
  915. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  916. phr->u.d.u.stream_info.data_available =
  917. status->size_in_bytes - outstream_get_space_available(status);
  918. phr->u.d.u.stream_info.auxiliary_data_available =
  919. status->auxiliary_data_available;
  920. }
  921. static void outstream_start(struct hpi_adapter_obj *pao,
  922. struct hpi_message *phm, struct hpi_response *phr)
  923. {
  924. hw_message(pao, phm, phr);
  925. }
  926. static void outstream_reset(struct hpi_adapter_obj *pao,
  927. struct hpi_message *phm, struct hpi_response *phr)
  928. {
  929. struct hpi_hw_obj *phw = pao->priv;
  930. phw->flag_outstream_just_reset[phm->obj_index] = 1;
  931. hw_message(pao, phm, phr);
  932. }
  933. static void outstream_open(struct hpi_adapter_obj *pao,
  934. struct hpi_message *phm, struct hpi_response *phr)
  935. {
  936. outstream_reset(pao, phm, phr);
  937. }
  938. /*****************************************************************************/
  939. /* InStream Host buffer functions */
  940. static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
  941. struct hpi_message *phm, struct hpi_response *phr)
  942. {
  943. u16 err = 0;
  944. u32 command = phm->u.d.u.buffer.command;
  945. struct hpi_hw_obj *phw = pao->priv;
  946. struct bus_master_interface *interface = phw->p_interface_buffer;
  947. hpi_init_response(phr, phm->object, phm->function, 0);
  948. if (command == HPI_BUFFER_CMD_EXTERNAL
  949. || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
  950. phm->u.d.u.buffer.buffer_size =
  951. roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
  952. phr->u.d.u.stream_info.data_available =
  953. phw->instream_host_buffer_size[phm->obj_index];
  954. phr->u.d.u.stream_info.buffer_size =
  955. phm->u.d.u.buffer.buffer_size;
  956. if (phw->instream_host_buffer_size[phm->obj_index] ==
  957. phm->u.d.u.buffer.buffer_size) {
  958. /* Same size, no action required */
  959. return;
  960. }
  961. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  962. obj_index]))
  963. hpios_locked_mem_free(&phw->instream_host_buffers
  964. [phm->obj_index]);
  965. err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
  966. obj_index], phm->u.d.u.buffer.buffer_size,
  967. pao->pci.p_os_data);
  968. if (err) {
  969. phr->error = HPI_ERROR_INVALID_DATASIZE;
  970. phw->instream_host_buffer_size[phm->obj_index] = 0;
  971. return;
  972. }
  973. err = hpios_locked_mem_get_phys_addr
  974. (&phw->instream_host_buffers[phm->obj_index],
  975. &phm->u.d.u.buffer.pci_address);
  976. /* get the phys addr into msg for single call alloc. Caller
  977. needs to do this for split alloc so return the phy address */
  978. phr->u.d.u.stream_info.auxiliary_data_available =
  979. phm->u.d.u.buffer.pci_address;
  980. if (err) {
  981. hpios_locked_mem_free(&phw->instream_host_buffers
  982. [phm->obj_index]);
  983. phw->instream_host_buffer_size[phm->obj_index] = 0;
  984. phr->error = HPI_ERROR_MEMORY_ALLOC;
  985. return;
  986. }
  987. }
  988. if (command == HPI_BUFFER_CMD_EXTERNAL
  989. || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
  990. struct hpi_hostbuffer_status *status;
  991. if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
  992. buffer_size - 1)) {
  993. HPI_DEBUG_LOG(ERROR,
  994. "buffer size must be 2^N not %d\n",
  995. phm->u.d.u.buffer.buffer_size);
  996. phr->error = HPI_ERROR_INVALID_DATASIZE;
  997. return;
  998. }
  999. phw->instream_host_buffer_size[phm->obj_index] =
  1000. phm->u.d.u.buffer.buffer_size;
  1001. status = &interface->instream_host_buffer_status[phm->
  1002. obj_index];
  1003. status->samples_processed = 0;
  1004. status->stream_state = HPI_STATE_STOPPED;
  1005. status->dSP_index = 0;
  1006. status->host_index = status->dSP_index;
  1007. status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
  1008. hw_message(pao, phm, phr);
  1009. if (phr->error
  1010. && hpios_locked_mem_valid(&phw->
  1011. instream_host_buffers[phm->obj_index])) {
  1012. hpios_locked_mem_free(&phw->instream_host_buffers
  1013. [phm->obj_index]);
  1014. phw->instream_host_buffer_size[phm->obj_index] = 0;
  1015. }
  1016. }
  1017. }
  1018. static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
  1019. struct hpi_message *phm, struct hpi_response *phr)
  1020. {
  1021. struct hpi_hw_obj *phw = pao->priv;
  1022. struct bus_master_interface *interface = phw->p_interface_buffer;
  1023. struct hpi_hostbuffer_status *status;
  1024. u8 *p_bbm_data;
  1025. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  1026. obj_index])) {
  1027. if (hpios_locked_mem_get_virt_addr(&phw->
  1028. instream_host_buffers[phm->obj_index],
  1029. (void *)&p_bbm_data)) {
  1030. phr->error = HPI_ERROR_INVALID_OPERATION;
  1031. return;
  1032. }
  1033. status = &interface->instream_host_buffer_status[phm->
  1034. obj_index];
  1035. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  1036. HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
  1037. phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
  1038. phr->u.d.u.hostbuffer_info.p_status = status;
  1039. } else {
  1040. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  1041. HPI_ISTREAM_HOSTBUFFER_GET_INFO,
  1042. HPI_ERROR_INVALID_OPERATION);
  1043. }
  1044. }
  1045. static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
  1046. struct hpi_message *phm, struct hpi_response *phr)
  1047. {
  1048. struct hpi_hw_obj *phw = pao->priv;
  1049. u32 command = phm->u.d.u.buffer.command;
  1050. if (phw->instream_host_buffer_size[phm->obj_index]) {
  1051. if (command == HPI_BUFFER_CMD_EXTERNAL
  1052. || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
  1053. phw->instream_host_buffer_size[phm->obj_index] = 0;
  1054. hw_message(pao, phm, phr);
  1055. }
  1056. if (command == HPI_BUFFER_CMD_EXTERNAL
  1057. || command == HPI_BUFFER_CMD_INTERNAL_FREE)
  1058. hpios_locked_mem_free(&phw->instream_host_buffers
  1059. [phm->obj_index]);
  1060. } else {
  1061. /* Should HPI_ERROR_INVALID_OPERATION be returned
  1062. if no host buffer is allocated? */
  1063. hpi_init_response(phr, HPI_OBJ_ISTREAM,
  1064. HPI_ISTREAM_HOSTBUFFER_FREE, 0);
  1065. }
  1066. }
  1067. static void instream_start(struct hpi_adapter_obj *pao,
  1068. struct hpi_message *phm, struct hpi_response *phr)
  1069. {
  1070. hw_message(pao, phm, phr);
  1071. }
  1072. static long instream_get_bytes_available(struct hpi_hostbuffer_status *status)
  1073. {
  1074. return (long)(status->dSP_index) - (long)(status->host_index);
  1075. }
  1076. static void instream_read(struct hpi_adapter_obj *pao,
  1077. struct hpi_message *phm, struct hpi_response *phr)
  1078. {
  1079. struct hpi_hw_obj *phw = pao->priv;
  1080. struct bus_master_interface *interface = phw->p_interface_buffer;
  1081. struct hpi_hostbuffer_status *status;
  1082. long data_available;
  1083. u8 *p_bbm_data;
  1084. long l_first_read;
  1085. u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
  1086. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  1087. hw_message(pao, phm, phr);
  1088. return;
  1089. }
  1090. hpi_init_response(phr, phm->object, phm->function, 0);
  1091. status = &interface->instream_host_buffer_status[phm->obj_index];
  1092. data_available = instream_get_bytes_available(status);
  1093. if (data_available < (long)phm->u.d.u.data.data_size) {
  1094. phr->error = HPI_ERROR_INVALID_DATASIZE;
  1095. return;
  1096. }
  1097. if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
  1098. obj_index])) {
  1099. if (hpios_locked_mem_get_virt_addr(&phw->
  1100. instream_host_buffers[phm->obj_index],
  1101. (void *)&p_bbm_data)) {
  1102. phr->error = HPI_ERROR_INVALID_OPERATION;
  1103. return;
  1104. }
  1105. /* either all data,
  1106. or enough to fit from current to end of BBM buffer */
  1107. l_first_read =
  1108. min(phm->u.d.u.data.data_size,
  1109. status->size_in_bytes -
  1110. (status->host_index & (status->size_in_bytes - 1)));
  1111. memcpy(p_app_data,
  1112. p_bbm_data +
  1113. (status->host_index & (status->size_in_bytes - 1)),
  1114. l_first_read);
  1115. /* remaining data if any */
  1116. memcpy(p_app_data + l_first_read, p_bbm_data,
  1117. phm->u.d.u.data.data_size - l_first_read);
  1118. }
  1119. status->host_index += phm->u.d.u.data.data_size;
  1120. }
  1121. static void instream_get_info(struct hpi_adapter_obj *pao,
  1122. struct hpi_message *phm, struct hpi_response *phr)
  1123. {
  1124. struct hpi_hw_obj *phw = pao->priv;
  1125. struct bus_master_interface *interface = phw->p_interface_buffer;
  1126. struct hpi_hostbuffer_status *status;
  1127. if (!phw->instream_host_buffer_size[phm->obj_index]) {
  1128. hw_message(pao, phm, phr);
  1129. return;
  1130. }
  1131. status = &interface->instream_host_buffer_status[phm->obj_index];
  1132. hpi_init_response(phr, phm->object, phm->function, 0);
  1133. phr->u.d.u.stream_info.state = (u16)status->stream_state;
  1134. phr->u.d.u.stream_info.samples_transferred =
  1135. status->samples_processed;
  1136. phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
  1137. phr->u.d.u.stream_info.data_available =
  1138. instream_get_bytes_available(status);
  1139. phr->u.d.u.stream_info.auxiliary_data_available =
  1140. status->auxiliary_data_available;
  1141. }
  1142. /*****************************************************************************/
  1143. /* LOW-LEVEL */
  1144. #define HPI6205_MAX_FILES_TO_LOAD 2
  1145. static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  1146. u32 *pos_error_code)
  1147. {
  1148. struct hpi_hw_obj *phw = pao->priv;
  1149. struct dsp_code dsp_code;
  1150. u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
  1151. u16 firmware_id = pao->pci.subsys_device_id;
  1152. u32 temp;
  1153. int dsp = 0, i = 0;
  1154. u16 err = 0;
  1155. boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
  1156. /* special cases where firmware_id != subsys ID */
  1157. switch (firmware_id) {
  1158. case HPI_ADAPTER_FAMILY_ASI(0x5000):
  1159. boot_code_id[0] = firmware_id;
  1160. firmware_id = 0;
  1161. break;
  1162. case HPI_ADAPTER_FAMILY_ASI(0x5300):
  1163. case HPI_ADAPTER_FAMILY_ASI(0x5400):
  1164. case HPI_ADAPTER_FAMILY_ASI(0x6300):
  1165. firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6400);
  1166. break;
  1167. case HPI_ADAPTER_FAMILY_ASI(0x5600):
  1168. case HPI_ADAPTER_FAMILY_ASI(0x6500):
  1169. firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6600);
  1170. break;
  1171. }
  1172. boot_code_id[1] = firmware_id;
  1173. /* reset DSP by writing a 1 to the WARMRESET bit */
  1174. temp = C6205_HDCR_WARMRESET;
  1175. iowrite32(temp, phw->prHDCR);
  1176. hpios_delay_micro_seconds(1000);
  1177. /* check that PCI i/f was configured by EEPROM */
  1178. temp = ioread32(phw->prHSR);
  1179. if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
  1180. C6205_HSR_EEREAD)
  1181. return hpi6205_error(0, HPI6205_ERROR_6205_EEPROM);
  1182. temp |= 0x04;
  1183. /* disable PINTA interrupt */
  1184. iowrite32(temp, phw->prHSR);
  1185. /* check control register reports PCI boot mode */
  1186. temp = ioread32(phw->prHDCR);
  1187. if (!(temp & C6205_HDCR_PCIBOOT))
  1188. return hpi6205_error(0, HPI6205_ERROR_6205_REG);
  1189. /* try writing a couple of numbers to the DSP page register */
  1190. /* and reading them back. */
  1191. temp = 1;
  1192. iowrite32(temp, phw->prDSPP);
  1193. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1194. return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
  1195. temp = 2;
  1196. iowrite32(temp, phw->prDSPP);
  1197. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1198. return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
  1199. temp = 3;
  1200. iowrite32(temp, phw->prDSPP);
  1201. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1202. return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
  1203. /* reset DSP page to the correct number */
  1204. temp = 0;
  1205. iowrite32(temp, phw->prDSPP);
  1206. if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
  1207. return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
  1208. phw->dsp_page = 0;
  1209. /* release 6713 from reset before 6205 is bootloaded.
  1210. This ensures that the EMIF is inactive,
  1211. and the 6713 HPI gets the correct bootmode etc
  1212. */
  1213. if (boot_code_id[1] != 0) {
  1214. /* DSP 1 is a C6713 */
  1215. /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
  1216. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
  1217. hpios_delay_micro_seconds(100);
  1218. /* Reset the 6713 #1 - revB */
  1219. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
  1220. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1221. boot_loader_read_mem32(pao, 0, 0);
  1222. hpios_delay_micro_seconds(100);
  1223. /* Release C6713 from reset - revB */
  1224. boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
  1225. hpios_delay_micro_seconds(100);
  1226. }
  1227. for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
  1228. /* is there a DSP to load? */
  1229. if (boot_code_id[dsp] == 0)
  1230. continue;
  1231. err = boot_loader_config_emif(pao, dsp);
  1232. if (err)
  1233. return err;
  1234. err = boot_loader_test_internal_memory(pao, dsp);
  1235. if (err)
  1236. return err;
  1237. err = boot_loader_test_external_memory(pao, dsp);
  1238. if (err)
  1239. return err;
  1240. err = boot_loader_test_pld(pao, dsp);
  1241. if (err)
  1242. return err;
  1243. /* write the DSP code down into the DSPs memory */
  1244. dsp_code.ps_dev = pao->pci.p_os_data;
  1245. err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
  1246. pos_error_code);
  1247. if (err)
  1248. return err;
  1249. while (1) {
  1250. u32 length;
  1251. u32 address;
  1252. u32 type;
  1253. u32 *pcode;
  1254. err = hpi_dsp_code_read_word(&dsp_code, &length);
  1255. if (err)
  1256. break;
  1257. if (length == 0xFFFFFFFF)
  1258. break; /* end of code */
  1259. err = hpi_dsp_code_read_word(&dsp_code, &address);
  1260. if (err)
  1261. break;
  1262. err = hpi_dsp_code_read_word(&dsp_code, &type);
  1263. if (err)
  1264. break;
  1265. err = hpi_dsp_code_read_block(length, &dsp_code,
  1266. &pcode);
  1267. if (err)
  1268. break;
  1269. for (i = 0; i < (int)length; i++) {
  1270. err = boot_loader_write_mem32(pao, dsp,
  1271. address, *pcode);
  1272. if (err)
  1273. break;
  1274. /* dummy read every 4 words */
  1275. /* for 6205 advisory 1.4.4 */
  1276. if (i % 4 == 0)
  1277. boot_loader_read_mem32(pao, dsp,
  1278. address);
  1279. pcode++;
  1280. address += 4;
  1281. }
  1282. }
  1283. if (err) {
  1284. hpi_dsp_code_close(&dsp_code);
  1285. return err;
  1286. }
  1287. /* verify code */
  1288. hpi_dsp_code_rewind(&dsp_code);
  1289. while (1) {
  1290. u32 length = 0;
  1291. u32 address = 0;
  1292. u32 type = 0;
  1293. u32 *pcode = NULL;
  1294. u32 data = 0;
  1295. hpi_dsp_code_read_word(&dsp_code, &length);
  1296. if (length == 0xFFFFFFFF)
  1297. break; /* end of code */
  1298. hpi_dsp_code_read_word(&dsp_code, &address);
  1299. hpi_dsp_code_read_word(&dsp_code, &type);
  1300. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  1301. for (i = 0; i < (int)length; i++) {
  1302. data = boot_loader_read_mem32(pao, dsp,
  1303. address);
  1304. if (data != *pcode) {
  1305. err = 0;
  1306. break;
  1307. }
  1308. pcode++;
  1309. address += 4;
  1310. }
  1311. if (err)
  1312. break;
  1313. }
  1314. hpi_dsp_code_close(&dsp_code);
  1315. if (err)
  1316. return err;
  1317. }
  1318. /* After bootloading all DSPs, start DSP0 running
  1319. * The DSP0 code will handle starting and synchronizing with its slaves
  1320. */
  1321. if (phw->p_interface_buffer) {
  1322. /* we need to tell the card the physical PCI address */
  1323. u32 physicalPC_iaddress;
  1324. struct bus_master_interface *interface =
  1325. phw->p_interface_buffer;
  1326. u32 host_mailbox_address_on_dsp;
  1327. u32 physicalPC_iaddress_verify = 0;
  1328. int time_out = 10;
  1329. /* set ack so we know when DSP is ready to go */
  1330. /* (dwDspAck will be changed to HIF_RESET) */
  1331. interface->dsp_ack = H620_HIF_UNKNOWN;
  1332. wmb(); /* ensure ack is written before dsp writes back */
  1333. err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
  1334. &physicalPC_iaddress);
  1335. /* locate the host mailbox on the DSP. */
  1336. host_mailbox_address_on_dsp = 0x80000000;
  1337. while ((physicalPC_iaddress != physicalPC_iaddress_verify)
  1338. && time_out--) {
  1339. err = boot_loader_write_mem32(pao, 0,
  1340. host_mailbox_address_on_dsp,
  1341. physicalPC_iaddress);
  1342. physicalPC_iaddress_verify =
  1343. boot_loader_read_mem32(pao, 0,
  1344. host_mailbox_address_on_dsp);
  1345. }
  1346. }
  1347. HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
  1348. /* enable interrupts */
  1349. temp = ioread32(phw->prHSR);
  1350. temp &= ~(u32)C6205_HSR_INTAM;
  1351. iowrite32(temp, phw->prHSR);
  1352. /* start code running... */
  1353. temp = ioread32(phw->prHDCR);
  1354. temp |= (u32)C6205_HDCR_DSPINT;
  1355. iowrite32(temp, phw->prHDCR);
  1356. /* give the DSP 10ms to start up */
  1357. hpios_delay_micro_seconds(10000);
  1358. return err;
  1359. }
  1360. /*****************************************************************************/
  1361. /* Bootloader utility functions */
  1362. static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  1363. u32 address)
  1364. {
  1365. struct hpi_hw_obj *phw = pao->priv;
  1366. u32 data = 0;
  1367. __iomem u32 *p_data;
  1368. if (dsp_index == 0) {
  1369. /* DSP 0 is always C6205 */
  1370. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1371. /* BAR1 register access */
  1372. p_data = pao->pci.ap_mem_base[1] +
  1373. (address & 0x007fffff) /
  1374. sizeof(*pao->pci.ap_mem_base[1]);
  1375. /* HPI_DEBUG_LOG(WARNING,
  1376. "BAR1 access %08x\n", dwAddress); */
  1377. } else {
  1378. u32 dw4M_page = address >> 22L;
  1379. if (dw4M_page != phw->dsp_page) {
  1380. phw->dsp_page = dw4M_page;
  1381. /* *INDENT OFF* */
  1382. iowrite32(phw->dsp_page, phw->prDSPP);
  1383. /* *INDENT-ON* */
  1384. }
  1385. address &= 0x3fffff; /* address within 4M page */
  1386. /* BAR0 memory access */
  1387. p_data = pao->pci.ap_mem_base[0] +
  1388. address / sizeof(u32);
  1389. }
  1390. data = ioread32(p_data);
  1391. } else if (dsp_index == 1) {
  1392. /* DSP 1 is a C6713 */
  1393. u32 lsb;
  1394. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1395. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1396. lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
  1397. data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
  1398. data = (data << 16) | (lsb & 0xFFFF);
  1399. }
  1400. return data;
  1401. }
  1402. static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
  1403. u32 address, u32 data)
  1404. {
  1405. struct hpi_hw_obj *phw = pao->priv;
  1406. u16 err = 0;
  1407. __iomem u32 *p_data;
  1408. /* u32 dwVerifyData=0; */
  1409. if (dsp_index == 0) {
  1410. /* DSP 0 is always C6205 */
  1411. if ((address >= 0x01800000) & (address < 0x02000000)) {
  1412. /* BAR1 - DSP register access using */
  1413. /* Non-prefetchable PCI access */
  1414. p_data = pao->pci.ap_mem_base[1] +
  1415. (address & 0x007fffff) /
  1416. sizeof(*pao->pci.ap_mem_base[1]);
  1417. } else {
  1418. /* BAR0 access - all of DSP memory using */
  1419. /* pre-fetchable PCI access */
  1420. u32 dw4M_page = address >> 22L;
  1421. if (dw4M_page != phw->dsp_page) {
  1422. phw->dsp_page = dw4M_page;
  1423. /* *INDENT-OFF* */
  1424. iowrite32(phw->dsp_page, phw->prDSPP);
  1425. /* *INDENT-ON* */
  1426. }
  1427. address &= 0x3fffff; /* address within 4M page */
  1428. p_data = pao->pci.ap_mem_base[0] +
  1429. address / sizeof(u32);
  1430. }
  1431. iowrite32(data, p_data);
  1432. } else if (dsp_index == 1) {
  1433. /* DSP 1 is a C6713 */
  1434. boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
  1435. boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
  1436. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1437. boot_loader_read_mem32(pao, 0, 0);
  1438. boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
  1439. boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
  1440. /* dummy read every 4 words for 6205 advisory 1.4.4 */
  1441. boot_loader_read_mem32(pao, 0, 0);
  1442. } else
  1443. err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
  1444. return err;
  1445. }
  1446. static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
  1447. {
  1448. u16 err = 0;
  1449. if (dsp_index == 0) {
  1450. u32 setting;
  1451. /* DSP 0 is always C6205 */
  1452. /* Set the EMIF */
  1453. /* memory map of C6205 */
  1454. /* 00000000-0000FFFF 16Kx32 internal program */
  1455. /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
  1456. /* EMIF config */
  1457. /*------------ */
  1458. /* Global EMIF control */
  1459. boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
  1460. #define WS_OFS 28
  1461. #define WST_OFS 22
  1462. #define WH_OFS 20
  1463. #define RS_OFS 16
  1464. #define RST_OFS 8
  1465. #define MTYPE_OFS 4
  1466. #define RH_OFS 0
  1467. /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
  1468. setting = 0x00000030;
  1469. boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
  1470. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1471. 0x01800008))
  1472. return hpi6205_error(dsp_index,
  1473. HPI6205_ERROR_DSP_EMIF);
  1474. /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
  1475. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1476. /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
  1477. /* WST should be 71, but 63 is max possible */
  1478. setting =
  1479. (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
  1480. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1481. (2L << MTYPE_OFS);
  1482. boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
  1483. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1484. 0x01800004))
  1485. return hpi6205_error(dsp_index,
  1486. HPI6205_ERROR_DSP_EMIF);
  1487. /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
  1488. /* which occupies D15..0. 6713 starts at 27MHz, so need */
  1489. /* plenty of wait states */
  1490. setting =
  1491. (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
  1492. (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
  1493. (2L << MTYPE_OFS);
  1494. boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
  1495. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1496. 0x01800010))
  1497. return hpi6205_error(dsp_index,
  1498. HPI6205_ERROR_DSP_EMIF);
  1499. /* EMIF CE3 setup - 32 bit async. */
  1500. /* This is the PLD on the ASI5000 cards only */
  1501. setting =
  1502. (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
  1503. (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
  1504. (2L << MTYPE_OFS);
  1505. boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
  1506. if (setting != boot_loader_read_mem32(pao, dsp_index,
  1507. 0x01800014))
  1508. return hpi6205_error(dsp_index,
  1509. HPI6205_ERROR_DSP_EMIF);
  1510. /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
  1511. /* need to use this else DSP code crashes? */
  1512. boot_loader_write_mem32(pao, dsp_index, 0x01800018,
  1513. 0x07117000);
  1514. /* EMIF SDRAM Refresh Timing */
  1515. /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
  1516. boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
  1517. 0x00000410);
  1518. } else if (dsp_index == 1) {
  1519. /* test access to the C6713s HPI registers */
  1520. u32 write_data = 0, read_data = 0, i = 0;
  1521. /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
  1522. write_data = 1;
  1523. boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
  1524. boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
  1525. /* C67 HPI is on lower 16bits of 32bit EMIF */
  1526. read_data =
  1527. 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
  1528. if (write_data != read_data) {
  1529. err = hpi6205_error(dsp_index,
  1530. HPI6205_ERROR_C6713_HPIC);
  1531. HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
  1532. read_data);
  1533. return err;
  1534. }
  1535. /* HPIA - walking ones test */
  1536. write_data = 1;
  1537. for (i = 0; i < 32; i++) {
  1538. boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
  1539. write_data);
  1540. boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
  1541. (write_data >> 16));
  1542. read_data =
  1543. 0xFFFF & boot_loader_read_mem32(pao, 0,
  1544. HPIAL_ADDR);
  1545. read_data =
  1546. read_data | ((0xFFFF &
  1547. boot_loader_read_mem32(pao, 0,
  1548. HPIAH_ADDR))
  1549. << 16);
  1550. if (read_data != write_data) {
  1551. err = hpi6205_error(dsp_index,
  1552. HPI6205_ERROR_C6713_HPIA);
  1553. HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
  1554. write_data, read_data);
  1555. return err;
  1556. }
  1557. write_data = write_data << 1;
  1558. }
  1559. /* setup C67x PLL
  1560. * ** C6713 datasheet says we cannot program PLL from HPI,
  1561. * and indeed if we try to set the PLL multiply from the HPI,
  1562. * the PLL does not seem to lock, so we enable the PLL and
  1563. * use the default multiply of x 7, which for a 27MHz clock
  1564. * gives a DSP speed of 189MHz
  1565. */
  1566. /* bypass PLL */
  1567. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
  1568. hpios_delay_micro_seconds(1000);
  1569. /* EMIF = 189/3=63MHz */
  1570. boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
  1571. /* peri = 189/2 */
  1572. boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
  1573. /* cpu = 189/1 */
  1574. boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
  1575. hpios_delay_micro_seconds(1000);
  1576. /* ** SGT test to take GPO3 high when we start the PLL */
  1577. /* and low when the delay is completed */
  1578. /* FSX0 <- '1' (GPO3) */
  1579. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
  1580. /* PLL not bypassed */
  1581. boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
  1582. hpios_delay_micro_seconds(1000);
  1583. /* FSX0 <- '0' (GPO3) */
  1584. boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
  1585. /* 6205 EMIF CE1 resetup - 32 bit async. */
  1586. /* Now 6713 #1 is running at 189MHz can reduce waitstates */
  1587. boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
  1588. (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
  1589. (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
  1590. (2L << MTYPE_OFS));
  1591. hpios_delay_micro_seconds(1000);
  1592. /* check that we can read one of the PLL registers */
  1593. /* PLL should not be bypassed! */
  1594. if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
  1595. != 0x0001) {
  1596. err = hpi6205_error(dsp_index,
  1597. HPI6205_ERROR_C6713_PLL);
  1598. return err;
  1599. }
  1600. /* setup C67x EMIF (note this is the only use of
  1601. BAR1 via BootLoader_WriteMem32) */
  1602. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
  1603. 0x000034A8);
  1604. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
  1605. 0x00000030);
  1606. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
  1607. 0x001BDF29);
  1608. boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
  1609. 0x47117000);
  1610. boot_loader_write_mem32(pao, dsp_index,
  1611. C6713_EMIF_SDRAMTIMING, 0x00000410);
  1612. hpios_delay_micro_seconds(1000);
  1613. } else if (dsp_index == 2) {
  1614. /* DSP 2 is a C6713 */
  1615. } else
  1616. err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
  1617. return err;
  1618. }
  1619. static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
  1620. u32 start_address, u32 length)
  1621. {
  1622. u32 i = 0, j = 0;
  1623. u32 test_addr = 0;
  1624. u32 test_data = 0, data = 0;
  1625. length = 1000;
  1626. /* for 1st word, test each bit in the 32bit word, */
  1627. /* dwLength specifies number of 32bit words to test */
  1628. /*for(i=0; i<dwLength; i++) */
  1629. i = 0;
  1630. {
  1631. test_addr = start_address + i * 4;
  1632. test_data = 0x00000001;
  1633. for (j = 0; j < 32; j++) {
  1634. boot_loader_write_mem32(pao, dsp_index, test_addr,
  1635. test_data);
  1636. data = boot_loader_read_mem32(pao, dsp_index,
  1637. test_addr);
  1638. if (data != test_data) {
  1639. HPI_DEBUG_LOG(VERBOSE,
  1640. "memtest error details "
  1641. "%08x %08x %08x %i\n", test_addr,
  1642. test_data, data, dsp_index);
  1643. return 1; /* error */
  1644. }
  1645. test_data = test_data << 1;
  1646. } /* for(j) */
  1647. } /* for(i) */
  1648. /* for the next 100 locations test each location, leaving it as zero */
  1649. /* write a zero to the next word in memory before we read */
  1650. /* the previous write to make sure every memory location is unique */
  1651. for (i = 0; i < 100; i++) {
  1652. test_addr = start_address + i * 4;
  1653. test_data = 0xA5A55A5A;
  1654. boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
  1655. boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
  1656. data = boot_loader_read_mem32(pao, dsp_index, test_addr);
  1657. if (data != test_data) {
  1658. HPI_DEBUG_LOG(VERBOSE,
  1659. "memtest error details "
  1660. "%08x %08x %08x %i\n", test_addr, test_data,
  1661. data, dsp_index);
  1662. return 1; /* error */
  1663. }
  1664. /* leave location as zero */
  1665. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1666. }
  1667. /* zero out entire memory block */
  1668. for (i = 0; i < length; i++) {
  1669. test_addr = start_address + i * 4;
  1670. boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
  1671. }
  1672. return 0;
  1673. }
  1674. static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
  1675. int dsp_index)
  1676. {
  1677. int err = 0;
  1678. if (dsp_index == 0) {
  1679. /* DSP 0 is a C6205 */
  1680. /* 64K prog mem */
  1681. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1682. 0x10000);
  1683. if (!err)
  1684. /* 64K data mem */
  1685. err = boot_loader_test_memory(pao, dsp_index,
  1686. 0x80000000, 0x10000);
  1687. } else if ((dsp_index == 1) || (dsp_index == 2)) {
  1688. /* DSP 1&2 are a C6713 */
  1689. /* 192K internal mem */
  1690. err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
  1691. 0x30000);
  1692. if (!err)
  1693. /* 64K internal mem / L2 cache */
  1694. err = boot_loader_test_memory(pao, dsp_index,
  1695. 0x00030000, 0x10000);
  1696. } else
  1697. return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
  1698. if (err)
  1699. return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_INTMEM);
  1700. else
  1701. return 0;
  1702. }
  1703. static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
  1704. int dsp_index)
  1705. {
  1706. u32 dRAM_start_address = 0;
  1707. u32 dRAM_size = 0;
  1708. if (dsp_index == 0) {
  1709. /* only test for SDRAM if an ASI5000 card */
  1710. if (pao->pci.subsys_device_id == 0x5000) {
  1711. /* DSP 0 is always C6205 */
  1712. dRAM_start_address = 0x00400000;
  1713. dRAM_size = 0x200000;
  1714. /*dwDRAMinc=1024; */
  1715. } else
  1716. return 0;
  1717. } else if ((dsp_index == 1) || (dsp_index == 2)) {
  1718. /* DSP 1 is a C6713 */
  1719. dRAM_start_address = 0x80000000;
  1720. dRAM_size = 0x200000;
  1721. /*dwDRAMinc=1024; */
  1722. } else
  1723. return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
  1724. if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
  1725. dRAM_size))
  1726. return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_EXTMEM);
  1727. return 0;
  1728. }
  1729. static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
  1730. {
  1731. u32 data = 0;
  1732. if (dsp_index == 0) {
  1733. /* only test for DSP0 PLD on ASI5000 card */
  1734. if (pao->pci.subsys_device_id == 0x5000) {
  1735. /* PLD is located at CE3=0x03000000 */
  1736. data = boot_loader_read_mem32(pao, dsp_index,
  1737. 0x03000008);
  1738. if ((data & 0xF) != 0x5)
  1739. return hpi6205_error(dsp_index,
  1740. HPI6205_ERROR_DSP_PLD);
  1741. data = boot_loader_read_mem32(pao, dsp_index,
  1742. 0x0300000C);
  1743. if ((data & 0xF) != 0xA)
  1744. return hpi6205_error(dsp_index,
  1745. HPI6205_ERROR_DSP_PLD);
  1746. }
  1747. } else if (dsp_index == 1) {
  1748. /* DSP 1 is a C6713 */
  1749. if (pao->pci.subsys_device_id == 0x8700) {
  1750. /* PLD is located at CE1=0x90000000 */
  1751. data = boot_loader_read_mem32(pao, dsp_index,
  1752. 0x90000010);
  1753. if ((data & 0xFF) != 0xAA)
  1754. return hpi6205_error(dsp_index,
  1755. HPI6205_ERROR_DSP_PLD);
  1756. /* 8713 - LED on */
  1757. boot_loader_write_mem32(pao, dsp_index, 0x90000000,
  1758. 0x02);
  1759. }
  1760. }
  1761. return 0;
  1762. }
  1763. /** Transfer data to or from DSP
  1764. nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
  1765. */
  1766. static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
  1767. u32 data_size, int operation)
  1768. {
  1769. struct hpi_hw_obj *phw = pao->priv;
  1770. u32 data_transferred = 0;
  1771. u16 err = 0;
  1772. #ifndef HPI6205_NO_HSR_POLL
  1773. u32 time_out;
  1774. #endif
  1775. u32 temp2;
  1776. struct bus_master_interface *interface = phw->p_interface_buffer;
  1777. if (!p_data)
  1778. return HPI_ERROR_INVALID_DATA_TRANSFER;
  1779. data_size &= ~3L; /* round data_size down to nearest 4 bytes */
  1780. /* make sure state is IDLE */
  1781. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
  1782. return HPI_ERROR_DSP_HARDWARE;
  1783. while (data_transferred < data_size) {
  1784. u32 this_copy = data_size - data_transferred;
  1785. if (this_copy > HPI6205_SIZEOF_DATA)
  1786. this_copy = HPI6205_SIZEOF_DATA;
  1787. if (operation == H620_HIF_SEND_DATA)
  1788. memcpy((void *)&interface->u.b_data[0],
  1789. &p_data[data_transferred], this_copy);
  1790. interface->transfer_size_in_bytes = this_copy;
  1791. #ifdef HPI6205_NO_HSR_POLL
  1792. /* DSP must change this back to nOperation */
  1793. interface->dsp_ack = H620_HIF_IDLE;
  1794. #endif
  1795. send_dsp_command(phw, operation);
  1796. #ifdef HPI6205_NO_HSR_POLL
  1797. temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
  1798. HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
  1799. HPI6205_TIMEOUT - temp2, this_copy);
  1800. if (!temp2) {
  1801. /* timed out */
  1802. HPI_DEBUG_LOG(ERROR,
  1803. "timed out waiting for " "state %d got %d\n",
  1804. operation, interface->dsp_ack);
  1805. break;
  1806. }
  1807. #else
  1808. /* spin waiting on the result */
  1809. time_out = HPI6205_TIMEOUT;
  1810. temp2 = 0;
  1811. while ((temp2 == 0) && time_out--) {
  1812. /* give 16k bus mastering transfer time to happen */
  1813. /*(16k / 132Mbytes/s = 122usec) */
  1814. hpios_delay_micro_seconds(20);
  1815. temp2 = ioread32(phw->prHSR);
  1816. temp2 &= C6205_HSR_INTSRC;
  1817. }
  1818. HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
  1819. HPI6205_TIMEOUT - time_out, this_copy);
  1820. if (temp2 == C6205_HSR_INTSRC) {
  1821. HPI_DEBUG_LOG(VERBOSE,
  1822. "interrupt from HIF <data> OK\n");
  1823. /*
  1824. if(interface->dwDspAck != nOperation) {
  1825. HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d,
  1826. expected %d \n",
  1827. interface->dwDspAck,nOperation);
  1828. }
  1829. */
  1830. }
  1831. /* need to handle this differently... */
  1832. else {
  1833. HPI_DEBUG_LOG(ERROR,
  1834. "interrupt from HIF <data> BAD\n");
  1835. err = HPI_ERROR_DSP_HARDWARE;
  1836. }
  1837. /* reset the interrupt from the DSP */
  1838. iowrite32(C6205_HSR_INTSRC, phw->prHSR);
  1839. #endif
  1840. if (operation == H620_HIF_GET_DATA)
  1841. memcpy(&p_data[data_transferred],
  1842. (void *)&interface->u.b_data[0], this_copy);
  1843. data_transferred += this_copy;
  1844. }
  1845. if (interface->dsp_ack != operation)
  1846. HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
  1847. interface->dsp_ack, operation);
  1848. /* err=HPI_ERROR_DSP_HARDWARE; */
  1849. send_dsp_command(phw, H620_HIF_IDLE);
  1850. return err;
  1851. }
  1852. /* wait for up to timeout_us microseconds for the DSP
  1853. to signal state by DMA into dwDspAck
  1854. */
  1855. static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
  1856. {
  1857. struct bus_master_interface *interface = phw->p_interface_buffer;
  1858. int t = timeout_us / 4;
  1859. rmb(); /* ensure interface->dsp_ack is up to date */
  1860. while ((interface->dsp_ack != state) && --t) {
  1861. hpios_delay_micro_seconds(4);
  1862. rmb(); /* DSP changes dsp_ack by DMA */
  1863. }
  1864. /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
  1865. return t * 4;
  1866. }
  1867. /* set the busmaster interface to cmd, then interrupt the DSP */
  1868. static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
  1869. {
  1870. struct bus_master_interface *interface = phw->p_interface_buffer;
  1871. u32 r;
  1872. interface->host_cmd = cmd;
  1873. wmb(); /* DSP gets state by DMA, make sure it is written to memory */
  1874. /* before we interrupt the DSP */
  1875. r = ioread32(phw->prHDCR);
  1876. r |= (u32)C6205_HDCR_DSPINT;
  1877. iowrite32(r, phw->prHDCR);
  1878. r &= ~(u32)C6205_HDCR_DSPINT;
  1879. iowrite32(r, phw->prHDCR);
  1880. }
  1881. static unsigned int message_count;
  1882. static u16 message_response_sequence(struct hpi_adapter_obj *pao,
  1883. struct hpi_message *phm, struct hpi_response *phr)
  1884. {
  1885. #ifndef HPI6205_NO_HSR_POLL
  1886. u32 temp2;
  1887. #endif
  1888. u32 time_out, time_out2;
  1889. struct hpi_hw_obj *phw = pao->priv;
  1890. struct bus_master_interface *interface = phw->p_interface_buffer;
  1891. u16 err = 0;
  1892. message_count++;
  1893. /* Assume buffer of type struct bus_master_interface
  1894. is allocated "noncacheable" */
  1895. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1896. HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
  1897. return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
  1898. }
  1899. interface->u.message_buffer = *phm;
  1900. /* signal we want a response */
  1901. send_dsp_command(phw, H620_HIF_GET_RESP);
  1902. time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
  1903. if (time_out2 == 0) {
  1904. HPI_DEBUG_LOG(ERROR,
  1905. "(%u) timed out waiting for " "GET_RESP state [%x]\n",
  1906. message_count, interface->dsp_ack);
  1907. } else {
  1908. HPI_DEBUG_LOG(VERBOSE,
  1909. "(%u) transition to GET_RESP after %u\n",
  1910. message_count, HPI6205_TIMEOUT - time_out2);
  1911. }
  1912. /* spin waiting on HIF interrupt flag (end of msg process) */
  1913. time_out = HPI6205_TIMEOUT;
  1914. #ifndef HPI6205_NO_HSR_POLL
  1915. temp2 = 0;
  1916. while ((temp2 == 0) && --time_out) {
  1917. temp2 = ioread32(phw->prHSR);
  1918. temp2 &= C6205_HSR_INTSRC;
  1919. hpios_delay_micro_seconds(1);
  1920. }
  1921. if (temp2 == C6205_HSR_INTSRC) {
  1922. rmb(); /* ensure we see latest value for dsp_ack */
  1923. if ((interface->dsp_ack != H620_HIF_GET_RESP)) {
  1924. HPI_DEBUG_LOG(DEBUG,
  1925. "(%u)interface->dsp_ack(0x%x) != "
  1926. "H620_HIF_GET_RESP, t=%u\n", message_count,
  1927. interface->dsp_ack,
  1928. HPI6205_TIMEOUT - time_out);
  1929. } else {
  1930. HPI_DEBUG_LOG(VERBOSE,
  1931. "(%u)int with GET_RESP after %u\n",
  1932. message_count, HPI6205_TIMEOUT - time_out);
  1933. }
  1934. } else {
  1935. /* can we do anything else in response to the error ? */
  1936. HPI_DEBUG_LOG(ERROR,
  1937. "interrupt from HIF module BAD (function %x)\n",
  1938. phm->function);
  1939. }
  1940. /* reset the interrupt from the DSP */
  1941. iowrite32(C6205_HSR_INTSRC, phw->prHSR);
  1942. #endif
  1943. /* read the result */
  1944. if (time_out != 0)
  1945. *phr = interface->u.response_buffer;
  1946. /* set interface back to idle */
  1947. send_dsp_command(phw, H620_HIF_IDLE);
  1948. if ((time_out == 0) || (time_out2 == 0)) {
  1949. HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
  1950. return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_TIMEOUT);
  1951. }
  1952. /* special case for adapter close - */
  1953. /* wait for the DSP to indicate it is idle */
  1954. if (phm->function == HPI_ADAPTER_CLOSE) {
  1955. if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
  1956. HPI_DEBUG_LOG(DEBUG,
  1957. "timeout waiting for idle "
  1958. "(on adapter_close)\n");
  1959. return hpi6205_error(0,
  1960. HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
  1961. }
  1962. }
  1963. err = hpi_validate_response(phm, phr);
  1964. return err;
  1965. }
  1966. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1967. struct hpi_response *phr)
  1968. {
  1969. u16 err = 0;
  1970. hpios_dsplock_lock(pao);
  1971. err = message_response_sequence(pao, phm, phr);
  1972. /* maybe an error response */
  1973. if (err) {
  1974. /* something failed in the HPI/DSP interface */
  1975. phr->error = err;
  1976. pao->dsp_crashed++;
  1977. /* just the header of the response is valid */
  1978. phr->size = sizeof(struct hpi_response_header);
  1979. goto err;
  1980. } else
  1981. pao->dsp_crashed = 0;
  1982. if (phr->error != 0) /* something failed in the DSP */
  1983. goto err;
  1984. switch (phm->function) {
  1985. case HPI_OSTREAM_WRITE:
  1986. case HPI_ISTREAM_ANC_WRITE:
  1987. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1988. phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
  1989. break;
  1990. case HPI_ISTREAM_READ:
  1991. case HPI_OSTREAM_ANC_READ:
  1992. err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
  1993. phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
  1994. break;
  1995. case HPI_CONTROL_SET_STATE:
  1996. if (phm->object == HPI_OBJ_CONTROLEX
  1997. && phm->u.cx.attribute == HPI_COBRANET_SET_DATA)
  1998. err = hpi6205_transfer_data(pao,
  1999. phm->u.cx.u.cobranet_bigdata.pb_data,
  2000. phm->u.cx.u.cobranet_bigdata.byte_count,
  2001. H620_HIF_SEND_DATA);
  2002. break;
  2003. case HPI_CONTROL_GET_STATE:
  2004. if (phm->object == HPI_OBJ_CONTROLEX
  2005. && phm->u.cx.attribute == HPI_COBRANET_GET_DATA)
  2006. err = hpi6205_transfer_data(pao,
  2007. phm->u.cx.u.cobranet_bigdata.pb_data,
  2008. phr->u.cx.u.cobranet_data.byte_count,
  2009. H620_HIF_GET_DATA);
  2010. break;
  2011. }
  2012. phr->error = err;
  2013. err:
  2014. hpios_dsplock_unlock(pao);
  2015. return;
  2016. }