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