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