afs: Always define our own osi_timeval32_t
[openafs.git] / src / afs / HPUX / osi_machdep.h
1
2 /*
3  * Copyright 2000, International Business Machines Corporation and others.
4  * All Rights Reserved.
5  *
6  * This software has been released under the terms of the IBM Public
7  * License.  For details, see the LICENSE file in the top-level source
8  * directory or online at http://www.openafs.org/dl/license10.html
9  */
10
11 /*
12  * HPUX OSI header file. Extends afs_osi.h.
13  *
14  * afs_osi.h includes this file, which is the only way this file should
15  * be included in a source file. This file can redefine macros declared in
16  * afs_osi.h.
17  */
18
19 #ifndef _OSI_MACHDEP_H_
20 #define _OSI_MACHDEP_H_
21
22 #include "h/kern_sem.h"
23 #include "h/proc_iface.h"
24
25 #define afs_hz      hz
26 extern struct timeval time;
27 #define osi_Time() (time.tv_sec)
28
29 typedef struct ucred afs_ucred_t;
30 typedef proc_t afs_proc_t;
31
32 #define gop_rdwr(rw,gp,base,len,offset,segflg,unit,aresid) \
33   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(aresid),0)
34 #define gop_lookupname(fnamep,segflg,followlink,compvpp) \
35   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
36 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) \
37   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
38
39 #undef  afs_suser
40
41 #define osi_curcred()           (p_cred(u.u_procp))
42
43 #define getpid()                (afs_uint32)p_pid(u.u_procp)
44
45 #define getppid()               (afs_uint32)p_ppid(u.u_procp)
46
47 /*
48  * Global lock support.
49  *
50  * HP uses global mutex to protect afs land
51  */
52
53 #if !defined(AFS_HPUX110_ENV)
54 extern sema_t afs_global_sema;
55 #else
56 extern b_sema_t afs_global_sema;
57 #endif
58
59 extern void osi_InitGlock(void);
60
61 #if !defined(AFS_HPUX110_ENV)
62 extern void afsHash(int nbuckets);
63 extern sv_sema_t *afsHashInsertFind(tid_t key);
64 extern sv_sema_t *afsHashFind(tid_t key);
65 extern void afsHashRelease(tid_t key);
66
67 #define AFS_GLOCK_PID   kt_tid(u.u_kthreadp)
68 #define AFS_SAVE_SEMA   afsHashInsertFind(AFS_GLOCK_PID)
69 #define AFS_FIND_SEMA   afsHashFind(AFS_GLOCK_PID)
70
71 #define AFS_GLOCK()     MP_PXSEMA(&afs_global_sema, AFS_SAVE_SEMA)
72 #define AFS_GUNLOCK()   (AFS_ASSERT_GLOCK(), MP_VXSEMA(&afs_global_sema,AFS_FIND_SEMA), (!uniprocessor ? (afsHashRelease(AFS_GLOCK_PID),0) : 0))
73 #define ISAFS_GLOCK()   (!uniprocessor ? owns_sema(&afs_global_sema):1)
74
75 #else
76 #define AFS_GLOCK()  b_psema(&afs_global_sema)
77 #define AFS_GUNLOCK() b_vsema(&afs_global_sema)
78 #define ISAFS_GLOCK() b_owns_sema(&afs_global_sema)
79
80 #endif
81
82 /* Uses splnet only in the SP case */
83 #define SPLVAR      ulong_t splvar
84 #define NETPRI      NET_SPLNET(splvar)
85 #define USERPRI     NET_SPLX(splvar)
86
87 #if !defined(AFS_HPUX110_ENV)
88 /*
89  * On HP, the global lock is an alpha semaphore, hence it is automatically
90  * released and reacquired aroubd a sleep() and wakeup().
91  */
92
93 #define afs_osi_Sleep(x)        sleep((caddr_t) x,PZERO-2)
94 #else
95 /*
96  * On 11.22 global lock is a beta semaphore, hence we need to
97  * release and reacquire around sllep and wakeup. We also need to
98  * use the get_sleep_lock.
99  * afs_osi_Sleep and afs_osi_Wakeup are defined
100  */
101 void afs_osi_Sleep(void *event);
102 int afs_osi_Wakeup(void *event);
103 #endif
104
105 #define osi_NullHandle(x)       ((x)->proc == (caddr_t) 0)
106
107 #if !defined(AFS_HPUX110_ENV)
108 extern caddr_t kmem_alloc();
109 #endif
110 #if defined(AFS_HPUX1111_ENV)
111 #include <sys/kthread_iface.h>  /* for kt_cred() */
112 #endif
113
114 /* Expected to be available as a patch from HP */
115 /* See section D of the top level README for details */
116 #if defined(AFS_HPUX110_ENV)
117 #include <sys/vfs_vm.h>
118 #else
119 #include <vfs_vm.h>
120 #endif
121
122 #define osi_procname(procname, size) strncpy(procname, "", size)
123
124 static_inline void
125 osi_GetTime(osi_timeval32_t *atv)
126 {
127     struct timeval now;
128     uniqtime(&now);
129     atv->tv_sec = now.tv_sec;
130     atv->tv_usec = now.tv_usec;
131 }
132
133 #endif /* _OSI_MACHDEP_H_ */