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