Re: mmapping the physical pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 11, 2002 at 10:42:39AM +0530, Nagaraj wrote:
> hallooo,
> 
> Sorry im asking this question again, but i didnt get any replies for this:
> 
> I want to allocate physically contiguous blocks of memory for a DMA capable
> PCI device.
> Im working on 2.4.18 kernel, i586.
> Ive used series of __get_free_pages() with GFP_DMA|GFP_KERNEL flags,
> and tried to get array of 128k buffers.
> 
> Now i want to do a mmap() of all these blocks.
> How do i do that ?

I didn't try it, but few hints:

First you have to create a device (or proc entry - it's operations can
be defined any way you like, just it's less straightforward) and define
mmap operation for it.

generic_file_mmap gets a vma struct and all it does is some sanity-check
and then sets it's vm_ops. So you need your own mmap, that just sets it
to your own vm_ops.

vm_ops have three functions - one for open (called late in mmap), close
(called in munmap) and nopage, which is the actual function to serve
page faults.

Now, you have to read the code for filemap_nopage and write something
similar. That is you need to look if you already have page struct for
the page and if not, create it. Then you must associate it with your
page and return it. Generic code takes care of creating propper PTE.

You will probably need the mapping operations (ie. the
adress_space->a_ops) readpage and writepage. That is, nobody should call
readpage but you - it's normally called from filemap_nopage. But
writepage will be called if the user process mapped the page and a)
called msync, b) the page is dirty too long and c) there is memory
presure. You will probably also need the releasepage method.

You probably have to play with page flags (maybe PageReserved) so
removing the page works properly. There is a lot of flags and I don't
understand some of them. Flags are the PG_* constants defined in mm.h
and each has accessor macros and functions, because testing and seting
must be atomic (if there is set_page_* function for the flag, it's
appropriate, else there are the SetPage* macros).

(Because it's useless to remove the page before you are ready to free
the underlying DMA buffer)

> If it cant be answered here, any other lists that i can try ?

AFAIK this should be the right list.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux