Xenomai  3.0.5
bufd.h
1 /*
2  * Copyright (C) 2009 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_KERNEL_BUFD_H
20 #define _COBALT_KERNEL_BUFD_H
21 
22 #include <linux/types.h>
23 
30 struct mm_struct;
31 
32 struct xnbufd {
33  caddr_t b_ptr; /* src/dst buffer address */
34  size_t b_len; /* total length of buffer */
35  off_t b_off; /* # of bytes read/written */
36  struct mm_struct *b_mm; /* src/dst address space */
37  caddr_t b_carry; /* pointer to carry over area */
38  char b_buf[64]; /* fast carry over area */
39 };
40 
41 void xnbufd_map_umem(struct xnbufd *bufd,
42  void __user *ptr, size_t len);
43 
44 static inline void xnbufd_map_uread(struct xnbufd *bufd,
45  const void __user *ptr, size_t len)
46 {
47  xnbufd_map_umem(bufd, (void __user *)ptr, len);
48 }
49 
50 static inline void xnbufd_map_uwrite(struct xnbufd *bufd,
51  void __user *ptr, size_t len)
52 {
53  xnbufd_map_umem(bufd, ptr, len);
54 }
55 
56 ssize_t xnbufd_unmap_uread(struct xnbufd *bufd);
57 
58 ssize_t xnbufd_unmap_uwrite(struct xnbufd *bufd);
59 
60 void xnbufd_map_kmem(struct xnbufd *bufd,
61  void *ptr, size_t len);
62 
63 static inline void xnbufd_map_kread(struct xnbufd *bufd,
64  const void *ptr, size_t len)
65 {
66  xnbufd_map_kmem(bufd, (void *)ptr, len);
67 }
68 
69 static inline void xnbufd_map_kwrite(struct xnbufd *bufd,
70  void *ptr, size_t len)
71 {
72  xnbufd_map_kmem(bufd, ptr, len);
73 }
74 
75 ssize_t xnbufd_unmap_kread(struct xnbufd *bufd);
76 
77 ssize_t xnbufd_unmap_kwrite(struct xnbufd *bufd);
78 
79 ssize_t xnbufd_copy_to_kmem(void *ptr,
80  struct xnbufd *bufd, size_t len);
81 
82 ssize_t xnbufd_copy_from_kmem(struct xnbufd *bufd,
83  void *from, size_t len);
84 
85 void xnbufd_invalidate(struct xnbufd *bufd);
86 
87 static inline void xnbufd_reset(struct xnbufd *bufd)
88 {
89  bufd->b_off = 0;
90 }
91 
94 #endif /* !_COBALT_KERNEL_BUFD_H */
ssize_t xnbufd_unmap_kread(struct xnbufd *bufd)
Finalize a buffer descriptor obtained from xnbufd_map_kread().
Definition: bufd.c:621
void xnbufd_invalidate(struct xnbufd *bufd)
Invalidate a buffer descriptor.
Definition: bufd.c:593
static void xnbufd_map_kread(struct xnbufd *bufd, const void *ptr, size_t len)
Initialize a buffer descriptor for reading from kernel memory.
Definition: bufd.h:63
static void xnbufd_reset(struct xnbufd *bufd)
Reset a buffer descriptor.
Definition: bufd.h:87
static void xnbufd_map_kwrite(struct xnbufd *bufd, void *ptr, size_t len)
Initialize a buffer descriptor for writing to kernel memory.
Definition: bufd.h:69
static void xnbufd_map_uread(struct xnbufd *bufd, const void __user *ptr, size_t len)
Initialize a buffer descriptor for reading from user memory.
Definition: bufd.h:44
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.
Definition: bufd.c:402
ssize_t xnbufd_copy_to_kmem(void *ptr, struct xnbufd *bufd, size_t len)
Copy memory covered by a buffer descriptor to kernel memory.
Definition: bufd.c:295
ssize_t xnbufd_unmap_uread(struct xnbufd *bufd)
Finalize a buffer descriptor obtained from xnbufd_map_uread().
Definition: bufd.c:492
ssize_t xnbufd_unmap_kwrite(struct xnbufd *bufd)
Finalize a buffer descriptor obtained from xnbufd_map_kwrite().
Definition: bufd.c:644
ssize_t xnbufd_unmap_uwrite(struct xnbufd *bufd)
Finalize a buffer descriptor obtained from xnbufd_map_uwrite().
Definition: bufd.c:528
static void xnbufd_map_uwrite(struct xnbufd *bufd, void __user *ptr, size_t len)
Initialize a buffer descriptor for writing to user memory.
Definition: bufd.h:50