]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/unix_startup.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / dev / unix_startup.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
8ad349bb 5 *
8f6c56a5
A
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * Copyright (c) 1992,7 NeXT Computer, Inc.
30 *
31 * Unix data structure initialization.
91447636 32 *
1c79356b
A
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>
91447636 41#include <sys/buf_internal.h>
1c79356b
A
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
91447636
A
48extern vm_map_t mb_map;
49
50extern u_long tcp_sendspace;
51extern u_long tcp_recvspace;
52
53void bsd_bufferinit(void);
54extern void md_prepare_for_shutdown(int, int, char *);
1c79356b
A
55
56/*
57 * Declare these as initialized data so we can patch them.
58 */
59
60#ifdef NBUF
8f6c56a5 61int nbuf = NBUF;
91447636 62int niobuf = NBUF / 2;
8f6c56a5 63
1c79356b 64#else
8f6c56a5 65int nbuf = 0;
91447636 66int niobuf = 0;
c0fea474 67
8f6c56a5 68#endif
5d5c5d0d 69
91447636
A
70int srv = 0; /* Flag indicates a server boot when set */
71int ncl = 0;
72
73vm_map_t buffer_map;
74vm_map_t bufferhdr_map;
1c79356b 75
91447636
A
76
77extern void bsd_startupearly(void);
1c79356b
A
78
79void
91447636 80bsd_startupearly(void)
1c79356b 81{
91447636
A
82 vm_offset_t firstaddr;
83 vm_size_t size;
84 kern_return_t ret;
1c79356b 85
8f6c56a5
A
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;
1c79356b
A
92
93 if (niobuf == 0)
8f6c56a5 94 niobuf = nbuf;
1c79356b
A
95 if (niobuf > 4096)
96 niobuf = 4096;
97 if (niobuf < 128)
98 niobuf = 128;
99
8f6c56a5 100 size = (nbuf + niobuf) * sizeof(struct buf);
91447636 101 size = round_page(size);
1c79356b
A
102
103 ret = kmem_suballoc(kernel_map,
91447636
A
104 &firstaddr,
105 size,
106 FALSE,
107 VM_FLAGS_ANYWHERE,
108 &bufferhdr_map);
1c79356b 109
91447636 110 if (ret != KERN_SUCCESS)
1c79356b 111 panic("Failed to create bufferhdr_map");
91447636 112
1c79356b 113 ret = kernel_memory_allocate(bufferhdr_map,
91447636
A
114 &firstaddr,
115 size,
116 0,
117 KMA_HERE | KMA_KOBJECT);
1c79356b
A
118
119 if (ret != KERN_SUCCESS)
120 panic("Failed to allocate bufferhdr_map");
121
91447636
A
122 buf = (struct buf *) firstaddr;
123 bzero(buf, size);
1c79356b 124
8f6c56a5 125 if (sane_size > (64 * 1024 * 1024) || ncl) {
91447636 126 int scale;
1c79356b 127
8f6c56a5
A
128 if ((nmbclusters = ncl) == 0) {
129 if ((nmbclusters = ((sane_size / 16)/MCLBYTES)) > 32768)
130 nmbclusters = 32768;
131 }
1c79356b
A
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
144void
91447636 145bsd_bufferinit(void)
1c79356b 146{
91447636 147 kern_return_t ret;
1c79356b 148
91447636 149 cons.t_dev = makedev(12, 0);
1c79356b
A
150
151 bsd_startupearly();
152
91447636
A
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);
1c79356b 159
91447636 160 if (ret != KERN_SUCCESS)
1c79356b 161 panic("Failed to allocate mb_map\n");
0b4e3aa0 162
91447636
A
163 /*
164 * Set up buffers, so they can be used to read disk labels.
165 */
166 bufinit();
0b4e3aa0 167}