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=