From owner-freebsd-net@FreeBSD.ORG Tue Jul 31 19:32:19 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 298FF1065672 for ; Tue, 31 Jul 2012 19:32:19 +0000 (UTC) (envelope-from artemb@gmail.com) Received: from mail-ee0-f54.google.com (mail-ee0-f54.google.com [74.125.83.54]) by mx1.freebsd.org (Postfix) with ESMTP id ADD888FC08 for ; Tue, 31 Jul 2012 19:32:18 +0000 (UTC) Received: by eeke52 with SMTP id e52so1773591eek.13 for ; Tue, 31 Jul 2012 12:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=0hzbQ63oZJw7fkmbuOVyIqZVKfbNdVRWgl8EXVLjesY=; b=0N58HT4heogq2JkeTJ2n91iwqvzJ035MMnOv/tOXQxUJofGReN/V0Am8k/Kniuv6ts jvXOjVjeaFE3HvFuZ109CFhsFUnnQTSfZjSakITwM0G8uUvrRpZWc+2jsGphVt2huXch 6RoCzHXwigIOasfFHhqyE3Hzk/pkoOdsJ1br8CuHun/TnwHhPKy8HbInLP6QK7wOf2X+ ci+mpF63jqHrTcKFnu87QZzHEdbqGl0qBGYQhENEER8+lM6m6Mrmyeez/3rX3OXrIIKv 9LSpClxy8KxsqdDynhVhDneSUn8TTAsCtC7AImKu0o70wls0O7mX6STPzQqlswmNAEYe UlKw== MIME-Version: 1.0 Received: by 10.14.198.200 with SMTP id v48mr19458107een.3.1343763131917; Tue, 31 Jul 2012 12:32:11 -0700 (PDT) Sender: artemb@gmail.com Received: by 10.14.182.199 with HTTP; Tue, 31 Jul 2012 12:32:11 -0700 (PDT) In-Reply-To: <20120731174101.GE2676@deviant.kiev.zoral.com.ua> References: <20120731174101.GE2676@deviant.kiev.zoral.com.ua> Date: Tue, 31 Jul 2012 12:32:11 -0700 X-Google-Sender-Auth: sGKwD4ExSy3e4ShTXO5elLF-VzI Message-ID: From: Artem Belevich To: Konstantin Belousov Content-Type: text/plain; charset=ISO-8859-1 Cc: freebsd-net@freebsd.org, Venkat Duvvuru Subject: Re: PCI BAR mmap X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2012 19:32:19 -0000 On Tue, Jul 31, 2012 at 10:41 AM, Konstantin Belousov wrote: >> It's a bit of a hack, but if you are root, you can access physical >> memory via /dev/mem. >> >> memfd = open(/dev/mem) >> ptr = mmap(NULL, bar_size, PROT_READ, 0, memfd, bar_address); >> >> You can even use dd: >> >> dd if=/dev/mem bs=4k skip= count= of=bar.dump > > This probably only works on x86, only for memory BARs, and only if BAR > is already activated. But yes, I did grabbed scanouts (i.e. screen) on > Intel GPUs this way. Indeed, the hack above makes number of assumptions. * BARs indeed should be enabled. * one should know where on particular architecture BARs are mapped. BAR address is not necessarily the address kernel will see it at. * MD part of mem driver should cover that address range. The last one is a problem even on i386/amd64. It appears that, at least on i386/amd64, implicit assumption is that /dev/mem is for accessing RAM (or that peripherals are mapped in the hole below 4GB). /dev/mem does not work for devices that are mapped way above RAM in physical address space. On one of industrial boards I worked with 64-bit BARs were mapped at addresses 0xffff_xxxx_xxxx and those devices could not be accesses via /dev/mem because DMM didn't cover that range. I think DMM size got bumped up since then, but I don't think it covers complete physical address range. If device is not in that range, one can't use /dev/mem to access it. --Artem