From owner-freebsd-drivers@FreeBSD.ORG Sun Jan 22 11:41:14 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 C98B3106564A for ; Sun, 22 Jan 2012 11:41:14 +0000 (UTC) (envelope-from g.s@arcor.de) Received: from mail-in-18.arcor-online.net (mail-in-18.arcor-online.net [151.189.21.58]) by mx1.freebsd.org (Postfix) with ESMTP id 81D148FC12 for ; Sun, 22 Jan 2012 11:41:14 +0000 (UTC) Received: from mail-in-20-z2.arcor-online.net (mail-in-20-z2.arcor-online.net [151.189.8.85]) by mx.arcor.de (Postfix) with ESMTP id 29FB43DCC09 for ; Sun, 22 Jan 2012 12:10:00 +0100 (CET) Received: from mail-in-18.arcor-online.net (mail-in-18.arcor-online.net [151.189.21.58]) by mail-in-20-z2.arcor-online.net (Postfix) with ESMTP id 25D4BE9ABA for ; Sun, 22 Jan 2012 12:10:00 +0100 (CET) Received: from [192.168.0.95] (178-27-25-16-dynip.superkabel.de [178.27.25.16]) (Authenticated sender: g.s@arcor.de) by mail-in-18.arcor-online.net (Postfix) with ESMTPSA id C71773DD443 for ; Sun, 22 Jan 2012 12:09:59 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-18.arcor-online.net C71773DD443 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1327230600; bh=E0nUGAOFdHqDbIWSviuRNnp9xogd/Pl+h/wmM+Dbnlo=; h=Message-ID:Date:From:MIME-Version:To:Subject:Content-Type: Content-Transfer-Encoding; b=SoUpj0bEGyso+OvTkiBueH97E2WZmX9zgFF4mF0i22ETaxOWkKw91VfXqE4gbzV8W cPBeqGwN308cBTEo/w3yZ+Fl3EhNjHUeqsKTq0LV6vz98viRbFX8QRP7F0LHvogkop Cq590mDh1wUpX/Ble4ppk5wXfBZDLl3Hkt/NwWGA= Message-ID: <4F1BEE87.6080303@arcor.de> Date: Sun, 22 Jan 2012 12:09:59 +0100 From: Gerhard Strangar User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1.24) Gecko/20100228 MIME-Version: 1.0 To: freebsd-drivers@freebsd.org X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: 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 11:41:14 -0000 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? 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? 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"? 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.