Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add hdaudioctl(8), a tool to manipulate hdaudio(4) devices.



details:   https://anonhg.NetBSD.org/src/rev/62d38562a081
branches:  trunk
changeset: 748043:62d38562a081
user:      sborrill <sborrill%NetBSD.org@localhost>
date:      Sun Oct 11 08:57:54 2009 +0000

description:
Add hdaudioctl(8), a tool to manipulate hdaudio(4) devices.
It offer the following subcommands:
        list - shows all child codec
        get - get a plist of the chosen codec's widget configuration
        set - forcibly reconfigure a specified codec from a plist
        graph - generate a graphviz file for the specified codec

diffstat:

 distrib/sets/lists/base/mi       |    3 +-
 distrib/sets/lists/man/mi        |    5 +-
 doc/CHANGES                      |    4 +-
 usr.sbin/Makefile                |    5 +-
 usr.sbin/hdaudioctl/Makefile     |   11 +
 usr.sbin/hdaudioctl/graph.c      |  209 +++++++++++++++++++++++++++++++
 usr.sbin/hdaudioctl/hdaudioctl.8 |  101 +++++++++++++++
 usr.sbin/hdaudioctl/hdaudioctl.c |  255 +++++++++++++++++++++++++++++++++++++++
 usr.sbin/hdaudioctl/hdaudioctl.h |    2 +
 9 files changed, 590 insertions(+), 5 deletions(-)

diffs (truncated from 682 to 300 lines):

diff -r 328c6a263dc1 -r 62d38562a081 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sun Oct 11 08:50:11 2009 +0000
+++ b/distrib/sets/lists/base/mi        Sun Oct 11 08:57:54 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.832 2009/10/05 22:32:58 haad Exp $
+# $NetBSD: mi,v 1.833 2009/10/11 08:57:54 sborrill Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -1068,6 +1068,7 @@
 ./usr/sbin/groupdel                            base-sysutil-bin
 ./usr/sbin/groupinfo                           base-sysutil-bin
 ./usr/sbin/groupmod                            base-sysutil-bin
+./usr/sbin/hdaudioctl                          base-sysutil-bin
 ./usr/sbin/hlfsd                               base-amd-bin
 ./usr/sbin/host                                        base-obsolete           obsolete
 ./usr/sbin/hostapd                             base-sysutil-bin
diff -r 328c6a263dc1 -r 62d38562a081 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun Oct 11 08:50:11 2009 +0000
+++ b/distrib/sets/lists/man/mi Sun Oct 11 08:57:54 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1163 2009/10/09 00:48:35 haad Exp $
+# $NetBSD: mi,v 1.1164 2009/10/11 08:57:54 sborrill Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2118,6 +2118,7 @@
 ./usr/share/man/cat8/groupmod.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/gspa.0                    man-sysutil-catman      .cat
 ./usr/share/man/cat8/halt.0                    man-sysutil-catman      .cat
+./usr/share/man/cat8/hdaudioctl.0              man-sysutil-catman      .cat
 ./usr/share/man/cat8/hlfsd.0                   man-amd-catman          .cat
 ./usr/share/man/cat8/hostapd.0                 man-sysutil-catman      .cat
 ./usr/share/man/cat8/hostapd_cli.0             man-sysutil-catman      .cat
@@ -4582,6 +4583,7 @@
 ./usr/share/man/html8/groupmod.html            man-sysutil-htmlman     html
 ./usr/share/man/html8/gspa.html                        man-sysutil-htmlman     html
 ./usr/share/man/html8/halt.html                        man-sysutil-htmlman     html
+./usr/share/man/html8/hdaudioctl.html          man-sysutil-htmlman     html
 ./usr/share/man/html8/hlfsd.html               man-amd-htmlman         html
 ./usr/share/man/html8/hostapd.html             man-sysutil-htmlman     html
 ./usr/share/man/html8/hostapd_cli.html         man-sysutil-htmlman     html
@@ -7143,6 +7145,7 @@
 ./usr/share/man/man8/groupmod.8                        man-sysutil-man         .man
 ./usr/share/man/man8/gspa.8                    man-sysutil-man         .man
 ./usr/share/man/man8/halt.8                    man-sysutil-man         .man
+./usr/share/man/man8/hdaudioctl.8              man-sysutil-man         .man
 ./usr/share/man/man8/hlfsd.8                   man-amd-man             .man
 ./usr/share/man/man8/hostapd.8                 man-sysutil-man         .man
 ./usr/share/man/man8/hostapd_cli.8             man-sysutil-man         .man
