1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 Hardware Programming Interface (HPI) for AudioScience
20 ASI50xx, AS51xx, ASI6xxx, ASI87xx ASI89xx series adapters.
21 These PCI and PCIe bus adapters are based on a
22 TMS320C6205 PCI bus mastering DSP,
23 and (except ASI50xx) TI TMS320C6xxx floating point DSP
26 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
28 (C) Copyright AudioScience Inc. 1998-2010
29 *******************************************************************************/
30 #define SOURCEFILE_NAME "hpi6205.c"
32 #include "hpi_internal.h"
33 #include "hpimsginit.h"
39 /*****************************************************************************/
40 /* HPI6205 specific error codes */
41 #define HPI6205_ERROR_BASE 1000
42 /*#define HPI6205_ERROR_MEM_ALLOC 1001 */
43 #define HPI6205_ERROR_6205_NO_IRQ 1002
44 #define HPI6205_ERROR_6205_INIT_FAILED 1003
45 /*#define HPI6205_ERROR_MISSING_DSPCODE 1004 */
46 #define HPI6205_ERROR_UNKNOWN_PCI_DEVICE 1005
47 #define HPI6205_ERROR_6205_REG 1006
48 #define HPI6205_ERROR_6205_DSPPAGE 1007
49 #define HPI6205_ERROR_BAD_DSPINDEX 1008
50 #define HPI6205_ERROR_C6713_HPIC 1009
51 #define HPI6205_ERROR_C6713_HPIA 1010
52 #define HPI6205_ERROR_C6713_PLL 1011
53 #define HPI6205_ERROR_DSP_INTMEM 1012
54 #define HPI6205_ERROR_DSP_EXTMEM 1013
55 #define HPI6205_ERROR_DSP_PLD 1014
56 #define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
57 #define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
58 #define HPI6205_ERROR_6205_EEPROM 1017
59 #define HPI6205_ERROR_DSP_EMIF 1018
61 #define hpi6205_error(dsp_index, err) (err)
62 /*****************************************************************************/
63 /* for C6205 PCI i/f */
64 /* Host Status Register (HSR) bitfields */
65 #define C6205_HSR_INTSRC 0x01
66 #define C6205_HSR_INTAVAL 0x02
67 #define C6205_HSR_INTAM 0x04
68 #define C6205_HSR_CFGERR 0x08
69 #define C6205_HSR_EEREAD 0x10
70 /* Host-to-DSP Control Register (HDCR) bitfields */
71 #define C6205_HDCR_WARMRESET 0x01
72 #define C6205_HDCR_DSPINT 0x02
73 #define C6205_HDCR_PCIBOOT 0x04
74 /* DSP Page Register (DSPP) bitfields, */
75 /* defines 4 Mbyte page that BAR0 points to */
76 #define C6205_DSPP_MAP1 0x400
78 /* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
79 * BAR1 maps to non-prefetchable 8 Mbyte memory block
80 * of DSP memory mapped registers (starting at 0x01800000).
81 * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
82 * needs to be added to the BAR1 base address set in the PCI config reg
84 #define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
85 #define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
86 #define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
87 #define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
89 /* used to control LED (revA) and reset C6713 (revB) */
90 #define C6205_BAR0_TIMER1_CTL (0x01980000L)
92 /* For first 6713 in CE1 space, using DA17,16,2 */
93 #define HPICL_ADDR 0x01400000L
94 #define HPICH_ADDR 0x01400004L
95 #define HPIAL_ADDR 0x01410000L
96 #define HPIAH_ADDR 0x01410004L
97 #define HPIDIL_ADDR 0x01420000L
98 #define HPIDIH_ADDR 0x01420004L
99 #define HPIDL_ADDR 0x01430000L
100 #define HPIDH_ADDR 0x01430004L
102 #define C6713_EMIF_GCTL 0x01800000
103 #define C6713_EMIF_CE1 0x01800004
104 #define C6713_EMIF_CE0 0x01800008
105 #define C6713_EMIF_CE2 0x01800010
106 #define C6713_EMIF_CE3 0x01800014
107 #define C6713_EMIF_SDRAMCTL 0x01800018
108 #define C6713_EMIF_SDRAMTIMING 0x0180001C
109 #define C6713_EMIF_SDRAMEXT 0x01800020
119 struct consistent_dma_area h_locked_mem
;
120 struct bus_master_interface
*p_interface_buffer
;
122 u16 flag_outstream_just_reset
[HPI_MAX_STREAMS
];
123 /* a non-NULL handle means there is an HPI allocated buffer */
124 struct consistent_dma_area instream_host_buffers
[HPI_MAX_STREAMS
];
125 struct consistent_dma_area outstream_host_buffers
[HPI_MAX_STREAMS
];
126 /* non-zero size means a buffer exists, may be external */
127 u32 instream_host_buffer_size
[HPI_MAX_STREAMS
];
128 u32 outstream_host_buffer_size
[HPI_MAX_STREAMS
];
130 struct consistent_dma_area h_control_cache
;
131 struct consistent_dma_area h_async_event_buffer
;
132 /* struct hpi_control_cache_single *pControlCache; */
133 struct hpi_async_event
*p_async_event_buffer
;
134 struct hpi_control_cache
*p_cache
;
137 /*****************************************************************************/
138 /* local prototypes */
140 #define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
142 static int wait_dsp_ack(struct hpi_hw_obj
*phw
, int state
, int timeout_us
);
144 static void send_dsp_command(struct hpi_hw_obj
*phw
, int cmd
);
146 static u16
adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
147 u32
*pos_error_code
);
149 static u16
message_response_sequence(struct hpi_adapter_obj
*pao
,
150 struct hpi_message
*phm
, struct hpi_response
*phr
);
152 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
153 struct hpi_response
*phr
);
155 #define HPI6205_TIMEOUT 1000000
157 static void subsys_create_adapter(struct hpi_message
*phm
,
158 struct hpi_response
*phr
);
159 static void subsys_delete_adapter(struct hpi_message
*phm
,
160 struct hpi_response
*phr
);
162 static u16
create_adapter_obj(struct hpi_adapter_obj
*pao
,
163 u32
*pos_error_code
);
165 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
);
167 static void outstream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
168 struct hpi_message
*phm
, struct hpi_response
*phr
);
170 static void outstream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
171 struct hpi_message
*phm
, struct hpi_response
*phr
);
173 static void outstream_host_buffer_free(struct hpi_adapter_obj
*pao
,
174 struct hpi_message
*phm
, struct hpi_response
*phr
);
175 static void outstream_write(struct hpi_adapter_obj
*pao
,
176 struct hpi_message
*phm
, struct hpi_response
*phr
);
178 static void outstream_get_info(struct hpi_adapter_obj
*pao
,
179 struct hpi_message
*phm
, struct hpi_response
*phr
);
181 static void outstream_start(struct hpi_adapter_obj
*pao
,
182 struct hpi_message
*phm
, struct hpi_response
*phr
);
184 static void outstream_open(struct hpi_adapter_obj
*pao
,
185 struct hpi_message
*phm
, struct hpi_response
*phr
);
187 static void outstream_reset(struct hpi_adapter_obj
*pao
,
188 struct hpi_message
*phm
, struct hpi_response
*phr
);
190 static void instream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
191 struct hpi_message
*phm
, struct hpi_response
*phr
);
193 static void instream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
194 struct hpi_message
*phm
, struct hpi_response
*phr
);
196 static void instream_host_buffer_free(struct hpi_adapter_obj
*pao
,
197 struct hpi_message
*phm
, struct hpi_response
*phr
);
199 static void instream_read(struct hpi_adapter_obj
*pao
,
200 struct hpi_message
*phm
, struct hpi_response
*phr
);
202 static void instream_get_info(struct hpi_adapter_obj
*pao
,
203 struct hpi_message
*phm
, struct hpi_response
*phr
);
205 static void instream_start(struct hpi_adapter_obj
*pao
,
206 struct hpi_message
*phm
, struct hpi_response
*phr
);
208 static u32
boot_loader_read_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
211 static u16
boot_loader_write_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
212 u32 address
, u32 data
);
214 static u16
boot_loader_config_emif(struct hpi_adapter_obj
*pao
,
217 static u16
boot_loader_test_memory(struct hpi_adapter_obj
*pao
, int dsp_index
,
218 u32 address
, u32 length
);
220 static u16
boot_loader_test_internal_memory(struct hpi_adapter_obj
*pao
,
223 static u16
boot_loader_test_external_memory(struct hpi_adapter_obj
*pao
,
226 static u16
boot_loader_test_pld(struct hpi_adapter_obj
*pao
, int dsp_index
);
228 /*****************************************************************************/
230 static void subsys_message(struct hpi_message
*phm
, struct hpi_response
*phr
)
233 switch (phm
->function
) {
234 case HPI_SUBSYS_OPEN
:
235 case HPI_SUBSYS_CLOSE
:
236 case HPI_SUBSYS_GET_INFO
:
237 case HPI_SUBSYS_DRIVER_UNLOAD
:
238 case HPI_SUBSYS_DRIVER_LOAD
:
239 case HPI_SUBSYS_FIND_ADAPTERS
:
240 /* messages that should not get here */
241 phr
->error
= HPI_ERROR_UNIMPLEMENTED
;
243 case HPI_SUBSYS_CREATE_ADAPTER
:
244 subsys_create_adapter(phm
, phr
);
246 case HPI_SUBSYS_DELETE_ADAPTER
:
247 subsys_delete_adapter(phm
, phr
);
250 phr
->error
= HPI_ERROR_INVALID_FUNC
;
255 static void control_message(struct hpi_adapter_obj
*pao
,
256 struct hpi_message
*phm
, struct hpi_response
*phr
)
259 struct hpi_hw_obj
*phw
= pao
->priv
;
261 switch (phm
->function
) {
262 case HPI_CONTROL_GET_STATE
:
263 if (pao
->has_control_cache
) {
264 rmb(); /* make sure we see updates DM_aed from DSP */
265 if (hpi_check_control_cache(phw
->p_cache
, phm
, phr
))
268 hw_message(pao
, phm
, phr
);
270 case HPI_CONTROL_GET_INFO
:
271 hw_message(pao
, phm
, phr
);
273 case HPI_CONTROL_SET_STATE
:
274 hw_message(pao
, phm
, phr
);
275 if (pao
->has_control_cache
)
276 hpi_sync_control_cache(phw
->p_cache
, phm
, phr
);
279 phr
->error
= HPI_ERROR_INVALID_FUNC
;
284 static void adapter_message(struct hpi_adapter_obj
*pao
,
285 struct hpi_message
*phm
, struct hpi_response
*phr
)
287 switch (phm
->function
) {
289 hw_message(pao
, phm
, phr
);
294 static void outstream_message(struct hpi_adapter_obj
*pao
,
295 struct hpi_message
*phm
, struct hpi_response
*phr
)
298 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
299 phr
->error
= HPI_ERROR_INVALID_STREAM
;
300 HPI_DEBUG_LOG(WARNING
,
301 "message referencing invalid stream %d "
302 "on adapter index %d\n", phm
->obj_index
,
307 switch (phm
->function
) {
308 case HPI_OSTREAM_WRITE
:
309 outstream_write(pao
, phm
, phr
);
311 case HPI_OSTREAM_GET_INFO
:
312 outstream_get_info(pao
, phm
, phr
);
314 case HPI_OSTREAM_HOSTBUFFER_ALLOC
:
315 outstream_host_buffer_allocate(pao
, phm
, phr
);
317 case HPI_OSTREAM_HOSTBUFFER_GET_INFO
:
318 outstream_host_buffer_get_info(pao
, phm
, phr
);
320 case HPI_OSTREAM_HOSTBUFFER_FREE
:
321 outstream_host_buffer_free(pao
, phm
, phr
);
323 case HPI_OSTREAM_START
:
324 outstream_start(pao
, phm
, phr
);
326 case HPI_OSTREAM_OPEN
:
327 outstream_open(pao
, phm
, phr
);
329 case HPI_OSTREAM_RESET
:
330 outstream_reset(pao
, phm
, phr
);
333 hw_message(pao
, phm
, phr
);
338 static void instream_message(struct hpi_adapter_obj
*pao
,
339 struct hpi_message
*phm
, struct hpi_response
*phr
)
342 if (phm
->obj_index
>= HPI_MAX_STREAMS
) {
343 phr
->error
= HPI_ERROR_INVALID_STREAM
;
344 HPI_DEBUG_LOG(WARNING
,
345 "message referencing invalid stream %d "
346 "on adapter index %d\n", phm
->obj_index
,
351 switch (phm
->function
) {
352 case HPI_ISTREAM_READ
:
353 instream_read(pao
, phm
, phr
);
355 case HPI_ISTREAM_GET_INFO
:
356 instream_get_info(pao
, phm
, phr
);
358 case HPI_ISTREAM_HOSTBUFFER_ALLOC
:
359 instream_host_buffer_allocate(pao
, phm
, phr
);
361 case HPI_ISTREAM_HOSTBUFFER_GET_INFO
:
362 instream_host_buffer_get_info(pao
, phm
, phr
);
364 case HPI_ISTREAM_HOSTBUFFER_FREE
:
365 instream_host_buffer_free(pao
, phm
, phr
);
367 case HPI_ISTREAM_START
:
368 instream_start(pao
, phm
, phr
);
371 hw_message(pao
, phm
, phr
);
376 /*****************************************************************************/
377 /** Entry point to this HPI backend
378 * All calls to the HPI start here
380 void HPI_6205(struct hpi_message
*phm
, struct hpi_response
*phr
)
382 struct hpi_adapter_obj
*pao
= NULL
;
384 /* subsytem messages are processed by every HPI.
385 * All other messages are ignored unless the adapter index matches
386 * an adapter in the HPI
388 HPI_DEBUG_LOG(DEBUG
, "HPI obj=%d, func=%d\n", phm
->object
,
391 /* if Dsp has crashed then do not communicate with it any more */
392 if (phm
->object
!= HPI_OBJ_SUBSYSTEM
) {
393 pao
= hpi_find_adapter(phm
->adapter_index
);
396 " %d,%d refused, for another HPI?\n",
397 phm
->object
, phm
->function
);
401 if ((pao
->dsp_crashed
>= 10)
402 && (phm
->function
!= HPI_ADAPTER_DEBUG_READ
)) {
403 /* allow last resort debug read even after crash */
404 hpi_init_response(phr
, phm
->object
, phm
->function
,
405 HPI_ERROR_DSP_HARDWARE
);
406 HPI_DEBUG_LOG(WARNING
, " %d,%d dsp crashed.\n",
407 phm
->object
, phm
->function
);
412 /* Init default response */
413 if (phm
->function
!= HPI_SUBSYS_CREATE_ADAPTER
)
414 hpi_init_response(phr
, phm
->object
, phm
->function
,
415 HPI_ERROR_PROCESSING_MESSAGE
);
417 HPI_DEBUG_LOG(VERBOSE
, "start of switch\n");
419 case HPI_TYPE_MESSAGE
:
420 switch (phm
->object
) {
421 case HPI_OBJ_SUBSYSTEM
:
422 subsys_message(phm
, phr
);
425 case HPI_OBJ_ADAPTER
:
427 sizeof(struct hpi_response_header
) +
428 sizeof(struct hpi_adapter_res
);
429 adapter_message(pao
, phm
, phr
);
432 case HPI_OBJ_CONTROLEX
:
433 case HPI_OBJ_CONTROL
:
434 control_message(pao
, phm
, phr
);
437 case HPI_OBJ_OSTREAM
:
438 outstream_message(pao
, phm
, phr
);
441 case HPI_OBJ_ISTREAM
:
442 instream_message(pao
, phm
, phr
);
446 hw_message(pao
, phm
, phr
);
452 phr
->error
= HPI_ERROR_INVALID_TYPE
;
457 /*****************************************************************************/
460 /** Create an adapter object and initialise it based on resource information
461 * passed in in the message
462 * *** NOTE - you cannot use this function AND the FindAdapters function at the
463 * same time, the application must use only one of them to get the adapters ***
465 static void subsys_create_adapter(struct hpi_message
*phm
,
466 struct hpi_response
*phr
)
468 /* create temp adapter obj, because we don't know what index yet */
469 struct hpi_adapter_obj ao
;
473 HPI_DEBUG_LOG(DEBUG
, " subsys_create_adapter\n");
475 memset(&ao
, 0, sizeof(ao
));
477 /* this HPI only creates adapters for TI/PCI devices */
478 if (phm
->u
.s
.resource
.bus_type
!= HPI_BUS_PCI
)
480 if (phm
->u
.s
.resource
.r
.pci
->vendor_id
!= HPI_PCI_VENDOR_ID_TI
)
482 if (phm
->u
.s
.resource
.r
.pci
->device_id
!= HPI_PCI_DEV_ID_DSP6205
)
485 ao
.priv
= kzalloc(sizeof(struct hpi_hw_obj
), GFP_KERNEL
);
487 HPI_DEBUG_LOG(ERROR
, "cant get mem for adapter object\n");
488 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
492 ao
.pci
= *phm
->u
.s
.resource
.r
.pci
;
493 err
= create_adapter_obj(&ao
, &os_error_code
);
495 err
= hpi_add_adapter(&ao
);
497 phr
->u
.s
.data
= os_error_code
;
498 delete_adapter_obj(&ao
);
503 phr
->u
.s
.aw_adapter_list
[ao
.index
] = ao
.adapter_type
;
504 phr
->u
.s
.adapter_index
= ao
.index
;
505 phr
->u
.s
.num_adapters
++;
509 /** delete an adapter - required by WDM driver */
510 static void subsys_delete_adapter(struct hpi_message
*phm
,
511 struct hpi_response
*phr
)
513 struct hpi_adapter_obj
*pao
;
514 struct hpi_hw_obj
*phw
;
516 pao
= hpi_find_adapter(phm
->adapter_index
);
518 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
521 phw
= (struct hpi_hw_obj
*)pao
->priv
;
522 /* reset adapter h/w */
524 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
526 iowrite32(C6205_HDCR_WARMRESET
, phw
->prHDCR
);
528 delete_adapter_obj(pao
);
532 /** Create adapter object
533 allocate buffers, bootload DSPs, initialise control cache
535 static u16
create_adapter_obj(struct hpi_adapter_obj
*pao
,
538 struct hpi_hw_obj
*phw
= pao
->priv
;
539 struct bus_master_interface
*interface
;
541 #ifndef HPI6205_NO_HSR_POLL
542 u32 time_out
= HPI6205_TIMEOUT
;
548 /* init error reporting */
549 pao
->dsp_crashed
= 0;
551 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
552 phw
->flag_outstream_just_reset
[i
] = 1;
554 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
556 pao
->pci
.ap_mem_base
[1] +
557 C6205_BAR1_HSR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
559 pao
->pci
.ap_mem_base
[1] +
560 C6205_BAR1_HDCR
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
562 pao
->pci
.ap_mem_base
[1] +
563 C6205_BAR1_DSPP
/ sizeof(*pao
->pci
.ap_mem_base
[1]);
565 pao
->has_control_cache
= 0;
567 if (hpios_locked_mem_alloc(&phw
->h_locked_mem
,
568 sizeof(struct bus_master_interface
),
570 phw
->p_interface_buffer
= NULL
;
571 else if (hpios_locked_mem_get_virt_addr(&phw
->h_locked_mem
,
572 (void *)&phw
->p_interface_buffer
))
573 phw
->p_interface_buffer
= NULL
;
575 HPI_DEBUG_LOG(DEBUG
, "interface buffer address %p\n",
576 phw
->p_interface_buffer
);
578 if (phw
->p_interface_buffer
) {
579 memset((void *)phw
->p_interface_buffer
, 0,
580 sizeof(struct bus_master_interface
));
581 phw
->p_interface_buffer
->dsp_ack
= H620_HIF_UNKNOWN
;
584 err
= adapter_boot_load_dsp(pao
, pos_error_code
);
586 /* no need to clean up as SubSysCreateAdapter */
587 /* calls DeleteAdapter on error. */
590 HPI_DEBUG_LOG(INFO
, "load DSP code OK\n");
592 /* allow boot load even if mem alloc wont work */
593 if (!phw
->p_interface_buffer
)
594 return hpi6205_error(0, HPI_ERROR_MEMORY_ALLOC
);
596 interface
= phw
->p_interface_buffer
;
598 #ifndef HPI6205_NO_HSR_POLL
599 /* wait for first interrupt indicating the DSP init is done */
600 time_out
= HPI6205_TIMEOUT
* 10;
602 while (((temp1
& C6205_HSR_INTSRC
) == 0) && --time_out
)
603 temp1
= ioread32(phw
->prHSR
);
605 if (temp1
& C6205_HSR_INTSRC
)
607 "interrupt confirming DSP code running OK\n");
610 "timed out waiting for interrupt "
611 "confirming DSP code running\n");
612 return hpi6205_error(0, HPI6205_ERROR_6205_NO_IRQ
);
615 /* reset the interrupt */
616 iowrite32(C6205_HSR_INTSRC
, phw
->prHSR
);
619 /* make sure the DSP has started ok */
620 if (!wait_dsp_ack(phw
, H620_HIF_RESET
, HPI6205_TIMEOUT
* 10)) {
621 HPI_DEBUG_LOG(ERROR
, "timed out waiting reset state \n");
622 return hpi6205_error(0, HPI6205_ERROR_6205_INIT_FAILED
);
624 /* Note that *pao, *phw are zeroed after allocation,
625 * so pointers and flags are NULL by default.
626 * Allocate bus mastering control cache buffer and tell the DSP about it
628 if (interface
->control_cache
.number_of_controls
) {
629 void *p_control_cache_virtual
;
631 err
= hpios_locked_mem_alloc(&phw
->h_control_cache
,
632 interface
->control_cache
.size_in_bytes
,
635 err
= hpios_locked_mem_get_virt_addr(&phw
->
636 h_control_cache
, &p_control_cache_virtual
);
638 memset(p_control_cache_virtual
, 0,
639 interface
->control_cache
.size_in_bytes
);
642 hpi_alloc_control_cache(interface
->
643 control_cache
.number_of_controls
,
644 interface
->control_cache
.size_in_bytes
,
645 (struct hpi_control_cache_info
*)
646 p_control_cache_virtual
);
649 err
= hpios_locked_mem_get_phys_addr(&phw
->
650 h_control_cache
, &phys_addr
);
651 interface
->control_cache
.physical_address32
=
656 pao
->has_control_cache
= 1;
658 if (hpios_locked_mem_valid(&phw
->h_control_cache
))
659 hpios_locked_mem_free(&phw
->h_control_cache
);
660 pao
->has_control_cache
= 0;
663 /* allocate bus mastering async buffer and tell the DSP about it */
664 if (interface
->async_buffer
.b
.size
) {
665 err
= hpios_locked_mem_alloc(&phw
->h_async_event_buffer
,
666 interface
->async_buffer
.b
.size
*
667 sizeof(struct hpi_async_event
), pao
->pci
.p_os_data
);
669 err
= hpios_locked_mem_get_virt_addr
670 (&phw
->h_async_event_buffer
, (void *)
671 &phw
->p_async_event_buffer
);
673 memset((void *)phw
->p_async_event_buffer
, 0,
674 interface
->async_buffer
.b
.size
*
675 sizeof(struct hpi_async_event
));
677 err
= hpios_locked_mem_get_phys_addr
678 (&phw
->h_async_event_buffer
, &phys_addr
);
679 interface
->async_buffer
.physical_address32
=
683 if (hpios_locked_mem_valid(&phw
->
684 h_async_event_buffer
)) {
685 hpios_locked_mem_free
686 (&phw
->h_async_event_buffer
);
687 phw
->p_async_event_buffer
= NULL
;
691 send_dsp_command(phw
, H620_HIF_IDLE
);
694 struct hpi_message hM
;
695 struct hpi_response hR
;
698 HPI_DEBUG_LOG(VERBOSE
, "init ADAPTER_GET_INFO\n");
699 memset(&hM
, 0, sizeof(hM
));
700 hM
.type
= HPI_TYPE_MESSAGE
;
701 hM
.size
= sizeof(hM
);
702 hM
.object
= HPI_OBJ_ADAPTER
;
703 hM
.function
= HPI_ADAPTER_GET_INFO
;
704 hM
.adapter_index
= 0;
705 memset(&hR
, 0, sizeof(hR
));
706 hR
.size
= sizeof(hR
);
708 err
= message_response_sequence(pao
, &hM
, &hR
);
710 HPI_DEBUG_LOG(ERROR
, "message transport error %d\n",
717 pao
->adapter_type
= hR
.u
.a
.adapter_type
;
718 pao
->index
= hR
.u
.a
.adapter_index
;
720 max_streams
= hR
.u
.a
.num_outstreams
+ hR
.u
.a
.num_instreams
;
722 hpios_locked_mem_prepare((max_streams
* 6) / 10, max_streams
,
723 65536, pao
->pci
.p_os_data
);
725 HPI_DEBUG_LOG(VERBOSE
,
726 "got adapter info type %x index %d serial %d\n",
727 hR
.u
.a
.adapter_type
, hR
.u
.a
.adapter_index
,
728 hR
.u
.a
.serial_number
);
731 pao
->open
= 0; /* upon creation the adapter is closed */
733 HPI_DEBUG_LOG(INFO
, "bootload DSP OK\n");
737 /** Free memory areas allocated by adapter
738 * this routine is called from SubSysDeleteAdapter,
739 * and SubSysCreateAdapter if duplicate index
741 static void delete_adapter_obj(struct hpi_adapter_obj
*pao
)
743 struct hpi_hw_obj
*phw
;
748 if (hpios_locked_mem_valid(&phw
->h_async_event_buffer
)) {
749 hpios_locked_mem_free(&phw
->h_async_event_buffer
);
750 phw
->p_async_event_buffer
= NULL
;
753 if (hpios_locked_mem_valid(&phw
->h_control_cache
)) {
754 hpios_locked_mem_free(&phw
->h_control_cache
);
755 hpi_free_control_cache(phw
->p_cache
);
758 if (hpios_locked_mem_valid(&phw
->h_locked_mem
)) {
759 hpios_locked_mem_free(&phw
->h_locked_mem
);
760 phw
->p_interface_buffer
= NULL
;
763 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
764 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[i
])) {
765 hpios_locked_mem_free(&phw
->instream_host_buffers
[i
]);
766 /*?phw->InStreamHostBuffers[i] = NULL; */
767 phw
->instream_host_buffer_size
[i
] = 0;
770 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++)
771 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[i
])) {
772 hpios_locked_mem_free(&phw
->outstream_host_buffers
774 phw
->outstream_host_buffer_size
[i
] = 0;
777 hpios_locked_mem_unprepare(pao
->pci
.p_os_data
);
779 hpi_delete_adapter(pao
);
783 /*****************************************************************************/
784 /* OutStream Host buffer functions */
786 /** Allocate or attach buffer for busmastering
788 static void outstream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
789 struct hpi_message
*phm
, struct hpi_response
*phr
)
792 u32 command
= phm
->u
.d
.u
.buffer
.command
;
793 struct hpi_hw_obj
*phw
= pao
->priv
;
794 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
796 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
798 if (command
== HPI_BUFFER_CMD_EXTERNAL
799 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
800 /* ALLOC phase, allocate a buffer with power of 2 size,
801 get its bus address for PCI bus mastering
803 phm
->u
.d
.u
.buffer
.buffer_size
=
804 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
805 /* return old size and allocated size,
806 so caller can detect change */
807 phr
->u
.d
.u
.stream_info
.data_available
=
808 phw
->outstream_host_buffer_size
[phm
->obj_index
];
809 phr
->u
.d
.u
.stream_info
.buffer_size
=
810 phm
->u
.d
.u
.buffer
.buffer_size
;
812 if (phw
->outstream_host_buffer_size
[phm
->obj_index
] ==
813 phm
->u
.d
.u
.buffer
.buffer_size
) {
814 /* Same size, no action required */
818 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
820 hpios_locked_mem_free(&phw
->outstream_host_buffers
823 err
= hpios_locked_mem_alloc(&phw
->outstream_host_buffers
824 [phm
->obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
828 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
829 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
833 err
= hpios_locked_mem_get_phys_addr
834 (&phw
->outstream_host_buffers
[phm
->obj_index
],
835 &phm
->u
.d
.u
.buffer
.pci_address
);
836 /* get the phys addr into msg for single call alloc caller
837 * needs to do this for split alloc (or use the same message)
838 * return the phy address for split alloc in the respose too
840 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
841 phm
->u
.d
.u
.buffer
.pci_address
;
844 hpios_locked_mem_free(&phw
->outstream_host_buffers
846 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
847 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
852 if (command
== HPI_BUFFER_CMD_EXTERNAL
853 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
854 /* GRANT phase. Set up the BBM status, tell the DSP about
855 the buffer so it can start using BBM.
857 struct hpi_hostbuffer_status
*status
;
859 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
862 "buffer size must be 2^N not %d\n",
863 phm
->u
.d
.u
.buffer
.buffer_size
);
864 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
867 phw
->outstream_host_buffer_size
[phm
->obj_index
] =
868 phm
->u
.d
.u
.buffer
.buffer_size
;
869 status
= &interface
->outstream_host_buffer_status
[phm
->
871 status
->samples_processed
= 0;
872 status
->stream_state
= HPI_STATE_STOPPED
;
873 status
->dSP_index
= 0;
874 status
->host_index
= status
->dSP_index
;
875 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
877 hw_message(pao
, phm
, phr
);
880 && hpios_locked_mem_valid(&phw
->
881 outstream_host_buffers
[phm
->obj_index
])) {
882 hpios_locked_mem_free(&phw
->outstream_host_buffers
884 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
889 static void outstream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
890 struct hpi_message
*phm
, struct hpi_response
*phr
)
892 struct hpi_hw_obj
*phw
= pao
->priv
;
893 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
894 struct hpi_hostbuffer_status
*status
;
897 if (hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
899 if (hpios_locked_mem_get_virt_addr(&phw
->
900 outstream_host_buffers
[phm
->obj_index
],
901 (void *)&p_bbm_data
)) {
902 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
905 status
= &interface
->outstream_host_buffer_status
[phm
->
907 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
908 HPI_OSTREAM_HOSTBUFFER_GET_INFO
, 0);
909 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
910 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
912 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
913 HPI_OSTREAM_HOSTBUFFER_GET_INFO
,
914 HPI_ERROR_INVALID_OPERATION
);
918 static void outstream_host_buffer_free(struct hpi_adapter_obj
*pao
,
919 struct hpi_message
*phm
, struct hpi_response
*phr
)
921 struct hpi_hw_obj
*phw
= pao
->priv
;
922 u32 command
= phm
->u
.d
.u
.buffer
.command
;
924 if (phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
925 if (command
== HPI_BUFFER_CMD_EXTERNAL
926 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
927 phw
->outstream_host_buffer_size
[phm
->obj_index
] = 0;
928 hw_message(pao
, phm
, phr
);
929 /* Tell adapter to stop using the host buffer. */
931 if (command
== HPI_BUFFER_CMD_EXTERNAL
932 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
933 hpios_locked_mem_free(&phw
->outstream_host_buffers
936 /* Should HPI_ERROR_INVALID_OPERATION be returned
937 if no host buffer is allocated? */
939 hpi_init_response(phr
, HPI_OBJ_OSTREAM
,
940 HPI_OSTREAM_HOSTBUFFER_FREE
, 0);
944 static long outstream_get_space_available(struct hpi_hostbuffer_status
947 return status
->size_in_bytes
- ((long)(status
->host_index
) -
948 (long)(status
->dSP_index
));
951 static void outstream_write(struct hpi_adapter_obj
*pao
,
952 struct hpi_message
*phm
, struct hpi_response
*phr
)
954 struct hpi_hw_obj
*phw
= pao
->priv
;
955 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
956 struct hpi_hostbuffer_status
*status
;
957 long space_available
;
959 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
960 /* there is no BBM buffer, write via message */
961 hw_message(pao
, phm
, phr
);
965 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
966 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
968 if (phw
->flag_outstream_just_reset
[phm
->obj_index
]) {
969 /* First OutStremWrite() call following reset will write data to the
970 adapter's buffers, reducing delay before stream can start. The DSP
971 takes care of setting the stream data format using format information
974 int partial_write
= 0;
975 unsigned int original_size
= 0;
977 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 0;
979 /* Send the first buffer to the DSP the old way. */
980 /* Limit size of first transfer - */
981 /* expect that this will not usually be triggered. */
982 if (phm
->u
.d
.u
.data
.data_size
> HPI6205_SIZEOF_DATA
) {
984 original_size
= phm
->u
.d
.u
.data
.data_size
;
985 phm
->u
.d
.u
.data
.data_size
= HPI6205_SIZEOF_DATA
;
988 phm
->function
= HPI_OSTREAM_WRITE
;
989 hw_message(pao
, phm
, phr
);
990 /* update status information that the DSP would typically
991 * update (and will update next time the DSP
992 * buffer update task reads data from the host BBM buffer)
994 status
->auxiliary_data_available
= phm
->u
.d
.u
.data
.data_size
;
995 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
996 status
->dSP_index
+= phm
->u
.d
.u
.data
.data_size
;
998 /* if we did a full write, we can return from here. */
1002 /* tweak buffer parameters and let the rest of the */
1003 /* buffer land in internal BBM buffer */
1004 phm
->u
.d
.u
.data
.data_size
=
1005 original_size
- HPI6205_SIZEOF_DATA
;
1006 phm
->u
.d
.u
.data
.pb_data
+= HPI6205_SIZEOF_DATA
;
1009 space_available
= outstream_get_space_available(status
);
1010 if (space_available
< (long)phm
->u
.d
.u
.data
.data_size
) {
1011 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1015 /* HostBuffers is used to indicate host buffer is internally allocated.
1016 otherwise, assumed external, data written externally */
1017 if (phm
->u
.d
.u
.data
.pb_data
1018 && hpios_locked_mem_valid(&phw
->outstream_host_buffers
[phm
->
1022 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
1024 if (hpios_locked_mem_get_virt_addr(&phw
->
1025 outstream_host_buffers
[phm
->obj_index
],
1026 (void *)&p_bbm_data
)) {
1027 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1032 or enough to fit from current to end of BBM buffer */
1034 min(phm
->u
.d
.u
.data
.data_size
,
1035 status
->size_in_bytes
-
1036 (status
->host_index
& (status
->size_in_bytes
- 1)));
1039 (status
->host_index
& (status
->size_in_bytes
- 1)),
1040 p_app_data
, l_first_write
);
1041 /* remaining data if any */
1042 memcpy(p_bbm_data
, p_app_data
+ l_first_write
,
1043 phm
->u
.d
.u
.data
.data_size
- l_first_write
);
1045 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
1048 static void outstream_get_info(struct hpi_adapter_obj
*pao
,
1049 struct hpi_message
*phm
, struct hpi_response
*phr
)
1051 struct hpi_hw_obj
*phw
= pao
->priv
;
1052 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1053 struct hpi_hostbuffer_status
*status
;
1055 if (!phw
->outstream_host_buffer_size
[phm
->obj_index
]) {
1056 hw_message(pao
, phm
, phr
);
1060 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1062 status
= &interface
->outstream_host_buffer_status
[phm
->obj_index
];
1064 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
1065 phr
->u
.d
.u
.stream_info
.samples_transferred
=
1066 status
->samples_processed
;
1067 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
1068 phr
->u
.d
.u
.stream_info
.data_available
=
1069 status
->size_in_bytes
- outstream_get_space_available(status
);
1070 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1071 status
->auxiliary_data_available
;
1074 static void outstream_start(struct hpi_adapter_obj
*pao
,
1075 struct hpi_message
*phm
, struct hpi_response
*phr
)
1077 hw_message(pao
, phm
, phr
);
1080 static void outstream_reset(struct hpi_adapter_obj
*pao
,
1081 struct hpi_message
*phm
, struct hpi_response
*phr
)
1083 struct hpi_hw_obj
*phw
= pao
->priv
;
1084 phw
->flag_outstream_just_reset
[phm
->obj_index
] = 1;
1085 hw_message(pao
, phm
, phr
);
1088 static void outstream_open(struct hpi_adapter_obj
*pao
,
1089 struct hpi_message
*phm
, struct hpi_response
*phr
)
1091 outstream_reset(pao
, phm
, phr
);
1094 /*****************************************************************************/
1095 /* InStream Host buffer functions */
1097 static void instream_host_buffer_allocate(struct hpi_adapter_obj
*pao
,
1098 struct hpi_message
*phm
, struct hpi_response
*phr
)
1101 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1102 struct hpi_hw_obj
*phw
= pao
->priv
;
1103 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1105 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1107 if (command
== HPI_BUFFER_CMD_EXTERNAL
1108 || command
== HPI_BUFFER_CMD_INTERNAL_ALLOC
) {
1110 phm
->u
.d
.u
.buffer
.buffer_size
=
1111 roundup_pow_of_two(phm
->u
.d
.u
.buffer
.buffer_size
);
1112 phr
->u
.d
.u
.stream_info
.data_available
=
1113 phw
->instream_host_buffer_size
[phm
->obj_index
];
1114 phr
->u
.d
.u
.stream_info
.buffer_size
=
1115 phm
->u
.d
.u
.buffer
.buffer_size
;
1117 if (phw
->instream_host_buffer_size
[phm
->obj_index
] ==
1118 phm
->u
.d
.u
.buffer
.buffer_size
) {
1119 /* Same size, no action required */
1123 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1125 hpios_locked_mem_free(&phw
->instream_host_buffers
1128 err
= hpios_locked_mem_alloc(&phw
->instream_host_buffers
[phm
->
1129 obj_index
], phm
->u
.d
.u
.buffer
.buffer_size
,
1130 pao
->pci
.p_os_data
);
1133 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1134 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1138 err
= hpios_locked_mem_get_phys_addr
1139 (&phw
->instream_host_buffers
[phm
->obj_index
],
1140 &phm
->u
.d
.u
.buffer
.pci_address
);
1141 /* get the phys addr into msg for single call alloc. Caller
1142 needs to do this for split alloc so return the phy address */
1143 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1144 phm
->u
.d
.u
.buffer
.pci_address
;
1146 hpios_locked_mem_free(&phw
->instream_host_buffers
1148 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1149 phr
->error
= HPI_ERROR_MEMORY_ALLOC
;
1154 if (command
== HPI_BUFFER_CMD_EXTERNAL
1155 || command
== HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER
) {
1156 struct hpi_hostbuffer_status
*status
;
1158 if (phm
->u
.d
.u
.buffer
.buffer_size
& (phm
->u
.d
.u
.buffer
.
1160 HPI_DEBUG_LOG(ERROR
,
1161 "buffer size must be 2^N not %d\n",
1162 phm
->u
.d
.u
.buffer
.buffer_size
);
1163 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1167 phw
->instream_host_buffer_size
[phm
->obj_index
] =
1168 phm
->u
.d
.u
.buffer
.buffer_size
;
1169 status
= &interface
->instream_host_buffer_status
[phm
->
1171 status
->samples_processed
= 0;
1172 status
->stream_state
= HPI_STATE_STOPPED
;
1173 status
->dSP_index
= 0;
1174 status
->host_index
= status
->dSP_index
;
1175 status
->size_in_bytes
= phm
->u
.d
.u
.buffer
.buffer_size
;
1177 hw_message(pao
, phm
, phr
);
1179 && hpios_locked_mem_valid(&phw
->
1180 instream_host_buffers
[phm
->obj_index
])) {
1181 hpios_locked_mem_free(&phw
->instream_host_buffers
1183 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1188 static void instream_host_buffer_get_info(struct hpi_adapter_obj
*pao
,
1189 struct hpi_message
*phm
, struct hpi_response
*phr
)
1191 struct hpi_hw_obj
*phw
= pao
->priv
;
1192 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1193 struct hpi_hostbuffer_status
*status
;
1196 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1198 if (hpios_locked_mem_get_virt_addr(&phw
->
1199 instream_host_buffers
[phm
->obj_index
],
1200 (void *)&p_bbm_data
)) {
1201 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1204 status
= &interface
->instream_host_buffer_status
[phm
->
1206 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1207 HPI_ISTREAM_HOSTBUFFER_GET_INFO
, 0);
1208 phr
->u
.d
.u
.hostbuffer_info
.p_buffer
= p_bbm_data
;
1209 phr
->u
.d
.u
.hostbuffer_info
.p_status
= status
;
1211 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1212 HPI_ISTREAM_HOSTBUFFER_GET_INFO
,
1213 HPI_ERROR_INVALID_OPERATION
);
1217 static void instream_host_buffer_free(struct hpi_adapter_obj
*pao
,
1218 struct hpi_message
*phm
, struct hpi_response
*phr
)
1220 struct hpi_hw_obj
*phw
= pao
->priv
;
1221 u32 command
= phm
->u
.d
.u
.buffer
.command
;
1223 if (phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1224 if (command
== HPI_BUFFER_CMD_EXTERNAL
1225 || command
== HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER
) {
1226 phw
->instream_host_buffer_size
[phm
->obj_index
] = 0;
1227 hw_message(pao
, phm
, phr
);
1230 if (command
== HPI_BUFFER_CMD_EXTERNAL
1231 || command
== HPI_BUFFER_CMD_INTERNAL_FREE
)
1232 hpios_locked_mem_free(&phw
->instream_host_buffers
1236 /* Should HPI_ERROR_INVALID_OPERATION be returned
1237 if no host buffer is allocated? */
1238 hpi_init_response(phr
, HPI_OBJ_ISTREAM
,
1239 HPI_ISTREAM_HOSTBUFFER_FREE
, 0);
1245 static void instream_start(struct hpi_adapter_obj
*pao
,
1246 struct hpi_message
*phm
, struct hpi_response
*phr
)
1248 hw_message(pao
, phm
, phr
);
1251 static long instream_get_bytes_available(struct hpi_hostbuffer_status
*status
)
1253 return (long)(status
->dSP_index
) - (long)(status
->host_index
);
1256 static void instream_read(struct hpi_adapter_obj
*pao
,
1257 struct hpi_message
*phm
, struct hpi_response
*phr
)
1259 struct hpi_hw_obj
*phw
= pao
->priv
;
1260 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1261 struct hpi_hostbuffer_status
*status
;
1262 long data_available
;
1265 u8
*p_app_data
= (u8
*)phm
->u
.d
.u
.data
.pb_data
;
1267 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1268 hw_message(pao
, phm
, phr
);
1271 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1273 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1274 data_available
= instream_get_bytes_available(status
);
1275 if (data_available
< (long)phm
->u
.d
.u
.data
.data_size
) {
1276 phr
->error
= HPI_ERROR_INVALID_DATASIZE
;
1280 if (hpios_locked_mem_valid(&phw
->instream_host_buffers
[phm
->
1282 if (hpios_locked_mem_get_virt_addr(&phw
->
1283 instream_host_buffers
[phm
->obj_index
],
1284 (void *)&p_bbm_data
)) {
1285 phr
->error
= HPI_ERROR_INVALID_OPERATION
;
1290 or enough to fit from current to end of BBM buffer */
1292 min(phm
->u
.d
.u
.data
.data_size
,
1293 status
->size_in_bytes
-
1294 (status
->host_index
& (status
->size_in_bytes
- 1)));
1298 (status
->host_index
& (status
->size_in_bytes
- 1)),
1300 /* remaining data if any */
1301 memcpy(p_app_data
+ l_first_read
, p_bbm_data
,
1302 phm
->u
.d
.u
.data
.data_size
- l_first_read
);
1304 status
->host_index
+= phm
->u
.d
.u
.data
.data_size
;
1307 static void instream_get_info(struct hpi_adapter_obj
*pao
,
1308 struct hpi_message
*phm
, struct hpi_response
*phr
)
1310 struct hpi_hw_obj
*phw
= pao
->priv
;
1311 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
1312 struct hpi_hostbuffer_status
*status
;
1313 if (!phw
->instream_host_buffer_size
[phm
->obj_index
]) {
1314 hw_message(pao
, phm
, phr
);
1318 status
= &interface
->instream_host_buffer_status
[phm
->obj_index
];
1320 hpi_init_response(phr
, phm
->object
, phm
->function
, 0);
1322 phr
->u
.d
.u
.stream_info
.state
= (u16
)status
->stream_state
;
1323 phr
->u
.d
.u
.stream_info
.samples_transferred
=
1324 status
->samples_processed
;
1325 phr
->u
.d
.u
.stream_info
.buffer_size
= status
->size_in_bytes
;
1326 phr
->u
.d
.u
.stream_info
.data_available
=
1327 instream_get_bytes_available(status
);
1328 phr
->u
.d
.u
.stream_info
.auxiliary_data_available
=
1329 status
->auxiliary_data_available
;
1332 /*****************************************************************************/
1334 #define HPI6205_MAX_FILES_TO_LOAD 2
1336 static u16
adapter_boot_load_dsp(struct hpi_adapter_obj
*pao
,
1337 u32
*pos_error_code
)
1339 struct hpi_hw_obj
*phw
= pao
->priv
;
1340 struct dsp_code dsp_code
;
1341 u16 boot_code_id
[HPI6205_MAX_FILES_TO_LOAD
];
1342 u16 firmware_id
= pao
->pci
.subsys_device_id
;
1347 boot_code_id
[0] = HPI_ADAPTER_ASI(0x6205);
1349 /* special cases where firmware_id != subsys ID */
1350 switch (firmware_id
) {
1351 case HPI_ADAPTER_FAMILY_ASI(0x5000):
1352 boot_code_id
[0] = firmware_id
;
1355 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1356 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1357 case HPI_ADAPTER_FAMILY_ASI(0x6300):
1358 firmware_id
= HPI_ADAPTER_FAMILY_ASI(0x6400);
1360 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1361 case HPI_ADAPTER_FAMILY_ASI(0x6500):
1362 firmware_id
= HPI_ADAPTER_FAMILY_ASI(0x6600);
1364 case HPI_ADAPTER_FAMILY_ASI(0x8800):
1365 firmware_id
= HPI_ADAPTER_FAMILY_ASI(0x8900);
1368 boot_code_id
[1] = firmware_id
;
1370 /* reset DSP by writing a 1 to the WARMRESET bit */
1371 temp
= C6205_HDCR_WARMRESET
;
1372 iowrite32(temp
, phw
->prHDCR
);
1373 hpios_delay_micro_seconds(1000);
1375 /* check that PCI i/f was configured by EEPROM */
1376 temp
= ioread32(phw
->prHSR
);
1377 if ((temp
& (C6205_HSR_CFGERR
| C6205_HSR_EEREAD
)) !=
1379 return hpi6205_error(0, HPI6205_ERROR_6205_EEPROM
);
1381 /* disable PINTA interrupt */
1382 iowrite32(temp
, phw
->prHSR
);
1384 /* check control register reports PCI boot mode */
1385 temp
= ioread32(phw
->prHDCR
);
1386 if (!(temp
& C6205_HDCR_PCIBOOT
))
1387 return hpi6205_error(0, HPI6205_ERROR_6205_REG
);
1389 /* try writing a couple of numbers to the DSP page register */
1390 /* and reading them back. */
1392 iowrite32(temp
, phw
->prDSPP
);
1393 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1394 return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE
);
1396 iowrite32(temp
, phw
->prDSPP
);
1397 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1398 return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE
);
1400 iowrite32(temp
, phw
->prDSPP
);
1401 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1402 return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE
);
1403 /* reset DSP page to the correct number */
1405 iowrite32(temp
, phw
->prDSPP
);
1406 if ((temp
| C6205_DSPP_MAP1
) != ioread32(phw
->prDSPP
))
1407 return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE
);
1410 /* release 6713 from reset before 6205 is bootloaded.
1411 This ensures that the EMIF is inactive,
1412 and the 6713 HPI gets the correct bootmode etc
1414 if (boot_code_id
[1] != 0) {
1415 /* DSP 1 is a C6713 */
1416 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1417 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002202);
1418 hpios_delay_micro_seconds(100);
1419 /* Reset the 6713 #1 - revB */
1420 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 0);
1422 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1423 boot_loader_read_mem32(pao
, 0, 0);
1425 hpios_delay_micro_seconds(100);
1426 /* Release C6713 from reset - revB */
1427 boot_loader_write_mem32(pao
, 0, C6205_BAR0_TIMER1_CTL
, 4);
1428 hpios_delay_micro_seconds(100);
1431 for (dsp
= 0; dsp
< HPI6205_MAX_FILES_TO_LOAD
; dsp
++) {
1432 /* is there a DSP to load? */
1433 if (boot_code_id
[dsp
] == 0)
1436 err
= boot_loader_config_emif(pao
, dsp
);
1440 err
= boot_loader_test_internal_memory(pao
, dsp
);
1444 err
= boot_loader_test_external_memory(pao
, dsp
);
1448 err
= boot_loader_test_pld(pao
, dsp
);
1452 /* write the DSP code down into the DSPs memory */
1453 dsp_code
.ps_dev
= pao
->pci
.p_os_data
;
1454 err
= hpi_dsp_code_open(boot_code_id
[dsp
], &dsp_code
,
1465 err
= hpi_dsp_code_read_word(&dsp_code
, &length
);
1468 if (length
== 0xFFFFFFFF)
1469 break; /* end of code */
1471 err
= hpi_dsp_code_read_word(&dsp_code
, &address
);
1474 err
= hpi_dsp_code_read_word(&dsp_code
, &type
);
1477 err
= hpi_dsp_code_read_block(length
, &dsp_code
,
1481 for (i
= 0; i
< (int)length
; i
++) {
1482 err
= boot_loader_write_mem32(pao
, dsp
,
1486 /* dummy read every 4 words */
1487 /* for 6205 advisory 1.4.4 */
1489 boot_loader_read_mem32(pao
, dsp
,
1497 hpi_dsp_code_close(&dsp_code
);
1502 hpi_dsp_code_rewind(&dsp_code
);
1510 hpi_dsp_code_read_word(&dsp_code
, &length
);
1511 if (length
== 0xFFFFFFFF)
1512 break; /* end of code */
1514 hpi_dsp_code_read_word(&dsp_code
, &address
);
1515 hpi_dsp_code_read_word(&dsp_code
, &type
);
1516 hpi_dsp_code_read_block(length
, &dsp_code
, &pcode
);
1518 for (i
= 0; i
< (int)length
; i
++) {
1519 data
= boot_loader_read_mem32(pao
, dsp
,
1521 if (data
!= *pcode
) {
1531 hpi_dsp_code_close(&dsp_code
);
1536 /* After bootloading all DSPs, start DSP0 running
1537 * The DSP0 code will handle starting and synchronizing with its slaves
1539 if (phw
->p_interface_buffer
) {
1540 /* we need to tell the card the physical PCI address */
1541 u32 physicalPC_iaddress
;
1542 struct bus_master_interface
*interface
=
1543 phw
->p_interface_buffer
;
1544 u32 host_mailbox_address_on_dsp
;
1545 u32 physicalPC_iaddress_verify
= 0;
1547 /* set ack so we know when DSP is ready to go */
1548 /* (dwDspAck will be changed to HIF_RESET) */
1549 interface
->dsp_ack
= H620_HIF_UNKNOWN
;
1550 wmb(); /* ensure ack is written before dsp writes back */
1552 err
= hpios_locked_mem_get_phys_addr(&phw
->h_locked_mem
,
1553 &physicalPC_iaddress
);
1555 /* locate the host mailbox on the DSP. */
1556 host_mailbox_address_on_dsp
= 0x80000000;
1557 while ((physicalPC_iaddress
!= physicalPC_iaddress_verify
)
1559 err
= boot_loader_write_mem32(pao
, 0,
1560 host_mailbox_address_on_dsp
,
1561 physicalPC_iaddress
);
1562 physicalPC_iaddress_verify
=
1563 boot_loader_read_mem32(pao
, 0,
1564 host_mailbox_address_on_dsp
);
1567 HPI_DEBUG_LOG(DEBUG
, "starting DS_ps running\n");
1568 /* enable interrupts */
1569 temp
= ioread32(phw
->prHSR
);
1570 temp
&= ~(u32
)C6205_HSR_INTAM
;
1571 iowrite32(temp
, phw
->prHSR
);
1573 /* start code running... */
1574 temp
= ioread32(phw
->prHDCR
);
1575 temp
|= (u32
)C6205_HDCR_DSPINT
;
1576 iowrite32(temp
, phw
->prHDCR
);
1578 /* give the DSP 10ms to start up */
1579 hpios_delay_micro_seconds(10000);
1584 /*****************************************************************************/
1585 /* Bootloader utility functions */
1587 static u32
boot_loader_read_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
1590 struct hpi_hw_obj
*phw
= pao
->priv
;
1592 __iomem u32
*p_data
;
1594 if (dsp_index
== 0) {
1595 /* DSP 0 is always C6205 */
1596 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1597 /* BAR1 register access */
1598 p_data
= pao
->pci
.ap_mem_base
[1] +
1599 (address
& 0x007fffff) /
1600 sizeof(*pao
->pci
.ap_mem_base
[1]);
1601 /* HPI_DEBUG_LOG(WARNING,
1602 "BAR1 access %08x\n", dwAddress); */
1604 u32 dw4M_page
= address
>> 22L;
1605 if (dw4M_page
!= phw
->dsp_page
) {
1606 phw
->dsp_page
= dw4M_page
;
1608 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1611 address
&= 0x3fffff; /* address within 4M page */
1612 /* BAR0 memory access */
1613 p_data
= pao
->pci
.ap_mem_base
[0] +
1614 address
/ sizeof(u32
);
1616 data
= ioread32(p_data
);
1617 } else if (dsp_index
== 1) {
1618 /* DSP 1 is a C6713 */
1620 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1621 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1622 lsb
= boot_loader_read_mem32(pao
, 0, HPIDL_ADDR
);
1623 data
= boot_loader_read_mem32(pao
, 0, HPIDH_ADDR
);
1624 data
= (data
<< 16) | (lsb
& 0xFFFF);
1629 static u16
boot_loader_write_mem32(struct hpi_adapter_obj
*pao
, int dsp_index
,
1630 u32 address
, u32 data
)
1632 struct hpi_hw_obj
*phw
= pao
->priv
;
1634 __iomem u32
*p_data
;
1635 /* u32 dwVerifyData=0; */
1637 if (dsp_index
== 0) {
1638 /* DSP 0 is always C6205 */
1639 if ((address
>= 0x01800000) & (address
< 0x02000000)) {
1640 /* BAR1 - DSP register access using */
1641 /* Non-prefetchable PCI access */
1642 p_data
= pao
->pci
.ap_mem_base
[1] +
1643 (address
& 0x007fffff) /
1644 sizeof(*pao
->pci
.ap_mem_base
[1]);
1646 /* BAR0 access - all of DSP memory using */
1647 /* pre-fetchable PCI access */
1648 u32 dw4M_page
= address
>> 22L;
1649 if (dw4M_page
!= phw
->dsp_page
) {
1650 phw
->dsp_page
= dw4M_page
;
1652 iowrite32(phw
->dsp_page
, phw
->prDSPP
);
1655 address
&= 0x3fffff; /* address within 4M page */
1656 p_data
= pao
->pci
.ap_mem_base
[0] +
1657 address
/ sizeof(u32
);
1659 iowrite32(data
, p_data
);
1660 } else if (dsp_index
== 1) {
1661 /* DSP 1 is a C6713 */
1662 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
, address
);
1663 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
, address
>> 16);
1665 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1666 boot_loader_read_mem32(pao
, 0, 0);
1668 boot_loader_write_mem32(pao
, 0, HPIDL_ADDR
, data
);
1669 boot_loader_write_mem32(pao
, 0, HPIDH_ADDR
, data
>> 16);
1671 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1672 boot_loader_read_mem32(pao
, 0, 0);
1674 err
= hpi6205_error(dsp_index
, HPI6205_ERROR_BAD_DSPINDEX
);
1678 static u16
boot_loader_config_emif(struct hpi_adapter_obj
*pao
, int dsp_index
)
1682 if (dsp_index
== 0) {
1685 /* DSP 0 is always C6205 */
1688 /* memory map of C6205 */
1689 /* 00000000-0000FFFF 16Kx32 internal program */
1690 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1694 /* Global EMIF control */
1695 boot_loader_write_mem32(pao
, dsp_index
, 0x01800000, 0x3779);
1704 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1705 setting
= 0x00000030;
1706 boot_loader_write_mem32(pao
, dsp_index
, 0x01800008, setting
);
1707 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1709 return hpi6205_error(dsp_index
,
1710 HPI6205_ERROR_DSP_EMIF
);
1712 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1713 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1714 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1715 /* WST should be 71, but 63 is max possible */
1717 (1L << WS_OFS
) | (63L << WST_OFS
) | (1L << WH_OFS
) |
1718 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1720 boot_loader_write_mem32(pao
, dsp_index
, 0x01800004, setting
);
1721 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1723 return hpi6205_error(dsp_index
,
1724 HPI6205_ERROR_DSP_EMIF
);
1726 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1727 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1728 /* plenty of wait states */
1730 (1L << WS_OFS
) | (28L << WST_OFS
) | (1L << WH_OFS
) |
1731 (1L << RS_OFS
) | (63L << RST_OFS
) | (1L << RH_OFS
) |
1733 boot_loader_write_mem32(pao
, dsp_index
, 0x01800010, setting
);
1734 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1736 return hpi6205_error(dsp_index
,
1737 HPI6205_ERROR_DSP_EMIF
);
1739 /* EMIF CE3 setup - 32 bit async. */
1740 /* This is the PLD on the ASI5000 cards only */
1742 (1L << WS_OFS
) | (10L << WST_OFS
) | (1L << WH_OFS
) |
1743 (1L << RS_OFS
) | (10L << RST_OFS
) | (1L << RH_OFS
) |
1745 boot_loader_write_mem32(pao
, dsp_index
, 0x01800014, setting
);
1746 if (setting
!= boot_loader_read_mem32(pao
, dsp_index
,
1748 return hpi6205_error(dsp_index
,
1749 HPI6205_ERROR_DSP_EMIF
);
1751 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1752 /* need to use this else DSP code crashes? */
1753 boot_loader_write_mem32(pao
, dsp_index
, 0x01800018,
1756 /* EMIF SDRAM Refresh Timing */
1757 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1758 boot_loader_write_mem32(pao
, dsp_index
, 0x0180001C,
1761 } else if (dsp_index
== 1) {
1762 /* test access to the C6713s HPI registers */
1763 u32 write_data
= 0, read_data
= 0, i
= 0;
1765 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1767 boot_loader_write_mem32(pao
, 0, HPICL_ADDR
, write_data
);
1768 boot_loader_write_mem32(pao
, 0, HPICH_ADDR
, write_data
);
1769 /* C67 HPI is on lower 16bits of 32bit EMIF */
1771 0xFFF7 & boot_loader_read_mem32(pao
, 0, HPICL_ADDR
);
1772 if (write_data
!= read_data
) {
1773 err
= hpi6205_error(dsp_index
,
1774 HPI6205_ERROR_C6713_HPIC
);
1775 HPI_DEBUG_LOG(ERROR
, "HPICL %x %x\n", write_data
,
1780 /* HPIA - walking ones test */
1782 for (i
= 0; i
< 32; i
++) {
1783 boot_loader_write_mem32(pao
, 0, HPIAL_ADDR
,
1785 boot_loader_write_mem32(pao
, 0, HPIAH_ADDR
,
1786 (write_data
>> 16));
1788 0xFFFF & boot_loader_read_mem32(pao
, 0,
1791 read_data
| ((0xFFFF &
1792 boot_loader_read_mem32(pao
, 0,
1795 if (read_data
!= write_data
) {
1796 err
= hpi6205_error(dsp_index
,
1797 HPI6205_ERROR_C6713_HPIA
);
1798 HPI_DEBUG_LOG(ERROR
, "HPIA %x %x\n",
1799 write_data
, read_data
);
1802 write_data
= write_data
<< 1;
1806 * ** C6713 datasheet says we cannot program PLL from HPI,
1807 * and indeed if we try to set the PLL multiply from the HPI,
1808 * the PLL does not seem to lock, so we enable the PLL and
1809 * use the default multiply of x 7, which for a 27MHz clock
1810 * gives a DSP speed of 189MHz
1813 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0000);
1814 hpios_delay_micro_seconds(1000);
1815 /* EMIF = 189/3=63MHz */
1816 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C120, 0x8002);
1818 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C11C, 0x8001);
1820 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C118, 0x8000);
1821 hpios_delay_micro_seconds(1000);
1822 /* ** SGT test to take GPO3 high when we start the PLL */
1823 /* and low when the delay is completed */
1824 /* FSX0 <- '1' (GPO3) */
1825 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A0A);
1826 /* PLL not bypassed */
1827 boot_loader_write_mem32(pao
, dsp_index
, 0x01B7C100, 0x0001);
1828 hpios_delay_micro_seconds(1000);
1829 /* FSX0 <- '0' (GPO3) */
1830 boot_loader_write_mem32(pao
, 0, (0x018C0024L
), 0x00002A02);
1832 /* 6205 EMIF CE1 resetup - 32 bit async. */
1833 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1834 boot_loader_write_mem32(pao
, 0, 0x01800004, /* CE1 */
1835 (1L << WS_OFS
) | (8L << WST_OFS
) | (1L << WH_OFS
) |
1836 (1L << RS_OFS
) | (12L << RST_OFS
) | (1L << RH_OFS
) |
1839 hpios_delay_micro_seconds(1000);
1841 /* check that we can read one of the PLL registers */
1842 /* PLL should not be bypassed! */
1843 if ((boot_loader_read_mem32(pao
, dsp_index
, 0x01B7C100) & 0xF)
1845 err
= hpi6205_error(dsp_index
,
1846 HPI6205_ERROR_C6713_PLL
);
1849 /* setup C67x EMIF (note this is the only use of
1850 BAR1 via BootLoader_WriteMem32) */
1851 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_GCTL
,
1853 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_CE0
,
1855 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMEXT
,
1857 boot_loader_write_mem32(pao
, dsp_index
, C6713_EMIF_SDRAMCTL
,
1859 boot_loader_write_mem32(pao
, dsp_index
,
1860 C6713_EMIF_SDRAMTIMING
, 0x00000410);
1862 hpios_delay_micro_seconds(1000);
1863 } else if (dsp_index
== 2) {
1864 /* DSP 2 is a C6713 */
1867 err
= hpi6205_error(dsp_index
, HPI6205_ERROR_BAD_DSPINDEX
);
1871 static u16
boot_loader_test_memory(struct hpi_adapter_obj
*pao
, int dsp_index
,
1872 u32 start_address
, u32 length
)
1876 u32 test_data
= 0, data
= 0;
1880 /* for 1st word, test each bit in the 32bit word, */
1881 /* dwLength specifies number of 32bit words to test */
1882 /*for(i=0; i<dwLength; i++) */
1885 test_addr
= start_address
+ i
* 4;
1886 test_data
= 0x00000001;
1887 for (j
= 0; j
< 32; j
++) {
1888 boot_loader_write_mem32(pao
, dsp_index
, test_addr
,
1890 data
= boot_loader_read_mem32(pao
, dsp_index
,
1892 if (data
!= test_data
) {
1893 HPI_DEBUG_LOG(VERBOSE
,
1894 "memtest error details "
1895 "%08x %08x %08x %i\n", test_addr
,
1896 test_data
, data
, dsp_index
);
1897 return 1; /* error */
1899 test_data
= test_data
<< 1;
1903 /* for the next 100 locations test each location, leaving it as zero */
1904 /* write a zero to the next word in memory before we read */
1905 /* the previous write to make sure every memory location is unique */
1906 for (i
= 0; i
< 100; i
++) {
1907 test_addr
= start_address
+ i
* 4;
1908 test_data
= 0xA5A55A5A;
1909 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, test_data
);
1910 boot_loader_write_mem32(pao
, dsp_index
, test_addr
+ 4, 0);
1911 data
= boot_loader_read_mem32(pao
, dsp_index
, test_addr
);
1912 if (data
!= test_data
) {
1913 HPI_DEBUG_LOG(VERBOSE
,
1914 "memtest error details "
1915 "%08x %08x %08x %i\n", test_addr
, test_data
,
1917 return 1; /* error */
1919 /* leave location as zero */
1920 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1923 /* zero out entire memory block */
1924 for (i
= 0; i
< length
; i
++) {
1925 test_addr
= start_address
+ i
* 4;
1926 boot_loader_write_mem32(pao
, dsp_index
, test_addr
, 0x0);
1931 static u16
boot_loader_test_internal_memory(struct hpi_adapter_obj
*pao
,
1935 if (dsp_index
== 0) {
1936 /* DSP 0 is a C6205 */
1938 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1942 err
= boot_loader_test_memory(pao
, dsp_index
,
1943 0x80000000, 0x10000);
1944 } else if ((dsp_index
== 1) || (dsp_index
== 2)) {
1945 /* DSP 1&2 are a C6713 */
1946 /* 192K internal mem */
1947 err
= boot_loader_test_memory(pao
, dsp_index
, 0x00000000,
1950 /* 64K internal mem / L2 cache */
1951 err
= boot_loader_test_memory(pao
, dsp_index
,
1952 0x00030000, 0x10000);
1954 return hpi6205_error(dsp_index
, HPI6205_ERROR_BAD_DSPINDEX
);
1957 return hpi6205_error(dsp_index
, HPI6205_ERROR_DSP_INTMEM
);
1962 static u16
boot_loader_test_external_memory(struct hpi_adapter_obj
*pao
,
1965 u32 dRAM_start_address
= 0;
1968 if (dsp_index
== 0) {
1969 /* only test for SDRAM if an ASI5000 card */
1970 if (pao
->pci
.subsys_device_id
== 0x5000) {
1971 /* DSP 0 is always C6205 */
1972 dRAM_start_address
= 0x00400000;
1973 dRAM_size
= 0x200000;
1974 /*dwDRAMinc=1024; */
1977 } else if ((dsp_index
== 1) || (dsp_index
== 2)) {
1978 /* DSP 1 is a C6713 */
1979 dRAM_start_address
= 0x80000000;
1980 dRAM_size
= 0x200000;
1981 /*dwDRAMinc=1024; */
1983 return hpi6205_error(dsp_index
, HPI6205_ERROR_BAD_DSPINDEX
);
1985 if (boot_loader_test_memory(pao
, dsp_index
, dRAM_start_address
,
1987 return hpi6205_error(dsp_index
, HPI6205_ERROR_DSP_EXTMEM
);
1991 static u16
boot_loader_test_pld(struct hpi_adapter_obj
*pao
, int dsp_index
)
1994 if (dsp_index
== 0) {
1995 /* only test for DSP0 PLD on ASI5000 card */
1996 if (pao
->pci
.subsys_device_id
== 0x5000) {
1997 /* PLD is located at CE3=0x03000000 */
1998 data
= boot_loader_read_mem32(pao
, dsp_index
,
2000 if ((data
& 0xF) != 0x5)
2001 return hpi6205_error(dsp_index
,
2002 HPI6205_ERROR_DSP_PLD
);
2003 data
= boot_loader_read_mem32(pao
, dsp_index
,
2005 if ((data
& 0xF) != 0xA)
2006 return hpi6205_error(dsp_index
,
2007 HPI6205_ERROR_DSP_PLD
);
2009 } else if (dsp_index
== 1) {
2010 /* DSP 1 is a C6713 */
2011 if (pao
->pci
.subsys_device_id
== 0x8700) {
2012 /* PLD is located at CE1=0x90000000 */
2013 data
= boot_loader_read_mem32(pao
, dsp_index
,
2015 if ((data
& 0xFF) != 0xAA)
2016 return hpi6205_error(dsp_index
,
2017 HPI6205_ERROR_DSP_PLD
);
2019 boot_loader_write_mem32(pao
, dsp_index
, 0x90000000,
2026 /** Transfer data to or from DSP
2027 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
2029 static short hpi6205_transfer_data(struct hpi_adapter_obj
*pao
, u8
*p_data
,
2030 u32 data_size
, int operation
)
2032 struct hpi_hw_obj
*phw
= pao
->priv
;
2033 u32 data_transferred
= 0;
2035 #ifndef HPI6205_NO_HSR_POLL
2039 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2042 return HPI_ERROR_INVALID_DATA_TRANSFER
;
2044 data_size
&= ~3L; /* round data_size down to nearest 4 bytes */
2046 /* make sure state is IDLE */
2047 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
))
2048 return HPI_ERROR_DSP_HARDWARE
;
2050 while (data_transferred
< data_size
) {
2051 u32 this_copy
= data_size
- data_transferred
;
2053 if (this_copy
> HPI6205_SIZEOF_DATA
)
2054 this_copy
= HPI6205_SIZEOF_DATA
;
2056 if (operation
== H620_HIF_SEND_DATA
)
2057 memcpy((void *)&interface
->u
.b_data
[0],
2058 &p_data
[data_transferred
], this_copy
);
2060 interface
->transfer_size_in_bytes
= this_copy
;
2062 #ifdef HPI6205_NO_HSR_POLL
2063 /* DSP must change this back to nOperation */
2064 interface
->dsp_ack
= H620_HIF_IDLE
;
2067 send_dsp_command(phw
, operation
);
2069 #ifdef HPI6205_NO_HSR_POLL
2070 temp2
= wait_dsp_ack(phw
, operation
, HPI6205_TIMEOUT
);
2071 HPI_DEBUG_LOG(DEBUG
, "spun %d times for data xfer of %d\n",
2072 HPI6205_TIMEOUT
- temp2
, this_copy
);
2076 HPI_DEBUG_LOG(ERROR
,
2077 "timed out waiting for " "state %d got %d\n",
2078 operation
, interface
->dsp_ack
);
2083 /* spin waiting on the result */
2084 time_out
= HPI6205_TIMEOUT
;
2086 while ((temp2
== 0) && time_out
--) {
2087 /* give 16k bus mastering transfer time to happen */
2088 /*(16k / 132Mbytes/s = 122usec) */
2089 hpios_delay_micro_seconds(20);
2090 temp2
= ioread32(phw
->prHSR
);
2091 temp2
&= C6205_HSR_INTSRC
;
2093 HPI_DEBUG_LOG(DEBUG
, "spun %d times for data xfer of %d\n",
2094 HPI6205_TIMEOUT
- time_out
, this_copy
);
2095 if (temp2
== C6205_HSR_INTSRC
) {
2096 HPI_DEBUG_LOG(VERBOSE
,
2097 "interrupt from HIF <data> OK\n");
2099 if(interface->dwDspAck != nOperation) {
2100 HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d,
2102 interface->dwDspAck,nOperation);
2106 /* need to handle this differently... */
2108 HPI_DEBUG_LOG(ERROR
,
2109 "interrupt from HIF <data> BAD\n");
2110 err
= HPI_ERROR_DSP_HARDWARE
;
2113 /* reset the interrupt from the DSP */
2114 iowrite32(C6205_HSR_INTSRC
, phw
->prHSR
);
2116 if (operation
== H620_HIF_GET_DATA
)
2117 memcpy(&p_data
[data_transferred
],
2118 (void *)&interface
->u
.b_data
[0], this_copy
);
2120 data_transferred
+= this_copy
;
2122 if (interface
->dsp_ack
!= operation
)
2123 HPI_DEBUG_LOG(DEBUG
, "interface->dsp_ack=%d, expected %d\n",
2124 interface
->dsp_ack
, operation
);
2125 /* err=HPI_ERROR_DSP_HARDWARE; */
2127 send_dsp_command(phw
, H620_HIF_IDLE
);
2132 /* wait for up to timeout_us microseconds for the DSP
2133 to signal state by DMA into dwDspAck
2135 static int wait_dsp_ack(struct hpi_hw_obj
*phw
, int state
, int timeout_us
)
2137 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2138 int t
= timeout_us
/ 4;
2140 rmb(); /* ensure interface->dsp_ack is up to date */
2141 while ((interface
->dsp_ack
!= state
) && --t
) {
2142 hpios_delay_micro_seconds(4);
2143 rmb(); /* DSP changes dsp_ack by DMA */
2146 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2150 /* set the busmaster interface to cmd, then interrupt the DSP */
2151 static void send_dsp_command(struct hpi_hw_obj
*phw
, int cmd
)
2153 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2157 interface
->host_cmd
= cmd
;
2158 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2159 /* before we interrupt the DSP */
2160 r
= ioread32(phw
->prHDCR
);
2161 r
|= (u32
)C6205_HDCR_DSPINT
;
2162 iowrite32(r
, phw
->prHDCR
);
2163 r
&= ~(u32
)C6205_HDCR_DSPINT
;
2164 iowrite32(r
, phw
->prHDCR
);
2167 static unsigned int message_count
;
2169 static u16
message_response_sequence(struct hpi_adapter_obj
*pao
,
2170 struct hpi_message
*phm
, struct hpi_response
*phr
)
2172 #ifndef HPI6205_NO_HSR_POLL
2175 u32 time_out
, time_out2
;
2176 struct hpi_hw_obj
*phw
= pao
->priv
;
2177 struct bus_master_interface
*interface
= phw
->p_interface_buffer
;
2181 /* Assume buffer of type struct bus_master_interface
2182 is allocated "noncacheable" */
2184 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2185 HPI_DEBUG_LOG(DEBUG
, "timeout waiting for idle\n");
2186 return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
);
2188 interface
->u
.message_buffer
= *phm
;
2189 /* signal we want a response */
2190 send_dsp_command(phw
, H620_HIF_GET_RESP
);
2192 time_out2
= wait_dsp_ack(phw
, H620_HIF_GET_RESP
, HPI6205_TIMEOUT
);
2194 if (time_out2
== 0) {
2195 HPI_DEBUG_LOG(ERROR
,
2196 "(%u) timed out waiting for " "GET_RESP state [%x]\n",
2197 message_count
, interface
->dsp_ack
);
2199 HPI_DEBUG_LOG(VERBOSE
,
2200 "(%u) transition to GET_RESP after %u\n",
2201 message_count
, HPI6205_TIMEOUT
- time_out2
);
2203 /* spin waiting on HIF interrupt flag (end of msg process) */
2204 time_out
= HPI6205_TIMEOUT
;
2206 #ifndef HPI6205_NO_HSR_POLL
2208 while ((temp2
== 0) && --time_out
) {
2209 temp2
= ioread32(phw
->prHSR
);
2210 temp2
&= C6205_HSR_INTSRC
;
2211 hpios_delay_micro_seconds(1);
2213 if (temp2
== C6205_HSR_INTSRC
) {
2214 rmb(); /* ensure we see latest value for dsp_ack */
2215 if ((interface
->dsp_ack
!= H620_HIF_GET_RESP
)) {
2216 HPI_DEBUG_LOG(DEBUG
,
2217 "(%u)interface->dsp_ack(0x%x) != "
2218 "H620_HIF_GET_RESP, t=%u\n", message_count
,
2220 HPI6205_TIMEOUT
- time_out
);
2222 HPI_DEBUG_LOG(VERBOSE
,
2223 "(%u)int with GET_RESP after %u\n",
2224 message_count
, HPI6205_TIMEOUT
- time_out
);
2228 /* can we do anything else in response to the error ? */
2229 HPI_DEBUG_LOG(ERROR
,
2230 "interrupt from HIF module BAD (function %x)\n",
2234 /* reset the interrupt from the DSP */
2235 iowrite32(C6205_HSR_INTSRC
, phw
->prHSR
);
2238 /* read the result */
2240 *phr
= interface
->u
.response_buffer
;
2242 /* set interface back to idle */
2243 send_dsp_command(phw
, H620_HIF_IDLE
);
2245 if ((time_out
== 0) || (time_out2
== 0)) {
2246 HPI_DEBUG_LOG(DEBUG
, "something timed out!\n");
2247 return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_TIMEOUT
);
2249 /* special case for adapter close - */
2250 /* wait for the DSP to indicate it is idle */
2251 if (phm
->function
== HPI_ADAPTER_CLOSE
) {
2252 if (!wait_dsp_ack(phw
, H620_HIF_IDLE
, HPI6205_TIMEOUT
)) {
2253 HPI_DEBUG_LOG(DEBUG
,
2254 "timeout waiting for idle "
2255 "(on adapter_close)\n");
2256 return hpi6205_error(0,
2257 HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT
);
2260 err
= hpi_validate_response(phm
, phr
);
2264 static void hw_message(struct hpi_adapter_obj
*pao
, struct hpi_message
*phm
,
2265 struct hpi_response
*phr
)
2270 hpios_dsplock_lock(pao
);
2272 err
= message_response_sequence(pao
, phm
, phr
);
2274 /* maybe an error response */
2276 /* something failed in the HPI/DSP interface */
2280 /* just the header of the response is valid */
2281 phr
->size
= sizeof(struct hpi_response_header
);
2284 pao
->dsp_crashed
= 0;
2286 if (phr
->error
!= 0) /* something failed in the DSP */
2289 switch (phm
->function
) {
2290 case HPI_OSTREAM_WRITE
:
2291 case HPI_ISTREAM_ANC_WRITE
:
2292 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2293 phm
->u
.d
.u
.data
.data_size
, H620_HIF_SEND_DATA
);
2296 case HPI_ISTREAM_READ
:
2297 case HPI_OSTREAM_ANC_READ
:
2298 err
= hpi6205_transfer_data(pao
, phm
->u
.d
.u
.data
.pb_data
,
2299 phm
->u
.d
.u
.data
.data_size
, H620_HIF_GET_DATA
);
2302 case HPI_CONTROL_SET_STATE
:
2303 if (phm
->object
== HPI_OBJ_CONTROLEX
2304 && phm
->u
.cx
.attribute
== HPI_COBRANET_SET_DATA
)
2305 err
= hpi6205_transfer_data(pao
,
2306 phm
->u
.cx
.u
.cobranet_bigdata
.pb_data
,
2307 phm
->u
.cx
.u
.cobranet_bigdata
.byte_count
,
2308 H620_HIF_SEND_DATA
);
2311 case HPI_CONTROL_GET_STATE
:
2312 if (phm
->object
== HPI_OBJ_CONTROLEX
2313 && phm
->u
.cx
.attribute
== HPI_COBRANET_GET_DATA
)
2314 err
= hpi6205_transfer_data(pao
,
2315 phm
->u
.cx
.u
.cobranet_bigdata
.pb_data
,
2316 phr
->u
.cx
.u
.cobranet_data
.byte_count
,
2323 hpios_dsplock_unlock(pao
);