Subject: Re: LKM
To: Sander Storms <s.storms@technology.asb.nl>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 10/01/2004 10:04:46
--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Fri, Oct 01, 2004 at 08:48:50AM +0200, Sander Storms wrote:
> Hello,
>=20
> I already posted this message some month ago, but I never got an answer.
> Either I am at the wrong
> mailing-list, or the message did not arrive properly.
> But anyway, here's my question:
>=20
> I want to create a driver for a custom-made PCI-device. This device has
> always been
> put directly into the kernel (NetBSD 1.5.1 back then), and it worked
> properly.
> Now, our software-supplier upgraded to NetBSD 1.6.1 and the driver has to=
be
> rewritten.
> Since 1.6.1 has kernel module support, it is unlogical to hack the driver
> into the kernel again.
I think you need to hack it in. The ability for lkms to find devices on=20
say the PCI bus is much more recent than 1.6.x. Though if you manually=20
rescan, that's ok.
> Here's the problem:
>=20
> In the kernel-version of the software, 3 device-nodes where created:
> 1 for the PCI communication (/dev/pciDevice0) and 2 modem interfaces
> (/dev/modem0 and /dev/modem1),=20
> present on the PCI device.
> If I create a kernel-module, only the 1st device-node (/dev/pciDevice0) w=
ill
> be created :
>=20
> -------------- SAMPLE CODE -------------------
>=20
> MOD_DEV("pciDevice", LM_DT_CHAR, -1, &pciDevice_cdevsw);
>=20
> int device_pci_lkmmatch(struct pci_attach_args *pa)
> {
> if (device_pci_match(NULL, NULL, pa))
> {
> struct device *sc =3D (struct device *) device_lkmalloc();
> if (sc !=3D NULL)
> {
> printf("%s at pci%u", sc->dv_xname, pa->pa_bus);
> pciprint(pa, NULL);
> device_pci_attach(NULL, sc, pa);
> }
> }
>=20
> return 0;
> }
>=20
>=20
> static int device_lkmload(struct lkm_table *lkmt, int cmd)
> {
> int error;
> struct pci_attach_args paa;
> =20
> if (lkmexists(lkmt))
> {
> return (EEXIST);
> }
>=20
> (void)pci_find_device(&paa, device_pci_lkmmatch);
> =20
> if (device_counter =3D=3D 0)
> {
> return(ENXIO);
> }
>=20
> if ((error =3D modemIfattach ()))
> {
> return error;
> }
> return 0;
> }
>=20
> -------------- END SAMPLE CODE -------------------
>=20
> Can anyone tell me how I can create the 2 modem-interfaces, accessed thro=
ugh
> the function "modemIfattach ()" ?
> The 'modload' function returns the major device-number for my PCI-device,
> but NOT for my
> 2 modem-interfaces.
All the lkm helper modules, like the MOD_DEV() macro, are designed for=20
simple cases. Like one device.
If you want to use MOD_DEV, make two lkms, one that depends on the other.=
=20
You use the '-o' option to modload on the first load to generate a file,=20
then use that file as the "kernel" ('-A' option) for the second load.
The alternative is to make one LKM, of type MOD_MISC, and in your handling=
=20
routine duplicate the helper code from MOD_DEV. Just do it twice.
Take care,
Bill
--W/nzBZO5zC0uMSeA
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)
iD8DBQFBXY4uWz+3JHUci9cRAv5bAKCVv4iUPQ1Evok6ogs4xj3cKoKcdgCfRKYE
kKKdImeINGCKNN0M1kuggJs=
=8jcr
-----END PGP SIGNATURE-----
--W/nzBZO5zC0uMSeA--