1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Hardware Programming Interface (HPI) for AudioScience
20 ASI50xx, AS51xx, ASI6xxx, ASI87xx ASI89xx series adapters.
21 These PCI and PCIe bus adapters are based on a
22 TMS320C6205 PCI bus mastering DSP,
23 and (except ASI50xx) TI TMS320C6xxx floating point DSP
26 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
28 (C) Copyright AudioScience Inc. 1998-2010
29 *******************************************************************************/
30 #define SOURCEFILE_NAME "hpi6205.c"
32 #include "hpi_internal.h"
33 #include "hpimsginit.h"
39 /*****************************************************************************/
40 /* HPI6205 specific error codes */
41 #define HPI6205_ERROR_BASE 1000 /* not actually used anywhere */
43 /* operational/messaging errors */
44 #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
45 #define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
47 /* initialization/bootload errors */
48 #define HPI6205_ERROR_6205_NO_IRQ 1002
49 #define HPI6205_ERROR_6205_INIT_FAILED 1003
50 #define HPI6205_ERROR_6205_REG 1006
51 #define HPI6205_ERROR_6205_DSPPAGE 1007
52 #define HPI6205_ERROR_C6713_HPIC 1009
53 #define HPI6205_ERROR_C6713_HPIA 1010
54 #define HPI6205_ERROR_C6713_PLL 1011
55 #define HPI6205_ERROR_DSP_INTMEM 1012
56 #define HPI6205_ERROR_DSP_EXTMEM 1013
57 #define HPI6205_ERROR_DSP_PLD 1014
58 #define HPI6205_ERROR_6205_EEPROM 1017
59 #define HPI6205_ERROR_DSP_EMIF 1018
61 /*****************************************************************************/
62 /* for C6205 PCI i/f */
63 /* Host Status Register (HSR) bitfields */
64 #define C6205_HSR_INTSRC 0x01
65 #define C6205_HSR_INTAVAL 0x02
66 #define C6205_HSR_INTAM 0x04
67 #define C6205_HSR_CFGERR 0x08
68 #define C6205_HSR_EEREAD 0x10
69 /* Host-to-DSP Control Register (HDCR) bitfields */
70 #define C6205_HDCR_WARMRESET 0x01
71 #define C6205_HDCR_DSPINT 0x02
72 #define C6205_HDCR_PCIBOOT 0x04
73 /* DSP Page Register (DSPP) bitfields, */
74 /* defines 4 Mbyte page that BAR0 points to */
75 #define C6205_DSPP_MAP1 0x400
77 /* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
78 * BAR1 maps to non-prefetchable 8 Mbyte memory block
79 * of DSP memory mapped registers (starting at 0x01800000).
80 * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
81 * needs to be added to the BAR1 base address set in the PCI config reg
83 #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
84 #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
85 #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
86 #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
88 /* used to control LED (revA) and reset C6713 (revB) */
89 #define C6205_BAR0_TIMER1_CTL (0x01980000L)
91 /* For first 6713 in CE1 space, using DA17,16,2 */
92 #define HPICL_ADDR 0x01400000L
93 #define HPICH_ADDR 0x01400004L
94 #define HPIAL_ADDR 0x01410000L
95 #define HPIAH_ADDR 0x01410004L
96 #define HPIDIL_ADDR 0x01420000L
97 #define HPIDIH_ADDR 0x01420004L
98 #define HPIDL_ADDR 0x01430000L
99 #define HPIDH_ADDR 0x01430004L
101 #define C6713_EMIF_GCTL 0x01800000
102 #define C6713_EMIF_CE1 0x01800004
103 #define C6713_EMIF_CE0 0x01800008
104 #define C6713_EMIF_CE2 0x01800010
105 #define C6713_EMIF_CE3 0x01800014
106 #define C6713_EMIF_SDRAMCTL 0x01800018
107 #define C6713_EMIF_SDRAMTIMING 0x0180001C
108 #define C6713_EMIF_SDRAMEXT 0x01800020
118 struct consistent_dma_area h_locked_mem
;
119 struct bus_master_interface
*p_interface_buffer
;
121 u16 flag_outstream_just_reset
[HPI_MAX_STREAMS
];
122 /* a non-NULL handle means there is an HPI allocated buffer */
123 struct consistent_dma_area instream_host_buffers
[HPI_MAX_STREAMS
];
124 struct consistent_dma_area outstream_host_buffers
[HPI_MAX_STREAMS
];
125 /* non-zero size means a buffer exists, may be external */
126 u32 instream_host_buffer_size
[HPI_MAX_STREAMS
];
127 u32 outstream_host_buffer_size
[HPI_MAX_STREAMS
];
129 struct consistent_dma_area h_control_cache
;
130 struct hpi_control_cache
*p_cache
;
133 /*****************************************************************************/
134 /* local prototypes */
136 #define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
138 static int wait_dsp_ack(struct hpi_hw_obj
*phw
, int state
, int timeout_us
);
140 static void send_dsp_command(struct hpi_hw_obj
*phw
, int cmd
);
142 static u16
adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
143 u32
*pos_error_code
);
145 static u16
message_response_sequence(struct hpi_adapter_obj
*pao
,
146 struct hpi_message
*phm
, struct hpi_response
*phr
);
148 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
149 struct hpi_response
*phr
);
151 #define HPI6205_TIMEOUT 1000000
153 static void subsys_create_adapter(struct hpi_message
*phm
,
154 struct hpi_response
*phr
);
155 static void adapter_delete(struct hpi_adapter_obj
*pao
,
156 struct hpi_message
*phm
, struct hpi_response
*phr
);
158 static u16
create_adapter_obj(struct hpi_adapter_obj
*pao
,
159 u32
*pos_error_code
);
161 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
);
163 static void outstream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
164 struct hpi_message
*phm
, struct hpi_response
*phr
);
166 static void outstream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
167 struct hpi_message
*phm
, struct hpi_response
*phr
);
169 static void outstream_host_buffer_free(struct hpi_adapter_obj
*pao
,
170 struct hpi_message
*phm
, struct hpi_response
*phr
);
171 static void outstream_write(struct hpi_adapter_obj
*pao
,
172 struct hpi_message
*phm
, struct hpi_response
*phr
);
174 static void outstream_get_info(struct hpi_adapter_obj
*pao
,
175 struct hpi_message
*phm
, struct hpi_response
*phr
);
177 static void outstream_start(struct hpi_adapter_obj
*pao
,
178 struct hpi_message
*phm
, struct hpi_response
*phr
);
180 static void outstream_open(struct hpi_adapter_obj
*pao
,
181 struct hpi_message
*phm
, struct hpi_response
*phr
);
183 static void outstream_reset(struct hpi_adapter_obj
*pao
,
184 struct hpi_message
*phm
, struct hpi_response
*phr
);
186 static void instream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
187 struct hpi_message
*phm
, struct hpi_response
*phr
);
189 static void instream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
190 struct hpi_message
*phm
, struct hpi_response
*phr
);
192 static void instream_host_buffer_free(struct hpi_adapter_obj
*pao
,
193 struct hpi_message
*phm
, struct hpi_response
*phr
);
195 static void instream_read(struct hpi_adapter_obj
*pao
,
196 struct hpi_message
*phm
, struct hpi_response
*phr
);
198 static void instream_get_info(struct hpi_adapter_obj
*pao
,
199 struct hpi_message
*phm
, struct hpi_response
*phr
);
201 static void instream_start(struct hpi_adapter_obj
*pao
,
202 struct hpi_message
*phm
, struct hpi_response
*phr
);
204 static u32
boot_loader_read_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
207 static void boot_loader_write_mem32(struct hpi_adapter_obj
*pao
,
208 int dsp_index
, u32 address
, u32 data
);
210 static u16
boot_loader_config_emif(struct hpi_adapter_obj
*pao
,
213 static u16
boot_loader_test_memory(struct hpi_adapter_obj
*pao
, int dsp_index
,
214 u32 address
, u32 length
);
216 static u16
boot_loader_test_internal_memory(struct hpi_adapter_obj
*pao
,
219 static u16
boot_loader_test_external_memory(struct hpi_adapter_obj
*pao
,
222 static u16
boot_loader_test_pld(struct hpi_adapter_obj
*pao
, int dsp_index
);
224 /*****************************************************************************/
226 static void subsys_message(struct hpi_adapter_obj
*pao
,
227 struct hpi_message
*phm
, struct hpi_response
*phr
)
229 switch (phm
->function
) {
230 case HPI_SUBSYS_CREATE_ADAPTER
:
231 subsys_create_adapter(phm
, phr
);
234 phr
->error
= HPI_ERROR_INVALID_FUNC
;
239 static void control_message(struct hpi_adapter_obj
*pao
,
240 struct hpi_message
*phm
, struct hpi_response
*phr
)
243 struct hpi_hw_obj
*phw
= pao
->priv
;
244 u16 pending_cache_error
= 0;
246 switch (phm
->function
) {
247 case HPI_CONTROL_GET_STATE
:
248 if (pao
->has_control_cache
) {
249 rmb(); /* make sure we see updates DMAed from DSP */
250 if (hpi_check_control_cache(phw
->p_cache
, phm
, phr
)) {
252 } else if (phm
->u
.c
.attribute
== HPI_METER_PEAK
) {
253 pending_cache_error
=
254 HPI_ERROR_CONTROL_CACHING
;
257 hw_message(pao
, phm
, phr
);
258 if (pending_cache_error
&& !phr
->error
)
259 phr
->error
= pending_cache_error
;
261 case HPI_CONTROL_GET_INFO
:
262 hw_message(pao
, phm
, phr
);
264 case HPI_CONTROL_SET_STATE
:
265 hw_message(pao
, phm
, phr
);
266 if (pao
->has_control_cache
)
267 hpi_cmn_control_cache_sync_to_msg(phw
->p_cache
, phm
,
271 phr
->error
= HPI_ERROR_INVALID_FUNC
;
276 static void adapter_message(struct hpi_adapter_obj
*pao
,
277 struct hpi_message
*phm
, struct hpi_response
*phr
)
279 switch (phm
->function
) {
280 case HPI_ADAPTER_DELETE
:
281 adapter_delete(pao
, phm
, phr
);
285 hw_message(pao
, phm
, phr
);
290 static void outstream_message(struct hpi_adapter_obj
*pao
,
291 struct hpi_message
*phm
, struct hpi_response
*phr
)
294 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
295 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
296 HPI_DEBUG_LOG(WARNING
,
297 "Message referencing invalid stream %d "
298 "on adapter index %d\n", phm
->obj_index
,
303 switch (phm
->function
) {
304 case HPI_OSTREAM_WRITE
:
305 outstream_write(pao
, phm
, phr
);
307 case HPI_OSTREAM_GET_INFO
:
308 outstream_get_info(pao
, phm
, phr
);
310 case HPI_OSTREAM_HOSTBUFFER_ALLOC
:
311 outstream_host_buffer_allocate(pao
, phm
, phr
);
313 case HPI_OSTREAM_HOSTBUFFER_GET_INFO
:
314 outstream_host_buffer_get_info(pao
, phm
, phr
);
316 case HPI_OSTREAM_HOSTBUFFER_FREE
:
317 outstream_host_buffer_free(pao
, phm
, phr
);
319 case HPI_OSTREAM_START
:
320 outstream_start(pao
, phm
, phr
);
322 case HPI_OSTREAM_OPEN
:
323 outstream_open(pao
, phm
, phr
);
325 case HPI_OSTREAM_RESET
:
326 outstream_reset(pao
, phm
, phr
);
329 hw_message(pao
, phm
, phr
);
334 static void instream_message(struct hpi_adapter_obj
*pao
,
335 struct hpi_message
*phm
, struct hpi_response
*phr
)
338 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
339 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
340 HPI_DEBUG_LOG(WARNING
,
341 "Message referencing invalid stream %d "
342 "on adapter index %d\n", phm
->obj_index
,
347 switch (phm
->function
) {
348 case HPI_ISTREAM_READ
:
349 instream_read(pao
, phm
, phr
);
351 case HPI_ISTREAM_GET_INFO
:
352 instream_get_info(pao
, phm
, phr
);
354 case HPI_ISTREAM_HOSTBUFFER_ALLOC
:
355 instream_host_buffer_allocate(pao
, phm
, phr
);
357 case HPI_ISTREAM_HOSTBUFFER_GET_INFO
:
358 instream_host_buffer_get_info(pao
, phm
, phr
);
360 case HPI_ISTREAM_HOSTBUFFER_FREE
:
361 instream_host_buffer_free(pao
, phm
, phr
);
363 case HPI_ISTREAM_START
:
364 instream_start(pao
, phm
, phr
);
367 hw_message(pao
, phm
, phr
);
372 /*****************************************************************************/
373 /** Entry point to this HPI backend
374 * All calls to the HPI start here
376 void _HPI_6205(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
377 struct hpi_response
*phr
)
379 if (pao
&& (pao
->dsp_crashed
>= 10)
380 && (phm
->function
!= HPI_ADAPTER_DEBUG_READ
)) {
381 /* allow last resort debug read even after crash */
382 hpi_init_response(phr
, phm
->object
, phm
->function
,
383 HPI_ERROR_DSP_HARDWARE
);
384 HPI_DEBUG_LOG(WARNING
, " %d,%d dsp crashed.\n", phm
->object
,
389 /* Init default response */
390 if (phm
->function
!= HPI_SUBSYS_CREATE_ADAPTER
)
391 phr
->error
= HPI_ERROR_PROCESSING_MESSAGE
;
393 HPI_DEBUG_LOG(VERBOSE
, "start of switch\n");
395 case HPI_TYPE_REQUEST
:
396 switch (phm
->object
) {
397 case HPI_OBJ_SUBSYSTEM
:
398 subsys_message(pao
, phm
, phr
);
401 case HPI_OBJ_ADAPTER
:
402 adapter_message(pao
, phm
, phr
);
405 case HPI_OBJ_CONTROLEX
:
406 case HPI_OBJ_CONTROL
:
407 control_message(pao
, phm
, phr
);
410 case HPI_OBJ_OSTREAM
:
411 outstream_message(pao
, phm
, phr
);
414 case HPI_OBJ_ISTREAM
:
415 instream_message(pao
, phm
, phr
);
419 hw_message(pao
, phm
, phr
);
425 phr
->error
= HPI_ERROR_INVALID_TYPE
;
430 void HPI_6205(struct hpi_message
*phm
, struct hpi_response
*phr
)
432 struct hpi_adapter_obj
*pao
= NULL
;
434 if (phm
->object
!= HPI_OBJ_SUBSYSTEM
) {
435 /* normal messages must have valid adapter index */
436 pao
= hpi_find_adapter(phm
->adapter_index
);
438 /* subsys messages don't address an adapter */
439 _HPI_6205(NULL
, phm
, phr
);
444 _HPI_6205(pao
, phm
, phr
);
446 hpi_init_response(phr
, phm
->object
, phm
->function
,
447 HPI_ERROR_BAD_ADAPTER_NUMBER
);
450 /*****************************************************************************/
453 /** Create an adapter object and initialise it based on resource information
454 * passed in in the message
455 * *** NOTE - you cannot use this function AND the FindAdapters function at the
456 * same time, the application must use only one of them to get the adapters ***
458 static void subsys_create_adapter(struct hpi_message
*phm
,
459 struct hpi_response
*phr
)
461 /* create temp adapter obj, because we don't know what index yet */
462 struct hpi_adapter_obj ao
;
466 HPI_DEBUG_LOG(DEBUG
, " subsys_create_adapter\n");
468 memset(&ao
, 0, sizeof(ao
));
470 ao
.priv
= kzalloc(sizeof(struct hpi_hw_obj
), GFP_KERNEL
);
472 HPI_DEBUG_LOG(ERROR
, "can't get mem for adapter object\n");
473 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
477 ao
.pci
= *phm
->u
.s
.resource
.r
.pci
;
478 err
= create_adapter_obj(&ao
, &os_error_code
);
480 delete_adapter_obj(&ao
);
481 if (err
>= HPI_ERROR_BACKEND_BASE
) {
482 phr
->error
= HPI_ERROR_DSP_BOOTLOAD
;
483 phr
->specific_error
= err
;
487 phr
->u
.s
.data
= os_error_code
;
491 phr
->u
.s
.adapter_type
= ao
.adapter_type
;
492 phr
->u
.s
.adapter_index
= ao
.index
;
496 /** delete an adapter - required by WDM driver */
497 static void adapter_delete(struct hpi_adapter_obj
*pao
,
498 struct hpi_message
*phm
, struct hpi_response
*phr
)
500 struct hpi_hw_obj
*phw
;
503 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
506 phw
= (struct hpi_hw_obj
*)pao
->priv
;
507 /* reset adapter h/w */
509 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
511 iowrite32(C6205_HDCR_WARMRESET
, phw
->prHDCR
);
513 delete_adapter_obj(pao
);
514 hpi_delete_adapter(pao
);
518 /** Create adapter object
519 allocate buffers, bootload DSPs, initialise control cache
521 static u16
create_adapter_obj(struct hpi_adapter_obj
*pao
,
524 struct hpi_hw_obj
*phw
= pao
->priv
;
525 struct bus_master_interface
*interface
;
530 /* init error reporting */
531 pao
->dsp_crashed
= 0;
533 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
534 phw
->flag_outstream_just_reset
[i
] = 1;
536 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
538 pao
->pci
.ap_mem_base
[1] +
539 C6205_BAR1_HSR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
541 pao
->pci
.ap_mem_base
[1] +
542 C6205_BAR1_HDCR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
544 pao
->pci
.ap_mem_base
[1] +
545 C6205_BAR1_DSPP
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
547 pao
->has_control_cache
= 0;
549 if (hpios_locked_mem_alloc(&phw
->h_locked_mem
,
550 sizeof(struct bus_master_interface
),
552 phw
->p_interface_buffer
= NULL
;
553 else if (hpios_locked_mem_get_virt_addr(&phw
->h_locked_mem
,
554 (void *)&phw
->p_interface_buffer
))
555 phw
->p_interface_buffer
= NULL
;
557 HPI_DEBUG_LOG(DEBUG
, "interface buffer address %p\n",
558 phw
->p_interface_buffer
);
560 if (phw
->p_interface_buffer
) {
561 memset((void *)phw
->p_interface_buffer
, 0,
562 sizeof(struct bus_master_interface
));
563 phw
->p_interface_buffer
->dsp_ack
= H620_HIF_UNKNOWN
;
566 err
= adapter_boot_load_dsp(pao
, pos_error_code
);
568 HPI_DEBUG_LOG(ERROR
, "DSP code load failed\n");
569 /* no need to clean up as SubSysCreateAdapter */
570 /* calls DeleteAdapter on error. */
573 HPI_DEBUG_LOG(INFO
, "load DSP code OK\n");
575 /* allow boot load even if mem alloc wont work */
576 if (!phw
->p_interface_buffer
)
577 return HPI_ERROR_MEMORY_ALLOC
;
579 interface
= phw
->p_interface_buffer
;
581 /* make sure the DSP has started ok */
582 if (!wait_dsp_ack(phw
, H620_HIF_RESET
, HPI6205_TIMEOUT
* 10)) {
583 HPI_DEBUG_LOG(ERROR
, "timed out waiting reset state \n");
584 return HPI6205_ERROR_6205_INIT_FAILED
;
586 /* Note that *pao, *phw are zeroed after allocation,
587 * so pointers and flags are NULL by default.
588 * Allocate bus mastering control cache buffer and tell the DSP about it
590 if (interface
->control_cache
.number_of_controls
) {
591 u8
*p_control_cache_virtual
;
593 err
= hpios_locked_mem_alloc(&phw
->h_control_cache
,
594 interface
->control_cache
.size_in_bytes
,
597 err
= hpios_locked_mem_get_virt_addr(&phw
->
599 (void *)&p_control_cache_virtual
);
601 memset(p_control_cache_virtual
, 0,
602 interface
->control_cache
.size_in_bytes
);
605 hpi_alloc_control_cache(interface
->
606 control_cache
.number_of_controls
,
607 interface
->control_cache
.size_in_bytes
,
608 p_control_cache_virtual
);
611 err
= HPI_ERROR_MEMORY_ALLOC
;
614 err
= hpios_locked_mem_get_phys_addr(&phw
->
615 h_control_cache
, &phys_addr
);
616 interface
->control_cache
.physical_address32
=
621 pao
->has_control_cache
= 1;
623 if (hpios_locked_mem_valid(&phw
->h_control_cache
))
624 hpios_locked_mem_free(&phw
->h_control_cache
);
625 pao
->has_control_cache
= 0;
628 send_dsp_command(phw
, H620_HIF_IDLE
);
631 struct hpi_message hm
;
632 struct hpi_response hr
;
635 HPI_DEBUG_LOG(VERBOSE
, "init ADAPTER_GET_INFO\n");
636 memset(&hm
, 0, sizeof(hm
));
637 /* wAdapterIndex == version == 0 */
638 hm
.type
= HPI_TYPE_REQUEST
;
639 hm
.size
= sizeof(hm
);
640 hm
.object
= HPI_OBJ_ADAPTER
;
641 hm
.function
= HPI_ADAPTER_GET_INFO
;
643 memset(&hr
, 0, sizeof(hr
));
644 hr
.size
= sizeof(hr
);
646 err
= message_response_sequence(pao
, &hm
, &hr
);
648 HPI_DEBUG_LOG(ERROR
, "message transport error %d\n",
655 pao
->adapter_type
= hr
.u
.ax
.info
.adapter_type
;
656 pao
->index
= hr
.u
.ax
.info
.adapter_index
;
659 hr
.u
.ax
.info
.num_outstreams
+
660 hr
.u
.ax
.info
.num_instreams
;
662 hpios_locked_mem_prepare((max_streams
* 6) / 10, max_streams
,
663 65536, pao
->pci
.pci_dev
);
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
);
671 pao
->open
= 0; /* upon creation the adapter is closed */
674 phw
->p_cache
->adap_idx
= pao
->index
;
676 HPI_DEBUG_LOG(INFO
, "bootload DSP OK\n");
678 return hpi_add_adapter(pao
);
681 /** Free memory areas allocated by adapter
682 * this routine is called from AdapterDelete,
683 * and SubSysCreateAdapter if duplicate index
685 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
)
687 struct hpi_hw_obj
*phw
= pao
->priv
;
690 if (hpios_locked_mem_valid(&phw
->h_control_cache
)) {
691 hpios_locked_mem_free(&phw
->h_control_cache
);
692 hpi_free_control_cache(phw
->p_cache
);
695 if (hpios_locked_mem_valid(&phw
->h_locked_mem
)) {
696 hpios_locked_mem_free(&phw
->h_locked_mem
);
697 phw
->p_interface_buffer
= NULL
;
700 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
701 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[i
])) {
702 hpios_locked_mem_free(&phw
->instream_host_buffers
[i
]);
703 /*?phw->InStreamHostBuffers[i] = NULL; */
704 phw
->instream_host_buffer_size
[i
] = 0;
707 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
708 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[i
])) {
709 hpios_locked_mem_free(&phw
->outstream_host_buffers
711 phw
->outstream_host_buffer_size
[i
] = 0;
714 hpios_locked_mem_unprepare(pao
->pci
.pci_dev
);
719 /*****************************************************************************/
720 /* Adapter functions */
722 /*****************************************************************************/
723 /* OutStream Host buffer functions */
725 /** Allocate or attach buffer for busmastering
727 static void outstream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
728 struct hpi_message
*phm
, struct hpi_response
*phr
)
731 u32 command
= phm
->u
.d
.u
.buffer
.command
;
732 struct hpi_hw_obj
*phw
= pao
->priv
;
733 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
735 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
737 if (command
== HPI_BUFFER_CMD_EXTERNAL
738 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
739 /* ALLOC phase, allocate a buffer with power of 2 size,
740 get its bus address for PCI bus mastering
742 phm
->u
.d
.u
.buffer
.buffer_size
=
743 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
744 /* return old size and allocated size,
745 so caller can detect change */
746 phr
->u
.d
.u
.stream_info
.data_available
=
747 phw
->outstream_host_buffer_size
[phm
->obj_index
];
748 phr
->u
.d
.u
.stream_info
.buffer_size
=
749 phm
->u
.d
.u
.buffer
.buffer_size
;
751 if (phw
->outstream_host_buffer_size
[phm
->obj_index
] ==
752 phm
->u
.d
.u
.buffer
.buffer_size
) {
753 /* Same size, no action required */
757 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
759 hpios_locked_mem_free(&phw
->outstream_host_buffers
762 err
= hpios_locked_mem_alloc(&phw
->outstream_host_buffers
763 [phm
->obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
767 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
768 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
772 err
= hpios_locked_mem_get_phys_addr
773 (&phw
->outstream_host_buffers
[phm
->obj_index
],
774 &phm
->u
.d
.u
.buffer
.pci_address
);
775 /* get the phys addr into msg for single call alloc caller
776 * needs to do this for split alloc (or use the same message)
777 * return the phy address for split alloc in the respose too
779 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
780 phm
->u
.d
.u
.buffer
.pci_address
;
783 hpios_locked_mem_free(&phw
->outstream_host_buffers
785 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
786 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
791 if (command
== HPI_BUFFER_CMD_EXTERNAL
792 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
793 /* GRANT phase. Set up the BBM status, tell the DSP about
794 the buffer so it can start using BBM.
796 struct hpi_hostbuffer_status
*status
;
798 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
801 "Buffer size must be 2^N not %d\n",
802 phm
->u
.d
.u
.buffer
.buffer_size
);
803 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
806 phw
->outstream_host_buffer_size
[phm
->obj_index
] =
807 phm
->u
.d
.u
.buffer
.buffer_size
;
808 status
= &interface
->outstream_host_buffer_status
[phm
->
810 status
->samples_processed
= 0;
811 status
->stream_state
= HPI_STATE_STOPPED
;
812 status
->dSP_index
= 0;
813 status
->host_index
= status
->dSP_index
;
814 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
815 status
->auxiliary_data_available
= 0;
817 hw_message(pao
, phm
, phr
);
820 && hpios_locked_mem_valid(&phw
->
821 outstream_host_buffers
[phm
->obj_index
])) {
822 hpios_locked_mem_free(&phw
->outstream_host_buffers
824 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
829 static void outstream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
830 struct hpi_message
*phm
, struct hpi_response
*phr
)
832 struct hpi_hw_obj
*phw
= pao
->priv
;
833 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
834 struct hpi_hostbuffer_status
*status
;
837 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
839 if (hpios_locked_mem_get_virt_addr(&phw
->
840 outstream_host_buffers
[phm
->obj_index
],
841 (void *)&p_bbm_data
)) {
842 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
845 status
= &interface
->outstream_host_buffer_status
[phm
->
847 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
848 HPI_OSTREAM_HOSTBUFFER_GET_INFO
, 0);
849 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
850 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
852 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
853 HPI_OSTREAM_HOSTBUFFER_GET_INFO
,
854 HPI_ERROR_INVALID_OPERATION
);
858 static void outstream_host_buffer_free(struct hpi_adapter_obj
*pao
,
859 struct hpi_message
*phm
, struct hpi_response
*phr
)
861 struct hpi_hw_obj
*phw
= pao
->priv
;
862 u32 command
= phm
->u
.d
.u
.buffer
.command
;
864 if (phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
865 if (command
== HPI_BUFFER_CMD_EXTERNAL
866 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
867 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
868 hw_message(pao
, phm
, phr
);
869 /* Tell adapter to stop using the host buffer. */
871 if (command
== HPI_BUFFER_CMD_EXTERNAL
872 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
873 hpios_locked_mem_free(&phw
->outstream_host_buffers
876 /* Should HPI_ERROR_INVALID_OPERATION be returned
877 if no host buffer is allocated? */
879 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
880 HPI_OSTREAM_HOSTBUFFER_FREE
, 0);
884 static u32
outstream_get_space_available(struct hpi_hostbuffer_status
*status
)
886 return status
->size_in_bytes
- (status
->host_index
-
890 static void outstream_write(struct hpi_adapter_obj
*pao
,
891 struct hpi_message
*phm
, struct hpi_response
*phr
)
893 struct hpi_hw_obj
*phw
= pao
->priv
;
894 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
895 struct hpi_hostbuffer_status
*status
;
898 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
899 /* there is no BBM buffer, write via message */
900 hw_message(pao
, phm
, phr
);
904 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
905 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
907 space_available
= outstream_get_space_available(status
);
908 if (space_available
< phm
->u
.d
.u
.data
.data_size
) {
909 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
913 /* HostBuffers is used to indicate host buffer is internally allocated.
914 otherwise, assumed external, data written externally */
915 if (phm
->u
.d
.u
.data
.pb_data
916 && hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
920 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
922 if (hpios_locked_mem_get_virt_addr(&phw
->
923 outstream_host_buffers
[phm
->obj_index
],
924 (void *)&p_bbm_data
)) {
925 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
930 or enough to fit from current to end of BBM buffer */
932 min(phm
->u
.d
.u
.data
.data_size
,
933 status
->size_in_bytes
-
934 (status
->host_index
& (status
->size_in_bytes
- 1)));
937 (status
->host_index
& (status
->size_in_bytes
- 1)),
938 p_app_data
, l_first_write
);
939 /* remaining data if any */
940 memcpy(p_bbm_data
, p_app_data
+ l_first_write
,
941 phm
->u
.d
.u
.data
.data_size
- l_first_write
);
945 * This version relies on the DSP code triggering an OStream buffer
946 * update immediately following a SET_FORMAT call. The host has
947 * already written data into the BBM buffer, but the DSP won't know
948 * about it until dwHostIndex is adjusted.
950 if (phw
->flag_outstream_just_reset
[phm
->obj_index
]) {
951 /* Format can only change after reset. Must tell DSP. */
952 u16 function
= phm
->function
;
953 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 0;
954 phm
->function
= HPI_OSTREAM_SET_FORMAT
;
955 hw_message(pao
, phm
, phr
); /* send the format to the DSP */
956 phm
->function
= function
;
961 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
964 static void outstream_get_info(struct hpi_adapter_obj
*pao
,
965 struct hpi_message
*phm
, struct hpi_response
*phr
)
967 struct hpi_hw_obj
*phw
= pao
->priv
;
968 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
969 struct hpi_hostbuffer_status
*status
;
971 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
972 hw_message(pao
, phm
, phr
);
976 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
978 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
980 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
981 phr
->u
.d
.u
.stream_info
.samples_transferred
=
982 status
->samples_processed
;
983 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
984 phr
->u
.d
.u
.stream_info
.data_available
=
985 status
->size_in_bytes
- outstream_get_space_available(status
);
986 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
987 status
->auxiliary_data_available
;
990 static void outstream_start(struct hpi_adapter_obj
*pao
,
991 struct hpi_message
*phm
, struct hpi_response
*phr
)
993 hw_message(pao
, phm
, phr
);
996 static void outstream_reset(struct hpi_adapter_obj
*pao
,
997 struct hpi_message
*phm
, struct hpi_response
*phr
)
999 struct hpi_hw_obj
*phw
= pao
->priv
;
1000 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 1;
1001 hw_message(pao
, phm
, phr
);
1004 static void outstream_open(struct hpi_adapter_obj
*pao
,
1005 struct hpi_message
*phm
, struct hpi_response
*phr
)
1007 outstream_reset(pao
, phm
, phr
);
1010 /*****************************************************************************/
1011 /* InStream Host buffer functions */
1013 static void instream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
1014 struct hpi_message
*phm
, struct hpi_response
*phr
)
1017 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1018 struct hpi_hw_obj
*phw
= pao
->priv
;
1019 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1021 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1023 if (command
== HPI_BUFFER_CMD_EXTERNAL
1024 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
1026 phm
->u
.d
.u
.buffer
.buffer_size
=
1027 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
1028 phr
->u
.d
.u
.stream_info
.data_available
=
1029 phw
->instream_host_buffer_size
[phm
->obj_index
];
1030 phr
->u
.d
.u
.stream_info
.buffer_size
=
1031 phm
->u
.d
.u
.buffer
.buffer_size
;
1033 if (phw
->instream_host_buffer_size
[phm
->obj_index
] ==
1034 phm
->u
.d
.u
.buffer
.buffer_size
) {
1035 /* Same size, no action required */
1039 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1041 hpios_locked_mem_free(&phw
->instream_host_buffers
1044 err
= hpios_locked_mem_alloc(&phw
->instream_host_buffers
[phm
->
1045 obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
1049 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1050 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1054 err
= hpios_locked_mem_get_phys_addr
1055 (&phw
->instream_host_buffers
[phm
->obj_index
],
1056 &phm
->u
.d
.u
.buffer
.pci_address
);
1057 /* get the phys addr into msg for single call alloc. Caller
1058 needs to do this for split alloc so return the phy address */
1059 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1060 phm
->u
.d
.u
.buffer
.pci_address
;
1062 hpios_locked_mem_free(&phw
->instream_host_buffers
1064 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1065 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
1070 if (command
== HPI_BUFFER_CMD_EXTERNAL
1071 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
1072 struct hpi_hostbuffer_status
*status
;
1074 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
1076 HPI_DEBUG_LOG(ERROR
,
1077 "Buffer size must be 2^N not %d\n",
1078 phm
->u
.d
.u
.buffer
.buffer_size
);
1079 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1083 phw
->instream_host_buffer_size
[phm
->obj_index
] =
1084 phm
->u
.d
.u
.buffer
.buffer_size
;
1085 status
= &interface
->instream_host_buffer_status
[phm
->
1087 status
->samples_processed
= 0;
1088 status
->stream_state
= HPI_STATE_STOPPED
;
1089 status
->dSP_index
= 0;
1090 status
->host_index
= status
->dSP_index
;
1091 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
1092 status
->auxiliary_data_available
= 0;
1094 hw_message(pao
, phm
, phr
);
1097 && hpios_locked_mem_valid(&phw
->
1098 instream_host_buffers
[phm
->obj_index
])) {
1099 hpios_locked_mem_free(&phw
->instream_host_buffers
1101 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1106 static void instream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
1107 struct hpi_message
*phm
, struct hpi_response
*phr
)
1109 struct hpi_hw_obj
*phw
= pao
->priv
;
1110 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1111 struct hpi_hostbuffer_status
*status
;
1114 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1116 if (hpios_locked_mem_get_virt_addr(&phw
->
1117 instream_host_buffers
[phm
->obj_index
],
1118 (void *)&p_bbm_data
)) {
1119 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1122 status
= &interface
->instream_host_buffer_status
[phm
->
1124 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1125 HPI_ISTREAM_HOSTBUFFER_GET_INFO
, 0);
1126 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
1127 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
1129 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1130 HPI_ISTREAM_HOSTBUFFER_GET_INFO
,
1131 HPI_ERROR_INVALID_OPERATION
);
1135 static void instream_host_buffer_free(struct hpi_adapter_obj
*pao
,
1136 struct hpi_message
*phm
, struct hpi_response
*phr
)
1138 struct hpi_hw_obj
*phw
= pao
->priv
;
1139 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1141 if (phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1142 if (command
== HPI_BUFFER_CMD_EXTERNAL
1143 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
1144 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1145 hw_message(pao
, phm
, phr
);
1148 if (command
== HPI_BUFFER_CMD_EXTERNAL
1149 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
1150 hpios_locked_mem_free(&phw
->instream_host_buffers
1154 /* Should HPI_ERROR_INVALID_OPERATION be returned
1155 if no host buffer is allocated? */
1156 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1157 HPI_ISTREAM_HOSTBUFFER_FREE
, 0);
1163 static void instream_start(struct hpi_adapter_obj
*pao
,
1164 struct hpi_message
*phm
, struct hpi_response
*phr
)
1166 hw_message(pao
, phm
, phr
);
1169 static u32
instream_get_bytes_available(struct hpi_hostbuffer_status
*status
)
1171 return status
->dSP_index
- status
->host_index
;
1174 static void instream_read(struct hpi_adapter_obj
*pao
,
1175 struct hpi_message
*phm
, struct hpi_response
*phr
)
1177 struct hpi_hw_obj
*phw
= pao
->priv
;
1178 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1179 struct hpi_hostbuffer_status
*status
;
1183 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
1185 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1186 hw_message(pao
, phm
, phr
);
1189 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1191 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1192 data_available
= instream_get_bytes_available(status
);
1193 if (data_available
< phm
->u
.d
.u
.data
.data_size
) {
1194 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1198 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1200 if (hpios_locked_mem_get_virt_addr(&phw
->
1201 instream_host_buffers
[phm
->obj_index
],
1202 (void *)&p_bbm_data
)) {
1203 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1208 or enough to fit from current to end of BBM buffer */
1210 min(phm
->u
.d
.u
.data
.data_size
,
1211 status
->size_in_bytes
-
1212 (status
->host_index
& (status
->size_in_bytes
- 1)));
1216 (status
->host_index
& (status
->size_in_bytes
- 1)),
1218 /* remaining data if any */
1219 memcpy(p_app_data
+ l_first_read
, p_bbm_data
,
1220 phm
->u
.d
.u
.data
.data_size
- l_first_read
);
1222 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
1225 static void instream_get_info(struct hpi_adapter_obj
*pao
,
1226 struct hpi_message
*phm
, struct hpi_response
*phr
)
1228 struct hpi_hw_obj
*phw
= pao
->priv
;
1229 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1230 struct hpi_hostbuffer_status
*status
;
1231 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1232 hw_message(pao
, phm
, phr
);
1236 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1238 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1240 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
1241 phr
->u
.d
.u
.stream_info
.samples_transferred
=
1242 status
->samples_processed
;
1243 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
1244 phr
->u
.d
.u
.stream_info
.data_available
=
1245 instream_get_bytes_available(status
);
1246 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1247 status
->auxiliary_data_available
;
1250 /*****************************************************************************/
1252 #define HPI6205_MAX_FILES_TO_LOAD 2
1254 static u16
adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
1255 u32
*pos_error_code
)
1257 struct hpi_hw_obj
*phw
= pao
->priv
;
1258 struct dsp_code dsp_code
;
1259 u16 boot_code_id
[HPI6205_MAX_FILES_TO_LOAD
];
1264 boot_code_id
[0] = HPI_ADAPTER_ASI(0x6205);
1266 boot_code_id
[1] = pao
->pci
.pci_dev
->subsystem_device
;
1267 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id
[1]);
1269 /* fix up cases where bootcode id[1] != subsys id */
1270 switch (boot_code_id
[1]) {
1271 case HPI_ADAPTER_FAMILY_ASI(0x5000):
1272 boot_code_id
[0] = boot_code_id
[1];
1273 boot_code_id
[1] = 0;
1275 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1276 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1277 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1278 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
1280 case HPI_ADAPTER_FAMILY_ASI(0x5500):
1281 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1282 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1283 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
1285 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1286 boot_code_id
[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
1292 /* reset DSP by writing a 1 to the WARMRESET bit */
1293 temp
= C6205_HDCR_WARMRESET
;
1294 iowrite32(temp
, phw
->prHDCR
);
1295 hpios_delay_micro_seconds(1000);
1297 /* check that PCI i/f was configured by EEPROM */
1298 temp
= ioread32(phw
->prHSR
);
1299 if ((temp
& (C6205_HSR_CFGERR
| C6205_HSR_EEREAD
)) !=
1301 return HPI6205_ERROR_6205_EEPROM
;
1303 /* disable PINTA interrupt */
1304 iowrite32(temp
, phw
->prHSR
);
1306 /* check control register reports PCI boot mode */
1307 temp
= ioread32(phw
->prHDCR
);
1308 if (!(temp
& C6205_HDCR_PCIBOOT
))
1309 return HPI6205_ERROR_6205_REG
;
1311 /* try writing a few numbers to the DSP page register */
1312 /* and reading them back. */
1314 iowrite32(temp
, phw
->prDSPP
);
1315 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1316 return HPI6205_ERROR_6205_DSPPAGE
;
1318 iowrite32(temp
, phw
->prDSPP
);
1319 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1320 return HPI6205_ERROR_6205_DSPPAGE
;
1322 iowrite32(temp
, phw
->prDSPP
);
1323 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1324 return HPI6205_ERROR_6205_DSPPAGE
;
1325 /* reset DSP page to the correct number */
1327 iowrite32(temp
, phw
->prDSPP
);
1328 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1329 return HPI6205_ERROR_6205_DSPPAGE
;
1332 /* release 6713 from reset before 6205 is bootloaded.
1333 This ensures that the EMIF is inactive,
1334 and the 6713 HPI gets the correct bootmode etc
1336 if (boot_code_id
[1] != 0) {
1337 /* DSP 1 is a C6713 */
1338 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1339 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002202);
1340 hpios_delay_micro_seconds(100);
1341 /* Reset the 6713 #1 - revB */
1342 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
1344 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1345 boot_loader_read_mem32(pao
, 0, 0);
1347 hpios_delay_micro_seconds(100);
1348 /* Release C6713 from reset - revB */
1349 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 4);
1350 hpios_delay_micro_seconds(100);
1353 for (dsp
= 0; dsp
< HPI6205_MAX_FILES_TO_LOAD
; dsp
++) {
1354 /* is there a DSP to load? */
1355 if (boot_code_id
[dsp
] == 0)
1358 err
= boot_loader_config_emif(pao
, dsp
);
1362 err
= boot_loader_test_internal_memory(pao
, dsp
);
1366 err
= boot_loader_test_external_memory(pao
, dsp
);
1370 err
= boot_loader_test_pld(pao
, dsp
);
1374 /* write the DSP code down into the DSPs memory */
1375 dsp_code
.ps_dev
= pao
->pci
.pci_dev
;
1376 err
= hpi_dsp_code_open(boot_code_id
[dsp
], &dsp_code
,
1387 err
= hpi_dsp_code_read_word(&dsp_code
, &length
);
1390 if (length
== 0xFFFFFFFF)
1391 break; /* end of code */
1393 err
= hpi_dsp_code_read_word(&dsp_code
, &address
);
1396 err
= hpi_dsp_code_read_word(&dsp_code
, &type
);
1399 err
= hpi_dsp_code_read_block(length
, &dsp_code
,
1403 for (i
= 0; i
< (int)length
; i
++) {
1404 boot_loader_write_mem32(pao
, dsp
, address
,
1406 /* dummy read every 4 words */
1407 /* for 6205 advisory 1.4.4 */
1409 boot_loader_read_mem32(pao
, dsp
,
1417 hpi_dsp_code_close(&dsp_code
);
1422 hpi_dsp_code_rewind(&dsp_code
);
1430 hpi_dsp_code_read_word(&dsp_code
, &length
);
1431 if (length
== 0xFFFFFFFF)
1432 break; /* end of code */
1434 hpi_dsp_code_read_word(&dsp_code
, &address
);
1435 hpi_dsp_code_read_word(&dsp_code
, &type
);
1436 hpi_dsp_code_read_block(length
, &dsp_code
, &pcode
);
1438 for (i
= 0; i
< (int)length
; i
++) {
1439 data
= boot_loader_read_mem32(pao
, dsp
,
1441 if (data
!= *pcode
) {
1451 hpi_dsp_code_close(&dsp_code
);
1456 /* After bootloading all DSPs, start DSP0 running
1457 * The DSP0 code will handle starting and synchronizing with its slaves
1459 if (phw
->p_interface_buffer
) {
1460 /* we need to tell the card the physical PCI address */
1461 u32 physicalPC_iaddress
;
1462 struct bus_master_interface
*interface
=
1463 phw
->p_interface_buffer
;
1464 u32 host_mailbox_address_on_dsp
;
1465 u32 physicalPC_iaddress_verify
= 0;
1467 /* set ack so we know when DSP is ready to go */
1468 /* (dwDspAck will be changed to HIF_RESET) */
1469 interface
->dsp_ack
= H620_HIF_UNKNOWN
;
1470 wmb(); /* ensure ack is written before dsp writes back */
1472 err
= hpios_locked_mem_get_phys_addr(&phw
->h_locked_mem
,
1473 &physicalPC_iaddress
);
1475 /* locate the host mailbox on the DSP. */
1476 host_mailbox_address_on_dsp
= 0x80000000;
1477 while ((physicalPC_iaddress
!= physicalPC_iaddress_verify
)
1479 boot_loader_write_mem32(pao
, 0,
1480 host_mailbox_address_on_dsp
,
1481 physicalPC_iaddress
);
1482 physicalPC_iaddress_verify
=
1483 boot_loader_read_mem32(pao
, 0,
1484 host_mailbox_address_on_dsp
);
1487 HPI_DEBUG_LOG(DEBUG
, "starting DS_ps running\n");
1488 /* enable interrupts */
1489 temp
= ioread32(phw
->prHSR
);
1490 temp
&= ~(u32
)C6205_HSR_INTAM
;
1491 iowrite32(temp
, phw
->prHSR
);
1493 /* start code running... */
1494 temp
= ioread32(phw
->prHDCR
);
1495 temp
|= (u32
)C6205_HDCR_DSPINT
;
1496 iowrite32(temp
, phw
->prHDCR
);
1498 /* give the DSP 10ms to start up */
1499 hpios_delay_micro_seconds(10000);
1504 /*****************************************************************************/
1505 /* Bootloader utility functions */
1507 static u32
boot_loader_read_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
1510 struct hpi_hw_obj
*phw
= pao
->priv
;
1512 __iomem u32
*p_data
;
1514 if (dsp_index
== 0) {
1515 /* DSP 0 is always C6205 */
1516 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1517 /* BAR1 register access */
1518 p_data
= pao
->pci
.ap_mem_base
[1] +
1519 (address
& 0x007fffff) /
1520 sizeof(*pao
->pci
.ap_mem_base
[1]);
1521 /* HPI_DEBUG_LOG(WARNING,
1522 "BAR1 access %08x\n", dwAddress); */
1524 u32 dw4M_page
= address
>> 22L;
1525 if (dw4M_page
!= phw
->dsp_page
) {
1526 phw
->dsp_page
= dw4M_page
;
1528 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1531 address
&= 0x3fffff; /* address within 4M page */
1532 /* BAR0 memory access */
1533 p_data
= pao
->pci
.ap_mem_base
[0] +
1534 address
/ sizeof(u32
);
1536 data
= ioread32(p_data
);
1537 } else if (dsp_index
== 1) {
1538 /* DSP 1 is a C6713 */
1540 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1541 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1542 lsb
= boot_loader_read_mem32(pao
, 0, HPIDL_ADDR
);
1543 data
= boot_loader_read_mem32(pao
, 0, HPIDH_ADDR
);
1544 data
= (data
<< 16) | (lsb
& 0xFFFF);
1549 static void boot_loader_write_mem32(struct hpi_adapter_obj
*pao
,
1550 int dsp_index
, u32 address
, u32 data
)
1552 struct hpi_hw_obj
*phw
= pao
->priv
;
1553 __iomem u32
*p_data
;
1554 /* u32 dwVerifyData=0; */
1556 if (dsp_index
== 0) {
1557 /* DSP 0 is always C6205 */
1558 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1559 /* BAR1 - DSP register access using */
1560 /* Non-prefetchable PCI access */
1561 p_data
= pao
->pci
.ap_mem_base
[1] +
1562 (address
& 0x007fffff) /
1563 sizeof(*pao
->pci
.ap_mem_base
[1]);
1565 /* BAR0 access - all of DSP memory using */
1566 /* pre-fetchable PCI access */
1567 u32 dw4M_page
= address
>> 22L;
1568 if (dw4M_page
!= phw
->dsp_page
) {
1569 phw
->dsp_page
= dw4M_page
;
1571 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1574 address
&= 0x3fffff; /* address within 4M page */
1575 p_data
= pao
->pci
.ap_mem_base
[0] +
1576 address
/ sizeof(u32
);
1578 iowrite32(data
, p_data
);
1579 } else if (dsp_index
== 1) {
1580 /* DSP 1 is a C6713 */
1581 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1582 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1584 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1585 boot_loader_read_mem32(pao
, 0, 0);
1587 boot_loader_write_mem32(pao
, 0, HPIDL_ADDR
, data
);
1588 boot_loader_write_mem32(pao
, 0, HPIDH_ADDR
, data
>> 16);
1590 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1591 boot_loader_read_mem32(pao
, 0, 0);
1595 static u16
boot_loader_config_emif(struct hpi_adapter_obj
*pao
, int dsp_index
)
1597 if (dsp_index
== 0) {
1600 /* DSP 0 is always C6205 */
1603 /* memory map of C6205 */
1604 /* 00000000-0000FFFF 16Kx32 internal program */
1605 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1609 /* Global EMIF control */
1610 boot_loader_write_mem32(pao
, dsp_index
, 0x01800000, 0x3779);
1619 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1620 setting
= 0x00000030;
1621 boot_loader_write_mem32(pao
, dsp_index
, 0x01800008, setting
);
1622 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1624 return HPI6205_ERROR_DSP_EMIF
;
1626 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1627 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1628 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1629 /* WST should be 71, but 63 is max possible */
1631 (1L << WS_OFS
) | (63L << WST_OFS
) | (1L << WH_OFS
) |
1632 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1634 boot_loader_write_mem32(pao
, dsp_index
, 0x01800004, setting
);
1635 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1637 return HPI6205_ERROR_DSP_EMIF
;
1639 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1640 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1641 /* plenty of wait states */
1643 (1L << WS_OFS
) | (28L << WST_OFS
) | (1L << WH_OFS
) |
1644 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1646 boot_loader_write_mem32(pao
, dsp_index
, 0x01800010, setting
);
1647 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1649 return HPI6205_ERROR_DSP_EMIF
;
1651 /* EMIF CE3 setup - 32 bit async. */
1652 /* This is the PLD on the ASI5000 cards only */
1654 (1L << WS_OFS
) | (10L << WST_OFS
) | (1L << WH_OFS
) |
1655 (1L << RS_OFS
) | (10L << RST_OFS
) | (1L << RH_OFS
) |
1657 boot_loader_write_mem32(pao
, dsp_index
, 0x01800014, setting
);
1658 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1660 return HPI6205_ERROR_DSP_EMIF
;
1662 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1663 /* need to use this else DSP code crashes? */
1664 boot_loader_write_mem32(pao
, dsp_index
, 0x01800018,
1667 /* EMIF SDRAM Refresh Timing */
1668 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1669 boot_loader_write_mem32(pao
, dsp_index
, 0x0180001C,
1672 } else if (dsp_index
== 1) {
1673 /* test access to the C6713s HPI registers */
1674 u32 write_data
= 0, read_data
= 0, i
= 0;
1676 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1678 boot_loader_write_mem32(pao
, 0, HPICL_ADDR
, write_data
);
1679 boot_loader_write_mem32(pao
, 0, HPICH_ADDR
, write_data
);
1680 /* C67 HPI is on lower 16bits of 32bit EMIF */
1682 0xFFF7 & boot_loader_read_mem32(pao
, 0, HPICL_ADDR
);
1683 if (write_data
!= read_data
) {
1684 HPI_DEBUG_LOG(ERROR
, "HPICL %x %x\n", write_data
,
1686 return HPI6205_ERROR_C6713_HPIC
;
1688 /* HPIA - walking ones test */
1690 for (i
= 0; i
< 32; i
++) {
1691 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
,
1693 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
,
1694 (write_data
>> 16));
1696 0xFFFF & boot_loader_read_mem32(pao
, 0,
1699 read_data
| ((0xFFFF &
1700 boot_loader_read_mem32(pao
, 0,
1703 if (read_data
!= write_data
) {
1704 HPI_DEBUG_LOG(ERROR
, "HPIA %x %x\n",
1705 write_data
, read_data
);
1706 return HPI6205_ERROR_C6713_HPIA
;
1708 write_data
= write_data
<< 1;
1712 * ** C6713 datasheet says we cannot program PLL from HPI,
1713 * and indeed if we try to set the PLL multiply from the HPI,
1714 * the PLL does not seem to lock, so we enable the PLL and
1715 * use the default multiply of x 7, which for a 27MHz clock
1716 * gives a DSP speed of 189MHz
1719 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0000);
1720 hpios_delay_micro_seconds(1000);
1721 /* EMIF = 189/3=63MHz */
1722 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C120, 0x8002);
1724 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C11C, 0x8001);
1726 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C118, 0x8000);
1727 hpios_delay_micro_seconds(1000);
1728 /* ** SGT test to take GPO3 high when we start the PLL */
1729 /* and low when the delay is completed */
1730 /* FSX0 <- '1' (GPO3) */
1731 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A0A);
1732 /* PLL not bypassed */
1733 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0001);
1734 hpios_delay_micro_seconds(1000);
1735 /* FSX0 <- '0' (GPO3) */
1736 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A02);
1738 /* 6205 EMIF CE1 resetup - 32 bit async. */
1739 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1740 boot_loader_write_mem32(pao
, 0, 0x01800004, /* CE1 */
1741 (1L << WS_OFS
) | (8L << WST_OFS
) | (1L << WH_OFS
) |
1742 (1L << RS_OFS
) | (12L << RST_OFS
) | (1L << RH_OFS
) |
1745 hpios_delay_micro_seconds(1000);
1747 /* check that we can read one of the PLL registers */
1748 /* PLL should not be bypassed! */
1749 if ((boot_loader_read_mem32(pao
, dsp_index
, 0x01B7C100) & 0xF)
1751 return HPI6205_ERROR_C6713_PLL
;
1753 /* setup C67x EMIF (note this is the only use of
1754 BAR1 via BootLoader_WriteMem32) */
1755 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_GCTL
,
1758 /* EMIF CE0 setup - 2Mx32 Sync DRAM
1765 7..4 MTYPE 0011 Sync DRAM 32bits
1769 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_CE0
,
1772 /* EMIF SDRAM Extension
1774 31-21 0000b 0000b 000b
1775 20 WR2RD = 2cycles-1 = 1b
1777 19-18 WR2DEAC = 3cycle-1 = 10b
1778 17 WR2WR = 2cycle-1 = 1b
1779 16-15 R2WDQM = 4cycle-1 = 11b
1780 14-12 RD2WR = 6cycles-1 = 101b
1782 11-10 RD2DEAC = 4cycle-1 = 11b
1783 9 RD2RD = 2cycle-1 = 1b
1784 8-7 THZP = 3cycle-1 = 10b
1785 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
1786 4 TRRD = 2cycle = 0b (tRRD = 14ns)
1787 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
1788 1 CAS latency = 3cyc = 1b
1789 (for Micron 2M32-7 operating at 100MHz)
1791 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMEXT
,
1794 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
1797 29..28 SDRSZ 00b 11 row address pins
1799 27..26 SDCSZ 01b 8 column address pins
1800 25 RFEN 1b refersh enabled
1801 24 INIT 1b init SDRAM!
1803 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
1805 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
1807 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
1809 11..0 - 0000b 0000b 0000b
1811 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMCTL
,
1814 /* SDRAM refresh timing
1815 Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
1817 boot_loader_write_mem32(pao
, dsp_index
,
1818 C6713_EMIF_SDRAMTIMING
, 0x00000410);
1820 hpios_delay_micro_seconds(1000);
1821 } else if (dsp_index
== 2) {
1822 /* DSP 2 is a C6713 */
1828 static u16
boot_loader_test_memory(struct hpi_adapter_obj
*pao
, int dsp_index
,
1829 u32 start_address
, u32 length
)
1833 u32 test_data
= 0, data
= 0;
1837 /* for 1st word, test each bit in the 32bit word, */
1838 /* dwLength specifies number of 32bit words to test */
1839 /*for(i=0; i<dwLength; i++) */
1842 test_addr
= start_address
+ i
* 4;
1843 test_data
= 0x00000001;
1844 for (j
= 0; j
< 32; j
++) {
1845 boot_loader_write_mem32(pao
, dsp_index
, test_addr
,
1847 data
= boot_loader_read_mem32(pao
, dsp_index
,
1849 if (data
!= test_data
) {
1850 HPI_DEBUG_LOG(VERBOSE
,
1851 "Memtest error details "
1852 "%08x %08x %08x %i\n", test_addr
,
1853 test_data
, data
, dsp_index
);
1854 return 1; /* error */
1856 test_data
= test_data
<< 1;
1860 /* for the next 100 locations test each location, leaving it as zero */
1861 /* write a zero to the next word in memory before we read */
1862 /* the previous write to make sure every memory location is unique */
1863 for (i
= 0; i
< 100; i
++) {
1864 test_addr
= start_address
+ i
* 4;
1865 test_data
= 0xA5A55A5A;
1866 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, test_data
);
1867 boot_loader_write_mem32(pao
, dsp_index
, test_addr
+ 4, 0);
1868 data
= boot_loader_read_mem32(pao
, dsp_index
, test_addr
);
1869 if (data
!= test_data
) {
1870 HPI_DEBUG_LOG(VERBOSE
,
1871 "Memtest error details "
1872 "%08x %08x %08x %i\n", test_addr
, test_data
,
1874 return 1; /* error */
1876 /* leave location as zero */
1877 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1880 /* zero out entire memory block */
1881 for (i
= 0; i
< length
; i
++) {
1882 test_addr
= start_address
+ i
* 4;
1883 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1888 static u16
boot_loader_test_internal_memory(struct hpi_adapter_obj
*pao
,
1892 if (dsp_index
== 0) {
1893 /* DSP 0 is a C6205 */
1895 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1899 err
= boot_loader_test_memory(pao
, dsp_index
,
1900 0x80000000, 0x10000);
1901 } else if (dsp_index
== 1) {
1902 /* DSP 1 is a C6713 */
1903 /* 192K internal mem */
1904 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1907 /* 64K internal mem / L2 cache */
1908 err
= boot_loader_test_memory(pao
, dsp_index
,
1909 0x00030000, 0x10000);
1913 return HPI6205_ERROR_DSP_INTMEM
;
1918 static u16
boot_loader_test_external_memory(struct hpi_adapter_obj
*pao
,
1921 u32 dRAM_start_address
= 0;
1924 if (dsp_index
== 0) {
1925 /* only test for SDRAM if an ASI5000 card */
1926 if (pao
->pci
.pci_dev
->subsystem_device
== 0x5000) {
1927 /* DSP 0 is always C6205 */
1928 dRAM_start_address
= 0x00400000;
1929 dRAM_size
= 0x200000;
1930 /*dwDRAMinc=1024; */
1933 } else if (dsp_index
== 1) {
1934 /* DSP 1 is a C6713 */
1935 dRAM_start_address
= 0x80000000;
1936 dRAM_size
= 0x200000;
1937 /*dwDRAMinc=1024; */
1940 if (boot_loader_test_memory(pao
, dsp_index
, dRAM_start_address
,
1942 return HPI6205_ERROR_DSP_EXTMEM
;
1946 static u16
boot_loader_test_pld(struct hpi_adapter_obj
*pao
, int dsp_index
)
1949 if (dsp_index
== 0) {
1950 /* only test for DSP0 PLD on ASI5000 card */
1951 if (pao
->pci
.pci_dev
->subsystem_device
== 0x5000) {
1952 /* PLD is located at CE3=0x03000000 */
1953 data
= boot_loader_read_mem32(pao
, dsp_index
,
1955 if ((data
& 0xF) != 0x5)
1956 return HPI6205_ERROR_DSP_PLD
;
1957 data
= boot_loader_read_mem32(pao
, dsp_index
,
1959 if ((data
& 0xF) != 0xA)
1960 return HPI6205_ERROR_DSP_PLD
;
1962 } else if (dsp_index
== 1) {
1963 /* DSP 1 is a C6713 */
1964 if (pao
->pci
.pci_dev
->subsystem_device
== 0x8700) {
1965 /* PLD is located at CE1=0x90000000 */
1966 data
= boot_loader_read_mem32(pao
, dsp_index
,
1968 if ((data
& 0xFF) != 0xAA)
1969 return HPI6205_ERROR_DSP_PLD
;
1971 boot_loader_write_mem32(pao
, dsp_index
, 0x90000000,
1978 /** Transfer data to or from DSP
1979 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
1981 static short hpi6205_transfer_data(struct hpi_adapter_obj
*pao
, u8
*p_data
,
1982 u32 data_size
, int operation
)
1984 struct hpi_hw_obj
*phw
= pao
->priv
;
1985 u32 data_transferred
= 0;
1988 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1991 return HPI_ERROR_INVALID_DATA_POINTER
;
1993 data_size
&= ~3L; /* round data_size down to nearest 4 bytes */
1995 /* make sure state is IDLE */
1996 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
))
1997 return HPI_ERROR_DSP_HARDWARE
;
1999 while (data_transferred
< data_size
) {
2000 u32 this_copy
= data_size
- data_transferred
;
2002 if (this_copy
> HPI6205_SIZEOF_DATA
)
2003 this_copy
= HPI6205_SIZEOF_DATA
;
2005 if (operation
== H620_HIF_SEND_DATA
)
2006 memcpy((void *)&interface
->u
.b_data
[0],
2007 &p_data
[data_transferred
], this_copy
);
2009 interface
->transfer_size_in_bytes
= this_copy
;
2011 /* DSP must change this back to nOperation */
2012 interface
->dsp_ack
= H620_HIF_IDLE
;
2013 send_dsp_command(phw
, operation
);
2015 temp2
= wait_dsp_ack(phw
, operation
, HPI6205_TIMEOUT
);
2016 HPI_DEBUG_LOG(DEBUG
, "spun %d times for data xfer of %d\n",
2017 HPI6205_TIMEOUT
- temp2
, this_copy
);
2021 HPI_DEBUG_LOG(ERROR
,
2022 "Timed out waiting for " "state %d got %d\n",
2023 operation
, interface
->dsp_ack
);
2027 if (operation
== H620_HIF_GET_DATA
)
2028 memcpy(&p_data
[data_transferred
],
2029 (void *)&interface
->u
.b_data
[0], this_copy
);
2031 data_transferred
+= this_copy
;
2033 if (interface
->dsp_ack
!= operation
)
2034 HPI_DEBUG_LOG(DEBUG
, "interface->dsp_ack=%d, expected %d\n",
2035 interface
->dsp_ack
, operation
);
2036 /* err=HPI_ERROR_DSP_HARDWARE; */
2038 send_dsp_command(phw
, H620_HIF_IDLE
);
2043 /* wait for up to timeout_us microseconds for the DSP
2044 to signal state by DMA into dwDspAck
2046 static int wait_dsp_ack(struct hpi_hw_obj
*phw
, int state
, int timeout_us
)
2048 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2049 int t
= timeout_us
/ 4;
2051 rmb(); /* ensure interface->dsp_ack is up to date */
2052 while ((interface
->dsp_ack
!= state
) && --t
) {
2053 hpios_delay_micro_seconds(4);
2054 rmb(); /* DSP changes dsp_ack by DMA */
2057 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2061 /* set the busmaster interface to cmd, then interrupt the DSP */
2062 static void send_dsp_command(struct hpi_hw_obj
*phw
, int cmd
)
2064 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2067 interface
->host_cmd
= cmd
;
2068 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2069 /* before we interrupt the DSP */
2070 r
= ioread32(phw
->prHDCR
);
2071 r
|= (u32
)C6205_HDCR_DSPINT
;
2072 iowrite32(r
, phw
->prHDCR
);
2073 r
&= ~(u32
)C6205_HDCR_DSPINT
;
2074 iowrite32(r
, phw
->prHDCR
);
2077 static unsigned int message_count
;
2079 static u16
message_response_sequence(struct hpi_adapter_obj
*pao
,
2080 struct hpi_message
*phm
, struct hpi_response
*phr
)
2082 u32 time_out
, time_out2
;
2083 struct hpi_hw_obj
*phw
= pao
->priv
;
2084 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2088 if (phm
->size
> sizeof(interface
->u
)) {
2089 phr
->error
= HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL
;
2090 phr
->specific_error
= sizeof(interface
->u
);
2091 phr
->size
= sizeof(struct hpi_response_header
);
2092 HPI_DEBUG_LOG(ERROR
,
2093 "message len %d too big for buffer %zd \n", phm
->size
,
2094 sizeof(interface
->u
));
2098 /* Assume buffer of type struct bus_master_interface
2099 is allocated "noncacheable" */
2101 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2102 HPI_DEBUG_LOG(DEBUG
, "timeout waiting for idle\n");
2103 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
;
2106 memcpy(&interface
->u
.message_buffer
, phm
, phm
->size
);
2107 /* signal we want a response */
2108 send_dsp_command(phw
, H620_HIF_GET_RESP
);
2110 time_out2
= wait_dsp_ack(phw
, H620_HIF_GET_RESP
, HPI6205_TIMEOUT
);
2113 HPI_DEBUG_LOG(ERROR
,
2114 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
2115 message_count
, interface
->dsp_ack
);
2117 HPI_DEBUG_LOG(VERBOSE
,
2118 "(%u) transition to GET_RESP after %u\n",
2119 message_count
, HPI6205_TIMEOUT
- time_out2
);
2121 /* spin waiting on HIF interrupt flag (end of msg process) */
2122 time_out
= HPI6205_TIMEOUT
;
2124 /* read the result */
2126 if (interface
->u
.response_buffer
.size
<= phr
->size
)
2127 memcpy(phr
, &interface
->u
.response_buffer
,
2128 interface
->u
.response_buffer
.size
);
2130 HPI_DEBUG_LOG(ERROR
,
2131 "response len %d too big for buffer %d\n",
2132 interface
->u
.response_buffer
.size
, phr
->size
);
2133 memcpy(phr
, &interface
->u
.response_buffer
,
2134 sizeof(struct hpi_response_header
));
2135 phr
->error
= HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL
;
2136 phr
->specific_error
=
2137 interface
->u
.response_buffer
.size
;
2138 phr
->size
= sizeof(struct hpi_response_header
);
2141 /* set interface back to idle */
2142 send_dsp_command(phw
, H620_HIF_IDLE
);
2144 if (!time_out
|| !time_out2
) {
2145 HPI_DEBUG_LOG(DEBUG
, "something timed out!\n");
2146 return HPI6205_ERROR_MSG_RESP_TIMEOUT
;
2148 /* special case for adapter close - */
2149 /* wait for the DSP to indicate it is idle */
2150 if (phm
->function
== HPI_ADAPTER_CLOSE
) {
2151 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2152 HPI_DEBUG_LOG(DEBUG
,
2153 "Timeout waiting for idle "
2154 "(on adapter_close)\n");
2155 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
;
2158 err
= hpi_validate_response(phm
, phr
);
2162 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
2163 struct hpi_response
*phr
)
2168 hpios_dsplock_lock(pao
);
2170 err
= message_response_sequence(pao
, phm
, phr
);
2172 /* maybe an error response */
2174 /* something failed in the HPI/DSP interface */
2175 if (err
>= HPI_ERROR_BACKEND_BASE
) {
2176 phr
->error
= HPI_ERROR_DSP_COMMUNICATION
;
2177 phr
->specific_error
= err
;
2184 /* just the header of the response is valid */
2185 phr
->size
= sizeof(struct hpi_response_header
);
2188 pao
->dsp_crashed
= 0;
2190 if (phr
->error
!= 0) /* something failed in the DSP */
2193 switch (phm
->function
) {
2194 case HPI_OSTREAM_WRITE
:
2195 case HPI_ISTREAM_ANC_WRITE
:
2196 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2197 phm
->u
.d
.u
.data
.data_size
, H620_HIF_SEND_DATA
);
2200 case HPI_ISTREAM_READ
:
2201 case HPI_OSTREAM_ANC_READ
:
2202 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2203 phm
->u
.d
.u
.data
.data_size
, H620_HIF_GET_DATA
);
2206 case HPI_CONTROL_SET_STATE
:
2207 if (phm
->object
== HPI_OBJ_CONTROLEX
2208 && phm
->u
.cx
.attribute
== HPI_COBRANET_SET_DATA
)
2209 err
= hpi6205_transfer_data(pao
,
2210 phm
->u
.cx
.u
.cobranet_bigdata
.pb_data
,
2211 phm
->u
.cx
.u
.cobranet_bigdata
.byte_count
,
2212 H620_HIF_SEND_DATA
);
2215 case HPI_CONTROL_GET_STATE
:
2216 if (phm
->object
== HPI_OBJ_CONTROLEX
2217 && phm
->u
.cx
.attribute
== HPI_COBRANET_GET_DATA
)
2218 err
= hpi6205_transfer_data(pao
,
2219 phm
->u
.cx
.u
.cobranet_bigdata
.pb_data
,
2220 phr
->u
.cx
.u
.cobranet_data
.byte_count
,
2227 hpios_dsplock_unlock(pao
);