Xenomai  3.1
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 struct rtdm_device;
35 
58 int rtdm_open_handler(struct rtdm_fd *fd, int oflags);
59 
71 int rtdm_socket_handler(struct rtdm_fd *fd, int protocol);
72 
82 void rtdm_close_handler(struct rtdm_fd *fd);
83 
98 int rtdm_ioctl_handler(struct rtdm_fd *fd, unsigned int request, void __user *arg);
99 
114 ssize_t rtdm_read_handler(struct rtdm_fd *fd, void __user *buf, size_t size);
115 
130 ssize_t rtdm_write_handler(struct rtdm_fd *fd, const void __user *buf, size_t size);
131 
147 ssize_t rtdm_recvmsg_handler(struct rtdm_fd *fd, struct user_msghdr *msg, int flags);
148 
164 ssize_t rtdm_sendmsg_handler(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags);
165 
181 int rtdm_select_handler(struct rtdm_fd *fd, struct xnselector *selector,
182  unsigned int type, unsigned int index);
183 
199 int rtdm_mmap_handler(struct rtdm_fd *fd, struct vm_area_struct *vma);
200 
232 unsigned long
233 rtdm_get_unmapped_area_handler(struct rtdm_fd *fd,
234  unsigned long len, unsigned long pgoff,
235  unsigned long flags);
244 struct rtdm_fd_ops {
246  int (*open)(struct rtdm_fd *fd, int oflags);
248  int (*socket)(struct rtdm_fd *fd, int protocol);
250  void (*close)(struct rtdm_fd *fd);
252  int (*ioctl_rt)(struct rtdm_fd *fd,
253  unsigned int request, void __user *arg);
255  int (*ioctl_nrt)(struct rtdm_fd *fd,
256  unsigned int request, void __user *arg);
258  ssize_t (*read_rt)(struct rtdm_fd *fd,
259  void __user *buf, size_t size);
261  ssize_t (*read_nrt)(struct rtdm_fd *fd,
262  void __user *buf, size_t size);
264  ssize_t (*write_rt)(struct rtdm_fd *fd,
265  const void __user *buf, size_t size);
267  ssize_t (*write_nrt)(struct rtdm_fd *fd,
268  const void __user *buf, size_t size);
270  ssize_t (*recvmsg_rt)(struct rtdm_fd *fd,
271  struct user_msghdr *msg, int flags);
273  ssize_t (*recvmsg_nrt)(struct rtdm_fd *fd,
274  struct user_msghdr *msg, int flags);
276  ssize_t (*sendmsg_rt)(struct rtdm_fd *fd,
277  const struct user_msghdr *msg, int flags);
279  ssize_t (*sendmsg_nrt)(struct rtdm_fd *fd,
280  const struct user_msghdr *msg, int flags);
282  int (*select)(struct rtdm_fd *fd,
283  struct xnselector *selector,
284  unsigned int type, unsigned int index);
286  int (*mmap)(struct rtdm_fd *fd,
287  struct vm_area_struct *vma);
289  unsigned long (*get_unmapped_area)(struct rtdm_fd *fd,
290  unsigned long len,
291  unsigned long pgoff,
292  unsigned long flags);
293 };
294 
297 struct rtdm_fd {
298  unsigned int magic;
299  struct rtdm_fd_ops *ops;
300  struct cobalt_ppd *owner;
301  unsigned int refs;
302  int ufd;
303  int minor;
304  int oflags;
305 #ifdef CONFIG_XENO_ARCH_SYS3264
306  int compat;
307 #endif
308  bool stale;
309  struct list_head cleanup;
310  struct list_head next; /* in dev->openfd_list */
311 };
312 
313 #define RTDM_FD_MAGIC 0x52544446
314 
315 #define RTDM_FD_COMPAT __COBALT_COMPAT_BIT
316 #define RTDM_FD_COMPATX __COBALT_COMPATX_BIT
317 
318 int __rtdm_anon_getfd(const char *name, int flags);
319 
320 void __rtdm_anon_putfd(int ufd);
321 
322 static inline struct cobalt_ppd *rtdm_fd_owner(const struct rtdm_fd *fd)
323 {
324  return fd->owner;
325 }
326 
327 static inline int rtdm_fd_ufd(const struct rtdm_fd *fd)
328 {
329  return fd->ufd;
330 }
331 
332 static inline int rtdm_fd_minor(const struct rtdm_fd *fd)
333 {
334  return fd->minor;
335 }
336 
337 static inline int rtdm_fd_flags(const struct rtdm_fd *fd)
338 {
339  return fd->oflags;
340 }
341 
342 #ifdef CONFIG_XENO_ARCH_SYS3264
343 static inline int rtdm_fd_is_compat(const struct rtdm_fd *fd)
344 {
345  return fd->compat;
346 }
347 #else
348 static inline int rtdm_fd_is_compat(const struct rtdm_fd *fd)
349 {
350  return 0;
351 }
352 #endif
353 
354 int rtdm_fd_enter(struct rtdm_fd *rtdm_fd, int ufd,
355  unsigned int magic, struct rtdm_fd_ops *ops);
356 
357 int rtdm_fd_register(struct rtdm_fd *fd, int ufd);
358 
359 struct rtdm_fd *rtdm_fd_get(int ufd, unsigned int magic);
360 
361 int rtdm_fd_lock(struct rtdm_fd *fd);
362 
363 void rtdm_fd_put(struct rtdm_fd *fd);
364 
365 void rtdm_fd_unlock(struct rtdm_fd *fd);
366 
367 int rtdm_fd_fcntl(int ufd, int cmd, ...);
368 
369 int rtdm_fd_ioctl(int ufd, unsigned int request, ...);
370 
371 ssize_t rtdm_fd_read(int ufd, void __user *buf, size_t size);
372 
373 ssize_t rtdm_fd_write(int ufd, const void __user *buf, size_t size);
374 
375 int rtdm_fd_close(int ufd, unsigned int magic);
376 
377 ssize_t rtdm_fd_recvmsg(int ufd, struct user_msghdr *msg, int flags);
378 
379 int __rtdm_fd_recvmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
380  unsigned int flags, void __user *u_timeout,
381  int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
382  int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg),
383  int (*get_timespec)(struct timespec *ts, const void __user *u_ts));
384 
385 ssize_t rtdm_fd_sendmsg(int ufd, const struct user_msghdr *msg,
386  int flags);
387 
388 int __rtdm_fd_sendmmsg(int ufd, void __user *u_msgvec, unsigned int vlen,
389  unsigned int flags,
390  int (*get_mmsg)(struct mmsghdr *mmsg, void __user *u_mmsg),
391  int (*put_mmsg)(void __user **u_mmsg_p, const struct mmsghdr *mmsg));
392 
393 int rtdm_fd_mmap(int ufd, struct _rtdm_mmap_request *rma,
394  void **u_addrp);
395 
396 int rtdm_fd_valid_p(int ufd);
397 
398 int rtdm_fd_select(int ufd, struct xnselector *selector,
399  unsigned int type);
400 
401 int rtdm_device_new_fd(struct rtdm_fd *fd, int ufd,
402  struct rtdm_device *dev);
403 
404 void rtdm_device_flush_fds(struct rtdm_device *dev);
405 
406 void rtdm_fd_cleanup(struct cobalt_ppd *p);
407 
408 void rtdm_fd_init(void);
409 
410 #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:261
int(* mmap)(struct rtdm_fd *fd, struct vm_area_struct *vma)
See rtdm_mmap_handler().
Definition: fd.h:286
ssize_t(* sendmsg_nrt)(struct rtdm_fd *fd, const struct user_msghdr *msg, int flags)
See rtdm_sendmsg_handler().
Definition: fd.h:279
void rtdm_fd_put(struct rtdm_fd *fd)
Release a RTDM file descriptor obtained via rtdm_fd_get()
Definition: fd.c:362
ssize_t(* recvmsg_rt)(struct rtdm_fd *fd, struct user_msghdr *msg, int flags)
See rtdm_recvmsg_handler().
Definition: fd.h:270
RTDM file operation descriptor.
Definition: fd.h:244
ssize_t(* read_rt)(struct rtdm_fd *fd, void __user *buf, size_t size)
See rtdm_read_handler().
Definition: fd.h:258
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:248
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:234
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:252
int rtdm_fd_lock(struct rtdm_fd *fd)
Hold a reference on a RTDM file descriptor
Definition: fd.c:386
int(* ioctl_nrt)(struct rtdm_fd *fd, unsigned int request, void __user *arg)
See rtdm_ioctl_handler().
Definition: fd.h:255
ssize_t(* write_rt)(struct rtdm_fd *fd, const void __user *buf, size_t size)
See rtdm_write_handler().
Definition: fd.h:264
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:952
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:273
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:282
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:267
int(* open)(struct rtdm_fd *fd, int oflags)
See rtdm_open_handler().
Definition: fd.h:246
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:276
void(* close)(struct rtdm_fd *fd)
See rtdm_close_handler().
Definition: fd.h:250
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:413
RTDM device.
Definition: driver.h:338
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:289