Date: Fri, 4 Jan 2013 00:18:24 -0600 From: Warner Losh <imp@bsdimp.com> To: "Dr. Rolf Jansen" <rj@cyclaero.com> Cc: freebsd-drivers@freebsd.org Subject: Re: How to map device addresses into user space Message-ID: <A1ADF0D2-435D-4169-8849-7FE0EFDB760E@bsdimp.com> In-Reply-To: <A3C44BB7-0849-4E2C-B812-D1EC4AB49926@cyclaero.com> References: <DFC983B8-91B2-4ED8-89B0-FC4BD4AB2576@cyclaero.com> <CAOgwaMv8rzHPyCLV2OJ-2h9T2SiRHdvdCD=Dp%2Bs8guaCmybe1Q@mail.gmail.com> <A3C44BB7-0849-4E2C-B812-D1EC4AB49926@cyclaero.com>
index | next in thread | previous in thread | raw e-mail
On Jan 3, 2013, at 9:00 PM, Dr. Rolf Jansen wrote: > Am 03.01.2013 um 17:17 schrieb Mehmet Erol Sanliturk: > >> On Thu, Jan 3, 2013 at 8:45 AM, Dr. Rolf Jansen <rj@cyclaero.com> wrote: >> >>> ... >>> >>> I need to map the Base Address Registers into user space memory, in order to pass the BAR's to the National Instruments Drivers Development Kit (NI-DDK). The DDK is a complex set of C++ classes running in user space, that read/write directly from/into the BAR's. >>> >>> The FreeBSD bus_space_* functions are useless in this respect, because the DDK isn't designed that way, I need the BAR addresses mapped into user space. >>> >>> ... >> >> There is the following book: >> >> FreeBSD Device Drivers >> >> Product Details >> >> Paperback: 352 pages >> Publisher: No Starch Press; Original edition (May 7, 2012) >> Language: English >> ISBN-10: 1593272049 >> ISBN-13: 978-1593272043 > > > Mehmet, > > Many thanks for your response. > > I know this book. It suggests accessing the PCI registers using Newbus (Chapter 7). Newbus hides away direct reading/writing to the BAR's, and therefore, Newbus is useless in the given respect. > > Again, I need the exact PCI Base Address Registers directly mapped into user space, so that I can do in my user space measurement controller something like the following: > > user_space_BAR[0 + funcOffset] &= 0x03; (1) You could map /dev/mem. Lots of folks do this. (2) You could put all that code into your driver so you can map a small part of /dev/mem that corresponds to the part of the physical address space your device occupies. You can get that from rman_get_start from the bar resource that you allocate in your driver. This is a little more complicated, but doable. You'll need to make sure to cleanup in the close as well, otherwise bad things will happen. Get to know sys/vm. You will need to understand the subtle difference between different wiring and mapping. Note well that this will only work on architectures where bouncing and special MMU/iommu tricks aren't needed. Warnerhelp
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A1ADF0D2-435D-4169-8849-7FE0EFDB760E>
