From owner-freebsd-drivers@FreeBSD.ORG Wed Dec 21 04:24:28 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1CE6A1065686 for ; Wed, 21 Dec 2011 04:24:28 +0000 (UTC) (envelope-from ssgriffonuser@gmail.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id E158F8FC12 for ; Wed, 21 Dec 2011 04:24:27 +0000 (UTC) Received: by iadj38 with SMTP id j38so10889222iad.13 for ; Tue, 20 Dec 2011 20:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=QhgIQLrsomOfjdYktKbJE184evoD5uYNdZ5r05y8w3Q=; b=cU/vzv5NEyta6skAKLr8QlRQCW7D7QtwJmcwZWP7nadzwbhwg6w/K+aQuKEvXr+RJB LQ9+sFwpvvgahfH816HP+91egOMzkWOHqlTiTgflWevRdM28TRQMB3/Zq0Qfn9m8gSes zlkzb+iX2Ywh6Js0Za5WczSmSdpqujKP+a0Bk= MIME-Version: 1.0 Received: by 10.42.164.71 with SMTP id f7mr4917257icy.49.1324439719776; Tue, 20 Dec 2011 19:55:19 -0800 (PST) Received: by 10.42.117.74 with HTTP; Tue, 20 Dec 2011 19:55:19 -0800 (PST) Date: Tue, 20 Dec 2011 20:55:19 -0700 Message-ID: From: ss griffon To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Attaching pseudo bus to i386 nexus bus. X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2011 04:24:28 -0000 I've been playing around with the hdac sound driver and as an exercise I decided to make my own "pseudo" pcm driver. =A0However, I can't seem to get my device_probe and device_attach functions to be called on my "pseudo" bus driver. =A0I've spent a lot of time looking at the bus code in kernel/subr_bus.c and I think I have a good understanding of it but apparently not good enough. =A0I've looked at other devices that implement buses, such as hdac, pci and acpi (which hangs off of nexus as well) and I can't find what they are doing to make their device_probe/device_attach to be called. =A0Perhaps my driver is missing a reference to a parent? =A0Anyway, any help would be greatly appreciated, maybe it is something very obvious. =A0I turned on the BUS_DEBUG option and provide it's output along with the code. Code: #ifdef HAVE_KERNEL_OPTION_HEADERS #include "opt_snd.h" #endif #include #include #include "device_if.h" #include "bus_if.h" #include "mixer_if.h" static int snd_loop_bus_probe(device_t dev) { printf("%s %d called\n", __func__, __LINE__); return 0; } static int snd_loop_bus_attach(device_t dev) { printf("%s %d called\n", __func__, __LINE__); return 0; } static void snd_loop_bus_driver_added(device_t dev, driver_t *driver) { printf("%s %d called\n", __func__, __LINE__); } static device_method_t snd_loop_bus_methods[] =3D { DEVMETHOD(device_probe, snd_loop_bus_probe), DEVMETHOD(device_attach, snd_loop_bus_attach), /*Bus Interface*/ DEVMETHOD(bus_driver_added, snd_loop_bus_driver_added), { 0, 0 } }; static driver_t snd_loop_bus_driver =3D { "snd_loop_bus", snd_loop_bus_methods, PCM_SOFTC_SIZE, /*This isn't used, should be 1*/ }; devclass_t snd_loop_bus_devclass; DRIVER_MODULE(snd_loop_bus, nexus, snd_loop_bus_driver, snd_loop_bus_devclass, 0, 0); BUS_DEBUG Output: devclass_find_internal:914: looking for nexus driver_module_handler:4462: Loading module: driver snd_loop_bus on bus nexus (pass 2147483647) devclass_add_driver:1047: snd_loop_bus devclass_find_internal:914: looking for snd_loop_bus devclass_find_internal:924: creating snd_loop_bus From owner-freebsd-drivers@FreeBSD.ORG Wed Dec 21 08:37:39 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E34401065686 for ; Wed, 21 Dec 2011 08:37:38 +0000 (UTC) (envelope-from ssgriffonuser@gmail.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id 918718FC16 for ; Wed, 21 Dec 2011 08:37:38 +0000 (UTC) Received: by iadj38 with SMTP id j38so11412857iad.13 for ; Wed, 21 Dec 2011 00:37:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Nlf2pSEV86JZh3DjSrQPxUl7E9JNfbn36cz6QwMyRPI=; b=qBOLOnVXeJRSDVD3q56Jkdj/omy+4cpEUcDMXz7M+/OtMY0jcvlE2EykDFxCPwdty/ JezwdCQPBNsuk8DR733NcTIY+9QbGgSeyjHse2iTGw7dsiUVqSUR9fzJJcMQJYjLvvZw azvbvwRZj6da6w6J6zkVzeyzCF9b49i2tszVI= MIME-Version: 1.0 Received: by 10.50.77.227 with SMTP id v3mr1894550igw.8.1324456657780; Wed, 21 Dec 2011 00:37:37 -0800 (PST) Received: by 10.42.117.74 with HTTP; Wed, 21 Dec 2011 00:37:37 -0800 (PST) In-Reply-To: References: Date: Wed, 21 Dec 2011 01:37:37 -0700 Message-ID: From: ss griffon To: freebsd-drivers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: Attaching pseudo bus to i386 nexus bus. X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2011 08:37:39 -0000 On Tue, Dec 20, 2011 at 8:55 PM, ss griffon wrote= : > I've been playing around with the hdac sound driver and as an exercise > I decided to make my own "pseudo" pcm driver. =A0However, I can't seem > to get my device_probe and device_attach functions to be called on my > "pseudo" bus driver. =A0I've spent a lot of time looking at the bus code > in kernel/subr_bus.c and I think I have a good understanding of it but > apparently not good enough. =A0I've looked at other devices that > implement buses, such as hdac, pci and acpi (which hangs off of nexus > as well) and I can't find what they are doing to make their > device_probe/device_attach to be called. =A0Perhaps my driver is missing > a reference to a parent? =A0Anyway, any help would be greatly > appreciated, maybe it is something very obvious. =A0I turned on the > BUS_DEBUG option and provide it's output along with the code. > > Code: > > #ifdef HAVE_KERNEL_OPTION_HEADERS > #include "opt_snd.h" > #endif > > #include > #include > > #include "device_if.h" > #include "bus_if.h" > #include "mixer_if.h" > > static int > snd_loop_bus_probe(device_t dev) > { > =A0printf("%s %d called\n", __func__, __LINE__); > =A0return 0; > } > > static int > snd_loop_bus_attach(device_t dev) > { > =A0printf("%s %d called\n", __func__, __LINE__); > =A0return 0; > } > > static void > snd_loop_bus_driver_added(device_t dev, driver_t *driver) > { > =A0printf("%s %d called\n", __func__, __LINE__); > } > > static device_method_t snd_loop_bus_methods[] =3D { > =A0DEVMETHOD(device_probe, =A0 =A0 =A0 snd_loop_bus_probe), > =A0DEVMETHOD(device_attach, =A0 =A0 =A0snd_loop_bus_attach), > =A0/*Bus Interface*/ > =A0DEVMETHOD(bus_driver_added, =A0 snd_loop_bus_driver_added), > =A0{ 0, 0 } > }; > > static driver_t snd_loop_bus_driver =3D { > =A0"snd_loop_bus", > =A0snd_loop_bus_methods, > =A0PCM_SOFTC_SIZE, /*This isn't used, should be 1*/ > }; > > devclass_t snd_loop_bus_devclass; > DRIVER_MODULE(snd_loop_bus, nexus, snd_loop_bus_driver, > snd_loop_bus_devclass, 0, 0); > > > > BUS_DEBUG Output: >bus > devclass_find_internal:914: looking for nexus > driver_module_handler:4462: Loading module: driver snd_loop_bus on bus > nexus (pass 2147483647) > devclass_add_driver:1047: snd_loop_bus > devclass_find_internal:914: looking for snd_loop_bus > devclass_find_internal:924: creating snd_loop_bus In case anyone is interested, I got this figured out. If you want to add a device to the nexus bus you must implement the device_identify method. From device identify, you can call BUS_ADD_CHILD and add your driver to the nexus bus. This seems to be necessary for the nexus bus and some other buses that do not implement bus_driver_added which is where buses can probe and attach the driver. So if you add your device to the "pci" bus, your device_probe and device_attach methods will be called automatically. sys/dev/nvram2env is a good simple example of adding a device to the nexus = bus. From owner-freebsd-drivers@FreeBSD.ORG Wed Dec 21 17:43:44 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 935E1106564A for ; Wed, 21 Dec 2011 17:43:44 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id 313D68FC14 for ; Wed, 21 Dec 2011 17:43:44 +0000 (UTC) Received: from [10.30.101.53] ([209.117.142.2]) (authenticated bits=0) by harmony.bsdimp.com (8.14.4/8.14.3) with ESMTP id pBLHZNKr079588 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES128-SHA bits=128 verify=NO); Wed, 21 Dec 2011 10:35:26 -0700 (MST) (envelope-from imp@bsdimp.com) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: Date: Wed, 21 Dec 2011 10:35:18 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <09E51D07-3B6A-4E5C-87D7-BB1C2454969D@bsdimp.com> References: To: ss griffon X-Mailer: Apple Mail (2.1084) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (harmony.bsdimp.com [10.0.0.6]); Wed, 21 Dec 2011 10:35:26 -0700 (MST) Cc: freebsd-drivers@freebsd.org Subject: Re: Attaching pseudo bus to i386 nexus bus. X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2011 17:43:44 -0000 The nexus bus doesn't automatically add children. You need to do that = yourself with an identify routine. Warner On Dec 20, 2011, at 8:55 PM, ss griffon wrote: > I've been playing around with the hdac sound driver and as an exercise > I decided to make my own "pseudo" pcm driver. However, I can't seem > to get my device_probe and device_attach functions to be called on my > "pseudo" bus driver. I've spent a lot of time looking at the bus code > in kernel/subr_bus.c and I think I have a good understanding of it but > apparently not good enough. I've looked at other devices that > implement buses, such as hdac, pci and acpi (which hangs off of nexus > as well) and I can't find what they are doing to make their > device_probe/device_attach to be called. Perhaps my driver is missing > a reference to a parent? Anyway, any help would be greatly > appreciated, maybe it is something very obvious. I turned on the > BUS_DEBUG option and provide it's output along with the code. >=20 > Code: >=20 > #ifdef HAVE_KERNEL_OPTION_HEADERS > #include "opt_snd.h" > #endif >=20 > #include > #include >=20 > #include "device_if.h" > #include "bus_if.h" > #include "mixer_if.h" >=20 > static int > snd_loop_bus_probe(device_t dev) > { > printf("%s %d called\n", __func__, __LINE__); > return 0; > } >=20 > static int > snd_loop_bus_attach(device_t dev) > { > printf("%s %d called\n", __func__, __LINE__); > return 0; > } >=20 > static void > snd_loop_bus_driver_added(device_t dev, driver_t *driver) > { > printf("%s %d called\n", __func__, __LINE__); > } >=20 > static device_method_t snd_loop_bus_methods[] =3D { > DEVMETHOD(device_probe, snd_loop_bus_probe), > DEVMETHOD(device_attach, snd_loop_bus_attach), > /*Bus Interface*/ > DEVMETHOD(bus_driver_added, snd_loop_bus_driver_added), > { 0, 0 } > }; >=20 > static driver_t snd_loop_bus_driver =3D { > "snd_loop_bus", > snd_loop_bus_methods, > PCM_SOFTC_SIZE, /*This isn't used, should be 1*/ > }; >=20 > devclass_t snd_loop_bus_devclass; > DRIVER_MODULE(snd_loop_bus, nexus, snd_loop_bus_driver, > snd_loop_bus_devclass, 0, 0); >=20 >=20 >=20 > BUS_DEBUG Output: >=20 > devclass_find_internal:914: looking for nexus > driver_module_handler:4462: Loading module: driver snd_loop_bus on bus > nexus (pass 2147483647) > devclass_add_driver:1047: snd_loop_bus > devclass_find_internal:914: looking for snd_loop_bus > devclass_find_internal:924: creating snd_loop_bus > _______________________________________________ > freebsd-drivers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-drivers > To unsubscribe, send any mail to = "freebsd-drivers-unsubscribe@freebsd.org" >=20 >=20