1 /* $NetBSD: irix_sysmp.c,v 1.21 2008/04/28 20:23:42 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_sysmp.c,v 1.21 2008/04/28 20:23:42 martin Exp $");
34
35 #include <sys/errno.h>
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/systm.h>
39 #include <sys/sysctl.h>
40 #include <sys/resource.h>
41 #include <sys/buf.h>
42 #include <sys/malloc.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/vmparam.h>
47
48 #include <compat/common/compat_util.h>
49
50 #include <compat/svr4/svr4_types.h>
51
52 #include <compat/irix/irix_types.h>
53 #include <compat/irix/irix_signal.h>
54 #include <compat/irix/irix_sysmp.h>
55 #include <compat/irix/irix_syscallargs.h>
56
57 /* IRIX /dev/kmem diggers emulation */
58 static int irix_sysmp_kernaddr(int, register_t *);
59 static int irix_sysmp_sasz(int, register_t *);
60 static int irix_sysmp_saget(int, char *, size_t);
61 extern struct loadavg averunnable;
62 extern long irix_kernel_var[32];
63
64 int
65 irix_sys_sysmp(struct lwp *l, const struct irix_sys_sysmp_args *uap, register_t *retval)
66 {
67 /* {
68 syscallarg(int) cmd;
69 syscallarg(void *) arg1;
70 syscallarg(void *) arg2;
71 syscallarg(void *) arg3;
72 syscallarg(void *) arg4;
73 } */
74 int cmd = SCARG(uap, cmd);
75
76 #ifdef DEBUG_IRIX
77 printf("irix_sys_sysmp(): cmd = %d\n", cmd);
78 #endif
79
80 switch(cmd) {
81 case IRIX_MP_NPROCS: /* Number of processors in complex */
82 case IRIX_MP_NAPROCS: { /* Number of active processors in complex */
83 *retval = ncpu;
84 return 0;
85 break;
86 }
87 case IRIX_MP_PGSIZE: /* Page size */
88 *retval = (register_t)PAGE_SIZE;
89 break;
90
91 case IRIX_MP_KERNADDR: /* Kernel structure addresses */
92 return irix_sysmp_kernaddr((int)SCARG(uap, arg1), retval);
93 break;
94
95 case IRIX_MP_SASZ: /* System accounting structure size */
96 return irix_sysmp_sasz((int)SCARG(uap, arg1), retval);
97 break;
98
99 case IRIX_MP_SAGET1: /* Get system accounting structure for one CPU */
100 case IRIX_MP_SAGET: /* Get system accounting structure for all CPU */
101 return irix_sysmp_saget((int)SCARG(uap, arg1),
102 (char *)SCARG(uap, arg2), (size_t)SCARG(uap, arg3));
103 break;
104
105 default:
106 printf("Warning: call to unimplemented sysmp() command %d\n",
107 cmd);
108 return EINVAL;
109 break;
110 }
111 return 0;
112 }
113
114 static int
115 irix_sysmp_kernaddr(int kernaddr, register_t *retval)
116 {
117 switch (kernaddr) {
118 case IRIX_MPKA_AVENRUN:
119 *retval = (register_t)&averunnable;
120 break;
121
122 case IRIX_MPKA_VAR:
123 *retval = (register_t)&irix_kernel_var;
124 break;
125
126 default:
127 printf("Warning: sysmp(KERNADDR) unimplemented address %d\n",
128 kernaddr);
129 return EINVAL;
130 break;
131 }
132
133 return 0;
134 }
135
136 static int
137 irix_sysmp_sasz(int cmd, register_t *retval)
138 {
139 switch (cmd) {
140 case IRIX_MPSA_RMINFO:
141 *retval = sizeof(struct irix_sysmp_rminfo);
142 break;
143 default:
144 printf("Warning: sysmp(SASZ) unimplemented struct %d\n",
145 cmd);
146 return EINVAL;
147 break;
148 }
149 return 0;
150 }
151
152 static int
153 irix_sysmp_saget(int cmd, char *buf, size_t len)
154 {
155 extern u_int bufpages;
156 void *kbuf;
157 int error = 0;
158
159 kbuf = malloc(len, M_TEMP, M_WAITOK);
160
161 switch (cmd) {
162 case IRIX_MPSA_RMINFO: {
163 struct irix_sysmp_rminfo *irm =
164 (struct irix_sysmp_rminfo *)kbuf;
165 int active, inactive;
166
167 uvm_estimatepageable(&active, &inactive);
168 irm->freemem = uvmexp.free + uvmexp.filepages;
169 irm->availsmem = uvmexp.free + active + inactive
170 + uvmexp.wired + (uvmexp.swpages - uvmexp.swpgonly);
171 irm->availrmem = uvmexp.free + active + inactive + uvmexp.wired;
172 irm->bufmem = bufpages;
173 irm->physmem = uvmexp.npages;
174 irm->dchunkpages = 0; /* unsupported */
175 irm->pmapmem = 0; /* unsupported */
176 irm->strmem = 0; /* unsupported */
177 irm->chunkpages = 0; /* unsupported */
178 irm->dpages = 0; /* unsupported */
179 irm->emptymem = uvmexp.free;
180 irm->ravailrmem = active + inactive + uvmexp.free;
181 break;
182 }
183 default:
184 printf("Warning: sysmp(SAGET) unimplemented struct %d\n",
185 cmd);
186 error = EINVAL;
187 break;
188 }
189
190 if (error == 0)
191 error = copyout(kbuf, buf, len);
192
193 free(kbuf, M_TEMP);
194 return error;
195 }
Cache object: 6407e18a549d825c30c2a73979a7e328
|