From 6ef811ff41a9e02c685a42cb82cc250aadafdfcc Mon Sep 17 00:00:00 2001 From: Hasso Tepper Date: Fri, 30 Nov 2007 07:47:44 +0000 Subject: [PATCH 1/1] - Add codec id for Realtek ALC268. - Add controller id for Intel 82801I (ICH9). - MSI support, though commented out due to lack of support in DragonFly. Obtained-from: FreeBSD --- sys/dev/sound/pci/hda/hdac.c | 69 ++++++++++++++++++++-------- sys/dev/sound/pci/hda/hdac_private.h | 15 ++++-- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/sys/dev/sound/pci/hda/hdac.c b/sys/dev/sound/pci/hda/hdac.c index 733ced34fd..349184609b 100644 --- a/sys/dev/sound/pci/hda/hdac.c +++ b/sys/dev/sound/pci/hda/hdac.c @@ -24,8 +24,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/sound/pci/hda/hdac.c,v 1.36.2.4 2007/07/04 04:05:22 ariff Exp $ - * $DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 07:41:28 hasso Exp $ + * $FreeBSD: src/sys/dev/sound/pci/hda/hdac.c,v 1.36.2.5 2007/07/12 06:39:08 ariff Exp $ + * $DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.11 2007/11/30 07:47:44 hasso Exp $ */ /* @@ -84,10 +84,10 @@ #include "mixer_if.h" -#define HDA_DRV_TEST_REV "20070702_0046" +#define HDA_DRV_TEST_REV "20070710_0047" #define HDA_WIDGET_PARSER_REV 1 -SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 07:41:28 hasso Exp $"); +SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.11 2007/11/30 07:47:44 hasso Exp $"); #define HDA_BOOTVERBOSE(stmt) do { \ if (bootverbose != 0) { \ @@ -110,7 +110,8 @@ SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 #define HDAC_DMA_ATTR(sc, v, s, attr) do { \ vm_offset_t va = (vm_offset_t)(v); \ vm_size_t sz = (vm_size_t)(s); \ - if ((sc) != NULL && (sc)->nocache != 0 && va != 0 && sz != 0) \ + if ((sc) != NULL && ((sc)->flags & HDAC_F_DMA_NOCACHE) && \ + va != 0 && sz != 0) \ (void)pmap_change_attr(va, sz, (attr)); \ } while(0) #else @@ -146,9 +147,10 @@ SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pci/hda/hdac.c,v 1.10 2007/11/30 /* Intel */ #define INTEL_VENDORID 0x8086 #define HDA_INTEL_82801F HDA_MODEL_CONSTRUCT(INTEL, 0x2668) +#define HDA_INTEL_63XXESB HDA_MODEL_CONSTRUCT(INTEL, 0x269a) #define HDA_INTEL_82801G HDA_MODEL_CONSTRUCT(INTEL, 0x27d8) #define HDA_INTEL_82801H HDA_MODEL_CONSTRUCT(INTEL, 0x284b) -#define HDA_INTEL_63XXESB HDA_MODEL_CONSTRUCT(INTEL, 0x269a) +#define HDA_INTEL_82801I HDA_MODEL_CONSTRUCT(INTEL, 0x293e) #define HDA_INTEL_ALL HDA_MODEL_CONSTRUCT(INTEL, 0xffff) /* Nvidia */ @@ -409,9 +411,10 @@ static const struct { char *desc; } hdac_devices[] = { { HDA_INTEL_82801F, "Intel 82801F" }, + { HDA_INTEL_63XXESB, "Intel 631x/632xESB" }, { HDA_INTEL_82801G, "Intel 82801G" }, { HDA_INTEL_82801H, "Intel 82801H" }, - { HDA_INTEL_63XXESB, "Intel 631x/632xESB" }, + { HDA_INTEL_82801I, "Intel 82801I" }, { HDA_NVIDIA_MCP51, "NVidia MCP51" }, { HDA_NVIDIA_MCP55, "NVidia MCP55" }, { HDA_NVIDIA_MCP61A, "NVidia MCP61A" }, @@ -497,6 +500,7 @@ static const struct { #define REALTEK_VENDORID 0x10ec #define HDA_CODEC_ALC260 HDA_CODEC_CONSTRUCT(REALTEK, 0x0260) #define HDA_CODEC_ALC262 HDA_CODEC_CONSTRUCT(REALTEK, 0x0262) +#define HDA_CODEC_ALC268 HDA_CODEC_CONSTRUCT(REALTEK, 0x0268) #define HDA_CODEC_ALC660 HDA_CODEC_CONSTRUCT(REALTEK, 0x0660) #define HDA_CODEC_ALC861 HDA_CODEC_CONSTRUCT(REALTEK, 0x0861) #define HDA_CODEC_ALC861VD HDA_CODEC_CONSTRUCT(REALTEK, 0x0862) @@ -569,6 +573,7 @@ static const struct { } hdac_codecs[] = { { HDA_CODEC_ALC260, "Realtek ALC260" }, { HDA_CODEC_ALC262, "Realtek ALC262" }, + { HDA_CODEC_ALC268, "Realtek ALC268" }, { HDA_CODEC_ALC660, "Realtek ALC660" }, { HDA_CODEC_ALC861, "Realtek ALC861" }, { HDA_CODEC_ALC861VD, "Realtek ALC861-VD" }, @@ -1088,7 +1093,7 @@ hdac_stream_intr(struct hdac_softc *sc, struct hdac_chan *ch) uint32_t res; #endif - if (ch->blkcnt == 0) + if (!(ch->flags & HDAC_CHN_RUNNING)) return (0); /* XXX to be removed */ @@ -1397,7 +1402,8 @@ hdac_dma_alloc(struct hdac_softc *sc, struct hdac_dma *dma, bus_size_t size) #if 0 /* TODO: No uncacheable DMA support in DragonFly. */ result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr, BUS_DMA_NOWAIT | BUS_DMA_ZERO | - ((sc->nocache != 0) ? BUS_DMA_NOCACHE : 0), &dma->dma_map); + ((sc->flags & HDAC_F_DMA_NOCACHE) ? BUS_DMA_NOCACHE : 0), + &dma->dma_map); #else result = bus_dmamem_alloc(dma->dma_tag, (void **)&dma->dma_vaddr, BUS_DMA_NOWAIT | BUS_DMA_ZERO, &dma->dma_map); @@ -1522,6 +1528,16 @@ hdac_irq_alloc(struct hdac_softc *sc) irq = &sc->irq; irq->irq_rid = 0x0; + +#if 0 /* TODO: No MSI support in DragonFly yet. */ + if ((sc->flags & HDAC_F_MSI) && + (result = pci_msi_count(sc->dev)) == 1 && + pci_alloc_msi(sc->dev, &result) == 0) + irq->irq_rid = 0x1; + else +#endif + sc->flags &= ~HDAC_F_MSI; + irq->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->irq_rid, RF_SHAREABLE | RF_ACTIVE); if (irq->irq_res == NULL) { @@ -1562,8 +1578,13 @@ hdac_irq_free(struct hdac_softc *sc) if (irq->irq_res != NULL) bus_release_resource(sc->dev, SYS_RES_IRQ, irq->irq_rid, irq->irq_res); +#if 0 /* TODO: No MSI support in DragonFly yet. */ + if ((sc->flags & HDAC_F_MSI) && irq->irq_rid == 0x1) + pci_release_msi(sc->dev); +#endif irq->irq_handle = NULL; irq->irq_res = NULL; + irq->irq_rid = 0x0; } /**************************************************************************** @@ -2387,7 +2408,7 @@ hda_poll_channel(struct hdac_chan *ch) uint32_t sz, delta; volatile uint32_t ptr; - if (ch->active == 0) + if (!(ch->flags & HDAC_CHN_RUNNING)) return (0); sz = ch->blksz * ch->blkcnt; @@ -2409,7 +2430,8 @@ hda_poll_channel(struct hdac_chan *ch) return (1); } -#define hda_chan_active(sc) ((sc)->play.active + (sc)->rec.active) +#define hda_chan_active(sc) (((sc)->play.flags | (sc)->rec.flags) & \ + HDAC_CHN_RUNNING) static void hda_poll_callback(void *arg) @@ -2537,7 +2559,7 @@ hdac_stream_stop(struct hdac_chan *ch) HDAC_SDCTL_RUN); HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl); - ch->active = 0; + ch->flags &= ~HDAC_CHN_RUNNING; if (sc->polling != 0) { int pollticks; @@ -2546,7 +2568,7 @@ hdac_stream_stop(struct hdac_chan *ch) callout_stop(&sc->poll_hda); sc->poll_ticks = 1; } else { - if (sc->play.active != 0) + if (sc->play.flags & HDAC_CHN_RUNNING) ch = &sc->play; else ch = &sc->rec; @@ -2634,7 +2656,7 @@ hdac_stream_start(struct hdac_chan *ch) } HDAC_WRITE_1(&sc->mem, ch->off + HDAC_SDCTL0, ctl); - ch->active = 1; + ch->flags |= HDAC_CHN_RUNNING; } static void @@ -3737,14 +3759,22 @@ hdac_attach(device_t dev) pci_read_config(dev, 0x44, 1)); ); } +#if 0 /* TODO: No MSI support yet in DragonFly. */ + if (resource_int_value(device_get_name(dev), + device_get_unit(dev), "msi", &i) == 0 && i != 0 && + pci_msi_count(dev) == 1) + sc->flags |= HDAC_F_MSI; + else +#endif + sc->flags &= ~HDAC_F_MSI; #if 0 /* TODO: No uncacheable DMA support in DragonFly. */ - sc->nocache = 1; + sc->flags |= HDAC_F_DMA_NOCACHE; if (resource_int_value(device_get_name(dev), device_get_unit(dev), "snoop", &i) == 0 && i != 0) { #else - sc->nocache = 0; + sc->flags &= ~HDAC_F_DMA_NOCACHE; #endif /* * Try to enable PCIe snoop to avoid messing around with @@ -3759,7 +3789,7 @@ hdac_attach(device_t dev) for (i = 0; i < HDAC_PCIESNOOP_LEN; i++) { if (hdac_pcie_snoop[i].vendor != vendor) continue; - sc->nocache = 0; + sc->flags &= ~HDAC_F_DMA_NOCACHE; if (hdac_pcie_snoop[i].reg == 0x00) break; v = pci_read_config(dev, hdac_pcie_snoop[i].reg, 1); @@ -3778,7 +3808,7 @@ hdac_attach(device_t dev) "snoop!\n"); ); #if 0 /* TODO: No uncacheable DMA support in DragonFly. */ - sc->nocache = 1; + sc->flags |= HDAC_F_DMA_NOCACHE; #endif } break; @@ -3789,7 +3819,8 @@ hdac_attach(device_t dev) HDA_BOOTVERBOSE( device_printf(dev, "DMA Coherency: %s / vendor=0x%04x\n", - (sc->nocache == 0) ? "PCIe snoop" : "Uncacheable", vendor); + (sc->flags & HDAC_F_DMA_NOCACHE) ? + "Uncacheable" : "PCIe snoop", vendor); ); /* Allocate resources */ diff --git a/sys/dev/sound/pci/hda/hdac_private.h b/sys/dev/sound/pci/hda/hdac_private.h index eac9b69c3b..6696597b7e 100644 --- a/sys/dev/sound/pci/hda/hdac_private.h +++ b/sys/dev/sound/pci/hda/hdac_private.h @@ -23,8 +23,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/sound/pci/hda/hdac_private.h,v 1.6.2.2 2007/07/04 04:05:22 ariff Exp $ - * $DragonFly: src/sys/dev/sound/pci/hda/hdac_private.h,v 1.5 2007/11/30 07:41:28 hasso Exp $ + * $FreeBSD: src/sys/dev/sound/pci/hda/hdac_private.h,v 1.6.2.3 2007/07/12 06:39:08 ariff Exp $ + * $DragonFly: src/sys/dev/sound/pci/hda/hdac_private.h,v 1.6 2007/11/30 07:47:44 hasso Exp $ */ #ifndef _HDAC_PRIVATE_H_ @@ -261,6 +261,9 @@ struct hdac_devinfo { } function; }; +#define HDAC_CHN_RUNNING 0x00000001 +#define HDAC_CHN_SUSPEND 0x00000002 + struct hdac_chan { struct snd_dbuf *b; struct pcm_channel *c; @@ -271,7 +274,7 @@ struct hdac_chan { uint32_t supp_stream_formats, supp_pcm_size_rate; uint32_t ptr, prevptr, blkcnt, blksz; uint32_t *dmapos; - int active; + uint32_t flags; int dir; int off; int sid; @@ -284,6 +287,10 @@ struct hdac_chan { * * This structure holds the current state of the hdac driver. ****************************************************************************/ + +#define HDAC_F_DMA_NOCACHE 0x00000001 +#define HDAC_F_MSI 0x00000002 + struct hdac_softc { device_t dev; device_t hdabus; @@ -295,7 +302,7 @@ struct hdac_softc { struct hdac_irq irq; uint32_t pci_subvendor; - int nocache; + uint32_t flags; int num_iss; int num_oss; -- 2.41.0