From owner-freebsd-arm@FreeBSD.ORG Fri Apr 17 13:31:52 2015 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 29B99DB1 for ; Fri, 17 Apr 2015 13:31:52 +0000 (UTC) Received: from relay.mailchannels.net (ftx-008-i769.relay.mailchannels.net [50.61.143.69]) by mx1.freebsd.org (Postfix) with ESMTP id 4A10916C for ; Fri, 17 Apr 2015 13:31:46 +0000 (UTC) X-Sender-Id: duocircle|x-authuser|hippie Received: from smtp3.ore.mailhop.org (ip-10-204-4-183.us-west-2.compute.internal [10.204.4.183]) by relay.mailchannels.net (Postfix) with ESMTPA id D4A7760744; Fri, 17 Apr 2015 13:13:41 +0000 (UTC) X-Sender-Id: duocircle|x-authuser|hippie Received: from smtp3.ore.mailhop.org (smtp3.ore.mailhop.org [10.21.145.197]) (using TLSv1 with cipher DHE-RSA-AES256-SHA) by 0.0.0.0:2500 (trex/5.4.8); Fri, 17 Apr 2015 13:13:49 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: duocircle|x-authuser|hippie X-MailChannels-Auth-Id: duocircle X-MC-Loop-Signature: 1429276429003:562426853 X-MC-Ingress-Time: 1429276429002 Received: from c-73-34-117-227.hsd1.co.comcast.net ([73.34.117.227] helo=ilsoft.org) by smtp3.ore.mailhop.org with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.82) (envelope-from ) id 1Yj65U-0004lR-Bv; Fri, 17 Apr 2015 13:13:40 +0000 Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by ilsoft.org (8.14.9/8.14.9) with ESMTP id t3HDDbFG023182; Fri, 17 Apr 2015 07:13:38 -0600 (MDT) (envelope-from ian@freebsd.org) X-Mail-Handler: DuoCircle Outbound SMTP X-Originating-IP: 73.34.117.227 X-Report-Abuse-To: abuse@duocircle.com (see https://support.duocircle.com/support/solutions/articles/5000540958-duocircle-standard-smtp-abuse-information for abuse reporting information) X-MHO-User: U2FsdGVkX19eHoWX/u6OzqZtJF0OkVIe Message-ID: <1429276417.1182.71.camel@freebsd.org> Subject: Re: help with coding a loadable kernel module From: Ian Lepore To: Daniel Braniss Cc: Tom Jones , freebsd-arm@freebsd.org Date: Fri, 17 Apr 2015 07:13:37 -0600 In-Reply-To: <32D7EBD3-813E-4062-8A06-ED8E82BA50DA@cs.huji.ac.il> References: <20150417080839.GO2743@home.opsec.eu> <9B835088-661C-456E-84A7-47BC1835C0CB@cs.huji.ac.il> <20150417095536.GA38091@gmail.com> <32D7EBD3-813E-4062-8A06-ED8E82BA50DA@cs.huji.ac.il> Content-Type: text/plain; charset="windows-1251" X-Mailer: Evolution 3.12.10 FreeBSD GNOME Team Port Mime-Version: 1.0 X-AuthUser: hippie Content-Transfer-Encoding: quoted-printable X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Apr 2015 13:31:52 -0000 On Fri, 2015-04-17 at 13:46 +0300, Daniel Braniss wrote: > > On Apr 17, 2015, at 12:55 PM, Tom Jones wrote: > >=20 > > On Fri, Apr 17, 2015 at 12:15:33PM +0300, Daniel Braniss wrote: > >>=20 > >>> On Apr 17, 2015, at 11:08 AM, Kurt Jaeger wrote: > >>>=20 > >>> Hi! > >>>=20 > >>>> I know I'm embarking on a dangerous trip, but I want to use a Rasp= berry Pi > >>>> and or a BeagleBone to read (and write) RFID cards. > >>>> Since a driver is needed to use the spibus, I have 2 options while > >>>> developing: > >>> [...] > >>>> So before I give up on option 2, is there some examples/help? > >>>=20 > >>> Are you aware of this book ? > >>>=20 > >>> http://www.nostarch.com/bsddrivers.htm > >>=20 > >> no, but before I spend more money (this is getting expensive :-), > >> does it explain how to write a loadable module that needs to to talk > >> to a spibus?=20 > >=20 > > I don't think it does. > >=20 > > spibus is very simple, there is one interface call > >=20 > > SPIBUS_TRANSFER(device_t, device_t, strcut spi_command); > >=20 >=20 > chicken and egg issue :-), what device_t dev should I use? > it must point to the spibus =85 Your device will be a child of the spibus, and it is the bus that implements the SPIBUS_TRANSFER() method, so it's the bus's device_t that needs to be passed as the first parameter in the call (if it were C++ it would be the "this" pointer -- this stuff is OO implemented in plain-C). >From your driver, something like: SPIBUS_TRANSFER(device_get_parent(sc->sc_dev), sc->sc_dev, cmdptr); I haven't got time this morning to put together a complete example of how to add a module to the build, but the process is basically along the lines of... Add a new directory to sys/dev for your driver just like you were going to compile it into the kernel. Then in sys/modules find another simple driver, copy it to a new directory, and change the names of things in the makefile so that it refers to your new dir/files in sys/dev. You can set MODULES_OVERRIDE=3Dyournew_dirname on the make command line or in your kernel config to make it compile. -- Ian