introduce-linux-ia64-port-20010806
[openafs.git] / src / afs / LINUX / osi_machdep.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Linux implementation.
12  *
13  */
14
15 #ifndef OSI_MACHDEP_H_
16 #define OSI_MACHDEP_H_
17
18 /* Only needed for xdr.h in glibc 2.1.x */
19 #ifndef quad_t
20 #define quad_t __quad_t
21 #define u_quad_t __u_quad_t
22 #endif
23
24 #undef getuerror
25
26 #define getpid() current->pid
27 #define getppid() current->p_opptr->pid
28
29
30 #define afs_hz HZ
31 #include "../h/sched.h"
32 #define osi_Time() (xtime.tv_sec)
33 #if  (CPU == sparc64)
34 #define osi_GetTime(V) do { (*(V)).tv_sec = xtime.tv_sec; (*(V)).tv_usec = xtime.tv_usec; } while (0)
35 #else
36 #define osi_GetTime(V) (*(V)=xtime)
37 #endif
38
39 #undef gop_lookupname
40 #define gop_lookupname osi_lookupname
41
42 #define osi_vnhold(v, n)  VN_HOLD(v)
43
44 #define osi_AllocSmall afs_osi_Alloc
45 #define osi_FreeSmall afs_osi_Free
46
47 #define afs_suser suser
48 #define wakeup afs_osi_Wakeup
49
50 #undef vType
51 #define vType(V) ((( vnode_t *)V)->v_type & S_IFMT)
52
53 /* IsAfsVnode relies on the fast that there is only one vnodeop table for AFS.
54  * Use the same type of test as other OS's for compatibility.
55  */
56 #undef IsAfsVnode
57 extern struct vnodeops afs_dir_iops, afs_symlink_iops;
58 #define IsAfsVnode(vc) (((vc)->v_op == afs_ops) ? 1 : \
59                         ((vc)->v_op == &afs_dir_iops) ? 1 : \
60                         ((vc)->v_op == &afs_symlink_iops))
61
62 /* bcopy is in stds.h, just so fcrpyt.c can pick it up. */
63 #define bzero(D,C)   memset((D), 0, (C))
64 #define bcmp(A,B,C)  memcmp((A), (B), (C))
65
66 /* We often need to pretend we're in user space to get memory transfers
67  * right for the kernel calls we use.
68  */
69 #ifdef KERNEL_SPACE_DECL
70 #undef KERNEL_SPACE_DECL
71 #undef TO_USER_SPACE
72 #undef TO_KERNEL_SPACE
73 #endif
74 #define KERNEL_SPACE_DECL mm_segment_t _fs_space_decl
75 #define TO_USER_SPACE() { _fs_space_decl = get_fs(); set_fs(get_ds()); }
76 #define TO_KERNEL_SPACE() set_fs(_fs_space_decl)
77
78 /* Backwards compatibilty macros - copyin/copyout are redone because macro
79  * inside parentheses is not evalutated.
80  */
81 #define memcpy_fromfs copy_from_user
82 #define memcpy_tofs copy_to_user
83 #define copyin(F, T, C)  (copy_from_user ((char*)(T), (char*)(F), (C)), 0)
84 #define copyinstr(F, T, C, L) (copyin(F, T, C), *(L)=strlen(T), 0)
85 #define copyout(F, T, C) (copy_to_user ((char*)(T), (char*)(F), (C)), 0)
86
87 /* kernel print statements */
88 #define printf printk
89 #define uprintf printk
90
91
92 #define PAGESIZE PAGE_SIZE
93
94 /* cred struct */
95 typedef struct cred {           /* maps to task field: */
96 #if (CPU == sparc64)
97     long cr_ref;
98 #else
99     int cr_ref;
100 #endif
101     unsigned short cr_uid;      /* euid */
102     unsigned short cr_ruid;     /* uid */
103     unsigned short cr_gid;      /* egid */
104     unsigned short cr_rgid;     /* gid */
105     gid_t cr_groups[NGROUPS];   /* 32 groups - empty set to NOGROUP */
106     int cr_ngroups;
107 } cred_t;
108 #define AFS_UCRED cred
109 #define crhold(c) (c)->cr_ref++
110
111 /* UIO manipulation */
112 typedef enum { AFS_UIOSYS, AFS_UIOUSER } uio_seg_t;
113 typedef enum { UIO_READ, UIO_WRITE } uio_flag_t;
114 typedef struct uio {
115     struct      iovec *uio_iov;
116     int         uio_iovcnt;
117     int         uio_offset;
118     uio_seg_t   uio_seg;
119     int         uio_resid;
120     uio_flag_t  uio_flag;
121 } uio_t;
122 #define afsio_iov       uio_iov
123 #define afsio_iovcnt    uio_iovcnt
124 #define afsio_offset    uio_offset
125 #define afsio_seg       uio_segflg
126 #define afsio_fmode     uio_fmode
127 #define afsio_resid     uio_resid
128
129 /* Get/set the inode in the osifile struct. */
130 #define FILE_INODE(F) (F)->f_dentry->d_inode
131
132
133 /* page offset is obtained and stored here during module initialization 
134  * We need a variable to do this because, the PAGE_OFFSET macro defined in
135  * include/asm/page.h can change from kernel to kernel and we cannot use
136  * the hardcoded version.
137  */
138 extern unsigned long afs_linux_page_offset;
139
140 /* some more functions to help with the page offset stuff */
141 #define AFS_LINUX_MAP_NR(addr) ((((unsigned long)addr) - afs_linux_page_offset)  >> PAGE_SHIFT)
142
143 #define afs_linux_page_address(page) (afs_linux_page_offset + PAGE_SIZE * (page - mem_map))
144
145 #if defined(__KERNEL__) && defined(CONFIG_SMP)
146 #include "linux/wait.h"
147
148 extern struct semaphore afs_global_lock;
149 extern int afs_global_owner;
150
151 #define AFS_GLOCK() \
152 do { \
153          down(&afs_global_lock); \
154          if (afs_global_owner) \
155              osi_Panic("afs_global_lock already held by pid %d", \
156                        afs_global_owner); \
157          afs_global_owner = current->pid; \
158 } while (0)
159
160 #define ISAFS_GLOCK() (afs_global_owner == current->pid)
161
162 #define AFS_GUNLOCK() \
163 do { \
164     if (!ISAFS_GLOCK()) \
165         osi_Panic("afs global lock not held"); \
166     afs_global_owner = 0; \
167     up(&afs_global_lock); \
168 } while (0)
169
170
171 #else
172 #define AFS_GLOCK()
173 #define AFS_GUNLOCK()
174 #define ISAFS_GLOCK() 1
175 #define AFS_ASSERT_GLOCK()
176 #define AFS_ASSERT_RXGLOCK()
177 #endif
178
179 #define AFS_RXGLOCK()
180 #define AFS_RXGUNLOCK()
181 #define ISAFS_RXGLOCK() 1
182 #endif /* OSI_MACHDEP_H_ */