1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Hardware Programming Interface (HPI) for AudioScience
20 ASI50xx, AS51xx, ASI6xxx, ASI87xx ASI89xx series adapters.
21 These PCI and PCIe bus adapters are based on a
22 TMS320C6205 PCI bus mastering DSP,
23 and (except ASI50xx) TI TMS320C6xxx floating point DSP
26 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
28 (C) Copyright AudioScience Inc. 1998-2010
29 *******************************************************************************/
30 #define SOURCEFILE_NAME "hpi6205.c"
32 #include "hpi_internal.h"
33 #include "hpimsginit.h"
39 /*****************************************************************************/
40 /* HPI6205 specific error codes */
41 #define HPI6205_ERROR_BASE 1000 /* not actually used anywhere */
43 /* operational/messaging errors */
44 #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
45 #define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
47 /* initialization/bootload errors */
48 #define HPI6205_ERROR_6205_NO_IRQ 1002
49 #define HPI6205_ERROR_6205_INIT_FAILED 1003
50 #define HPI6205_ERROR_6205_REG 1006
51 #define HPI6205_ERROR_6205_DSPPAGE 1007
52 #define HPI6205_ERROR_C6713_HPIC 1009
53 #define HPI6205_ERROR_C6713_HPIA 1010
54 #define HPI6205_ERROR_C6713_PLL 1011
55 #define HPI6205_ERROR_DSP_INTMEM 1012
56 #define HPI6205_ERROR_DSP_EXTMEM 1013
57 #define HPI6205_ERROR_DSP_PLD 1014
58 #define HPI6205_ERROR_6205_EEPROM 1017
59 #define HPI6205_ERROR_DSP_EMIF 1018
61 /*****************************************************************************/
62 /* for C6205 PCI i/f */
63 /* Host Status Register (HSR) bitfields */
64 #define C6205_HSR_INTSRC 0x01
65 #define C6205_HSR_INTAVAL 0x02
66 #define C6205_HSR_INTAM 0x04
67 #define C6205_HSR_CFGERR 0x08
68 #define C6205_HSR_EEREAD 0x10
69 /* Host-to-DSP Control Register (HDCR) bitfields */
70 #define C6205_HDCR_WARMRESET 0x01
71 #define C6205_HDCR_DSPINT 0x02
72 #define C6205_HDCR_PCIBOOT 0x04
73 /* DSP Page Register (DSPP) bitfields, */
74 /* defines 4 Mbyte page that BAR0 points to */
75 #define C6205_DSPP_MAP1 0x400
77 /* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
78 * BAR1 maps to non-prefetchable 8 Mbyte memory block
79 * of DSP memory mapped registers (starting at 0x01800000).
80 * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
81 * needs to be added to the BAR1 base address set in the PCI config reg
83 #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
84 #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
85 #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
86 #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
88 /* used to control LED (revA) and reset C6713 (revB) */
89 #define C6205_BAR0_TIMER1_CTL (0x01980000L)
91 /* For first 6713 in CE1 space, using DA17,16,2 */
92 #define HPICL_ADDR 0x01400000L
93 #define HPICH_ADDR 0x01400004L
94 #define HPIAL_ADDR 0x01410000L
95 #define HPIAH_ADDR 0x01410004L
96 #define HPIDIL_ADDR 0x01420000L
97 #define HPIDIH_ADDR 0x01420004L
98 #define HPIDL_ADDR 0x01430000L
99 #define HPIDH_ADDR 0x01430004L
101 #define C6713_EMIF_GCTL 0x01800000
102 #define C6713_EMIF_CE1 0x01800004
103 #define C6713_EMIF_CE0 0x01800008
104 #define C6713_EMIF_CE2 0x01800010
105 #define C6713_EMIF_CE3 0x01800014
106 #define C6713_EMIF_SDRAMCTL 0x01800018
107 #define C6713_EMIF_SDRAMTIMING 0x0180001C
108 #define C6713_EMIF_SDRAMEXT 0x01800020
118 struct consistent_dma_area h_locked_mem;
119 struct bus_master_interface *p_interface_buffer;
121 u16 flag_outstream_just_reset[HPI_MAX_STREAMS];
122 /* a non-NULL handle means there is an HPI allocated buffer */
123 struct consistent_dma_area instream_host_buffers[HPI_MAX_STREAMS];
124 struct consistent_dma_area outstream_host_buffers[HPI_MAX_STREAMS];
125 /* non-zero size means a buffer exists, may be external */
126 u32 instream_host_buffer_size[HPI_MAX_STREAMS];
127 u32 outstream_host_buffer_size[HPI_MAX_STREAMS];
129 struct consistent_dma_area h_control_cache;
130 struct consistent_dma_area h_async_event_buffer;
131 /* struct hpi_control_cache_single *pControlCache; */
132 struct hpi_async_event *p_async_event_buffer;
133 struct hpi_control_cache *p_cache;
136 /*****************************************************************************/
137 /* local prototypes */
139 #define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
141 static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us);
143 static void send_dsp_command(struct hpi_hw_obj *phw, int cmd);
145 static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
146 u32 *pos_error_code);
148 static u16 message_response_sequence(struct hpi_adapter_obj *pao,
149 struct hpi_message *phm, struct hpi_response *phr);
151 static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
152 struct hpi_response *phr);
154 #define HPI6205_TIMEOUT 1000000
156 static void subsys_create_adapter(struct hpi_message *phm,
157 struct hpi_response *phr);
158 static void subsys_delete_adapter(struct hpi_message *phm,
159 struct hpi_response *phr);
161 static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
162 u32 *pos_error_code);
164 static void delete_adapter_obj(struct hpi_adapter_obj *pao);
166 static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
167 struct hpi_message *phm, struct hpi_response *phr);
169 static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
170 struct hpi_message *phm, struct hpi_response *phr);
172 static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
173 struct hpi_message *phm, struct hpi_response *phr);
174 static void outstream_write(struct hpi_adapter_obj *pao,
175 struct hpi_message *phm, struct hpi_response *phr);
177 static void outstream_get_info(struct hpi_adapter_obj *pao,
178 struct hpi_message *phm, struct hpi_response *phr);
180 static void outstream_start(struct hpi_adapter_obj *pao,
181 struct hpi_message *phm, struct hpi_response *phr);
183 static void outstream_open(struct hpi_adapter_obj *pao,
184 struct hpi_message *phm, struct hpi_response *phr);
186 static void outstream_reset(struct hpi_adapter_obj *pao,
187 struct hpi_message *phm, struct hpi_response *phr);
189 static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
190 struct hpi_message *phm, struct hpi_response *phr);
192 static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
193 struct hpi_message *phm, struct hpi_response *phr);
195 static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
196 struct hpi_message *phm, struct hpi_response *phr);
198 static void instream_read(struct hpi_adapter_obj *pao,
199 struct hpi_message *phm, struct hpi_response *phr);
201 static void instream_get_info(struct hpi_adapter_obj *pao,
202 struct hpi_message *phm, struct hpi_response *phr);
204 static void instream_start(struct hpi_adapter_obj *pao,
205 struct hpi_message *phm, struct hpi_response *phr);
207 static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
210 static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
211 int dsp_index, u32 address, u32 data);
213 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
216 static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
217 u32 address, u32 length);
219 static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
222 static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
225 static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
227 /*****************************************************************************/
229 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
231 switch (phm->function) {
232 case HPI_SUBSYS_CREATE_ADAPTER:
233 subsys_create_adapter(phm, phr);
235 case HPI_SUBSYS_DELETE_ADAPTER:
236 subsys_delete_adapter(phm, phr);
239 phr->error = HPI_ERROR_INVALID_FUNC;
244 static void control_message(struct hpi_adapter_obj *pao,
245 struct hpi_message *phm, struct hpi_response *phr)
248 struct hpi_hw_obj *phw = pao->priv;
249 u16 pending_cache_error = 0;
251 switch (phm->function) {
252 case HPI_CONTROL_GET_STATE:
253 if (pao->has_control_cache) {
254 rmb(); /* make sure we see updates DMAed from DSP */
255 if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
257 } else if (phm->u.c.attribute == HPI_METER_PEAK) {
258 pending_cache_error =
259 HPI_ERROR_CONTROL_CACHING;
262 hw_message(pao, phm, phr);
263 if (pending_cache_error && !phr->error)
264 phr->error = pending_cache_error;
266 case HPI_CONTROL_GET_INFO:
267 hw_message(pao, phm, phr);
269 case HPI_CONTROL_SET_STATE:
270 hw_message(pao, phm, phr);
271 if (pao->has_control_cache)
272 hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
276 phr->error = HPI_ERROR_INVALID_FUNC;
281 static void adapter_message(struct hpi_adapter_obj *pao,
282 struct hpi_message *phm, struct hpi_response *phr)
284 switch (phm->function) {
286 hw_message(pao, phm, phr);
291 static void outstream_message(struct hpi_adapter_obj *pao,
292 struct hpi_message *phm, struct hpi_response *phr)
295 if (phm->obj_index >= HPI_MAX_STREAMS) {
296 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
297 HPI_DEBUG_LOG(WARNING,
298 "Message referencing invalid stream %d "
299 "on adapter index %d\n", phm->obj_index,
304 switch (phm->function) {
305 case HPI_OSTREAM_WRITE:
306 outstream_write(pao, phm, phr);
308 case HPI_OSTREAM_GET_INFO:
309 outstream_get_info(pao, phm, phr);
311 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
312 outstream_host_buffer_allocate(pao, phm, phr);
314 case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
315 outstream_host_buffer_get_info(pao, phm, phr);
317 case HPI_OSTREAM_HOSTBUFFER_FREE:
318 outstream_host_buffer_free(pao, phm, phr);
320 case HPI_OSTREAM_START:
321 outstream_start(pao, phm, phr);
323 case HPI_OSTREAM_OPEN:
324 outstream_open(pao, phm, phr);
326 case HPI_OSTREAM_RESET:
327 outstream_reset(pao, phm, phr);
330 hw_message(pao, phm, phr);
335 static void instream_message(struct hpi_adapter_obj *pao,
336 struct hpi_message *phm, struct hpi_response *phr)
339 if (phm->obj_index >= HPI_MAX_STREAMS) {
340 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
341 HPI_DEBUG_LOG(WARNING,
342 "Message referencing invalid stream %d "
343 "on adapter index %d\n", phm->obj_index,
348 switch (phm->function) {
349 case HPI_ISTREAM_READ:
350 instream_read(pao, phm, phr);
352 case HPI_ISTREAM_GET_INFO:
353 instream_get_info(pao, phm, phr);
355 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
356 instream_host_buffer_allocate(pao, phm, phr);
358 case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
359 instream_host_buffer_get_info(pao, phm, phr);
361 case HPI_ISTREAM_HOSTBUFFER_FREE:
362 instream_host_buffer_free(pao, phm, phr);
364 case HPI_ISTREAM_START:
365 instream_start(pao, phm, phr);
368 hw_message(pao, phm, phr);
373 /*****************************************************************************/
374 /** Entry point to this HPI backend
375 * All calls to the HPI start here
377 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
379 struct hpi_adapter_obj *pao = NULL;
381 /* subsytem messages are processed by every HPI.
382 * All other messages are ignored unless the adapter index matches
383 * an adapter in the HPI
385 /* HPI_DEBUG_LOG(DEBUG, "HPI Obj=%d, Func=%d\n", phm->wObject,
388 /* if Dsp has crashed then do not communicate with it any more */
389 if (phm->object != HPI_OBJ_SUBSYSTEM) {
390 pao = hpi_find_adapter(phm->adapter_index);
393 " %d,%d refused, for another HPI?\n",
394 phm->object, phm->function);
398 if ((pao->dsp_crashed >= 10)
399 && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
400 /* allow last resort debug read even after crash */
401 hpi_init_response(phr, phm->object, phm->function,
402 HPI_ERROR_DSP_HARDWARE);
403 HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n",
404 phm->object, phm->function);
409 /* Init default response */
410 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
411 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
413 HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
415 case HPI_TYPE_MESSAGE:
416 switch (phm->object) {
417 case HPI_OBJ_SUBSYSTEM:
418 subsys_message(phm, phr);
421 case HPI_OBJ_ADAPTER:
422 adapter_message(pao, phm, phr);
425 case HPI_OBJ_CONTROLEX:
426 case HPI_OBJ_CONTROL:
427 control_message(pao, phm, phr);
430 case HPI_OBJ_OSTREAM:
431 outstream_message(pao, phm, phr);
434 case HPI_OBJ_ISTREAM:
435 instream_message(pao, phm, phr);
439 hw_message(pao, phm, phr);
445 phr->error = HPI_ERROR_INVALID_TYPE;
450 /*****************************************************************************/
453 /** Create an adapter object and initialise it based on resource information
454 * passed in in the message
455 * *** NOTE - you cannot use this function AND the FindAdapters function at the
456 * same time, the application must use only one of them to get the adapters ***
458 static void subsys_create_adapter(struct hpi_message *phm,
459 struct hpi_response *phr)
461 /* create temp adapter obj, because we don't know what index yet */
462 struct hpi_adapter_obj ao;
466 HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
468 memset(&ao, 0, sizeof(ao));
470 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
472 HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
473 phr->error = HPI_ERROR_MEMORY_ALLOC;
477 ao.pci = *phm->u.s.resource.r.pci;
478 err = create_adapter_obj(&ao, &os_error_code);
480 delete_adapter_obj(&ao);
482 phr->u.s.data = os_error_code;
486 phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type;
487 phr->u.s.adapter_index = ao.index;
488 phr->u.s.num_adapters++;
492 /** delete an adapter - required by WDM driver */
493 static void subsys_delete_adapter(struct hpi_message *phm,
494 struct hpi_response *phr)
496 struct hpi_adapter_obj *pao;
497 struct hpi_hw_obj *phw;
499 pao = hpi_find_adapter(phm->obj_index);
501 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
504 phw = (struct hpi_hw_obj *)pao->priv;
505 /* reset adapter h/w */
507 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
509 iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
511 delete_adapter_obj(pao);
512 hpi_delete_adapter(pao);
516 /** Create adapter object
517 allocate buffers, bootload DSPs, initialise control cache
519 static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
522 struct hpi_hw_obj *phw = pao->priv;
523 struct bus_master_interface *interface;
525 #ifndef HPI6205_NO_HSR_POLL
526 u32 time_out = HPI6205_TIMEOUT;
532 /* init error reporting */
533 pao->dsp_crashed = 0;
535 for (i = 0; i < HPI_MAX_STREAMS; i++)
536 phw->flag_outstream_just_reset[i] = 1;
538 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
540 pao->pci.ap_mem_base[1] +
541 C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
543 pao->pci.ap_mem_base[1] +
544 C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
546 pao->pci.ap_mem_base[1] +
547 C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
549 pao->has_control_cache = 0;
551 if (hpios_locked_mem_alloc(&phw->h_locked_mem,
552 sizeof(struct bus_master_interface),
554 phw->p_interface_buffer = NULL;
555 else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
556 (void *)&phw->p_interface_buffer))
557 phw->p_interface_buffer = NULL;
559 HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
560 phw->p_interface_buffer);
562 if (phw->p_interface_buffer) {
563 memset((void *)phw->p_interface_buffer, 0,
564 sizeof(struct bus_master_interface));
565 phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
568 err = adapter_boot_load_dsp(pao, pos_error_code);
570 /* no need to clean up as SubSysCreateAdapter */
571 /* calls DeleteAdapter on error. */
574 HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
576 /* allow boot load even if mem alloc wont work */
577 if (!phw->p_interface_buffer)
578 return HPI_ERROR_MEMORY_ALLOC;
580 interface = phw->p_interface_buffer;
582 #ifndef HPI6205_NO_HSR_POLL
583 /* wait for first interrupt indicating the DSP init is done */
584 time_out = HPI6205_TIMEOUT * 10;
586 while (((temp1 & C6205_HSR_INTSRC) == 0) && --time_out)
587 temp1 = ioread32(phw->prHSR);
589 if (temp1 & C6205_HSR_INTSRC)
591 "Interrupt confirming DSP code running OK\n");
594 "Timed out waiting for interrupt "
595 "confirming DSP code running\n");
596 return HPI6205_ERROR_6205_NO_IRQ;
599 /* reset the interrupt */
600 iowrite32(C6205_HSR_INTSRC, phw->prHSR);
603 /* make sure the DSP has started ok */
604 if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
605 HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
606 return HPI6205_ERROR_6205_INIT_FAILED;
608 /* Note that *pao, *phw are zeroed after allocation,
609 * so pointers and flags are NULL by default.
610 * Allocate bus mastering control cache buffer and tell the DSP about it
612 if (interface->control_cache.number_of_controls) {
613 u8 *p_control_cache_virtual;
615 err = hpios_locked_mem_alloc(&phw->h_control_cache,
616 interface->control_cache.size_in_bytes,
619 err = hpios_locked_mem_get_virt_addr(&phw->
621 (void *)&p_control_cache_virtual);
623 memset(p_control_cache_virtual, 0,
624 interface->control_cache.size_in_bytes);
627 hpi_alloc_control_cache(interface->
628 control_cache.number_of_controls,
629 interface->control_cache.size_in_bytes,
630 p_control_cache_virtual);
632 err = HPI_ERROR_MEMORY_ALLOC;
635 err = hpios_locked_mem_get_phys_addr(&phw->
636 h_control_cache, &phys_addr);
637 interface->control_cache.physical_address32 =
642 pao->has_control_cache = 1;
644 if (hpios_locked_mem_valid(&phw->h_control_cache))
645 hpios_locked_mem_free(&phw->h_control_cache);
646 pao->has_control_cache = 0;
649 /* allocate bus mastering async buffer and tell the DSP about it */
650 if (interface->async_buffer.b.size) {
651 err = hpios_locked_mem_alloc(&phw->h_async_event_buffer,
652 interface->async_buffer.b.size *
653 sizeof(struct hpi_async_event), pao->pci.pci_dev);
655 err = hpios_locked_mem_get_virt_addr
656 (&phw->h_async_event_buffer, (void *)
657 &phw->p_async_event_buffer);
659 memset((void *)phw->p_async_event_buffer, 0,
660 interface->async_buffer.b.size *
661 sizeof(struct hpi_async_event));
663 err = hpios_locked_mem_get_phys_addr
664 (&phw->h_async_event_buffer, &phys_addr);
665 interface->async_buffer.physical_address32 =
669 if (hpios_locked_mem_valid(&phw->
670 h_async_event_buffer)) {
671 hpios_locked_mem_free
672 (&phw->h_async_event_buffer);
673 phw->p_async_event_buffer = NULL;
677 send_dsp_command(phw, H620_HIF_IDLE);
680 struct hpi_message hm;
681 struct hpi_response hr;
684 HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
685 memset(&hm, 0, sizeof(hm));
686 hm.type = HPI_TYPE_MESSAGE;
687 hm.size = sizeof(hm);
688 hm.object = HPI_OBJ_ADAPTER;
689 hm.function = HPI_ADAPTER_GET_INFO;
690 hm.adapter_index = 0;
691 memset(&hr, 0, sizeof(hr));
692 hr.size = sizeof(hr);
694 err = message_response_sequence(pao, &hm, &hr);
696 HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
703 pao->adapter_type = hr.u.ax.info.adapter_type;
704 pao->index = hr.u.ax.info.adapter_index;
707 hr.u.ax.info.num_outstreams +
708 hr.u.ax.info.num_instreams;
710 hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams,
711 65536, pao->pci.pci_dev);
713 HPI_DEBUG_LOG(VERBOSE,
714 "got adapter info type %x index %d serial %d\n",
715 hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
716 hr.u.ax.info.serial_number);
719 pao->open = 0; /* upon creation the adapter is closed */
722 phw->p_cache->adap_idx = pao->index;
724 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
726 return hpi_add_adapter(pao);
729 /** Free memory areas allocated by adapter
730 * this routine is called from SubSysDeleteAdapter,
731 * and SubSysCreateAdapter if duplicate index
733 static void delete_adapter_obj(struct hpi_adapter_obj *pao)
735 struct hpi_hw_obj *phw;
740 if (hpios_locked_mem_valid(&phw->h_async_event_buffer)) {
741 hpios_locked_mem_free(&phw->h_async_event_buffer);
742 phw->p_async_event_buffer = NULL;
745 if (hpios_locked_mem_valid(&phw->h_control_cache)) {
746 hpios_locked_mem_free(&phw->h_control_cache);
747 hpi_free_control_cache(phw->p_cache);
750 if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
751 hpios_locked_mem_free(&phw->h_locked_mem);
752 phw->p_interface_buffer = NULL;
755 for (i = 0; i < HPI_MAX_STREAMS; i++)
756 if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
757 hpios_locked_mem_free(&phw->instream_host_buffers[i]);
758 /*?phw->InStreamHostBuffers[i] = NULL; */
759 phw->instream_host_buffer_size[i] = 0;
762 for (i = 0; i < HPI_MAX_STREAMS; i++)
763 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
764 hpios_locked_mem_free(&phw->outstream_host_buffers
766 phw->outstream_host_buffer_size[i] = 0;
769 hpios_locked_mem_unprepare(pao->pci.pci_dev);
774 /*****************************************************************************/
775 /* OutStream Host buffer functions */
777 /** Allocate or attach buffer for busmastering
779 static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
780 struct hpi_message *phm, struct hpi_response *phr)
783 u32 command = phm->u.d.u.buffer.command;
784 struct hpi_hw_obj *phw = pao->priv;
785 struct bus_master_interface *interface = phw->p_interface_buffer;
787 hpi_init_response(phr, phm->object, phm->function, 0);
789 if (command == HPI_BUFFER_CMD_EXTERNAL
790 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
791 /* ALLOC phase, allocate a buffer with power of 2 size,
792 get its bus address for PCI bus mastering
794 phm->u.d.u.buffer.buffer_size =
795 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
796 /* return old size and allocated size,
797 so caller can detect change */
798 phr->u.d.u.stream_info.data_available =
799 phw->outstream_host_buffer_size[phm->obj_index];
800 phr->u.d.u.stream_info.buffer_size =
801 phm->u.d.u.buffer.buffer_size;
803 if (phw->outstream_host_buffer_size[phm->obj_index] ==
804 phm->u.d.u.buffer.buffer_size) {
805 /* Same size, no action required */
809 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
811 hpios_locked_mem_free(&phw->outstream_host_buffers
814 err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
815 [phm->obj_index], phm->u.d.u.buffer.buffer_size,
819 phr->error = HPI_ERROR_INVALID_DATASIZE;
820 phw->outstream_host_buffer_size[phm->obj_index] = 0;
824 err = hpios_locked_mem_get_phys_addr
825 (&phw->outstream_host_buffers[phm->obj_index],
826 &phm->u.d.u.buffer.pci_address);
827 /* get the phys addr into msg for single call alloc caller
828 * needs to do this for split alloc (or use the same message)
829 * return the phy address for split alloc in the respose too
831 phr->u.d.u.stream_info.auxiliary_data_available =
832 phm->u.d.u.buffer.pci_address;
835 hpios_locked_mem_free(&phw->outstream_host_buffers
837 phw->outstream_host_buffer_size[phm->obj_index] = 0;
838 phr->error = HPI_ERROR_MEMORY_ALLOC;
843 if (command == HPI_BUFFER_CMD_EXTERNAL
844 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
845 /* GRANT phase. Set up the BBM status, tell the DSP about
846 the buffer so it can start using BBM.
848 struct hpi_hostbuffer_status *status;
850 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
853 "Buffer size must be 2^N not %d\n",
854 phm->u.d.u.buffer.buffer_size);
855 phr->error = HPI_ERROR_INVALID_DATASIZE;
858 phw->outstream_host_buffer_size[phm->obj_index] =
859 phm->u.d.u.buffer.buffer_size;
860 status = &interface->outstream_host_buffer_status[phm->
862 status->samples_processed = 0;
863 status->stream_state = HPI_STATE_STOPPED;
864 status->dSP_index = 0;
865 status->host_index = status->dSP_index;
866 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
867 status->auxiliary_data_available = 0;
869 hw_message(pao, phm, phr);
872 && hpios_locked_mem_valid(&phw->
873 outstream_host_buffers[phm->obj_index])) {
874 hpios_locked_mem_free(&phw->outstream_host_buffers
876 phw->outstream_host_buffer_size[phm->obj_index] = 0;
881 static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
882 struct hpi_message *phm, struct hpi_response *phr)
884 struct hpi_hw_obj *phw = pao->priv;
885 struct bus_master_interface *interface = phw->p_interface_buffer;
886 struct hpi_hostbuffer_status *status;
889 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
891 if (hpios_locked_mem_get_virt_addr(&phw->
892 outstream_host_buffers[phm->obj_index],
893 (void *)&p_bbm_data)) {
894 phr->error = HPI_ERROR_INVALID_OPERATION;
897 status = &interface->outstream_host_buffer_status[phm->
899 hpi_init_response(phr, HPI_OBJ_OSTREAM,
900 HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
901 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
902 phr->u.d.u.hostbuffer_info.p_status = status;
904 hpi_init_response(phr, HPI_OBJ_OSTREAM,
905 HPI_OSTREAM_HOSTBUFFER_GET_INFO,
906 HPI_ERROR_INVALID_OPERATION);
910 static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
911 struct hpi_message *phm, struct hpi_response *phr)
913 struct hpi_hw_obj *phw = pao->priv;
914 u32 command = phm->u.d.u.buffer.command;
916 if (phw->outstream_host_buffer_size[phm->obj_index]) {
917 if (command == HPI_BUFFER_CMD_EXTERNAL
918 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
919 phw->outstream_host_buffer_size[phm->obj_index] = 0;
920 hw_message(pao, phm, phr);
921 /* Tell adapter to stop using the host buffer. */
923 if (command == HPI_BUFFER_CMD_EXTERNAL
924 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
925 hpios_locked_mem_free(&phw->outstream_host_buffers
928 /* Should HPI_ERROR_INVALID_OPERATION be returned
929 if no host buffer is allocated? */
931 hpi_init_response(phr, HPI_OBJ_OSTREAM,
932 HPI_OSTREAM_HOSTBUFFER_FREE, 0);
936 static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)
938 return status->size_in_bytes - (status->host_index -
942 static void outstream_write(struct hpi_adapter_obj *pao,
943 struct hpi_message *phm, struct hpi_response *phr)
945 struct hpi_hw_obj *phw = pao->priv;
946 struct bus_master_interface *interface = phw->p_interface_buffer;
947 struct hpi_hostbuffer_status *status;
950 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
951 /* there is no BBM buffer, write via message */
952 hw_message(pao, phm, phr);
956 hpi_init_response(phr, phm->object, phm->function, 0);
957 status = &interface->outstream_host_buffer_status[phm->obj_index];
959 space_available = outstream_get_space_available(status);
960 if (space_available < phm->u.d.u.data.data_size) {
961 phr->error = HPI_ERROR_INVALID_DATASIZE;
965 /* HostBuffers is used to indicate host buffer is internally allocated.
966 otherwise, assumed external, data written externally */
967 if (phm->u.d.u.data.pb_data
968 && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
972 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
974 if (hpios_locked_mem_get_virt_addr(&phw->
975 outstream_host_buffers[phm->obj_index],
976 (void *)&p_bbm_data)) {
977 phr->error = HPI_ERROR_INVALID_OPERATION;
982 or enough to fit from current to end of BBM buffer */
984 min(phm->u.d.u.data.data_size,
985 status->size_in_bytes -
986 (status->host_index & (status->size_in_bytes - 1)));
989 (status->host_index & (status->size_in_bytes - 1)),
990 p_app_data, l_first_write);
991 /* remaining data if any */
992 memcpy(p_bbm_data, p_app_data + l_first_write,
993 phm->u.d.u.data.data_size - l_first_write);
997 * This version relies on the DSP code triggering an OStream buffer
998 * update immediately following a SET_FORMAT call. The host has
999 * already written data into the BBM buffer, but the DSP won't know
1000 * about it until dwHostIndex is adjusted.
1002 if (phw->flag_outstream_just_reset[phm->obj_index]) {
1003 /* Format can only change after reset. Must tell DSP. */
1004 u16 function = phm->function;
1005 phw->flag_outstream_just_reset[phm->obj_index] = 0;
1006 phm->function = HPI_OSTREAM_SET_FORMAT;
1007 hw_message(pao, phm, phr); /* send the format to the DSP */
1008 phm->function = function;
1013 status->host_index += phm->u.d.u.data.data_size;
1016 static void outstream_get_info(struct hpi_adapter_obj *pao,
1017 struct hpi_message *phm, struct hpi_response *phr)
1019 struct hpi_hw_obj *phw = pao->priv;
1020 struct bus_master_interface *interface = phw->p_interface_buffer;
1021 struct hpi_hostbuffer_status *status;
1023 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
1024 hw_message(pao, phm, phr);
1028 hpi_init_response(phr, phm->object, phm->function, 0);
1030 status = &interface->outstream_host_buffer_status[phm->obj_index];
1032 phr->u.d.u.stream_info.state = (u16)status->stream_state;
1033 phr->u.d.u.stream_info.samples_transferred =
1034 status->samples_processed;
1035 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
1036 phr->u.d.u.stream_info.data_available =
1037 status->size_in_bytes - outstream_get_space_available(status);
1038 phr->u.d.u.stream_info.auxiliary_data_available =
1039 status->auxiliary_data_available;
1042 static void outstream_start(struct hpi_adapter_obj *pao,
1043 struct hpi_message *phm, struct hpi_response *phr)
1045 hw_message(pao, phm, phr);
1048 static void outstream_reset(struct hpi_adapter_obj *pao,
1049 struct hpi_message *phm, struct hpi_response *phr)
1051 struct hpi_hw_obj *phw = pao->priv;
1052 phw->flag_outstream_just_reset[phm->obj_index] = 1;
1053 hw_message(pao, phm, phr);
1056 static void outstream_open(struct hpi_adapter_obj *pao,
1057 struct hpi_message *phm, struct hpi_response *phr)
1059 outstream_reset(pao, phm, phr);
1062 /*****************************************************************************/
1063 /* InStream Host buffer functions */
1065 static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
1066 struct hpi_message *phm, struct hpi_response *phr)
1069 u32 command = phm->u.d.u.buffer.command;
1070 struct hpi_hw_obj *phw = pao->priv;
1071 struct bus_master_interface *interface = phw->p_interface_buffer;
1073 hpi_init_response(phr, phm->object, phm->function, 0);
1075 if (command == HPI_BUFFER_CMD_EXTERNAL
1076 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
1078 phm->u.d.u.buffer.buffer_size =
1079 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
1080 phr->u.d.u.stream_info.data_available =
1081 phw->instream_host_buffer_size[phm->obj_index];
1082 phr->u.d.u.stream_info.buffer_size =
1083 phm->u.d.u.buffer.buffer_size;
1085 if (phw->instream_host_buffer_size[phm->obj_index] ==
1086 phm->u.d.u.buffer.buffer_size) {
1087 /* Same size, no action required */
1091 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1093 hpios_locked_mem_free(&phw->instream_host_buffers
1096 err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
1097 obj_index], phm->u.d.u.buffer.buffer_size,
1101 phr->error = HPI_ERROR_INVALID_DATASIZE;
1102 phw->instream_host_buffer_size[phm->obj_index] = 0;
1106 err = hpios_locked_mem_get_phys_addr
1107 (&phw->instream_host_buffers[phm->obj_index],
1108 &phm->u.d.u.buffer.pci_address);
1109 /* get the phys addr into msg for single call alloc. Caller
1110 needs to do this for split alloc so return the phy address */
1111 phr->u.d.u.stream_info.auxiliary_data_available =
1112 phm->u.d.u.buffer.pci_address;
1114 hpios_locked_mem_free(&phw->instream_host_buffers
1116 phw->instream_host_buffer_size[phm->obj_index] = 0;
1117 phr->error = HPI_ERROR_MEMORY_ALLOC;
1122 if (command == HPI_BUFFER_CMD_EXTERNAL
1123 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
1124 struct hpi_hostbuffer_status *status;
1126 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
1128 HPI_DEBUG_LOG(ERROR,
1129 "Buffer size must be 2^N not %d\n",
1130 phm->u.d.u.buffer.buffer_size);
1131 phr->error = HPI_ERROR_INVALID_DATASIZE;
1135 phw->instream_host_buffer_size[phm->obj_index] =
1136 phm->u.d.u.buffer.buffer_size;
1137 status = &interface->instream_host_buffer_status[phm->
1139 status->samples_processed = 0;
1140 status->stream_state = HPI_STATE_STOPPED;
1141 status->dSP_index = 0;
1142 status->host_index = status->dSP_index;
1143 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
1144 status->auxiliary_data_available = 0;
1146 hw_message(pao, phm, phr);
1148 && hpios_locked_mem_valid(&phw->
1149 instream_host_buffers[phm->obj_index])) {
1150 hpios_locked_mem_free(&phw->instream_host_buffers
1152 phw->instream_host_buffer_size[phm->obj_index] = 0;
1157 static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
1158 struct hpi_message *phm, struct hpi_response *phr)
1160 struct hpi_hw_obj *phw = pao->priv;
1161 struct bus_master_interface *interface = phw->p_interface_buffer;
1162 struct hpi_hostbuffer_status *status;
1165 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1167 if (hpios_locked_mem_get_virt_addr(&phw->
1168 instream_host_buffers[phm->obj_index],
1169 (void *)&p_bbm_data)) {
1170 phr->error = HPI_ERROR_INVALID_OPERATION;
1173 status = &interface->instream_host_buffer_status[phm->
1175 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1176 HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
1177 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
1178 phr->u.d.u.hostbuffer_info.p_status = status;
1180 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1181 HPI_ISTREAM_HOSTBUFFER_GET_INFO,
1182 HPI_ERROR_INVALID_OPERATION);
1186 static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
1187 struct hpi_message *phm, struct hpi_response *phr)
1189 struct hpi_hw_obj *phw = pao->priv;
1190 u32 command = phm->u.d.u.buffer.command;
1192 if (phw->instream_host_buffer_size[phm->obj_index]) {
1193 if (command == HPI_BUFFER_CMD_EXTERNAL
1194 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
1195 phw->instream_host_buffer_size[phm->obj_index] = 0;
1196 hw_message(pao, phm, phr);
1199 if (command == HPI_BUFFER_CMD_EXTERNAL
1200 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
1201 hpios_locked_mem_free(&phw->instream_host_buffers
1205 /* Should HPI_ERROR_INVALID_OPERATION be returned
1206 if no host buffer is allocated? */
1207 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1208 HPI_ISTREAM_HOSTBUFFER_FREE, 0);
1214 static void instream_start(struct hpi_adapter_obj *pao,
1215 struct hpi_message *phm, struct hpi_response *phr)
1217 hw_message(pao, phm, phr);
1220 static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
1222 return status->dSP_index - status->host_index;
1225 static void instream_read(struct hpi_adapter_obj *pao,
1226 struct hpi_message *phm, struct hpi_response *phr)
1228 struct hpi_hw_obj *phw = pao->priv;
1229 struct bus_master_interface *interface = phw->p_interface_buffer;
1230 struct hpi_hostbuffer_status *status;
1234 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
1236 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1237 hw_message(pao, phm, phr);
1240 hpi_init_response(phr, phm->object, phm->function, 0);
1242 status = &interface->instream_host_buffer_status[phm->obj_index];
1243 data_available = instream_get_bytes_available(status);
1244 if (data_available < phm->u.d.u.data.data_size) {
1245 phr->error = HPI_ERROR_INVALID_DATASIZE;
1249 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1251 if (hpios_locked_mem_get_virt_addr(&phw->
1252 instream_host_buffers[phm->obj_index],
1253 (void *)&p_bbm_data)) {
1254 phr->error = HPI_ERROR_INVALID_OPERATION;
1259 or enough to fit from current to end of BBM buffer */
1261 min(phm->u.d.u.data.data_size,
1262 status->size_in_bytes -
1263 (status->host_index & (status->size_in_bytes - 1)));
1267 (status->host_index & (status->size_in_bytes - 1)),
1269 /* remaining data if any */
1270 memcpy(p_app_data + l_first_read, p_bbm_data,
1271 phm->u.d.u.data.data_size - l_first_read);
1273 status->host_index += phm->u.d.u.data.data_size;
1276 static void instream_get_info(struct hpi_adapter_obj *pao,
1277 struct hpi_message *phm, struct hpi_response *phr)
1279 struct hpi_hw_obj *phw = pao->priv;
1280 struct bus_master_interface *interface = phw->p_interface_buffer;
1281 struct hpi_hostbuffer_status *status;
1282 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1283 hw_message(pao, phm, phr);
1287 status = &interface->instream_host_buffer_status[phm->obj_index];
1289 hpi_init_response(phr, phm->object, phm->function, 0);
1291 phr->u.d.u.stream_info.state = (u16)status->stream_state;
1292 phr->u.d.u.stream_info.samples_transferred =
1293 status->samples_processed;
1294 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
1295 phr->u.d.u.stream_info.data_available =
1296 instream_get_bytes_available(status);
1297 phr->u.d.u.stream_info.auxiliary_data_available =
1298 status->auxiliary_data_available;
1301 /*****************************************************************************/
1303 #define HPI6205_MAX_FILES_TO_LOAD 2
1305 static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
1306 u32 *pos_error_code)
1308 struct hpi_hw_obj *phw = pao->priv;
1309 struct dsp_code dsp_code;
1310 u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
1311 u16 firmware_id = pao->pci.pci_dev->subsystem_device;
1316 boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
1318 /* special cases where firmware_id != subsys ID */
1319 switch (firmware_id) {
1320 case HPI_ADAPTER_FAMILY_ASI(0x5000):
1321 boot_code_id[0] = firmware_id;
1324 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1325 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1326 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1327 firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6400);
1329 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1330 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1331 firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6600);
1333 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1334 firmware_id = HPI_ADAPTER_FAMILY_ASI(0x8900);
1337 boot_code_id[1] = firmware_id;
1339 /* reset DSP by writing a 1 to the WARMRESET bit */
1340 temp = C6205_HDCR_WARMRESET;
1341 iowrite32(temp, phw->prHDCR);
1342 hpios_delay_micro_seconds(1000);
1344 /* check that PCI i/f was configured by EEPROM */
1345 temp = ioread32(phw->prHSR);
1346 if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
1348 return HPI6205_ERROR_6205_EEPROM;
1350 /* disable PINTA interrupt */
1351 iowrite32(temp, phw->prHSR);
1353 /* check control register reports PCI boot mode */
1354 temp = ioread32(phw->prHDCR);
1355 if (!(temp & C6205_HDCR_PCIBOOT))
1356 return HPI6205_ERROR_6205_REG;
1358 /* try writing a few numbers to the DSP page register */
1359 /* and reading them back. */
1361 iowrite32(temp, phw->prDSPP);
1362 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1363 return HPI6205_ERROR_6205_DSPPAGE;
1365 iowrite32(temp, phw->prDSPP);
1366 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1367 return HPI6205_ERROR_6205_DSPPAGE;
1369 iowrite32(temp, phw->prDSPP);
1370 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1371 return HPI6205_ERROR_6205_DSPPAGE;
1372 /* reset DSP page to the correct number */
1374 iowrite32(temp, phw->prDSPP);
1375 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1376 return HPI6205_ERROR_6205_DSPPAGE;
1379 /* release 6713 from reset before 6205 is bootloaded.
1380 This ensures that the EMIF is inactive,
1381 and the 6713 HPI gets the correct bootmode etc
1383 if (boot_code_id[1] != 0) {
1384 /* DSP 1 is a C6713 */
1385 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1386 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
1387 hpios_delay_micro_seconds(100);
1388 /* Reset the 6713 #1 - revB */
1389 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
1391 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1392 boot_loader_read_mem32(pao, 0, 0);
1394 hpios_delay_micro_seconds(100);
1395 /* Release C6713 from reset - revB */
1396 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
1397 hpios_delay_micro_seconds(100);
1400 for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
1401 /* is there a DSP to load? */
1402 if (boot_code_id[dsp] == 0)
1405 err = boot_loader_config_emif(pao, dsp);
1409 err = boot_loader_test_internal_memory(pao, dsp);
1413 err = boot_loader_test_external_memory(pao, dsp);
1417 err = boot_loader_test_pld(pao, dsp);
1421 /* write the DSP code down into the DSPs memory */
1422 dsp_code.ps_dev = pao->pci.pci_dev;
1423 err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
1434 err = hpi_dsp_code_read_word(&dsp_code, &length);
1437 if (length == 0xFFFFFFFF)
1438 break; /* end of code */
1440 err = hpi_dsp_code_read_word(&dsp_code, &address);
1443 err = hpi_dsp_code_read_word(&dsp_code, &type);
1446 err = hpi_dsp_code_read_block(length, &dsp_code,
1450 for (i = 0; i < (int)length; i++) {
1451 boot_loader_write_mem32(pao, dsp, address,
1453 /* dummy read every 4 words */
1454 /* for 6205 advisory 1.4.4 */
1456 boot_loader_read_mem32(pao, dsp,
1464 hpi_dsp_code_close(&dsp_code);
1469 hpi_dsp_code_rewind(&dsp_code);
1477 hpi_dsp_code_read_word(&dsp_code, &length);
1478 if (length == 0xFFFFFFFF)
1479 break; /* end of code */
1481 hpi_dsp_code_read_word(&dsp_code, &address);
1482 hpi_dsp_code_read_word(&dsp_code, &type);
1483 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
1485 for (i = 0; i < (int)length; i++) {
1486 data = boot_loader_read_mem32(pao, dsp,
1488 if (data != *pcode) {
1498 hpi_dsp_code_close(&dsp_code);
1503 /* After bootloading all DSPs, start DSP0 running
1504 * The DSP0 code will handle starting and synchronizing with its slaves
1506 if (phw->p_interface_buffer) {
1507 /* we need to tell the card the physical PCI address */
1508 u32 physicalPC_iaddress;
1509 struct bus_master_interface *interface =
1510 phw->p_interface_buffer;
1511 u32 host_mailbox_address_on_dsp;
1512 u32 physicalPC_iaddress_verify = 0;
1514 /* set ack so we know when DSP is ready to go */
1515 /* (dwDspAck will be changed to HIF_RESET) */
1516 interface->dsp_ack = H620_HIF_UNKNOWN;
1517 wmb(); /* ensure ack is written before dsp writes back */
1519 err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
1520 &physicalPC_iaddress);
1522 /* locate the host mailbox on the DSP. */
1523 host_mailbox_address_on_dsp = 0x80000000;
1524 while ((physicalPC_iaddress != physicalPC_iaddress_verify)
1526 boot_loader_write_mem32(pao, 0,
1527 host_mailbox_address_on_dsp,
1528 physicalPC_iaddress);
1529 physicalPC_iaddress_verify =
1530 boot_loader_read_mem32(pao, 0,
1531 host_mailbox_address_on_dsp);
1534 HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
1535 /* enable interrupts */
1536 temp = ioread32(phw->prHSR);
1537 temp &= ~(u32)C6205_HSR_INTAM;
1538 iowrite32(temp, phw->prHSR);
1540 /* start code running... */
1541 temp = ioread32(phw->prHDCR);
1542 temp |= (u32)C6205_HDCR_DSPINT;
1543 iowrite32(temp, phw->prHDCR);
1545 /* give the DSP 10ms to start up */
1546 hpios_delay_micro_seconds(10000);
1551 /*****************************************************************************/
1552 /* Bootloader utility functions */
1554 static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
1557 struct hpi_hw_obj *phw = pao->priv;
1559 __iomem u32 *p_data;
1561 if (dsp_index == 0) {
1562 /* DSP 0 is always C6205 */
1563 if ((address >= 0x01800000) & (address < 0x02000000)) {
1564 /* BAR1 register access */
1565 p_data = pao->pci.ap_mem_base[1] +
1566 (address & 0x007fffff) /
1567 sizeof(*pao->pci.ap_mem_base[1]);
1568 /* HPI_DEBUG_LOG(WARNING,
1569 "BAR1 access %08x\n", dwAddress); */
1571 u32 dw4M_page = address >> 22L;
1572 if (dw4M_page != phw->dsp_page) {
1573 phw->dsp_page = dw4M_page;
1575 iowrite32(phw->dsp_page, phw->prDSPP);
1578 address &= 0x3fffff; /* address within 4M page */
1579 /* BAR0 memory access */
1580 p_data = pao->pci.ap_mem_base[0] +
1581 address / sizeof(u32);
1583 data = ioread32(p_data);
1584 } else if (dsp_index == 1) {
1585 /* DSP 1 is a C6713 */
1587 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1588 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1589 lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
1590 data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
1591 data = (data << 16) | (lsb & 0xFFFF);
1596 static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
1597 int dsp_index, u32 address, u32 data)
1599 struct hpi_hw_obj *phw = pao->priv;
1600 __iomem u32 *p_data;
1601 /* u32 dwVerifyData=0; */
1603 if (dsp_index == 0) {
1604 /* DSP 0 is always C6205 */
1605 if ((address >= 0x01800000) & (address < 0x02000000)) {
1606 /* BAR1 - DSP register access using */
1607 /* Non-prefetchable PCI access */
1608 p_data = pao->pci.ap_mem_base[1] +
1609 (address & 0x007fffff) /
1610 sizeof(*pao->pci.ap_mem_base[1]);
1612 /* BAR0 access - all of DSP memory using */
1613 /* pre-fetchable PCI access */
1614 u32 dw4M_page = address >> 22L;
1615 if (dw4M_page != phw->dsp_page) {
1616 phw->dsp_page = dw4M_page;
1618 iowrite32(phw->dsp_page, phw->prDSPP);
1621 address &= 0x3fffff; /* address within 4M page */
1622 p_data = pao->pci.ap_mem_base[0] +
1623 address / sizeof(u32);
1625 iowrite32(data, p_data);
1626 } else if (dsp_index == 1) {
1627 /* DSP 1 is a C6713 */
1628 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1629 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1631 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1632 boot_loader_read_mem32(pao, 0, 0);
1634 boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
1635 boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
1637 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1638 boot_loader_read_mem32(pao, 0, 0);
1642 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
1644 if (dsp_index == 0) {
1647 /* DSP 0 is always C6205 */
1650 /* memory map of C6205 */
1651 /* 00000000-0000FFFF 16Kx32 internal program */
1652 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1656 /* Global EMIF control */
1657 boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
1666 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1667 setting = 0x00000030;
1668 boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
1669 if (setting != boot_loader_read_mem32(pao, dsp_index,
1671 return HPI6205_ERROR_DSP_EMIF;
1673 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1674 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1675 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1676 /* WST should be 71, but 63 is max possible */
1678 (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
1679 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1681 boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
1682 if (setting != boot_loader_read_mem32(pao, dsp_index,
1684 return HPI6205_ERROR_DSP_EMIF;
1686 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1687 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1688 /* plenty of wait states */
1690 (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
1691 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1693 boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
1694 if (setting != boot_loader_read_mem32(pao, dsp_index,
1696 return HPI6205_ERROR_DSP_EMIF;
1698 /* EMIF CE3 setup - 32 bit async. */
1699 /* This is the PLD on the ASI5000 cards only */
1701 (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
1702 (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
1704 boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
1705 if (setting != boot_loader_read_mem32(pao, dsp_index,
1707 return HPI6205_ERROR_DSP_EMIF;
1709 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1710 /* need to use this else DSP code crashes? */
1711 boot_loader_write_mem32(pao, dsp_index, 0x01800018,
1714 /* EMIF SDRAM Refresh Timing */
1715 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1716 boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
1719 } else if (dsp_index == 1) {
1720 /* test access to the C6713s HPI registers */
1721 u32 write_data = 0, read_data = 0, i = 0;
1723 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1725 boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
1726 boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
1727 /* C67 HPI is on lower 16bits of 32bit EMIF */
1729 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
1730 if (write_data != read_data) {
1731 HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
1733 return HPI6205_ERROR_C6713_HPIC;
1735 /* HPIA - walking ones test */
1737 for (i = 0; i < 32; i++) {
1738 boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
1740 boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
1741 (write_data >> 16));
1743 0xFFFF & boot_loader_read_mem32(pao, 0,
1746 read_data | ((0xFFFF &
1747 boot_loader_read_mem32(pao, 0,
1750 if (read_data != write_data) {
1751 HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
1752 write_data, read_data);
1753 return HPI6205_ERROR_C6713_HPIA;
1755 write_data = write_data << 1;
1759 * ** C6713 datasheet says we cannot program PLL from HPI,
1760 * and indeed if we try to set the PLL multiply from the HPI,
1761 * the PLL does not seem to lock, so we enable the PLL and
1762 * use the default multiply of x 7, which for a 27MHz clock
1763 * gives a DSP speed of 189MHz
1766 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
1767 hpios_delay_micro_seconds(1000);
1768 /* EMIF = 189/3=63MHz */
1769 boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
1771 boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
1773 boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
1774 hpios_delay_micro_seconds(1000);
1775 /* ** SGT test to take GPO3 high when we start the PLL */
1776 /* and low when the delay is completed */
1777 /* FSX0 <- '1' (GPO3) */
1778 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
1779 /* PLL not bypassed */
1780 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
1781 hpios_delay_micro_seconds(1000);
1782 /* FSX0 <- '0' (GPO3) */
1783 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
1785 /* 6205 EMIF CE1 resetup - 32 bit async. */
1786 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1787 boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
1788 (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
1789 (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
1792 hpios_delay_micro_seconds(1000);
1794 /* check that we can read one of the PLL registers */
1795 /* PLL should not be bypassed! */
1796 if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
1798 return HPI6205_ERROR_C6713_PLL;
1800 /* setup C67x EMIF (note this is the only use of
1801 BAR1 via BootLoader_WriteMem32) */
1802 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
1804 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
1806 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
1808 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
1810 boot_loader_write_mem32(pao, dsp_index,
1811 C6713_EMIF_SDRAMTIMING, 0x00000410);
1813 hpios_delay_micro_seconds(1000);
1814 } else if (dsp_index == 2) {
1815 /* DSP 2 is a C6713 */
1821 static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
1822 u32 start_address, u32 length)
1826 u32 test_data = 0, data = 0;
1830 /* for 1st word, test each bit in the 32bit word, */
1831 /* dwLength specifies number of 32bit words to test */
1832 /*for(i=0; i<dwLength; i++) */
1835 test_addr = start_address + i * 4;
1836 test_data = 0x00000001;
1837 for (j = 0; j < 32; j++) {
1838 boot_loader_write_mem32(pao, dsp_index, test_addr,
1840 data = boot_loader_read_mem32(pao, dsp_index,
1842 if (data != test_data) {
1843 HPI_DEBUG_LOG(VERBOSE,
1844 "Memtest error details "
1845 "%08x %08x %08x %i\n", test_addr,
1846 test_data, data, dsp_index);
1847 return 1; /* error */
1849 test_data = test_data << 1;
1853 /* for the next 100 locations test each location, leaving it as zero */
1854 /* write a zero to the next word in memory before we read */
1855 /* the previous write to make sure every memory location is unique */
1856 for (i = 0; i < 100; i++) {
1857 test_addr = start_address + i * 4;
1858 test_data = 0xA5A55A5A;
1859 boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
1860 boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
1861 data = boot_loader_read_mem32(pao, dsp_index, test_addr);
1862 if (data != test_data) {
1863 HPI_DEBUG_LOG(VERBOSE,
1864 "Memtest error details "
1865 "%08x %08x %08x %i\n", test_addr, test_data,
1867 return 1; /* error */
1869 /* leave location as zero */
1870 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1873 /* zero out entire memory block */
1874 for (i = 0; i < length; i++) {
1875 test_addr = start_address + i * 4;
1876 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1881 static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
1885 if (dsp_index == 0) {
1886 /* DSP 0 is a C6205 */
1888 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1892 err = boot_loader_test_memory(pao, dsp_index,
1893 0x80000000, 0x10000);
1894 } else if (dsp_index == 1) {
1895 /* DSP 1 is a C6713 */
1896 /* 192K internal mem */
1897 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1900 /* 64K internal mem / L2 cache */
1901 err = boot_loader_test_memory(pao, dsp_index,
1902 0x00030000, 0x10000);
1906 return HPI6205_ERROR_DSP_INTMEM;
1911 static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
1914 u32 dRAM_start_address = 0;
1917 if (dsp_index == 0) {
1918 /* only test for SDRAM if an ASI5000 card */
1919 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
1920 /* DSP 0 is always C6205 */
1921 dRAM_start_address = 0x00400000;
1922 dRAM_size = 0x200000;
1923 /*dwDRAMinc=1024; */
1926 } else if (dsp_index == 1) {
1927 /* DSP 1 is a C6713 */
1928 dRAM_start_address = 0x80000000;
1929 dRAM_size = 0x200000;
1930 /*dwDRAMinc=1024; */
1933 if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
1935 return HPI6205_ERROR_DSP_EXTMEM;
1939 static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
1942 if (dsp_index == 0) {
1943 /* only test for DSP0 PLD on ASI5000 card */
1944 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
1945 /* PLD is located at CE3=0x03000000 */
1946 data = boot_loader_read_mem32(pao, dsp_index,
1948 if ((data & 0xF) != 0x5)
1949 return HPI6205_ERROR_DSP_PLD;
1950 data = boot_loader_read_mem32(pao, dsp_index,
1952 if ((data & 0xF) != 0xA)
1953 return HPI6205_ERROR_DSP_PLD;
1955 } else if (dsp_index == 1) {
1956 /* DSP 1 is a C6713 */
1957 if (pao->pci.pci_dev->subsystem_device == 0x8700) {
1958 /* PLD is located at CE1=0x90000000 */
1959 data = boot_loader_read_mem32(pao, dsp_index,
1961 if ((data & 0xFF) != 0xAA)
1962 return HPI6205_ERROR_DSP_PLD;
1964 boot_loader_write_mem32(pao, dsp_index, 0x90000000,
1971 /** Transfer data to or from DSP
1972 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
1974 static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
1975 u32 data_size, int operation)
1977 struct hpi_hw_obj *phw = pao->priv;
1978 u32 data_transferred = 0;
1980 #ifndef HPI6205_NO_HSR_POLL
1984 struct bus_master_interface *interface = phw->p_interface_buffer;
1987 return HPI_ERROR_INVALID_DATA_POINTER;
1989 data_size &= ~3L; /* round data_size down to nearest 4 bytes */
1991 /* make sure state is IDLE */
1992 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
1993 return HPI_ERROR_DSP_HARDWARE;
1995 while (data_transferred < data_size) {
1996 u32 this_copy = data_size - data_transferred;
1998 if (this_copy > HPI6205_SIZEOF_DATA)
1999 this_copy = HPI6205_SIZEOF_DATA;
2001 if (operation == H620_HIF_SEND_DATA)
2002 memcpy((void *)&interface->u.b_data[0],
2003 &p_data[data_transferred], this_copy);
2005 interface->transfer_size_in_bytes = this_copy;
2007 #ifdef HPI6205_NO_HSR_POLL
2008 /* DSP must change this back to nOperation */
2009 interface->dsp_ack = H620_HIF_IDLE;
2012 send_dsp_command(phw, operation);
2014 #ifdef HPI6205_NO_HSR_POLL
2015 temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
2016 HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
2017 HPI6205_TIMEOUT - temp2, this_copy);
2021 HPI_DEBUG_LOG(ERROR,
2022 "Timed out waiting for " "state %d got %d\n",
2023 operation, interface->dsp_ack);
2028 /* spin waiting on the result */
2029 time_out = HPI6205_TIMEOUT;
2031 while ((temp2 == 0) && time_out--) {
2032 /* give 16k bus mastering transfer time to happen */
2033 /*(16k / 132Mbytes/s = 122usec) */
2034 hpios_delay_micro_seconds(20);
2035 temp2 = ioread32(phw->prHSR);
2036 temp2 &= C6205_HSR_INTSRC;
2038 HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
2039 HPI6205_TIMEOUT - time_out, this_copy);
2040 if (temp2 == C6205_HSR_INTSRC) {
2041 HPI_DEBUG_LOG(VERBOSE,
2042 "Interrupt from HIF <data> OK\n");
2044 if(interface->dwDspAck != nOperation) {
2045 HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d,
2047 interface->dwDspAck,nOperation);
2051 /* need to handle this differently... */
2053 HPI_DEBUG_LOG(ERROR,
2054 "Interrupt from HIF <data> BAD\n");
2055 err = HPI_ERROR_DSP_HARDWARE;
2058 /* reset the interrupt from the DSP */
2059 iowrite32(C6205_HSR_INTSRC, phw->prHSR);
2061 if (operation == H620_HIF_GET_DATA)
2062 memcpy(&p_data[data_transferred],
2063 (void *)&interface->u.b_data[0], this_copy);
2065 data_transferred += this_copy;
2067 if (interface->dsp_ack != operation)
2068 HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
2069 interface->dsp_ack, operation);
2070 /* err=HPI_ERROR_DSP_HARDWARE; */
2072 send_dsp_command(phw, H620_HIF_IDLE);
2077 /* wait for up to timeout_us microseconds for the DSP
2078 to signal state by DMA into dwDspAck
2080 static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
2082 struct bus_master_interface *interface = phw->p_interface_buffer;
2083 int t = timeout_us / 4;
2085 rmb(); /* ensure interface->dsp_ack is up to date */
2086 while ((interface->dsp_ack != state) && --t) {
2087 hpios_delay_micro_seconds(4);
2088 rmb(); /* DSP changes dsp_ack by DMA */
2091 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2095 /* set the busmaster interface to cmd, then interrupt the DSP */
2096 static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
2098 struct bus_master_interface *interface = phw->p_interface_buffer;
2102 interface->host_cmd = cmd;
2103 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2104 /* before we interrupt the DSP */
2105 r = ioread32(phw->prHDCR);
2106 r |= (u32)C6205_HDCR_DSPINT;
2107 iowrite32(r, phw->prHDCR);
2108 r &= ~(u32)C6205_HDCR_DSPINT;
2109 iowrite32(r, phw->prHDCR);
2112 static unsigned int message_count;
2114 static u16 message_response_sequence(struct hpi_adapter_obj *pao,
2115 struct hpi_message *phm, struct hpi_response *phr)
2117 #ifndef HPI6205_NO_HSR_POLL
2120 u32 time_out, time_out2;
2121 struct hpi_hw_obj *phw = pao->priv;
2122 struct bus_master_interface *interface = phw->p_interface_buffer;
2126 if (phm->size > sizeof(interface->u)) {
2127 phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
2128 phr->specific_error = sizeof(interface->u);
2129 phr->size = sizeof(struct hpi_response_header);
2130 HPI_DEBUG_LOG(ERROR,
2131 "message len %d too big for buffer %ld \n", phm->size,
2132 sizeof(interface->u));
2136 /* Assume buffer of type struct bus_master_interface
2137 is allocated "noncacheable" */
2139 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2140 HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
2141 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
2144 memcpy(&interface->u.message_buffer, phm, phm->size);
2145 /* signal we want a response */
2146 send_dsp_command(phw, H620_HIF_GET_RESP);
2148 time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
2151 HPI_DEBUG_LOG(ERROR,
2152 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
2153 message_count, interface->dsp_ack);
2155 HPI_DEBUG_LOG(VERBOSE,
2156 "(%u) transition to GET_RESP after %u\n",
2157 message_count, HPI6205_TIMEOUT - time_out2);
2159 /* spin waiting on HIF interrupt flag (end of msg process) */
2160 time_out = HPI6205_TIMEOUT;
2162 #ifndef HPI6205_NO_HSR_POLL
2164 while ((temp2 == 0) && --time_out) {
2165 temp2 = ioread32(phw->prHSR);
2166 temp2 &= C6205_HSR_INTSRC;
2167 hpios_delay_micro_seconds(1);
2169 if (temp2 == C6205_HSR_INTSRC) {
2170 rmb(); /* ensure we see latest value for dsp_ack */
2171 if ((interface->dsp_ack != H620_HIF_GET_RESP)) {
2172 HPI_DEBUG_LOG(DEBUG,
2173 "(%u)interface->dsp_ack(0x%x) != "
2174 "H620_HIF_GET_RESP, t=%u\n", message_count,
2176 HPI6205_TIMEOUT - time_out);
2178 HPI_DEBUG_LOG(VERBOSE,
2179 "(%u)int with GET_RESP after %u\n",
2180 message_count, HPI6205_TIMEOUT - time_out);
2184 /* can we do anything else in response to the error ? */
2185 HPI_DEBUG_LOG(ERROR,
2186 "Interrupt from HIF module BAD (function %x)\n",
2190 /* reset the interrupt from the DSP */
2191 iowrite32(C6205_HSR_INTSRC, phw->prHSR);
2194 /* read the result */
2196 if (interface->u.response_buffer.size <= phr->size)
2197 memcpy(phr, &interface->u.response_buffer,
2198 interface->u.response_buffer.size);
2200 HPI_DEBUG_LOG(ERROR,
2201 "response len %d too big for buffer %d\n",
2202 interface->u.response_buffer.size, phr->size);
2203 memcpy(phr, &interface->u.response_buffer,
2204 sizeof(struct hpi_response_header));
2205 phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
2206 phr->specific_error =
2207 interface->u.response_buffer.size;
2208 phr->size = sizeof(struct hpi_response_header);
2211 /* set interface back to idle */
2212 send_dsp_command(phw, H620_HIF_IDLE);
2214 if (!time_out || !time_out2) {
2215 HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
2216 return HPI6205_ERROR_MSG_RESP_TIMEOUT;
2218 /* special case for adapter close - */
2219 /* wait for the DSP to indicate it is idle */
2220 if (phm->function == HPI_ADAPTER_CLOSE) {
2221 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2222 HPI_DEBUG_LOG(DEBUG,
2223 "Timeout waiting for idle "
2224 "(on adapter_close)\n");
2225 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
2228 err = hpi_validate_response(phm, phr);
2232 static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
2233 struct hpi_response *phr)
2238 hpios_dsplock_lock(pao);
2240 err = message_response_sequence(pao, phm, phr);
2242 /* maybe an error response */
2244 /* something failed in the HPI/DSP interface */
2248 /* just the header of the response is valid */
2249 phr->size = sizeof(struct hpi_response_header);
2252 pao->dsp_crashed = 0;
2254 if (phr->error != 0) /* something failed in the DSP */
2257 switch (phm->function) {
2258 case HPI_OSTREAM_WRITE:
2259 case HPI_ISTREAM_ANC_WRITE:
2260 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2261 phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
2264 case HPI_ISTREAM_READ:
2265 case HPI_OSTREAM_ANC_READ:
2266 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2267 phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
2270 case HPI_CONTROL_SET_STATE:
2271 if (phm->object == HPI_OBJ_CONTROLEX
2272 && phm->u.cx.attribute == HPI_COBRANET_SET_DATA)
2273 err = hpi6205_transfer_data(pao,
2274 phm->u.cx.u.cobranet_bigdata.pb_data,
2275 phm->u.cx.u.cobranet_bigdata.byte_count,
2276 H620_HIF_SEND_DATA);
2279 case HPI_CONTROL_GET_STATE:
2280 if (phm->object == HPI_OBJ_CONTROLEX
2281 && phm->u.cx.attribute == HPI_COBRANET_GET_DATA)
2282 err = hpi6205_transfer_data(pao,
2283 phm->u.cx.u.cobranet_bigdata.pb_data,
2284 phr->u.cx.u.cobranet_data.byte_count,
2291 hpios_dsplock_unlock(pao);