]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_init.c
xnu-517.12.7.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 * 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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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
63 #include <mach/kern_return.h>
64 #include <kern/mach_param.h>
65 #include <kern/ipc_host.h>
66 #include <kern/host_notify.h>
67 #include <kern/mk_timer.h>
68 #include <kern/misc_protos.h>
69 #include <vm/vm_map.h>
70 #include <vm/vm_kern.h>
71 #include <ipc/ipc_entry.h>
72 #include <ipc/ipc_space.h>
73 #include <ipc/ipc_object.h>
74 #include <ipc/ipc_port.h>
75 #include <ipc/ipc_pset.h>
76 #include <ipc/ipc_notify.h>
77 #include <ipc/ipc_kmsg.h>
78 #include <ipc/ipc_hash.h>
79 #include <ipc/ipc_init.h>
80 #include <mach/machine/ndr_def.h> /* NDR_record */
81
82 vm_map_t ipc_kernel_map;
83 vm_size_t ipc_kernel_map_size = 1024 * 1024;
84
85 vm_map_t ipc_kernel_copy_map;
86 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
87 vm_size_t ipc_kernel_copy_map_size = IPC_KERNEL_COPY_MAP_SIZE;
88 vm_size_t ipc_kmsg_max_vm_space = (IPC_KERNEL_COPY_MAP_SIZE * 7)/8;
89
90 int ipc_space_max = SPACE_MAX;
91 int ipc_tree_entry_max = ITE_MAX;
92 int ipc_port_max = PORT_MAX;
93 int ipc_pset_max = SET_MAX;
94
95 extern void mig_init(void);
96 extern void ikm_cache_init(void);
97
98 /*
99 * Routine: ipc_bootstrap
100 * Purpose:
101 * Initialization needed before the kernel task
102 * can be created.
103 */
104
105 void
106 ipc_bootstrap(void)
107 {
108 kern_return_t kr;
109
110 ipc_port_multiple_lock_init();
111
112 ipc_port_timestamp_lock_init();
113 ipc_port_timestamp_data = 0;
114
115 /* all IPC zones should be exhaustible */
116
117 ipc_space_zone = zinit(sizeof(struct ipc_space),
118 ipc_space_max * sizeof(struct ipc_space),
119 sizeof(struct ipc_space),
120 "ipc spaces");
121 #if 0
122 /* make it exhaustible */
123 zone_change(ipc_space_zone, Z_EXHAUST, TRUE);
124 #endif
125
126 ipc_tree_entry_zone =
127 zinit(sizeof(struct ipc_tree_entry),
128 ipc_tree_entry_max * sizeof(struct ipc_tree_entry),
129 sizeof(struct ipc_tree_entry),
130 "ipc tree entries");
131 #if 0
132 /* make it exhaustible */
133 zone_change(ipc_tree_entry_zone, Z_EXHAUST, TRUE);
134 #endif
135
136 /*
137 * populate all port(set) zones
138 */
139 ipc_object_zones[IOT_PORT] =
140 zinit(sizeof(struct ipc_port),
141 ipc_port_max * sizeof(struct ipc_port),
142 sizeof(struct ipc_port),
143 "ipc ports");
144 /*
145 * XXX Can't make the port zone exhaustible because the kernel
146 * XXX panics when port allocation for an internal object fails.
147 *zone_change(ipc_object_zones[IOT_PORT], Z_EXHAUST, TRUE);
148 */
149
150 ipc_object_zones[IOT_PORT_SET] =
151 zinit(sizeof(struct ipc_pset),
152 ipc_pset_max * sizeof(struct ipc_pset),
153 sizeof(struct ipc_pset),
154 "ipc port sets");
155 /* make it exhaustible */
156 zone_change(ipc_object_zones[IOT_PORT_SET], Z_EXHAUST, TRUE);
157
158 /* create special spaces */
159
160 kr = ipc_space_create_special(&ipc_space_kernel);
161 assert(kr == KERN_SUCCESS);
162
163
164 kr = ipc_space_create_special(&ipc_space_reply);
165 assert(kr == KERN_SUCCESS);
166
167 /* initialize modules with hidden data structures */
168
169 #if MACH_ASSERT
170 ipc_port_debug_init();
171 #endif
172 mig_init();
173 ipc_table_init();
174 ipc_hash_init();
175 ipc_kmsg_init();
176 semaphore_init();
177 lock_set_init();
178 mk_timer_init();
179 host_notify_init();
180 }
181
182 /*
183 * XXX tunable, belongs in mach.message.h
184 */
185 #define MSG_OOL_SIZE_SMALL_MAX 4096
186 vm_size_t msg_ool_size_small;
187
188 /*
189 * Routine: ipc_init
190 * Purpose:
191 * Final initialization of the IPC system.
192 */
193
194 void
195 ipc_init(void)
196 {
197 kern_return_t retval;
198 vm_offset_t min, max;
199 extern vm_size_t kalloc_max_prerounded;
200
201 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_map_size,
202 TRUE, TRUE, &ipc_kernel_map);
203 if (retval != KERN_SUCCESS)
204 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
205
206 retval = kmem_suballoc(kernel_map, &min, ipc_kernel_copy_map_size,
207 TRUE, TRUE, &ipc_kernel_copy_map);
208 if (retval != KERN_SUCCESS)
209 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
210
211 ipc_kernel_copy_map->no_zero_fill = TRUE;
212 ipc_kernel_copy_map->wait_for_space = TRUE;
213
214 /*
215 * As an optimization, 'small' out of line data regions using a
216 * physical copy strategy are copied into kalloc'ed buffers.
217 * The value of 'small' is determined here. Requests kalloc()
218 * with sizes greater or equal to kalloc_max_prerounded may fail.
219 */
220 if (kalloc_max_prerounded <= MSG_OOL_SIZE_SMALL_MAX) {
221 msg_ool_size_small = kalloc_max_prerounded;
222 }
223 else {
224 msg_ool_size_small = MSG_OOL_SIZE_SMALL_MAX;
225 }
226
227 ipc_host_init();
228 }