]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_init.c
2fffb52e6b447789079659b5bfaf50f3a0f97854
[apple/xnu.git] / osfmk / ipc / ipc_init.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
37 *
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
43 *
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58 /*
59 */
60 /*
61 * File: ipc/ipc_init.c
62 * Author: Rich Draves
63 * Date: 1989
64 *
65 * Functions to initialize the IPC system.
66 */
67
68 #include <mach_debug.h>
69 #include <mach_rt.h>
70
71 #include <mach/port.h>
72 #include <mach/kern_return.h>
73
74 #include <kern/kern_types.h>
75 #include <kern/kalloc.h>
76 #include <kern/mach_param.h>
77 #include <kern/ipc_host.h>
78 #include <kern/ipc_mig.h>
79 #include <kern/host_notify.h>
80 #include <kern/mk_timer.h>
81 #include <kern/misc_protos.h>
82 #include <kern/sync_lock.h>
83 #include <kern/sync_sema.h>
84 #include <vm/vm_map.h>
85 #include <vm/vm_kern.h>
86
87 #include <ipc/ipc_entry.h>
88 #include <ipc/ipc_space.h>
89 #include <ipc/ipc_object.h>
90 #include <ipc/ipc_port.h>
91 #include <ipc/ipc_pset.h>
92 #include <ipc/ipc_notify.h>
93 #include <ipc/ipc_kmsg.h>
94 #include <ipc/ipc_hash.h>
95 #include <ipc/ipc_init.h>
96 #include <ipc/ipc_table.h>
97
98 #include <mach/machine/ndr_def.h> /* NDR_record */
99
100 vm_map_t ipc_kernel_map;
101 vm_size_t ipc_kernel_map_size = 1024 * 1024;
102
103 vm_map_t ipc_kernel_copy_map;
104 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
105 vm_size_t ipc_kernel_copy_map_size = IPC_KERNEL_COPY_MAP_SIZE;
106 vm_size_t ipc_kmsg_max_vm_space = (IPC_KERNEL_COPY_MAP_SIZE * 7)/8;
107
108 int ipc_space_max = SPACE_MAX;
109 int ipc_tree_entry_max = ITE_MAX;
110 int ipc_port_max = PORT_MAX;
111 int ipc_pset_max = SET_MAX;
112
113 extern void ikm_cache_init(void);
114
115 /*
116 * Routine: ipc_bootstrap
117 * Purpose:
118 * Initialization needed before the kernel task
119 * can be created.
120 */
121
122 void
123 ipc_bootstrap(void)
124 {
125 kern_return_t kr;
126
127 ipc_port_multiple_lock_init();
128
129 ipc_port_timestamp_lock_init();
130 ipc_port_timestamp_data = 0;
131
132 /* all IPC zones should be exhaustible */
133
134 ipc_space_zone = zinit(sizeof(struct ipc_space),
135 ipc_space_max * sizeof(struct ipc_space),
136 sizeof(struct ipc_space),
137 "ipc spaces");
138 #if 0
139 /* make it exhaustible */
140 zone_change(ipc_space_zone, Z_EXHAUST, TRUE);
141 #endif
142
143 ipc_tree_entry_zone =
144 zinit(sizeof(struct ipc_tree_entry),
145 ipc_tree_entry_max * sizeof(struct ipc_tree_entry),
146 sizeof(struct ipc_tree_entry),
147 "ipc tree entries");
148 #if 0
149 /* make it exhaustible */
150 zone_change(ipc_tree_entry_zone, Z_EXHAUST, TRUE);
151 #endif
152
153 /*
154 * populate all port(set) zones
155 */
156 ipc_object_zones[IOT_PORT] =
157 zinit(sizeof(struct ipc_port),
158 ipc_port_max * sizeof(struct ipc_port),
159 sizeof(struct ipc_port),
160 "ipc ports");
161 /*
162 * XXX Can't make the port zone exhaustible because the kernel
163 * XXX panics when port allocation for an internal object fails.
164 *zone_change(ipc_object_zones[IOT_PORT], Z_EXHAUST, TRUE);
165 */
166
167 ipc_object_zones[IOT_PORT_SET] =
168 zinit(sizeof(struct ipc_pset),
169 ipc_pset_max * sizeof(struct ipc_pset),
170 sizeof(struct ipc_pset),
171 "ipc port sets");
172 /* make it exhaustible */
173 zone_change(ipc_object_zones[IOT_PORT_SET], Z_EXHAUST, TRUE);
174
175 /*
176 * Create the basic ipc_kmsg_t zone (the one we also cache)
177 * elements at the processor-level to avoid the locking.
178 */
179 ipc_kmsg_zone = zinit(IKM_SAVED_KMSG_SIZE,
180 ipc_port_max * MACH_PORT_QLIMIT_MAX *
181 IKM_SAVED_KMSG_SIZE,
182 IKM_SAVED_KMSG_SIZE,
183 "ipc kmsgs");
184
185 /* create special spaces */
186
187 kr = ipc_space_create_special(&ipc_space_kernel);
188 assert(kr == KERN_SUCCESS);
189
190
191 kr = ipc_space_create_special(&ipc_space_reply);
192 assert(kr == KERN_SUCCESS);
193
194 /* initialize modules with hidden data structures */
195
196 #if MACH_ASSERT
197 ipc_port_debug_init();
198 #endif
199 mig_init();
200 ipc_table_init();
201 ipc_hash_init();
202 semaphore_init();
203 lock_set_init();
204 mk_timer_init();
205 host_notify_init();
206 }
207
208 /*
209 * XXX tunable, belongs in mach.message.h
210 */
211 #define MSG_OOL_SIZE_SMALL_MAX 4096
212 vm_size_t msg_ool_size_small;
213
214 /*
215 * Routine: ipc_init
216 * Purpose:
217 * Final initialization of the IPC system.
218 */
219
220 void
221 ipc_init(void)
222 {
223 kern_return_t retval;
224 vm_offset_t min;
225
226 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_map_size,
227 TRUE, VM_FLAGS_ANYWHERE, &ipc_kernel_map);
228
229 if (retval != KERN_SUCCESS)
230 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
231
232 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_copy_map_size,
233 TRUE, VM_FLAGS_ANYWHERE, &ipc_kernel_copy_map);
234
235 if (retval != KERN_SUCCESS)
236 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
237
238 ipc_kernel_copy_map->no_zero_fill = TRUE;
239 ipc_kernel_copy_map->wait_for_space = TRUE;
240
241 /*
242 * As an optimization, 'small' out of line data regions using a
243 * physical copy strategy are copied into kalloc'ed buffers.
244 * The value of 'small' is determined here. Requests kalloc()
245 * with sizes greater or equal to kalloc_max_prerounded may fail.
246 */
247 if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL_MAX) {
248 msg_ool_size_small = kalloc_max_prerounded;
249 }
250 else {
251 msg_ool_size_small = MSG_OOL_SIZE_SMALL_MAX;
252 }
253
254 ipc_host_init();
255 }