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