Date: Tue, 31 Jul 2012 12:32:11 -0700 From: Artem Belevich <art@freebsd.org> To: Konstantin Belousov <kostikbel@gmail.com> Cc: freebsd-net@freebsd.org, Venkat Duvvuru <venkatduvvuru.ml@gmail.com> Subject: Re: PCI BAR mmap Message-ID: <CAFqOu6i-U6CSrrPeOx=Sm8=Oq-dBnxq=A9a4Y8MHUfZEZODzmA@mail.gmail.com> In-Reply-To: <20120731174101.GE2676@deviant.kiev.zoral.com.ua> References: <CAGdae7a0xuKnFaeOTUykLcUKuCf17TTuYD_MuG4t7FKbHNoqAg@mail.gmail.com> <CAFqOu6g%2BTypQngY6tyeFigPZahixL1QGTiwaEwABqDyMWA-3uw@mail.gmail.com> <20120731174101.GE2676@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 31, 2012 at 10:41 AM, Konstantin Belousov <kostikbel@gmail.com> 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=<BAR_ADDRESS/4k> count=<BAR_SIZE/4k> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFqOu6i-U6CSrrPeOx=Sm8=Oq-dBnxq=A9a4Y8MHUfZEZODzmA>