Xenomai  3.0.5
fd.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2007 Jan Kiszka <jan.kiszka@web.de>
3  * Copyright (C) 2005 Joerg Langenberg <joerg.langenberg@gmx.net>
4  * Copyright (C) 2008,2013,2014 Gilles Chanteperdrix <gch@xenomai.org>.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 #ifndef _COBALT_KERNEL_FD_H
21 #define _COBALT_KERNEL_FD_H
22 
23 #include <linux/types.h>
24 #include <linux/socket.h>
25 #include <linux/file.h>
26 #include <cobalt/kernel/tree.h>
27 #include <asm-generic/xenomai/syscall.h>
28 
29 struct vm_area_struct;
30 struct rtdm_fd;
31 struct _rtdm_mmap_request;
32 struct xnselector;
33 struct cobalt_ppd;
34 
57 int rtdm_open_handler(struct rtdm_fd *fd, int oflags);
58 
70 int rtdm_socket_handler(struct rtdm_fd *fd, int protocol);
71 
81 void rtdm_close_handler(struct rtdm_fd *fd);
82 
97 int rtdm_ioctl_handler(struct rtdm_fd *fd, unsigned int request, void __user *arg);
98 
113 ssize_t rtdm_read_handler(struct rtdm_fd *fd, void __user *buf, size_t size);
114 
129 ssize_t rtdm_write_handler(struct rtdm_fd *fd, const void __user *buf, size_t size);
130 
146 ssize_t rtdm_recvmsg_handler(struct rtdm_fd *fd, struct user_msghdr *msg, int flags);
147 
163 ssize_t rtdm_sendmsg_handler(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags);
164 
180 int rtdm_select_handler(struct rtdm_fd *fd, struct xnselector *selector,
181  unsigned int type, unsigned int index);
182 
198 int rtdm_mmap_handler(struct rtdm_fd *fd, struct vm_area_struct *vma);
199 
231 unsigned long
232 rtdm_get_unmapped_area_handler(struct rtdm_fd *fd,
233  unsigned long len, unsigned long pgoff,
234  unsigned long flags);
243 struct rtdm_fd_ops {
245  int (*open)(struct rtdm_fd *fd, int oflags);
247  int (*socket)(struct rtdm_fd *fd, int protocol);
249  void (*close)(struct rtdm_fd *fd);
251  int (*ioctl_rt)(struct rtdm_fd *fd,
252  unsigned int request, void __user *arg);
254  int (*ioctl_nrt)(struct rtdm_fd *fd,
255  unsigned int request, void __user *arg);
257  ssize_t (*read_rt)(struct rtdm_fd *fd,
258  void __user *buf, size_t size);
260  ssize_t (*read_nrt)(struct rtdm_fd *fd,
261  void __user *buf, size_t size);
263  ssize_t (*write_rt)(struct rtdm_fd *fd,
264  const void __user *buf, size_t size);
266  ssize_t (*write_nrt)(struct rtdm_fd *fd,
267  const void __user *buf, size_t size);
269  ssize_t (*recvmsg_rt)(struct rtdm_fd *fd,
270  struct user_msghdr *msg, int flags);
272  ssize_t (*recvmsg_nrt)(struct rtdm_fd *fd,
273  struct user_msghdr *msg, int flags);
275  ssize_t (*sendmsg_rt)(struct rtdm_fd *fd,
276  const struct user_msghdr *msg, int flags);
278  ssize_t (*sendmsg_nrt)(struct rtdm_fd *fd,
279  const struct user_msghdr *msg, int flags);
281  int (*select)(struct rtdm_fd *fd,
282  struct xnselector *selector,
283  unsigned int type, unsigned int index);
285  int (*mmap)(struct rtdm_fd *fd,
286  struct vm_area_struct *vma);
288  unsigned long (*get_unmapped_area)(struct rtdm_fd *fd,
289  unsigned long len,
290  unsigned long pgoff,
291  unsigned long flags);
292 };
293 
296 struct rtdm_fd {
297  unsigned int magic;
298  struct rtdm_fd_ops *ops;
299  struct cobalt_ppd *owner;
300  unsigned int refs;
301  int minor;
302  int oflags;
303 #ifdef CONFIG_XENO_ARCH_SYS3264
304  int compat;
305 #endif
306  struct list_head cleanup;
307 };
308 
309 #define RTDM_FD_MAGIC 0x52544446
310 
311 #define RTDM_FD_COMPAT __COBALT_COMPAT_BIT
312 #define RTDM_FD_COMPATX __COBALT_COMPATX_BIT
313 
314 int __rtdm_anon_getfd(const char *name, int flags);
315 
316 void __rtdm_anon_putfd(int ufd);
317 
318 static inline struct cobalt_ppd *rtdm_fd_owner(const struct rtdm_fd *fd)
319 {
320  return fd->owner;
321 }
322 
323 static inline int rtdm_fd_minor(const struct rtdm_fd *fd)
324 {
325  return fd->minor;
326 }
327 
328 static inline int rtdm_fd_flags(const struct rtdm_fd *fd)
329 {
330  return fd->oflags;
331 }
332 
333 #ifdef CONFIG_XENO_ARCH_SYS3264
334 static inline int rtdm_fd_is_compat(const struct rtdm_fd *fd)
335 {
336  return fd->compat;
337 }
338 #else
339 static inline int rtdm_fd_is_compat(const struct rtdm_fd *fd)
340 {
341  return 0;
342 }
343 #endif
344 
345 int rtdm_fd_enter(struct rtdm_fd *rtdm_fd, int ufd,
346  unsigned int magic, struct rtdm_fd_ops *ops);
347 
348 struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic);
349 
350 int rtdm_fd_lock(struct rtdm_fd *fd);
351 
352 void rtdm_fd_put(struct rtdm_fd *fd);
353 
354 void rtdm_fd_unlock(struct rtdm_fd *fd);
355 
356 int rtdm_fd_fcntl(int ufd, int cmd, ...);
357 
358 int rtdm_fd_ioctl(int ufd, unsigned int request, ...);
359 
360 ssize_t rtdm_fd_read(int ufd, void __user *buf, size_t size);
361 
362 ssize_t rtdm_fd_write(int ufd, const void __user *buf, size_t size);
363 
364 int rtdm_fd_close(int ufd, unsigned int magic);
365 
366 ssize_t rtdm_fd_recvmsg(int ufd, struct user_msghdr *msg, int flags);
367 
368 ssize_t rtdm_fd_sendmsg(int ufd, const struct user_msghdr *msg,
369  int flags);
370 
371 int rtdm_fd_mmap(int ufd, struct _rtdm_mmap_request *rma,
372  void **u_addrp);
373 
374 int rtdm_fd_valid_p(int ufd);
375 
376 int rtdm_fd_select(int ufd, struct xnselector *selector,
377  unsigned int type);
378 
379 void rtdm_fd_cleanup(struct cobalt_ppd *p);
380 
381 void rtdm_fd_init(void);
382 
383 #endif /* _COBALT_KERNEL_FD_H */
ssize_t(* read_nrt)(struct rtdm_fd *fd, void __user *buf, size_t size)
See rtdm_read_handler().
Definition: fd.h:260
int(* mmap)(struct rtdm_fd *fd, struct vm_area_struct *vma)
See rtdm_mmap_handler().
Definition: fd.h:285
ssize_t(* sendmsg_nrt)(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags)
See rtdm_sendmsg_handler().
Definition: fd.h:278
void rtdm_fd_put(struct rtdm_fd *fd)
Release a RTDM file descriptor obtained via rtdm_fd_get()
Definition: fd.c:301
ssize_t(* recvmsg_rt)(struct rtdm_fd *fd, struct user_msghdr *msg, int flags)
See rtdm_recvmsg_handler().
Definition: fd.h:269
RTDM file operation descriptor.
Definition: fd.h:243
ssize_t(* read_rt)(struct rtdm_fd *fd, void __user *buf, size_t size)
See rtdm_read_handler().
Definition: fd.h:257
ssize_t rtdm_write_handler(struct rtdm_fd *fd, const void __user *buf, size_t size)
Write handler.
int rtdm_mmap_handler(struct rtdm_fd *fd, struct vm_area_struct *vma)
Memory mapping handler.
int(* socket)(struct rtdm_fd *fd, int protocol)
See rtdm_socket_handler().
Definition: fd.h:247
unsigned long rtdm_get_unmapped_area_handler(struct rtdm_fd *fd, unsigned long len, unsigned long pgoff, unsigned long flags)
Allocate mapping region in address space.
struct rtdm_fd * rtdm_fd_get(int ufd, unsigned int magic)
Retrieve and lock a RTDM file descriptor.
Definition: fd.c:205
ssize_t rtdm_sendmsg_handler(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags)
Transmit message handler.
int(* ioctl_rt)(struct rtdm_fd *fd, unsigned int request, void __user *arg)
See rtdm_ioctl_handler().
Definition: fd.h:251
int rtdm_fd_lock(struct rtdm_fd *fd)
Hold a reference on a RTDM file descriptor.
Definition: fd.c:324
int(* ioctl_nrt)(struct rtdm_fd *fd, unsigned int request, void __user *arg)
See rtdm_ioctl_handler().
Definition: fd.h:254
ssize_t(* write_rt)(struct rtdm_fd *fd, const void __user *buf, size_t size)
See rtdm_write_handler().
Definition: fd.h:263
int rtdm_ioctl_handler(struct rtdm_fd *fd, unsigned int request, void __user *arg)
IOCTL handler.
int rtdm_fd_select(int ufd, struct xnselector *selector, unsigned int type)
Bind a selector to specified event types of a given file descriptor.
Definition: fd.c:723
int rtdm_open_handler(struct rtdm_fd *fd, int oflags)
Open handler for named devices.
ssize_t(* recvmsg_nrt)(struct rtdm_fd *fd, struct user_msghdr *msg, int flags)
See rtdm_recvmsg_handler().
Definition: fd.h:272
int rtdm_select_handler(struct rtdm_fd *fd, struct xnselector *selector, unsigned int type, unsigned int index)
Select handler.
int(* select)(struct rtdm_fd *fd, struct xnselector *selector, unsigned int type, unsigned int index)
See rtdm_select_handler().
Definition: fd.h:281
ssize_t rtdm_read_handler(struct rtdm_fd *fd, void __user *buf, size_t size)
Read handler.
void rtdm_close_handler(struct rtdm_fd *fd)
Close handler.
ssize_t(* write_nrt)(struct rtdm_fd *fd, const void __user *buf, size_t size)
See rtdm_write_handler().
Definition: fd.h:266
int(* open)(struct rtdm_fd *fd, int oflags)
See rtdm_open_handler().
Definition: fd.h:245
int rtdm_socket_handler(struct rtdm_fd *fd, int protocol)
Socket creation handler for protocol devices.
ssize_t(* sendmsg_rt)(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags)
See rtdm_sendmsg_handler().
Definition: fd.h:275
void(* close)(struct rtdm_fd *fd)
See rtdm_close_handler().
Definition: fd.h:249
ssize_t rtdm_recvmsg_handler(struct rtdm_fd *fd, struct user_msghdr *msg, int flags)
Receive message handler.
void rtdm_fd_unlock(struct rtdm_fd *fd)
Drop a reference on a RTDM file descriptor.
Definition: fd.c:350
unsigned long(* get_unmapped_area)(struct rtdm_fd *fd, unsigned long len, unsigned long pgoff, unsigned long flags)
See rtdm_get_unmapped_area_handler().
Definition: fd.h:288