From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 21 20:09:53 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDE40106576A for ; Wed, 21 Jan 2009 20:09:53 +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 9E9548FC22 for ; Wed, 21 Jan 2009 20:09:53 +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 3343D46B32; Wed, 21 Jan 2009 15:09:53 -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 n0LK9NdU035728; Wed, 21 Jan 2009 15:09:47 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Wed, 21 Jan 2009 14:08:37 -0500 User-Agent: KMail/1.9.7 References: <20081216230430.GA24352@curry.mchp.siemens.de> <20081223173322.GA4123@curry.mchp.siemens.de> In-Reply-To: <20081223173322.GA4123@curry.mchp.siemens.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901211408.37883.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, 21 Jan 2009 15:09:47 -0500 (EST) X-Virus-Scanned: ClamAV 0.94.2/8885/Wed Jan 21 12:48:08 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: Andre Albsmeier Subject: Re: How to "detach" a foreign driver from a device so my driver can attach? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2009 20:09:54 -0000 On Tuesday 23 December 2008 12:33:22 pm Andre Albsmeier wrote: > On Wed, 17-Dec-2008 at 00:04:30 +0100, Andre Albsmeier wrote: > > Hello all, > > > > I am writing a driver which attaches to the Host-PCI bridge. When > > compiled into the kernel or loaded by the loader everything works > > and the driver gets attached. This is due to the fact that I return > > BUS_PROBE_SPECIFIC in my probe routine which gains over the -10000 > > returned by pci_hostb_probe() in i386/pci/pci_bus.c. > > > > However, when I want to load my driver via kldload this fails since > > the hostb device has already been attached during kernel load (when > > my driver was not present): > > > > hostb0@pci0:0:0: class=0x060000 card=0x11d510cf chip=0x35808086 rev=0x02 hdr=0x00 > > > > What can I do to make my driver load via kldload? > > Is there a way to detach the hostb0 from the Host-PCI bridge? > > Found the answer myself but will post it here in case anyone > got a similar problem one day: I added the device detach method > for the hostb driver to sys/i386/pci/pci_bus.c: > > --- sys/i386/pci/pci_bus.c.ORI 2007-08-17 08:12:33.000000000 +0200 > +++ sys/i386/pci/pci_bus.c 2008-12-23 13:34:35.000000000 +0100 > @@ -619,10 +619,13 @@ > return 0; > } > > +static int pci_hostb_detach(device_t dev) { return 0; } > + > static device_method_t pci_hostb_methods[] = { > /* Device interface */ > DEVMETHOD(device_probe, pci_hostb_probe), > DEVMETHOD(device_attach, pci_hostb_attach), > + DEVMETHOD(device_detach, pci_hostb_detach), > DEVMETHOD(device_shutdown, bus_generic_shutdown), > DEVMETHOD(device_suspend, bus_generic_suspend), > DEVMETHOD(device_resume, bus_generic_resume), > > Now, when kldload'ing my driver, it can walk through all devices > and detach hostb using device_detach(). In the case of hostb, this is wrong however. You want to attach as a child of hostb as other devices (e.g. agp(4)) need to attach to host-pci bridges as well. -- John Baldwin