xref: /illumos-gate/usr/src/cmd/bhyve/pci_hda.h (revision 32640292)
184659b24SMichael Zeller /*-
2*32640292SAndy Fiddaman  * SPDX-License-Identifier: BSD-2-Clause
384659b24SMichael Zeller  *
484659b24SMichael Zeller  * Copyright (c) 2016 Alex Teaca <iateaca@FreeBSD.org>
584659b24SMichael Zeller  * All rights reserved.
684659b24SMichael Zeller  *
784659b24SMichael Zeller  * Redistribution and use in source and binary forms, with or without
884659b24SMichael Zeller  * modification, are permitted provided that the following conditions
984659b24SMichael Zeller  * are met:
1084659b24SMichael Zeller  * 1. Redistributions of source code must retain the above copyright
1184659b24SMichael Zeller  *    notice, this list of conditions and the following disclaimer.
1284659b24SMichael Zeller  * 2. Redistributions in binary form must reproduce the above copyright
1384659b24SMichael Zeller  *    notice, this list of conditions and the following disclaimer in the
1484659b24SMichael Zeller  *    documentation and/or other materials provided with the distribution.
1584659b24SMichael Zeller  *
1684659b24SMichael Zeller  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
1784659b24SMichael Zeller  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1884659b24SMichael Zeller  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1984659b24SMichael Zeller  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2084659b24SMichael Zeller  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2184659b24SMichael Zeller  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2284659b24SMichael Zeller  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2384659b24SMichael Zeller  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2484659b24SMichael Zeller  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2584659b24SMichael Zeller  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2684659b24SMichael Zeller  * SUCH DAMAGE.
2784659b24SMichael Zeller  */
2884659b24SMichael Zeller 
296dc98349SAndy Fiddaman #ifndef _HDA_EMUL_H_
3084659b24SMichael Zeller #define _HDA_EMUL_H_
3184659b24SMichael Zeller 
3284659b24SMichael Zeller #include <stdio.h>
3384659b24SMichael Zeller #include <stdlib.h>
3484659b24SMichael Zeller #include <string.h>
3584659b24SMichael Zeller #include <sys/types.h>
3684659b24SMichael Zeller #include <assert.h>
3784659b24SMichael Zeller 
3884659b24SMichael Zeller #include <sys/types.h>
3984659b24SMichael Zeller #include <sys/queue.h>
4084659b24SMichael Zeller #include <sys/kernel.h>
4184659b24SMichael Zeller 
4284659b24SMichael Zeller #include "hda_reg.h"
4384659b24SMichael Zeller 
4484659b24SMichael Zeller /*
4584659b24SMichael Zeller  * HDA Debug Log
4684659b24SMichael Zeller  */
4784659b24SMichael Zeller #if DEBUG_HDA == 1
4884659b24SMichael Zeller extern FILE *dbg;
4984659b24SMichael Zeller #define DPRINTF(fmt, arg...)						\
50154972afSPatrick Mooney do {fprintf(dbg, "%s-%d: " fmt "\n", __func__, __LINE__, ##arg);		\
5184659b24SMichael Zeller fflush(dbg); } while (0)
52*32640292SAndy Fiddaman #ifndef DEBUG_HDA_FILE
53*32640292SAndy Fiddaman #define DEBUG_HDA_FILE "/tmp/bhyve_hda.log"
54*32640292SAndy Fiddaman #endif
5584659b24SMichael Zeller #else
5684659b24SMichael Zeller #define DPRINTF(fmt, arg...)
5784659b24SMichael Zeller #endif
5884659b24SMichael Zeller 
5984659b24SMichael Zeller #define HDA_FIFO_SIZE			0x100
6084659b24SMichael Zeller 
6184659b24SMichael Zeller struct hda_softc;
6284659b24SMichael Zeller struct hda_codec_class;
6384659b24SMichael Zeller 
6484659b24SMichael Zeller struct hda_codec_inst {
6584659b24SMichael Zeller 	uint8_t cad;
6684659b24SMichael Zeller 	struct hda_codec_class *codec;
6784659b24SMichael Zeller 	struct hda_softc *hda;
6859d65d31SAndy Fiddaman 	const struct hda_ops *hops;
6984659b24SMichael Zeller 	void *priv;
7084659b24SMichael Zeller };
7184659b24SMichael Zeller 
7284659b24SMichael Zeller struct hda_codec_class {
734f3f3e9aSAndy Fiddaman 	const char *name;
7484659b24SMichael Zeller 	int (*init)(struct hda_codec_inst *hci, const char *play,
752b948146SAndy Fiddaman 		const char *rec);
7684659b24SMichael Zeller 	int (*reset)(struct hda_codec_inst *hci);
7784659b24SMichael Zeller 	int (*command)(struct hda_codec_inst *hci, uint32_t cmd_data);
7884659b24SMichael Zeller 	int (*notify)(struct hda_codec_inst *hci, uint8_t run, uint8_t stream,
7984659b24SMichael Zeller 		uint8_t dir);
8084659b24SMichael Zeller };
8184659b24SMichael Zeller 
8284659b24SMichael Zeller struct hda_ops {
8384659b24SMichael Zeller 	int (*signal)(struct hda_codec_inst *hci);
8484659b24SMichael Zeller 	int (*response)(struct hda_codec_inst *hci, uint32_t response,
8584659b24SMichael Zeller 		uint8_t unsol);
8684659b24SMichael Zeller 	int (*transfer)(struct hda_codec_inst *hci, uint8_t stream,
8759d65d31SAndy Fiddaman 		uint8_t dir, uint8_t *buf, size_t count);
8884659b24SMichael Zeller };
8984659b24SMichael Zeller 
90*32640292SAndy Fiddaman #define HDA_EMUL_SET(x)		DATA_SET(hda_codec_class_set, x)
9184659b24SMichael Zeller 
9284659b24SMichael Zeller #endif	/* _HDA_EMUL_H_ */
93