forked from NetBSD/src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.c
220 lines (194 loc) · 6.63 KB
/
graph.c
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
/* $NetBSD: graph.c,v 1.6 2021/06/21 03:09:52 christos Exp $ */
/*
* Copyright (c) 2009 Precedence Technologies Ltd <support@precedence.co.uk>
* Copyright (c) 2009 Jared D. McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Precedence Technologies Ltd
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/ioctl.h>
#include <prop/proplib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dev/hdaudio/hdaudioio.h>
#include <dev/hdaudio/hdaudioreg.h>
#include "hdaudioctl.h"
int
hdaudioctl_graph(int fd, int argc, char *argv[])
{
prop_dictionary_t request, response;
prop_object_iterator_t iter;
prop_number_t nnid;
prop_array_t connlist;
const char *name;
int error, index;
uint32_t cap, config;
uint16_t reqnid, reqcodecid;
uint16_t vendor, product;
uint8_t type, nid;
char buf[10] = "??h";
if (argc != 2)
usage();
reqcodecid = strtol(argv[0], NULL, 0);
reqnid = strtol(argv[1], NULL, 0);
request = prop_dictionary_create();
if (request == NULL) {
fprintf(stderr, "out of memory\n");
return ENOMEM;
}
prop_dictionary_set_uint16(request, "codecid", reqcodecid);
prop_dictionary_set_uint16(request, "nid", reqnid);
error = prop_dictionary_sendrecv_ioctl(request, fd,
HDAUDIO_FGRP_CODEC_INFO, &response);
if (error != 0) {
perror("HDAUDIO_FGRP_CODEC_INFO failed");
prop_object_release(request);
return error;
}
prop_dictionary_get_uint16(response, "vendor-id", &vendor);
prop_dictionary_get_uint16(response, "product-id", &product);
printf("digraph \"HD Audio %04X:%04X\" {\n",
vendor, product);
for (index = 0;; index++) {
prop_dictionary_set_uint16(request, "index", index);
error = prop_dictionary_sendrecv_ioctl(request, fd,
HDAUDIO_FGRP_WIDGET_INFO, &response);
if (error != 0)
break;
prop_dictionary_get_string(response, "name", &name);
prop_dictionary_get_uint32(response, "cap", &cap);
prop_dictionary_get_uint32(response, "config", &config);
prop_dictionary_get_uint8(response, "type", &type);
prop_dictionary_get_uint8(response, "nid", &nid);
sprintf(buf, "widget%02Xh", nid);
switch (type) {
case COP_AWCAP_TYPE_AUDIO_OUTPUT:
printf(" %s [label=\"%s\\naudio output\",shape=box,style=filled,fillcolor=\""
"#88ff88\"];\n", buf, buf);
break;
case COP_AWCAP_TYPE_AUDIO_INPUT:
printf(" %s [label=\"%s\\naudio input\",shape=box,style=filled,fillcolor=\""
"#ff8888\"];\n", buf, buf);
break;
case COP_AWCAP_TYPE_AUDIO_MIXER:
printf(" %s [label=\"%s\\naudio mixer\","
"shape=invhouse];\n", buf, buf);
break;
case COP_AWCAP_TYPE_AUDIO_SELECTOR:
printf(" %s [label=\"%s\\naudio selector\","
"shape=invtrapezium];\n", buf, buf);
break;
case COP_AWCAP_TYPE_PIN_COMPLEX:
printf(" %s [label=\"%s\\ndevice=%s\",style=filled",
buf, buf,
pin_devices[COP_CFG_DEFAULT_DEVICE(config)]);
if (cap & COP_PINCAP_OUTPUT_CAPABLE &&
cap & COP_PINCAP_INPUT_CAPABLE)
puts(",shape=doublecircle,fillcolor=\""
"#ffff88\"];");
else if (cap & COP_PINCAP_OUTPUT_CAPABLE)
puts(",shape=circle,fillcolor=\"#88ff88\"];");
else if (cap & COP_PINCAP_INPUT_CAPABLE)
puts(",shape=circle,fillcolor=\"#ff8888\"];");
else
puts(",shape=circle,fillcolor=\"#888888\"];");
break;
case COP_AWCAP_TYPE_POWER_WIDGET:
printf(" %s [label=\"%s\\npower widget\","
"shape=box];\n", buf, buf);
break;
case COP_AWCAP_TYPE_VOLUME_KNOB:
printf(" %s [label=\"%s\\nvolume knob\","
"shape=box];\n", buf, buf);
break;
case COP_AWCAP_TYPE_BEEP_GENERATOR:
printf(" %s [label=\"%s\\nbeep generator\","
"shape=box];\n", buf, buf);
break;
case COP_AWCAP_TYPE_VENDOR_DEFINED:
printf(" %s [label=\"%s\\nvendor defined\","
"shape=box];\n", buf, buf);
break;
}
connlist = prop_dictionary_get(response, "connlist");
if (connlist == NULL)
goto next;
iter = prop_array_iterator(connlist);
prop_object_iterator_reset(iter);
while ((nnid = prop_object_iterator_next(iter)) != NULL) {
nid = prop_number_unsigned_value(nnid);
printf(" widget%02Xh -> %s [sametail=widget%02Xh];\n",
nid, buf, nid);
}
prop_object_iterator_release(iter);
next:
prop_object_release(response);
}
printf(" {rank=min;");
for (index = 0;; index++) {
prop_dictionary_set_uint16(request, "index", index);
error = prop_dictionary_sendrecv_ioctl(request, fd,
HDAUDIO_AFG_WIDGET_INFO, &response);
if (error != 0)
break;
prop_dictionary_get_string(response, "name", &name);
prop_dictionary_get_uint8(response, "type", &type);
prop_dictionary_get_uint8(response, "nid", &nid);
sprintf(buf, "widget%02Xh", nid);
switch (type) {
case COP_AWCAP_TYPE_AUDIO_OUTPUT:
case COP_AWCAP_TYPE_AUDIO_INPUT:
printf(" %s;", buf);
break;
}
prop_object_release(response);
}
printf("}\n");
printf(" {rank=max;");
for (index = 0;; index++) {
prop_dictionary_set_uint16(request, "index", index);
error = prop_dictionary_sendrecv_ioctl(request, fd,
HDAUDIO_AFG_WIDGET_INFO, &response);
if (error != 0)
break;
prop_dictionary_get_string(response, "name", &name);
prop_dictionary_get_uint8(response, "type", &type);
prop_dictionary_get_uint8(response, "nid", &nid);
sprintf(buf, "widget%02Xh", nid);
switch (type) {
case COP_AWCAP_TYPE_PIN_COMPLEX:
printf(" %s;", buf);
break;
}
prop_object_release(response);
}
printf("}\n");
printf("}\n");
prop_object_release(request);
return 0;
}