Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Aug 2016 16:15:29 GMT
From:      iateaca@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r307409 - soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve
Message-ID:  <201608101615.u7AGFTII028746@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: iateaca
Date: Wed Aug 10 16:15:28 2016
New Revision: 307409
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=307409

Log:
  
  parse the configuration options and look after play= and rec= keys
  in order to get the audio device backends
  
  M    pci_hda.c

Modified:
  soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c

Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c
==============================================================================
--- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c	Wed Aug 10 15:45:25 2016	(r307408)
+++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/pci_hda.c	Wed Aug 10 16:15:28 2016	(r307409)
@@ -112,13 +112,16 @@
 static inline void
 hda_set_field_by_offset(struct hda_softc *sc, uint32_t offset, uint32_t mask, uint32_t value);
 
+static uint8_t
+hda_parse_config(const char *opts, const char *key, char *val);
 static struct hda_softc *hda_init(const char *opts);
 static void
 hda_update_intr(struct hda_softc *sc);
 static void
 hda_response_interrupt(struct hda_softc *sc);
 static int
-hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec);
+hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec,
+		      const char *play, const char *rec, const char *opts);
 static struct hda_codec_class *
 hda_find_codec_class(const char *name);
 
@@ -311,11 +314,60 @@
 	return;
 }
 
+static uint8_t
+hda_parse_config(const char *opts, const char *key, char *val)
+{
+	char buf[64];
+	char *s = buf;
+	char *tmp = NULL;
+	int len;
+	int i;
+
+	if (!opts)
+		return 0;
+
+	len = strlen(opts);
+
+	if (len >= 64) {
+		DPRINTF("Opts too big\n");
+		return 0;
+	}
+
+	DPRINTF("opts: %s\n", opts);
+
+	strcpy(buf, opts);
+
+	for (i = 0; i < len; i++)
+		if (buf[i] == ',') {
+			buf[i] = 0;
+			tmp = buf + i + 1;
+			break;
+		}
+
+	if (!memcmp(s, key, strlen(key))) {
+		strncpy(val, s + strlen(key), 64);
+		return 1;
+	}
+
+	if (!tmp)
+		return 0;
+
+	s = tmp;
+	if (!memcmp(s, key, strlen(key))) {
+		strncpy(val, s + strlen(key), 64);
+		return 1;
+	}
+
+	return 0;
+}
+
 static struct hda_softc *hda_init(const char *opts)
 {
 	struct hda_softc *sc = NULL;
 	struct hda_codec_class *codec = NULL;
-	int err;
+	char play[64];
+	char rec[64];
+	int err, p, r;
 
 #if DEBUG_HDA == 1
 	dbg = fopen("/tmp/bhyve_hda.log", "w+");
@@ -335,8 +387,13 @@
 	 */
 	codec = hda_find_codec_class("hda_codec");
 	if (codec) {
-		err = hda_codec_constructor(sc, codec);
-		assert(!err);
+		p = hda_parse_config(opts, "play=", play);
+		r = hda_parse_config(opts, "rec=", rec);
+		DPRINTF("play: %s rec: %s\n", play, rec);
+		if (p | r) {
+			err = hda_codec_constructor(sc, codec, p ? play : NULL, r ? rec : NULL, NULL);
+			assert(!err);
+		}
 	}
 
 	return sc;
@@ -409,7 +466,8 @@
 }
 
 static int
-hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec)
+hda_codec_constructor(struct hda_softc *sc, struct hda_codec_class *codec,
+		      const char *play, const char *rec, const char *opts)
 {
 	struct hda_codec_inst *hci = NULL;
 
@@ -432,7 +490,7 @@
 		return -1;
 	}
 
-	return codec->init(hci, "/dev/dsp0", "/dev/dsp1", NULL);
+	return codec->init(hci, play, rec, opts);
 }
 
 static struct hda_codec_class *



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201608101615.u7AGFTII028746>