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 # include <linux/config.h>
13 # include <linux/kernel.h>
14 # include <linux/mm.h>
15 # include <linux/string.h>
16 # include <linux/stat.h>
17 # include <linux/init.h>
18 # include <linux/errno.h>
19 # include <linux/unistd.h>
20 # include <asm/system.h>
21 # include <linux/kmod.h>
22 # include <linux/notifier.h>
23 # include <linux/fs.h>
24 # include <asm/segment.h>
25 # include <linux/miscdevice.h>
26 # include <linux/vmalloc.h>
27 # include <linux/time.h>
28 # include <linux/slab.h>
29 # include <linux/interrupt.h>
30 # include <linux/highmem.h>
31 # include <linux/module.h>
32 # include <linux/version.h>
33 # include <portals/p30.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 # ifdef HAVE_MM_INLINE
43 # include <linux/mm_inline.h>
45 # if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
46 # include <linux/kallsyms.h>
49 #include <libcfs/linux/portals_compat25.h>
51 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
52 #define schedule_work schedule_task
53 #define prepare_work(wq,cb,cbdata) \
55 INIT_TQUEUE((wq), 0, 0); \
56 PREPARE_TQUEUE((wq), (cb), (cbdata)); \
59 #define PageUptodate Page_Uptodate
60 #define our_recalc_sigpending(current) recalc_sigpending(current)
61 #define num_online_cpus() smp_num_cpus
62 static inline void our_cond_resched(void)
64 if (current->need_resched)
67 #define work_struct_t struct tq_struct
71 #define prepare_work(wq,cb,cbdata) \
73 INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
75 #define wait_on_page wait_on_page_locked
76 #define our_recalc_sigpending(current) recalc_sigpending()
77 #define strtok(a,b) strpbrk(a, b)
78 static inline void our_cond_resched(void)
82 #define work_struct_t struct work_struct
84 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
87 #define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
89 #define LASSERT_SPIN_LOCKED(lock) do {} while(0)
93 #define LBUG_WITH_LOC(file, func, line) \
95 CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n"); \
96 portals_debug_dumplog(); \
97 portals_run_lbug_upcall(file, func, line); \
101 #define LBUG_WITH_LOC(file, func, line) \
104 portals_debug_dumpstack(NULL); \
105 portals_debug_dumplog(); \
106 portals_run_lbug_upcall(file, func, line); \
107 set_task_state(current, TASK_UNINTERRUPTIBLE); \
110 #endif /* __arch_um__ */
112 /* ------------------------------------------------------------------- */
114 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
116 #define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
117 #define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
119 #define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
120 #define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
122 #define PORTAL_MODULE_USE MOD_INC_USE_COUNT
123 #define PORTAL_MODULE_UNUSE MOD_DEC_USE_COUNT
126 #define PORTAL_SYMBOL_REGISTER(x)
127 #define PORTAL_SYMBOL_UNREGISTER(x)
129 #define PORTAL_SYMBOL_GET(x) symbol_get(x)
130 #define PORTAL_SYMBOL_PUT(x) symbol_put(x)
132 #define PORTAL_MODULE_USE try_module_get(THIS_MODULE)
133 #define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
137 /******************************************************************************/
140 /* Use the special GNU C __attribute__ hack to have the compiler check the
141 * printf style argument string against the actual argument count and
145 # warning printf has been defined as a macro...
149 #endif /* __GNUC__ */
151 # define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
152 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
153 # define time(a) CURRENT_TIME
155 #else /* !__KERNEL__ */
161 # include <cygwin-ioctl.h>
167 #endif /* End of !__KERNEL__ */
169 /******************************************************************************/
170 /* Light-weight trace
171 * Support for temporary event tracing with minimal Heisenberg effect. */
172 #define LWT_SUPPORT 0
174 #define LWT_MEMORY (16<<20)
177 # if defined(__KERNEL__)
178 # if !defined(BITS_PER_LONG)
179 # error "BITS_PER_LONG not defined"
181 # elif !defined(__WORDSIZE)
182 # error "__WORDSIZE not defined"
184 # define BITS_PER_LONG __WORDSIZE
187 /* kernel hasn't defined this? */
196 # if BITS_PER_LONG > 32
200 #endif /* !KLWT_SUPPORT */
206 typedef struct _lwt_page {
207 struct list_head lwtp_list;
208 struct page *lwtp_page;
209 lwt_event_t *lwtp_events;
213 int lwtc_current_index;
214 lwt_page_t *lwtc_current_page;
217 extern int lwt_enabled;
218 extern lwt_cpu_t lwt_cpus[];
220 /* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
221 * This stuff is meant for finding specific problems; it never stays in
222 * production code... */
225 #define LWTWHERE(f,l) f ":" LWTSTR(l)
226 #define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
228 #define LWT_EVENT(p1, p2, p3, p4) \
230 unsigned long flags; \
236 local_irq_save (flags); \
238 cpu = &lwt_cpus[smp_processor_id()]; \
239 p = cpu->lwtc_current_page; \
240 e = &p->lwtp_events[cpu->lwtc_current_index++]; \
242 if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
243 cpu->lwtc_current_page = \
244 list_entry (p->lwtp_list.next, \
245 lwt_page_t, lwtp_list); \
246 cpu->lwtc_current_index = 0; \
249 e->lwte_when = get_cycles(); \
250 e->lwte_where = LWTWHERE(__FILE__,__LINE__); \
251 e->lwte_task = current; \
252 e->lwte_p1 = (long)(p1); \
253 e->lwte_p2 = (long)(p2); \
254 e->lwte_p3 = (long)(p3); \
255 e->lwte_p4 = (long)(p4); \
257 local_irq_restore (flags); \
261 #endif /* !KLWT_SUPPORT */
263 extern int lwt_init (void);
264 extern void lwt_fini (void);
265 extern int lwt_lookup_string (int *size, char *knlptr,
266 char *usrptr, int usrsize);
267 extern int lwt_control (int enable, int clear);
268 extern int lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
269 void *user_ptr, int user_size);
270 # else /* __KERNEL__ */
271 # define LWT_EVENT(p1,p2,p3,p4) /* no userland implementation yet */
272 # endif /* __KERNEL__ */
273 #endif /* LWT_SUPPORT */
275 /* ------------------------------------------------------------------ */
277 #define IOCTL_PORTAL_TYPE long
280 # ifndef BITS_PER_LONG
281 # if (~0UL) == 0xffffffffUL
282 # define BITS_PER_LONG 32
284 # define BITS_PER_LONG 64
289 #if BITS_PER_LONG > 32
290 # define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
291 # define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
292 # define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
294 # define LI_POISON ((int)0x5a5a5a5a)
295 # define LL_POISON ((long)0x5a5a5a5a)
296 # define LP_POISON ((void *)(long)0x5a5a5a5a)
299 #if defined(__x86_64__)
302 # define LPX64 "%#Lx"
305 #elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
308 # define LPX64 "%#Lx"
311 #elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
314 # define LPX64 "%#lx"
319 # error "No word size defined"