> Date: Wed, 31 Oct 2018 22:01:14 +0530
> From: Siddharth Muralee <siddharth.mura...@gmail.com>
> 
> Hello All,
>     I have recently been working on porting the kcov(4) feature to NetBSD.
> The feature comes as a /dev module. I have been stuck for a while with the
> mmap() function of the device. I have been trying to populate a buffer from
> the module and then pass it to the userspace program.
> 
> The mmap function of the device is here
> <https://github.com/R3x/src/blob/32806c3abfcfb5e82d1a0c69e00749ef97fdaf21/sys/dev/kcov.c#L205>
> and the function populating the buffer is here
> <https://github.com/R3x/src/blob/32806c3abfcfb5e82d1a0c69e00749ef97fdaf21/sys/dev/kcov.c#L86>

There is no MI API for turning a paddr or kva into a pmap mmap cookie,
which is what the struct cdev::d_mmap routine is supposed to return.

For bus space, there's bus_space_mmap; for bus DMA buffers, there's
bus_dmamem_mmap; but nothing that takes an arbitrary paddr or kva.

The pmap_phys_address and pmap_mmap_flags functions _take_ a pmap mmap
cookie and turn them into a physical address and a set of flags, but
that's the reverse.

For the moment, as a provisional workaround to make progress, you can
probably get by with `pa << PGSHIFT', where pa is the physical (byte)
address of the page you want -- but make sure to add a big scary XXX
comment saying that this is not right and needs to be fixed.

Beware that you'll also have to pmap_page_protect(PROT_NONE) all
physical addresses in the uvm_km buffer before you can uvm_km_free,
too.  Not sure offhand whether this might have a bad interaction with
uvm_km_free(UVM_KMF_WIRED), so be careful!

Reply via email to