hpi6000.c 50 KB

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