Xenomai  3.0-rc3
process.h
1 /*
2  * Copyright (C) 2013 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 #ifndef _COBALT_POSIX_PROCESS_H
19 #define _COBALT_POSIX_PROCESS_H
20 
21 #include <linux/list.h>
22 #include <linux/bitmap.h>
23 #include <cobalt/kernel/ppd.h>
24 
25 #define KEVENT_PROPAGATE 0
26 #define KEVENT_STOP 1
27 
28 #define NR_PERSONALITIES 4
29 #if BITS_PER_LONG < NR_PERSONALITIES
30 #error "NR_PERSONALITIES overflows internal bitmap"
31 #endif
32 
33 struct mm_struct;
34 struct xnthread_personality;
35 struct cobalt_timer;
36 
37 struct cobalt_kqueues {
38  struct list_head condq;
39  struct list_head mutexq;
40  struct list_head semq;
41  struct list_head threadq;
42  struct list_head monitorq;
43  struct list_head eventq;
44  struct list_head schedq;
45 };
46 
47 struct cobalt_process {
48  struct mm_struct *mm;
49  struct hlist_node hlink;
50  struct cobalt_ppd sys_ppd;
51  unsigned long permap;
52  struct cobalt_kqueues kqueues;
53  struct rb_root usems;
54  struct list_head sigwaiters;
55  DECLARE_BITMAP(timers_map, CONFIG_XENO_OPT_NRTIMERS);
56  struct cobalt_timer *timers[CONFIG_XENO_OPT_NRTIMERS];
57  void *priv[NR_PERSONALITIES];
58 };
59 
60 extern struct cobalt_kqueues cobalt_global_kqueues;
61 
62 int cobalt_register_personality(struct xnthread_personality *personality);
63 
64 int cobalt_unregister_personality(int xid);
65 
66 struct xnthread_personality *cobalt_push_personality(int xid);
67 
68 void cobalt_pop_personality(struct xnthread_personality *prev);
69 
70 int cobalt_bind_core(void);
71 
72 int cobalt_bind_personality(unsigned int magic);
73 
74 struct cobalt_process *cobalt_search_process(struct mm_struct *mm);
75 
76 int cobalt_map_user(struct xnthread *thread, __u32 __user *u_winoff);
77 
78 void *cobalt_get_context(int xid);
79 
80 int cobalt_yield(xnticks_t min, xnticks_t max);
81 
82 int cobalt_process_init(void);
83 
84 void cobalt_process_cleanup(void);
85 
86 static inline struct cobalt_process *cobalt_current_process(void)
87 {
88  return ipipe_current_threadinfo()->process;
89 }
90 
91 static inline struct cobalt_process *
92 cobalt_set_process(struct cobalt_process *process)
93 {
94  struct ipipe_threadinfo *p = ipipe_current_threadinfo();
95  struct cobalt_process *old;
96 
97  old = p->process;
98  p->process = process;
99 
100  return old;
101 }
102 
103 static inline struct cobalt_ppd *cobalt_ppd_get(int global)
104 {
105  struct cobalt_process *process;
106 
107  if (global || (process = cobalt_current_process()) == NULL)
108  return &__xnsys_global_ppd;
109 
110  return &process->sys_ppd;
111 }
112 
113 extern struct xnthread_personality *cobalt_personalities[];
114 
115 extern struct xnthread_personality cobalt_personality;
116 
117 #endif /* !_COBALT_POSIX_PROCESS_H */