xref: /freebsd/usr.sbin/bhyve/pci_hda.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
16b021cc2SWarner Losh /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33e21da8aSMarcelo Araujo  *
46b021cc2SWarner Losh  * Copyright (c) 2016 Alex Teaca <iateaca@FreeBSD.org>
56b021cc2SWarner Losh  * All rights reserved.
66b021cc2SWarner Losh  *
76b021cc2SWarner Losh  * Redistribution and use in source and binary forms, with or without
86b021cc2SWarner Losh  * modification, are permitted provided that the following conditions
96b021cc2SWarner Losh  * are met:
106b021cc2SWarner Losh  * 1. Redistributions of source code must retain the above copyright
116b021cc2SWarner Losh  *    notice, this list of conditions and the following disclaimer.
126b021cc2SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
136b021cc2SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
146b021cc2SWarner Losh  *    documentation and/or other materials provided with the distribution.
156b021cc2SWarner Losh  *
166b021cc2SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
176b021cc2SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
186b021cc2SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
196b021cc2SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
206b021cc2SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
216b021cc2SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
226b021cc2SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
236b021cc2SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246b021cc2SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256b021cc2SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266b021cc2SWarner Losh  * SUCH DAMAGE.
276b021cc2SWarner Losh  */
286b021cc2SWarner Losh 
296b021cc2SWarner Losh #ifndef _HDA_EMUL_H_
306b021cc2SWarner Losh #define _HDA_EMUL_H_
316b021cc2SWarner Losh 
326b021cc2SWarner Losh #include <stdio.h>
336b021cc2SWarner Losh #include <stdlib.h>
346b021cc2SWarner Losh #include <string.h>
356b021cc2SWarner Losh #include <sys/types.h>
366b021cc2SWarner Losh #include <assert.h>
376b021cc2SWarner Losh 
386b021cc2SWarner Losh #include <sys/types.h>
396b021cc2SWarner Losh #include <sys/queue.h>
406b021cc2SWarner Losh #include <sys/kernel.h>
416b021cc2SWarner Losh 
426b021cc2SWarner Losh #include "hda_reg.h"
436b021cc2SWarner Losh 
446b021cc2SWarner Losh /*
456b021cc2SWarner Losh  * HDA Debug Log
466b021cc2SWarner Losh  */
476b021cc2SWarner Losh #if DEBUG_HDA == 1
486b021cc2SWarner Losh extern FILE *dbg;
496b021cc2SWarner Losh #define DPRINTF(fmt, arg...)						\
50332eff95SVincenzo Maffione do {fprintf(dbg, "%s-%d: " fmt "\n", __func__, __LINE__, ##arg);		\
516b021cc2SWarner Losh fflush(dbg); } while (0)
52014e0341SGuido Falsi #ifndef DEBUG_HDA_FILE
53014e0341SGuido Falsi #define DEBUG_HDA_FILE "/tmp/bhyve_hda.log"
54014e0341SGuido Falsi #endif
556b021cc2SWarner Losh #else
566b021cc2SWarner Losh #define DPRINTF(fmt, arg...)
576b021cc2SWarner Losh #endif
586b021cc2SWarner Losh 
596b021cc2SWarner Losh #define HDA_FIFO_SIZE			0x100
606b021cc2SWarner Losh 
616b021cc2SWarner Losh struct hda_softc;
626b021cc2SWarner Losh struct hda_codec_class;
636b021cc2SWarner Losh 
646b021cc2SWarner Losh struct hda_codec_inst {
656b021cc2SWarner Losh 	uint8_t cad;
666b021cc2SWarner Losh 	struct hda_codec_class *codec;
676b021cc2SWarner Losh 	struct hda_softc *hda;
68489392feSMark Johnston 	const struct hda_ops *hops;
696b021cc2SWarner Losh 	void *priv;
706b021cc2SWarner Losh };
716b021cc2SWarner Losh 
726b021cc2SWarner Losh struct hda_codec_class {
73d06bf11cSMark Johnston 	const char *name;
746b021cc2SWarner Losh 	int (*init)(struct hda_codec_inst *hci, const char *play,
75621b5090SJohn Baldwin 		const char *rec);
766b021cc2SWarner Losh 	int (*reset)(struct hda_codec_inst *hci);
776b021cc2SWarner Losh 	int (*command)(struct hda_codec_inst *hci, uint32_t cmd_data);
786b021cc2SWarner Losh 	int (*notify)(struct hda_codec_inst *hci, uint8_t run, uint8_t stream,
796b021cc2SWarner Losh 		uint8_t dir);
806b021cc2SWarner Losh };
816b021cc2SWarner Losh 
826b021cc2SWarner Losh struct hda_ops {
836b021cc2SWarner Losh 	int (*signal)(struct hda_codec_inst *hci);
846b021cc2SWarner Losh 	int (*response)(struct hda_codec_inst *hci, uint32_t response,
856b021cc2SWarner Losh 		uint8_t unsol);
866b021cc2SWarner Losh 	int (*transfer)(struct hda_codec_inst *hci, uint8_t stream,
8763898728SMark Johnston 		uint8_t dir, uint8_t *buf, size_t count);
886b021cc2SWarner Losh };
896b021cc2SWarner Losh 
901308a17bSElyes Haouas #define HDA_EMUL_SET(x)		DATA_SET(hda_codec_class_set, x)
916b021cc2SWarner Losh 
926b021cc2SWarner Losh #endif	/* _HDA_EMUL_H_ */
93