enable kexec
[linux-2.6.git] / include / linux / ckrm.h
1 /* ckrm.h - Class-based Kernel Resource Management (CKRM)
2  *
3  * Copyright (C) Hubertus Franke, IBM Corp. 2003,2004
4  *           (C) Shailabh Nagar,  IBM Corp. 2003
5  *           (C) Chandra Seetharaman, IBM Corp. 2003
6  * 
7  * 
8  * Provides a base header file including macros and basic data structures.
9  *
10  * Latest version, more details at http://ckrm.sf.net
11  * 
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of version 2.1 of the GNU Lesser General Public License
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it would be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  */
21
22 /* Changes
23  *
24  * 28 Aug 2003
25  *        Created.
26  * 06 Nov 2003
27  *        Made modifications to suit the new RBCE module.
28  * 10 Nov 2003
29  *        Added callbacks_active and surrounding logic. Added task paramter
30  *        for all CE callbacks.
31  * 19 Nov 2004
32  *        New Event callback structure
33  */
34
35 #ifndef _LINUX_CKRM_H
36 #define _LINUX_CKRM_H
37
38 #ifdef CONFIG_CKRM
39
40 // Data structure and function to get the list of registered 
41 // resource controllers.
42
43 // #include <linux/sched.h>
44
45 /* CKRM defines a set of events at particular points in the kernel
46  * at which callbacks registered by various class types are called
47  */
48
49 enum ckrm_event {
50         /* we distinguish various events types
51          *
52          * (a) CKRM_LATCHABLE_EVENTS
53          *      events can be latched for event callbacks by classtypes
54          *
55          * (b) CKRM_NONLATACHBLE_EVENTS
56          *     events can not be latched but can be used to call classification
57          * 
58          * (c) event that are used for notification purposes
59          *     range: [ CKRM_EVENT_CANNOT_CLASSIFY .. )
60          */
61
62         /* events (a) */
63
64         CKRM_LATCHABLE_EVENTS,
65
66         CKRM_EVENT_NEWTASK = CKRM_LATCHABLE_EVENTS,
67         CKRM_EVENT_FORK,
68         CKRM_EVENT_EXIT,
69         CKRM_EVENT_EXEC,
70         CKRM_EVENT_UID,
71         CKRM_EVENT_GID,
72         CKRM_EVENT_XID,
73         CKRM_EVENT_LOGIN,
74         CKRM_EVENT_USERADD,
75         CKRM_EVENT_USERDEL,
76         CKRM_EVENT_LISTEN_START,
77         CKRM_EVENT_LISTEN_STOP,
78         CKRM_EVENT_APPTAG,
79
80         /* events (b) */
81
82         CKRM_NONLATCHABLE_EVENTS,
83
84         CKRM_EVENT_RECLASSIFY = CKRM_NONLATCHABLE_EVENTS,
85
86         /* events (c) */
87         CKRM_NOTCLASSIFY_EVENTS,
88
89         CKRM_EVENT_MANUAL = CKRM_NOTCLASSIFY_EVENTS,
90
91         CKRM_NUM_EVENTS
92 };
93 #endif
94
95 #ifdef __KERNEL__
96 #ifdef CONFIG_CKRM
97
98 extern void ckrm_invoke_event_cb_chain(enum ckrm_event ev, void *arg);
99
100 typedef void (*ckrm_event_cb) (void *arg);
101
102 struct ckrm_hook_cb {
103         ckrm_event_cb fct;
104         struct ckrm_hook_cb *next;
105 };
106
107 #define CKRM_DEF_CB(EV,fct)                                     \
108 static inline void ckrm_cb_##fct(void)                          \
109 {                                                               \
110          ckrm_invoke_event_cb_chain(CKRM_EVENT_##EV,NULL);      \
111 }
112
113 #define CKRM_DEF_CB_ARG(EV,fct,argtp)                                   \
114 static inline void ckrm_cb_##fct(argtp arg)                             \
115 {                                                                       \
116          ckrm_invoke_event_cb_chain(CKRM_EVENT_##EV,(void*)arg);        \
117 }
118
119 #else                           // !CONFIG_CKRM
120
121 #define CKRM_DEF_CB(EV,fct)                     \
122 static inline void ckrm_cb_##fct(void)  { }
123
124 #define CKRM_DEF_CB_ARG(EV,fct,argtp)           \
125 static inline void ckrm_cb_##fct(argtp arg) { }
126
127 #endif                          // CONFIG_CKRM
128
129 /*-----------------------------------------------------------------
130  *   define the CKRM event functions 
131  *               EVENT          FCT           ARG         
132  *-----------------------------------------------------------------*/
133
134 // types we refer at 
135 struct task_struct;
136 struct sock;
137 struct user_struct;
138
139 CKRM_DEF_CB_ARG(FORK, fork, struct task_struct *);
140 CKRM_DEF_CB_ARG(EXEC, exec, const char *);
141 CKRM_DEF_CB(UID, uid);
142 CKRM_DEF_CB(GID, gid);
143 CKRM_DEF_CB_ARG(XID, xid, struct task_struct *);
144 CKRM_DEF_CB(APPTAG, apptag);
145 CKRM_DEF_CB(LOGIN, login);
146 CKRM_DEF_CB_ARG(USERADD, useradd, struct user_struct *);
147 CKRM_DEF_CB_ARG(USERDEL, userdel, struct user_struct *);
148 CKRM_DEF_CB_ARG(LISTEN_START, listen_start, struct sock *);
149 CKRM_DEF_CB_ARG(LISTEN_STOP, listen_stop, struct sock *);
150
151 // some other functions required
152 #ifdef CONFIG_CKRM
153 extern void ckrm_init(void);
154 void ckrm_cb_newtask(struct task_struct *);
155 void ckrm_cb_exit(struct task_struct *);
156 #else
157 #define ckrm_init(x)            do { } while (0)
158 #define ckrm_cb_newtask(x)      do { } while (0)
159 #define ckrm_cb_exit(x)         do { } while (0)
160 #endif
161
162 extern int get_exe_path_name(struct task_struct *, char *, int);
163
164 #endif                          // __KERNEL__
165
166 #endif                          // _LINUX_CKRM_H