1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2011 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 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_adapter_obj
*pao
,
230 struct hpi_message
*phm
, struct hpi_response
*phr
)
232 switch (phm
->function
) {
233 case HPI_SUBSYS_CREATE_ADAPTER
:
234 subsys_create_adapter(phm
, phr
);
237 phr
->error
= HPI_ERROR_INVALID_FUNC
;
242 static void control_message(struct hpi_adapter_obj
*pao
,
243 struct hpi_message
*phm
, struct hpi_response
*phr
)
246 struct hpi_hw_obj
*phw
= pao
->priv
;
247 u16 pending_cache_error
= 0;
249 switch (phm
->function
) {
250 case HPI_CONTROL_GET_STATE
:
251 if (pao
->has_control_cache
) {
252 rmb(); /* make sure we see updates DMAed from DSP */
253 if (hpi_check_control_cache(phw
->p_cache
, phm
, phr
)) {
255 } else if (phm
->u
.c
.attribute
== HPI_METER_PEAK
) {
256 pending_cache_error
=
257 HPI_ERROR_CONTROL_CACHING
;
260 hw_message(pao
, phm
, phr
);
261 if (pending_cache_error
&& !phr
->error
)
262 phr
->error
= pending_cache_error
;
264 case HPI_CONTROL_GET_INFO
:
265 hw_message(pao
, phm
, phr
);
267 case HPI_CONTROL_SET_STATE
:
268 hw_message(pao
, phm
, phr
);
269 if (pao
->has_control_cache
)
270 hpi_cmn_control_cache_sync_to_msg(phw
->p_cache
, phm
,
274 phr
->error
= HPI_ERROR_INVALID_FUNC
;
279 static void adapter_message(struct hpi_adapter_obj
*pao
,
280 struct hpi_message
*phm
, struct hpi_response
*phr
)
282 switch (phm
->function
) {
283 case HPI_ADAPTER_DELETE
:
284 adapter_delete(pao
, phm
, phr
);
288 hw_message(pao
, phm
, phr
);
293 static void outstream_message(struct hpi_adapter_obj
*pao
,
294 struct hpi_message
*phm
, struct hpi_response
*phr
)
297 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
298 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
299 HPI_DEBUG_LOG(WARNING
,
300 "Message referencing invalid stream %d "
301 "on adapter index %d\n", phm
->obj_index
,
306 switch (phm
->function
) {
307 case HPI_OSTREAM_WRITE
:
308 outstream_write(pao
, phm
, phr
);
310 case HPI_OSTREAM_GET_INFO
:
311 outstream_get_info(pao
, phm
, phr
);
313 case HPI_OSTREAM_HOSTBUFFER_ALLOC
:
314 outstream_host_buffer_allocate(pao
, phm
, phr
);
316 case HPI_OSTREAM_HOSTBUFFER_GET_INFO
:
317 outstream_host_buffer_get_info(pao
, phm
, phr
);
319 case HPI_OSTREAM_HOSTBUFFER_FREE
:
320 outstream_host_buffer_free(pao
, phm
, phr
);
322 case HPI_OSTREAM_START
:
323 outstream_start(pao
, phm
, phr
);
325 case HPI_OSTREAM_OPEN
:
326 outstream_open(pao
, phm
, phr
);
328 case HPI_OSTREAM_RESET
:
329 outstream_reset(pao
, phm
, phr
);
332 hw_message(pao
, phm
, phr
);
337 static void instream_message(struct hpi_adapter_obj
*pao
,
338 struct hpi_message
*phm
, struct hpi_response
*phr
)
341 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
342 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
343 HPI_DEBUG_LOG(WARNING
,
344 "Message referencing invalid stream %d "
345 "on adapter index %d\n", phm
->obj_index
,
350 switch (phm
->function
) {
351 case HPI_ISTREAM_READ
:
352 instream_read(pao
, phm
, phr
);
354 case HPI_ISTREAM_GET_INFO
:
355 instream_get_info(pao
, phm
, phr
);
357 case HPI_ISTREAM_HOSTBUFFER_ALLOC
:
358 instream_host_buffer_allocate(pao
, phm
, phr
);
360 case HPI_ISTREAM_HOSTBUFFER_GET_INFO
:
361 instream_host_buffer_get_info(pao
, phm
, phr
);
363 case HPI_ISTREAM_HOSTBUFFER_FREE
:
364 instream_host_buffer_free(pao
, phm
, phr
);
366 case HPI_ISTREAM_START
:
367 instream_start(pao
, phm
, phr
);
370 hw_message(pao
, phm
, phr
);
375 /*****************************************************************************/
376 /** Entry point to this HPI backend
377 * All calls to the HPI start here
380 void _HPI_6205(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
381 struct hpi_response
*phr
)
383 if (pao
&& (pao
->dsp_crashed
>= 10)
384 && (phm
->function
!= HPI_ADAPTER_DEBUG_READ
)) {
385 /* allow last resort debug read even after crash */
386 hpi_init_response(phr
, phm
->object
, phm
->function
,
387 HPI_ERROR_DSP_HARDWARE
);
388 HPI_DEBUG_LOG(WARNING
, " %d,%d dsp crashed.\n", phm
->object
,
393 /* Init default response */
394 if (phm
->function
!= HPI_SUBSYS_CREATE_ADAPTER
)
395 phr
->error
= HPI_ERROR_PROCESSING_MESSAGE
;
397 HPI_DEBUG_LOG(VERBOSE
, "start of switch\n");
399 case HPI_TYPE_REQUEST
:
400 switch (phm
->object
) {
401 case HPI_OBJ_SUBSYSTEM
:
402 subsys_message(pao
, phm
, phr
);
405 case HPI_OBJ_ADAPTER
:
406 adapter_message(pao
, phm
, phr
);
409 case HPI_OBJ_CONTROL
:
410 control_message(pao
, phm
, phr
);
413 case HPI_OBJ_OSTREAM
:
414 outstream_message(pao
, phm
, phr
);
417 case HPI_OBJ_ISTREAM
:
418 instream_message(pao
, phm
, phr
);
422 hw_message(pao
, phm
, phr
);
428 phr
->error
= HPI_ERROR_INVALID_TYPE
;
433 void HPI_6205(struct hpi_message
*phm
, struct hpi_response
*phr
)
435 struct hpi_adapter_obj
*pao
= NULL
;
437 if (phm
->object
!= HPI_OBJ_SUBSYSTEM
) {
438 /* normal messages must have valid adapter index */
439 pao
= hpi_find_adapter(phm
->adapter_index
);
441 /* subsys messages don't address an adapter */
442 _HPI_6205(NULL
, phm
, phr
);
447 _HPI_6205(pao
, phm
, phr
);
449 hpi_init_response(phr
, phm
->object
, phm
->function
,
450 HPI_ERROR_BAD_ADAPTER_NUMBER
);
453 /*****************************************************************************/
456 /** Create an adapter object and initialise it based on resource information
457 * passed in in the message
458 * *** NOTE - you cannot use this function AND the FindAdapters function at the
459 * same time, the application must use only one of them to get the adapters ***
461 static void subsys_create_adapter(struct hpi_message
*phm
,
462 struct hpi_response
*phr
)
464 /* create temp adapter obj, because we don't know what index yet */
465 struct hpi_adapter_obj ao
;
469 HPI_DEBUG_LOG(DEBUG
, " subsys_create_adapter\n");
471 memset(&ao
, 0, sizeof(ao
));
473 ao
.priv
= kzalloc(sizeof(struct hpi_hw_obj
), GFP_KERNEL
);
475 HPI_DEBUG_LOG(ERROR
, "can't get mem for adapter object\n");
476 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
480 ao
.pci
= *phm
->u
.s
.resource
.r
.pci
;
481 err
= create_adapter_obj(&ao
, &os_error_code
);
483 delete_adapter_obj(&ao
);
484 if (err
>= HPI_ERROR_BACKEND_BASE
) {
485 phr
->error
= HPI_ERROR_DSP_BOOTLOAD
;
486 phr
->specific_error
= err
;
490 phr
->u
.s
.data
= os_error_code
;
494 phr
->u
.s
.adapter_type
= ao
.type
;
495 phr
->u
.s
.adapter_index
= ao
.index
;
499 /** delete an adapter - required by WDM driver */
500 static void adapter_delete(struct hpi_adapter_obj
*pao
,
501 struct hpi_message
*phm
, struct hpi_response
*phr
)
503 struct hpi_hw_obj
*phw
;
506 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
510 /* reset adapter h/w */
512 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
514 iowrite32(C6205_HDCR_WARMRESET
, phw
->prHDCR
);
516 delete_adapter_obj(pao
);
517 hpi_delete_adapter(pao
);
521 /** Create adapter object
522 allocate buffers, bootload DSPs, initialise control cache
524 static u16
create_adapter_obj(struct hpi_adapter_obj
*pao
,
527 struct hpi_hw_obj
*phw
= pao
->priv
;
528 struct bus_master_interface
*interface
;
533 /* init error reporting */
534 pao
->dsp_crashed
= 0;
536 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
537 phw
->flag_outstream_just_reset
[i
] = 1;
539 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
541 pao
->pci
.ap_mem_base
[1] +
542 C6205_BAR1_HSR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
544 pao
->pci
.ap_mem_base
[1] +
545 C6205_BAR1_HDCR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
547 pao
->pci
.ap_mem_base
[1] +
548 C6205_BAR1_DSPP
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
550 pao
->has_control_cache
= 0;
552 if (hpios_locked_mem_alloc(&phw
->h_locked_mem
,
553 sizeof(struct bus_master_interface
),
555 phw
->p_interface_buffer
= NULL
;
556 else if (hpios_locked_mem_get_virt_addr(&phw
->h_locked_mem
,
557 (void *)&phw
->p_interface_buffer
))
558 phw
->p_interface_buffer
= NULL
;
560 HPI_DEBUG_LOG(DEBUG
, "interface buffer address %p\n",
561 phw
->p_interface_buffer
);
563 if (phw
->p_interface_buffer
) {
564 memset((void *)phw
->p_interface_buffer
, 0,
565 sizeof(struct bus_master_interface
));
566 phw
->p_interface_buffer
->dsp_ack
= H620_HIF_UNKNOWN
;
569 err
= adapter_boot_load_dsp(pao
, pos_error_code
);
571 HPI_DEBUG_LOG(ERROR
, "DSP code load failed\n");
572 /* no need to clean up as SubSysCreateAdapter */
573 /* calls DeleteAdapter on error. */
576 HPI_DEBUG_LOG(INFO
, "load DSP code OK\n");
578 /* allow boot load even if mem alloc wont work */
579 if (!phw
->p_interface_buffer
)
580 return HPI_ERROR_MEMORY_ALLOC
;
582 interface
= phw
->p_interface_buffer
;
584 /* make sure the DSP has started ok */
585 if (!wait_dsp_ack(phw
, H620_HIF_RESET
, HPI6205_TIMEOUT
* 10)) {
586 HPI_DEBUG_LOG(ERROR
, "timed out waiting reset state \n");
587 return HPI6205_ERROR_6205_INIT_FAILED
;
589 /* Note that *pao, *phw are zeroed after allocation,
590 * so pointers and flags are NULL by default.
591 * Allocate bus mastering control cache buffer and tell the DSP about it
593 if (interface
->control_cache
.number_of_controls
) {
594 u8
*p_control_cache_virtual
;
596 err
= hpios_locked_mem_alloc(&phw
->h_control_cache
,
597 interface
->control_cache
.size_in_bytes
,
600 err
= hpios_locked_mem_get_virt_addr(&phw
->
602 (void *)&p_control_cache_virtual
);
604 memset(p_control_cache_virtual
, 0,
605 interface
->control_cache
.size_in_bytes
);
608 hpi_alloc_control_cache(interface
->
609 control_cache
.number_of_controls
,
610 interface
->control_cache
.size_in_bytes
,
611 p_control_cache_virtual
);
614 err
= HPI_ERROR_MEMORY_ALLOC
;
617 err
= hpios_locked_mem_get_phys_addr(&phw
->
618 h_control_cache
, &phys_addr
);
619 interface
->control_cache
.physical_address32
=
624 pao
->has_control_cache
= 1;
626 if (hpios_locked_mem_valid(&phw
->h_control_cache
))
627 hpios_locked_mem_free(&phw
->h_control_cache
);
628 pao
->has_control_cache
= 0;
631 send_dsp_command(phw
, H620_HIF_IDLE
);
634 struct hpi_message hm
;
635 struct hpi_response hr
;
638 HPI_DEBUG_LOG(VERBOSE
, "init ADAPTER_GET_INFO\n");
639 memset(&hm
, 0, sizeof(hm
));
640 /* wAdapterIndex == version == 0 */
641 hm
.type
= HPI_TYPE_REQUEST
;
642 hm
.size
= sizeof(hm
);
643 hm
.object
= HPI_OBJ_ADAPTER
;
644 hm
.function
= HPI_ADAPTER_GET_INFO
;
646 memset(&hr
, 0, sizeof(hr
));
647 hr
.size
= sizeof(hr
);
649 err
= message_response_sequence(pao
, &hm
, &hr
);
651 HPI_DEBUG_LOG(ERROR
, "message transport error %d\n",
658 pao
->type
= hr
.u
.ax
.info
.adapter_type
;
659 pao
->index
= hr
.u
.ax
.info
.adapter_index
;
662 hr
.u
.ax
.info
.num_outstreams
+
663 hr
.u
.ax
.info
.num_instreams
;
665 HPI_DEBUG_LOG(VERBOSE
,
666 "got adapter info type %x index %d serial %d\n",
667 hr
.u
.ax
.info
.adapter_type
, hr
.u
.ax
.info
.adapter_index
,
668 hr
.u
.ax
.info
.serial_number
);
672 phw
->p_cache
->adap_idx
= pao
->index
;
674 HPI_DEBUG_LOG(INFO
, "bootload DSP OK\n");
676 return hpi_add_adapter(pao
);
679 /** Free memory areas allocated by adapter
680 * this routine is called from AdapterDelete,
681 * and SubSysCreateAdapter if duplicate index
683 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
)
685 struct hpi_hw_obj
*phw
= pao
->priv
;
688 if (hpios_locked_mem_valid(&phw
->h_control_cache
)) {
689 hpios_locked_mem_free(&phw
->h_control_cache
);
690 hpi_free_control_cache(phw
->p_cache
);
693 if (hpios_locked_mem_valid(&phw
->h_locked_mem
)) {
694 hpios_locked_mem_free(&phw
->h_locked_mem
);
695 phw
->p_interface_buffer
= NULL
;
698 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
699 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[i
])) {
700 hpios_locked_mem_free(&phw
->instream_host_buffers
[i
]);
701 /*?phw->InStreamHostBuffers[i] = NULL; */
702 phw
->instream_host_buffer_size
[i
] = 0;
705 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
706 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[i
])) {
707 hpios_locked_mem_free(&phw
->outstream_host_buffers
709 phw
->outstream_host_buffer_size
[i
] = 0;
714 /*****************************************************************************/
715 /* Adapter functions */
717 /*****************************************************************************/
718 /* OutStream Host buffer functions */
720 /** Allocate or attach buffer for busmastering
722 static void outstream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
723 struct hpi_message
*phm
, struct hpi_response
*phr
)
726 u32 command
= phm
->u
.d
.u
.buffer
.command
;
727 struct hpi_hw_obj
*phw
= pao
->priv
;
728 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
730 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
732 if (command
== HPI_BUFFER_CMD_EXTERNAL
733 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
734 /* ALLOC phase, allocate a buffer with power of 2 size,
735 get its bus address for PCI bus mastering
737 phm
->u
.d
.u
.buffer
.buffer_size
=
738 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
739 /* return old size and allocated size,
740 so caller can detect change */
741 phr
->u
.d
.u
.stream_info
.data_available
=
742 phw
->outstream_host_buffer_size
[phm
->obj_index
];
743 phr
->u
.d
.u
.stream_info
.buffer_size
=
744 phm
->u
.d
.u
.buffer
.buffer_size
;
746 if (phw
->outstream_host_buffer_size
[phm
->obj_index
] ==
747 phm
->u
.d
.u
.buffer
.buffer_size
) {
748 /* Same size, no action required */
752 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
754 hpios_locked_mem_free(&phw
->outstream_host_buffers
757 err
= hpios_locked_mem_alloc(&phw
->outstream_host_buffers
758 [phm
->obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
762 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
763 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
767 err
= hpios_locked_mem_get_phys_addr
768 (&phw
->outstream_host_buffers
[phm
->obj_index
],
769 &phm
->u
.d
.u
.buffer
.pci_address
);
770 /* get the phys addr into msg for single call alloc caller
771 * needs to do this for split alloc (or use the same message)
772 * return the phy address for split alloc in the respose too
774 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
775 phm
->u
.d
.u
.buffer
.pci_address
;
778 hpios_locked_mem_free(&phw
->outstream_host_buffers
780 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
781 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
786 if (command
== HPI_BUFFER_CMD_EXTERNAL
787 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
788 /* GRANT phase. Set up the BBM status, tell the DSP about
789 the buffer so it can start using BBM.
791 struct hpi_hostbuffer_status
*status
;
793 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
796 "Buffer size must be 2^N not %d\n",
797 phm
->u
.d
.u
.buffer
.buffer_size
);
798 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
801 phw
->outstream_host_buffer_size
[phm
->obj_index
] =
802 phm
->u
.d
.u
.buffer
.buffer_size
;
803 status
= &interface
->outstream_host_buffer_status
[phm
->
805 status
->samples_processed
= 0;
806 status
->stream_state
= HPI_STATE_STOPPED
;
807 status
->dsp_index
= 0;
808 status
->host_index
= status
->dsp_index
;
809 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
810 status
->auxiliary_data_available
= 0;
812 hw_message(pao
, phm
, phr
);
815 && hpios_locked_mem_valid(&phw
->
816 outstream_host_buffers
[phm
->obj_index
])) {
817 hpios_locked_mem_free(&phw
->outstream_host_buffers
819 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
824 static void outstream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
825 struct hpi_message
*phm
, struct hpi_response
*phr
)
827 struct hpi_hw_obj
*phw
= pao
->priv
;
828 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
829 struct hpi_hostbuffer_status
*status
;
832 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
834 if (hpios_locked_mem_get_virt_addr(&phw
->
835 outstream_host_buffers
[phm
->obj_index
],
836 (void *)&p_bbm_data
)) {
837 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
840 status
= &interface
->outstream_host_buffer_status
[phm
->
842 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
843 HPI_OSTREAM_HOSTBUFFER_GET_INFO
, 0);
844 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
845 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
847 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
848 HPI_OSTREAM_HOSTBUFFER_GET_INFO
,
849 HPI_ERROR_INVALID_OPERATION
);
853 static void outstream_host_buffer_free(struct hpi_adapter_obj
*pao
,
854 struct hpi_message
*phm
, struct hpi_response
*phr
)
856 struct hpi_hw_obj
*phw
= pao
->priv
;
857 u32 command
= phm
->u
.d
.u
.buffer
.command
;
859 if (phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
860 if (command
== HPI_BUFFER_CMD_EXTERNAL
861 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
862 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
863 hw_message(pao
, phm
, phr
);
864 /* Tell adapter to stop using the host buffer. */
866 if (command
== HPI_BUFFER_CMD_EXTERNAL
867 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
868 hpios_locked_mem_free(&phw
->outstream_host_buffers
871 /* Should HPI_ERROR_INVALID_OPERATION be returned
872 if no host buffer is allocated? */
874 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
875 HPI_OSTREAM_HOSTBUFFER_FREE
, 0);
879 static u32
outstream_get_space_available(struct hpi_hostbuffer_status
*status
)
881 return status
->size_in_bytes
- (status
->host_index
-
885 static void outstream_write(struct hpi_adapter_obj
*pao
,
886 struct hpi_message
*phm
, struct hpi_response
*phr
)
888 struct hpi_hw_obj
*phw
= pao
->priv
;
889 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
890 struct hpi_hostbuffer_status
*status
;
893 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
894 /* there is no BBM buffer, write via message */
895 hw_message(pao
, phm
, phr
);
899 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
900 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
902 space_available
= outstream_get_space_available(status
);
903 if (space_available
< phm
->u
.d
.u
.data
.data_size
) {
904 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
908 /* HostBuffers is used to indicate host buffer is internally allocated.
909 otherwise, assumed external, data written externally */
910 if (phm
->u
.d
.u
.data
.pb_data
911 && hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
915 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
917 if (hpios_locked_mem_get_virt_addr(&phw
->
918 outstream_host_buffers
[phm
->obj_index
],
919 (void *)&p_bbm_data
)) {
920 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
925 or enough to fit from current to end of BBM buffer */
927 min(phm
->u
.d
.u
.data
.data_size
,
928 status
->size_in_bytes
-
929 (status
->host_index
& (status
->size_in_bytes
- 1)));
932 (status
->host_index
& (status
->size_in_bytes
- 1)),
933 p_app_data
, l_first_write
);
934 /* remaining data if any */
935 memcpy(p_bbm_data
, p_app_data
+ l_first_write
,
936 phm
->u
.d
.u
.data
.data_size
- l_first_write
);
940 * This version relies on the DSP code triggering an OStream buffer
941 * update immediately following a SET_FORMAT call. The host has
942 * already written data into the BBM buffer, but the DSP won't know
943 * about it until dwHostIndex is adjusted.
945 if (phw
->flag_outstream_just_reset
[phm
->obj_index
]) {
946 /* Format can only change after reset. Must tell DSP. */
947 u16 function
= phm
->function
;
948 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 0;
949 phm
->function
= HPI_OSTREAM_SET_FORMAT
;
950 hw_message(pao
, phm
, phr
); /* send the format to the DSP */
951 phm
->function
= function
;
956 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
959 static void outstream_get_info(struct hpi_adapter_obj
*pao
,
960 struct hpi_message
*phm
, struct hpi_response
*phr
)
962 struct hpi_hw_obj
*phw
= pao
->priv
;
963 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
964 struct hpi_hostbuffer_status
*status
;
966 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
967 hw_message(pao
, phm
, phr
);
971 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
973 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
975 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
976 phr
->u
.d
.u
.stream_info
.samples_transferred
=
977 status
->samples_processed
;
978 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
979 phr
->u
.d
.u
.stream_info
.data_available
=
980 status
->size_in_bytes
- outstream_get_space_available(status
);
981 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
982 status
->auxiliary_data_available
;
985 static void outstream_start(struct hpi_adapter_obj
*pao
,
986 struct hpi_message
*phm
, struct hpi_response
*phr
)
988 hw_message(pao
, phm
, phr
);
991 static void outstream_reset(struct hpi_adapter_obj
*pao
,
992 struct hpi_message
*phm
, struct hpi_response
*phr
)
994 struct hpi_hw_obj
*phw
= pao
->priv
;
995 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 1;
996 hw_message(pao
, phm
, phr
);
999 static void outstream_open(struct hpi_adapter_obj
*pao
,
1000 struct hpi_message
*phm
, struct hpi_response
*phr
)
1002 outstream_reset(pao
, phm
, phr
);
1005 /*****************************************************************************/
1006 /* InStream Host buffer functions */
1008 static void instream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
1009 struct hpi_message
*phm
, struct hpi_response
*phr
)
1012 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1013 struct hpi_hw_obj
*phw
= pao
->priv
;
1014 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1016 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1018 if (command
== HPI_BUFFER_CMD_EXTERNAL
1019 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
1021 phm
->u
.d
.u
.buffer
.buffer_size
=
1022 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
1023 phr
->u
.d
.u
.stream_info
.data_available
=
1024 phw
->instream_host_buffer_size
[phm
->obj_index
];
1025 phr
->u
.d
.u
.stream_info
.buffer_size
=
1026 phm
->u
.d
.u
.buffer
.buffer_size
;
1028 if (phw
->instream_host_buffer_size
[phm
->obj_index
] ==
1029 phm
->u
.d
.u
.buffer
.buffer_size
) {
1030 /* Same size, no action required */
1034 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1036 hpios_locked_mem_free(&phw
->instream_host_buffers
1039 err
= hpios_locked_mem_alloc(&phw
->instream_host_buffers
[phm
->
1040 obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
1044 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1045 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1049 err
= hpios_locked_mem_get_phys_addr
1050 (&phw
->instream_host_buffers
[phm
->obj_index
],
1051 &phm
->u
.d
.u
.buffer
.pci_address
);
1052 /* get the phys addr into msg for single call alloc. Caller
1053 needs to do this for split alloc so return the phy address */
1054 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1055 phm
->u
.d
.u
.buffer
.pci_address
;
1057 hpios_locked_mem_free(&phw
->instream_host_buffers
1059 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1060 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
1065 if (command
== HPI_BUFFER_CMD_EXTERNAL
1066 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
1067 struct hpi_hostbuffer_status
*status
;
1069 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
1071 HPI_DEBUG_LOG(ERROR
,
1072 "Buffer size must be 2^N not %d\n",
1073 phm
->u
.d
.u
.buffer
.buffer_size
);
1074 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1078 phw
->instream_host_buffer_size
[phm
->obj_index
] =
1079 phm
->u
.d
.u
.buffer
.buffer_size
;
1080 status
= &interface
->instream_host_buffer_status
[phm
->
1082 status
->samples_processed
= 0;
1083 status
->stream_state
= HPI_STATE_STOPPED
;
1084 status
->dsp_index
= 0;
1085 status
->host_index
= status
->dsp_index
;
1086 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
1087 status
->auxiliary_data_available
= 0;
1089 hw_message(pao
, phm
, phr
);
1092 && hpios_locked_mem_valid(&phw
->
1093 instream_host_buffers
[phm
->obj_index
])) {
1094 hpios_locked_mem_free(&phw
->instream_host_buffers
1096 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1101 static void instream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
1102 struct hpi_message
*phm
, struct hpi_response
*phr
)
1104 struct hpi_hw_obj
*phw
= pao
->priv
;
1105 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1106 struct hpi_hostbuffer_status
*status
;
1109 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1111 if (hpios_locked_mem_get_virt_addr(&phw
->
1112 instream_host_buffers
[phm
->obj_index
],
1113 (void *)&p_bbm_data
)) {
1114 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1117 status
= &interface
->instream_host_buffer_status
[phm
->
1119 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1120 HPI_ISTREAM_HOSTBUFFER_GET_INFO
, 0);
1121 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
1122 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
1124 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1125 HPI_ISTREAM_HOSTBUFFER_GET_INFO
,
1126 HPI_ERROR_INVALID_OPERATION
);
1130 static void instream_host_buffer_free(struct hpi_adapter_obj
*pao
,
1131 struct hpi_message
*phm
, struct hpi_response
*phr
)
1133 struct hpi_hw_obj
*phw
= pao
->priv
;
1134 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1136 if (phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1137 if (command
== HPI_BUFFER_CMD_EXTERNAL
1138 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
1139 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1140 hw_message(pao
, phm
, phr
);
1143 if (command
== HPI_BUFFER_CMD_EXTERNAL
1144 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
1145 hpios_locked_mem_free(&phw
->instream_host_buffers
1149 /* Should HPI_ERROR_INVALID_OPERATION be returned
1150 if no host buffer is allocated? */
1151 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1152 HPI_ISTREAM_HOSTBUFFER_FREE
, 0);
1158 static void instream_start(struct hpi_adapter_obj
*pao
,
1159 struct hpi_message
*phm
, struct hpi_response
*phr
)
1161 hw_message(pao
, phm
, phr
);
1164 static u32
instream_get_bytes_available(struct hpi_hostbuffer_status
*status
)
1166 return status
->dsp_index
- status
->host_index
;
1169 static void instream_read(struct hpi_adapter_obj
*pao
,
1170 struct hpi_message
*phm
, struct hpi_response
*phr
)
1172 struct hpi_hw_obj
*phw
= pao
->priv
;
1173 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1174 struct hpi_hostbuffer_status
*status
;
1178 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
1180 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1181 hw_message(pao
, phm
, phr
);
1184 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1186 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1187 data_available
= instream_get_bytes_available(status
);
1188 if (data_available
< phm
->u
.d
.u
.data
.data_size
) {
1189 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1193 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1195 if (hpios_locked_mem_get_virt_addr(&phw
->
1196 instream_host_buffers
[phm
->obj_index
],
1197 (void *)&p_bbm_data
)) {
1198 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1203 or enough to fit from current to end of BBM buffer */
1205 min(phm
->u
.d
.u
.data
.data_size
,
1206 status
->size_in_bytes
-
1207 (status
->host_index
& (status
->size_in_bytes
- 1)));
1211 (status
->host_index
& (status
->size_in_bytes
- 1)),
1213 /* remaining data if any */
1214 memcpy(p_app_data
+ l_first_read
, p_bbm_data
,
1215 phm
->u
.d
.u
.data
.data_size
- l_first_read
);
1217 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
1220 static void instream_get_info(struct hpi_adapter_obj
*pao
,
1221 struct hpi_message
*phm
, struct hpi_response
*phr
)
1223 struct hpi_hw_obj
*phw
= pao
->priv
;
1224 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1225 struct hpi_hostbuffer_status
*status
;
1226 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1227 hw_message(pao
, phm
, phr
);
1231 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1233 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1235 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
1236 phr
->u
.d
.u
.stream_info
.samples_transferred
=
1237 status
->samples_processed
;
1238 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
1239 phr
->u
.d
.u
.stream_info
.data_available
=
1240 instream_get_bytes_available(status
);
1241 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1242 status
->auxiliary_data_available
;
1245 /*****************************************************************************/
1247 #define HPI6205_MAX_FILES_TO_LOAD 2
1249 static u16
adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
1250 u32
*pos_error_code
)
1252 struct hpi_hw_obj
*phw
= pao
->priv
;
1253 struct dsp_code dsp_code
;
1254 u16 boot_code_id
[HPI6205_MAX_FILES_TO_LOAD
];
1259 boot_code_id
[0] = HPI_ADAPTER_ASI(0x6205);
1261 boot_code_id
[1] = pao
->pci
.pci_dev
->subsystem_device
;
1262 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id
[1]);
1264 /* fix up cases where bootcode id[1] != subsys id */
1265 switch (boot_code_id
[1]) {
1266 case HPI_ADAPTER_FAMILY_ASI(0x5000):
1267 boot_code_id
[0] = boot_code_id
[1];
1268 boot_code_id
[1] = 0;
1270 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1271 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1272 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1273 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
1275 case HPI_ADAPTER_FAMILY_ASI(0x5500):
1276 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1277 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1278 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
1280 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1281 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
1287 /* reset DSP by writing a 1 to the WARMRESET bit */
1288 temp
= C6205_HDCR_WARMRESET
;
1289 iowrite32(temp
, phw
->prHDCR
);
1290 hpios_delay_micro_seconds(1000);
1292 /* check that PCI i/f was configured by EEPROM */
1293 temp
= ioread32(phw
->prHSR
);
1294 if ((temp
& (C6205_HSR_CFGERR
| C6205_HSR_EEREAD
)) !=
1296 return HPI6205_ERROR_6205_EEPROM
;
1298 /* disable PINTA interrupt */
1299 iowrite32(temp
, phw
->prHSR
);
1301 /* check control register reports PCI boot mode */
1302 temp
= ioread32(phw
->prHDCR
);
1303 if (!(temp
& C6205_HDCR_PCIBOOT
))
1304 return HPI6205_ERROR_6205_REG
;
1306 /* try writing a few numbers to the DSP page register */
1307 /* and reading them back. */
1309 iowrite32(temp
, phw
->prDSPP
);
1310 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1311 return HPI6205_ERROR_6205_DSPPAGE
;
1313 iowrite32(temp
, phw
->prDSPP
);
1314 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1315 return HPI6205_ERROR_6205_DSPPAGE
;
1317 iowrite32(temp
, phw
->prDSPP
);
1318 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1319 return HPI6205_ERROR_6205_DSPPAGE
;
1320 /* reset DSP page to the correct number */
1322 iowrite32(temp
, phw
->prDSPP
);
1323 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1324 return HPI6205_ERROR_6205_DSPPAGE
;
1327 /* release 6713 from reset before 6205 is bootloaded.
1328 This ensures that the EMIF is inactive,
1329 and the 6713 HPI gets the correct bootmode etc
1331 if (boot_code_id
[1] != 0) {
1332 /* DSP 1 is a C6713 */
1333 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1334 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002202);
1335 hpios_delay_micro_seconds(100);
1336 /* Reset the 6713 #1 - revB */
1337 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
1339 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1340 boot_loader_read_mem32(pao
, 0, 0);
1342 hpios_delay_micro_seconds(100);
1343 /* Release C6713 from reset - revB */
1344 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 4);
1345 hpios_delay_micro_seconds(100);
1348 for (dsp
= 0; dsp
< HPI6205_MAX_FILES_TO_LOAD
; dsp
++) {
1349 /* is there a DSP to load? */
1350 if (boot_code_id
[dsp
] == 0)
1353 err
= boot_loader_config_emif(pao
, dsp
);
1357 err
= boot_loader_test_internal_memory(pao
, dsp
);
1361 err
= boot_loader_test_external_memory(pao
, dsp
);
1365 err
= boot_loader_test_pld(pao
, dsp
);
1369 /* write the DSP code down into the DSPs memory */
1370 err
= hpi_dsp_code_open(boot_code_id
[dsp
], pao
->pci
.pci_dev
,
1371 &dsp_code
, pos_error_code
);
1381 err
= hpi_dsp_code_read_word(&dsp_code
, &length
);
1384 if (length
== 0xFFFFFFFF)
1385 break; /* end of code */
1387 err
= hpi_dsp_code_read_word(&dsp_code
, &address
);
1390 err
= hpi_dsp_code_read_word(&dsp_code
, &type
);
1393 err
= hpi_dsp_code_read_block(length
, &dsp_code
,
1397 for (i
= 0; i
< (int)length
; i
++) {
1398 boot_loader_write_mem32(pao
, dsp
, address
,
1400 /* dummy read every 4 words */
1401 /* for 6205 advisory 1.4.4 */
1403 boot_loader_read_mem32(pao
, dsp
,
1411 hpi_dsp_code_close(&dsp_code
);
1416 hpi_dsp_code_rewind(&dsp_code
);
1424 hpi_dsp_code_read_word(&dsp_code
, &length
);
1425 if (length
== 0xFFFFFFFF)
1426 break; /* end of code */
1428 hpi_dsp_code_read_word(&dsp_code
, &address
);
1429 hpi_dsp_code_read_word(&dsp_code
, &type
);
1430 hpi_dsp_code_read_block(length
, &dsp_code
, &pcode
);
1432 for (i
= 0; i
< (int)length
; i
++) {
1433 data
= boot_loader_read_mem32(pao
, dsp
,
1435 if (data
!= *pcode
) {
1445 hpi_dsp_code_close(&dsp_code
);
1450 /* After bootloading all DSPs, start DSP0 running
1451 * The DSP0 code will handle starting and synchronizing with its slaves
1453 if (phw
->p_interface_buffer
) {
1454 /* we need to tell the card the physical PCI address */
1455 u32 physicalPC_iaddress
;
1456 struct bus_master_interface
*interface
=
1457 phw
->p_interface_buffer
;
1458 u32 host_mailbox_address_on_dsp
;
1459 u32 physicalPC_iaddress_verify
= 0;
1461 /* set ack so we know when DSP is ready to go */
1462 /* (dwDspAck will be changed to HIF_RESET) */
1463 interface
->dsp_ack
= H620_HIF_UNKNOWN
;
1464 wmb(); /* ensure ack is written before dsp writes back */
1466 err
= hpios_locked_mem_get_phys_addr(&phw
->h_locked_mem
,
1467 &physicalPC_iaddress
);
1469 /* locate the host mailbox on the DSP. */
1470 host_mailbox_address_on_dsp
= 0x80000000;
1471 while ((physicalPC_iaddress
!= physicalPC_iaddress_verify
)
1473 boot_loader_write_mem32(pao
, 0,
1474 host_mailbox_address_on_dsp
,
1475 physicalPC_iaddress
);
1476 physicalPC_iaddress_verify
=
1477 boot_loader_read_mem32(pao
, 0,
1478 host_mailbox_address_on_dsp
);
1481 HPI_DEBUG_LOG(DEBUG
, "starting DS_ps running\n");
1482 /* enable interrupts */
1483 temp
= ioread32(phw
->prHSR
);
1484 temp
&= ~(u32
)C6205_HSR_INTAM
;
1485 iowrite32(temp
, phw
->prHSR
);
1487 /* start code running... */
1488 temp
= ioread32(phw
->prHDCR
);
1489 temp
|= (u32
)C6205_HDCR_DSPINT
;
1490 iowrite32(temp
, phw
->prHDCR
);
1492 /* give the DSP 10ms to start up */
1493 hpios_delay_micro_seconds(10000);
1498 /*****************************************************************************/
1499 /* Bootloader utility functions */
1501 static u32
boot_loader_read_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
1504 struct hpi_hw_obj
*phw
= pao
->priv
;
1506 __iomem u32
*p_data
;
1508 if (dsp_index
== 0) {
1509 /* DSP 0 is always C6205 */
1510 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1511 /* BAR1 register access */
1512 p_data
= pao
->pci
.ap_mem_base
[1] +
1513 (address
& 0x007fffff) /
1514 sizeof(*pao
->pci
.ap_mem_base
[1]);
1515 /* HPI_DEBUG_LOG(WARNING,
1516 "BAR1 access %08x\n", dwAddress); */
1518 u32 dw4M_page
= address
>> 22L;
1519 if (dw4M_page
!= phw
->dsp_page
) {
1520 phw
->dsp_page
= dw4M_page
;
1522 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1525 address
&= 0x3fffff; /* address within 4M page */
1526 /* BAR0 memory access */
1527 p_data
= pao
->pci
.ap_mem_base
[0] +
1528 address
/ sizeof(u32
);
1530 data
= ioread32(p_data
);
1531 } else if (dsp_index
== 1) {
1532 /* DSP 1 is a C6713 */
1534 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1535 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1536 lsb
= boot_loader_read_mem32(pao
, 0, HPIDL_ADDR
);
1537 data
= boot_loader_read_mem32(pao
, 0, HPIDH_ADDR
);
1538 data
= (data
<< 16) | (lsb
& 0xFFFF);
1543 static void boot_loader_write_mem32(struct hpi_adapter_obj
*pao
,
1544 int dsp_index
, u32 address
, u32 data
)
1546 struct hpi_hw_obj
*phw
= pao
->priv
;
1547 __iomem u32
*p_data
;
1548 /* u32 dwVerifyData=0; */
1550 if (dsp_index
== 0) {
1551 /* DSP 0 is always C6205 */
1552 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1553 /* BAR1 - DSP register access using */
1554 /* Non-prefetchable PCI access */
1555 p_data
= pao
->pci
.ap_mem_base
[1] +
1556 (address
& 0x007fffff) /
1557 sizeof(*pao
->pci
.ap_mem_base
[1]);
1559 /* BAR0 access - all of DSP memory using */
1560 /* pre-fetchable PCI access */
1561 u32 dw4M_page
= address
>> 22L;
1562 if (dw4M_page
!= phw
->dsp_page
) {
1563 phw
->dsp_page
= dw4M_page
;
1565 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1568 address
&= 0x3fffff; /* address within 4M page */
1569 p_data
= pao
->pci
.ap_mem_base
[0] +
1570 address
/ sizeof(u32
);
1572 iowrite32(data
, p_data
);
1573 } else if (dsp_index
== 1) {
1574 /* DSP 1 is a C6713 */
1575 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1576 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1578 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1579 boot_loader_read_mem32(pao
, 0, 0);
1581 boot_loader_write_mem32(pao
, 0, HPIDL_ADDR
, data
);
1582 boot_loader_write_mem32(pao
, 0, HPIDH_ADDR
, data
>> 16);
1584 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1585 boot_loader_read_mem32(pao
, 0, 0);
1589 static u16
boot_loader_config_emif(struct hpi_adapter_obj
*pao
, int dsp_index
)
1591 if (dsp_index
== 0) {
1594 /* DSP 0 is always C6205 */
1597 /* memory map of C6205 */
1598 /* 00000000-0000FFFF 16Kx32 internal program */
1599 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1603 /* Global EMIF control */
1604 boot_loader_write_mem32(pao
, dsp_index
, 0x01800000, 0x3779);
1613 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1614 setting
= 0x00000030;
1615 boot_loader_write_mem32(pao
, dsp_index
, 0x01800008, setting
);
1616 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1618 return HPI6205_ERROR_DSP_EMIF1
;
1620 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1621 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1622 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1623 /* WST should be 71, but 63 is max possible */
1625 (1L << WS_OFS
) | (63L << WST_OFS
) | (1L << WH_OFS
) |
1626 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1628 boot_loader_write_mem32(pao
, dsp_index
, 0x01800004, setting
);
1629 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1631 return HPI6205_ERROR_DSP_EMIF2
;
1633 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1634 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1635 /* plenty of wait states */
1637 (1L << WS_OFS
) | (28L << WST_OFS
) | (1L << WH_OFS
) |
1638 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1640 boot_loader_write_mem32(pao
, dsp_index
, 0x01800010, setting
);
1641 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1643 return HPI6205_ERROR_DSP_EMIF3
;
1645 /* EMIF CE3 setup - 32 bit async. */
1646 /* This is the PLD on the ASI5000 cards only */
1648 (1L << WS_OFS
) | (10L << WST_OFS
) | (1L << WH_OFS
) |
1649 (1L << RS_OFS
) | (10L << RST_OFS
) | (1L << RH_OFS
) |
1651 boot_loader_write_mem32(pao
, dsp_index
, 0x01800014, setting
);
1652 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1654 return HPI6205_ERROR_DSP_EMIF4
;
1656 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1657 /* need to use this else DSP code crashes? */
1658 boot_loader_write_mem32(pao
, dsp_index
, 0x01800018,
1661 /* EMIF SDRAM Refresh Timing */
1662 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1663 boot_loader_write_mem32(pao
, dsp_index
, 0x0180001C,
1666 } else if (dsp_index
== 1) {
1667 /* test access to the C6713s HPI registers */
1668 u32 write_data
= 0, read_data
= 0, i
= 0;
1670 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1672 boot_loader_write_mem32(pao
, 0, HPICL_ADDR
, write_data
);
1673 boot_loader_write_mem32(pao
, 0, HPICH_ADDR
, write_data
);
1674 /* C67 HPI is on lower 16bits of 32bit EMIF */
1676 0xFFF7 & boot_loader_read_mem32(pao
, 0, HPICL_ADDR
);
1677 if (write_data
!= read_data
) {
1678 HPI_DEBUG_LOG(ERROR
, "HPICL %x %x\n", write_data
,
1680 return HPI6205_ERROR_C6713_HPIC
;
1682 /* HPIA - walking ones test */
1684 for (i
= 0; i
< 32; i
++) {
1685 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
,
1687 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
,
1688 (write_data
>> 16));
1690 0xFFFF & boot_loader_read_mem32(pao
, 0,
1693 read_data
| ((0xFFFF &
1694 boot_loader_read_mem32(pao
, 0,
1697 if (read_data
!= write_data
) {
1698 HPI_DEBUG_LOG(ERROR
, "HPIA %x %x\n",
1699 write_data
, read_data
);
1700 return HPI6205_ERROR_C6713_HPIA
;
1702 write_data
= write_data
<< 1;
1706 * ** C6713 datasheet says we cannot program PLL from HPI,
1707 * and indeed if we try to set the PLL multiply from the HPI,
1708 * the PLL does not seem to lock, so we enable the PLL and
1709 * use the default multiply of x 7, which for a 27MHz clock
1710 * gives a DSP speed of 189MHz
1713 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0000);
1714 hpios_delay_micro_seconds(1000);
1715 /* EMIF = 189/3=63MHz */
1716 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C120, 0x8002);
1718 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C11C, 0x8001);
1720 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C118, 0x8000);
1721 hpios_delay_micro_seconds(1000);
1722 /* ** SGT test to take GPO3 high when we start the PLL */
1723 /* and low when the delay is completed */
1724 /* FSX0 <- '1' (GPO3) */
1725 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A0A);
1726 /* PLL not bypassed */
1727 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0001);
1728 hpios_delay_micro_seconds(1000);
1729 /* FSX0 <- '0' (GPO3) */
1730 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A02);
1732 /* 6205 EMIF CE1 resetup - 32 bit async. */
1733 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1734 boot_loader_write_mem32(pao
, 0, 0x01800004, /* CE1 */
1735 (1L << WS_OFS
) | (8L << WST_OFS
) | (1L << WH_OFS
) |
1736 (1L << RS_OFS
) | (12L << RST_OFS
) | (1L << RH_OFS
) |
1739 hpios_delay_micro_seconds(1000);
1741 /* check that we can read one of the PLL registers */
1742 /* PLL should not be bypassed! */
1743 if ((boot_loader_read_mem32(pao
, dsp_index
, 0x01B7C100) & 0xF)
1745 return HPI6205_ERROR_C6713_PLL
;
1747 /* setup C67x EMIF (note this is the only use of
1748 BAR1 via BootLoader_WriteMem32) */
1749 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_GCTL
,
1752 /* EMIF CE0 setup - 2Mx32 Sync DRAM
1759 7..4 MTYPE 0011 Sync DRAM 32bits
1763 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_CE0
,
1766 /* EMIF SDRAM Extension
1768 31-21 0000b 0000b 000b
1769 20 WR2RD = 2cycles-1 = 1b
1771 19-18 WR2DEAC = 3cycle-1 = 10b
1772 17 WR2WR = 2cycle-1 = 1b
1773 16-15 R2WDQM = 4cycle-1 = 11b
1774 14-12 RD2WR = 6cycles-1 = 101b
1776 11-10 RD2DEAC = 4cycle-1 = 11b
1777 9 RD2RD = 2cycle-1 = 1b
1778 8-7 THZP = 3cycle-1 = 10b
1779 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
1780 4 TRRD = 2cycle = 0b (tRRD = 14ns)
1781 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
1782 1 CAS latency = 3cyc = 1b
1783 (for Micron 2M32-7 operating at 100MHz)
1785 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMEXT
,
1788 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
1791 29..28 SDRSZ 00b 11 row address pins
1793 27..26 SDCSZ 01b 8 column address pins
1794 25 RFEN 1b refersh enabled
1795 24 INIT 1b init SDRAM!
1797 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
1799 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
1801 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
1803 11..0 - 0000b 0000b 0000b
1805 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMCTL
,
1808 /* SDRAM refresh timing
1809 Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
1811 boot_loader_write_mem32(pao
, dsp_index
,
1812 C6713_EMIF_SDRAMTIMING
, 0x00000410);
1814 hpios_delay_micro_seconds(1000);
1815 } else if (dsp_index
== 2) {
1816 /* DSP 2 is a C6713 */
1822 static u16
boot_loader_test_memory(struct hpi_adapter_obj
*pao
, int dsp_index
,
1823 u32 start_address
, u32 length
)
1827 u32 test_data
= 0, data
= 0;
1831 /* for 1st word, test each bit in the 32bit word, */
1832 /* dwLength specifies number of 32bit words to test */
1833 /*for(i=0; i<dwLength; i++) */
1836 test_addr
= start_address
+ i
* 4;
1837 test_data
= 0x00000001;
1838 for (j
= 0; j
< 32; j
++) {
1839 boot_loader_write_mem32(pao
, dsp_index
, test_addr
,
1841 data
= boot_loader_read_mem32(pao
, dsp_index
,
1843 if (data
!= test_data
) {
1844 HPI_DEBUG_LOG(VERBOSE
,
1845 "Memtest error details "
1846 "%08x %08x %08x %i\n", test_addr
,
1847 test_data
, data
, dsp_index
);
1848 return 1; /* error */
1850 test_data
= test_data
<< 1;
1854 /* for the next 100 locations test each location, leaving it as zero */
1855 /* write a zero to the next word in memory before we read */
1856 /* the previous write to make sure every memory location is unique */
1857 for (i
= 0; i
< 100; i
++) {
1858 test_addr
= start_address
+ i
* 4;
1859 test_data
= 0xA5A55A5A;
1860 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, test_data
);
1861 boot_loader_write_mem32(pao
, dsp_index
, test_addr
+ 4, 0);
1862 data
= boot_loader_read_mem32(pao
, dsp_index
, test_addr
);
1863 if (data
!= test_data
) {
1864 HPI_DEBUG_LOG(VERBOSE
,
1865 "Memtest error details "
1866 "%08x %08x %08x %i\n", test_addr
, test_data
,
1868 return 1; /* error */
1870 /* leave location as zero */
1871 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1874 /* zero out entire memory block */
1875 for (i
= 0; i
< length
; i
++) {
1876 test_addr
= start_address
+ i
* 4;
1877 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1882 static u16
boot_loader_test_internal_memory(struct hpi_adapter_obj
*pao
,
1886 if (dsp_index
== 0) {
1887 /* DSP 0 is a C6205 */
1889 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1893 err
= boot_loader_test_memory(pao
, dsp_index
,
1894 0x80000000, 0x10000);
1895 } else if (dsp_index
== 1) {
1896 /* DSP 1 is a C6713 */
1897 /* 192K internal mem */
1898 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1901 /* 64K internal mem / L2 cache */
1902 err
= boot_loader_test_memory(pao
, dsp_index
,
1903 0x00030000, 0x10000);
1907 return HPI6205_ERROR_DSP_INTMEM
;
1912 static u16
boot_loader_test_external_memory(struct hpi_adapter_obj
*pao
,
1915 u32 dRAM_start_address
= 0;
1918 if (dsp_index
== 0) {
1919 /* only test for SDRAM if an ASI5000 card */
1920 if (pao
->pci
.pci_dev
->subsystem_device
== 0x5000) {
1921 /* DSP 0 is always C6205 */
1922 dRAM_start_address
= 0x00400000;
1923 dRAM_size
= 0x200000;
1924 /*dwDRAMinc=1024; */
1927 } else if (dsp_index
== 1) {
1928 /* DSP 1 is a C6713 */
1929 dRAM_start_address
= 0x80000000;
1930 dRAM_size
= 0x200000;
1931 /*dwDRAMinc=1024; */
1934 if (boot_loader_test_memory(pao
, dsp_index
, dRAM_start_address
,
1936 return HPI6205_ERROR_DSP_EXTMEM
;
1940 static u16
boot_loader_test_pld(struct hpi_adapter_obj
*pao
, int dsp_index
)
1943 if (dsp_index
== 0) {
1944 /* only test for DSP0 PLD on ASI5000 card */
1945 if (pao
->pci
.pci_dev
->subsystem_device
== 0x5000) {
1946 /* PLD is located at CE3=0x03000000 */
1947 data
= boot_loader_read_mem32(pao
, dsp_index
,
1949 if ((data
& 0xF) != 0x5)
1950 return HPI6205_ERROR_DSP_PLD
;
1951 data
= boot_loader_read_mem32(pao
, dsp_index
,
1953 if ((data
& 0xF) != 0xA)
1954 return HPI6205_ERROR_DSP_PLD
;
1956 } else if (dsp_index
== 1) {
1957 /* DSP 1 is a C6713 */
1958 if (pao
->pci
.pci_dev
->subsystem_device
== 0x8700) {
1959 /* PLD is located at CE1=0x90000000 */
1960 data
= boot_loader_read_mem32(pao
, dsp_index
,
1962 if ((data
& 0xFF) != 0xAA)
1963 return HPI6205_ERROR_DSP_PLD
;
1965 boot_loader_write_mem32(pao
, dsp_index
, 0x90000000,
1972 /** Transfer data to or from DSP
1973 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
1975 static short hpi6205_transfer_data(struct hpi_adapter_obj
*pao
, u8
*p_data
,
1976 u32 data_size
, int operation
)
1978 struct hpi_hw_obj
*phw
= pao
->priv
;
1979 u32 data_transferred
= 0;
1982 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1985 return HPI_ERROR_INVALID_DATA_POINTER
;
1987 data_size
&= ~3L; /* round data_size down to nearest 4 bytes */
1989 /* make sure state is IDLE */
1990 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
))
1991 return HPI_ERROR_DSP_HARDWARE
;
1993 while (data_transferred
< data_size
) {
1994 u32 this_copy
= data_size
- data_transferred
;
1996 if (this_copy
> HPI6205_SIZEOF_DATA
)
1997 this_copy
= HPI6205_SIZEOF_DATA
;
1999 if (operation
== H620_HIF_SEND_DATA
)
2000 memcpy((void *)&interface
->u
.b_data
[0],
2001 &p_data
[data_transferred
], this_copy
);
2003 interface
->transfer_size_in_bytes
= this_copy
;
2005 /* DSP must change this back to nOperation */
2006 interface
->dsp_ack
= H620_HIF_IDLE
;
2007 send_dsp_command(phw
, operation
);
2009 temp2
= wait_dsp_ack(phw
, operation
, HPI6205_TIMEOUT
);
2010 HPI_DEBUG_LOG(DEBUG
, "spun %d times for data xfer of %d\n",
2011 HPI6205_TIMEOUT
- temp2
, this_copy
);
2015 HPI_DEBUG_LOG(ERROR
,
2016 "Timed out waiting for " "state %d got %d\n",
2017 operation
, interface
->dsp_ack
);
2021 if (operation
== H620_HIF_GET_DATA
)
2022 memcpy(&p_data
[data_transferred
],
2023 (void *)&interface
->u
.b_data
[0], this_copy
);
2025 data_transferred
+= this_copy
;
2027 if (interface
->dsp_ack
!= operation
)
2028 HPI_DEBUG_LOG(DEBUG
, "interface->dsp_ack=%d, expected %d\n",
2029 interface
->dsp_ack
, operation
);
2030 /* err=HPI_ERROR_DSP_HARDWARE; */
2032 send_dsp_command(phw
, H620_HIF_IDLE
);
2037 /* wait for up to timeout_us microseconds for the DSP
2038 to signal state by DMA into dwDspAck
2040 static int wait_dsp_ack(struct hpi_hw_obj
*phw
, int state
, int timeout_us
)
2042 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2043 int t
= timeout_us
/ 4;
2045 rmb(); /* ensure interface->dsp_ack is up to date */
2046 while ((interface
->dsp_ack
!= state
) && --t
) {
2047 hpios_delay_micro_seconds(4);
2048 rmb(); /* DSP changes dsp_ack by DMA */
2051 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2055 /* set the busmaster interface to cmd, then interrupt the DSP */
2056 static void send_dsp_command(struct hpi_hw_obj
*phw
, int cmd
)
2058 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2061 interface
->host_cmd
= cmd
;
2062 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2063 /* before we interrupt the DSP */
2064 r
= ioread32(phw
->prHDCR
);
2065 r
|= (u32
)C6205_HDCR_DSPINT
;
2066 iowrite32(r
, phw
->prHDCR
);
2067 r
&= ~(u32
)C6205_HDCR_DSPINT
;
2068 iowrite32(r
, phw
->prHDCR
);
2071 static unsigned int message_count
;
2073 static u16
message_response_sequence(struct hpi_adapter_obj
*pao
,
2074 struct hpi_message
*phm
, struct hpi_response
*phr
)
2076 u32 time_out
, time_out2
;
2077 struct hpi_hw_obj
*phw
= pao
->priv
;
2078 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2082 if (phm
->size
> sizeof(interface
->u
.message_buffer
)) {
2083 phr
->error
= HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL
;
2084 phr
->specific_error
= sizeof(interface
->u
.message_buffer
);
2085 phr
->size
= sizeof(struct hpi_response_header
);
2086 HPI_DEBUG_LOG(ERROR
,
2087 "message len %d too big for buffer %zd \n", phm
->size
,
2088 sizeof(interface
->u
.message_buffer
));
2092 /* Assume buffer of type struct bus_master_interface
2093 is allocated "noncacheable" */
2095 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2096 HPI_DEBUG_LOG(DEBUG
, "timeout waiting for idle\n");
2097 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
;
2100 memcpy(&interface
->u
.message_buffer
, phm
, phm
->size
);
2101 /* signal we want a response */
2102 send_dsp_command(phw
, H620_HIF_GET_RESP
);
2104 time_out2
= wait_dsp_ack(phw
, H620_HIF_GET_RESP
, HPI6205_TIMEOUT
);
2107 HPI_DEBUG_LOG(ERROR
,
2108 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
2109 message_count
, interface
->dsp_ack
);
2111 HPI_DEBUG_LOG(VERBOSE
,
2112 "(%u) transition to GET_RESP after %u\n",
2113 message_count
, HPI6205_TIMEOUT
- time_out2
);
2115 /* spin waiting on HIF interrupt flag (end of msg process) */
2116 time_out
= HPI6205_TIMEOUT
;
2118 /* read the result */
2120 if (interface
->u
.response_buffer
.response
.size
<= phr
->size
)
2121 memcpy(phr
, &interface
->u
.response_buffer
,
2122 interface
->u
.response_buffer
.response
.size
);
2124 HPI_DEBUG_LOG(ERROR
,
2125 "response len %d too big for buffer %d\n",
2126 interface
->u
.response_buffer
.response
.size
,
2128 memcpy(phr
, &interface
->u
.response_buffer
,
2129 sizeof(struct hpi_response_header
));
2130 phr
->error
= HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL
;
2131 phr
->specific_error
=
2132 interface
->u
.response_buffer
.response
.size
;
2133 phr
->size
= sizeof(struct hpi_response_header
);
2136 /* set interface back to idle */
2137 send_dsp_command(phw
, H620_HIF_IDLE
);
2139 if (!time_out
|| !time_out2
) {
2140 HPI_DEBUG_LOG(DEBUG
, "something timed out!\n");
2141 return HPI6205_ERROR_MSG_RESP_TIMEOUT
;
2143 /* special case for adapter close - */
2144 /* wait for the DSP to indicate it is idle */
2145 if (phm
->function
== HPI_ADAPTER_CLOSE
) {
2146 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2147 HPI_DEBUG_LOG(DEBUG
,
2148 "Timeout waiting for idle "
2149 "(on adapter_close)\n");
2150 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
;
2153 err
= hpi_validate_response(phm
, phr
);
2157 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
2158 struct hpi_response
*phr
)
2163 hpios_dsplock_lock(pao
);
2165 err
= message_response_sequence(pao
, phm
, phr
);
2167 /* maybe an error response */
2169 /* something failed in the HPI/DSP interface */
2170 if (err
>= HPI_ERROR_BACKEND_BASE
) {
2171 phr
->error
= HPI_ERROR_DSP_COMMUNICATION
;
2172 phr
->specific_error
= err
;
2179 /* just the header of the response is valid */
2180 phr
->size
= sizeof(struct hpi_response_header
);
2183 pao
->dsp_crashed
= 0;
2185 if (phr
->error
!= 0) /* something failed in the DSP */
2188 switch (phm
->function
) {
2189 case HPI_OSTREAM_WRITE
:
2190 case HPI_ISTREAM_ANC_WRITE
:
2191 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2192 phm
->u
.d
.u
.data
.data_size
, H620_HIF_SEND_DATA
);
2195 case HPI_ISTREAM_READ
:
2196 case HPI_OSTREAM_ANC_READ
:
2197 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2198 phm
->u
.d
.u
.data
.data_size
, H620_HIF_GET_DATA
);
2205 hpios_dsplock_unlock(pao
);