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?