Subject: Re: DMA mapping file mappings
To: Damien Bergamini <email@example.com>
From: Jachym Holecek <firstname.lastname@example.org>
Date: 09/14/2004 20:43:25
> I want to map the content of a file into DMA memory. The file
> is mapped into user memory via mmap(2) by a userland tool which
> then send the resulting pointer to a kernel driver via a special
> ioctl. The driver then map the region into DMA using the
> bus_dmamap_load(9) function passing a pointer to the process that
> does the ioctl.
> Is it safe to do this? Do I need to call mlock(2) on the file
> mapping or to call mmap(2) with the MAP_WIRED flag before passing
> the pointer to the driver?
This way you have to trust userland passes wired memory. I'd instead
lock the memory myself on driver side using uvm_vslock(9). You'll need to
uvm_vsunlock(9) it after you're done with the buffer, of course - easy,
if your ioctl() call blocks.
> Should I copyin(9) everything into kernel memory first?
No, you don't need to.
-- Jachym Holecek