From owner-freebsd-hackers@freebsd.org Mon Aug 17 16:04:28 2015 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 65DB19BB5C7 for ; Mon, 17 Aug 2015 16:04:28 +0000 (UTC) (envelope-from indiestory@gmail.com) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 441CD1238 for ; Mon, 17 Aug 2015 16:04:28 +0000 (UTC) (envelope-from indiestory@gmail.com) Received: by mailman.ysv.freebsd.org (Postfix) id 40B4B9BB5C6; Mon, 17 Aug 2015 16:04:28 +0000 (UTC) Delivered-To: hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 263B99BB5C4 for ; Mon, 17 Aug 2015 16:04:28 +0000 (UTC) (envelope-from indiestory@gmail.com) Received: from mail-wi0-x22f.google.com (mail-wi0-x22f.google.com [IPv6:2a00:1450:400c:c05::22f]) (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 B2E541237 for ; Mon, 17 Aug 2015 16:04:27 +0000 (UTC) (envelope-from indiestory@gmail.com) Received: by wicja10 with SMTP id ja10so85053716wic.1 for ; Mon, 17 Aug 2015 09:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:hackerspace:user-agent; bh=va2lcRiZLCbzR1G2P1hj+E/ZGQSinENNbpB4cDzdlTs=; b=o29wuZznLx7X2XYSUtffdd+XwGFnhMd2rlYLxWY+FU0uTzhHfBWt/qrQuX0yVLkIQW SYVGMpNb2bl8CUtGnhyIcmsgFJCoqP8xJCkC5brhvoAJx6Ytnfx61jlrkAq7dnIX5Qx7 d467oJqSGXywJW412D0jefN48wCp9KUL59uIcn6lWYELAJ84quD+VZo3yhdfn4n4uavh Ei7SfI7tUuxc7sfu+psaTWHDsgUBHgulESG660Gcvl8g/Jvk4TygASXTl7X5HZNbMhjR sw71lNvJVa/i5AbAq2zzNmEro3xIPI2wTCZurS03aCBzX3TRCGva0CmtwaxFgJvLtBO/ xc/A== X-Received: by 10.194.60.226 with SMTP id k2mr3900566wjr.10.1439827465991; Mon, 17 Aug 2015 09:04:25 -0700 (PDT) Received: from gmail.com ([151.217.48.39]) by smtp.gmail.com with ESMTPSA id im10sm18300889wjb.40.2015.08.17.09.04.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Aug 2015 09:04:25 -0700 (PDT) Sender: Tom Jones Date: Mon, 17 Aug 2015 17:04:23 +0100 From: Tom Jones To: Brian Fundakowski Feldman Cc: hackers@freebsd.org Subject: Re: spigen(4) SPI Generic IO interface -- need comments Message-ID: <20150817160423.GB3078@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Hackerspace: 57North Hacklab User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Aug 2015 16:04:28 -0000 On Mon, Aug 17, 2015 at 10:00:26AM -0400, Brian Fundakowski Feldman wrote: > I'm woefully out-of-practice with my kernel hackery (but still pretty > proficient in jiggery-pokery) so I would like to get comments on a little > driver I just made for interfacing arbitrarily in userland with SPI > components. The only thing I'm exposing is a /dev/spigenN node with a > single transfer ioctl and I put together a test circuit and program with an > MCP3008 10-bit ADC IC to validate that it basically works, other than the > limitation that the transfers must be octet-multiply-sized, but I haven't > looked at the SoC's (I'm using a Raspberry Pi 2) data sheet to tell whether > that's just a limit on the spibus(4) interface or the Broadcom SPI driver > or the Broadcom SoC itself. > > I hit one snag in development where I simply called the ioctl wrong and > found copyin(9) to page fault HARD if given a bogus user address to copy > from, and panic the kernel. I can post up the test program if anyone wants > but it's very trivial: I just align the start bit and the command data into > the least significant bits of the first octet, shift it up two positions so > the NULs get clocked out as part of the command field, and provide two > octets for the data field to retrieve back the 10-bit digital value. Oh, cool. I did the same earlier this year, have you seen[1]?. The FreeBSD i2c api is the same/very similar the linux one[2][3]. Have you considered adding some of the ioctls[3] or the data structures to make it easier to port code? [1]: https://lists.freebsd.org/pipermail/freebsd-embedded/2015-April/002466.html [2]: https://www.kernel.org/doc/Documentation/i2c/dev-interface [3]: https://www.freebsd.org/cgi/man.cgi?query=iic&apropos=0&sektion=0&manpath=FreeBSD+10.2-RELEASE&arch=default&format=html [4]: https://www.kernel.org/doc/Documentation/spi/spidev - tj