Date: Wed, 21 Dec 2011 01:37:37 -0700 From: ss griffon <ssgriffonuser@gmail.com> To: freebsd-drivers@freebsd.org Subject: Re: Attaching pseudo bus to i386 nexus bus. Message-ID: <CAFYJ9eiNnL_eQC2TYAMGb0%2BZqmjb=tzG5Qszf5h6KXES1QQWkw@mail.gmail.com> In-Reply-To: <CAFYJ9ehmS=QAW0aHD8jwaptUsbZuDsS98kL2AL_4Pd1AbcEL6Q@mail.gmail.com> References: <CAFYJ9ehmS=QAW0aHD8jwaptUsbZuDsS98kL2AL_4Pd1AbcEL6Q@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 20, 2011 at 8:55 PM, ss griffon <ssgriffonuser@gmail.com> 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 <dev/sound/pcm/sound.h> > #include <dev/sound/pcm/pcm.h> > > #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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFYJ9eiNnL_eQC2TYAMGb0%2BZqmjb=tzG5Qszf5h6KXES1QQWkw>