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 adapter_delete(struct hpi_adapter_obj
*pao
,
204 struct hpi_message
*phm
, 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
);
226 phr
->error
= HPI_ERROR_INVALID_FUNC
;
231 static void control_message(struct hpi_adapter_obj
*pao
,
232 struct hpi_message
*phm
, struct hpi_response
*phr
)
234 switch (phm
->function
) {
235 case HPI_CONTROL_GET_STATE
:
236 if (pao
->has_control_cache
) {
238 err
= hpi6000_update_control_cache(pao
, phm
);
241 if (err
>= HPI_ERROR_BACKEND_BASE
) {
243 HPI_ERROR_CONTROL_CACHING
;
244 phr
->specific_error
= err
;
251 if (hpi_check_control_cache(((struct hpi_hw_obj
*)
252 pao
->priv
)->p_cache
, phm
,
256 hw_message(pao
, phm
, phr
);
258 case HPI_CONTROL_SET_STATE
:
259 hw_message(pao
, phm
, phr
);
260 hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj
*)pao
->
261 priv
)->p_cache
, phm
, phr
);
264 case HPI_CONTROL_GET_INFO
:
266 hw_message(pao
, phm
, phr
);
271 static void adapter_message(struct hpi_adapter_obj
*pao
,
272 struct hpi_message
*phm
, struct hpi_response
*phr
)
274 switch (phm
->function
) {
275 case HPI_ADAPTER_GET_ASSERT
:
276 adapter_get_asserts(pao
, phm
, phr
);
279 case HPI_ADAPTER_DELETE
:
280 adapter_delete(pao
, phm
, phr
);
284 hw_message(pao
, phm
, phr
);
289 static void outstream_message(struct hpi_adapter_obj
*pao
,
290 struct hpi_message
*phm
, struct hpi_response
*phr
)
292 switch (phm
->function
) {
293 case HPI_OSTREAM_HOSTBUFFER_ALLOC
:
294 case HPI_OSTREAM_HOSTBUFFER_FREE
:
295 /* Don't let these messages go to the HW function because
296 * they're called without locking the spinlock.
297 * For the HPI6000 adapters the HW would return
298 * HPI_ERROR_INVALID_FUNC anyway.
300 phr
->error
= HPI_ERROR_INVALID_FUNC
;
303 hw_message(pao
, phm
, phr
);
308 static void instream_message(struct hpi_adapter_obj
*pao
,
309 struct hpi_message
*phm
, struct hpi_response
*phr
)
312 switch (phm
->function
) {
313 case HPI_ISTREAM_HOSTBUFFER_ALLOC
:
314 case HPI_ISTREAM_HOSTBUFFER_FREE
:
315 /* Don't let these messages go to the HW function because
316 * they're called without locking the spinlock.
317 * For the HPI6000 adapters the HW would return
318 * HPI_ERROR_INVALID_FUNC anyway.
320 phr
->error
= HPI_ERROR_INVALID_FUNC
;
323 hw_message(pao
, phm
, phr
);
328 /************************************************************************/
330 * Entry point from HPIMAN
331 * All calls to the HPI start here
333 void HPI_6000(struct hpi_message
*phm
, struct hpi_response
*phr
)
335 struct hpi_adapter_obj
*pao
= NULL
;
337 if (phm
->object
!= HPI_OBJ_SUBSYSTEM
) {
338 pao
= hpi_find_adapter(phm
->adapter_index
);
340 hpi_init_response(phr
, phm
->object
, phm
->function
,
341 HPI_ERROR_BAD_ADAPTER_NUMBER
);
342 HPI_DEBUG_LOG(DEBUG
, "invalid adapter index: %d \n",
347 /* Don't even try to communicate with crashed DSP */
348 if (pao
->dsp_crashed
>= 10) {
349 hpi_init_response(phr
, phm
->object
, phm
->function
,
350 HPI_ERROR_DSP_HARDWARE
);
351 HPI_DEBUG_LOG(DEBUG
, "adapter %d dsp crashed\n",
356 /* Init default response including the size field */
357 if (phm
->function
!= HPI_SUBSYS_CREATE_ADAPTER
)
358 hpi_init_response(phr
, phm
->object
, phm
->function
,
359 HPI_ERROR_PROCESSING_MESSAGE
);
362 case HPI_TYPE_MESSAGE
:
363 switch (phm
->object
) {
364 case HPI_OBJ_SUBSYSTEM
:
365 subsys_message(phm
, phr
);
368 case HPI_OBJ_ADAPTER
:
370 sizeof(struct hpi_response_header
) +
371 sizeof(struct hpi_adapter_res
);
372 adapter_message(pao
, phm
, phr
);
375 case HPI_OBJ_CONTROL
:
376 control_message(pao
, phm
, phr
);
379 case HPI_OBJ_OSTREAM
:
380 outstream_message(pao
, phm
, phr
);
383 case HPI_OBJ_ISTREAM
:
384 instream_message(pao
, phm
, phr
);
388 hw_message(pao
, phm
, phr
);
394 phr
->error
= HPI_ERROR_INVALID_TYPE
;
399 /************************************************************************/
402 /* create an adapter object and initialise it based on resource information
403 * passed in in the message
404 * NOTE - you cannot use this function AND the FindAdapters function at the
405 * same time, the application must use only one of them to get the adapters
407 static void subsys_create_adapter(struct hpi_message
*phm
,
408 struct hpi_response
*phr
)
410 /* create temp adapter obj, because we don't know what index yet */
411 struct hpi_adapter_obj ao
;
412 struct hpi_adapter_obj
*pao
;
417 HPI_DEBUG_LOG(VERBOSE
, "subsys_create_adapter\n");
419 memset(&ao
, 0, sizeof(ao
));
421 ao
.priv
= kzalloc(sizeof(struct hpi_hw_obj
), GFP_KERNEL
);
423 HPI_DEBUG_LOG(ERROR
, "can't get mem for adapter object\n");
424 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
428 /* create the adapter object based on the resource information */
429 ao
.pci
= *phm
->u
.s
.resource
.r
.pci
;
431 err
= create_adapter_obj(&ao
, &os_error_code
);
433 delete_adapter_obj(&ao
);
434 if (err
>= HPI_ERROR_BACKEND_BASE
) {
435 phr
->error
= HPI_ERROR_DSP_BOOTLOAD
;
436 phr
->specific_error
= err
;
441 phr
->u
.s
.data
= os_error_code
;
444 /* need to update paParentAdapter */
445 pao
= hpi_find_adapter(ao
.index
);
447 /* We just added this adapter, why can't we find it!? */
448 HPI_DEBUG_LOG(ERROR
, "lost adapter after boot\n");
449 phr
->error
= HPI_ERROR_BAD_ADAPTER
;
453 for (dsp_index
= 0; dsp_index
< MAX_DSPS
; dsp_index
++) {
454 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
455 phw
->ado
[dsp_index
].pa_parent_adapter
= pao
;
458 phr
->u
.s
.adapter_type
= ao
.adapter_type
;
459 phr
->u
.s
.adapter_index
= ao
.index
;
463 static void adapter_delete(struct hpi_adapter_obj
*pao
,
464 struct hpi_message
*phm
, struct hpi_response
*phr
)
466 delete_adapter_obj(pao
);
467 hpi_delete_adapter(pao
);
471 /* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
472 static short create_adapter_obj(struct hpi_adapter_obj
*pao
,
475 short boot_error
= 0;
477 u32 control_cache_size
= 0;
478 u32 control_cache_count
= 0;
479 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
481 /* The PCI2040 has the following address map */
482 /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
483 /* BAR1 - 32K = HPI registers on DSP */
484 phw
->dw2040_HPICSR
= pao
->pci
.ap_mem_base
[0];
485 phw
->dw2040_HPIDSP
= pao
->pci
.ap_mem_base
[1];
486 HPI_DEBUG_LOG(VERBOSE
, "csr %p, dsp %p\n", phw
->dw2040_HPICSR
,
489 /* set addresses for the possible DSP HPI interfaces */
490 for (dsp_index
= 0; dsp_index
< MAX_DSPS
; dsp_index
++) {
491 phw
->ado
[dsp_index
].prHPI_control
=
492 phw
->dw2040_HPIDSP
+ (CONTROL
+
493 DSP_SPACING
* dsp_index
);
495 phw
->ado
[dsp_index
].prHPI_address
=
496 phw
->dw2040_HPIDSP
+ (ADDRESS
+
497 DSP_SPACING
* dsp_index
);
498 phw
->ado
[dsp_index
].prHPI_data
=
499 phw
->dw2040_HPIDSP
+ (DATA
+ DSP_SPACING
* dsp_index
);
501 phw
->ado
[dsp_index
].prHPI_data_auto_inc
=
502 phw
->dw2040_HPIDSP
+ (DATA_AUTOINC
+
503 DSP_SPACING
* dsp_index
);
505 HPI_DEBUG_LOG(VERBOSE
, "ctl %p, adr %p, dat %p, dat++ %p\n",
506 phw
->ado
[dsp_index
].prHPI_control
,
507 phw
->ado
[dsp_index
].prHPI_address
,
508 phw
->ado
[dsp_index
].prHPI_data
,
509 phw
->ado
[dsp_index
].prHPI_data_auto_inc
);
511 phw
->ado
[dsp_index
].pa_parent_adapter
= pao
;
514 phw
->pCI2040HPI_error_count
= 0;
515 pao
->has_control_cache
= 0;
517 /* Set the default number of DSPs on this card */
518 /* This is (conditionally) adjusted after bootloading */
519 /* of the first DSP in the bootload section. */
522 boot_error
= hpi6000_adapter_boot_load_dsp(pao
, pos_error_code
);
526 HPI_DEBUG_LOG(INFO
, "bootload DSP OK\n");
528 phw
->message_buffer_address_on_dsp
= 0L;
529 phw
->response_buffer_address_on_dsp
= 0L;
531 /* get info about the adapter by asking the adapter */
532 /* send a HPI_ADAPTER_GET_INFO message */
534 struct hpi_message hm
;
535 struct hpi_response hr0
; /* response from DSP 0 */
536 struct hpi_response hr1
; /* response from DSP 1 */
539 HPI_DEBUG_LOG(VERBOSE
, "send ADAPTER_GET_INFO\n");
540 memset(&hm
, 0, sizeof(hm
));
541 hm
.type
= HPI_TYPE_MESSAGE
;
542 hm
.size
= sizeof(struct hpi_message
);
543 hm
.object
= HPI_OBJ_ADAPTER
;
544 hm
.function
= HPI_ADAPTER_GET_INFO
;
545 hm
.adapter_index
= 0;
546 memset(&hr0
, 0, sizeof(hr0
));
547 memset(&hr1
, 0, sizeof(hr1
));
548 hr0
.size
= sizeof(hr0
);
549 hr1
.size
= sizeof(hr1
);
551 error
= hpi6000_message_response_sequence(pao
, 0, &hm
, &hr0
);
553 HPI_DEBUG_LOG(DEBUG
, "message error %d\n", hr0
.error
);
556 if (phw
->num_dsp
== 2) {
557 error
= hpi6000_message_response_sequence(pao
, 1, &hm
,
562 pao
->adapter_type
= hr0
.u
.ax
.info
.adapter_type
;
563 pao
->index
= hr0
.u
.ax
.info
.adapter_index
;
566 memset(&phw
->control_cache
[0], 0,
567 sizeof(struct hpi_control_cache_single
) *
568 HPI_NMIXER_CONTROLS
);
569 /* Read the control cache length to figure out if it is turned on */
571 hpi_read_word(&phw
->ado
[0],
572 HPI_HIF_ADDR(control_cache_size_in_bytes
));
573 if (control_cache_size
) {
574 control_cache_count
=
575 hpi_read_word(&phw
->ado
[0],
576 HPI_HIF_ADDR(control_cache_count
));
579 hpi_alloc_control_cache(control_cache_count
,
580 control_cache_size
, (unsigned char *)
581 &phw
->control_cache
[0]
584 pao
->has_control_cache
= 1;
587 HPI_DEBUG_LOG(DEBUG
, "get adapter info ASI%04X index %d\n",
588 pao
->adapter_type
, pao
->index
);
589 pao
->open
= 0; /* upon creation the adapter is closed */
592 phw
->p_cache
->adap_idx
= pao
->index
;
594 return hpi_add_adapter(pao
);
597 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
)
599 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
601 if (pao
->has_control_cache
)
602 hpi_free_control_cache(phw
->p_cache
);
604 /* reset DSPs on adapter */
605 iowrite32(0x0003000F, phw
->dw2040_HPICSR
+ HPI_RESET
);
610 /************************************************************************/
613 static void adapter_get_asserts(struct hpi_adapter_obj
*pao
,
614 struct hpi_message
*phm
, struct hpi_response
*phr
)
616 #ifndef HIDE_PCI_ASSERTS
617 /* if we have PCI2040 asserts then collect them */
618 if ((gw_pci_read_asserts
> 0) || (gw_pci_write_asserts
> 0)) {
619 phr
->u
.ax
.assert.p1
=
620 gw_pci_read_asserts
* 100 + gw_pci_write_asserts
;
621 phr
->u
.ax
.assert.p2
= 0;
622 phr
->u
.ax
.assert.count
= 1; /* assert count */
623 phr
->u
.ax
.assert.dsp_index
= -1; /* "dsp index" */
624 strcpy(phr
->u
.ax
.assert.sz_message
, "PCI2040 error");
625 phr
->u
.ax
.assert.dsp_msg_addr
= 0;
626 gw_pci_read_asserts
= 0;
627 gw_pci_write_asserts
= 0;
631 hw_message(pao
, phm
, phr
); /*get DSP asserts */
636 /************************************************************************/
639 static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
642 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
649 u32 test_addr
= 0x80000000;
650 u32 test_data
= 0x00000001;
651 u32 dw2040_reset
= 0;
654 u32 adapter_info
= 0;
657 struct dsp_code dsp_code
;
658 u16 boot_load_family
= 0;
660 /* NOTE don't use wAdapterType in this routine. It is not setup yet */
662 switch (pao
->pci
.pci_dev
->subsystem_device
) {
664 case 0x5110: /* ASI5100 revB or higher with C6711D */
665 case 0x5200: /* ASI5200 PCIe version of ASI5100 */
668 boot_load_family
= HPI_ADAPTER_FAMILY_ASI(0x6200);
671 return HPI6000_ERROR_UNHANDLED_SUBSYS_ID
;
674 /* reset all DSPs, indicate two DSPs are present
675 * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
678 dw2040_reset
= 0x0003000F;
679 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
681 /* read back register to make sure PCI2040 chip is functioning
682 * note that bits 4..15 are read-only and so should always return zero,
683 * even though we wrote 1 to them
685 hpios_delay_micro_seconds(1000);
686 delay
= ioread32(phw
->dw2040_HPICSR
+ HPI_RESET
);
688 if (delay
!= dw2040_reset
) {
689 HPI_DEBUG_LOG(ERROR
, "INIT_PCI2040 %x %x\n", dw2040_reset
,
691 return HPI6000_ERROR_INIT_PCI2040
;
694 /* Indicate that DSP#0,1 is a C6X */
695 iowrite32(0x00000003, phw
->dw2040_HPICSR
+ HPI_DATA_WIDTH
);
696 /* set Bit30 and 29 - which will prevent Target aborts from being
697 * issued upon HPI or GP error
699 iowrite32(0x60000000, phw
->dw2040_HPICSR
+ INTERRUPT_MASK_SET
);
701 /* isolate DSP HAD8 line from PCI2040 so that
702 * Little endian can be set by pullup
704 dw2040_reset
= dw2040_reset
& (~(endian
<< 3));
705 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
707 phw
->ado
[0].c_dsp_rev
= 'B'; /* revB */
708 phw
->ado
[1].c_dsp_rev
= 'B'; /* revB */
710 /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
711 dw2040_reset
= dw2040_reset
& (~0x00000001); /* start DSP 0 */
712 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
713 dw2040_reset
= dw2040_reset
& (~0x00000002); /* start DSP 1 */
714 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
716 /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
717 dw2040_reset
= dw2040_reset
& (~0x00000008);
718 iowrite32(dw2040_reset
, phw
->dw2040_HPICSR
+ HPI_RESET
);
719 /*delay to allow DSP to get going */
720 hpios_delay_micro_seconds(100);
722 /* loop through all DSPs, downloading DSP code */
723 for (dsp_index
= 0; dsp_index
< phw
->num_dsp
; dsp_index
++) {
724 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
726 /* configure DSP so that we download code into the SRAM */
727 /* set control reg for little endian, HWOB=1 */
728 iowrite32(0x00010001, pdo
->prHPI_control
);
730 /* test access to the HPI address register (HPIA) */
731 test_data
= 0x00000001;
732 for (j
= 0; j
< 32; j
++) {
733 iowrite32(test_data
, pdo
->prHPI_address
);
734 data
= ioread32(pdo
->prHPI_address
);
735 if (data
!= test_data
) {
736 HPI_DEBUG_LOG(ERROR
, "INIT_DSPHPI %x %x %x\n",
737 test_data
, data
, dsp_index
);
738 return HPI6000_ERROR_INIT_DSPHPI
;
740 test_data
= test_data
<< 1;
743 /* if C6713 the setup PLL to generate 225MHz from 25MHz.
744 * Since the PLLDIV1 read is sometimes wrong, even on a C6713,
745 * we're going to do this unconditionally
747 /* PLLDIV1 should have a value of 8000 after reset */
749 if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
752 /* C6713 datasheet says we cannot program PLL from HPI,
753 * and indeed if we try to set the PLL multiply from the
754 * HPI, the PLL does not seem to lock,
755 * so we enable the PLL and use the default of x 7
758 hpi_write_word(pdo
, 0x01B7C100, 0x0000);
759 hpios_delay_micro_seconds(100);
761 /* ** use default of PLL x7 ** */
762 /* EMIF = 225/3=75MHz */
763 hpi_write_word(pdo
, 0x01B7C120, 0x8002);
764 hpios_delay_micro_seconds(100);
767 hpi_write_word(pdo
, 0x01B7C11C, 0x8001);
768 hpios_delay_micro_seconds(100);
771 hpi_write_word(pdo
, 0x01B7C118, 0x8000);
774 hpios_delay_micro_seconds(2000);
776 /* PLL not bypassed */
777 hpi_write_word(pdo
, 0x01B7C100, 0x0001);
779 hpios_delay_micro_seconds(2000);
782 /* test r/w to internal DSP memory
783 * C6711 has L2 cache mapped to 0x0 when reset
785 * revB - because of bug 3.0.1 last HPI read
786 * (before HPI address issued) must be non-autoinc
788 /* test each bit in the 32bit word */
789 for (i
= 0; i
< 100; i
++) {
790 test_addr
= 0x00000000;
791 test_data
= 0x00000001;
792 for (j
= 0; j
< 32; j
++) {
793 hpi_write_word(pdo
, test_addr
+ i
, test_data
);
794 data
= hpi_read_word(pdo
, test_addr
+ i
);
795 if (data
!= test_data
) {
797 "DSP mem %x %x %x %x\n",
798 test_addr
+ i
, test_data
,
801 return HPI6000_ERROR_INIT_DSPINTMEM
;
803 test_data
= test_data
<< 1;
807 /* memory map of ASI6200
808 00000000-0000FFFF 16Kx32 internal program
809 01800000-019FFFFF Internal peripheral
810 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
811 90000000-9000FFFF CE1 Async peripherals:
819 3 CLK2EN = 1 CLKOUT2 enabled
820 4 CLK1EN = 0 CLKOUT1 disabled
821 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
823 7 NOHOLD = 1 external HOLD disabled
824 8 HOLDA = 0 HOLDA output is low
825 9 HOLD = 0 HOLD input is low
826 10 ARDY = 1 ARDY input is high
827 11 BUSREQ = 0 BUSREQ output is low
830 hpi_write_word(pdo
, 0x01800000, 0x34A8);
832 /* EMIF CE0 setup - 2Mx32 Sync DRAM
839 7..4 MTYPE 0011 Sync DRAM 32bits
843 hpi_write_word(pdo
, 0x01800008, 0x00000030);
845 /* EMIF SDRAM Extension
855 6-5 TWR = 2-1 = 01b (tWR = 10ns)
856 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
857 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
858 1 CAS latency = 3 ECLK
859 (for Micron 2M32-7 operating at 100Mhz)
862 /* need to use this else DSP code crashes */
863 hpi_write_word(pdo
, 0x01800020, 0x001BDF29);
865 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
868 29..28 SDRSZ 00 11 row address pins
869 27..26 SDCSZ 01 8 column address pins
870 25 RFEN 1 refersh enabled
877 /* need to use this else DSP code crashes */
878 hpi_write_word(pdo
, 0x01800018, 0x47117000);
880 /* EMIF SDRAM Refresh Timing */
881 hpi_write_word(pdo
, 0x0180001C, 0x00000410);
883 /*MIF CE1 setup - Async peripherals
884 @100MHz bus speed, each cycle is 10ns,
886 27..22 Wr strobe = 3 30ns
890 13..8 Rd strobe = 3 30ns
891 7..4 MTYPE 0010 Async 32bits
897 (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
898 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
899 hpi_write_word(pdo
, 0x01800004, cE1
);
902 /* delay a little to allow SDRAM and DSP to "get going" */
903 hpios_delay_micro_seconds(1000);
905 /* test access to SDRAM */
907 test_addr
= 0x80000000;
908 test_data
= 0x00000001;
909 /* test each bit in the 32bit word */
910 for (j
= 0; j
< 32; j
++) {
911 hpi_write_word(pdo
, test_addr
, test_data
);
912 data
= hpi_read_word(pdo
, test_addr
);
913 if (data
!= test_data
) {
915 "DSP dram %x %x %x %x\n",
916 test_addr
, test_data
, data
,
919 return HPI6000_ERROR_INIT_SDRAM1
;
921 test_data
= test_data
<< 1;
923 /* test every Nth address in the DRAM */
924 #define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
925 #define DRAM_INC 1024
926 test_addr
= 0x80000000;
928 for (i
= 0; i
< DRAM_SIZE_WORDS
; i
= i
+ DRAM_INC
) {
929 hpi_write_word(pdo
, test_addr
+ i
, test_data
);
932 test_addr
= 0x80000000;
934 for (i
= 0; i
< DRAM_SIZE_WORDS
; i
= i
+ DRAM_INC
) {
935 data
= hpi_read_word(pdo
, test_addr
+ i
);
936 if (data
!= test_data
) {
938 "DSP dram %x %x %x %x\n",
939 test_addr
+ i
, test_data
,
941 return HPI6000_ERROR_INIT_SDRAM2
;
948 /* write the DSP code down into the DSPs memory */
949 /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
950 dsp_code
.ps_dev
= pao
->pci
.pci_dev
;
952 error
= hpi_dsp_code_open(boot_load_family
, &dsp_code
,
964 error
= hpi_dsp_code_read_word(&dsp_code
, &length
);
967 if (length
== 0xFFFFFFFF)
968 break; /* end of code */
970 error
= hpi_dsp_code_read_word(&dsp_code
, &address
);
973 error
= hpi_dsp_code_read_word(&dsp_code
, &type
);
976 error
= hpi_dsp_code_read_block(length
, &dsp_code
,
980 error
= hpi6000_dsp_block_write32(pao
, (u16
)dsp_index
,
981 address
, pcode
, length
);
987 hpi_dsp_code_close(&dsp_code
);
990 /* verify that code was written correctly */
991 /* this time through, assume no errors in DSP code file/array */
992 hpi_dsp_code_rewind(&dsp_code
);
999 hpi_dsp_code_read_word(&dsp_code
, &length
);
1000 if (length
== 0xFFFFFFFF)
1001 break; /* end of code */
1003 hpi_dsp_code_read_word(&dsp_code
, &address
);
1004 hpi_dsp_code_read_word(&dsp_code
, &type
);
1005 hpi_dsp_code_read_block(length
, &dsp_code
, &pcode
);
1007 for (i
= 0; i
< length
; i
++) {
1008 data
= hpi_read_word(pdo
, address
);
1009 if (data
!= *pcode
) {
1010 error
= HPI6000_ERROR_INIT_VERIFY
;
1011 HPI_DEBUG_LOG(ERROR
,
1012 "DSP verify %x %x %x %x\n",
1013 address
, *pcode
, data
,
1023 hpi_dsp_code_close(&dsp_code
);
1027 /* zero out the hostmailbox */
1029 u32 address
= HPI_HIF_ADDR(host_cmd
);
1030 for (i
= 0; i
< 4; i
++) {
1031 hpi_write_word(pdo
, address
, 0);
1035 /* write the DSP number into the hostmailbox */
1036 /* structure before starting the DSP */
1037 hpi_write_word(pdo
, HPI_HIF_ADDR(dsp_number
), dsp_index
);
1039 /* write the DSP adapter Info into the */
1040 /* hostmailbox before starting the DSP */
1042 hpi_write_word(pdo
, HPI_HIF_ADDR(adapter_info
),
1045 /* step 3. Start code by sending interrupt */
1046 iowrite32(0x00030003, pdo
->prHPI_control
);
1047 hpios_delay_micro_seconds(10000);
1049 /* wait for a non-zero value in hostcmd -
1050 * indicating initialization is complete
1052 * Init could take a while if DSP checks SDRAM memory
1053 * Was 200000. Increased to 2000000 for ASI8801 so we
1054 * don't get 938 errors.
1059 read
= hpi_read_word(pdo
,
1060 HPI_HIF_ADDR(host_cmd
));
1062 && hpi6000_check_PCI2040_error_flag(pao
,
1067 /* The following is a workaround for bug #94:
1068 * Bluescreen on install and subsequent boots on a
1069 * DELL PowerEdge 600SC PC with 1.8GHz P4 and
1070 * ServerWorks chipset. Without this delay the system
1071 * locks up with a bluescreen (NOT GPF or pagefault).
1074 hpios_delay_micro_seconds(10000);
1077 return HPI6000_ERROR_INIT_NOACK
;
1079 /* read the DSP adapter Info from the */
1080 /* hostmailbox structure after starting the DSP */
1081 if (dsp_index
== 0) {
1082 /*u32 dwTestData=0; */
1087 HPI_HIF_ADDR(adapter_info
));
1088 if (HPI_ADAPTER_FAMILY_ASI
1089 (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
1091 HPI_ADAPTER_FAMILY_ASI(0x6200))
1092 /* all 6200 cards have this many DSPs */
1095 /* test that the PLD is programmed */
1096 /* and we can read/write 24bits */
1097 #define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
1099 switch (boot_load_family
) {
1100 case HPI_ADAPTER_FAMILY_ASI(0x6200):
1101 /* ASI6100/6200 has 24bit path to FPGA */
1103 /* ASI5100 uses AX6 code, */
1104 /* but has no PLD r/w register to test */
1105 if (HPI_ADAPTER_FAMILY_ASI(pao
->pci
.pci_dev
->
1106 subsystem_device
) ==
1107 HPI_ADAPTER_FAMILY_ASI(0x5100))
1109 /* ASI5200 uses AX6 code, */
1110 /* but has no PLD r/w register to test */
1111 if (HPI_ADAPTER_FAMILY_ASI(pao
->pci
.pci_dev
->
1112 subsystem_device
) ==
1113 HPI_ADAPTER_FAMILY_ASI(0x5200))
1116 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1117 /* ASI8800 has 16bit path to FPGA */
1121 test_data
= 0xAAAAAA00L
& mask
;
1122 /* write to 24 bit Debug register (D31-D8) */
1123 hpi_write_word(pdo
, PLD_BASE_ADDRESS
+ 4L, test_data
);
1124 read
= hpi_read_word(pdo
,
1125 PLD_BASE_ADDRESS
+ 4L) & mask
;
1126 if (read
!= test_data
) {
1127 HPI_DEBUG_LOG(ERROR
, "PLD %x %x\n", test_data
,
1129 return HPI6000_ERROR_INIT_PLDTEST1
;
1131 test_data
= 0x55555500L
& mask
;
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_PLDTEST2
;
1145 #define PCI_TIMEOUT 100
1147 static int hpi_set_address(struct dsp_obj
*pdo
, u32 address
)
1149 u32 timeout
= PCI_TIMEOUT
;
1152 iowrite32(address
, pdo
->prHPI_address
);
1153 } while (hpi6000_check_PCI2040_error_flag(pdo
->pa_parent_adapter
,
1163 /* write one word to the HPI port */
1164 static void hpi_write_word(struct dsp_obj
*pdo
, u32 address
, u32 data
)
1166 if (hpi_set_address(pdo
, address
))
1168 iowrite32(data
, pdo
->prHPI_data
);
1171 /* read one word from the HPI port */
1172 static u32
hpi_read_word(struct dsp_obj
*pdo
, u32 address
)
1176 if (hpi_set_address(pdo
, address
))
1177 return 0; /*? No way to return error */
1179 /* take care of errata in revB DSP (2.0.1) */
1180 data
= ioread32(pdo
->prHPI_data
);
1184 /* write a block of 32bit words to the DSP HPI port using auto-inc mode */
1185 static void hpi_write_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
1188 u16 length16
= length
- 1;
1193 if (hpi_set_address(pdo
, address
))
1196 iowrite32_rep(pdo
->prHPI_data_auto_inc
, pdata
, length16
);
1198 /* take care of errata in revB DSP (2.0.1) */
1199 /* must end with non auto-inc */
1200 iowrite32(*(pdata
+ length
- 1), pdo
->prHPI_data
);
1203 /** read a block of 32bit words from the DSP HPI port using auto-inc mode
1205 static void hpi_read_block(struct dsp_obj
*pdo
, u32 address
, u32
*pdata
,
1208 u16 length16
= length
- 1;
1213 if (hpi_set_address(pdo
, address
))
1216 ioread32_rep(pdo
->prHPI_data_auto_inc
, pdata
, length16
);
1218 /* take care of errata in revB DSP (2.0.1) */
1219 /* must end with non auto-inc */
1220 *(pdata
+ length
- 1) = ioread32(pdo
->prHPI_data
);
1223 static u16
hpi6000_dsp_block_write32(struct hpi_adapter_obj
*pao
,
1224 u16 dsp_index
, u32 hpi_address
, u32
*source
, u32 count
)
1226 struct dsp_obj
*pdo
=
1227 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1228 u32 time_out
= PCI_TIMEOUT
;
1229 int c6711_burst_size
= 128;
1230 u32 local_hpi_address
= hpi_address
;
1231 int local_count
= count
;
1233 u32
*pdata
= source
;
1235 while (local_count
) {
1236 if (local_count
> c6711_burst_size
)
1237 xfer_size
= c6711_burst_size
;
1239 xfer_size
= local_count
;
1241 time_out
= PCI_TIMEOUT
;
1243 hpi_write_block(pdo
, local_hpi_address
, pdata
,
1245 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
)
1251 local_hpi_address
+= sizeof(u32
) * xfer_size
;
1252 local_count
-= xfer_size
;
1261 static u16
hpi6000_dsp_block_read32(struct hpi_adapter_obj
*pao
,
1262 u16 dsp_index
, u32 hpi_address
, u32
*dest
, u32 count
)
1264 struct dsp_obj
*pdo
=
1265 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1266 u32 time_out
= PCI_TIMEOUT
;
1267 int c6711_burst_size
= 16;
1268 u32 local_hpi_address
= hpi_address
;
1269 int local_count
= count
;
1274 while (local_count
) {
1275 if (local_count
> c6711_burst_size
)
1276 xfer_size
= c6711_burst_size
;
1278 xfer_size
= local_count
;
1280 time_out
= PCI_TIMEOUT
;
1282 hpi_read_block(pdo
, local_hpi_address
, pdata
,
1284 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1290 local_hpi_address
+= sizeof(u32
) * xfer_size
;
1291 local_count
-= xfer_size
;
1301 static short hpi6000_message_response_sequence(struct hpi_adapter_obj
*pao
,
1302 u16 dsp_index
, struct hpi_message
*phm
, struct hpi_response
*phr
)
1304 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1305 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
1313 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1314 if (ack
& HPI_HIF_ERROR_MASK
) {
1316 return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT
;
1318 pao
->dsp_crashed
= 0;
1320 /* get the message address and size */
1321 if (phw
->message_buffer_address_on_dsp
== 0) {
1326 HPI_HIF_ADDR(message_buffer_address
));
1327 phw
->message_buffer_address_on_dsp
= address
;
1328 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1331 return HPI6000_ERROR_MSG_GET_ADR
;
1333 address
= phw
->message_buffer_address_on_dsp
;
1337 /* send the message */
1338 p_data
= (u32
*)phm
;
1339 if (hpi6000_dsp_block_write32(pao
, dsp_index
, address
, p_data
,
1341 return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32
;
1343 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_GET_RESP
))
1344 return HPI6000_ERROR_MSG_RESP_GETRESPCMD
;
1345 hpi6000_send_dsp_interrupt(pdo
);
1347 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_GET_RESP
);
1348 if (ack
& HPI_HIF_ERROR_MASK
)
1349 return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK
;
1351 /* get the response address */
1352 if (phw
->response_buffer_address_on_dsp
== 0) {
1357 HPI_HIF_ADDR(response_buffer_address
));
1358 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1360 phw
->response_buffer_address_on_dsp
= address
;
1363 return HPI6000_ERROR_RESP_GET_ADR
;
1365 address
= phw
->response_buffer_address_on_dsp
;
1367 /* read the length of the response back from the DSP */
1370 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1371 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
) && --timeout
);
1373 length
= sizeof(struct hpi_response
);
1375 /* get the response */
1376 p_data
= (u32
*)phr
;
1377 if (hpi6000_dsp_block_read32(pao
, dsp_index
, address
, p_data
,
1379 return HPI6000_ERROR_MSG_RESP_BLOCKREAD32
;
1381 /* set i/f back to idle */
1382 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1383 return HPI6000_ERROR_MSG_RESP_IDLECMD
;
1384 hpi6000_send_dsp_interrupt(pdo
);
1386 error
= hpi_validate_response(phm
, phr
);
1390 /* have to set up the below defines to match stuff in the MAP file */
1392 #define MSG_ADDRESS (HPI_HIF_BASE+0x18)
1393 #define MSG_LENGTH 11
1394 #define RESP_ADDRESS (HPI_HIF_BASE+0x44)
1395 #define RESP_LENGTH 16
1396 #define QUEUE_START (HPI_HIF_BASE+0x88)
1397 #define QUEUE_SIZE 0x8000
1399 static short hpi6000_send_data_check_adr(u32 address
, u32 length_in_dwords
)
1401 /*#define CHECKING // comment this line in to enable checking */
1403 if (address
< (u32
)MSG_ADDRESS
)
1405 if (address
> (u32
)(QUEUE_START
+ QUEUE_SIZE
))
1407 if ((address
+ (length_in_dwords
<< 2)) >
1408 (u32
)(QUEUE_START
+ QUEUE_SIZE
))
1412 (void)length_in_dwords
;
1417 static short hpi6000_send_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1418 struct hpi_message
*phm
, struct hpi_response
*phr
)
1420 struct dsp_obj
*pdo
=
1421 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1424 u32 length
, address
;
1425 u32
*p_data
= (u32
*)phm
->u
.d
.u
.data
.pb_data
;
1430 /* round dwDataSize down to nearest 4 bytes */
1431 while ((data_sent
< (phm
->u
.d
.u
.data
.data_size
& ~3L))
1433 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1434 if (ack
& HPI_HIF_ERROR_MASK
)
1435 return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT
;
1437 if (hpi6000_send_host_command(pao
, dsp_index
,
1439 return HPI6000_ERROR_SEND_DATA_CMD
;
1441 hpi6000_send_dsp_interrupt(pdo
);
1443 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_SEND_DATA
);
1445 if (ack
& HPI_HIF_ERROR_MASK
)
1446 return HPI6000_ERROR_SEND_DATA_ACK
;
1449 /* get the address and size */
1450 address
= hpi_read_word(pdo
, HPI_HIF_ADDR(address
));
1451 /* DSP returns number of DWORDS */
1452 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1453 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
));
1455 if (!hpi6000_send_data_check_adr(address
, length
))
1456 return HPI6000_ERROR_SEND_DATA_ADR
;
1458 /* send the data. break data into 512 DWORD blocks (2K bytes)
1459 * and send using block write. 2Kbytes is the max as this is the
1460 * memory window given to the HPI data register by the PCI2040
1469 if (hpi6000_dsp_block_write32(pao
, dsp_index
,
1470 address
, p_data
, blk_len
))
1471 return HPI6000_ERROR_SEND_DATA_WRITE
;
1472 address
+= blk_len
* 4;
1478 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1479 return HPI6000_ERROR_SEND_DATA_IDLECMD
;
1481 hpi6000_send_dsp_interrupt(pdo
);
1483 data_sent
+= length
* 4;
1486 return HPI6000_ERROR_SEND_DATA_TIMEOUT
;
1490 static short hpi6000_get_data(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1491 struct hpi_message
*phm
, struct hpi_response
*phr
)
1493 struct dsp_obj
*pdo
=
1494 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1497 u32 length
, address
;
1498 u32
*p_data
= (u32
*)phm
->u
.d
.u
.data
.pb_data
;
1500 (void)phr
; /* this parameter not used! */
1502 /* round dwDataSize down to nearest 4 bytes */
1503 while (data_got
< (phm
->u
.d
.u
.data
.data_size
& ~3L)) {
1504 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_IDLE
);
1505 if (ack
& HPI_HIF_ERROR_MASK
)
1506 return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT
;
1508 if (hpi6000_send_host_command(pao
, dsp_index
,
1510 return HPI6000_ERROR_GET_DATA_CMD
;
1511 hpi6000_send_dsp_interrupt(pdo
);
1513 ack
= hpi6000_wait_dsp_ack(pao
, dsp_index
, HPI_HIF_GET_DATA
);
1515 if (ack
& HPI_HIF_ERROR_MASK
)
1516 return HPI6000_ERROR_GET_DATA_ACK
;
1518 /* get the address and size */
1520 address
= hpi_read_word(pdo
, HPI_HIF_ADDR(address
));
1521 length
= hpi_read_word(pdo
, HPI_HIF_ADDR(length
));
1522 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
));
1531 if (hpi6000_dsp_block_read32(pao
, dsp_index
,
1532 address
, p_data
, blk_len
))
1533 return HPI6000_ERROR_GET_DATA_READ
;
1534 address
+= blk_len
* 4;
1540 if (hpi6000_send_host_command(pao
, dsp_index
, HPI_HIF_IDLE
))
1541 return HPI6000_ERROR_GET_DATA_IDLECMD
;
1542 hpi6000_send_dsp_interrupt(pdo
);
1544 data_got
+= length
* 4;
1549 static void hpi6000_send_dsp_interrupt(struct dsp_obj
*pdo
)
1551 iowrite32(0x00030003, pdo
->prHPI_control
); /* DSPINT */
1554 static short hpi6000_send_host_command(struct hpi_adapter_obj
*pao
,
1555 u16 dsp_index
, u32 host_cmd
)
1557 struct dsp_obj
*pdo
=
1558 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1559 u32 timeout
= TIMEOUT
;
1563 hpi_write_word(pdo
, HPI_HIF_ADDR(host_cmd
), host_cmd
);
1564 /* flush the FIFO */
1565 hpi_set_address(pdo
, HPI_HIF_ADDR(host_cmd
));
1566 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
) && --timeout
);
1568 /* reset the interrupt bit */
1569 iowrite32(0x00040004, pdo
->prHPI_control
);
1577 /* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
1578 static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj
*pao
,
1583 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1585 /* read the error bits from the PCI2040 */
1586 hPI_error
= ioread32(phw
->dw2040_HPICSR
+ HPI_ERROR_REPORT
);
1588 /* reset the error flag */
1589 iowrite32(0L, phw
->dw2040_HPICSR
+ HPI_ERROR_REPORT
);
1590 phw
->pCI2040HPI_error_count
++;
1591 if (read_or_write
== 1)
1592 gw_pci_read_asserts
++; /************* inc global */
1594 gw_pci_write_asserts
++;
1600 static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj
*pao
, u16 dsp_index
,
1603 struct dsp_obj
*pdo
=
1604 &(*(struct hpi_hw_obj
*)pao
->priv
).ado
[dsp_index
];
1609 /* wait for host interrupt to signal ack is ready */
1612 hPIC
= ioread32(pdo
->prHPI_control
);
1613 if (hPIC
& 0x04) /* 0x04 = HINT from DSP */
1617 return HPI_HIF_ERROR_MASK
;
1619 /* wait for dwAckValue */
1622 /* read the ack mailbox */
1623 ack
= hpi_read_word(pdo
, HPI_HIF_ADDR(dsp_ack
));
1624 if (ack
== ack_value
)
1626 if ((ack
& HPI_HIF_ERROR_MASK
)
1627 && !hpi6000_check_PCI2040_error_flag(pao
, H6READ
))
1629 /*for (i=0;i<1000;i++) */
1632 if (ack
& HPI_HIF_ERROR_MASK
)
1633 /* indicates bad read from DSP -
1634 typically 0xffffff is read for some reason */
1635 ack
= HPI_HIF_ERROR_MASK
;
1638 ack
= HPI_HIF_ERROR_MASK
;
1642 static short hpi6000_update_control_cache(struct hpi_adapter_obj
*pao
,
1643 struct hpi_message
*phm
)
1645 const u16 dsp_index
= 0;
1646 struct hpi_hw_obj
*phw
= (struct hpi_hw_obj
*)pao
->priv
;
1647 struct dsp_obj
*pdo
= &phw
->ado
[dsp_index
];
1649 u32 cache_dirty_flag
;
1652 hpios_dsplock_lock(pao
);
1657 hpi_read_word((struct dsp_obj
*)pdo
,
1658 HPI_HIF_ADDR(control_cache_is_dirty
));
1659 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
) && --timeout
);
1661 err
= HPI6000_ERROR_CONTROL_CACHE_PARAMS
;
1665 if (cache_dirty_flag
) {
1666 /* read the cached controls */
1671 if (pdo
->control_cache_address_on_dsp
== 0) {
1674 hpi_read_word((struct dsp_obj
*)pdo
,
1675 HPI_HIF_ADDR(control_cache_address
));
1677 length
= hpi_read_word((struct dsp_obj
*)pdo
,
1679 (control_cache_size_in_bytes
));
1680 } while (hpi6000_check_PCI2040_error_flag(pao
, H6READ
)
1683 err
= HPI6000_ERROR_CONTROL_CACHE_ADDRLEN
;
1686 pdo
->control_cache_address_on_dsp
= address
;
1687 pdo
->control_cache_length_on_dsp
= length
;
1689 address
= pdo
->control_cache_address_on_dsp
;
1690 length
= pdo
->control_cache_length_on_dsp
;
1693 if (hpi6000_dsp_block_read32(pao
, dsp_index
, address
,
1694 (u32
*)&phw
->control_cache
[0],
1695 length
/ sizeof(u32
))) {
1696 err
= HPI6000_ERROR_CONTROL_CACHE_READ
;
1700 hpi_write_word((struct dsp_obj
*)pdo
,
1701 HPI_HIF_ADDR(control_cache_is_dirty
), 0);
1702 /* flush the FIFO */
1703 hpi_set_address(pdo
, HPI_HIF_ADDR(host_cmd
));
1704 } while (hpi6000_check_PCI2040_error_flag(pao
, H6WRITE
)
1707 err
= HPI6000_ERROR_CONTROL_CACHE_FLUSH
;
1715 hpios_dsplock_unlock(pao
);
1719 /** Get dsp index for multi DSP adapters only */
1720 static u16
get_dsp_index(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
)
1723 switch (phm
->object
) {
1724 case HPI_OBJ_ISTREAM
:
1725 if (phm
->obj_index
< 2)
1728 case HPI_OBJ_PROFILE
:
1729 ret
= phm
->obj_index
;
1737 /** Complete transaction with DSP
1739 Send message, get response, send or get stream data if any.
1741 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
1742 struct hpi_response
*phr
)
1746 u16 num_dsp
= ((struct hpi_hw_obj
*)pao
->priv
)->num_dsp
;
1751 dsp_index
= get_dsp_index(pao
, phm
);
1753 /* is this checked on the DSP anyway? */
1754 if ((phm
->function
== HPI_ISTREAM_GROUP_ADD
)
1755 || (phm
->function
== HPI_OSTREAM_GROUP_ADD
)) {
1756 struct hpi_message hm
;
1758 hm
.obj_index
= phm
->u
.d
.u
.stream
.stream_index
;
1759 hm
.object
= phm
->u
.d
.u
.stream
.object_type
;
1760 add_index
= get_dsp_index(pao
, &hm
);
1761 if (add_index
!= dsp_index
) {
1762 phr
->error
= HPI_ERROR_NO_INTERDSP_GROUPS
;
1768 hpios_dsplock_lock(pao
);
1769 error
= hpi6000_message_response_sequence(pao
, dsp_index
, phm
, phr
);
1771 if (error
) /* something failed in the HPI/DSP interface */
1774 if (phr
->error
) /* something failed in the DSP */
1777 switch (phm
->function
) {
1778 case HPI_OSTREAM_WRITE
:
1779 case HPI_ISTREAM_ANC_WRITE
:
1780 error
= hpi6000_send_data(pao
, dsp_index
, phm
, phr
);
1782 case HPI_ISTREAM_READ
:
1783 case HPI_OSTREAM_ANC_READ
:
1784 error
= hpi6000_get_data(pao
, dsp_index
, phm
, phr
);
1786 case HPI_ADAPTER_GET_ASSERT
:
1787 phr
->u
.ax
.assert.dsp_index
= 0; /* dsp 0 default */
1789 if (!phr
->u
.ax
.assert.count
) {
1790 /* no assert from dsp 0, check dsp 1 */
1791 error
= hpi6000_message_response_sequence(pao
,
1793 phr
->u
.ax
.assert.dsp_index
= 1;
1800 if (error
>= HPI_ERROR_BACKEND_BASE
) {
1801 phr
->error
= HPI_ERROR_DSP_COMMUNICATION
;
1802 phr
->specific_error
= error
;
1807 /* just the header of the response is valid */
1808 phr
->size
= sizeof(struct hpi_response_header
);
1811 hpios_dsplock_unlock(pao
);