From owner-freebsd-drivers@FreeBSD.ORG Wed Oct 19 01:32:26 2005 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EB91616A41F; Wed, 19 Oct 2005 01:32:25 +0000 (GMT) (envelope-from mayong@mail.com) Received: from cal1-1.us4.outblaze.com (cal1-1.us4.outblaze.com [205.158.62.188]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6745343D45; Wed, 19 Oct 2005 01:32:25 +0000 (GMT) (envelope-from mayong@mail.com) Received: (from mdrop@localhost) by cal1-1.us4.outblaze.com (8.11.6/8.11.6) id j9J1WOg16689; Wed, 19 Oct 2005 01:32:24 GMT Message-Id: <200510190132.j9J1WOg16689@cal1-1.us4.outblaze.com> Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 From: "Yong Ma" To: "John Baldwin" , freebsd-drivers@freebsd.org Date: Tue, 18 Oct 2005 20:32:24 -0500 Received: from [159.226.5.225] by cal1-1.us4.outblaze.com with http for mayong@mail.com; Tue, 18 Oct 2005 20:32:24 -0500 X-Originating-Ip: 159.226.5.225 X-Originating-Server: cal1-1.us4.outblaze.com Cc: Subject: Re: Some Questions 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, 19 Oct 2005 01:32:26 -0000 ----- Original Message ----- From: "John Baldwin" To: freebsd-drivers@freebsd.org Subject: Re: Some Questions Date: Tue, 18 Oct 2005 11:17:51 -0400 >=20 > On Tuesday 18 October 2005 04:26 am, Yong Ma wrote: > > Hi everybody: > > > > > > I'm new here,nice to meet you all! I'm also aFreeBSD_device_driver newb= ie, > > and now I'm enaged in writting a driverfor a cryptographic accelerator > > card.As a preparation I read thesections of device driver in "FreeBSD > > Architecture Handbook",andexercised the example driver in the book.now I > > have several questions(maybeeasy for you but most useful for me): > > > > 1)Some drivers declares the device_open() as int device_open(dev_t > > dev,...),and some declare it as int device_open(struct cdev > > *dev,...),sometimes the first one couldn't be compliedsuccessfully,what= 's > > the difference? >=20 > On 6.0 and later you should use 'struct cdev *dev' and on 5.x and earlier > 'dev_t dev'. >=20 > > 2) if (pci_get_vendor(dev) =3D=3D 0x11c1) { ... > > ~~~~~~~~how to get this number if I don't > > know it? >=20 > This number is part of the chip ID in pciconf -l output. For example, on= my > laptop: >=20 > pcib1@pci0:1:0: class=3D0x060400 card=3D0x00000000 chip=3D0x1a318086 rev= =3D0x04 > hdr=3D0x01 >=20 > For this device, pci_get_devid(dev) would return 0x1a318086. > pci_get_vendor(dev) would return the 0x8086 part of that. >=20 > > 3)Could the device on PCI slot be listed by /pciconf -l /without driver. >=20 > You mean cutting out the pcib1 part from the line above? You could alway= s use > something like awk, sed, or cut. For example: >=20 > % pciconf -l | cut -d @ -f 2 > pci0:0:0: class=3D0x060000 card=3D0x56001558 chip=3D0x1a308086 rev= =3D0x04 > hdr=3D0x00 > pci0:1:0: class=3D0x060400 card=3D0x00000000 chip=3D0x1a318086 rev= =3D0x04 > hdr=3D0x01 > pci0:29:0: class=3D0x0c0300 card=3D0x56001558 chip=3D0x24828086 rev= =3D0x02 > hdr=3D0x00 > ... >=20 > > 4)The printf() seems not work under XWindow mode in functions like > > deviec_prob or device_attach,how to make it work? >=20 > Run 'dmesg' in your Xterminal to see the messages. Alternatively, you ca= n use > the 'xconsole' program which should show the messages in its window. >=20 > > 5)If only the pseudo-device in /dev can be destroyed with > > destroy_dev(sc->dev0) in detach() function in a KLD driver? I can't do > > that! >=20 > I'm not sure what you are asking here. You can't leave an entry in /dev > around when your module is unloaded via kldunload since you would be remo= ving > the devsw and devsw functions that back that device resulting in a kernel > panic the next time some process tried to use the /dev entry. What exact > problem are you trying to solve? >=20 There is a make_dev() in the attach() in my test driver,and a destroy_dev()= and a bus_generic_detach() in the detach(),but the later ones seems don't = work when I unload the KLD module,while the make_dev() works properly,so as= I load and unload the module,there are quite a few devices in /dev have th= e same name(for me they are mypci0). Several days ago,I did a driver test of a PSEUDO-DEVICE with the detach() w= orks properly.I wander if it is because of the real HARDWARE device this ti= me ? this is my detach() function: static int mypci_detach(device_t dev) { struct mypci_softc *sc; sc =3D (struct mypci_softc *) device_get_softc(dev); destroy_dev(sc->dev0); bus_generic_detach(dev); bus_release_resource(dev, SYS_RES_IOPORT, sc->rid, sc->res); printf("Mypci detached!\n"); return (0); } > -- > John Baldwin <>< http://www.FreeBSD.org/~jhb/ > "Power Users Use the Power to Serve" =3D http://www.FreeBSD.org Thanks very much Yong --=20 ___________________________________________________ Play 100s of games for FREE! http://games.mail.com/