1 /* Copyright (C) 1995 Transarc Corporation - All rights reserved. */
3 * IRIX OSI header file. Extends afs_osi.h.
5 * afs_osi.h includes this file, which is the only way this file should
6 * be included in a source file. This file can redefine macros declared in
9 #ifndef _OSI_MACHDEP_H_
10 #define _OSI_MACHDEP_H_
14 extern kmutex_t afs_global_lock;
19 #define osi_Time() (time)
21 #define AFS_UCRED ucred
23 #define osi_vnhold(avc, r) do { VN_HOLD((struct vnode *)(avc)); } while(0)
25 #undef afs_osi_Alloc_NoSleep
26 extern void *afs_osi_Alloc_NoSleep(size_t size);
30 #include <sys/flock.h>
31 extern flid_t osi_flid;
32 #define v_op v_bh.bh_first->bd_ops
33 #define v_data v_bh.bh_first->bd_pdata
34 #define vfs_data vfs_bh.bh_first->bd_pdata
35 #endif /* AFS_SGI64_ENV */
39 * Global lock, semaphore, mutex and state vector support.
41 #define SV_INIT(cv, nm, t, c) cv_init(cv, nm, t, c)
44 #define SV_SIGNAL(cv) sv_signal(cv)
45 #define SPINLOCK_INIT(l, nm) spinlock_init((l),(nm))
46 #define SPLOCK(l) mp_mutex_spinlock(&(l))
47 #define SPUNLOCK(l,s) mp_mutex_spinunlock(&(l),s)
48 #define SP_WAIT(l, s, cv, p) mp_sv_wait_sig(cv, p, (void*)(&(l)), s)
51 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
52 #define AFSD_PRI() ((kt_basepri(curthreadp) == PTIME_SHARE) ? PZERO : (PZERO|PLTWAIT))
53 #undef AFS_MUTEX_ENTER
54 #define AFS_MUTEX_ENTER(mp) \
56 register struct kthread *_kthreadP; \
57 while(mutex_tryenter(mp) == 0) { \
58 _kthreadP = (struct kthread*)mutex_owner(mp); \
59 if (_kthreadP != NULL && _kthreadP->k_sonproc == CPU_NONE) { \
60 mutex_lock(mp, AFSD_PRI()); \
66 #else /* AFS_SGI65_ENV */
67 /* Add PLTWAIT for afsd's to wait so we don't rack up the load average. */
68 #define AFSD_PRI() ((curprocp && curprocp->p_rss==0) ? (PZERO|PLTWAIT) : PZERO)
70 #define AFS_MUTEX_ENTER(mp) \
73 while(mutex_tryenter(mp) == 0) { \
74 kt = mutex_owner(mp); \
75 if (kt != NULL && kt->k_sonproc == CPU_NONE) { \
76 mutex_lock(mp, AFSD_PRI()); \
81 #endif /* AFS_SGI65_ENV */
83 #define cv_timedwait(cv, l, t) { \
84 sv_timedwait(cv, AFSD_PRI(), l, 0, 0, &(t), \
85 (struct timespec*)0); \
91 #define cv_wait(cv, l) { \
92 sv_wait(cv, AFSD_PRI(), l, 0); \
95 #else /* AFS_SGI64_ENV */
98 #define AFS_MUTEX_ENTER(mp) \
100 register struct proc *_procP; \
101 while(mutex_tryenter(mp) == 0) { \
102 _procP = mutex_owner(mp); \
103 if (_procP != NULL && _procP->p_sonproc == CPU_NONE) { \
110 #else /* AFS_SGI62_ENV */
112 #define AFS_MUTEX_ENTER(mp) mutex_enter(mp)
114 #endif /* AFS_SGI62_ENV */
116 #define cv_timedwait(cv, l, t) { \
117 sv_timedwait(cv, l, t); \
120 #endif /* AFS_SGI64_ENV */
124 #define _MP_NETLOCKS /* to get sblock to work right */
126 /* On SGI mutex_owned doesn't work, so simulate this by remembering the owning
127 * thread explicitly. This is only used for debugging so could be disabled for
130 * CAUTION -- The ISAFS_(RX)?GLOCK macros are not safe to use when the lock is
131 * not held if the test may be made at interrupt level as the code may
132 * appear to be running as the process that is (or last was) running at
133 * non-interrupt level. Worse yet, the interrupt may occur just as the
134 * process is exiting, in which case, the pid may change from the start
135 * of the interrupt to the end, since the u area has been changed. So,
136 * at interrupt level, I'm using the base of the current interrupt stack.
137 * Note that afs_osinet.c also modifies afs_global_owner for osi_Sleep and
138 * afs_osi_Wakeup. Changes made here should be reflected there as well.
139 * NOTE - As of 6.2, we can no longer use mutexes in interrupts, so the above
140 * concern no longer exists.
145 /* Irix does not check for deadlocks unless it's a debug kernel. */
146 #define AFS_ASSERT_GNOTME() \
147 (!ISAFS_GLOCK() || (panic("afs global lock held be me"), 0))
148 #define AFS_GLOCK() \
149 { AFS_ASSERT_GNOTME(); AFS_MUTEX_ENTER(&afs_global_lock); }
151 #define AFS_GLOCK() AFS_MUTEX_ENTER(&afs_global_lock)
153 #define AFS_GUNLOCK() (AFS_ASSERT_GLOCK(), mutex_exit(&afs_global_lock))
154 #define ISAFS_GLOCK() mutex_mine(&afs_global_lock)
156 extern long afs_global_owner;
157 #define AFS_GLOCK() \
159 AFS_MUTEX_ENTER(&afs_global_lock) ; \
160 afs_global_owner = osi_ThreadUnique(); \
162 #define AFS_GUNLOCK() \
163 (AFS_ASSERT_GLOCK(), afs_global_owner = 0, mutex_exit(&afs_global_lock))
164 #define ISAFS_GLOCK() (osi_ThreadUnique() == afs_global_owner)
165 #endif /* AFS_SGI64_ENV */
167 #define AFS_RXGLOCK()
168 #define AFS_RXGUNLOCK()
169 #define ISAFS_RXGLOCK() 1
173 #define AFS_GUNLOCK()
174 #define ISAFS_GLOCK() 1
176 #define SPLVAR register int splvar
177 #define NETPRI splvar=splnet()
178 #define USERPRI splx(splvar)
188 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
189 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),\
190 (int *)(aresid), &osi_flid)
192 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
193 vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr), \
199 #define suser() cap_able(CAP_DEVICE_MGT)
200 #define afs_suser() suser()
202 #define afs_suser suser
210 #define PAGESIZE 4096
218 /* OS independent user structure stuff */
220 * OSI_GET_CURRENT_PID
222 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
223 #define OSI_GET_CURRENT_PID() (u.u_procp->p_pid)
224 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
226 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
227 #define OSI_GET_CURRENT_PID() current_pid()
228 #endif /* AFS_SGI64_ENV */
230 #if defined(AFS_SGI65_ENV)
231 #define OSI_GET_CURRENT_PID() proc_pid(curproc())
234 #define getpid() OSI_GET_CURRENT_PID()
237 * OSI_GET_CURRENT_PROCP
239 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
240 #define OSI_GET_CURRENT_PROCP() (u.u_procp)
241 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
243 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
244 #define OSI_GET_CURRENT_PROCP() curprocp
245 #endif /* AFS_SGI64_ENV */
247 #if defined(AFS_SGI65_ENV)
248 #define OSI_GET_CURRENT_PROCP() UT_TO_PROC(curuthread)
255 * Prior to IRIX 6.4, pid sufficed, now we need kthread.
257 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
258 #define OSI_GET_LOCKID() (u.u_procp->p_pid)
259 #define OSI_NO_LOCKID (-1)
260 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
262 #if defined(AFS_SGI64_ENV)
263 /* IRIX returns k_id, but this way, we've got the thread address for debugging. */
264 #define OSI_GET_LOCKID() \
265 (private.p_curkthread ? (uint64_t)private.p_curkthread : (uint64_t)0)
266 #define OSI_NO_LOCKID ((uint64_t)-1)
267 #endif /* AFS_SGI64_ENV */
270 * OSI_GET_CURRENT_CRED
272 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
273 #define OSI_GET_CURRENT_CRED() (u.u_cred)
274 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
276 #if defined(AFS_SGI64_ENV)
277 #define OSI_GET_CURRENT_CRED() get_current_cred()
278 #endif /* AFS_SGI64_ENV */
281 * OSI_SET_CURRENT_CRED
283 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
284 #define OSI_SET_CURRENT_CRED(x) u.u_cred=x
285 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
287 #if defined(AFS_SGI64_ENV)
288 #define OSI_SET_CURRENT_CRED(C) set_current_cred((C))
289 #endif /* AFS_SGI64_ENV */
292 * OSI_GET_CURRENT_ABI
294 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
295 #define OSI_GET_CURRENT_ABI() (u.u_procp->p_abi)
296 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
298 #if defined(AFS_SGI64_ENV)
299 #define OSI_GET_CURRENT_ABI() get_current_abi()
300 #endif /* AFS_SGI64_ENV */
303 * OSI_GET_CURRENT_SYSID
305 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
306 #define OSI_GET_CURRENT_SYSID() (u.u_procp->p_sysid)
307 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
309 #if defined(AFS_SGI64_ENV)
310 #define OSI_GET_CURRENT_SYSID() (curprocp->p_flid.fl_sysid)
311 #endif /* AFS_SGI64_ENV */
314 * OSI_GET_CURRENT_COMM
316 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
317 #define OSI_GET_CURRENT_COMM() (u.u_comm)
318 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
320 #if defined(AFS_SGI64_ENV)
321 #define OSI_GET_CURRENT_COMM() (curprocp->p_comm)
322 #endif /* AFS_SGI64_ENV */
325 * OSI_GET_CURRENT_CDIR
327 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
328 #define OSI_GET_CURRENT_CDIR() (u.u_cdir)
329 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
331 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
332 #define OSI_GET_CURRENT_CDIR() (curprocp->p_cdir)
333 #endif /* AFS_SGI64_ENV */
335 #if defined(AFS_SGI65_ENV)
336 #define OSI_GET_CURRENT_CDIR() (curuthread->ut_cdir)
337 #endif /* AFS_SGI65_ENV */
341 * OSI_GET_CURRENT_RDIR
343 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
344 #define OSI_GET_CURRENT_RDIR() (u.u_rdir)
345 #endif /* AFS_SGI_ENV but not AFS_SGI64_ENV */
347 #if defined(AFS_SGI64_ENV) && !defined(AFS_SGI65_ENV)
348 #define OSI_GET_CURRENT_RDIR() (curprocp->p_rdir)
349 #endif /* AFS_SGI64_ENV */
351 #if defined(AFS_SGI65_ENV)
352 #define OSI_GET_CURRENT_RDIR() (curuthread->ut_rdir)
353 #endif /* AFS_SGI65_ENV */
357 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops.
359 * Note that the _CONVERT routines get the ";" here so that argument lists
360 * can have arguments after the OSI_x_CONVERT macro is called.
364 #define OSI_VN_ARG(V) bhv_##V
366 #define OSI_VN_DECL(V) bhv_desc_t *bhv_##V
367 #undef OSI_VN_CONVERT
368 #define OSI_VN_CONVERT(V) struct vnode * V = (struct vnode*)BHV_TO_VNODE(bhv_##V);
370 #define OSI_VC_ARG(V) bhv_##V
372 #define OSI_VC_DECL(V) bhv_desc_t *bhv_##V
373 #undef OSI_VC_CONVERT
374 #define OSI_VC_CONVERT(V) struct vcache * V = (struct vcache*)BHV_TO_VNODE(bhv_##V);
376 #define OSI_VFS_ARG(V) bhv_##V
378 #define OSI_VFS_DECL(V) bhv_desc_t *bhv_##V
379 #undef OSI_VFS_CONVERT
380 #define OSI_VFS_CONVERT(V) struct vfs * V = (struct vfs*)bhvtovfs(bhv_##V);
381 #endif /* AFS_SGI64_ENV */
386 #endif /* _OSI_MACHDEP_H_ */