]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/unix_startup.c
fc8bb8f41f87caf076a620a56a298a16fc199c33
[apple/xnu.git] / bsd / dev / unix_startup.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1992,7 NeXT Computer, Inc.
25 *
26 * Unix data structure initialization.
27 *
28 */
29
30 #include <mach/mach_types.h>
31
32 #include <vm/vm_kern.h>
33 #include <mach/vm_prot.h>
34
35 #include <sys/param.h>
36 #include <sys/buf_internal.h>
37 #include <sys/clist.h>
38 #include <sys/mbuf.h>
39 #include <sys/systm.h>
40 #include <sys/tty.h>
41 #include <dev/ppc/cons.h>
42
43 extern vm_map_t mb_map;
44
45 extern u_long tcp_sendspace;
46 extern u_long tcp_recvspace;
47
48 void bsd_bufferinit(void);
49 extern void md_prepare_for_shutdown(int, int, char *);
50
51 /*
52 * Declare these as initialized data so we can patch them.
53 */
54
55 #ifdef NBUF
56 int nbuf = NBUF;
57 int niobuf = NBUF / 2;
58
59 #else
60 int nbuf = 0;
61 int niobuf = 0;
62
63 #endif
64
65 int srv = 0; /* Flag indicates a server boot when set */
66 int ncl = 0;
67
68 vm_map_t buffer_map;
69 vm_map_t bufferhdr_map;
70
71
72 extern void bsd_startupearly(void);
73
74 void
75 bsd_startupearly(void)
76 {
77 vm_offset_t firstaddr;
78 vm_size_t size;
79 kern_return_t ret;
80
81 if (nbuf == 0)
82 nbuf = atop(sane_size / 100); /* Get 1% of ram, but no more than we can map */
83 if (nbuf > 8192)
84 nbuf = 8192;
85 if (nbuf < 256)
86 nbuf = 256;
87
88 if (niobuf == 0)
89 niobuf = nbuf;
90 if (niobuf > 4096)
91 niobuf = 4096;
92 if (niobuf < 128)
93 niobuf = 128;
94
95 size = (nbuf + niobuf) * sizeof(struct buf);
96 size = round_page(size);
97
98 ret = kmem_suballoc(kernel_map,
99 &firstaddr,
100 size,
101 FALSE,
102 VM_FLAGS_ANYWHERE,
103 &bufferhdr_map);
104
105 if (ret != KERN_SUCCESS)
106 panic("Failed to create bufferhdr_map");
107
108 ret = kernel_memory_allocate(bufferhdr_map,
109 &firstaddr,
110 size,
111 0,
112 KMA_HERE | KMA_KOBJECT);
113
114 if (ret != KERN_SUCCESS)
115 panic("Failed to allocate bufferhdr_map");
116
117 buf = (struct buf *) firstaddr;
118 bzero(buf, size);
119
120 if (sane_size > (64 * 1024 * 1024) || ncl) {
121 int scale;
122
123 if ((nmbclusters = ncl) == 0) {
124 if ((nmbclusters = ((sane_size / 16)/MCLBYTES)) > 32768)
125 nmbclusters = 32768;
126 }
127 if ((scale = nmbclusters / NMBCLUSTERS) > 1) {
128 tcp_sendspace *= scale;
129 tcp_recvspace *= scale;
130
131 if (tcp_sendspace > (32 * 1024))
132 tcp_sendspace = 32 * 1024;
133 if (tcp_recvspace > (32 * 1024))
134 tcp_recvspace = 32 * 1024;
135 }
136 }
137 }
138
139 void
140 bsd_bufferinit(void)
141 {
142 kern_return_t ret;
143
144 cons.t_dev = makedev(12, 0);
145
146 bsd_startupearly();
147
148 ret = kmem_suballoc(kernel_map,
149 (vm_offset_t *) & mbutl,
150 (vm_size_t) (nmbclusters * MCLBYTES),
151 FALSE,
152 VM_FLAGS_ANYWHERE,
153 &mb_map);
154
155 if (ret != KERN_SUCCESS)
156 panic("Failed to allocate mb_map\n");
157
158 /*
159 * Set up buffers, so they can be used to read disk labels.
160 */
161 bufinit();
162 }