2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: ipc/ipc_init.c
58 * Functions to initialize the IPC system.
61 #include <mach_debug.h>
64 #include <mach/port.h>
65 #include <mach/kern_return.h>
67 #include <kern/kern_types.h>
68 #include <kern/kalloc.h>
69 #include <kern/mach_param.h>
70 #include <kern/ipc_host.h>
71 #include <kern/ipc_mig.h>
72 #include <kern/host_notify.h>
73 #include <kern/mk_timer.h>
74 #include <kern/misc_protos.h>
75 #include <kern/sync_lock.h>
76 #include <kern/sync_sema.h>
77 #include <vm/vm_map.h>
78 #include <vm/vm_kern.h>
80 #include <ipc/ipc_entry.h>
81 #include <ipc/ipc_space.h>
82 #include <ipc/ipc_object.h>
83 #include <ipc/ipc_port.h>
84 #include <ipc/ipc_pset.h>
85 #include <ipc/ipc_notify.h>
86 #include <ipc/ipc_kmsg.h>
87 #include <ipc/ipc_hash.h>
88 #include <ipc/ipc_init.h>
89 #include <ipc/ipc_table.h>
91 #include <mach/machine/ndr_def.h> /* NDR_record */
93 vm_map_t ipc_kernel_map
;
94 vm_size_t ipc_kernel_map_size
= 1024 * 1024;
96 vm_map_t ipc_kernel_copy_map
;
97 #define IPC_KERNEL_COPY_MAP_SIZE (8 * 1024 * 1024)
98 vm_size_t ipc_kernel_copy_map_size
= IPC_KERNEL_COPY_MAP_SIZE
;
99 vm_size_t ipc_kmsg_max_vm_space
= (IPC_KERNEL_COPY_MAP_SIZE
* 7)/8;
101 int ipc_space_max
= SPACE_MAX
;
102 int ipc_tree_entry_max
= ITE_MAX
;
103 int ipc_port_max
= PORT_MAX
;
104 int ipc_pset_max
= SET_MAX
;
106 extern void ikm_cache_init(void);
109 * Routine: ipc_bootstrap
111 * Initialization needed before the kernel task
120 ipc_port_multiple_lock_init();
122 ipc_port_timestamp_lock_init();
123 ipc_port_timestamp_data
= 0;
125 /* all IPC zones should be exhaustible */
127 ipc_space_zone
= zinit(sizeof(struct ipc_space
),
128 ipc_space_max
* sizeof(struct ipc_space
),
129 sizeof(struct ipc_space
),
132 /* make it exhaustible */
133 zone_change(ipc_space_zone
, Z_EXHAUST
, TRUE
);
136 ipc_tree_entry_zone
=
137 zinit(sizeof(struct ipc_tree_entry
),
138 ipc_tree_entry_max
* sizeof(struct ipc_tree_entry
),
139 sizeof(struct ipc_tree_entry
),
142 /* make it exhaustible */
143 zone_change(ipc_tree_entry_zone
, Z_EXHAUST
, TRUE
);
147 * populate all port(set) zones
149 ipc_object_zones
[IOT_PORT
] =
150 zinit(sizeof(struct ipc_port
),
151 ipc_port_max
* sizeof(struct ipc_port
),
152 sizeof(struct ipc_port
),
155 * XXX Can't make the port zone exhaustible because the kernel
156 * XXX panics when port allocation for an internal object fails.
157 *zone_change(ipc_object_zones[IOT_PORT], Z_EXHAUST, TRUE);
160 ipc_object_zones
[IOT_PORT_SET
] =
161 zinit(sizeof(struct ipc_pset
),
162 ipc_pset_max
* sizeof(struct ipc_pset
),
163 sizeof(struct ipc_pset
),
165 /* make it exhaustible */
166 zone_change(ipc_object_zones
[IOT_PORT_SET
], Z_EXHAUST
, TRUE
);
169 * Create the basic ipc_kmsg_t zone (the one we also cache)
170 * elements at the processor-level to avoid the locking.
172 ipc_kmsg_zone
= zinit(IKM_SAVED_KMSG_SIZE
,
173 ipc_port_max
* MACH_PORT_QLIMIT_MAX
*
178 /* create special spaces */
180 kr
= ipc_space_create_special(&ipc_space_kernel
);
181 assert(kr
== KERN_SUCCESS
);
184 kr
= ipc_space_create_special(&ipc_space_reply
);
185 assert(kr
== KERN_SUCCESS
);
187 /* initialize modules with hidden data structures */
190 ipc_port_debug_init();
202 * XXX tunable, belongs in mach.message.h
204 #define MSG_OOL_SIZE_SMALL_MAX 4096
205 vm_size_t msg_ool_size_small
;
210 * Final initialization of the IPC system.
216 kern_return_t retval
;
219 retval
= kmem_suballoc(kernel_map
, &min
, ipc_kernel_map_size
,
220 TRUE
, VM_FLAGS_ANYWHERE
, &ipc_kernel_map
);
222 if (retval
!= KERN_SUCCESS
)
223 panic("ipc_init: kmem_suballoc of ipc_kernel_map failed");
225 retval
= kmem_suballoc(kernel_map
, &min
, ipc_kernel_copy_map_size
,
226 TRUE
, VM_FLAGS_ANYWHERE
, &ipc_kernel_copy_map
);
228 if (retval
!= KERN_SUCCESS
)
229 panic("ipc_init: kmem_suballoc of ipc_kernel_copy_map failed");
231 ipc_kernel_copy_map
->no_zero_fill
= TRUE
;
232 ipc_kernel_copy_map
->wait_for_space
= TRUE
;
235 * As an optimization, 'small' out of line data regions using a
236 * physical copy strategy are copied into kalloc'ed buffers.
237 * The value of 'small' is determined here. Requests kalloc()
238 * with sizes greater or equal to kalloc_max_prerounded may fail.
240 if (kalloc_max_prerounded
<= MSG_OOL_SIZE_SMALL_MAX
) {
241 msg_ool_size_small
= kalloc_max_prerounded
;
244 msg_ool_size_small
= MSG_OOL_SIZE_SMALL_MAX
;