emuxkivar.h revision 1.15 1 /* $NetBSD: emuxkivar.h,v 1.15 2022/09/07 01:00:37 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/device.h>
36 #include <sys/audioio.h>
37 #include <sys/mutex.h>
38
39 #include <sys/bus.h>
40
41 #include <dev/audio/audio_if.h>
42
43 #include <dev/ic/ac97reg.h>
44 #include <dev/ic/ac97var.h>
45
46 #include <dev/pci/pcidevs.h>
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49
50 #define EMU_PTESIZE (4096)
51 #define EMU_MINPTE (3)
52 /*
53 * Hardware limit of PTE is 4096 entry but it's too big for single voice.
54 * Reasonable candidate is:
55 * 48kHz * 2ch * 2byte * 1sec * 3buf/EMU_PTESIZE = 141
56 * and then round it up to 2^n.
57 */
58 #define EMU_MAXPTE (256)
59 #define EMU_NUMCHAN (64)
60
61 /*
62 * Internal recording DMA buffer
63 */
64 /* Recommend the same size as EMU_PTESIZE to be symmetrical for play/rec */
65 #define EMU_REC_DMABLKSIZE (4096)
66 /* must be EMU_REC_DMABLKSIZE * 2 */
67 #define EMU_REC_DMASIZE (8192)
68 /* must be EMU_RECBS_BUFSIZE_(EMU_REC_DMASIZE) */
69 #define EMU_REC_BUFSIZE_RECBS EMU_RECBS_BUFSIZE_8192
70
71 /*
72 * DMA memory management
73 */
74
75 #define EMU_DMA_ALIGN (4096)
76 #define EMU_DMA_NSEGS (1)
77
78 struct dmamem {
79 bus_dma_tag_t dmat;
80 bus_size_t size;
81 bus_size_t align;
82 bus_size_t bound;
83 bus_dma_segment_t *segs;
84 int nsegs;
85 int rsegs;
86 void * kaddr;
87 bus_dmamap_t map;
88 };
89
90 #define KERNADDR(ptr) ((void *)((ptr)->kaddr))
91 /*
92 * (ptr)->segs[] is CPU's PA translated by CPU's MMU.
93 * (ptr)->map->dm_segs[] is PCI device's PA translated by PCI's MMU.
94 */
95 #define DMASEGADDR(ptr, segno) ((ptr)->map->dm_segs[segno].ds_addr)
96 #define DMAADDR(ptr) DMASEGADDR(ptr, 0)
97 #define DMASIZE(ptr) ((ptr)->size)
98
99 struct emuxki_softc {
100 device_t sc_dev;
101 device_t sc_audev;
102 enum {
103 EMUXKI_SBLIVE = 0x00,
104 EMUXKI_AUDIGY = 0x01,
105 EMUXKI_AUDIGY2 = 0x02,
106 EMUXKI_AUDIGY2_VALUE = 0x04,
107 EMUXKI_LIVE_5_1 = 0x08,
108 EMUXKI_APS = 0x10
109 } sc_type;
110 audio_device_t sc_audv; /* for GETDEV */
111
112 /* Autoconfig parameters */
113 bus_space_tag_t sc_iot;
114 bus_space_handle_t sc_ioh;
115 bus_addr_t sc_iob;
116 bus_size_t sc_ios;
117 pci_chipset_tag_t sc_pc; /* PCI tag */
118 bus_dma_tag_t sc_dmat;
119 void *sc_ih; /* interrupt handler */
120 kmutex_t sc_intr_lock;
121 kmutex_t sc_lock;
122 kmutex_t sc_index_lock;
123
124 /* register parameters */
125 struct dmamem *ptb; /* page table */
126
127 struct dmamem *pmem; /* play memory */
128 void (*pintr)(void *);
129 void *pintrarg;
130 audio_params_t play;
131 uint32_t pframesize;
132 uint32_t pblksize;
133 uint32_t plength;
134 uint32_t poffset;
135
136 struct dmamem *rmem; /* rec internal memory */
137 void (*rintr)(void *);
138 void *rintrarg;
139 audio_params_t rec;
140 void *rptr; /* rec MI ptr */
141 int rcurrent; /* rec software trans count */
142 int rframesize;
143 int rblksize;
144 int rlength;
145 int roffset;
146
147 /* others */
148
149 struct ac97_host_if hostif;
150 struct ac97_codec_if *codecif;
151 };
152
153 #endif /* _DEV_PCI_EMUXKIVAR_H_ */
154