Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Oct 2014 12:12:52 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        leon zadorin <leonleon77@gmail.com>
Cc:        freebsd-emulation@freebsd.org, hackers@freebsd.org
Subject:   Re: does linsysfs support mmap on pci resources (e.g. pci device's registers etc.)
Message-ID:  <20141001091252.GP26076@kib.kiev.ua>
In-Reply-To: <CAPpySAaJ2CbsOMrvsrrstD_EQxt3d015T6HgF-Y9zPC7WAh4vA@mail.gmail.com>
References:  <CAPpySAaJ2CbsOMrvsrrstD_EQxt3d015T6HgF-Y9zPC7WAh4vA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
You choice of the list to ask the question is weird.  I added hackers@
as more suitable ML.

On Wed, Oct 01, 2014 at 03:44:48PM +1000, leon zadorin wrote:
> Hello everyone,
> Sorry if this is a bit of a noob question -- I'm just starting on this
> topic... does FreeBSD's emulation of sysfs (from linux world) support
> "mmap" on pci resources?
> 
> Something similar to the following in the linux environment:
> 
> fd = open("/sys/devices/pci0001\:00/0001\:00\:07.0/resource0", O_RDWR | O_SYNC);
> ptr = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> printf("PCI BAR0 0x0000 = 0x%4x\n",  *((unsigned short *) ptr);
> 
> (above taken from
> http://billfarrow.blogspot.com.au/2010/09/userspace-access-to-pci-memory.html)
> 
> The reason I am asking is because I would like to map pci device
> registers/memory in user space (and read/write some of the device's
> registers from userspace). The reasons are auxiliary to this post
> (e.g. kernel-bypass, system call bypass, etc.) At this stage it would
> suffice to simply accept that user space pci-register access is needed
> without paying the price of any system/ioctl/etc. call on every
> access-instance to device's config/control register(s).
> 
> I would prefer to avoid writing additional explicit (albeit generic)
> pci related kernel module in order to provide "mmapping" of the given
> pci resources to userspace  if there is already such a generic way to
> do it via sysfs "syntax" (I would like to reduce any of the
> specific/additional code re-writing at the kernel level as much as
> possible).

AFAIK, there is no facilities in FreeBSD kernel which allow you to get
the configuration registers or memory BARs mmapped into the userspace.
The linsysfs is out of question for this sort of hacks. The native
FreeBSD' /dev/pci does not support mmaping either.

It should be not too hard to extend the /dev/pci to do what you described.
Start looking at the sys/dev/pci/pci_user.c

PCIe configuration window is active, so you could access it by hand by
mmapping /dev/mem. Also, the window is mapped into KVA, so you could
access it by /dev/kmem as well. /dev/mem would be easier, I think,
because it needs the physical address, which can be learned from ACPI
MCFG much easier than the value of the static symbol pcie_base.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141001091252.GP26076>