2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
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.
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.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: ipc/ipc_init.c
60 * Functions to initialize the IPC system.
63 #include <mach_debug.h>
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 */
85 vm_map_t ipc_kernel_map
;
86 vm_size_t ipc_kernel_map_size
= 1024 * 1024;
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;
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
;
98 extern void mig_init(void);
99 extern void ikm_cache_init(void);
102 * Routine: ipc_bootstrap
104 * Initialization needed before the kernel task
113 ipc_port_multiple_lock_init();
115 ipc_port_timestamp_lock_init();
116 ipc_port_timestamp_data
= 0;
118 /* all IPC zones should be exhaustible */
120 ipc_space_zone
= zinit(sizeof(struct ipc_space
),
121 ipc_space_max
* sizeof(struct ipc_space
),
122 sizeof(struct ipc_space
),
125 /* make it exhaustible */
126 zone_change(ipc_space_zone
, Z_EXHAUST
, TRUE
);
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
),
135 /* make it exhaustible */
136 zone_change(ipc_tree_entry_zone
, Z_EXHAUST
, TRUE
);
140 * populate all port(set) zones
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
),
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);
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
),
158 /* make it exhaustible */
159 zone_change(ipc_object_zones
[IOT_PORT_SET
], Z_EXHAUST
, TRUE
);
161 /* create special spaces */
163 kr
= ipc_space_create_special(&ipc_space_kernel
);
164 assert(kr
== KERN_SUCCESS
);
167 kr
= ipc_space_create_special(&ipc_space_reply
);
168 assert(kr
== KERN_SUCCESS
);
170 /* initialize modules with hidden data structures */
173 ipc_port_debug_init();
186 * XXX tunable, belongs in mach.message.h
188 #define MSG_OOL_SIZE_SMALL_MAX 4096
189 vm_size_t msg_ool_size_small
;
194 * Final initialization of the IPC system.
200 kern_return_t retval
;
201 vm_offset_t min
, max
;
202 extern vm_size_t kalloc_max_prerounded
;
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");
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");
214 ipc_kernel_copy_map
->no_zero_fill
= TRUE
;
215 ipc_kernel_copy_map
->wait_for_space
= TRUE
;
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.
223 if (kalloc_max_prerounded
<= MSG_OOL_SIZE_SMALL_MAX
) {
224 msg_ool_size_small
= kalloc_max_prerounded
;
227 msg_ool_size_small
= MSG_OOL_SIZE_SMALL_MAX
;