From owner-freebsd-drivers@FreeBSD.ORG Thu Jan 3 16:45:37 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id A84E16C2 for ; Thu, 3 Jan 2013 16:45:37 +0000 (UTC) (envelope-from rj@cyclaero.com) Received: from mo6-p00-ob.rzone.de (mo6-p00-ob.rzone.de [IPv6:2a01:238:20a:202:5300::1]) by mx1.freebsd.org (Postfix) with ESMTP id 48B9430C for ; Thu, 3 Jan 2013 16:45:36 +0000 (UTC) X-RZG-AUTH: :O2kGeEG7b/pS1E6gSHOyjPKyNsg/5l1He+DgCy9/8FSej6CwUysqfN3Dd+qW8pqf5aP/Kw== X-RZG-CLASS-ID: mo00 Received: from rolf.projectworld.net (b150f7b8.virtua.com.br [177.80.247.184]) by smtp.strato.de (josoe mo8) (RZmta 31.11 DYNA|AUTH) with (AES128-SHA encrypted) ESMTPA id f010a9p03FjMbI for ; Thu, 3 Jan 2013 17:45:33 +0100 (CET) From: "Dr. Rolf Jansen" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: How to map device addresses into user space Date: Thu, 3 Jan 2013 14:45:29 -0200 Message-Id: To: freebsd-drivers@freebsd.org Mime-Version: 1.0 (Apple Message framework v1283) X-Mailer: Apple Mail (2.1283) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jan 2013 16:45:37 -0000 I am building a loadable kernel module for FreeBSD 9.1-RELEASE x86_64 = for a PCI Data Acquisition board from National Instruments. 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. Having the measurement done by the kernel module is not an option = either, because it is math intensive, and kernel modules are build = without SSE and with soft float. I got tiny kernel modules/extensions only providing the mapped addresses = of the PCI BAR's running together with the Measurement Routines using = the NI-DDK on Darwin (Mac OS X) and Linux. So, how can I map device addresses into user space on FreeBSD? Best regards Rolf From owner-freebsd-drivers@FreeBSD.ORG Thu Jan 3 19:17:43 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5A1C8BF5 for ; Thu, 3 Jan 2013 19:17:43 +0000 (UTC) (envelope-from m.e.sanliturk@gmail.com) Received: from mail-vb0-f44.google.com (mail-vb0-f44.google.com [209.85.212.44]) by mx1.freebsd.org (Postfix) with ESMTP id 1CFAAD06 for ; Thu, 3 Jan 2013 19:17:42 +0000 (UTC) Received: by mail-vb0-f44.google.com with SMTP id fc26so15721465vbb.31 for ; Thu, 03 Jan 2013 11:17:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iy8zTuw12GDYctQcQ3jXQYB1HJ5fTaslpSy5+pkhzeE=; b=aCywVrZLfHTKBMr5MZdmc75JISqHE75WJZCxO3f3YjjJiBICqhevHXmTp+BTCzbUb1 jeahLNQKiKCeDDE3OLlJKs3O79qiPhc5RuCPzDkMtf9nI8wHA872PvEHSHo6henqrGmp Rzfcml2ZJJqaqaXr6l14d2lpdqMZQai1gcw/Mrf3SU42CAD3pQajGHhYr4fPUdpJ0AxI HJaW6xF3DEpK28aLcxxd8p+6f1OqA2VG4IesDENBARJ2xKrDWJ62aiCPHfRabgxV8P1a 3stnCMNGLd0aW1mBO2peBZepm5Qctfu4IcopliN0wvk0RblN58H1yqaCl83oxYMKBysZ KQlg== MIME-Version: 1.0 Received: by 10.52.75.100 with SMTP id b4mr64213645vdw.52.1357240662196; Thu, 03 Jan 2013 11:17:42 -0800 (PST) Received: by 10.58.214.226 with HTTP; Thu, 3 Jan 2013 11:17:42 -0800 (PST) In-Reply-To: References: Date: Thu, 3 Jan 2013 11:17:42 -0800 Message-ID: Subject: Re: How to map device addresses into user space From: Mehmet Erol Sanliturk To: "Dr. Rolf Jansen" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: freebsd-drivers@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jan 2013 19:17:43 -0000 On Thu, Jan 3, 2013 at 8:45 AM, Dr. Rolf Jansen wrote: > I am building a loadable kernel module for FreeBSD 9.1-RELEASE x86_64 for > a PCI Data Acquisition board from National Instruments. > > 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. > > Having the measurement done by the kernel module is not an option either, > because it is math intensive, and kernel modules are build without SSE and > with soft float. > > I got tiny kernel modules/extensions only providing the mapped addresses > of the PCI BAR's running together with the Measurement Routines using the > NI-DDK on Darwin (Mac OS X) and Linux. > > So, how can I map device addresses into user space on FreeBSD? > > > Best regards > > Rolf > > There is the following book : ----------------------------- http://www.amazon.com/FreeBSD-Device-Drivers-Guide-Intrepid/dp/1593272049/ref=sr_1_1?s=books&ie=UTF8&qid=1350180756&sr=1-1&keywords=9781593272043 http://nostarch.com/bsddrivers.htm 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 ----------------------------- I do not how much it can be useful for you , but it may be very helpful in details . Thank you very much . Mehmet Erol Sanliturk From owner-freebsd-drivers@FreeBSD.ORG Fri Jan 4 03:00:27 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 52DC89FA for ; Fri, 4 Jan 2013 03:00:27 +0000 (UTC) (envelope-from rj@cyclaero.com) Received: from mo6-p00-ob.rzone.de (mo6-p00-ob.rzone.de [IPv6:2a01:238:20a:202:5300::1]) by mx1.freebsd.org (Postfix) with ESMTP id E51EC61A for ; Fri, 4 Jan 2013 03:00:26 +0000 (UTC) X-RZG-AUTH: :O2kGeEG7b/pS1E6gSHOyjPKyNsg/5l1He+DgCy9/8FSej6CwUysqfN3Dd+qW8pqf5aP/Kw== X-RZG-CLASS-ID: mo00 Received: from rolf.projectworld.net (b150f7b8.virtua.com.br [177.80.247.184]) by smtp.strato.de (jored mo36) (RZmta 31.11 DYNA|AUTH) with (AES128-SHA encrypted) ESMTPA id x07710p042YYTG ; Fri, 4 Jan 2013 04:00:21 +0100 (CET) Subject: Re: How to map device addresses into user space Mime-Version: 1.0 (Apple Message framework v1283) Content-Type: text/plain; charset=us-ascii From: "Dr. Rolf Jansen" In-Reply-To: Date: Fri, 4 Jan 2013 01:00:17 -0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: freebsd-drivers@freebsd.org X-Mailer: Apple Mail (2.1283) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jan 2013 03:00:27 -0000 Am 03.01.2013 um 17:17 schrieb Mehmet Erol Sanliturk: > On Thu, Jan 3, 2013 at 8:45 AM, Dr. Rolf Jansen = wrote: >=20 >> ... >>=20 >> 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. >>=20 >> 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. >>=20 >> ... >=20 > There is the following book: >=20 > FreeBSD Device Drivers >=20 > Product Details >=20 > 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] &=3D 0x03; Best regards Rolf From owner-freebsd-drivers@FreeBSD.ORG Fri Jan 4 03:18:35 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E9CA7D94 for ; Fri, 4 Jan 2013 03:18:35 +0000 (UTC) (envelope-from bright@mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id D3C75715 for ; Fri, 4 Jan 2013 03:18:35 +0000 (UTC) Received: from Alfreds-MacBook-Pro-9.local (c-67-180-208-218.hsd1.ca.comcast.net [67.180.208.218]) by elvis.mu.org (Postfix) with ESMTPSA id 8DD141A3C1A; Thu, 3 Jan 2013 19:18:33 -0800 (PST) Message-ID: <50E64A02.8060109@mu.org> Date: Thu, 03 Jan 2013 19:18:26 -0800 From: Alfred Perlstein User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: "Dr. Rolf Jansen" Subject: Re: How to map device addresses into user space References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-drivers@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jan 2013 03:18:36 -0000 On 1/3/13 7: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 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; Can't you mmap /dev/mem? Sorry for being naive, I have not done this before. -Alfred From owner-freebsd-drivers@FreeBSD.ORG Fri Jan 4 06:18:31 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 85C7D1B5 for ; Fri, 4 Jan 2013 06:18:31 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from mail-ie0-f181.google.com (mail-ie0-f181.google.com [209.85.223.181]) by mx1.freebsd.org (Postfix) with ESMTP id 58442E55 for ; Fri, 4 Jan 2013 06:18:31 +0000 (UTC) Received: by mail-ie0-f181.google.com with SMTP id 16so19399086iea.12 for ; Thu, 03 Jan 2013 22:18:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:subject:mime-version:content-type:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to:x-mailer:x-gm-message-state; bh=4xWcs6Lw1PN9sc8UV+rduWIjmklCKHp2mtC0Wzu7dsA=; b=Cu+gOOBo/nljv+aKs1RYy+BnwoqSs394B3GphBB1BXIM/5B67J3Kl9ALWJkq+qh96a GM++9+rAgg/BRUlEhuVzlqjo1MX+FzR2zUt+Pyv0iDY/W4ZsVrK+D8Q0WbGhVERzoP4f yYEmFm0EfX54r1+jzDNEURmV5z5JM0O5R3gClpgenmjyHz014fZDlKZ7w0jvVtRkYTDY skJQkMJBFZ9agLX9Pv0TtGS4PU+SE443AqdTz1Ka26rQLEhz4jkGeMEgqGkaAJ26Kgtn GKnXO/euGmm7cV4w6ICUKoVoj7e+s/2LDYs5WIlWY/8vpchtRs0aJFEWx05Ea7aHXBTJ 3aBw== X-Received: by 10.50.16.144 with SMTP id g16mr39638548igd.2.1357280310313; Thu, 03 Jan 2013 22:18:30 -0800 (PST) Received: from [192.168.43.239] (me62836d0.tmodns.net. [208.54.40.230]) by mx.google.com with ESMTPS id j11sm22041169igc.5.2013.01.03.22.18.27 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Jan 2013 22:18:28 -0800 (PST) Sender: Warner Losh Subject: Re: How to map device addresses into user space Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: Date: Fri, 4 Jan 2013 00:18:24 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: "Dr. Rolf Jansen" X-Mailer: Apple Mail (2.1085) X-Gm-Message-State: ALoCoQnNU4fEkIzQn+Ab7gjeoEjJ+BtwINBT5A4z33Kr4OGGkDlupImcAJ6peXFd47ncHLFCsGcz Cc: freebsd-drivers@freebsd.org X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jan 2013 06:18:31 -0000 On Jan 3, 2013, at 9:00 PM, Dr. Rolf Jansen wrote: > Am 03.01.2013 um 17:17 schrieb Mehmet Erol Sanliturk: >=20 >> On Thu, Jan 3, 2013 at 8:45 AM, Dr. Rolf Jansen = wrote: >>=20 >>> ... >>>=20 >>> 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. >>>=20 >>> 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. >>>=20 >>> ... >>=20 >> There is the following book: >>=20 >> FreeBSD Device Drivers >>=20 >> Product Details >>=20 >> Paperback: 352 pages >> Publisher: No Starch Press; Original edition (May 7, 2012) >> Language: English >> ISBN-10: 1593272049 >> ISBN-13: 978-1593272043 >=20 >=20 > Mehmet, >=20 > Many thanks for your response. >=20 > 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. >=20 > 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: >=20 > user_space_BAR[0 + funcOffset] &=3D 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. Warner= From owner-freebsd-drivers@FreeBSD.ORG Sat Jan 5 05:15:14 2013 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 4FE34999 for ; Sat, 5 Jan 2013 05:15:14 +0000 (UTC) (envelope-from bsd.mharv@gmail.com) Received: from mail-la0-f66.google.com (mail-la0-f66.google.com [209.85.215.66]) by mx1.freebsd.org (Postfix) with ESMTP id BCAFF9DD for ; Sat, 5 Jan 2013 05:15:13 +0000 (UTC) Received: by mail-la0-f66.google.com with SMTP id fr10so4115335lab.1 for ; Fri, 04 Jan 2013 21:15:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:to:subject:content-type; bh=BnwEdtp89c8mkqA1Wfnw6ecYbo6i9soKed/BvRUba8I=; b=LOCqUyNCX/huBQukbTL8VTDRXmUltz6qHLEuSe3qTHcbAsEUyeStL5mmJX8YvJGnjd qauJMMFbmYZMzTp7FaQ5oVZsDtwduFQJuwtYOLCHsmS7Q9Yl+MwkqZILXa/h/HIVDDgu 0rUCbugOsXbi+0awLG6II+UmGyWVcv/nLzA+I44HywhtLDa8yMrgTnDHBSRG9wih+8Pr vttKRng8XoNaYci5qE8tNRtwVa/ub/INr5Gzs4Eud8CLSLM/5OJUBjAz4yhdHwCmfBVH r67pVHbLHCdcgsmN4u+hPaAP0hIuufUsi46tOkVlqBTezOHJT8ogQFpgWzTWVsBq7ikI 71FQ== X-Received: by 10.112.103.167 with SMTP id fx7mr22290045lbb.19.1357362907078; Fri, 04 Jan 2013 21:15:07 -0800 (PST) Received: from localhost ([165.138.17.10]) by mx.google.com with ESMTPS id hc20sm20075825lab.11.2013.01.04.21.15.05 (version=SSLv3 cipher=OTHER); Fri, 04 Jan 2013 21:15:06 -0800 (PST) Message-ID: <50e7b6da.946b980a.1927.ffffca6c@mx.google.com> Date: Sat, 5 Jan 2013 05:15:02 +0100 From: some body To: freebsd-drivers@freebsd.org Subject: Fwd: Content-Type: text/plain; X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Jan 2013 05:15:14 -0000 http://woningruilnederland.nl/mkdpveh.php