Xenomai  3.0.8
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_resources {
38  struct list_head condq;
39  struct list_head mutexq;
40  struct list_head semq;
41  struct list_head monitorq;
42  struct list_head eventq;
43  struct list_head schedq;
44 };
45 
46 struct cobalt_process {
47  struct mm_struct *mm;
48  struct hlist_node hlink;
49  struct cobalt_ppd sys_ppd;
50  unsigned long permap;
51  struct rb_root usems;
52  struct list_head sigwaiters;
53  struct cobalt_resources resources;
54  DECLARE_BITMAP(timers_map, CONFIG_XENO_OPT_NRTIMERS);
55  struct cobalt_timer *timers[CONFIG_XENO_OPT_NRTIMERS];
56  void *priv[NR_PERSONALITIES];
57 };
58 
59 struct cobalt_resnode {
60  struct cobalt_resources *scope;
61  struct cobalt_process *owner;
62  struct list_head next;
63  xnhandle_t handle;
64 };
65 
66 int cobalt_register_personality(struct xnthread_personality *personality);
67 
68 int cobalt_unregister_personality(int xid);
69 
70 struct xnthread_personality *cobalt_push_personality(int xid);
71 
72 void cobalt_pop_personality(struct xnthread_personality *prev);
73 
74 int cobalt_bind_core(void);
75 
76 int cobalt_bind_personality(unsigned int magic);
77 
78 struct cobalt_process *cobalt_search_process(struct mm_struct *mm);
79 
80 int cobalt_map_user(struct xnthread *thread, __u32 __user *u_winoff);
81 
82 void *cobalt_get_context(int xid);
83 
84 int cobalt_yield(xnticks_t min, xnticks_t max);
85 
86 int cobalt_process_init(void);
87 
88 extern struct list_head cobalt_thread_list;
89 
90 extern struct cobalt_resources cobalt_global_resources;
91 
92 static inline struct cobalt_process *cobalt_current_process(void)
93 {
94  return ipipe_current_threadinfo()->process;
95 }
96 
97 static inline struct cobalt_process *
98 cobalt_set_process(struct cobalt_process *process)
99 {
100  struct ipipe_threadinfo *p = ipipe_current_threadinfo();
101  struct cobalt_process *old;
102 
103  old = p->process;
104  p->process = process;
105 
106  return old;
107 }
108 
109 static inline struct cobalt_ppd *cobalt_ppd_get(int global)
110 {
111  struct cobalt_process *process;
112 
113  if (global || (process = cobalt_current_process()) == NULL)
114  return &cobalt_kernel_ppd;
115 
116  return &process->sys_ppd;
117 }
118 
119 static inline struct cobalt_resources *cobalt_current_resources(int pshared)
120 {
121  struct cobalt_process *process;
122 
123  if (pshared || (process = cobalt_current_process()) == NULL)
124  return &cobalt_global_resources;
125 
126  return &process->resources;
127 }
128 
129 static inline
130 void __cobalt_add_resource(struct cobalt_resnode *node, int pshared)
131 {
132  node->owner = cobalt_current_process();
133  node->scope = cobalt_current_resources(pshared);
134 }
135 
136 #define cobalt_add_resource(__node, __type, __pshared) \
137  do { \
138  __cobalt_add_resource(__node, __pshared); \
139  list_add_tail(&(__node)->next, \
140  &((__node)->scope)->__type ## q); \
141  } while (0)
142 
143 static inline
144 void cobalt_del_resource(struct cobalt_resnode *node)
145 {
146  list_del(&node->next);
147 }
148 
149 extern struct xnthread_personality *cobalt_personalities[];
150 
151 extern struct xnthread_personality cobalt_personality;
152 
153 #endif /* !_COBALT_POSIX_PROCESS_H */