From owner-freebsd-drivers@FreeBSD.ORG Tue Oct 18 15:50:50 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 B7BD316A424 for ; Tue, 18 Oct 2005 15:50:50 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from mv.twc.weather.com (mv.twc.weather.com [65.212.71.225]) by mx1.FreeBSD.org (Postfix) with ESMTP id 122FD43D45 for ; Tue, 18 Oct 2005 15:50:49 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from [10.50.41.234] (Not Verified[10.50.41.234]) by mv.twc.weather.com with NetIQ MailMarshal (v6, 0, 3, 8) id ; Tue, 18 Oct 2005 12:07:16 -0400 From: John Baldwin To: freebsd-drivers@freebsd.org Date: Tue, 18 Oct 2005 11:17:51 -0400 User-Agent: KMail/1.8.2 References: <200510180826.j9I8Quw26871@cal1-1.us4.outblaze.com> In-Reply-To: <200510180826.j9I8Quw26871@cal1-1.us4.outblaze.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510181117.52583.jhb@freebsd.org> 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: Tue, 18 Oct 2005 15:50:50 -0000 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 newbie, > 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? On 6.0 and later you should use 'struct cdev *dev' and on 5.x and earlier 'dev_t dev'. > 2) if (pci_get_vendor(dev) == 0x11c1) { ... > ~~~~~~~~how to get this number if I don't > know it? This number is part of the chip ID in pciconf -l output. For example, on my laptop: pcib1@pci0:1:0: class=0x060400 card=0x00000000 chip=0x1a318086 rev=0x04 hdr=0x01 For this device, pci_get_devid(dev) would return 0x1a318086. pci_get_vendor(dev) would return the 0x8086 part of that. > 3)Could the device on PCI slot be listed by /pciconf -l /without driver. You mean cutting out the pcib1 part from the line above? You could always use something like awk, sed, or cut. For example: % pciconf -l | cut -d @ -f 2 pci0:0:0: class=0x060000 card=0x56001558 chip=0x1a308086 rev=0x04 hdr=0x00 pci0:1:0: class=0x060400 card=0x00000000 chip=0x1a318086 rev=0x04 hdr=0x01 pci0:29:0: class=0x0c0300 card=0x56001558 chip=0x24828086 rev=0x02 hdr=0x00 ... > 4)The printf() seems not work under XWindow mode in functions like > deviec_prob or device_attach,how to make it work? Run 'dmesg' in your Xterminal to see the messages. Alternatively, you can use the 'xconsole' program which should show the messages in its window. > 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! 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 removing 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? -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve" = http://www.FreeBSD.org