]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/unix_startup.c
86cfdd66412582e60c82f2abb140d057cb14726d
[apple/xnu.git] / bsd / dev / unix_startup.c
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1992,7 NeXT Computer, Inc.
32 *
33 * Unix data structure initialization.
34 *
35 */
36
37 #include <mach/mach_types.h>
38
39 #include <vm/vm_kern.h>
40 #include <mach/vm_prot.h>
41
42 #include <sys/param.h>
43 #include <sys/buf_internal.h>
44 #include <sys/clist.h>
45 #include <sys/mbuf.h>
46 #include <sys/systm.h>
47 #include <sys/tty.h>
48 #include <dev/ppc/cons.h>
49
50 extern vm_map_t mb_map;
51
52 extern u_long tcp_sendspace;
53 extern u_long tcp_recvspace;
54
55 void bsd_bufferinit(void);
56 extern void md_prepare_for_shutdown(int, int, char *);
57
58 /*
59 * Declare these as initialized data so we can patch them.
60 */
61
62 #ifdef NBUF
63 int nbuf = NBUF;
64 int niobuf = NBUF / 2;
65
66 #else
67 int nbuf = 0;
68 int niobuf = 0;
69
70 #endif
71
72 int srv = 0; /* Flag indicates a server boot when set */
73 int ncl = 0;
74
75 vm_map_t buffer_map;
76 vm_map_t bufferhdr_map;
77
78
79 extern void bsd_startupearly(void);
80
81 void
82 bsd_startupearly(void)
83 {
84 vm_offset_t firstaddr;
85 vm_size_t size;
86 kern_return_t ret;
87
88 if (nbuf == 0)
89 nbuf = atop(sane_size / 100); /* Get 1% of ram, but no more than we can map */
90 if (nbuf > 8192)
91 nbuf = 8192;
92 if (nbuf < 256)
93 nbuf = 256;
94
95 if (niobuf == 0)
96 niobuf = nbuf;
97 if (niobuf > 4096)
98 niobuf = 4096;
99 if (niobuf < 128)
100 niobuf = 128;
101
102 size = (nbuf + niobuf) * sizeof(struct buf);
103 size = round_page(size);
104
105 ret = kmem_suballoc(kernel_map,
106 &firstaddr,
107 size,
108 FALSE,
109 VM_FLAGS_ANYWHERE,
110 &bufferhdr_map);
111
112 if (ret != KERN_SUCCESS)
113 panic("Failed to create bufferhdr_map");
114
115 ret = kernel_memory_allocate(bufferhdr_map,
116 &firstaddr,
117 size,
118 0,
119 KMA_HERE | KMA_KOBJECT);
120
121 if (ret != KERN_SUCCESS)
122 panic("Failed to allocate bufferhdr_map");
123
124 buf = (struct buf *) firstaddr;
125 bzero(buf, size);
126
127 if (sane_size > (64 * 1024 * 1024) || ncl) {
128 int scale;
129
130 if ((nmbclusters = ncl) == 0) {
131 if ((nmbclusters = ((sane_size / 16)/MCLBYTES)) > 32768)
132 nmbclusters = 32768;
133 }
134 if ((scale = nmbclusters / NMBCLUSTERS) > 1) {
135 tcp_sendspace *= scale;
136 tcp_recvspace *= scale;
137
138 if (tcp_sendspace > (32 * 1024))
139 tcp_sendspace = 32 * 1024;
140 if (tcp_recvspace > (32 * 1024))
141 tcp_recvspace = 32 * 1024;
142 }
143 }
144 }
145
146 void
147 bsd_bufferinit(void)
148 {
149 kern_return_t ret;
150
151 cons.t_dev = makedev(12, 0);
152
153 bsd_startupearly();
154
155 ret = kmem_suballoc(kernel_map,
156 (vm_offset_t *) & mbutl,
157 (vm_size_t) (nmbclusters * MCLBYTES),
158 FALSE,
159 VM_FLAGS_ANYWHERE,
160 &mb_map);
161
162 if (ret != KERN_SUCCESS)
163 panic("Failed to allocate mb_map\n");
164
165 /*
166 * Set up buffers, so they can be used to read disk labels.
167 */
168 bufinit();
169 }