|
|
1.1 root 1: /*
2: * Copyright (c) 2000 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: * HISTORY
28: *
29: * 11 Mar 1997 Eryk Vershen @ NeXT
30: * Modified from hppa version.
31: * 26 May 1992 ? at NeXT
32: * Created from 68k version.
33: */
34:
35: #include <mach_nbc.h>
36: #import <mach/mach_types.h>
37:
38: #import <vm/vm_kern.h>
39: #include <mach/vm_prot.h>
40:
41: #import <sys/param.h>
42: #import <sys/buf.h>
43: #import <sys/clist.h>
44: #import <sys/mbuf.h>
45: #import <sys/systm.h>
46: #import <sys/tty.h>
47: #import <bsd/dev/ppc/cons.h>
48:
49:
50: extern vm_map_t mb_map;
51: /*
52: * Declare these as initialized data so we can patch them.
53: */
54: int niobuf = 0;
55:
56: #ifdef NBUF
57: int nbuf = NBUF;
58: #else
59: int nbuf = 0;
60: #endif
61: #ifdef NMFSBUF
62: int nmfsbuf = NMFSBUF
63: #else
64: int nmfsbuf = 0;
65: #endif
66: #ifdef BUFPAGES
67: int bufpages = BUFPAGES;
68: #else
69: int bufpages = 0;
70: #endif
71:
72: int srv = 0; /* Flag indicates a server boot when set */
73: int ncl = 0;
74:
75: vm_map_t buffer_map;
76: vm_map_t bufferhdr_map;
77:
78:
79:
80:
81: void
82: bsd_startupearly()
83: {
84: vm_offset_t v, firstaddr, trash_offset;
85: vm_size_t size;
86: kern_return_t ret;
87:
88:
89: /*
90: * Since these pages are virtual-size pages (larger
91: * than physical page size), use only one page
92: * per buffer.
93: */
94: if (bufpages == 0) {
95: bufpages = atop(mem_size / 50);
96: }
97:
98: if (nbuf == 0) {
99: #if PRIVATE_BUFS
100: nbuf = 100;
101: #else PRIVATE_BUFS
102: /* Go for a 1-1 correspondence between the number of buffer
103: * headers and bufpages. Then add some extra (empty) buffer
104: * headers to aid clustering.
105: */
106: if ((nbuf = bufpages) < 16)
107: nbuf = 16;
108: nbuf += 64;
109: #endif PRIVATE_BUFS
110: }
111:
112: if (bufpages > nbuf * (MAXBSIZE / page_size))
113: bufpages = nbuf * (MAXBSIZE / page_size);
114: if (niobuf == 0) {
115: if ((niobuf = bufpages / (MAXPHYSIO / page_size)) > 1024)
116: niobuf = 1024;
117: if (niobuf < 32)
118: niobuf = 32;
119: }
120:
121: size = (nbuf + niobuf) * sizeof (struct buf);
122: size = round_page(size);
123:
124: ret = kmem_suballoc(kernel_map,
125: &firstaddr,
126: size,
127: FALSE,
128: TRUE,
129: &bufferhdr_map);
130:
131: if (ret != KERN_SUCCESS)
132: panic("Failed to create bufferhdr_map\n");
133:
134: if (kernel_memory_allocate(bufferhdr_map, &firstaddr, size,
135: 0,
136: KMA_HERE | KMA_KOBJECT) != KERN_SUCCESS)
137: panic("Failed to allocate bufferhdr_map\n");
138:
139: buf = (struct buf * )firstaddr;
140: bzero(buf,size);
141:
142:
143: /*
144: * Unless set at the boot command line, mfs gets no more than
145: * half of the system's bufs. Hack to prevent buf starvation
146: * and system hang.
147: */
148: if (nmfsbuf == 0)
149: nmfsbuf = nbuf / 2;
150:
151: if (mem_size > (64 * 1024 * 1024)) {
152: int scale;
153: extern u_long tcp_sendspace;
154: extern u_long tcp_recvspace;
155:
156: if ((nmbclusters = ncl) == 0) {
157: if ((nmbclusters = ((mem_size / 16) / MCLBYTES)) > 4096)
158: nmbclusters = 8192;
159: }
160: if ((scale = nmbclusters / NMBCLUSTERS) > 1) {
161: tcp_sendspace *= scale;
162: tcp_recvspace *= scale;
163:
164: if (tcp_sendspace > (32 * 1024))
165: tcp_sendspace = 32 * 1024;
166: if (tcp_recvspace > (32 * 1024))
167: tcp_recvspace = 32 * 1024;
168: }
169: }
170:
171: }
172:
173: void
174: bsd_bufferinit()
175: {
176: unsigned int i;
177: vm_offset_t v;
178: vm_size_t size;
179: kern_return_t ret;
180: vm_offset_t trash_offset, firstaddr;
181: int base, residual;
182:
183: cons.t_dev = makedev(12, 0);
184:
185:
186: bsd_startupearly();
187:
188: size = round_page(nbuf * MAXBSIZE) + (niobuf * MAXPHYSIO);
189: ret = kmem_suballoc(kernel_map,
190: &firstaddr,
191: size,
192: TRUE,
193: TRUE,
194: &buffer_map);
195:
196: if (ret != KERN_SUCCESS)
197: panic("Failed to create buffer_map\n");
198: buffers = firstaddr;
199: base = bufpages / nbuf;
200: residual = bufpages % nbuf;
201:
202: for (i = 0; i < nbuf; i++) {
203: vm_size_t thisbsize;
204: vm_offset_t curbuf;
205:
206: /*
207: * First <residual> buffers get (base+1) physical pages
208: * allocated for them. The rest get (base) physical pages.
209: *
210: * The rest of each buffer occupies virtual space,
211: * but has no physical memory allocated for it.
212: */
213:
214: thisbsize = page_size*(i < residual ? base+1 : base);
215: curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
216: if (thisbsize) {
217:
218: ret = vm_map_enter(buffer_map, &curbuf, thisbsize,
219: (vm_offset_t) 0, FALSE,
220: VM_OBJECT_NULL, (vm_offset_t) 0, FALSE,
221: VM_PROT_DEFAULT, VM_PROT_ALL, VM_INHERIT_DEFAULT);
222: if (ret != KERN_SUCCESS) {
223: panic("Failed to allocate buffer cache pages\n");
224: }
225: ret = vm_map_wire(buffer_map, curbuf, curbuf+thisbsize, VM_PROT_READ | VM_PROT_WRITE, FALSE);
226: if (ret != KERN_SUCCESS)
227: panic("Failed to wire buffer cache pages\n");
228:
229: } else {
230: //printf("skipping allocating buffer page to buf %d\n",i);
231: }
232: }
233:
234:
235: #define MEG (1024*1024)
236: {
237: register int nbytes;
238:
239: nbytes = ptoa(bufpages);
240: printf("using %d buffers containing %d.%d%d megabytes of memory\n",
241: nbuf,
242: nbytes/MEG,
243: ((nbytes%MEG)*10)/MEG,
244: ((nbytes%(MEG/10))*100)/MEG);
245:
246: }
247:
248: ret = kmem_suballoc(kernel_map,
249: (vm_offset_t *)&mbutl,
250: (vm_size_t) (nmbclusters * MCLBYTES),
251: FALSE,
252: TRUE,
253: &mb_map);
254:
255: if (ret != KERN_SUCCESS)
256: panic("Failed to allocate mb_map\n");
257: /* embutl = ((unsigned char *)mbutl + (nmbclusters * MCLBYTES)); */
258:
259: /*
260: * Set up buffers, so they can be used to read disk labels.
261: */
262: bufinit();
263: }
264:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.