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 ASI6200 series adapters.
20 These PCI bus adapters are based on the TI C6711 DSP.
23 void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
26 HIDE_PCI_ASSERTS to show the PCI asserts
27 PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
29 (C) Copyright AudioScience Inc. 1998-2003
30 *******************************************************************************/
31 #define SOURCEFILE_NAME "hpi6000.c"
33 #include "hpi_internal.h"
34 #include "hpimsginit.h"
40 #define HPI_HIF_BASE (0x00000200) /* start of C67xx internal RAM */
41 #define HPI_HIF_ADDR(member) \
42 (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
43 #define HPI_HIF_ERROR_MASK 0x4000
45 /* HPI6000 specific error codes */
46 #define HPI6000_ERROR_BASE 900 /* not actually used anywhere */
48 /* operational/messaging errors */
49 #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
51 #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK 903
52 #define HPI6000_ERROR_MSG_GET_ADR 904
53 #define HPI6000_ERROR_RESP_GET_ADR 905
54 #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32 906
55 #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32 907
57 #define HPI6000_ERROR_CONTROL_CACHE_PARAMS 909
59 #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT 911
60 #define HPI6000_ERROR_SEND_DATA_ACK 912
61 #define HPI6000_ERROR_SEND_DATA_ADR 913
62 #define HPI6000_ERROR_SEND_DATA_TIMEOUT 914
63 #define HPI6000_ERROR_SEND_DATA_CMD 915
64 #define HPI6000_ERROR_SEND_DATA_WRITE 916
65 #define HPI6000_ERROR_SEND_DATA_IDLECMD 917
67 #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT 921
68 #define HPI6000_ERROR_GET_DATA_ACK 922
69 #define HPI6000_ERROR_GET_DATA_CMD 923
70 #define HPI6000_ERROR_GET_DATA_READ 924
71 #define HPI6000_ERROR_GET_DATA_IDLECMD 925
73 #define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN 951
74 #define HPI6000_ERROR_CONTROL_CACHE_READ 952
75 #define HPI6000_ERROR_CONTROL_CACHE_FLUSH 953
77 #define HPI6000_ERROR_MSG_RESP_GETRESPCMD 961
78 #define HPI6000_ERROR_MSG_RESP_IDLECMD 962
80 /* Initialisation/bootload errors */
81 #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
83 /* can't access PCI2040 */
84 #define HPI6000_ERROR_INIT_PCI2040 931
85 /* can't access DSP HPI i/f */
86 #define HPI6000_ERROR_INIT_DSPHPI 932
87 /* can't access internal DSP memory */
88 #define HPI6000_ERROR_INIT_DSPINTMEM 933
89 /* can't access SDRAM - test#1 */
90 #define HPI6000_ERROR_INIT_SDRAM1 934
91 /* can't access SDRAM - test#2 */
92 #define HPI6000_ERROR_INIT_SDRAM2 935
94 #define HPI6000_ERROR_INIT_VERIFY 938
96 #define HPI6000_ERROR_INIT_NOACK 939
98 #define HPI6000_ERROR_INIT_PLDTEST1 941
99 #define HPI6000_ERROR_INIT_PLDTEST2 942
103 #define HIDE_PCI_ASSERTS
106 /* for PCI2040 i/f chip */
107 /* HPI CSR registers */
108 /* word offsets from CSR base */
109 /* use when io addresses defined as u32 * */
111 #define INTERRUPT_EVENT_SET 0
112 #define INTERRUPT_EVENT_CLEAR 1
113 #define INTERRUPT_MASK_SET 2
114 #define INTERRUPT_MASK_CLEAR 3
115 #define HPI_ERROR_REPORT 4
117 #define HPI_DATA_WIDTH 6
120 /* HPI registers, spaced 8K bytes = 2K words apart */
121 #define DSP_SPACING 0x800
123 #define CONTROL 0x0000
124 #define ADDRESS 0x0200
125 #define DATA_AUTOINC 0x0400
128 #define TIMEOUT 500000
131 __iomem u32
*prHPI_control
;
132 __iomem u32
*prHPI_address
;
133 __iomem u32
*prHPI_data
;
134 __iomem u32
*prHPI_data_auto_inc
;
135 char c_dsp_rev
; /*A, B */
136 u32 control_cache_address_on_dsp
;
137 u32 control_cache_length_on_dsp
;
138 struct hpi_adapter_obj
*pa_parent_adapter
;
142 __iomem u32
*dw2040_HPICSR
;
143 __iomem u32
*dw2040_HPIDSP
;
146 struct dsp_obj ado
[MAX_DSPS
];
148 u32 message_buffer_address_on_dsp
;
149 u32 response_buffer_address_on_dsp
;
150 u32 pCI2040HPI_error_count
;
152 struct hpi_control_cache_single control_cache
[HPI_NMIXER_CONTROLS
];
153 struct hpi_control_cache
*p_cache
;
156 static u16
hpi6000_dsp_block_write32(struct hpi_adapter_obj
*pao
,
157 u16 dsp_index
, u32 hpi_address
, u32
*source
, u32 count
);
158 static u16
hpi6000_dsp_block_read32(struct hpi_adapter_obj
*pao
,
159 u16 dsp_index
, u32 hpi_address
, u32
*dest
, u32 count
);
161 static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
162 u32
*pos_error_code
);
163 static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj
*pao
,
168 static short hpi6000_update_control_cache(struct hpi_adapter_obj
*pao
,
169 struct hpi_message
*phm
);
170 static short hpi6000_message_response_sequence(struct hpi_adapter_obj
*pao
,
171 u16 dsp_index
, struct hpi_message
*phm
, struct hpi_response
*phr
);
173 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
174 struct hpi_response
*phr
);
176 static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
179 static short hpi6000_send_host_command(struct hpi_adapter_obj
*pao
,
180 u16 dsp_index
, u32 host_cmd
);
182 static void hpi6000_send_dsp_interrupt(struct dsp_obj
*pdo
);
184 static short hpi6000_send_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
185 struct hpi_message
*phm
, struct hpi_response
*phr
);
187 static short hpi6000_get_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
188 struct hpi_message
*phm
, struct hpi_response
*phr
);
190 static void hpi_write_word(struct dsp_obj
*pdo
, u32 address
, u32 data
);
192 static u32
hpi_read_word(struct dsp_obj
*pdo
, u32 address
);
194 static void hpi_write_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
197 static void hpi_read_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
200 static void subsys_create_adapter(struct hpi_message
*phm
,
201 struct hpi_response
*phr
);
203 static void subsys_delete_adapter(struct hpi_message
*phm
,
204 struct hpi_response
*phr
);
206 static void adapter_get_asserts(struct hpi_adapter_obj
*pao
,
207 struct hpi_message
*phm
, struct hpi_response
*phr
);
209 static short create_adapter_obj(struct hpi_adapter_obj
*pao
,
210 u32
*pos_error_code
);
212 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
);
216 static u16 gw_pci_read_asserts
; /* used to count PCI2040 errors */
217 static u16 gw_pci_write_asserts
; /* used to count PCI2040 errors */
219 static void subsys_message(struct hpi_message
*phm
, struct hpi_response
*phr
)
221 switch (phm
->function
) {
222 case HPI_SUBSYS_CREATE_ADAPTER
:
223 subsys_create_adapter(phm
, phr
);
225 case HPI_SUBSYS_DELETE_ADAPTER
:
226 subsys_delete_adapter(phm
, phr
);
229 phr
->error
= HPI_ERROR_INVALID_FUNC
;
234 static void control_message(struct hpi_adapter_obj
*pao
,
235 struct hpi_message
*phm
, struct hpi_response
*phr
)
237 switch (phm
->function
) {
238 case HPI_CONTROL_GET_STATE
:
239 if (pao
->has_control_cache
) {
241 err
= hpi6000_update_control_cache(pao
, phm
);
244 if (err
>= HPI_ERROR_BACKEND_BASE
) {
246 HPI_ERROR_CONTROL_CACHING
;
247 phr
->specific_error
= err
;
254 if (hpi_check_control_cache(((struct hpi_hw_obj
*)
255 pao
->priv
)->p_cache
, phm
,
259 hw_message(pao
, phm
, phr
);
261 case HPI_CONTROL_SET_STATE
:
262 hw_message(pao
, phm
, phr
);
263 hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj
*)pao
->
264 priv
)->p_cache
, phm
, phr
);
267 case HPI_CONTROL_GET_INFO
:
269 hw_message(pao
, phm
, phr
);
274 static void adapter_message(struct hpi_adapter_obj
*pao
,
275 struct hpi_message
*phm
, struct hpi_response
*phr
)
277 switch (phm
->function
) {
278 case HPI_ADAPTER_GET_ASSERT
:
279 adapter_get_asserts(pao
, phm
, phr
);
283 hw_message(pao
, phm
, phr
);
288 static void outstream_message(struct hpi_adapter_obj
*pao
,
289 struct hpi_message
*phm
, struct hpi_response
*phr
)
291 switch (phm
->function
) {
292 case HPI_OSTREAM_HOSTBUFFER_ALLOC
:
293 case HPI_OSTREAM_HOSTBUFFER_FREE
:
294 /* Don't let these messages go to the HW function because
295 * they're called without locking the spinlock.
296 * For the HPI6000 adapters the HW would return
297 * HPI_ERROR_INVALID_FUNC anyway.
299 phr
->error
= HPI_ERROR_INVALID_FUNC
;
302 hw_message(pao
, phm
, phr
);
307 static void instream_message(struct hpi_adapter_obj
*pao
,
308 struct hpi_message
*phm
, struct hpi_response
*phr
)
311 switch (phm
->function
) {
312 case HPI_ISTREAM_HOSTBUFFER_ALLOC
:
313 case HPI_ISTREAM_HOSTBUFFER_FREE
:
314 /* Don't let these messages go to the HW function because
315 * they're called without locking the spinlock.
316 * For the HPI6000 adapters the HW would return
317 * HPI_ERROR_INVALID_FUNC anyway.
319 phr
->error
= HPI_ERROR_INVALID_FUNC
;
322 hw_message(pao
, phm
, phr
);
327 /************************************************************************/
329 * Entry point from HPIMAN
330 * All calls to the HPI start here
332 void HPI_6000(struct hpi_message
*phm
, struct hpi_response
*phr
)
334 struct hpi_adapter_obj
*pao
= NULL
;
336 /* subsytem messages get executed by every HPI. */
337 /* All other messages are ignored unless the adapter index matches */
338 /* an adapter in the HPI */
339 /*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */
341 /* if Dsp has crashed then do not communicate with it any more */
342 if (phm
->object
!= HPI_OBJ_SUBSYSTEM
) {
343 pao
= hpi_find_adapter(phm
->adapter_index
);
346 " %d,%d refused, for another HPI?\n",
347 phm
->object
, phm
->function
);
351 if (pao
->dsp_crashed
>= 10) {
352 hpi_init_response(phr
, phm
->object
, phm
->function
,
353 HPI_ERROR_DSP_HARDWARE
);
354 HPI_DEBUG_LOG(DEBUG
, " %d,%d dsp crashed.\n",
355 phm
->object
, phm
->function
);
359 /* Init default response including the size field */
360 if (phm
->function
!= HPI_SUBSYS_CREATE_ADAPTER
)
361 hpi_init_response(phr
, phm
->object
, phm
->function
,
362 HPI_ERROR_PROCESSING_MESSAGE
);
365 case HPI_TYPE_MESSAGE
:
366 switch (phm
->object
) {
367 case HPI_OBJ_SUBSYSTEM
:
368 subsys_message(phm
, phr
);
371 case HPI_OBJ_ADAPTER
:
373 sizeof(struct hpi_response_header
) +
374 sizeof(struct hpi_adapter_res
);
375 adapter_message(pao
, phm
, phr
);
378 case HPI_OBJ_CONTROL
:
379 control_message(pao
, phm
, phr
);
382 case HPI_OBJ_OSTREAM
:
383 outstream_message(pao
, phm
, phr
);
386 case HPI_OBJ_ISTREAM
:
387 instream_message(pao
, phm
, phr
);
391 hw_message(pao
, phm
, phr
);
397 phr
->error
= HPI_ERROR_INVALID_TYPE
;
402 /************************************************************************/
405 /* create an adapter object and initialise it based on resource information
406 * passed in in the message
407 * NOTE - you cannot use this function AND the FindAdapters function at the
408 * same time, the application must use only one of them to get the adapters
410 static void subsys_create_adapter(struct hpi_message
*phm
,
411 struct hpi_response
*phr
)
413 /* create temp adapter obj, because we don't know what index yet */
414 struct hpi_adapter_obj ao
;
415 struct hpi_adapter_obj
*pao
;
420 HPI_DEBUG_LOG(VERBOSE
, "subsys_create_adapter\n");
422 memset(&ao
, 0, sizeof(ao
));
424 ao
.priv
= kzalloc(sizeof(struct hpi_hw_obj
), GFP_KERNEL
);
426 HPI_DEBUG_LOG(ERROR
, "cant get mem for adapter object\n");
427 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
431 /* create the adapter object based on the resource information */
432 ao
.pci
= *phm
->u
.s
.resource
.r
.pci
;
434 err
= create_adapter_obj(&ao
, &os_error_code
);
436 delete_adapter_obj(&ao
);
437 if (err
>= HPI_ERROR_BACKEND_BASE
) {
438 phr
->error
= HPI_ERROR_DSP_BOOTLOAD
;
439 phr
->specific_error
= err
;
444 phr
->u
.s
.data
= os_error_code
;
447 /* need to update paParentAdapter */
448 pao
= hpi_find_adapter(ao
.index
);
450 /* We just added this adapter, why can't we find it!? */
451 HPI_DEBUG_LOG(ERROR
, "lost adapter after boot\n");
452 phr
->error
= HPI_ERROR_BAD_ADAPTER
;
456 for (dsp_index
= 0; dsp_index
< MAX_DSPS
; dsp_index
++) {
457 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
458 phw
->ado
[dsp_index
].pa_parent_adapter
= pao
;
461 phr
->u
.s
.adapter_type
= ao
.adapter_type
;
462 phr
->u
.s
.adapter_index
= ao
.index
;
466 static void subsys_delete_adapter(struct hpi_message
*phm
,
467 struct hpi_response
*phr
)
469 struct hpi_adapter_obj
*pao
= NULL
;
471 pao
= hpi_find_adapter(phm
->obj_index
);
475 delete_adapter_obj(pao
);
476 hpi_delete_adapter(pao
);
480 /* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
481 static short create_adapter_obj(struct hpi_adapter_obj
*pao
,
484 short boot_error
= 0;
486 u32 control_cache_size
= 0;
487 u32 control_cache_count
= 0;
488 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
490 /* The PCI2040 has the following address map */
491 /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
492 /* BAR1 - 32K = HPI registers on DSP */
493 phw
->dw2040_HPICSR
= pao
->pci
.ap_mem_base
[0];
494 phw
->dw2040_HPIDSP
= pao
->pci
.ap_mem_base
[1];
495 HPI_DEBUG_LOG(VERBOSE
, "csr %p, dsp %p\n", phw
->dw2040_HPICSR
,
498 /* set addresses for the possible DSP HPI interfaces */
499 for (dsp_index
= 0; dsp_index
< MAX_DSPS
; dsp_index
++) {
500 phw
->ado
[dsp_index
].prHPI_control
=
501 phw
->dw2040_HPIDSP
+ (CONTROL
+
502 DSP_SPACING
* dsp_index
);
504 phw
->ado
[dsp_index
].prHPI_address
=
505 phw
->dw2040_HPIDSP
+ (ADDRESS
+
506 DSP_SPACING
* dsp_index
);
507 phw
->ado
[dsp_index
].prHPI_data
=
508 phw
->dw2040_HPIDSP
+ (DATA
+ DSP_SPACING
* dsp_index
);
510 phw
->ado
[dsp_index
].prHPI_data_auto_inc
=
511 phw
->dw2040_HPIDSP
+ (DATA_AUTOINC
+
512 DSP_SPACING
* dsp_index
);
514 HPI_DEBUG_LOG(VERBOSE
, "ctl %p, adr %p, dat %p, dat++ %p\n",
515 phw
->ado
[dsp_index
].prHPI_control
,
516 phw
->ado
[dsp_index
].prHPI_address
,
517 phw
->ado
[dsp_index
].prHPI_data
,
518 phw
->ado
[dsp_index
].prHPI_data_auto_inc
);
520 phw
->ado
[dsp_index
].pa_parent_adapter
= pao
;
523 phw
->pCI2040HPI_error_count
= 0;
524 pao
->has_control_cache
= 0;
526 /* Set the default number of DSPs on this card */
527 /* This is (conditionally) adjusted after bootloading */
528 /* of the first DSP in the bootload section. */
531 boot_error
= hpi6000_adapter_boot_load_dsp(pao
, pos_error_code
);
535 HPI_DEBUG_LOG(INFO
, "bootload DSP OK\n");
537 phw
->message_buffer_address_on_dsp
= 0L;
538 phw
->response_buffer_address_on_dsp
= 0L;
540 /* get info about the adapter by asking the adapter */
541 /* send a HPI_ADAPTER_GET_INFO message */
543 struct hpi_message hm
;
544 struct hpi_response hr0
; /* response from DSP 0 */
545 struct hpi_response hr1
; /* response from DSP 1 */
548 HPI_DEBUG_LOG(VERBOSE
, "send ADAPTER_GET_INFO\n");
549 memset(&hm
, 0, sizeof(hm
));
550 hm
.type
= HPI_TYPE_MESSAGE
;
551 hm
.size
= sizeof(struct hpi_message
);
552 hm
.object
= HPI_OBJ_ADAPTER
;
553 hm
.function
= HPI_ADAPTER_GET_INFO
;
554 hm
.adapter_index
= 0;
555 memset(&hr0
, 0, sizeof(hr0
));
556 memset(&hr1
, 0, sizeof(hr1
));
557 hr0
.size
= sizeof(hr0
);
558 hr1
.size
= sizeof(hr1
);
560 error
= hpi6000_message_response_sequence(pao
, 0, &hm
, &hr0
);
562 HPI_DEBUG_LOG(DEBUG
, "message error %d\n", hr0
.error
);
565 if (phw
->num_dsp
== 2) {
566 error
= hpi6000_message_response_sequence(pao
, 1, &hm
,
571 pao
->adapter_type
= hr0
.u
.ax
.info
.adapter_type
;
572 pao
->index
= hr0
.u
.ax
.info
.adapter_index
;
575 memset(&phw
->control_cache
[0], 0,
576 sizeof(struct hpi_control_cache_single
) *
577 HPI_NMIXER_CONTROLS
);
578 /* Read the control cache length to figure out if it is turned on */
580 hpi_read_word(&phw
->ado
[0],
581 HPI_HIF_ADDR(control_cache_size_in_bytes
));
582 if (control_cache_size
) {
583 control_cache_count
=
584 hpi_read_word(&phw
->ado
[0],
585 HPI_HIF_ADDR(control_cache_count
));
588 hpi_alloc_control_cache(control_cache_count
,
589 control_cache_size
, (unsigned char *)
590 &phw
->control_cache
[0]
593 pao
->has_control_cache
= 1;
596 HPI_DEBUG_LOG(DEBUG
, "get adapter info ASI%04X index %d\n",
597 pao
->adapter_type
, pao
->index
);
598 pao
->open
= 0; /* upon creation the adapter is closed */
601 phw
->p_cache
->adap_idx
= pao
->index
;
603 return hpi_add_adapter(pao
);
606 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
)
608 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
610 if (pao
->has_control_cache
)
611 hpi_free_control_cache(phw
->p_cache
);
613 /* reset DSPs on adapter */
614 iowrite32(0x0003000F, phw
->dw2040_HPICSR
+ HPI_RESET
);
619 /************************************************************************/
622 static void adapter_get_asserts(struct hpi_adapter_obj
*pao
,
623 struct hpi_message
*phm
, struct hpi_response
*phr
)
625 #ifndef HIDE_PCI_ASSERTS
626 /* if we have PCI2040 asserts then collect them */
627 if ((gw_pci_read_asserts
> 0) || (gw_pci_write_asserts
> 0)) {
628 phr
->u
.ax
.assert.p1
=
629 gw_pci_read_asserts
* 100 + gw_pci_write_asserts
;
630 phr
->u
.ax
.assert.p2
= 0;
631 phr
->u
.ax
.assert.count
= 1; /* assert count */
632 phr
->u
.ax
.assert.dsp_index
= -1; /* "dsp index" */
633 strcpy(phr
->u
.ax
.assert.sz_message
, "PCI2040 error");
634 phr
->u
.ax
.assert.dsp_msg_addr
= 0;
635 gw_pci_read_asserts
= 0;
636 gw_pci_write_asserts
= 0;
640 hw_message(pao
, phm
, phr
); /*get DSP asserts */
645 /************************************************************************/
648 static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
651 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
658 u32 test_addr
= 0x80000000;
659 u32 test_data
= 0x00000001;
660 u32 dw2040_reset
= 0;
663 u32 adapter_info
= 0;
666 struct dsp_code dsp_code
;
667 u16 boot_load_family
= 0;
669 /* NOTE don't use wAdapterType in this routine. It is not setup yet */
671 switch (pao
->pci
.pci_dev
->subsystem_device
) {
673 case 0x5110: /* ASI5100 revB or higher with C6711D */
674 case 0x5200: /* ASI5200 PCIe version of ASI5100 */
677 boot_load_family
= HPI_ADAPTER_FAMILY_ASI(0x6200);
680 return HPI6000_ERROR_UNHANDLED_SUBSYS_ID
;
683 /* reset all DSPs, indicate two DSPs are present
684 * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
687 dw2040_reset
= 0x0003000F;
688 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
690 /* read back register to make sure PCI2040 chip is functioning
691 * note that bits 4..15 are read-only and so should always return zero,
692 * even though we wrote 1 to them
694 hpios_delay_micro_seconds(1000);
695 delay
= ioread32(phw
->dw2040_HPICSR
+ HPI_RESET
);
697 if (delay
!= dw2040_reset
) {
698 HPI_DEBUG_LOG(ERROR
, "INIT_PCI2040 %x %x\n", dw2040_reset
,
700 return HPI6000_ERROR_INIT_PCI2040
;
703 /* Indicate that DSP#0,1 is a C6X */
704 iowrite32(0x00000003, phw
->dw2040_HPICSR
+ HPI_DATA_WIDTH
);
705 /* set Bit30 and 29 - which will prevent Target aborts from being
706 * issued upon HPI or GP error
708 iowrite32(0x60000000, phw
->dw2040_HPICSR
+ INTERRUPT_MASK_SET
);
710 /* isolate DSP HAD8 line from PCI2040 so that
711 * Little endian can be set by pullup
713 dw2040_reset
= dw2040_reset
& (~(endian
<< 3));
714 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
716 phw
->ado
[0].c_dsp_rev
= 'B'; /* revB */
717 phw
->ado
[1].c_dsp_rev
= 'B'; /* revB */
719 /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
720 dw2040_reset
= dw2040_reset
& (~0x00000001); /* start DSP 0 */
721 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
722 dw2040_reset
= dw2040_reset
& (~0x00000002); /* start DSP 1 */
723 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
725 /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
726 dw2040_reset
= dw2040_reset
& (~0x00000008);
727 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
728 /*delay to allow DSP to get going */
729 hpios_delay_micro_seconds(100);
731 /* loop through all DSPs, downloading DSP code */
732 for (dsp_index
= 0; dsp_index
< phw
->num_dsp
; dsp_index
++) {
733 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
735 /* configure DSP so that we download code into the SRAM */
736 /* set control reg for little endian, HWOB=1 */
737 iowrite32(0x00010001, pdo
->prHPI_control
);
739 /* test access to the HPI address register (HPIA) */
740 test_data
= 0x00000001;
741 for (j
= 0; j
< 32; j
++) {
742 iowrite32(test_data
, pdo
->prHPI_address
);
743 data
= ioread32(pdo
->prHPI_address
);
744 if (data
!= test_data
) {
745 HPI_DEBUG_LOG(ERROR
, "INIT_DSPHPI %x %x %x\n",
746 test_data
, data
, dsp_index
);
747 return HPI6000_ERROR_INIT_DSPHPI
;
749 test_data
= test_data
<< 1;
752 /* if C6713 the setup PLL to generate 225MHz from 25MHz.
753 * Since the PLLDIV1 read is sometimes wrong, even on a C6713,
754 * we're going to do this unconditionally
756 /* PLLDIV1 should have a value of 8000 after reset */
758 if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
761 /* C6713 datasheet says we cannot program PLL from HPI,
762 * and indeed if we try to set the PLL multiply from the
763 * HPI, the PLL does not seem to lock,
764 * so we enable the PLL and use the default of x 7
767 hpi_write_word(pdo
, 0x01B7C100, 0x0000);
768 hpios_delay_micro_seconds(100);
770 /* ** use default of PLL x7 ** */
771 /* EMIF = 225/3=75MHz */
772 hpi_write_word(pdo
, 0x01B7C120, 0x8002);
773 hpios_delay_micro_seconds(100);
776 hpi_write_word(pdo
, 0x01B7C11C, 0x8001);
777 hpios_delay_micro_seconds(100);
780 hpi_write_word(pdo
, 0x01B7C118, 0x8000);
783 hpios_delay_micro_seconds(2000);
785 /* PLL not bypassed */
786 hpi_write_word(pdo
, 0x01B7C100, 0x0001);
788 hpios_delay_micro_seconds(2000);
791 /* test r/w to internal DSP memory
792 * C6711 has L2 cache mapped to 0x0 when reset
794 * revB - because of bug 3.0.1 last HPI read
795 * (before HPI address issued) must be non-autoinc
797 /* test each bit in the 32bit word */
798 for (i
= 0; i
< 100; i
++) {
799 test_addr
= 0x00000000;
800 test_data
= 0x00000001;
801 for (j
= 0; j
< 32; j
++) {
802 hpi_write_word(pdo
, test_addr
+ i
, test_data
);
803 data
= hpi_read_word(pdo
, test_addr
+ i
);
804 if (data
!= test_data
) {
806 "DSP mem %x %x %x %x\n",
807 test_addr
+ i
, test_data
,
810 return HPI6000_ERROR_INIT_DSPINTMEM
;
812 test_data
= test_data
<< 1;
816 /* memory map of ASI6200
817 00000000-0000FFFF 16Kx32 internal program
818 01800000-019FFFFF Internal peripheral
819 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
820 90000000-9000FFFF CE1 Async peripherals:
828 3 CLK2EN = 1 CLKOUT2 enabled
829 4 CLK1EN = 0 CLKOUT1 disabled
830 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
832 7 NOHOLD = 1 external HOLD disabled
833 8 HOLDA = 0 HOLDA output is low
834 9 HOLD = 0 HOLD input is low
835 10 ARDY = 1 ARDY input is high
836 11 BUSREQ = 0 BUSREQ output is low
839 hpi_write_word(pdo
, 0x01800000, 0x34A8);
841 /* EMIF CE0 setup - 2Mx32 Sync DRAM
848 7..4 MTYPE 0011 Sync DRAM 32bits
852 hpi_write_word(pdo
, 0x01800008, 0x00000030);
854 /* EMIF SDRAM Extension
864 6-5 TWR = 2-1 = 01b (tWR = 10ns)
865 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
866 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
867 1 CAS latency = 3 ECLK
868 (for Micron 2M32-7 operating at 100Mhz)
871 /* need to use this else DSP code crashes */
872 hpi_write_word(pdo
, 0x01800020, 0x001BDF29);
874 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
877 29..28 SDRSZ 00 11 row address pins
878 27..26 SDCSZ 01 8 column address pins
879 25 RFEN 1 refersh enabled
886 /* need to use this else DSP code crashes */
887 hpi_write_word(pdo
, 0x01800018, 0x47117000);
889 /* EMIF SDRAM Refresh Timing */
890 hpi_write_word(pdo
, 0x0180001C, 0x00000410);
892 /*MIF CE1 setup - Async peripherals
893 @100MHz bus speed, each cycle is 10ns,
895 27..22 Wr strobe = 3 30ns
899 13..8 Rd strobe = 3 30ns
900 7..4 MTYPE 0010 Async 32bits
906 (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
907 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
908 hpi_write_word(pdo
, 0x01800004, cE1
);
911 /* delay a little to allow SDRAM and DSP to "get going" */
912 hpios_delay_micro_seconds(1000);
914 /* test access to SDRAM */
916 test_addr
= 0x80000000;
917 test_data
= 0x00000001;
918 /* test each bit in the 32bit word */
919 for (j
= 0; j
< 32; j
++) {
920 hpi_write_word(pdo
, test_addr
, test_data
);
921 data
= hpi_read_word(pdo
, test_addr
);
922 if (data
!= test_data
) {
924 "DSP dram %x %x %x %x\n",
925 test_addr
, test_data
, data
,
928 return HPI6000_ERROR_INIT_SDRAM1
;
930 test_data
= test_data
<< 1;
932 /* test every Nth address in the DRAM */
933 #define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
934 #define DRAM_INC 1024
935 test_addr
= 0x80000000;
937 for (i
= 0; i
< DRAM_SIZE_WORDS
; i
= i
+ DRAM_INC
) {
938 hpi_write_word(pdo
, test_addr
+ i
, test_data
);
941 test_addr
= 0x80000000;
943 for (i
= 0; i
< DRAM_SIZE_WORDS
; i
= i
+ DRAM_INC
) {
944 data
= hpi_read_word(pdo
, test_addr
+ i
);
945 if (data
!= test_data
) {
947 "DSP dram %x %x %x %x\n",
948 test_addr
+ i
, test_data
,
950 return HPI6000_ERROR_INIT_SDRAM2
;
957 /* write the DSP code down into the DSPs memory */
958 /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
959 dsp_code
.ps_dev
= pao
->pci
.pci_dev
;
961 error
= hpi_dsp_code_open(boot_load_family
, &dsp_code
,
973 error
= hpi_dsp_code_read_word(&dsp_code
, &length
);
976 if (length
== 0xFFFFFFFF)
977 break; /* end of code */
979 error
= hpi_dsp_code_read_word(&dsp_code
, &address
);
982 error
= hpi_dsp_code_read_word(&dsp_code
, &type
);
985 error
= hpi_dsp_code_read_block(length
, &dsp_code
,
989 error
= hpi6000_dsp_block_write32(pao
, (u16
)dsp_index
,
990 address
, pcode
, length
);
996 hpi_dsp_code_close(&dsp_code
);
999 /* verify that code was written correctly */
1000 /* this time through, assume no errors in DSP code file/array */
1001 hpi_dsp_code_rewind(&dsp_code
);
1008 hpi_dsp_code_read_word(&dsp_code
, &length
);
1009 if (length
== 0xFFFFFFFF)
1010 break; /* end of code */
1012 hpi_dsp_code_read_word(&dsp_code
, &address
);
1013 hpi_dsp_code_read_word(&dsp_code
, &type
);
1014 hpi_dsp_code_read_block(length
, &dsp_code
, &pcode
);
1016 for (i
= 0; i
< length
; i
++) {
1017 data
= hpi_read_word(pdo
, address
);
1018 if (data
!= *pcode
) {
1019 error
= HPI6000_ERROR_INIT_VERIFY
;
1020 HPI_DEBUG_LOG(ERROR
,
1021 "DSP verify %x %x %x %x\n",
1022 address
, *pcode
, data
,
1032 hpi_dsp_code_close(&dsp_code
);
1036 /* zero out the hostmailbox */
1038 u32 address
= HPI_HIF_ADDR(host_cmd
);
1039 for (i
= 0; i
< 4; i
++) {
1040 hpi_write_word(pdo
, address
, 0);
1044 /* write the DSP number into the hostmailbox */
1045 /* structure before starting the DSP */
1046 hpi_write_word(pdo
, HPI_HIF_ADDR(dsp_number
), dsp_index
);
1048 /* write the DSP adapter Info into the */
1049 /* hostmailbox before starting the DSP */
1051 hpi_write_word(pdo
, HPI_HIF_ADDR(adapter_info
),
1054 /* step 3. Start code by sending interrupt */
1055 iowrite32(0x00030003, pdo
->prHPI_control
);
1056 hpios_delay_micro_seconds(10000);
1058 /* wait for a non-zero value in hostcmd -
1059 * indicating initialization is complete
1061 * Init could take a while if DSP checks SDRAM memory
1062 * Was 200000. Increased to 2000000 for ASI8801 so we
1063 * don't get 938 errors.
1068 read
= hpi_read_word(pdo
,
1069 HPI_HIF_ADDR(host_cmd
));
1071 && hpi6000_check_PCI2040_error_flag(pao
,
1076 /* The following is a workaround for bug #94:
1077 * Bluescreen on install and subsequent boots on a
1078 * DELL PowerEdge 600SC PC with 1.8GHz P4 and
1079 * ServerWorks chipset. Without this delay the system
1080 * locks up with a bluescreen (NOT GPF or pagefault).
1083 hpios_delay_micro_seconds(10000);
1086 return HPI6000_ERROR_INIT_NOACK
;
1088 /* read the DSP adapter Info from the */
1089 /* hostmailbox structure after starting the DSP */
1090 if (dsp_index
== 0) {
1091 /*u32 dwTestData=0; */
1096 HPI_HIF_ADDR(adapter_info
));
1097 if (HPI_ADAPTER_FAMILY_ASI
1098 (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
1100 HPI_ADAPTER_FAMILY_ASI(0x6200))
1101 /* all 6200 cards have this many DSPs */
1104 /* test that the PLD is programmed */
1105 /* and we can read/write 24bits */
1106 #define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
1108 switch (boot_load_family
) {
1109 case HPI_ADAPTER_FAMILY_ASI(0x6200):
1110 /* ASI6100/6200 has 24bit path to FPGA */
1112 /* ASI5100 uses AX6 code, */
1113 /* but has no PLD r/w register to test */
1114 if (HPI_ADAPTER_FAMILY_ASI(pao
->pci
.pci_dev
->
1115 subsystem_device
) ==
1116 HPI_ADAPTER_FAMILY_ASI(0x5100))
1118 /* ASI5200 uses AX6 code, */
1119 /* but has no PLD r/w register to test */
1120 if (HPI_ADAPTER_FAMILY_ASI(pao
->pci
.pci_dev
->
1121 subsystem_device
) ==
1122 HPI_ADAPTER_FAMILY_ASI(0x5200))
1125 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1126 /* ASI8800 has 16bit path to FPGA */
1130 test_data
= 0xAAAAAA00L
& mask
;
1131 /* write to 24 bit Debug register (D31-D8) */
1132 hpi_write_word(pdo
, PLD_BASE_ADDRESS
+ 4L, test_data
);
1133 read
= hpi_read_word(pdo
,
1134 PLD_BASE_ADDRESS
+ 4L) & mask
;
1135 if (read
!= test_data
) {
1136 HPI_DEBUG_LOG(ERROR
, "PLD %x %x\n", test_data
,
1138 return HPI6000_ERROR_INIT_PLDTEST1
;
1140 test_data
= 0x55555500L
& mask
;
1141 hpi_write_word(pdo
, PLD_BASE_ADDRESS
+ 4L, test_data
);
1142 read
= hpi_read_word(pdo
,
1143 PLD_BASE_ADDRESS
+ 4L) & mask
;
1144 if (read
!= test_data
) {
1145 HPI_DEBUG_LOG(ERROR
, "PLD %x %x\n", test_data
,
1147 return HPI6000_ERROR_INIT_PLDTEST2
;
1154 #define PCI_TIMEOUT 100
1156 static int hpi_set_address(struct dsp_obj
*pdo
, u32 address
)
1158 u32 timeout
= PCI_TIMEOUT
;
1161 iowrite32(address
, pdo
->prHPI_address
);
1162 } while (hpi6000_check_PCI2040_error_flag(pdo
->pa_parent_adapter
,
1172 /* write one word to the HPI port */
1173 static void hpi_write_word(struct dsp_obj
*pdo
, u32 address
, u32 data
)
1175 if (hpi_set_address(pdo
, address
))
1177 iowrite32(data
, pdo
->prHPI_data
);
1180 /* read one word from the HPI port */
1181 static u32
hpi_read_word(struct dsp_obj
*pdo
, u32 address
)
1185 if (hpi_set_address(pdo
, address
))
1186 return 0; /*? No way to return error */
1188 /* take care of errata in revB DSP (2.0.1) */
1189 data
= ioread32(pdo
->prHPI_data
);
1193 /* write a block of 32bit words to the DSP HPI port using auto-inc mode */
1194 static void hpi_write_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
1197 u16 length16
= length
- 1;
1202 if (hpi_set_address(pdo
, address
))
1205 iowrite32_rep(pdo
->prHPI_data_auto_inc
, pdata
, length16
);
1207 /* take care of errata in revB DSP (2.0.1) */
1208 /* must end with non auto-inc */
1209 iowrite32(*(pdata
+ length
- 1), pdo
->prHPI_data
);
1212 /** read a block of 32bit words from the DSP HPI port using auto-inc mode
1214 static void hpi_read_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
1217 u16 length16
= length
- 1;
1222 if (hpi_set_address(pdo
, address
))
1225 ioread32_rep(pdo
->prHPI_data_auto_inc
, pdata
, length16
);
1227 /* take care of errata in revB DSP (2.0.1) */
1228 /* must end with non auto-inc */
1229 *(pdata
+ length
- 1) = ioread32(pdo
->prHPI_data
);
1232 static u16
hpi6000_dsp_block_write32(struct hpi_adapter_obj
*pao
,
1233 u16 dsp_index
, u32 hpi_address
, u32
*source
, u32 count
)
1235 struct dsp_obj
*pdo
=
1236 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1237 u32 time_out
= PCI_TIMEOUT
;
1238 int c6711_burst_size
= 128;
1239 u32 local_hpi_address
= hpi_address
;
1240 int local_count
= count
;
1242 u32
*pdata
= source
;
1244 while (local_count
) {
1245 if (local_count
> c6711_burst_size
)
1246 xfer_size
= c6711_burst_size
;
1248 xfer_size
= local_count
;
1250 time_out
= PCI_TIMEOUT
;
1252 hpi_write_block(pdo
, local_hpi_address
, pdata
,
1254 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
)
1260 local_hpi_address
+= sizeof(u32
) * xfer_size
;
1261 local_count
-= xfer_size
;
1270 static u16
hpi6000_dsp_block_read32(struct hpi_adapter_obj
*pao
,
1271 u16 dsp_index
, u32 hpi_address
, u32
*dest
, u32 count
)
1273 struct dsp_obj
*pdo
=
1274 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1275 u32 time_out
= PCI_TIMEOUT
;
1276 int c6711_burst_size
= 16;
1277 u32 local_hpi_address
= hpi_address
;
1278 int local_count
= count
;
1283 while (local_count
) {
1284 if (local_count
> c6711_burst_size
)
1285 xfer_size
= c6711_burst_size
;
1287 xfer_size
= local_count
;
1289 time_out
= PCI_TIMEOUT
;
1291 hpi_read_block(pdo
, local_hpi_address
, pdata
,
1293 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1299 local_hpi_address
+= sizeof(u32
) * xfer_size
;
1300 local_count
-= xfer_size
;
1310 static short hpi6000_message_response_sequence(struct hpi_adapter_obj
*pao
,
1311 u16 dsp_index
, struct hpi_message
*phm
, struct hpi_response
*phr
)
1313 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1314 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
1322 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1323 if (ack
& HPI_HIF_ERROR_MASK
) {
1325 return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT
;
1327 pao
->dsp_crashed
= 0;
1329 /* get the message address and size */
1330 if (phw
->message_buffer_address_on_dsp
== 0) {
1335 HPI_HIF_ADDR(message_buffer_address
));
1336 phw
->message_buffer_address_on_dsp
= address
;
1337 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1340 return HPI6000_ERROR_MSG_GET_ADR
;
1342 address
= phw
->message_buffer_address_on_dsp
;
1346 /* send the message */
1347 p_data
= (u32
*)phm
;
1348 if (hpi6000_dsp_block_write32(pao
, dsp_index
, address
, p_data
,
1350 return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32
;
1352 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_GET_RESP
))
1353 return HPI6000_ERROR_MSG_RESP_GETRESPCMD
;
1354 hpi6000_send_dsp_interrupt(pdo
);
1356 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_GET_RESP
);
1357 if (ack
& HPI_HIF_ERROR_MASK
)
1358 return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK
;
1360 /* get the response address */
1361 if (phw
->response_buffer_address_on_dsp
== 0) {
1366 HPI_HIF_ADDR(response_buffer_address
));
1367 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1369 phw
->response_buffer_address_on_dsp
= address
;
1372 return HPI6000_ERROR_RESP_GET_ADR
;
1374 address
= phw
->response_buffer_address_on_dsp
;
1376 /* read the length of the response back from the DSP */
1379 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1380 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
) && --timeout
);
1382 length
= sizeof(struct hpi_response
);
1384 /* get the response */
1385 p_data
= (u32
*)phr
;
1386 if (hpi6000_dsp_block_read32(pao
, dsp_index
, address
, p_data
,
1388 return HPI6000_ERROR_MSG_RESP_BLOCKREAD32
;
1390 /* set i/f back to idle */
1391 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1392 return HPI6000_ERROR_MSG_RESP_IDLECMD
;
1393 hpi6000_send_dsp_interrupt(pdo
);
1395 error
= hpi_validate_response(phm
, phr
);
1399 /* have to set up the below defines to match stuff in the MAP file */
1401 #define MSG_ADDRESS (HPI_HIF_BASE+0x18)
1402 #define MSG_LENGTH 11
1403 #define RESP_ADDRESS (HPI_HIF_BASE+0x44)
1404 #define RESP_LENGTH 16
1405 #define QUEUE_START (HPI_HIF_BASE+0x88)
1406 #define QUEUE_SIZE 0x8000
1408 static short hpi6000_send_data_check_adr(u32 address
, u32 length_in_dwords
)
1410 /*#define CHECKING // comment this line in to enable checking */
1412 if (address
< (u32
)MSG_ADDRESS
)
1414 if (address
> (u32
)(QUEUE_START
+ QUEUE_SIZE
))
1416 if ((address
+ (length_in_dwords
<< 2)) >
1417 (u32
)(QUEUE_START
+ QUEUE_SIZE
))
1421 (void)length_in_dwords
;
1426 static short hpi6000_send_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1427 struct hpi_message
*phm
, struct hpi_response
*phr
)
1429 struct dsp_obj
*pdo
=
1430 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1433 u32 length
, address
;
1434 u32
*p_data
= (u32
*)phm
->u
.d
.u
.data
.pb_data
;
1439 /* round dwDataSize down to nearest 4 bytes */
1440 while ((data_sent
< (phm
->u
.d
.u
.data
.data_size
& ~3L))
1442 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1443 if (ack
& HPI_HIF_ERROR_MASK
)
1444 return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT
;
1446 if (hpi6000_send_host_command(pao
, dsp_index
,
1448 return HPI6000_ERROR_SEND_DATA_CMD
;
1450 hpi6000_send_dsp_interrupt(pdo
);
1452 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_SEND_DATA
);
1454 if (ack
& HPI_HIF_ERROR_MASK
)
1455 return HPI6000_ERROR_SEND_DATA_ACK
;
1458 /* get the address and size */
1459 address
= hpi_read_word(pdo
, HPI_HIF_ADDR(address
));
1460 /* DSP returns number of DWORDS */
1461 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1462 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
));
1464 if (!hpi6000_send_data_check_adr(address
, length
))
1465 return HPI6000_ERROR_SEND_DATA_ADR
;
1467 /* send the data. break data into 512 DWORD blocks (2K bytes)
1468 * and send using block write. 2Kbytes is the max as this is the
1469 * memory window given to the HPI data register by the PCI2040
1478 if (hpi6000_dsp_block_write32(pao
, dsp_index
,
1479 address
, p_data
, blk_len
))
1480 return HPI6000_ERROR_SEND_DATA_WRITE
;
1481 address
+= blk_len
* 4;
1487 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1488 return HPI6000_ERROR_SEND_DATA_IDLECMD
;
1490 hpi6000_send_dsp_interrupt(pdo
);
1492 data_sent
+= length
* 4;
1495 return HPI6000_ERROR_SEND_DATA_TIMEOUT
;
1499 static short hpi6000_get_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1500 struct hpi_message
*phm
, struct hpi_response
*phr
)
1502 struct dsp_obj
*pdo
=
1503 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1506 u32 length
, address
;
1507 u32
*p_data
= (u32
*)phm
->u
.d
.u
.data
.pb_data
;
1509 (void)phr
; /* this parameter not used! */
1511 /* round dwDataSize down to nearest 4 bytes */
1512 while (data_got
< (phm
->u
.d
.u
.data
.data_size
& ~3L)) {
1513 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1514 if (ack
& HPI_HIF_ERROR_MASK
)
1515 return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT
;
1517 if (hpi6000_send_host_command(pao
, dsp_index
,
1519 return HPI6000_ERROR_GET_DATA_CMD
;
1520 hpi6000_send_dsp_interrupt(pdo
);
1522 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_GET_DATA
);
1524 if (ack
& HPI_HIF_ERROR_MASK
)
1525 return HPI6000_ERROR_GET_DATA_ACK
;
1527 /* get the address and size */
1529 address
= hpi_read_word(pdo
, HPI_HIF_ADDR(address
));
1530 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1531 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
));
1540 if (hpi6000_dsp_block_read32(pao
, dsp_index
,
1541 address
, p_data
, blk_len
))
1542 return HPI6000_ERROR_GET_DATA_READ
;
1543 address
+= blk_len
* 4;
1549 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1550 return HPI6000_ERROR_GET_DATA_IDLECMD
;
1551 hpi6000_send_dsp_interrupt(pdo
);
1553 data_got
+= length
* 4;
1558 static void hpi6000_send_dsp_interrupt(struct dsp_obj
*pdo
)
1560 iowrite32(0x00030003, pdo
->prHPI_control
); /* DSPINT */
1563 static short hpi6000_send_host_command(struct hpi_adapter_obj
*pao
,
1564 u16 dsp_index
, u32 host_cmd
)
1566 struct dsp_obj
*pdo
=
1567 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1568 u32 timeout
= TIMEOUT
;
1572 hpi_write_word(pdo
, HPI_HIF_ADDR(host_cmd
), host_cmd
);
1573 /* flush the FIFO */
1574 hpi_set_address(pdo
, HPI_HIF_ADDR(host_cmd
));
1575 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
) && --timeout
);
1577 /* reset the interrupt bit */
1578 iowrite32(0x00040004, pdo
->prHPI_control
);
1586 /* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
1587 static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj
*pao
,
1592 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1594 /* read the error bits from the PCI2040 */
1595 hPI_error
= ioread32(phw
->dw2040_HPICSR
+ HPI_ERROR_REPORT
);
1597 /* reset the error flag */
1598 iowrite32(0L, phw
->dw2040_HPICSR
+ HPI_ERROR_REPORT
);
1599 phw
->pCI2040HPI_error_count
++;
1600 if (read_or_write
== 1)
1601 gw_pci_read_asserts
++; /************* inc global */
1603 gw_pci_write_asserts
++;
1609 static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1612 struct dsp_obj
*pdo
=
1613 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1618 /* wait for host interrupt to signal ack is ready */
1621 hPIC
= ioread32(pdo
->prHPI_control
);
1622 if (hPIC
& 0x04) /* 0x04 = HINT from DSP */
1626 return HPI_HIF_ERROR_MASK
;
1628 /* wait for dwAckValue */
1631 /* read the ack mailbox */
1632 ack
= hpi_read_word(pdo
, HPI_HIF_ADDR(dsp_ack
));
1633 if (ack
== ack_value
)
1635 if ((ack
& HPI_HIF_ERROR_MASK
)
1636 && !hpi6000_check_PCI2040_error_flag(pao
, H6READ
))
1638 /*for (i=0;i<1000;i++) */
1641 if (ack
& HPI_HIF_ERROR_MASK
)
1642 /* indicates bad read from DSP -
1643 typically 0xffffff is read for some reason */
1644 ack
= HPI_HIF_ERROR_MASK
;
1647 ack
= HPI_HIF_ERROR_MASK
;
1651 static short hpi6000_update_control_cache(struct hpi_adapter_obj
*pao
,
1652 struct hpi_message
*phm
)
1654 const u16 dsp_index
= 0;
1655 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1656 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
1658 u32 cache_dirty_flag
;
1661 hpios_dsplock_lock(pao
);
1666 hpi_read_word((struct dsp_obj
*)pdo
,
1667 HPI_HIF_ADDR(control_cache_is_dirty
));
1668 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
) && --timeout
);
1670 err
= HPI6000_ERROR_CONTROL_CACHE_PARAMS
;
1674 if (cache_dirty_flag
) {
1675 /* read the cached controls */
1680 if (pdo
->control_cache_address_on_dsp
== 0) {
1683 hpi_read_word((struct dsp_obj
*)pdo
,
1684 HPI_HIF_ADDR(control_cache_address
));
1686 length
= hpi_read_word((struct dsp_obj
*)pdo
,
1688 (control_cache_size_in_bytes
));
1689 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1692 err
= HPI6000_ERROR_CONTROL_CACHE_ADDRLEN
;
1695 pdo
->control_cache_address_on_dsp
= address
;
1696 pdo
->control_cache_length_on_dsp
= length
;
1698 address
= pdo
->control_cache_address_on_dsp
;
1699 length
= pdo
->control_cache_length_on_dsp
;
1702 if (hpi6000_dsp_block_read32(pao
, dsp_index
, address
,
1703 (u32
*)&phw
->control_cache
[0],
1704 length
/ sizeof(u32
))) {
1705 err
= HPI6000_ERROR_CONTROL_CACHE_READ
;
1709 hpi_write_word((struct dsp_obj
*)pdo
,
1710 HPI_HIF_ADDR(control_cache_is_dirty
), 0);
1711 /* flush the FIFO */
1712 hpi_set_address(pdo
, HPI_HIF_ADDR(host_cmd
));
1713 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
)
1716 err
= HPI6000_ERROR_CONTROL_CACHE_FLUSH
;
1724 hpios_dsplock_unlock(pao
);
1728 /** Get dsp index for multi DSP adapters only */
1729 static u16
get_dsp_index(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
)
1732 switch (phm
->object
) {
1733 case HPI_OBJ_ISTREAM
:
1734 if (phm
->obj_index
< 2)
1737 case HPI_OBJ_PROFILE
:
1738 ret
= phm
->obj_index
;
1746 /** Complete transaction with DSP
1748 Send message, get response, send or get stream data if any.
1750 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
1751 struct hpi_response
*phr
)
1755 u16 num_dsp
= ((struct hpi_hw_obj
*)pao
->priv
)->num_dsp
;
1760 dsp_index
= get_dsp_index(pao
, phm
);
1762 /* is this checked on the DSP anyway? */
1763 if ((phm
->function
== HPI_ISTREAM_GROUP_ADD
)
1764 || (phm
->function
== HPI_OSTREAM_GROUP_ADD
)) {
1765 struct hpi_message hm
;
1767 hm
.obj_index
= phm
->u
.d
.u
.stream
.stream_index
;
1768 hm
.object
= phm
->u
.d
.u
.stream
.object_type
;
1769 add_index
= get_dsp_index(pao
, &hm
);
1770 if (add_index
!= dsp_index
) {
1771 phr
->error
= HPI_ERROR_NO_INTERDSP_GROUPS
;
1777 hpios_dsplock_lock(pao
);
1778 error
= hpi6000_message_response_sequence(pao
, dsp_index
, phm
, phr
);
1780 if (error
) /* something failed in the HPI/DSP interface */
1783 if (phr
->error
) /* something failed in the DSP */
1786 switch (phm
->function
) {
1787 case HPI_OSTREAM_WRITE
:
1788 case HPI_ISTREAM_ANC_WRITE
:
1789 error
= hpi6000_send_data(pao
, dsp_index
, phm
, phr
);
1791 case HPI_ISTREAM_READ
:
1792 case HPI_OSTREAM_ANC_READ
:
1793 error
= hpi6000_get_data(pao
, dsp_index
, phm
, phr
);
1795 case HPI_ADAPTER_GET_ASSERT
:
1796 phr
->u
.ax
.assert.dsp_index
= 0; /* dsp 0 default */
1798 if (!phr
->u
.ax
.assert.count
) {
1799 /* no assert from dsp 0, check dsp 1 */
1800 error
= hpi6000_message_response_sequence(pao
,
1802 phr
->u
.ax
.assert.dsp_index
= 1;
1809 if (error
>= HPI_ERROR_BACKEND_BASE
) {
1810 phr
->error
= HPI_ERROR_DSP_COMMUNICATION
;
1811 phr
->specific_error
= error
;
1816 /* just the header of the response is valid */
1817 phr
->size
= sizeof(struct hpi_response_header
);
1820 hpios_dsplock_unlock(pao
);