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