blob: e3d0f55ad6c49b7b0523d0de07caed731f4f7e3c [file] [log] [blame]
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001/******************************************************************************
2
3 AudioScience HPI driver
Eliot Blennerhassett40818b62011-12-22 13:38:32 +13004 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02005
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;
9
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.
14
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
18
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
24
25 Exported function:
26 void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
27
28(C) Copyright AudioScience Inc. 1998-2010
29*******************************************************************************/
30#define SOURCEFILE_NAME "hpi6205.c"
31
32#include "hpi_internal.h"
33#include "hpimsginit.h"
34#include "hpidebug.h"
35#include "hpi6205.h"
36#include "hpidspcd.h"
37#include "hpicmn.h"
38
39/*****************************************************************************/
40/* HPI6205 specific error codes */
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +130041#define HPI6205_ERROR_BASE 1000 /* not actually used anywhere */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +130042
43/* operational/messaging errors */
44#define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT 1015
45#define HPI6205_ERROR_MSG_RESP_TIMEOUT 1016
46
47/* initialization/bootload errors */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020048#define HPI6205_ERROR_6205_NO_IRQ 1002
49#define HPI6205_ERROR_6205_INIT_FAILED 1003
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020050#define HPI6205_ERROR_6205_REG 1006
51#define HPI6205_ERROR_6205_DSPPAGE 1007
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020052#define HPI6205_ERROR_C6713_HPIC 1009
53#define HPI6205_ERROR_C6713_HPIA 1010
54#define HPI6205_ERROR_C6713_PLL 1011
55#define HPI6205_ERROR_DSP_INTMEM 1012
56#define HPI6205_ERROR_DSP_EXTMEM 1013
57#define HPI6205_ERROR_DSP_PLD 1014
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020058#define HPI6205_ERROR_6205_EEPROM 1017
59#define HPI6205_ERROR_DSP_EMIF 1018
60
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +020061/*****************************************************************************/
62/* for C6205 PCI i/f */
63/* Host Status Register (HSR) bitfields */
64#define C6205_HSR_INTSRC 0x01
65#define C6205_HSR_INTAVAL 0x02
66#define C6205_HSR_INTAM 0x04
67#define C6205_HSR_CFGERR 0x08
68#define C6205_HSR_EEREAD 0x10
69/* Host-to-DSP Control Register (HDCR) bitfields */
70#define C6205_HDCR_WARMRESET 0x01
71#define C6205_HDCR_DSPINT 0x02
72#define C6205_HDCR_PCIBOOT 0x04
73/* DSP Page Register (DSPP) bitfields, */
74/* defines 4 Mbyte page that BAR0 points to */
75#define C6205_DSPP_MAP1 0x400
76
77/* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
78 * BAR1 maps to non-prefetchable 8 Mbyte memory block
79 * of DSP memory mapped registers (starting at 0x01800000).
80 * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
81 * needs to be added to the BAR1 base address set in the PCI config reg
82 */
83#define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
84#define C6205_BAR1_HSR (C6205_BAR1_PCI_IO_OFFSET)
85#define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
86#define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
87
88/* used to control LED (revA) and reset C6713 (revB) */
89#define C6205_BAR0_TIMER1_CTL (0x01980000L)
90
91/* For first 6713 in CE1 space, using DA17,16,2 */
92#define HPICL_ADDR 0x01400000L
93#define HPICH_ADDR 0x01400004L
94#define HPIAL_ADDR 0x01410000L
95#define HPIAH_ADDR 0x01410004L
96#define HPIDIL_ADDR 0x01420000L
97#define HPIDIH_ADDR 0x01420004L
98#define HPIDL_ADDR 0x01430000L
99#define HPIDH_ADDR 0x01430004L
100
101#define C6713_EMIF_GCTL 0x01800000
102#define C6713_EMIF_CE1 0x01800004
103#define C6713_EMIF_CE0 0x01800008
104#define C6713_EMIF_CE2 0x01800010
105#define C6713_EMIF_CE3 0x01800014
106#define C6713_EMIF_SDRAMCTL 0x01800018
107#define C6713_EMIF_SDRAMTIMING 0x0180001C
108#define C6713_EMIF_SDRAMEXT 0x01800020
109
110struct hpi_hw_obj {
111 /* PCI registers */
112 __iomem u32 *prHSR;
113 __iomem u32 *prHDCR;
114 __iomem u32 *prDSPP;
115
116 u32 dsp_page;
117
118 struct consistent_dma_area h_locked_mem;
119 struct bus_master_interface *p_interface_buffer;
120
121 u16 flag_outstream_just_reset[HPI_MAX_STREAMS];
122 /* a non-NULL handle means there is an HPI allocated buffer */
123 struct consistent_dma_area instream_host_buffers[HPI_MAX_STREAMS];
124 struct consistent_dma_area outstream_host_buffers[HPI_MAX_STREAMS];
125 /* non-zero size means a buffer exists, may be external */
126 u32 instream_host_buffer_size[HPI_MAX_STREAMS];
127 u32 outstream_host_buffer_size[HPI_MAX_STREAMS];
128
129 struct consistent_dma_area h_control_cache;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200130 struct hpi_control_cache *p_cache;
131};
132
133/*****************************************************************************/
134/* local prototypes */
135
136#define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
137
138static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us);
139
140static void send_dsp_command(struct hpi_hw_obj *phw, int cmd);
141
142static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
143 u32 *pos_error_code);
144
145static u16 message_response_sequence(struct hpi_adapter_obj *pao,
146 struct hpi_message *phm, struct hpi_response *phr);
147
148static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
149 struct hpi_response *phr);
150
151#define HPI6205_TIMEOUT 1000000
152
153static void subsys_create_adapter(struct hpi_message *phm,
154 struct hpi_response *phr);
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200155static void adapter_delete(struct hpi_adapter_obj *pao,
156 struct hpi_message *phm, struct hpi_response *phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200157
158static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
159 u32 *pos_error_code);
160
161static void delete_adapter_obj(struct hpi_adapter_obj *pao);
162
163static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
164 struct hpi_message *phm, struct hpi_response *phr);
165
166static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
167 struct hpi_message *phm, struct hpi_response *phr);
168
169static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
170 struct hpi_message *phm, struct hpi_response *phr);
171static void outstream_write(struct hpi_adapter_obj *pao,
172 struct hpi_message *phm, struct hpi_response *phr);
173
174static void outstream_get_info(struct hpi_adapter_obj *pao,
175 struct hpi_message *phm, struct hpi_response *phr);
176
177static void outstream_start(struct hpi_adapter_obj *pao,
178 struct hpi_message *phm, struct hpi_response *phr);
179
180static void outstream_open(struct hpi_adapter_obj *pao,
181 struct hpi_message *phm, struct hpi_response *phr);
182
183static void outstream_reset(struct hpi_adapter_obj *pao,
184 struct hpi_message *phm, struct hpi_response *phr);
185
186static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
187 struct hpi_message *phm, struct hpi_response *phr);
188
189static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
190 struct hpi_message *phm, struct hpi_response *phr);
191
192static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
193 struct hpi_message *phm, struct hpi_response *phr);
194
195static void instream_read(struct hpi_adapter_obj *pao,
196 struct hpi_message *phm, struct hpi_response *phr);
197
198static void instream_get_info(struct hpi_adapter_obj *pao,
199 struct hpi_message *phm, struct hpi_response *phr);
200
201static void instream_start(struct hpi_adapter_obj *pao,
202 struct hpi_message *phm, struct hpi_response *phr);
203
204static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
205 u32 address);
206
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300207static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
208 int dsp_index, u32 address, u32 data);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200209
210static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
211 int dsp_index);
212
213static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
214 u32 address, u32 length);
215
216static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
217 int dsp_index);
218
219static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
220 int dsp_index);
221
222static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
223
224/*****************************************************************************/
225
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200226static void subsys_message(struct hpi_adapter_obj *pao,
227 struct hpi_message *phm, struct hpi_response *phr)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200228{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200229 switch (phm->function) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200230 case HPI_SUBSYS_CREATE_ADAPTER:
231 subsys_create_adapter(phm, phr);
232 break;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200233 default:
234 phr->error = HPI_ERROR_INVALID_FUNC;
235 break;
236 }
237}
238
239static void control_message(struct hpi_adapter_obj *pao,
240 struct hpi_message *phm, struct hpi_response *phr)
241{
242
243 struct hpi_hw_obj *phw = pao->priv;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300244 u16 pending_cache_error = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200245
246 switch (phm->function) {
247 case HPI_CONTROL_GET_STATE:
248 if (pao->has_control_cache) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300249 rmb(); /* make sure we see updates DMAed from DSP */
250 if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200251 break;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300252 } else if (phm->u.c.attribute == HPI_METER_PEAK) {
253 pending_cache_error =
254 HPI_ERROR_CONTROL_CACHING;
255 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200256 }
257 hw_message(pao, phm, phr);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300258 if (pending_cache_error && !phr->error)
259 phr->error = pending_cache_error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200260 break;
261 case HPI_CONTROL_GET_INFO:
262 hw_message(pao, phm, phr);
263 break;
264 case HPI_CONTROL_SET_STATE:
265 hw_message(pao, phm, phr);
266 if (pao->has_control_cache)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300267 hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
268 phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200269 break;
270 default:
271 phr->error = HPI_ERROR_INVALID_FUNC;
272 break;
273 }
274}
275
276static void adapter_message(struct hpi_adapter_obj *pao,
277 struct hpi_message *phm, struct hpi_response *phr)
278{
279 switch (phm->function) {
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200280 case HPI_ADAPTER_DELETE:
281 adapter_delete(pao, phm, phr);
282 break;
283
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200284 default:
285 hw_message(pao, phm, phr);
286 break;
287 }
288}
289
290static void outstream_message(struct hpi_adapter_obj *pao,
291 struct hpi_message *phm, struct hpi_response *phr)
292{
293
294 if (phm->obj_index >= HPI_MAX_STREAMS) {
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +1300295 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200296 HPI_DEBUG_LOG(WARNING,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300297 "Message referencing invalid stream %d "
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200298 "on adapter index %d\n", phm->obj_index,
299 phm->adapter_index);
300 return;
301 }
302
303 switch (phm->function) {
304 case HPI_OSTREAM_WRITE:
305 outstream_write(pao, phm, phr);
306 break;
307 case HPI_OSTREAM_GET_INFO:
308 outstream_get_info(pao, phm, phr);
309 break;
310 case HPI_OSTREAM_HOSTBUFFER_ALLOC:
311 outstream_host_buffer_allocate(pao, phm, phr);
312 break;
313 case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
314 outstream_host_buffer_get_info(pao, phm, phr);
315 break;
316 case HPI_OSTREAM_HOSTBUFFER_FREE:
317 outstream_host_buffer_free(pao, phm, phr);
318 break;
319 case HPI_OSTREAM_START:
320 outstream_start(pao, phm, phr);
321 break;
322 case HPI_OSTREAM_OPEN:
323 outstream_open(pao, phm, phr);
324 break;
325 case HPI_OSTREAM_RESET:
326 outstream_reset(pao, phm, phr);
327 break;
328 default:
329 hw_message(pao, phm, phr);
330 break;
331 }
332}
333
334static void instream_message(struct hpi_adapter_obj *pao,
335 struct hpi_message *phm, struct hpi_response *phr)
336{
337
338 if (phm->obj_index >= HPI_MAX_STREAMS) {
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +1300339 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200340 HPI_DEBUG_LOG(WARNING,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300341 "Message referencing invalid stream %d "
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200342 "on adapter index %d\n", phm->obj_index,
343 phm->adapter_index);
344 return;
345 }
346
347 switch (phm->function) {
348 case HPI_ISTREAM_READ:
349 instream_read(pao, phm, phr);
350 break;
351 case HPI_ISTREAM_GET_INFO:
352 instream_get_info(pao, phm, phr);
353 break;
354 case HPI_ISTREAM_HOSTBUFFER_ALLOC:
355 instream_host_buffer_allocate(pao, phm, phr);
356 break;
357 case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
358 instream_host_buffer_get_info(pao, phm, phr);
359 break;
360 case HPI_ISTREAM_HOSTBUFFER_FREE:
361 instream_host_buffer_free(pao, phm, phr);
362 break;
363 case HPI_ISTREAM_START:
364 instream_start(pao, phm, phr);
365 break;
366 default:
367 hw_message(pao, phm, phr);
368 break;
369 }
370}
371
372/*****************************************************************************/
373/** Entry point to this HPI backend
374 * All calls to the HPI start here
375 */
Eliot Blennerhassett33162d22011-07-22 15:52:52 +1200376static
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200377void _HPI_6205(struct hpi_adapter_obj *pao, struct hpi_message *phm,
378 struct hpi_response *phr)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200379{
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200380 if (pao && (pao->dsp_crashed >= 10)
381 && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
382 /* allow last resort debug read even after crash */
383 hpi_init_response(phr, phm->object, phm->function,
384 HPI_ERROR_DSP_HARDWARE);
385 HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n", phm->object,
386 phm->function);
387 return;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200388 }
389
390 /* Init default response */
391 if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300392 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200393
394 HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
395 switch (phm->type) {
Eliot Blennerhassett82b57742011-07-22 15:52:36 +1200396 case HPI_TYPE_REQUEST:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200397 switch (phm->object) {
398 case HPI_OBJ_SUBSYSTEM:
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200399 subsys_message(pao, phm, phr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200400 break;
401
402 case HPI_OBJ_ADAPTER:
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200403 adapter_message(pao, phm, phr);
404 break;
405
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200406 case HPI_OBJ_CONTROL:
407 control_message(pao, phm, phr);
408 break;
409
410 case HPI_OBJ_OSTREAM:
411 outstream_message(pao, phm, phr);
412 break;
413
414 case HPI_OBJ_ISTREAM:
415 instream_message(pao, phm, phr);
416 break;
417
418 default:
419 hw_message(pao, phm, phr);
420 break;
421 }
422 break;
423
424 default:
425 phr->error = HPI_ERROR_INVALID_TYPE;
426 break;
427 }
428}
429
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200430void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
431{
432 struct hpi_adapter_obj *pao = NULL;
433
434 if (phm->object != HPI_OBJ_SUBSYSTEM) {
435 /* normal messages must have valid adapter index */
436 pao = hpi_find_adapter(phm->adapter_index);
437 } else {
438 /* subsys messages don't address an adapter */
439 _HPI_6205(NULL, phm, phr);
440 return;
441 }
442
443 if (pao)
444 _HPI_6205(pao, phm, phr);
445 else
446 hpi_init_response(phr, phm->object, phm->function,
447 HPI_ERROR_BAD_ADAPTER_NUMBER);
448}
449
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200450/*****************************************************************************/
451/* SUBSYSTEM */
452
453/** Create an adapter object and initialise it based on resource information
454 * passed in in the message
455 * *** NOTE - you cannot use this function AND the FindAdapters function at the
456 * same time, the application must use only one of them to get the adapters ***
457 */
458static void subsys_create_adapter(struct hpi_message *phm,
459 struct hpi_response *phr)
460{
461 /* create temp adapter obj, because we don't know what index yet */
462 struct hpi_adapter_obj ao;
463 u32 os_error_code;
464 u16 err;
465
466 HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
467
468 memset(&ao, 0, sizeof(ao));
469
Julia Lawall550a8b62010-05-13 21:58:37 +0200470 ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200471 if (!ao.priv) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300472 HPI_DEBUG_LOG(ERROR, "can't get mem for adapter object\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200473 phr->error = HPI_ERROR_MEMORY_ALLOC;
474 return;
475 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200476
477 ao.pci = *phm->u.s.resource.r.pci;
478 err = create_adapter_obj(&ao, &os_error_code);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200479 if (err) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200480 delete_adapter_obj(&ao);
Eliot Blennerhassett0a000442011-02-10 17:26:05 +1300481 if (err >= HPI_ERROR_BACKEND_BASE) {
482 phr->error = HPI_ERROR_DSP_BOOTLOAD;
483 phr->specific_error = err;
484 } else {
485 phr->error = err;
486 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300487 phr->u.s.data = os_error_code;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200488 return;
489 }
490
Eliot Blennerhassett7036b922011-12-22 13:38:43 +1300491 phr->u.s.adapter_type = ao.type;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200492 phr->u.s.adapter_index = ao.index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200493 phr->error = 0;
494}
495
496/** delete an adapter - required by WDM driver */
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200497static void adapter_delete(struct hpi_adapter_obj *pao,
498 struct hpi_message *phm, struct hpi_response *phr)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200499{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200500 struct hpi_hw_obj *phw;
501
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200502 if (!pao) {
503 phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
504 return;
505 }
Eliot Blennerhassett7036b922011-12-22 13:38:43 +1300506 phw = pao->priv;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200507 /* reset adapter h/w */
508 /* Reset C6713 #1 */
509 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
510 /* reset C6205 */
511 iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
512
513 delete_adapter_obj(pao);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300514 hpi_delete_adapter(pao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200515 phr->error = 0;
516}
517
518/** Create adapter object
519 allocate buffers, bootload DSPs, initialise control cache
520*/
521static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
522 u32 *pos_error_code)
523{
524 struct hpi_hw_obj *phw = pao->priv;
525 struct bus_master_interface *interface;
526 u32 phys_addr;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200527 int i;
528 u16 err;
529
530 /* init error reporting */
531 pao->dsp_crashed = 0;
532
533 for (i = 0; i < HPI_MAX_STREAMS; i++)
534 phw->flag_outstream_just_reset[i] = 1;
535
536 /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
537 phw->prHSR =
538 pao->pci.ap_mem_base[1] +
539 C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
540 phw->prHDCR =
541 pao->pci.ap_mem_base[1] +
542 C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
543 phw->prDSPP =
544 pao->pci.ap_mem_base[1] +
545 C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
546
547 pao->has_control_cache = 0;
548
549 if (hpios_locked_mem_alloc(&phw->h_locked_mem,
550 sizeof(struct bus_master_interface),
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300551 pao->pci.pci_dev))
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200552 phw->p_interface_buffer = NULL;
553 else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
554 (void *)&phw->p_interface_buffer))
555 phw->p_interface_buffer = NULL;
556
557 HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
558 phw->p_interface_buffer);
559
560 if (phw->p_interface_buffer) {
561 memset((void *)phw->p_interface_buffer, 0,
562 sizeof(struct bus_master_interface));
563 phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
564 }
565
566 err = adapter_boot_load_dsp(pao, pos_error_code);
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200567 if (err) {
568 HPI_DEBUG_LOG(ERROR, "DSP code load failed\n");
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200569 /* no need to clean up as SubSysCreateAdapter */
570 /* calls DeleteAdapter on error. */
571 return err;
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200572 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200573 HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
574
575 /* allow boot load even if mem alloc wont work */
576 if (!phw->p_interface_buffer)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300577 return HPI_ERROR_MEMORY_ALLOC;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200578
579 interface = phw->p_interface_buffer;
580
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200581 /* make sure the DSP has started ok */
582 if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
583 HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300584 return HPI6205_ERROR_6205_INIT_FAILED;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200585 }
586 /* Note that *pao, *phw are zeroed after allocation,
587 * so pointers and flags are NULL by default.
588 * Allocate bus mastering control cache buffer and tell the DSP about it
589 */
590 if (interface->control_cache.number_of_controls) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300591 u8 *p_control_cache_virtual;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200592
593 err = hpios_locked_mem_alloc(&phw->h_control_cache,
594 interface->control_cache.size_in_bytes,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300595 pao->pci.pci_dev);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200596 if (!err)
597 err = hpios_locked_mem_get_virt_addr(&phw->
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300598 h_control_cache,
599 (void *)&p_control_cache_virtual);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200600 if (!err) {
601 memset(p_control_cache_virtual, 0,
602 interface->control_cache.size_in_bytes);
603
604 phw->p_cache =
605 hpi_alloc_control_cache(interface->
606 control_cache.number_of_controls,
607 interface->control_cache.size_in_bytes,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200608 p_control_cache_virtual);
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200609
Jesper Juhlfd0977d2010-10-29 21:35:25 +0200610 if (!phw->p_cache)
611 err = HPI_ERROR_MEMORY_ALLOC;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200612 }
613 if (!err) {
614 err = hpios_locked_mem_get_phys_addr(&phw->
615 h_control_cache, &phys_addr);
616 interface->control_cache.physical_address32 =
617 phys_addr;
618 }
619
620 if (!err)
621 pao->has_control_cache = 1;
622 else {
623 if (hpios_locked_mem_valid(&phw->h_control_cache))
624 hpios_locked_mem_free(&phw->h_control_cache);
625 pao->has_control_cache = 0;
626 }
627 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200628 send_dsp_command(phw, H620_HIF_IDLE);
629
630 {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300631 struct hpi_message hm;
632 struct hpi_response hr;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200633 u32 max_streams;
634
635 HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300636 memset(&hm, 0, sizeof(hm));
Eliot Blennerhassett82b57742011-07-22 15:52:36 +1200637 /* wAdapterIndex == version == 0 */
638 hm.type = HPI_TYPE_REQUEST;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300639 hm.size = sizeof(hm);
640 hm.object = HPI_OBJ_ADAPTER;
641 hm.function = HPI_ADAPTER_GET_INFO;
Eliot Blennerhassett82b57742011-07-22 15:52:36 +1200642
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300643 memset(&hr, 0, sizeof(hr));
644 hr.size = sizeof(hr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200645
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300646 err = message_response_sequence(pao, &hm, &hr);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200647 if (err) {
648 HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
649 err);
650 return err;
651 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300652 if (hr.error)
653 return hr.error;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200654
Eliot Blennerhassett7036b922011-12-22 13:38:43 +1300655 pao->type = hr.u.ax.info.adapter_type;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300656 pao->index = hr.u.ax.info.adapter_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200657
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300658 max_streams =
659 hr.u.ax.info.num_outstreams +
660 hr.u.ax.info.num_instreams;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200661
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200662 HPI_DEBUG_LOG(VERBOSE,
663 "got adapter info type %x index %d serial %d\n",
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300664 hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
665 hr.u.ax.info.serial_number);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200666 }
667
Eliot Blennerhassettffdb5782011-02-10 17:26:00 +1300668 if (phw->p_cache)
669 phw->p_cache->adap_idx = pao->index;
670
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200671 HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300672
673 return hpi_add_adapter(pao);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200674}
675
676/** Free memory areas allocated by adapter
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200677 * this routine is called from AdapterDelete,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200678 * and SubSysCreateAdapter if duplicate index
679*/
680static void delete_adapter_obj(struct hpi_adapter_obj *pao)
681{
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +1200682 struct hpi_hw_obj *phw = pao->priv;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200683 int i;
684
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200685 if (hpios_locked_mem_valid(&phw->h_control_cache)) {
686 hpios_locked_mem_free(&phw->h_control_cache);
687 hpi_free_control_cache(phw->p_cache);
688 }
689
690 if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
691 hpios_locked_mem_free(&phw->h_locked_mem);
692 phw->p_interface_buffer = NULL;
693 }
694
695 for (i = 0; i < HPI_MAX_STREAMS; i++)
696 if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
697 hpios_locked_mem_free(&phw->instream_host_buffers[i]);
698 /*?phw->InStreamHostBuffers[i] = NULL; */
699 phw->instream_host_buffer_size[i] = 0;
700 }
701
702 for (i = 0; i < HPI_MAX_STREAMS; i++)
703 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
704 hpios_locked_mem_free(&phw->outstream_host_buffers
705 [i]);
706 phw->outstream_host_buffer_size[i] = 0;
707 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200708 kfree(phw);
709}
710
711/*****************************************************************************/
Eliot Blennerhassett1d595d22011-02-10 17:26:08 +1300712/* Adapter functions */
713
714/*****************************************************************************/
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200715/* OutStream Host buffer functions */
716
717/** Allocate or attach buffer for busmastering
718*/
719static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
720 struct hpi_message *phm, struct hpi_response *phr)
721{
722 u16 err = 0;
723 u32 command = phm->u.d.u.buffer.command;
724 struct hpi_hw_obj *phw = pao->priv;
725 struct bus_master_interface *interface = phw->p_interface_buffer;
726
727 hpi_init_response(phr, phm->object, phm->function, 0);
728
729 if (command == HPI_BUFFER_CMD_EXTERNAL
730 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
731 /* ALLOC phase, allocate a buffer with power of 2 size,
732 get its bus address for PCI bus mastering
733 */
734 phm->u.d.u.buffer.buffer_size =
735 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
736 /* return old size and allocated size,
737 so caller can detect change */
738 phr->u.d.u.stream_info.data_available =
739 phw->outstream_host_buffer_size[phm->obj_index];
740 phr->u.d.u.stream_info.buffer_size =
741 phm->u.d.u.buffer.buffer_size;
742
743 if (phw->outstream_host_buffer_size[phm->obj_index] ==
744 phm->u.d.u.buffer.buffer_size) {
745 /* Same size, no action required */
746 return;
747 }
748
749 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
750 obj_index]))
751 hpios_locked_mem_free(&phw->outstream_host_buffers
752 [phm->obj_index]);
753
754 err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
755 [phm->obj_index], phm->u.d.u.buffer.buffer_size,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300756 pao->pci.pci_dev);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200757
758 if (err) {
759 phr->error = HPI_ERROR_INVALID_DATASIZE;
760 phw->outstream_host_buffer_size[phm->obj_index] = 0;
761 return;
762 }
763
764 err = hpios_locked_mem_get_phys_addr
765 (&phw->outstream_host_buffers[phm->obj_index],
766 &phm->u.d.u.buffer.pci_address);
767 /* get the phys addr into msg for single call alloc caller
768 * needs to do this for split alloc (or use the same message)
769 * return the phy address for split alloc in the respose too
770 */
771 phr->u.d.u.stream_info.auxiliary_data_available =
772 phm->u.d.u.buffer.pci_address;
773
774 if (err) {
775 hpios_locked_mem_free(&phw->outstream_host_buffers
776 [phm->obj_index]);
777 phw->outstream_host_buffer_size[phm->obj_index] = 0;
778 phr->error = HPI_ERROR_MEMORY_ALLOC;
779 return;
780 }
781 }
782
783 if (command == HPI_BUFFER_CMD_EXTERNAL
784 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
785 /* GRANT phase. Set up the BBM status, tell the DSP about
786 the buffer so it can start using BBM.
787 */
788 struct hpi_hostbuffer_status *status;
789
790 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
791 buffer_size - 1)) {
792 HPI_DEBUG_LOG(ERROR,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300793 "Buffer size must be 2^N not %d\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200794 phm->u.d.u.buffer.buffer_size);
795 phr->error = HPI_ERROR_INVALID_DATASIZE;
796 return;
797 }
798 phw->outstream_host_buffer_size[phm->obj_index] =
799 phm->u.d.u.buffer.buffer_size;
800 status = &interface->outstream_host_buffer_status[phm->
801 obj_index];
802 status->samples_processed = 0;
803 status->stream_state = HPI_STATE_STOPPED;
Eliot Blennerhassett8e0874e2011-12-22 13:38:36 +1300804 status->dsp_index = 0;
805 status->host_index = status->dsp_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200806 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +1300807 status->auxiliary_data_available = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200808
809 hw_message(pao, phm, phr);
810
811 if (phr->error
812 && hpios_locked_mem_valid(&phw->
813 outstream_host_buffers[phm->obj_index])) {
814 hpios_locked_mem_free(&phw->outstream_host_buffers
815 [phm->obj_index]);
816 phw->outstream_host_buffer_size[phm->obj_index] = 0;
817 }
818 }
819}
820
821static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
822 struct hpi_message *phm, struct hpi_response *phr)
823{
824 struct hpi_hw_obj *phw = pao->priv;
825 struct bus_master_interface *interface = phw->p_interface_buffer;
826 struct hpi_hostbuffer_status *status;
827 u8 *p_bbm_data;
828
829 if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
830 obj_index])) {
831 if (hpios_locked_mem_get_virt_addr(&phw->
832 outstream_host_buffers[phm->obj_index],
833 (void *)&p_bbm_data)) {
834 phr->error = HPI_ERROR_INVALID_OPERATION;
835 return;
836 }
837 status = &interface->outstream_host_buffer_status[phm->
838 obj_index];
839 hpi_init_response(phr, HPI_OBJ_OSTREAM,
840 HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
841 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
842 phr->u.d.u.hostbuffer_info.p_status = status;
843 } else {
844 hpi_init_response(phr, HPI_OBJ_OSTREAM,
845 HPI_OSTREAM_HOSTBUFFER_GET_INFO,
846 HPI_ERROR_INVALID_OPERATION);
847 }
848}
849
850static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
851 struct hpi_message *phm, struct hpi_response *phr)
852{
853 struct hpi_hw_obj *phw = pao->priv;
854 u32 command = phm->u.d.u.buffer.command;
855
856 if (phw->outstream_host_buffer_size[phm->obj_index]) {
857 if (command == HPI_BUFFER_CMD_EXTERNAL
858 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
859 phw->outstream_host_buffer_size[phm->obj_index] = 0;
860 hw_message(pao, phm, phr);
861 /* Tell adapter to stop using the host buffer. */
862 }
863 if (command == HPI_BUFFER_CMD_EXTERNAL
864 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
865 hpios_locked_mem_free(&phw->outstream_host_buffers
866 [phm->obj_index]);
867 }
868 /* Should HPI_ERROR_INVALID_OPERATION be returned
869 if no host buffer is allocated? */
870 else
871 hpi_init_response(phr, HPI_OBJ_OSTREAM,
872 HPI_OSTREAM_HOSTBUFFER_FREE, 0);
873
874}
875
Eliot Blennerhassett60f1deb2010-08-28 19:52:24 +1200876static u32 outstream_get_space_available(struct hpi_hostbuffer_status *status)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200877{
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +1200878 return status->size_in_bytes - (status->host_index -
Eliot Blennerhassett8e0874e2011-12-22 13:38:36 +1300879 status->dsp_index);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200880}
881
882static void outstream_write(struct hpi_adapter_obj *pao,
883 struct hpi_message *phm, struct hpi_response *phr)
884{
885 struct hpi_hw_obj *phw = pao->priv;
886 struct bus_master_interface *interface = phw->p_interface_buffer;
887 struct hpi_hostbuffer_status *status;
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +1200888 u32 space_available;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200889
890 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
891 /* there is no BBM buffer, write via message */
892 hw_message(pao, phm, phr);
893 return;
894 }
895
896 hpi_init_response(phr, phm->object, phm->function, 0);
897 status = &interface->outstream_host_buffer_status[phm->obj_index];
898
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200899 space_available = outstream_get_space_available(status);
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +1200900 if (space_available < phm->u.d.u.data.data_size) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200901 phr->error = HPI_ERROR_INVALID_DATASIZE;
902 return;
903 }
904
905 /* HostBuffers is used to indicate host buffer is internally allocated.
906 otherwise, assumed external, data written externally */
907 if (phm->u.d.u.data.pb_data
908 && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
909 obj_index])) {
910 u8 *p_bbm_data;
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +1200911 u32 l_first_write;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200912 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
913
914 if (hpios_locked_mem_get_virt_addr(&phw->
915 outstream_host_buffers[phm->obj_index],
916 (void *)&p_bbm_data)) {
917 phr->error = HPI_ERROR_INVALID_OPERATION;
918 return;
919 }
920
921 /* either all data,
922 or enough to fit from current to end of BBM buffer */
923 l_first_write =
924 min(phm->u.d.u.data.data_size,
925 status->size_in_bytes -
926 (status->host_index & (status->size_in_bytes - 1)));
927
928 memcpy(p_bbm_data +
929 (status->host_index & (status->size_in_bytes - 1)),
930 p_app_data, l_first_write);
931 /* remaining data if any */
932 memcpy(p_bbm_data, p_app_data + l_first_write,
933 phm->u.d.u.data.data_size - l_first_write);
934 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300935
936 /*
937 * This version relies on the DSP code triggering an OStream buffer
938 * update immediately following a SET_FORMAT call. The host has
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +1300939 * already written data into the BBM buffer, but the DSP won't know
940 * about it until dwHostIndex is adjusted.
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +1300941 */
942 if (phw->flag_outstream_just_reset[phm->obj_index]) {
943 /* Format can only change after reset. Must tell DSP. */
944 u16 function = phm->function;
945 phw->flag_outstream_just_reset[phm->obj_index] = 0;
946 phm->function = HPI_OSTREAM_SET_FORMAT;
947 hw_message(pao, phm, phr); /* send the format to the DSP */
948 phm->function = function;
949 if (phr->error)
950 return;
951 }
952
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +0200953 status->host_index += phm->u.d.u.data.data_size;
954}
955
956static void outstream_get_info(struct hpi_adapter_obj *pao,
957 struct hpi_message *phm, struct hpi_response *phr)
958{
959 struct hpi_hw_obj *phw = pao->priv;
960 struct bus_master_interface *interface = phw->p_interface_buffer;
961 struct hpi_hostbuffer_status *status;
962
963 if (!phw->outstream_host_buffer_size[phm->obj_index]) {
964 hw_message(pao, phm, phr);
965 return;
966 }
967
968 hpi_init_response(phr, phm->object, phm->function, 0);
969
970 status = &interface->outstream_host_buffer_status[phm->obj_index];
971
972 phr->u.d.u.stream_info.state = (u16)status->stream_state;
973 phr->u.d.u.stream_info.samples_transferred =
974 status->samples_processed;
975 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
976 phr->u.d.u.stream_info.data_available =
977 status->size_in_bytes - outstream_get_space_available(status);
978 phr->u.d.u.stream_info.auxiliary_data_available =
979 status->auxiliary_data_available;
980}
981
982static void outstream_start(struct hpi_adapter_obj *pao,
983 struct hpi_message *phm, struct hpi_response *phr)
984{
985 hw_message(pao, phm, phr);
986}
987
988static void outstream_reset(struct hpi_adapter_obj *pao,
989 struct hpi_message *phm, struct hpi_response *phr)
990{
991 struct hpi_hw_obj *phw = pao->priv;
992 phw->flag_outstream_just_reset[phm->obj_index] = 1;
993 hw_message(pao, phm, phr);
994}
995
996static void outstream_open(struct hpi_adapter_obj *pao,
997 struct hpi_message *phm, struct hpi_response *phr)
998{
999 outstream_reset(pao, phm, phr);
1000}
1001
1002/*****************************************************************************/
1003/* InStream Host buffer functions */
1004
1005static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
1006 struct hpi_message *phm, struct hpi_response *phr)
1007{
1008 u16 err = 0;
1009 u32 command = phm->u.d.u.buffer.command;
1010 struct hpi_hw_obj *phw = pao->priv;
1011 struct bus_master_interface *interface = phw->p_interface_buffer;
1012
1013 hpi_init_response(phr, phm->object, phm->function, 0);
1014
1015 if (command == HPI_BUFFER_CMD_EXTERNAL
1016 || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
1017
1018 phm->u.d.u.buffer.buffer_size =
1019 roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
1020 phr->u.d.u.stream_info.data_available =
1021 phw->instream_host_buffer_size[phm->obj_index];
1022 phr->u.d.u.stream_info.buffer_size =
1023 phm->u.d.u.buffer.buffer_size;
1024
1025 if (phw->instream_host_buffer_size[phm->obj_index] ==
1026 phm->u.d.u.buffer.buffer_size) {
1027 /* Same size, no action required */
1028 return;
1029 }
1030
1031 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1032 obj_index]))
1033 hpios_locked_mem_free(&phw->instream_host_buffers
1034 [phm->obj_index]);
1035
1036 err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
1037 obj_index], phm->u.d.u.buffer.buffer_size,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001038 pao->pci.pci_dev);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001039
1040 if (err) {
1041 phr->error = HPI_ERROR_INVALID_DATASIZE;
1042 phw->instream_host_buffer_size[phm->obj_index] = 0;
1043 return;
1044 }
1045
1046 err = hpios_locked_mem_get_phys_addr
1047 (&phw->instream_host_buffers[phm->obj_index],
1048 &phm->u.d.u.buffer.pci_address);
1049 /* get the phys addr into msg for single call alloc. Caller
1050 needs to do this for split alloc so return the phy address */
1051 phr->u.d.u.stream_info.auxiliary_data_available =
1052 phm->u.d.u.buffer.pci_address;
1053 if (err) {
1054 hpios_locked_mem_free(&phw->instream_host_buffers
1055 [phm->obj_index]);
1056 phw->instream_host_buffer_size[phm->obj_index] = 0;
1057 phr->error = HPI_ERROR_MEMORY_ALLOC;
1058 return;
1059 }
1060 }
1061
1062 if (command == HPI_BUFFER_CMD_EXTERNAL
1063 || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
1064 struct hpi_hostbuffer_status *status;
1065
1066 if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
1067 buffer_size - 1)) {
1068 HPI_DEBUG_LOG(ERROR,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001069 "Buffer size must be 2^N not %d\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001070 phm->u.d.u.buffer.buffer_size);
1071 phr->error = HPI_ERROR_INVALID_DATASIZE;
1072 return;
1073 }
1074
1075 phw->instream_host_buffer_size[phm->obj_index] =
1076 phm->u.d.u.buffer.buffer_size;
1077 status = &interface->instream_host_buffer_status[phm->
1078 obj_index];
1079 status->samples_processed = 0;
1080 status->stream_state = HPI_STATE_STOPPED;
Eliot Blennerhassett8e0874e2011-12-22 13:38:36 +13001081 status->dsp_index = 0;
1082 status->host_index = status->dsp_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001083 status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +13001084 status->auxiliary_data_available = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001085
1086 hw_message(pao, phm, phr);
Eliot Blennerhassettba3a9092011-02-10 17:26:14 +13001087
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001088 if (phr->error
1089 && hpios_locked_mem_valid(&phw->
1090 instream_host_buffers[phm->obj_index])) {
1091 hpios_locked_mem_free(&phw->instream_host_buffers
1092 [phm->obj_index]);
1093 phw->instream_host_buffer_size[phm->obj_index] = 0;
1094 }
1095 }
1096}
1097
1098static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
1099 struct hpi_message *phm, struct hpi_response *phr)
1100{
1101 struct hpi_hw_obj *phw = pao->priv;
1102 struct bus_master_interface *interface = phw->p_interface_buffer;
1103 struct hpi_hostbuffer_status *status;
1104 u8 *p_bbm_data;
1105
1106 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1107 obj_index])) {
1108 if (hpios_locked_mem_get_virt_addr(&phw->
1109 instream_host_buffers[phm->obj_index],
1110 (void *)&p_bbm_data)) {
1111 phr->error = HPI_ERROR_INVALID_OPERATION;
1112 return;
1113 }
1114 status = &interface->instream_host_buffer_status[phm->
1115 obj_index];
1116 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1117 HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
1118 phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
1119 phr->u.d.u.hostbuffer_info.p_status = status;
1120 } else {
1121 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1122 HPI_ISTREAM_HOSTBUFFER_GET_INFO,
1123 HPI_ERROR_INVALID_OPERATION);
1124 }
1125}
1126
1127static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
1128 struct hpi_message *phm, struct hpi_response *phr)
1129{
1130 struct hpi_hw_obj *phw = pao->priv;
1131 u32 command = phm->u.d.u.buffer.command;
1132
1133 if (phw->instream_host_buffer_size[phm->obj_index]) {
1134 if (command == HPI_BUFFER_CMD_EXTERNAL
1135 || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
1136 phw->instream_host_buffer_size[phm->obj_index] = 0;
1137 hw_message(pao, phm, phr);
1138 }
1139
1140 if (command == HPI_BUFFER_CMD_EXTERNAL
1141 || command == HPI_BUFFER_CMD_INTERNAL_FREE)
1142 hpios_locked_mem_free(&phw->instream_host_buffers
1143 [phm->obj_index]);
1144
1145 } else {
1146 /* Should HPI_ERROR_INVALID_OPERATION be returned
1147 if no host buffer is allocated? */
1148 hpi_init_response(phr, HPI_OBJ_ISTREAM,
1149 HPI_ISTREAM_HOSTBUFFER_FREE, 0);
1150
1151 }
1152
1153}
1154
1155static void instream_start(struct hpi_adapter_obj *pao,
1156 struct hpi_message *phm, struct hpi_response *phr)
1157{
1158 hw_message(pao, phm, phr);
1159}
1160
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +12001161static u32 instream_get_bytes_available(struct hpi_hostbuffer_status *status)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001162{
Eliot Blennerhassett8e0874e2011-12-22 13:38:36 +13001163 return status->dsp_index - status->host_index;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001164}
1165
1166static void instream_read(struct hpi_adapter_obj *pao,
1167 struct hpi_message *phm, struct hpi_response *phr)
1168{
1169 struct hpi_hw_obj *phw = pao->priv;
1170 struct bus_master_interface *interface = phw->p_interface_buffer;
1171 struct hpi_hostbuffer_status *status;
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +12001172 u32 data_available;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001173 u8 *p_bbm_data;
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +12001174 u32 l_first_read;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001175 u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
1176
1177 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1178 hw_message(pao, phm, phr);
1179 return;
1180 }
1181 hpi_init_response(phr, phm->object, phm->function, 0);
1182
1183 status = &interface->instream_host_buffer_status[phm->obj_index];
1184 data_available = instream_get_bytes_available(status);
Eliot Blennerhassett2a383cb2010-06-17 17:08:36 +12001185 if (data_available < phm->u.d.u.data.data_size) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001186 phr->error = HPI_ERROR_INVALID_DATASIZE;
1187 return;
1188 }
1189
1190 if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
1191 obj_index])) {
1192 if (hpios_locked_mem_get_virt_addr(&phw->
1193 instream_host_buffers[phm->obj_index],
1194 (void *)&p_bbm_data)) {
1195 phr->error = HPI_ERROR_INVALID_OPERATION;
1196 return;
1197 }
1198
1199 /* either all data,
1200 or enough to fit from current to end of BBM buffer */
1201 l_first_read =
1202 min(phm->u.d.u.data.data_size,
1203 status->size_in_bytes -
1204 (status->host_index & (status->size_in_bytes - 1)));
1205
1206 memcpy(p_app_data,
1207 p_bbm_data +
1208 (status->host_index & (status->size_in_bytes - 1)),
1209 l_first_read);
1210 /* remaining data if any */
1211 memcpy(p_app_data + l_first_read, p_bbm_data,
1212 phm->u.d.u.data.data_size - l_first_read);
1213 }
1214 status->host_index += phm->u.d.u.data.data_size;
1215}
1216
1217static void instream_get_info(struct hpi_adapter_obj *pao,
1218 struct hpi_message *phm, struct hpi_response *phr)
1219{
1220 struct hpi_hw_obj *phw = pao->priv;
1221 struct bus_master_interface *interface = phw->p_interface_buffer;
1222 struct hpi_hostbuffer_status *status;
1223 if (!phw->instream_host_buffer_size[phm->obj_index]) {
1224 hw_message(pao, phm, phr);
1225 return;
1226 }
1227
1228 status = &interface->instream_host_buffer_status[phm->obj_index];
1229
1230 hpi_init_response(phr, phm->object, phm->function, 0);
1231
1232 phr->u.d.u.stream_info.state = (u16)status->stream_state;
1233 phr->u.d.u.stream_info.samples_transferred =
1234 status->samples_processed;
1235 phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
1236 phr->u.d.u.stream_info.data_available =
1237 instream_get_bytes_available(status);
1238 phr->u.d.u.stream_info.auxiliary_data_available =
1239 status->auxiliary_data_available;
1240}
1241
1242/*****************************************************************************/
1243/* LOW-LEVEL */
1244#define HPI6205_MAX_FILES_TO_LOAD 2
1245
1246static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
1247 u32 *pos_error_code)
1248{
1249 struct hpi_hw_obj *phw = pao->priv;
1250 struct dsp_code dsp_code;
1251 u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001252 u32 temp;
1253 int dsp = 0, i = 0;
1254 u16 err = 0;
1255
1256 boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
1257
Eliot Blennerhassettee246fc2011-02-10 17:26:13 +13001258 boot_code_id[1] = pao->pci.pci_dev->subsystem_device;
1259 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(boot_code_id[1]);
1260
1261 /* fix up cases where bootcode id[1] != subsys id */
1262 switch (boot_code_id[1]) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001263 case HPI_ADAPTER_FAMILY_ASI(0x5000):
Eliot Blennerhassettee246fc2011-02-10 17:26:13 +13001264 boot_code_id[0] = boot_code_id[1];
1265 boot_code_id[1] = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001266 break;
1267 case HPI_ADAPTER_FAMILY_ASI(0x5300):
1268 case HPI_ADAPTER_FAMILY_ASI(0x5400):
1269 case HPI_ADAPTER_FAMILY_ASI(0x6300):
Eliot Blennerhassettee246fc2011-02-10 17:26:13 +13001270 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6400);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001271 break;
Eliot Blennerhassett6d0b8982011-04-05 20:55:47 +12001272 case HPI_ADAPTER_FAMILY_ASI(0x5500):
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001273 case HPI_ADAPTER_FAMILY_ASI(0x5600):
1274 case HPI_ADAPTER_FAMILY_ASI(0x6500):
Eliot Blennerhassettee246fc2011-02-10 17:26:13 +13001275 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x6600);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001276 break;
Eliot Blennerhassettcadae422010-05-27 17:53:54 +12001277 case HPI_ADAPTER_FAMILY_ASI(0x8800):
Eliot Blennerhassettee246fc2011-02-10 17:26:13 +13001278 boot_code_id[1] = HPI_ADAPTER_FAMILY_ASI(0x8900);
1279 break;
1280 default:
Eliot Blennerhassettcadae422010-05-27 17:53:54 +12001281 break;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001282 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001283
1284 /* reset DSP by writing a 1 to the WARMRESET bit */
1285 temp = C6205_HDCR_WARMRESET;
1286 iowrite32(temp, phw->prHDCR);
1287 hpios_delay_micro_seconds(1000);
1288
1289 /* check that PCI i/f was configured by EEPROM */
1290 temp = ioread32(phw->prHSR);
1291 if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
1292 C6205_HSR_EEREAD)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001293 return HPI6205_ERROR_6205_EEPROM;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001294 temp |= 0x04;
1295 /* disable PINTA interrupt */
1296 iowrite32(temp, phw->prHSR);
1297
1298 /* check control register reports PCI boot mode */
1299 temp = ioread32(phw->prHDCR);
1300 if (!(temp & C6205_HDCR_PCIBOOT))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001301 return HPI6205_ERROR_6205_REG;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001302
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001303 /* try writing a few numbers to the DSP page register */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001304 /* and reading them back. */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001305 temp = 3;
1306 iowrite32(temp, phw->prDSPP);
1307 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001308 return HPI6205_ERROR_6205_DSPPAGE;
1309 temp = 2;
1310 iowrite32(temp, phw->prDSPP);
1311 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1312 return HPI6205_ERROR_6205_DSPPAGE;
1313 temp = 1;
1314 iowrite32(temp, phw->prDSPP);
1315 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
1316 return HPI6205_ERROR_6205_DSPPAGE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001317 /* reset DSP page to the correct number */
1318 temp = 0;
1319 iowrite32(temp, phw->prDSPP);
1320 if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001321 return HPI6205_ERROR_6205_DSPPAGE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001322 phw->dsp_page = 0;
1323
1324 /* release 6713 from reset before 6205 is bootloaded.
1325 This ensures that the EMIF is inactive,
1326 and the 6713 HPI gets the correct bootmode etc
1327 */
1328 if (boot_code_id[1] != 0) {
1329 /* DSP 1 is a C6713 */
1330 /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
1331 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
1332 hpios_delay_micro_seconds(100);
1333 /* Reset the 6713 #1 - revB */
1334 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
1335
1336 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1337 boot_loader_read_mem32(pao, 0, 0);
1338
1339 hpios_delay_micro_seconds(100);
1340 /* Release C6713 from reset - revB */
1341 boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
1342 hpios_delay_micro_seconds(100);
1343 }
1344
1345 for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
1346 /* is there a DSP to load? */
1347 if (boot_code_id[dsp] == 0)
1348 continue;
1349
1350 err = boot_loader_config_emif(pao, dsp);
1351 if (err)
1352 return err;
1353
1354 err = boot_loader_test_internal_memory(pao, dsp);
1355 if (err)
1356 return err;
1357
1358 err = boot_loader_test_external_memory(pao, dsp);
1359 if (err)
1360 return err;
1361
1362 err = boot_loader_test_pld(pao, dsp);
1363 if (err)
1364 return err;
1365
1366 /* write the DSP code down into the DSPs memory */
Eliot Blennerhassett95a4c6e2011-07-22 15:52:42 +12001367 err = hpi_dsp_code_open(boot_code_id[dsp], pao->pci.pci_dev,
1368 &dsp_code, pos_error_code);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001369 if (err)
1370 return err;
1371
1372 while (1) {
1373 u32 length;
1374 u32 address;
1375 u32 type;
1376 u32 *pcode;
1377
1378 err = hpi_dsp_code_read_word(&dsp_code, &length);
1379 if (err)
1380 break;
1381 if (length == 0xFFFFFFFF)
1382 break; /* end of code */
1383
1384 err = hpi_dsp_code_read_word(&dsp_code, &address);
1385 if (err)
1386 break;
1387 err = hpi_dsp_code_read_word(&dsp_code, &type);
1388 if (err)
1389 break;
1390 err = hpi_dsp_code_read_block(length, &dsp_code,
1391 &pcode);
1392 if (err)
1393 break;
1394 for (i = 0; i < (int)length; i++) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001395 boot_loader_write_mem32(pao, dsp, address,
1396 *pcode);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001397 /* dummy read every 4 words */
1398 /* for 6205 advisory 1.4.4 */
1399 if (i % 4 == 0)
1400 boot_loader_read_mem32(pao, dsp,
1401 address);
1402 pcode++;
1403 address += 4;
1404 }
1405
1406 }
1407 if (err) {
1408 hpi_dsp_code_close(&dsp_code);
1409 return err;
1410 }
1411
1412 /* verify code */
1413 hpi_dsp_code_rewind(&dsp_code);
1414 while (1) {
1415 u32 length = 0;
1416 u32 address = 0;
1417 u32 type = 0;
1418 u32 *pcode = NULL;
1419 u32 data = 0;
1420
1421 hpi_dsp_code_read_word(&dsp_code, &length);
1422 if (length == 0xFFFFFFFF)
1423 break; /* end of code */
1424
1425 hpi_dsp_code_read_word(&dsp_code, &address);
1426 hpi_dsp_code_read_word(&dsp_code, &type);
1427 hpi_dsp_code_read_block(length, &dsp_code, &pcode);
1428
1429 for (i = 0; i < (int)length; i++) {
1430 data = boot_loader_read_mem32(pao, dsp,
1431 address);
1432 if (data != *pcode) {
1433 err = 0;
1434 break;
1435 }
1436 pcode++;
1437 address += 4;
1438 }
1439 if (err)
1440 break;
1441 }
1442 hpi_dsp_code_close(&dsp_code);
1443 if (err)
1444 return err;
1445 }
1446
1447 /* After bootloading all DSPs, start DSP0 running
1448 * The DSP0 code will handle starting and synchronizing with its slaves
1449 */
1450 if (phw->p_interface_buffer) {
1451 /* we need to tell the card the physical PCI address */
1452 u32 physicalPC_iaddress;
1453 struct bus_master_interface *interface =
1454 phw->p_interface_buffer;
1455 u32 host_mailbox_address_on_dsp;
1456 u32 physicalPC_iaddress_verify = 0;
1457 int time_out = 10;
1458 /* set ack so we know when DSP is ready to go */
1459 /* (dwDspAck will be changed to HIF_RESET) */
1460 interface->dsp_ack = H620_HIF_UNKNOWN;
1461 wmb(); /* ensure ack is written before dsp writes back */
1462
1463 err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
1464 &physicalPC_iaddress);
1465
1466 /* locate the host mailbox on the DSP. */
1467 host_mailbox_address_on_dsp = 0x80000000;
1468 while ((physicalPC_iaddress != physicalPC_iaddress_verify)
1469 && time_out--) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001470 boot_loader_write_mem32(pao, 0,
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001471 host_mailbox_address_on_dsp,
1472 physicalPC_iaddress);
1473 physicalPC_iaddress_verify =
1474 boot_loader_read_mem32(pao, 0,
1475 host_mailbox_address_on_dsp);
1476 }
1477 }
1478 HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
1479 /* enable interrupts */
1480 temp = ioread32(phw->prHSR);
1481 temp &= ~(u32)C6205_HSR_INTAM;
1482 iowrite32(temp, phw->prHSR);
1483
1484 /* start code running... */
1485 temp = ioread32(phw->prHDCR);
1486 temp |= (u32)C6205_HDCR_DSPINT;
1487 iowrite32(temp, phw->prHDCR);
1488
1489 /* give the DSP 10ms to start up */
1490 hpios_delay_micro_seconds(10000);
1491 return err;
1492
1493}
1494
1495/*****************************************************************************/
1496/* Bootloader utility functions */
1497
1498static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
1499 u32 address)
1500{
1501 struct hpi_hw_obj *phw = pao->priv;
1502 u32 data = 0;
1503 __iomem u32 *p_data;
1504
1505 if (dsp_index == 0) {
1506 /* DSP 0 is always C6205 */
1507 if ((address >= 0x01800000) & (address < 0x02000000)) {
1508 /* BAR1 register access */
1509 p_data = pao->pci.ap_mem_base[1] +
1510 (address & 0x007fffff) /
1511 sizeof(*pao->pci.ap_mem_base[1]);
1512 /* HPI_DEBUG_LOG(WARNING,
1513 "BAR1 access %08x\n", dwAddress); */
1514 } else {
1515 u32 dw4M_page = address >> 22L;
1516 if (dw4M_page != phw->dsp_page) {
1517 phw->dsp_page = dw4M_page;
1518 /* *INDENT OFF* */
1519 iowrite32(phw->dsp_page, phw->prDSPP);
1520 /* *INDENT-ON* */
1521 }
1522 address &= 0x3fffff; /* address within 4M page */
1523 /* BAR0 memory access */
1524 p_data = pao->pci.ap_mem_base[0] +
1525 address / sizeof(u32);
1526 }
1527 data = ioread32(p_data);
1528 } else if (dsp_index == 1) {
1529 /* DSP 1 is a C6713 */
1530 u32 lsb;
1531 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1532 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1533 lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
1534 data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
1535 data = (data << 16) | (lsb & 0xFFFF);
1536 }
1537 return data;
1538}
1539
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001540static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
1541 int dsp_index, u32 address, u32 data)
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001542{
1543 struct hpi_hw_obj *phw = pao->priv;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001544 __iomem u32 *p_data;
1545 /* u32 dwVerifyData=0; */
1546
1547 if (dsp_index == 0) {
1548 /* DSP 0 is always C6205 */
1549 if ((address >= 0x01800000) & (address < 0x02000000)) {
1550 /* BAR1 - DSP register access using */
1551 /* Non-prefetchable PCI access */
1552 p_data = pao->pci.ap_mem_base[1] +
1553 (address & 0x007fffff) /
1554 sizeof(*pao->pci.ap_mem_base[1]);
1555 } else {
1556 /* BAR0 access - all of DSP memory using */
1557 /* pre-fetchable PCI access */
1558 u32 dw4M_page = address >> 22L;
1559 if (dw4M_page != phw->dsp_page) {
1560 phw->dsp_page = dw4M_page;
1561 /* *INDENT-OFF* */
1562 iowrite32(phw->dsp_page, phw->prDSPP);
1563 /* *INDENT-ON* */
1564 }
1565 address &= 0x3fffff; /* address within 4M page */
1566 p_data = pao->pci.ap_mem_base[0] +
1567 address / sizeof(u32);
1568 }
1569 iowrite32(data, p_data);
1570 } else if (dsp_index == 1) {
1571 /* DSP 1 is a C6713 */
1572 boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
1573 boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
1574
1575 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1576 boot_loader_read_mem32(pao, 0, 0);
1577
1578 boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
1579 boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
1580
1581 /* dummy read every 4 words for 6205 advisory 1.4.4 */
1582 boot_loader_read_mem32(pao, 0, 0);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001583 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001584}
1585
1586static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
1587{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001588 if (dsp_index == 0) {
1589 u32 setting;
1590
1591 /* DSP 0 is always C6205 */
1592
1593 /* Set the EMIF */
1594 /* memory map of C6205 */
1595 /* 00000000-0000FFFF 16Kx32 internal program */
1596 /* 00400000-00BFFFFF CE0 2Mx32 SDRAM running @ 100MHz */
1597
1598 /* EMIF config */
1599 /*------------ */
1600 /* Global EMIF control */
1601 boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
1602#define WS_OFS 28
1603#define WST_OFS 22
1604#define WH_OFS 20
1605#define RS_OFS 16
1606#define RST_OFS 8
1607#define MTYPE_OFS 4
1608#define RH_OFS 0
1609
1610 /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
1611 setting = 0x00000030;
1612 boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
1613 if (setting != boot_loader_read_mem32(pao, dsp_index,
1614 0x01800008))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001615 return HPI6205_ERROR_DSP_EMIF;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001616
1617 /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
1618 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1619 /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
1620 /* WST should be 71, but 63 is max possible */
1621 setting =
1622 (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
1623 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1624 (2L << MTYPE_OFS);
1625 boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
1626 if (setting != boot_loader_read_mem32(pao, dsp_index,
1627 0x01800004))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001628 return HPI6205_ERROR_DSP_EMIF;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001629
1630 /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
1631 /* which occupies D15..0. 6713 starts at 27MHz, so need */
1632 /* plenty of wait states */
1633 setting =
1634 (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
1635 (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
1636 (2L << MTYPE_OFS);
1637 boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
1638 if (setting != boot_loader_read_mem32(pao, dsp_index,
1639 0x01800010))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001640 return HPI6205_ERROR_DSP_EMIF;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001641
1642 /* EMIF CE3 setup - 32 bit async. */
1643 /* This is the PLD on the ASI5000 cards only */
1644 setting =
1645 (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
1646 (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
1647 (2L << MTYPE_OFS);
1648 boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
1649 if (setting != boot_loader_read_mem32(pao, dsp_index,
1650 0x01800014))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001651 return HPI6205_ERROR_DSP_EMIF;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001652
1653 /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
1654 /* need to use this else DSP code crashes? */
1655 boot_loader_write_mem32(pao, dsp_index, 0x01800018,
1656 0x07117000);
1657
1658 /* EMIF SDRAM Refresh Timing */
1659 /* EMIF SDRAM timing (orig = 0x410, emulator = 0x61a) */
1660 boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
1661 0x00000410);
1662
1663 } else if (dsp_index == 1) {
1664 /* test access to the C6713s HPI registers */
1665 u32 write_data = 0, read_data = 0, i = 0;
1666
1667 /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
1668 write_data = 1;
1669 boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
1670 boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
1671 /* C67 HPI is on lower 16bits of 32bit EMIF */
1672 read_data =
1673 0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
1674 if (write_data != read_data) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001675 HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
1676 read_data);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001677 return HPI6205_ERROR_C6713_HPIC;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001678 }
1679 /* HPIA - walking ones test */
1680 write_data = 1;
1681 for (i = 0; i < 32; i++) {
1682 boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
1683 write_data);
1684 boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
1685 (write_data >> 16));
1686 read_data =
1687 0xFFFF & boot_loader_read_mem32(pao, 0,
1688 HPIAL_ADDR);
1689 read_data =
1690 read_data | ((0xFFFF &
1691 boot_loader_read_mem32(pao, 0,
1692 HPIAH_ADDR))
1693 << 16);
1694 if (read_data != write_data) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001695 HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
1696 write_data, read_data);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001697 return HPI6205_ERROR_C6713_HPIA;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001698 }
1699 write_data = write_data << 1;
1700 }
1701
1702 /* setup C67x PLL
1703 * ** C6713 datasheet says we cannot program PLL from HPI,
1704 * and indeed if we try to set the PLL multiply from the HPI,
1705 * the PLL does not seem to lock, so we enable the PLL and
1706 * use the default multiply of x 7, which for a 27MHz clock
1707 * gives a DSP speed of 189MHz
1708 */
1709 /* bypass PLL */
1710 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
1711 hpios_delay_micro_seconds(1000);
1712 /* EMIF = 189/3=63MHz */
1713 boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
1714 /* peri = 189/2 */
1715 boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
1716 /* cpu = 189/1 */
1717 boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
1718 hpios_delay_micro_seconds(1000);
1719 /* ** SGT test to take GPO3 high when we start the PLL */
1720 /* and low when the delay is completed */
1721 /* FSX0 <- '1' (GPO3) */
1722 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
1723 /* PLL not bypassed */
1724 boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
1725 hpios_delay_micro_seconds(1000);
1726 /* FSX0 <- '0' (GPO3) */
1727 boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
1728
1729 /* 6205 EMIF CE1 resetup - 32 bit async. */
1730 /* Now 6713 #1 is running at 189MHz can reduce waitstates */
1731 boot_loader_write_mem32(pao, 0, 0x01800004, /* CE1 */
1732 (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
1733 (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
1734 (2L << MTYPE_OFS));
1735
1736 hpios_delay_micro_seconds(1000);
1737
1738 /* check that we can read one of the PLL registers */
1739 /* PLL should not be bypassed! */
1740 if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
1741 != 0x0001) {
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001742 return HPI6205_ERROR_C6713_PLL;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001743 }
1744 /* setup C67x EMIF (note this is the only use of
1745 BAR1 via BootLoader_WriteMem32) */
1746 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
1747 0x000034A8);
Eliot Blennerhassett1d595d22011-02-10 17:26:08 +13001748
1749 /* EMIF CE0 setup - 2Mx32 Sync DRAM
1750 31..28 Wr setup
1751 27..22 Wr strobe
1752 21..20 Wr hold
1753 19..16 Rd setup
1754 15..14 -
1755 13..8 Rd strobe
1756 7..4 MTYPE 0011 Sync DRAM 32bits
1757 3 Wr hold MSB
1758 2..0 Rd hold
1759 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001760 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
1761 0x00000030);
Eliot Blennerhassett1d595d22011-02-10 17:26:08 +13001762
1763 /* EMIF SDRAM Extension
1764 0x00
1765 31-21 0000b 0000b 000b
1766 20 WR2RD = 2cycles-1 = 1b
1767
1768 19-18 WR2DEAC = 3cycle-1 = 10b
1769 17 WR2WR = 2cycle-1 = 1b
1770 16-15 R2WDQM = 4cycle-1 = 11b
1771 14-12 RD2WR = 6cycles-1 = 101b
1772
1773 11-10 RD2DEAC = 4cycle-1 = 11b
1774 9 RD2RD = 2cycle-1 = 1b
1775 8-7 THZP = 3cycle-1 = 10b
1776 6-5 TWR = 2cycle-1 = 01b (tWR = 17ns)
1777 4 TRRD = 2cycle = 0b (tRRD = 14ns)
1778 3-1 TRAS = 5cycle-1 = 100b (Tras=42ns)
1779 1 CAS latency = 3cyc = 1b
1780 (for Micron 2M32-7 operating at 100MHz)
1781 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001782 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
1783 0x001BDF29);
Eliot Blennerhassett1d595d22011-02-10 17:26:08 +13001784
1785 /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
1786 31 - 0b -
1787 30 SDBSZ 1b 4 bank
1788 29..28 SDRSZ 00b 11 row address pins
1789
1790 27..26 SDCSZ 01b 8 column address pins
1791 25 RFEN 1b refersh enabled
1792 24 INIT 1b init SDRAM!
1793
1794 23..20 TRCD 0001b (Trcd/Tcyc)-1 = (20/10)-1 = 1
1795
1796 19..16 TRP 0001b (Trp/Tcyc)-1 = (20/10)-1 = 1
1797
1798 15..12 TRC 0110b (Trc/Tcyc)-1 = (70/10)-1 = 6
1799
1800 11..0 - 0000b 0000b 0000b
1801 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001802 boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
Eliot Blennerhassett1d595d22011-02-10 17:26:08 +13001803 0x47116000);
1804
1805 /* SDRAM refresh timing
1806 Need 4,096 refresh cycles every 64ms = 15.625us = 1562cycles of 100MHz = 0x61A
1807 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001808 boot_loader_write_mem32(pao, dsp_index,
1809 C6713_EMIF_SDRAMTIMING, 0x00000410);
1810
1811 hpios_delay_micro_seconds(1000);
1812 } else if (dsp_index == 2) {
1813 /* DSP 2 is a C6713 */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001814 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001815
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001816 return 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001817}
1818
1819static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
1820 u32 start_address, u32 length)
1821{
1822 u32 i = 0, j = 0;
1823 u32 test_addr = 0;
1824 u32 test_data = 0, data = 0;
1825
1826 length = 1000;
1827
1828 /* for 1st word, test each bit in the 32bit word, */
1829 /* dwLength specifies number of 32bit words to test */
1830 /*for(i=0; i<dwLength; i++) */
1831 i = 0;
1832 {
1833 test_addr = start_address + i * 4;
1834 test_data = 0x00000001;
1835 for (j = 0; j < 32; j++) {
1836 boot_loader_write_mem32(pao, dsp_index, test_addr,
1837 test_data);
1838 data = boot_loader_read_mem32(pao, dsp_index,
1839 test_addr);
1840 if (data != test_data) {
1841 HPI_DEBUG_LOG(VERBOSE,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001842 "Memtest error details "
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001843 "%08x %08x %08x %i\n", test_addr,
1844 test_data, data, dsp_index);
1845 return 1; /* error */
1846 }
1847 test_data = test_data << 1;
1848 } /* for(j) */
1849 } /* for(i) */
1850
1851 /* for the next 100 locations test each location, leaving it as zero */
1852 /* write a zero to the next word in memory before we read */
1853 /* the previous write to make sure every memory location is unique */
1854 for (i = 0; i < 100; i++) {
1855 test_addr = start_address + i * 4;
1856 test_data = 0xA5A55A5A;
1857 boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
1858 boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
1859 data = boot_loader_read_mem32(pao, dsp_index, test_addr);
1860 if (data != test_data) {
1861 HPI_DEBUG_LOG(VERBOSE,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001862 "Memtest error details "
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001863 "%08x %08x %08x %i\n", test_addr, test_data,
1864 data, dsp_index);
1865 return 1; /* error */
1866 }
1867 /* leave location as zero */
1868 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1869 }
1870
1871 /* zero out entire memory block */
1872 for (i = 0; i < length; i++) {
1873 test_addr = start_address + i * 4;
1874 boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
1875 }
1876 return 0;
1877}
1878
1879static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
1880 int dsp_index)
1881{
1882 int err = 0;
1883 if (dsp_index == 0) {
1884 /* DSP 0 is a C6205 */
1885 /* 64K prog mem */
1886 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1887 0x10000);
1888 if (!err)
1889 /* 64K data mem */
1890 err = boot_loader_test_memory(pao, dsp_index,
1891 0x80000000, 0x10000);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001892 } else if (dsp_index == 1) {
1893 /* DSP 1 is a C6713 */
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001894 /* 192K internal mem */
1895 err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
1896 0x30000);
1897 if (!err)
1898 /* 64K internal mem / L2 cache */
1899 err = boot_loader_test_memory(pao, dsp_index,
1900 0x00030000, 0x10000);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001901 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001902
1903 if (err)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001904 return HPI6205_ERROR_DSP_INTMEM;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001905 else
1906 return 0;
1907}
1908
1909static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
1910 int dsp_index)
1911{
1912 u32 dRAM_start_address = 0;
1913 u32 dRAM_size = 0;
1914
1915 if (dsp_index == 0) {
1916 /* only test for SDRAM if an ASI5000 card */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001917 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001918 /* DSP 0 is always C6205 */
1919 dRAM_start_address = 0x00400000;
1920 dRAM_size = 0x200000;
1921 /*dwDRAMinc=1024; */
1922 } else
1923 return 0;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001924 } else if (dsp_index == 1) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001925 /* DSP 1 is a C6713 */
1926 dRAM_start_address = 0x80000000;
1927 dRAM_size = 0x200000;
1928 /*dwDRAMinc=1024; */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001929 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001930
1931 if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
1932 dRAM_size))
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001933 return HPI6205_ERROR_DSP_EXTMEM;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001934 return 0;
1935}
1936
1937static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
1938{
1939 u32 data = 0;
1940 if (dsp_index == 0) {
1941 /* only test for DSP0 PLD on ASI5000 card */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001942 if (pao->pci.pci_dev->subsystem_device == 0x5000) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001943 /* PLD is located at CE3=0x03000000 */
1944 data = boot_loader_read_mem32(pao, dsp_index,
1945 0x03000008);
1946 if ((data & 0xF) != 0x5)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001947 return HPI6205_ERROR_DSP_PLD;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001948 data = boot_loader_read_mem32(pao, dsp_index,
1949 0x0300000C);
1950 if ((data & 0xF) != 0xA)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001951 return HPI6205_ERROR_DSP_PLD;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001952 }
1953 } else if (dsp_index == 1) {
1954 /* DSP 1 is a C6713 */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001955 if (pao->pci.pci_dev->subsystem_device == 0x8700) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001956 /* PLD is located at CE1=0x90000000 */
1957 data = boot_loader_read_mem32(pao, dsp_index,
1958 0x90000010);
1959 if ((data & 0xFF) != 0xAA)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13001960 return HPI6205_ERROR_DSP_PLD;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001961 /* 8713 - LED on */
1962 boot_loader_write_mem32(pao, dsp_index, 0x90000000,
1963 0x02);
1964 }
1965 }
1966 return 0;
1967}
1968
1969/** Transfer data to or from DSP
1970 nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
1971*/
1972static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
1973 u32 data_size, int operation)
1974{
1975 struct hpi_hw_obj *phw = pao->priv;
1976 u32 data_transferred = 0;
1977 u16 err = 0;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001978 u32 temp2;
1979 struct bus_master_interface *interface = phw->p_interface_buffer;
1980
1981 if (!p_data)
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +13001982 return HPI_ERROR_INVALID_DATA_POINTER;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02001983
1984 data_size &= ~3L; /* round data_size down to nearest 4 bytes */
1985
1986 /* make sure state is IDLE */
1987 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
1988 return HPI_ERROR_DSP_HARDWARE;
1989
1990 while (data_transferred < data_size) {
1991 u32 this_copy = data_size - data_transferred;
1992
1993 if (this_copy > HPI6205_SIZEOF_DATA)
1994 this_copy = HPI6205_SIZEOF_DATA;
1995
1996 if (operation == H620_HIF_SEND_DATA)
1997 memcpy((void *)&interface->u.b_data[0],
1998 &p_data[data_transferred], this_copy);
1999
2000 interface->transfer_size_in_bytes = this_copy;
2001
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002002 /* DSP must change this back to nOperation */
2003 interface->dsp_ack = H620_HIF_IDLE;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002004 send_dsp_command(phw, operation);
2005
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002006 temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
2007 HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
2008 HPI6205_TIMEOUT - temp2, this_copy);
2009
2010 if (!temp2) {
2011 /* timed out */
2012 HPI_DEBUG_LOG(ERROR,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002013 "Timed out waiting for " "state %d got %d\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002014 operation, interface->dsp_ack);
2015
2016 break;
2017 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002018 if (operation == H620_HIF_GET_DATA)
2019 memcpy(&p_data[data_transferred],
2020 (void *)&interface->u.b_data[0], this_copy);
2021
2022 data_transferred += this_copy;
2023 }
2024 if (interface->dsp_ack != operation)
2025 HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
2026 interface->dsp_ack, operation);
2027 /* err=HPI_ERROR_DSP_HARDWARE; */
2028
2029 send_dsp_command(phw, H620_HIF_IDLE);
2030
2031 return err;
2032}
2033
2034/* wait for up to timeout_us microseconds for the DSP
2035 to signal state by DMA into dwDspAck
2036*/
2037static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
2038{
2039 struct bus_master_interface *interface = phw->p_interface_buffer;
2040 int t = timeout_us / 4;
2041
2042 rmb(); /* ensure interface->dsp_ack is up to date */
2043 while ((interface->dsp_ack != state) && --t) {
2044 hpios_delay_micro_seconds(4);
2045 rmb(); /* DSP changes dsp_ack by DMA */
2046 }
2047
2048 /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
2049 return t * 4;
2050}
2051
2052/* set the busmaster interface to cmd, then interrupt the DSP */
2053static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
2054{
2055 struct bus_master_interface *interface = phw->p_interface_buffer;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002056 u32 r;
2057
2058 interface->host_cmd = cmd;
2059 wmb(); /* DSP gets state by DMA, make sure it is written to memory */
2060 /* before we interrupt the DSP */
2061 r = ioread32(phw->prHDCR);
2062 r |= (u32)C6205_HDCR_DSPINT;
2063 iowrite32(r, phw->prHDCR);
2064 r &= ~(u32)C6205_HDCR_DSPINT;
2065 iowrite32(r, phw->prHDCR);
2066}
2067
2068static unsigned int message_count;
2069
2070static u16 message_response_sequence(struct hpi_adapter_obj *pao,
2071 struct hpi_message *phm, struct hpi_response *phr)
2072{
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002073 u32 time_out, time_out2;
2074 struct hpi_hw_obj *phw = pao->priv;
2075 struct bus_master_interface *interface = phw->p_interface_buffer;
2076 u16 err = 0;
2077
2078 message_count++;
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002079 if (phm->size > sizeof(interface->u.message_buffer)) {
Eliot Blennerhassettdeb21a22011-02-10 17:26:03 +13002080 phr->error = HPI_ERROR_MESSAGE_BUFFER_TOO_SMALL;
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002081 phr->specific_error = sizeof(interface->u.message_buffer);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002082 phr->size = sizeof(struct hpi_response_header);
2083 HPI_DEBUG_LOG(ERROR,
Takashi Iwaia2800302011-03-08 18:20:46 +01002084 "message len %d too big for buffer %zd \n", phm->size,
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002085 sizeof(interface->u.message_buffer));
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002086 return 0;
2087 }
2088
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002089 /* Assume buffer of type struct bus_master_interface
2090 is allocated "noncacheable" */
2091
2092 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2093 HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002094 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002095 }
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002096
2097 memcpy(&interface->u.message_buffer, phm, phm->size);
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002098 /* signal we want a response */
2099 send_dsp_command(phw, H620_HIF_GET_RESP);
2100
2101 time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
2102
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002103 if (!time_out2) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002104 HPI_DEBUG_LOG(ERROR,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002105 "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002106 message_count, interface->dsp_ack);
2107 } else {
2108 HPI_DEBUG_LOG(VERBOSE,
2109 "(%u) transition to GET_RESP after %u\n",
2110 message_count, HPI6205_TIMEOUT - time_out2);
2111 }
2112 /* spin waiting on HIF interrupt flag (end of msg process) */
2113 time_out = HPI6205_TIMEOUT;
2114
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002115 /* read the result */
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002116 if (time_out) {
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002117 if (interface->u.response_buffer.response.size <= phr->size)
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002118 memcpy(phr, &interface->u.response_buffer,
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002119 interface->u.response_buffer.response.size);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002120 else {
2121 HPI_DEBUG_LOG(ERROR,
2122 "response len %d too big for buffer %d\n",
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002123 interface->u.response_buffer.response.size,
2124 phr->size);
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002125 memcpy(phr, &interface->u.response_buffer,
2126 sizeof(struct hpi_response_header));
2127 phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
2128 phr->specific_error =
Eliot Blennerhassettc6c2c9a2011-07-22 15:52:38 +12002129 interface->u.response_buffer.response.size;
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002130 phr->size = sizeof(struct hpi_response_header);
2131 }
2132 }
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002133 /* set interface back to idle */
2134 send_dsp_command(phw, H620_HIF_IDLE);
2135
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002136 if (!time_out || !time_out2) {
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002137 HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002138 return HPI6205_ERROR_MSG_RESP_TIMEOUT;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002139 }
2140 /* special case for adapter close - */
2141 /* wait for the DSP to indicate it is idle */
2142 if (phm->function == HPI_ADAPTER_CLOSE) {
2143 if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
2144 HPI_DEBUG_LOG(DEBUG,
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002145 "Timeout waiting for idle "
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002146 "(on adapter_close)\n");
Eliot Blennerhassett3285ea12011-02-10 17:25:58 +13002147 return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002148 }
2149 }
2150 err = hpi_validate_response(phm, phr);
2151 return err;
2152}
2153
2154static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
2155 struct hpi_response *phr)
2156{
2157
2158 u16 err = 0;
2159
2160 hpios_dsplock_lock(pao);
2161
2162 err = message_response_sequence(pao, phm, phr);
2163
2164 /* maybe an error response */
2165 if (err) {
2166 /* something failed in the HPI/DSP interface */
Eliot Blennerhassett0a000442011-02-10 17:26:05 +13002167 if (err >= HPI_ERROR_BACKEND_BASE) {
2168 phr->error = HPI_ERROR_DSP_COMMUNICATION;
2169 phr->specific_error = err;
2170 } else {
2171 phr->error = err;
2172 }
2173
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002174 pao->dsp_crashed++;
2175
2176 /* just the header of the response is valid */
2177 phr->size = sizeof(struct hpi_response_header);
2178 goto err;
2179 } else
2180 pao->dsp_crashed = 0;
2181
2182 if (phr->error != 0) /* something failed in the DSP */
2183 goto err;
2184
2185 switch (phm->function) {
2186 case HPI_OSTREAM_WRITE:
2187 case HPI_ISTREAM_ANC_WRITE:
2188 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2189 phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
2190 break;
2191
2192 case HPI_ISTREAM_READ:
2193 case HPI_OSTREAM_ANC_READ:
2194 err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
2195 phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
2196 break;
2197
Eliot Blennerhassett719f82d2010-04-21 18:17:39 +02002198 }
2199 phr->error = err;
2200
2201err:
2202 hpios_dsplock_unlock(pao);
2203
2204 return;
2205}