From owner-svn-soc-all@freebsd.org Fri Jun 17 15:06:50 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D9217A783BA for ; Fri, 17 Jun 2016 15:06:50 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CC3BD1982 for ; Fri, 17 Jun 2016 15:06:50 +0000 (UTC) (envelope-from iateaca@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u5HF6oOr068175 for ; Fri, 17 Jun 2016 15:06:50 GMT (envelope-from iateaca@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u5HF6osK067928 for svn-soc-all@FreeBSD.org; Fri, 17 Jun 2016 15:06:50 GMT (envelope-from iateaca@FreeBSD.org) Date: Fri, 17 Jun 2016 15:06:50 GMT Message-Id: <201606171506.u5HF6osK067928@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to iateaca@FreeBSD.org using -f From: iateaca@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r305285 - soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jun 2016 15:06:50 -0000 Author: iateaca Date: Fri Jun 17 15:06:49 2016 New Revision: 305285 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305285 Log: design the hda_codec_stream data structure add one hda_codec_stream data for the audio output converter add specific handlers per node in order to implement the verb commands M bhyve/hda_codec.c Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Modified: soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c ============================================================================== --- soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Fri Jun 17 09:07:27 2016 (r305284) +++ soc2016/iateaca/bhyve-hda-head/usr.sbin/bhyve/hda_codec.c Fri Jun 17 15:06:49 2016 (r305285) @@ -12,6 +12,9 @@ #define HDA_CODEC_AUDIO_OUTPUT_NID 0x02 #define HDA_CODEC_PIN_OUTPUT_NID 0x03 +#define HDA_CODEC_STREAMS_COUNT 0x01 +#define HDA_CODEC_STREAM_OUTPUT 0x00 + #define HDA_CODEC_PARAMS_COUNT 0x14 #define HDA_CODEC_CONN_LIST_COUNT 0x01 #define HDA_CODEC_RESPONSE_EX_UNSOL 0x10 @@ -46,6 +49,15 @@ * HDA Codec data structures */ +struct hda_codec_softc; + +typedef uint32_t (*verb_func_t)(struct hda_codec_softc *sc, uint16_t verb, uint16_t payload); + +struct hda_codec_stream { + uint8_t stream; + uint8_t channel; + uint16_t fmt; +}; struct hda_codec_softc { uint32_t subsystem_id; @@ -54,6 +66,9 @@ const uint8_t (*conn_list)[HDA_CODEC_CONN_LIST_COUNT]; const uint32_t *conf_default; const uint8_t *pin_ctrl_default; + const verb_func_t *verb_handlers; + + struct hda_codec_stream streams[HDA_CODEC_STREAMS_COUNT]; }; /* @@ -66,6 +81,8 @@ static int hda_codec_command(struct hda_codec_inst *hci, uint32_t cmd_data); +uint32_t hda_codec_audio_output_nid(struct hda_codec_softc *sc, uint16_t verb, uint16_t payload); + /* * HDA Codec global data */ @@ -129,6 +146,10 @@ [HDA_CODEC_PIN_OUTPUT_NID] = HDA_CODEC_PIN_WIDGET_CTRL_OUT_ENABLE, }; +static const verb_func_t hda_codec_verb_handlers[HDA_CODEC_NODES_COUNT] = { + [HDA_CODEC_AUDIO_OUTPUT_NID] = hda_codec_audio_output_nid, +}; + /* * HDA Codec module function definitions */ @@ -150,6 +171,7 @@ sc->conn_list = hda_codec_conn_list; sc->conf_default = hda_codec_conf_default; sc->pin_ctrl_default = hda_codec_pin_ctrl_default; + sc->verb_handlers = hda_codec_verb_handlers; DPRINTF("HDA Codec nodes: %d\n", sc->no_nodes); hci->priv = sc; @@ -206,6 +228,8 @@ sc = (struct hda_codec_softc *)hci->priv; assert(sc); + assert(nid < sc->no_nodes); + if (!hops->response) { DPRINTF("The controller ops does not implement the response function\n"); return -1; @@ -213,35 +237,29 @@ switch (verb) { case HDA_CMD_VERB_GET_PARAMETER: - if (nid < sc->no_nodes) - res = sc->get_parameters[nid][payload]; - else - DPRINTF("GET_PARAMETER(nid: %d) not described\n", nid); + res = sc->get_parameters[nid][payload]; break; case HDA_CMD_VERB_GET_CONN_LIST_ENTRY: - assert(nid < sc->no_nodes); res = sc->conn_list[nid][0]; break; case HDA_CMD_VERB_GET_PIN_WIDGET_CTRL: - assert(nid < sc->no_nodes); res = sc->pin_ctrl_default[nid]; break; case HDA_CMD_VERB_GET_PIN_SENSE: res = HDA_CODEC_PIN_SENSE_PRESENCE_PLUGGED; break; case HDA_CMD_VERB_GET_CONFIGURATION_DEFAULT: - assert(nid < sc->no_nodes); res = sc->conf_default[nid]; break; case HDA_CMD_VERB_GET_SUBSYSTEM_ID: res = sc->subsystem_id; break; - case HDA_CMD_VERB_SET_AMP_GAIN_MUTE: - /* TODO - handle this command */ - break; default: - /* TODO - call a specific handler per node */ - DPRINTF("Unknown VERB: 0x%x\n", verb); + assert(sc->verb_handlers); + if (sc->verb_handlers[nid]) + res = sc->verb_handlers[nid](sc, verb, payload); + else + DPRINTF("Unknown VERB: 0x%x\n", verb); break; } @@ -251,6 +269,31 @@ return hops->response(hci, res, HDA_CODEC_RESPONSE_EX_SOL); } +uint32_t hda_codec_audio_output_nid(struct hda_codec_softc *sc, uint16_t verb, uint16_t payload) +{ + struct hda_codec_stream *st = NULL; + uint32_t res = 0; + + DPRINTF("verb: 0x%x, payload, 0x%x\n", verb, payload); + + st = &sc->streams[HDA_CODEC_STREAM_OUTPUT]; + + switch (verb) { + case HDA_CMD_VERB_SET_CONV_FMT: + st->fmt = payload; + break; + case HDA_CMD_VERB_SET_CONV_STREAM_CHAN: + st->channel = payload & 0x0f; + st->stream = (payload >> 4) & 0x0f; + break; + default: + DPRINTF("Unknown VERB: 0x%x\n", verb); + break; + } + + return res; +} + struct hda_codec_class hda_codec = { .name = "hda_codec", .init = hda_codec_init,