From owner-freebsd-multimedia@FreeBSD.ORG Mon Jul 2 14:33:37 2007 Return-Path: X-Original-To: freebsd-multimedia@freebsd.org Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2AEC116A46B for ; Mon, 2 Jul 2007 14:33:37 +0000 (UTC) (envelope-from taku@tackymt.homeip.net) Received: from basalt.tackymt.homeip.net (124x38x115x218.ap124.ftth.ucom.ne.jp [124.38.115.218]) by mx1.freebsd.org (Postfix) with ESMTP id E2E1113C465 for ; Mon, 2 Jul 2007 14:33:36 +0000 (UTC) (envelope-from taku@tackymt.homeip.net) Received: from localhost (localhost [127.0.0.1]) by basalt.tackymt.homeip.net (Postfix) with ESMTP id F35C210748 for ; Mon, 2 Jul 2007 23:12:01 +0900 (JST) Received: from basalt.tackymt.homeip.net ([127.0.0.1]) by localhost (basalt.tackymt.homeip.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12738-08 for ; Mon, 2 Jul 2007 23:11:59 +0900 (JST) Received: from biotite (unknown [IPv6:2001:3e0:577:0:216:cfff:febc:1472]) by basalt.tackymt.homeip.net (Postfix) with ESMTP for ; Mon, 2 Jul 2007 23:11:59 +0900 (JST) Date: Mon, 2 Jul 2007 23:11:57 +0900 From: "YAMAMOTO, Taku" To: freebsd-multimedia@freebsd.org Message-Id: <20070702231157.dd465e9f.taku@tackymt.homeip.net> Organization: Trans New Technology, Inc. X-Mailer: Sylpheed 2.4.2 (GTK+ 2.10.13; i386-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Mon__2_Jul_2007_23_11_57_+0900_ZHkOoSDFApI.I+6I" X-Virus-Scanned: amavisd-new at tackymt.homeip.net Subject: [PATCH] snd_hda resume + MSI X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2007 14:33:37 -0000 This is a multi-part message in MIME format. --Multipart=_Mon__2_Jul_2007_23_11_57_+0900_ZHkOoSDFApI.I+6I Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Greetings, I've made a couple of patches for snd_hda: 1. It reinitializes the hardware after resume. Otherwise my ThinkPad X60 won't make a noise after resume. 2. It utilizes MSI for interrupt delivery. To isolate the interrupt line shared with MP-unsafe devices such as uhci. Neither patches are depending on each other; one can apply either one without another. Of cource, both of the two can be applied at the same time. Enjoy! -- YAMAMOTO, Taku --Multipart=_Mon__2_Jul_2007_23_11_57_+0900_ZHkOoSDFApI.I+6I Content-Type: text/x-diff; name="snd_hda-resume.patch" Content-Disposition: attachment; filename="snd_hda-resume.patch" Content-Transfer-Encoding: 7bit --- sys/dev/sound/pci/hda/hdac.c.orig Sun Jan 28 12:16:54 2007 +++ sys/dev/sound/pci/hda/hdac.c Sun Feb 4 16:46:32 2007 @@ -5370,11 +5370,95 @@ hdac_detach(device_t dev) return (0); } +#if 0 +/**************************************************************************** + * int hdac_suspend(device_t) + * + * Prepare for system suspending. + * Stops all DMA engines and interrupts for the safety. + ****************************************************************************/ +static int +hdac_suspend(device_t dev) +{ + struct hdac_softc *sc = NULL; + struct hdac_devinfo *devinfo = NULL; + + devinfo = (struct hdac_devinfo *)pcm_getdevinfo(dev); + if (devinfo != NULL && devinfo->codec != NULL) + sc = devinfo->codec->sc; + if (sc == NULL) + return (0); + + hdac_lock(sc); + hdac_reset(sc); + /* XXX - TODO: stop playback and record channels if running */ + hdac_unlock(sc); + + return (0); +} +#endif + +/**************************************************************************** + * int hdac_resume(device_t) + * + * Bring the card back to the operational state. + * What we do is basically the same what hdac_attach() and hdac_attach2() do, + * sans descriptor parsing and node-graph reconstruction. + ****************************************************************************/ +static int +hdac_resume(device_t dev) +{ + struct hdac_softc *sc = NULL; + struct hdac_devinfo *devinfo = NULL; + + devinfo = pcm_getdevinfo(dev); + if (devinfo != NULL && devinfo->codec != NULL) + sc = devinfo->codec->sc; + if (sc == NULL) + return (0); + hdac_lock(sc); + + /* Quiesce everything */ + hdac_reset(sc); + + /* Disable PCI-Express QOS */ + pci_write_config(sc->dev, 0x44, + pci_read_config(sc->dev, 0x44, 1) & 0xf8, 1); + + /* Initialize the CORB and RIRB */ + hdac_corb_init(sc); + hdac_rirb_init(sc); + + /* Restart the CORB and RIRB engines */ + hdac_corb_start(sc); + hdac_rirb_start(sc); + if (sc->polling == 0) + HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, + HDAC_INTCTL_CIE | HDAC_INTCTL_GIE); + HDAC_WRITE_4(&sc->mem, HDAC_GCTL, HDAC_READ_4(&sc->mem, HDAC_GCTL) | + HDAC_GCTL_UNSOL); + + DELAY(1000); + + hdac_audio_commit(devinfo, HDA_COMMIT_ALL); + hdac_audio_ctl_commit(devinfo); + + /* XXX - TODO: restart playback and/or record channels if necessary */ + + hdac_unlock(sc); + + /*mixer_reinit(dev);*/ + + return (0); +} + static device_method_t hdac_methods[] = { /* device interface */ DEVMETHOD(device_probe, hdac_probe), DEVMETHOD(device_attach, hdac_attach), DEVMETHOD(device_detach, hdac_detach), + /*DEVMETHOD(device_suspend, hdac_suspend),*/ + DEVMETHOD(device_resume, hdac_resume), { 0, 0 } }; --Multipart=_Mon__2_Jul_2007_23_11_57_+0900_ZHkOoSDFApI.I+6I Content-Type: text/x-diff; name="snd_hda-msi.patch" Content-Disposition: attachment; filename="snd_hda-msi.patch" Content-Transfer-Encoding: 7bit --- sys/dev/sound/pci/hda/hdac.c.orig Sun Jan 28 12:16:54 2007 +++ sys/dev/sound/pci/hda/hdac.c Wed Feb 14 05:07:01 2007 @@ -1297,9 +1297,14 @@ hdac_irq_alloc(struct hdac_softc *sc) { struct hdac_irq *irq; int result; + int msicnt; irq = &sc->irq; - irq->irq_rid = 0x0; + msicnt = pci_msi_count(sc->dev); + if (msicnt == 1 && pci_alloc_msi(sc->dev, &msicnt) == 0) + irq->irq_rid = 0x1; + else + irq->irq_rid = 0x0; irq->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, &irq->irq_rid, RF_SHAREABLE | RF_ACTIVE); if (irq->irq_res == NULL) { @@ -1340,6 +1345,8 @@ 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 (irq->irq_rid == 0x01) + pci_release_msi(sc->dev); irq->irq_handle = NULL; irq->irq_res = NULL; } --Multipart=_Mon__2_Jul_2007_23_11_57_+0900_ZHkOoSDFApI.I+6I--