Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / irix / irix_sysmp.c
blobed2fc5242b5b1dca3133f7905d97b0ae24e07305
1 /* $NetBSD: irix_sysmp.c,v 1.22 2009/11/28 20:09:56 dsl Exp $ */
3 /*-
4 * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus.
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: irix_sysmp.c,v 1.22 2009/11/28 20:09:56 dsl Exp $");
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>
44 #include <uvm/uvm_extern.h>
46 #include <machine/vmparam.h>
48 #include <compat/common/compat_util.h>
50 #include <compat/svr4/svr4_types.h>
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>
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];
64 int
65 irix_sys_sysmp(struct lwp *l, const struct irix_sys_sysmp_args *uap, register_t *retval)
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);
76 #ifdef DEBUG_IRIX
77 printf("irix_sys_sysmp(): cmd = %d\n", cmd);
78 #endif
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;
87 case IRIX_MP_PGSIZE: /* Page size */
88 *retval = (register_t)PAGE_SIZE;
89 break;
91 case IRIX_MP_KERNADDR: /* Kernel structure addresses */
92 return irix_sysmp_kernaddr((intptr_t)SCARG(uap, arg1), retval);
93 break;
95 case IRIX_MP_SASZ: /* System accounting structure size */
96 return irix_sysmp_sasz((intptr_t)SCARG(uap, arg1), retval);
97 break;
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((intptr_t)SCARG(uap, arg1),
102 (char *)SCARG(uap, arg2), (size_t)SCARG(uap, arg3));
103 break;
105 default:
106 printf("Warning: call to unimplemented sysmp() command %d\n",
107 cmd);
108 return EINVAL;
109 break;
111 return 0;
114 static int
115 irix_sysmp_kernaddr(int kernaddr, register_t *retval)
117 switch (kernaddr) {
118 case IRIX_MPKA_AVENRUN:
119 *retval = (register_t)&averunnable;
120 break;
122 case IRIX_MPKA_VAR:
123 *retval = (register_t)&irix_kernel_var;
124 break;
126 default:
127 printf("Warning: sysmp(KERNADDR) unimplemented address %d\n",
128 kernaddr);
129 return EINVAL;
130 break;
133 return 0;
136 static int
137 irix_sysmp_sasz(int cmd, register_t *retval)
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;
149 return 0;
152 static int
153 irix_sysmp_saget(int cmd, char *buf, size_t len)
155 void *kbuf;
156 int error = 0;
158 kbuf = malloc(len, M_TEMP, M_WAITOK);
160 switch (cmd) {
161 case IRIX_MPSA_RMINFO: {
162 struct irix_sysmp_rminfo *irm =
163 (struct irix_sysmp_rminfo *)kbuf;
164 int active, inactive;
166 uvm_estimatepageable(&active, &inactive);
167 irm->freemem = uvmexp.free + uvmexp.filepages;
168 irm->availsmem = uvmexp.free + active + inactive
169 + uvmexp.wired + (uvmexp.swpages - uvmexp.swpgonly);
170 irm->availrmem = uvmexp.free + active + inactive + uvmexp.wired;
171 irm->bufmem = uvmexp.filepages;
172 irm->physmem = uvmexp.npages;
173 irm->dchunkpages = 0; /* unsupported */
174 irm->pmapmem = 0; /* unsupported */
175 irm->strmem = 0; /* unsupported */
176 irm->chunkpages = 0; /* unsupported */
177 irm->dpages = 0; /* unsupported */
178 irm->emptymem = uvmexp.free;
179 irm->ravailrmem = active + inactive + uvmexp.free;
180 break;
182 default:
183 printf("Warning: sysmp(SAGET) unimplemented struct %d\n",
184 cmd);
185 error = EINVAL;
186 break;
189 if (error == 0)
190 error = copyout(kbuf, buf, len);
192 free(kbuf, M_TEMP);
193 return error;