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