xref: /titanic_50/usr/src/uts/sun4v/os/fillsysinfo.c (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/errno.h>
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/cpu.h>
32 #include <sys/cpuvar.h>
33 #include <sys/clock.h>
34 #include <sys/promif.h>
35 #include <sys/promimpl.h>
36 #include <sys/systm.h>
37 #include <sys/machsystm.h>
38 #include <sys/debug.h>
39 #include <sys/sunddi.h>
40 #include <sys/modctl.h>
41 #include <sys/cpu_module.h>
42 #include <sys/kobj.h>
43 #include <sys/cmp.h>
44 #include <sys/async.h>
45 #include <vm/page.h>
46 #include <vm/hat_sfmmu.h>
47 #include <sys/sysmacros.h>
48 #include <sys/mach_descrip.h>
49 #include <sys/mdesc.h>
50 #include <sys/archsystm.h>
51 #include <sys/error.h>
52 #include <sys/mmu.h>
53 #include <sys/bitmap.h>
54 #include <sys/intreg.h>
55 
56 int ncpunode;
57 struct cpu_node cpunodes[NCPU];
58 
59 uint64_t cpu_q_entries;
60 uint64_t dev_q_entries;
61 uint64_t cpu_rq_entries;
62 uint64_t cpu_nrq_entries;
63 uint64_t ncpu_guest_max;
64 
65 void fill_cpu(md_t *, mde_cookie_t);
66 
67 static uint64_t get_mmu_ctx_bits(md_t *, mde_cookie_t);
68 static uint64_t get_cpu_pagesizes(md_t *, mde_cookie_t);
69 static char *construct_isalist(md_t *, mde_cookie_t, char **);
70 static void set_at_flags(char *, int, char **);
71 static void init_md_broken(md_t *, mde_cookie_t *);
72 static int get_l2_cache_info(md_t *, mde_cookie_t, uint64_t *, uint64_t *,
73     uint64_t *);
74 static id_t get_exec_unit_mapping(md_t *, mde_cookie_t, mde_cookie_t *);
75 static int find_exec_unit_id(mde_cookie_t, mde_cookie_t *);
76 static void get_q_sizes(md_t *, mde_cookie_t);
77 static void get_va_bits(md_t *, mde_cookie_t);
78 static size_t get_ra_limit(md_t *);
79 
80 uint64_t	system_clock_freq;
81 int		niobus = 0;
82 uint_t		niommu_tsbs = 0;
83 
84 /* prevent compilation with VAC defined */
85 #ifdef VAC
86 #error "The sun4v architecture does not support VAC"
87 #endif
88 
89 #define	S_VAC_SIZE	MMU_PAGESIZE
90 #define	S_VAC_SHIFT	MMU_PAGESHIFT
91 
92 int		vac_size = S_VAC_SIZE;
93 uint_t		vac_mask = MMU_PAGEMASK & (S_VAC_SIZE - 1);
94 int		vac_shift = S_VAC_SHIFT;
95 uintptr_t	shm_alignment = S_VAC_SIZE;
96 
97 void
98 map_wellknown_devices()
99 {
100 }
101 
102 void
103 fill_cpu(md_t *mdp, mde_cookie_t cpuc)
104 {
105 	struct cpu_node *cpunode;
106 	uint64_t cpuid;
107 	uint64_t clk_freq;
108 	char *namebuf;
109 	char *namebufp;
110 	int namelen;
111 	uint64_t associativity = 0, linesize = 0, size = 0;
112 
113 	if (md_get_prop_val(mdp, cpuc, "id", &cpuid)) {
114 		return;
115 	}
116 
117 	/* All out-of-range cpus will be stopped later. */
118 	if (cpuid >= NCPU) {
119 		cmn_err(CE_CONT, "fill_cpu: out of range cpuid %ld - "
120 		    "cpu excluded from configuration\n", cpuid);
121 
122 		return;
123 	}
124 
125 	cpunode = &cpunodes[cpuid];
126 	cpunode->cpuid = (int)cpuid;
127 	cpunode->device_id = cpuid;
128 
129 	if (sizeof (cpunode->fru_fmri) > strlen(CPU_FRU_FMRI))
130 		(void) strcpy(cpunode->fru_fmri, CPU_FRU_FMRI);
131 
132 	if (md_get_prop_data(mdp, cpuc,
133 	    "compatible", (uint8_t **)&namebuf, &namelen)) {
134 		cmn_err(CE_PANIC, "fill_cpu: Cannot read compatible "
135 		    "property");
136 	}
137 	namebufp = namebuf;
138 	if (strncmp(namebufp, "SUNW,", 5) == 0)
139 		namebufp += 5;
140 	if (strlen(namebufp) > sizeof (cpunode->name))
141 		cmn_err(CE_PANIC, "Compatible property too big to "
142 		    "fit into the cpunode name buffer");
143 	(void) strcpy(cpunode->name, namebufp);
144 
145 	if (md_get_prop_val(mdp, cpuc,
146 	    "clock-frequency", &clk_freq)) {
147 			clk_freq = 0;
148 	}
149 	cpunode->clock_freq = clk_freq;
150 
151 	ASSERT(cpunode->clock_freq != 0);
152 	/*
153 	 * Compute scaling factor based on rate of %tick. This is used
154 	 * to convert from ticks derived from %tick to nanoseconds. See
155 	 * comment in sun4u/sys/clock.h for details.
156 	 */
157 	cpunode->tick_nsec_scale = (uint_t)(((uint64_t)NANOSEC <<
158 	    (32 - TICK_NSEC_SHIFT)) / cpunode->clock_freq);
159 
160 	/*
161 	 * The nodeid is not used in sun4v at all. Setting it
162 	 * to positive value to make starting of slave CPUs
163 	 * code happy.
164 	 */
165 	cpunode->nodeid = cpuid + 1;
166 
167 	/*
168 	 * Obtain the L2 cache information from MD.
169 	 * If "Cache" node exists, then set L2 cache properties
170 	 * as read from MD.
171 	 * If node does not exists, then set the L2 cache properties
172 	 * in individual CPU module.
173 	 */
174 	if ((!get_l2_cache_info(mdp, cpuc,
175 	    &associativity, &size, &linesize)) ||
176 	    associativity == 0 || size == 0 || linesize == 0) {
177 		cpu_fiximp(cpunode);
178 	} else {
179 		/*
180 		 * Do not expect L2 cache properties to be bigger
181 		 * than 32-bit quantity.
182 		 */
183 		cpunode->ecache_associativity = (int)associativity;
184 		cpunode->ecache_size = (int)size;
185 		cpunode->ecache_linesize = (int)linesize;
186 	}
187 
188 	cpunode->ecache_setsize =
189 	    cpunode->ecache_size / cpunode->ecache_associativity;
190 
191 		/*
192 		 * Start off by assigning the cpu id as the default
193 		 * mapping index.
194 		 */
195 
196 	cpunode->exec_unit_mapping = NO_EU_MAPPING_FOUND;
197 
198 	if (ecache_setsize == 0)
199 		ecache_setsize = cpunode->ecache_setsize;
200 	if (ecache_alignsize == 0)
201 		ecache_alignsize = cpunode->ecache_linesize;
202 
203 	ncpunode++;
204 }
205 
206 void
207 empty_cpu(int cpuid)
208 {
209 	bzero(&cpunodes[cpuid], sizeof (struct cpu_node));
210 	ncpunode--;
211 }
212 
213 void
214 setup_exec_unit_mappings(md_t *mdp)
215 {
216 	uint64_t num, num_eunits;
217 	mde_cookie_t cpus_node;
218 	mde_cookie_t *node, *eunit;
219 	int idx, i, j;
220 	processorid_t cpuid;
221 	char *eunit_name = broken_md_flag ? "exec_unit" : "exec-unit";
222 	enum eu_type { INTEGER, FPU } etype;
223 
224 	/*
225 	 * Find the cpu integer exec units - and
226 	 * setup the mappings appropriately.
227 	 */
228 	num = md_alloc_scan_dag(mdp, md_root_node(mdp), "cpus", "fwd", &node);
229 	if (num < 1)
230 		cmn_err(CE_PANIC, "No cpus node in machine description");
231 	if (num > 1)
232 		cmn_err(CE_PANIC, "More than 1 cpus node in machine"
233 		    " description");
234 
235 	cpus_node = node[0];
236 	md_free_scan_dag(mdp, &node);
237 
238 	num_eunits = md_alloc_scan_dag(mdp, cpus_node, eunit_name,
239 	    "fwd", &eunit);
240 	if (num_eunits > 0) {
241 		char *int_str = broken_md_flag ? "int" : "integer";
242 		char *fpu_str = "fp";
243 
244 		/* Spin through and find all the integer exec units */
245 		for (i = 0; i < num_eunits; i++) {
246 			char *p;
247 			char *val;
248 			int vallen;
249 			uint64_t lcpuid;
250 
251 			/* ignore nodes with no type */
252 			if (md_get_prop_data(mdp, eunit[i], "type",
253 				(uint8_t **)&val, &vallen)) continue;
254 
255 			for (p = val; *p != '\0'; p += strlen(p) + 1) {
256 				if (strcmp(p, int_str) == 0) {
257 					etype = INTEGER;
258 					goto found;
259 				}
260 				if (strcmp(p, fpu_str) == 0) {
261 					etype = FPU;
262 					goto found;
263 				}
264 			}
265 
266 			continue;
267 found:
268 			idx = NCPU + i;
269 			/*
270 			 * find the cpus attached to this EU and
271 			 * update their mapping indices
272 			 */
273 			num = md_alloc_scan_dag(mdp, eunit[i], "cpu",
274 			    "back", &node);
275 
276 			if (num < 1)
277 				cmn_err(CE_PANIC, "exec-unit node in MD"
278 				    " not attached to a cpu node");
279 
280 			for (j = 0; j < num; j++) {
281 				if (md_get_prop_val(mdp, node[j], "id",
282 				    &lcpuid))
283 					continue;
284 				if (lcpuid >= NCPU)
285 					continue;
286 				cpuid = (processorid_t)lcpuid;
287 				switch (etype) {
288 				case INTEGER:
289 					cpunodes[cpuid].exec_unit_mapping = idx;
290 					break;
291 				case FPU:
292 					cpunodes[cpuid].fpu_mapping = idx;
293 					break;
294 				}
295 			}
296 			md_free_scan_dag(mdp, &node);
297 		}
298 
299 
300 		md_free_scan_dag(mdp, &eunit);
301 	}
302 }
303 
304 /*
305  * All the common setup of sun4v CPU modules is done by this routine.
306  */
307 void
308 cpu_setup_common(char **cpu_module_isa_set)
309 {
310 	extern int disable_delay_tlb_flush, delay_tlb_flush;
311 	extern int mmu_exported_pagesize_mask;
312 	int nocpus, i;
313 	size_t ra_limit;
314 	mde_cookie_t *cpulist;
315 	md_t *mdp;
316 
317 	if ((mdp = md_get_handle()) == NULL)
318 		cmn_err(CE_PANIC, "Unable to initialize machine description");
319 
320 	nocpus = md_alloc_scan_dag(mdp,
321 	    md_root_node(mdp), "cpu", "fwd", &cpulist);
322 	if (nocpus < 1) {
323 		cmn_err(CE_PANIC, "cpu_common_setup: cpulist allocation "
324 		    "failed or incorrect number of CPUs in MD");
325 	}
326 
327 	init_md_broken(mdp, cpulist);
328 
329 	if (use_page_coloring) {
330 		do_pg_coloring = 1;
331 		if (use_virtual_coloring) {
332 			/*
333 			 * XXX Sun4v cpus don't have virtual caches
334 			 */
335 			do_virtual_coloring = 1;
336 		}
337 	}
338 
339 	/*
340 	 * Get the valid mmu page sizes mask, Q sizes and isalist/r
341 	 * from the MD for the first available CPU in cpulist.
342 	 *
343 	 * Do not expect the MMU page sizes mask to be more than 32-bit.
344 	 */
345 	mmu_exported_pagesize_mask = (int)get_cpu_pagesizes(mdp, cpulist[0]);
346 
347 	for (i = 0; i < nocpus; i++)
348 		fill_cpu(mdp, cpulist[i]);
349 
350 	setup_exec_unit_mappings(mdp);
351 
352 	/*
353 	 * If MD is broken then append the passed ISA set,
354 	 * otherwise trust the MD.
355 	 */
356 
357 	if (broken_md_flag)
358 		isa_list = construct_isalist(mdp, cpulist[0],
359 		    cpu_module_isa_set);
360 	else
361 		isa_list = construct_isalist(mdp, cpulist[0], NULL);
362 
363 	get_q_sizes(mdp, cpulist[0]);
364 
365 	get_va_bits(mdp, cpulist[0]);
366 
367 	/*
368 	 * ra_limit is the highest real address in the machine.
369 	 */
370 	ra_limit = get_ra_limit(mdp);
371 
372 	md_free_scan_dag(mdp, &cpulist);
373 
374 	(void) md_fini_handle(mdp);
375 
376 	/*
377 	 * Block stores invalidate all pages of the d$ so pagecopy
378 	 * et. al. do not need virtual translations with virtual
379 	 * coloring taken into consideration.
380 	 */
381 	pp_consistent_coloring = 0;
382 
383 	/*
384 	 * The kpm mapping window.
385 	 * kpm_size:
386 	 *	The size of a single kpm range.
387 	 *	The overall size will be: kpm_size * vac_colors.
388 	 * kpm_vbase:
389 	 *	The virtual start address of the kpm range within the kernel
390 	 *	virtual address space. kpm_vbase has to be kpm_size aligned.
391 	 */
392 
393 	/*
394 	 * Make kpm_vbase, kpm_size aligned to kpm_size_shift.
395 	 * To do this find the nearest power of 2 size that the
396 	 * actual ra_limit fits within.
397 	 * If it is an even power of two use that, otherwise use the
398 	 * next power of two larger than ra_limit.
399 	 */
400 
401 	ASSERT(ra_limit != 0);
402 
403 	kpm_size_shift = (ra_limit & (ra_limit - 1)) != 0 ?
404 		highbit(ra_limit) : highbit(ra_limit) - 1;
405 
406 	/*
407 	 * No virtual caches on sun4v so size matches size shift
408 	 */
409 	kpm_size = 1ul << kpm_size_shift;
410 
411 	if (va_bits < VA_ADDRESS_SPACE_BITS) {
412 		/*
413 		 * In case of VA hole
414 		 * kpm_base = hole_end + 1TB
415 		 * Starting 1TB beyond where VA hole ends because on Niagara
416 		 * processor software must not use pages within 4GB of the
417 		 * VA hole as instruction pages to avoid problems with
418 		 * prefetching into the VA hole.
419 		 */
420 		kpm_vbase = (caddr_t)((0ull - (1ull << (va_bits - 1))) +
421 		    (1ull << 40));
422 	} else {		/* Number of VA bits 64 ... no VA hole */
423 		kpm_vbase = (caddr_t)0x8000000000000000ull;	/* 8 EB */
424 	}
425 
426 	/*
427 	 * The traptrace code uses either %tick or %stick for
428 	 * timestamping.  The sun4v require use of %stick.
429 	 */
430 	traptrace_use_stick = 1;
431 
432 	/*
433 	 * sun4v provides demap_all
434 	 */
435 	if (!disable_delay_tlb_flush)
436 		delay_tlb_flush = 1;
437 }
438 
439 /*
440  * Get the nctxs from MD. If absent panic.
441  */
442 static uint64_t
443 get_mmu_ctx_bits(md_t *mdp, mde_cookie_t cpu_node_cookie)
444 {
445 	uint64_t ctx_bits;
446 
447 	if (md_get_prop_val(mdp, cpu_node_cookie, "mmu-#context-bits",
448 	    &ctx_bits))
449 		ctx_bits = 0;
450 
451 	if (ctx_bits < MIN_NCTXS_BITS || ctx_bits > MAX_NCTXS_BITS)
452 		cmn_err(CE_PANIC, "Incorrect %ld number of contexts bits "
453 		    "returned by MD", ctx_bits);
454 
455 	return (ctx_bits);
456 }
457 
458 /*
459  * Initalize supported page sizes information.
460  * Set to 0, if the page sizes mask information is absent in MD.
461  */
462 static uint64_t
463 get_cpu_pagesizes(md_t *mdp, mde_cookie_t cpu_node_cookie)
464 {
465 	uint64_t mmu_page_size_list;
466 
467 	if (md_get_prop_val(mdp, cpu_node_cookie, "mmu-page-size-list",
468 	    &mmu_page_size_list))
469 		mmu_page_size_list = 0;
470 
471 	if (mmu_page_size_list == 0 || mmu_page_size_list > MAX_PAGESIZE_MASK)
472 		cmn_err(CE_PANIC, "Incorrect 0x%lx pagesize mask returned"
473 		    "by MD", mmu_page_size_list);
474 
475 	return (mmu_page_size_list);
476 }
477 
478 /*
479  * This routine gets the isalist information from MD and appends
480  * the CPU module ISA set if required.
481  */
482 static char *
483 construct_isalist(md_t *mdp, mde_cookie_t cpu_node_cookie,
484     char **cpu_module_isa_set)
485 {
486 	extern int at_flags;
487 	char *md_isalist;
488 	int md_isalen;
489 	char *isabuf;
490 	int isalen;
491 	char **isa_set;
492 	char *p, *q;
493 	int cpu_module_isalen = 0, found = 0;
494 
495 	(void) md_get_prop_data(mdp, cpu_node_cookie,
496 	    "isalist", (uint8_t **)&isabuf, &isalen);
497 
498 	/*
499 	 * We support binaries for all the cpus that have shipped so far.
500 	 * The kernel emulates instructions that are not supported by hardware.
501 	 */
502 	at_flags = EF_SPARC_SUN_US3 | EF_SPARC_32PLUS | EF_SPARC_SUN_US1;
503 
504 	/*
505 	 * Construct the space separated isa_list.
506 	 */
507 	if (cpu_module_isa_set != NULL) {
508 		for (isa_set = cpu_module_isa_set; *isa_set != NULL;
509 		    isa_set++) {
510 			cpu_module_isalen += strlen(*isa_set);
511 			cpu_module_isalen++;	/* for space character */
512 		}
513 	}
514 
515 	/*
516 	 * Allocate the buffer of MD isa buffer length + CPU module
517 	 * isa buffer length.
518 	 */
519 	md_isalen = isalen + cpu_module_isalen + 2;
520 	md_isalist = (char *)prom_alloc((caddr_t)0, md_isalen, 0);
521 	if (md_isalist == NULL)
522 		cmn_err(CE_PANIC, "construct_isalist: Allocation failed for "
523 		    "md_isalist");
524 
525 	md_isalist[0] = '\0'; /* create an empty string to start */
526 	for (p = isabuf, q = p + isalen; p < q; p += strlen(p) + 1) {
527 		(void) strlcat(md_isalist, p, md_isalen);
528 		(void) strcat(md_isalist, " ");
529 	}
530 
531 	/*
532 	 * Check if the isa_set is present in isalist returned by MD.
533 	 * If yes, then no need to append it, if no then append it to
534 	 * isalist returned by MD.
535 	 */
536 	if (cpu_module_isa_set != NULL) {
537 		for (isa_set = cpu_module_isa_set; *isa_set != NULL;
538 		    isa_set++) {
539 			found = 0;
540 			for (p = isabuf, q = p + isalen; p < q;
541 			    p += strlen(p) + 1) {
542 				if (strcmp(p, *isa_set) == 0) {
543 					found = 1;
544 					break;
545 				}
546 			}
547 			if (!found) {
548 				(void) strlcat(md_isalist, *isa_set, md_isalen);
549 				(void) strcat(md_isalist, " ");
550 			}
551 		}
552 	}
553 
554 	/* Get rid of any trailing white spaces */
555 	md_isalist[strlen(md_isalist) - 1] = '\0';
556 
557 	return (md_isalist);
558 }
559 
560 uint64_t
561 get_ra_limit(md_t *mdp)
562 {
563 	mde_cookie_t *mem_list;
564 	mde_cookie_t *mblock_list;
565 	int i;
566 	int memnodes;
567 	int nmblock;
568 	uint64_t base;
569 	uint64_t size;
570 	uint64_t ra_limit = 0, new_limit = 0;
571 
572 	memnodes = md_alloc_scan_dag(mdp,
573 	    md_root_node(mdp), "memory", "fwd", &mem_list);
574 
575 	ASSERT(memnodes == 1);
576 
577 	nmblock = md_alloc_scan_dag(mdp,
578 	    mem_list[0], "mblock", "fwd", &mblock_list);
579 	if (nmblock < 1)
580 		cmn_err(CE_PANIC, "cannot find mblock nodes in MD");
581 
582 	for (i = 0; i < nmblock; i++) {
583 		if (md_get_prop_val(mdp, mblock_list[i], "base", &base))
584 			cmn_err(CE_PANIC, "base property missing from MD"
585 			    " mblock node");
586 		if (md_get_prop_val(mdp, mblock_list[i], "size", &size))
587 			cmn_err(CE_PANIC, "size property missing from MD"
588 			    " mblock node");
589 
590 		ASSERT(size != 0);
591 
592 		new_limit = base + size;
593 
594 		if (base > new_limit)
595 			cmn_err(CE_PANIC, "mblock in MD wrapped around");
596 
597 		if (new_limit > ra_limit)
598 		    ra_limit = new_limit;
599 	}
600 
601 	ASSERT(ra_limit != 0);
602 
603 	if (ra_limit > MAX_REAL_ADDRESS) {
604 		cmn_err(CE_WARN, "Highest real address in MD too large"
605 		    " clipping to %llx\n", MAX_REAL_ADDRESS);
606 		ra_limit = MAX_REAL_ADDRESS;
607 	}
608 
609 	md_free_scan_dag(mdp, &mblock_list);
610 
611 	md_free_scan_dag(mdp, &mem_list);
612 
613 	return (ra_limit);
614 }
615 
616 /*
617  * This routine sets the globals for CPU and DEV mondo queue entries and
618  * resumable and non-resumable error queue entries.
619  *
620  * First, look up the number of bits available to pass an entry number.
621  * This can vary by platform and may result in allocating an unreasonably
622  * (or impossibly) large amount of memory for the corresponding table,
623  * so we clamp it by 'max_entries'.  If the prop is missing, use
624  * 'default_entries'.
625  */
626 static uint64_t
627 get_single_q_size(md_t *mdp, mde_cookie_t cpu_node_cookie,
628     char *qnamep, uint64_t default_entries, uint64_t max_entries)
629 {
630 	uint64_t entries;
631 
632 	if (default_entries > max_entries)
633 		cmn_err(CE_CONT, "!get_single_q_size: dflt %ld > "
634 		    "max %ld for %s\n", default_entries, max_entries, qnamep);
635 
636 	if (md_get_prop_val(mdp, cpu_node_cookie, qnamep, &entries)) {
637 		if (!broken_md_flag)
638 			cmn_err(CE_PANIC, "Missing %s property in MD cpu node",
639 				qnamep);
640 		entries = default_entries;
641 	} else {
642 		entries = 1 << entries;
643 	}
644 
645 	entries = MIN(entries, max_entries);
646 
647 	return (entries);
648 }
649 
650 /* Scaling constant used to compute size of cpu mondo queue */
651 #define	CPU_MONDO_Q_MULTIPLIER	8
652 
653 static void
654 get_q_sizes(md_t *mdp, mde_cookie_t cpu_node_cookie)
655 {
656 	uint64_t max_qsize;
657 	mde_cookie_t *platlist;
658 	int nrnode;
659 
660 	/*
661 	 * Compute the maximum number of entries for the cpu mondo queue.
662 	 * Use the appropriate property in the platform node, if it is
663 	 * available.  Else, base it on NCPU.
664 	 */
665 	nrnode = md_alloc_scan_dag(mdp,
666 	    md_root_node(mdp), "platform", "fwd", &platlist);
667 
668 	ASSERT(nrnode == 1);
669 
670 	ncpu_guest_max = NCPU;
671 	(void) md_get_prop_val(mdp, platlist[0], "max-cpus", &ncpu_guest_max);
672 	max_qsize = ncpu_guest_max * CPU_MONDO_Q_MULTIPLIER;
673 
674 	md_free_scan_dag(mdp, &platlist);
675 
676 	cpu_q_entries = get_single_q_size(mdp, cpu_node_cookie,
677 	    "q-cpu-mondo-#bits", DEFAULT_CPU_Q_ENTRIES, max_qsize);
678 
679 	dev_q_entries = get_single_q_size(mdp, cpu_node_cookie,
680 	    "q-dev-mondo-#bits", DEFAULT_DEV_Q_ENTRIES, MAXIVNUM);
681 
682 	cpu_rq_entries = get_single_q_size(mdp, cpu_node_cookie,
683 	    "q-resumable-#bits", CPU_RQ_ENTRIES, MAX_CPU_RQ_ENTRIES);
684 
685 	cpu_nrq_entries = get_single_q_size(mdp, cpu_node_cookie,
686 	    "q-nonresumable-#bits", CPU_NRQ_ENTRIES, MAX_CPU_NRQ_ENTRIES);
687 }
688 
689 
690 static void
691 get_va_bits(md_t *mdp, mde_cookie_t cpu_node_cookie)
692 {
693 	uint64_t value = VA_ADDRESS_SPACE_BITS;
694 
695 	if (md_get_prop_val(mdp, cpu_node_cookie, "mmu-#va-bits", &value))
696 		cmn_err(CE_PANIC, "mmu-#va-bits property  not found in MD");
697 
698 
699 	if (value == 0 || value > VA_ADDRESS_SPACE_BITS)
700 		cmn_err(CE_PANIC, "Incorrect number of va bits in MD");
701 
702 	/* Do not expect number of VA bits to be more than 32-bit quantity */
703 
704 	va_bits = (int)value;
705 
706 	/*
707 	 * Correct the value for VA bits on UltraSPARC-T1 based systems
708 	 * in case of broken MD.
709 	 */
710 	if (broken_md_flag)
711 		va_bits = DEFAULT_VA_ADDRESS_SPACE_BITS;
712 }
713 
714 /*
715  * This routine returns the L2 cache information such as -- associativity,
716  * size and linesize.
717  */
718 static int
719 get_l2_cache_info(md_t *mdp, mde_cookie_t cpu_node_cookie,
720 	    uint64_t *associativity, uint64_t *size, uint64_t *linesize)
721 {
722 	mde_cookie_t *cachelist;
723 	int ncaches, i;
724 	uint64_t max_level;
725 
726 	ncaches = md_alloc_scan_dag(mdp, cpu_node_cookie, "cache",
727 	    "fwd", &cachelist);
728 	/*
729 	 * The "cache" node is optional in MD, therefore ncaches can be 0.
730 	 */
731 	if (ncaches < 1) {
732 		return (0);
733 	}
734 
735 	max_level = 0;
736 	for (i = 0; i < ncaches; i++) {
737 		uint64_t cache_level;
738 		uint64_t local_assoc;
739 		uint64_t local_size;
740 		uint64_t local_lsize;
741 
742 		if (md_get_prop_val(mdp, cachelist[i], "level", &cache_level))
743 			continue;
744 
745 		if (cache_level <= max_level) continue;
746 
747 		/* If properties are missing from this cache ignore it */
748 
749 		if ((md_get_prop_val(mdp, cachelist[i],
750 		    "associativity", &local_assoc))) {
751 			continue;
752 		}
753 
754 		if ((md_get_prop_val(mdp, cachelist[i],
755 		    "size", &local_size))) {
756 			continue;
757 		}
758 
759 		if ((md_get_prop_val(mdp, cachelist[i],
760 		    "line-size", &local_lsize))) {
761 			continue;
762 		}
763 
764 		max_level = cache_level;
765 		*associativity = local_assoc;
766 		*size = local_size;
767 		*linesize = local_lsize;
768 	}
769 
770 	md_free_scan_dag(mdp, &cachelist);
771 
772 	return ((max_level > 0) ? 1 : 0);
773 }
774 
775 
776 /*
777  * Set the broken_md_flag to 1 if the MD doesn't have
778  * the domaining-enabled property in the platform node and the
779  * platform uses the UltraSPARC-T1 cpu. This flag is used to
780  * workaround some of the incorrect MD properties.
781  */
782 static void
783 init_md_broken(md_t *mdp, mde_cookie_t *cpulist)
784 {
785 	int nrnode;
786 	mde_cookie_t *platlist, rootnode;
787 	uint64_t val = 0;
788 	char *namebuf;
789 	int namelen;
790 
791 	rootnode = md_root_node(mdp);
792 	ASSERT(rootnode != MDE_INVAL_ELEM_COOKIE);
793 	ASSERT(cpulist);
794 
795 	nrnode = md_alloc_scan_dag(mdp, rootnode, "platform", "fwd",
796 	    &platlist);
797 
798 	if (nrnode < 1)
799 		cmn_err(CE_PANIC, "init_md_broken: platform node missing");
800 
801 	if (md_get_prop_data(mdp, cpulist[0],
802 	    "compatible", (uint8_t **)&namebuf, &namelen)) {
803 		cmn_err(CE_PANIC, "init_md_broken: "
804 		    "Cannot read 'compatible' property of 'cpu' node");
805 	}
806 
807 	if (md_get_prop_val(mdp, platlist[0],
808 		"domaining-enabled", &val) == -1 &&
809 	    strcmp(namebuf, "SUNW,UltraSPARC-T1") == 0)
810 		broken_md_flag = 1;
811 
812 	md_free_scan_dag(mdp, &platlist);
813 }
814