Print this page
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/startup.c
+++ new/usr/src/uts/i86pc/os/startup.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
25 25 * Copyright 2017 Nexenta Systems, Inc.
26 - * Copyright 2015 Joyent, Inc.
26 + * Copyright (c) 2018 Joyent, Inc.
27 27 * Copyright (c) 2015 by Delphix. All rights reserved.
28 28 */
29 29 /*
30 30 * Copyright (c) 2010, Intel Corporation.
31 31 * All rights reserved.
32 32 */
33 33
34 34 #include <sys/types.h>
35 35 #include <sys/t_lock.h>
36 36 #include <sys/param.h>
37 37 #include <sys/sysmacros.h>
38 38 #include <sys/signal.h>
39 39 #include <sys/systm.h>
40 40 #include <sys/user.h>
41 41 #include <sys/mman.h>
42 42 #include <sys/vm.h>
43 43 #include <sys/conf.h>
44 44 #include <sys/avintr.h>
45 45 #include <sys/autoconf.h>
46 46 #include <sys/disp.h>
47 47 #include <sys/class.h>
48 48 #include <sys/bitmap.h>
49 49
50 50 #include <sys/privregs.h>
51 51
52 52 #include <sys/proc.h>
53 53 #include <sys/buf.h>
54 54 #include <sys/kmem.h>
55 55 #include <sys/mem.h>
56 56 #include <sys/kstat.h>
57 57
58 58 #include <sys/reboot.h>
59 59
60 60 #include <sys/cred.h>
61 61 #include <sys/vnode.h>
62 62 #include <sys/file.h>
63 63
64 64 #include <sys/procfs.h>
65 65
66 66 #include <sys/vfs.h>
67 67 #include <sys/cmn_err.h>
68 68 #include <sys/utsname.h>
69 69 #include <sys/debug.h>
70 70 #include <sys/kdi.h>
71 71
72 72 #include <sys/dumphdr.h>
73 73 #include <sys/bootconf.h>
74 74 #include <sys/memlist_plat.h>
75 75 #include <sys/varargs.h>
76 76 #include <sys/promif.h>
77 77 #include <sys/modctl.h>
78 78
79 79 #include <sys/sunddi.h>
80 80 #include <sys/sunndi.h>
81 81 #include <sys/ndi_impldefs.h>
82 82 #include <sys/ddidmareq.h>
83 83 #include <sys/psw.h>
84 84 #include <sys/regset.h>
85 85 #include <sys/clock.h>
86 86 #include <sys/pte.h>
87 87 #include <sys/tss.h>
88 88 #include <sys/stack.h>
89 89 #include <sys/trap.h>
90 90 #include <sys/fp.h>
91 91 #include <vm/kboot_mmu.h>
92 92 #include <vm/anon.h>
93 93 #include <vm/as.h>
94 94 #include <vm/page.h>
95 95 #include <vm/seg.h>
96 96 #include <vm/seg_dev.h>
97 97 #include <vm/seg_kmem.h>
98 98 #include <vm/seg_kpm.h>
99 99 #include <vm/seg_map.h>
100 100 #include <vm/seg_vn.h>
101 101 #include <vm/seg_kp.h>
102 102 #include <sys/memnode.h>
103 103 #include <vm/vm_dep.h>
104 104 #include <sys/thread.h>
105 105 #include <sys/sysconf.h>
106 106 #include <sys/vm_machparam.h>
107 107 #include <sys/archsystm.h>
108 108 #include <sys/machsystm.h>
109 109 #include <vm/hat.h>
110 110 #include <vm/hat_i86.h>
111 111 #include <sys/pmem.h>
112 112 #include <sys/smp_impldefs.h>
113 113 #include <sys/x86_archext.h>
114 114 #include <sys/cpuvar.h>
115 115 #include <sys/segments.h>
116 116 #include <sys/clconf.h>
117 117 #include <sys/kobj.h>
118 118 #include <sys/kobj_lex.h>
119 119 #include <sys/cpc_impl.h>
120 120 #include <sys/cpu_module.h>
121 121 #include <sys/smbios.h>
122 122 #include <sys/debug_info.h>
123 123 #include <sys/bootinfo.h>
124 124 #include <sys/ddi_periodic.h>
125 125 #include <sys/systeminfo.h>
126 126 #include <sys/multiboot.h>
127 127 #include <sys/ramdisk.h>
128 128
129 129 #ifdef __xpv
130 130
131 131 #include <sys/hypervisor.h>
132 132 #include <sys/xen_mmu.h>
133 133 #include <sys/evtchn_impl.h>
134 134 #include <sys/gnttab.h>
135 135 #include <sys/xpv_panic.h>
136 136 #include <xen/sys/xenbus_comms.h>
137 137 #include <xen/public/physdev.h>
138 138
139 139 extern void xen_late_startup(void);
140 140
141 141 struct xen_evt_data cpu0_evt_data;
142 142
143 143 #else /* __xpv */
144 144 #include <sys/memlist_impl.h>
145 145
146 146 extern void mem_config_init(void);
147 147 #endif /* __xpv */
148 148
149 149 extern void progressbar_init(void);
150 150 extern void brand_init(void);
151 151 extern void pcf_init(void);
152 152 extern void pg_init(void);
153 153 extern void ssp_init(void);
154 154
155 155 extern int size_pse_array(pgcnt_t, int);
156 156
157 157 #if defined(_SOFT_HOSTID)
158 158
159 159 #include <sys/rtc.h>
160 160
161 161 static int32_t set_soft_hostid(void);
162 162 static char hostid_file[] = "/etc/hostid";
163 163
164 164 #endif
165 165
166 166 void *gfx_devinfo_list;
167 167
168 168 #if defined(__amd64) && !defined(__xpv)
169 169 extern void immu_startup(void);
170 170 #endif
171 171
172 172 /*
173 173 * XXX make declaration below "static" when drivers no longer use this
174 174 * interface.
175 175 */
176 176 extern caddr_t p0_va; /* Virtual address for accessing physical page 0 */
177 177
178 178 /*
179 179 * segkp
180 180 */
181 181 extern int segkp_fromheap;
182 182
183 183 static void kvm_init(void);
184 184 static void startup_init(void);
185 185 static void startup_memlist(void);
186 186 static void startup_kmem(void);
187 187 static void startup_modules(void);
188 188 static void startup_vm(void);
189 189 static void startup_end(void);
190 190 static void layout_kernel_va(void);
191 191
192 192 /*
193 193 * Declare these as initialized data so we can patch them.
194 194 */
195 195 #ifdef __i386
196 196
197 197 /*
198 198 * Due to virtual address space limitations running in 32 bit mode, restrict
199 199 * the amount of physical memory configured to a max of PHYSMEM pages (16g).
200 200 *
201 201 * If the physical max memory size of 64g were allowed to be configured, the
202 202 * size of user virtual address space will be less than 1g. A limited user
203 203 * address space greatly reduces the range of applications that can run.
204 204 *
205 205 * If more physical memory than PHYSMEM is required, users should preferably
206 206 * run in 64 bit mode which has far looser virtual address space limitations.
207 207 *
208 208 * If 64 bit mode is not available (as in IA32) and/or more physical memory
209 209 * than PHYSMEM is required in 32 bit mode, physmem can be set to the desired
210 210 * value or to 0 (to configure all available memory) via eeprom(1M). kernelbase
211 211 * should also be carefully tuned to balance out the need of the user
212 212 * application while minimizing the risk of kernel heap exhaustion due to
213 213 * kernelbase being set too high.
214 214 */
215 215 #define PHYSMEM 0x400000
216 216
217 217 #else /* __amd64 */
218 218
219 219 /*
220 220 * For now we can handle memory with physical addresses up to about
221 221 * 64 Terabytes. This keeps the kernel above the VA hole, leaving roughly
222 222 * half the VA space for seg_kpm. When systems get bigger than 64TB this
223 223 * code will need revisiting. There is an implicit assumption that there
224 224 * are no *huge* holes in the physical address space too.
225 225 */
226 226 #define TERABYTE (1ul << 40)
227 227 #define PHYSMEM_MAX64 mmu_btop(64 * TERABYTE)
228 228 #define PHYSMEM PHYSMEM_MAX64
229 229 #define AMD64_VA_HOLE_END 0xFFFF800000000000ul
230 230
231 231 #endif /* __amd64 */
232 232
233 233 pgcnt_t physmem = PHYSMEM;
234 234 pgcnt_t obp_pages; /* Memory used by PROM for its text and data */
235 235
236 236 char *kobj_file_buf;
237 237 int kobj_file_bufsize; /* set in /etc/system */
238 238
239 239 /* Global variables for MP support. Used in mp_startup */
240 240 caddr_t rm_platter_va = 0;
241 241 uint32_t rm_platter_pa;
242 242
243 243 int auto_lpg_disable = 1;
244 244
245 245 /*
246 246 * Some CPUs have holes in the middle of the 64-bit virtual address range.
247 247 */
248 248 uintptr_t hole_start, hole_end;
249 249
250 250 /*
251 251 * kpm mapping window
252 252 */
253 253 caddr_t kpm_vbase;
254 254 size_t kpm_size;
255 255 static int kpm_desired;
256 256 #ifdef __amd64
257 257 static uintptr_t segkpm_base = (uintptr_t)SEGKPM_BASE;
258 258 #endif
259 259
260 260 /*
261 261 * Configuration parameters set at boot time.
262 262 */
263 263
264 264 caddr_t econtig; /* end of first block of contiguous kernel */
265 265
266 266 struct bootops *bootops = 0; /* passed in from boot */
267 267 struct bootops **bootopsp;
268 268 struct boot_syscalls *sysp; /* passed in from boot */
269 269
270 270 char bootblock_fstype[16];
271 271
272 272 char kern_bootargs[OBP_MAXPATHLEN];
273 273 char kern_bootfile[OBP_MAXPATHLEN];
274 274
275 275 /*
276 276 * ZFS zio segment. This allows us to exclude large portions of ZFS data that
277 277 * gets cached in kmem caches on the heap. If this is set to zero, we allocate
278 278 * zio buffers from their own segment, otherwise they are allocated from the
279 279 * heap. The optimization of allocating zio buffers from their own segment is
280 280 * only valid on 64-bit kernels.
281 281 */
282 282 #if defined(__amd64)
283 283 int segzio_fromheap = 0;
284 284 #else
285 285 int segzio_fromheap = 1;
286 286 #endif
287 287
288 288 /*
289 289 * Give folks an escape hatch for disabling SMAP via kmdb. Doesn't work
290 290 * post-boot.
291 291 */
292 292 int disable_smap = 0;
293 293
294 294 /*
295 295 * new memory fragmentations are possible in startup() due to BOP_ALLOCs. this
296 296 * depends on number of BOP_ALLOC calls made and requested size, memory size
297 297 * combination and whether boot.bin memory needs to be freed.
298 298 */
299 299 #define POSS_NEW_FRAGMENTS 12
300 300
301 301 /*
302 302 * VM data structures
303 303 */
304 304 long page_hashsz; /* Size of page hash table (power of two) */
305 305 unsigned int page_hashsz_shift; /* log2(page_hashsz) */
306 306 struct page *pp_base; /* Base of initial system page struct array */
307 307 struct page **page_hash; /* Page hash table */
308 308 pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */
309 309 size_t pse_table_size; /* Number of mutexes in pse_mutex[] */
310 310 int pse_shift; /* log2(pse_table_size) */
311 311 struct seg ktextseg; /* Segment used for kernel executable image */
312 312 struct seg kvalloc; /* Segment used for "valloc" mapping */
313 313 struct seg kpseg; /* Segment used for pageable kernel virt mem */
314 314 struct seg kmapseg; /* Segment used for generic kernel mappings */
315 315 struct seg kdebugseg; /* Segment used for the kernel debugger */
316 316
317 317 struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */
318 318 static struct seg *segmap = &kmapseg; /* easier to use name for in here */
319 319
320 320 struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */
321 321
322 322 #if defined(__amd64)
323 323 struct seg kvseg_core; /* Segment used for the core heap */
324 324 struct seg kpmseg; /* Segment used for physical mapping */
325 325 struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */
326 326 #else
327 327 struct seg *segkpm = NULL; /* Unused on IA32 */
328 328 #endif
329 329
330 330 caddr_t segkp_base; /* Base address of segkp */
331 331 caddr_t segzio_base; /* Base address of segzio */
332 332 #if defined(__amd64)
333 333 pgcnt_t segkpsize = btop(SEGKPDEFSIZE); /* size of segkp segment in pages */
334 334 #else
335 335 pgcnt_t segkpsize = 0;
336 336 #endif
337 337 pgcnt_t segziosize = 0; /* size of zio segment in pages */
338 338
339 339 /*
340 340 * A static DR page_t VA map is reserved that can map the page structures
341 341 * for a domain's entire RA space. The pages that back this space are
342 342 * dynamically allocated and need not be physically contiguous. The DR
343 343 * map size is derived from KPM size.
344 344 * This mechanism isn't used by x86 yet, so just stubs here.
345 345 */
346 346 int ppvm_enable = 0; /* Static virtual map for page structs */
347 347 page_t *ppvm_base = NULL; /* Base of page struct map */
348 348 pgcnt_t ppvm_size = 0; /* Size of page struct map */
349 349
350 350 /*
351 351 * VA range available to the debugger
352 352 */
353 353 const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE;
354 354 const size_t kdi_segdebugsize = SEGDEBUGSIZE;
355 355
356 356 struct memseg *memseg_base;
357 357 struct vnode unused_pages_vp;
358 358
359 359 #define FOURGB 0x100000000LL
360 360
361 361 struct memlist *memlist;
362 362
363 363 caddr_t s_text; /* start of kernel text segment */
364 364 caddr_t e_text; /* end of kernel text segment */
365 365 caddr_t s_data; /* start of kernel data segment */
366 366 caddr_t e_data; /* end of kernel data segment */
367 367 caddr_t modtext; /* start of loadable module text reserved */
368 368 caddr_t e_modtext; /* end of loadable module text reserved */
369 369 caddr_t moddata; /* start of loadable module data reserved */
370 370 caddr_t e_moddata; /* end of loadable module data reserved */
371 371
372 372 struct memlist *phys_install; /* Total installed physical memory */
373 373 struct memlist *phys_avail; /* Total available physical memory */
374 374 struct memlist *bios_rsvd; /* Bios reserved memory */
375 375
376 376 /*
377 377 * kphysm_init returns the number of pages that were processed
378 378 */
379 379 static pgcnt_t kphysm_init(page_t *, pgcnt_t);
380 380
381 381 #define IO_PROP_SIZE 64 /* device property size */
382 382
383 383 /*
384 384 * a couple useful roundup macros
385 385 */
386 386 #define ROUND_UP_PAGE(x) \
387 387 ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)MMU_PAGESIZE))
388 388 #define ROUND_UP_LPAGE(x) \
389 389 ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[1]))
390 390 #define ROUND_UP_4MEG(x) \
391 391 ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)FOUR_MEG))
392 392 #define ROUND_UP_TOPLEVEL(x) \
393 393 ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[mmu.max_level]))
394 394
395 395 /*
396 396 * 32-bit Kernel's Virtual memory layout.
397 397 * +-----------------------+
398 398 * | |
399 399 * 0xFFC00000 -|-----------------------|- ARGSBASE
400 400 * | debugger |
401 401 * 0xFF800000 -|-----------------------|- SEGDEBUGBASE
402 402 * | Kernel Data |
403 403 * 0xFEC00000 -|-----------------------|
404 404 * | Kernel Text |
405 405 * 0xFE800000 -|-----------------------|- KERNEL_TEXT (0xFB400000 on Xen)
406 406 * |--- GDT ---|- GDT page (GDT_VA)
407 407 * |--- debug info ---|- debug info (DEBUG_INFO_VA)
408 408 * | |
409 409 * | page_t structures |
410 410 * | memsegs, memlists, |
411 411 * | page hash, etc. |
412 412 * --- -|-----------------------|- ekernelheap, valloc_base (floating)
413 413 * | | (segkp is just an arena in the heap)
414 414 * | |
415 415 * | kvseg |
416 416 * | |
417 417 * | |
418 418 * --- -|-----------------------|- kernelheap (floating)
419 419 * | Segkmap |
420 420 * 0xC3002000 -|-----------------------|- segmap_start (floating)
421 421 * | Red Zone |
422 422 * 0xC3000000 -|-----------------------|- kernelbase / userlimit (floating)
423 423 * | | ||
424 424 * | Shared objects | \/
425 425 * | |
426 426 * : :
427 427 * | user data |
428 428 * |-----------------------|
429 429 * | user text |
430 430 * 0x08048000 -|-----------------------|
431 431 * | user stack |
432 432 * : :
433 433 * | invalid |
434 434 * 0x00000000 +-----------------------+
435 435 *
436 436 *
437 437 * 64-bit Kernel's Virtual memory layout. (assuming 64 bit app)
438 438 * +-----------------------+
↓ open down ↓ |
402 lines elided |
↑ open up ↑ |
439 439 * | |
440 440 * 0xFFFFFFFF.FFC00000 |-----------------------|- ARGSBASE
441 441 * | debugger (?) |
442 442 * 0xFFFFFFFF.FF800000 |-----------------------|- SEGDEBUGBASE
443 443 * | unused |
444 444 * +-----------------------+
445 445 * | Kernel Data |
446 446 * 0xFFFFFFFF.FBC00000 |-----------------------|
447 447 * | Kernel Text |
448 448 * 0xFFFFFFFF.FB800000 |-----------------------|- KERNEL_TEXT
449 - * |--- GDT ---|- GDT page (GDT_VA)
450 449 * |--- debug info ---|- debug info (DEBUG_INFO_VA)
450 + * |--- GDT ---|- GDT page (GDT_VA)
451 + * |--- IDT ---|- IDT page (IDT_VA)
452 + * |--- LDT ---|- LDT pages (LDT_VA)
451 453 * | |
452 454 * | Core heap | (used for loadable modules)
453 455 * 0xFFFFFFFF.C0000000 |-----------------------|- core_base / ekernelheap
454 456 * | Kernel |
455 457 * | heap |
456 458 * 0xFFFFFXXX.XXX00000 |-----------------------|- kernelheap (floating)
457 459 * | segmap |
458 460 * 0xFFFFFXXX.XXX00000 |-----------------------|- segmap_start (floating)
459 461 * | device mappings |
460 462 * 0xFFFFFXXX.XXX00000 |-----------------------|- toxic_addr (floating)
461 463 * | segzio |
462 464 * 0xFFFFFXXX.XXX00000 |-----------------------|- segzio_base (floating)
463 465 * | segkp |
464 466 * --- |-----------------------|- segkp_base (floating)
465 467 * | page_t structures | valloc_base + valloc_sz
466 468 * | memsegs, memlists, |
467 469 * | page hash, etc. |
468 470 * 0xFFFFFF00.00000000 |-----------------------|- valloc_base (lower if >256GB)
469 471 * | segkpm |
470 472 * 0xFFFFFE00.00000000 |-----------------------|
471 473 * | Red Zone |
472 474 * 0xFFFFFD80.00000000 |-----------------------|- KERNELBASE (lower if >256GB)
473 475 * | User stack |- User space memory
474 476 * | |
475 477 * | shared objects, etc | (grows downwards)
476 478 * : :
477 479 * | |
478 480 * 0xFFFF8000.00000000 |-----------------------|
479 481 * | |
480 482 * | VA Hole / unused |
481 483 * | |
482 484 * 0x00008000.00000000 |-----------------------|
483 485 * | |
484 486 * | |
485 487 * : :
486 488 * | user heap | (grows upwards)
487 489 * | |
488 490 * | user data |
489 491 * |-----------------------|
490 492 * | user text |
491 493 * 0x00000000.04000000 |-----------------------|
492 494 * | invalid |
493 495 * 0x00000000.00000000 +-----------------------+
494 496 *
495 497 * A 32 bit app on the 64 bit kernel sees the same layout as on the 32 bit
496 498 * kernel, except that userlimit is raised to 0xfe000000
497 499 *
498 500 * Floating values:
499 501 *
500 502 * valloc_base: start of the kernel's memory management/tracking data
501 503 * structures. This region contains page_t structures for
502 504 * physical memory, memsegs, memlists, and the page hash.
503 505 *
504 506 * core_base: start of the kernel's "core" heap area on 64-bit systems.
505 507 * This area is intended to be used for global data as well as for module
506 508 * text/data that does not fit into the nucleus pages. The core heap is
507 509 * restricted to a 2GB range, allowing every address within it to be
508 510 * accessed using rip-relative addressing
509 511 *
510 512 * ekernelheap: end of kernelheap and start of segmap.
511 513 *
512 514 * kernelheap: start of kernel heap. On 32-bit systems, this starts right
513 515 * above a red zone that separates the user's address space from the
514 516 * kernel's. On 64-bit systems, it sits above segkp and segkpm.
515 517 *
516 518 * segmap_start: start of segmap. The length of segmap can be modified
517 519 * through eeprom. The default length is 16MB on 32-bit systems and 64MB
518 520 * on 64-bit systems.
519 521 *
520 522 * kernelbase: On a 32-bit kernel the default value of 0xd4000000 will be
521 523 * decreased by 2X the size required for page_t. This allows the kernel
522 524 * heap to grow in size with physical memory. With sizeof(page_t) == 80
523 525 * bytes, the following shows the values of kernelbase and kernel heap
524 526 * sizes for different memory configurations (assuming default segmap and
525 527 * segkp sizes).
526 528 *
527 529 * mem size for kernelbase kernel heap
528 530 * size page_t's size
529 531 * ---- --------- ---------- -----------
530 532 * 1gb 0x01400000 0xd1800000 684MB
531 533 * 2gb 0x02800000 0xcf000000 704MB
532 534 * 4gb 0x05000000 0xca000000 744MB
533 535 * 6gb 0x07800000 0xc5000000 784MB
534 536 * 8gb 0x0a000000 0xc0000000 824MB
535 537 * 16gb 0x14000000 0xac000000 984MB
536 538 * 32gb 0x28000000 0x84000000 1304MB
537 539 * 64gb 0x50000000 0x34000000 1944MB (*)
538 540 *
539 541 * kernelbase is less than the abi minimum of 0xc0000000 for memory
540 542 * configurations above 8gb.
541 543 *
542 544 * (*) support for memory configurations above 32gb will require manual tuning
543 545 * of kernelbase to balance out the need of user applications.
544 546 */
545 547
546 548 /* real-time-clock initialization parameters */
547 549 extern time_t process_rtc_config_file(void);
548 550
549 551 uintptr_t kernelbase;
550 552 uintptr_t postbootkernelbase; /* not set till boot loader is gone */
551 553 uintptr_t eprom_kernelbase;
552 554 size_t segmapsize;
553 555 uintptr_t segmap_start;
554 556 int segmapfreelists;
555 557 pgcnt_t npages;
556 558 pgcnt_t orig_npages;
557 559 size_t core_size; /* size of "core" heap */
558 560 uintptr_t core_base; /* base address of "core" heap */
559 561
560 562 /*
561 563 * List of bootstrap pages. We mark these as allocated in startup.
562 564 * release_bootstrap() will free them when we're completely done with
563 565 * the bootstrap.
564 566 */
565 567 static page_t *bootpages;
566 568
567 569 /*
568 570 * boot time pages that have a vnode from the ramdisk will keep that forever.
569 571 */
570 572 static page_t *rd_pages;
571 573
572 574 /*
573 575 * Lower 64K
574 576 */
575 577 static page_t *lower_pages = NULL;
576 578 static int lower_pages_count = 0;
577 579
578 580 struct system_hardware system_hardware;
579 581
580 582 /*
581 583 * Enable some debugging messages concerning memory usage...
582 584 */
583 585 static void
584 586 print_memlist(char *title, struct memlist *mp)
585 587 {
586 588 prom_printf("MEMLIST: %s:\n", title);
587 589 while (mp != NULL) {
588 590 prom_printf("\tAddress 0x%" PRIx64 ", size 0x%" PRIx64 "\n",
589 591 mp->ml_address, mp->ml_size);
590 592 mp = mp->ml_next;
591 593 }
592 594 }
593 595
594 596 /*
595 597 * XX64 need a comment here.. are these just default values, surely
596 598 * we read the "cpuid" type information to figure this out.
597 599 */
598 600 int l2cache_sz = 0x80000;
599 601 int l2cache_linesz = 0x40;
600 602 int l2cache_assoc = 1;
601 603
602 604 static size_t textrepl_min_gb = 10;
603 605
604 606 /*
605 607 * on 64 bit we use a predifined VA range for mapping devices in the kernel
606 608 * on 32 bit the mappings are intermixed in the heap, so we use a bit map
607 609 */
608 610 #ifdef __amd64
609 611
610 612 vmem_t *device_arena;
611 613 uintptr_t toxic_addr = (uintptr_t)NULL;
612 614 size_t toxic_size = 1024 * 1024 * 1024; /* Sparc uses 1 gig too */
613 615
614 616 #else /* __i386 */
615 617
616 618 ulong_t *toxic_bit_map; /* one bit for each 4k of VA in heap_arena */
617 619 size_t toxic_bit_map_len = 0; /* in bits */
618 620
619 621 #endif /* __i386 */
620 622
621 623 /*
622 624 * Simple boot time debug facilities
623 625 */
624 626 static char *prm_dbg_str[] = {
625 627 "%s:%d: '%s' is 0x%x\n",
626 628 "%s:%d: '%s' is 0x%llx\n"
627 629 };
628 630
629 631 int prom_debug;
630 632
631 633 #define PRM_DEBUG(q) if (prom_debug) \
632 634 prom_printf(prm_dbg_str[sizeof (q) >> 3], "startup.c", __LINE__, #q, q);
633 635 #define PRM_POINT(q) if (prom_debug) \
634 636 prom_printf("%s:%d: %s\n", "startup.c", __LINE__, q);
635 637
636 638 /*
637 639 * This structure is used to keep track of the intial allocations
638 640 * done in startup_memlist(). The value of NUM_ALLOCATIONS needs to
639 641 * be >= the number of ADD_TO_ALLOCATIONS() executed in the code.
640 642 */
641 643 #define NUM_ALLOCATIONS 8
642 644 int num_allocations = 0;
643 645 struct {
644 646 void **al_ptr;
645 647 size_t al_size;
646 648 } allocations[NUM_ALLOCATIONS];
647 649 size_t valloc_sz = 0;
648 650 uintptr_t valloc_base;
649 651
650 652 #define ADD_TO_ALLOCATIONS(ptr, size) { \
651 653 size = ROUND_UP_PAGE(size); \
652 654 if (num_allocations == NUM_ALLOCATIONS) \
653 655 panic("too many ADD_TO_ALLOCATIONS()"); \
654 656 allocations[num_allocations].al_ptr = (void**)&ptr; \
655 657 allocations[num_allocations].al_size = size; \
656 658 valloc_sz += size; \
657 659 ++num_allocations; \
658 660 }
659 661
660 662 /*
661 663 * Allocate all the initial memory needed by the page allocator.
662 664 */
663 665 static void
664 666 perform_allocations(void)
665 667 {
666 668 caddr_t mem;
667 669 int i;
668 670 int valloc_align;
669 671
670 672 PRM_DEBUG(valloc_base);
671 673 PRM_DEBUG(valloc_sz);
672 674 valloc_align = mmu.level_size[mmu.max_page_level > 0];
673 675 mem = BOP_ALLOC(bootops, (caddr_t)valloc_base, valloc_sz, valloc_align);
674 676 if (mem != (caddr_t)valloc_base)
675 677 panic("BOP_ALLOC() failed");
676 678 bzero(mem, valloc_sz);
677 679 for (i = 0; i < num_allocations; ++i) {
678 680 *allocations[i].al_ptr = (void *)mem;
679 681 mem += allocations[i].al_size;
680 682 }
681 683 }
682 684
683 685 /*
684 686 * Set up and enable SMAP now before we start other CPUs, but after the kernel's
685 687 * VM has been set up so we can use hot_patch_kernel_text().
686 688 *
687 689 * We can only patch 1, 2, or 4 bytes, but not three bytes. So instead, we
688 690 * replace the four byte word at the patch point. See uts/intel/ia32/ml/copy.s
689 691 * for more information on what's going on here.
690 692 */
691 693 static void
692 694 startup_smap(void)
693 695 {
694 696 int i;
695 697 uint32_t inst;
696 698 uint8_t *instp;
697 699 char sym[128];
698 700
699 701 extern int _smap_enable_patch_count;
700 702 extern int _smap_disable_patch_count;
701 703
702 704 if (disable_smap != 0)
703 705 remove_x86_feature(x86_featureset, X86FSET_SMAP);
704 706
705 707 if (is_x86_feature(x86_featureset, X86FSET_SMAP) == B_FALSE)
706 708 return;
707 709
708 710 for (i = 0; i < _smap_enable_patch_count; i++) {
709 711 int sizep;
710 712
711 713 VERIFY3U(i, <, _smap_enable_patch_count);
712 714 VERIFY(snprintf(sym, sizeof (sym), "_smap_enable_patch_%d", i) <
713 715 sizeof (sym));
714 716 instp = (uint8_t *)(void *)kobj_getelfsym(sym, NULL, &sizep);
715 717 VERIFY(instp != 0);
716 718 inst = (instp[3] << 24) | (SMAP_CLAC_INSTR & 0x00ffffff);
717 719 hot_patch_kernel_text((caddr_t)instp, inst, 4);
718 720 }
719 721
720 722 for (i = 0; i < _smap_disable_patch_count; i++) {
721 723 int sizep;
722 724
723 725 VERIFY(snprintf(sym, sizeof (sym), "_smap_disable_patch_%d",
724 726 i) < sizeof (sym));
725 727 instp = (uint8_t *)(void *)kobj_getelfsym(sym, NULL, &sizep);
726 728 VERIFY(instp != 0);
727 729 inst = (instp[3] << 24) | (SMAP_STAC_INSTR & 0x00ffffff);
728 730 hot_patch_kernel_text((caddr_t)instp, inst, 4);
729 731 }
730 732
731 733 hot_patch_kernel_text((caddr_t)smap_enable, SMAP_CLAC_INSTR, 4);
732 734 hot_patch_kernel_text((caddr_t)smap_disable, SMAP_STAC_INSTR, 4);
733 735 setcr4(getcr4() | CR4_SMAP);
734 736 smap_enable();
735 737 }
736 738
737 739 /*
738 740 * Our world looks like this at startup time.
739 741 *
740 742 * In a 32-bit OS, boot loads the kernel text at 0xfe800000 and kernel data
741 743 * at 0xfec00000. On a 64-bit OS, kernel text and data are loaded at
742 744 * 0xffffffff.fe800000 and 0xffffffff.fec00000 respectively. Those
743 745 * addresses are fixed in the binary at link time.
744 746 *
745 747 * On the text page:
746 748 * unix/genunix/krtld/module text loads.
747 749 *
748 750 * On the data page:
749 751 * unix/genunix/krtld/module data loads.
750 752 *
751 753 * Machine-dependent startup code
752 754 */
753 755 void
754 756 startup(void)
755 757 {
756 758 #if !defined(__xpv)
757 759 extern void startup_pci_bios(void);
758 760 #endif
759 761 extern cpuset_t cpu_ready_set;
760 762
761 763 /*
762 764 * Make sure that nobody tries to use sekpm until we have
763 765 * initialized it properly.
764 766 */
765 767 #if defined(__amd64)
766 768 kpm_desired = 1;
767 769 #endif
768 770 kpm_enable = 0;
769 771 CPUSET_ONLY(cpu_ready_set, 0); /* cpu 0 is boot cpu */
770 772
771 773 #if defined(__xpv) /* XXPV fix me! */
772 774 {
773 775 extern int segvn_use_regions;
774 776 segvn_use_regions = 0;
775 777 }
776 778 #endif
777 779 ssp_init();
778 780 progressbar_init();
779 781 startup_init();
780 782 #if defined(__xpv)
781 783 startup_xen_version();
782 784 #endif
783 785 startup_memlist();
784 786 startup_kmem();
785 787 startup_vm();
786 788 #if !defined(__xpv)
787 789 /*
788 790 * Note we need to do this even on fast reboot in order to access
789 791 * the irq routing table (used for pci labels).
790 792 */
791 793 startup_pci_bios();
792 794 startup_smap();
793 795 #endif
794 796 #if defined(__xpv)
795 797 startup_xen_mca();
796 798 #endif
797 799 startup_modules();
798 800
799 801 startup_end();
800 802 }
801 803
802 804 static void
803 805 startup_init()
804 806 {
805 807 PRM_POINT("startup_init() starting...");
806 808
807 809 /*
808 810 * Complete the extraction of cpuid data
809 811 */
810 812 cpuid_pass2(CPU);
811 813
812 814 (void) check_boot_version(BOP_GETVERSION(bootops));
813 815
814 816 /*
815 817 * Check for prom_debug in boot environment
816 818 */
817 819 if (BOP_GETPROPLEN(bootops, "prom_debug") >= 0) {
818 820 ++prom_debug;
819 821 PRM_POINT("prom_debug found in boot enviroment");
820 822 }
821 823
822 824 /*
823 825 * Collect node, cpu and memory configuration information.
824 826 */
825 827 get_system_configuration();
826 828
827 829 /*
828 830 * Halt if this is an unsupported processor.
829 831 */
830 832 if (x86_type == X86_TYPE_486 || x86_type == X86_TYPE_CYRIX_486) {
831 833 printf("\n486 processor (\"%s\") detected.\n",
832 834 CPU->cpu_brandstr);
833 835 halt("This processor is not supported by this release "
834 836 "of Solaris.");
835 837 }
836 838
837 839 PRM_POINT("startup_init() done");
838 840 }
839 841
840 842 /*
841 843 * Callback for copy_memlist_filter() to filter nucleus, kadb/kmdb, (ie.
842 844 * everything mapped above KERNEL_TEXT) pages from phys_avail. Note it
843 845 * also filters out physical page zero. There is some reliance on the
844 846 * boot loader allocating only a few contiguous physical memory chunks.
845 847 */
846 848 static void
847 849 avail_filter(uint64_t *addr, uint64_t *size)
848 850 {
849 851 uintptr_t va;
850 852 uintptr_t next_va;
851 853 pfn_t pfn;
852 854 uint64_t pfn_addr;
853 855 uint64_t pfn_eaddr;
854 856 uint_t prot;
855 857 size_t len;
856 858 uint_t change;
857 859
858 860 if (prom_debug)
859 861 prom_printf("\tFilter: in: a=%" PRIx64 ", s=%" PRIx64 "\n",
860 862 *addr, *size);
861 863
862 864 /*
863 865 * page zero is required for BIOS.. never make it available
864 866 */
865 867 if (*addr == 0) {
866 868 *addr += MMU_PAGESIZE;
867 869 *size -= MMU_PAGESIZE;
868 870 }
869 871
870 872 /*
871 873 * First we trim from the front of the range. Since kbm_probe()
872 874 * walks ranges in virtual order, but addr/size are physical, we need
873 875 * to the list until no changes are seen. This deals with the case
874 876 * where page "p" is mapped at v, page "p + PAGESIZE" is mapped at w
875 877 * but w < v.
876 878 */
877 879 do {
878 880 change = 0;
879 881 for (va = KERNEL_TEXT;
880 882 *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
881 883 va = next_va) {
882 884
883 885 next_va = va + len;
884 886 pfn_addr = pfn_to_pa(pfn);
885 887 pfn_eaddr = pfn_addr + len;
886 888
887 889 if (pfn_addr <= *addr && pfn_eaddr > *addr) {
888 890 change = 1;
889 891 while (*size > 0 && len > 0) {
890 892 *addr += MMU_PAGESIZE;
891 893 *size -= MMU_PAGESIZE;
892 894 len -= MMU_PAGESIZE;
893 895 }
894 896 }
895 897 }
896 898 if (change && prom_debug)
897 899 prom_printf("\t\ttrim: a=%" PRIx64 ", s=%" PRIx64 "\n",
898 900 *addr, *size);
899 901 } while (change);
900 902
901 903 /*
902 904 * Trim pages from the end of the range.
903 905 */
904 906 for (va = KERNEL_TEXT;
905 907 *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
906 908 va = next_va) {
907 909
908 910 next_va = va + len;
909 911 pfn_addr = pfn_to_pa(pfn);
910 912
911 913 if (pfn_addr >= *addr && pfn_addr < *addr + *size)
912 914 *size = pfn_addr - *addr;
913 915 }
914 916
915 917 if (prom_debug)
916 918 prom_printf("\tFilter out: a=%" PRIx64 ", s=%" PRIx64 "\n",
917 919 *addr, *size);
918 920 }
919 921
920 922 static void
921 923 kpm_init()
922 924 {
923 925 struct segkpm_crargs b;
924 926
925 927 /*
926 928 * These variables were all designed for sfmmu in which segkpm is
927 929 * mapped using a single pagesize - either 8KB or 4MB. On x86, we
928 930 * might use 2+ page sizes on a single machine, so none of these
929 931 * variables have a single correct value. They are set up as if we
930 932 * always use a 4KB pagesize, which should do no harm. In the long
931 933 * run, we should get rid of KPM's assumption that only a single
932 934 * pagesize is used.
933 935 */
934 936 kpm_pgshft = MMU_PAGESHIFT;
935 937 kpm_pgsz = MMU_PAGESIZE;
936 938 kpm_pgoff = MMU_PAGEOFFSET;
937 939 kpmp2pshft = 0;
938 940 kpmpnpgs = 1;
939 941 ASSERT(((uintptr_t)kpm_vbase & (kpm_pgsz - 1)) == 0);
940 942
941 943 PRM_POINT("about to create segkpm");
942 944 rw_enter(&kas.a_lock, RW_WRITER);
943 945
↓ open down ↓ |
483 lines elided |
↑ open up ↑ |
944 946 if (seg_attach(&kas, kpm_vbase, kpm_size, segkpm) < 0)
945 947 panic("cannot attach segkpm");
946 948
947 949 b.prot = PROT_READ | PROT_WRITE;
948 950 b.nvcolors = 1;
949 951
950 952 if (segkpm_create(segkpm, (caddr_t)&b) != 0)
951 953 panic("segkpm_create segkpm");
952 954
953 955 rw_exit(&kas.a_lock);
956 +
957 + kpm_enable = 1;
958 +
959 + /*
960 + * As the KPM was disabled while setting up the system, go back and fix
961 + * CPU zero's access to its user page table. This is a bit gross, but
962 + * we have a chicken and egg problem otherwise.
963 + */
964 + ASSERT(CPU->cpu_hat_info->hci_user_l3ptes == NULL);
965 + CPU->cpu_hat_info->hci_user_l3ptes =
966 + (x86pte_t *)hat_kpm_mapin_pfn(CPU->cpu_hat_info->hci_user_l3pfn);
954 967 }
955 968
956 969 /*
957 970 * The debug info page provides enough information to allow external
958 971 * inspectors (e.g. when running under a hypervisor) to bootstrap
959 972 * themselves into allowing full-blown kernel debugging.
960 973 */
961 974 static void
962 975 init_debug_info(void)
963 976 {
964 977 caddr_t mem;
965 978 debug_info_t *di;
966 979
967 980 #ifndef __lint
968 981 ASSERT(sizeof (debug_info_t) < MMU_PAGESIZE);
969 982 #endif
970 983
971 984 mem = BOP_ALLOC(bootops, (caddr_t)DEBUG_INFO_VA, MMU_PAGESIZE,
972 985 MMU_PAGESIZE);
973 986
974 987 if (mem != (caddr_t)DEBUG_INFO_VA)
975 988 panic("BOP_ALLOC() failed");
976 989 bzero(mem, MMU_PAGESIZE);
977 990
978 991 di = (debug_info_t *)mem;
979 992
980 993 di->di_magic = DEBUG_INFO_MAGIC;
981 994 di->di_version = DEBUG_INFO_VERSION;
982 995 di->di_modules = (uintptr_t)&modules;
983 996 di->di_s_text = (uintptr_t)s_text;
984 997 di->di_e_text = (uintptr_t)e_text;
985 998 di->di_s_data = (uintptr_t)s_data;
986 999 di->di_e_data = (uintptr_t)e_data;
987 1000 di->di_hat_htable_off = offsetof(hat_t, hat_htable);
988 1001 di->di_ht_pfn_off = offsetof(htable_t, ht_pfn);
989 1002 }
990 1003
991 1004 /*
992 1005 * Build the memlists and other kernel essential memory system data structures.
993 1006 * This is everything at valloc_base.
994 1007 */
995 1008 static void
996 1009 startup_memlist(void)
997 1010 {
998 1011 size_t memlist_sz;
999 1012 size_t memseg_sz;
1000 1013 size_t pagehash_sz;
1001 1014 size_t pp_sz;
1002 1015 uintptr_t va;
1003 1016 size_t len;
1004 1017 uint_t prot;
1005 1018 pfn_t pfn;
1006 1019 int memblocks;
1007 1020 pfn_t rsvd_high_pfn;
1008 1021 pgcnt_t rsvd_pgcnt;
1009 1022 size_t rsvdmemlist_sz;
1010 1023 int rsvdmemblocks;
1011 1024 caddr_t pagecolor_mem;
1012 1025 size_t pagecolor_memsz;
1013 1026 caddr_t page_ctrs_mem;
1014 1027 size_t page_ctrs_size;
1015 1028 size_t pse_table_alloc_size;
1016 1029 struct memlist *current;
1017 1030 extern void startup_build_mem_nodes(struct memlist *);
1018 1031
1019 1032 /* XX64 fix these - they should be in include files */
1020 1033 extern size_t page_coloring_init(uint_t, int, int);
1021 1034 extern void page_coloring_setup(caddr_t);
1022 1035
1023 1036 PRM_POINT("startup_memlist() starting...");
1024 1037
1025 1038 /*
1026 1039 * Use leftover large page nucleus text/data space for loadable modules.
1027 1040 * Use at most MODTEXT/MODDATA.
1028 1041 */
1029 1042 len = kbm_nucleus_size;
1030 1043 ASSERT(len > MMU_PAGESIZE);
1031 1044
1032 1045 moddata = (caddr_t)ROUND_UP_PAGE(e_data);
1033 1046 e_moddata = (caddr_t)P2ROUNDUP((uintptr_t)e_data, (uintptr_t)len);
1034 1047 if (e_moddata - moddata > MODDATA)
1035 1048 e_moddata = moddata + MODDATA;
1036 1049
1037 1050 modtext = (caddr_t)ROUND_UP_PAGE(e_text);
1038 1051 e_modtext = (caddr_t)P2ROUNDUP((uintptr_t)e_text, (uintptr_t)len);
1039 1052 if (e_modtext - modtext > MODTEXT)
1040 1053 e_modtext = modtext + MODTEXT;
1041 1054
1042 1055 econtig = e_moddata;
1043 1056
1044 1057 PRM_DEBUG(modtext);
1045 1058 PRM_DEBUG(e_modtext);
1046 1059 PRM_DEBUG(moddata);
1047 1060 PRM_DEBUG(e_moddata);
1048 1061 PRM_DEBUG(econtig);
1049 1062
1050 1063 /*
1051 1064 * Examine the boot loader physical memory map to find out:
1052 1065 * - total memory in system - physinstalled
1053 1066 * - the max physical address - physmax
1054 1067 * - the number of discontiguous segments of memory.
1055 1068 */
1056 1069 if (prom_debug)
1057 1070 print_memlist("boot physinstalled",
1058 1071 bootops->boot_mem->physinstalled);
1059 1072 installed_top_size_ex(bootops->boot_mem->physinstalled, &physmax,
1060 1073 &physinstalled, &memblocks);
1061 1074 PRM_DEBUG(physmax);
1062 1075 PRM_DEBUG(physinstalled);
1063 1076 PRM_DEBUG(memblocks);
1064 1077
1065 1078 /*
1066 1079 * Compute maximum physical address for memory DR operations.
1067 1080 * Memory DR operations are unsupported on xpv or 32bit OSes.
1068 1081 */
1069 1082 #ifdef __amd64
1070 1083 if (plat_dr_support_memory()) {
1071 1084 if (plat_dr_physmax == 0) {
1072 1085 uint_t pabits = UINT_MAX;
1073 1086
1074 1087 cpuid_get_addrsize(CPU, &pabits, NULL);
1075 1088 plat_dr_physmax = btop(1ULL << pabits);
1076 1089 }
1077 1090 if (plat_dr_physmax > PHYSMEM_MAX64)
1078 1091 plat_dr_physmax = PHYSMEM_MAX64;
1079 1092 } else
1080 1093 #endif
1081 1094 plat_dr_physmax = 0;
1082 1095
1083 1096 /*
1084 1097 * Examine the bios reserved memory to find out:
1085 1098 * - the number of discontiguous segments of memory.
1086 1099 */
1087 1100 if (prom_debug)
1088 1101 print_memlist("boot reserved mem",
1089 1102 bootops->boot_mem->rsvdmem);
1090 1103 installed_top_size_ex(bootops->boot_mem->rsvdmem, &rsvd_high_pfn,
1091 1104 &rsvd_pgcnt, &rsvdmemblocks);
1092 1105 PRM_DEBUG(rsvd_high_pfn);
1093 1106 PRM_DEBUG(rsvd_pgcnt);
1094 1107 PRM_DEBUG(rsvdmemblocks);
1095 1108
1096 1109 /*
1097 1110 * Initialize hat's mmu parameters.
1098 1111 * Check for enforce-prot-exec in boot environment. It's used to
1099 1112 * enable/disable support for the page table entry NX bit.
1100 1113 * The default is to enforce PROT_EXEC on processors that support NX.
1101 1114 * Boot seems to round up the "len", but 8 seems to be big enough.
1102 1115 */
1103 1116 mmu_init();
1104 1117
1105 1118 #ifdef __i386
1106 1119 /*
1107 1120 * physmax is lowered if there is more memory than can be
1108 1121 * physically addressed in 32 bit (PAE/non-PAE) modes.
1109 1122 */
1110 1123 if (mmu.pae_hat) {
1111 1124 if (PFN_ABOVE64G(physmax)) {
1112 1125 physinstalled -= (physmax - (PFN_64G - 1));
1113 1126 physmax = PFN_64G - 1;
1114 1127 }
1115 1128 } else {
1116 1129 if (PFN_ABOVE4G(physmax)) {
1117 1130 physinstalled -= (physmax - (PFN_4G - 1));
1118 1131 physmax = PFN_4G - 1;
1119 1132 }
1120 1133 }
1121 1134 #endif
1122 1135
1123 1136 startup_build_mem_nodes(bootops->boot_mem->physinstalled);
1124 1137
1125 1138 if (BOP_GETPROPLEN(bootops, "enforce-prot-exec") >= 0) {
1126 1139 int len = BOP_GETPROPLEN(bootops, "enforce-prot-exec");
1127 1140 char value[8];
1128 1141
1129 1142 if (len < 8)
1130 1143 (void) BOP_GETPROP(bootops, "enforce-prot-exec", value);
1131 1144 else
1132 1145 (void) strcpy(value, "");
1133 1146 if (strcmp(value, "off") == 0)
1134 1147 mmu.pt_nx = 0;
1135 1148 }
1136 1149 PRM_DEBUG(mmu.pt_nx);
1137 1150
1138 1151 /*
1139 1152 * We will need page_t's for every page in the system, except for
1140 1153 * memory mapped at or above above the start of the kernel text segment.
1141 1154 *
1142 1155 * pages above e_modtext are attributed to kernel debugger (obp_pages)
1143 1156 */
1144 1157 npages = physinstalled - 1; /* avail_filter() skips page 0, so "- 1" */
1145 1158 obp_pages = 0;
1146 1159 va = KERNEL_TEXT;
1147 1160 while (kbm_probe(&va, &len, &pfn, &prot) != 0) {
1148 1161 npages -= len >> MMU_PAGESHIFT;
1149 1162 if (va >= (uintptr_t)e_moddata)
1150 1163 obp_pages += len >> MMU_PAGESHIFT;
1151 1164 va += len;
1152 1165 }
1153 1166 PRM_DEBUG(npages);
1154 1167 PRM_DEBUG(obp_pages);
1155 1168
1156 1169 /*
1157 1170 * If physmem is patched to be non-zero, use it instead of the computed
1158 1171 * value unless it is larger than the actual amount of memory on hand.
1159 1172 */
1160 1173 if (physmem == 0 || physmem > npages) {
1161 1174 physmem = npages;
1162 1175 } else if (physmem < npages) {
1163 1176 orig_npages = npages;
1164 1177 npages = physmem;
1165 1178 }
1166 1179 PRM_DEBUG(physmem);
1167 1180
1168 1181 /*
1169 1182 * We now compute the sizes of all the initial allocations for
1170 1183 * structures the kernel needs in order do kmem_alloc(). These
1171 1184 * include:
1172 1185 * memsegs
1173 1186 * memlists
1174 1187 * page hash table
1175 1188 * page_t's
1176 1189 * page coloring data structs
1177 1190 */
1178 1191 memseg_sz = sizeof (struct memseg) * (memblocks + POSS_NEW_FRAGMENTS);
1179 1192 ADD_TO_ALLOCATIONS(memseg_base, memseg_sz);
1180 1193 PRM_DEBUG(memseg_sz);
1181 1194
1182 1195 /*
1183 1196 * Reserve space for memlists. There's no real good way to know exactly
1184 1197 * how much room we'll need, but this should be a good upper bound.
1185 1198 */
1186 1199 memlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
1187 1200 (memblocks + POSS_NEW_FRAGMENTS));
1188 1201 ADD_TO_ALLOCATIONS(memlist, memlist_sz);
1189 1202 PRM_DEBUG(memlist_sz);
1190 1203
1191 1204 /*
1192 1205 * Reserve space for bios reserved memlists.
1193 1206 */
1194 1207 rsvdmemlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
1195 1208 (rsvdmemblocks + POSS_NEW_FRAGMENTS));
1196 1209 ADD_TO_ALLOCATIONS(bios_rsvd, rsvdmemlist_sz);
1197 1210 PRM_DEBUG(rsvdmemlist_sz);
1198 1211
1199 1212 /* LINTED */
1200 1213 ASSERT(P2SAMEHIGHBIT((1 << PP_SHIFT), sizeof (struct page)));
1201 1214 /*
1202 1215 * The page structure hash table size is a power of 2
1203 1216 * such that the average hash chain length is PAGE_HASHAVELEN.
1204 1217 */
1205 1218 page_hashsz = npages / PAGE_HASHAVELEN;
1206 1219 page_hashsz_shift = highbit(page_hashsz);
1207 1220 page_hashsz = 1 << page_hashsz_shift;
1208 1221 pagehash_sz = sizeof (struct page *) * page_hashsz;
1209 1222 ADD_TO_ALLOCATIONS(page_hash, pagehash_sz);
1210 1223 PRM_DEBUG(pagehash_sz);
1211 1224
1212 1225 /*
1213 1226 * Set aside room for the page structures themselves.
1214 1227 */
1215 1228 PRM_DEBUG(npages);
1216 1229 pp_sz = sizeof (struct page) * npages;
1217 1230 ADD_TO_ALLOCATIONS(pp_base, pp_sz);
1218 1231 PRM_DEBUG(pp_sz);
1219 1232
1220 1233 /*
1221 1234 * determine l2 cache info and memory size for page coloring
1222 1235 */
1223 1236 (void) getl2cacheinfo(CPU,
1224 1237 &l2cache_sz, &l2cache_linesz, &l2cache_assoc);
1225 1238 pagecolor_memsz =
1226 1239 page_coloring_init(l2cache_sz, l2cache_linesz, l2cache_assoc);
1227 1240 ADD_TO_ALLOCATIONS(pagecolor_mem, pagecolor_memsz);
1228 1241 PRM_DEBUG(pagecolor_memsz);
1229 1242
1230 1243 page_ctrs_size = page_ctrs_sz();
1231 1244 ADD_TO_ALLOCATIONS(page_ctrs_mem, page_ctrs_size);
1232 1245 PRM_DEBUG(page_ctrs_size);
1233 1246
1234 1247 /*
1235 1248 * Allocate the array that protects pp->p_selock.
1236 1249 */
1237 1250 pse_shift = size_pse_array(physmem, max_ncpus);
1238 1251 pse_table_size = 1 << pse_shift;
1239 1252 pse_table_alloc_size = pse_table_size * sizeof (pad_mutex_t);
1240 1253 ADD_TO_ALLOCATIONS(pse_mutex, pse_table_alloc_size);
1241 1254
1242 1255 #if defined(__amd64)
1243 1256 valloc_sz = ROUND_UP_LPAGE(valloc_sz);
1244 1257 valloc_base = VALLOC_BASE;
1245 1258
1246 1259 /*
1247 1260 * The default values of VALLOC_BASE and SEGKPM_BASE should work
1248 1261 * for values of physmax up to 256GB (1/4 TB). They need adjusting when
1249 1262 * memory is at addresses above 256GB. When adjusted, segkpm_base must
1250 1263 * be aligned on KERNEL_REDZONE_SIZE boundary (span of top level pte).
1251 1264 *
1252 1265 * In the general case (>256GB), we use (4 * physmem) for the
1253 1266 * kernel's virtual addresses, which is divided approximately
1254 1267 * as follows:
1255 1268 * - 1 * physmem for segkpm
1256 1269 * - 1.5 * physmem for segzio
1257 1270 * - 1.5 * physmem for heap
1258 1271 * Total: 4.0 * physmem
1259 1272 *
1260 1273 * Note that the segzio and heap sizes are more than physmem so that
1261 1274 * VA fragmentation does not prevent either of them from being
1262 1275 * able to use nearly all of physmem. The value of 1.5x is determined
1263 1276 * experimentally and may need to change if the workload changes.
1264 1277 */
1265 1278 if (physmax + 1 > mmu_btop(TERABYTE / 4) ||
1266 1279 plat_dr_physmax > mmu_btop(TERABYTE / 4)) {
1267 1280 uint64_t kpm_resv_amount = mmu_ptob(physmax + 1);
1268 1281
1269 1282 if (kpm_resv_amount < mmu_ptob(plat_dr_physmax)) {
1270 1283 kpm_resv_amount = mmu_ptob(plat_dr_physmax);
1271 1284 }
1272 1285
1273 1286 /*
1274 1287 * This is what actually controls the KVA : UVA split.
1275 1288 * The kernel uses high VA, and this is lowering the
1276 1289 * boundary, thus increasing the amount of VA for the kernel.
1277 1290 * This gives the kernel 4 * (amount of physical memory) VA.
1278 1291 *
1279 1292 * The maximum VA is UINT64_MAX and we are using
1280 1293 * 64-bit 2's complement math, so e.g. if you have 512GB
1281 1294 * of memory, segkpm_base = -(4 * 512GB) == -2TB ==
1282 1295 * UINT64_MAX - 2TB (approximately). So the kernel's
1283 1296 * VA is [UINT64_MAX-2TB to UINT64_MAX].
1284 1297 */
1285 1298 segkpm_base = -(P2ROUNDUP((4 * kpm_resv_amount),
1286 1299 KERNEL_REDZONE_SIZE));
1287 1300
1288 1301 /* make sure we leave some space for user apps above hole */
1289 1302 segkpm_base = MAX(segkpm_base, AMD64_VA_HOLE_END + TERABYTE);
1290 1303 if (segkpm_base > SEGKPM_BASE)
1291 1304 segkpm_base = SEGKPM_BASE;
1292 1305 PRM_DEBUG(segkpm_base);
1293 1306
1294 1307 valloc_base = segkpm_base + P2ROUNDUP(kpm_resv_amount, ONE_GIG);
1295 1308 if (valloc_base < segkpm_base)
1296 1309 panic("not enough kernel VA to support memory size");
1297 1310 PRM_DEBUG(valloc_base);
1298 1311 }
1299 1312 #else /* __i386 */
1300 1313 valloc_base = (uintptr_t)(MISC_VA_BASE - valloc_sz);
1301 1314 valloc_base = P2ALIGN(valloc_base, mmu.level_size[1]);
1302 1315 PRM_DEBUG(valloc_base);
1303 1316 #endif /* __i386 */
1304 1317
1305 1318 /*
1306 1319 * do all the initial allocations
1307 1320 */
1308 1321 perform_allocations();
1309 1322
1310 1323 /*
1311 1324 * Build phys_install and phys_avail in kernel memspace.
1312 1325 * - phys_install should be all memory in the system.
1313 1326 * - phys_avail is phys_install minus any memory mapped before this
1314 1327 * point above KERNEL_TEXT.
1315 1328 */
1316 1329 current = phys_install = memlist;
1317 1330 copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t, NULL);
1318 1331 if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
1319 1332 panic("physinstalled was too big!");
1320 1333 if (prom_debug)
1321 1334 print_memlist("phys_install", phys_install);
1322 1335
1323 1336 phys_avail = current;
1324 1337 PRM_POINT("Building phys_avail:\n");
1325 1338 copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t,
1326 1339 avail_filter);
1327 1340 if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
1328 1341 panic("physavail was too big!");
1329 1342 if (prom_debug)
1330 1343 print_memlist("phys_avail", phys_avail);
1331 1344 #ifndef __xpv
1332 1345 /*
1333 1346 * Free unused memlist items, which may be used by memory DR driver
1334 1347 * at runtime.
1335 1348 */
1336 1349 if ((caddr_t)current < (caddr_t)memlist + memlist_sz) {
1337 1350 memlist_free_block((caddr_t)current,
1338 1351 (caddr_t)memlist + memlist_sz - (caddr_t)current);
1339 1352 }
1340 1353 #endif
1341 1354
1342 1355 /*
1343 1356 * Build bios reserved memspace
1344 1357 */
1345 1358 current = bios_rsvd;
1346 1359 copy_memlist_filter(bootops->boot_mem->rsvdmem, ¤t, NULL);
1347 1360 if ((caddr_t)current > (caddr_t)bios_rsvd + rsvdmemlist_sz)
1348 1361 panic("bios_rsvd was too big!");
1349 1362 if (prom_debug)
1350 1363 print_memlist("bios_rsvd", bios_rsvd);
1351 1364 #ifndef __xpv
1352 1365 /*
1353 1366 * Free unused memlist items, which may be used by memory DR driver
1354 1367 * at runtime.
1355 1368 */
1356 1369 if ((caddr_t)current < (caddr_t)bios_rsvd + rsvdmemlist_sz) {
1357 1370 memlist_free_block((caddr_t)current,
1358 1371 (caddr_t)bios_rsvd + rsvdmemlist_sz - (caddr_t)current);
1359 1372 }
1360 1373 #endif
1361 1374
1362 1375 /*
1363 1376 * setup page coloring
1364 1377 */
1365 1378 page_coloring_setup(pagecolor_mem);
1366 1379 page_lock_init(); /* currently a no-op */
1367 1380
1368 1381 /*
1369 1382 * free page list counters
1370 1383 */
1371 1384 (void) page_ctrs_alloc(page_ctrs_mem);
1372 1385
1373 1386 /*
1374 1387 * Size the pcf array based on the number of cpus in the box at
1375 1388 * boot time.
1376 1389 */
1377 1390
1378 1391 pcf_init();
1379 1392
1380 1393 /*
1381 1394 * Initialize the page structures from the memory lists.
1382 1395 */
1383 1396 availrmem_initial = availrmem = freemem = 0;
1384 1397 PRM_POINT("Calling kphysm_init()...");
1385 1398 npages = kphysm_init(pp_base, npages);
1386 1399 PRM_POINT("kphysm_init() done");
1387 1400 PRM_DEBUG(npages);
1388 1401
1389 1402 init_debug_info();
1390 1403
1391 1404 /*
1392 1405 * Now that page_t's have been initialized, remove all the
1393 1406 * initial allocation pages from the kernel free page lists.
1394 1407 */
1395 1408 boot_mapin((caddr_t)valloc_base, valloc_sz);
1396 1409 boot_mapin((caddr_t)MISC_VA_BASE, MISC_VA_SIZE);
1397 1410 PRM_POINT("startup_memlist() done");
1398 1411
1399 1412 PRM_DEBUG(valloc_sz);
1400 1413
1401 1414 #if defined(__amd64)
1402 1415 if ((availrmem >> (30 - MMU_PAGESHIFT)) >=
1403 1416 textrepl_min_gb && l2cache_sz <= 2 << 20) {
1404 1417 extern size_t textrepl_size_thresh;
1405 1418 textrepl_size_thresh = (16 << 20) - 1;
1406 1419 }
↓ open down ↓ |
443 lines elided |
↑ open up ↑ |
1407 1420 #endif
1408 1421 }
1409 1422
1410 1423 /*
1411 1424 * Layout the kernel's part of address space and initialize kmem allocator.
1412 1425 */
1413 1426 static void
1414 1427 startup_kmem(void)
1415 1428 {
1416 1429 extern void page_set_colorequiv_arr(void);
1430 +#if !defined(__xpv)
1431 + extern uint64_t kpti_kbase;
1432 +#endif
1417 1433
1418 1434 PRM_POINT("startup_kmem() starting...");
1419 1435
1420 1436 #if defined(__amd64)
1421 1437 if (eprom_kernelbase && eprom_kernelbase != KERNELBASE)
1422 1438 cmn_err(CE_NOTE, "!kernelbase cannot be changed on 64-bit "
1423 1439 "systems.");
1424 1440 kernelbase = segkpm_base - KERNEL_REDZONE_SIZE;
1425 1441 core_base = (uintptr_t)COREHEAP_BASE;
1426 1442 core_size = (size_t)MISC_VA_BASE - COREHEAP_BASE;
1427 1443 #else /* __i386 */
1428 1444 /*
1429 1445 * We configure kernelbase based on:
1430 1446 *
1431 1447 * 1. user specified kernelbase via eeprom command. Value cannot exceed
1432 1448 * KERNELBASE_MAX. we large page align eprom_kernelbase
1433 1449 *
1434 1450 * 2. Default to KERNELBASE and adjust to 2X less the size for page_t.
1435 1451 * On large memory systems we must lower kernelbase to allow
1436 1452 * enough room for page_t's for all of memory.
1437 1453 *
1438 1454 * The value set here, might be changed a little later.
1439 1455 */
1440 1456 if (eprom_kernelbase) {
1441 1457 kernelbase = eprom_kernelbase & mmu.level_mask[1];
1442 1458 if (kernelbase > KERNELBASE_MAX)
1443 1459 kernelbase = KERNELBASE_MAX;
1444 1460 } else {
1445 1461 kernelbase = (uintptr_t)KERNELBASE;
1446 1462 kernelbase -= ROUND_UP_4MEG(2 * valloc_sz);
1447 1463 }
1448 1464 ASSERT((kernelbase & mmu.level_offset[1]) == 0);
1449 1465 core_base = valloc_base;
1450 1466 core_size = 0;
1451 1467 #endif /* __i386 */
1452 1468
1453 1469 PRM_DEBUG(core_base);
1454 1470 PRM_DEBUG(core_size);
1455 1471 PRM_DEBUG(kernelbase);
1456 1472
1457 1473 #if defined(__i386)
1458 1474 segkp_fromheap = 1;
1459 1475 #endif /* __i386 */
1460 1476
1461 1477 ekernelheap = (char *)core_base;
1462 1478 PRM_DEBUG(ekernelheap);
1463 1479
1464 1480 /*
1465 1481 * Now that we know the real value of kernelbase,
1466 1482 * update variables that were initialized with a value of
1467 1483 * KERNELBASE (in common/conf/param.c).
1468 1484 *
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
1469 1485 * XXX The problem with this sort of hackery is that the
1470 1486 * compiler just may feel like putting the const declarations
1471 1487 * (in param.c) into the .text section. Perhaps they should
1472 1488 * just be declared as variables there?
1473 1489 */
1474 1490
1475 1491 *(uintptr_t *)&_kernelbase = kernelbase;
1476 1492 *(uintptr_t *)&_userlimit = kernelbase;
1477 1493 #if defined(__amd64)
1478 1494 *(uintptr_t *)&_userlimit -= KERNELBASE - USERLIMIT;
1495 +#if !defined(__xpv)
1496 + kpti_kbase = kernelbase;
1497 +#endif
1479 1498 #else
1480 1499 *(uintptr_t *)&_userlimit32 = _userlimit;
1481 1500 #endif
1482 1501 PRM_DEBUG(_kernelbase);
1483 1502 PRM_DEBUG(_userlimit);
1484 1503 PRM_DEBUG(_userlimit32);
1485 1504
1505 + /* We have to re-do this now that we've modified _userlimit. */
1506 + mmu_calc_user_slots();
1507 +
1486 1508 layout_kernel_va();
1487 1509
1488 1510 #if defined(__i386)
1489 1511 /*
1490 1512 * If segmap is too large we can push the bottom of the kernel heap
1491 1513 * higher than the base. Or worse, it could exceed the top of the
1492 1514 * VA space entirely, causing it to wrap around.
1493 1515 */
1494 1516 if (kernelheap >= ekernelheap || (uintptr_t)kernelheap < kernelbase)
1495 1517 panic("too little address space available for kernelheap,"
1496 1518 " use eeprom for lower kernelbase or smaller segmapsize");
1497 1519 #endif /* __i386 */
1498 1520
1499 1521 /*
1500 1522 * Initialize the kernel heap. Note 3rd argument must be > 1st.
1501 1523 */
1502 1524 kernelheap_init(kernelheap, ekernelheap,
1503 1525 kernelheap + MMU_PAGESIZE,
1504 1526 (void *)core_base, (void *)(core_base + core_size));
1505 1527
1506 1528 #if defined(__xpv)
1507 1529 /*
1508 1530 * Link pending events struct into cpu struct
1509 1531 */
1510 1532 CPU->cpu_m.mcpu_evt_pend = &cpu0_evt_data;
1511 1533 #endif
1512 1534 /*
1513 1535 * Initialize kernel memory allocator.
1514 1536 */
1515 1537 kmem_init();
1516 1538
1517 1539 /*
1518 1540 * Factor in colorequiv to check additional 'equivalent' bins
1519 1541 */
1520 1542 page_set_colorequiv_arr();
1521 1543
1522 1544 /*
1523 1545 * print this out early so that we know what's going on
1524 1546 */
1525 1547 print_x86_featureset(x86_featureset);
1526 1548
1527 1549 /*
1528 1550 * Initialize bp_mapin().
1529 1551 */
1530 1552 bp_init(MMU_PAGESIZE, HAT_STORECACHING_OK);
1531 1553
1532 1554 /*
1533 1555 * orig_npages is non-zero if physmem has been configured for less
1534 1556 * than the available memory.
1535 1557 */
1536 1558 if (orig_npages) {
1537 1559 cmn_err(CE_WARN, "!%slimiting physmem to 0x%lx of 0x%lx pages",
1538 1560 (npages == PHYSMEM ? "Due to virtual address space " : ""),
1539 1561 npages, orig_npages);
1540 1562 }
1541 1563 #if defined(__i386)
1542 1564 if (eprom_kernelbase && (eprom_kernelbase != kernelbase))
1543 1565 cmn_err(CE_WARN, "kernelbase value, User specified 0x%lx, "
1544 1566 "System using 0x%lx",
1545 1567 (uintptr_t)eprom_kernelbase, (uintptr_t)kernelbase);
1546 1568 #endif
1547 1569
1548 1570 #ifdef KERNELBASE_ABI_MIN
1549 1571 if (kernelbase < (uintptr_t)KERNELBASE_ABI_MIN) {
1550 1572 cmn_err(CE_NOTE, "!kernelbase set to 0x%lx, system is not "
1551 1573 "i386 ABI compliant.", (uintptr_t)kernelbase);
1552 1574 }
1553 1575 #endif
1554 1576
1555 1577 #ifndef __xpv
1556 1578 if (plat_dr_support_memory()) {
1557 1579 mem_config_init();
1558 1580 }
1559 1581 #else /* __xpv */
1560 1582 /*
1561 1583 * Some of the xen start information has to be relocated up
1562 1584 * into the kernel's permanent address space.
1563 1585 */
1564 1586 PRM_POINT("calling xen_relocate_start_info()");
1565 1587 xen_relocate_start_info();
1566 1588 PRM_POINT("xen_relocate_start_info() done");
1567 1589
1568 1590 /*
1569 1591 * (Update the vcpu pointer in our cpu structure to point into
1570 1592 * the relocated shared info.)
1571 1593 */
1572 1594 CPU->cpu_m.mcpu_vcpu_info =
1573 1595 &HYPERVISOR_shared_info->vcpu_info[CPU->cpu_id];
1574 1596 #endif /* __xpv */
1575 1597
1576 1598 PRM_POINT("startup_kmem() done");
1577 1599 }
1578 1600
1579 1601 #ifndef __xpv
1580 1602 /*
1581 1603 * If we have detected that we are running in an HVM environment, we need
1582 1604 * to prepend the PV driver directory to the module search path.
1583 1605 */
1584 1606 #define HVM_MOD_DIR "/platform/i86hvm/kernel"
1585 1607 static void
1586 1608 update_default_path()
1587 1609 {
1588 1610 char *current, *newpath;
1589 1611 int newlen;
1590 1612
1591 1613 /*
1592 1614 * We are about to resync with krtld. krtld will reset its
1593 1615 * internal module search path iff Solaris has set default_path.
1594 1616 * We want to be sure we're prepending this new directory to the
1595 1617 * right search path.
1596 1618 */
1597 1619 current = (default_path == NULL) ? kobj_module_path : default_path;
1598 1620
1599 1621 newlen = strlen(HVM_MOD_DIR) + strlen(current) + 2;
1600 1622 newpath = kmem_alloc(newlen, KM_SLEEP);
1601 1623 (void) strcpy(newpath, HVM_MOD_DIR);
1602 1624 (void) strcat(newpath, " ");
1603 1625 (void) strcat(newpath, current);
1604 1626
1605 1627 default_path = newpath;
1606 1628 }
1607 1629 #endif
1608 1630
1609 1631 static void
1610 1632 startup_modules(void)
1611 1633 {
1612 1634 int cnt;
1613 1635 extern void prom_setup(void);
1614 1636 int32_t v, h;
1615 1637 char d[11];
1616 1638 char *cp;
1617 1639 cmi_hdl_t hdl;
1618 1640
1619 1641 PRM_POINT("startup_modules() starting...");
1620 1642
1621 1643 #ifndef __xpv
1622 1644 /*
1623 1645 * Initialize ten-micro second timer so that drivers will
1624 1646 * not get short changed in their init phase. This was
1625 1647 * not getting called until clkinit which, on fast cpu's
1626 1648 * caused the drv_usecwait to be way too short.
1627 1649 */
1628 1650 microfind();
1629 1651
1630 1652 if ((get_hwenv() & HW_XEN_HVM) != 0)
1631 1653 update_default_path();
1632 1654 #endif
1633 1655
1634 1656 /*
1635 1657 * Read the GMT lag from /etc/rtc_config.
1636 1658 */
1637 1659 sgmtl(process_rtc_config_file());
1638 1660
1639 1661 /*
1640 1662 * Calculate default settings of system parameters based upon
1641 1663 * maxusers, yet allow to be overridden via the /etc/system file.
1642 1664 */
1643 1665 param_calc(0);
1644 1666
1645 1667 mod_setup();
1646 1668
1647 1669 /*
1648 1670 * Initialize system parameters.
1649 1671 */
1650 1672 param_init();
1651 1673
1652 1674 /*
1653 1675 * Initialize the default brands
1654 1676 */
1655 1677 brand_init();
1656 1678
1657 1679 /*
1658 1680 * maxmem is the amount of physical memory we're playing with.
1659 1681 */
1660 1682 maxmem = physmem;
1661 1683
1662 1684 /*
1663 1685 * Initialize segment management stuff.
1664 1686 */
1665 1687 seg_init();
1666 1688
1667 1689 if (modload("fs", "specfs") == -1)
1668 1690 halt("Can't load specfs");
1669 1691
1670 1692 if (modload("fs", "devfs") == -1)
1671 1693 halt("Can't load devfs");
1672 1694
1673 1695 if (modload("fs", "dev") == -1)
1674 1696 halt("Can't load dev");
1675 1697
1676 1698 if (modload("fs", "procfs") == -1)
1677 1699 halt("Can't load procfs");
1678 1700
1679 1701 (void) modloadonly("sys", "lbl_edition");
1680 1702
1681 1703 dispinit();
1682 1704
1683 1705 /* Read cluster configuration data. */
1684 1706 clconf_init();
1685 1707
1686 1708 #if defined(__xpv)
1687 1709 (void) ec_init();
1688 1710 gnttab_init();
1689 1711 (void) xs_early_init();
1690 1712 #endif /* __xpv */
1691 1713
1692 1714 /*
1693 1715 * Create a kernel device tree. First, create rootnex and
1694 1716 * then invoke bus specific code to probe devices.
1695 1717 */
1696 1718 setup_ddi();
1697 1719
1698 1720 #ifdef __xpv
1699 1721 if (DOMAIN_IS_INITDOMAIN(xen_info))
1700 1722 #endif
1701 1723 {
1702 1724 id_t smid;
1703 1725 smbios_system_t smsys;
1704 1726 smbios_info_t sminfo;
1705 1727 char *mfg;
1706 1728 /*
1707 1729 * Load the System Management BIOS into the global ksmbios
1708 1730 * handle, if an SMBIOS is present on this system.
1709 1731 * Also set "si-hw-provider" property, if not already set.
1710 1732 */
1711 1733 ksmbios = smbios_open(NULL, SMB_VERSION, ksmbios_flags, NULL);
1712 1734 if (ksmbios != NULL &&
1713 1735 ((smid = smbios_info_system(ksmbios, &smsys)) != SMB_ERR) &&
1714 1736 (smbios_info_common(ksmbios, smid, &sminfo)) != SMB_ERR) {
1715 1737 mfg = (char *)sminfo.smbi_manufacturer;
1716 1738 if (BOP_GETPROPLEN(bootops, "si-hw-provider") < 0) {
1717 1739 extern char hw_provider[];
1718 1740 int i;
1719 1741 for (i = 0; i < SYS_NMLN; i++) {
1720 1742 if (isprint(mfg[i]))
1721 1743 hw_provider[i] = mfg[i];
1722 1744 else {
1723 1745 hw_provider[i] = '\0';
1724 1746 break;
1725 1747 }
1726 1748 }
1727 1749 hw_provider[SYS_NMLN - 1] = '\0';
1728 1750 }
1729 1751 }
1730 1752 }
1731 1753
1732 1754
1733 1755 /*
1734 1756 * Originally clconf_init() apparently needed the hostid. But
1735 1757 * this no longer appears to be true - it uses its own nodeid.
1736 1758 * By placing the hostid logic here, we are able to make use of
1737 1759 * the SMBIOS UUID.
1738 1760 */
1739 1761 if ((h = set_soft_hostid()) == HW_INVALID_HOSTID) {
1740 1762 cmn_err(CE_WARN, "Unable to set hostid");
1741 1763 } else {
1742 1764 for (v = h, cnt = 0; cnt < 10; cnt++) {
1743 1765 d[cnt] = (char)(v % 10);
1744 1766 v /= 10;
1745 1767 if (v == 0)
1746 1768 break;
1747 1769 }
1748 1770 for (cp = hw_serial; cnt >= 0; cnt--)
1749 1771 *cp++ = d[cnt] + '0';
1750 1772 *cp = 0;
1751 1773 }
1752 1774
1753 1775 /*
1754 1776 * Set up the CPU module subsystem for the boot cpu in the native
1755 1777 * case, and all physical cpu resource in the xpv dom0 case.
1756 1778 * Modifies the device tree, so this must be done after
1757 1779 * setup_ddi().
1758 1780 */
1759 1781 #ifdef __xpv
1760 1782 /*
1761 1783 * If paravirtualized and on dom0 then we initialize all physical
1762 1784 * cpu handles now; if paravirtualized on a domU then do not
1763 1785 * initialize.
1764 1786 */
1765 1787 if (DOMAIN_IS_INITDOMAIN(xen_info)) {
1766 1788 xen_mc_lcpu_cookie_t cpi;
1767 1789
1768 1790 for (cpi = xen_physcpu_next(NULL); cpi != NULL;
1769 1791 cpi = xen_physcpu_next(cpi)) {
1770 1792 if ((hdl = cmi_init(CMI_HDL_SOLARIS_xVM_MCA,
1771 1793 xen_physcpu_chipid(cpi), xen_physcpu_coreid(cpi),
1772 1794 xen_physcpu_strandid(cpi))) != NULL &&
1773 1795 is_x86_feature(x86_featureset, X86FSET_MCA))
1774 1796 cmi_mca_init(hdl);
1775 1797 }
1776 1798 }
1777 1799 #else
1778 1800 /*
1779 1801 * Initialize a handle for the boot cpu - others will initialize
1780 1802 * as they startup.
1781 1803 */
1782 1804 if ((hdl = cmi_init(CMI_HDL_NATIVE, cmi_ntv_hwchipid(CPU),
1783 1805 cmi_ntv_hwcoreid(CPU), cmi_ntv_hwstrandid(CPU))) != NULL) {
1784 1806 if (is_x86_feature(x86_featureset, X86FSET_MCA))
1785 1807 cmi_mca_init(hdl);
1786 1808 CPU->cpu_m.mcpu_cmi_hdl = hdl;
1787 1809 }
1788 1810 #endif /* __xpv */
1789 1811
1790 1812 /*
1791 1813 * Fake a prom tree such that /dev/openprom continues to work
1792 1814 */
1793 1815 PRM_POINT("startup_modules: calling prom_setup...");
1794 1816 prom_setup();
1795 1817 PRM_POINT("startup_modules: done");
1796 1818
1797 1819 /*
1798 1820 * Load all platform specific modules
1799 1821 */
1800 1822 PRM_POINT("startup_modules: calling psm_modload...");
1801 1823 psm_modload();
1802 1824
1803 1825 PRM_POINT("startup_modules() done");
1804 1826 }
1805 1827
1806 1828 /*
1807 1829 * claim a "setaside" boot page for use in the kernel
1808 1830 */
1809 1831 page_t *
1810 1832 boot_claim_page(pfn_t pfn)
1811 1833 {
1812 1834 page_t *pp;
1813 1835
1814 1836 pp = page_numtopp_nolock(pfn);
1815 1837 ASSERT(pp != NULL);
1816 1838
1817 1839 if (PP_ISBOOTPAGES(pp)) {
1818 1840 if (pp->p_next != NULL)
1819 1841 pp->p_next->p_prev = pp->p_prev;
1820 1842 if (pp->p_prev == NULL)
1821 1843 bootpages = pp->p_next;
1822 1844 else
1823 1845 pp->p_prev->p_next = pp->p_next;
1824 1846 } else {
1825 1847 /*
1826 1848 * htable_attach() expects a base pagesize page
1827 1849 */
1828 1850 if (pp->p_szc != 0)
1829 1851 page_boot_demote(pp);
1830 1852 pp = page_numtopp(pfn, SE_EXCL);
1831 1853 }
1832 1854 return (pp);
1833 1855 }
1834 1856
1835 1857 /*
1836 1858 * Walk through the pagetables looking for pages mapped in by boot. If the
1837 1859 * setaside flag is set the pages are expected to be returned to the
1838 1860 * kernel later in boot, so we add them to the bootpages list.
1839 1861 */
1840 1862 static void
1841 1863 protect_boot_range(uintptr_t low, uintptr_t high, int setaside)
1842 1864 {
1843 1865 uintptr_t va = low;
1844 1866 size_t len;
1845 1867 uint_t prot;
1846 1868 pfn_t pfn;
1847 1869 page_t *pp;
1848 1870 pgcnt_t boot_protect_cnt = 0;
1849 1871
1850 1872 while (kbm_probe(&va, &len, &pfn, &prot) != 0 && va < high) {
1851 1873 if (va + len >= high)
1852 1874 panic("0x%lx byte mapping at 0x%p exceeds boot's "
1853 1875 "legal range.", len, (void *)va);
1854 1876
1855 1877 while (len > 0) {
1856 1878 pp = page_numtopp_alloc(pfn);
1857 1879 if (pp != NULL) {
1858 1880 if (setaside == 0)
1859 1881 panic("Unexpected mapping by boot. "
1860 1882 "addr=%p pfn=%lx\n",
1861 1883 (void *)va, pfn);
1862 1884
1863 1885 pp->p_next = bootpages;
1864 1886 pp->p_prev = NULL;
1865 1887 PP_SETBOOTPAGES(pp);
1866 1888 if (bootpages != NULL) {
1867 1889 bootpages->p_prev = pp;
1868 1890 }
1869 1891 bootpages = pp;
1870 1892 ++boot_protect_cnt;
1871 1893 }
1872 1894
1873 1895 ++pfn;
1874 1896 len -= MMU_PAGESIZE;
1875 1897 va += MMU_PAGESIZE;
1876 1898 }
1877 1899 }
1878 1900 PRM_DEBUG(boot_protect_cnt);
1879 1901 }
1880 1902
1881 1903 /*
1882 1904 *
1883 1905 */
1884 1906 static void
1885 1907 layout_kernel_va(void)
1886 1908 {
1887 1909 PRM_POINT("layout_kernel_va() starting...");
1888 1910 /*
1889 1911 * Establish the final size of the kernel's heap, size of segmap,
1890 1912 * segkp, etc.
1891 1913 */
1892 1914
1893 1915 #if defined(__amd64)
1894 1916
1895 1917 kpm_vbase = (caddr_t)segkpm_base;
1896 1918 if (physmax + 1 < plat_dr_physmax) {
1897 1919 kpm_size = ROUND_UP_LPAGE(mmu_ptob(plat_dr_physmax));
1898 1920 } else {
1899 1921 kpm_size = ROUND_UP_LPAGE(mmu_ptob(physmax + 1));
1900 1922 }
1901 1923 if ((uintptr_t)kpm_vbase + kpm_size > (uintptr_t)valloc_base)
1902 1924 panic("not enough room for kpm!");
1903 1925 PRM_DEBUG(kpm_size);
1904 1926 PRM_DEBUG(kpm_vbase);
1905 1927
1906 1928 /*
1907 1929 * By default we create a seg_kp in 64 bit kernels, it's a little
1908 1930 * faster to access than embedding it in the heap.
1909 1931 */
1910 1932 segkp_base = (caddr_t)valloc_base + valloc_sz;
1911 1933 if (!segkp_fromheap) {
1912 1934 size_t sz = mmu_ptob(segkpsize);
1913 1935
1914 1936 /*
1915 1937 * determine size of segkp
1916 1938 */
1917 1939 if (sz < SEGKPMINSIZE || sz > SEGKPMAXSIZE) {
1918 1940 sz = SEGKPDEFSIZE;
1919 1941 cmn_err(CE_WARN, "!Illegal value for segkpsize. "
1920 1942 "segkpsize has been reset to %ld pages",
1921 1943 mmu_btop(sz));
1922 1944 }
1923 1945 sz = MIN(sz, MAX(SEGKPMINSIZE, mmu_ptob(physmem)));
1924 1946
1925 1947 segkpsize = mmu_btop(ROUND_UP_LPAGE(sz));
1926 1948 }
1927 1949 PRM_DEBUG(segkp_base);
1928 1950 PRM_DEBUG(segkpsize);
1929 1951
1930 1952 /*
1931 1953 * segzio is used for ZFS cached data. It uses a distinct VA
1932 1954 * segment (from kernel heap) so that we can easily tell not to
1933 1955 * include it in kernel crash dumps on 64 bit kernels. The trick is
1934 1956 * to give it lots of VA, but not constrain the kernel heap.
1935 1957 * We can use 1.5x physmem for segzio, leaving approximately
1936 1958 * another 1.5x physmem for heap. See also the comment in
1937 1959 * startup_memlist().
1938 1960 */
1939 1961 segzio_base = segkp_base + mmu_ptob(segkpsize);
1940 1962 if (segzio_fromheap) {
1941 1963 segziosize = 0;
1942 1964 } else {
1943 1965 size_t physmem_size = mmu_ptob(physmem);
1944 1966 size_t size = (segziosize == 0) ?
1945 1967 physmem_size * 3 / 2 : mmu_ptob(segziosize);
1946 1968
1947 1969 if (size < SEGZIOMINSIZE)
1948 1970 size = SEGZIOMINSIZE;
1949 1971 segziosize = mmu_btop(ROUND_UP_LPAGE(size));
1950 1972 }
1951 1973 PRM_DEBUG(segziosize);
1952 1974 PRM_DEBUG(segzio_base);
1953 1975
1954 1976 /*
1955 1977 * Put the range of VA for device mappings next, kmdb knows to not
1956 1978 * grep in this range of addresses.
1957 1979 */
1958 1980 toxic_addr =
1959 1981 ROUND_UP_LPAGE((uintptr_t)segzio_base + mmu_ptob(segziosize));
1960 1982 PRM_DEBUG(toxic_addr);
1961 1983 segmap_start = ROUND_UP_LPAGE(toxic_addr + toxic_size);
1962 1984 #else /* __i386 */
1963 1985 segmap_start = ROUND_UP_LPAGE(kernelbase);
1964 1986 #endif /* __i386 */
1965 1987 PRM_DEBUG(segmap_start);
1966 1988
1967 1989 /*
1968 1990 * Users can change segmapsize through eeprom. If the variable
1969 1991 * is tuned through eeprom, there is no upper bound on the
1970 1992 * size of segmap.
1971 1993 */
1972 1994 segmapsize = MAX(ROUND_UP_LPAGE(segmapsize), SEGMAPDEFAULT);
1973 1995
1974 1996 #if defined(__i386)
1975 1997 /*
1976 1998 * 32-bit systems don't have segkpm or segkp, so segmap appears at
1977 1999 * the bottom of the kernel's address range. Set aside space for a
1978 2000 * small red zone just below the start of segmap.
1979 2001 */
1980 2002 segmap_start += KERNEL_REDZONE_SIZE;
1981 2003 segmapsize -= KERNEL_REDZONE_SIZE;
1982 2004 #endif
1983 2005
1984 2006 PRM_DEBUG(segmap_start);
1985 2007 PRM_DEBUG(segmapsize);
1986 2008 kernelheap = (caddr_t)ROUND_UP_LPAGE(segmap_start + segmapsize);
1987 2009 PRM_DEBUG(kernelheap);
1988 2010 PRM_POINT("layout_kernel_va() done...");
1989 2011 }
1990 2012
1991 2013 /*
1992 2014 * Finish initializing the VM system, now that we are no longer
1993 2015 * relying on the boot time memory allocators.
1994 2016 */
1995 2017 static void
1996 2018 startup_vm(void)
1997 2019 {
1998 2020 struct segmap_crargs a;
1999 2021
2000 2022 extern int use_brk_lpg, use_stk_lpg;
2001 2023
2002 2024 PRM_POINT("startup_vm() starting...");
2003 2025
2004 2026 /*
2005 2027 * Initialize the hat layer.
2006 2028 */
2007 2029 hat_init();
2008 2030
2009 2031 /*
2010 2032 * Do final allocations of HAT data structures that need to
2011 2033 * be allocated before quiescing the boot loader.
2012 2034 */
2013 2035 PRM_POINT("Calling hat_kern_alloc()...");
2014 2036 hat_kern_alloc((caddr_t)segmap_start, segmapsize, ekernelheap);
2015 2037 PRM_POINT("hat_kern_alloc() done");
2016 2038
2017 2039 #ifndef __xpv
2018 2040 /*
2019 2041 * Setup Page Attribute Table
2020 2042 */
2021 2043 pat_sync();
2022 2044 #endif
2023 2045
2024 2046 /*
2025 2047 * The next two loops are done in distinct steps in order
2026 2048 * to be sure that any page that is doubly mapped (both above
2027 2049 * KERNEL_TEXT and below kernelbase) is dealt with correctly.
2028 2050 * Note this may never happen, but it might someday.
2029 2051 */
2030 2052 bootpages = NULL;
2031 2053 PRM_POINT("Protecting boot pages");
2032 2054
2033 2055 /*
2034 2056 * Protect any pages mapped above KERNEL_TEXT that somehow have
2035 2057 * page_t's. This can only happen if something weird allocated
2036 2058 * in this range (like kadb/kmdb).
2037 2059 */
2038 2060 protect_boot_range(KERNEL_TEXT, (uintptr_t)-1, 0);
2039 2061
2040 2062 /*
2041 2063 * Before we can take over memory allocation/mapping from the boot
2042 2064 * loader we must remove from our free page lists any boot allocated
2043 2065 * pages that stay mapped until release_bootstrap().
2044 2066 */
2045 2067 protect_boot_range(0, kernelbase, 1);
2046 2068
2047 2069
2048 2070 /*
2049 2071 * Switch to running on regular HAT (not boot_mmu)
2050 2072 */
2051 2073 PRM_POINT("Calling hat_kern_setup()...");
2052 2074 hat_kern_setup();
2053 2075
2054 2076 /*
2055 2077 * It is no longer safe to call BOP_ALLOC(), so make sure we don't.
2056 2078 */
2057 2079 bop_no_more_mem();
2058 2080
2059 2081 PRM_POINT("hat_kern_setup() done");
2060 2082
2061 2083 hat_cpu_online(CPU);
2062 2084
2063 2085 /*
2064 2086 * Initialize VM system
2065 2087 */
2066 2088 PRM_POINT("Calling kvm_init()...");
2067 2089 kvm_init();
2068 2090 PRM_POINT("kvm_init() done");
2069 2091
2070 2092 /*
2071 2093 * Tell kmdb that the VM system is now working
2072 2094 */
2073 2095 if (boothowto & RB_DEBUG)
2074 2096 kdi_dvec_vmready();
2075 2097
2076 2098 #if defined(__xpv)
2077 2099 /*
2078 2100 * Populate the I/O pool on domain 0
2079 2101 */
2080 2102 if (DOMAIN_IS_INITDOMAIN(xen_info)) {
2081 2103 extern long populate_io_pool(void);
2082 2104 long init_io_pool_cnt;
2083 2105
2084 2106 PRM_POINT("Populating reserve I/O page pool");
2085 2107 init_io_pool_cnt = populate_io_pool();
2086 2108 PRM_DEBUG(init_io_pool_cnt);
2087 2109 }
2088 2110 #endif
2089 2111 /*
2090 2112 * Mangle the brand string etc.
2091 2113 */
2092 2114 cpuid_pass3(CPU);
2093 2115
2094 2116 #if defined(__amd64)
2095 2117
2096 2118 /*
2097 2119 * Create the device arena for toxic (to dtrace/kmdb) mappings.
2098 2120 */
2099 2121 device_arena = vmem_create("device", (void *)toxic_addr,
2100 2122 toxic_size, MMU_PAGESIZE, NULL, NULL, NULL, 0, VM_SLEEP);
2101 2123
2102 2124 #else /* __i386 */
2103 2125
2104 2126 /*
2105 2127 * allocate the bit map that tracks toxic pages
2106 2128 */
2107 2129 toxic_bit_map_len = btop((ulong_t)(valloc_base - kernelbase));
2108 2130 PRM_DEBUG(toxic_bit_map_len);
2109 2131 toxic_bit_map =
2110 2132 kmem_zalloc(BT_SIZEOFMAP(toxic_bit_map_len), KM_NOSLEEP);
2111 2133 ASSERT(toxic_bit_map != NULL);
2112 2134 PRM_DEBUG(toxic_bit_map);
2113 2135
↓ open down ↓ |
618 lines elided |
↑ open up ↑ |
2114 2136 #endif /* __i386 */
2115 2137
2116 2138
2117 2139 /*
2118 2140 * Now that we've got more VA, as well as the ability to allocate from
2119 2141 * it, tell the debugger.
2120 2142 */
2121 2143 if (boothowto & RB_DEBUG)
2122 2144 kdi_dvec_memavail();
2123 2145
2124 - /*
2125 - * The following code installs a special page fault handler (#pf)
2126 - * to work around a pentium bug.
2127 - */
2128 -#if !defined(__amd64) && !defined(__xpv)
2129 - if (x86_type == X86_TYPE_P5) {
2130 - desctbr_t idtr;
2131 - gate_desc_t *newidt;
2132 -
2133 - if ((newidt = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP)) == NULL)
2134 - panic("failed to install pentium_pftrap");
2135 -
2136 - bcopy(idt0, newidt, NIDT * sizeof (*idt0));
2137 - set_gatesegd(&newidt[T_PGFLT], &pentium_pftrap,
2138 - KCS_SEL, SDT_SYSIGT, TRP_KPL, 0);
2139 -
2140 - (void) as_setprot(&kas, (caddr_t)newidt, MMU_PAGESIZE,
2141 - PROT_READ | PROT_EXEC);
2142 -
2143 - CPU->cpu_idt = newidt;
2144 - idtr.dtr_base = (uintptr_t)CPU->cpu_idt;
2145 - idtr.dtr_limit = (NIDT * sizeof (*idt0)) - 1;
2146 - wr_idtr(&idtr);
2147 - }
2148 -#endif /* !__amd64 */
2149 -
2150 2146 #if !defined(__xpv)
2151 2147 /*
2152 2148 * Map page pfn=0 for drivers, such as kd, that need to pick up
2153 2149 * parameters left there by controllers/BIOS.
2154 2150 */
2155 2151 PRM_POINT("setup up p0_va");
2156 2152 p0_va = i86devmap(0, 1, PROT_READ);
2157 2153 PRM_DEBUG(p0_va);
2158 2154 #endif
2159 2155
2160 2156 cmn_err(CE_CONT, "?mem = %luK (0x%lx)\n",
2161 2157 physinstalled << (MMU_PAGESHIFT - 10), ptob(physinstalled));
2162 2158
2163 2159 /*
2164 2160 * disable automatic large pages for small memory systems or
2165 2161 * when the disable flag is set.
2166 2162 *
2167 2163 * Do not yet consider page sizes larger than 2m/4m.
2168 2164 */
2169 2165 if (!auto_lpg_disable && mmu.max_page_level > 0) {
2170 2166 max_uheap_lpsize = LEVEL_SIZE(1);
2171 2167 max_ustack_lpsize = LEVEL_SIZE(1);
2172 2168 max_privmap_lpsize = LEVEL_SIZE(1);
2173 2169 max_uidata_lpsize = LEVEL_SIZE(1);
2174 2170 max_utext_lpsize = LEVEL_SIZE(1);
2175 2171 max_shm_lpsize = LEVEL_SIZE(1);
2176 2172 }
2177 2173 if (physmem < privm_lpg_min_physmem || mmu.max_page_level == 0 ||
2178 2174 auto_lpg_disable) {
2179 2175 use_brk_lpg = 0;
2180 2176 use_stk_lpg = 0;
2181 2177 }
2182 2178 mcntl0_lpsize = LEVEL_SIZE(mmu.umax_page_level);
2183 2179
2184 2180 PRM_POINT("Calling hat_init_finish()...");
2185 2181 hat_init_finish();
2186 2182 PRM_POINT("hat_init_finish() done");
2187 2183
2188 2184 /*
2189 2185 * Initialize the segkp segment type.
2190 2186 */
2191 2187 rw_enter(&kas.a_lock, RW_WRITER);
2192 2188 PRM_POINT("Attaching segkp");
2193 2189 if (segkp_fromheap) {
2194 2190 segkp->s_as = &kas;
2195 2191 } else if (seg_attach(&kas, (caddr_t)segkp_base, mmu_ptob(segkpsize),
2196 2192 segkp) < 0) {
2197 2193 panic("startup: cannot attach segkp");
2198 2194 /*NOTREACHED*/
2199 2195 }
2200 2196 PRM_POINT("Doing segkp_create()");
2201 2197 if (segkp_create(segkp) != 0) {
↓ open down ↓ |
42 lines elided |
↑ open up ↑ |
2202 2198 panic("startup: segkp_create failed");
2203 2199 /*NOTREACHED*/
2204 2200 }
2205 2201 PRM_DEBUG(segkp);
2206 2202 rw_exit(&kas.a_lock);
2207 2203
2208 2204 /*
2209 2205 * kpm segment
2210 2206 */
2211 2207 segmap_kpm = 0;
2212 - if (kpm_desired) {
2208 + if (kpm_desired)
2213 2209 kpm_init();
2214 - kpm_enable = 1;
2215 - }
2216 2210
2217 2211 /*
2218 2212 * Now create segmap segment.
2219 2213 */
2220 2214 rw_enter(&kas.a_lock, RW_WRITER);
2221 2215 if (seg_attach(&kas, (caddr_t)segmap_start, segmapsize, segmap) < 0) {
2222 2216 panic("cannot attach segmap");
2223 2217 /*NOTREACHED*/
2224 2218 }
2225 2219 PRM_DEBUG(segmap);
2226 2220
2227 2221 a.prot = PROT_READ | PROT_WRITE;
2228 2222 a.shmsize = 0;
2229 2223 a.nfreelist = segmapfreelists;
2230 2224
2231 2225 if (segmap_create(segmap, (caddr_t)&a) != 0)
2232 2226 panic("segmap_create segmap");
2233 2227 rw_exit(&kas.a_lock);
2234 2228
2235 2229 setup_vaddr_for_ppcopy(CPU);
2236 2230
2237 2231 segdev_init();
2238 2232 #if defined(__xpv)
2239 2233 if (DOMAIN_IS_INITDOMAIN(xen_info))
2240 2234 #endif
2241 2235 pmem_init();
2242 2236
2243 2237 PRM_POINT("startup_vm() done");
2244 2238 }
2245 2239
2246 2240 /*
2247 2241 * Load a tod module for the non-standard tod part found on this system.
2248 2242 */
2249 2243 static void
2250 2244 load_tod_module(char *todmod)
2251 2245 {
2252 2246 if (modload("tod", todmod) == -1)
2253 2247 halt("Can't load TOD module");
2254 2248 }
2255 2249
2256 2250 static void
2257 2251 startup_end(void)
2258 2252 {
2259 2253 int i;
2260 2254 extern void setx86isalist(void);
2261 2255 extern void cpu_event_init(void);
2262 2256
2263 2257 PRM_POINT("startup_end() starting...");
2264 2258
2265 2259 /*
2266 2260 * Perform tasks that get done after most of the VM
2267 2261 * initialization has been done but before the clock
2268 2262 * and other devices get started.
2269 2263 */
2270 2264 kern_setup1();
2271 2265
2272 2266 /*
2273 2267 * Perform CPC initialization for this CPU.
2274 2268 */
2275 2269 kcpc_hw_init(CPU);
2276 2270
2277 2271 /*
2278 2272 * Initialize cpu event framework.
2279 2273 */
2280 2274 cpu_event_init();
2281 2275
2282 2276 #if defined(OPTERON_WORKAROUND_6323525)
2283 2277 if (opteron_workaround_6323525)
2284 2278 patch_workaround_6323525();
2285 2279 #endif
2286 2280 /*
2287 2281 * If needed, load TOD module now so that ddi_get_time(9F) etc. work
2288 2282 * (For now, "needed" is defined as set tod_module_name in /etc/system)
2289 2283 */
2290 2284 if (tod_module_name != NULL) {
2291 2285 PRM_POINT("load_tod_module()");
2292 2286 load_tod_module(tod_module_name);
2293 2287 }
2294 2288
2295 2289 #if defined(__xpv)
2296 2290 /*
2297 2291 * Forceload interposing TOD module for the hypervisor.
2298 2292 */
2299 2293 PRM_POINT("load_tod_module()");
2300 2294 load_tod_module("xpvtod");
2301 2295 #endif
2302 2296
2303 2297 /*
2304 2298 * Configure the system.
2305 2299 */
2306 2300 PRM_POINT("Calling configure()...");
2307 2301 configure(); /* set up devices */
2308 2302 PRM_POINT("configure() done");
2309 2303
2310 2304 /*
2311 2305 * We can now setup for XSAVE because fpu_probe is done in configure().
2312 2306 */
2313 2307 if (fp_save_mech == FP_XSAVE) {
2314 2308 xsave_setup_msr(CPU);
2315 2309 }
2316 2310
2317 2311 /*
2318 2312 * Set the isa_list string to the defined instruction sets we
2319 2313 * support.
2320 2314 */
2321 2315 setx86isalist();
2322 2316 cpu_intr_alloc(CPU, NINTR_THREADS);
2323 2317 psm_install();
2324 2318
2325 2319 /*
2326 2320 * We're done with bootops. We don't unmap the bootstrap yet because
2327 2321 * we're still using bootsvcs.
↓ open down ↓ |
102 lines elided |
↑ open up ↑ |
2328 2322 */
2329 2323 PRM_POINT("NULLing out bootops");
2330 2324 *bootopsp = (struct bootops *)NULL;
2331 2325 bootops = (struct bootops *)NULL;
2332 2326
2333 2327 #if defined(__xpv)
2334 2328 ec_init_debug_irq();
2335 2329 xs_domu_init();
2336 2330 #endif
2337 2331
2338 -#if defined(__amd64) && !defined(__xpv)
2332 +#if !defined(__xpv)
2339 2333 /*
2340 2334 * Intel IOMMU has been setup/initialized in ddi_impl.c
2341 2335 * Start it up now.
2342 2336 */
2343 2337 immu_startup();
2338 +
2339 + /*
2340 + * Now that we're no longer going to drop into real mode for a BIOS call
2341 + * via bootops, we can enable PCID (which requires CR0.PG).
2342 + */
2343 + enable_pcid();
2344 2344 #endif
2345 2345
2346 2346 PRM_POINT("Enabling interrupts");
2347 2347 (*picinitf)();
2348 2348 sti();
2349 2349 #if defined(__xpv)
2350 2350 ASSERT(CPU->cpu_m.mcpu_vcpu_info->evtchn_upcall_mask == 0);
2351 2351 xen_late_startup();
2352 2352 #endif
2353 2353
2354 2354 (void) add_avsoftintr((void *)&softlevel1_hdl, 1, softlevel1,
2355 2355 "softlevel1", NULL, NULL); /* XXX to be moved later */
2356 2356
2357 2357 /*
2358 2358 * Register software interrupt handlers for ddi_periodic_add(9F).
2359 2359 * Software interrupts up to the level 10 are supported.
2360 2360 */
2361 2361 for (i = DDI_IPL_1; i <= DDI_IPL_10; i++) {
2362 2362 (void) add_avsoftintr((void *)&softlevel_hdl[i-1], i,
2363 2363 (avfunc)ddi_periodic_softintr, "ddi_periodic",
2364 2364 (caddr_t)(uintptr_t)i, NULL);
2365 2365 }
2366 2366
2367 2367 #if !defined(__xpv)
2368 2368 if (modload("drv", "amd_iommu") < 0) {
2369 2369 PRM_POINT("No AMD IOMMU present\n");
2370 2370 } else if (ddi_hold_installed_driver(ddi_name_to_major(
2371 2371 "amd_iommu")) == NULL) {
2372 2372 prom_printf("ERROR: failed to attach AMD IOMMU\n");
2373 2373 }
2374 2374 #endif
2375 2375 post_startup_cpu_fixups();
2376 2376
2377 2377 PRM_POINT("startup_end() done");
2378 2378 }
2379 2379
2380 2380 /*
2381 2381 * Don't remove the following 2 variables. They are necessary
2382 2382 * for reading the hostid from the legacy file (/kernel/misc/sysinit).
2383 2383 */
2384 2384 char *_hs1107 = hw_serial;
2385 2385 ulong_t _bdhs34;
2386 2386
2387 2387 void
2388 2388 post_startup(void)
2389 2389 {
2390 2390 extern void cpupm_init(cpu_t *);
2391 2391 extern void cpu_event_init_cpu(cpu_t *);
2392 2392
2393 2393 /*
2394 2394 * Set the system wide, processor-specific flags to be passed
2395 2395 * to userland via the aux vector for performance hints and
2396 2396 * instruction set extensions.
2397 2397 */
2398 2398 bind_hwcap();
2399 2399
2400 2400 #ifdef __xpv
2401 2401 if (DOMAIN_IS_INITDOMAIN(xen_info))
2402 2402 #endif
2403 2403 {
2404 2404 #if defined(__xpv)
2405 2405 xpv_panic_init();
2406 2406 #else
2407 2407 /*
2408 2408 * Startup the memory scrubber.
2409 2409 * XXPV This should be running somewhere ..
2410 2410 */
2411 2411 if ((get_hwenv() & HW_VIRTUAL) == 0)
2412 2412 memscrub_init();
2413 2413 #endif
2414 2414 }
2415 2415
2416 2416 /*
2417 2417 * Complete CPU module initialization
2418 2418 */
2419 2419 cmi_post_startup();
2420 2420
2421 2421 /*
2422 2422 * Perform forceloading tasks for /etc/system.
2423 2423 */
2424 2424 (void) mod_sysctl(SYS_FORCELOAD, NULL);
2425 2425
2426 2426 /*
2427 2427 * ON4.0: Force /proc module in until clock interrupt handle fixed
2428 2428 * ON4.0: This must be fixed or restated in /etc/systems.
2429 2429 */
2430 2430 (void) modload("fs", "procfs");
2431 2431
2432 2432 (void) i_ddi_attach_hw_nodes("pit_beep");
2433 2433
2434 2434 #if defined(__i386)
2435 2435 /*
2436 2436 * Check for required functional Floating Point hardware,
2437 2437 * unless FP hardware explicitly disabled.
2438 2438 */
2439 2439 if (fpu_exists && (fpu_pentium_fdivbug || fp_kind == FP_NO))
2440 2440 halt("No working FP hardware found");
2441 2441 #endif
2442 2442
2443 2443 maxmem = freemem;
2444 2444
2445 2445 cpu_event_init_cpu(CPU);
2446 2446 cpupm_init(CPU);
2447 2447 (void) mach_cpu_create_device_node(CPU, NULL);
2448 2448
2449 2449 pg_init();
2450 2450 }
2451 2451
2452 2452 static int
2453 2453 pp_in_range(page_t *pp, uint64_t low_addr, uint64_t high_addr)
2454 2454 {
2455 2455 return ((pp->p_pagenum >= btop(low_addr)) &&
2456 2456 (pp->p_pagenum < btopr(high_addr)));
2457 2457 }
2458 2458
2459 2459 static int
2460 2460 pp_in_module(page_t *pp, const rd_existing_t *modranges)
2461 2461 {
2462 2462 uint_t i;
2463 2463
2464 2464 for (i = 0; modranges[i].phys != 0; i++) {
2465 2465 if (pp_in_range(pp, modranges[i].phys,
2466 2466 modranges[i].phys + modranges[i].size))
2467 2467 return (1);
2468 2468 }
2469 2469
2470 2470 return (0);
2471 2471 }
2472 2472
2473 2473 void
2474 2474 release_bootstrap(void)
2475 2475 {
2476 2476 int root_is_ramdisk;
2477 2477 page_t *pp;
2478 2478 extern void kobj_boot_unmountroot(void);
2479 2479 extern dev_t rootdev;
2480 2480 uint_t i;
2481 2481 char propname[32];
2482 2482 rd_existing_t *modranges;
2483 2483 #if !defined(__xpv)
2484 2484 pfn_t pfn;
2485 2485 #endif
2486 2486
2487 2487 /*
2488 2488 * Save the bootfs module ranges so that we can reserve them below
2489 2489 * for the real bootfs.
2490 2490 */
2491 2491 modranges = kmem_alloc(sizeof (rd_existing_t) * MAX_BOOT_MODULES,
2492 2492 KM_SLEEP);
2493 2493 for (i = 0; ; i++) {
2494 2494 uint64_t start, size;
2495 2495
2496 2496 modranges[i].phys = 0;
2497 2497
2498 2498 (void) snprintf(propname, sizeof (propname),
2499 2499 "module-addr-%u", i);
2500 2500 if (do_bsys_getproplen(NULL, propname) <= 0)
2501 2501 break;
2502 2502 (void) do_bsys_getprop(NULL, propname, &start);
2503 2503
2504 2504 (void) snprintf(propname, sizeof (propname),
2505 2505 "module-size-%u", i);
2506 2506 if (do_bsys_getproplen(NULL, propname) <= 0)
2507 2507 break;
2508 2508 (void) do_bsys_getprop(NULL, propname, &size);
2509 2509
2510 2510 modranges[i].phys = start;
2511 2511 modranges[i].size = size;
2512 2512 }
2513 2513
2514 2514 /* unmount boot ramdisk and release kmem usage */
2515 2515 kobj_boot_unmountroot();
2516 2516
2517 2517 /*
2518 2518 * We're finished using the boot loader so free its pages.
2519 2519 */
2520 2520 PRM_POINT("Unmapping lower boot pages");
2521 2521
2522 2522 clear_boot_mappings(0, _userlimit);
2523 2523
2524 2524 postbootkernelbase = kernelbase;
2525 2525
2526 2526 /*
2527 2527 * If root isn't on ramdisk, destroy the hardcoded
2528 2528 * ramdisk node now and release the memory. Else,
2529 2529 * ramdisk memory is kept in rd_pages.
2530 2530 */
2531 2531 root_is_ramdisk = (getmajor(rootdev) == ddi_name_to_major("ramdisk"));
2532 2532 if (!root_is_ramdisk) {
2533 2533 dev_info_t *dip = ddi_find_devinfo("ramdisk", -1, 0);
2534 2534 ASSERT(dip && ddi_get_parent(dip) == ddi_root_node());
2535 2535 ndi_rele_devi(dip); /* held from ddi_find_devinfo */
2536 2536 (void) ddi_remove_child(dip, 0);
2537 2537 }
2538 2538
2539 2539 PRM_POINT("Releasing boot pages");
2540 2540 while (bootpages) {
2541 2541 extern uint64_t ramdisk_start, ramdisk_end;
2542 2542 pp = bootpages;
2543 2543 bootpages = pp->p_next;
2544 2544
2545 2545
2546 2546 /* Keep pages for the lower 64K */
2547 2547 if (pp_in_range(pp, 0, 0x40000)) {
2548 2548 pp->p_next = lower_pages;
2549 2549 lower_pages = pp;
2550 2550 lower_pages_count++;
2551 2551 continue;
2552 2552 }
2553 2553
2554 2554 if (root_is_ramdisk && pp_in_range(pp, ramdisk_start,
2555 2555 ramdisk_end) || pp_in_module(pp, modranges)) {
2556 2556 pp->p_next = rd_pages;
2557 2557 rd_pages = pp;
2558 2558 continue;
2559 2559 }
2560 2560 pp->p_next = (struct page *)0;
2561 2561 pp->p_prev = (struct page *)0;
2562 2562 PP_CLRBOOTPAGES(pp);
2563 2563 page_free(pp, 1);
2564 2564 }
2565 2565 PRM_POINT("Boot pages released");
2566 2566
2567 2567 kmem_free(modranges, sizeof (rd_existing_t) * 99);
2568 2568
2569 2569 #if !defined(__xpv)
2570 2570 /* XXPV -- note this following bunch of code needs to be revisited in Xen 3.0 */
2571 2571 /*
2572 2572 * Find 1 page below 1 MB so that other processors can boot up or
2573 2573 * so that any processor can resume.
2574 2574 * Make sure it has a kernel VA as well as a 1:1 mapping.
2575 2575 * We should have just free'd one up.
2576 2576 */
2577 2577
2578 2578 /*
2579 2579 * 0x10 pages is 64K. Leave the bottom 64K alone
2580 2580 * for BIOS.
2581 2581 */
2582 2582 for (pfn = 0x10; pfn < btop(1*1024*1024); pfn++) {
2583 2583 if (page_numtopp_alloc(pfn) == NULL)
2584 2584 continue;
2585 2585 rm_platter_va = i86devmap(pfn, 1,
2586 2586 PROT_READ | PROT_WRITE | PROT_EXEC);
2587 2587 rm_platter_pa = ptob(pfn);
2588 2588 break;
2589 2589 }
2590 2590 if (pfn == btop(1*1024*1024) && use_mp)
2591 2591 panic("No page below 1M available for starting "
2592 2592 "other processors or for resuming from system-suspend");
2593 2593 #endif /* !__xpv */
2594 2594 }
2595 2595
2596 2596 /*
2597 2597 * Initialize the platform-specific parts of a page_t.
2598 2598 */
2599 2599 void
2600 2600 add_physmem_cb(page_t *pp, pfn_t pnum)
2601 2601 {
2602 2602 pp->p_pagenum = pnum;
2603 2603 pp->p_mapping = NULL;
2604 2604 pp->p_embed = 0;
2605 2605 pp->p_share = 0;
2606 2606 pp->p_mlentry = 0;
2607 2607 }
2608 2608
2609 2609 /*
2610 2610 * kphysm_init() initializes physical memory.
2611 2611 */
2612 2612 static pgcnt_t
2613 2613 kphysm_init(
2614 2614 page_t *pp,
2615 2615 pgcnt_t npages)
2616 2616 {
2617 2617 struct memlist *pmem;
2618 2618 struct memseg *cur_memseg;
2619 2619 pfn_t base_pfn;
2620 2620 pfn_t end_pfn;
2621 2621 pgcnt_t num;
2622 2622 pgcnt_t pages_done = 0;
2623 2623 uint64_t addr;
2624 2624 uint64_t size;
2625 2625 extern pfn_t ddiphysmin;
2626 2626 extern int mnode_xwa;
2627 2627 int ms = 0, me = 0;
2628 2628
2629 2629 ASSERT(page_hash != NULL && page_hashsz != 0);
2630 2630
2631 2631 cur_memseg = memseg_base;
2632 2632 for (pmem = phys_avail; pmem && npages; pmem = pmem->ml_next) {
2633 2633 /*
2634 2634 * In a 32 bit kernel can't use higher memory if we're
2635 2635 * not booting in PAE mode. This check takes care of that.
2636 2636 */
2637 2637 addr = pmem->ml_address;
2638 2638 size = pmem->ml_size;
2639 2639 if (btop(addr) > physmax)
2640 2640 continue;
2641 2641
2642 2642 /*
2643 2643 * align addr and size - they may not be at page boundaries
2644 2644 */
2645 2645 if ((addr & MMU_PAGEOFFSET) != 0) {
2646 2646 addr += MMU_PAGEOFFSET;
2647 2647 addr &= ~(uint64_t)MMU_PAGEOFFSET;
2648 2648 size -= addr - pmem->ml_address;
2649 2649 }
2650 2650
2651 2651 /* only process pages below or equal to physmax */
2652 2652 if ((btop(addr + size) - 1) > physmax)
2653 2653 size = ptob(physmax - btop(addr) + 1);
2654 2654
2655 2655 num = btop(size);
2656 2656 if (num == 0)
2657 2657 continue;
2658 2658
2659 2659 if (num > npages)
2660 2660 num = npages;
2661 2661
2662 2662 npages -= num;
2663 2663 pages_done += num;
2664 2664 base_pfn = btop(addr);
2665 2665
2666 2666 if (prom_debug)
2667 2667 prom_printf("MEMSEG addr=0x%" PRIx64
2668 2668 " pgs=0x%lx pfn 0x%lx-0x%lx\n",
2669 2669 addr, num, base_pfn, base_pfn + num);
2670 2670
2671 2671 /*
2672 2672 * Ignore pages below ddiphysmin to simplify ddi memory
2673 2673 * allocation with non-zero addr_lo requests.
2674 2674 */
2675 2675 if (base_pfn < ddiphysmin) {
2676 2676 if (base_pfn + num <= ddiphysmin)
2677 2677 continue;
2678 2678 pp += (ddiphysmin - base_pfn);
2679 2679 num -= (ddiphysmin - base_pfn);
2680 2680 base_pfn = ddiphysmin;
2681 2681 }
2682 2682
2683 2683 /*
2684 2684 * mnode_xwa is greater than 1 when large pages regions can
2685 2685 * cross memory node boundaries. To prevent the formation
2686 2686 * of these large pages, configure the memsegs based on the
2687 2687 * memory node ranges which had been made non-contiguous.
2688 2688 */
2689 2689 if (mnode_xwa > 1) {
2690 2690
2691 2691 end_pfn = base_pfn + num - 1;
2692 2692 ms = PFN_2_MEM_NODE(base_pfn);
2693 2693 me = PFN_2_MEM_NODE(end_pfn);
2694 2694
2695 2695 if (ms != me) {
2696 2696 /*
2697 2697 * current range spans more than 1 memory node.
2698 2698 * Set num to only the pfn range in the start
2699 2699 * memory node.
2700 2700 */
2701 2701 num = mem_node_config[ms].physmax - base_pfn
2702 2702 + 1;
2703 2703 ASSERT(end_pfn > mem_node_config[ms].physmax);
2704 2704 }
2705 2705 }
2706 2706
2707 2707 for (;;) {
2708 2708 /*
2709 2709 * Build the memsegs entry
2710 2710 */
2711 2711 cur_memseg->pages = pp;
2712 2712 cur_memseg->epages = pp + num;
2713 2713 cur_memseg->pages_base = base_pfn;
2714 2714 cur_memseg->pages_end = base_pfn + num;
2715 2715
2716 2716 /*
2717 2717 * Insert into memseg list in decreasing pfn range
2718 2718 * order. Low memory is typically more fragmented such
2719 2719 * that this ordering keeps the larger ranges at the
2720 2720 * front of the list for code that searches memseg.
2721 2721 * This ASSERTS that the memsegs coming in from boot
2722 2722 * are in increasing physical address order and not
2723 2723 * contiguous.
2724 2724 */
2725 2725 if (memsegs != NULL) {
2726 2726 ASSERT(cur_memseg->pages_base >=
2727 2727 memsegs->pages_end);
2728 2728 cur_memseg->next = memsegs;
2729 2729 }
2730 2730 memsegs = cur_memseg;
2731 2731
2732 2732 /*
2733 2733 * add_physmem() initializes the PSM part of the page
2734 2734 * struct by calling the PSM back with add_physmem_cb().
2735 2735 * In addition it coalesces pages into larger pages as
2736 2736 * it initializes them.
2737 2737 */
2738 2738 add_physmem(pp, num, base_pfn);
2739 2739 cur_memseg++;
2740 2740 availrmem_initial += num;
2741 2741 availrmem += num;
2742 2742
2743 2743 pp += num;
2744 2744 if (ms >= me)
2745 2745 break;
2746 2746
2747 2747 /* process next memory node range */
2748 2748 ms++;
2749 2749 base_pfn = mem_node_config[ms].physbase;
2750 2750 num = MIN(mem_node_config[ms].physmax,
2751 2751 end_pfn) - base_pfn + 1;
2752 2752 }
2753 2753 }
2754 2754
2755 2755 PRM_DEBUG(availrmem_initial);
2756 2756 PRM_DEBUG(availrmem);
2757 2757 PRM_DEBUG(freemem);
2758 2758 build_pfn_hash();
2759 2759 return (pages_done);
2760 2760 }
2761 2761
2762 2762 /*
2763 2763 * Kernel VM initialization.
2764 2764 */
2765 2765 static void
2766 2766 kvm_init(void)
2767 2767 {
2768 2768 ASSERT((((uintptr_t)s_text) & MMU_PAGEOFFSET) == 0);
2769 2769
2770 2770 /*
2771 2771 * Put the kernel segments in kernel address space.
2772 2772 */
2773 2773 rw_enter(&kas.a_lock, RW_WRITER);
2774 2774 as_avlinit(&kas);
2775 2775
2776 2776 (void) seg_attach(&kas, s_text, e_moddata - s_text, &ktextseg);
2777 2777 (void) segkmem_create(&ktextseg);
2778 2778
2779 2779 (void) seg_attach(&kas, (caddr_t)valloc_base, valloc_sz, &kvalloc);
2780 2780 (void) segkmem_create(&kvalloc);
2781 2781
2782 2782 (void) seg_attach(&kas, kernelheap,
2783 2783 ekernelheap - kernelheap, &kvseg);
2784 2784 (void) segkmem_create(&kvseg);
2785 2785
2786 2786 if (core_size > 0) {
2787 2787 PRM_POINT("attaching kvseg_core");
2788 2788 (void) seg_attach(&kas, (caddr_t)core_base, core_size,
2789 2789 &kvseg_core);
2790 2790 (void) segkmem_create(&kvseg_core);
2791 2791 }
2792 2792
2793 2793 if (segziosize > 0) {
2794 2794 PRM_POINT("attaching segzio");
2795 2795 (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize),
2796 2796 &kzioseg);
2797 2797 (void) segkmem_zio_create(&kzioseg);
2798 2798
2799 2799 /* create zio area covering new segment */
2800 2800 segkmem_zio_init(segzio_base, mmu_ptob(segziosize));
2801 2801 }
2802 2802
2803 2803 (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg);
2804 2804 (void) segkmem_create(&kdebugseg);
2805 2805
2806 2806 rw_exit(&kas.a_lock);
2807 2807
2808 2808 /*
2809 2809 * Ensure that the red zone at kernelbase is never accessible.
2810 2810 */
2811 2811 PRM_POINT("protecting redzone");
2812 2812 (void) as_setprot(&kas, (caddr_t)kernelbase, KERNEL_REDZONE_SIZE, 0);
2813 2813
2814 2814 /*
2815 2815 * Make the text writable so that it can be hot patched by DTrace.
2816 2816 */
2817 2817 (void) as_setprot(&kas, s_text, e_modtext - s_text,
2818 2818 PROT_READ | PROT_WRITE | PROT_EXEC);
2819 2819
2820 2820 /*
2821 2821 * Make data writable until end.
2822 2822 */
2823 2823 (void) as_setprot(&kas, s_data, e_moddata - s_data,
2824 2824 PROT_READ | PROT_WRITE | PROT_EXEC);
2825 2825 }
2826 2826
2827 2827 #ifndef __xpv
2828 2828 /*
2829 2829 * Solaris adds an entry for Write Combining caching to the PAT
2830 2830 */
2831 2831 static uint64_t pat_attr_reg = PAT_DEFAULT_ATTRIBUTE;
2832 2832
2833 2833 void
2834 2834 pat_sync(void)
2835 2835 {
2836 2836 ulong_t cr0, cr0_orig, cr4;
2837 2837
2838 2838 if (!is_x86_feature(x86_featureset, X86FSET_PAT))
2839 2839 return;
2840 2840 cr0_orig = cr0 = getcr0();
2841 2841 cr4 = getcr4();
2842 2842
2843 2843 /* disable caching and flush all caches and TLBs */
2844 2844 cr0 |= CR0_CD;
2845 2845 cr0 &= ~CR0_NW;
2846 2846 setcr0(cr0);
2847 2847 invalidate_cache();
2848 2848 if (cr4 & CR4_PGE) {
2849 2849 setcr4(cr4 & ~(ulong_t)CR4_PGE);
2850 2850 setcr4(cr4);
2851 2851 } else {
2852 2852 reload_cr3();
2853 2853 }
2854 2854
2855 2855 /* add our entry to the PAT */
2856 2856 wrmsr(REG_PAT, pat_attr_reg);
2857 2857
2858 2858 /* flush TLBs and cache again, then reenable cr0 caching */
2859 2859 if (cr4 & CR4_PGE) {
2860 2860 setcr4(cr4 & ~(ulong_t)CR4_PGE);
2861 2861 setcr4(cr4);
2862 2862 } else {
2863 2863 reload_cr3();
2864 2864 }
2865 2865 invalidate_cache();
2866 2866 setcr0(cr0_orig);
2867 2867 }
2868 2868
2869 2869 #endif /* !__xpv */
2870 2870
2871 2871 #if defined(_SOFT_HOSTID)
2872 2872 /*
2873 2873 * On platforms that do not have a hardware serial number, attempt
2874 2874 * to set one based on the contents of /etc/hostid. If this file does
2875 2875 * not exist, assume that we are to generate a new hostid and set
2876 2876 * it in the kernel, for subsequent saving by a userland process
2877 2877 * once the system is up and the root filesystem is mounted r/w.
2878 2878 *
2879 2879 * In order to gracefully support upgrade on OpenSolaris, if
2880 2880 * /etc/hostid does not exist, we will attempt to get a serial number
2881 2881 * using the legacy method (/kernel/misc/sysinit).
2882 2882 *
2883 2883 * If that isn't present, we attempt to use an SMBIOS UUID, which is
2884 2884 * a hardware serial number. Note that we don't automatically trust
2885 2885 * all SMBIOS UUIDs (some older platforms are defective and ship duplicate
2886 2886 * UUIDs in violation of the standard), we check against a blacklist.
2887 2887 *
2888 2888 * In an attempt to make the hostid less prone to abuse
2889 2889 * (for license circumvention, etc), we store it in /etc/hostid
2890 2890 * in rot47 format.
2891 2891 */
2892 2892 extern volatile unsigned long tenmicrodata;
2893 2893 static int atoi(char *);
2894 2894
2895 2895 /*
2896 2896 * Set this to non-zero in /etc/system if you think your SMBIOS returns a
2897 2897 * UUID that is not unique. (Also report it so that the smbios_uuid_blacklist
2898 2898 * array can be updated.)
2899 2899 */
2900 2900 int smbios_broken_uuid = 0;
2901 2901
2902 2902 /*
2903 2903 * List of known bad UUIDs. This is just the lower 32-bit values, since
2904 2904 * that's what we use for the host id. If your hostid falls here, you need
2905 2905 * to contact your hardware OEM for a fix for your BIOS.
2906 2906 */
2907 2907 static unsigned char
2908 2908 smbios_uuid_blacklist[][16] = {
2909 2909
2910 2910 { /* Reported bad UUID (Google search) */
2911 2911 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05,
2912 2912 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09,
2913 2913 },
2914 2914 { /* Known bad DELL UUID */
2915 2915 0x4C, 0x4C, 0x45, 0x44, 0x00, 0x00, 0x20, 0x10,
2916 2916 0x80, 0x20, 0x80, 0xC0, 0x4F, 0x20, 0x20, 0x20,
2917 2917 },
2918 2918 { /* Uninitialized flash */
2919 2919 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2920 2920 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2921 2921 },
2922 2922 { /* All zeros */
2923 2923 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2924 2924 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2925 2925 },
2926 2926 };
2927 2927
2928 2928 static int32_t
2929 2929 uuid_to_hostid(const uint8_t *uuid)
2930 2930 {
2931 2931 /*
2932 2932 * Although the UUIDs are 128-bits, they may not distribute entropy
2933 2933 * evenly. We would like to use SHA or MD5, but those are located
2934 2934 * in loadable modules and not available this early in boot. As we
2935 2935 * don't need the values to be cryptographically strong, we just
2936 2936 * generate 32-bit vaue by xor'ing the various sequences together,
2937 2937 * which ensures that the entire UUID contributes to the hostid.
2938 2938 */
2939 2939 uint32_t id = 0;
2940 2940
2941 2941 /* first check against the blacklist */
2942 2942 for (int i = 0; i < (sizeof (smbios_uuid_blacklist) / 16); i++) {
2943 2943 if (bcmp(smbios_uuid_blacklist[0], uuid, 16) == 0) {
2944 2944 cmn_err(CE_CONT, "?Broken SMBIOS UUID. "
2945 2945 "Contact BIOS manufacturer for repair.\n");
2946 2946 return ((int32_t)HW_INVALID_HOSTID);
2947 2947 }
2948 2948 }
2949 2949
2950 2950 for (int i = 0; i < 16; i++)
2951 2951 id ^= ((uuid[i]) << (8 * (i % sizeof (id))));
2952 2952
2953 2953 /* Make sure return value is positive */
2954 2954 return (id & 0x7fffffff);
2955 2955 }
2956 2956
2957 2957 static int32_t
2958 2958 set_soft_hostid(void)
2959 2959 {
2960 2960 struct _buf *file;
2961 2961 char tokbuf[MAXNAMELEN];
2962 2962 token_t token;
2963 2963 int done = 0;
2964 2964 u_longlong_t tmp;
2965 2965 int i;
2966 2966 int32_t hostid = (int32_t)HW_INVALID_HOSTID;
2967 2967 unsigned char *c;
2968 2968 hrtime_t tsc;
2969 2969 smbios_system_t smsys;
2970 2970
2971 2971 /*
2972 2972 * If /etc/hostid file not found, we'd like to get a pseudo
2973 2973 * random number to use at the hostid. A nice way to do this
2974 2974 * is to read the real time clock. To remain xen-compatible,
2975 2975 * we can't poke the real hardware, so we use tsc_read() to
2976 2976 * read the real time clock. However, there is an ominous
2977 2977 * warning in tsc_read that says it can return zero, so we
2978 2978 * deal with that possibility by falling back to using the
2979 2979 * (hopefully random enough) value in tenmicrodata.
2980 2980 */
2981 2981
2982 2982 if ((file = kobj_open_file(hostid_file)) == (struct _buf *)-1) {
2983 2983 /*
2984 2984 * hostid file not found - try to load sysinit module
2985 2985 * and see if it has a nonzero hostid value...use that
2986 2986 * instead of generating a new hostid here if so.
2987 2987 */
2988 2988 if ((i = modload("misc", "sysinit")) != -1) {
2989 2989 if (strlen(hw_serial) > 0)
2990 2990 hostid = (int32_t)atoi(hw_serial);
2991 2991 (void) modunload(i);
2992 2992 }
2993 2993
2994 2994 /*
2995 2995 * We try to use the SMBIOS UUID. But not if it is blacklisted
2996 2996 * in /etc/system.
2997 2997 */
2998 2998 if ((hostid == HW_INVALID_HOSTID) &&
2999 2999 (smbios_broken_uuid == 0) &&
3000 3000 (ksmbios != NULL) &&
3001 3001 (smbios_info_system(ksmbios, &smsys) != SMB_ERR) &&
3002 3002 (smsys.smbs_uuidlen >= 16)) {
3003 3003 hostid = uuid_to_hostid(smsys.smbs_uuid);
3004 3004 }
3005 3005
3006 3006 /*
3007 3007 * Generate a "random" hostid using the clock. These
3008 3008 * hostids will change on each boot if the value is not
3009 3009 * saved to a persistent /etc/hostid file.
3010 3010 */
3011 3011 if (hostid == HW_INVALID_HOSTID) {
3012 3012 tsc = tsc_read();
3013 3013 if (tsc == 0) /* tsc_read can return zero sometimes */
3014 3014 hostid = (int32_t)tenmicrodata & 0x0CFFFFF;
3015 3015 else
3016 3016 hostid = (int32_t)tsc & 0x0CFFFFF;
3017 3017 }
3018 3018 } else {
3019 3019 /* hostid file found */
3020 3020 while (!done) {
3021 3021 token = kobj_lex(file, tokbuf, sizeof (tokbuf));
3022 3022
3023 3023 switch (token) {
3024 3024 case POUND:
3025 3025 /*
3026 3026 * skip comments
3027 3027 */
3028 3028 kobj_find_eol(file);
3029 3029 break;
3030 3030 case STRING:
3031 3031 /*
3032 3032 * un-rot47 - obviously this
3033 3033 * nonsense is ascii-specific
3034 3034 */
3035 3035 for (c = (unsigned char *)tokbuf;
3036 3036 *c != '\0'; c++) {
3037 3037 *c += 47;
3038 3038 if (*c > '~')
3039 3039 *c -= 94;
3040 3040 else if (*c < '!')
3041 3041 *c += 94;
3042 3042 }
3043 3043 /*
3044 3044 * now we should have a real number
3045 3045 */
3046 3046
3047 3047 if (kobj_getvalue(tokbuf, &tmp) != 0)
3048 3048 kobj_file_err(CE_WARN, file,
3049 3049 "Bad value %s for hostid",
3050 3050 tokbuf);
3051 3051 else
3052 3052 hostid = (int32_t)tmp;
3053 3053
3054 3054 break;
3055 3055 case EOF:
3056 3056 done = 1;
3057 3057 /* FALLTHROUGH */
3058 3058 case NEWLINE:
3059 3059 kobj_newline(file);
3060 3060 break;
3061 3061 default:
3062 3062 break;
3063 3063
3064 3064 }
3065 3065 }
3066 3066 if (hostid == HW_INVALID_HOSTID) /* didn't find a hostid */
3067 3067 kobj_file_err(CE_WARN, file,
3068 3068 "hostid missing or corrupt");
3069 3069
3070 3070 kobj_close_file(file);
3071 3071 }
3072 3072 /*
3073 3073 * hostid is now the value read from /etc/hostid, or the
3074 3074 * new hostid we generated in this routine or HW_INVALID_HOSTID if not
3075 3075 * set.
3076 3076 */
3077 3077 return (hostid);
3078 3078 }
3079 3079
3080 3080 static int
3081 3081 atoi(char *p)
3082 3082 {
3083 3083 int i = 0;
3084 3084
3085 3085 while (*p != '\0')
3086 3086 i = 10 * i + (*p++ - '0');
3087 3087
3088 3088 return (i);
3089 3089 }
3090 3090
3091 3091 #endif /* _SOFT_HOSTID */
3092 3092
3093 3093 void
3094 3094 get_system_configuration(void)
3095 3095 {
3096 3096 char prop[32];
3097 3097 u_longlong_t nodes_ll, cpus_pernode_ll, lvalue;
3098 3098
3099 3099 if (BOP_GETPROPLEN(bootops, "nodes") > sizeof (prop) ||
3100 3100 BOP_GETPROP(bootops, "nodes", prop) < 0 ||
3101 3101 kobj_getvalue(prop, &nodes_ll) == -1 ||
3102 3102 nodes_ll > MAXNODES ||
3103 3103 BOP_GETPROPLEN(bootops, "cpus_pernode") > sizeof (prop) ||
3104 3104 BOP_GETPROP(bootops, "cpus_pernode", prop) < 0 ||
3105 3105 kobj_getvalue(prop, &cpus_pernode_ll) == -1) {
3106 3106 system_hardware.hd_nodes = 1;
3107 3107 system_hardware.hd_cpus_per_node = 0;
3108 3108 } else {
3109 3109 system_hardware.hd_nodes = (int)nodes_ll;
3110 3110 system_hardware.hd_cpus_per_node = (int)cpus_pernode_ll;
3111 3111 }
3112 3112
3113 3113 if (BOP_GETPROPLEN(bootops, "kernelbase") > sizeof (prop) ||
3114 3114 BOP_GETPROP(bootops, "kernelbase", prop) < 0 ||
3115 3115 kobj_getvalue(prop, &lvalue) == -1)
3116 3116 eprom_kernelbase = NULL;
3117 3117 else
3118 3118 eprom_kernelbase = (uintptr_t)lvalue;
3119 3119
3120 3120 if (BOP_GETPROPLEN(bootops, "segmapsize") > sizeof (prop) ||
3121 3121 BOP_GETPROP(bootops, "segmapsize", prop) < 0 ||
3122 3122 kobj_getvalue(prop, &lvalue) == -1)
3123 3123 segmapsize = SEGMAPDEFAULT;
3124 3124 else
3125 3125 segmapsize = (uintptr_t)lvalue;
3126 3126
3127 3127 if (BOP_GETPROPLEN(bootops, "segmapfreelists") > sizeof (prop) ||
3128 3128 BOP_GETPROP(bootops, "segmapfreelists", prop) < 0 ||
3129 3129 kobj_getvalue(prop, &lvalue) == -1)
3130 3130 segmapfreelists = 0; /* use segmap driver default */
3131 3131 else
3132 3132 segmapfreelists = (int)lvalue;
3133 3133
3134 3134 /* physmem used to be here, but moved much earlier to fakebop.c */
3135 3135 }
3136 3136
3137 3137 /*
3138 3138 * Add to a memory list.
3139 3139 * start = start of new memory segment
3140 3140 * len = length of new memory segment in bytes
3141 3141 * new = pointer to a new struct memlist
3142 3142 * memlistp = memory list to which to add segment.
3143 3143 */
3144 3144 void
3145 3145 memlist_add(
3146 3146 uint64_t start,
3147 3147 uint64_t len,
3148 3148 struct memlist *new,
3149 3149 struct memlist **memlistp)
3150 3150 {
3151 3151 struct memlist *cur;
3152 3152 uint64_t end = start + len;
3153 3153
3154 3154 new->ml_address = start;
3155 3155 new->ml_size = len;
3156 3156
3157 3157 cur = *memlistp;
3158 3158
3159 3159 while (cur) {
3160 3160 if (cur->ml_address >= end) {
3161 3161 new->ml_next = cur;
3162 3162 *memlistp = new;
3163 3163 new->ml_prev = cur->ml_prev;
3164 3164 cur->ml_prev = new;
3165 3165 return;
3166 3166 }
3167 3167 ASSERT(cur->ml_address + cur->ml_size <= start);
3168 3168 if (cur->ml_next == NULL) {
3169 3169 cur->ml_next = new;
3170 3170 new->ml_prev = cur;
3171 3171 new->ml_next = NULL;
3172 3172 return;
3173 3173 }
3174 3174 memlistp = &cur->ml_next;
3175 3175 cur = cur->ml_next;
3176 3176 }
3177 3177 }
3178 3178
3179 3179 void
3180 3180 kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena)
3181 3181 {
3182 3182 size_t tsize = e_modtext - modtext;
3183 3183 size_t dsize = e_moddata - moddata;
3184 3184
3185 3185 *text_arena = vmem_create("module_text", tsize ? modtext : NULL, tsize,
3186 3186 1, segkmem_alloc, segkmem_free, heaptext_arena, 0, VM_SLEEP);
3187 3187 *data_arena = vmem_create("module_data", dsize ? moddata : NULL, dsize,
3188 3188 1, segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP);
3189 3189 }
3190 3190
3191 3191 caddr_t
3192 3192 kobj_text_alloc(vmem_t *arena, size_t size)
3193 3193 {
3194 3194 return (vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT));
3195 3195 }
3196 3196
3197 3197 /*ARGSUSED*/
3198 3198 caddr_t
3199 3199 kobj_texthole_alloc(caddr_t addr, size_t size)
3200 3200 {
3201 3201 panic("unexpected call to kobj_texthole_alloc()");
3202 3202 /*NOTREACHED*/
3203 3203 return (0);
3204 3204 }
3205 3205
3206 3206 /*ARGSUSED*/
3207 3207 void
3208 3208 kobj_texthole_free(caddr_t addr, size_t size)
3209 3209 {
3210 3210 panic("unexpected call to kobj_texthole_free()");
3211 3211 }
3212 3212
3213 3213 /*
3214 3214 * This is called just after configure() in startup().
3215 3215 *
3216 3216 * The ISALIST concept is a bit hopeless on Intel, because
3217 3217 * there's no guarantee of an ever-more-capable processor
3218 3218 * given that various parts of the instruction set may appear
3219 3219 * and disappear between different implementations.
3220 3220 *
3221 3221 * While it would be possible to correct it and even enhance
3222 3222 * it somewhat, the explicit hardware capability bitmask allows
3223 3223 * more flexibility.
3224 3224 *
3225 3225 * So, we just leave this alone.
3226 3226 */
3227 3227 void
3228 3228 setx86isalist(void)
3229 3229 {
3230 3230 char *tp;
3231 3231 size_t len;
3232 3232 extern char *isa_list;
3233 3233
3234 3234 #define TBUFSIZE 1024
3235 3235
3236 3236 tp = kmem_alloc(TBUFSIZE, KM_SLEEP);
3237 3237 *tp = '\0';
3238 3238
3239 3239 #if defined(__amd64)
3240 3240 (void) strcpy(tp, "amd64 ");
3241 3241 #endif
3242 3242
3243 3243 switch (x86_vendor) {
3244 3244 case X86_VENDOR_Intel:
3245 3245 case X86_VENDOR_AMD:
3246 3246 case X86_VENDOR_TM:
3247 3247 if (is_x86_feature(x86_featureset, X86FSET_CMOV)) {
3248 3248 /*
3249 3249 * Pentium Pro or later
3250 3250 */
3251 3251 (void) strcat(tp, "pentium_pro");
3252 3252 (void) strcat(tp,
3253 3253 is_x86_feature(x86_featureset, X86FSET_MMX) ?
3254 3254 "+mmx pentium_pro " : " ");
3255 3255 }
3256 3256 /*FALLTHROUGH*/
3257 3257 case X86_VENDOR_Cyrix:
3258 3258 /*
3259 3259 * The Cyrix 6x86 does not have any Pentium features
3260 3260 * accessible while not at privilege level 0.
3261 3261 */
3262 3262 if (is_x86_feature(x86_featureset, X86FSET_CPUID)) {
3263 3263 (void) strcat(tp, "pentium");
3264 3264 (void) strcat(tp,
3265 3265 is_x86_feature(x86_featureset, X86FSET_MMX) ?
3266 3266 "+mmx pentium " : " ");
3267 3267 }
3268 3268 break;
3269 3269 default:
3270 3270 break;
3271 3271 }
3272 3272 (void) strcat(tp, "i486 i386 i86");
3273 3273 len = strlen(tp) + 1; /* account for NULL at end of string */
3274 3274 isa_list = strcpy(kmem_alloc(len, KM_SLEEP), tp);
3275 3275 kmem_free(tp, TBUFSIZE);
3276 3276
3277 3277 #undef TBUFSIZE
3278 3278 }
3279 3279
3280 3280
3281 3281 #ifdef __amd64
3282 3282
3283 3283 void *
3284 3284 device_arena_alloc(size_t size, int vm_flag)
3285 3285 {
3286 3286 return (vmem_alloc(device_arena, size, vm_flag));
3287 3287 }
3288 3288
3289 3289 void
3290 3290 device_arena_free(void *vaddr, size_t size)
3291 3291 {
3292 3292 vmem_free(device_arena, vaddr, size);
3293 3293 }
3294 3294
3295 3295 #else /* __i386 */
3296 3296
3297 3297 void *
3298 3298 device_arena_alloc(size_t size, int vm_flag)
3299 3299 {
3300 3300 caddr_t vaddr;
3301 3301 uintptr_t v;
3302 3302 size_t start;
3303 3303 size_t end;
3304 3304
3305 3305 vaddr = vmem_alloc(heap_arena, size, vm_flag);
3306 3306 if (vaddr == NULL)
3307 3307 return (NULL);
3308 3308
3309 3309 v = (uintptr_t)vaddr;
3310 3310 ASSERT(v >= kernelbase);
3311 3311 ASSERT(v + size <= valloc_base);
3312 3312
3313 3313 start = btop(v - kernelbase);
3314 3314 end = btop(v + size - 1 - kernelbase);
3315 3315 ASSERT(start < toxic_bit_map_len);
3316 3316 ASSERT(end < toxic_bit_map_len);
3317 3317
3318 3318 while (start <= end) {
3319 3319 BT_ATOMIC_SET(toxic_bit_map, start);
3320 3320 ++start;
3321 3321 }
3322 3322 return (vaddr);
3323 3323 }
3324 3324
3325 3325 void
3326 3326 device_arena_free(void *vaddr, size_t size)
3327 3327 {
3328 3328 uintptr_t v = (uintptr_t)vaddr;
3329 3329 size_t start;
3330 3330 size_t end;
3331 3331
3332 3332 ASSERT(v >= kernelbase);
3333 3333 ASSERT(v + size <= valloc_base);
3334 3334
3335 3335 start = btop(v - kernelbase);
3336 3336 end = btop(v + size - 1 - kernelbase);
3337 3337 ASSERT(start < toxic_bit_map_len);
3338 3338 ASSERT(end < toxic_bit_map_len);
3339 3339
3340 3340 while (start <= end) {
3341 3341 ASSERT(BT_TEST(toxic_bit_map, start) != 0);
3342 3342 BT_ATOMIC_CLEAR(toxic_bit_map, start);
3343 3343 ++start;
3344 3344 }
3345 3345 vmem_free(heap_arena, vaddr, size);
3346 3346 }
3347 3347
3348 3348 /*
3349 3349 * returns 1st address in range that is in device arena, or NULL
3350 3350 * if len is not NULL it returns the length of the toxic range
3351 3351 */
3352 3352 void *
3353 3353 device_arena_contains(void *vaddr, size_t size, size_t *len)
3354 3354 {
3355 3355 uintptr_t v = (uintptr_t)vaddr;
3356 3356 uintptr_t eaddr = v + size;
3357 3357 size_t start;
3358 3358 size_t end;
3359 3359
3360 3360 /*
3361 3361 * if called very early by kmdb, just return NULL
3362 3362 */
3363 3363 if (toxic_bit_map == NULL)
3364 3364 return (NULL);
3365 3365
3366 3366 /*
3367 3367 * First check if we're completely outside the bitmap range.
3368 3368 */
3369 3369 if (v >= valloc_base || eaddr < kernelbase)
3370 3370 return (NULL);
3371 3371
3372 3372 /*
3373 3373 * Trim ends of search to look at only what the bitmap covers.
3374 3374 */
3375 3375 if (v < kernelbase)
3376 3376 v = kernelbase;
3377 3377 start = btop(v - kernelbase);
3378 3378 end = btop(eaddr - kernelbase);
3379 3379 if (end >= toxic_bit_map_len)
3380 3380 end = toxic_bit_map_len;
3381 3381
3382 3382 if (bt_range(toxic_bit_map, &start, &end, end) == 0)
3383 3383 return (NULL);
3384 3384
3385 3385 v = kernelbase + ptob(start);
3386 3386 if (len != NULL)
3387 3387 *len = ptob(end - start);
3388 3388 return ((void *)v);
3389 3389 }
3390 3390
3391 3391 #endif /* __i386 */
↓ open down ↓ |
1038 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX