1 1.6 christos /* $NetBSD: graph.c,v 1.6 2021/06/21 03:09:52 christos Exp $ */ 2 1.1 sborrill 3 1.1 sborrill /* 4 1.1 sborrill * Copyright (c) 2009 Precedence Technologies Ltd <support (at) precedence.co.uk> 5 1.1 sborrill * Copyright (c) 2009 Jared D. McNeill <jmcneill (at) invisible.ca> 6 1.1 sborrill * All rights reserved. 7 1.1 sborrill * 8 1.1 sborrill * This code is derived from software contributed to The NetBSD Foundation 9 1.1 sborrill * by Precedence Technologies Ltd 10 1.1 sborrill * 11 1.1 sborrill * Redistribution and use in source and binary forms, with or without 12 1.1 sborrill * modification, are permitted provided that the following conditions 13 1.1 sborrill * are met: 14 1.1 sborrill * 1. Redistributions of source code must retain the above copyright 15 1.1 sborrill * notice, this list of conditions and the following disclaimer. 16 1.1 sborrill * 2. The name of the author may not be used to endorse or promote products 17 1.1 sborrill * derived from this software without specific prior written permission. 18 1.1 sborrill * 19 1.1 sborrill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20 1.1 sborrill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 1.1 sborrill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22 1.1 sborrill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23 1.1 sborrill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 1.1 sborrill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 1.1 sborrill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 1.1 sborrill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 1.1 sborrill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 sborrill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 sborrill * SUCH DAMAGE. 30 1.1 sborrill */ 31 1.1 sborrill 32 1.1 sborrill #include <sys/types.h> 33 1.1 sborrill #include <sys/ioctl.h> 34 1.1 sborrill 35 1.1 sborrill #include <prop/proplib.h> 36 1.1 sborrill 37 1.1 sborrill #include <errno.h> 38 1.1 sborrill #include <fcntl.h> 39 1.1 sborrill #include <stdio.h> 40 1.1 sborrill #include <stdlib.h> 41 1.1 sborrill #include <unistd.h> 42 1.1 sborrill 43 1.3 jmcneill #include <dev/hdaudio/hdaudioio.h> 44 1.3 jmcneill #include <dev/hdaudio/hdaudioreg.h> 45 1.1 sborrill 46 1.1 sborrill #include "hdaudioctl.h" 47 1.1 sborrill 48 1.1 sborrill int 49 1.1 sborrill hdaudioctl_graph(int fd, int argc, char *argv[]) 50 1.1 sborrill { 51 1.1 sborrill prop_dictionary_t request, response; 52 1.1 sborrill prop_object_iterator_t iter; 53 1.1 sborrill prop_number_t nnid; 54 1.1 sborrill prop_array_t connlist; 55 1.1 sborrill const char *name; 56 1.1 sborrill int error, index; 57 1.1 sborrill uint32_t cap, config; 58 1.1 sborrill uint16_t reqnid, reqcodecid; 59 1.1 sborrill uint16_t vendor, product; 60 1.1 sborrill uint8_t type, nid; 61 1.1 sborrill char buf[10] = "??h"; 62 1.1 sborrill 63 1.1 sborrill if (argc != 2) 64 1.1 sborrill usage(); 65 1.1 sborrill 66 1.1 sborrill reqcodecid = strtol(argv[0], NULL, 0); 67 1.1 sborrill reqnid = strtol(argv[1], NULL, 0); 68 1.1 sborrill 69 1.1 sborrill request = prop_dictionary_create(); 70 1.1 sborrill if (request == NULL) { 71 1.1 sborrill fprintf(stderr, "out of memory\n"); 72 1.1 sborrill return ENOMEM; 73 1.1 sborrill } 74 1.1 sborrill 75 1.1 sborrill prop_dictionary_set_uint16(request, "codecid", reqcodecid); 76 1.1 sborrill prop_dictionary_set_uint16(request, "nid", reqnid); 77 1.1 sborrill 78 1.1 sborrill error = prop_dictionary_sendrecv_ioctl(request, fd, 79 1.1 sborrill HDAUDIO_FGRP_CODEC_INFO, &response); 80 1.1 sborrill if (error != 0) { 81 1.1 sborrill perror("HDAUDIO_FGRP_CODEC_INFO failed"); 82 1.1 sborrill prop_object_release(request); 83 1.1 sborrill return error; 84 1.1 sborrill } 85 1.1 sborrill 86 1.1 sborrill prop_dictionary_get_uint16(response, "vendor-id", &vendor); 87 1.1 sborrill prop_dictionary_get_uint16(response, "product-id", &product); 88 1.1 sborrill 89 1.1 sborrill printf("digraph \"HD Audio %04X:%04X\" {\n", 90 1.1 sborrill vendor, product); 91 1.1 sborrill 92 1.1 sborrill for (index = 0;; index++) { 93 1.1 sborrill prop_dictionary_set_uint16(request, "index", index); 94 1.1 sborrill error = prop_dictionary_sendrecv_ioctl(request, fd, 95 1.1 sborrill HDAUDIO_FGRP_WIDGET_INFO, &response); 96 1.1 sborrill if (error != 0) 97 1.1 sborrill break; 98 1.6 christos prop_dictionary_get_string(response, "name", &name); 99 1.1 sborrill prop_dictionary_get_uint32(response, "cap", &cap); 100 1.1 sborrill prop_dictionary_get_uint32(response, "config", &config); 101 1.1 sborrill prop_dictionary_get_uint8(response, "type", &type); 102 1.1 sborrill prop_dictionary_get_uint8(response, "nid", &nid); 103 1.1 sborrill 104 1.1 sborrill sprintf(buf, "widget%02Xh", nid); 105 1.1 sborrill 106 1.1 sborrill switch (type) { 107 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_OUTPUT: 108 1.2 joerg printf(" %s [label=\"%s\\naudio output\",shape=box,style=filled,fillcolor=\"" 109 1.2 joerg "#88ff88\"];\n", buf, buf); 110 1.1 sborrill break; 111 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_INPUT: 112 1.2 joerg printf(" %s [label=\"%s\\naudio input\",shape=box,style=filled,fillcolor=\"" 113 1.2 joerg "#ff8888\"];\n", buf, buf); 114 1.1 sborrill break; 115 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_MIXER: 116 1.2 joerg printf(" %s [label=\"%s\\naudio mixer\"," 117 1.2 joerg "shape=invhouse];\n", buf, buf); 118 1.1 sborrill break; 119 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_SELECTOR: 120 1.2 joerg printf(" %s [label=\"%s\\naudio selector\"," 121 1.2 joerg "shape=invtrapezium];\n", buf, buf); 122 1.1 sborrill break; 123 1.1 sborrill case COP_AWCAP_TYPE_PIN_COMPLEX: 124 1.1 sborrill printf(" %s [label=\"%s\\ndevice=%s\",style=filled", 125 1.1 sborrill buf, buf, 126 1.1 sborrill pin_devices[COP_CFG_DEFAULT_DEVICE(config)]); 127 1.1 sborrill if (cap & COP_PINCAP_OUTPUT_CAPABLE && 128 1.1 sborrill cap & COP_PINCAP_INPUT_CAPABLE) 129 1.2 joerg puts(",shape=doublecircle,fillcolor=\"" 130 1.2 joerg "#ffff88\"];"); 131 1.1 sborrill else if (cap & COP_PINCAP_OUTPUT_CAPABLE) 132 1.2 joerg puts(",shape=circle,fillcolor=\"#88ff88\"];"); 133 1.1 sborrill else if (cap & COP_PINCAP_INPUT_CAPABLE) 134 1.2 joerg puts(",shape=circle,fillcolor=\"#ff8888\"];"); 135 1.1 sborrill else 136 1.2 joerg puts(",shape=circle,fillcolor=\"#888888\"];"); 137 1.2 joerg break; 138 1.2 joerg case COP_AWCAP_TYPE_POWER_WIDGET: 139 1.2 joerg printf(" %s [label=\"%s\\npower widget\"," 140 1.2 joerg "shape=box];\n", buf, buf); 141 1.2 joerg break; 142 1.2 joerg case COP_AWCAP_TYPE_VOLUME_KNOB: 143 1.2 joerg printf(" %s [label=\"%s\\nvolume knob\"," 144 1.2 joerg "shape=box];\n", buf, buf); 145 1.2 joerg break; 146 1.2 joerg case COP_AWCAP_TYPE_BEEP_GENERATOR: 147 1.2 joerg printf(" %s [label=\"%s\\nbeep generator\"," 148 1.2 joerg "shape=box];\n", buf, buf); 149 1.2 joerg break; 150 1.2 joerg case COP_AWCAP_TYPE_VENDOR_DEFINED: 151 1.2 joerg printf(" %s [label=\"%s\\nvendor defined\"," 152 1.2 joerg "shape=box];\n", buf, buf); 153 1.1 sborrill break; 154 1.1 sborrill } 155 1.1 sborrill connlist = prop_dictionary_get(response, "connlist"); 156 1.1 sborrill if (connlist == NULL) 157 1.1 sborrill goto next; 158 1.1 sborrill iter = prop_array_iterator(connlist); 159 1.1 sborrill prop_object_iterator_reset(iter); 160 1.1 sborrill while ((nnid = prop_object_iterator_next(iter)) != NULL) { 161 1.4 thorpej nid = prop_number_unsigned_value(nnid); 162 1.1 sborrill printf(" widget%02Xh -> %s [sametail=widget%02Xh];\n", 163 1.1 sborrill nid, buf, nid); 164 1.1 sborrill } 165 1.1 sborrill prop_object_iterator_release(iter); 166 1.1 sborrill next: 167 1.1 sborrill prop_object_release(response); 168 1.1 sborrill } 169 1.1 sborrill 170 1.1 sborrill printf(" {rank=min;"); 171 1.1 sborrill for (index = 0;; index++) { 172 1.1 sborrill prop_dictionary_set_uint16(request, "index", index); 173 1.1 sborrill error = prop_dictionary_sendrecv_ioctl(request, fd, 174 1.1 sborrill HDAUDIO_AFG_WIDGET_INFO, &response); 175 1.1 sborrill if (error != 0) 176 1.1 sborrill break; 177 1.6 christos prop_dictionary_get_string(response, "name", &name); 178 1.1 sborrill prop_dictionary_get_uint8(response, "type", &type); 179 1.1 sborrill prop_dictionary_get_uint8(response, "nid", &nid); 180 1.1 sborrill 181 1.1 sborrill sprintf(buf, "widget%02Xh", nid); 182 1.1 sborrill 183 1.1 sborrill switch (type) { 184 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_OUTPUT: 185 1.1 sborrill case COP_AWCAP_TYPE_AUDIO_INPUT: 186 1.1 sborrill printf(" %s;", buf); 187 1.1 sborrill break; 188 1.1 sborrill } 189 1.1 sborrill prop_object_release(response); 190 1.1 sborrill } 191 1.1 sborrill printf("}\n"); 192 1.1 sborrill 193 1.1 sborrill printf(" {rank=max;"); 194 1.1 sborrill for (index = 0;; index++) { 195 1.1 sborrill prop_dictionary_set_uint16(request, "index", index); 196 1.1 sborrill error = prop_dictionary_sendrecv_ioctl(request, fd, 197 1.1 sborrill HDAUDIO_AFG_WIDGET_INFO, &response); 198 1.1 sborrill if (error != 0) 199 1.1 sborrill break; 200 1.6 christos prop_dictionary_get_string(response, "name", &name); 201 1.1 sborrill prop_dictionary_get_uint8(response, "type", &type); 202 1.1 sborrill prop_dictionary_get_uint8(response, "nid", &nid); 203 1.1 sborrill 204 1.1 sborrill sprintf(buf, "widget%02Xh", nid); 205 1.1 sborrill 206 1.1 sborrill switch (type) { 207 1.1 sborrill case COP_AWCAP_TYPE_PIN_COMPLEX: 208 1.1 sborrill printf(" %s;", buf); 209 1.1 sborrill break; 210 1.1 sborrill } 211 1.1 sborrill prop_object_release(response); 212 1.1 sborrill } 213 1.1 sborrill printf("}\n"); 214 1.1 sborrill 215 1.1 sborrill printf("}\n"); 216 1.1 sborrill 217 1.1 sborrill prop_object_release(request); 218 1.1 sborrill 219 1.1 sborrill return 0; 220 1.1 sborrill } 221