From owner-freebsd-arch Mon Jun 24 9:24:10 2002 Delivered-To: freebsd-arch@freebsd.org Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by hub.freebsd.org (Postfix) with ESMTP id 554C737B400 for ; Mon, 24 Jun 2002 09:24:05 -0700 (PDT) Received: from mailgate.nlsystems.com ([62.49.251.130] helo=herring.nlsystems.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 17MWcN-0009AH-0U; Mon, 24 Jun 2002 17:23:07 +0100 Received: from herring.nlsystems.com (localhost [127.0.0.1]) by herring.nlsystems.com (8.12.4/8.12.4) with ESMTP id g5O8wmGL028096; Mon, 24 Jun 2002 09:58:48 +0100 (BST) (envelope-from dfr@herring.nlsystems.com) Received: (from dfr@localhost) by herring.nlsystems.com (8.12.4/8.12.4/Submit) id g5O8wmjh028095; Mon, 24 Jun 2002 09:58:48 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Doug Rabson To: "M. Warner Losh" , arch@freebsd.org Subject: Re: It is time to admit that removable devices exist Date: Mon, 24 Jun 2002 09:58:48 +0100 User-Agent: KMail/1.4.1 References: <20020623.171200.96231110.imp@village.org> In-Reply-To: <20020623.171200.96231110.imp@village.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200206240958.48240.dfr@nlsystems.com> Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Monday 24 June 2002 12:12 am, M. Warner Losh wrote: > Please find enclosed the beginnings of a patch to make removable > devices better represented in the system. Right now all it adds is a > mechanism by which client drivers can ask if the device is still > really there or not. > > The new bus_if method would be "child_present". The default, > implemented in the nexus, would return "yes." However, busses that > can have their devices removed, and can have knowledge of such an > event, are expected to override the bus_child_present method. In that > method, they are expected to make the determination, by direct > inspection of the hardware if possible, if the device is really there > or not. > > child_present is expected to return 0 when the device is gone, and a > -1 when the device is present. This also happens to be binary > compatible with old releases since when you call a method that isn't > in a device's method table, it return ENXIO. This is non-zero and is > the most compatible thing you can return. Drivers that wish to cope > on their own with systems too old to have this call can check for 0 or > -1 directly and if not one of those two methods, they are free to > adopt their own ad-hoc methods for dealing. I expect there to be no > such drivers, but it never hurts to design for them. Most client > drivers will check for =3D=3D 0 or !=3D 0. > > Why do we need this? Many device drivers do not properly deal with > device gone conditions. When the device disappears, they either loop > forever waiting for a bit to clear, or they have some kind of kludge > that prevents this from happening (0xff is magic, limits on the number > of loops, etc). It would be much cleaner if a device had a > bus-independent way to ask these questions. > > I plan to implement this for both OLDCARD/NEWCARD soon, and also to > MFC it into -stable since it is useful and also backwards compatible. > It will likely be one of the last things that I do to OLDCARD. > > Comments? In your implementation of bus_generic_child_present, you pass the origina= l=20 device to the parent bus' child_present method. The idea of cascading the= =20 request is a good one (e.g. the phy of a cardbus ethernet card is clearly= not=20 present if the card itself isn't present). It might be better for the bus= =20 implementation though if you pass the bus rather than the original child=20 device, e.g.: int +bus_generic_child_present(device_t bus, device_t child) +{ +=09return (BUS_CHILD_PRESENT(device_get_parent(bus), bus)); +} This would give the parent bus enough information to find the ivars etc. = to=20 make a decision about whether 'bus' is still present. --=20 Doug Rabson=09=09=09=09Mail: dfr@nlsystems.com =09=09=09=09=09Phone: +44 20 8348 6160 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message