1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2014 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_EMIF1 1018
60 #define HPI6205_ERROR_DSP_EMIF2 1019
61 #define HPI6205_ERROR_DSP_EMIF3 1020
62 #define HPI6205_ERROR_DSP_EMIF4 1021
64 /*****************************************************************************/
65 /* for C6205 PCI i/f */
66 /* Host Status Register (HSR) bitfields */
67 #define C6205_HSR_INTSRC 0x01
68 #define C6205_HSR_INTAVAL 0x02
69 #define C6205_HSR_INTAM 0x04
70 #define C6205_HSR_CFGERR 0x08
71 #define C6205_HSR_EEREAD 0x10
72 /* Host-to-DSP Control Register (HDCR) bitfields */
73 #define C6205_HDCR_WARMRESET 0x01
74 #define C6205_HDCR_DSPINT 0x02
75 #define C6205_HDCR_PCIBOOT 0x04
76 /* DSP Page Register (DSPP) bitfields, */
77 /* defines 4 Mbyte page that BAR0 points to */
78 #define C6205_DSPP_MAP1 0x400
80 /* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
81 * BAR1 maps to non-prefetchable 8 Mbyte memory block
82 * of DSP memory mapped registers (starting at 0x01800000).
83 * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
84 * needs to be added to the BAR1 base address set in the PCI config reg
86 #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
87 #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
88 #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
89 #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
91 /* used to control LED (revA) and reset C6713 (revB) */
92 #define C6205_BAR0_TIMER1_CTL (0x01980000L)
94 /* For first 6713 in CE1 space, using DA17,16,2 */
95 #define HPICL_ADDR 0x01400000L
96 #define HPICH_ADDR 0x01400004L
97 #define HPIAL_ADDR 0x01410000L
98 #define HPIAH_ADDR 0x01410004L
99 #define HPIDIL_ADDR 0x01420000L
100 #define HPIDIH_ADDR 0x01420004L
101 #define HPIDL_ADDR 0x01430000L
102 #define HPIDH_ADDR 0x01430004L
104 #define C6713_EMIF_GCTL 0x01800000
105 #define C6713_EMIF_CE1 0x01800004
106 #define C6713_EMIF_CE0 0x01800008
107 #define C6713_EMIF_CE2 0x01800010
108 #define C6713_EMIF_CE3 0x01800014
109 #define C6713_EMIF_SDRAMCTL 0x01800018
110 #define C6713_EMIF_SDRAMTIMING 0x0180001C
111 #define C6713_EMIF_SDRAMEXT 0x01800020
121 struct consistent_dma_area h_locked_mem;
122 struct bus_master_interface *p_interface_buffer;
124 u16 flag_outstream_just_reset[HPI_MAX_STREAMS];
125 /* a non-NULL handle means there is an HPI allocated buffer */
126 struct consistent_dma_area instream_host_buffers[HPI_MAX_STREAMS];
127 struct consistent_dma_area outstream_host_buffers[HPI_MAX_STREAMS];
128 /* non-zero size means a buffer exists, may be external */
129 u32 instream_host_buffer_size[HPI_MAX_STREAMS];
130 u32 outstream_host_buffer_size[HPI_MAX_STREAMS];
132 struct consistent_dma_area h_control_cache;
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 adapter_delete(struct hpi_adapter_obj *pao,
159 struct hpi_message *phm, 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 int adapter_irq_query_and_clear(struct hpi_adapter_obj *pao,
169 static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
170 struct hpi_message *phm, struct hpi_response *phr);
172 static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
173 struct hpi_message *phm, struct hpi_response *phr);
175 static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
176 struct hpi_message *phm, struct hpi_response *phr);
177 static void outstream_write(struct hpi_adapter_obj *pao,
178 struct hpi_message *phm, struct hpi_response *phr);
180 static void outstream_get_info(struct hpi_adapter_obj *pao,
181 struct hpi_message *phm, struct hpi_response *phr);
183 static void outstream_start(struct hpi_adapter_obj *pao,
184 struct hpi_message *phm, struct hpi_response *phr);
186 static void outstream_open(struct hpi_adapter_obj *pao,
187 struct hpi_message *phm, struct hpi_response *phr);
189 static void outstream_reset(struct hpi_adapter_obj *pao,
190 struct hpi_message *phm, struct hpi_response *phr);
192 static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
193 struct hpi_message *phm, struct hpi_response *phr);
195 static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
196 struct hpi_message *phm, struct hpi_response *phr);
198 static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
199 struct hpi_message *phm, struct hpi_response *phr);
201 static void instream_read(struct hpi_adapter_obj *pao,
202 struct hpi_message *phm, struct hpi_response *phr);
204 static void instream_get_info(struct hpi_adapter_obj *pao,
205 struct hpi_message *phm, struct hpi_response *phr);
207 static void instream_start(struct hpi_adapter_obj *pao,
208 struct hpi_message *phm, struct hpi_response *phr);
210 static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
213 static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
214 int dsp_index, u32 address, u32 data);
216 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
219 static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
220 u32 address, u32 length);
222 static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
225 static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
228 static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
230 /*****************************************************************************/
232 static void subsys_message(struct hpi_adapter_obj *pao,
233 struct hpi_message *phm, struct hpi_response *phr)
235 switch (phm->function) {
236 case HPI_SUBSYS_CREATE_ADAPTER:
237 subsys_create_adapter(phm, phr);
240 phr->error = HPI_ERROR_INVALID_FUNC;
245 static void control_message(struct hpi_adapter_obj *pao,
246 struct hpi_message *phm, struct hpi_response *phr)
249 struct hpi_hw_obj *phw = pao->priv;
250 u16 pending_cache_error = 0;
252 switch (phm->function) {
253 case HPI_CONTROL_GET_STATE:
254 if (pao->has_control_cache) {
255 rmb(); /* make sure we see updates DMAed from DSP */
256 if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
258 } else if (phm->u.c.attribute == HPI_METER_PEAK) {
259 pending_cache_error =
260 HPI_ERROR_CONTROL_CACHING;
263 hw_message(pao, phm, phr);
264 if (pending_cache_error && !phr->error)
265 phr->error = pending_cache_error;
267 case HPI_CONTROL_GET_INFO:
268 hw_message(pao, phm, phr);
270 case HPI_CONTROL_SET_STATE:
271 hw_message(pao, phm, phr);
272 if (pao->has_control_cache)
273 hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
277 phr->error = HPI_ERROR_INVALID_FUNC;
282 static void adapter_message(struct hpi_adapter_obj *pao,
283 struct hpi_message *phm, struct hpi_response *phr)
285 switch (phm->function) {
286 case HPI_ADAPTER_DELETE:
287 adapter_delete(pao, phm, phr);
290 hw_message(pao, phm, phr);
295 static void outstream_message(struct hpi_adapter_obj *pao,
296 struct hpi_message *phm, struct hpi_response *phr)
299 if (phm->obj_index >= HPI_MAX_STREAMS) {
300 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
301 HPI_DEBUG_LOG(WARNING,
302 "Message referencing invalid stream %d "
303 "on adapter index %d\n", phm->obj_index,
308 switch (phm->function) {
309 case HPI_OSTREAM_WRITE:
310 outstream_write(pao, phm, phr);
312 case HPI_OSTREAM_GET_INFO:
313 outstream_get_info(pao, phm, phr);
315 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
316 outstream_host_buffer_allocate(pao, phm, phr);
318 case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
319 outstream_host_buffer_get_info(pao, phm, phr);
321 case HPI_OSTREAM_HOSTBUFFER_FREE:
322 outstream_host_buffer_free(pao, phm, phr);
324 case HPI_OSTREAM_START:
325 outstream_start(pao, phm, phr);
327 case HPI_OSTREAM_OPEN:
328 outstream_open(pao, phm, phr);
330 case HPI_OSTREAM_RESET:
331 outstream_reset(pao, phm, phr);
334 hw_message(pao, phm, phr);
339 static void instream_message(struct hpi_adapter_obj *pao,
340 struct hpi_message *phm, struct hpi_response *phr)
343 if (phm->obj_index >= HPI_MAX_STREAMS) {
344 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
345 HPI_DEBUG_LOG(WARNING,
346 "Message referencing invalid stream %d "
347 "on adapter index %d\n", phm->obj_index,
352 switch (phm->function) {
353 case HPI_ISTREAM_READ:
354 instream_read(pao, phm, phr);
356 case HPI_ISTREAM_GET_INFO:
357 instream_get_info(pao, phm, phr);
359 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
360 instream_host_buffer_allocate(pao, phm, phr);
362 case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
363 instream_host_buffer_get_info(pao, phm, phr);
365 case HPI_ISTREAM_HOSTBUFFER_FREE:
366 instream_host_buffer_free(pao, phm, phr);
368 case HPI_ISTREAM_START:
369 instream_start(pao, phm, phr);
372 hw_message(pao, phm, phr);
377 /*****************************************************************************/
378 /** Entry point to this HPI backend
379 * All calls to the HPI start here
382 void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm,
383 struct hpi_response *phr)
385 if (pao && (pao->dsp_crashed >= 10)
386 && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
387 /* allow last resort debug read even after crash */
388 hpi_init_response(phr, phm->object, phm->function,
389 HPI_ERROR_DSP_HARDWARE);
390 HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object,
395 /* Init default response */
396 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
397 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
399 HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
401 case HPI_TYPE_REQUEST:
402 switch (phm->object) {
403 case HPI_OBJ_SUBSYSTEM:
404 subsys_message(pao, phm, phr);
407 case HPI_OBJ_ADAPTER:
408 adapter_message(pao, phm, phr);
411 case HPI_OBJ_CONTROL:
412 control_message(pao, phm, phr);
415 case HPI_OBJ_OSTREAM:
416 outstream_message(pao, phm, phr);
419 case HPI_OBJ_ISTREAM:
420 instream_message(pao, phm, phr);
424 hw_message(pao, phm, phr);
430 phr->error = HPI_ERROR_INVALID_TYPE;
435 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
437 struct hpi_adapter_obj *pao = NULL;
439 if (phm->object != HPI_OBJ_SUBSYSTEM) {
440 /* normal messages must have valid adapter index */
441 pao = hpi_find_adapter(phm->adapter_index);
443 /* subsys messages don't address an adapter */
444 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
449 _HPI_6205(pao, phm, phr);
451 hpi_init_response(phr, phm->object, phm->function,
452 HPI_ERROR_BAD_ADAPTER_NUMBER);
455 /*****************************************************************************/
458 /** Create an adapter object and initialise it based on resource information
459 * passed in in the message
460 * *** NOTE - you cannot use this function AND the FindAdapters function at the
461 * same time, the application must use only one of them to get the adapters ***
463 static void subsys_create_adapter(struct hpi_message *phm,
464 struct hpi_response *phr)
466 /* create temp adapter obj, because we don't know what index yet */
467 struct hpi_adapter_obj ao;
471 HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
473 memset(&ao, 0, sizeof(ao));
475 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
477 HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
478 phr->error = HPI_ERROR_MEMORY_ALLOC;
482 ao.pci = *phm->u.s.resource.r.pci;
483 err = create_adapter_obj(&ao, &os_error_code);
485 delete_adapter_obj(&ao);
486 if (err >= HPI_ERROR_BACKEND_BASE) {
487 phr->error = HPI_ERROR_DSP_BOOTLOAD;
488 phr->specific_error = err;
492 phr->u.s.data = os_error_code;
496 phr->u.s.adapter_type = ao.type;
497 phr->u.s.adapter_index = ao.index;
501 /** delete an adapter - required by WDM driver */
502 static void adapter_delete(struct hpi_adapter_obj *pao,
503 struct hpi_message *phm, struct hpi_response *phr)
505 struct hpi_hw_obj *phw;
508 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
512 /* reset adapter h/w */
514 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
516 iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
518 delete_adapter_obj(pao);
519 hpi_delete_adapter(pao);
523 /** Create adapter object
524 allocate buffers, bootload DSPs, initialise control cache
526 static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
529 struct hpi_hw_obj *phw = pao->priv;
530 struct bus_master_interface *interface;
535 /* init error reporting */
536 pao->dsp_crashed = 0;
538 for (i = 0; i < HPI_MAX_STREAMS; i++)
539 phw->flag_outstream_just_reset[i] = 1;
541 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
543 pao->pci.ap_mem_base[1] +
544 C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
546 pao->pci.ap_mem_base[1] +
547 C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
549 pao->pci.ap_mem_base[1] +
550 C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
552 pao->has_control_cache = 0;
554 if (hpios_locked_mem_alloc(&phw->h_locked_mem,
555 sizeof(struct bus_master_interface),
557 phw->p_interface_buffer = NULL;
558 else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
559 (void *)&phw->p_interface_buffer))
560 phw->p_interface_buffer = NULL;
562 HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
563 phw->p_interface_buffer);
565 if (phw->p_interface_buffer) {
566 memset((void *)phw->p_interface_buffer, 0,
567 sizeof(struct bus_master_interface));
568 phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
571 err = adapter_boot_load_dsp(pao, pos_error_code);
573 HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");
574 /* no need to clean up as SubSysCreateAdapter */
575 /* calls DeleteAdapter on error. */
578 HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
580 /* allow boot load even if mem alloc wont work */
581 if (!phw->p_interface_buffer)
582 return HPI_ERROR_MEMORY_ALLOC;
584 interface = phw->p_interface_buffer;
586 /* make sure the DSP has started ok */
587 if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
588 HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
589 return HPI6205_ERROR_6205_INIT_FAILED;
591 /* Note that *pao, *phw are zeroed after allocation,
592 * so pointers and flags are NULL by default.
593 * Allocate bus mastering control cache buffer and tell the DSP about it
595 if (interface->control_cache.number_of_controls) {
596 u8 *p_control_cache_virtual;
598 err = hpios_locked_mem_alloc(&phw->h_control_cache,
599 interface->control_cache.size_in_bytes,
602 err = hpios_locked_mem_get_virt_addr(&phw->
604 (void *)&p_control_cache_virtual);
606 memset(p_control_cache_virtual, 0,
607 interface->control_cache.size_in_bytes);
610 hpi_alloc_control_cache(interface->
611 control_cache.number_of_controls,
612 interface->control_cache.size_in_bytes,
613 p_control_cache_virtual);
616 err = HPI_ERROR_MEMORY_ALLOC;
619 err = hpios_locked_mem_get_phys_addr(&phw->
620 h_control_cache, &phys_addr);
621 interface->control_cache.physical_address32 =
626 pao->has_control_cache = 1;
628 if (hpios_locked_mem_valid(&phw->h_control_cache))
629 hpios_locked_mem_free(&phw->h_control_cache);
630 pao->has_control_cache = 0;
633 send_dsp_command(phw, H620_HIF_IDLE);
636 struct hpi_message hm;
637 struct hpi_response hr;
639 HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
640 memset(&hm, 0, sizeof(hm));
641 /* wAdapterIndex == version == 0 */
642 hm.type = HPI_TYPE_REQUEST;
643 hm.size = sizeof(hm);
644 hm.object = HPI_OBJ_ADAPTER;
645 hm.function = HPI_ADAPTER_GET_INFO;
647 memset(&hr, 0, sizeof(hr));
648 hr.size = sizeof(hr);
650 err = message_response_sequence(pao, &hm, &hr);
652 HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
659 pao->type = hr.u.ax.info.adapter_type;
660 pao->index = hr.u.ax.info.adapter_index;
662 HPI_DEBUG_LOG(VERBOSE,
663 "got adapter info type %x index %d serial %d\n",
664 hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
665 hr.u.ax.info.serial_number);
669 phw->p_cache->adap_idx = pao->index;
671 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
673 pao->irq_query_and_clear = adapter_irq_query_and_clear;
674 pao->instream_host_buffer_status =
675 phw->p_interface_buffer->instream_host_buffer_status;
676 pao->outstream_host_buffer_status =
677 phw->p_interface_buffer->outstream_host_buffer_status;
679 return hpi_add_adapter(pao);
682 /** Free memory areas allocated by adapter
683 * this routine is called from AdapterDelete,
684 * and SubSysCreateAdapter if duplicate index
686 static void delete_adapter_obj(struct hpi_adapter_obj *pao)
688 struct hpi_hw_obj *phw = pao->priv;
691 if (hpios_locked_mem_valid(&phw->h_control_cache)) {
692 hpios_locked_mem_free(&phw->h_control_cache);
693 hpi_free_control_cache(phw->p_cache);
696 if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
697 hpios_locked_mem_free(&phw->h_locked_mem);
698 phw->p_interface_buffer = NULL;
701 for (i = 0; i < HPI_MAX_STREAMS; i++)
702 if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
703 hpios_locked_mem_free(&phw->instream_host_buffers[i]);
704 /*?phw->InStreamHostBuffers[i] = NULL; */
705 phw->instream_host_buffer_size[i] = 0;
708 for (i = 0; i < HPI_MAX_STREAMS; i++)
709 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
710 hpios_locked_mem_free(&phw->outstream_host_buffers
712 phw->outstream_host_buffer_size[i] = 0;
717 /*****************************************************************************/
718 /* Adapter functions */
719 static int adapter_irq_query_and_clear(struct hpi_adapter_obj *pao,
722 struct hpi_hw_obj *phw = pao->priv;
725 hsr = ioread32(phw->prHSR);
726 if (hsr & C6205_HSR_INTSRC) {
727 /* reset the interrupt from the DSP */
728 iowrite32(C6205_HSR_INTSRC, phw->prHSR);
729 return HPI_IRQ_MIXER;
735 /*****************************************************************************/
736 /* OutStream Host buffer functions */
738 /** Allocate or attach buffer for busmastering
740 static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
741 struct hpi_message *phm, struct hpi_response *phr)
744 u32 command = phm->u.d.u.buffer.command;
745 struct hpi_hw_obj *phw = pao->priv;
746 struct bus_master_interface *interface = phw->p_interface_buffer;
748 hpi_init_response(phr, phm->object, phm->function, 0);
750 if (command == HPI_BUFFER_CMD_EXTERNAL
751 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
752 /* ALLOC phase, allocate a buffer with power of 2 size,
753 get its bus address for PCI bus mastering
755 phm->u.d.u.buffer.buffer_size =
756 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
757 /* return old size and allocated size,
758 so caller can detect change */
759 phr->u.d.u.stream_info.data_available =
760 phw->outstream_host_buffer_size[phm->obj_index];
761 phr->u.d.u.stream_info.buffer_size =
762 phm->u.d.u.buffer.buffer_size;
764 if (phw->outstream_host_buffer_size[phm->obj_index] ==
765 phm->u.d.u.buffer.buffer_size) {
766 /* Same size, no action required */
770 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
772 hpios_locked_mem_free(&phw->outstream_host_buffers
775 err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
776 [phm->obj_index], phm->u.d.u.buffer.buffer_size,
780 phr->error = HPI_ERROR_INVALID_DATASIZE;
781 phw->outstream_host_buffer_size[phm->obj_index] = 0;
785 err = hpios_locked_mem_get_phys_addr
786 (&phw->outstream_host_buffers[phm->obj_index],
787 &phm->u.d.u.buffer.pci_address);
788 /* get the phys addr into msg for single call alloc caller
789 * needs to do this for split alloc (or use the same message)
790 * return the phy address for split alloc in the respose too
792 phr->u.d.u.stream_info.auxiliary_data_available =
793 phm->u.d.u.buffer.pci_address;
796 hpios_locked_mem_free(&phw->outstream_host_buffers
798 phw->outstream_host_buffer_size[phm->obj_index] = 0;
799 phr->error = HPI_ERROR_MEMORY_ALLOC;
804 if (command == HPI_BUFFER_CMD_EXTERNAL
805 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
806 /* GRANT phase. Set up the BBM status, tell the DSP about
807 the buffer so it can start using BBM.
809 struct hpi_hostbuffer_status *status;
811 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
814 "Buffer size must be 2^N not %d\n",
815 phm->u.d.u.buffer.buffer_size);
816 phr->error = HPI_ERROR_INVALID_DATASIZE;
819 phw->outstream_host_buffer_size[phm->obj_index] =
820 phm->u.d.u.buffer.buffer_size;
821 status = &interface->outstream_host_buffer_status[phm->
823 status->samples_processed = 0;
824 status->stream_state = HPI_STATE_STOPPED;
825 status->dsp_index = 0;
826 status->host_index = status->dsp_index;
827 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
828 status->auxiliary_data_available = 0;
830 hw_message(pao, phm, phr);
833 && hpios_locked_mem_valid(&phw->
834 outstream_host_buffers[phm->obj_index])) {
835 hpios_locked_mem_free(&phw->outstream_host_buffers
837 phw->outstream_host_buffer_size[phm->obj_index] = 0;
842 static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
843 struct hpi_message *phm, struct hpi_response *phr)
845 struct hpi_hw_obj *phw = pao->priv;
846 struct bus_master_interface *interface = phw->p_interface_buffer;
847 struct hpi_hostbuffer_status *status;
850 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
852 if (hpios_locked_mem_get_virt_addr(&phw->
853 outstream_host_buffers[phm->obj_index],
854 (void *)&p_bbm_data)) {
855 phr->error = HPI_ERROR_INVALID_OPERATION;
858 status = &interface->outstream_host_buffer_status[phm->
860 hpi_init_response(phr, HPI_OBJ_OSTREAM,
861 HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
862 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
863 phr->u.d.u.hostbuffer_info.p_status = status;
865 hpi_init_response(phr, HPI_OBJ_OSTREAM,
866 HPI_OSTREAM_HOSTBUFFER_GET_INFO,
867 HPI_ERROR_INVALID_OPERATION);
871 static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
872 struct hpi_message *phm, struct hpi_response *phr)
874 struct hpi_hw_obj *phw = pao->priv;
875 u32 command = phm->u.d.u.buffer.command;
877 if (phw->outstream_host_buffer_size[phm->obj_index]) {
878 if (command == HPI_BUFFER_CMD_EXTERNAL
879 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
880 phw->outstream_host_buffer_size[phm->obj_index] = 0;
881 hw_message(pao, phm, phr);
882 /* Tell adapter to stop using the host buffer. */
884 if (command == HPI_BUFFER_CMD_EXTERNAL
885 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
886 hpios_locked_mem_free(&phw->outstream_host_buffers
889 /* Should HPI_ERROR_INVALID_OPERATION be returned
890 if no host buffer is allocated? */
892 hpi_init_response(phr, HPI_OBJ_OSTREAM,
893 HPI_OSTREAM_HOSTBUFFER_FREE, 0);
897 static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)
899 return status->size_in_bytes - (status->host_index -
903 static void outstream_write(struct hpi_adapter_obj *pao,
904 struct hpi_message *phm, struct hpi_response *phr)
906 struct hpi_hw_obj *phw = pao->priv;
907 struct bus_master_interface *interface = phw->p_interface_buffer;
908 struct hpi_hostbuffer_status *status;
911 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
912 /* there is no BBM buffer, write via message */
913 hw_message(pao, phm, phr);
917 hpi_init_response(phr, phm->object, phm->function, 0);
918 status = &interface->outstream_host_buffer_status[phm->obj_index];
920 space_available = outstream_get_space_available(status);
921 if (space_available < phm->u.d.u.data.data_size) {
922 phr->error = HPI_ERROR_INVALID_DATASIZE;
926 /* HostBuffers is used to indicate host buffer is internally allocated.
927 otherwise, assumed external, data written externally */
928 if (phm->u.d.u.data.pb_data
929 && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
933 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
935 if (hpios_locked_mem_get_virt_addr(&phw->
936 outstream_host_buffers[phm->obj_index],
937 (void *)&p_bbm_data)) {
938 phr->error = HPI_ERROR_INVALID_OPERATION;
943 or enough to fit from current to end of BBM buffer */
945 min(phm->u.d.u.data.data_size,
946 status->size_in_bytes -
947 (status->host_index & (status->size_in_bytes - 1)));
950 (status->host_index & (status->size_in_bytes - 1)),
951 p_app_data, l_first_write);
952 /* remaining data if any */
953 memcpy(p_bbm_data, p_app_data + l_first_write,
954 phm->u.d.u.data.data_size - l_first_write);
958 * This version relies on the DSP code triggering an OStream buffer
959 * update immediately following a SET_FORMAT call. The host has
960 * already written data into the BBM buffer, but the DSP won't know
961 * about it until dwHostIndex is adjusted.
963 if (phw->flag_outstream_just_reset[phm->obj_index]) {
964 /* Format can only change after reset. Must tell DSP. */
965 u16 function = phm->function;
966 phw->flag_outstream_just_reset[phm->obj_index] = 0;
967 phm->function = HPI_OSTREAM_SET_FORMAT;
968 hw_message(pao, phm, phr); /* send the format to the DSP */
969 phm->function = function;
974 status->host_index += phm->u.d.u.data.data_size;
977 static void outstream_get_info(struct hpi_adapter_obj *pao,
978 struct hpi_message *phm, struct hpi_response *phr)
980 struct hpi_hw_obj *phw = pao->priv;
981 struct bus_master_interface *interface = phw->p_interface_buffer;
982 struct hpi_hostbuffer_status *status;
984 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
985 hw_message(pao, phm, phr);
989 hpi_init_response(phr, phm->object, phm->function, 0);
991 status = &interface->outstream_host_buffer_status[phm->obj_index];
993 phr->u.d.u.stream_info.state = (u16)status->stream_state;
994 phr->u.d.u.stream_info.samples_transferred =
995 status->samples_processed;
996 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
997 phr->u.d.u.stream_info.data_available =
998 status->size_in_bytes - outstream_get_space_available(status);
999 phr->u.d.u.stream_info.auxiliary_data_available =
1000 status->auxiliary_data_available;
1003 static void outstream_start(struct hpi_adapter_obj *pao,
1004 struct hpi_message *phm, struct hpi_response *phr)
1006 hw_message(pao, phm, phr);
1009 static void outstream_reset(struct hpi_adapter_obj *pao,
1010 struct hpi_message *phm, struct hpi_response *phr)
1012 struct hpi_hw_obj *phw = pao->priv;
1013 phw->flag_outstream_just_reset[phm->obj_index] = 1;
1014 hw_message(pao, phm, phr);
1017 static void outstream_open(struct hpi_adapter_obj *pao,
1018 struct hpi_message *phm, struct hpi_response *phr)
1020 outstream_reset(pao, phm, phr);
1023 /*****************************************************************************/
1024 /* InStream Host buffer functions */
1026 static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
1027 struct hpi_message *phm, struct hpi_response *phr)
1030 u32 command = phm->u.d.u.buffer.command;
1031 struct hpi_hw_obj *phw = pao->priv;
1032 struct bus_master_interface *interface = phw->p_interface_buffer;
1034 hpi_init_response(phr, phm->object, phm->function, 0);
1036 if (command == HPI_BUFFER_CMD_EXTERNAL
1037 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
1039 phm->u.d.u.buffer.buffer_size =
1040 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
1041 phr->u.d.u.stream_info.data_available =
1042 phw->instream_host_buffer_size[phm->obj_index];
1043 phr->u.d.u.stream_info.buffer_size =
1044 phm->u.d.u.buffer.buffer_size;
1046 if (phw->instream_host_buffer_size[phm->obj_index] ==
1047 phm->u.d.u.buffer.buffer_size) {
1048 /* Same size, no action required */
1052 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1054 hpios_locked_mem_free(&phw->instream_host_buffers
1057 err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
1058 obj_index], phm->u.d.u.buffer.buffer_size,
1062 phr->error = HPI_ERROR_INVALID_DATASIZE;
1063 phw->instream_host_buffer_size[phm->obj_index] = 0;
1067 err = hpios_locked_mem_get_phys_addr
1068 (&phw->instream_host_buffers[phm->obj_index],
1069 &phm->u.d.u.buffer.pci_address);
1070 /* get the phys addr into msg for single call alloc. Caller
1071 needs to do this for split alloc so return the phy address */
1072 phr->u.d.u.stream_info.auxiliary_data_available =
1073 phm->u.d.u.buffer.pci_address;
1075 hpios_locked_mem_free(&phw->instream_host_buffers
1077 phw->instream_host_buffer_size[phm->obj_index] = 0;
1078 phr->error = HPI_ERROR_MEMORY_ALLOC;
1083 if (command == HPI_BUFFER_CMD_EXTERNAL
1084 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
1085 struct hpi_hostbuffer_status *status;
1087 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
1089 HPI_DEBUG_LOG(ERROR,
1090 "Buffer size must be 2^N not %d\n",
1091 phm->u.d.u.buffer.buffer_size);
1092 phr->error = HPI_ERROR_INVALID_DATASIZE;
1096 phw->instream_host_buffer_size[phm->obj_index] =
1097 phm->u.d.u.buffer.buffer_size;
1098 status = &interface->instream_host_buffer_status[phm->
1100 status->samples_processed = 0;
1101 status->stream_state = HPI_STATE_STOPPED;
1102 status->dsp_index = 0;
1103 status->host_index = status->dsp_index;
1104 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
1105 status->auxiliary_data_available = 0;
1107 hw_message(pao, phm, phr);
1110 && hpios_locked_mem_valid(&phw->
1111 instream_host_buffers[phm->obj_index])) {
1112 hpios_locked_mem_free(&phw->instream_host_buffers
1114 phw->instream_host_buffer_size[phm->obj_index] = 0;
1119 static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
1120 struct hpi_message *phm, struct hpi_response *phr)
1122 struct hpi_hw_obj *phw = pao->priv;
1123 struct bus_master_interface *interface = phw->p_interface_buffer;
1124 struct hpi_hostbuffer_status *status;
1127 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1129 if (hpios_locked_mem_get_virt_addr(&phw->
1130 instream_host_buffers[phm->obj_index],
1131 (void *)&p_bbm_data)) {
1132 phr->error = HPI_ERROR_INVALID_OPERATION;
1135 status = &interface->instream_host_buffer_status[phm->
1137 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1138 HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
1139 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
1140 phr->u.d.u.hostbuffer_info.p_status = status;
1142 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1143 HPI_ISTREAM_HOSTBUFFER_GET_INFO,
1144 HPI_ERROR_INVALID_OPERATION);
1148 static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
1149 struct hpi_message *phm, struct hpi_response *phr)
1151 struct hpi_hw_obj *phw = pao->priv;
1152 u32 command = phm->u.d.u.buffer.command;
1154 if (phw->instream_host_buffer_size[phm->obj_index]) {
1155 if (command == HPI_BUFFER_CMD_EXTERNAL
1156 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
1157 phw->instream_host_buffer_size[phm->obj_index] = 0;
1158 hw_message(pao, phm, phr);
1161 if (command == HPI_BUFFER_CMD_EXTERNAL
1162 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
1163 hpios_locked_mem_free(&phw->instream_host_buffers
1167 /* Should HPI_ERROR_INVALID_OPERATION be returned
1168 if no host buffer is allocated? */
1169 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1170 HPI_ISTREAM_HOSTBUFFER_FREE, 0);
1176 static void instream_start(struct hpi_adapter_obj *pao,
1177 struct hpi_message *phm, struct hpi_response *phr)
1179 hw_message(pao, phm, phr);
1182 static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
1184 return status->dsp_index - status->host_index;
1187 static void instream_read(struct hpi_adapter_obj *pao,
1188 struct hpi_message *phm, struct hpi_response *phr)
1190 struct hpi_hw_obj *phw = pao->priv;
1191 struct bus_master_interface *interface = phw->p_interface_buffer;
1192 struct hpi_hostbuffer_status *status;
1196 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
1198 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1199 hw_message(pao, phm, phr);
1202 hpi_init_response(phr, phm->object, phm->function, 0);
1204 status = &interface->instream_host_buffer_status[phm->obj_index];
1205 data_available = instream_get_bytes_available(status);
1206 if (data_available < phm->u.d.u.data.data_size) {
1207 phr->error = HPI_ERROR_INVALID_DATASIZE;
1211 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1213 if (hpios_locked_mem_get_virt_addr(&phw->
1214 instream_host_buffers[phm->obj_index],
1215 (void *)&p_bbm_data)) {
1216 phr->error = HPI_ERROR_INVALID_OPERATION;
1221 or enough to fit from current to end of BBM buffer */
1223 min(phm->u.d.u.data.data_size,
1224 status->size_in_bytes -
1225 (status->host_index & (status->size_in_bytes - 1)));
1229 (status->host_index & (status->size_in_bytes - 1)),
1231 /* remaining data if any */
1232 memcpy(p_app_data + l_first_read, p_bbm_data,
1233 phm->u.d.u.data.data_size - l_first_read);
1235 status->host_index += phm->u.d.u.data.data_size;
1238 static void instream_get_info(struct hpi_adapter_obj *pao,
1239 struct hpi_message *phm, struct hpi_response *phr)
1241 struct hpi_hw_obj *phw = pao->priv;
1242 struct bus_master_interface *interface = phw->p_interface_buffer;
1243 struct hpi_hostbuffer_status *status;
1244 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1245 hw_message(pao, phm, phr);
1249 status = &interface->instream_host_buffer_status[phm->obj_index];
1251 hpi_init_response(phr, phm->object, phm->function, 0);
1253 phr->u.d.u.stream_info.state = (u16)status->stream_state;
1254 phr->u.d.u.stream_info.samples_transferred =
1255 status->samples_processed;
1256 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
1257 phr->u.d.u.stream_info.data_available =
1258 instream_get_bytes_available(status);
1259 phr->u.d.u.stream_info.auxiliary_data_available =
1260 status->auxiliary_data_available;
1263 /*****************************************************************************/
1265 #define HPI6205_MAX_FILES_TO_LOAD 2
1267 static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
1268 u32 *pos_error_code)
1270 struct hpi_hw_obj *phw = pao->priv;
1271 struct dsp_code dsp_code;
1272 u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
1277 boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
1279 boot_code_id[1] = pao->pci.pci_dev->subsystem_device;
1280 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id[1]);
1282 /* fix up cases where bootcode id[1] != subsys id */
1283 switch (boot_code_id[1]) {
1284 case HPI_ADAPTER_FAMILY_ASI(0x5000):
1285 boot_code_id[0] = boot_code_id[1];
1286 boot_code_id[1] = 0;
1288 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1289 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1290 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1291 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
1293 case HPI_ADAPTER_FAMILY_ASI(0x5500):
1294 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1295 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1296 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
1298 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1299 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
1305 /* reset DSP by writing a 1 to the WARMRESET bit */
1306 temp = C6205_HDCR_WARMRESET;
1307 iowrite32(temp, phw->prHDCR);
1308 hpios_delay_micro_seconds(1000);
1310 /* check that PCI i/f was configured by EEPROM */
1311 temp = ioread32(phw->prHSR);
1312 if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
1314 return HPI6205_ERROR_6205_EEPROM;
1316 /* disable PINTA interrupt */
1317 iowrite32(temp, phw->prHSR);
1319 /* check control register reports PCI boot mode */
1320 temp = ioread32(phw->prHDCR);
1321 if (!(temp & C6205_HDCR_PCIBOOT))
1322 return HPI6205_ERROR_6205_REG;
1324 /* try writing a few numbers to the DSP page register */
1325 /* and reading them back. */
1327 iowrite32(temp, phw->prDSPP);
1328 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1329 return HPI6205_ERROR_6205_DSPPAGE;
1331 iowrite32(temp, phw->prDSPP);
1332 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1333 return HPI6205_ERROR_6205_DSPPAGE;
1335 iowrite32(temp, phw->prDSPP);
1336 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1337 return HPI6205_ERROR_6205_DSPPAGE;
1338 /* reset DSP page to the correct number */
1340 iowrite32(temp, phw->prDSPP);
1341 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1342 return HPI6205_ERROR_6205_DSPPAGE;
1345 /* release 6713 from reset before 6205 is bootloaded.
1346 This ensures that the EMIF is inactive,
1347 and the 6713 HPI gets the correct bootmode etc
1349 if (boot_code_id[1] != 0) {
1350 /* DSP 1 is a C6713 */
1351 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1352 boot_loader_write_mem32(pao, 0, 0x018C0024, 0x00002202);
1353 hpios_delay_micro_seconds(100);
1354 /* Reset the 6713 #1 - revB */
1355 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
1356 /* value of bit 3 is unknown after DSP reset, other bits shoudl be 0 */
1357 if (0 != (boot_loader_read_mem32(pao, 0,
1358 (C6205_BAR0_TIMER1_CTL)) & ~8))
1359 return HPI6205_ERROR_6205_REG;
1360 hpios_delay_micro_seconds(100);
1362 /* Release C6713 from reset - revB */
1363 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
1364 if (4 != (boot_loader_read_mem32(pao, 0,
1365 (C6205_BAR0_TIMER1_CTL)) & ~8))
1366 return HPI6205_ERROR_6205_REG;
1367 hpios_delay_micro_seconds(100);
1370 for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
1371 /* is there a DSP to load? */
1372 if (boot_code_id[dsp] == 0)
1375 err = boot_loader_config_emif(pao, dsp);
1379 err = boot_loader_test_internal_memory(pao, dsp);
1383 err = boot_loader_test_external_memory(pao, dsp);
1387 err = boot_loader_test_pld(pao, dsp);
1391 /* write the DSP code down into the DSPs memory */
1392 err = hpi_dsp_code_open(boot_code_id[dsp], pao->pci.pci_dev,
1393 &dsp_code, pos_error_code);
1403 err = hpi_dsp_code_read_word(&dsp_code, &length);
1406 if (length == 0xFFFFFFFF)
1407 break; /* end of code */
1409 err = hpi_dsp_code_read_word(&dsp_code, &address);
1412 err = hpi_dsp_code_read_word(&dsp_code, &type);
1415 err = hpi_dsp_code_read_block(length, &dsp_code,
1419 for (i = 0; i < (int)length; i++) {
1420 boot_loader_write_mem32(pao, dsp, address,
1422 /* dummy read every 4 words */
1423 /* for 6205 advisory 1.4.4 */
1425 boot_loader_read_mem32(pao, dsp,
1433 hpi_dsp_code_close(&dsp_code);
1438 hpi_dsp_code_rewind(&dsp_code);
1446 hpi_dsp_code_read_word(&dsp_code, &length);
1447 if (length == 0xFFFFFFFF)
1448 break; /* end of code */
1450 hpi_dsp_code_read_word(&dsp_code, &address);
1451 hpi_dsp_code_read_word(&dsp_code, &type);
1452 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
1454 for (i = 0; i < (int)length; i++) {
1455 data = boot_loader_read_mem32(pao, dsp,
1457 if (data != *pcode) {
1467 hpi_dsp_code_close(&dsp_code);
1472 /* After bootloading all DSPs, start DSP0 running
1473 * The DSP0 code will handle starting and synchronizing with its slaves
1475 if (phw->p_interface_buffer) {
1476 /* we need to tell the card the physical PCI address */
1477 u32 physicalPC_iaddress;
1478 struct bus_master_interface *interface =
1479 phw->p_interface_buffer;
1480 u32 host_mailbox_address_on_dsp;
1481 u32 physicalPC_iaddress_verify = 0;
1483 /* set ack so we know when DSP is ready to go */
1484 /* (dwDspAck will be changed to HIF_RESET) */
1485 interface->dsp_ack = H620_HIF_UNKNOWN;
1486 wmb(); /* ensure ack is written before dsp writes back */
1488 err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
1489 &physicalPC_iaddress);
1491 /* locate the host mailbox on the DSP. */
1492 host_mailbox_address_on_dsp = 0x80000000;
1493 while ((physicalPC_iaddress != physicalPC_iaddress_verify)
1495 boot_loader_write_mem32(pao, 0,
1496 host_mailbox_address_on_dsp,
1497 physicalPC_iaddress);
1498 physicalPC_iaddress_verify =
1499 boot_loader_read_mem32(pao, 0,
1500 host_mailbox_address_on_dsp);
1503 HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
1504 /* enable interrupts */
1505 temp = ioread32(phw->prHSR);
1506 temp &= ~(u32)C6205_HSR_INTAM;
1507 iowrite32(temp, phw->prHSR);
1509 /* start code running... */
1510 temp = ioread32(phw->prHDCR);
1511 temp |= (u32)C6205_HDCR_DSPINT;
1512 iowrite32(temp, phw->prHDCR);
1514 /* give the DSP 10ms to start up */
1515 hpios_delay_micro_seconds(10000);
1520 /*****************************************************************************/
1521 /* Bootloader utility functions */
1523 static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
1526 struct hpi_hw_obj *phw = pao->priv;
1528 __iomem u32 *p_data;
1530 if (dsp_index == 0) {
1531 /* DSP 0 is always C6205 */
1532 if ((address >= 0x01800000) & (address < 0x02000000)) {
1533 /* BAR1 register access */
1534 p_data = pao->pci.ap_mem_base[1] +
1535 (address & 0x007fffff) /
1536 sizeof(*pao->pci.ap_mem_base[1]);
1537 /* HPI_DEBUG_LOG(WARNING,
1538 "BAR1 access %08x\n", dwAddress); */
1540 u32 dw4M_page = address >> 22L;
1541 if (dw4M_page != phw->dsp_page) {
1542 phw->dsp_page = dw4M_page;
1544 iowrite32(phw->dsp_page, phw->prDSPP);
1547 address &= 0x3fffff; /* address within 4M page */
1548 /* BAR0 memory access */
1549 p_data = pao->pci.ap_mem_base[0] +
1550 address / sizeof(u32);
1552 data = ioread32(p_data);
1553 } else if (dsp_index == 1) {
1554 /* DSP 1 is a C6713 */
1556 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1557 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1558 lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
1559 data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
1560 data = (data << 16) | (lsb & 0xFFFF);
1565 static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
1566 int dsp_index, u32 address, u32 data)
1568 struct hpi_hw_obj *phw = pao->priv;
1569 __iomem u32 *p_data;
1570 /* u32 dwVerifyData=0; */
1572 if (dsp_index == 0) {
1573 /* DSP 0 is always C6205 */
1574 if ((address >= 0x01800000) & (address < 0x02000000)) {
1575 /* BAR1 - DSP register access using */
1576 /* Non-prefetchable PCI access */
1577 p_data = pao->pci.ap_mem_base[1] +
1578 (address & 0x007fffff) /
1579 sizeof(*pao->pci.ap_mem_base[1]);
1581 /* BAR0 access - all of DSP memory using */
1582 /* pre-fetchable PCI access */
1583 u32 dw4M_page = address >> 22L;
1584 if (dw4M_page != phw->dsp_page) {
1585 phw->dsp_page = dw4M_page;
1587 iowrite32(phw->dsp_page, phw->prDSPP);
1590 address &= 0x3fffff; /* address within 4M page */
1591 p_data = pao->pci.ap_mem_base[0] +
1592 address / sizeof(u32);
1594 iowrite32(data, p_data);
1595 } else if (dsp_index == 1) {
1596 /* DSP 1 is a C6713 */
1597 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1598 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1600 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1601 boot_loader_read_mem32(pao, 0, 0);
1603 boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
1604 boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
1606 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1607 boot_loader_read_mem32(pao, 0, 0);
1611 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
1613 if (dsp_index == 0) {
1616 /* DSP 0 is always C6205 */
1619 /* memory map of C6205 */
1620 /* 00000000-0000FFFF 16Kx32 internal program */
1621 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1625 /* Global EMIF control */
1626 boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
1635 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1636 setting = 0x00000030;
1637 boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
1638 if (setting != boot_loader_read_mem32(pao, dsp_index,
1640 return HPI6205_ERROR_DSP_EMIF1;
1642 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1643 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1644 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1645 /* WST should be 71, but 63 is max possible */
1647 (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
1648 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1650 boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
1651 if (setting != boot_loader_read_mem32(pao, dsp_index,
1653 return HPI6205_ERROR_DSP_EMIF2;
1655 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1656 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1657 /* plenty of wait states */
1659 (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
1660 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1662 boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
1663 if (setting != boot_loader_read_mem32(pao, dsp_index,
1665 return HPI6205_ERROR_DSP_EMIF3;
1667 /* EMIF CE3 setup - 32 bit async. */
1668 /* This is the PLD on the ASI5000 cards only */
1670 (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
1671 (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
1673 boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
1674 if (setting != boot_loader_read_mem32(pao, dsp_index,
1676 return HPI6205_ERROR_DSP_EMIF4;
1678 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1679 /* need to use this else DSP code crashes? */
1680 boot_loader_write_mem32(pao, dsp_index, 0x01800018,
1683 /* EMIF SDRAM Refresh Timing */
1684 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1685 boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
1688 } else if (dsp_index == 1) {
1689 /* test access to the C6713s HPI registers */
1690 u32 write_data = 0, read_data = 0, i = 0;
1692 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1694 boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
1695 boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
1696 /* C67 HPI is on lower 16bits of 32bit EMIF */
1698 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
1699 if (write_data != read_data) {
1700 HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
1702 return HPI6205_ERROR_C6713_HPIC;
1704 /* HPIA - walking ones test */
1706 for (i = 0; i < 32; i++) {
1707 boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
1709 boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
1710 (write_data >> 16));
1712 0xFFFF & boot_loader_read_mem32(pao, 0,
1715 read_data | ((0xFFFF &
1716 boot_loader_read_mem32(pao, 0,
1719 if (read_data != write_data) {
1720 HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
1721 write_data, read_data);
1722 return HPI6205_ERROR_C6713_HPIA;
1724 write_data = write_data << 1;
1728 * ** C6713 datasheet says we cannot program PLL from HPI,
1729 * and indeed if we try to set the PLL multiply from the HPI,
1730 * the PLL does not seem to lock, so we enable the PLL and
1731 * use the default multiply of x 7, which for a 27MHz clock
1732 * gives a DSP speed of 189MHz
1735 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
1736 hpios_delay_micro_seconds(1000);
1737 /* EMIF = 189/3=63MHz */
1738 boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
1740 boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
1742 boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
1743 hpios_delay_micro_seconds(1000);
1744 /* ** SGT test to take GPO3 high when we start the PLL */
1745 /* and low when the delay is completed */
1746 /* FSX0 <- '1' (GPO3) */
1747 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
1748 /* PLL not bypassed */
1749 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
1750 hpios_delay_micro_seconds(1000);
1751 /* FSX0 <- '0' (GPO3) */
1752 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
1754 /* 6205 EMIF CE1 resetup - 32 bit async. */
1755 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1756 boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
1757 (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
1758 (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
1761 hpios_delay_micro_seconds(1000);
1763 /* check that we can read one of the PLL registers */
1764 /* PLL should not be bypassed! */
1765 if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
1767 return HPI6205_ERROR_C6713_PLL;
1769 /* setup C67x EMIF (note this is the only use of
1770 BAR1 via BootLoader_WriteMem32) */
1771 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
1774 /* EMIF CE0 setup - 2Mx32 Sync DRAM
1781 7..4 MTYPE 0011 Sync DRAM 32bits
1785 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
1788 /* EMIF SDRAM Extension
1790 31-21 0000b 0000b 000b
1791 20 WR2RD = 2cycles-1 = 1b
1793 19-18 WR2DEAC = 3cycle-1 = 10b
1794 17 WR2WR = 2cycle-1 = 1b
1795 16-15 R2WDQM = 4cycle-1 = 11b
1796 14-12 RD2WR = 6cycles-1 = 101b
1798 11-10 RD2DEAC = 4cycle-1 = 11b
1799 9 RD2RD = 2cycle-1 = 1b
1800 8-7 THZP = 3cycle-1 = 10b
1801 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
1802 4 TRRD = 2cycle = 0b (tRRD = 14ns)
1803 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
1804 1 CAS latency = 3cyc = 1b
1805 (for Micron 2M32-7 operating at 100MHz)
1807 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
1810 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
1813 29..28 SDRSZ 00b 11 row address pins
1815 27..26 SDCSZ 01b 8 column address pins
1816 25 RFEN 1b refersh enabled
1817 24 INIT 1b init SDRAM!
1819 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
1821 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
1823 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
1825 11..0 - 0000b 0000b 0000b
1827 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
1830 /* SDRAM refresh timing
1831 Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
1833 boot_loader_write_mem32(pao, dsp_index,
1834 C6713_EMIF_SDRAMTIMING, 0x00000410);
1836 hpios_delay_micro_seconds(1000);
1837 } else if (dsp_index == 2) {
1838 /* DSP 2 is a C6713 */
1844 static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
1845 u32 start_address, u32 length)
1849 u32 test_data = 0, data = 0;
1853 /* for 1st word, test each bit in the 32bit word, */
1854 /* dwLength specifies number of 32bit words to test */
1855 /*for(i=0; i<dwLength; i++) */
1858 test_addr = start_address + i * 4;
1859 test_data = 0x00000001;
1860 for (j = 0; j < 32; j++) {
1861 boot_loader_write_mem32(pao, dsp_index, test_addr,
1863 data = boot_loader_read_mem32(pao, dsp_index,
1865 if (data != test_data) {
1866 HPI_DEBUG_LOG(VERBOSE,
1867 "Memtest error details "
1868 "%08x %08x %08x %i\n", test_addr,
1869 test_data, data, dsp_index);
1870 return 1; /* error */
1872 test_data = test_data << 1;
1876 /* for the next 100 locations test each location, leaving it as zero */
1877 /* write a zero to the next word in memory before we read */
1878 /* the previous write to make sure every memory location is unique */
1879 for (i = 0; i < 100; i++) {
1880 test_addr = start_address + i * 4;
1881 test_data = 0xA5A55A5A;
1882 boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
1883 boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
1884 data = boot_loader_read_mem32(pao, dsp_index, test_addr);
1885 if (data != test_data) {
1886 HPI_DEBUG_LOG(VERBOSE,
1887 "Memtest error details "
1888 "%08x %08x %08x %i\n", test_addr, test_data,
1890 return 1; /* error */
1892 /* leave location as zero */
1893 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1896 /* zero out entire memory block */
1897 for (i = 0; i < length; i++) {
1898 test_addr = start_address + i * 4;
1899 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1904 static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
1908 if (dsp_index == 0) {
1909 /* DSP 0 is a C6205 */
1911 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1915 err = boot_loader_test_memory(pao, dsp_index,
1916 0x80000000, 0x10000);
1917 } else if (dsp_index == 1) {
1918 /* DSP 1 is a C6713 */
1919 /* 192K internal mem */
1920 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1923 /* 64K internal mem / L2 cache */
1924 err = boot_loader_test_memory(pao, dsp_index,
1925 0x00030000, 0x10000);
1929 return HPI6205_ERROR_DSP_INTMEM;
1934 static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
1937 u32 dRAM_start_address = 0;
1940 if (dsp_index == 0) {
1941 /* only test for SDRAM if an ASI5000 card */
1942 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
1943 /* DSP 0 is always C6205 */
1944 dRAM_start_address = 0x00400000;
1945 dRAM_size = 0x200000;
1946 /*dwDRAMinc=1024; */
1949 } else if (dsp_index == 1) {
1950 /* DSP 1 is a C6713 */
1951 dRAM_start_address = 0x80000000;
1952 dRAM_size = 0x200000;
1953 /*dwDRAMinc=1024; */
1956 if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
1958 return HPI6205_ERROR_DSP_EXTMEM;
1962 static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
1965 if (dsp_index == 0) {
1966 /* only test for DSP0 PLD on ASI5000 card */
1967 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
1968 /* PLD is located at CE3=0x03000000 */
1969 data = boot_loader_read_mem32(pao, dsp_index,
1971 if ((data & 0xF) != 0x5)
1972 return HPI6205_ERROR_DSP_PLD;
1973 data = boot_loader_read_mem32(pao, dsp_index,
1975 if ((data & 0xF) != 0xA)
1976 return HPI6205_ERROR_DSP_PLD;
1978 } else if (dsp_index == 1) {
1979 /* DSP 1 is a C6713 */
1980 if (pao->pci.pci_dev->subsystem_device == 0x8700) {
1981 /* PLD is located at CE1=0x90000000 */
1982 data = boot_loader_read_mem32(pao, dsp_index,
1984 if ((data & 0xFF) != 0xAA)
1985 return HPI6205_ERROR_DSP_PLD;
1987 boot_loader_write_mem32(pao, dsp_index, 0x90000000,
1994 /** Transfer data to or from DSP
1995 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
1997 static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
1998 u32 data_size, int operation)
2000 struct hpi_hw_obj *phw = pao->priv;
2001 u32 data_transferred = 0;
2004 struct bus_master_interface *interface = phw->p_interface_buffer;
2007 return HPI_ERROR_INVALID_DATA_POINTER;
2009 data_size &= ~3L; /* round data_size down to nearest 4 bytes */
2011 /* make sure state is IDLE */
2012 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
2013 return HPI_ERROR_DSP_HARDWARE;
2015 while (data_transferred < data_size) {
2016 u32 this_copy = data_size - data_transferred;
2018 if (this_copy > HPI6205_SIZEOF_DATA)
2019 this_copy = HPI6205_SIZEOF_DATA;
2021 if (operation == H620_HIF_SEND_DATA)
2022 memcpy((void *)&interface->u.b_data[0],
2023 &p_data[data_transferred], this_copy);
2025 interface->transfer_size_in_bytes = this_copy;
2027 /* DSP must change this back to nOperation */
2028 interface->dsp_ack = H620_HIF_IDLE;
2029 send_dsp_command(phw, operation);
2031 temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
2032 HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
2033 HPI6205_TIMEOUT - temp2, this_copy);
2037 HPI_DEBUG_LOG(ERROR,
2038 "Timed out waiting for " "state %d got %d\n",
2039 operation, interface->dsp_ack);
2043 if (operation == H620_HIF_GET_DATA)
2044 memcpy(&p_data[data_transferred],
2045 (void *)&interface->u.b_data[0], this_copy);
2047 data_transferred += this_copy;
2049 if (interface->dsp_ack != operation)
2050 HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
2051 interface->dsp_ack, operation);
2052 /* err=HPI_ERROR_DSP_HARDWARE; */
2054 send_dsp_command(phw, H620_HIF_IDLE);
2059 /* wait for up to timeout_us microseconds for the DSP
2060 to signal state by DMA into dwDspAck
2062 static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
2064 struct bus_master_interface *interface = phw->p_interface_buffer;
2065 int t = timeout_us / 4;
2067 rmb(); /* ensure interface->dsp_ack is up to date */
2068 while ((interface->dsp_ack != state) && --t) {
2069 hpios_delay_micro_seconds(4);
2070 rmb(); /* DSP changes dsp_ack by DMA */
2073 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2077 /* set the busmaster interface to cmd, then interrupt the DSP */
2078 static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
2080 struct bus_master_interface *interface = phw->p_interface_buffer;
2083 interface->host_cmd = cmd;
2084 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2085 /* before we interrupt the DSP */
2086 r = ioread32(phw->prHDCR);
2087 r |= (u32)C6205_HDCR_DSPINT;
2088 iowrite32(r, phw->prHDCR);
2089 r &= ~(u32)C6205_HDCR_DSPINT;
2090 iowrite32(r, phw->prHDCR);
2093 static unsigned int message_count;
2095 static u16 message_response_sequence(struct hpi_adapter_obj *pao,
2096 struct hpi_message *phm, struct hpi_response *phr)
2098 u32 time_out, time_out2;
2099 struct hpi_hw_obj *phw = pao->priv;
2100 struct bus_master_interface *interface = phw->p_interface_buffer;
2104 if (phm->size > sizeof(interface->u.message_buffer)) {
2105 phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
2106 phr->specific_error = sizeof(interface->u.message_buffer);
2107 phr->size = sizeof(struct hpi_response_header);
2108 HPI_DEBUG_LOG(ERROR,
2109 "message len %d too big for buffer %zd \n", phm->size,
2110 sizeof(interface->u.message_buffer));
2114 /* Assume buffer of type struct bus_master_interface_62
2115 is allocated "noncacheable" */
2117 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2118 HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
2119 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
2122 memcpy(&interface->u.message_buffer, phm, phm->size);
2123 /* signal we want a response */
2124 send_dsp_command(phw, H620_HIF_GET_RESP);
2126 time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
2129 HPI_DEBUG_LOG(ERROR,
2130 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
2131 message_count, interface->dsp_ack);
2133 HPI_DEBUG_LOG(VERBOSE,
2134 "(%u) transition to GET_RESP after %u\n",
2135 message_count, HPI6205_TIMEOUT - time_out2);
2137 /* spin waiting on HIF interrupt flag (end of msg process) */
2138 time_out = HPI6205_TIMEOUT;
2140 /* read the result */
2142 if (interface->u.response_buffer.response.size <= phr->size)
2143 memcpy(phr, &interface->u.response_buffer,
2144 interface->u.response_buffer.response.size);
2146 HPI_DEBUG_LOG(ERROR,
2147 "response len %d too big for buffer %d\n",
2148 interface->u.response_buffer.response.size,
2150 memcpy(phr, &interface->u.response_buffer,
2151 sizeof(struct hpi_response_header));
2152 phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
2153 phr->specific_error =
2154 interface->u.response_buffer.response.size;
2155 phr->size = sizeof(struct hpi_response_header);
2158 /* set interface back to idle */
2159 send_dsp_command(phw, H620_HIF_IDLE);
2161 if (!time_out || !time_out2) {
2162 HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
2163 return HPI6205_ERROR_MSG_RESP_TIMEOUT;
2165 /* special case for adapter close - */
2166 /* wait for the DSP to indicate it is idle */
2167 if (phm->function == HPI_ADAPTER_CLOSE) {
2168 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2169 HPI_DEBUG_LOG(DEBUG,
2170 "Timeout waiting for idle "
2171 "(on adapter_close)\n");
2172 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
2175 err = hpi_validate_response(phm, phr);
2179 static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
2180 struct hpi_response *phr)
2185 hpios_dsplock_lock(pao);
2187 err = message_response_sequence(pao, phm, phr);
2189 /* maybe an error response */
2191 /* something failed in the HPI/DSP interface */
2192 if (err >= HPI_ERROR_BACKEND_BASE) {
2193 phr->error = HPI_ERROR_DSP_COMMUNICATION;
2194 phr->specific_error = err;
2201 /* just the header of the response is valid */
2202 phr->size = sizeof(struct hpi_response_header);
2205 pao->dsp_crashed = 0;
2207 if (phr->error != 0) /* something failed in the DSP */
2210 switch (phm->function) {
2211 case HPI_OSTREAM_WRITE:
2212 case HPI_ISTREAM_ANC_WRITE:
2213 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2214 phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
2217 case HPI_ISTREAM_READ:
2218 case HPI_OSTREAM_ANC_READ:
2219 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2220 phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
2227 hpios_dsplock_unlock(pao);