fix rules for optional plugins.
[galan.git] / plugins / emu10k1-lib / debug.c
blob3c09996ad96e7228ee61fee338b65f3db049f1bf
1 /*********************************************************************
2 * debug.c - dsp patch manager library - debug functions
3 *
4 * Copyright (C) 2000 Rui Sousa
5 *********************************************************************
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
19 * USA.
20 *********************************************************************
23 #include <stdio.h>
25 #include "../emu10k1-include/dsp.h"
26 #include "../emu10k1-include/list.h"
27 #include "../emu10k1-include/internal.h"
28 #include <sys/soundcard.h>
30 const char gpr_types[6][10]={
31 "NULL",
32 "IO",
33 "STATIC",
34 "DYNAMIC",
35 "CONTROL",
36 "CONSTANT"
39 extern char dsp_in_name[DSP_NUM_INPUTS][DSP_LINE_NAME_SIZE];
40 extern char dsp_out_name[DSP_NUM_OUTPUTS][DSP_LINE_NAME_SIZE] ;
42 extern char *oss_mixer_name[SOUND_MIXER_NRDEVICES];
43 extern char dsp_in_name[DSP_NUM_INPUTS][DSP_LINE_NAME_SIZE];
44 extern char dsp_out_name[DSP_NUM_OUTPUTS][DSP_LINE_NAME_SIZE];
45 int get_control_gpr_info(struct dsp_patch_manager *mgr, const char *patch_name, const char *gpr_name,
46 struct dsp_gpr *gpr)
48 int addr;
50 addr = find_control_gpr_addr(mgr, patch_name, gpr_name);
51 if (addr < 0)
52 return -1;
54 memcpy(gpr, &mgr->gpr[addr - GPR_BASE], sizeof(struct dsp_gpr));
56 return 0;
59 static void print_patch_control_gprs(struct dsp_patch_manager *mgr, __u32 * used)
61 int i;
63 for (i = 0; i < DSP_NUM_GPRS; i++)
64 if (mgr->gpr[i].type == GPR_TYPE_CONTROL && test_bit(i, used)) {
65 printf(" name: %s\n", mgr->gpr[i].name);
66 printf(" addr: %#04x\n", mgr->gpr[i].addr);
67 if (mgr->gpr[i].mixer_id < SOUND_MIXER_NRDEVICES)
68 printf(" mixer: %s_%c\n", oss_mixer_name[mgr->gpr[i].mixer_id],
69 mgr->gpr[i].mixer_ch ? 'r': 'l');
71 printf(" value: %#010x (%#010x - %#010x)\n\n", mgr->gpr[i].value,
72 mgr->gpr[i].min_val, mgr->gpr[i].max_val);
77 int dsp_print_control_gprs_patch( struct dsp_patch_manager *mgr, const char *patch_name)
79 struct dsp_patch *patch=NULL;
81 if( dsp_find_patch(mgr, patch_name,&patch) < 0)
82 return -1;
83 printf("Control GPR's:\n");
84 if (patch->id)
85 printf(" Patch: %s %d\n", patch->name, patch->id);
86 else
87 printf(" Patch: %s\n", patch->name);
89 print_patch_control_gprs(mgr, patch->gpr_used);
90 return 0;
93 void dsp_print_control_gpr_list(struct dsp_patch_manager *mgr)
95 struct dsp_rpatch *rpatch;
96 struct dsp_patch *patch;
97 struct list_head *entry;
99 if (!mgr->init)
100 dsp_init(mgr);
102 printf("Control GPR's:\n");
105 list_for_each(entry, &mgr->ipatch_list) {
106 patch = list_entry(entry, struct dsp_patch, list);
107 if (patch->id)
108 printf(" Patch: %s %d\n", patch->name, patch->id);
109 else
110 printf(" Patch: %s\n", patch->name);
111 print_patch_control_gprs(mgr, patch->gpr_used);
114 rpatch = &mgr->rpatch;
115 printf(" Patch: %s\n", rpatch->name);
116 print_patch_control_gprs(mgr, rpatch->gpr_used);
119 list_for_each(entry, &mgr->opatch_list) {
120 patch = list_entry(entry, struct dsp_patch, list);
121 if (patch->id)
122 printf(" Patch: %s %d\n", patch->name, patch->id);
123 else
124 printf(" Patch: %s\n", patch->name);
126 print_patch_control_gprs(mgr, patch->gpr_used);
130 void dsp_print_route_list(struct dsp_patch_manager *mgr)
132 struct dsp_rpatch *rpatch;
133 int i, j;
135 if (!mgr->init)
136 dsp_init(mgr);
138 rpatch = &mgr->rpatch;
140 printf("\n Routes:\n");
142 for (j = 0; j < DSP_NUM_INPUTS; j++)
143 for (i = 0; i < DSP_NUM_OUTPUTS; i++)
144 if (test_bit(j, &rpatch->route[i]))
145 printf(" %s:%s\n", dsp_in_name[j], dsp_out_name[i]);
146 else if (test_bit(j, &rpatch->route_v[i]))
147 printf(" %s:%s (with volume control)\n", dsp_in_name[j], dsp_out_name[i]);
151 void print_patch_code(__u32 * code, __u32 start, __u32 size)
153 int i;
155 printf("\n code:\n");
156 printf(" start: %#05x\n size: %#05x\n", start, size);
157 for (i = 0; i < size / 2; i++) {
158 printf
159 (" %#05x %#010x %#010x %2d %#05x %#05x %#05x %#05x\n",
160 DSP_CODE_BASE + start + 2 * i, code[i * 2 + 1],
161 code[i * 2], (code[i * 2 + 1] >> 20) & 0xf,
162 (code[i * 2 + 1] >> 10) & 0x3ff, code[i * 2 + 1] & 0x3ff,
163 (code[i * 2] >> 10) & 0x3ff, code[i * 2] & 0x3ff);
167 void print_patch_gprs(struct dsp_patch_manager *mgr, __u32 * used, __u32 * input, int io)
169 int i;
171 printf("\n gprs:");
172 for (i = 0; i < DSP_NUM_GPRS; i++)
173 if (test_bit(i, used)) {
174 printf("\n");
175 printf(" addr: %#05x", GPR_BASE + i);
176 printf(" usage: %#04x", mgr->gpr[i].usage);
177 printf(" type: %s", gpr_types[mgr->gpr[i].type]);
179 if (mgr->gpr[i].type == GPR_TYPE_CONTROL) {
180 printf("\n name: %-24s", mgr->gpr[i].name);
181 if (mgr->gpr[i].mixer_id < SOUND_MIXER_NRDEVICES)
182 printf(" mixer: %s_%c", oss_mixer_name[mgr->gpr[i].mixer_id],
183 mgr->gpr[i].mixer_ch ? 'r': 'l');
184 printf("\n range: %#010x - %#010x", mgr->gpr[i].min_val, mgr->gpr[i].max_val);
188 if (mgr->gpr[i].type == GPR_TYPE_IO) {
189 if (test_bit(i, input))
190 printf(" (Input) ");
191 else
192 printf(" (Output)");
193 if(io)
194 printf(" line: %s", dsp_in_name[mgr->gpr[i].line] );
195 else
196 printf(" line: %s", dsp_out_name[mgr->gpr[i].line] );
200 if (mgr->gpr[i].type == GPR_TYPE_CONTROL ||
201 mgr->gpr[i].type == GPR_TYPE_STATIC || mgr->gpr[i].type == GPR_TYPE_CONSTANT)
202 printf(" value: %#010x", mgr->gpr[i].value);
208 void print_patch_tram(struct dsp_patch_manager *mgr, struct dsp_patch *patch)
210 int i;
212 if (patch->tramb_isize || patch->tramb_esize || patch->traml_isize || patch->traml_esize)
213 printf("\n tram:\n");
215 if (patch->tramb_isize || patch->tramb_esize)
216 printf(" blocks:\n");
218 if (patch->tramb_isize)
219 printf(" internal: %#07x - %#07x\n", patch->tramb_istart,
220 patch->tramb_istart + patch->tramb_isize);
222 if (patch->tramb_esize)
223 printf(" external: %#07x - %#07x\n", patch->tramb_estart,
224 patch->tramb_estart + patch->tramb_esize);
226 if (patch->traml_isize || patch->traml_esize)
227 printf(" lines:\n");
229 if (patch->traml_isize) {
230 printf(" data internal: %#05x - %#05x\n",
231 TRAML_IDATA_BASE + patch->traml_istart,
232 TRAML_IDATA_BASE + patch->traml_istart + patch->traml_isize - 1);
234 printf(" address internal: %#05x - %#05x\n",
235 TRAML_IADDR_BASE + patch->traml_istart,
236 TRAML_IADDR_BASE + patch->traml_istart + patch->traml_isize - 1);
238 for (i = 0; i < patch->traml_isize; i++)
239 printf(" %#05x %#06x type: %s Align bit: %s\n",
240 TRAML_IADDR_BASE + patch->traml_istart + i,
241 patch->traml_iaddr[i] & 0xfffff,
242 (patch->traml_iaddr[i]& TANKMEMADDRREG_READ)?"Read, ":"Write,",
243 (patch->traml_iaddr[i]& TANKMEMADDRREG_ALIGN)?"1":"0");
246 if (patch->traml_esize) {
247 printf(" data external: %#05x - %#05x\n",
248 TRAML_EDATA_BASE + patch->traml_estart,
249 TRAML_EDATA_BASE + patch->traml_estart + patch->traml_esize - 1);
251 printf(" address external: %#05x - %#05x\n",
252 TRAML_EADDR_BASE + patch->traml_estart,
253 TRAML_EADDR_BASE + patch->traml_estart + patch->traml_esize - 1);
255 for (i = 0; i < patch->traml_esize; i++)
256 printf(" %#05x %#07x type: %s Align bit:%s \n",
257 TRAML_EADDR_BASE + patch->traml_estart + i,
258 patch->traml_eaddr[i] & 0xfffff,
259 (patch->traml_eaddr[i]& TANKMEMADDRREG_READ)?"Read, ":"Write,",
260 (patch->traml_eaddr[i]& TANKMEMADDRREG_ALIGN)?"1":"0");
264 void print_in_patch(struct dsp_patch_manager *mgr, struct dsp_patch *patch)
266 int i;
267 printf("\n Name: %s", patch->name);
268 if (patch->id)
269 printf(" %d", patch->id);
270 printf("\n");
272 //printf(" input line :");
273 printf(" lines :");
274 for( i=0;i<DSP_NUM_INPUTS;i++)
275 if(test_bit(i,&patch->input))
276 printf(" \"%s\" ",dsp_in_name[i]);
277 printf("\n");
278 //for now, this is useless
280 printf(" output line:");
281 for(i=0;i<DSP_NUM_OUTPUTS;i++)
282 if(test_bit(i,&patch->output))
283 printf(" \"%s\" ",dsp_in_name[i]);
284 printf("\n");
287 print_patch_gprs(mgr, patch->gpr_used, patch->gpr_input,1);
288 print_patch_code(patch->code, patch->code_start, patch->code_size);
289 print_patch_tram(mgr, patch);
292 void print_out_patch(struct dsp_patch_manager *mgr, struct dsp_patch *patch)
294 int i;
295 printf("\n Name: %s", patch->name);
296 if (patch->id)
297 printf(" %d", patch->id);
298 printf("\n");
300 printf(" input line :");
301 for( i=0;i<DSP_NUM_INPUTS;i++)
302 if(test_bit(i,&patch->input))
303 printf(" \"%s\" ",dsp_out_name[i]);
304 printf("\n");
306 printf(" output line:");
307 for(i=0;i<DSP_NUM_OUTPUTS;i++)
308 if(test_bit(i,&patch->output))
309 printf(" \"%s\" ",dsp_out_name[i]);
310 printf("\n");
312 print_patch_gprs(mgr, patch->gpr_used, patch->gpr_input,0);
313 print_patch_code(patch->code, patch->code_start, patch->code_size);
314 print_patch_tram(mgr, patch);
316 void print_summary(struct dsp_patch_manager *mgr)
319 int i,j=DSP_NUM_GPRS,k=-1;
321 for (i = 0; i < DSP_NUM_GPRS; i++) {
322 if (mgr->gpr[i].type == GPR_TYPE_NULL)
323 j--;
324 else
325 k=i;
327 printf("\
328 Usage Summary:
329 --------
330 Instructions : %d
331 GPRS: %d (last used is %d)
333 Tram
334 Internal
335 buffers: %d
336 space : 0x%06x
337 External
338 buffers: %d
339 space : 0x%06x
341 mgr->code_free_start/2, j,k,
342 mgr->traml_ifree_start, mgr->tramb_ifree_start,
343 mgr->traml_efree_start, mgr->tramb_efree_start);
346 void print_debug(struct dsp_patch_manager *mgr)
348 struct dsp_rpatch *rpatch;
349 struct dsp_patch *patch;
350 struct list_head *entry;
352 print_summary(mgr);
354 printf("\nInput patches:\n");
356 list_for_each(entry, &mgr->ipatch_list) {
357 patch = list_entry(entry, struct dsp_patch, list);
358 print_in_patch(mgr, patch);
362 rpatch = &mgr->rpatch;
364 printf("\nRouting patch:\n");
366 print_patch_gprs(mgr, rpatch->gpr_used, rpatch->gpr_input,2);
367 dsp_print_route_list(mgr);
368 print_patch_code(rpatch->code, rpatch->code_start, rpatch->code_size);
370 printf("\nOutput patches:\n");
372 list_for_each(entry, &mgr->opatch_list) {
373 patch = list_entry(entry, struct dsp_patch, list);
374 print_out_patch(mgr, patch);
379 void dsp_print_patch_list(struct dsp_patch_manager *mgr)
381 struct dsp_patch *patch;
382 struct list_head *entry;
383 int i,j;
384 char tmp[10];
386 if (!mgr->init)
387 dsp_init(mgr);
388 printf("Input patches Attached to:\n");
389 printf("------------- -----------\n");
390 if (!list_empty(&mgr->ipatch_list)) {
391 list_for_each(entry, &mgr->ipatch_list) {
392 patch = list_entry(entry, struct dsp_patch, list);
393 tmp[0]='\0';
394 if (patch->id)
395 sprintf(tmp," %d", patch->id);
396 printf("%s%s%n", patch->name,tmp,&j);
397 j=DSP_PATCH_NAME_SIZE - j;
398 printf("%*s",j, " " );
399 for(i=0;i<DSP_NUM_OUTPUTS;i++)
400 if(test_bit(i,&patch->output))
401 printf("\"%s\" ",dsp_in_name[i]);
402 printf("\n");
407 printf("\nOutput patches Attached to:\n");
408 printf("-------------- -----------\n");
409 if (!list_empty(&mgr->opatch_list)) {
410 list_for_each(entry, &mgr->opatch_list) {
411 patch = list_entry(entry, struct dsp_patch, list);
412 tmp[0]='\0';
413 if (patch->id)
414 sprintf(tmp," %d", patch->id);
415 printf("%s%s%n", patch->name,tmp,&j);
416 j=DSP_PATCH_NAME_SIZE - j;
417 printf("%*s",j, " " );
419 for(i=0;i<DSP_NUM_OUTPUTS;i++)
420 if(test_bit(i,&patch->output))
421 printf("\"%s\" ",dsp_out_name[i]);
422 printf("\n");
427 void dsp_set_debug(struct dsp_patch_manager *mgr)
429 if (!mgr->init)
430 dsp_init(mgr);
432 mgr->debug = 1;
435 void dsp_print_oss_mixers(void)
437 int i;
439 printf("OSS Mixers:\n");
441 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
442 printf(" %s\n", oss_mixer_name[i]);