Xenomai
3.0.5
|
Abstraction for copying data to/from different address spaces. More...
Functions | |
static void | xnbufd_map_uread (struct xnbufd *bufd, const void __user *ptr, size_t len) |
Initialize a buffer descriptor for reading from user memory. More... | |
static void | xnbufd_map_uwrite (struct xnbufd *bufd, void __user *ptr, size_t len) |
Initialize a buffer descriptor for writing to user memory. More... | |
ssize_t | xnbufd_unmap_uread (struct xnbufd *bufd) |
Finalize a buffer descriptor obtained from xnbufd_map_uread(). More... | |
ssize_t | xnbufd_unmap_uwrite (struct xnbufd *bufd) |
Finalize a buffer descriptor obtained from xnbufd_map_uwrite(). More... | |
static void | xnbufd_map_kread (struct xnbufd *bufd, const void *ptr, size_t len) |
Initialize a buffer descriptor for reading from kernel memory. More... | |
static void | xnbufd_map_kwrite (struct xnbufd *bufd, void *ptr, size_t len) |
Initialize a buffer descriptor for writing to kernel memory. More... | |
ssize_t | xnbufd_unmap_kread (struct xnbufd *bufd) |
Finalize a buffer descriptor obtained from xnbufd_map_kread(). More... | |
ssize_t | xnbufd_unmap_kwrite (struct xnbufd *bufd) |
Finalize a buffer descriptor obtained from xnbufd_map_kwrite(). More... | |
ssize_t | xnbufd_copy_to_kmem (void *ptr, struct xnbufd *bufd, size_t len) |
Copy memory covered by a buffer descriptor to kernel memory. More... | |
ssize_t | xnbufd_copy_from_kmem (struct xnbufd *bufd, void *from, size_t len) |
Copy kernel memory to the area covered by a buffer descriptor. More... | |
void | xnbufd_invalidate (struct xnbufd *bufd) |
Invalidate a buffer descriptor. More... | |
static void | xnbufd_reset (struct xnbufd *bufd) |
Reset a buffer descriptor. More... | |
Abstraction for copying data to/from different address spaces.
A buffer descriptor is a simple abstraction dealing with copy operations to/from memory buffers which may belong to different address spaces.
To this end, the buffer descriptor library provides a small set of copy routines which are aware of address space restrictions when moving data, and a generic container type which can hold a reference to - or cover - a particular memory area, either present in kernel space, or in any of the existing user memory contexts.
The goal of the buffer descriptor abstraction is to hide address space specifics from Xenomai services dealing with memory areas, allowing them to operate on multiple address spaces seamlessly.
The common usage patterns are as follows:
ssize_t xnbufd_copy_from_kmem | ( | struct xnbufd * | bufd, |
void * | from, | ||
size_t | len | ||
) |
Copy kernel memory to the area covered by a buffer descriptor.
This routine copies len bytes from the kernel memory starting at from to the area referred to by the buffer descriptor bufd. xnbufd_copy_from_kmem() tracks the write offset within the destination memory internally, so that it may be called several times in a loop, until the entire memory area is stored.
The destination address space is dealt with, according to the following rules:
bufd | The address of the buffer descriptor covering the user memory to copy data to. |
from | The start address of the kernel memory to copy from. |
len | The length of the kernel memory to copy to bufd. |
This routine may switch the caller to secondary mode if a page fault occurs while reading from the user area. For that reason, xnbufd_copy_to_kmem() may only be called from a preemptible section (Linux-wise).
ssize_t xnbufd_copy_to_kmem | ( | void * | to, |
struct xnbufd * | bufd, | ||
size_t | len | ||
) |
Copy memory covered by a buffer descriptor to kernel memory.
This routine copies len bytes from the area referred to by the buffer descriptor bufd to the kernel memory area to. xnbufd_copy_to_kmem() tracks the read offset within the source memory internally, so that it may be called several times in a loop, until the entire memory area is loaded.
The source address space is dealt with, according to the following rules:
to | The start address of the kernel memory to copy to. |
bufd | The address of the buffer descriptor covering the user memory to copy data from. |
len | The length of the user memory to copy from bufd. |
This routine may switch the caller to secondary mode if a page fault occurs while reading from the user area. For that reason, xnbufd_copy_to_kmem() may only be called from a preemptible section (Linux-wise).
void xnbufd_invalidate | ( | struct xnbufd * | bufd | ) |
Invalidate a buffer descriptor.
The buffer descriptor is invalidated, making it unusable for further copy operations. If an outstanding carry over buffer was allocated by a previous call to xnbufd_copy_from_kmem(), it is immediately freed so that no data transfer will happen when the descriptor is finalized.
The only action that may subsequently be performed on an invalidated descriptor is calling the relevant unmapping routine for it. For that reason, xnbufd_invalidate() should be invoked on the error path when data may have been transferred to the carry over buffer.
bufd | The address of the buffer descriptor to invalidate. |
|
inlinestatic |
Initialize a buffer descriptor for reading from kernel memory.
The new buffer descriptor may be used to copy data from kernel memory. This routine should be used in pair with xnbufd_unmap_kread().
bufd | The address of the buffer descriptor which will map a len bytes kernel memory area, starting from ptr. |
ptr | The start of the kernel buffer to map. |
len | The length of the kernel buffer starting at ptr. |
|
inlinestatic |
Initialize a buffer descriptor for writing to kernel memory.
The new buffer descriptor may be used to copy data to kernel memory. This routine should be used in pair with xnbufd_unmap_kwrite().
bufd | The address of the buffer descriptor which will map a len bytes kernel memory area, starting from ptr. |
ptr | The start of the kernel buffer to map. |
len | The length of the kernel buffer starting at ptr. |
|
inlinestatic |
Initialize a buffer descriptor for reading from user memory.
The new buffer descriptor may be used to copy data from user memory. This routine should be used in pair with xnbufd_unmap_uread().
bufd | The address of the buffer descriptor which will map a len bytes user memory area, starting from ptr. ptr is never dereferenced directly, since it may refer to a buffer that lives in another address space. |
ptr | The start of the user buffer to map. |
len | The length of the user buffer starting at ptr. |
|
inlinestatic |
Initialize a buffer descriptor for writing to user memory.
The new buffer descriptor may be used to copy data to user memory. This routine should be used in pair with xnbufd_unmap_uwrite().
bufd | The address of the buffer descriptor which will map a len bytes user memory area, starting from ptr. ptr is never dereferenced directly, since it may refer to a buffer that lives in another address space. |
ptr | The start of the user buffer to map. |
len | The length of the user buffer starting at ptr. |
|
inlinestatic |
Reset a buffer descriptor.
The buffer descriptor is reset, so that all data already copied is forgotten. Any carry over buffer allocated is kept, though.
bufd | The address of the buffer descriptor to reset. |
ssize_t xnbufd_unmap_kread | ( | struct xnbufd * | bufd | ) |
Finalize a buffer descriptor obtained from xnbufd_map_kread().
This routine finalizes a buffer descriptor previously initialized by a call to xnbufd_map_kread(), to read data from a kernel area.
bufd | The address of the buffer descriptor to finalize. |
ssize_t xnbufd_unmap_kwrite | ( | struct xnbufd * | bufd | ) |
Finalize a buffer descriptor obtained from xnbufd_map_kwrite().
This routine finalizes a buffer descriptor previously initialized by a call to xnbufd_map_kwrite(), to write data to a kernel area.
bufd | The address of the buffer descriptor to finalize. |
ssize_t xnbufd_unmap_uread | ( | struct xnbufd * | bufd | ) |
Finalize a buffer descriptor obtained from xnbufd_map_uread().
This routine finalizes a buffer descriptor previously initialized by a call to xnbufd_map_uread(), to read data from a user area.
bufd | The address of the buffer descriptor to finalize. |
ssize_t xnbufd_unmap_uwrite | ( | struct xnbufd * | bufd | ) |
Finalize a buffer descriptor obtained from xnbufd_map_uwrite().
This routine finalizes a buffer descriptor previously initialized by a call to xnbufd_map_uwrite(), to write data to a user area.
The main action taken is to write the contents of the kernel memory area passed to xnbufd_copy_from_kmem() whenever the copy operation was postponed at that time; the carry over buffer is eventually released as needed. If xnbufd_copy_from_kmem() was allowed to copy to the destination user memory at once, then xnbufd_unmap_uwrite() leads to a no-op.
bufd | The address of the buffer descriptor to finalize. |