diff -r 328c6a263dc1 -r 62d38562a081 doc/CHANGES
--- a/doc/CHANGES       Sun Oct 11 08:50:11 2009 +0000
+++ b/doc/CHANGES       Sun Oct 11 08:57:54 2009 +0000
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1305 $>
+# LIST OF CHANGES FROM LAST RELEASE:                   <$Revision: 1.1306 $>
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -419,3 +419,5 @@
        dhcpcd(8): Import dhcpcd-5.1.1. [roy 20091002]
        libm(3): Add f{dim,max,min}{,f,l} from FreeBSD [christos 20091004]
        man(1): Display manpage when specified with a path [cegger 20091007]
+       hdaudioctl(8): Add tool to manipulate hdaudio(4) devices
+               [sborrill 20091011]
diff -r 328c6a263dc1 -r 62d38562a081 usr.sbin/Makefile
--- a/usr.sbin/Makefile Sun Oct 11 08:50:11 2009 +0000
+++ b/usr.sbin/Makefile Sun Oct 11 08:57:54 2009 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.242 2009/06/25 18:41:21 mbalmer Exp $
+#      $NetBSD: Makefile,v 1.243 2009/10/11 08:57:54 sborrill Exp $
 #      from: @(#)Makefile      5.20 (Berkeley) 6/12/93
 
 .include <bsd.own.mk>
@@ -8,7 +8,8 @@
        chown chroot chrtbl cnwctl cpuctl crash cron dev_mkdb \
        dhcp diskpart dumpfs dumplfs edquota eeprom \
        envstat eshconfig etcupdate extattrctl fssconfig fusermount fwctl \
-       gpioctl grfconfig grfinfo gspa hilinfo ifwatchd inetd installboot \
+       gpioctl grfconfig grfinfo gspa hdaudioctl hilinfo ifwatchd inetd \
+       installboot \
        iopctl iostat ipwctl irdaattach isdn iteconfig iwictl\
        kgmon lastlogin link lmcconfig lockstat lpr mailwrapper makefs \
        map-mbone mdconfig memswitch mlxctl mmcformat mopd mountd moused \
diff -r 328c6a263dc1 -r 62d38562a081 usr.sbin/hdaudioctl/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/hdaudioctl/Makefile      Sun Oct 11 08:57:54 2009 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1 2009/10/11 08:57:54 sborrill Exp $
+
+PROG=          hdaudioctl
+SRCS=          hdaudioctl.c
+SRCS+=         graph.c
+MAN=           hdaudioctl.8
+
+LDADD+=                -lprop
+DPADD+=                ${LIBPROP}
+
+.include <bsd.prog.mk>
diff -r 328c6a263dc1 -r 62d38562a081 usr.sbin/hdaudioctl/graph.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/hdaudioctl/graph.c       Sun Oct 11 08:57:54 2009 +0000
@@ -0,0 +1,209 @@
+/* $NetBSD: graph.c,v 1.1 2009/10/11 08:57:54 sborrill Exp $ */
+
+/*
+ * Copyright (c) 2009 Precedence Technologies Ltd <support%precedence.co.uk@localhost>
+ * Copyright (c) 2009 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * 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/pci/hdaudio/hdaudioio.h>
+#include <dev/pci/hdaudio/hdaudioreg.h>
+
+#include "hdaudioctl.h"
+
+static const char *pin_devices[16] = {
+       "Line Out", "Speaker", "HP Out", "CD",
+       "SPDIF Out", "Digital Out", "Modem Line", "Modem Handset",
+       "Line In", "AUX", "Mic In", "Telephony",
+       "SPDIF In", "Digital In", "Reserved", "Other"
+};
+
+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_cstring_nocopy(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 [shape=box,style=filled,fillcolor=\""
+                           "#88ff88\"];\n", buf);
+                       break;
+               case COP_AWCAP_TYPE_AUDIO_INPUT:
+                       printf(" %s [shape=box,style=filled,fillcolor=\""
+                           "#ff8888\"];\n", buf);
+                       break;
+               case COP_AWCAP_TYPE_AUDIO_MIXER:
+                       printf(" %s [shape=invhouse];\n", buf);
+                       break;
+               case COP_AWCAP_TYPE_AUDIO_SELECTOR:
+                       printf(" %s [shape=invtrapezium];\n", 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)
+                               printf(",shape=doublecircle,fillcolor=\""
+                                   "#ffff88\"];\n");
+                       else if (cap & COP_PINCAP_OUTPUT_CAPABLE)
+                               printf(",shape=circle,fillcolor=\"#88ff88\"];\n");
+                       else if (cap & COP_PINCAP_INPUT_CAPABLE)
+                               printf(",shape=circle,fillcolor=\"#ff8888\"];\n");
+                       else
+                               printf(",shape=circle,fillcolor=\"#888888\"];\n");
+                       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_integer_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_cstring_nocopy(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_cstring_nocopy(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);



Home | Main Index | Thread Index | Old Index