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