Specifications

This is the Title of the Book, eMatter Edition
Copyright © 2005 O’Reilly & Associates, Inc. All rights reserved.
436
|
Chapter 15: Memory Mapping and DMA
This function has several arguments:
tsk
A pointer to the task performing the I/O; its main purpose is to tell the kernel
who should be charged for any page faults incurred while setting up the buffer.
This argument is almost always passed as
current.
mm A pointer to the memory management structure describing the address space to
be mapped. The
mm_struct structure is the piece that ties together all of the parts
(VMAs) of a process’s virtual address space. For driver use, this argument should
always be
current->mm.
start
len
start is the (page-aligned) address of the user-space buffer, and len is the length
of the buffer in pages.
write
force
If write is nonzero, the pages are mapped for write access (implying, of course,
that user space is performing a read operation). The
force flag tells get_user_pages
to override the protections on the given pages to provide the requested access;
drivers should always pass
0 here.
pages
vmas
Output parameters. Upon successful completion, pages contain a list of pointers
to the
struct page structures describing the user-space buffer, and vmas contains
pointers to the associated VMAs. The parameters should, obviously, point to
arrays capable of holding at least
len pointers. Either parameter can be NULL,but
you need, at least, the
struct page pointers to actually operate on the buffer.
get_user_pages is a low-level memory management function, with a suitably complex
interface. It also requires that the mmap reader/writer semaphore for the address
space be obtained in read mode before the call. As a result, calls to get_user_pages
usually look something like:
down_read(&current->mm->mmap_sem);
result = get_user_pages(current, current->mm, ...);
up_read(&current->mm->mmap_sem);
The return value is the number of pages actually mapped, which could be fewer than
the number requested (but greater than zero).
Upon successful completion, the caller has a
pages array pointing to the user-space
buffer, which is locked into memory. To operate on the buffer directly, the kernel-
space code must turn each
struct page pointer into a kernel virtual address with
kmap or kmap_atomic. Usually, however, devices for which direct I/O is justified are
using DMA operations, so your driver will probably want to create a scatter/gather
,ch15.13676 Page 436 Friday, January 21, 2005 11:04 AM