1 /* $NetBSD: irix_sysmp.c,v 1.22 2009/11/28 20:09:56 dsl Exp $ */
4 * Copyright (c) 2001-2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
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];
65 irix_sys_sysmp(struct lwp
*l
, const struct irix_sys_sysmp_args
*uap
, register_t
*retval
)
69 syscallarg(void *) arg1;
70 syscallarg(void *) arg2;
71 syscallarg(void *) arg3;
72 syscallarg(void *) arg4;
74 int cmd
= SCARG(uap
, cmd
);
77 printf("irix_sys_sysmp(): cmd = %d\n", cmd
);
81 case IRIX_MP_NPROCS
: /* Number of processors in complex */
82 case IRIX_MP_NAPROCS
: { /* Number of active processors in complex */
87 case IRIX_MP_PGSIZE
: /* Page size */
88 *retval
= (register_t
)PAGE_SIZE
;
91 case IRIX_MP_KERNADDR
: /* Kernel structure addresses */
92 return irix_sysmp_kernaddr((intptr_t)SCARG(uap
, arg1
), retval
);
95 case IRIX_MP_SASZ
: /* System accounting structure size */
96 return irix_sysmp_sasz((intptr_t)SCARG(uap
, arg1
), retval
);
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
));
106 printf("Warning: call to unimplemented sysmp() command %d\n",
115 irix_sysmp_kernaddr(int kernaddr
, register_t
*retval
)
118 case IRIX_MPKA_AVENRUN
:
119 *retval
= (register_t
)&averunnable
;
123 *retval
= (register_t
)&irix_kernel_var
;
127 printf("Warning: sysmp(KERNADDR) unimplemented address %d\n",
137 irix_sysmp_sasz(int cmd
, register_t
*retval
)
140 case IRIX_MPSA_RMINFO
:
141 *retval
= sizeof(struct irix_sysmp_rminfo
);
144 printf("Warning: sysmp(SASZ) unimplemented struct %d\n",
153 irix_sysmp_saget(int cmd
, char *buf
, size_t len
)
158 kbuf
= malloc(len
, M_TEMP
, M_WAITOK
);
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
;
183 printf("Warning: sysmp(SAGET) unimplemented struct %d\n",
190 error
= copyout(kbuf
, buf
, len
);