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 #ifdef HAVE_KERNEL_CONFIG_H
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 <asm/segment.h>
27 # include <linux/miscdevice.h>
28 # include <linux/vmalloc.h>
29 # include <linux/time.h>
30 # include <linux/slab.h>
31 # include <linux/interrupt.h>
32 # include <linux/highmem.h>
33 # include <linux/module.h>
34 # include <linux/version.h>
35 # include <lnet/lnet.h>
36 # include <linux/smp_lock.h>
37 # include <asm/atomic.h>
38 # include <asm/uaccess.h>
39 # include <linux/rwsem.h>
40 # include <linux/proc_fs.h>
41 # include <linux/file.h>
42 # include <linux/smp.h>
43 # include <linux/ctype.h>
44 # include <linux/compiler.h>
45 # ifdef HAVE_MM_INLINE
46 # include <linux/mm_inline.h>
48 # if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
49 # include <linux/kallsyms.h>
50 # include <linux/moduleparam.h>
53 #include <libcfs/linux/portals_compat25.h>
55 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
56 #define schedule_work schedule_task
57 #define prepare_work(wq,cb,cbdata) \
59 INIT_TQUEUE((wq), 0, 0); \
60 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
63 #define PageUptodate Page_Uptodate
64 #define our_recalc_sigpending(current) recalc_sigpending(current)
65 #define num_online_cpus() smp_num_cpus
66 static inline void our_cond_resched(void)
68 if (current->need_resched)
71 #define work_struct_t struct tq_struct
75 #define prepare_work(wq,cb,cbdata) \
77 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
79 #define wait_on_page wait_on_page_locked
80 #define our_recalc_sigpending(current) recalc_sigpending()
81 #define strtok(a,b) strpbrk(a, b)
82 static inline void our_cond_resched(void)
86 #define work_struct_t struct work_struct
88 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
91 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
93 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
95 #define LASSERT_SEM_LOCKED(sem) LASSERT(down_trylock(sem) != 0)
97 #define LIBCFS_PANIC(msg) panic(msg)
99 /* ------------------------------------------------------------------- */
101 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
103 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
104 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
106 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
107 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
109 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
110 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
113 #define PORTAL_SYMBOL_REGISTER(x)
114 #define PORTAL_SYMBOL_UNREGISTER(x)
116 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
117 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
119 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
120 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
124 /******************************************************************************/
125 /* Module parameter support */
126 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
127 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
128 MODULE_PARM(name, t);\
129 MODULE_PARM_DESC(name, desc)
132 # define CFS_MODULE_PARM(name, t, type, perm, desc) \
133 module_param(name, type, perm);\
134 MODULE_PARM_DESC(name, desc)
137 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
138 # define CFS_SYSFS_MODULE_PARM 0 /* no sysfs module parameters */
140 # define CFS_SYSFS_MODULE_PARM 1 /* module parameters accessible via sysfs */
142 /******************************************************************************/
145 /* Use the special GNU C __attribute__ hack to have the compiler check the
146 * printf style argument string against the actual argument count and
150 # warning printf has been defined as a macro...
154 #endif /* __GNUC__ */
156 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
157 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
158 # define time(a) CURRENT_TIME
160 #else /* !__KERNEL__ */
165 #elif defined(__CYGWIN__)
166 # include <cygwin-ioctl.h>
174 # include <sys/ioctl.h> /* for _IOWR */
176 # define CFS_MODULE_PARM(name, t, type, perm, desc)
177 #define PORTAL_SYMBOL_GET(x) inter_module_get(#x)
178 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
180 #endif /* End of !__KERNEL__ */
182 /******************************************************************************/
183 /* Light-weight trace
184 * Support for temporary event tracing with minimal Heisenberg effect. */
185 #define LWT_SUPPORT 0
187 #define LWT_MEMORY (16<<20)
190 # if defined(__KERNEL__)
191 # if !defined(BITS_PER_LONG)
192 # error "BITS_PER_LONG not defined"
194 # elif !defined(__WORDSIZE)
195 # error "__WORDSIZE not defined"
197 # define BITS_PER_LONG __WORDSIZE
200 /* kernel hasn't defined this? */
209 # if BITS_PER_LONG > 32
213 #endif /* !KLWT_SUPPORT */
219 typedef struct _lwt_page {
220 struct list_head lwtp_list;
221 struct page *lwtp_page;
222 lwt_event_t *lwtp_events;
226 int lwtc_current_index;
227 lwt_page_t *lwtc_current_page;
230 extern int lwt_enabled;
231 extern lwt_cpu_t lwt_cpus[];
233 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
234 * This stuff is meant for finding specific problems; it never stays in
235 * production code... */
238 #define LWTWHERE(f,l) f ":" LWTSTR(l)
239 #define LWT_EVENTS_PER_PAGE (CFS_PAGE_SIZE / sizeof (lwt_event_t))
241 #define LWT_EVENT(p1, p2, p3, p4) \
243 unsigned long flags; \
249 local_irq_save (flags); \
251 cpu = &lwt_cpus[smp_processor_id()]; \
252 p = cpu->lwtc_current_page; \
253 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
255 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
256 cpu->lwtc_current_page = \
257 list_entry (p->lwtp_list.next, \
258 lwt_page_t, lwtp_list); \
259 cpu->lwtc_current_index = 0; \
262 e->lwte_when = get_cycles(); \
263 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
264 e->lwte_task = current; \
265 e->lwte_p1 = (long)(p1); \
266 e->lwte_p2 = (long)(p2); \
267 e->lwte_p3 = (long)(p3); \
268 e->lwte_p4 = (long)(p4); \
270 local_irq_restore (flags); \
274 #endif /* !KLWT_SUPPORT */
276 extern int lwt_init (void);
277 extern void lwt_fini (void);
278 extern int lwt_lookup_string (int *size, char *knlptr,
279 char *usrptr, int usrsize);
280 extern int lwt_control (int enable, int clear);
281 extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
282 void *user_ptr, int user_size);
283 # else /* __KERNEL__ */
284 # define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
285 # endif /* __KERNEL__ */
286 #endif /* LWT_SUPPORT */
288 /* ------------------------------------------------------------------ */
290 #define IOCTL_LIBCFS_TYPE long
293 # ifndef BITS_PER_LONG
294 # if (~0UL) == 0xffffffffUL
295 # define BITS_PER_LONG 32
297 # define BITS_PER_LONG 64
302 #if BITS_PER_LONG > 32
303 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
304 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
305 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
307 # define LI_POISON ((int)0x5a5a5a5a)
308 # define LL_POISON ((long)0x5a5a5a5a)
309 # define LP_POISON ((void *)(long)0x5a5a5a5a)
312 /* this is a bit chunky */
314 #if defined(__KERNEL__)
315 #define _LWORDSIZE BITS_PER_LONG
317 #define _LWORDSIZE __WORDSIZE
320 #if (defined(__x86_64__) && (defined(__KERNEL__) || defined(CRAY_XT3)))
321 /* x86_64 defines __u64 as "long" in userspace, but "long long" in the kernel */
324 # define LPX64 "%#Lx"
328 #elif (_LWORDSIZE == 32)
331 # define LPX64 "%#Lx"
335 #elif (_LWORDSIZE == 64)
338 # define LPX64 "%#lx"
344 # error "No word size defined"