From owner-freebsd-current@FreeBSD.ORG Wed Mar 4 15:34:17 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CEAD2106567E for ; Wed, 4 Mar 2009 15:34:17 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 90DB58FC2F for ; Wed, 4 Mar 2009 15:34:17 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (pool-98-109-39-197.nwrknj.fios.verizon.net [98.109.39.197]) by cyrus.watson.org (Postfix) with ESMTPSA id 2557046B55; Wed, 4 Mar 2009 10:34:17 -0500 (EST) Received: from localhost (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.3/8.14.3) with ESMTP id n24FYBcO095933; Wed, 4 Mar 2009 10:34:11 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-current@freebsd.org Date: Wed, 4 Mar 2009 10:34:06 -0500 User-Agent: KMail/1.9.7 References: <49ADE16C.9030805@protected-networks.net> <200903041011.24606.jhb@freebsd.org> In-Reply-To: <200903041011.24606.jhb@freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200903041034.06931.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Wed, 04 Mar 2009 10:34:11 -0500 (EST) X-Virus-Scanned: ClamAV 0.94.2/9067/Wed Mar 4 05:06:09 2009 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Michael Butler Subject: Re: pci regression: "panic: resource_list_alloc: resource entry is busy" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Mar 2009 15:34:19 -0000 On Wednesday 04 March 2009 10:11:24 am John Baldwin wrote: > On Tuesday 03 March 2009 9:03:24 pm Michael Butler wrote: > > Post SVN rev 189306 on my Toshiba laptop, I get a bootstrap panic as > > follows: > > > > vgapci0: port 0x1800-0x1807 > > mem 0xf0a00000-0xf0a7ffff,0xd0000000-0xdfffffff, > > 0xf0b00000-0xf0b3ffff > > irq 16 at device 2.0 on pci0 > > acpi_video0: on vgapci0 > > found VGA CRT or VESA Compatible Analog Monitor(100), idx#0, > > port#0, detectable by BIOS, head #0 > > found TV/HDTV or Analog-Video Monitor(200), idx#0, > > port#0, detectable by BIOS, head #0 > > found Internal/Integrated Digital Flat Panel(400), idx#0, > > port#0, detectable by BIOS, head #0 > > agp0: on vgapci0 > > vgapci0: Reserved 0x10000000 bytes for rid 0x18 type 3 at 0xd0000000 > > vgapci0: Reserved 0x80000 bytes for rid 0x10 type 3 at 0xf0a00000 > > vgapci0: Reserved 0x40000 bytes for rid 0x1c type 3 at 0xf0b00000 > > agp0: detected 7932k stolen memory > > agp0: aperture size is 256M > > drm0: on vgapci0 > > > > <<< fails here with "panic: resource_list_alloc: resource entry is busy" > > > > vgapci0: Reserved 0x80000 bytes for rid 0x10 type 3 at 0xf0a00000 > > vgapci0: child drm0 requested pci_enable_busmaster > > info: [drm] AGP at 0xd0000000 256MB > > info: [drm] Initialized i915 1.6.0 20080730 > > vgapci1: mem 0xf0a80000-0xf0afffff at > > device 2.1 on pci0 > > > > Presumably, the agp/drm interaction with vgapci resources prompts this :-( > > Hmmm, so the issue is that agp0 and drm0 are both allocating the same BAR. I > can probably make this work with some patches to vgapci to have it proxy the > requests and share the resources. Probably at some point the agp and drm drivers for Intel will be merged which would fix this, but this patch should help for now. We used to be leaking a small portion of KVA due to this problem before. --- //depot/vendor/freebsd/src/sys/dev/pci/vga_pci.c 2008/09/19 19:15:30 +++ //depot/user/jhb/acpipci/dev/pci/vga_pci.c 2009/03/04 15:32:08 @@ -42,12 +42,20 @@ #include #include #include +#include +#include #include #include +struct vga_resource { + struct resource *vr_res; + int vr_refs; +}; + struct vga_pci_softc { device_t vga_msi_child; /* Child driver using MSI. */ + struct vga_resource vga_res[PCIR_MAX_BAR_0 + 1]; }; static int @@ -130,7 +138,27 @@ vga_pci_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { + struct vga_pci_softc *sc; + int bar; + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + /* + * For BARs, we cache the resource so that we only allocate it + * from the PCI bus once. + */ + bar = PCI_RID2BAR(*rid); + if (bar < 0 || bar > PCIR_MAX_BAR_0) + return (NULL); + sc = device_get_softc(dev); + if (sc->vga_res[bar].vr_res == NULL) + sc->vga_res[bar].vr_res = bus_alloc_resource(dev, type, + rid, start, end, count, flags); + if (sc->vga_res[bar].vr_res != NULL) + sc->vga_res[bar].vr_refs++; + return (sc->vga_res[bar].vr_res); + } return (bus_alloc_resource(dev, type, rid, start, end, count, flags)); } @@ -138,6 +166,37 @@ vga_pci_release_resource(device_t dev, device_t child, int type, int rid, struct resource *r) { + struct vga_pci_softc *sc; + int bar, error; + + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + /* + * For BARs, we release the resource from the PCI bus + * when the last child reference goes away. + */ + bar = PCI_RID2BAR(rid); + if (bar < 0 || bar > PCIR_MAX_BAR_0) + return (EINVAL); + sc = device_get_softc(dev); + if (sc->vga_res[bar].vr_res == NULL) + return (EINVAL); + KASSERT(sc->vga_res[bar].vr_res == r, + ("vga_pci resource mismatch")); + if (sc->vga_res[bar].vr_refs > 1) { + sc->vga_res[bar].vr_refs--; + return (0); + } + KASSERT(sc->vga_res[bar].vr_refs > 0, + ("vga_pci resource reference count underflow")); + error = bus_release_resource(dev, type, rid, r); + if (error == 0) { + sc->vga_res[bar].vr_res = NULL; + sc->vga_res[bar].vr_refs = 0; + } + return (error); + } return (bus_release_resource(dev, type, rid, r)); } -- John Baldwin