From owner-freebsd-drivers@FreeBSD.ORG Sun Jan 22 13:12:58 2012 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 196F4106564A for ; Sun, 22 Jan 2012 13:12:58 +0000 (UTC) (envelope-from patfbsd@davenulle.org) Received: from smtp.lamaiziere.net (net.lamaiziere.net [94.23.254.147]) by mx1.freebsd.org (Postfix) with ESMTP id D41CF8FC12 for ; Sun, 22 Jan 2012 13:12:57 +0000 (UTC) Received: from roxette.lamaiziere.net (136.9.74.86.rev.sfr.net [86.74.9.136]) by smtp.lamaiziere.net (Postfix) with ESMTPA id 49D7EFAA2D08; Sun, 22 Jan 2012 13:57:05 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by roxette.lamaiziere.net (Postfix) with ESMTP id 9D5B5C1EA; Sun, 22 Jan 2012 13:57:04 +0100 (CET) Date: Sun, 22 Jan 2012 13:57:03 +0100 From: Patrick Lamaiziere To: Gerhard Strangar Message-ID: <20120122135703.15810f3f@davenulle.org> In-Reply-To: <4F1BEE87.6080303@arcor.de> References: <4F1BEE87.6080303@arcor.de> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.6; amd64-portbld-freebsd9.0) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Cc: freebsd-drivers@freebsd.org Subject: Re: Introduction to writing kernel modules 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: Sun, 22 Jan 2012 13:12:58 -0000 Le Sun, 22 Jan 2012 12:09:59 +0100, Gerhard Strangar a écrit : > Hello, Hello, > I'm trying to write a driver for my watchdog card. However I don't > know anything about kernel modules in FreeBSD. I'm running 8.2 > Release and I found /usr/src/share/examples/drivers/, but there are > lines like > > struct ${1}_softc { > [...] > char buffer[BUFFERSIZE]; /* If we need to buffer something. */ > }; > > Does it mean that it's for internal use of the example module only or > does an other component use it? The softc is used to store private informations (but I guess you can store public information too). Each instance of the driver owns its softc. I mean that if you have two network cards like "em0, em1" there will be two softc allocated, one for each. > My card is PCI-based and all I need to do is write a byte via > port-based IO, no Interrupts, no DMA or other stuff. I'm planning to > use a character device for triggering the timer reset or disabling > the card. But I don't need to copy the input to kernel space before > checking if it was 0 or 1, do I? There is a facility for watchdogs, you should use it. You only have to register you watchdog in the kernel and watchdogd(8) is used to control the watchdog from userland. introduction: http://web.archive.org/web/20040629062401/http://ezine.daemonnews.org/200406/watchdog.html also see man 9 watchdog. > Later on, the example uses: > static struct _pcsid > { > u_int32_t type; > const char *desc; > } pci_ids[] = { > { 0x1234abcd, "ACME PCI Widgetplus" }, > { 0x1243fedc, "Happy moon brand RIPOFFplus" }, > { 0x00000000, NULL } > }; > > What's the meaning of those? Is the driver looking for two cards and > 0x0 and NULL terminate the list or is it looking for one card only > and the abcd matches the "class" of "pcilist -lv" and fedc matches > "card"? It is looking for two cards. Few docs / papers about the kernel are listed here : http://forums.freebsd.org/showthread.php?t=1566 And you can use the kernel cross reference to dig into the code: http://fxr.watson.org/. You will find few examples of kernel watchdogs. Regards.