No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / mach / mach_host.c
blobcc3fa4512285b14dd9dd43ff984b9e287ebadacb
1 /* $NetBSD: mach_host.c,v 1.30 2007/12/08 18:36:14 dsl Exp $ */
3 /*-
4 * Copyright (c) 2002-2003 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: mach_host.c,v 1.30 2007/12/08 18:36:14 dsl Exp $");
35 #include <sys/types.h>
36 #include <sys/malloc.h>
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 #include <sys/signal.h>
41 #include <sys/proc.h>
43 #include <uvm/uvm_extern.h>
44 #include <uvm/uvm_param.h>
46 #include <compat/mach/mach_types.h>
47 #include <compat/mach/mach_host.h>
48 #include <compat/mach/mach_port.h>
49 #include <compat/mach/mach_clock.h>
50 #include <compat/mach/mach_errno.h>
51 #include <compat/mach/mach_services.h>
53 int
54 mach_host_info(struct mach_trap_args *args)
56 mach_host_info_request_t *req = args->smsg;
57 mach_host_info_reply_t *rep = args->rmsg;
58 size_t *msglen = args->rsize;
59 mach_host_info_reply_simple_t *reps;
61 *msglen = sizeof(*rep);
62 mach_set_header(rep, req, *msglen);
64 switch(req->req_flavor) {
65 case MACH_HOST_BASIC_INFO: {
66 struct mach_host_basic_info *info
67 = (struct mach_host_basic_info *)&rep->rep_data[0];
69 rep->rep_msgh.msgh_size = sizeof(*reps)
70 - sizeof(rep->rep_trailer) + sizeof(*info);
71 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
72 mach_host_basic_info(info);
73 break;
76 case MACH_HOST_PRIORITY_INFO: {
77 struct mach_host_priority_info *info
78 = (struct mach_host_priority_info *)&rep->rep_data[0];
80 rep->rep_msgh.msgh_size = sizeof(*reps)
81 - sizeof(rep->rep_trailer) + sizeof(*info);
82 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
83 mach_host_priority_info(info);
84 break;
87 case MACH_HOST_SEMAPHORE_TRAPS:
88 case MACH_HOST_MACH_MSG_TRAP:
89 reps = (mach_host_info_reply_simple_t *)rep;
90 reps->rep_msgh.msgh_size =
91 sizeof(*reps) - sizeof(reps->rep_trailer);
92 *msglen = sizeof(*reps);
93 break;
95 case MACH_HOST_SCHED_INFO: {
96 struct mach_host_sched_info *info
97 = (struct mach_host_sched_info *)&rep->rep_data[0];
99 rep->rep_msgh.msgh_size = sizeof(*reps)
100 - sizeof(rep->rep_trailer) + sizeof(*info);
101 rep->rep_count = sizeof(*info) / sizeof(mach_integer_t);
103 info->min_timeout = 1000 / hz; /* XXX timout in ms */
104 info->min_quantum = 1000 / hz; /* quantum in ms */
106 break;
109 case MACH_HOST_RESOURCE_SIZES:
110 uprintf("mach_host_info() Unimplemented host_info flavor %d\n",
111 req->req_flavor);
112 default:
113 uprintf("Unknown host_info flavor %d\n", req->req_flavor);
114 rep->rep_retval = native_to_mach_errno[EINVAL];
115 break;
118 mach_set_trailer(rep, *msglen);
120 return 0;
125 mach_host_page_size(struct mach_trap_args *args)
127 mach_host_page_size_request_t *req = args->smsg;
128 mach_host_page_size_reply_t *rep = args->rmsg;
129 size_t *msglen = args->rsize;
131 *msglen = sizeof(*rep);
132 mach_set_header(rep, req, *msglen);
134 rep->rep_page_size = PAGE_SIZE;
136 mach_set_trailer(rep, *msglen);
138 return 0;
142 mach_host_get_clock_service(struct mach_trap_args *args)
144 mach_host_get_clock_service_request_t *req = args->smsg;
145 mach_host_get_clock_service_reply_t *rep = args->rmsg;
146 size_t *msglen = args->rsize;
147 struct lwp *l = args->l;
148 struct mach_right *mr;
150 mr = mach_right_get(mach_clock_port, l, MACH_PORT_TYPE_SEND, 0);
152 *msglen = sizeof(*rep);
153 mach_set_header(rep, req, *msglen);
154 mach_add_port_desc(rep, mr->mr_name);
155 mach_set_trailer(rep, *msglen);
157 return 0;
160 void
161 mach_host_priority_info(struct mach_host_priority_info *info)
163 /* XXX One day, try to fill this correctly */
164 info->kernel_priority = 0x50;
165 info->system_priority = 0x50;
166 info->server_priority = 0x40;
167 info->user_priority = 0x1f;
168 info->depress_priority = 0x00;
169 info->idle_priority = 0x00;
170 info->minimum_priority = 0x00;
171 info->maximum_priority = 0x4f;
173 return;
177 mach_host_get_io_master(struct mach_trap_args *args)
179 mach_host_get_io_master_request_t *req = args->smsg;
180 mach_host_get_io_master_reply_t *rep = args->rmsg;
181 size_t *msglen = args->rsize;
182 struct lwp *l = args->l;
183 struct mach_right *mr;
185 mr = mach_right_get(mach_io_master_port, l, MACH_PORT_TYPE_SEND, 0);
187 *msglen = sizeof(*rep);
188 mach_set_header(rep, req, *msglen);
189 mach_add_port_desc(rep, mr->mr_name);
190 mach_set_trailer(rep, *msglen);
192 return 0;
196 mach_processor_set_default(struct mach_trap_args *args)
198 mach_processor_set_default_request_t *req = args->smsg;
199 mach_processor_set_default_reply_t *rep = args->rmsg;
200 size_t *msglen = args->rsize;
201 struct lwp *l = args->l;
202 struct mach_right *mr;
203 struct mach_port *mp;
205 mp = mach_port_get();
206 mr = mach_right_get(mp, l, MACH_PORT_TYPE_SEND, 0);
208 *msglen = sizeof(*rep);
209 mach_set_header(rep, req, *msglen);
210 mach_add_port_desc(rep, mr->mr_name);
211 mach_set_trailer(rep, *msglen);
213 return 0;
217 mach_host_processor_set_priv(struct mach_trap_args *args)
219 mach_host_processor_set_priv_request_t *req = args->smsg;
220 mach_host_processor_set_priv_reply_t *rep = args->rmsg;
221 size_t *msglen = args->rsize;
222 struct lwp *l = args->l;
223 mach_port_t mn;
224 struct mach_right *mr;
225 struct mach_right *smr;
226 struct mach_port *smp;
228 mn = req->req_set.name;
229 if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
230 return mach_msg_error(args, EINVAL);
232 smp = mach_port_get();
233 smr = mach_right_get(smp, l, MACH_PORT_TYPE_SEND, 0);
235 *msglen = sizeof(*rep);
236 mach_set_header(rep, req, *msglen);
237 mach_add_port_desc(rep, smr->mr_name);
238 mach_set_trailer(rep, *msglen);
240 return 0;