hpi6000.c 49 KB

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