hpi6000.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2011 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 ASI6200 series adapters.
  15. These PCI bus adapters are based on the TI C6711 DSP.
  16. Exported functions:
  17. void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
  18. #defines
  19. HIDE_PCI_ASSERTS to show the PCI asserts
  20. PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
  21. (C) Copyright AudioScience Inc. 1998-2003
  22. *******************************************************************************/
  23. #define SOURCEFILE_NAME "hpi6000.c"
  24. #include "hpi_internal.h"
  25. #include "hpimsginit.h"
  26. #include "hpidebug.h"
  27. #include "hpi6000.h"
  28. #include "hpidspcd.h"
  29. #include "hpicmn.h"
  30. #define HPI_HIF_BASE (0x00000200) /* start of C67xx internal RAM */
  31. #define HPI_HIF_ADDR(member) \
  32. (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
  33. #define HPI_HIF_ERROR_MASK 0x4000
  34. /* HPI6000 specific error codes */
  35. #define HPI6000_ERROR_BASE 900 /* not actually used anywhere */
  36. /* operational/messaging errors */
  37. #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
  38. #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK 903
  39. #define HPI6000_ERROR_MSG_GET_ADR 904
  40. #define HPI6000_ERROR_RESP_GET_ADR 905
  41. #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32 906
  42. #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32 907
  43. #define HPI6000_ERROR_CONTROL_CACHE_PARAMS 909
  44. #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT 911
  45. #define HPI6000_ERROR_SEND_DATA_ACK 912
  46. #define HPI6000_ERROR_SEND_DATA_ADR 913
  47. #define HPI6000_ERROR_SEND_DATA_TIMEOUT 914
  48. #define HPI6000_ERROR_SEND_DATA_CMD 915
  49. #define HPI6000_ERROR_SEND_DATA_WRITE 916
  50. #define HPI6000_ERROR_SEND_DATA_IDLECMD 917
  51. #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT 921
  52. #define HPI6000_ERROR_GET_DATA_ACK 922
  53. #define HPI6000_ERROR_GET_DATA_CMD 923
  54. #define HPI6000_ERROR_GET_DATA_READ 924
  55. #define HPI6000_ERROR_GET_DATA_IDLECMD 925
  56. #define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN 951
  57. #define HPI6000_ERROR_CONTROL_CACHE_READ 952
  58. #define HPI6000_ERROR_CONTROL_CACHE_FLUSH 953
  59. #define HPI6000_ERROR_MSG_RESP_GETRESPCMD 961
  60. #define HPI6000_ERROR_MSG_RESP_IDLECMD 962
  61. /* Initialisation/bootload errors */
  62. #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
  63. /* can't access PCI2040 */
  64. #define HPI6000_ERROR_INIT_PCI2040 931
  65. /* can't access DSP HPI i/f */
  66. #define HPI6000_ERROR_INIT_DSPHPI 932
  67. /* can't access internal DSP memory */
  68. #define HPI6000_ERROR_INIT_DSPINTMEM 933
  69. /* can't access SDRAM - test#1 */
  70. #define HPI6000_ERROR_INIT_SDRAM1 934
  71. /* can't access SDRAM - test#2 */
  72. #define HPI6000_ERROR_INIT_SDRAM2 935
  73. #define HPI6000_ERROR_INIT_VERIFY 938
  74. #define HPI6000_ERROR_INIT_NOACK 939
  75. #define HPI6000_ERROR_INIT_PLDTEST1 941
  76. #define HPI6000_ERROR_INIT_PLDTEST2 942
  77. /* local defines */
  78. #define HIDE_PCI_ASSERTS
  79. #define PROFILE_DSP2
  80. /* for PCI2040 i/f chip */
  81. /* HPI CSR registers */
  82. /* word offsets from CSR base */
  83. /* use when io addresses defined as u32 * */
  84. #define INTERRUPT_EVENT_SET 0
  85. #define INTERRUPT_EVENT_CLEAR 1
  86. #define INTERRUPT_MASK_SET 2
  87. #define INTERRUPT_MASK_CLEAR 3
  88. #define HPI_ERROR_REPORT 4
  89. #define HPI_RESET 5
  90. #define HPI_DATA_WIDTH 6
  91. #define MAX_DSPS 2
  92. /* HPI registers, spaced 8K bytes = 2K words apart */
  93. #define DSP_SPACING 0x800
  94. #define CONTROL 0x0000
  95. #define ADDRESS 0x0200
  96. #define DATA_AUTOINC 0x0400
  97. #define DATA 0x0600
  98. #define TIMEOUT 500000
  99. struct dsp_obj {
  100. __iomem u32 *prHPI_control;
  101. __iomem u32 *prHPI_address;
  102. __iomem u32 *prHPI_data;
  103. __iomem u32 *prHPI_data_auto_inc;
  104. char c_dsp_rev; /*A, B */
  105. u32 control_cache_address_on_dsp;
  106. u32 control_cache_length_on_dsp;
  107. struct hpi_adapter_obj *pa_parent_adapter;
  108. };
  109. struct hpi_hw_obj {
  110. __iomem u32 *dw2040_HPICSR;
  111. __iomem u32 *dw2040_HPIDSP;
  112. u16 num_dsp;
  113. struct dsp_obj ado[MAX_DSPS];
  114. u32 message_buffer_address_on_dsp;
  115. u32 response_buffer_address_on_dsp;
  116. u32 pCI2040HPI_error_count;
  117. struct hpi_control_cache_single control_cache[HPI_NMIXER_CONTROLS];
  118. struct hpi_control_cache *p_cache;
  119. };
  120. static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
  121. u16 dsp_index, u32 hpi_address, u32 *source, u32 count);
  122. static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
  123. u16 dsp_index, u32 hpi_address, u32 *dest, u32 count);
  124. static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  125. u32 *pos_error_code);
  126. static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
  127. u16 read_or_write);
  128. #define H6READ 1
  129. #define H6WRITE 0
  130. static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
  131. struct hpi_message *phm);
  132. static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
  133. u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr);
  134. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  135. struct hpi_response *phr);
  136. static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
  137. u32 ack_value);
  138. static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
  139. u16 dsp_index, u32 host_cmd);
  140. static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo);
  141. static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  142. struct hpi_message *phm, struct hpi_response *phr);
  143. static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  144. struct hpi_message *phm, struct hpi_response *phr);
  145. static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data);
  146. static u32 hpi_read_word(struct dsp_obj *pdo, u32 address);
  147. static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  148. u32 length);
  149. static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  150. u32 length);
  151. static void subsys_create_adapter(struct hpi_message *phm,
  152. struct hpi_response *phr);
  153. static void adapter_delete(struct hpi_adapter_obj *pao,
  154. struct hpi_message *phm, struct hpi_response *phr);
  155. static void adapter_get_asserts(struct hpi_adapter_obj *pao,
  156. struct hpi_message *phm, struct hpi_response *phr);
  157. static short create_adapter_obj(struct hpi_adapter_obj *pao,
  158. u32 *pos_error_code);
  159. static void delete_adapter_obj(struct hpi_adapter_obj *pao);
  160. /* local globals */
  161. static u16 gw_pci_read_asserts; /* used to count PCI2040 errors */
  162. static u16 gw_pci_write_asserts; /* used to count PCI2040 errors */
  163. static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
  164. {
  165. switch (phm->function) {
  166. case HPI_SUBSYS_CREATE_ADAPTER:
  167. subsys_create_adapter(phm, phr);
  168. break;
  169. default:
  170. phr->error = HPI_ERROR_INVALID_FUNC;
  171. break;
  172. }
  173. }
  174. static void control_message(struct hpi_adapter_obj *pao,
  175. struct hpi_message *phm, struct hpi_response *phr)
  176. {
  177. struct hpi_hw_obj *phw = pao->priv;
  178. switch (phm->function) {
  179. case HPI_CONTROL_GET_STATE:
  180. if (pao->has_control_cache) {
  181. u16 err;
  182. err = hpi6000_update_control_cache(pao, phm);
  183. if (err) {
  184. if (err >= HPI_ERROR_BACKEND_BASE) {
  185. phr->error =
  186. HPI_ERROR_CONTROL_CACHING;
  187. phr->specific_error = err;
  188. } else {
  189. phr->error = err;
  190. }
  191. break;
  192. }
  193. if (hpi_check_control_cache(phw->p_cache, phm, phr))
  194. break;
  195. }
  196. hw_message(pao, phm, phr);
  197. break;
  198. case HPI_CONTROL_SET_STATE:
  199. hw_message(pao, phm, phr);
  200. hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm, phr);
  201. break;
  202. case HPI_CONTROL_GET_INFO:
  203. default:
  204. hw_message(pao, phm, phr);
  205. break;
  206. }
  207. }
  208. static void adapter_message(struct hpi_adapter_obj *pao,
  209. struct hpi_message *phm, struct hpi_response *phr)
  210. {
  211. switch (phm->function) {
  212. case HPI_ADAPTER_GET_ASSERT:
  213. adapter_get_asserts(pao, phm, phr);
  214. break;
  215. case HPI_ADAPTER_DELETE:
  216. adapter_delete(pao, phm, phr);
  217. break;
  218. default:
  219. hw_message(pao, phm, phr);
  220. break;
  221. }
  222. }
  223. static void outstream_message(struct hpi_adapter_obj *pao,
  224. struct hpi_message *phm, struct hpi_response *phr)
  225. {
  226. switch (phm->function) {
  227. case HPI_OSTREAM_HOSTBUFFER_ALLOC:
  228. case HPI_OSTREAM_HOSTBUFFER_FREE:
  229. /* Don't let these messages go to the HW function because
  230. * they're called without locking the spinlock.
  231. * For the HPI6000 adapters the HW would return
  232. * HPI_ERROR_INVALID_FUNC anyway.
  233. */
  234. phr->error = HPI_ERROR_INVALID_FUNC;
  235. break;
  236. default:
  237. hw_message(pao, phm, phr);
  238. return;
  239. }
  240. }
  241. static void instream_message(struct hpi_adapter_obj *pao,
  242. struct hpi_message *phm, struct hpi_response *phr)
  243. {
  244. switch (phm->function) {
  245. case HPI_ISTREAM_HOSTBUFFER_ALLOC:
  246. case HPI_ISTREAM_HOSTBUFFER_FREE:
  247. /* Don't let these messages go to the HW function because
  248. * they're called without locking the spinlock.
  249. * For the HPI6000 adapters the HW would return
  250. * HPI_ERROR_INVALID_FUNC anyway.
  251. */
  252. phr->error = HPI_ERROR_INVALID_FUNC;
  253. break;
  254. default:
  255. hw_message(pao, phm, phr);
  256. return;
  257. }
  258. }
  259. /************************************************************************/
  260. /** HPI_6000()
  261. * Entry point from HPIMAN
  262. * All calls to the HPI start here
  263. */
  264. void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
  265. {
  266. struct hpi_adapter_obj *pao = NULL;
  267. if (phm->object != HPI_OBJ_SUBSYSTEM) {
  268. pao = hpi_find_adapter(phm->adapter_index);
  269. if (!pao) {
  270. hpi_init_response(phr, phm->object, phm->function,
  271. HPI_ERROR_BAD_ADAPTER_NUMBER);
  272. HPI_DEBUG_LOG(DEBUG, "invalid adapter index: %d \n",
  273. phm->adapter_index);
  274. return;
  275. }
  276. /* Don't even try to communicate with crashed DSP */
  277. if (pao->dsp_crashed >= 10) {
  278. hpi_init_response(phr, phm->object, phm->function,
  279. HPI_ERROR_DSP_HARDWARE);
  280. HPI_DEBUG_LOG(DEBUG, "adapter %d dsp crashed\n",
  281. phm->adapter_index);
  282. return;
  283. }
  284. }
  285. /* Init default response including the size field */
  286. if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
  287. hpi_init_response(phr, phm->object, phm->function,
  288. HPI_ERROR_PROCESSING_MESSAGE);
  289. switch (phm->type) {
  290. case HPI_TYPE_REQUEST:
  291. switch (phm->object) {
  292. case HPI_OBJ_SUBSYSTEM:
  293. subsys_message(phm, phr);
  294. break;
  295. case HPI_OBJ_ADAPTER:
  296. phr->size =
  297. sizeof(struct hpi_response_header) +
  298. sizeof(struct hpi_adapter_res);
  299. adapter_message(pao, phm, phr);
  300. break;
  301. case HPI_OBJ_CONTROL:
  302. control_message(pao, phm, phr);
  303. break;
  304. case HPI_OBJ_OSTREAM:
  305. outstream_message(pao, phm, phr);
  306. break;
  307. case HPI_OBJ_ISTREAM:
  308. instream_message(pao, phm, phr);
  309. break;
  310. default:
  311. hw_message(pao, phm, phr);
  312. break;
  313. }
  314. break;
  315. default:
  316. phr->error = HPI_ERROR_INVALID_TYPE;
  317. break;
  318. }
  319. }
  320. /************************************************************************/
  321. /* SUBSYSTEM */
  322. /* create an adapter object and initialise it based on resource information
  323. * passed in in the message
  324. * NOTE - you cannot use this function AND the FindAdapters function at the
  325. * same time, the application must use only one of them to get the adapters
  326. */
  327. static void subsys_create_adapter(struct hpi_message *phm,
  328. struct hpi_response *phr)
  329. {
  330. /* create temp adapter obj, because we don't know what index yet */
  331. struct hpi_adapter_obj ao;
  332. struct hpi_adapter_obj *pao;
  333. u32 os_error_code;
  334. u16 err = 0;
  335. u32 dsp_index = 0;
  336. HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
  337. memset(&ao, 0, sizeof(ao));
  338. ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
  339. if (!ao.priv) {
  340. HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
  341. phr->error = HPI_ERROR_MEMORY_ALLOC;
  342. return;
  343. }
  344. /* create the adapter object based on the resource information */
  345. ao.pci = *phm->u.s.resource.r.pci;
  346. err = create_adapter_obj(&ao, &os_error_code);
  347. if (err) {
  348. delete_adapter_obj(&ao);
  349. if (err >= HPI_ERROR_BACKEND_BASE) {
  350. phr->error = HPI_ERROR_DSP_BOOTLOAD;
  351. phr->specific_error = err;
  352. } else {
  353. phr->error = err;
  354. }
  355. phr->u.s.data = os_error_code;
  356. return;
  357. }
  358. /* need to update paParentAdapter */
  359. pao = hpi_find_adapter(ao.index);
  360. if (!pao) {
  361. /* We just added this adapter, why can't we find it!? */
  362. HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
  363. phr->error = HPI_ERROR_BAD_ADAPTER;
  364. return;
  365. }
  366. for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
  367. struct hpi_hw_obj *phw = pao->priv;
  368. phw->ado[dsp_index].pa_parent_adapter = pao;
  369. }
  370. phr->u.s.adapter_type = ao.type;
  371. phr->u.s.adapter_index = ao.index;
  372. phr->error = 0;
  373. }
  374. static void adapter_delete(struct hpi_adapter_obj *pao,
  375. struct hpi_message *phm, struct hpi_response *phr)
  376. {
  377. delete_adapter_obj(pao);
  378. hpi_delete_adapter(pao);
  379. phr->error = 0;
  380. }
  381. /* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
  382. static short create_adapter_obj(struct hpi_adapter_obj *pao,
  383. u32 *pos_error_code)
  384. {
  385. short boot_error = 0;
  386. u32 dsp_index = 0;
  387. u32 control_cache_size = 0;
  388. u32 control_cache_count = 0;
  389. struct hpi_hw_obj *phw = pao->priv;
  390. /* The PCI2040 has the following address map */
  391. /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
  392. /* BAR1 - 32K = HPI registers on DSP */
  393. phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
  394. phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
  395. HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
  396. phw->dw2040_HPIDSP);
  397. /* set addresses for the possible DSP HPI interfaces */
  398. for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
  399. phw->ado[dsp_index].prHPI_control =
  400. phw->dw2040_HPIDSP + (CONTROL +
  401. DSP_SPACING * dsp_index);
  402. phw->ado[dsp_index].prHPI_address =
  403. phw->dw2040_HPIDSP + (ADDRESS +
  404. DSP_SPACING * dsp_index);
  405. phw->ado[dsp_index].prHPI_data =
  406. phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
  407. phw->ado[dsp_index].prHPI_data_auto_inc =
  408. phw->dw2040_HPIDSP + (DATA_AUTOINC +
  409. DSP_SPACING * dsp_index);
  410. HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
  411. phw->ado[dsp_index].prHPI_control,
  412. phw->ado[dsp_index].prHPI_address,
  413. phw->ado[dsp_index].prHPI_data,
  414. phw->ado[dsp_index].prHPI_data_auto_inc);
  415. phw->ado[dsp_index].pa_parent_adapter = pao;
  416. }
  417. phw->pCI2040HPI_error_count = 0;
  418. pao->has_control_cache = 0;
  419. /* Set the default number of DSPs on this card */
  420. /* This is (conditionally) adjusted after bootloading */
  421. /* of the first DSP in the bootload section. */
  422. phw->num_dsp = 1;
  423. boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
  424. if (boot_error)
  425. return boot_error;
  426. HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
  427. phw->message_buffer_address_on_dsp = 0L;
  428. phw->response_buffer_address_on_dsp = 0L;
  429. /* get info about the adapter by asking the adapter */
  430. /* send a HPI_ADAPTER_GET_INFO message */
  431. {
  432. struct hpi_message hm;
  433. struct hpi_response hr0; /* response from DSP 0 */
  434. struct hpi_response hr1; /* response from DSP 1 */
  435. u16 error = 0;
  436. HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
  437. memset(&hm, 0, sizeof(hm));
  438. hm.type = HPI_TYPE_REQUEST;
  439. hm.size = sizeof(struct hpi_message);
  440. hm.object = HPI_OBJ_ADAPTER;
  441. hm.function = HPI_ADAPTER_GET_INFO;
  442. hm.adapter_index = 0;
  443. memset(&hr0, 0, sizeof(hr0));
  444. memset(&hr1, 0, sizeof(hr1));
  445. hr0.size = sizeof(hr0);
  446. hr1.size = sizeof(hr1);
  447. error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
  448. if (hr0.error) {
  449. HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
  450. return hr0.error;
  451. }
  452. if (phw->num_dsp == 2) {
  453. error = hpi6000_message_response_sequence(pao, 1, &hm,
  454. &hr1);
  455. if (error)
  456. return error;
  457. }
  458. pao->type = hr0.u.ax.info.adapter_type;
  459. pao->index = hr0.u.ax.info.adapter_index;
  460. }
  461. memset(&phw->control_cache[0], 0,
  462. sizeof(struct hpi_control_cache_single) *
  463. HPI_NMIXER_CONTROLS);
  464. /* Read the control cache length to figure out if it is turned on */
  465. control_cache_size =
  466. hpi_read_word(&phw->ado[0],
  467. HPI_HIF_ADDR(control_cache_size_in_bytes));
  468. if (control_cache_size) {
  469. control_cache_count =
  470. hpi_read_word(&phw->ado[0],
  471. HPI_HIF_ADDR(control_cache_count));
  472. phw->p_cache =
  473. hpi_alloc_control_cache(control_cache_count,
  474. control_cache_size, (unsigned char *)
  475. &phw->control_cache[0]
  476. );
  477. if (phw->p_cache)
  478. pao->has_control_cache = 1;
  479. }
  480. HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n", pao->type,
  481. pao->index);
  482. if (phw->p_cache)
  483. phw->p_cache->adap_idx = pao->index;
  484. return hpi_add_adapter(pao);
  485. }
  486. static void delete_adapter_obj(struct hpi_adapter_obj *pao)
  487. {
  488. struct hpi_hw_obj *phw = pao->priv;
  489. if (pao->has_control_cache)
  490. hpi_free_control_cache(phw->p_cache);
  491. /* reset DSPs on adapter */
  492. iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
  493. kfree(phw);
  494. }
  495. /************************************************************************/
  496. /* ADAPTER */
  497. static void adapter_get_asserts(struct hpi_adapter_obj *pao,
  498. struct hpi_message *phm, struct hpi_response *phr)
  499. {
  500. #ifndef HIDE_PCI_ASSERTS
  501. /* if we have PCI2040 asserts then collect them */
  502. if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
  503. phr->u.ax.assert.p1 =
  504. gw_pci_read_asserts * 100 + gw_pci_write_asserts;
  505. phr->u.ax.assert.p2 = 0;
  506. phr->u.ax.assert.count = 1; /* assert count */
  507. phr->u.ax.assert.dsp_index = -1; /* "dsp index" */
  508. strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
  509. phr->u.ax.assert.dsp_msg_addr = 0;
  510. gw_pci_read_asserts = 0;
  511. gw_pci_write_asserts = 0;
  512. phr->error = 0;
  513. } else
  514. #endif
  515. hw_message(pao, phm, phr); /*get DSP asserts */
  516. return;
  517. }
  518. /************************************************************************/
  519. /* LOW-LEVEL */
  520. static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
  521. u32 *pos_error_code)
  522. {
  523. struct hpi_hw_obj *phw = pao->priv;
  524. short error;
  525. u32 timeout;
  526. u32 read = 0;
  527. u32 i = 0;
  528. u32 data = 0;
  529. u32 j = 0;
  530. u32 test_addr = 0x80000000;
  531. u32 test_data = 0x00000001;
  532. u32 dw2040_reset = 0;
  533. u32 dsp_index = 0;
  534. u32 endian = 0;
  535. u32 adapter_info = 0;
  536. u32 delay = 0;
  537. struct dsp_code dsp_code;
  538. u16 boot_load_family = 0;
  539. /* NOTE don't use wAdapterType in this routine. It is not setup yet */
  540. switch (pao->pci.pci_dev->subsystem_device) {
  541. case 0x5100:
  542. case 0x5110: /* ASI5100 revB or higher with C6711D */
  543. case 0x5200: /* ASI5200 PCIe version of ASI5100 */
  544. case 0x6100:
  545. case 0x6200:
  546. boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
  547. break;
  548. default:
  549. return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
  550. }
  551. /* reset all DSPs, indicate two DSPs are present
  552. * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
  553. */
  554. endian = 0;
  555. dw2040_reset = 0x0003000F;
  556. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  557. /* read back register to make sure PCI2040 chip is functioning
  558. * note that bits 4..15 are read-only and so should always return zero,
  559. * even though we wrote 1 to them
  560. */
  561. hpios_delay_micro_seconds(1000);
  562. delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
  563. if (delay != dw2040_reset) {
  564. HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
  565. delay);
  566. return HPI6000_ERROR_INIT_PCI2040;
  567. }
  568. /* Indicate that DSP#0,1 is a C6X */
  569. iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
  570. /* set Bit30 and 29 - which will prevent Target aborts from being
  571. * issued upon HPI or GP error
  572. */
  573. iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
  574. /* isolate DSP HAD8 line from PCI2040 so that
  575. * Little endian can be set by pullup
  576. */
  577. dw2040_reset = dw2040_reset & (~(endian << 3));
  578. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  579. phw->ado[0].c_dsp_rev = 'B'; /* revB */
  580. phw->ado[1].c_dsp_rev = 'B'; /* revB */
  581. /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
  582. dw2040_reset = dw2040_reset & (~0x00000001); /* start DSP 0 */
  583. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  584. dw2040_reset = dw2040_reset & (~0x00000002); /* start DSP 1 */
  585. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  586. /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
  587. dw2040_reset = dw2040_reset & (~0x00000008);
  588. iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
  589. /*delay to allow DSP to get going */
  590. hpios_delay_micro_seconds(100);
  591. /* loop through all DSPs, downloading DSP code */
  592. for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
  593. struct dsp_obj *pdo = &phw->ado[dsp_index];
  594. /* configure DSP so that we download code into the SRAM */
  595. /* set control reg for little endian, HWOB=1 */
  596. iowrite32(0x00010001, pdo->prHPI_control);
  597. /* test access to the HPI address register (HPIA) */
  598. test_data = 0x00000001;
  599. for (j = 0; j < 32; j++) {
  600. iowrite32(test_data, pdo->prHPI_address);
  601. data = ioread32(pdo->prHPI_address);
  602. if (data != test_data) {
  603. HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
  604. test_data, data, dsp_index);
  605. return HPI6000_ERROR_INIT_DSPHPI;
  606. }
  607. test_data = test_data << 1;
  608. }
  609. /* if C6713 the setup PLL to generate 225MHz from 25MHz.
  610. * Since the PLLDIV1 read is sometimes wrong, even on a C6713,
  611. * we're going to do this unconditionally
  612. */
  613. /* PLLDIV1 should have a value of 8000 after reset */
  614. /*
  615. if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
  616. */
  617. {
  618. /* C6713 datasheet says we cannot program PLL from HPI,
  619. * and indeed if we try to set the PLL multiply from the
  620. * HPI, the PLL does not seem to lock,
  621. * so we enable the PLL and use the default of x 7
  622. */
  623. /* bypass PLL */
  624. hpi_write_word(pdo, 0x01B7C100, 0x0000);
  625. hpios_delay_micro_seconds(100);
  626. /* ** use default of PLL x7 ** */
  627. /* EMIF = 225/3=75MHz */
  628. hpi_write_word(pdo, 0x01B7C120, 0x8002);
  629. hpios_delay_micro_seconds(100);
  630. /* peri = 225/2 */
  631. hpi_write_word(pdo, 0x01B7C11C, 0x8001);
  632. hpios_delay_micro_seconds(100);
  633. /* cpu = 225/1 */
  634. hpi_write_word(pdo, 0x01B7C118, 0x8000);
  635. /* ~2ms delay */
  636. hpios_delay_micro_seconds(2000);
  637. /* PLL not bypassed */
  638. hpi_write_word(pdo, 0x01B7C100, 0x0001);
  639. /* ~2ms delay */
  640. hpios_delay_micro_seconds(2000);
  641. }
  642. /* test r/w to internal DSP memory
  643. * C6711 has L2 cache mapped to 0x0 when reset
  644. *
  645. * revB - because of bug 3.0.1 last HPI read
  646. * (before HPI address issued) must be non-autoinc
  647. */
  648. /* test each bit in the 32bit word */
  649. for (i = 0; i < 100; i++) {
  650. test_addr = 0x00000000;
  651. test_data = 0x00000001;
  652. for (j = 0; j < 32; j++) {
  653. hpi_write_word(pdo, test_addr + i, test_data);
  654. data = hpi_read_word(pdo, test_addr + i);
  655. if (data != test_data) {
  656. HPI_DEBUG_LOG(ERROR,
  657. "DSP mem %x %x %x %x\n",
  658. test_addr + i, test_data,
  659. data, dsp_index);
  660. return HPI6000_ERROR_INIT_DSPINTMEM;
  661. }
  662. test_data = test_data << 1;
  663. }
  664. }
  665. /* memory map of ASI6200
  666. 00000000-0000FFFF 16Kx32 internal program
  667. 01800000-019FFFFF Internal peripheral
  668. 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
  669. 90000000-9000FFFF CE1 Async peripherals:
  670. EMIF config
  671. ------------
  672. Global EMIF control
  673. 0 -
  674. 1 -
  675. 2 -
  676. 3 CLK2EN = 1 CLKOUT2 enabled
  677. 4 CLK1EN = 0 CLKOUT1 disabled
  678. 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
  679. 6 -
  680. 7 NOHOLD = 1 external HOLD disabled
  681. 8 HOLDA = 0 HOLDA output is low
  682. 9 HOLD = 0 HOLD input is low
  683. 10 ARDY = 1 ARDY input is high
  684. 11 BUSREQ = 0 BUSREQ output is low
  685. 12,13 Reserved = 1
  686. */
  687. hpi_write_word(pdo, 0x01800000, 0x34A8);
  688. /* EMIF CE0 setup - 2Mx32 Sync DRAM
  689. 31..28 Wr setup
  690. 27..22 Wr strobe
  691. 21..20 Wr hold
  692. 19..16 Rd setup
  693. 15..14 -
  694. 13..8 Rd strobe
  695. 7..4 MTYPE 0011 Sync DRAM 32bits
  696. 3 Wr hold MSB
  697. 2..0 Rd hold
  698. */
  699. hpi_write_word(pdo, 0x01800008, 0x00000030);
  700. /* EMIF SDRAM Extension
  701. 31-21 0
  702. 20 WR2RD = 0
  703. 19-18 WR2DEAC = 1
  704. 17 WR2WR = 0
  705. 16-15 R2WDQM = 2
  706. 14-12 RD2WR = 4
  707. 11-10 RD2DEAC = 1
  708. 9 RD2RD = 1
  709. 8-7 THZP = 10b
  710. 6-5 TWR = 2-1 = 01b (tWR = 10ns)
  711. 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
  712. 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
  713. 1 CAS latency = 3 ECLK
  714. (for Micron 2M32-7 operating at 100Mhz)
  715. */
  716. /* need to use this else DSP code crashes */
  717. hpi_write_word(pdo, 0x01800020, 0x001BDF29);
  718. /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
  719. 31 - -
  720. 30 SDBSZ 1 4 bank
  721. 29..28 SDRSZ 00 11 row address pins
  722. 27..26 SDCSZ 01 8 column address pins
  723. 25 RFEN 1 refersh enabled
  724. 24 INIT 1 init SDRAM
  725. 23..20 TRCD 0001
  726. 19..16 TRP 0001
  727. 15..12 TRC 0110
  728. 11..0 - -
  729. */
  730. /* need to use this else DSP code crashes */
  731. hpi_write_word(pdo, 0x01800018, 0x47117000);
  732. /* EMIF SDRAM Refresh Timing */
  733. hpi_write_word(pdo, 0x0180001C, 0x00000410);
  734. /*MIF CE1 setup - Async peripherals
  735. @100MHz bus speed, each cycle is 10ns,
  736. 31..28 Wr setup = 1
  737. 27..22 Wr strobe = 3 30ns
  738. 21..20 Wr hold = 1
  739. 19..16 Rd setup =1
  740. 15..14 Ta = 2
  741. 13..8 Rd strobe = 3 30ns
  742. 7..4 MTYPE 0010 Async 32bits
  743. 3 Wr hold MSB =0
  744. 2..0 Rd hold = 1
  745. */
  746. {
  747. u32 cE1 =
  748. (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
  749. 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
  750. hpi_write_word(pdo, 0x01800004, cE1);
  751. }
  752. /* delay a little to allow SDRAM and DSP to "get going" */
  753. hpios_delay_micro_seconds(1000);
  754. /* test access to SDRAM */
  755. {
  756. test_addr = 0x80000000;
  757. test_data = 0x00000001;
  758. /* test each bit in the 32bit word */
  759. for (j = 0; j < 32; j++) {
  760. hpi_write_word(pdo, test_addr, test_data);
  761. data = hpi_read_word(pdo, test_addr);
  762. if (data != test_data) {
  763. HPI_DEBUG_LOG(ERROR,
  764. "DSP dram %x %x %x %x\n",
  765. test_addr, test_data, data,
  766. dsp_index);
  767. return HPI6000_ERROR_INIT_SDRAM1;
  768. }
  769. test_data = test_data << 1;
  770. }
  771. /* test every Nth address in the DRAM */
  772. #define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
  773. #define DRAM_INC 1024
  774. test_addr = 0x80000000;
  775. test_data = 0x0;
  776. for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
  777. hpi_write_word(pdo, test_addr + i, test_data);
  778. test_data++;
  779. }
  780. test_addr = 0x80000000;
  781. test_data = 0x0;
  782. for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
  783. data = hpi_read_word(pdo, test_addr + i);
  784. if (data != test_data) {
  785. HPI_DEBUG_LOG(ERROR,
  786. "DSP dram %x %x %x %x\n",
  787. test_addr + i, test_data,
  788. data, dsp_index);
  789. return HPI6000_ERROR_INIT_SDRAM2;
  790. }
  791. test_data++;
  792. }
  793. }
  794. /* write the DSP code down into the DSPs memory */
  795. error = hpi_dsp_code_open(boot_load_family, pao->pci.pci_dev,
  796. &dsp_code, pos_error_code);
  797. if (error)
  798. return error;
  799. while (1) {
  800. u32 length;
  801. u32 address;
  802. u32 type;
  803. u32 *pcode;
  804. error = hpi_dsp_code_read_word(&dsp_code, &length);
  805. if (error)
  806. break;
  807. if (length == 0xFFFFFFFF)
  808. break; /* end of code */
  809. error = hpi_dsp_code_read_word(&dsp_code, &address);
  810. if (error)
  811. break;
  812. error = hpi_dsp_code_read_word(&dsp_code, &type);
  813. if (error)
  814. break;
  815. error = hpi_dsp_code_read_block(length, &dsp_code,
  816. &pcode);
  817. if (error)
  818. break;
  819. error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
  820. address, pcode, length);
  821. if (error)
  822. break;
  823. }
  824. if (error) {
  825. hpi_dsp_code_close(&dsp_code);
  826. return error;
  827. }
  828. /* verify that code was written correctly */
  829. /* this time through, assume no errors in DSP code file/array */
  830. hpi_dsp_code_rewind(&dsp_code);
  831. while (1) {
  832. u32 length;
  833. u32 address;
  834. u32 type;
  835. u32 *pcode;
  836. hpi_dsp_code_read_word(&dsp_code, &length);
  837. if (length == 0xFFFFFFFF)
  838. break; /* end of code */
  839. hpi_dsp_code_read_word(&dsp_code, &address);
  840. hpi_dsp_code_read_word(&dsp_code, &type);
  841. hpi_dsp_code_read_block(length, &dsp_code, &pcode);
  842. for (i = 0; i < length; i++) {
  843. data = hpi_read_word(pdo, address);
  844. if (data != *pcode) {
  845. error = HPI6000_ERROR_INIT_VERIFY;
  846. HPI_DEBUG_LOG(ERROR,
  847. "DSP verify %x %x %x %x\n",
  848. address, *pcode, data,
  849. dsp_index);
  850. break;
  851. }
  852. pcode++;
  853. address += 4;
  854. }
  855. if (error)
  856. break;
  857. }
  858. hpi_dsp_code_close(&dsp_code);
  859. if (error)
  860. return error;
  861. /* zero out the hostmailbox */
  862. {
  863. u32 address = HPI_HIF_ADDR(host_cmd);
  864. for (i = 0; i < 4; i++) {
  865. hpi_write_word(pdo, address, 0);
  866. address += 4;
  867. }
  868. }
  869. /* write the DSP number into the hostmailbox */
  870. /* structure before starting the DSP */
  871. hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
  872. /* write the DSP adapter Info into the */
  873. /* hostmailbox before starting the DSP */
  874. if (dsp_index > 0)
  875. hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
  876. adapter_info);
  877. /* step 3. Start code by sending interrupt */
  878. iowrite32(0x00030003, pdo->prHPI_control);
  879. hpios_delay_micro_seconds(10000);
  880. /* wait for a non-zero value in hostcmd -
  881. * indicating initialization is complete
  882. *
  883. * Init could take a while if DSP checks SDRAM memory
  884. * Was 200000. Increased to 2000000 for ASI8801 so we
  885. * don't get 938 errors.
  886. */
  887. timeout = 2000000;
  888. while (timeout) {
  889. do {
  890. read = hpi_read_word(pdo,
  891. HPI_HIF_ADDR(host_cmd));
  892. } while (--timeout
  893. && hpi6000_check_PCI2040_error_flag(pao,
  894. H6READ));
  895. if (read)
  896. break;
  897. /* The following is a workaround for bug #94:
  898. * Bluescreen on install and subsequent boots on a
  899. * DELL PowerEdge 600SC PC with 1.8GHz P4 and
  900. * ServerWorks chipset. Without this delay the system
  901. * locks up with a bluescreen (NOT GPF or pagefault).
  902. */
  903. else
  904. hpios_delay_micro_seconds(10000);
  905. }
  906. if (timeout == 0)
  907. return HPI6000_ERROR_INIT_NOACK;
  908. /* read the DSP adapter Info from the */
  909. /* hostmailbox structure after starting the DSP */
  910. if (dsp_index == 0) {
  911. /*u32 dwTestData=0; */
  912. u32 mask = 0;
  913. adapter_info =
  914. hpi_read_word(pdo,
  915. HPI_HIF_ADDR(adapter_info));
  916. if (HPI_ADAPTER_FAMILY_ASI
  917. (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
  918. (adapter_info)) ==
  919. HPI_ADAPTER_FAMILY_ASI(0x6200))
  920. /* all 6200 cards have this many DSPs */
  921. phw->num_dsp = 2;
  922. /* test that the PLD is programmed */
  923. /* and we can read/write 24bits */
  924. #define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
  925. switch (boot_load_family) {
  926. case HPI_ADAPTER_FAMILY_ASI(0x6200):
  927. /* ASI6100/6200 has 24bit path to FPGA */
  928. mask = 0xFFFFFF00L;
  929. /* ASI5100 uses AX6 code, */
  930. /* but has no PLD r/w register to test */
  931. if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
  932. subsystem_device) ==
  933. HPI_ADAPTER_FAMILY_ASI(0x5100))
  934. mask = 0x00000000L;
  935. /* ASI5200 uses AX6 code, */
  936. /* but has no PLD r/w register to test */
  937. if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
  938. subsystem_device) ==
  939. HPI_ADAPTER_FAMILY_ASI(0x5200))
  940. mask = 0x00000000L;
  941. break;
  942. case HPI_ADAPTER_FAMILY_ASI(0x8800):
  943. /* ASI8800 has 16bit path to FPGA */
  944. mask = 0xFFFF0000L;
  945. break;
  946. }
  947. test_data = 0xAAAAAA00L & mask;
  948. /* write to 24 bit Debug register (D31-D8) */
  949. hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
  950. read = hpi_read_word(pdo,
  951. PLD_BASE_ADDRESS + 4L) & mask;
  952. if (read != test_data) {
  953. HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
  954. read);
  955. return HPI6000_ERROR_INIT_PLDTEST1;
  956. }
  957. test_data = 0x55555500L & mask;
  958. hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
  959. read = hpi_read_word(pdo,
  960. PLD_BASE_ADDRESS + 4L) & mask;
  961. if (read != test_data) {
  962. HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
  963. read);
  964. return HPI6000_ERROR_INIT_PLDTEST2;
  965. }
  966. }
  967. } /* for numDSP */
  968. return 0;
  969. }
  970. #define PCI_TIMEOUT 100
  971. static int hpi_set_address(struct dsp_obj *pdo, u32 address)
  972. {
  973. u32 timeout = PCI_TIMEOUT;
  974. do {
  975. iowrite32(address, pdo->prHPI_address);
  976. } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
  977. H6WRITE)
  978. && --timeout);
  979. if (timeout)
  980. return 0;
  981. return 1;
  982. }
  983. /* write one word to the HPI port */
  984. static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
  985. {
  986. if (hpi_set_address(pdo, address))
  987. return;
  988. iowrite32(data, pdo->prHPI_data);
  989. }
  990. /* read one word from the HPI port */
  991. static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
  992. {
  993. u32 data = 0;
  994. if (hpi_set_address(pdo, address))
  995. return 0; /*? No way to return error */
  996. /* take care of errata in revB DSP (2.0.1) */
  997. data = ioread32(pdo->prHPI_data);
  998. return data;
  999. }
  1000. /* write a block of 32bit words to the DSP HPI port using auto-inc mode */
  1001. static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  1002. u32 length)
  1003. {
  1004. u16 length16 = length - 1;
  1005. if (length == 0)
  1006. return;
  1007. if (hpi_set_address(pdo, address))
  1008. return;
  1009. iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
  1010. /* take care of errata in revB DSP (2.0.1) */
  1011. /* must end with non auto-inc */
  1012. iowrite32(*(pdata + length - 1), pdo->prHPI_data);
  1013. }
  1014. /** read a block of 32bit words from the DSP HPI port using auto-inc mode
  1015. */
  1016. static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
  1017. u32 length)
  1018. {
  1019. u16 length16 = length - 1;
  1020. if (length == 0)
  1021. return;
  1022. if (hpi_set_address(pdo, address))
  1023. return;
  1024. ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
  1025. /* take care of errata in revB DSP (2.0.1) */
  1026. /* must end with non auto-inc */
  1027. *(pdata + length - 1) = ioread32(pdo->prHPI_data);
  1028. }
  1029. static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
  1030. u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
  1031. {
  1032. struct hpi_hw_obj *phw = pao->priv;
  1033. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1034. u32 time_out = PCI_TIMEOUT;
  1035. int c6711_burst_size = 128;
  1036. u32 local_hpi_address = hpi_address;
  1037. int local_count = count;
  1038. int xfer_size;
  1039. u32 *pdata = source;
  1040. while (local_count) {
  1041. if (local_count > c6711_burst_size)
  1042. xfer_size = c6711_burst_size;
  1043. else
  1044. xfer_size = local_count;
  1045. time_out = PCI_TIMEOUT;
  1046. do {
  1047. hpi_write_block(pdo, local_hpi_address, pdata,
  1048. xfer_size);
  1049. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
  1050. && --time_out);
  1051. if (!time_out)
  1052. break;
  1053. pdata += xfer_size;
  1054. local_hpi_address += sizeof(u32) * xfer_size;
  1055. local_count -= xfer_size;
  1056. }
  1057. if (time_out)
  1058. return 0;
  1059. else
  1060. return 1;
  1061. }
  1062. static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
  1063. u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
  1064. {
  1065. struct hpi_hw_obj *phw = pao->priv;
  1066. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1067. u32 time_out = PCI_TIMEOUT;
  1068. int c6711_burst_size = 16;
  1069. u32 local_hpi_address = hpi_address;
  1070. int local_count = count;
  1071. int xfer_size;
  1072. u32 *pdata = dest;
  1073. u32 loop_count = 0;
  1074. while (local_count) {
  1075. if (local_count > c6711_burst_size)
  1076. xfer_size = c6711_burst_size;
  1077. else
  1078. xfer_size = local_count;
  1079. time_out = PCI_TIMEOUT;
  1080. do {
  1081. hpi_read_block(pdo, local_hpi_address, pdata,
  1082. xfer_size);
  1083. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1084. && --time_out);
  1085. if (!time_out)
  1086. break;
  1087. pdata += xfer_size;
  1088. local_hpi_address += sizeof(u32) * xfer_size;
  1089. local_count -= xfer_size;
  1090. loop_count++;
  1091. }
  1092. if (time_out)
  1093. return 0;
  1094. else
  1095. return 1;
  1096. }
  1097. static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
  1098. u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
  1099. {
  1100. struct hpi_hw_obj *phw = pao->priv;
  1101. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1102. u32 timeout;
  1103. u16 ack;
  1104. u32 address;
  1105. u32 length;
  1106. u32 *p_data;
  1107. u16 error = 0;
  1108. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1109. if (ack & HPI_HIF_ERROR_MASK) {
  1110. pao->dsp_crashed++;
  1111. return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
  1112. }
  1113. pao->dsp_crashed = 0;
  1114. /* get the message address and size */
  1115. if (phw->message_buffer_address_on_dsp == 0) {
  1116. timeout = TIMEOUT;
  1117. do {
  1118. address =
  1119. hpi_read_word(pdo,
  1120. HPI_HIF_ADDR(message_buffer_address));
  1121. phw->message_buffer_address_on_dsp = address;
  1122. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1123. && --timeout);
  1124. if (!timeout)
  1125. return HPI6000_ERROR_MSG_GET_ADR;
  1126. } else
  1127. address = phw->message_buffer_address_on_dsp;
  1128. length = phm->size;
  1129. /* send the message */
  1130. p_data = (u32 *)phm;
  1131. if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
  1132. (u16)length / 4))
  1133. return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
  1134. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
  1135. return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
  1136. hpi6000_send_dsp_interrupt(pdo);
  1137. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
  1138. if (ack & HPI_HIF_ERROR_MASK)
  1139. return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
  1140. /* get the response address */
  1141. if (phw->response_buffer_address_on_dsp == 0) {
  1142. timeout = TIMEOUT;
  1143. do {
  1144. address =
  1145. hpi_read_word(pdo,
  1146. HPI_HIF_ADDR(response_buffer_address));
  1147. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1148. && --timeout);
  1149. phw->response_buffer_address_on_dsp = address;
  1150. if (!timeout)
  1151. return HPI6000_ERROR_RESP_GET_ADR;
  1152. } else
  1153. address = phw->response_buffer_address_on_dsp;
  1154. /* read the length of the response back from the DSP */
  1155. timeout = TIMEOUT;
  1156. do {
  1157. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1158. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
  1159. if (!timeout)
  1160. length = sizeof(struct hpi_response);
  1161. /* get the response */
  1162. p_data = (u32 *)phr;
  1163. if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
  1164. (u16)length / 4))
  1165. return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
  1166. /* set i/f back to idle */
  1167. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1168. return HPI6000_ERROR_MSG_RESP_IDLECMD;
  1169. hpi6000_send_dsp_interrupt(pdo);
  1170. error = hpi_validate_response(phm, phr);
  1171. return error;
  1172. }
  1173. /* have to set up the below defines to match stuff in the MAP file */
  1174. #define MSG_ADDRESS (HPI_HIF_BASE+0x18)
  1175. #define MSG_LENGTH 11
  1176. #define RESP_ADDRESS (HPI_HIF_BASE+0x44)
  1177. #define RESP_LENGTH 16
  1178. #define QUEUE_START (HPI_HIF_BASE+0x88)
  1179. #define QUEUE_SIZE 0x8000
  1180. static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
  1181. {
  1182. /*#define CHECKING // comment this line in to enable checking */
  1183. #ifdef CHECKING
  1184. if (address < (u32)MSG_ADDRESS)
  1185. return 0;
  1186. if (address > (u32)(QUEUE_START + QUEUE_SIZE))
  1187. return 0;
  1188. if ((address + (length_in_dwords << 2)) >
  1189. (u32)(QUEUE_START + QUEUE_SIZE))
  1190. return 0;
  1191. #else
  1192. (void)address;
  1193. (void)length_in_dwords;
  1194. return 1;
  1195. #endif
  1196. }
  1197. static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  1198. struct hpi_message *phm, struct hpi_response *phr)
  1199. {
  1200. struct hpi_hw_obj *phw = pao->priv;
  1201. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1202. u32 data_sent = 0;
  1203. u16 ack;
  1204. u32 length, address;
  1205. u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
  1206. u16 time_out = 8;
  1207. (void)phr;
  1208. /* round dwDataSize down to nearest 4 bytes */
  1209. while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
  1210. && --time_out) {
  1211. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1212. if (ack & HPI_HIF_ERROR_MASK)
  1213. return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
  1214. if (hpi6000_send_host_command(pao, dsp_index,
  1215. HPI_HIF_SEND_DATA))
  1216. return HPI6000_ERROR_SEND_DATA_CMD;
  1217. hpi6000_send_dsp_interrupt(pdo);
  1218. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
  1219. if (ack & HPI_HIF_ERROR_MASK)
  1220. return HPI6000_ERROR_SEND_DATA_ACK;
  1221. do {
  1222. /* get the address and size */
  1223. address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
  1224. /* DSP returns number of DWORDS */
  1225. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1226. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
  1227. if (!hpi6000_send_data_check_adr(address, length))
  1228. return HPI6000_ERROR_SEND_DATA_ADR;
  1229. /* send the data. break data into 512 DWORD blocks (2K bytes)
  1230. * and send using block write. 2Kbytes is the max as this is the
  1231. * memory window given to the HPI data register by the PCI2040
  1232. */
  1233. {
  1234. u32 len = length;
  1235. u32 blk_len = 512;
  1236. while (len) {
  1237. if (len < blk_len)
  1238. blk_len = len;
  1239. if (hpi6000_dsp_block_write32(pao, dsp_index,
  1240. address, p_data, blk_len))
  1241. return HPI6000_ERROR_SEND_DATA_WRITE;
  1242. address += blk_len * 4;
  1243. p_data += blk_len;
  1244. len -= blk_len;
  1245. }
  1246. }
  1247. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1248. return HPI6000_ERROR_SEND_DATA_IDLECMD;
  1249. hpi6000_send_dsp_interrupt(pdo);
  1250. data_sent += length * 4;
  1251. }
  1252. if (!time_out)
  1253. return HPI6000_ERROR_SEND_DATA_TIMEOUT;
  1254. return 0;
  1255. }
  1256. static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
  1257. struct hpi_message *phm, struct hpi_response *phr)
  1258. {
  1259. struct hpi_hw_obj *phw = pao->priv;
  1260. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1261. u32 data_got = 0;
  1262. u16 ack;
  1263. u32 length, address;
  1264. u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
  1265. (void)phr; /* this parameter not used! */
  1266. /* round dwDataSize down to nearest 4 bytes */
  1267. while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
  1268. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
  1269. if (ack & HPI_HIF_ERROR_MASK)
  1270. return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
  1271. if (hpi6000_send_host_command(pao, dsp_index,
  1272. HPI_HIF_GET_DATA))
  1273. return HPI6000_ERROR_GET_DATA_CMD;
  1274. hpi6000_send_dsp_interrupt(pdo);
  1275. ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
  1276. if (ack & HPI_HIF_ERROR_MASK)
  1277. return HPI6000_ERROR_GET_DATA_ACK;
  1278. /* get the address and size */
  1279. do {
  1280. address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
  1281. length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
  1282. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
  1283. /* read the data */
  1284. {
  1285. u32 len = length;
  1286. u32 blk_len = 512;
  1287. while (len) {
  1288. if (len < blk_len)
  1289. blk_len = len;
  1290. if (hpi6000_dsp_block_read32(pao, dsp_index,
  1291. address, p_data, blk_len))
  1292. return HPI6000_ERROR_GET_DATA_READ;
  1293. address += blk_len * 4;
  1294. p_data += blk_len;
  1295. len -= blk_len;
  1296. }
  1297. }
  1298. if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
  1299. return HPI6000_ERROR_GET_DATA_IDLECMD;
  1300. hpi6000_send_dsp_interrupt(pdo);
  1301. data_got += length * 4;
  1302. }
  1303. return 0;
  1304. }
  1305. static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
  1306. {
  1307. iowrite32(0x00030003, pdo->prHPI_control); /* DSPINT */
  1308. }
  1309. static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
  1310. u16 dsp_index, u32 host_cmd)
  1311. {
  1312. struct hpi_hw_obj *phw = pao->priv;
  1313. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1314. u32 timeout = TIMEOUT;
  1315. /* set command */
  1316. do {
  1317. hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
  1318. /* flush the FIFO */
  1319. hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
  1320. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
  1321. /* reset the interrupt bit */
  1322. iowrite32(0x00040004, pdo->prHPI_control);
  1323. if (timeout)
  1324. return 0;
  1325. else
  1326. return 1;
  1327. }
  1328. /* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
  1329. static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
  1330. u16 read_or_write)
  1331. {
  1332. u32 hPI_error;
  1333. struct hpi_hw_obj *phw = pao->priv;
  1334. /* read the error bits from the PCI2040 */
  1335. hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
  1336. if (hPI_error) {
  1337. /* reset the error flag */
  1338. iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
  1339. phw->pCI2040HPI_error_count++;
  1340. if (read_or_write == 1)
  1341. gw_pci_read_asserts++; /************* inc global */
  1342. else
  1343. gw_pci_write_asserts++;
  1344. return 1;
  1345. } else
  1346. return 0;
  1347. }
  1348. static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
  1349. u32 ack_value)
  1350. {
  1351. struct hpi_hw_obj *phw = pao->priv;
  1352. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1353. u32 ack = 0L;
  1354. u32 timeout;
  1355. u32 hPIC = 0L;
  1356. /* wait for host interrupt to signal ack is ready */
  1357. timeout = TIMEOUT;
  1358. while (--timeout) {
  1359. hPIC = ioread32(pdo->prHPI_control);
  1360. if (hPIC & 0x04) /* 0x04 = HINT from DSP */
  1361. break;
  1362. }
  1363. if (timeout == 0)
  1364. return HPI_HIF_ERROR_MASK;
  1365. /* wait for dwAckValue */
  1366. timeout = TIMEOUT;
  1367. while (--timeout) {
  1368. /* read the ack mailbox */
  1369. ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
  1370. if (ack == ack_value)
  1371. break;
  1372. if ((ack & HPI_HIF_ERROR_MASK)
  1373. && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
  1374. break;
  1375. /*for (i=0;i<1000;i++) */
  1376. /* dwPause=i+1; */
  1377. }
  1378. if (ack & HPI_HIF_ERROR_MASK)
  1379. /* indicates bad read from DSP -
  1380. typically 0xffffff is read for some reason */
  1381. ack = HPI_HIF_ERROR_MASK;
  1382. if (timeout == 0)
  1383. ack = HPI_HIF_ERROR_MASK;
  1384. return (short)ack;
  1385. }
  1386. static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
  1387. struct hpi_message *phm)
  1388. {
  1389. const u16 dsp_index = 0;
  1390. struct hpi_hw_obj *phw = pao->priv;
  1391. struct dsp_obj *pdo = &phw->ado[dsp_index];
  1392. u32 timeout;
  1393. u32 cache_dirty_flag;
  1394. u16 err;
  1395. hpios_dsplock_lock(pao);
  1396. timeout = TIMEOUT;
  1397. do {
  1398. cache_dirty_flag =
  1399. hpi_read_word((struct dsp_obj *)pdo,
  1400. HPI_HIF_ADDR(control_cache_is_dirty));
  1401. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
  1402. if (!timeout) {
  1403. err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
  1404. goto unlock;
  1405. }
  1406. if (cache_dirty_flag) {
  1407. /* read the cached controls */
  1408. u32 address;
  1409. u32 length;
  1410. timeout = TIMEOUT;
  1411. if (pdo->control_cache_address_on_dsp == 0) {
  1412. do {
  1413. address =
  1414. hpi_read_word((struct dsp_obj *)pdo,
  1415. HPI_HIF_ADDR(control_cache_address));
  1416. length = hpi_read_word((struct dsp_obj *)pdo,
  1417. HPI_HIF_ADDR
  1418. (control_cache_size_in_bytes));
  1419. } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
  1420. && --timeout);
  1421. if (!timeout) {
  1422. err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
  1423. goto unlock;
  1424. }
  1425. pdo->control_cache_address_on_dsp = address;
  1426. pdo->control_cache_length_on_dsp = length;
  1427. } else {
  1428. address = pdo->control_cache_address_on_dsp;
  1429. length = pdo->control_cache_length_on_dsp;
  1430. }
  1431. if (hpi6000_dsp_block_read32(pao, dsp_index, address,
  1432. (u32 *)&phw->control_cache[0],
  1433. length / sizeof(u32))) {
  1434. err = HPI6000_ERROR_CONTROL_CACHE_READ;
  1435. goto unlock;
  1436. }
  1437. do {
  1438. hpi_write_word((struct dsp_obj *)pdo,
  1439. HPI_HIF_ADDR(control_cache_is_dirty), 0);
  1440. /* flush the FIFO */
  1441. hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
  1442. } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
  1443. && --timeout);
  1444. if (!timeout) {
  1445. err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
  1446. goto unlock;
  1447. }
  1448. }
  1449. err = 0;
  1450. unlock:
  1451. hpios_dsplock_unlock(pao);
  1452. return err;
  1453. }
  1454. /** Get dsp index for multi DSP adapters only */
  1455. static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
  1456. {
  1457. u16 ret = 0;
  1458. switch (phm->object) {
  1459. case HPI_OBJ_ISTREAM:
  1460. if (phm->obj_index < 2)
  1461. ret = 1;
  1462. break;
  1463. case HPI_OBJ_PROFILE:
  1464. ret = phm->obj_index;
  1465. break;
  1466. default:
  1467. break;
  1468. }
  1469. return ret;
  1470. }
  1471. /** Complete transaction with DSP
  1472. Send message, get response, send or get stream data if any.
  1473. */
  1474. static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
  1475. struct hpi_response *phr)
  1476. {
  1477. u16 error = 0;
  1478. u16 dsp_index = 0;
  1479. struct hpi_hw_obj *phw = pao->priv;
  1480. u16 num_dsp = phw->num_dsp;
  1481. if (num_dsp < 2)
  1482. dsp_index = 0;
  1483. else {
  1484. dsp_index = get_dsp_index(pao, phm);
  1485. /* is this checked on the DSP anyway? */
  1486. if ((phm->function == HPI_ISTREAM_GROUP_ADD)
  1487. || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
  1488. struct hpi_message hm;
  1489. u16 add_index;
  1490. hm.obj_index = phm->u.d.u.stream.stream_index;
  1491. hm.object = phm->u.d.u.stream.object_type;
  1492. add_index = get_dsp_index(pao, &hm);
  1493. if (add_index != dsp_index) {
  1494. phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
  1495. return;
  1496. }
  1497. }
  1498. }
  1499. hpios_dsplock_lock(pao);
  1500. error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
  1501. if (error) /* something failed in the HPI/DSP interface */
  1502. goto err;
  1503. if (phr->error) /* something failed in the DSP */
  1504. goto out;
  1505. switch (phm->function) {
  1506. case HPI_OSTREAM_WRITE:
  1507. case HPI_ISTREAM_ANC_WRITE:
  1508. error = hpi6000_send_data(pao, dsp_index, phm, phr);
  1509. break;
  1510. case HPI_ISTREAM_READ:
  1511. case HPI_OSTREAM_ANC_READ:
  1512. error = hpi6000_get_data(pao, dsp_index, phm, phr);
  1513. break;
  1514. case HPI_ADAPTER_GET_ASSERT:
  1515. phr->u.ax.assert.dsp_index = 0; /* dsp 0 default */
  1516. if (num_dsp == 2) {
  1517. if (!phr->u.ax.assert.count) {
  1518. /* no assert from dsp 0, check dsp 1 */
  1519. error = hpi6000_message_response_sequence(pao,
  1520. 1, phm, phr);
  1521. phr->u.ax.assert.dsp_index = 1;
  1522. }
  1523. }
  1524. }
  1525. err:
  1526. if (error) {
  1527. if (error >= HPI_ERROR_BACKEND_BASE) {
  1528. phr->error = HPI_ERROR_DSP_COMMUNICATION;
  1529. phr->specific_error = error;
  1530. } else {
  1531. phr->error = error;
  1532. }
  1533. /* just the header of the response is valid */
  1534. phr->size = sizeof(struct hpi_response_header);
  1535. }
  1536. out:
  1537. hpios_dsplock_unlock(pao);
  1538. return;
  1539. }