xref: /titanic_52/usr/src/uts/sun4u/opl/os/opl.c (revision a2cedc52cb05701ca77d7e4b4f4aa95448b52ed5)
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/cpuvar.h>
29 #include <sys/systm.h>
30 #include <sys/sysmacros.h>
31 #include <sys/promif.h>
32 #include <sys/platform_module.h>
33 #include <sys/cmn_err.h>
34 #include <sys/errno.h>
35 #include <sys/machsystm.h>
36 #include <sys/bootconf.h>
37 #include <sys/nvpair.h>
38 #include <sys/kobj.h>
39 #include <sys/mem_cage.h>
40 #include <sys/opl.h>
41 #include <sys/scfd/scfostoescf.h>
42 #include <sys/cpu_sgnblk_defs.h>
43 #include <sys/utsname.h>
44 #include <sys/ddi.h>
45 #include <sys/sunndi.h>
46 #include <sys/lgrp.h>
47 #include <sys/memnode.h>
48 #include <sys/sysmacros.h>
49 #include <vm/vm_dep.h>
50 
51 int (*opl_get_mem_unum)(int, uint64_t, char *, int, int *);
52 int (*opl_get_mem_sid)(char *unum, char *buf, int buflen, int *lenp);
53 int (*opl_get_mem_offset)(uint64_t paddr, uint64_t *offp);
54 int (*opl_get_mem_addr)(char *unum, char *sid,
55     uint64_t offset, uint64_t *paddr);
56 
57 /* Memory for fcode claims.  16k times # maximum possible IO units */
58 #define	EFCODE_SIZE	(OPL_MAX_BOARDS * OPL_MAX_IO_UNITS_PER_BOARD * 0x4000)
59 int efcode_size = EFCODE_SIZE;
60 
61 #define	OPL_MC_MEMBOARD_SHIFT 38	/* Boards on 256BG boundary */
62 
63 /* Set the maximum number of boards for DR */
64 int opl_boards = OPL_MAX_BOARDS;
65 
66 void sgn_update_all_cpus(ushort_t, uchar_t, uchar_t);
67 
68 extern int tsb_lgrp_affinity;
69 
70 int opl_tsb_spares = (OPL_MAX_BOARDS) * (OPL_MAX_PCICH_UNITS_PER_BOARD) *
71 	(OPL_MAX_TSBS_PER_PCICH);
72 
73 pgcnt_t opl_startup_cage_size = 0;
74 
75 static opl_model_info_t opl_models[] = {
76 	{ "FF1", OPL_MAX_BOARDS_FF1 },
77 	{ "FF2", OPL_MAX_BOARDS_FF2 },
78 	{ "DC1", OPL_MAX_BOARDS_DC1 },
79 	{ "DC2", OPL_MAX_BOARDS_DC2 },
80 	{ "DC3", OPL_MAX_BOARDS_DC3 },
81 };
82 static	int	opl_num_models = sizeof (opl_models)/sizeof (opl_model_info_t);
83 
84 static	opl_model_info_t *opl_cur_model = NULL;
85 
86 static struct memlist *opl_memlist_per_board(struct memlist *ml);
87 
88 static enum {
89 	MODEL_FF1 = 0,
90 	MODEL_FF2 = 1,
91 	MODEL_DC = 2
92 } plat_model = -1;
93 
94 int
95 set_platform_max_ncpus(void)
96 {
97 	return (OPL_MAX_CPU_PER_BOARD * OPL_MAX_BOARDS);
98 }
99 
100 int
101 set_platform_tsb_spares(void)
102 {
103 	return (MIN(opl_tsb_spares, MAX_UPA));
104 }
105 
106 static void
107 set_model_info()
108 {
109 	char	name[MAXSYSNAME];
110 	int	i;
111 
112 	/*
113 	 * Get model name from the root node.
114 	 *
115 	 * We are using the prom device tree since, at this point,
116 	 * the Solaris device tree is not yet setup.
117 	 */
118 	(void) prom_getprop(prom_rootnode(), "model", (caddr_t)name);
119 
120 	for (i = 0; i < opl_num_models; i++) {
121 		if (strncmp(name, opl_models[i].model_name, MAXSYSNAME) == 0) {
122 			opl_cur_model = &opl_models[i];
123 			break;
124 		}
125 	}
126 	if (i == opl_num_models)
127 		cmn_err(CE_WARN, "No valid OPL model is found!"
128 		    "Set max_mmu_ctxdoms to the default.");
129 }
130 
131 static void
132 set_max_mmu_ctxdoms()
133 {
134 	extern uint_t	max_mmu_ctxdoms;
135 	int		max_boards;
136 
137 	/*
138 	 * From the model, get the maximum number of boards
139 	 * supported and set the value accordingly. If the model
140 	 * could not be determined or recognized, we assume the max value.
141 	 */
142 	if (opl_cur_model == NULL)
143 		max_boards = OPL_MAX_BOARDS;
144 	else
145 		max_boards = opl_cur_model->model_max_boards;
146 
147 	/*
148 	 * On OPL, cores and MMUs are one-to-one.
149 	 */
150 	max_mmu_ctxdoms = OPL_MAX_CORE_UNITS_PER_BOARD * max_boards;
151 }
152 
153 #pragma weak mmu_init_large_pages
154 
155 void
156 set_platform_defaults(void)
157 {
158 	extern char *tod_module_name;
159 	extern void cpu_sgn_update(ushort_t, uchar_t, uchar_t, int);
160 	extern int ts_dispatch_extended;
161 	extern void mmu_init_large_pages(size_t);
162 
163 	/* Set the CPU signature function pointer */
164 	cpu_sgn_func = cpu_sgn_update;
165 
166 	/* Set appropriate tod module for OPL platform */
167 	ASSERT(tod_module_name == NULL);
168 	tod_module_name = "todopl";
169 
170 	/*
171 	 * Use the alternate TS dispatch table, which is better tuned
172 	 * for large servers.
173 	 */
174 	if (ts_dispatch_extended == -1)
175 		ts_dispatch_extended = 1;
176 
177 	if ((mmu_page_sizes == max_mmu_page_sizes) &&
178 	    (mmu_ism_pagesize != DEFAULT_ISM_PAGESIZE)) {
179 		if (&mmu_init_large_pages)
180 			mmu_init_large_pages(mmu_ism_pagesize);
181 	}
182 
183 	tsb_lgrp_affinity = 1;
184 
185 	set_model_info();
186 	set_max_mmu_ctxdoms();
187 }
188 
189 /*
190  * Convert logical a board number to a physical one.
191  */
192 
193 #define	LSBPROP		"board#"
194 #define	PSBPROP		"physical-board#"
195 
196 int
197 opl_get_physical_board(int id)
198 {
199 	dev_info_t	*root_dip, *dip = NULL;
200 	char		*dname = NULL;
201 	int		circ;
202 
203 	pnode_t		pnode;
204 	char		pname[MAXSYSNAME] = {0};
205 
206 	int		lsb_id;	/* Logical System Board ID */
207 	int		psb_id;	/* Physical System Board ID */
208 
209 
210 	/*
211 	 * This function is called on early stage of bootup when the
212 	 * kernel device tree is not initialized yet, and also
213 	 * later on when the device tree is up. We want to try
214 	 * the fast track first.
215 	 */
216 	root_dip = ddi_root_node();
217 	if (root_dip) {
218 		/* Get from devinfo node */
219 		ndi_devi_enter(root_dip, &circ);
220 		for (dip = ddi_get_child(root_dip); dip;
221 		    dip = ddi_get_next_sibling(dip)) {
222 
223 			dname = ddi_node_name(dip);
224 			if (strncmp(dname, "pseudo-mc", 9) != 0)
225 				continue;
226 
227 			if ((lsb_id = (int)ddi_getprop(DDI_DEV_T_ANY, dip,
228 			    DDI_PROP_DONTPASS, LSBPROP, -1)) == -1)
229 				continue;
230 
231 			if (id == lsb_id) {
232 				if ((psb_id = (int)ddi_getprop(DDI_DEV_T_ANY,
233 				    dip, DDI_PROP_DONTPASS, PSBPROP, -1))
234 				    == -1) {
235 					ndi_devi_exit(root_dip, circ);
236 					return (-1);
237 				} else {
238 					ndi_devi_exit(root_dip, circ);
239 					return (psb_id);
240 				}
241 			}
242 		}
243 		ndi_devi_exit(root_dip, circ);
244 	}
245 
246 	/*
247 	 * We do not have the kernel device tree, or we did not
248 	 * find the node for some reason (let's say the kernel
249 	 * device tree was modified), let's try the OBP tree.
250 	 */
251 	pnode = prom_rootnode();
252 	for (pnode = prom_childnode(pnode); pnode;
253 	    pnode = prom_nextnode(pnode)) {
254 
255 		if ((prom_getprop(pnode, "name", (caddr_t)pname) == -1) ||
256 		    (strncmp(pname, "pseudo-mc", 9) != 0))
257 			continue;
258 
259 		if (prom_getprop(pnode, LSBPROP, (caddr_t)&lsb_id) == -1)
260 			continue;
261 
262 		if (id == lsb_id) {
263 			if (prom_getprop(pnode, PSBPROP,
264 			    (caddr_t)&psb_id) == -1) {
265 				return (-1);
266 			} else {
267 				return (psb_id);
268 			}
269 		}
270 	}
271 
272 	return (-1);
273 }
274 
275 /*
276  * For OPL it's possible that memory from two or more successive boards
277  * will be contiguous across the boards, and therefore represented as a
278  * single chunk.
279  * This function splits such chunks down the board boundaries.
280  */
281 static struct memlist *
282 opl_memlist_per_board(struct memlist *ml)
283 {
284 	uint64_t ssize, low, high, boundary;
285 	struct memlist *head, *tail, *new;
286 
287 	ssize = (1ull << OPL_MC_MEMBOARD_SHIFT);
288 
289 	head = tail = NULL;
290 
291 	for (; ml; ml = ml->next) {
292 		low  = (uint64_t)ml->address;
293 		high = low+(uint64_t)(ml->size);
294 		while (low < high) {
295 			boundary = roundup(low+1, ssize);
296 			boundary = MIN(high, boundary);
297 			new = kmem_zalloc(sizeof (struct memlist), KM_SLEEP);
298 			new->address = low;
299 			new->size = boundary - low;
300 			if (head == NULL)
301 				head = new;
302 			if (tail) {
303 				tail->next = new;
304 				new->prev = tail;
305 			}
306 			tail = new;
307 			low = boundary;
308 		}
309 	}
310 	return (head);
311 }
312 
313 void
314 set_platform_cage_params(void)
315 {
316 	extern pgcnt_t total_pages;
317 	extern struct memlist *phys_avail;
318 	struct memlist *ml, *tml;
319 	int ret;
320 
321 	if (kernel_cage_enable) {
322 		pgcnt_t preferred_cage_size;
323 
324 		preferred_cage_size =
325 			MAX(opl_startup_cage_size, total_pages / 256);
326 
327 		ml = opl_memlist_per_board(phys_avail);
328 
329 		kcage_range_lock();
330 		/*
331 		 * Note: we are assuming that post has load the
332 		 * whole show in to the high end of memory. Having
333 		 * taken this leap, we copy the whole of phys_avail
334 		 * the glist and arrange for the cage to grow
335 		 * downward (descending pfns).
336 		 */
337 		ret = kcage_range_init(ml, 1);
338 
339 		/* free the memlist */
340 		do {
341 			tml = ml->next;
342 			kmem_free(ml, sizeof (struct memlist));
343 			ml = tml;
344 		} while (ml != NULL);
345 
346 		if (ret == 0)
347 			kcage_init(preferred_cage_size);
348 		kcage_range_unlock();
349 	}
350 
351 	if (kcage_on)
352 		cmn_err(CE_NOTE, "!DR Kernel Cage is ENABLED");
353 	else
354 		cmn_err(CE_NOTE, "!DR Kernel Cage is DISABLED");
355 }
356 
357 /*ARGSUSED*/
358 int
359 plat_cpu_poweron(struct cpu *cp)
360 {
361 	int (*opl_cpu_poweron)(struct cpu *) = NULL;
362 
363 	opl_cpu_poweron =
364 	    (int (*)(struct cpu *))kobj_getsymvalue("drmach_cpu_poweron", 0);
365 
366 	if (opl_cpu_poweron == NULL)
367 		return (ENOTSUP);
368 	else
369 		return ((opl_cpu_poweron)(cp));
370 
371 }
372 
373 /*ARGSUSED*/
374 int
375 plat_cpu_poweroff(struct cpu *cp)
376 {
377 	int (*opl_cpu_poweroff)(struct cpu *) = NULL;
378 
379 	opl_cpu_poweroff =
380 	    (int (*)(struct cpu *))kobj_getsymvalue("drmach_cpu_poweroff", 0);
381 
382 	if (opl_cpu_poweroff == NULL)
383 		return (ENOTSUP);
384 	else
385 		return ((opl_cpu_poweroff)(cp));
386 
387 }
388 
389 int
390 plat_max_boards(void)
391 {
392 	return (OPL_MAX_BOARDS);
393 }
394 
395 int
396 plat_max_cpu_units_per_board(void)
397 {
398 	return (OPL_MAX_CPU_PER_BOARD);
399 }
400 
401 int
402 plat_max_mem_units_per_board(void)
403 {
404 	return (OPL_MAX_MEM_UNITS_PER_BOARD);
405 }
406 
407 int
408 plat_max_io_units_per_board(void)
409 {
410 	return (OPL_MAX_IO_UNITS_PER_BOARD);
411 }
412 
413 int
414 plat_max_cmp_units_per_board(void)
415 {
416 	return (OPL_MAX_CMP_UNITS_PER_BOARD);
417 }
418 
419 int
420 plat_max_core_units_per_board(void)
421 {
422 	return (OPL_MAX_CORE_UNITS_PER_BOARD);
423 }
424 
425 int
426 plat_pfn_to_mem_node(pfn_t pfn)
427 {
428 	return (pfn >> mem_node_pfn_shift);
429 }
430 
431 /* ARGSUSED */
432 void
433 plat_build_mem_nodes(u_longlong_t *list, size_t nelems)
434 {
435 	size_t	elem;
436 	pfn_t	basepfn;
437 	pgcnt_t	npgs;
438 	uint64_t	boundary, ssize;
439 	uint64_t	low, high;
440 
441 	/*
442 	 * OPL mem slices are always aligned on a 256GB boundary.
443 	 */
444 	mem_node_pfn_shift = OPL_MC_MEMBOARD_SHIFT - MMU_PAGESHIFT;
445 	mem_node_physalign = 0;
446 
447 	/*
448 	 * Boot install lists are arranged <addr, len>, <addr, len>, ...
449 	 */
450 	ssize = (1ull << OPL_MC_MEMBOARD_SHIFT);
451 	for (elem = 0; elem < nelems; elem += 2) {
452 		low  = (uint64_t)list[elem];
453 		high = low+(uint64_t)(list[elem+1]);
454 		while (low < high) {
455 			boundary = roundup(low+1, ssize);
456 			boundary = MIN(high, boundary);
457 			basepfn = btop(low);
458 			npgs = btop(boundary - low);
459 			mem_node_add_slice(basepfn, basepfn + npgs - 1);
460 			low = boundary;
461 		}
462 	}
463 }
464 
465 /*
466  * Find the CPU associated with a slice at boot-time.
467  */
468 void
469 plat_fill_mc(pnode_t nodeid)
470 {
471 	int board;
472 	int memnode;
473 	struct {
474 		uint64_t	addr;
475 		uint64_t	size;
476 	} mem_range;
477 
478 	if (prom_getprop(nodeid, "board#", (caddr_t)&board) < 0) {
479 		panic("Can not find board# property in mc node %x", nodeid);
480 	}
481 	if (prom_getprop(nodeid, "sb-mem-ranges", (caddr_t)&mem_range) < 0) {
482 		panic("Can not find sb-mem-ranges property in mc node %x",
483 			nodeid);
484 	}
485 	memnode = mem_range.addr >> OPL_MC_MEMBOARD_SHIFT;
486 	plat_assign_lgrphand_to_mem_node(board, memnode);
487 }
488 
489 /*
490  * Return the platform handle for the lgroup containing the given CPU
491  *
492  * For OPL, lgroup platform handle == board #.
493  */
494 
495 extern int mpo_disabled;
496 extern lgrp_handle_t lgrp_default_handle;
497 
498 lgrp_handle_t
499 plat_lgrp_cpu_to_hand(processorid_t id)
500 {
501 	lgrp_handle_t plathand;
502 
503 	/*
504 	 * Return the real platform handle for the CPU until
505 	 * such time as we know that MPO should be disabled.
506 	 * At that point, we set the "mpo_disabled" flag to true,
507 	 * and from that point on, return the default handle.
508 	 *
509 	 * By the time we know that MPO should be disabled, the
510 	 * first CPU will have already been added to a leaf
511 	 * lgroup, but that's ok. The common lgroup code will
512 	 * double check that the boot CPU is in the correct place,
513 	 * and in the case where mpo should be disabled, will move
514 	 * it to the root if necessary.
515 	 */
516 	if (mpo_disabled) {
517 		/* If MPO is disabled, return the default (UMA) handle */
518 		plathand = lgrp_default_handle;
519 	} else
520 		plathand = (lgrp_handle_t)LSB_ID(id);
521 	return (plathand);
522 }
523 
524 /*
525  * Platform specific lgroup initialization
526  */
527 void
528 plat_lgrp_init(void)
529 {
530 	extern uint32_t lgrp_expand_proc_thresh;
531 	extern uint32_t lgrp_expand_proc_diff;
532 
533 	/*
534 	 * Set tuneables for the OPL architecture
535 	 *
536 	 * lgrp_expand_proc_thresh is the minimum load on the lgroups
537 	 * this process is currently running on before considering
538 	 * expanding threads to another lgroup.
539 	 *
540 	 * lgrp_expand_proc_diff determines how much less the remote lgroup
541 	 * must be loaded before expanding to it.
542 	 *
543 	 * Since remote latencies can be costly, attempt to keep 3 threads
544 	 * within the same lgroup before expanding to the next lgroup.
545 	 */
546 	lgrp_expand_proc_thresh = LGRP_LOADAVG_THREAD_MAX * 3;
547 	lgrp_expand_proc_diff = LGRP_LOADAVG_THREAD_MAX;
548 }
549 
550 /*
551  * Platform notification of lgroup (re)configuration changes
552  */
553 /*ARGSUSED*/
554 void
555 plat_lgrp_config(lgrp_config_flag_t evt, uintptr_t arg)
556 {
557 	update_membounds_t *umb;
558 	lgrp_config_mem_rename_t lmr;
559 	int sbd, tbd;
560 	lgrp_handle_t hand, shand, thand;
561 	int mnode, snode, tnode;
562 	pfn_t start, end;
563 
564 	if (mpo_disabled)
565 		return;
566 
567 	switch (evt) {
568 
569 	case LGRP_CONFIG_MEM_ADD:
570 		/*
571 		 * Establish the lgroup handle to memnode translation.
572 		 */
573 		umb = (update_membounds_t *)arg;
574 
575 		hand = umb->u_board;
576 		mnode = plat_pfn_to_mem_node(umb->u_base >> MMU_PAGESHIFT);
577 		plat_assign_lgrphand_to_mem_node(hand, mnode);
578 
579 		break;
580 
581 	case LGRP_CONFIG_MEM_DEL:
582 		/*
583 		 * Special handling for possible memory holes.
584 		 */
585 		umb = (update_membounds_t *)arg;
586 		hand = umb->u_board;
587 		if ((mnode = plat_lgrphand_to_mem_node(hand)) != -1) {
588 			if (mem_node_config[mnode].exists) {
589 				start = mem_node_config[mnode].physbase;
590 				end = mem_node_config[mnode].physmax;
591 				mem_node_pre_del_slice(start, end);
592 				mem_node_post_del_slice(start, end, 0);
593 			}
594 		}
595 
596 		break;
597 
598 	case LGRP_CONFIG_MEM_RENAME:
599 		/*
600 		 * During a DR copy-rename operation, all of the memory
601 		 * on one board is moved to another board -- but the
602 		 * addresses/pfns and memnodes don't change. This means
603 		 * the memory has changed locations without changing identity.
604 		 *
605 		 * Source is where we are copying from and target is where we
606 		 * are copying to.  After source memnode is copied to target
607 		 * memnode, the physical addresses of the target memnode are
608 		 * renamed to match what the source memnode had.  Then target
609 		 * memnode can be removed and source memnode can take its
610 		 * place.
611 		 *
612 		 * To do this, swap the lgroup handle to memnode mappings for
613 		 * the boards, so target lgroup will have source memnode and
614 		 * source lgroup will have empty target memnode which is where
615 		 * its memory will go (if any is added to it later).
616 		 *
617 		 * Then source memnode needs to be removed from its lgroup
618 		 * and added to the target lgroup where the memory was living
619 		 * but under a different name/memnode.  The memory was in the
620 		 * target memnode and now lives in the source memnode with
621 		 * different physical addresses even though it is the same
622 		 * memory.
623 		 */
624 		sbd = arg & 0xffff;
625 		tbd = (arg & 0xffff0000) >> 16;
626 		shand = sbd;
627 		thand = tbd;
628 		snode = plat_lgrphand_to_mem_node(shand);
629 		tnode = plat_lgrphand_to_mem_node(thand);
630 
631 		/*
632 		 * Special handling for possible memory holes.
633 		 */
634 		if (tnode != -1 && mem_node_config[tnode].exists) {
635 			start = mem_node_config[mnode].physbase;
636 			end = mem_node_config[mnode].physmax;
637 			mem_node_pre_del_slice(start, end);
638 			mem_node_post_del_slice(start, end, 0);
639 		}
640 
641 		plat_assign_lgrphand_to_mem_node(thand, snode);
642 		plat_assign_lgrphand_to_mem_node(shand, tnode);
643 
644 		lmr.lmem_rename_from = shand;
645 		lmr.lmem_rename_to = thand;
646 
647 		/*
648 		 * Remove source memnode of copy rename from its lgroup
649 		 * and add it to its new target lgroup
650 		 */
651 		lgrp_config(LGRP_CONFIG_MEM_RENAME, (uintptr_t)snode,
652 		    (uintptr_t)&lmr);
653 
654 		break;
655 
656 	default:
657 		break;
658 	}
659 }
660 
661 /*
662  * Return latency between "from" and "to" lgroups
663  *
664  * This latency number can only be used for relative comparison
665  * between lgroups on the running system, cannot be used across platforms,
666  * and may not reflect the actual latency.  It is platform and implementation
667  * specific, so platform gets to decide its value.  It would be nice if the
668  * number was at least proportional to make comparisons more meaningful though.
669  * NOTE: The numbers below are supposed to be load latencies for uncached
670  * memory divided by 10.
671  *
672  */
673 int
674 plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
675 {
676 	/*
677 	 * Return min remote latency when there are more than two lgroups
678 	 * (root and child) and getting latency between two different lgroups
679 	 * or root is involved
680 	 */
681 	if (lgrp_optimizations() && (from != to ||
682 	    from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
683 		return (42);
684 	else
685 		return (35);
686 }
687 
688 /*
689  * Return platform handle for root lgroup
690  */
691 lgrp_handle_t
692 plat_lgrp_root_hand(void)
693 {
694 	if (mpo_disabled)
695 		return (lgrp_default_handle);
696 
697 	return (LGRP_DEFAULT_HANDLE);
698 }
699 
700 /*ARGSUSED*/
701 void
702 plat_freelist_process(int mnode)
703 {
704 }
705 
706 void
707 load_platform_drivers(void)
708 {
709 	(void) i_ddi_attach_pseudo_node("dr");
710 }
711 
712 /*
713  * No platform drivers on this platform
714  */
715 char *platform_module_list[] = {
716 	(char *)0
717 };
718 
719 /*ARGSUSED*/
720 void
721 plat_tod_fault(enum tod_fault_type tod_bad)
722 {
723 }
724 
725 /*ARGSUSED*/
726 void
727 cpu_sgn_update(ushort_t sgn, uchar_t state, uchar_t sub_state, int cpuid)
728 {
729 	static void (*scf_panic_callback)(int);
730 	static void (*scf_shutdown_callback)(int);
731 
732 	/*
733 	 * This is for notifing system panic/shutdown to SCF.
734 	 * In case of shutdown and panic, SCF call back
735 	 * function should be called.
736 	 *  <SCF call back functions>
737 	 *   scf_panic_callb()   : panicsys()->panic_quiesce_hw()
738 	 *   scf_shutdown_callb(): halt() or power_down() or reboot_machine()
739 	 * cpuid should be -1 and state should be SIGST_EXIT.
740 	 */
741 	if (state == SIGST_EXIT && cpuid == -1) {
742 
743 		/*
744 		 * find the symbol for the SCF panic callback routine in driver
745 		 */
746 		if (scf_panic_callback == NULL)
747 			scf_panic_callback = (void (*)(int))
748 				modgetsymvalue("scf_panic_callb", 0);
749 		if (scf_shutdown_callback == NULL)
750 			scf_shutdown_callback = (void (*)(int))
751 				modgetsymvalue("scf_shutdown_callb", 0);
752 
753 		switch (sub_state) {
754 		case SIGSUBST_PANIC:
755 			if (scf_panic_callback == NULL) {
756 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
757 				    "scf_panic_callb not found\n");
758 				return;
759 			}
760 			scf_panic_callback(SIGSUBST_PANIC);
761 			break;
762 
763 		case SIGSUBST_HALT:
764 			if (scf_shutdown_callback == NULL) {
765 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
766 				    "scf_shutdown_callb not found\n");
767 				return;
768 			}
769 			scf_shutdown_callback(SIGSUBST_HALT);
770 			break;
771 
772 		case SIGSUBST_ENVIRON:
773 			if (scf_shutdown_callback == NULL) {
774 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
775 				    "scf_shutdown_callb not found\n");
776 				return;
777 			}
778 			scf_shutdown_callback(SIGSUBST_ENVIRON);
779 			break;
780 
781 		case SIGSUBST_REBOOT:
782 			if (scf_shutdown_callback == NULL) {
783 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
784 				    "scf_shutdown_callb not found\n");
785 				return;
786 			}
787 			scf_shutdown_callback(SIGSUBST_REBOOT);
788 			break;
789 		}
790 	}
791 }
792 
793 /*ARGSUSED*/
794 int
795 plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
796 	int flt_in_memory, ushort_t flt_status,
797 	char *buf, int buflen, int *lenp)
798 {
799 	/*
800 	 * check if it's a Memory error.
801 	 */
802 	if (flt_in_memory) {
803 		if (opl_get_mem_unum != NULL) {
804 			return (opl_get_mem_unum(synd_code, flt_addr,
805 				buf, buflen, lenp));
806 		} else {
807 			return (ENOTSUP);
808 		}
809 	} else {
810 		return (ENOTSUP);
811 	}
812 }
813 
814 /*ARGSUSED*/
815 int
816 plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
817 {
818 	int	plen;
819 	int	ret = 0;
820 	char	model[20];
821 	uint_t	sb;
822 	pnode_t	node;
823 
824 	/* determine the platform model once */
825 	if (plat_model == -1) {
826 		plat_model = MODEL_DC; /* Default model */
827 		node = prom_rootnode();
828 		plen = prom_getproplen(node, "model");
829 		if (plen > 0 && plen < sizeof (model)) {
830 			(void) prom_getprop(node, "model", model);
831 			model[plen] = '\0';
832 			if (strcmp(model, "FF1") == 0)
833 				plat_model = MODEL_FF1;
834 			else if (strcmp(model, "FF2") == 0)
835 				plat_model = MODEL_FF2;
836 			else if (strncmp(model, "DC", 2) == 0)
837 				plat_model = MODEL_DC;
838 		}
839 	}
840 
841 	sb = opl_get_physical_board(LSB_ID(cpuid));
842 	if (sb == -1) {
843 		return (ENXIO);
844 	}
845 
846 	switch (plat_model) {
847 	case MODEL_FF1:
848 		plen = snprintf(buf, buflen, "/%s/CPUM%d", "MBU_A",
849 		    CHIP_ID(cpuid) / 2);
850 		break;
851 
852 	case MODEL_FF2:
853 		plen = snprintf(buf, buflen, "/%s/CPUM%d", "MBU_B",
854 		    CHIP_ID(cpuid) / 2);
855 		break;
856 
857 	case MODEL_DC:
858 		plen = snprintf(buf, buflen, "/%s%02d/CPUM%d", "CMU", sb,
859 		    CHIP_ID(cpuid));
860 		break;
861 
862 	default:
863 		/* This should never happen */
864 		return (ENODEV);
865 	}
866 
867 	if (plen >= buflen) {
868 		ret = ENOSPC;
869 	} else {
870 		if (lenp)
871 			*lenp = strlen(buf);
872 	}
873 	return (ret);
874 }
875 
876 #define	SCF_PUTINFO(f, s, p)	\
877 	f(KEY_ESCF, 0x01, 0, s, p)
878 void
879 plat_nodename_set(void)
880 {
881 	void *datap;
882 	static int (*scf_service_function)(uint32_t, uint8_t,
883 	    uint32_t, uint32_t, void *);
884 	int counter = 5;
885 
886 	/*
887 	 * find the symbol for the SCF put routine in driver
888 	 */
889 	if (scf_service_function == NULL)
890 		scf_service_function =
891 			(int (*)(uint32_t, uint8_t, uint32_t, uint32_t, void *))
892 			modgetsymvalue("scf_service_putinfo", 0);
893 
894 	/*
895 	 * If the symbol was found, call it.  Otherwise, log a note (but not to
896 	 * the console).
897 	 */
898 
899 	if (scf_service_function == NULL) {
900 		cmn_err(CE_NOTE,
901 		    "!plat_nodename_set: scf_service_putinfo not found\n");
902 		return;
903 	}
904 
905 	datap =
906 	    (struct utsname *)kmem_zalloc(sizeof (struct utsname), KM_SLEEP);
907 
908 	if (datap == NULL) {
909 		return;
910 	}
911 
912 	bcopy((struct utsname *)&utsname,
913 	    (struct utsname *)datap, sizeof (struct utsname));
914 
915 	while ((SCF_PUTINFO(scf_service_function,
916 		sizeof (struct utsname), datap) == EBUSY) && (counter-- > 0)) {
917 		delay(10 * drv_usectohz(1000000));
918 	}
919 	if (counter == 0)
920 		cmn_err(CE_NOTE,
921 			"!plat_nodename_set: "
922 			"scf_service_putinfo not responding\n");
923 
924 	kmem_free(datap, sizeof (struct utsname));
925 }
926 
927 caddr_t	efcode_vaddr = NULL;
928 
929 /*
930  * Preallocate enough memory for fcode claims.
931  */
932 
933 caddr_t
934 efcode_alloc(caddr_t alloc_base)
935 {
936 	caddr_t efcode_alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
937 	    MMU_PAGESIZE);
938 	caddr_t vaddr;
939 
940 	/*
941 	 * allocate the physical memory for the Oberon fcode.
942 	 */
943 	if ((vaddr = (caddr_t)BOP_ALLOC(bootops, efcode_alloc_base,
944 	    efcode_size, MMU_PAGESIZE)) == NULL)
945 		cmn_err(CE_PANIC, "Cannot allocate Efcode Memory");
946 
947 	efcode_vaddr = vaddr;
948 
949 	return (efcode_alloc_base + efcode_size);
950 }
951 
952 caddr_t
953 plat_startup_memlist(caddr_t alloc_base)
954 {
955 	caddr_t tmp_alloc_base;
956 
957 	tmp_alloc_base = efcode_alloc(alloc_base);
958 	tmp_alloc_base =
959 	    (caddr_t)roundup((uintptr_t)tmp_alloc_base, ecache_alignsize);
960 	return (tmp_alloc_base);
961 }
962 
963 void
964 startup_platform(void)
965 {
966 }
967 
968 void
969 plat_cpuid_to_mmu_ctx_info(processorid_t cpuid, mmu_ctx_info_t *info)
970 {
971 	int	impl;
972 
973 	impl = cpunodes[cpuid].implementation;
974 	if (IS_OLYMPUS_C(impl)) {
975 		info->mmu_idx = MMU_ID(cpuid);
976 		info->mmu_nctxs = 8192;
977 	} else {
978 		cmn_err(CE_PANIC, "Unknown processor %d", impl);
979 	}
980 }
981 
982 int
983 plat_get_mem_sid(char *unum, char *buf, int buflen, int *lenp)
984 {
985 	if (opl_get_mem_sid == NULL) {
986 		return (ENOTSUP);
987 	}
988 	return (opl_get_mem_sid(unum, buf, buflen, lenp));
989 }
990 
991 int
992 plat_get_mem_offset(uint64_t paddr, uint64_t *offp)
993 {
994 	if (opl_get_mem_offset == NULL) {
995 		return (ENOTSUP);
996 	}
997 	return (opl_get_mem_offset(paddr, offp));
998 }
999 
1000 int
1001 plat_get_mem_addr(char *unum, char *sid, uint64_t offset, uint64_t *addrp)
1002 {
1003 	if (opl_get_mem_addr == NULL) {
1004 		return (ENOTSUP);
1005 	}
1006 	return (opl_get_mem_addr(unum, sid, offset, addrp));
1007 }
1008