Date: Tue, 5 Apr 2016 19:21:29 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-current@freebsd.org, Ryan Stone <rysto32@gmail.com> Subject: Re: accessing a PCIe register from userspace through kmem or other ways ? Message-ID: <20160405162129.GG1741@kib.kiev.ua> In-Reply-To: <2874767.SJKfSzhn1q@ralph.baldwin.cx> References: <CA%2BhQ2%2BiU4odjhaNicFA4QjvSZR2OZOOy%2BFu4LTqsibdoK4M8zg@mail.gmail.com> <9376230.YZMFsgSvTf@ralph.baldwin.cx> <20160405061431.GF1741@kib.kiev.ua> <2874767.SJKfSzhn1q@ralph.baldwin.cx>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Apr 05, 2016 at 08:55:54AM -0700, John Baldwin wrote: > Mostly I do not have experience with MGTDEVICE, though I was planning to > look at it as a way to implement this. Two things though: 1) there may > not be a cdev to associate with, and 2) I know of at least one device driver > that would use this in addition to using this for a general "map this BAR" > ioctl on /dev/pci. So /dev/pci is the natural cdev to place the functionality. An ioctl on /dev/pci may mmap BAR and return the base address. > There are other cases in the past where I used OBJT_SG > but would have preferred to use a variant that used managed pages so that > I could invidate any existing mappings. In particular what I want to do > is invalidate an object so that any future uses fail. > > Alternatively, it might be nice to hook a destructor call into a VM object > so that I could know when the object is no longer in use (knowing that all > its mappings have been destroyed). When using OBJT_SG objects as aliases > for other things (memory allocated via contigmalloc or bus_dma or for > resources like PCI BARs), I could keep a reference count on the original > "thing" that I increment when creating an OBJT_SG object to return from > something like d_mmap_single() or the /dev/pci ioctl and drop the reference > count in the destructor hook for that object. This is in essence how GEM objects + MGTDEVICE mappings work for i915. The only bottleneck in the API arrangement is that d_mmap_single() only gets the offset as the identifying data to construct the mapping. For /dev/pci, the offset parameter would need to encode d:b:s:f and BAR index.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160405162129.GG1741>