xref: /netbsd/sys/dev/pci/emuxkivar.h (revision c90a6c91)
1 /*	$NetBSD: emuxkivar.h,v 1.16 2022/09/07 03:34:43 khorben Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Yannick Montulet, and by Andrew Doran.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _DEV_PCI_EMUXKIVAR_H_
33 #define _DEV_PCI_EMUXKIVAR_H_
34 
35 #include <sys/types.h>
36 #include <sys/device.h>
37 #include <sys/audioio.h>
38 #include <sys/mutex.h>
39 
40 #include <sys/bus.h>
41 
42 #include <dev/audio/audio_if.h>
43 
44 #include <dev/ic/ac97reg.h>
45 #include <dev/ic/ac97var.h>
46 
47 #include <dev/pci/pcidevs.h>
48 #include <dev/pci/pcireg.h>
49 #include <dev/pci/pcivar.h>
50 
51 #define EMU_PTESIZE		(4096)
52 #define EMU_MINPTE		(3)
53 /*
54  * Hardware limit of PTE is 4096 entry but it's too big for single voice.
55  * Reasonable candidate is:
56  *  48kHz * 2ch * 2byte * 1sec * 3buf/EMU_PTESIZE = 141
57  * and then round it up to 2^n.
58  */
59 #define EMU_MAXPTE		(256)
60 #define EMU_NUMCHAN		(64)
61 
62 /*
63  * Internal recording DMA buffer
64  */
65 /* Recommend the same size as EMU_PTESIZE to be symmetrical for play/rec */
66 #define EMU_REC_DMABLKSIZE	(4096)
67 /* must be EMU_REC_DMABLKSIZE * 2 */
68 #define EMU_REC_DMASIZE		(8192)
69 /* must be EMU_RECBS_BUFSIZE_(EMU_REC_DMASIZE) */
70 #define EMU_REC_BUFSIZE_RECBS	EMU_RECBS_BUFSIZE_8192
71 
72 /*
73  * DMA memory management
74  */
75 
76 #define EMU_DMA_ALIGN		(4096)
77 #define EMU_DMA_NSEGS		(1)
78 
79 struct dmamem {
80 	bus_dma_tag_t		dmat;
81 	bus_size_t		size;
82 	bus_size_t		align;
83 	bus_size_t		bound;
84 	bus_dma_segment_t	*segs;
85 	int			nsegs;
86 	int			rsegs;
87 	void *			kaddr;
88 	bus_dmamap_t		map;
89 };
90 
91 #define KERNADDR(ptr)		((void *)((ptr)->kaddr))
92 /*
93  * (ptr)->segs[] is CPU's PA translated by CPU's MMU.
94  * (ptr)->map->dm_segs[] is PCI device's PA translated by PCI's MMU.
95  */
96 #define DMASEGADDR(ptr, segno)	((ptr)->map->dm_segs[segno].ds_addr)
97 #define DMAADDR(ptr)		DMASEGADDR(ptr, 0)
98 #define DMASIZE(ptr)		((ptr)->size)
99 
100 struct emuxki_softc {
101 	device_t		sc_dev;
102 	device_t		sc_audev;
103 	enum {
104 		EMUXKI_SBLIVE = 0x00,
105 		EMUXKI_AUDIGY = 0x01,
106 		EMUXKI_AUDIGY2 = 0x02,
107 		EMUXKI_AUDIGY2_CA0108 = 0x04,
108 		EMUXKI_LIVE_5_1 = 0x08,
109 		EMUXKI_APS = 0x10
110 	} sc_type;
111 	audio_device_t		sc_audv;	/* for GETDEV */
112 
113 	/* Autoconfig parameters */
114 	bus_space_tag_t		sc_iot;
115 	bus_space_handle_t	sc_ioh;
116 	bus_addr_t		sc_iob;
117 	bus_size_t		sc_ios;
118 	pci_chipset_tag_t	sc_pc;		/* PCI tag */
119 	bus_dma_tag_t		sc_dmat;
120 	void			*sc_ih;		/* interrupt handler */
121 	kmutex_t		sc_intr_lock;
122 	kmutex_t		sc_lock;
123 	kmutex_t		sc_index_lock;
124 
125 	/* register parameters */
126 	struct dmamem		*ptb;		/* page table */
127 
128 	struct dmamem		*pmem;		/* play memory */
129 	void			(*pintr)(void *);
130 	void			*pintrarg;
131 	audio_params_t		play;
132 	uint32_t		pframesize;
133 	uint32_t		pblksize;
134 	uint32_t		plength;
135 	uint32_t		poffset;
136 
137 	struct dmamem		*rmem;		/* rec internal memory */
138 	void			(*rintr)(void *);
139 	void			*rintrarg;
140 	audio_params_t		rec;
141 	void			*rptr;		/* rec MI ptr */
142 	int			rcurrent;	/* rec software trans count */
143 	int			rframesize;
144 	int			rblksize;
145 	int			rlength;
146 	int			roffset;
147 
148 	/* others */
149 
150 	struct ac97_host_if	hostif;
151 	struct ac97_codec_if	*codecif;
152 };
153 
154 #endif /* _DEV_PCI_EMUXKIVAR_H_ */
155