1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (C) 4Front Technologies 1996-2008.
*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
#include <sys/list.h>
#include <sys/sysmacros.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/callb.h>
#include <sys/kstat.h>
#include <sys/note.h>
#include "audio_impl.h"
/*
* Audio Engine functions.
*/
/*
* Globals
*/
uint_t audio_intrhz = AUDIO_INTRHZ;
/*
* We need to operate at fairly high interrupt priority to avoid
* underruns due to other less time sensitive processing.
*/
int audio_priority = DDI_IPL_8;
audio_dev_t *
audio_dev_alloc(dev_info_t *dip, int instance)
{
audio_dev_t *d;
/*
* For a card with multiple independent audio ports on it, we
* allow the driver to provide a different instance numbering
* scheme than the standard DDI instance number. (This is
* sort of like the PPA numbering scheme used by NIC drivers
* -- by default PPA == instance, but sometimes we need more
* flexibility.)
*/
if (instance == 0) {
instance = ddi_get_instance(dip);
}
/* generally this shouldn't occur */
if (instance > AUDIO_MN_INST_MASK) {
audio_dev_warn(NULL, "bad instance number for %s (%d)",
ddi_driver_name(dip), instance);
return (NULL);
}
if ((d = kmem_zalloc(sizeof (*d), KM_NOSLEEP)) == NULL) {
audio_dev_warn(NULL, "unable to allocate audio device struct");
return (NULL);
}
d->d_dip = dip;
d->d_number = -1;
d->d_major = ddi_driver_major(dip);
d->d_instance = instance;
d->d_pcmvol = 100;
mutex_init(&d->d_lock, NULL, MUTEX_DRIVER, NULL);
cv_init(&d->d_cv, NULL, CV_DRIVER, NULL);
mutex_init(&d->d_ctrl_lock, NULL, MUTEX_DRIVER, NULL);
cv_init(&d->d_ctrl_cv, NULL, CV_DRIVER, NULL);
list_create(&d->d_clients, sizeof (struct audio_client),
offsetof(struct audio_client, c_dev_linkage));
list_create(&d->d_engines, sizeof (struct audio_engine),
offsetof(struct audio_engine, e_dev_linkage));
list_create(&d->d_controls, sizeof (struct audio_ctrl),
offsetof(struct audio_ctrl, ctrl_linkage));
list_create(&d->d_hwinfo, sizeof (struct audio_infostr),
offsetof(struct audio_infostr, i_linkage));
(void) snprintf(d->d_name, sizeof (d->d_name), "%s#%d",
ddi_driver_name(dip), instance);
return (d);
}
void
audio_dev_free(audio_dev_t *d)
{
struct audio_infostr *isp;
while ((isp = list_remove_head(&d->d_hwinfo)) != NULL) {
kmem_free(isp, sizeof (*isp));
}
if (d->d_pcmvol_ctrl != NULL) {
audio_dev_del_control(d->d_pcmvol_ctrl);
}
list_destroy(&d->d_hwinfo);
list_destroy(&d->d_engines);
list_destroy(&d->d_controls);
list_destroy(&d->d_clients);
mutex_destroy(&d->d_ctrl_lock);
mutex_destroy(&d->d_lock);
cv_destroy(&d->d_cv);
cv_destroy(&d->d_ctrl_cv);
kmem_free(d, sizeof (*d));
}
void
audio_dev_set_description(audio_dev_t *d, const char *desc)
{
(void) strlcpy(d->d_desc, desc, sizeof (d->d_desc));
}
void
audio_dev_set_version(audio_dev_t *d, const char *vers)
{
(void) strlcpy(d->d_vers, vers, sizeof (d->d_vers));
}
void
audio_dev_add_info(audio_dev_t *d, const char *info)
{
struct audio_infostr *isp;
/* failure to add information structure is not critical */
isp = kmem_zalloc(sizeof (*isp), KM_NOSLEEP);
if (isp == NULL) {
audio_dev_warn(d, "unable to allocate information structure");
} else {
(void) snprintf(isp->i_line, sizeof (isp->i_line), info);
list_insert_tail(&d->d_hwinfo, isp);
}
}
static void
auimpl_engine_reset(audio_engine_t *e)
{
char *buf;
char *ptr;
int nfr, resid, cnt;
int tidx;
tidx = e->e_tidx;
nfr = min(e->e_head - e->e_tail, e->e_nframes);
buf = kmem_alloc(nfr * e->e_framesz, KM_SLEEP);
ptr = buf;
cnt = 0;
ASSERT(e->e_nframes);
for (resid = nfr; resid; resid -= cnt) {
int nbytes;
cnt = min((e->e_nframes - tidx), resid);
nbytes = cnt * e->e_framesz;
bcopy(e->e_data + (tidx * e->e_framesz), ptr, nbytes);
ptr += nbytes;
tidx += cnt;
if (tidx == e->e_nframes) {
tidx = 0;
}
}
if (e->e_flags & ENGINE_INPUT) {
/* record */
e->e_hidx = 0;
e->e_tidx = (e->e_nframes - nfr) % e->e_nframes;
} else {
/* play */
e->e_hidx = nfr % e->e_nframes;
e->e_tidx = 0;
}
/* relocate from scratch area to destination */
bcopy(buf, e->e_data + (e->e_tidx * e->e_framesz), nfr * e->e_framesz);
kmem_free(buf, nfr * e->e_framesz);
}
static volatile uint_t auimpl_engno = 0;
audio_engine_t *
audio_engine_alloc(audio_engine_ops_t *ops, uint_t flags)
{
int i;
audio_engine_t *e;
char tname[32];
int num;
if (ops->audio_engine_version != AUDIO_ENGINE_VERSION) {
audio_dev_warn(NULL, "audio engine version mismatch: %d != %d",
ops->audio_engine_version, AUDIO_ENGINE_VERSION);
return (NULL);
}
/* NB: The ops vector must be held in persistent storage! */
e = kmem_zalloc(sizeof (audio_engine_t), KM_NOSLEEP);
if (e == NULL) {
audio_dev_warn(NULL, "unable to allocate engine struct");
return (NULL);
}
e->e_ops = *ops;
mutex_init(&e->e_lock, NULL, MUTEX_DRIVER,
DDI_INTR_PRI(audio_priority));
cv_init(&e->e_cv, NULL, CV_DRIVER, NULL);
list_create(&e->e_streams, sizeof (struct audio_stream),
offsetof(struct audio_stream, s_eng_linkage));
for (i = 0; i < AUDIO_MAX_CHANNELS; i++) {
e->e_chbufs[i] = kmem_zalloc(sizeof (int32_t) * AUDIO_CHBUFS,
KM_NOSLEEP);
if (e->e_chbufs[i] == NULL) {
audio_dev_warn(NULL, "unable to allocate channel buf");
audio_engine_free(e);
return (NULL);
}
}
num = atomic_inc_uint_nv(&auimpl_engno);
(void) snprintf(tname, sizeof (tname), "audio_engine_%d", num);
e->e_flags = flags & ENGINE_DRIVER_FLAGS;
return (e);
}
void
audio_engine_free(audio_engine_t *e)
{
int i;
for (i = 0; i < AUDIO_MAX_CHANNELS; i++) {
if (e->e_chbufs[i] != NULL) {
kmem_free(e->e_chbufs[i],
sizeof (int32_t) * AUDIO_CHBUFS);
}
}
list_destroy(&e->e_streams);
mutex_destroy(&e->e_lock);
cv_destroy(&e->e_cv);
kmem_free(e, sizeof (*e));
}
static list_t auimpl_devs_by_index;
static list_t auimpl_devs_by_number;
static krwlock_t auimpl_dev_lock;
/*
* Not for public consumption: Private interfaces.
*/
void
auimpl_dev_hold(audio_dev_t *d)
{
/* bump the reference count */
mutex_enter(&d->d_lock);
d->d_refcnt++;
mutex_exit(&d->d_lock);
}
audio_dev_t *
auimpl_dev_hold_by_devt(dev_t dev)
{
audio_dev_t *d;
major_t major;
int instance;
list_t *l = &auimpl_devs_by_index;
major = getmajor(dev);
instance = (getminor(dev) >> AUDIO_MN_INST_SHIFT) & AUDIO_MN_INST_MASK;
rw_enter(&auimpl_dev_lock, RW_READER);
for (d = list_head(l); d; d = list_next(l, d)) {
if ((d->d_major == major) && (d->d_instance == instance)) {
auimpl_dev_hold(d);
break;
}
}
rw_exit(&auimpl_dev_lock);
return (d);
}
audio_dev_t *
auimpl_dev_hold_by_index(int index)
{
audio_dev_t *d;
list_t *l = &auimpl_devs_by_index;
rw_enter(&auimpl_dev_lock, RW_READER);
for (d = list_head(l); d; d = list_next(l, d)) {
if (d->d_index == index) {
auimpl_dev_hold(d);
break;
}
}
rw_exit(&auimpl_dev_lock);
return (d);
}
void
auimpl_dev_release(audio_dev_t *d)
{
mutex_enter(&d->d_lock);
d->d_refcnt--;
mutex_exit(&d->d_lock);
}
int
auimpl_choose_format(int fmts)
{
/*
* Choose the very best format we can. We choose 24 bit in
* preference to 32 bit because we mix in 24 bit. We do that
* to allow overflows to fit within 32-bits. (Very few humans
* can tell a difference between 24 and 32 bit audio anyway.)
*/
if (fmts & AUDIO_FORMAT_S24_NE)
return (AUDIO_FORMAT_S24_NE);
if (fmts & AUDIO_FORMAT_S32_NE)
return (AUDIO_FORMAT_S32_NE);
if (fmts & AUDIO_FORMAT_S24_OE)
return (AUDIO_FORMAT_S24_OE);
if (fmts & AUDIO_FORMAT_S32_OE)
return (AUDIO_FORMAT_S32_OE);
if (fmts & AUDIO_FORMAT_S16_NE)
return (AUDIO_FORMAT_S16_NE);
if (fmts & AUDIO_FORMAT_S16_OE)
return (AUDIO_FORMAT_S16_OE);
if (fmts & AUDIO_FORMAT_AC3)
return (AUDIO_FORMAT_AC3);
return (AUDIO_FORMAT_NONE);
}
int
auimpl_engine_open(audio_stream_t *sp, int flags)
{
return (auimpl_engine_setup(sp, flags, NULL, FORMAT_MSK_NONE));
}
int
auimpl_engine_setup(audio_stream_t *sp, int flags, audio_parms_t *parms,
uint_t mask)
{
audio_dev_t *d = sp->s_client->c_dev;
audio_engine_t *e = NULL;
audio_parms_t uparms;
list_t *list;
uint_t cap;
int priority = 0;
int rv = ENODEV;
int sampsz;
int i;
int fragfr;
int fmts;
mutex_enter(&d->d_lock);
uparms = *sp->s_user_parms;
if (mask & FORMAT_MSK_FMT)
uparms.p_format = parms->p_format;
if (mask & FORMAT_MSK_RATE)
uparms.p_rate = parms->p_rate;
if (mask & FORMAT_MSK_CHAN)
uparms.p_nchan = parms->p_nchan;
/*
* Which direction are we opening? (We must open exactly
* one direction, otherwise the open is meaningless.)
*/
if (sp == &sp->s_client->c_ostream) {
cap = ENGINE_OUTPUT_CAP;
flags |= ENGINE_OUTPUT;
} else {
cap = ENGINE_INPUT_CAP;
flags |= ENGINE_INPUT;
}
if (uparms.p_format == AUDIO_FORMAT_AC3) {
fmts = AUDIO_FORMAT_AC3;
flags |= ENGINE_EXCLUSIVE;
} else {
fmts = AUDIO_FORMAT_PCM;
}
list = &d->d_engines;
/* If the device is suspended, wait for it to resume. */
while (d->d_suspended) {
cv_wait(&d->d_ctrl_cv, &d->d_lock);
}
again:
for (audio_engine_t *t = list_head(list); t; t = list_next(list, t)) {
int mypri;
int r;
/* Make sure the engine can do what we want it to. */
mutex_enter(&t->e_lock);
if ((t->e_flags & cap) == 0) {
mutex_exit(&t->e_lock);
continue;
}
/*
* Open the engine early, as the inquiries to rate and format
* may not be accurate until this is done.
*/
if (list_is_empty(&t->e_streams)) {
if (ENG_OPEN(t, flags, &t->e_nframes, &t->e_data)) {
mutex_exit(&t->e_lock);
rv = EIO;
continue;
}
}
if ((ENG_FORMAT(t) & fmts) == 0) {
if (list_is_empty(&t->e_streams))
ENG_CLOSE(t);
mutex_exit(&t->e_lock);
continue;
}
/* If it is in failed state, don't use this engine. */
if (t->e_failed) {
if (list_is_empty(&t->e_streams))
ENG_CLOSE(t);
mutex_exit(&t->e_lock);
rv = rv ? EIO : 0;
continue;
}
/*
* If the engine is in exclusive use, we can't use it.
* This is intended for use with AC3 or digital
* streams that cannot tolerate mixing.
*/
if ((t->e_flags & ENGINE_EXCLUSIVE) && (t != sp->s_engine)) {
if (list_is_empty(&t->e_streams))
ENG_CLOSE(t);
mutex_exit(&t->e_lock);
rv = rv ? EBUSY : 0;
continue;
}
/*
* If the engine is in use incompatibly, we can't use
* it. This should only happen for half-duplex audio
* devices. I've not seen any of these that are
* recent enough to be supported by Solaris.
*/
if (((flags & ENGINE_INPUT) && (t->e_flags & ENGINE_OUTPUT)) ||
((flags & ENGINE_OUTPUT) && (t->e_flags & ENGINE_INPUT))) {
if (list_is_empty(&t->e_streams))
ENG_CLOSE(t);
mutex_exit(&t->e_lock);
/* Only override the ENODEV or EIO. */
rv = rv ? EBUSY : 0;
continue;
}
/*
* In order to support as many different possible
* output streams (e.g. AC3 passthru or AC3 decode),
* or multiple exclusive outputs, we treat audio
* engines as *precious*.
*
* This means that we will try hard to reuse an
* existing allocated engine. This may not be the
* optimal performance configuration (especially if we
* wanted to avoid rate conversion, for example), but
* it should have fewer cases where the configuration
* results in denying service to any client.
*/
/*
* This engine *can* support us, so we should no longer
* have a failure mode.
*/
rv = 0;
mypri = (1U << 0);
/*
* Mixing is cheap, so try not to pick on idle
* engines. This avoids burning bus bandwidth (which
* may be precious for certain classes of traffic).
* Note that idleness is given a low priority compared
* to the other considerations.
*
* We also use this opportunity open the engine, if
* not already done so, so that our parameter
* inquiries will be valid.
*/
if (!list_is_empty(&t->e_streams))
mypri |= (1U << 1);
/*
* Slight preference is given to reuse an engine that
* we might already be using.
*/
if (t == sp->s_engine)
mypri |= (1U << 2);
/*
* Sample rate conversion avoidance. Upsampling
* requires multiplications and is moderately
* expensive. Downsampling requires division and is
* quite expensive, and hence to be avoided if at all
* possible.
*/
r = ENG_RATE(t);
if (uparms.p_rate == r) {
/*
* No conversion needed at all. This is ideal.
*/
mypri |= (1U << 4) | (1U << 3);
} else {
int src, dst;
if (flags & ENGINE_INPUT) {
src = r;
dst = uparms.p_rate;
} else {
src = uparms.p_rate;
dst = r;
}
if ((src < dst) && ((dst % src) == 0)) {
/*
* Pure upsampling only. This
* penalizes any engine which requires
* downsampling.
*/
mypri |= (1U << 3);
}
}
/*
* Try not to pick on duplex engines. This way we
* leave engines that can be used for recording or
* playback available as such. All modern drivers
* use separate unidirectional engines for playback
* and record.
*/
if ((t->e_flags & ENGINE_CAPS) == cap) {
mypri |= (1U << 5);
}
/*
* Try not to pick on engines that can do other
* formats. This will generally be false, but if it
* happens we pretty strongly avoid using a limited
* resource.
*/
if ((t->e_format & ~fmts) == 0) {
mypri |= (1U << 6);
}
if (mypri > priority) {
if (e != NULL) {
/*
* If we opened this for our own use
* and we are no longer using it, then
* close it back down.
*/
if (list_is_empty(&e->e_streams))
ENG_CLOSE(e);
mutex_exit(&e->e_lock);
}
e = t;
priority = mypri;
} else {
mutex_exit(&t->e_lock);
}
/*
* Locking: at this point, if we have an engine, "e", it is
* locked. No other engines should have a lock held.
*/
}
if ((rv == EBUSY) && ((flags & ENGINE_NDELAY) == 0)) {
ASSERT(e == NULL);
if (cv_wait_sig(&d->d_cv, &d->d_lock) == 0) {
mutex_exit(&d->d_lock);
return (EINTR);
}
goto again;
}
if (rv != 0) {
ASSERT(e == NULL);
mutex_exit(&d->d_lock);
return (rv);
}
ASSERT(e != NULL);
ASSERT(mutex_owned(&e->e_lock));
if (sp->s_engine && (sp->s_engine != e)) {
/*
* If this represents a potential engine change, then
* we close off everything, and start anew. This turns
* out to be vastly simpler than trying to close all
* the races associated with a true hand off. This
* ought to be relatively uncommon (changing engines).
*/
/* Drop the new reference. */
if (list_is_empty(&e->e_streams))
ENG_CLOSE(e);
mutex_exit(&e->e_lock);
mutex_exit(&d->d_lock);
auimpl_engine_close(sp);
/* Try again. */
return (auimpl_engine_setup(sp, flags, parms, mask));
}
if (sp->s_engine == NULL) {
/*
* Add a reference to this engine if we don't already
* have one.
*/
sp->s_engine = e;
if (!list_is_empty(&e->e_streams)) {
/*
* If the engine is already open, there is no
* need for further work. The first open will
* be relatively expensive, but subsequent
* opens should be as cheap as possible.
*/
list_insert_tail(&e->e_streams, sp);
goto ok;
}
list_insert_tail(&e->e_streams, sp);
} else {
ASSERT(sp->s_engine == e);
/*
* No change in engine... hence don't reprogram the
* engine, and don't change references.
*/
goto ok;
}
e->e_format = ENG_FORMAT(e);
e->e_nchan = ENG_CHANNELS(e);
e->e_rate = ENG_RATE(e);
/* Select format converters for the engine. */
switch (e->e_format) {
case AUDIO_FORMAT_S24_NE:
e->e_export = auimpl_export_24ne;
e->e_import = auimpl_import_24ne;
sampsz = 4;
break;
case AUDIO_FORMAT_S32_NE:
e->e_export = auimpl_export_32ne;
e->e_import = auimpl_import_32ne;
sampsz = 4;
break;
case AUDIO_FORMAT_S24_OE:
e->e_export = auimpl_export_24oe;
e->e_import = auimpl_import_24oe;
sampsz = 4;
break;
case AUDIO_FORMAT_S32_OE:
e->e_export = auimpl_export_32oe;
e->e_import = auimpl_import_32oe;
sampsz = 4;
break;
case AUDIO_FORMAT_S16_NE:
e->e_export = auimpl_export_16ne;
e->e_import = auimpl_import_16ne;
sampsz = 2;
break;
case AUDIO_FORMAT_S16_OE:
e->e_export = auimpl_export_16oe;
e->e_import = auimpl_import_16oe;
sampsz = 2;
break;
case AUDIO_FORMAT_AC3:
e->e_export = auimpl_export_24ne;
e->e_import = auimpl_import_24ne;
flags |= ENGINE_EXCLUSIVE;
sampsz = 2;
break;
default:
audio_dev_warn(d, "bad format");
rv = ENOTSUP;
goto done;
}
fragfr = e->e_rate / audio_intrhz;
if ((fragfr > AUDIO_CHBUFS) || (fragfr < 1)) {
audio_dev_warn(d, "invalid fragment configration");
rv = EINVAL;
goto done;
}
/* Sanity test a few values. */
if ((e->e_nchan < 0) || (e->e_nchan > AUDIO_MAX_CHANNELS) ||
(e->e_rate < 5000) || (e->e_rate > 192000)) {
audio_dev_warn(d, "bad engine channels or rate");
rv = EINVAL;
goto done;
}
if ((e->e_nframes <= (fragfr * 2)) || (e->e_data == NULL)) {
audio_dev_warn(d, "improper engine configuration");
rv = EINVAL;
goto done;
}
e->e_framesz = e->e_nchan * sampsz;
e->e_fragfr = fragfr;
e->e_head = 0;
e->e_tail = 0;
e->e_hidx = 0;
e->e_tidx = 0;
e->e_limiter_state = 0x10000;
bzero(e->e_data, e->e_nframes * e->e_framesz);
if (e->e_ops.audio_engine_playahead == NULL) {
e->e_playahead = (fragfr * 3) / 2;
} else {
e->e_playahead = ENG_PLAYAHEAD(e);
/*
* Need to have at least a fragment plus some extra to
* avoid underruns.
*/
if (e->e_playahead < ((fragfr * 3) / 2)) {
e->e_playahead = (fragfr * 3) / 2;
}
/*
* Impossible to queue more frames than FIFO can hold.
*/
if (e->e_playahead > e->e_nframes) {
e->e_playahead = (fragfr * 3) / 2;
}
}
for (i = 0; i < e->e_nchan; i++) {
if (e->e_ops.audio_engine_chinfo == NULL) {
e->e_choffs[i] = i;
e->e_chincr[i] = e->e_nchan;
} else {
ENG_CHINFO(e, i, &e->e_choffs[i], &e->e_chincr[i]);
}
}
e->e_flags |= flags;
/*
* Arrange for the engine to be started. We defer this to the
* periodic callback, to ensure that the start happens near
* the edge of the periodic callback. This is necessary to
* ensure that the first fragment processed is about the same
* size as the usual fragment size. (Basically, the problem
* is that we have only 10 msec resolution with the periodic
* interface, whch is rather unfortunate.)
*/
e->e_need_start = B_TRUE;
if (flags & ENGINE_OUTPUT) {
/*
* Start the output callback to populate the engine on
* startup. This avoids a false underrun when we're
* first starting up.
*/
auimpl_output_preload(e);
e->e_periodic = ddi_periodic_add(auimpl_output_callback, e,
NANOSEC / audio_intrhz, audio_priority);
} else {
e->e_periodic = ddi_periodic_add(auimpl_input_callback, e,
NANOSEC / audio_intrhz, audio_priority);
}
ok:
sp->s_phys_parms->p_rate = e->e_rate;
sp->s_phys_parms->p_nchan = e->e_nchan;
/* Configure the engine. */
mutex_enter(&sp->s_lock);
rv = auimpl_format_setup(sp, parms, mask);
mutex_exit(&sp->s_lock);
done:
mutex_exit(&e->e_lock);
mutex_exit(&d->d_lock);
return (rv);
}
void
auimpl_engine_close(audio_stream_t *sp)
{
audio_engine_t *e = sp->s_engine;
audio_dev_t *d;
ddi_periodic_t ep;
if (e == NULL)
return;
d = e->e_dev;
ep = 0;
mutex_enter(&d->d_lock);
while (d->d_suspended) {
cv_wait(&d->d_ctrl_cv, &d->d_lock);
}
mutex_enter(&e->e_lock);
sp->s_engine = NULL;
list_remove(&e->e_streams, sp);
if (list_is_empty(&e->e_streams)) {
ENG_STOP(e);
ep = e->e_periodic;
e->e_periodic = 0;
e->e_flags &= ENGINE_DRIVER_FLAGS;
ENG_CLOSE(e);
}
mutex_exit(&e->e_lock);
if (ep != 0)
ddi_periodic_delete(ep);
cv_broadcast(&d->d_cv);
mutex_exit(&d->d_lock);
}
int
audio_dev_register(audio_dev_t *d)
{
list_t *l;
audio_dev_t *srch;
int start;
/*
* Make sure we don't automatically unload. This prevents
* loss of hardware settings when no audio clients are
* running.
*/
(void) ddi_prop_update_int(DDI_DEV_T_NONE, d->d_dip,
DDI_NO_AUTODETACH, 1);
/*
* This does an in-order insertion, finding the first available
* free index. "Special" devices (ones without any actual engines)
* are all numbered 0. There should only be one of them anyway.
* All others start at one.
*/
if (d->d_flags & DEV_SNDSTAT_CAP) {
start = 0;
} else {
start = 1;
}
d->d_index = start;
rw_enter(&auimpl_dev_lock, RW_WRITER);
l = &auimpl_devs_by_index;
for (srch = list_head(l); srch; srch = list_next(l, srch)) {
/* skip over special nodes */
if (srch->d_index < start)
continue;
if (srch->d_index > d->d_index) {
/* found a free spot! */
break;
}
d->d_index++;
}
/*
* NB: If srch is NULL, then list_insert_before puts
* it on the tail of the list. So if we didn't find a
* hole, then that's where we want it.
*/
list_insert_before(l, srch, d);
/* insert in order by number */
l = &auimpl_devs_by_number;
for (srch = list_head(l); srch; srch = list_next(l, srch)) {
if (srch->d_number >= d->d_number) {
break;
}
}
list_insert_before(l, srch, d);
rw_exit(&auimpl_dev_lock);
if (auimpl_create_minors(d) != 0) {
rw_enter(&auimpl_dev_lock, RW_WRITER);
auimpl_remove_minors(d);
list_remove(&auimpl_devs_by_index, d);
list_remove(&auimpl_devs_by_number, d);
rw_exit(&auimpl_dev_lock);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
audio_dev_unregister(audio_dev_t *d)
{
rw_enter(&auimpl_dev_lock, RW_WRITER);
mutex_enter(&d->d_lock);
/* if we are still in use, we can't unregister */
if (d->d_refcnt) {
mutex_exit(&d->d_lock);
rw_exit(&auimpl_dev_lock);
return (DDI_FAILURE);
}
auimpl_remove_minors(d);
list_remove(&auimpl_devs_by_index, d);
list_remove(&auimpl_devs_by_number, d);
mutex_exit(&d->d_lock);
rw_exit(&auimpl_dev_lock);
return (DDI_SUCCESS);
}
static int
auimpl_engine_ksupdate(kstat_t *ksp, int rw)
{
audio_engine_t *e = ksp->ks_private;
struct audio_stats *st = &e->e_stats;
if (rw == KSTAT_WRITE) {
return (EACCES);
}
mutex_enter(&e->e_lock);
st->st_head.value.ui64 = e->e_head;
st->st_tail.value.ui64 = e->e_tail;
st->st_flags.value.ui32 = e->e_flags;
st->st_nbytes.value.ui32 = e->e_framesz * e->e_nframes;
st->st_framesz.value.ui32 = e->e_framesz;
st->st_hidx.value.ui32 = e->e_hidx;
st->st_tidx.value.ui32 = e->e_tidx;
st->st_format.value.ui32 = e->e_format;
st->st_nchan.value.ui32 = e->e_nchan;
st->st_rate.value.ui32 = e->e_rate;
st->st_errors.value.ui32 = e->e_errors;
st->st_engine_underruns.value.ui32 = e->e_underruns;
st->st_engine_overruns.value.ui32 = e->e_overruns;
st->st_stream_underruns.value.ui32 = e->e_stream_underruns;
st->st_stream_overruns.value.ui32 = e->e_stream_overruns;
st->st_suspended.value.ui32 = e->e_suspended;
st->st_failed.value.ui32 = e->e_failed;
st->st_playahead.value.ui32 = e->e_playahead;
mutex_exit(&e->e_lock);
return (0);
}
static void
auimpl_engine_ksinit(audio_dev_t *d, audio_engine_t *e)
{
char name[32];
struct audio_stats *st;
(void) snprintf(name, sizeof (name), "engine_%d", e->e_num);
e->e_ksp = kstat_create(ddi_driver_name(d->d_dip), d->d_instance,
name, "misc", KSTAT_TYPE_NAMED,
sizeof (struct audio_stats) / sizeof (kstat_named_t), 0);
if (e->e_ksp == NULL) {
audio_dev_warn(d, "unable to initialize kstats");
return;
}
st = &e->e_stats;
e->e_ksp->ks_data = st;
e->e_ksp->ks_private = e;
e->e_ksp->ks_lock = NULL;
e->e_ksp->ks_update = auimpl_engine_ksupdate;
kstat_named_init(&st->st_head, "head", KSTAT_DATA_UINT64);
kstat_named_init(&st->st_tail, "tail", KSTAT_DATA_UINT64);
kstat_named_init(&st->st_flags, "flags", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_nbytes, "nbytes", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_framesz, "framesz", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_hidx, "hidx", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_tidx, "tidx", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_format, "format", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_nchan, "channels", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_rate, "rate", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_errors, "errors", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_engine_overruns, "engine_overruns",
KSTAT_DATA_UINT32);
kstat_named_init(&st->st_engine_underruns, "engine_underruns",
KSTAT_DATA_UINT32);
kstat_named_init(&st->st_stream_overruns, "stream_overruns",
KSTAT_DATA_UINT32);
kstat_named_init(&st->st_stream_underruns, "stream_underruns",
KSTAT_DATA_UINT32);
kstat_named_init(&st->st_playahead, "playahead", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_suspended, "suspended", KSTAT_DATA_UINT32);
kstat_named_init(&st->st_failed, "failed", KSTAT_DATA_UINT32);
kstat_install(e->e_ksp);
}
void
audio_dev_add_engine(audio_dev_t *d, audio_engine_t *e)
{
mutex_enter(&d->d_lock);
e->e_num = d->d_engno++;
auimpl_engine_ksinit(d, e);
/* check for duplex */
if ((e->e_flags & ENGINE_OUTPUT_CAP) && (d->d_flags & DEV_INPUT_CAP)) {
d->d_flags |= DEV_DUPLEX_CAP;
}
if ((e->e_flags & ENGINE_INPUT_CAP) && (d->d_flags & DEV_OUTPUT_CAP)) {
d->d_flags |= DEV_DUPLEX_CAP;
}
/* add in the direction caps -- must be done after duplex above */
if (e->e_flags & ENGINE_OUTPUT_CAP) {
d->d_flags |= DEV_OUTPUT_CAP;
}
if (e->e_flags & ENGINE_INPUT_CAP) {
d->d_flags |= DEV_INPUT_CAP;
}
list_insert_tail(&d->d_engines, e);
e->e_dev = d;
mutex_exit(&d->d_lock);
}
void
audio_dev_remove_engine(audio_dev_t *d, audio_engine_t *e)
{
mutex_enter(&d->d_lock);
list_remove(&d->d_engines, e);
e->e_dev = NULL;
if (e->e_ksp)
kstat_delete(e->e_ksp);
e->e_ksp = NULL;
mutex_exit(&d->d_lock);
}
/*
* Change the number.
*/
void
auclnt_set_dev_number(audio_dev_t *d, int num)
{
list_t *l = &auimpl_devs_by_number;
audio_dev_t *srch;
/* reorder our list */
rw_enter(&auimpl_dev_lock, RW_WRITER);
d->d_number = num;
list_remove(l, d);
for (srch = list_head(l); srch; srch = list_next(l, srch)) {
if (srch->d_number >= d->d_number) {
break;
}
}
list_insert_before(l, srch, d);
rw_exit(&auimpl_dev_lock);
}
void
auclnt_walk_devs(int (*walker)(audio_dev_t *, void *), void *arg)
{
audio_dev_t *d;
boolean_t cont;
list_t *l;
l = &auimpl_devs_by_index;
rw_enter(&auimpl_dev_lock, RW_READER);
for (d = list_head(l); d; d = list_next(l, d)) {
cont = walker(d, arg);
if (cont == AUDIO_WALK_STOP)
break;
}
rw_exit(&auimpl_dev_lock);
}
void
auclnt_walk_devs_by_number(int (*walker)(audio_dev_t *, void *), void *arg)
{
audio_dev_t *d;
boolean_t cont;
list_t *l;
l = &auimpl_devs_by_number;
rw_enter(&auimpl_dev_lock, RW_READER);
for (d = list_head(l); d; d = list_next(l, d)) {
cont = walker(d, arg);
if (cont == AUDIO_WALK_STOP)
break;
}
rw_exit(&auimpl_dev_lock);
}
void
auclnt_dev_walk_engines(audio_dev_t *d,
int (*walker)(audio_engine_t *, void *),
void *arg)
{
audio_engine_t *e;
list_t *l = &d->d_engines;
mutex_enter(&d->d_lock);
for (e = list_head(l); e != NULL; e = list_next(l, e)) {
if (walker(e, arg) == AUDIO_WALK_STOP) {
break;
}
}
mutex_exit(&d->d_lock);
}
int
auclnt_engine_get_format(audio_engine_t *e)
{
return (ENG_FORMAT(e));
}
int
auclnt_engine_get_channels(audio_engine_t *e)
{
return (ENG_CHANNELS(e));
}
int
auclnt_engine_get_rate(audio_engine_t *e)
{
return (ENG_RATE(e));
}
uint_t
auclnt_engine_get_capab(audio_engine_t *e)
{
uint_t capab = 0;
if (e->e_flags & ENGINE_INPUT_CAP) {
capab |= AUDIO_CLIENT_CAP_RECORD;
}
if (e->e_flags & ENGINE_OUTPUT_CAP) {
capab |= AUDIO_CLIENT_CAP_PLAY;
}
return (capab);
}
/*
* This function suspends an engine. The intent is to pause the
* engine temporarily so that it does not underrun while user threads
* are suspended. The driver is still responsible for actually doing
* the driver suspend work -- all this does is put the engine in a
* paused state. It does not prevent, for example, threads from
* accessing the hardware.
*
* A properly implemented driver won't even be aware of the existence
* of this routine -- the driver will just handle the suspend &
* resume. At the point of suspend & resume, the driver will see that
* the engines are not running (as if all threads had "paused" it).
*
* Failure to execute either of the routines below is not critical,
* but will probably lead to underruns and overflows as the kernel
* driver gets resumed well in advance of the time when user threads
* are ready to start operation.
*/
static void
auimpl_engine_suspend(audio_engine_t *e)
{
ASSERT(mutex_owned(&e->e_lock));
if (e->e_failed || e->e_suspended) {
e->e_suspended = B_TRUE;
return;
}
e->e_suspended = B_TRUE;
if (e->e_flags & ENGINE_INPUT) {
e->e_head = ENG_COUNT(e);
ENG_STOP(e);
}
if (e->e_flags & ENGINE_OUTPUT) {
e->e_tail = ENG_COUNT(e);
ENG_STOP(e);
}
}
static void
auimpl_engine_resume(audio_engine_t *e)
{
ASSERT(mutex_owned(&e->e_lock));
ASSERT(e->e_suspended);
if (e->e_failed) {
/* No longer suspended, but still failed! */
e->e_suspended = B_FALSE;
return;
}
if (e->e_flags & (ENGINE_INPUT | ENGINE_OUTPUT)) {
auimpl_engine_reset(e);
if (e->e_flags & ENGINE_OUTPUT) {
auimpl_output_preload(e);
}
e->e_need_start = B_TRUE;
}
e->e_suspended = B_FALSE;
cv_broadcast(&e->e_cv);
}
static int
auimpl_dev_suspend(audio_dev_t *d, void *dontcare)
{
list_t *l;
audio_engine_t *e;
_NOTE(ARGUNUSED(dontcare));
mutex_enter(&d->d_lock);
mutex_enter(&d->d_ctrl_lock);
if (d->d_suspended) {
d->d_suspended++;
mutex_exit(&d->d_ctrl_lock);
mutex_exit(&d->d_lock);
return (AUDIO_WALK_CONTINUE);
}
d->d_suspended++;
(void) auimpl_save_controls(d);
mutex_exit(&d->d_ctrl_lock);
l = &d->d_engines;
for (e = list_head(l); e != NULL; e = list_next(l, e)) {
mutex_enter(&e->e_lock);
auimpl_engine_suspend(e);
mutex_exit(&e->e_lock);
}
mutex_exit(&d->d_lock);
return (AUDIO_WALK_CONTINUE);
}
static int
auimpl_dev_resume(audio_dev_t *d, void *dontcare)
{
list_t *l;
audio_engine_t *e;
_NOTE(ARGUNUSED(dontcare));
mutex_enter(&d->d_lock);
mutex_enter(&d->d_ctrl_lock);
ASSERT(d->d_suspended);
d->d_suspended--;
if (d->d_suspended) {
mutex_exit(&d->d_ctrl_lock);
mutex_exit(&d->d_lock);
return (AUDIO_WALK_CONTINUE);
}
(void) auimpl_restore_controls(d);
cv_broadcast(&d->d_ctrl_cv);
mutex_exit(&d->d_ctrl_lock);
l = &d->d_engines;
for (e = list_head(l); e != NULL; e = list_next(l, e)) {
mutex_enter(&e->e_lock);
auimpl_engine_resume(e);
mutex_exit(&e->e_lock);
}
mutex_exit(&d->d_lock);
return (AUDIO_WALK_CONTINUE);
}
boolean_t
auimpl_cpr(void *arg, int code)
{
_NOTE(ARGUNUSED(arg));
switch (code) {
case CB_CODE_CPR_CHKPT:
auclnt_walk_devs(auimpl_dev_suspend, NULL);
return (B_TRUE);
case CB_CODE_CPR_RESUME:
auclnt_walk_devs(auimpl_dev_resume, NULL);
return (B_TRUE);
default:
return (B_FALSE);
}
}
void
audio_dev_suspend(audio_dev_t *d)
{
(void) auimpl_dev_suspend(d, NULL);
}
void
audio_dev_resume(audio_dev_t *d)
{
(void) auimpl_dev_resume(d, NULL);
}
static callb_id_t auimpl_cpr_id = 0;
void
auimpl_dev_init(void)
{
rw_init(&auimpl_dev_lock, NULL, RW_DRIVER, NULL);
list_create(&auimpl_devs_by_index, sizeof (struct audio_dev),
offsetof(struct audio_dev, d_by_index));
list_create(&auimpl_devs_by_number, sizeof (struct audio_dev),
offsetof(struct audio_dev, d_by_number));
/*
* We "borrow" the CB_CL_CPR_PM class, which gets executed at
* about the right time for us. It would be nice to have a
* new CB_CL_CPR_AUDIO class, but it isn't critical at this
* point.
*
* Note that we don't care about our thread id.
*/
auimpl_cpr_id = callb_add(auimpl_cpr, NULL, CB_CL_CPR_PM, "audio_cpr");
}
void
auimpl_dev_fini(void)
{
(void) callb_delete(auimpl_cpr_id);
list_destroy(&auimpl_devs_by_index);
list_destroy(&auimpl_devs_by_number);
rw_destroy(&auimpl_dev_lock);
}
void
audio_engine_set_private(audio_engine_t *eng, void *prv)
{
eng->e_private = prv;
}
void *
audio_engine_get_private(audio_engine_t *eng)
{
return (eng->e_private);
}
void
audio_dump_bytes(const uint8_t *w, int dcount)
{
char line[64];
char *s;
int i;
const int wrap = 16;
s = line;
line[0] = 0;
cmn_err(CE_NOTE, "starting @ %p", (void *)w);
for (i = 0; i < dcount; i++) {
(void) sprintf(s, " %02x", *w);
s += strlen(s);
w++;
if ((i % wrap) == (wrap - 1)) {
cmn_err(CE_NOTE, "%08x:%s", i - (wrap - 1), line);
line[0] = 0;
s = line;
}
}
if ((i % wrap) != 0) {
cmn_err(CE_NOTE, "%08x:%s", i - (i % wrap), line);
}
}
void
audio_dump_words(const uint16_t *w, int dcount)
{
char line[64];
char *s;
int i;
const int wrap = 8;
s = line;
line[0] = 0;
cmn_err(CE_NOTE, "starting @ %p", (void *)w);
for (i = 0; i < dcount; i++) {
(void) sprintf(s, " %04x", *w);
s += strlen(s);
w++;
if ((i % wrap) == (wrap - 1)) {
cmn_err(CE_NOTE, "%08x:%s", i - (wrap - 1), line);
line[0] = 0;
s = line;
}
}
if ((i % wrap) != 0) {
cmn_err(CE_NOTE, "%08x:%s", i - (i % wrap), line);
}
}
void
audio_dump_dwords(const uint32_t *w, int dcount)
{
char line[128];
char *s;
int i;
const int wrap = 4;
s = line;
line[0] = 0;
cmn_err(CE_NOTE, "starting @ %p", (void *)w);
for (i = 0; i < dcount; i++) {
(void) sprintf(s, " %08x", *w);
s += strlen(s);
w++;
if ((i % wrap) == (wrap - 1)) {
cmn_err(CE_NOTE, "%08x:%s", i - (wrap - 1), line);
line[0] = 0;
s = line;
}
}
if ((i % wrap) != 0) {
cmn_err(CE_NOTE, "%08x:%s", i - (i % wrap), line);
}
}
|