2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * IRIX OSI header file. Extends afs_osi.h.
13 * afs_osi.h includes this file, which is the only way this file should
14 * be included in a source file. This file can redefine macros declared in
17 #ifndef _OSI_MACHDEP_H_
18 #define _OSI_MACHDEP_H_
22 extern kmutex_t afs_global_lock;
27 #define osi_Time() (time)
29 #define AFS_UCRED ucred
31 #define osi_vnhold(avc, r) do { VN_HOLD(AFSTOV(avc)); } while(0)
33 #undef afs_osi_Alloc_NoSleep
34 extern void *afs_osi_Alloc_NoSleep(size_t size);
38 #include <sys/flock.h>
39 extern flid_t osi_flid;
40 #define v_op v_bh.bh_first->bd_ops
41 #define v_data v_bh.bh_first->bd_pdata
42 #define vfs_data vfs_bh.bh_first->bd_pdata
43 #endif /* AFS_SGI64_ENV */
47 * Global lock, semaphore, mutex and state vector support.
49 #define SV_INIT(cv, nm, t, c) cv_init(cv, nm, t, c)
52 #define SV_SIGNAL(cv) sv_signal(cv)
53 #define SPINLOCK_INIT(l, nm) spinlock_init((l),(nm))
54 #define SPLOCK(l) mp_mutex_spinlock(&(l))
55 #define SPUNLOCK(l,s) mp_mutex_spinunlock(&(l),s)
56 #define SP_WAIT(l, s, cv, p) mp_sv_wait_sig(cv, p, (void*)(&(l)), s)
59 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
60 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT))
61 #undef AFS_MUTEX_ENTER
62 #define AFS_MUTEX_ENTER(mp) \
64 register struct kthread *_kthreadP; \
65 while(mutex_tryenter(mp) == 0) { \
66 _kthreadP = (struct kthread*)mutex_owner(mp); \
67 if (_kthreadP != NULL && _kthreadP->k_sonproc == CPU_NONE) { \
68 mutex_lock(mp, AFSD_PRI()); \
74 #else /* AFS_SGI65_ENV */
75 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
76 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO)
78 #define AFS_MUTEX_ENTER(mp) \
81 while(mutex_tryenter(mp) == 0) { \
82 kt = mutex_owner(mp); \
83 if (kt != NULL && kt->k_sonproc == CPU_NONE) { \
84 mutex_lock(mp, AFSD_PRI()); \
89 #endif /* AFS_SGI65_ENV */
91 #define cv_timedwait(cv, l, t) { \
92 sv_timedwait(cv, AFSD_PRI(), l, 0, 0, &(t), \
93 (struct timespec*)0); \
99 #define cv_wait(cv, l) { \
100 sv_wait(cv, AFSD_PRI(), l, 0); \
101 AFS_MUTEX_ENTER(l); \
103 #else /* AFS_SGI64_ENV */
106 #define AFS_MUTEX_ENTER(mp) \
108 register struct proc *_procP; \
109 while(mutex_tryenter(mp) == 0) { \
110 _procP = mutex_owner(mp); \
111 if (_procP != NULL && _procP->p_sonproc == CPU_NONE) { \
118 #else /* AFS_SGI62_ENV */
120 #define AFS_MUTEX_ENTER(mp) mutex_enter(mp)
122 #endif /* AFS_SGI62_ENV */
124 #define cv_timedwait(cv, l, t) { \
125 sv_timedwait(cv, l, t); \
128 #endif /* AFS_SGI64_ENV */
132 #define _MP_NETLOCKS /* to get sblock to work right */
134 /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning
135 * thread explicitly. This is only used for debugging so could be disabled for
138 * CAUTION -- The ISAFS_(RX)?GLOCK macros are not safe to use when the lock is
139 * not held if the test may be made at interrupt level as the code may
140 * appear to be running as the process that is (or last was) running at
141 * non-interrupt level. Worse yet, the interrupt may occur just as the
142 * process is exiting, in which case, the pid may change from the start
143 * of the interrupt to the end, since the u area has been changed. So,
144 * at interrupt level, I'm using the base of the current interrupt stack.
145 * Note that afs_osinet.c also modifies afs_global_owner for osi_Sleep and
146 * afs_osi_Wakeup. Changes made here should be reflected there as well.
147 * NOTE - As of 6.2, we can no longer use mutexes in interrupts, so the above
148 * concern no longer exists.
153 /* Irix does not check for deadlocks unless it's a debug kernel. */
154 #define AFS_ASSERT_GNOTME() \
155 (!ISAFS_GLOCK() || (panic("afs global lock held be me"), 0))
156 #define AFS_GLOCK() \
157 { AFS_ASSERT_GNOTME(); AFS_MUTEX_ENTER(&afs_global_lock); }
159 #define AFS_GLOCK() AFS_MUTEX_ENTER(&afs_global_lock)
161 #define AFS_GUNLOCK() (AFS_ASSERT_GLOCK(), mutex_exit(&afs_global_lock))
162 #define ISAFS_GLOCK() mutex_mine(&afs_global_lock)
164 extern long afs_global_owner;
165 #define AFS_GLOCK() \
167 AFS_MUTEX_ENTER(&afs_global_lock) ; \
168 afs_global_owner = osi_ThreadUnique(); \
170 #define AFS_GUNLOCK() \
171 (AFS_ASSERT_GLOCK(), afs_global_owner = 0, mutex_exit(&afs_global_lock))
172 #define ISAFS_GLOCK() (osi_ThreadUnique() == afs_global_owner)
173 #endif /* AFS_SGI64_ENV */
175 #define AFS_RXGLOCK()
176 #define AFS_RXGUNLOCK()
177 #define ISAFS_RXGLOCK() 1
181 #define AFS_GUNLOCK()
182 #define ISAFS_GLOCK() 1
184 #define SPLVAR register int splvar
185 #define NETPRI splvar=splnet()
186 #define USERPRI splx(splvar)
196 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
197 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),\
198 (int *)(aresid), &osi_flid)
200 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
201 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr), \
207 #define suser() cap_able(CAP_DEVICE_MGT)
208 #define afs_suser() suser()
210 #define afs_suser suser
218 #define PAGESIZE 4096
226 /* OS independent user structure stuff */
228 * OSI_GET_CURRENT_PID
230 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
231 #define OSI_GET_CURRENT_PID() (u.u_procp->p_pid)
232 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
234 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
235 #define OSI_GET_CURRENT_PID() current_pid()
236 #endif /* AFS_SGI64_ENV */
238 #if defined(AFS_SGI65_ENV)
239 #define OSI_GET_CURRENT_PID() proc_pid(curproc())
242 #define getpid() OSI_GET_CURRENT_PID()
245 * OSI_GET_CURRENT_PROCP
247 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
248 #define OSI_GET_CURRENT_PROCP() (u.u_procp)
249 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
251 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
252 #define OSI_GET_CURRENT_PROCP() curprocp
253 #endif /* AFS_SGI64_ENV */
255 #if defined(AFS_SGI65_ENV)
256 #define OSI_GET_CURRENT_PROCP() UT_TO_PROC(curuthread)
263 * Prior to IRIX 6.4, pid sufficed, now we need kthread.
265 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
266 #define OSI_GET_LOCKID() (u.u_procp->p_pid)
267 #define OSI_NO_LOCKID (-1)
268 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
270 #if defined(AFS_SGI64_ENV)
271 /* IRIX returns k_id, but this way, we've got the thread address for debugging. */
272 #define OSI_GET_LOCKID() \
273 (private.p_curkthread ? (uint64_t)private.p_curkthread : (uint64_t)0)
274 #define OSI_NO_LOCKID ((uint64_t)-1)
275 #endif /* AFS_SGI64_ENV */
278 * OSI_GET_CURRENT_CRED
280 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
281 #define OSI_GET_CURRENT_CRED() (u.u_cred)
282 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
284 #if defined(AFS_SGI64_ENV)
285 #define OSI_GET_CURRENT_CRED() get_current_cred()
286 #endif /* AFS_SGI64_ENV */
288 #define osi_curcred() OSI_GET_CURRENT_CRED()
291 * OSI_SET_CURRENT_CRED
293 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
294 #define OSI_SET_CURRENT_CRED(x) u.u_cred=x
295 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
297 #if defined(AFS_SGI64_ENV)
298 #define OSI_SET_CURRENT_CRED(C) set_current_cred((C))
299 #endif /* AFS_SGI64_ENV */
302 * OSI_GET_CURRENT_ABI
304 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
305 #define OSI_GET_CURRENT_ABI() (u.u_procp->p_abi)
306 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
308 #if defined(AFS_SGI64_ENV)
309 #define OSI_GET_CURRENT_ABI() get_current_abi()
310 #endif /* AFS_SGI64_ENV */
313 * OSI_GET_CURRENT_SYSID
315 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
316 #define OSI_GET_CURRENT_SYSID() (u.u_procp->p_sysid)
317 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
319 #if defined(AFS_SGI64_ENV)
320 #define OSI_GET_CURRENT_SYSID() (curprocp->p_flid.fl_sysid)
321 #endif /* AFS_SGI64_ENV */
324 * OSI_GET_CURRENT_COMM
326 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
327 #define OSI_GET_CURRENT_COMM() (u.u_comm)
328 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
330 #if defined(AFS_SGI64_ENV)
331 #define OSI_GET_CURRENT_COMM() (curprocp->p_comm)
332 #endif /* AFS_SGI64_ENV */
335 * OSI_GET_CURRENT_CDIR
337 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
338 #define OSI_GET_CURRENT_CDIR() (u.u_cdir)
339 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
341 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
342 #define OSI_GET_CURRENT_CDIR() (curprocp->p_cdir)
343 #endif /* AFS_SGI64_ENV */
345 #if defined(AFS_SGI65_ENV)
346 #define OSI_GET_CURRENT_CDIR() (curuthread->ut_cdir)
347 #endif /* AFS_SGI65_ENV */
351 * OSI_GET_CURRENT_RDIR
353 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
354 #define OSI_GET_CURRENT_RDIR() (u.u_rdir)
355 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
357 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
358 #define OSI_GET_CURRENT_RDIR() (curprocp->p_rdir)
359 #endif /* AFS_SGI64_ENV */
361 #if defined(AFS_SGI65_ENV)
362 #define OSI_GET_CURRENT_RDIR() (curuthread->ut_rdir)
363 #endif /* AFS_SGI65_ENV */
367 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops.
369 * Note that the _CONVERT routines get the ";" here so that argument lists
370 * can have arguments after the OSI_x_CONVERT macro is called.
374 #define OSI_VN_ARG(V) bhv_##V
376 #define OSI_VN_DECL(V) bhv_desc_t *bhv_##V
377 #undef OSI_VN_CONVERT
378 #define OSI_VN_CONVERT(V) struct vnode * V = (struct vnode*)BHV_TO_VNODE(bhv_##V);
380 #define OSI_VC_ARG(V) bhv_##V
382 #define OSI_VC_DECL(V) bhv_desc_t *bhv_##V
383 #undef OSI_VC_CONVERT
384 #define OSI_VC_CONVERT(V) struct vcache * V = VTOAFS(BHV_TO_VNODE(bhv_##V));
386 #define OSI_VFS_ARG(V) bhv_##V
388 #define OSI_VFS_DECL(V) bhv_desc_t *bhv_##V
389 #undef OSI_VFS_CONVERT
390 #define OSI_VFS_CONVERT(V) struct vfs * V = (struct vfs*)bhvtovfs(bhv_##V);
391 #endif /* AFS_SGI64_ENV */
396 #endif /* _OSI_MACHDEP_H_ */