1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 AudioScience HPI driver
5 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
8 Hardware Programming Interface (HPI) for AudioScience ASI6200 series adapters.
9 These PCI bus adapters are based on the TI C6711 DSP.
12 void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
15 HIDE_PCI_ASSERTS to show the PCI asserts
16 PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
18 (C) Copyright AudioScience Inc. 1998-2003
19 *******************************************************************************/
20 #define SOURCEFILE_NAME "hpi6000.c"
22 #include "hpi_internal.h"
23 #include "hpimsginit.h"
29 #define HPI_HIF_BASE (0x00000200) /* start of C67xx internal RAM */
30 #define HPI_HIF_ADDR(member) \
31 (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
32 #define HPI_HIF_ERROR_MASK 0x4000
34 /* HPI6000 specific error codes */
35 #define HPI6000_ERROR_BASE 900 /* not actually used anywhere */
37 /* operational/messaging errors */
38 #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT 901
39 #define HPI6000_ERROR_RESP_GET_LEN 902
40 #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK 903
41 #define HPI6000_ERROR_MSG_GET_ADR 904
42 #define HPI6000_ERROR_RESP_GET_ADR 905
43 #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32 906
44 #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32 907
46 #define HPI6000_ERROR_CONTROL_CACHE_PARAMS 909
48 #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT 911
49 #define HPI6000_ERROR_SEND_DATA_ACK 912
50 #define HPI6000_ERROR_SEND_DATA_ADR 913
51 #define HPI6000_ERROR_SEND_DATA_TIMEOUT 914
52 #define HPI6000_ERROR_SEND_DATA_CMD 915
53 #define HPI6000_ERROR_SEND_DATA_WRITE 916
54 #define HPI6000_ERROR_SEND_DATA_IDLECMD 917
56 #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT 921
57 #define HPI6000_ERROR_GET_DATA_ACK 922
58 #define HPI6000_ERROR_GET_DATA_CMD 923
59 #define HPI6000_ERROR_GET_DATA_READ 924
60 #define HPI6000_ERROR_GET_DATA_IDLECMD 925
62 #define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN 951
63 #define HPI6000_ERROR_CONTROL_CACHE_READ 952
64 #define HPI6000_ERROR_CONTROL_CACHE_FLUSH 953
66 #define HPI6000_ERROR_MSG_RESP_GETRESPCMD 961
67 #define HPI6000_ERROR_MSG_RESP_IDLECMD 962
69 /* Initialisation/bootload errors */
70 #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID 930
72 /* can't access PCI2040 */
73 #define HPI6000_ERROR_INIT_PCI2040 931
74 /* can't access DSP HPI i/f */
75 #define HPI6000_ERROR_INIT_DSPHPI 932
76 /* can't access internal DSP memory */
77 #define HPI6000_ERROR_INIT_DSPINTMEM 933
78 /* can't access SDRAM - test#1 */
79 #define HPI6000_ERROR_INIT_SDRAM1 934
80 /* can't access SDRAM - test#2 */
81 #define HPI6000_ERROR_INIT_SDRAM2 935
83 #define HPI6000_ERROR_INIT_VERIFY 938
85 #define HPI6000_ERROR_INIT_NOACK 939
87 #define HPI6000_ERROR_INIT_PLDTEST1 941
88 #define HPI6000_ERROR_INIT_PLDTEST2 942
92 #define HIDE_PCI_ASSERTS
95 /* for PCI2040 i/f chip */
96 /* HPI CSR registers */
97 /* word offsets from CSR base */
98 /* use when io addresses defined as u32 * */
100 #define INTERRUPT_EVENT_SET 0
101 #define INTERRUPT_EVENT_CLEAR 1
102 #define INTERRUPT_MASK_SET 2
103 #define INTERRUPT_MASK_CLEAR 3
104 #define HPI_ERROR_REPORT 4
106 #define HPI_DATA_WIDTH 6
109 /* HPI registers, spaced 8K bytes = 2K words apart */
110 #define DSP_SPACING 0x800
112 #define CONTROL 0x0000
113 #define ADDRESS 0x0200
114 #define DATA_AUTOINC 0x0400
117 #define TIMEOUT 500000
120 __iomem u32 *prHPI_control;
121 __iomem u32 *prHPI_address;
122 __iomem u32 *prHPI_data;
123 __iomem u32 *prHPI_data_auto_inc;
124 char c_dsp_rev; /*A, B */
125 u32 control_cache_address_on_dsp;
126 u32 control_cache_length_on_dsp;
127 struct hpi_adapter_obj *pa_parent_adapter;
131 __iomem u32 *dw2040_HPICSR;
132 __iomem u32 *dw2040_HPIDSP;
135 struct dsp_obj ado[MAX_DSPS];
137 u32 message_buffer_address_on_dsp;
138 u32 response_buffer_address_on_dsp;
139 u32 pCI2040HPI_error_count;
141 struct hpi_control_cache_single control_cache[HPI_NMIXER_CONTROLS];
142 struct hpi_control_cache *p_cache;
145 static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
146 u16 dsp_index, u32 hpi_address, u32 *source, u32 count);
147 static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
148 u16 dsp_index, u32 hpi_address, u32 *dest, u32 count);
150 static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
151 u32 *pos_error_code);
152 static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
157 static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
158 struct hpi_message *phm);
159 static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
160 u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr);
162 static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
163 struct hpi_response *phr);
165 static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
168 static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
169 u16 dsp_index, u32 host_cmd);
171 static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo);
173 static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
174 struct hpi_message *phm, struct hpi_response *phr);
176 static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
177 struct hpi_message *phm, struct hpi_response *phr);
179 static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data);
181 static u32 hpi_read_word(struct dsp_obj *pdo, u32 address);
183 static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
186 static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
189 static void subsys_create_adapter(struct hpi_message *phm,
190 struct hpi_response *phr);
192 static void adapter_delete(struct hpi_adapter_obj *pao,
193 struct hpi_message *phm, struct hpi_response *phr);
195 static void adapter_get_asserts(struct hpi_adapter_obj *pao,
196 struct hpi_message *phm, struct hpi_response *phr);
198 static short create_adapter_obj(struct hpi_adapter_obj *pao,
199 u32 *pos_error_code);
201 static void delete_adapter_obj(struct hpi_adapter_obj *pao);
205 static u16 gw_pci_read_asserts; /* used to count PCI2040 errors */
206 static u16 gw_pci_write_asserts; /* used to count PCI2040 errors */
208 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
210 switch (phm->function) {
211 case HPI_SUBSYS_CREATE_ADAPTER:
212 subsys_create_adapter(phm, phr);
215 phr->error = HPI_ERROR_INVALID_FUNC;
220 static void control_message(struct hpi_adapter_obj *pao,
221 struct hpi_message *phm, struct hpi_response *phr)
223 struct hpi_hw_obj *phw = pao->priv;
225 switch (phm->function) {
226 case HPI_CONTROL_GET_STATE:
227 if (pao->has_control_cache) {
229 err = hpi6000_update_control_cache(pao, phm);
232 if (err >= HPI_ERROR_BACKEND_BASE) {
234 HPI_ERROR_CONTROL_CACHING;
235 phr->specific_error = err;
242 if (hpi_check_control_cache(phw->p_cache, phm, phr))
245 hw_message(pao, phm, phr);
247 case HPI_CONTROL_SET_STATE:
248 hw_message(pao, phm, phr);
249 hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm, phr);
252 case HPI_CONTROL_GET_INFO:
254 hw_message(pao, phm, phr);
259 static void adapter_message(struct hpi_adapter_obj *pao,
260 struct hpi_message *phm, struct hpi_response *phr)
262 switch (phm->function) {
263 case HPI_ADAPTER_GET_ASSERT:
264 adapter_get_asserts(pao, phm, phr);
267 case HPI_ADAPTER_DELETE:
268 adapter_delete(pao, phm, phr);
272 hw_message(pao, phm, phr);
277 static void outstream_message(struct hpi_adapter_obj *pao,
278 struct hpi_message *phm, struct hpi_response *phr)
280 switch (phm->function) {
281 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
282 case HPI_OSTREAM_HOSTBUFFER_FREE:
283 /* Don't let these messages go to the HW function because
284 * they're called without locking the spinlock.
285 * For the HPI6000 adapters the HW would return
286 * HPI_ERROR_INVALID_FUNC anyway.
288 phr->error = HPI_ERROR_INVALID_FUNC;
291 hw_message(pao, phm, phr);
296 static void instream_message(struct hpi_adapter_obj *pao,
297 struct hpi_message *phm, struct hpi_response *phr)
300 switch (phm->function) {
301 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
302 case HPI_ISTREAM_HOSTBUFFER_FREE:
303 /* Don't let these messages go to the HW function because
304 * they're called without locking the spinlock.
305 * For the HPI6000 adapters the HW would return
306 * HPI_ERROR_INVALID_FUNC anyway.
308 phr->error = HPI_ERROR_INVALID_FUNC;
311 hw_message(pao, phm, phr);
316 /************************************************************************/
318 * Entry point from HPIMAN
319 * All calls to the HPI start here
321 void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
323 struct hpi_adapter_obj *pao = NULL;
325 if (phm->object != HPI_OBJ_SUBSYSTEM) {
326 pao = hpi_find_adapter(phm->adapter_index);
328 hpi_init_response(phr, phm->object, phm->function,
329 HPI_ERROR_BAD_ADAPTER_NUMBER);
330 HPI_DEBUG_LOG(DEBUG, "invalid adapter index: %d \n",
335 /* Don't even try to communicate with crashed DSP */
336 if (pao->dsp_crashed >= 10) {
337 hpi_init_response(phr, phm->object, phm->function,
338 HPI_ERROR_DSP_HARDWARE);
339 HPI_DEBUG_LOG(DEBUG, "adapter %d dsp crashed\n",
344 /* Init default response including the size field */
345 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
346 hpi_init_response(phr, phm->object, phm->function,
347 HPI_ERROR_PROCESSING_MESSAGE);
350 case HPI_TYPE_REQUEST:
351 switch (phm->object) {
352 case HPI_OBJ_SUBSYSTEM:
353 subsys_message(phm, phr);
356 case HPI_OBJ_ADAPTER:
358 sizeof(struct hpi_response_header) +
359 sizeof(struct hpi_adapter_res);
360 adapter_message(pao, phm, phr);
363 case HPI_OBJ_CONTROL:
364 control_message(pao, phm, phr);
367 case HPI_OBJ_OSTREAM:
368 outstream_message(pao, phm, phr);
371 case HPI_OBJ_ISTREAM:
372 instream_message(pao, phm, phr);
376 hw_message(pao, phm, phr);
382 phr->error = HPI_ERROR_INVALID_TYPE;
387 /************************************************************************/
390 /* create an adapter object and initialise it based on resource information
391 * passed in the message
392 * NOTE - you cannot use this function AND the FindAdapters function at the
393 * same time, the application must use only one of them to get the adapters
395 static void subsys_create_adapter(struct hpi_message *phm,
396 struct hpi_response *phr)
398 /* create temp adapter obj, because we don't know what index yet */
399 struct hpi_adapter_obj ao;
400 struct hpi_adapter_obj *pao;
405 HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
407 memset(&ao, 0, sizeof(ao));
409 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
411 HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
412 phr->error = HPI_ERROR_MEMORY_ALLOC;
416 /* create the adapter object based on the resource information */
417 ao.pci = *phm->u.s.resource.r.pci;
419 err = create_adapter_obj(&ao, &os_error_code);
421 delete_adapter_obj(&ao);
422 if (err >= HPI_ERROR_BACKEND_BASE) {
423 phr->error = HPI_ERROR_DSP_BOOTLOAD;
424 phr->specific_error = err;
429 phr->u.s.data = os_error_code;
432 /* need to update paParentAdapter */
433 pao = hpi_find_adapter(ao.index);
435 /* We just added this adapter, why can't we find it!? */
436 HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
437 phr->error = HPI_ERROR_BAD_ADAPTER;
441 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
442 struct hpi_hw_obj *phw = pao->priv;
443 phw->ado[dsp_index].pa_parent_adapter = pao;
446 phr->u.s.adapter_type = ao.type;
447 phr->u.s.adapter_index = ao.index;
451 static void adapter_delete(struct hpi_adapter_obj *pao,
452 struct hpi_message *phm, struct hpi_response *phr)
454 delete_adapter_obj(pao);
455 hpi_delete_adapter(pao);
459 /* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
460 static short create_adapter_obj(struct hpi_adapter_obj *pao,
463 short boot_error = 0;
465 u32 control_cache_size = 0;
466 u32 control_cache_count = 0;
467 struct hpi_hw_obj *phw = pao->priv;
469 /* The PCI2040 has the following address map */
470 /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
471 /* BAR1 - 32K = HPI registers on DSP */
472 phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
473 phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
474 HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
477 /* set addresses for the possible DSP HPI interfaces */
478 for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
479 phw->ado[dsp_index].prHPI_control =
480 phw->dw2040_HPIDSP + (CONTROL +
481 DSP_SPACING * dsp_index);
483 phw->ado[dsp_index].prHPI_address =
484 phw->dw2040_HPIDSP + (ADDRESS +
485 DSP_SPACING * dsp_index);
486 phw->ado[dsp_index].prHPI_data =
487 phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
489 phw->ado[dsp_index].prHPI_data_auto_inc =
490 phw->dw2040_HPIDSP + (DATA_AUTOINC +
491 DSP_SPACING * dsp_index);
493 HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
494 phw->ado[dsp_index].prHPI_control,
495 phw->ado[dsp_index].prHPI_address,
496 phw->ado[dsp_index].prHPI_data,
497 phw->ado[dsp_index].prHPI_data_auto_inc);
499 phw->ado[dsp_index].pa_parent_adapter = pao;
502 phw->pCI2040HPI_error_count = 0;
503 pao->has_control_cache = 0;
505 /* Set the default number of DSPs on this card */
506 /* This is (conditionally) adjusted after bootloading */
507 /* of the first DSP in the bootload section. */
510 boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
514 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
516 phw->message_buffer_address_on_dsp = 0L;
517 phw->response_buffer_address_on_dsp = 0L;
519 /* get info about the adapter by asking the adapter */
520 /* send a HPI_ADAPTER_GET_INFO message */
522 struct hpi_message hm;
523 struct hpi_response hr0; /* response from DSP 0 */
524 struct hpi_response hr1; /* response from DSP 1 */
527 HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
528 memset(&hm, 0, sizeof(hm));
529 hm.type = HPI_TYPE_REQUEST;
530 hm.size = sizeof(struct hpi_message);
531 hm.object = HPI_OBJ_ADAPTER;
532 hm.function = HPI_ADAPTER_GET_INFO;
533 hm.adapter_index = 0;
534 memset(&hr0, 0, sizeof(hr0));
535 memset(&hr1, 0, sizeof(hr1));
536 hr0.size = sizeof(hr0);
537 hr1.size = sizeof(hr1);
539 error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
541 HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
544 if (phw->num_dsp == 2) {
545 error = hpi6000_message_response_sequence(pao, 1, &hm,
550 pao->type = hr0.u.ax.info.adapter_type;
551 pao->index = hr0.u.ax.info.adapter_index;
554 memset(&phw->control_cache[0], 0,
555 sizeof(struct hpi_control_cache_single) *
556 HPI_NMIXER_CONTROLS);
557 /* Read the control cache length to figure out if it is turned on */
559 hpi_read_word(&phw->ado[0],
560 HPI_HIF_ADDR(control_cache_size_in_bytes));
561 if (control_cache_size) {
562 control_cache_count =
563 hpi_read_word(&phw->ado[0],
564 HPI_HIF_ADDR(control_cache_count));
567 hpi_alloc_control_cache(control_cache_count,
568 control_cache_size, (unsigned char *)
569 &phw->control_cache[0]
572 pao->has_control_cache = 1;
575 HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n", pao->type,
579 phw->p_cache->adap_idx = pao->index;
581 return hpi_add_adapter(pao);
584 static void delete_adapter_obj(struct hpi_adapter_obj *pao)
586 struct hpi_hw_obj *phw = pao->priv;
588 if (pao->has_control_cache)
589 hpi_free_control_cache(phw->p_cache);
591 /* reset DSPs on adapter */
592 iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
597 /************************************************************************/
600 static void adapter_get_asserts(struct hpi_adapter_obj *pao,
601 struct hpi_message *phm, struct hpi_response *phr)
603 #ifndef HIDE_PCI_ASSERTS
604 /* if we have PCI2040 asserts then collect them */
605 if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
606 phr->u.ax.assert.p1 =
607 gw_pci_read_asserts * 100 + gw_pci_write_asserts;
608 phr->u.ax.assert.p2 = 0;
609 phr->u.ax.assert.count = 1; /* assert count */
610 phr->u.ax.assert.dsp_index = -1; /* "dsp index" */
611 strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
612 phr->u.ax.assert.dsp_msg_addr = 0;
613 gw_pci_read_asserts = 0;
614 gw_pci_write_asserts = 0;
618 hw_message(pao, phm, phr); /*get DSP asserts */
623 /************************************************************************/
626 static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
629 struct hpi_hw_obj *phw = pao->priv;
636 u32 test_addr = 0x80000000;
637 u32 test_data = 0x00000001;
638 u32 dw2040_reset = 0;
641 u32 adapter_info = 0;
644 struct dsp_code dsp_code;
645 u16 boot_load_family = 0;
647 /* NOTE don't use wAdapterType in this routine. It is not setup yet */
649 switch (pao->pci.pci_dev->subsystem_device) {
651 case 0x5110: /* ASI5100 revB or higher with C6711D */
652 case 0x5200: /* ASI5200 PCIe version of ASI5100 */
655 boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
658 return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
661 /* reset all DSPs, indicate two DSPs are present
662 * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
665 dw2040_reset = 0x0003000F;
666 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
668 /* read back register to make sure PCI2040 chip is functioning
669 * note that bits 4..15 are read-only and so should always return zero,
670 * even though we wrote 1 to them
672 hpios_delay_micro_seconds(1000);
673 delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
675 if (delay != dw2040_reset) {
676 HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
678 return HPI6000_ERROR_INIT_PCI2040;
681 /* Indicate that DSP#0,1 is a C6X */
682 iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
683 /* set Bit30 and 29 - which will prevent Target aborts from being
684 * issued upon HPI or GP error
686 iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
688 /* isolate DSP HAD8 line from PCI2040 so that
689 * Little endian can be set by pullup
691 dw2040_reset = dw2040_reset & (~(endian << 3));
692 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
694 phw->ado[0].c_dsp_rev = 'B'; /* revB */
695 phw->ado[1].c_dsp_rev = 'B'; /* revB */
697 /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
698 dw2040_reset = dw2040_reset & (~0x00000001); /* start DSP 0 */
699 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
700 dw2040_reset = dw2040_reset & (~0x00000002); /* start DSP 1 */
701 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
703 /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
704 dw2040_reset = dw2040_reset & (~0x00000008);
705 iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
706 /*delay to allow DSP to get going */
707 hpios_delay_micro_seconds(100);
709 /* loop through all DSPs, downloading DSP code */
710 for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
711 struct dsp_obj *pdo = &phw->ado[dsp_index];
713 /* configure DSP so that we download code into the SRAM */
714 /* set control reg for little endian, HWOB=1 */
715 iowrite32(0x00010001, pdo->prHPI_control);
717 /* test access to the HPI address register (HPIA) */
718 test_data = 0x00000001;
719 for (j = 0; j < 32; j++) {
720 iowrite32(test_data, pdo->prHPI_address);
721 data = ioread32(pdo->prHPI_address);
722 if (data != test_data) {
723 HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
724 test_data, data, dsp_index);
725 return HPI6000_ERROR_INIT_DSPHPI;
727 test_data = test_data << 1;
730 /* if C6713 the setup PLL to generate 225MHz from 25MHz.
731 * Since the PLLDIV1 read is sometimes wrong, even on a C6713,
732 * we're going to do this unconditionally
734 /* PLLDIV1 should have a value of 8000 after reset */
736 if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
739 /* C6713 datasheet says we cannot program PLL from HPI,
740 * and indeed if we try to set the PLL multiply from the
741 * HPI, the PLL does not seem to lock,
742 * so we enable the PLL and use the default of x 7
745 hpi_write_word(pdo, 0x01B7C100, 0x0000);
746 hpios_delay_micro_seconds(100);
748 /* ** use default of PLL x7 ** */
749 /* EMIF = 225/3=75MHz */
750 hpi_write_word(pdo, 0x01B7C120, 0x8002);
751 hpios_delay_micro_seconds(100);
754 hpi_write_word(pdo, 0x01B7C11C, 0x8001);
755 hpios_delay_micro_seconds(100);
758 hpi_write_word(pdo, 0x01B7C118, 0x8000);
761 hpios_delay_micro_seconds(2000);
763 /* PLL not bypassed */
764 hpi_write_word(pdo, 0x01B7C100, 0x0001);
766 hpios_delay_micro_seconds(2000);
769 /* test r/w to internal DSP memory
770 * C6711 has L2 cache mapped to 0x0 when reset
772 * revB - because of bug 3.0.1 last HPI read
773 * (before HPI address issued) must be non-autoinc
775 /* test each bit in the 32bit word */
776 for (i = 0; i < 100; i++) {
777 test_addr = 0x00000000;
778 test_data = 0x00000001;
779 for (j = 0; j < 32; j++) {
780 hpi_write_word(pdo, test_addr + i, test_data);
781 data = hpi_read_word(pdo, test_addr + i);
782 if (data != test_data) {
784 "DSP mem %x %x %x %x\n",
785 test_addr + i, test_data,
788 return HPI6000_ERROR_INIT_DSPINTMEM;
790 test_data = test_data << 1;
794 /* memory map of ASI6200
795 00000000-0000FFFF 16Kx32 internal program
796 01800000-019FFFFF Internal peripheral
797 80000000-807FFFFF CE0 2Mx32 SDRAM running @ 100MHz
798 90000000-9000FFFF CE1 Async peripherals:
806 3 CLK2EN = 1 CLKOUT2 enabled
807 4 CLK1EN = 0 CLKOUT1 disabled
808 5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
810 7 NOHOLD = 1 external HOLD disabled
811 8 HOLDA = 0 HOLDA output is low
812 9 HOLD = 0 HOLD input is low
813 10 ARDY = 1 ARDY input is high
814 11 BUSREQ = 0 BUSREQ output is low
817 hpi_write_word(pdo, 0x01800000, 0x34A8);
819 /* EMIF CE0 setup - 2Mx32 Sync DRAM
826 7..4 MTYPE 0011 Sync DRAM 32bits
830 hpi_write_word(pdo, 0x01800008, 0x00000030);
832 /* EMIF SDRAM Extension
842 6-5 TWR = 2-1 = 01b (tWR = 10ns)
843 4 TRRD = 0b = 2 ECLK (tRRD = 14ns)
844 3-1 TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
845 1 CAS latency = 3 ECLK
846 (for Micron 2M32-7 operating at 100Mhz)
849 /* need to use this else DSP code crashes */
850 hpi_write_word(pdo, 0x01800020, 0x001BDF29);
852 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
855 29..28 SDRSZ 00 11 row address pins
856 27..26 SDCSZ 01 8 column address pins
857 25 RFEN 1 refersh enabled
864 /* need to use this else DSP code crashes */
865 hpi_write_word(pdo, 0x01800018, 0x47117000);
867 /* EMIF SDRAM Refresh Timing */
868 hpi_write_word(pdo, 0x0180001C, 0x00000410);
870 /*MIF CE1 setup - Async peripherals
871 @100MHz bus speed, each cycle is 10ns,
873 27..22 Wr strobe = 3 30ns
877 13..8 Rd strobe = 3 30ns
878 7..4 MTYPE 0010 Async 32bits
884 (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
885 16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
886 hpi_write_word(pdo, 0x01800004, cE1);
889 /* delay a little to allow SDRAM and DSP to "get going" */
890 hpios_delay_micro_seconds(1000);
892 /* test access to SDRAM */
894 test_addr = 0x80000000;
895 test_data = 0x00000001;
896 /* test each bit in the 32bit word */
897 for (j = 0; j < 32; j++) {
898 hpi_write_word(pdo, test_addr, test_data);
899 data = hpi_read_word(pdo, test_addr);
900 if (data != test_data) {
902 "DSP dram %x %x %x %x\n",
903 test_addr, test_data, data,
906 return HPI6000_ERROR_INIT_SDRAM1;
908 test_data = test_data << 1;
910 /* test every Nth address in the DRAM */
911 #define DRAM_SIZE_WORDS 0x200000 /*2_mx32 */
912 #define DRAM_INC 1024
913 test_addr = 0x80000000;
915 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
916 hpi_write_word(pdo, test_addr + i, test_data);
919 test_addr = 0x80000000;
921 for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
922 data = hpi_read_word(pdo, test_addr + i);
923 if (data != test_data) {
925 "DSP dram %x %x %x %x\n",
926 test_addr + i, test_data,
928 return HPI6000_ERROR_INIT_SDRAM2;
935 /* write the DSP code down into the DSPs memory */
936 error = hpi_dsp_code_open(boot_load_family, pao->pci.pci_dev,
937 &dsp_code, pos_error_code);
948 error = hpi_dsp_code_read_word(&dsp_code, &length);
951 if (length == 0xFFFFFFFF)
952 break; /* end of code */
954 error = hpi_dsp_code_read_word(&dsp_code, &address);
957 error = hpi_dsp_code_read_word(&dsp_code, &type);
960 error = hpi_dsp_code_read_block(length, &dsp_code,
964 error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
965 address, pcode, length);
971 hpi_dsp_code_close(&dsp_code);
974 /* verify that code was written correctly */
975 /* this time through, assume no errors in DSP code file/array */
976 hpi_dsp_code_rewind(&dsp_code);
983 hpi_dsp_code_read_word(&dsp_code, &length);
984 if (length == 0xFFFFFFFF)
985 break; /* end of code */
987 hpi_dsp_code_read_word(&dsp_code, &address);
988 hpi_dsp_code_read_word(&dsp_code, &type);
989 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
991 for (i = 0; i < length; i++) {
992 data = hpi_read_word(pdo, address);
993 if (data != *pcode) {
994 error = HPI6000_ERROR_INIT_VERIFY;
996 "DSP verify %x %x %x %x\n",
997 address, *pcode, data,
1007 hpi_dsp_code_close(&dsp_code);
1011 /* zero out the hostmailbox */
1013 u32 address = HPI_HIF_ADDR(host_cmd);
1014 for (i = 0; i < 4; i++) {
1015 hpi_write_word(pdo, address, 0);
1019 /* write the DSP number into the hostmailbox */
1020 /* structure before starting the DSP */
1021 hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
1023 /* write the DSP adapter Info into the */
1024 /* hostmailbox before starting the DSP */
1026 hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
1029 /* step 3. Start code by sending interrupt */
1030 iowrite32(0x00030003, pdo->prHPI_control);
1031 hpios_delay_micro_seconds(10000);
1033 /* wait for a non-zero value in hostcmd -
1034 * indicating initialization is complete
1036 * Init could take a while if DSP checks SDRAM memory
1037 * Was 200000. Increased to 2000000 for ASI8801 so we
1038 * don't get 938 errors.
1043 read = hpi_read_word(pdo,
1044 HPI_HIF_ADDR(host_cmd));
1046 && hpi6000_check_PCI2040_error_flag(pao,
1051 /* The following is a workaround for bug #94:
1052 * Bluescreen on install and subsequent boots on a
1053 * DELL PowerEdge 600SC PC with 1.8GHz P4 and
1054 * ServerWorks chipset. Without this delay the system
1055 * locks up with a bluescreen (NOT GPF or pagefault).
1058 hpios_delay_micro_seconds(10000);
1061 return HPI6000_ERROR_INIT_NOACK;
1063 /* read the DSP adapter Info from the */
1064 /* hostmailbox structure after starting the DSP */
1065 if (dsp_index == 0) {
1066 /*u32 dwTestData=0; */
1071 HPI_HIF_ADDR(adapter_info));
1072 if (HPI_ADAPTER_FAMILY_ASI
1073 (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
1075 HPI_ADAPTER_FAMILY_ASI(0x6200))
1076 /* all 6200 cards have this many DSPs */
1079 /* test that the PLD is programmed */
1080 /* and we can read/write 24bits */
1081 #define PLD_BASE_ADDRESS 0x90000000L /*for ASI6100/6200/8800 */
1083 switch (boot_load_family) {
1084 case HPI_ADAPTER_FAMILY_ASI(0x6200):
1085 /* ASI6100/6200 has 24bit path to FPGA */
1087 /* ASI5100 uses AX6 code, */
1088 /* but has no PLD r/w register to test */
1089 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1090 subsystem_device) ==
1091 HPI_ADAPTER_FAMILY_ASI(0x5100))
1093 /* ASI5200 uses AX6 code, */
1094 /* but has no PLD r/w register to test */
1095 if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
1096 subsystem_device) ==
1097 HPI_ADAPTER_FAMILY_ASI(0x5200))
1100 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1101 /* ASI8800 has 16bit path to FPGA */
1105 test_data = 0xAAAAAA00L & mask;
1106 /* write to 24 bit Debug register (D31-D8) */
1107 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1108 read = hpi_read_word(pdo,
1109 PLD_BASE_ADDRESS + 4L) & mask;
1110 if (read != test_data) {
1111 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1113 return HPI6000_ERROR_INIT_PLDTEST1;
1115 test_data = 0x55555500L & mask;
1116 hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
1117 read = hpi_read_word(pdo,
1118 PLD_BASE_ADDRESS + 4L) & mask;
1119 if (read != test_data) {
1120 HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
1122 return HPI6000_ERROR_INIT_PLDTEST2;
1129 #define PCI_TIMEOUT 100
1131 static int hpi_set_address(struct dsp_obj *pdo, u32 address)
1133 u32 timeout = PCI_TIMEOUT;
1136 iowrite32(address, pdo->prHPI_address);
1137 } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
1147 /* write one word to the HPI port */
1148 static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
1150 if (hpi_set_address(pdo, address))
1152 iowrite32(data, pdo->prHPI_data);
1155 /* read one word from the HPI port */
1156 static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
1160 if (hpi_set_address(pdo, address))
1161 return 0; /*? No way to return error */
1163 /* take care of errata in revB DSP (2.0.1) */
1164 data = ioread32(pdo->prHPI_data);
1168 /* write a block of 32bit words to the DSP HPI port using auto-inc mode */
1169 static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1172 u16 length16 = length - 1;
1177 if (hpi_set_address(pdo, address))
1180 iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1182 /* take care of errata in revB DSP (2.0.1) */
1183 /* must end with non auto-inc */
1184 iowrite32(*(pdata + length - 1), pdo->prHPI_data);
1187 /** read a block of 32bit words from the DSP HPI port using auto-inc mode
1189 static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
1192 u16 length16 = length - 1;
1197 if (hpi_set_address(pdo, address))
1200 ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
1202 /* take care of errata in revB DSP (2.0.1) */
1203 /* must end with non auto-inc */
1204 *(pdata + length - 1) = ioread32(pdo->prHPI_data);
1207 static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
1208 u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
1210 struct hpi_hw_obj *phw = pao->priv;
1211 struct dsp_obj *pdo = &phw->ado[dsp_index];
1212 u32 time_out = PCI_TIMEOUT;
1213 int c6711_burst_size = 128;
1214 u32 local_hpi_address = hpi_address;
1215 int local_count = count;
1217 u32 *pdata = source;
1219 while (local_count) {
1220 if (local_count > c6711_burst_size)
1221 xfer_size = c6711_burst_size;
1223 xfer_size = local_count;
1225 time_out = PCI_TIMEOUT;
1227 hpi_write_block(pdo, local_hpi_address, pdata,
1229 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1235 local_hpi_address += sizeof(u32) * xfer_size;
1236 local_count -= xfer_size;
1245 static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
1246 u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
1248 struct hpi_hw_obj *phw = pao->priv;
1249 struct dsp_obj *pdo = &phw->ado[dsp_index];
1250 u32 time_out = PCI_TIMEOUT;
1251 int c6711_burst_size = 16;
1252 u32 local_hpi_address = hpi_address;
1253 int local_count = count;
1257 while (local_count) {
1258 if (local_count > c6711_burst_size)
1259 xfer_size = c6711_burst_size;
1261 xfer_size = local_count;
1263 time_out = PCI_TIMEOUT;
1265 hpi_read_block(pdo, local_hpi_address, pdata,
1267 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1273 local_hpi_address += sizeof(u32) * xfer_size;
1274 local_count -= xfer_size;
1283 static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
1284 u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
1286 struct hpi_hw_obj *phw = pao->priv;
1287 struct dsp_obj *pdo = &phw->ado[dsp_index];
1295 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1296 if (ack & HPI_HIF_ERROR_MASK) {
1298 return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
1300 pao->dsp_crashed = 0;
1302 /* get the message address and size */
1303 if (phw->message_buffer_address_on_dsp == 0) {
1308 HPI_HIF_ADDR(message_buffer_address));
1309 phw->message_buffer_address_on_dsp = address;
1310 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1313 return HPI6000_ERROR_MSG_GET_ADR;
1315 address = phw->message_buffer_address_on_dsp;
1319 /* send the message */
1320 p_data = (u32 *)phm;
1321 if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
1323 return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
1325 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
1326 return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
1327 hpi6000_send_dsp_interrupt(pdo);
1329 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
1330 if (ack & HPI_HIF_ERROR_MASK)
1331 return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
1333 /* get the response address */
1334 if (phw->response_buffer_address_on_dsp == 0) {
1339 HPI_HIF_ADDR(response_buffer_address));
1340 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1342 phw->response_buffer_address_on_dsp = address;
1345 return HPI6000_ERROR_RESP_GET_ADR;
1347 address = phw->response_buffer_address_on_dsp;
1349 /* read the length of the response back from the DSP */
1352 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1353 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1355 return HPI6000_ERROR_RESP_GET_LEN;
1357 if (length > phr->size)
1358 return HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
1360 /* get the response */
1361 p_data = (u32 *)phr;
1362 if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
1364 return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
1366 /* set i/f back to idle */
1367 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1368 return HPI6000_ERROR_MSG_RESP_IDLECMD;
1369 hpi6000_send_dsp_interrupt(pdo);
1371 error = hpi_validate_response(phm, phr);
1375 /* have to set up the below defines to match stuff in the MAP file */
1377 #define MSG_ADDRESS (HPI_HIF_BASE+0x18)
1378 #define MSG_LENGTH 11
1379 #define RESP_ADDRESS (HPI_HIF_BASE+0x44)
1380 #define RESP_LENGTH 16
1381 #define QUEUE_START (HPI_HIF_BASE+0x88)
1382 #define QUEUE_SIZE 0x8000
1384 static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
1386 /*#define CHECKING // comment this line in to enable checking */
1388 if (address < (u32)MSG_ADDRESS)
1390 if (address > (u32)(QUEUE_START + QUEUE_SIZE))
1392 if ((address + (length_in_dwords << 2)) >
1393 (u32)(QUEUE_START + QUEUE_SIZE))
1397 (void)length_in_dwords;
1402 static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1403 struct hpi_message *phm, struct hpi_response *phr)
1405 struct hpi_hw_obj *phw = pao->priv;
1406 struct dsp_obj *pdo = &phw->ado[dsp_index];
1409 u32 length, address;
1410 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1415 /* round dwDataSize down to nearest 4 bytes */
1416 while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
1418 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1419 if (ack & HPI_HIF_ERROR_MASK)
1420 return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
1422 if (hpi6000_send_host_command(pao, dsp_index,
1424 return HPI6000_ERROR_SEND_DATA_CMD;
1426 hpi6000_send_dsp_interrupt(pdo);
1428 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
1430 if (ack & HPI_HIF_ERROR_MASK)
1431 return HPI6000_ERROR_SEND_DATA_ACK;
1434 /* get the address and size */
1435 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1436 /* DSP returns number of DWORDS */
1437 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1438 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1440 if (!hpi6000_send_data_check_adr(address, length))
1441 return HPI6000_ERROR_SEND_DATA_ADR;
1443 /* send the data. break data into 512 DWORD blocks (2K bytes)
1444 * and send using block write. 2Kbytes is the max as this is the
1445 * memory window given to the HPI data register by the PCI2040
1454 if (hpi6000_dsp_block_write32(pao, dsp_index,
1455 address, p_data, blk_len))
1456 return HPI6000_ERROR_SEND_DATA_WRITE;
1457 address += blk_len * 4;
1463 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1464 return HPI6000_ERROR_SEND_DATA_IDLECMD;
1466 hpi6000_send_dsp_interrupt(pdo);
1468 data_sent += length * 4;
1471 return HPI6000_ERROR_SEND_DATA_TIMEOUT;
1475 static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
1476 struct hpi_message *phm, struct hpi_response *phr)
1478 struct hpi_hw_obj *phw = pao->priv;
1479 struct dsp_obj *pdo = &phw->ado[dsp_index];
1482 u32 length, address;
1483 u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
1485 (void)phr; /* this parameter not used! */
1487 /* round dwDataSize down to nearest 4 bytes */
1488 while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
1489 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
1490 if (ack & HPI_HIF_ERROR_MASK)
1491 return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
1493 if (hpi6000_send_host_command(pao, dsp_index,
1495 return HPI6000_ERROR_GET_DATA_CMD;
1496 hpi6000_send_dsp_interrupt(pdo);
1498 ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
1500 if (ack & HPI_HIF_ERROR_MASK)
1501 return HPI6000_ERROR_GET_DATA_ACK;
1503 /* get the address and size */
1505 address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
1506 length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
1507 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
1516 if (hpi6000_dsp_block_read32(pao, dsp_index,
1517 address, p_data, blk_len))
1518 return HPI6000_ERROR_GET_DATA_READ;
1519 address += blk_len * 4;
1525 if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
1526 return HPI6000_ERROR_GET_DATA_IDLECMD;
1527 hpi6000_send_dsp_interrupt(pdo);
1529 data_got += length * 4;
1534 static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
1536 iowrite32(0x00030003, pdo->prHPI_control); /* DSPINT */
1539 static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
1540 u16 dsp_index, u32 host_cmd)
1542 struct hpi_hw_obj *phw = pao->priv;
1543 struct dsp_obj *pdo = &phw->ado[dsp_index];
1544 u32 timeout = TIMEOUT;
1548 hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
1549 /* flush the FIFO */
1550 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1551 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
1553 /* reset the interrupt bit */
1554 iowrite32(0x00040004, pdo->prHPI_control);
1562 /* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
1563 static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
1568 struct hpi_hw_obj *phw = pao->priv;
1570 /* read the error bits from the PCI2040 */
1571 hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1573 /* reset the error flag */
1574 iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
1575 phw->pCI2040HPI_error_count++;
1576 if (read_or_write == 1)
1577 gw_pci_read_asserts++; /************* inc global */
1579 gw_pci_write_asserts++;
1585 static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
1588 struct hpi_hw_obj *phw = pao->priv;
1589 struct dsp_obj *pdo = &phw->ado[dsp_index];
1594 /* wait for host interrupt to signal ack is ready */
1597 hPIC = ioread32(pdo->prHPI_control);
1598 if (hPIC & 0x04) /* 0x04 = HINT from DSP */
1602 return HPI_HIF_ERROR_MASK;
1604 /* wait for dwAckValue */
1607 /* read the ack mailbox */
1608 ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
1609 if (ack == ack_value)
1611 if ((ack & HPI_HIF_ERROR_MASK)
1612 && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
1614 /*for (i=0;i<1000;i++) */
1617 if (ack & HPI_HIF_ERROR_MASK)
1618 /* indicates bad read from DSP -
1619 typically 0xffffff is read for some reason */
1620 ack = HPI_HIF_ERROR_MASK;
1623 ack = HPI_HIF_ERROR_MASK;
1627 static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
1628 struct hpi_message *phm)
1630 const u16 dsp_index = 0;
1631 struct hpi_hw_obj *phw = pao->priv;
1632 struct dsp_obj *pdo = &phw->ado[dsp_index];
1634 u32 cache_dirty_flag;
1637 hpios_dsplock_lock(pao);
1642 hpi_read_word((struct dsp_obj *)pdo,
1643 HPI_HIF_ADDR(control_cache_is_dirty));
1644 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
1646 err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
1650 if (cache_dirty_flag) {
1651 /* read the cached controls */
1656 if (pdo->control_cache_address_on_dsp == 0) {
1659 hpi_read_word((struct dsp_obj *)pdo,
1660 HPI_HIF_ADDR(control_cache_address));
1662 length = hpi_read_word((struct dsp_obj *)pdo,
1664 (control_cache_size_in_bytes));
1665 } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
1668 err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
1671 pdo->control_cache_address_on_dsp = address;
1672 pdo->control_cache_length_on_dsp = length;
1674 address = pdo->control_cache_address_on_dsp;
1675 length = pdo->control_cache_length_on_dsp;
1678 if (hpi6000_dsp_block_read32(pao, dsp_index, address,
1679 (u32 *)&phw->control_cache[0],
1680 length / sizeof(u32))) {
1681 err = HPI6000_ERROR_CONTROL_CACHE_READ;
1685 hpi_write_word((struct dsp_obj *)pdo,
1686 HPI_HIF_ADDR(control_cache_is_dirty), 0);
1687 /* flush the FIFO */
1688 hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
1689 } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
1692 err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
1700 hpios_dsplock_unlock(pao);
1704 /** Get dsp index for multi DSP adapters only */
1705 static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
1708 switch (phm->object) {
1709 case HPI_OBJ_ISTREAM:
1710 if (phm->obj_index < 2)
1713 case HPI_OBJ_PROFILE:
1714 ret = phm->obj_index;
1722 /** Complete transaction with DSP
1724 Send message, get response, send or get stream data if any.
1726 static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
1727 struct hpi_response *phr)
1731 struct hpi_hw_obj *phw = pao->priv;
1732 u16 num_dsp = phw->num_dsp;
1737 dsp_index = get_dsp_index(pao, phm);
1739 /* is this checked on the DSP anyway? */
1740 if ((phm->function == HPI_ISTREAM_GROUP_ADD)
1741 || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
1742 struct hpi_message hm;
1744 hm.obj_index = phm->u.d.u.stream.stream_index;
1745 hm.object = phm->u.d.u.stream.object_type;
1746 add_index = get_dsp_index(pao, &hm);
1747 if (add_index != dsp_index) {
1748 phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
1754 hpios_dsplock_lock(pao);
1755 error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
1757 if (error) /* something failed in the HPI/DSP interface */
1760 if (phr->error) /* something failed in the DSP */
1763 switch (phm->function) {
1764 case HPI_OSTREAM_WRITE:
1765 case HPI_ISTREAM_ANC_WRITE:
1766 error = hpi6000_send_data(pao, dsp_index, phm, phr);
1768 case HPI_ISTREAM_READ:
1769 case HPI_OSTREAM_ANC_READ:
1770 error = hpi6000_get_data(pao, dsp_index, phm, phr);
1772 case HPI_ADAPTER_GET_ASSERT:
1773 phr->u.ax.assert.dsp_index = 0; /* dsp 0 default */
1775 if (!phr->u.ax.assert.count) {
1776 /* no assert from dsp 0, check dsp 1 */
1777 error = hpi6000_message_response_sequence(pao,
1779 phr->u.ax.assert.dsp_index = 1;
1786 if (error >= HPI_ERROR_BACKEND_BASE) {
1787 phr->error = HPI_ERROR_DSP_COMMUNICATION;
1788 phr->specific_error = error;
1793 /* just the header of the response is valid */
1794 phr->size = sizeof(struct hpi_response_header);
1797 hpios_dsplock_unlock(pao);