From owner-freebsd-arm@FreeBSD.ORG Fri Apr 17 13:43:02 2015 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 28C00151 for ; Fri, 17 Apr 2015 13:43:02 +0000 (UTC) Received: from mail-pd0-f170.google.com (mail-pd0-f170.google.com [209.85.192.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id EC83B2F5 for ; Fri, 17 Apr 2015 13:43:01 +0000 (UTC) Received: by pdbqd1 with SMTP id qd1so128764614pdb.2 for ; Fri, 17 Apr 2015 06:42:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:message-id:references:to; bh=weNZ+1x7w4ZpdYqF6l9iKOc7CDpOdiwpD0ftuHWl3j8=; b=kUtT6y5AvwB75EePdsO0XOePJd+0bccTXKnACKJRdMLA6eCQ0gvQUI7aZHTf7EhQIY OstFIjjRdqrI2U6witV4cM4IJKgPSCcNwt/MyMVpFrY2ioz4/jfhyQeQGWQ5stH7mFnC mnCsP96LssaevoSLqXg4ISAm2DZXoMj80qEpOBFn6RH8L+9mqP4nkp/IKW1tq+vahvpQ Wko5+wFCWLFJOSO69u0WNK+YHxQgh64wriCGP3AS5xngpbzH9ihB0EGA2aI/uGssqt+2 5KuHRbA41vjp9/xRkp66jpG1sgWDxSXNLaM3R1e4+uDTEbHnrTg1rbMglqA1EKuTyAj9 zcwg== X-Gm-Message-State: ALoCoQkycgTDDw6TEIUAbxwLqsXivoEckZV+lAb/Dx3g5ixc3vEeGwpK4WQHa0DqSQ20wrPBJHw0 X-Received: by 10.70.129.172 with SMTP id nx12mr5604070pdb.157.1429278175147; Fri, 17 Apr 2015 06:42:55 -0700 (PDT) Received: from [10.64.24.57] ([69.53.236.236]) by mx.google.com with ESMTPSA id qh9sm10232242pbc.24.2015.04.17.06.42.53 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Apr 2015 06:42:54 -0700 (PDT) Sender: Warner Losh Subject: Re: help with coding a loadable kernel module Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Content-Type: multipart/signed; boundary="Apple-Mail=_DA24257B-512A-44E0-B75E-42CB318684D8"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Pgp-Agent: GPGMail 2.5b6 From: Warner Losh In-Reply-To: Date: Fri, 17 Apr 2015 07:42:51 -0600 Cc: Ian Lepore , freebsd-arm@freebsd.org Message-Id: 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> <1429276417.1182.71.camel@freebsd.org> To: Daniel Braniss X-Mailer: Apple Mail (2.2098) 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:43:02 -0000 --Apple-Mail=_DA24257B-512A-44E0-B75E-42CB318684D8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Apr 17, 2015, at 7:26 AM, Daniel Braniss = wrote: >=20 >>=20 >> On Apr 17, 2015, at 4:13 PM, Ian Lepore wrote: >>=20 >> 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 = Raspberry 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 >>>> 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 =E2=80=A6 >>=20 >> Your device will be a child of the spibus, and it is the bus that >=20 > it=E2=80=99s the =E2=80=98child of=E2=80=99 that I have problems. this = will be a loadable module, so > it will have to tell the parent that he is no longer an orphan :-) When you declare the module, one of the parameters are what bus to attach to. If you are using FDT in your system, then you=E2=80=99ll put your device = into the FDT tree below the spibus to create the device_t node in the tree. When your module is loaded, its probe routine will be called, and you can match based on the compatible string given in the FDT. >> 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). >>> =46rom your driver, something like: >>=20 >> SPIBUS_TRANSFER(device_get_parent(sc->sc_dev), sc->sc_dev, cmdptr); >>=20 >> 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... >>=20 >> 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. >>=20 >=20 > I have that, even figured out how to cross compile and use the make = buildenv. > it=E2=80=99s great! I can compile outside the source tree too. Yes. That=E2=80=99s also possible. Build it in a buildenv environment = and then copy the .ko file over to the target system to kldload. Warner --Apple-Mail=_DA24257B-512A-44E0-B75E-42CB318684D8 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIcBAEBCgAGBQJVMQ3bAAoJEGwc0Sh9sBEAg/UQAMO3Uc6yPx4tK3y/iAbVDOsj ZLeg4ZVGDxXFMVeh/9q83yHCcjWcnGRvZXYCEHriNZbSF3OhLsafntopolfhWUpn eKDyyUUpd4NKDIBYTOiby+42NaE9Y67aIxDpdpcC0qfsrf2oNga4ak9kcYcTqOxN K+VUH0Wysgh5smHj1JoL83TkWZat1zD5h5h6ndESYUCV6ilQFmn4HB/14YAYOTWs ql68OCU3euXni33Mwkpe23nxki5FvjR/RGY6dN5KdKpqqywVk9TPCmDN+6W0Kxtn 6LlQ9OdjDZ/FDDVYA1CwQ5xtV75h65s06kDt/KexmOoK2hWOkaBOMC3qeetyLxgd eYHNjJixJV9/ybYYzREWtvcV3Y2TPOh0Ctk4kTlC5Dz6X9JAgcjsxiF74fsy8ymV HH92IsIiaRn4ZOqeaZgGKZ3Z/yFQmsz2TbFRbQuwwulSGGZovAwL6vpo1F/XL8SQ ZhrZ7ZvY6rwPOVj+knU5W/fm5ZfnVZ/BexA4MmVIkj0/9Gtirtw02XIrX+cBoiVe 6O5F+PKjNvb6CZqCFdGZ2yGjd7I0xYZqs4tdTDVMvscoFC9Edr0fU3mBPvCuimtg qmh/4DjkEYHJppuPCk7c80M9IypH0Y9t0c0cJE/qdYzAkT3q2LUFMrPJs/2yC4e7 L3vsKkkNvsdTNLDbKs10 =4PGo -----END PGP SIGNATURE----- --Apple-Mail=_DA24257B-512A-44E0-B75E-42CB318684D8--