From owner-freebsd-arch@FreeBSD.ORG Tue May 11 18:02:44 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3EC8416A4CE for ; Tue, 11 May 2004 18:02:44 -0700 (PDT) Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 84AC643D3F for ; Tue, 11 May 2004 18:02:43 -0700 (PDT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 30474 invoked from network); 12 May 2004 01:02:43 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 12 May 2004 01:02:43 -0000 Received: from hydrogen.funkthat.com (felopi@localhost.funkthat.com [127.0.0.1])i4C12fEx098411; Tue, 11 May 2004 18:02:42 -0700 (PDT) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id i4C12eDq098410; Tue, 11 May 2004 18:02:40 -0700 (PDT) Date: Tue, 11 May 2004 18:02:40 -0700 From: John-Mark Gurney To: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= Message-ID: <20040512010240.GD601@funkthat.com> Mail-Followup-To: Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?= , arch@freebsd.org, dfr@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: arch@freebsd.org cc: dfr@freebsd.org Subject: Re: newbus flaw X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 May 2004 01:02:44 -0000 Dag-Erling Smørgrav wrote this message on Tue, May 11, 2004 at 16:39 +0200: > When the driver is unloaded, the device is detached, but it remains on > the bus's list of child devices. The next time the module is loaded, > its DEVICE_IDENTIFY method is called again, and incorrectly adds a > second child device to the bus, because it does not know that one > already exists. > > There is no way for DEVICE_IDENTIFY to check if a matching child > already exists on the bus, or for the module's event handler to unlist > the child when unloading. As someone else points out, this is already a known case and was discusses on -arch a while back. You are incorrect in assuming you can't find out if another child already exists.. Usually this is a problem of properly allocating resources so that you know the other child exists. Since you are using identify, you already don't have a "self describing" bus, which means that you have to either use hints, or another method to make sure that your device doesn't already exist. For example, in my adv717xa driver, part of the zoran driver, I do the following in my _probe routine to prevent probing and attaching to the same chip. /* Make sure this isn't already attached */ if (sibs == NULL) device_get_children(iicbus, &sibs, &sibcnt); for (j = 0; j < sibcnt; j++) { if (device_get_state(sibs[j]) >= DS_ATTACHED && device_get_driver(sibs[j]) == drv && ((struct adv717xa_softc *) device_get_softc(sibs[j]))->adv_slvaddr == chips[i].addr) { device_printf(dev, "already attached at %s\n", device_get_nameunit(sibs[j])); break; } } This should not be a problem because the i2c bus should either do proper resource allocation for the id, which when I try to probe, I allocate the chip id, and that fails, preventing it's creation... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."