From owner-freebsd-drivers@FreeBSD.ORG Mon Jul 20 21:35:58 2009 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 429FE106564A for ; Mon, 20 Jul 2009 21:35:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 1782F8FC15 for ; Mon, 20 Jul 2009 21:35:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id CAC1046B53; Mon, 20 Jul 2009 17:35:57 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 0A91F8A09D; Mon, 20 Jul 2009 17:35:57 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Mon, 20 Jul 2009 09:58:48 -0400 User-Agent: KMail/1.9.7 References: <002801ca06f0$b1d42af0$157c80d0$@net> In-Reply-To: <002801ca06f0$b1d42af0$157c80d0$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907200958.49119.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 20 Jul 2009 17:35:57 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.0 required=4.2 tests=AWL,BAYES_00, DATE_IN_PAST_06_12,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: Driver development question 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: Mon, 20 Jul 2009 21:35:58 -0000 On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > Hi All, > > I'm hoping someone can point me in the right direction... I'm developing a > FreeBSD driver for a PCIe card. The driver controls a hardware device that > has DRAM and various state information on it. I'm trying to mimic > functionality I have for other OS support such that I can dump memory and > state information from the card to a file I create from within my driver > (kernel module). > > For example, in a Linux driver I use filp_open to create the dump file > (represented by fp), then use fp->f_op->write to put information into the > file. > > FreeBSD doesn't have filp_* API's. I've tried searching for example drivers > and googling for file API's from kernel modules to no avail. Can someone > please offer some guidance as to how I might proceed here? > > Thanks in advance and any insight would be most appreciated! You can look at sys/kern/kern_ktrace.c to see how the ktrace() system call creates a file. I think in general you will wind up using NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / vn_rdwr() / vn_close(). -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Mon Jul 20 23:17:58 2009 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 1C3AC106566B for ; Mon, 20 Jul 2009 23:17:58 +0000 (UTC) (envelope-from sam@errno.com) Received: from ebb.errno.com (ebb.errno.com [69.12.149.25]) by mx1.freebsd.org (Postfix) with ESMTP id E88118FC23 for ; Mon, 20 Jul 2009 23:17:57 +0000 (UTC) (envelope-from sam@errno.com) Received: from ice.local ([10.0.0.115]) (authenticated bits=0) by ebb.errno.com (8.13.6/8.12.6) with ESMTP id n6KMcumK011935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 20 Jul 2009 15:38:57 -0700 (PDT) (envelope-from sam@errno.com) Message-ID: <4A64F200.2060900@errno.com> Date: Mon, 20 Jul 2009 15:38:56 -0700 From: Sam Leffler User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: John Baldwin References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907200958.49119.jhb@freebsd.org> In-Reply-To: <200907200958.49119.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-DCC-x.dcc-servers-Metrics: ebb.errno.com; whitelist Cc: freebsd-drivers@freebsd.org Subject: Re: Driver development question 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: Mon, 20 Jul 2009 23:17:58 -0000 John Baldwin wrote: > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: >> Hi All, >> >> I'm hoping someone can point me in the right direction... I'm developing a >> FreeBSD driver for a PCIe card. The driver controls a hardware device that >> has DRAM and various state information on it. I'm trying to mimic >> functionality I have for other OS support such that I can dump memory and >> state information from the card to a file I create from within my driver >> (kernel module). >> >> For example, in a Linux driver I use filp_open to create the dump file >> (represented by fp), then use fp->f_op->write to put information into the >> file. >> >> FreeBSD doesn't have filp_* API's. I've tried searching for example drivers >> and googling for file API's from kernel modules to no avail. Can someone >> please offer some guidance as to how I might proceed here? >> >> Thanks in advance and any insight would be most appreciated! > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() system call > creates a file. I think in general you will wind up using NDINIT/namei() (to > lookup the vnode for a pathname) and then vn_open() / vn_rdwr() / vn_close(). > man alq(9). Sam From owner-freebsd-drivers@FreeBSD.ORG Tue Jul 21 06:53:01 2009 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 2DD7B106564A for ; Tue, 21 Jul 2009 06:53:01 +0000 (UTC) (envelope-from prvs=145303d3f5=marc.loerner@hob.de) Received: from mailgate.hob.de (mailgate.hob.de [212.185.199.3]) by mx1.freebsd.org (Postfix) with ESMTP id E25FF8FC0A for ; Tue, 21 Jul 2009 06:53:00 +0000 (UTC) (envelope-from prvs=145303d3f5=marc.loerner@hob.de) Received: from imap.hob.de (mail2.hob.de [172.25.1.102]) by mailgate.hob.de (Postfix) with ESMTP id 17BD1520017 for ; Tue, 21 Jul 2009 08:35:25 +0200 (CEST) Received: from linux05.localnet (linux05.hob.de [172.22.0.196]) by imap.hob.de (Postfix on SuSE eMail Server 2.0) with ESMTP id DF340FD8CF for ; Tue, 21 Jul 2009 08:35:24 +0200 (CEST) From: Marc Loerner To: freebsd-drivers@freebsd.org Date: Tue, 21 Jul 2009 08:34:21 +0200 User-Agent: KMail/1.10.4 (Linux/2.6.27-14-server; KDE/4.1.4; x86_64; ; ) References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907200958.49119.jhb@freebsd.org> <4A64F200.2060900@errno.com> In-Reply-To: <4A64F200.2060900@errno.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907210834.21541.marc.loerner@hob.de> Subject: Re: Driver development question 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, 21 Jul 2009 06:53:01 -0000 Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > John Baldwin wrote: > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > >> Hi All, > >> > >> I'm hoping someone can point me in the right direction... I'm > >> developing a FreeBSD driver for a PCIe card. The driver controls a > >> hardware device that has DRAM and various state information on it. I'm > >> trying to mimic functionality I have for other OS support such that I > >> can dump memory and state information from the card to a file I create > >> from within my driver (kernel module). > >> > >> For example, in a Linux driver I use filp_open to create the dump file > >> (represented by fp), then use fp->f_op->write to put information into > >> the file. > >> > >> FreeBSD doesn't have filp_* API's. I've tried searching for example > >> drivers and googling for file API's from kernel modules to no avail. > >> Can someone please offer some guidance as to how I might proceed here? > >> > >> Thanks in advance and any insight would be most appreciated! > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() system > > call creates a file. I think in general you will wind up using > > NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / > > vn_rdwr() / vn_close(). > > man alq(9). > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? Regards, Marc From owner-freebsd-drivers@FreeBSD.ORG Tue Jul 21 11:11:31 2009 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 761B61065677 for ; Tue, 21 Jul 2009 11:11:31 +0000 (UTC) (envelope-from charrer@alacritech.com) Received: from smtp135.iad.emailsrvr.com (smtp135.iad.emailsrvr.com [207.97.245.135]) by mx1.freebsd.org (Postfix) with ESMTP id 3A7888FC08 for ; Tue, 21 Jul 2009 11:11:31 +0000 (UTC) (envelope-from charrer@alacritech.com) Received: from relay23.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay23.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 8D5921B4079; Tue, 21 Jul 2009 06:55:13 -0400 (EDT) Received: by relay23.relay.iad.mlsrvr.com (Authenticated sender: charrer-AT-alacritech.com) with ESMTPA id 77A321B4072; Tue, 21 Jul 2009 06:55:13 -0400 (EDT) From: "Christopher J. Harrer" To: "'Marc Loerner'" , References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907200958.49119.jhb@freebsd.org> <4A64F200.2060900@errno.com> <200907210834.21541.marc.loerner@hob.de> In-Reply-To: <200907210834.21541.marc.loerner@hob.de> Date: Tue, 21 Jul 2009 06:55:26 -0400 Message-ID: <081601ca09f1$c1458ed0$43d0ac70$@com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcoJz+87ENR0XiwATFeGv39Bv8l9cgAIa5vQ Content-Language: en-us Cc: Subject: RE: Driver development question 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, 21 Jul 2009 11:11:31 -0000 > -----Original Message----- > From: owner-freebsd-drivers@freebsd.org [mailto:owner-freebsd- > drivers@freebsd.org] On Behalf Of Marc Loerner > Sent: Tuesday, July 21, 2009 2:34 AM > To: freebsd-drivers@freebsd.org > Subject: Re: Driver development question > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > John Baldwin wrote: > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > >> Hi All, > > >> > > >> I'm hoping someone can point me in the right direction... I'm > > >> developing a FreeBSD driver for a PCIe card. The driver controls > a > > >> hardware device that has DRAM and various state information on it. > I'm > > >> trying to mimic functionality I have for other OS support such > that I > > >> can dump memory and state information from the card to a file I > create > > >> from within my driver (kernel module). > > >> > > >> For example, in a Linux driver I use filp_open to create the dump > file > > >> (represented by fp), then use fp->f_op->write to put information > into > > >> the file. > > >> > > >> FreeBSD doesn't have filp_* API's. I've tried searching for > example > > >> drivers and googling for file API's from kernel modules to no > avail. > > >> Can someone please offer some guidance as to how I might proceed > here? > > >> > > >> Thanks in advance and any insight would be most appreciated! > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() > system > > > call creates a file. I think in general you will wind up using > > > NDINIT/namei() (to lookup the vnode for a pathname) and then > vn_open() / > > > vn_rdwr() / vn_close(). > > > > man alq(9). > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > Regards, > Marc Thanks for the suggestions everyone, I will be investigating more today. I appreciate all the pointers! Cheers, Chris From owner-freebsd-drivers@FreeBSD.ORG Tue Jul 21 21:43:53 2009 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 2F61A106564A for ; Tue, 21 Jul 2009 21:43:52 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id BFC8B8FC0C for ; Tue, 21 Jul 2009 21:43:52 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 5E26446B2C; Tue, 21 Jul 2009 17:43:52 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 862728A09F; Tue, 21 Jul 2009 17:43:51 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Tue, 21 Jul 2009 17:43:12 -0400 User-Agent: KMail/1.9.7 References: <002801ca06f0$b1d42af0$157c80d0$@net> <4A64F200.2060900@errno.com> <200907210834.21541.marc.loerner@hob.de> In-Reply-To: <200907210834.21541.marc.loerner@hob.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907211743.12667.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Tue, 21 Jul 2009 17:43:51 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: Driver development question 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, 21 Jul 2009 21:43:53 -0000 On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > John Baldwin wrote: > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > >> Hi All, > > >> > > >> I'm hoping someone can point me in the right direction... I'm > > >> developing a FreeBSD driver for a PCIe card. The driver controls a > > >> hardware device that has DRAM and various state information on it. I'm > > >> trying to mimic functionality I have for other OS support such that I > > >> can dump memory and state information from the card to a file I create > > >> from within my driver (kernel module). > > >> > > >> For example, in a Linux driver I use filp_open to create the dump file > > >> (represented by fp), then use fp->f_op->write to put information into > > >> the file. > > >> > > >> FreeBSD doesn't have filp_* API's. I've tried searching for example > > >> drivers and googling for file API's from kernel modules to no avail. > > >> Can someone please offer some guidance as to how I might proceed here? > > >> > > >> Thanks in advance and any insight would be most appreciated! > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() system > > > call creates a file. I think in general you will wind up using > > > NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / > > > vn_rdwr() / vn_close(). > > > > man alq(9). > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? Those affect the state of the current process by opening a new file descriptor, etc. That is generally bad practice for a device driver to be interfering with a process' state, and it will not work for kernel threads. You can rather easily have userland open a file and then pass the file descriptor to a driver which can then do operations on a file directly. -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 22 00:24:40 2009 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 3228E106566C for ; Wed, 22 Jul 2009 00:24:40 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 206158FC08 for ; Wed, 22 Jul 2009 00:24:39 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id 5FF671A3C3E; Tue, 21 Jul 2009 17:07:13 -0700 (PDT) Date: Tue, 21 Jul 2009 17:07:13 -0700 From: Alfred Perlstein To: John Baldwin Message-ID: <20090722000713.GZ49724@elvis.mu.org> References: <002801ca06f0$b1d42af0$157c80d0$@net> <4A64F200.2060900@errno.com> <200907210834.21541.marc.loerner@hob.de> <200907211743.12667.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907211743.12667.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: freebsd-drivers@freebsd.org Subject: Re: Driver development question 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, 22 Jul 2009 00:24:40 -0000 * John Baldwin [090721 14:44] wrote: > On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > > John Baldwin wrote: > > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > > >> Hi All, > > > >> > > > >> I'm hoping someone can point me in the right direction... I'm > > > >> developing a FreeBSD driver for a PCIe card. The driver controls a > > > >> hardware device that has DRAM and various state information on it. I'm > > > >> trying to mimic functionality I have for other OS support such that I > > > >> can dump memory and state information from the card to a file I create > > > >> from within my driver (kernel module). > > > >> > > > >> For example, in a Linux driver I use filp_open to create the dump file > > > >> (represented by fp), then use fp->f_op->write to put information into > > > >> the file. > > > >> > > > >> FreeBSD doesn't have filp_* API's. I've tried searching for example > > > >> drivers and googling for file API's from kernel modules to no avail. > > > >> Can someone please offer some guidance as to how I might proceed here? > > > >> > > > >> Thanks in advance and any insight would be most appreciated! > > > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() system > > > > call creates a file. I think in general you will wind up using > > > > NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / > > > > vn_rdwr() / vn_close(). > > > > > > man alq(9). > > > > > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > Those affect the state of the current process by opening a new file > descriptor, etc. That is generally bad practice for a device driver to be > interfering with a process' state, and it will not work for kernel threads. > You can rather easily have userland open a file and then pass the file > descriptor to a driver which can then do operations on a file directly. If the vnode operations are annoying to wrap ones head around, one could have the driver defer this this to a kernel resident process that the driver would create on attach. -- - Alfred Perlstein VMOA #5191, 03 vmax, 92 gs500, ch250 - FreeBSD From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 22 00:34:33 2009 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 B1968106564A for ; Wed, 22 Jul 2009 00:34:33 +0000 (UTC) (envelope-from sam@errno.com) Received: from ebb.errno.com (ebb.errno.com [69.12.149.25]) by mx1.freebsd.org (Postfix) with ESMTP id 7CD628FC17 for ; Wed, 22 Jul 2009 00:34:33 +0000 (UTC) (envelope-from sam@errno.com) Received: from ice.local ([10.0.0.115]) (authenticated bits=0) by ebb.errno.com (8.13.6/8.12.6) with ESMTP id n6M0YWVW019384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 21 Jul 2009 17:34:32 -0700 (PDT) (envelope-from sam@errno.com) Message-ID: <4A665E98.2060800@errno.com> Date: Tue, 21 Jul 2009 17:34:32 -0700 From: Sam Leffler User-Agent: Thunderbird 2.0.0.22 (Macintosh/20090605) MIME-Version: 1.0 To: Marc Loerner References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907200958.49119.jhb@freebsd.org> <4A64F200.2060900@errno.com> <200907210834.21541.marc.loerner@hob.de> In-Reply-To: <200907210834.21541.marc.loerner@hob.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-DCC-dmv.com-Metrics: ebb.errno.com; whitelist Cc: freebsd-drivers@freebsd.org Subject: Re: Driver development question 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, 22 Jul 2009 00:34:33 -0000 Marc Loerner wrote: > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: >> John Baldwin wrote: >>> On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: >>>> Hi All, >>>> >>>> I'm hoping someone can point me in the right direction... I'm >>>> developing a FreeBSD driver for a PCIe card. The driver controls a >>>> hardware device that has DRAM and various state information on it. I'm >>>> trying to mimic functionality I have for other OS support such that I >>>> can dump memory and state information from the card to a file I create >>>> from within my driver (kernel module). >>>> >>>> For example, in a Linux driver I use filp_open to create the dump file >>>> (represented by fp), then use fp->f_op->write to put information into >>>> the file. >>>> >>>> FreeBSD doesn't have filp_* API's. I've tried searching for example >>>> drivers and googling for file API's from kernel modules to no avail. >>>> Can someone please offer some guidance as to how I might proceed here? >>>> >>>> Thanks in advance and any insight would be most appreciated! >>> You can look at sys/kern/kern_ktrace.c to see how the ktrace() system >>> call creates a file. I think in general you will wind up using >>> NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / >>> vn_rdwr() / vn_close(). >> man alq(9). >> >> > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? These require a process context. alq is designed for exactly what the OP wants. The writes are non-blocking and can be done from interrupt context. The only (current) limitation is records must be fixed size but that's easy to deal with. I use alq to trace register r/w operations in a driver and it works great (low overhead so doesn't noticeably affect real-time operation). In fact it works so well that I ported the code to linux (you can find it in the madwifi code base). Sam From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 22 07:03:01 2009 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 66877106568C for ; Wed, 22 Jul 2009 07:03:01 +0000 (UTC) (envelope-from prvs=145457052a=marc.loerner@hob.de) Received: from mailgate.hob.de (mailgate.hob.de [212.185.199.3]) by mx1.freebsd.org (Postfix) with ESMTP id F30738FC1B for ; Wed, 22 Jul 2009 07:03:00 +0000 (UTC) (envelope-from prvs=145457052a=marc.loerner@hob.de) Received: from imap.hob.de (mail2.hob.de [172.25.1.102]) by mailgate.hob.de (Postfix) with ESMTP id A99DA520006 for ; Wed, 22 Jul 2009 08:38:54 +0200 (CEST) Received: from linux05.localnet (linux05.hob.de [172.22.0.196]) by imap.hob.de (Postfix on SuSE eMail Server 2.0) with ESMTP id 7C4F7FD3E9 for ; Wed, 22 Jul 2009 08:38:54 +0200 (CEST) From: Marc Loerner To: freebsd-drivers@freebsd.org Date: Wed, 22 Jul 2009 08:37:49 +0200 User-Agent: KMail/1.10.4 (Linux/2.6.27-14-server; KDE/4.1.4; x86_64; ; ) References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907211743.12667.jhb@freebsd.org> <20090722000713.GZ49724@elvis.mu.org> In-Reply-To: <20090722000713.GZ49724@elvis.mu.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907220837.49615.marc.loerner@hob.de> Subject: Re: Driver development question 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, 22 Jul 2009 07:03:01 -0000 Am Mittwoch 22 Juli 2009 02:07:13 schrieb Alfred Perlstein: > * John Baldwin [090721 14:44] wrote: > > On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > > > John Baldwin wrote: > > > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > > > >> Hi All, > > > > >> > > > > >> I'm hoping someone can point me in the right direction... I'm > > > > >> developing a FreeBSD driver for a PCIe card. The driver controls > > > > >> a hardware device that has DRAM and various state information on > > > > >> it. I'm trying to mimic functionality I have for other OS support > > > > >> such that I can dump memory and state information from the card to > > > > >> a file I create from within my driver (kernel module). > > > > >> > > > > >> For example, in a Linux driver I use filp_open to create the dump > > > > >> file (represented by fp), then use fp->f_op->write to put > > > > >> information into the file. > > > > >> > > > > >> FreeBSD doesn't have filp_* API's. I've tried searching for > > > > >> example drivers and googling for file API's from kernel modules to > > > > >> no avail. Can someone please offer some guidance as to how I might > > > > >> proceed here? > > > > >> > > > > >> Thanks in advance and any insight would be most appreciated! > > > > > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() > > > > > system call creates a file. I think in general you will wind up > > > > > using NDINIT/namei() (to lookup the vnode for a pathname) and then > > > > > vn_open() / vn_rdwr() / vn_close(). > > > > > > > > man alq(9). > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > > > Those affect the state of the current process by opening a new file > > descriptor, etc. That is generally bad practice for a device driver to > > be interfering with a process' state, and it will not work for kernel > > threads. You can rather easily have userland open a file and then pass > > the file descriptor to a driver which can then do operations on a file > > directly. > > If the vnode operations are annoying to wrap ones head around, one > could have the driver defer this this to a kernel resident process > that the driver would create on attach. So when action on a "pseudo" driver is requested via IOCTL from the same userspace-thread the above kern_* functions can be used for file-io? From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 22 13:21:05 2009 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 3D9501065674 for ; Wed, 22 Jul 2009 13:21:05 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id EEB538FC0A for ; Wed, 22 Jul 2009 13:21:04 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 7105E46B17; Wed, 22 Jul 2009 09:21:04 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id BF48B8A09D; Wed, 22 Jul 2009 09:21:03 -0400 (EDT) From: John Baldwin To: freebsd-drivers@freebsd.org Date: Wed, 22 Jul 2009 07:58:18 -0400 User-Agent: KMail/1.9.7 References: <002801ca06f0$b1d42af0$157c80d0$@net> <20090722000713.GZ49724@elvis.mu.org> <200907220837.49615.marc.loerner@hob.de> In-Reply-To: <200907220837.49615.marc.loerner@hob.de> MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200907220758.18327.jhb@freebsd.org> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Wed, 22 Jul 2009 09:21:03 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Subject: Re: Driver development question 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, 22 Jul 2009 13:21:06 -0000 On Wednesday 22 July 2009 2:37:49 am Marc Loerner wrote: > Am Mittwoch 22 Juli 2009 02:07:13 schrieb Alfred Perlstein: > > * John Baldwin [090721 14:44] wrote: > > > On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > > > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > > > > John Baldwin wrote: > > > > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > > > > >> Hi All, > > > > > >> > > > > > >> I'm hoping someone can point me in the right direction... I'm > > > > > >> developing a FreeBSD driver for a PCIe card. The driver controls > > > > > >> a hardware device that has DRAM and various state information on > > > > > >> it. I'm trying to mimic functionality I have for other OS support > > > > > >> such that I can dump memory and state information from the card to > > > > > >> a file I create from within my driver (kernel module). > > > > > >> > > > > > >> For example, in a Linux driver I use filp_open to create the dump > > > > > >> file (represented by fp), then use fp->f_op->write to put > > > > > >> information into the file. > > > > > >> > > > > > >> FreeBSD doesn't have filp_* API's. I've tried searching for > > > > > >> example drivers and googling for file API's from kernel modules to > > > > > >> no avail. Can someone please offer some guidance as to how I might > > > > > >> proceed here? > > > > > >> > > > > > >> Thanks in advance and any insight would be most appreciated! > > > > > > > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() > > > > > > system call creates a file. I think in general you will wind up > > > > > > using NDINIT/namei() (to lookup the vnode for a pathname) and then > > > > > > vn_open() / vn_rdwr() / vn_close(). > > > > > > > > > > man alq(9). > > > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > > > > > Those affect the state of the current process by opening a new file > > > descriptor, etc. That is generally bad practice for a device driver to > > > be interfering with a process' state, and it will not work for kernel > > > threads. You can rather easily have userland open a file and then pass > > > the file descriptor to a driver which can then do operations on a file > > > directly. > > > > If the vnode operations are annoying to wrap ones head around, one > > could have the driver defer this this to a kernel resident process > > that the driver would create on attach. > > So when action on a "pseudo" driver is requested via IOCTL from the same > userspace-thread the above kern_* functions can be used for file-io? Possibly. If the userland ioctl gives you an fd then you could invoke kern_read(), etc. I still think doing an actual open (i.e kern_open()) or close in a driver that affects the state of a process is a bad thing. Applications expect that the only file descriptors they have are ones they open. For example, some apps have assumptions about the relative order of fd numbers (at the moment I can only think of regression tests I've written that check for leaked fd's, etc.), though you also have apps that assume if they do 'close(0); open()' then the new fd will be stdin (i.e. fd == 0). If the app were multithreaded and another thread was invoking your ioctl, your icotl handler might claim 0 instead resulting in possible security holes, etc. I really think that sort of thing is best avoided. If an application has already opened a file and passes you an fd you could use kern_read/kern_stat, etc. safely though. However, for your use case (dumping debug info) I think Sam is correct and that ALQ is the best thing for you to use. -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Wed Jul 22 13:21:08 2009 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 7177810656DC; Wed, 22 Jul 2009 13:21:08 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 4255D8FC1F; Wed, 22 Jul 2009 13:21:08 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id EA9F046B17; Wed, 22 Jul 2009 09:21:07 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 42D8E8A09F; Wed, 22 Jul 2009 09:21:07 -0400 (EDT) From: John Baldwin To: Alfred Perlstein Date: Wed, 22 Jul 2009 08:19:04 -0400 User-Agent: KMail/1.9.7 References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907211743.12667.jhb@freebsd.org> <20090722000713.GZ49724@elvis.mu.org> In-Reply-To: <20090722000713.GZ49724@elvis.mu.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907220819.05087.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Wed, 22 Jul 2009 09:21:07 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: freebsd-drivers@freebsd.org Subject: Re: Driver development question 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, 22 Jul 2009 13:21:08 -0000 On Tuesday 21 July 2009 8:07:13 pm Alfred Perlstein wrote: > * John Baldwin [090721 14:44] wrote: > > On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > > > John Baldwin wrote: > > > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > > > >> Hi All, > > > > >> > > > > >> I'm hoping someone can point me in the right direction... I'm > > > > >> developing a FreeBSD driver for a PCIe card. The driver controls a > > > > >> hardware device that has DRAM and various state information on it. I'm > > > > >> trying to mimic functionality I have for other OS support such that I > > > > >> can dump memory and state information from the card to a file I create > > > > >> from within my driver (kernel module). > > > > >> > > > > >> For example, in a Linux driver I use filp_open to create the dump file > > > > >> (represented by fp), then use fp->f_op->write to put information into > > > > >> the file. > > > > >> > > > > >> FreeBSD doesn't have filp_* API's. I've tried searching for example > > > > >> drivers and googling for file API's from kernel modules to no avail. > > > > >> Can someone please offer some guidance as to how I might proceed here? > > > > >> > > > > >> Thanks in advance and any insight would be most appreciated! > > > > > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() system > > > > > call creates a file. I think in general you will wind up using > > > > > NDINIT/namei() (to lookup the vnode for a pathname) and then vn_open() / > > > > > vn_rdwr() / vn_close(). > > > > > > > > man alq(9). > > > > > > > > > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > > > Those affect the state of the current process by opening a new file > > descriptor, etc. That is generally bad practice for a device driver to be > > interfering with a process' state, and it will not work for kernel threads. > > You can rather easily have userland open a file and then pass the file > > descriptor to a driver which can then do operations on a file directly. > > If the vnode operations are annoying to wrap ones head around, one > could have the driver defer this this to a kernel resident process > that the driver would create on attach. Kernel processes don't have file descriptor tables. -- John Baldwin From owner-freebsd-drivers@FreeBSD.ORG Sat Jul 25 03:56:43 2009 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 D3143106566C; Sat, 25 Jul 2009 03:56:43 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id C17048FC15; Sat, 25 Jul 2009 03:56:43 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id ACC461A3C47; Fri, 24 Jul 2009 20:56:43 -0700 (PDT) Date: Fri, 24 Jul 2009 20:56:43 -0700 From: Alfred Perlstein To: John Baldwin Message-ID: <20090725035643.GT49724@elvis.mu.org> References: <002801ca06f0$b1d42af0$157c80d0$@net> <200907211743.12667.jhb@freebsd.org> <20090722000713.GZ49724@elvis.mu.org> <200907220819.05087.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200907220819.05087.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: freebsd-drivers@freebsd.org Subject: Re: Driver development question 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: Sat, 25 Jul 2009 03:56:44 -0000 * John Baldwin [090722 06:21] wrote: > On Tuesday 21 July 2009 8:07:13 pm Alfred Perlstein wrote: > > * John Baldwin [090721 14:44] wrote: > > > On Tuesday 21 July 2009 2:34:21 am Marc Loerner wrote: > > > > Am Dienstag 21 Juli 2009 00:38:56 schrieb Sam Leffler: > > > > > John Baldwin wrote: > > > > > > On Friday 17 July 2009 11:10:17 am Chris Harrer wrote: > > > > > >> Hi All, > > > > > >> > > > > > >> I'm hoping someone can point me in the right direction... I'm > > > > > >> developing a FreeBSD driver for a PCIe card. The driver controls a > > > > > >> hardware device that has DRAM and various state information on it. > I'm > > > > > >> trying to mimic functionality I have for other OS support such that > I > > > > > >> can dump memory and state information from the card to a file I > create > > > > > >> from within my driver (kernel module). > > > > > >> > > > > > >> For example, in a Linux driver I use filp_open to create the dump > file > > > > > >> (represented by fp), then use fp->f_op->write to put information > into > > > > > >> the file. > > > > > >> > > > > > >> FreeBSD doesn't have filp_* API's. I've tried searching for > example > > > > > >> drivers and googling for file API's from kernel modules to no > avail. > > > > > >> Can someone please offer some guidance as to how I might proceed > here? > > > > > >> > > > > > >> Thanks in advance and any insight would be most appreciated! > > > > > > > > > > > > You can look at sys/kern/kern_ktrace.c to see how the ktrace() > system > > > > > > call creates a file. I think in general you will wind up using > > > > > > NDINIT/namei() (to lookup the vnode for a pathname) and then > vn_open() / > > > > > > vn_rdwr() / vn_close(). > > > > > > > > > > man alq(9). > > > > > > > > > > > > > > > > > > Why not use kern_open, kern_close, kern_preadv, kern_pwritev? > > > > > > Those affect the state of the current process by opening a new file > > > descriptor, etc. That is generally bad practice for a device driver to be > > > interfering with a process' state, and it will not work for kernel > threads. > > > You can rather easily have userland open a file and then pass the file > > > descriptor to a driver which can then do operations on a file directly. > > > > If the vnode operations are annoying to wrap ones head around, one > > could have the driver defer this this to a kernel resident process > > that the driver would create on attach. > > Kernel processes don't have file descriptor tables. they do when you use an analogue to the old nfsd() syscall mechanism. -- - Alfred Perlstein VMOA #5191, 03 vmax, 92 gs500, ch250 - FreeBSD