1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 #ifndef __LIBCFS_LINUX_KP30_H__
5 #define __LIBCFS_LINUX_KP30_H__
7 #ifndef __LIBCFS_KP30_H__
8 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
12 #ifndef AUTOCONF_INCLUDED
13 # include <linux/config.h>
15 # include <linux/kernel.h>
16 # include <linux/mm.h>
17 # include <linux/string.h>
18 # include <linux/stat.h>
19 # include <linux/init.h>
20 # include <linux/errno.h>
21 # include <linux/unistd.h>
22 # include <asm/system.h>
23 # include <linux/kmod.h>
24 # include <linux/notifier.h>
25 # include <linux/fs.h>
26 # include <linux/miscdevice.h>
27 # include <linux/vmalloc.h>
28 # include <linux/time.h>
29 # include <linux/slab.h>
30 # include <linux/interrupt.h>
31 # include <linux/highmem.h>
32 # include <linux/module.h>
33 # include <linux/version.h>
34 # include <linux/smp_lock.h>
35 # include <asm/atomic.h>
36 # include <asm/uaccess.h>
37 # include <linux/rwsem.h>
38 # include <linux/proc_fs.h>
39 # include <linux/file.h>
40 # include <linux/smp.h>
41 # include <linux/ctype.h>
42 # include <linux/compiler.h>
43 # ifdef HAVE_MM_INLINE
44 # include <linux/mm_inline.h>
46 # if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
47 # include <linux/kallsyms.h>
48 # include <linux/moduleparam.h>
51 #include <libcfs/linux/portals_compat25.h>
53 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
54 #define schedule_work schedule_task
55 #define prepare_work(wq,cb,cbdata) \
57 INIT_TQUEUE((wq), 0, 0); \
58 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
61 #define PageUptodate Page_Uptodate
62 #define our_recalc_sigpending(current) recalc_sigpending(current)
63 #define num_online_cpus() smp_num_cpus
64 static inline void our_cond_resched(void)
66 if (current->need_resched)
69 #define work_struct_t struct tq_struct
70 #define cfs_get_work_data(type,field,data) (data)
73 #ifdef HAVE_3ARGS_INIT_WORK
75 #define prepare_work(wq,cb,cbdata) \
77 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
80 #define cfs_get_work_data(type,field,data) (data)
84 #define prepare_work(wq,cb,cbdata) \
86 INIT_WORK((wq), (void *)(cb)); \
89 #define cfs_get_work_data(type,field,data) container_of(data,type,field)
93 #define wait_on_page wait_on_page_locked
94 #define our_recalc_sigpending(current) recalc_sigpending()
95 #define strtok(a,b) strpbrk(a, b)
96 static inline void our_cond_resched(void)
100 #define work_struct_t struct work_struct
102 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
105 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
107 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
109 #define LASSERT_SEM_LOCKED(sem) LASSERT(down_trylock(sem) != 0)
111 #define LIBCFS_PANIC(msg) panic(msg)
113 /* ------------------------------------------------------------------- */
115 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
117 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
118 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
120 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
121 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
123 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
124 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
127 #define PORTAL_SYMBOL_REGISTER(x)
128 #define PORTAL_SYMBOL_UNREGISTER(x)
130 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
131 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
133 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
134 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
138 /******************************************************************************/
139 /* Module parameter support */
140 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
141 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
142 MODULE_PARM(name, t);\
143 MODULE_PARM_DESC(name, desc)
146 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
147 module_param(name, type, perm);\
148 MODULE_PARM_DESC(name, desc)
151 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
152 # define CFS_SYSFS_MODULE_PARM 0 /* no sysfs module parameters */
154 # define CFS_SYSFS_MODULE_PARM 1 /* module parameters accessible via sysfs */
156 /******************************************************************************/
159 /* Use the special GNU C __attribute__ hack to have the compiler check the
160 * printf style argument string against the actual argument count and
164 # warning printf has been defined as a macro...
168 #endif /* __GNUC__ */
170 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
171 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
172 # define time(a) CURRENT_TIME
174 #ifndef num_possible_cpus
175 #define num_possible_cpus() NR_CPUS
177 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
178 #define i_size_read(a) ((a)->i_size)
181 #else /* !__KERNEL__ */
184 #if defined(__CYGWIN__)
185 # include <cygwin-ioctl.h>
193 # include <sys/ioctl.h> /* for _IOWR */
198 # define CFS_MODULE_PARM(name, t, type, perm, desc)
199 #define PORTAL_SYMBOL_GET(x) inter_module_get(#x)
200 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
202 #endif /* End of !__KERNEL__ */
204 /******************************************************************************/
205 /* Light-weight trace
206 * Support for temporary event tracing with minimal Heisenberg effect. */
207 #define LWT_SUPPORT 0
209 #define LWT_MEMORY (16<<20)
212 # if defined(__KERNEL__)
213 # if !defined(BITS_PER_LONG)
214 # error "BITS_PER_LONG not defined"
216 # elif !defined(__WORDSIZE)
217 # error "__WORDSIZE not defined"
219 # define BITS_PER_LONG __WORDSIZE
222 /* kernel hasn't defined this? */
231 # if BITS_PER_LONG > 32
235 #endif /* !KLWT_SUPPORT */
241 typedef struct _lwt_page {
242 struct list_head lwtp_list;
243 struct page *lwtp_page;
244 lwt_event_t *lwtp_events;
248 int lwtc_current_index;
249 lwt_page_t *lwtc_current_page;
252 extern int lwt_enabled;
253 extern lwt_cpu_t lwt_cpus[];
255 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
256 * This stuff is meant for finding specific problems; it never stays in
257 * production code... */
260 #define LWTWHERE(f,l) f ":" LWTSTR(l)
261 #define LWT_EVENTS_PER_PAGE (CFS_PAGE_SIZE / sizeof (lwt_event_t))
263 #define LWT_EVENT(p1, p2, p3, p4) \
265 unsigned long flags; \
271 local_irq_save (flags); \
273 cpu = &lwt_cpus[smp_processor_id()]; \
274 p = cpu->lwtc_current_page; \
275 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
277 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
278 cpu->lwtc_current_page = \
279 list_entry (p->lwtp_list.next, \
280 lwt_page_t, lwtp_list); \
281 cpu->lwtc_current_index = 0; \
284 e->lwte_when = get_cycles(); \
285 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
286 e->lwte_task = current; \
287 e->lwte_p1 = (long)(p1); \
288 e->lwte_p2 = (long)(p2); \
289 e->lwte_p3 = (long)(p3); \
290 e->lwte_p4 = (long)(p4); \
292 local_irq_restore (flags); \
296 #endif /* !KLWT_SUPPORT */
298 extern int lwt_init (void);
299 extern void lwt_fini (void);
300 extern int lwt_lookup_string (int *size, char *knlptr,
301 char *usrptr, int usrsize);
302 extern int lwt_control (int enable, int clear);
303 extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
304 void *user_ptr, int user_size);
305 # else /* __KERNEL__ */
306 # define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
307 # endif /* __KERNEL__ */
308 #endif /* LWT_SUPPORT */
310 /* ------------------------------------------------------------------ */
312 #define IOCTL_LIBCFS_TYPE long
315 # ifndef BITS_PER_LONG
316 # if (~0UL) == 0xffffffffUL
317 # define BITS_PER_LONG 32
319 # define BITS_PER_LONG 64
324 #if BITS_PER_LONG > 32
325 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
326 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
327 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
329 # define LI_POISON ((int)0x5a5a5a5a)
330 # define LL_POISON ((long)0x5a5a5a5a)
331 # define LP_POISON ((void *)(long)0x5a5a5a5a)
334 /* this is a bit chunky */
336 #if defined(__KERNEL__)
337 #define _LWORDSIZE BITS_PER_LONG
339 #define _LWORDSIZE __WORDSIZE
342 #if (defined(__x86_64__) && (defined(__KERNEL__) || defined(CRAY_XT3))) || defined(HAVE_U64_LONG_LONG)
343 /* x86_64 defines __u64 as "long" in userspace, but "long long" in the kernel */
346 # define LPX64 "%#Lx"
348 #elif (_LWORDSIZE == 32)
351 # define LPX64 "%#Lx"
353 #elif (_LWORDSIZE == 64)
356 # define LPX64 "%#lx"
360 #ifdef HAVE_SIZE_T_LONG
366 #ifdef HAVE_SSIZE_T_LONG
373 # error "No word size defined"