2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2006 Stephane E. Potvin <sepotvin@videotron.ca>
5 * Copyright (c) 2006 Ariff Abdullah <ariff@FreeBSD.org>
6 * Copyright (c) 2008-2012 Alexander Motin <mav@FreeBSD.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Intel High Definition Audio (Controller) driver for FreeBSD.
35 #ifdef HAVE_KERNEL_OPTION_HEADERS
39 #include <dev/sound/pcm/sound.h>
40 #include <dev/pci/pcireg.h>
41 #include <dev/pci/pcivar.h>
43 #include <sys/ctype.h>
44 #include <sys/endian.h>
45 #include <sys/taskqueue.h>
47 #include <dev/sound/pci/hda/hdac_private.h>
48 #include <dev/sound/pci/hda/hdac_reg.h>
49 #include <dev/sound/pci/hda/hda_reg.h>
50 #include <dev/sound/pci/hda/hdac.h>
52 #define HDA_DRV_TEST_REV "20120126_0002"
54 SND_DECLARE_FILE("$FreeBSD$");
56 #define hdac_lock(sc) snd_mtxlock((sc)->lock)
57 #define hdac_unlock(sc) snd_mtxunlock((sc)->lock)
58 #define hdac_lockassert(sc) snd_mtxassert((sc)->lock)
60 #define HDAC_QUIRK_64BIT (1 << 0)
61 #define HDAC_QUIRK_DMAPOS (1 << 1)
62 #define HDAC_QUIRK_MSI (1 << 2)
67 } hdac_quirks_tab[] = {
68 { "64bit", HDAC_QUIRK_DMAPOS },
69 { "dmapos", HDAC_QUIRK_DMAPOS },
70 { "msi", HDAC_QUIRK_MSI },
73 MALLOC_DEFINE(M_HDAC, "hdac", "HDA Controller");
81 { HDA_INTEL_OAK, "Intel Oaktrail", 0, 0 },
82 { HDA_INTEL_BAY, "Intel BayTrail", 0, 0 },
83 { HDA_INTEL_HSW1, "Intel Haswell", 0, 0 },
84 { HDA_INTEL_HSW2, "Intel Haswell", 0, 0 },
85 { HDA_INTEL_HSW3, "Intel Haswell", 0, 0 },
86 { HDA_INTEL_BDW1, "Intel Broadwell", 0, 0 },
87 { HDA_INTEL_BDW2, "Intel Broadwell", 0, 0 },
88 { HDA_INTEL_CPT, "Intel Cougar Point", 0, 0 },
89 { HDA_INTEL_PATSBURG,"Intel Patsburg", 0, 0 },
90 { HDA_INTEL_PPT1, "Intel Panther Point", 0, 0 },
91 { HDA_INTEL_LPT1, "Intel Lynx Point", 0, 0 },
92 { HDA_INTEL_LPT2, "Intel Lynx Point", 0, 0 },
93 { HDA_INTEL_WCPT, "Intel Wildcat Point", 0, 0 },
94 { HDA_INTEL_WELLS1, "Intel Wellsburg", 0, 0 },
95 { HDA_INTEL_WELLS2, "Intel Wellsburg", 0, 0 },
96 { HDA_INTEL_LPTLP1, "Intel Lynx Point-LP", 0, 0 },
97 { HDA_INTEL_LPTLP2, "Intel Lynx Point-LP", 0, 0 },
98 { HDA_INTEL_SRPTLP, "Intel Sunrise Point-LP", 0, 0 },
99 { HDA_INTEL_KBLKLP, "Intel Kaby Lake-LP", 0, 0 },
100 { HDA_INTEL_SRPT, "Intel Sunrise Point", 0, 0 },
101 { HDA_INTEL_KBLK, "Intel Kaby Lake", 0, 0 },
102 { HDA_INTEL_KBLKH, "Intel Kaby Lake-H", 0, 0 },
103 { HDA_INTEL_CFLK, "Intel Coffee Lake", 0, 0 },
104 { HDA_INTEL_CNLK, "Intel Cannon Lake", 0, 0 },
105 { HDA_INTEL_ICLK, "Intel Ice Lake", 0, 0 },
106 { HDA_INTEL_CMLKLP, "Intel Comet Lake-LP", 0, 0 },
107 { HDA_INTEL_CMLKH, "Intel Comet Lake-H", 0, 0 },
108 { HDA_INTEL_TGLK, "Intel Tiger Lake", 0, 0 },
109 { HDA_INTEL_GMLK, "Intel Gemini Lake", 0, 0 },
110 { HDA_INTEL_82801F, "Intel 82801F", 0, 0 },
111 { HDA_INTEL_63XXESB, "Intel 631x/632xESB", 0, 0 },
112 { HDA_INTEL_82801G, "Intel 82801G", 0, 0 },
113 { HDA_INTEL_82801H, "Intel 82801H", 0, 0 },
114 { HDA_INTEL_82801I, "Intel 82801I", 0, 0 },
115 { HDA_INTEL_82801JI, "Intel 82801JI", 0, 0 },
116 { HDA_INTEL_82801JD, "Intel 82801JD", 0, 0 },
117 { HDA_INTEL_PCH, "Intel Ibex Peak", 0, 0 },
118 { HDA_INTEL_PCH2, "Intel Ibex Peak", 0, 0 },
119 { HDA_INTEL_SCH, "Intel SCH", 0, 0 },
120 { HDA_NVIDIA_MCP51, "NVIDIA MCP51", 0, HDAC_QUIRK_MSI },
121 { HDA_NVIDIA_MCP55, "NVIDIA MCP55", 0, HDAC_QUIRK_MSI },
122 { HDA_NVIDIA_MCP61_1, "NVIDIA MCP61", 0, 0 },
123 { HDA_NVIDIA_MCP61_2, "NVIDIA MCP61", 0, 0 },
124 { HDA_NVIDIA_MCP65_1, "NVIDIA MCP65", 0, 0 },
125 { HDA_NVIDIA_MCP65_2, "NVIDIA MCP65", 0, 0 },
126 { HDA_NVIDIA_MCP67_1, "NVIDIA MCP67", 0, 0 },
127 { HDA_NVIDIA_MCP67_2, "NVIDIA MCP67", 0, 0 },
128 { HDA_NVIDIA_MCP73_1, "NVIDIA MCP73", 0, 0 },
129 { HDA_NVIDIA_MCP73_2, "NVIDIA MCP73", 0, 0 },
130 { HDA_NVIDIA_MCP78_1, "NVIDIA MCP78", 0, HDAC_QUIRK_64BIT },
131 { HDA_NVIDIA_MCP78_2, "NVIDIA MCP78", 0, HDAC_QUIRK_64BIT },
132 { HDA_NVIDIA_MCP78_3, "NVIDIA MCP78", 0, HDAC_QUIRK_64BIT },
133 { HDA_NVIDIA_MCP78_4, "NVIDIA MCP78", 0, HDAC_QUIRK_64BIT },
134 { HDA_NVIDIA_MCP79_1, "NVIDIA MCP79", 0, 0 },
135 { HDA_NVIDIA_MCP79_2, "NVIDIA MCP79", 0, 0 },
136 { HDA_NVIDIA_MCP79_3, "NVIDIA MCP79", 0, 0 },
137 { HDA_NVIDIA_MCP79_4, "NVIDIA MCP79", 0, 0 },
138 { HDA_NVIDIA_MCP89_1, "NVIDIA MCP89", 0, 0 },
139 { HDA_NVIDIA_MCP89_2, "NVIDIA MCP89", 0, 0 },
140 { HDA_NVIDIA_MCP89_3, "NVIDIA MCP89", 0, 0 },
141 { HDA_NVIDIA_MCP89_4, "NVIDIA MCP89", 0, 0 },
142 { HDA_NVIDIA_0BE2, "NVIDIA (0x0be2)", 0, HDAC_QUIRK_MSI },
143 { HDA_NVIDIA_0BE3, "NVIDIA (0x0be3)", 0, HDAC_QUIRK_MSI },
144 { HDA_NVIDIA_0BE4, "NVIDIA (0x0be4)", 0, HDAC_QUIRK_MSI },
145 { HDA_NVIDIA_GT100, "NVIDIA GT100", 0, HDAC_QUIRK_MSI },
146 { HDA_NVIDIA_GT104, "NVIDIA GT104", 0, HDAC_QUIRK_MSI },
147 { HDA_NVIDIA_GT106, "NVIDIA GT106", 0, HDAC_QUIRK_MSI },
148 { HDA_NVIDIA_GT108, "NVIDIA GT108", 0, HDAC_QUIRK_MSI },
149 { HDA_NVIDIA_GT116, "NVIDIA GT116", 0, HDAC_QUIRK_MSI },
150 { HDA_NVIDIA_GF119, "NVIDIA GF119", 0, 0 },
151 { HDA_NVIDIA_GF110_1, "NVIDIA GF110", 0, HDAC_QUIRK_MSI },
152 { HDA_NVIDIA_GF110_2, "NVIDIA GF110", 0, HDAC_QUIRK_MSI },
153 { HDA_ATI_SB450, "ATI SB450", 0, 0 },
154 { HDA_ATI_SB600, "ATI SB600", 0, 0 },
155 { HDA_ATI_RS600, "ATI RS600", 0, 0 },
156 { HDA_ATI_RS690, "ATI RS690", 0, 0 },
157 { HDA_ATI_RS780, "ATI RS780", 0, 0 },
158 { HDA_ATI_R600, "ATI R600", 0, 0 },
159 { HDA_ATI_RV610, "ATI RV610", 0, 0 },
160 { HDA_ATI_RV620, "ATI RV620", 0, 0 },
161 { HDA_ATI_RV630, "ATI RV630", 0, 0 },
162 { HDA_ATI_RV635, "ATI RV635", 0, 0 },
163 { HDA_ATI_RV710, "ATI RV710", 0, 0 },
164 { HDA_ATI_RV730, "ATI RV730", 0, 0 },
165 { HDA_ATI_RV740, "ATI RV740", 0, 0 },
166 { HDA_ATI_RV770, "ATI RV770", 0, 0 },
167 { HDA_ATI_RV810, "ATI RV810", 0, 0 },
168 { HDA_ATI_RV830, "ATI RV830", 0, 0 },
169 { HDA_ATI_RV840, "ATI RV840", 0, 0 },
170 { HDA_ATI_RV870, "ATI RV870", 0, 0 },
171 { HDA_ATI_RV910, "ATI RV910", 0, 0 },
172 { HDA_ATI_RV930, "ATI RV930", 0, 0 },
173 { HDA_ATI_RV940, "ATI RV940", 0, 0 },
174 { HDA_ATI_RV970, "ATI RV970", 0, 0 },
175 { HDA_ATI_R1000, "ATI R1000", 0, 0 },
176 { HDA_AMD_HUDSON2, "AMD Hudson-2", 0, 0 },
177 { HDA_RDC_M3010, "RDC M3010", 0, 0 },
178 { HDA_VIA_VT82XX, "VIA VT8251/8237A",0, 0 },
179 { HDA_SIS_966, "SiS 966/968", 0, 0 },
180 { HDA_ULI_M5461, "ULI M5461", 0, 0 },
182 { HDA_INTEL_ALL, "Intel", 0, 0 },
183 { HDA_NVIDIA_ALL, "NVIDIA", 0, 0 },
184 { HDA_ATI_ALL, "ATI", 0, 0 },
185 { HDA_AMD_ALL, "AMD", 0, 0 },
186 { HDA_CREATIVE_ALL, "Creative", 0, 0 },
187 { HDA_VIA_ALL, "VIA", 0, 0 },
188 { HDA_SIS_ALL, "SiS", 0, 0 },
189 { HDA_ULI_ALL, "ULI", 0, 0 },
192 static const struct {
197 } hdac_pcie_snoop[] = {
198 { INTEL_VENDORID, 0x00, 0x00, 0x00 },
199 { ATI_VENDORID, 0x42, 0xf8, 0x02 },
200 { NVIDIA_VENDORID, 0x4e, 0xf0, 0x0f },
203 /****************************************************************************
204 * Function prototypes
205 ****************************************************************************/
206 static void hdac_intr_handler(void *);
207 static int hdac_reset(struct hdac_softc *, int);
208 static int hdac_get_capabilities(struct hdac_softc *);
209 static void hdac_dma_cb(void *, bus_dma_segment_t *, int, int);
210 static int hdac_dma_alloc(struct hdac_softc *,
211 struct hdac_dma *, bus_size_t);
212 static void hdac_dma_free(struct hdac_softc *, struct hdac_dma *);
213 static int hdac_mem_alloc(struct hdac_softc *);
214 static void hdac_mem_free(struct hdac_softc *);
215 static int hdac_irq_alloc(struct hdac_softc *);
216 static void hdac_irq_free(struct hdac_softc *);
217 static void hdac_corb_init(struct hdac_softc *);
218 static void hdac_rirb_init(struct hdac_softc *);
219 static void hdac_corb_start(struct hdac_softc *);
220 static void hdac_rirb_start(struct hdac_softc *);
222 static void hdac_attach2(void *);
224 static uint32_t hdac_send_command(struct hdac_softc *, nid_t, uint32_t);
226 static int hdac_probe(device_t);
227 static int hdac_attach(device_t);
228 static int hdac_detach(device_t);
229 static int hdac_suspend(device_t);
230 static int hdac_resume(device_t);
232 static int hdac_rirb_flush(struct hdac_softc *sc);
233 static int hdac_unsolq_flush(struct hdac_softc *sc);
235 /* This function surely going to make its way into upper level someday. */
237 hdac_config_fetch(struct hdac_softc *sc, uint32_t *on, uint32_t *off)
239 const char *res = NULL;
240 int i = 0, j, k, len, inv;
242 if (resource_string_value(device_get_name(sc->dev),
243 device_get_unit(sc->dev), "config", &res) != 0)
245 if (!(res != NULL && strlen(res) > 0))
248 device_printf(sc->dev, "Config options:");
251 while (res[i] != '\0' &&
252 (res[i] == ',' || isspace(res[i]) != 0))
254 if (res[i] == '\0') {
261 while (res[j] != '\0' &&
262 !(res[j] == ',' || isspace(res[j]) != 0))
265 if (len > 2 && strncmp(res + i, "no", 2) == 0)
269 for (k = 0; len > inv && k < nitems(hdac_quirks_tab); k++) {
270 if (strncmp(res + i + inv,
271 hdac_quirks_tab[k].key, len - inv) != 0)
273 if (len - inv != strlen(hdac_quirks_tab[k].key))
276 printf(" %s%s", (inv != 0) ? "no" : "",
277 hdac_quirks_tab[k].key);
280 *on |= hdac_quirks_tab[k].value;
281 *on &= ~hdac_quirks_tab[k].value;
282 } else if (inv != 0) {
283 *off |= hdac_quirks_tab[k].value;
284 *off &= ~hdac_quirks_tab[k].value;
292 /****************************************************************************
293 * void hdac_intr_handler(void *)
295 * Interrupt handler. Processes interrupts received from the hdac.
296 ****************************************************************************/
298 hdac_intr_handler(void *context)
300 struct hdac_softc *sc;
306 sc = (struct hdac_softc *)context;
309 /* Do we have anything to do? */
310 intsts = HDAC_READ_4(&sc->mem, HDAC_INTSTS);
311 if ((intsts & HDAC_INTSTS_GIS) == 0) {
316 /* Was this a controller interrupt? */
317 if (intsts & HDAC_INTSTS_CIS) {
318 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
319 /* Get as many responses that we can */
320 while (rirbsts & HDAC_RIRBSTS_RINTFL) {
321 HDAC_WRITE_1(&sc->mem,
322 HDAC_RIRBSTS, HDAC_RIRBSTS_RINTFL);
324 rirbsts = HDAC_READ_1(&sc->mem, HDAC_RIRBSTS);
326 if (sc->unsolq_rp != sc->unsolq_wp)
327 taskqueue_enqueue(taskqueue_thread, &sc->unsolq_task);
330 if (intsts & HDAC_INTSTS_SIS_MASK) {
331 for (i = 0; i < sc->num_ss; i++) {
332 if ((intsts & (1 << i)) == 0)
334 HDAC_WRITE_1(&sc->mem, (i << 5) + HDAC_SDSTS,
335 HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS );
336 if ((dev = sc->streams[i].dev) != NULL) {
337 HDAC_STREAM_INTR(dev,
338 sc->streams[i].dir, sc->streams[i].stream);
343 HDAC_WRITE_4(&sc->mem, HDAC_INTSTS, intsts);
348 hdac_poll_callback(void *arg)
350 struct hdac_softc *sc = arg;
356 if (sc->polling == 0) {
360 callout_reset(&sc->poll_callout, sc->poll_ival, hdac_poll_callback, sc);
363 hdac_intr_handler(sc);
366 /****************************************************************************
367 * int hdac_reset(hdac_softc *, int)
369 * Reset the hdac to a quiescent and known state.
370 ****************************************************************************/
372 hdac_reset(struct hdac_softc *sc, int wakeup)
378 * Stop all Streams DMA engine
380 for (i = 0; i < sc->num_iss; i++)
381 HDAC_WRITE_4(&sc->mem, HDAC_ISDCTL(sc, i), 0x0);
382 for (i = 0; i < sc->num_oss; i++)
383 HDAC_WRITE_4(&sc->mem, HDAC_OSDCTL(sc, i), 0x0);
384 for (i = 0; i < sc->num_bss; i++)
385 HDAC_WRITE_4(&sc->mem, HDAC_BSDCTL(sc, i), 0x0);
388 * Stop Control DMA engines.
390 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, 0x0);
391 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, 0x0);
394 * Reset DMA position buffer.
396 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE, 0x0);
397 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, 0x0);
400 * Reset the controller. The reset must remain asserted for
401 * a minimum of 100us.
403 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
404 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl & ~HDAC_GCTL_CRST);
407 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
408 if (!(gctl & HDAC_GCTL_CRST))
412 if (gctl & HDAC_GCTL_CRST) {
413 device_printf(sc->dev, "Unable to put hdac in reset\n");
417 /* If wakeup is not requested - leave the controller in reset state. */
422 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
423 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, gctl | HDAC_GCTL_CRST);
426 gctl = HDAC_READ_4(&sc->mem, HDAC_GCTL);
427 if (gctl & HDAC_GCTL_CRST)
431 if (!(gctl & HDAC_GCTL_CRST)) {
432 device_printf(sc->dev, "Device stuck in reset\n");
437 * Wait for codecs to finish their own reset sequence. The delay here
438 * must be at least 521us (HDA 1.0a section 4.3 Codec Discovery).
445 /****************************************************************************
446 * int hdac_get_capabilities(struct hdac_softc *);
448 * Retreive the general capabilities of the hdac;
449 * Number of Input Streams
450 * Number of Output Streams
451 * Number of bidirectional Streams
453 * CORB and RIRB sizes
454 ****************************************************************************/
456 hdac_get_capabilities(struct hdac_softc *sc)
459 uint8_t corbsize, rirbsize;
461 gcap = HDAC_READ_2(&sc->mem, HDAC_GCAP);
462 sc->num_iss = HDAC_GCAP_ISS(gcap);
463 sc->num_oss = HDAC_GCAP_OSS(gcap);
464 sc->num_bss = HDAC_GCAP_BSS(gcap);
465 sc->num_ss = sc->num_iss + sc->num_oss + sc->num_bss;
466 sc->num_sdo = HDAC_GCAP_NSDO(gcap);
467 sc->support_64bit = (gcap & HDAC_GCAP_64OK) != 0;
468 if (sc->quirks_on & HDAC_QUIRK_64BIT)
469 sc->support_64bit = 1;
470 else if (sc->quirks_off & HDAC_QUIRK_64BIT)
471 sc->support_64bit = 0;
473 corbsize = HDAC_READ_1(&sc->mem, HDAC_CORBSIZE);
474 if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_256) ==
475 HDAC_CORBSIZE_CORBSZCAP_256)
477 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_16) ==
478 HDAC_CORBSIZE_CORBSZCAP_16)
480 else if ((corbsize & HDAC_CORBSIZE_CORBSZCAP_2) ==
481 HDAC_CORBSIZE_CORBSZCAP_2)
484 device_printf(sc->dev, "%s: Invalid corb size (%x)\n",
489 rirbsize = HDAC_READ_1(&sc->mem, HDAC_RIRBSIZE);
490 if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_256) ==
491 HDAC_RIRBSIZE_RIRBSZCAP_256)
493 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_16) ==
494 HDAC_RIRBSIZE_RIRBSZCAP_16)
496 else if ((rirbsize & HDAC_RIRBSIZE_RIRBSZCAP_2) ==
497 HDAC_RIRBSIZE_RIRBSZCAP_2)
500 device_printf(sc->dev, "%s: Invalid rirb size (%x)\n",
506 device_printf(sc->dev, "Caps: OSS %d, ISS %d, BSS %d, "
507 "NSDO %d%s, CORB %d, RIRB %d\n",
508 sc->num_oss, sc->num_iss, sc->num_bss, 1 << sc->num_sdo,
509 sc->support_64bit ? ", 64bit" : "",
510 sc->corb_size, sc->rirb_size);
517 /****************************************************************************
520 * This function is called by bus_dmamap_load when the mapping has been
521 * established. We just record the physical address of the mapping into
522 * the struct hdac_dma passed in.
523 ****************************************************************************/
525 hdac_dma_cb(void *callback_arg, bus_dma_segment_t *segs, int nseg, int error)
527 struct hdac_dma *dma;
530 dma = (struct hdac_dma *)callback_arg;
531 dma->dma_paddr = segs[0].ds_addr;
536 /****************************************************************************
539 * This function allocate and setup a dma region (struct hdac_dma).
540 * It must be freed by a corresponding hdac_dma_free.
541 ****************************************************************************/
543 hdac_dma_alloc(struct hdac_softc *sc, struct hdac_dma *dma, bus_size_t size)
548 roundsz = roundup2(size, HDA_DMA_ALIGNMENT);
549 bzero(dma, sizeof(*dma));
554 result = bus_dma_tag_create(
555 bus_get_dma_tag(sc->dev), /* parent */
556 HDA_DMA_ALIGNMENT, /* alignment */
558 (sc->support_64bit) ? BUS_SPACE_MAXADDR :
559 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
560 BUS_SPACE_MAXADDR, /* highaddr */
562 NULL, /* fistfuncarg */
563 roundsz, /* maxsize */
565 roundsz, /* maxsegsz */
568 NULL, /* lockfuncarg */
569 &dma->dma_tag); /* dmat */
571 device_printf(sc->dev, "%s: bus_dma_tag_create failed (%d)\n",
573 goto hdac_dma_alloc_fail;
577 * Allocate DMA memory
579 result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr,
580 BUS_DMA_NOWAIT | BUS_DMA_ZERO |
581 ((sc->flags & HDAC_F_DMA_NOCACHE) ? BUS_DMA_NOCACHE :
585 device_printf(sc->dev, "%s: bus_dmamem_alloc failed (%d)\n",
587 goto hdac_dma_alloc_fail;
590 dma->dma_size = roundsz;
595 result = bus_dmamap_load(dma->dma_tag, dma->dma_map,
596 (void *)dma->dma_vaddr, roundsz, hdac_dma_cb, (void *)dma, 0);
597 if (result != 0 || dma->dma_paddr == 0) {
600 device_printf(sc->dev, "%s: bus_dmamem_load failed (%d)\n",
602 goto hdac_dma_alloc_fail;
606 device_printf(sc->dev, "%s: size=%ju -> roundsz=%ju\n",
607 __func__, (uintmax_t)size, (uintmax_t)roundsz);
613 hdac_dma_free(sc, dma);
618 /****************************************************************************
619 * void hdac_dma_free(struct hdac_softc *, struct hdac_dma *)
621 * Free a struct hdac_dma that has been previously allocated via the
622 * hdac_dma_alloc function.
623 ****************************************************************************/
625 hdac_dma_free(struct hdac_softc *sc, struct hdac_dma *dma)
627 if (dma->dma_paddr != 0) {
629 bus_dmamap_sync(dma->dma_tag, dma->dma_map,
630 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
631 bus_dmamap_unload(dma->dma_tag, dma->dma_map);
634 if (dma->dma_vaddr != NULL) {
635 bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
636 dma->dma_vaddr = NULL;
638 if (dma->dma_tag != NULL) {
639 bus_dma_tag_destroy(dma->dma_tag);
645 /****************************************************************************
646 * int hdac_mem_alloc(struct hdac_softc *)
648 * Allocate all the bus resources necessary to speak with the physical
650 ****************************************************************************/
652 hdac_mem_alloc(struct hdac_softc *sc)
654 struct hdac_mem *mem;
657 mem->mem_rid = PCIR_BAR(0);
658 mem->mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
659 &mem->mem_rid, RF_ACTIVE);
660 if (mem->mem_res == NULL) {
661 device_printf(sc->dev,
662 "%s: Unable to allocate memory resource\n", __func__);
665 mem->mem_tag = rman_get_bustag(mem->mem_res);
666 mem->mem_handle = rman_get_bushandle(mem->mem_res);
671 /****************************************************************************
672 * void hdac_mem_free(struct hdac_softc *)
674 * Free up resources previously allocated by hdac_mem_alloc.
675 ****************************************************************************/
677 hdac_mem_free(struct hdac_softc *sc)
679 struct hdac_mem *mem;
682 if (mem->mem_res != NULL)
683 bus_release_resource(sc->dev, SYS_RES_MEMORY, mem->mem_rid,
688 /****************************************************************************
689 * int hdac_irq_alloc(struct hdac_softc *)
691 * Allocate and setup the resources necessary for interrupt handling.
692 ****************************************************************************/
694 hdac_irq_alloc(struct hdac_softc *sc)
696 struct hdac_irq *irq;
702 if ((sc->quirks_off & HDAC_QUIRK_MSI) == 0 &&
703 (result = pci_msi_count(sc->dev)) == 1 &&
704 pci_alloc_msi(sc->dev, &result) == 0)
707 irq->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
708 &irq->irq_rid, RF_SHAREABLE | RF_ACTIVE);
709 if (irq->irq_res == NULL) {
710 device_printf(sc->dev, "%s: Unable to allocate irq\n",
712 goto hdac_irq_alloc_fail;
714 result = bus_setup_intr(sc->dev, irq->irq_res, INTR_MPSAFE | INTR_TYPE_AV,
715 NULL, hdac_intr_handler, sc, &irq->irq_handle);
717 device_printf(sc->dev,
718 "%s: Unable to setup interrupt handler (%d)\n",
720 goto hdac_irq_alloc_fail;
731 /****************************************************************************
732 * void hdac_irq_free(struct hdac_softc *)
734 * Free up resources previously allocated by hdac_irq_alloc.
735 ****************************************************************************/
737 hdac_irq_free(struct hdac_softc *sc)
739 struct hdac_irq *irq;
742 if (irq->irq_res != NULL && irq->irq_handle != NULL)
743 bus_teardown_intr(sc->dev, irq->irq_res, irq->irq_handle);
744 if (irq->irq_res != NULL)
745 bus_release_resource(sc->dev, SYS_RES_IRQ, irq->irq_rid,
747 if (irq->irq_rid == 0x1)
748 pci_release_msi(sc->dev);
749 irq->irq_handle = NULL;
754 /****************************************************************************
755 * void hdac_corb_init(struct hdac_softc *)
757 * Initialize the corb registers for operations but do not start it up yet.
758 * The CORB engine must not be running when this function is called.
759 ****************************************************************************/
761 hdac_corb_init(struct hdac_softc *sc)
766 /* Setup the CORB size. */
767 switch (sc->corb_size) {
769 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_256);
772 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_16);
775 corbsize = HDAC_CORBSIZE_CORBSIZE(HDAC_CORBSIZE_CORBSIZE_2);
778 panic("%s: Invalid CORB size (%x)\n", __func__, sc->corb_size);
780 HDAC_WRITE_1(&sc->mem, HDAC_CORBSIZE, corbsize);
782 /* Setup the CORB Address in the hdac */
783 corbpaddr = (uint64_t)sc->corb_dma.dma_paddr;
784 HDAC_WRITE_4(&sc->mem, HDAC_CORBLBASE, (uint32_t)corbpaddr);
785 HDAC_WRITE_4(&sc->mem, HDAC_CORBUBASE, (uint32_t)(corbpaddr >> 32));
787 /* Set the WP and RP */
789 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
790 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, HDAC_CORBRP_CORBRPRST);
792 * The HDA specification indicates that the CORBRPRST bit will always
793 * read as zero. Unfortunately, it seems that at least the 82801G
794 * doesn't reset the bit to zero, which stalls the corb engine.
795 * manually reset the bit to zero before continuing.
797 HDAC_WRITE_2(&sc->mem, HDAC_CORBRP, 0x0);
799 /* Enable CORB error reporting */
801 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, HDAC_CORBCTL_CMEIE);
805 /****************************************************************************
806 * void hdac_rirb_init(struct hdac_softc *)
808 * Initialize the rirb registers for operations but do not start it up yet.
809 * The RIRB engine must not be running when this function is called.
810 ****************************************************************************/
812 hdac_rirb_init(struct hdac_softc *sc)
817 /* Setup the RIRB size. */
818 switch (sc->rirb_size) {
820 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_256);
823 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_16);
826 rirbsize = HDAC_RIRBSIZE_RIRBSIZE(HDAC_RIRBSIZE_RIRBSIZE_2);
829 panic("%s: Invalid RIRB size (%x)\n", __func__, sc->rirb_size);
831 HDAC_WRITE_1(&sc->mem, HDAC_RIRBSIZE, rirbsize);
833 /* Setup the RIRB Address in the hdac */
834 rirbpaddr = (uint64_t)sc->rirb_dma.dma_paddr;
835 HDAC_WRITE_4(&sc->mem, HDAC_RIRBLBASE, (uint32_t)rirbpaddr);
836 HDAC_WRITE_4(&sc->mem, HDAC_RIRBUBASE, (uint32_t)(rirbpaddr >> 32));
838 /* Setup the WP and RP */
840 HDAC_WRITE_2(&sc->mem, HDAC_RIRBWP, HDAC_RIRBWP_RIRBWPRST);
842 /* Setup the interrupt threshold */
843 HDAC_WRITE_2(&sc->mem, HDAC_RINTCNT, sc->rirb_size / 2);
845 /* Enable Overrun and response received reporting */
847 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL,
848 HDAC_RIRBCTL_RIRBOIC | HDAC_RIRBCTL_RINTCTL);
850 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, HDAC_RIRBCTL_RINTCTL);
854 * Make sure that the Host CPU cache doesn't contain any dirty
855 * cache lines that falls in the rirb. If I understood correctly, it
856 * should be sufficient to do this only once as the rirb is purely
857 * read-only from now on.
859 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
860 BUS_DMASYNC_PREREAD);
863 /****************************************************************************
864 * void hdac_corb_start(hdac_softc *)
866 * Startup the corb DMA engine
867 ****************************************************************************/
869 hdac_corb_start(struct hdac_softc *sc)
873 corbctl = HDAC_READ_1(&sc->mem, HDAC_CORBCTL);
874 corbctl |= HDAC_CORBCTL_CORBRUN;
875 HDAC_WRITE_1(&sc->mem, HDAC_CORBCTL, corbctl);
878 /****************************************************************************
879 * void hdac_rirb_start(hdac_softc *)
881 * Startup the rirb DMA engine
882 ****************************************************************************/
884 hdac_rirb_start(struct hdac_softc *sc)
888 rirbctl = HDAC_READ_1(&sc->mem, HDAC_RIRBCTL);
889 rirbctl |= HDAC_RIRBCTL_RIRBDMAEN;
890 HDAC_WRITE_1(&sc->mem, HDAC_RIRBCTL, rirbctl);
894 hdac_rirb_flush(struct hdac_softc *sc)
896 struct hdac_rirb *rirb_base, *rirb;
898 uint32_t resp, resp_ex;
902 rirb_base = (struct hdac_rirb *)sc->rirb_dma.dma_vaddr;
903 rirbwp = HDAC_READ_1(&sc->mem, HDAC_RIRBWP);
904 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
905 BUS_DMASYNC_POSTREAD);
908 while (sc->rirb_rp != rirbwp) {
910 sc->rirb_rp %= sc->rirb_size;
911 rirb = &rirb_base[sc->rirb_rp];
912 resp = le32toh(rirb->response);
913 resp_ex = le32toh(rirb->response_ex);
914 cad = HDAC_RIRB_RESPONSE_EX_SDATA_IN(resp_ex);
915 if (resp_ex & HDAC_RIRB_RESPONSE_EX_UNSOLICITED) {
916 sc->unsolq[sc->unsolq_wp++] = resp;
917 sc->unsolq_wp %= HDAC_UNSOLQ_MAX;
918 sc->unsolq[sc->unsolq_wp++] = cad;
919 sc->unsolq_wp %= HDAC_UNSOLQ_MAX;
920 } else if (sc->codecs[cad].pending <= 0) {
921 device_printf(sc->dev, "Unexpected unsolicited "
922 "response from address %d: %08x\n", cad, resp);
924 sc->codecs[cad].response = resp;
925 sc->codecs[cad].pending--;
930 bus_dmamap_sync(sc->rirb_dma.dma_tag, sc->rirb_dma.dma_map,
931 BUS_DMASYNC_PREREAD);
936 hdac_unsolq_flush(struct hdac_softc *sc)
943 if (sc->unsolq_st == HDAC_UNSOLQ_READY) {
944 sc->unsolq_st = HDAC_UNSOLQ_BUSY;
945 while (sc->unsolq_rp != sc->unsolq_wp) {
946 resp = sc->unsolq[sc->unsolq_rp++];
947 sc->unsolq_rp %= HDAC_UNSOLQ_MAX;
948 cad = sc->unsolq[sc->unsolq_rp++];
949 sc->unsolq_rp %= HDAC_UNSOLQ_MAX;
950 if ((child = sc->codecs[cad].dev) != NULL)
951 HDAC_UNSOL_INTR(child, resp);
954 sc->unsolq_st = HDAC_UNSOLQ_READY;
960 /****************************************************************************
961 * uint32_t hdac_send_command
963 * Wrapper function that sends only one command to a given codec
964 ****************************************************************************/
966 hdac_send_command(struct hdac_softc *sc, nid_t cad, uint32_t verb)
972 verb &= ~HDA_CMD_CAD_MASK;
973 verb |= ((uint32_t)cad) << HDA_CMD_CAD_SHIFT;
974 sc->codecs[cad].response = HDA_INVALID;
976 sc->codecs[cad].pending++;
978 sc->corb_wp %= sc->corb_size;
979 corb = (uint32_t *)sc->corb_dma.dma_vaddr;
980 bus_dmamap_sync(sc->corb_dma.dma_tag,
981 sc->corb_dma.dma_map, BUS_DMASYNC_PREWRITE);
982 corb[sc->corb_wp] = htole32(verb);
983 bus_dmamap_sync(sc->corb_dma.dma_tag,
984 sc->corb_dma.dma_map, BUS_DMASYNC_POSTWRITE);
985 HDAC_WRITE_2(&sc->mem, HDAC_CORBWP, sc->corb_wp);
989 if (hdac_rirb_flush(sc) == 0)
991 } while (sc->codecs[cad].pending != 0 && --timeout);
993 if (sc->codecs[cad].pending != 0) {
994 device_printf(sc->dev, "Command 0x%08x timeout on address %d\n",
996 sc->codecs[cad].pending = 0;
999 if (sc->unsolq_rp != sc->unsolq_wp)
1000 taskqueue_enqueue(taskqueue_thread, &sc->unsolq_task);
1001 return (sc->codecs[cad].response);
1004 /****************************************************************************
1006 ****************************************************************************/
1008 /****************************************************************************
1009 * int hdac_probe(device_t)
1011 * Probe for the presence of an hdac. If none is found, check for a generic
1012 * match using the subclass of the device.
1013 ****************************************************************************/
1015 hdac_probe(device_t dev)
1019 uint16_t class, subclass;
1022 model = (uint32_t)pci_get_device(dev) << 16;
1023 model |= (uint32_t)pci_get_vendor(dev) & 0x0000ffff;
1024 class = pci_get_class(dev);
1025 subclass = pci_get_subclass(dev);
1027 bzero(desc, sizeof(desc));
1029 for (i = 0; i < nitems(hdac_devices); i++) {
1030 if (hdac_devices[i].model == model) {
1031 strlcpy(desc, hdac_devices[i].desc, sizeof(desc));
1032 result = BUS_PROBE_DEFAULT;
1035 if (HDA_DEV_MATCH(hdac_devices[i].model, model) &&
1036 class == PCIC_MULTIMEDIA &&
1037 subclass == PCIS_MULTIMEDIA_HDA) {
1038 snprintf(desc, sizeof(desc), "%s (0x%04x)",
1039 hdac_devices[i].desc, pci_get_device(dev));
1040 result = BUS_PROBE_GENERIC;
1044 if (result == ENXIO && class == PCIC_MULTIMEDIA &&
1045 subclass == PCIS_MULTIMEDIA_HDA) {
1046 snprintf(desc, sizeof(desc), "Generic (0x%08x)", model);
1047 result = BUS_PROBE_GENERIC;
1049 if (result != ENXIO) {
1050 strlcat(desc, " HDA Controller", sizeof(desc));
1051 device_set_desc_copy(dev, desc);
1058 hdac_unsolq_task(void *context, int pending)
1060 struct hdac_softc *sc;
1062 sc = (struct hdac_softc *)context;
1065 hdac_unsolq_flush(sc);
1069 /****************************************************************************
1070 * int hdac_attach(device_t)
1072 * Attach the device into the kernel. Interrupts usually won't be enabled
1073 * when this function is called. Setup everything that doesn't require
1074 * interrupts and defer probing of codecs until interrupts are enabled.
1075 ****************************************************************************/
1077 hdac_attach(device_t dev)
1079 struct hdac_softc *sc;
1083 uint16_t class, subclass;
1087 sc = device_get_softc(dev);
1089 device_printf(dev, "PCI card vendor: 0x%04x, device: 0x%04x\n",
1090 pci_get_subvendor(dev), pci_get_subdevice(dev));
1091 device_printf(dev, "HDA Driver Revision: %s\n",
1095 model = (uint32_t)pci_get_device(dev) << 16;
1096 model |= (uint32_t)pci_get_vendor(dev) & 0x0000ffff;
1097 class = pci_get_class(dev);
1098 subclass = pci_get_subclass(dev);
1100 for (i = 0; i < nitems(hdac_devices); i++) {
1101 if (hdac_devices[i].model == model) {
1105 if (HDA_DEV_MATCH(hdac_devices[i].model, model) &&
1106 class == PCIC_MULTIMEDIA &&
1107 subclass == PCIS_MULTIMEDIA_HDA) {
1113 sc->lock = snd_mtxcreate(device_get_nameunit(dev), "HDA driver mutex");
1115 TASK_INIT(&sc->unsolq_task, 0, hdac_unsolq_task, sc);
1116 callout_init(&sc->poll_callout, 1);
1117 for (i = 0; i < HDAC_CODEC_MAX; i++)
1118 sc->codecs[i].dev = NULL;
1120 sc->quirks_on = hdac_devices[devid].quirks_on;
1121 sc->quirks_off = hdac_devices[devid].quirks_off;
1126 if (resource_int_value(device_get_name(dev),
1127 device_get_unit(dev), "msi", &i) == 0) {
1129 sc->quirks_off |= HDAC_QUIRK_MSI;
1131 sc->quirks_on |= HDAC_QUIRK_MSI;
1132 sc->quirks_off |= ~HDAC_QUIRK_MSI;
1135 hdac_config_fetch(sc, &sc->quirks_on, &sc->quirks_off);
1137 device_printf(sc->dev,
1138 "Config options: on=0x%08x off=0x%08x\n",
1139 sc->quirks_on, sc->quirks_off);
1142 if (resource_int_value(device_get_name(dev),
1143 device_get_unit(dev), "polling", &i) == 0 && i != 0)
1148 pci_enable_busmaster(dev);
1150 vendor = pci_get_vendor(dev);
1151 if (vendor == INTEL_VENDORID) {
1153 v = pci_read_config(dev, 0x44, 1);
1154 pci_write_config(dev, 0x44, v & 0xf8, 1);
1156 device_printf(dev, "TCSEL: 0x%02d -> 0x%02d\n", v,
1157 pci_read_config(dev, 0x44, 1));
1161 #if defined(__i386__) || defined(__amd64__)
1162 sc->flags |= HDAC_F_DMA_NOCACHE;
1164 if (resource_int_value(device_get_name(dev),
1165 device_get_unit(dev), "snoop", &i) == 0 && i != 0) {
1167 sc->flags &= ~HDAC_F_DMA_NOCACHE;
1170 * Try to enable PCIe snoop to avoid messing around with
1171 * uncacheable DMA attribute. Since PCIe snoop register
1172 * config is pretty much vendor specific, there are no
1173 * general solutions on how to enable it, forcing us (even
1174 * Microsoft) to enable uncacheable or write combined DMA
1177 * http://msdn2.microsoft.com/en-us/library/ms790324.aspx
1179 for (i = 0; i < nitems(hdac_pcie_snoop); i++) {
1180 if (hdac_pcie_snoop[i].vendor != vendor)
1182 sc->flags &= ~HDAC_F_DMA_NOCACHE;
1183 if (hdac_pcie_snoop[i].reg == 0x00)
1185 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
1186 if ((v & hdac_pcie_snoop[i].enable) ==
1187 hdac_pcie_snoop[i].enable)
1189 v &= hdac_pcie_snoop[i].mask;
1190 v |= hdac_pcie_snoop[i].enable;
1191 pci_write_config(dev, hdac_pcie_snoop[i].reg, v, 1);
1192 v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1);
1193 if ((v & hdac_pcie_snoop[i].enable) !=
1194 hdac_pcie_snoop[i].enable) {
1197 "WARNING: Failed to enable PCIe "
1200 #if defined(__i386__) || defined(__amd64__)
1201 sc->flags |= HDAC_F_DMA_NOCACHE;
1206 #if defined(__i386__) || defined(__amd64__)
1211 device_printf(dev, "DMA Coherency: %s / vendor=0x%04x\n",
1212 (sc->flags & HDAC_F_DMA_NOCACHE) ?
1213 "Uncacheable" : "PCIe snoop", vendor);
1216 /* Allocate resources */
1217 result = hdac_mem_alloc(sc);
1219 goto hdac_attach_fail;
1220 result = hdac_irq_alloc(sc);
1222 goto hdac_attach_fail;
1224 /* Get Capabilities */
1225 result = hdac_get_capabilities(sc);
1227 goto hdac_attach_fail;
1229 /* Allocate CORB, RIRB, POS and BDLs dma memory */
1230 result = hdac_dma_alloc(sc, &sc->corb_dma,
1231 sc->corb_size * sizeof(uint32_t));
1233 goto hdac_attach_fail;
1234 result = hdac_dma_alloc(sc, &sc->rirb_dma,
1235 sc->rirb_size * sizeof(struct hdac_rirb));
1237 goto hdac_attach_fail;
1238 sc->streams = malloc(sizeof(struct hdac_stream) * sc->num_ss,
1239 M_HDAC, M_ZERO | M_WAITOK);
1240 for (i = 0; i < sc->num_ss; i++) {
1241 result = hdac_dma_alloc(sc, &sc->streams[i].bdl,
1242 sizeof(struct hdac_bdle) * HDA_BDL_MAX);
1244 goto hdac_attach_fail;
1246 if (sc->quirks_on & HDAC_QUIRK_DMAPOS) {
1247 if (hdac_dma_alloc(sc, &sc->pos_dma, (sc->num_ss) * 8) != 0) {
1249 device_printf(dev, "Failed to "
1250 "allocate DMA pos buffer "
1254 uint64_t addr = sc->pos_dma.dma_paddr;
1256 HDAC_WRITE_4(&sc->mem, HDAC_DPIBUBASE, addr >> 32);
1257 HDAC_WRITE_4(&sc->mem, HDAC_DPIBLBASE,
1258 (addr & HDAC_DPLBASE_DPLBASE_MASK) |
1259 HDAC_DPLBASE_DPLBASE_DMAPBE);
1263 result = bus_dma_tag_create(
1264 bus_get_dma_tag(sc->dev), /* parent */
1265 HDA_DMA_ALIGNMENT, /* alignment */
1267 (sc->support_64bit) ? BUS_SPACE_MAXADDR :
1268 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
1269 BUS_SPACE_MAXADDR, /* highaddr */
1270 NULL, /* filtfunc */
1271 NULL, /* fistfuncarg */
1272 HDA_BUFSZ_MAX, /* maxsize */
1274 HDA_BUFSZ_MAX, /* maxsegsz */
1276 NULL, /* lockfunc */
1277 NULL, /* lockfuncarg */
1278 &sc->chan_dmat); /* dmat */
1280 device_printf(dev, "%s: bus_dma_tag_create failed (%d)\n",
1282 goto hdac_attach_fail;
1285 /* Quiesce everything */
1287 device_printf(dev, "Reset controller...\n");
1291 /* Initialize the CORB and RIRB */
1295 /* Defer remaining of initialization until interrupts are enabled */
1296 sc->intrhook.ich_func = hdac_attach2;
1297 sc->intrhook.ich_arg = (void *)sc;
1298 if (cold == 0 || config_intrhook_establish(&sc->intrhook) != 0) {
1299 sc->intrhook.ich_func = NULL;
1300 hdac_attach2((void *)sc);
1307 if (sc->streams != NULL)
1308 for (i = 0; i < sc->num_ss; i++)
1309 hdac_dma_free(sc, &sc->streams[i].bdl);
1310 free(sc->streams, M_HDAC);
1311 hdac_dma_free(sc, &sc->rirb_dma);
1312 hdac_dma_free(sc, &sc->corb_dma);
1314 snd_mtxfree(sc->lock);
1320 sysctl_hdac_pindump(SYSCTL_HANDLER_ARGS)
1322 struct hdac_softc *sc;
1325 int devcount, i, err, val;
1327 dev = oidp->oid_arg1;
1328 sc = device_get_softc(dev);
1332 err = sysctl_handle_int(oidp, &val, 0, req);
1333 if (err != 0 || req->newptr == NULL || val == 0)
1336 /* XXX: Temporary. For debugging. */
1340 } else if (val == 101) {
1345 if ((err = device_get_children(dev, &devlist, &devcount)) != 0)
1348 for (i = 0; i < devcount; i++)
1349 HDAC_PINDUMP(devlist[i]);
1351 free(devlist, M_TEMP);
1356 hdac_mdata_rate(uint16_t fmt)
1358 static const int mbits[8] = { 8, 16, 32, 32, 32, 32, 32, 32 };
1361 if (fmt & (1 << 14))
1365 rate *= ((fmt >> 11) & 0x07) + 1;
1366 rate /= ((fmt >> 8) & 0x07) + 1;
1367 bits = mbits[(fmt >> 4) & 0x03];
1368 bits *= (fmt & 0x0f) + 1;
1369 return (rate * bits);
1373 hdac_bdata_rate(uint16_t fmt, int output)
1375 static const int bbits[8] = { 8, 16, 20, 24, 32, 32, 32, 32 };
1379 rate *= ((fmt >> 11) & 0x07) + 1;
1380 bits = bbits[(fmt >> 4) & 0x03];
1381 bits *= (fmt & 0x0f) + 1;
1383 bits = ((bits + 7) & ~0x07) + 10;
1384 return (rate * bits);
1388 hdac_poll_reinit(struct hdac_softc *sc)
1390 int i, pollticks, min = 1000000;
1391 struct hdac_stream *s;
1393 if (sc->polling == 0)
1395 if (sc->unsol_registered > 0)
1397 for (i = 0; i < sc->num_ss; i++) {
1398 s = &sc->streams[i];
1399 if (s->running == 0)
1401 pollticks = ((uint64_t)hz * s->blksz) /
1402 (hdac_mdata_rate(s->format) / 8);
1408 if (min > pollticks)
1411 sc->poll_ival = min;
1413 callout_stop(&sc->poll_callout);
1415 callout_reset(&sc->poll_callout, 1, hdac_poll_callback, sc);
1419 sysctl_hdac_polling(SYSCTL_HANDLER_ARGS)
1421 struct hdac_softc *sc;
1426 dev = oidp->oid_arg1;
1427 sc = device_get_softc(dev);
1433 err = sysctl_handle_int(oidp, &val, 0, req);
1435 if (err != 0 || req->newptr == NULL)
1437 if (val < 0 || val > 1)
1441 if (val != sc->polling) {
1443 callout_stop(&sc->poll_callout);
1445 callout_drain(&sc->poll_callout);
1448 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
1449 ctl |= HDAC_INTCTL_GIE;
1450 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
1452 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
1453 ctl &= ~HDAC_INTCTL_GIE;
1454 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
1456 hdac_poll_reinit(sc);
1465 hdac_attach2(void *arg)
1467 struct hdac_softc *sc;
1469 uint32_t vendorid, revisionid;
1473 sc = (struct hdac_softc *)arg;
1477 /* Remove ourselves from the config hooks */
1478 if (sc->intrhook.ich_func != NULL) {
1479 config_intrhook_disestablish(&sc->intrhook);
1480 sc->intrhook.ich_func = NULL;
1484 device_printf(sc->dev, "Starting CORB Engine...\n");
1486 hdac_corb_start(sc);
1488 device_printf(sc->dev, "Starting RIRB Engine...\n");
1490 hdac_rirb_start(sc);
1492 device_printf(sc->dev,
1493 "Enabling controller interrupt...\n");
1495 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
1497 if (sc->polling == 0) {
1498 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL,
1499 HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
1504 device_printf(sc->dev, "Scanning HDA codecs ...\n");
1506 statests = HDAC_READ_2(&sc->mem, HDAC_STATESTS);
1508 for (i = 0; i < HDAC_CODEC_MAX; i++) {
1509 if (HDAC_STATESTS_SDIWAKE(statests, i)) {
1511 device_printf(sc->dev,
1512 "Found CODEC at address %d\n", i);
1515 vendorid = hdac_send_command(sc, i,
1516 HDA_CMD_GET_PARAMETER(0, 0x0, HDA_PARAM_VENDOR_ID));
1517 revisionid = hdac_send_command(sc, i,
1518 HDA_CMD_GET_PARAMETER(0, 0x0, HDA_PARAM_REVISION_ID));
1520 if (vendorid == HDA_INVALID &&
1521 revisionid == HDA_INVALID) {
1522 device_printf(sc->dev,
1523 "CODEC at address %d not responding!\n", i);
1526 sc->codecs[i].vendor_id =
1527 HDA_PARAM_VENDOR_ID_VENDOR_ID(vendorid);
1528 sc->codecs[i].device_id =
1529 HDA_PARAM_VENDOR_ID_DEVICE_ID(vendorid);
1530 sc->codecs[i].revision_id =
1531 HDA_PARAM_REVISION_ID_REVISION_ID(revisionid);
1532 sc->codecs[i].stepping_id =
1533 HDA_PARAM_REVISION_ID_STEPPING_ID(revisionid);
1534 child = device_add_child(sc->dev, "hdacc", -1);
1535 if (child == NULL) {
1536 device_printf(sc->dev,
1537 "Failed to add CODEC device\n");
1540 device_set_ivars(child, (void *)(intptr_t)i);
1541 sc->codecs[i].dev = child;
1544 bus_generic_attach(sc->dev);
1546 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
1547 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
1548 "pindump", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc->dev,
1549 sizeof(sc->dev), sysctl_hdac_pindump, "I", "Dump pin states/data");
1550 SYSCTL_ADD_PROC(device_get_sysctl_ctx(sc->dev),
1551 SYSCTL_CHILDREN(device_get_sysctl_tree(sc->dev)), OID_AUTO,
1552 "polling", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, sc->dev,
1553 sizeof(sc->dev), sysctl_hdac_polling, "I", "Enable polling mode");
1556 /****************************************************************************
1557 * int hdac_suspend(device_t)
1559 * Suspend and power down HDA bus and codecs.
1560 ****************************************************************************/
1562 hdac_suspend(device_t dev)
1564 struct hdac_softc *sc = device_get_softc(dev);
1567 device_printf(dev, "Suspend...\n");
1569 bus_generic_suspend(dev);
1573 device_printf(dev, "Reset controller...\n");
1575 callout_stop(&sc->poll_callout);
1578 callout_drain(&sc->poll_callout);
1579 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
1581 device_printf(dev, "Suspend done\n");
1586 /****************************************************************************
1587 * int hdac_resume(device_t)
1589 * Powerup and restore HDA bus and codecs state.
1590 ****************************************************************************/
1592 hdac_resume(device_t dev)
1594 struct hdac_softc *sc = device_get_softc(dev);
1598 device_printf(dev, "Resume...\n");
1602 /* Quiesce everything */
1604 device_printf(dev, "Reset controller...\n");
1608 /* Initialize the CORB and RIRB */
1613 device_printf(dev, "Starting CORB Engine...\n");
1615 hdac_corb_start(sc);
1617 device_printf(dev, "Starting RIRB Engine...\n");
1619 hdac_rirb_start(sc);
1621 device_printf(dev, "Enabling controller interrupt...\n");
1623 HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) |
1625 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
1627 hdac_poll_reinit(sc);
1630 error = bus_generic_resume(dev);
1632 device_printf(dev, "Resume done\n");
1637 /****************************************************************************
1638 * int hdac_detach(device_t)
1640 * Detach and free up resources utilized by the hdac device.
1641 ****************************************************************************/
1643 hdac_detach(device_t dev)
1645 struct hdac_softc *sc = device_get_softc(dev);
1647 int cad, i, devcount, error;
1649 if ((error = device_get_children(dev, &devlist, &devcount)) != 0)
1651 for (i = 0; i < devcount; i++) {
1652 cad = (intptr_t)device_get_ivars(devlist[i]);
1653 if ((error = device_delete_child(dev, devlist[i])) != 0) {
1654 free(devlist, M_TEMP);
1657 sc->codecs[cad].dev = NULL;
1659 free(devlist, M_TEMP);
1664 taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
1667 for (i = 0; i < sc->num_ss; i++)
1668 hdac_dma_free(sc, &sc->streams[i].bdl);
1669 free(sc->streams, M_HDAC);
1670 hdac_dma_free(sc, &sc->pos_dma);
1671 hdac_dma_free(sc, &sc->rirb_dma);
1672 hdac_dma_free(sc, &sc->corb_dma);
1673 if (sc->chan_dmat != NULL) {
1674 bus_dma_tag_destroy(sc->chan_dmat);
1675 sc->chan_dmat = NULL;
1678 snd_mtxfree(sc->lock);
1682 static bus_dma_tag_t
1683 hdac_get_dma_tag(device_t dev, device_t child)
1685 struct hdac_softc *sc = device_get_softc(dev);
1687 return (sc->chan_dmat);
1691 hdac_print_child(device_t dev, device_t child)
1695 retval = bus_print_child_header(dev, child);
1696 retval += printf(" at cad %d", (int)(intptr_t)device_get_ivars(child));
1697 retval += bus_print_child_footer(dev, child);
1703 hdac_child_location_str(device_t dev, device_t child, char *buf, size_t buflen)
1706 snprintf(buf, buflen, "cad=%d", (int)(intptr_t)device_get_ivars(child));
1711 hdac_child_pnpinfo_str_method(device_t dev, device_t child, char *buf,
1714 struct hdac_softc *sc = device_get_softc(dev);
1715 nid_t cad = (uintptr_t)device_get_ivars(child);
1717 snprintf(buf, buflen,
1718 "vendor=0x%04x device=0x%04x revision=0x%02x stepping=0x%02x",
1719 sc->codecs[cad].vendor_id, sc->codecs[cad].device_id,
1720 sc->codecs[cad].revision_id, sc->codecs[cad].stepping_id);
1725 hdac_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
1727 struct hdac_softc *sc = device_get_softc(dev);
1728 nid_t cad = (uintptr_t)device_get_ivars(child);
1731 case HDA_IVAR_CODEC_ID:
1734 case HDA_IVAR_VENDOR_ID:
1735 *result = sc->codecs[cad].vendor_id;
1737 case HDA_IVAR_DEVICE_ID:
1738 *result = sc->codecs[cad].device_id;
1740 case HDA_IVAR_REVISION_ID:
1741 *result = sc->codecs[cad].revision_id;
1743 case HDA_IVAR_STEPPING_ID:
1744 *result = sc->codecs[cad].stepping_id;
1746 case HDA_IVAR_SUBVENDOR_ID:
1747 *result = pci_get_subvendor(dev);
1749 case HDA_IVAR_SUBDEVICE_ID:
1750 *result = pci_get_subdevice(dev);
1752 case HDA_IVAR_DMA_NOCACHE:
1753 *result = (sc->flags & HDAC_F_DMA_NOCACHE) != 0;
1755 case HDA_IVAR_STRIPES_MASK:
1756 *result = (1 << (1 << sc->num_sdo)) - 1;
1765 hdac_get_mtx(device_t dev, device_t child)
1767 struct hdac_softc *sc = device_get_softc(dev);
1773 hdac_codec_command(device_t dev, device_t child, uint32_t verb)
1776 return (hdac_send_command(device_get_softc(dev),
1777 (intptr_t)device_get_ivars(child), verb));
1781 hdac_find_stream(struct hdac_softc *sc, int dir, int stream)
1786 /* Allocate ISS/OSS first. */
1788 for (i = 0; i < sc->num_iss; i++) {
1789 if (sc->streams[i].stream == stream) {
1795 for (i = 0; i < sc->num_oss; i++) {
1796 if (sc->streams[i + sc->num_iss].stream == stream) {
1797 ss = i + sc->num_iss;
1802 /* Fallback to BSS. */
1804 for (i = 0; i < sc->num_bss; i++) {
1805 if (sc->streams[i + sc->num_iss + sc->num_oss].stream
1807 ss = i + sc->num_iss + sc->num_oss;
1816 hdac_stream_alloc(device_t dev, device_t child, int dir, int format, int stripe,
1819 struct hdac_softc *sc = device_get_softc(dev);
1820 nid_t cad = (uintptr_t)device_get_ivars(child);
1821 int stream, ss, bw, maxbw, prevbw;
1823 /* Look for empty stream. */
1824 ss = hdac_find_stream(sc, dir, 0);
1826 /* Return if found nothing. */
1830 /* Check bus bandwidth. */
1831 bw = hdac_bdata_rate(format, dir);
1833 bw *= 1 << (sc->num_sdo - stripe);
1834 prevbw = sc->sdo_bw_used;
1835 maxbw = 48000 * 960 * (1 << sc->num_sdo);
1837 prevbw = sc->codecs[cad].sdi_bw_used;
1838 maxbw = 48000 * 464;
1841 device_printf(dev, "%dKbps of %dKbps bandwidth used%s\n",
1842 (bw + prevbw) / 1000, maxbw / 1000,
1843 bw + prevbw > maxbw ? " -- OVERFLOW!" : "");
1845 if (bw + prevbw > maxbw)
1848 sc->sdo_bw_used += bw;
1850 sc->codecs[cad].sdi_bw_used += bw;
1852 /* Allocate stream number */
1853 if (ss >= sc->num_iss + sc->num_oss)
1854 stream = 15 - (ss - sc->num_iss - sc->num_oss);
1855 else if (ss >= sc->num_iss)
1856 stream = ss - sc->num_iss + 1;
1860 sc->streams[ss].dev = child;
1861 sc->streams[ss].dir = dir;
1862 sc->streams[ss].stream = stream;
1863 sc->streams[ss].bw = bw;
1864 sc->streams[ss].format = format;
1865 sc->streams[ss].stripe = stripe;
1866 if (dmapos != NULL) {
1867 if (sc->pos_dma.dma_vaddr != NULL)
1868 *dmapos = (uint32_t *)(sc->pos_dma.dma_vaddr + ss * 8);
1876 hdac_stream_free(device_t dev, device_t child, int dir, int stream)
1878 struct hdac_softc *sc = device_get_softc(dev);
1879 nid_t cad = (uintptr_t)device_get_ivars(child);
1882 ss = hdac_find_stream(sc, dir, stream);
1884 ("Free for not allocated stream (%d/%d)\n", dir, stream));
1886 sc->sdo_bw_used -= sc->streams[ss].bw;
1888 sc->codecs[cad].sdi_bw_used -= sc->streams[ss].bw;
1889 sc->streams[ss].stream = 0;
1890 sc->streams[ss].dev = NULL;
1894 hdac_stream_start(device_t dev, device_t child, int dir, int stream,
1895 bus_addr_t buf, int blksz, int blkcnt)
1897 struct hdac_softc *sc = device_get_softc(dev);
1898 struct hdac_bdle *bdle;
1903 ss = hdac_find_stream(sc, dir, stream);
1905 ("Start for not allocated stream (%d/%d)\n", dir, stream));
1907 addr = (uint64_t)buf;
1908 bdle = (struct hdac_bdle *)sc->streams[ss].bdl.dma_vaddr;
1909 for (i = 0; i < blkcnt; i++, bdle++) {
1910 bdle->addrl = htole32((uint32_t)addr);
1911 bdle->addrh = htole32((uint32_t)(addr >> 32));
1912 bdle->len = htole32(blksz);
1913 bdle->ioc = htole32(1);
1917 bus_dmamap_sync(sc->streams[ss].bdl.dma_tag,
1918 sc->streams[ss].bdl.dma_map, BUS_DMASYNC_PREWRITE);
1921 HDAC_WRITE_4(&sc->mem, off + HDAC_SDCBL, blksz * blkcnt);
1922 HDAC_WRITE_2(&sc->mem, off + HDAC_SDLVI, blkcnt - 1);
1923 addr = sc->streams[ss].bdl.dma_paddr;
1924 HDAC_WRITE_4(&sc->mem, off + HDAC_SDBDPL, (uint32_t)addr);
1925 HDAC_WRITE_4(&sc->mem, off + HDAC_SDBDPU, (uint32_t)(addr >> 32));
1927 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL2);
1929 ctl |= HDAC_SDCTL2_DIR;
1931 ctl &= ~HDAC_SDCTL2_DIR;
1932 ctl &= ~HDAC_SDCTL2_STRM_MASK;
1933 ctl |= stream << HDAC_SDCTL2_STRM_SHIFT;
1934 ctl &= ~HDAC_SDCTL2_STRIPE_MASK;
1935 ctl |= sc->streams[ss].stripe << HDAC_SDCTL2_STRIPE_SHIFT;
1936 HDAC_WRITE_1(&sc->mem, off + HDAC_SDCTL2, ctl);
1938 HDAC_WRITE_2(&sc->mem, off + HDAC_SDFMT, sc->streams[ss].format);
1940 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
1942 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
1944 HDAC_WRITE_1(&sc->mem, off + HDAC_SDSTS,
1945 HDAC_SDSTS_DESE | HDAC_SDSTS_FIFOE | HDAC_SDSTS_BCIS);
1946 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL0);
1947 ctl |= HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
1949 HDAC_WRITE_1(&sc->mem, off + HDAC_SDCTL0, ctl);
1951 sc->streams[ss].blksz = blksz;
1952 sc->streams[ss].running = 1;
1953 hdac_poll_reinit(sc);
1958 hdac_stream_stop(device_t dev, device_t child, int dir, int stream)
1960 struct hdac_softc *sc = device_get_softc(dev);
1964 ss = hdac_find_stream(sc, dir, stream);
1966 ("Stop for not allocated stream (%d/%d)\n", dir, stream));
1968 bus_dmamap_sync(sc->streams[ss].bdl.dma_tag,
1969 sc->streams[ss].bdl.dma_map, BUS_DMASYNC_POSTWRITE);
1972 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL0);
1973 ctl &= ~(HDAC_SDCTL_IOCE | HDAC_SDCTL_FEIE | HDAC_SDCTL_DEIE |
1975 HDAC_WRITE_1(&sc->mem, off + HDAC_SDCTL0, ctl);
1977 ctl = HDAC_READ_4(&sc->mem, HDAC_INTCTL);
1979 HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, ctl);
1981 sc->streams[ss].running = 0;
1982 hdac_poll_reinit(sc);
1986 hdac_stream_reset(device_t dev, device_t child, int dir, int stream)
1988 struct hdac_softc *sc = device_get_softc(dev);
1994 ss = hdac_find_stream(sc, dir, stream);
1996 ("Reset for not allocated stream (%d/%d)\n", dir, stream));
1999 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL0);
2000 ctl |= HDAC_SDCTL_SRST;
2001 HDAC_WRITE_1(&sc->mem, off + HDAC_SDCTL0, ctl);
2003 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL0);
2004 if (ctl & HDAC_SDCTL_SRST)
2008 if (!(ctl & HDAC_SDCTL_SRST))
2009 device_printf(dev, "Reset setting timeout\n");
2010 ctl &= ~HDAC_SDCTL_SRST;
2011 HDAC_WRITE_1(&sc->mem, off + HDAC_SDCTL0, ctl);
2014 ctl = HDAC_READ_1(&sc->mem, off + HDAC_SDCTL0);
2015 if (!(ctl & HDAC_SDCTL_SRST))
2019 if (ctl & HDAC_SDCTL_SRST)
2020 device_printf(dev, "Reset timeout!\n");
2024 hdac_stream_getptr(device_t dev, device_t child, int dir, int stream)
2026 struct hdac_softc *sc = device_get_softc(dev);
2029 ss = hdac_find_stream(sc, dir, stream);
2031 ("Reset for not allocated stream (%d/%d)\n", dir, stream));
2034 return (HDAC_READ_4(&sc->mem, off + HDAC_SDLPIB));
2038 hdac_unsol_alloc(device_t dev, device_t child, int tag)
2040 struct hdac_softc *sc = device_get_softc(dev);
2042 sc->unsol_registered++;
2043 hdac_poll_reinit(sc);
2048 hdac_unsol_free(device_t dev, device_t child, int tag)
2050 struct hdac_softc *sc = device_get_softc(dev);
2052 sc->unsol_registered--;
2053 hdac_poll_reinit(sc);
2056 static device_method_t hdac_methods[] = {
2057 /* device interface */
2058 DEVMETHOD(device_probe, hdac_probe),
2059 DEVMETHOD(device_attach, hdac_attach),
2060 DEVMETHOD(device_detach, hdac_detach),
2061 DEVMETHOD(device_suspend, hdac_suspend),
2062 DEVMETHOD(device_resume, hdac_resume),
2064 DEVMETHOD(bus_get_dma_tag, hdac_get_dma_tag),
2065 DEVMETHOD(bus_print_child, hdac_print_child),
2066 DEVMETHOD(bus_child_location_str, hdac_child_location_str),
2067 DEVMETHOD(bus_child_pnpinfo_str, hdac_child_pnpinfo_str_method),
2068 DEVMETHOD(bus_read_ivar, hdac_read_ivar),
2069 DEVMETHOD(hdac_get_mtx, hdac_get_mtx),
2070 DEVMETHOD(hdac_codec_command, hdac_codec_command),
2071 DEVMETHOD(hdac_stream_alloc, hdac_stream_alloc),
2072 DEVMETHOD(hdac_stream_free, hdac_stream_free),
2073 DEVMETHOD(hdac_stream_start, hdac_stream_start),
2074 DEVMETHOD(hdac_stream_stop, hdac_stream_stop),
2075 DEVMETHOD(hdac_stream_reset, hdac_stream_reset),
2076 DEVMETHOD(hdac_stream_getptr, hdac_stream_getptr),
2077 DEVMETHOD(hdac_unsol_alloc, hdac_unsol_alloc),
2078 DEVMETHOD(hdac_unsol_free, hdac_unsol_free),
2082 static driver_t hdac_driver = {
2085 sizeof(struct hdac_softc),
2088 static devclass_t hdac_devclass;
2090 DRIVER_MODULE(snd_hda, pci, hdac_driver, hdac_devclass, NULL, NULL);