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