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/kp30.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 # ifdef HAVE_SEGMENT_H
27 # include <asm/segment.h>
29 # include <linux/miscdevice.h>
30 # include <linux/vmalloc.h>
31 # include <linux/time.h>
32 # include <linux/slab.h>
33 # include <linux/interrupt.h>
34 # include <linux/highmem.h>
35 # include <linux/module.h>
36 # include <linux/version.h>
37 # include <lnet/lnet.h>
38 # include <linux/smp_lock.h>
39 # include <asm/atomic.h>
40 # include <asm/uaccess.h>
41 # include <linux/rwsem.h>
42 # include <linux/proc_fs.h>
43 # include <linux/file.h>
44 # include <linux/smp.h>
45 # include <linux/ctype.h>
46 # include <linux/compiler.h>
47 # ifdef HAVE_MM_INLINE
48 # include <linux/mm_inline.h>
50 # if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
51 # include <linux/kallsyms.h>
52 # include <linux/moduleparam.h>
55 #include <libcfs/linux/portals_compat25.h>
57 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
58 #define schedule_work schedule_task
59 #define prepare_work(wq,cb,cbdata) \
61 INIT_TQUEUE((wq), 0, 0); \
62 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
65 #define PageUptodate Page_Uptodate
66 #define our_recalc_sigpending(current) recalc_sigpending(current)
67 #define num_online_cpus() smp_num_cpus
68 static inline void our_cond_resched(void)
70 if (current->need_resched)
73 #define work_struct_t struct tq_struct
74 #define cfs_get_work_data(type,field,data) (data)
77 #ifdef HAVE_3ARGS_INIT_WORK
79 #define prepare_work(wq,cb,cbdata) \
81 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
84 #define cfs_get_work_data(type,field,data) (data)
88 #define prepare_work(wq,cb,cbdata) \
90 INIT_WORK((wq), (void *)(cb)); \
93 #define cfs_get_work_data(type,field,data) container_of(data,type,field)
97 #define wait_on_page wait_on_page_locked
98 #define our_recalc_sigpending(current) recalc_sigpending()
99 #define strtok(a,b) strpbrk(a, b)
100 static inline void our_cond_resched(void)
104 #define work_struct_t struct work_struct
106 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
109 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
111 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
113 #define LASSERT_SEM_LOCKED(sem) LASSERT(down_trylock(sem) != 0)
115 #define LIBCFS_PANIC(msg) panic(msg)
117 /* ------------------------------------------------------------------- */
119 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
121 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
122 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
124 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
125 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
127 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
128 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
131 #define PORTAL_SYMBOL_REGISTER(x)
132 #define PORTAL_SYMBOL_UNREGISTER(x)
134 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
135 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
137 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
138 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
142 /******************************************************************************/
143 /* Module parameter support */
144 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
145 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
146 MODULE_PARM(name, t);\
147 MODULE_PARM_DESC(name, desc)
150 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
151 module_param(name, type, perm);\
152 MODULE_PARM_DESC(name, desc)
155 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
156 # define CFS_SYSFS_MODULE_PARM 0 /* no sysfs module parameters */
158 # define CFS_SYSFS_MODULE_PARM 1 /* module parameters accessible via sysfs */
160 /******************************************************************************/
163 /* Use the special GNU C __attribute__ hack to have the compiler check the
164 * printf style argument string against the actual argument count and
168 # warning printf has been defined as a macro...
172 #endif /* __GNUC__ */
174 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
175 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
176 # define time(a) CURRENT_TIME
178 #ifndef num_possible_cpus
179 #define num_possible_cpus() NR_CPUS
181 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
182 #define i_size_read(a) ((a)->i_size)
185 #else /* !__KERNEL__ */
190 #elif defined(__CYGWIN__)
191 # include <cygwin-ioctl.h>
199 # include <sys/ioctl.h> /* for _IOWR */
201 # define CFS_MODULE_PARM(name, t, type, perm, desc)
202 #define PORTAL_SYMBOL_GET(x) inter_module_get(#x)
203 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
205 #endif /* End of !__KERNEL__ */
207 /******************************************************************************/
208 /* Light-weight trace
209 * Support for temporary event tracing with minimal Heisenberg effect. */
210 #define LWT_SUPPORT 0
212 #define LWT_MEMORY (16<<20)
215 # if defined(__KERNEL__)
216 # if !defined(BITS_PER_LONG)
217 # error "BITS_PER_LONG not defined"
219 # elif !defined(__WORDSIZE)
220 # error "__WORDSIZE not defined"
222 # define BITS_PER_LONG __WORDSIZE
225 /* kernel hasn't defined this? */
234 # if BITS_PER_LONG > 32
238 #endif /* !KLWT_SUPPORT */
244 typedef struct _lwt_page {
245 struct list_head lwtp_list;
246 struct page *lwtp_page;
247 lwt_event_t *lwtp_events;
251 int lwtc_current_index;
252 lwt_page_t *lwtc_current_page;
255 extern int lwt_enabled;
256 extern lwt_cpu_t lwt_cpus[];
258 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
259 * This stuff is meant for finding specific problems; it never stays in
260 * production code... */
263 #define LWTWHERE(f,l) f ":" LWTSTR(l)
264 #define LWT_EVENTS_PER_PAGE (CFS_PAGE_SIZE / sizeof (lwt_event_t))
266 #define LWT_EVENT(p1, p2, p3, p4) \
268 unsigned long flags; \
274 local_irq_save (flags); \
276 cpu = &lwt_cpus[smp_processor_id()]; \
277 p = cpu->lwtc_current_page; \
278 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
280 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
281 cpu->lwtc_current_page = \
282 list_entry (p->lwtp_list.next, \
283 lwt_page_t, lwtp_list); \
284 cpu->lwtc_current_index = 0; \
287 e->lwte_when = get_cycles(); \
288 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
289 e->lwte_task = current; \
290 e->lwte_p1 = (long)(p1); \
291 e->lwte_p2 = (long)(p2); \
292 e->lwte_p3 = (long)(p3); \
293 e->lwte_p4 = (long)(p4); \
295 local_irq_restore (flags); \
299 #endif /* !KLWT_SUPPORT */
301 extern int lwt_init (void);
302 extern void lwt_fini (void);
303 extern int lwt_lookup_string (int *size, char *knlptr,
304 char *usrptr, int usrsize);
305 extern int lwt_control (int enable, int clear);
306 extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
307 void *user_ptr, int user_size);
308 # else /* __KERNEL__ */
309 # define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
310 # endif /* __KERNEL__ */
311 #endif /* LWT_SUPPORT */
313 /* ------------------------------------------------------------------ */
315 #define IOCTL_LIBCFS_TYPE long
318 # ifndef BITS_PER_LONG
319 # if (~0UL) == 0xffffffffUL
320 # define BITS_PER_LONG 32
322 # define BITS_PER_LONG 64
327 #if BITS_PER_LONG > 32
328 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
329 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
330 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
332 # define LI_POISON ((int)0x5a5a5a5a)
333 # define LL_POISON ((long)0x5a5a5a5a)
334 # define LP_POISON ((void *)(long)0x5a5a5a5a)
337 /* this is a bit chunky */
339 #if defined(__KERNEL__)
340 #define _LWORDSIZE BITS_PER_LONG
342 #define _LWORDSIZE __WORDSIZE
345 #if (defined(__x86_64__) && (defined(__KERNEL__) || defined(CRAY_XT3)))
346 /* x86_64 defines __u64 as "long" in userspace, but "long long" in the kernel */
349 # define LPX64 "%#Lx"
353 #elif (_LWORDSIZE == 32)
356 # define LPX64 "%#Lx"
360 #elif (_LWORDSIZE == 64)
363 # define LPX64 "%#lx"
369 # error "No word size defined"