xref: /onnv-gate/usr/src/uts/sun4u/opl/os/opl.c (revision 5347:e02444540d9d)
11772Sjl139090 /*
21772Sjl139090  * CDDL HEADER START
31772Sjl139090  *
41772Sjl139090  * The contents of this file are subject to the terms of the
51772Sjl139090  * Common Development and Distribution License (the "License").
61772Sjl139090  * You may not use this file except in compliance with the License.
71772Sjl139090  *
81772Sjl139090  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91772Sjl139090  * or http://www.opensolaris.org/os/licensing.
101772Sjl139090  * See the License for the specific language governing permissions
111772Sjl139090  * and limitations under the License.
121772Sjl139090  *
131772Sjl139090  * When distributing Covered Code, include this CDDL HEADER in each
141772Sjl139090  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151772Sjl139090  * If applicable, add the following below this CDDL HEADER, with the
161772Sjl139090  * fields enclosed by brackets "[]" replaced with your own identifying
171772Sjl139090  * information: Portions Copyright [yyyy] [name of copyright owner]
181772Sjl139090  *
191772Sjl139090  * CDDL HEADER END
201772Sjl139090  */
211772Sjl139090 /*
223354Sjl139090  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
231772Sjl139090  * Use is subject to license terms.
241772Sjl139090  */
251772Sjl139090 
261772Sjl139090 #pragma ident	"%Z%%M%	%I%	%E% SMI"
271772Sjl139090 
281772Sjl139090 #include <sys/cpuvar.h>
291772Sjl139090 #include <sys/systm.h>
301772Sjl139090 #include <sys/sysmacros.h>
311772Sjl139090 #include <sys/promif.h>
321772Sjl139090 #include <sys/platform_module.h>
331772Sjl139090 #include <sys/cmn_err.h>
341772Sjl139090 #include <sys/errno.h>
351772Sjl139090 #include <sys/machsystm.h>
361772Sjl139090 #include <sys/bootconf.h>
371772Sjl139090 #include <sys/nvpair.h>
381772Sjl139090 #include <sys/kobj.h>
391772Sjl139090 #include <sys/mem_cage.h>
401772Sjl139090 #include <sys/opl.h>
411772Sjl139090 #include <sys/scfd/scfostoescf.h>
421772Sjl139090 #include <sys/cpu_sgnblk_defs.h>
431772Sjl139090 #include <sys/utsname.h>
441772Sjl139090 #include <sys/ddi.h>
451772Sjl139090 #include <sys/sunndi.h>
461772Sjl139090 #include <sys/lgrp.h>
471772Sjl139090 #include <sys/memnode.h>
481772Sjl139090 #include <sys/sysmacros.h>
493914Spm145316 #include <sys/time.h>
503914Spm145316 #include <sys/cpu.h>
511772Sjl139090 #include <vm/vm_dep.h>
521772Sjl139090 
531772Sjl139090 int (*opl_get_mem_unum)(int, uint64_t, char *, int, int *);
542214Sav145390 int (*opl_get_mem_sid)(char *unum, char *buf, int buflen, int *lenp);
552214Sav145390 int (*opl_get_mem_offset)(uint64_t paddr, uint64_t *offp);
562214Sav145390 int (*opl_get_mem_addr)(char *unum, char *sid,
572214Sav145390     uint64_t offset, uint64_t *paddr);
581772Sjl139090 
591772Sjl139090 /* Memory for fcode claims.  16k times # maximum possible IO units */
601772Sjl139090 #define	EFCODE_SIZE	(OPL_MAX_BOARDS * OPL_MAX_IO_UNITS_PER_BOARD * 0x4000)
611772Sjl139090 int efcode_size = EFCODE_SIZE;
621772Sjl139090 
631772Sjl139090 #define	OPL_MC_MEMBOARD_SHIFT 38	/* Boards on 256BG boundary */
641772Sjl139090 
651772Sjl139090 /* Set the maximum number of boards for DR */
661772Sjl139090 int opl_boards = OPL_MAX_BOARDS;
671772Sjl139090 
681772Sjl139090 void sgn_update_all_cpus(ushort_t, uchar_t, uchar_t);
691772Sjl139090 
701772Sjl139090 extern int tsb_lgrp_affinity;
711772Sjl139090 
721772Sjl139090 int opl_tsb_spares = (OPL_MAX_BOARDS) * (OPL_MAX_PCICH_UNITS_PER_BOARD) *
731772Sjl139090 	(OPL_MAX_TSBS_PER_PCICH);
741772Sjl139090 
751772Sjl139090 pgcnt_t opl_startup_cage_size = 0;
761772Sjl139090 
77*5347Sjfrank /*
78*5347Sjfrank  * The length of the delay in seconds in communication with XSCF after
79*5347Sjfrank  * which the warning message will be logged.
80*5347Sjfrank  */
81*5347Sjfrank uint_t	xscf_connect_delay = 60 * 15;
82*5347Sjfrank 
832241Shuah static opl_model_info_t opl_models[] = {
843123Ssubhan 	{ "FF1", OPL_MAX_BOARDS_FF1, FF1, STD_DISPATCH_TABLE },
853123Ssubhan 	{ "FF2", OPL_MAX_BOARDS_FF2, FF2, STD_DISPATCH_TABLE },
863123Ssubhan 	{ "DC1", OPL_MAX_BOARDS_DC1, DC1, STD_DISPATCH_TABLE },
873123Ssubhan 	{ "DC2", OPL_MAX_BOARDS_DC2, DC2, EXT_DISPATCH_TABLE },
883123Ssubhan 	{ "DC3", OPL_MAX_BOARDS_DC3, DC3, EXT_DISPATCH_TABLE },
892241Shuah };
902241Shuah static	int	opl_num_models = sizeof (opl_models)/sizeof (opl_model_info_t);
912241Shuah 
923123Ssubhan /*
933627Ssubhan  * opl_cur_model
943123Ssubhan  */
953627Ssubhan static	opl_model_info_t *opl_cur_model = NULL;
962241Shuah 
971772Sjl139090 static struct memlist *opl_memlist_per_board(struct memlist *ml);
98*5347Sjfrank static void post_xscf_msg(char *, int);
99*5347Sjfrank static void pass2xscf_thread();
1001772Sjl139090 
1013914Spm145316 /*
1023914Spm145316  * Note FF/DC out-of-order instruction engine takes only a
1033914Spm145316  * single cycle to execute each spin loop
1043914Spm145316  * for comparison, Panther takes 6 cycles for same loop
1053914Spm145316  * 1500 approx nsec for OPL sleep instruction
1063914Spm145316  * if spin count = OPL_BOFF_SLEEP*OPL_BOFF_SPIN then
1073914Spm145316  * spin time should be equal to OPL_BOFF_TM nsecs
1083914Spm145316  * Listed values tuned for 2.15GHz to 2.4GHz systems
1093914Spm145316  * Value may change for future systems
1103914Spm145316  */
1113914Spm145316 #define	OPL_BOFF_SPIN 720
1123914Spm145316 #define	OPL_BOFF_BASE 1
1133914Spm145316 #define	OPL_BOFF_SLEEP 5
1143914Spm145316 #define	OPL_BOFF_CAP1 20
1153914Spm145316 #define	OPL_BOFF_CAP2 60
1163914Spm145316 #define	OPL_BOFF_MAX (40 * OPL_BOFF_SLEEP)
1173914Spm145316 #define	OPL_BOFF_TM 1500
1183914Spm145316 
1191772Sjl139090 int
1201772Sjl139090 set_platform_max_ncpus(void)
1211772Sjl139090 {
1221772Sjl139090 	return (OPL_MAX_CPU_PER_BOARD * OPL_MAX_BOARDS);
1231772Sjl139090 }
1241772Sjl139090 
1251772Sjl139090 int
1261772Sjl139090 set_platform_tsb_spares(void)
1271772Sjl139090 {
1281772Sjl139090 	return (MIN(opl_tsb_spares, MAX_UPA));
1291772Sjl139090 }
1301772Sjl139090 
1312241Shuah static void
1322241Shuah set_model_info()
1332241Shuah {
1343123Ssubhan 	extern int ts_dispatch_extended;
1352241Shuah 	char	name[MAXSYSNAME];
1362241Shuah 	int	i;
1372241Shuah 
1382241Shuah 	/*
1392241Shuah 	 * Get model name from the root node.
1402241Shuah 	 *
1412241Shuah 	 * We are using the prom device tree since, at this point,
1422241Shuah 	 * the Solaris device tree is not yet setup.
1432241Shuah 	 */
1442241Shuah 	(void) prom_getprop(prom_rootnode(), "model", (caddr_t)name);
1452241Shuah 
1462241Shuah 	for (i = 0; i < opl_num_models; i++) {
1472241Shuah 		if (strncmp(name, opl_models[i].model_name, MAXSYSNAME) == 0) {
1482241Shuah 			opl_cur_model = &opl_models[i];
1492241Shuah 			break;
1502241Shuah 		}
1512241Shuah 	}
1523123Ssubhan 
1532241Shuah 	if (i == opl_num_models)
1543123Ssubhan 		halt("No valid OPL model is found!");
1553123Ssubhan 
1563123Ssubhan 	if ((opl_cur_model->model_cmds & EXT_DISPATCH_TABLE) &&
1575037Sjl139090 	    (ts_dispatch_extended == -1)) {
1583123Ssubhan 		/*
1593123Ssubhan 		 * Based on a platform model, select a dispatch table.
1603123Ssubhan 		 * Only DC2 and DC3 systems uses the alternate/extended
1613123Ssubhan 		 * TS dispatch table.
1623123Ssubhan 		 * FF1, FF2 and DC1 systems used standard dispatch tables.
1633123Ssubhan 		 */
1643123Ssubhan 		ts_dispatch_extended = 1;
1653123Ssubhan 	}
1663123Ssubhan 
1672241Shuah }
1682241Shuah 
1692241Shuah static void
1702241Shuah set_max_mmu_ctxdoms()
1712241Shuah {
1722241Shuah 	extern uint_t	max_mmu_ctxdoms;
1732241Shuah 	int		max_boards;
1742241Shuah 
1752241Shuah 	/*
1762241Shuah 	 * From the model, get the maximum number of boards
1772241Shuah 	 * supported and set the value accordingly. If the model
1782241Shuah 	 * could not be determined or recognized, we assume the max value.
1792241Shuah 	 */
1802241Shuah 	if (opl_cur_model == NULL)
1812241Shuah 		max_boards = OPL_MAX_BOARDS;
1822241Shuah 	else
1832241Shuah 		max_boards = opl_cur_model->model_max_boards;
1842241Shuah 
1852241Shuah 	/*
1862241Shuah 	 * On OPL, cores and MMUs are one-to-one.
1872241Shuah 	 */
1882241Shuah 	max_mmu_ctxdoms = OPL_MAX_CORE_UNITS_PER_BOARD * max_boards;
1892241Shuah }
1902241Shuah 
1911772Sjl139090 #pragma weak mmu_init_large_pages
1921772Sjl139090 
1931772Sjl139090 void
1941772Sjl139090 set_platform_defaults(void)
1951772Sjl139090 {
1961772Sjl139090 	extern char *tod_module_name;
1971772Sjl139090 	extern void cpu_sgn_update(ushort_t, uchar_t, uchar_t, int);
1981772Sjl139090 	extern void mmu_init_large_pages(size_t);
1991772Sjl139090 
2001772Sjl139090 	/* Set the CPU signature function pointer */
2011772Sjl139090 	cpu_sgn_func = cpu_sgn_update;
2021772Sjl139090 
2031772Sjl139090 	/* Set appropriate tod module for OPL platform */
2041772Sjl139090 	ASSERT(tod_module_name == NULL);
2051772Sjl139090 	tod_module_name = "todopl";
2061772Sjl139090 
2071772Sjl139090 	if ((mmu_page_sizes == max_mmu_page_sizes) &&
2082659Ssusans 	    (mmu_ism_pagesize != DEFAULT_ISM_PAGESIZE)) {
2091772Sjl139090 		if (&mmu_init_large_pages)
2101772Sjl139090 			mmu_init_large_pages(mmu_ism_pagesize);
2111772Sjl139090 	}
2121772Sjl139090 
2131772Sjl139090 	tsb_lgrp_affinity = 1;
2142241Shuah 
2152241Shuah 	set_max_mmu_ctxdoms();
2161772Sjl139090 }
2171772Sjl139090 
2181772Sjl139090 /*
2191772Sjl139090  * Convert logical a board number to a physical one.
2201772Sjl139090  */
2211772Sjl139090 
2221772Sjl139090 #define	LSBPROP		"board#"
2231772Sjl139090 #define	PSBPROP		"physical-board#"
2241772Sjl139090 
2251772Sjl139090 int
2261772Sjl139090 opl_get_physical_board(int id)
2271772Sjl139090 {
2281772Sjl139090 	dev_info_t	*root_dip, *dip = NULL;
2291772Sjl139090 	char		*dname = NULL;
2301772Sjl139090 	int		circ;
2311772Sjl139090 
2321772Sjl139090 	pnode_t		pnode;
2331772Sjl139090 	char		pname[MAXSYSNAME] = {0};
2341772Sjl139090 
2351772Sjl139090 	int		lsb_id;	/* Logical System Board ID */
2361772Sjl139090 	int		psb_id;	/* Physical System Board ID */
2371772Sjl139090 
2381772Sjl139090 
2391772Sjl139090 	/*
2401772Sjl139090 	 * This function is called on early stage of bootup when the
2411772Sjl139090 	 * kernel device tree is not initialized yet, and also
2421772Sjl139090 	 * later on when the device tree is up. We want to try
2431772Sjl139090 	 * the fast track first.
2441772Sjl139090 	 */
2451772Sjl139090 	root_dip = ddi_root_node();
2461772Sjl139090 	if (root_dip) {
2471772Sjl139090 		/* Get from devinfo node */
2481772Sjl139090 		ndi_devi_enter(root_dip, &circ);
2491772Sjl139090 		for (dip = ddi_get_child(root_dip); dip;
2501772Sjl139090 		    dip = ddi_get_next_sibling(dip)) {
2511772Sjl139090 
2521772Sjl139090 			dname = ddi_node_name(dip);
2531772Sjl139090 			if (strncmp(dname, "pseudo-mc", 9) != 0)
2541772Sjl139090 				continue;
2551772Sjl139090 
2561772Sjl139090 			if ((lsb_id = (int)ddi_getprop(DDI_DEV_T_ANY, dip,
2571772Sjl139090 			    DDI_PROP_DONTPASS, LSBPROP, -1)) == -1)
2581772Sjl139090 				continue;
2591772Sjl139090 
2601772Sjl139090 			if (id == lsb_id) {
2611772Sjl139090 				if ((psb_id = (int)ddi_getprop(DDI_DEV_T_ANY,
2621772Sjl139090 				    dip, DDI_PROP_DONTPASS, PSBPROP, -1))
2631772Sjl139090 				    == -1) {
2641772Sjl139090 					ndi_devi_exit(root_dip, circ);
2651772Sjl139090 					return (-1);
2661772Sjl139090 				} else {
2671772Sjl139090 					ndi_devi_exit(root_dip, circ);
2681772Sjl139090 					return (psb_id);
2691772Sjl139090 				}
2701772Sjl139090 			}
2711772Sjl139090 		}
2721772Sjl139090 		ndi_devi_exit(root_dip, circ);
2731772Sjl139090 	}
2741772Sjl139090 
2751772Sjl139090 	/*
2761772Sjl139090 	 * We do not have the kernel device tree, or we did not
2771772Sjl139090 	 * find the node for some reason (let's say the kernel
2781772Sjl139090 	 * device tree was modified), let's try the OBP tree.
2791772Sjl139090 	 */
2801772Sjl139090 	pnode = prom_rootnode();
2811772Sjl139090 	for (pnode = prom_childnode(pnode); pnode;
2821772Sjl139090 	    pnode = prom_nextnode(pnode)) {
2831772Sjl139090 
2841772Sjl139090 		if ((prom_getprop(pnode, "name", (caddr_t)pname) == -1) ||
2851772Sjl139090 		    (strncmp(pname, "pseudo-mc", 9) != 0))
2861772Sjl139090 			continue;
2871772Sjl139090 
2881772Sjl139090 		if (prom_getprop(pnode, LSBPROP, (caddr_t)&lsb_id) == -1)
2891772Sjl139090 			continue;
2901772Sjl139090 
2911772Sjl139090 		if (id == lsb_id) {
2921772Sjl139090 			if (prom_getprop(pnode, PSBPROP,
2931772Sjl139090 			    (caddr_t)&psb_id) == -1) {
2941772Sjl139090 				return (-1);
2951772Sjl139090 			} else {
2961772Sjl139090 				return (psb_id);
2971772Sjl139090 			}
2981772Sjl139090 		}
2991772Sjl139090 	}
3001772Sjl139090 
3011772Sjl139090 	return (-1);
3021772Sjl139090 }
3031772Sjl139090 
3041772Sjl139090 /*
3051772Sjl139090  * For OPL it's possible that memory from two or more successive boards
3061772Sjl139090  * will be contiguous across the boards, and therefore represented as a
3071772Sjl139090  * single chunk.
3081772Sjl139090  * This function splits such chunks down the board boundaries.
3091772Sjl139090  */
3101772Sjl139090 static struct memlist *
3111772Sjl139090 opl_memlist_per_board(struct memlist *ml)
3121772Sjl139090 {
3131772Sjl139090 	uint64_t ssize, low, high, boundary;
3141772Sjl139090 	struct memlist *head, *tail, *new;
3151772Sjl139090 
3161772Sjl139090 	ssize = (1ull << OPL_MC_MEMBOARD_SHIFT);
3171772Sjl139090 
3181772Sjl139090 	head = tail = NULL;
3191772Sjl139090 
3201772Sjl139090 	for (; ml; ml = ml->next) {
3211772Sjl139090 		low  = (uint64_t)ml->address;
3221772Sjl139090 		high = low+(uint64_t)(ml->size);
3231772Sjl139090 		while (low < high) {
3241772Sjl139090 			boundary = roundup(low+1, ssize);
3251772Sjl139090 			boundary = MIN(high, boundary);
3261772Sjl139090 			new = kmem_zalloc(sizeof (struct memlist), KM_SLEEP);
3271772Sjl139090 			new->address = low;
3281772Sjl139090 			new->size = boundary - low;
3291772Sjl139090 			if (head == NULL)
3301772Sjl139090 				head = new;
3311772Sjl139090 			if (tail) {
3321772Sjl139090 				tail->next = new;
3331772Sjl139090 				new->prev = tail;
3341772Sjl139090 			}
3351772Sjl139090 			tail = new;
3361772Sjl139090 			low = boundary;
3371772Sjl139090 		}
3381772Sjl139090 	}
3391772Sjl139090 	return (head);
3401772Sjl139090 }
3411772Sjl139090 
3421772Sjl139090 void
3431772Sjl139090 set_platform_cage_params(void)
3441772Sjl139090 {
3451772Sjl139090 	extern pgcnt_t total_pages;
3461772Sjl139090 	extern struct memlist *phys_avail;
3471772Sjl139090 	struct memlist *ml, *tml;
3481772Sjl139090 
3491772Sjl139090 	if (kernel_cage_enable) {
3501772Sjl139090 		pgcnt_t preferred_cage_size;
3511772Sjl139090 
3525037Sjl139090 		preferred_cage_size = MAX(opl_startup_cage_size,
3535037Sjl139090 		    total_pages / 256);
3541772Sjl139090 
3551772Sjl139090 		ml = opl_memlist_per_board(phys_avail);
3561772Sjl139090 
3571772Sjl139090 		/*
3581772Sjl139090 		 * Note: we are assuming that post has load the
3591772Sjl139090 		 * whole show in to the high end of memory. Having
3601772Sjl139090 		 * taken this leap, we copy the whole of phys_avail
3611772Sjl139090 		 * the glist and arrange for the cage to grow
3621772Sjl139090 		 * downward (descending pfns).
3631772Sjl139090 		 */
3644266Sdp78419 		kcage_range_init(ml, KCAGE_DOWN, preferred_cage_size);
3651772Sjl139090 
3661772Sjl139090 		/* free the memlist */
3671772Sjl139090 		do {
3681772Sjl139090 			tml = ml->next;
3691772Sjl139090 			kmem_free(ml, sizeof (struct memlist));
3701772Sjl139090 			ml = tml;
3711772Sjl139090 		} while (ml != NULL);
3721772Sjl139090 	}
3731772Sjl139090 
3741772Sjl139090 	if (kcage_on)
3751772Sjl139090 		cmn_err(CE_NOTE, "!DR Kernel Cage is ENABLED");
3761772Sjl139090 	else
3771772Sjl139090 		cmn_err(CE_NOTE, "!DR Kernel Cage is DISABLED");
3781772Sjl139090 }
3791772Sjl139090 
3801772Sjl139090 /*ARGSUSED*/
3811772Sjl139090 int
3821772Sjl139090 plat_cpu_poweron(struct cpu *cp)
3831772Sjl139090 {
3841772Sjl139090 	int (*opl_cpu_poweron)(struct cpu *) = NULL;
3851772Sjl139090 
3861772Sjl139090 	opl_cpu_poweron =
3871772Sjl139090 	    (int (*)(struct cpu *))kobj_getsymvalue("drmach_cpu_poweron", 0);
3881772Sjl139090 
3891772Sjl139090 	if (opl_cpu_poweron == NULL)
3901772Sjl139090 		return (ENOTSUP);
3911772Sjl139090 	else
3921772Sjl139090 		return ((opl_cpu_poweron)(cp));
3931772Sjl139090 
3941772Sjl139090 }
3951772Sjl139090 
3961772Sjl139090 /*ARGSUSED*/
3971772Sjl139090 int
3981772Sjl139090 plat_cpu_poweroff(struct cpu *cp)
3991772Sjl139090 {
4001772Sjl139090 	int (*opl_cpu_poweroff)(struct cpu *) = NULL;
4011772Sjl139090 
4021772Sjl139090 	opl_cpu_poweroff =
4031772Sjl139090 	    (int (*)(struct cpu *))kobj_getsymvalue("drmach_cpu_poweroff", 0);
4041772Sjl139090 
4051772Sjl139090 	if (opl_cpu_poweroff == NULL)
4061772Sjl139090 		return (ENOTSUP);
4071772Sjl139090 	else
4081772Sjl139090 		return ((opl_cpu_poweroff)(cp));
4091772Sjl139090 
4101772Sjl139090 }
4111772Sjl139090 
4121772Sjl139090 int
4131772Sjl139090 plat_max_boards(void)
4141772Sjl139090 {
4151772Sjl139090 	return (OPL_MAX_BOARDS);
4161772Sjl139090 }
4171772Sjl139090 
4181772Sjl139090 int
4191772Sjl139090 plat_max_cpu_units_per_board(void)
4201772Sjl139090 {
4211772Sjl139090 	return (OPL_MAX_CPU_PER_BOARD);
4221772Sjl139090 }
4231772Sjl139090 
4241772Sjl139090 int
4251772Sjl139090 plat_max_mem_units_per_board(void)
4261772Sjl139090 {
4271772Sjl139090 	return (OPL_MAX_MEM_UNITS_PER_BOARD);
4281772Sjl139090 }
4291772Sjl139090 
4301772Sjl139090 int
4311772Sjl139090 plat_max_io_units_per_board(void)
4321772Sjl139090 {
4331772Sjl139090 	return (OPL_MAX_IO_UNITS_PER_BOARD);
4341772Sjl139090 }
4351772Sjl139090 
4361772Sjl139090 int
4371772Sjl139090 plat_max_cmp_units_per_board(void)
4381772Sjl139090 {
4391772Sjl139090 	return (OPL_MAX_CMP_UNITS_PER_BOARD);
4401772Sjl139090 }
4411772Sjl139090 
4421772Sjl139090 int
4431772Sjl139090 plat_max_core_units_per_board(void)
4441772Sjl139090 {
4451772Sjl139090 	return (OPL_MAX_CORE_UNITS_PER_BOARD);
4461772Sjl139090 }
4471772Sjl139090 
4481772Sjl139090 int
4491772Sjl139090 plat_pfn_to_mem_node(pfn_t pfn)
4501772Sjl139090 {
4511772Sjl139090 	return (pfn >> mem_node_pfn_shift);
4521772Sjl139090 }
4531772Sjl139090 
4541772Sjl139090 /* ARGSUSED */
4551772Sjl139090 void
4561772Sjl139090 plat_build_mem_nodes(u_longlong_t *list, size_t nelems)
4571772Sjl139090 {
4581772Sjl139090 	size_t	elem;
4591772Sjl139090 	pfn_t	basepfn;
4601772Sjl139090 	pgcnt_t	npgs;
4611772Sjl139090 	uint64_t	boundary, ssize;
4621772Sjl139090 	uint64_t	low, high;
4631772Sjl139090 
4641772Sjl139090 	/*
4651772Sjl139090 	 * OPL mem slices are always aligned on a 256GB boundary.
4661772Sjl139090 	 */
4671772Sjl139090 	mem_node_pfn_shift = OPL_MC_MEMBOARD_SHIFT - MMU_PAGESHIFT;
4681772Sjl139090 	mem_node_physalign = 0;
4691772Sjl139090 
4701772Sjl139090 	/*
4711772Sjl139090 	 * Boot install lists are arranged <addr, len>, <addr, len>, ...
4721772Sjl139090 	 */
4731772Sjl139090 	ssize = (1ull << OPL_MC_MEMBOARD_SHIFT);
4741772Sjl139090 	for (elem = 0; elem < nelems; elem += 2) {
4751772Sjl139090 		low  = (uint64_t)list[elem];
4761772Sjl139090 		high = low+(uint64_t)(list[elem+1]);
4771772Sjl139090 		while (low < high) {
4781772Sjl139090 			boundary = roundup(low+1, ssize);
4791772Sjl139090 			boundary = MIN(high, boundary);
4801772Sjl139090 			basepfn = btop(low);
4811772Sjl139090 			npgs = btop(boundary - low);
4821772Sjl139090 			mem_node_add_slice(basepfn, basepfn + npgs - 1);
4831772Sjl139090 			low = boundary;
4841772Sjl139090 		}
4851772Sjl139090 	}
4861772Sjl139090 }
4871772Sjl139090 
4881772Sjl139090 /*
4891772Sjl139090  * Find the CPU associated with a slice at boot-time.
4901772Sjl139090  */
4911772Sjl139090 void
4921772Sjl139090 plat_fill_mc(pnode_t nodeid)
4931772Sjl139090 {
4941772Sjl139090 	int board;
4951772Sjl139090 	int memnode;
4961772Sjl139090 	struct {
4971772Sjl139090 		uint64_t	addr;
4981772Sjl139090 		uint64_t	size;
4991772Sjl139090 	} mem_range;
5001772Sjl139090 
5011772Sjl139090 	if (prom_getprop(nodeid, "board#", (caddr_t)&board) < 0) {
5021772Sjl139090 		panic("Can not find board# property in mc node %x", nodeid);
5031772Sjl139090 	}
5041772Sjl139090 	if (prom_getprop(nodeid, "sb-mem-ranges", (caddr_t)&mem_range) < 0) {
5051772Sjl139090 		panic("Can not find sb-mem-ranges property in mc node %x",
5065037Sjl139090 		    nodeid);
5071772Sjl139090 	}
5081772Sjl139090 	memnode = mem_range.addr >> OPL_MC_MEMBOARD_SHIFT;
5091772Sjl139090 	plat_assign_lgrphand_to_mem_node(board, memnode);
5101772Sjl139090 }
5111772Sjl139090 
5121772Sjl139090 /*
5131772Sjl139090  * Return the platform handle for the lgroup containing the given CPU
5141772Sjl139090  *
5151772Sjl139090  * For OPL, lgroup platform handle == board #.
5161772Sjl139090  */
5171772Sjl139090 
5181772Sjl139090 extern int mpo_disabled;
5191772Sjl139090 extern lgrp_handle_t lgrp_default_handle;
5201772Sjl139090 
5211772Sjl139090 lgrp_handle_t
5221772Sjl139090 plat_lgrp_cpu_to_hand(processorid_t id)
5231772Sjl139090 {
5241772Sjl139090 	lgrp_handle_t plathand;
5251772Sjl139090 
5261772Sjl139090 	/*
5271772Sjl139090 	 * Return the real platform handle for the CPU until
5281772Sjl139090 	 * such time as we know that MPO should be disabled.
5291772Sjl139090 	 * At that point, we set the "mpo_disabled" flag to true,
5301772Sjl139090 	 * and from that point on, return the default handle.
5311772Sjl139090 	 *
5321772Sjl139090 	 * By the time we know that MPO should be disabled, the
5331772Sjl139090 	 * first CPU will have already been added to a leaf
5341772Sjl139090 	 * lgroup, but that's ok. The common lgroup code will
5351772Sjl139090 	 * double check that the boot CPU is in the correct place,
5361772Sjl139090 	 * and in the case where mpo should be disabled, will move
5371772Sjl139090 	 * it to the root if necessary.
5381772Sjl139090 	 */
5391772Sjl139090 	if (mpo_disabled) {
5401772Sjl139090 		/* If MPO is disabled, return the default (UMA) handle */
5411772Sjl139090 		plathand = lgrp_default_handle;
5421772Sjl139090 	} else
5431772Sjl139090 		plathand = (lgrp_handle_t)LSB_ID(id);
5441772Sjl139090 	return (plathand);
5451772Sjl139090 }
5461772Sjl139090 
5471772Sjl139090 /*
5481772Sjl139090  * Platform specific lgroup initialization
5491772Sjl139090  */
5501772Sjl139090 void
5511772Sjl139090 plat_lgrp_init(void)
5521772Sjl139090 {
5531772Sjl139090 	extern uint32_t lgrp_expand_proc_thresh;
5541772Sjl139090 	extern uint32_t lgrp_expand_proc_diff;
5551772Sjl139090 
5561772Sjl139090 	/*
5571772Sjl139090 	 * Set tuneables for the OPL architecture
5581772Sjl139090 	 *
5591772Sjl139090 	 * lgrp_expand_proc_thresh is the minimum load on the lgroups
5601772Sjl139090 	 * this process is currently running on before considering
5611772Sjl139090 	 * expanding threads to another lgroup.
5621772Sjl139090 	 *
5631772Sjl139090 	 * lgrp_expand_proc_diff determines how much less the remote lgroup
5641772Sjl139090 	 * must be loaded before expanding to it.
5651772Sjl139090 	 *
5661772Sjl139090 	 * Since remote latencies can be costly, attempt to keep 3 threads
5671772Sjl139090 	 * within the same lgroup before expanding to the next lgroup.
5681772Sjl139090 	 */
5691772Sjl139090 	lgrp_expand_proc_thresh = LGRP_LOADAVG_THREAD_MAX * 3;
5701772Sjl139090 	lgrp_expand_proc_diff = LGRP_LOADAVG_THREAD_MAX;
5711772Sjl139090 }
5721772Sjl139090 
5731772Sjl139090 /*
5741772Sjl139090  * Platform notification of lgroup (re)configuration changes
5751772Sjl139090  */
5761772Sjl139090 /*ARGSUSED*/
5771772Sjl139090 void
5781772Sjl139090 plat_lgrp_config(lgrp_config_flag_t evt, uintptr_t arg)
5791772Sjl139090 {
5801772Sjl139090 	update_membounds_t *umb;
5811772Sjl139090 	lgrp_config_mem_rename_t lmr;
5821772Sjl139090 	int sbd, tbd;
5831772Sjl139090 	lgrp_handle_t hand, shand, thand;
5841772Sjl139090 	int mnode, snode, tnode;
5851772Sjl139090 	pfn_t start, end;
5861772Sjl139090 
5871772Sjl139090 	if (mpo_disabled)
5881772Sjl139090 		return;
5891772Sjl139090 
5901772Sjl139090 	switch (evt) {
5911772Sjl139090 
5921772Sjl139090 	case LGRP_CONFIG_MEM_ADD:
5931772Sjl139090 		/*
5941772Sjl139090 		 * Establish the lgroup handle to memnode translation.
5951772Sjl139090 		 */
5961772Sjl139090 		umb = (update_membounds_t *)arg;
5971772Sjl139090 
5981772Sjl139090 		hand = umb->u_board;
5991772Sjl139090 		mnode = plat_pfn_to_mem_node(umb->u_base >> MMU_PAGESHIFT);
6001772Sjl139090 		plat_assign_lgrphand_to_mem_node(hand, mnode);
6011772Sjl139090 
6021772Sjl139090 		break;
6031772Sjl139090 
6041772Sjl139090 	case LGRP_CONFIG_MEM_DEL:
6051772Sjl139090 		/*
6061772Sjl139090 		 * Special handling for possible memory holes.
6071772Sjl139090 		 */
6081772Sjl139090 		umb = (update_membounds_t *)arg;
6091772Sjl139090 		hand = umb->u_board;
6101772Sjl139090 		if ((mnode = plat_lgrphand_to_mem_node(hand)) != -1) {
6111772Sjl139090 			if (mem_node_config[mnode].exists) {
6121772Sjl139090 				start = mem_node_config[mnode].physbase;
6131772Sjl139090 				end = mem_node_config[mnode].physmax;
6141772Sjl139090 				mem_node_pre_del_slice(start, end);
6151772Sjl139090 				mem_node_post_del_slice(start, end, 0);
6161772Sjl139090 			}
6171772Sjl139090 		}
6181772Sjl139090 
6191772Sjl139090 		break;
6201772Sjl139090 
6211772Sjl139090 	case LGRP_CONFIG_MEM_RENAME:
6221772Sjl139090 		/*
6231772Sjl139090 		 * During a DR copy-rename operation, all of the memory
6241772Sjl139090 		 * on one board is moved to another board -- but the
6251772Sjl139090 		 * addresses/pfns and memnodes don't change. This means
6261772Sjl139090 		 * the memory has changed locations without changing identity.
6271772Sjl139090 		 *
6281772Sjl139090 		 * Source is where we are copying from and target is where we
6291772Sjl139090 		 * are copying to.  After source memnode is copied to target
6301772Sjl139090 		 * memnode, the physical addresses of the target memnode are
6311772Sjl139090 		 * renamed to match what the source memnode had.  Then target
6321772Sjl139090 		 * memnode can be removed and source memnode can take its
6331772Sjl139090 		 * place.
6341772Sjl139090 		 *
6351772Sjl139090 		 * To do this, swap the lgroup handle to memnode mappings for
6361772Sjl139090 		 * the boards, so target lgroup will have source memnode and
6371772Sjl139090 		 * source lgroup will have empty target memnode which is where
6381772Sjl139090 		 * its memory will go (if any is added to it later).
6391772Sjl139090 		 *
6401772Sjl139090 		 * Then source memnode needs to be removed from its lgroup
6411772Sjl139090 		 * and added to the target lgroup where the memory was living
6421772Sjl139090 		 * but under a different name/memnode.  The memory was in the
6431772Sjl139090 		 * target memnode and now lives in the source memnode with
6441772Sjl139090 		 * different physical addresses even though it is the same
6451772Sjl139090 		 * memory.
6461772Sjl139090 		 */
6471772Sjl139090 		sbd = arg & 0xffff;
6481772Sjl139090 		tbd = (arg & 0xffff0000) >> 16;
6491772Sjl139090 		shand = sbd;
6501772Sjl139090 		thand = tbd;
6511772Sjl139090 		snode = plat_lgrphand_to_mem_node(shand);
6521772Sjl139090 		tnode = plat_lgrphand_to_mem_node(thand);
6531772Sjl139090 
6541772Sjl139090 		/*
6551772Sjl139090 		 * Special handling for possible memory holes.
6561772Sjl139090 		 */
6571772Sjl139090 		if (tnode != -1 && mem_node_config[tnode].exists) {
6583354Sjl139090 			start = mem_node_config[tnode].physbase;
6593354Sjl139090 			end = mem_node_config[tnode].physmax;
6601772Sjl139090 			mem_node_pre_del_slice(start, end);
6611772Sjl139090 			mem_node_post_del_slice(start, end, 0);
6621772Sjl139090 		}
6631772Sjl139090 
6641772Sjl139090 		plat_assign_lgrphand_to_mem_node(thand, snode);
6651772Sjl139090 		plat_assign_lgrphand_to_mem_node(shand, tnode);
6661772Sjl139090 
6671772Sjl139090 		lmr.lmem_rename_from = shand;
6681772Sjl139090 		lmr.lmem_rename_to = thand;
6691772Sjl139090 
6701772Sjl139090 		/*
6711772Sjl139090 		 * Remove source memnode of copy rename from its lgroup
6721772Sjl139090 		 * and add it to its new target lgroup
6731772Sjl139090 		 */
6741772Sjl139090 		lgrp_config(LGRP_CONFIG_MEM_RENAME, (uintptr_t)snode,
6751772Sjl139090 		    (uintptr_t)&lmr);
6761772Sjl139090 
6771772Sjl139090 		break;
6781772Sjl139090 
6791772Sjl139090 	default:
6801772Sjl139090 		break;
6811772Sjl139090 	}
6821772Sjl139090 }
6831772Sjl139090 
6841772Sjl139090 /*
6851772Sjl139090  * Return latency between "from" and "to" lgroups
6861772Sjl139090  *
6871772Sjl139090  * This latency number can only be used for relative comparison
6881772Sjl139090  * between lgroups on the running system, cannot be used across platforms,
6891772Sjl139090  * and may not reflect the actual latency.  It is platform and implementation
6901772Sjl139090  * specific, so platform gets to decide its value.  It would be nice if the
6911772Sjl139090  * number was at least proportional to make comparisons more meaningful though.
6921772Sjl139090  * NOTE: The numbers below are supposed to be load latencies for uncached
6931772Sjl139090  * memory divided by 10.
6941772Sjl139090  *
6951772Sjl139090  */
6961772Sjl139090 int
6971772Sjl139090 plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
6981772Sjl139090 {
6991772Sjl139090 	/*
7001772Sjl139090 	 * Return min remote latency when there are more than two lgroups
7011772Sjl139090 	 * (root and child) and getting latency between two different lgroups
7021772Sjl139090 	 * or root is involved
7031772Sjl139090 	 */
7041772Sjl139090 	if (lgrp_optimizations() && (from != to ||
7051772Sjl139090 	    from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
7062491Shyw 		return (42);
7071772Sjl139090 	else
7082491Shyw 		return (35);
7091772Sjl139090 }
7101772Sjl139090 
7111772Sjl139090 /*
7121772Sjl139090  * Return platform handle for root lgroup
7131772Sjl139090  */
7141772Sjl139090 lgrp_handle_t
7151772Sjl139090 plat_lgrp_root_hand(void)
7161772Sjl139090 {
7171772Sjl139090 	if (mpo_disabled)
7181772Sjl139090 		return (lgrp_default_handle);
7191772Sjl139090 
7201772Sjl139090 	return (LGRP_DEFAULT_HANDLE);
7211772Sjl139090 }
7221772Sjl139090 
7231772Sjl139090 /*ARGSUSED*/
7241772Sjl139090 void
7251772Sjl139090 plat_freelist_process(int mnode)
7261772Sjl139090 {
7271772Sjl139090 }
7281772Sjl139090 
7291772Sjl139090 void
7301772Sjl139090 load_platform_drivers(void)
7311772Sjl139090 {
7321772Sjl139090 	(void) i_ddi_attach_pseudo_node("dr");
7331772Sjl139090 }
7341772Sjl139090 
7351772Sjl139090 /*
7361772Sjl139090  * No platform drivers on this platform
7371772Sjl139090  */
7381772Sjl139090 char *platform_module_list[] = {
7391772Sjl139090 	(char *)0
7401772Sjl139090 };
7411772Sjl139090 
7421772Sjl139090 /*ARGSUSED*/
7431772Sjl139090 void
7441772Sjl139090 plat_tod_fault(enum tod_fault_type tod_bad)
7451772Sjl139090 {
7461772Sjl139090 }
7471772Sjl139090 
7481772Sjl139090 /*ARGSUSED*/
7491772Sjl139090 void
7501772Sjl139090 cpu_sgn_update(ushort_t sgn, uchar_t state, uchar_t sub_state, int cpuid)
7511772Sjl139090 {
7521772Sjl139090 	static void (*scf_panic_callback)(int);
7531772Sjl139090 	static void (*scf_shutdown_callback)(int);
7541772Sjl139090 
7551772Sjl139090 	/*
7561772Sjl139090 	 * This is for notifing system panic/shutdown to SCF.
7571772Sjl139090 	 * In case of shutdown and panic, SCF call back
7581772Sjl139090 	 * function should be called.
7591772Sjl139090 	 *  <SCF call back functions>
7601772Sjl139090 	 *   scf_panic_callb()   : panicsys()->panic_quiesce_hw()
7611772Sjl139090 	 *   scf_shutdown_callb(): halt() or power_down() or reboot_machine()
7621772Sjl139090 	 * cpuid should be -1 and state should be SIGST_EXIT.
7631772Sjl139090 	 */
7641772Sjl139090 	if (state == SIGST_EXIT && cpuid == -1) {
7651772Sjl139090 
7661772Sjl139090 		/*
7671772Sjl139090 		 * find the symbol for the SCF panic callback routine in driver
7681772Sjl139090 		 */
7691772Sjl139090 		if (scf_panic_callback == NULL)
7701772Sjl139090 			scf_panic_callback = (void (*)(int))
7715037Sjl139090 			    modgetsymvalue("scf_panic_callb", 0);
7721772Sjl139090 		if (scf_shutdown_callback == NULL)
7731772Sjl139090 			scf_shutdown_callback = (void (*)(int))
7745037Sjl139090 			    modgetsymvalue("scf_shutdown_callb", 0);
7751772Sjl139090 
7761772Sjl139090 		switch (sub_state) {
7771772Sjl139090 		case SIGSUBST_PANIC:
7781772Sjl139090 			if (scf_panic_callback == NULL) {
7791772Sjl139090 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
7801772Sjl139090 				    "scf_panic_callb not found\n");
7811772Sjl139090 				return;
7821772Sjl139090 			}
7831772Sjl139090 			scf_panic_callback(SIGSUBST_PANIC);
7841772Sjl139090 			break;
7851772Sjl139090 
7861772Sjl139090 		case SIGSUBST_HALT:
7871772Sjl139090 			if (scf_shutdown_callback == NULL) {
7881772Sjl139090 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
7891772Sjl139090 				    "scf_shutdown_callb not found\n");
7901772Sjl139090 				return;
7911772Sjl139090 			}
7921772Sjl139090 			scf_shutdown_callback(SIGSUBST_HALT);
7931772Sjl139090 			break;
7941772Sjl139090 
7951772Sjl139090 		case SIGSUBST_ENVIRON:
7961772Sjl139090 			if (scf_shutdown_callback == NULL) {
7971772Sjl139090 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
7981772Sjl139090 				    "scf_shutdown_callb not found\n");
7991772Sjl139090 				return;
8001772Sjl139090 			}
8011772Sjl139090 			scf_shutdown_callback(SIGSUBST_ENVIRON);
8021772Sjl139090 			break;
8031772Sjl139090 
8041772Sjl139090 		case SIGSUBST_REBOOT:
8051772Sjl139090 			if (scf_shutdown_callback == NULL) {
8061772Sjl139090 				cmn_err(CE_NOTE, "!cpu_sgn_update: "
8071772Sjl139090 				    "scf_shutdown_callb not found\n");
8081772Sjl139090 				return;
8091772Sjl139090 			}
8101772Sjl139090 			scf_shutdown_callback(SIGSUBST_REBOOT);
8111772Sjl139090 			break;
8121772Sjl139090 		}
8131772Sjl139090 	}
8141772Sjl139090 }
8151772Sjl139090 
8161772Sjl139090 /*ARGSUSED*/
8171772Sjl139090 int
8181772Sjl139090 plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
8191772Sjl139090 	int flt_in_memory, ushort_t flt_status,
8201772Sjl139090 	char *buf, int buflen, int *lenp)
8211772Sjl139090 {
8221772Sjl139090 	/*
8231772Sjl139090 	 * check if it's a Memory error.
8241772Sjl139090 	 */
8251772Sjl139090 	if (flt_in_memory) {
8261772Sjl139090 		if (opl_get_mem_unum != NULL) {
8275037Sjl139090 			return (opl_get_mem_unum(synd_code, flt_addr, buf,
8285037Sjl139090 			    buflen, lenp));
8291772Sjl139090 		} else {
8301772Sjl139090 			return (ENOTSUP);
8311772Sjl139090 		}
8321772Sjl139090 	} else {
8331772Sjl139090 		return (ENOTSUP);
8341772Sjl139090 	}
8351772Sjl139090 }
8361772Sjl139090 
8371772Sjl139090 /*ARGSUSED*/
8381772Sjl139090 int
8391772Sjl139090 plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
8401772Sjl139090 {
8412214Sav145390 	int	ret = 0;
842*5347Sjfrank 	int	sb;
8433123Ssubhan 	int	plen;
8441772Sjl139090 
8451772Sjl139090 	sb = opl_get_physical_board(LSB_ID(cpuid));
8461772Sjl139090 	if (sb == -1) {
8471772Sjl139090 		return (ENXIO);
8481772Sjl139090 	}
8491772Sjl139090 
8503627Ssubhan 	/*
8513627Ssubhan 	 * opl_cur_model is assigned here
8523627Ssubhan 	 */
8533627Ssubhan 	if (opl_cur_model == NULL) {
8543627Ssubhan 		set_model_info();
8553627Ssubhan 	}
8563627Ssubhan 
8573123Ssubhan 	ASSERT((opl_cur_model - opl_models) == (opl_cur_model->model_type));
8583123Ssubhan 
8593123Ssubhan 	switch (opl_cur_model->model_type) {
8603123Ssubhan 	case FF1:
8612214Sav145390 		plen = snprintf(buf, buflen, "/%s/CPUM%d", "MBU_A",
8622214Sav145390 		    CHIP_ID(cpuid) / 2);
8632214Sav145390 		break;
8642214Sav145390 
8653123Ssubhan 	case FF2:
8662214Sav145390 		plen = snprintf(buf, buflen, "/%s/CPUM%d", "MBU_B",
8672808Sav145390 		    (CHIP_ID(cpuid) / 2) + (sb * 2));
8682214Sav145390 		break;
8692214Sav145390 
8703123Ssubhan 	case DC1:
8713123Ssubhan 	case DC2:
8723123Ssubhan 	case DC3:
8732214Sav145390 		plen = snprintf(buf, buflen, "/%s%02d/CPUM%d", "CMU", sb,
8742214Sav145390 		    CHIP_ID(cpuid));
8752214Sav145390 		break;
8762214Sav145390 
8772214Sav145390 	default:
8782214Sav145390 		/* This should never happen */
8792214Sav145390 		return (ENODEV);
8802214Sav145390 	}
8812214Sav145390 
8822214Sav145390 	if (plen >= buflen) {
8832214Sav145390 		ret = ENOSPC;
8841772Sjl139090 	} else {
8851772Sjl139090 		if (lenp)
8861772Sjl139090 			*lenp = strlen(buf);
8871772Sjl139090 	}
8882214Sav145390 	return (ret);
8891772Sjl139090 }
8901772Sjl139090 
8911772Sjl139090 void
8921772Sjl139090 plat_nodename_set(void)
8931772Sjl139090 {
894*5347Sjfrank 	post_xscf_msg((char *)&utsname, sizeof (struct utsname));
8951772Sjl139090 }
8961772Sjl139090 
8971772Sjl139090 caddr_t	efcode_vaddr = NULL;
8981772Sjl139090 
8991772Sjl139090 /*
9001772Sjl139090  * Preallocate enough memory for fcode claims.
9011772Sjl139090  */
9021772Sjl139090 
9031772Sjl139090 caddr_t
9041772Sjl139090 efcode_alloc(caddr_t alloc_base)
9051772Sjl139090 {
9061772Sjl139090 	caddr_t efcode_alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
9071772Sjl139090 	    MMU_PAGESIZE);
9081772Sjl139090 	caddr_t vaddr;
9091772Sjl139090 
9101772Sjl139090 	/*
9111772Sjl139090 	 * allocate the physical memory for the Oberon fcode.
9121772Sjl139090 	 */
9131772Sjl139090 	if ((vaddr = (caddr_t)BOP_ALLOC(bootops, efcode_alloc_base,
9141772Sjl139090 	    efcode_size, MMU_PAGESIZE)) == NULL)
9151772Sjl139090 		cmn_err(CE_PANIC, "Cannot allocate Efcode Memory");
9161772Sjl139090 
9171772Sjl139090 	efcode_vaddr = vaddr;
9181772Sjl139090 
9191772Sjl139090 	return (efcode_alloc_base + efcode_size);
9201772Sjl139090 }
9211772Sjl139090 
9221772Sjl139090 caddr_t
9231772Sjl139090 plat_startup_memlist(caddr_t alloc_base)
9241772Sjl139090 {
9251772Sjl139090 	caddr_t tmp_alloc_base;
9261772Sjl139090 
9271772Sjl139090 	tmp_alloc_base = efcode_alloc(alloc_base);
9281772Sjl139090 	tmp_alloc_base =
9291772Sjl139090 	    (caddr_t)roundup((uintptr_t)tmp_alloc_base, ecache_alignsize);
9301772Sjl139090 	return (tmp_alloc_base);
9311772Sjl139090 }
9321772Sjl139090 
9331772Sjl139090 void
9341772Sjl139090 startup_platform(void)
9351772Sjl139090 {
9361772Sjl139090 }
9372214Sav145390 
9382241Shuah void
9392241Shuah plat_cpuid_to_mmu_ctx_info(processorid_t cpuid, mmu_ctx_info_t *info)
9402241Shuah {
9412241Shuah 	int	impl;
9422241Shuah 
9432241Shuah 	impl = cpunodes[cpuid].implementation;
9445037Sjl139090 	if (IS_OLYMPUS_C(impl) || IS_JUPITER(impl)) {
9452457Smv143129 		info->mmu_idx = MMU_ID(cpuid);
9462241Shuah 		info->mmu_nctxs = 8192;
9472241Shuah 	} else {
9482241Shuah 		cmn_err(CE_PANIC, "Unknown processor %d", impl);
9492241Shuah 	}
9502241Shuah }
9512241Shuah 
9522214Sav145390 int
9532214Sav145390 plat_get_mem_sid(char *unum, char *buf, int buflen, int *lenp)
9542214Sav145390 {
9552214Sav145390 	if (opl_get_mem_sid == NULL) {
9562214Sav145390 		return (ENOTSUP);
9572214Sav145390 	}
9582214Sav145390 	return (opl_get_mem_sid(unum, buf, buflen, lenp));
9592214Sav145390 }
9602214Sav145390 
9612214Sav145390 int
9622214Sav145390 plat_get_mem_offset(uint64_t paddr, uint64_t *offp)
9632214Sav145390 {
9642214Sav145390 	if (opl_get_mem_offset == NULL) {
9652214Sav145390 		return (ENOTSUP);
9662214Sav145390 	}
9672214Sav145390 	return (opl_get_mem_offset(paddr, offp));
9682214Sav145390 }
9692214Sav145390 
9702214Sav145390 int
9712214Sav145390 plat_get_mem_addr(char *unum, char *sid, uint64_t offset, uint64_t *addrp)
9722214Sav145390 {
9732214Sav145390 	if (opl_get_mem_addr == NULL) {
9742214Sav145390 		return (ENOTSUP);
9752214Sav145390 	}
9762214Sav145390 	return (opl_get_mem_addr(unum, sid, offset, addrp));
9772214Sav145390 }
9783914Spm145316 
9793914Spm145316 void
9803914Spm145316 plat_lock_delay(int *backoff)
9813914Spm145316 {
9823914Spm145316 	int i;
9833914Spm145316 	int cnt;
9843914Spm145316 	int flag;
9853914Spm145316 	int ctr;
9863914Spm145316 	hrtime_t delay_start;
9873914Spm145316 	/*
9883914Spm145316 	 * Platform specific lock delay code for OPL
9893914Spm145316 	 *
9903914Spm145316 	 * Using staged linear increases in the delay.
9913914Spm145316 	 * The sleep instruction is the preferred method of delay,
9923914Spm145316 	 * but is too large of granularity for the initial backoff.
9933914Spm145316 	 */
9943914Spm145316 
9953914Spm145316 	if (*backoff == 0) *backoff = OPL_BOFF_BASE;
9963914Spm145316 
9973914Spm145316 	flag = !*backoff;
9983914Spm145316 
9993914Spm145316 	if (*backoff < OPL_BOFF_CAP1) {
10003914Spm145316 		/*
10013914Spm145316 		 * If desired backoff is long enough,
10023914Spm145316 		 * use sleep for most of it
10033914Spm145316 		 */
10045037Sjl139090 		for (cnt = *backoff; cnt >= OPL_BOFF_SLEEP;
10055037Sjl139090 		    cnt -= OPL_BOFF_SLEEP) {
10063914Spm145316 			cpu_smt_pause();
10073914Spm145316 		}
10083914Spm145316 		/*
10093914Spm145316 		 * spin for small remainder of backoff
10103914Spm145316 		 *
10113914Spm145316 		 * fake call to nulldev included to prevent
10123914Spm145316 		 * compiler from optimizing out the spin loop
10133914Spm145316 		 */
10143914Spm145316 		for (ctr = cnt * OPL_BOFF_SPIN; ctr; ctr--) {
10153914Spm145316 			if (flag) (void) nulldev();
10163914Spm145316 		}
10173914Spm145316 	} else {
10183914Spm145316 		/* backoff is very large.  Fill it by sleeping */
10193914Spm145316 		delay_start = gethrtime();
10203914Spm145316 		cnt = *backoff/OPL_BOFF_SLEEP;
10213914Spm145316 		/*
10223914Spm145316 		 * use sleep instructions for delay
10233914Spm145316 		 */
10243914Spm145316 		for (i = 0; i < cnt; i++) {
10253914Spm145316 			cpu_smt_pause();
10263914Spm145316 		}
10273914Spm145316 
10283914Spm145316 		/*
10293914Spm145316 		 * Note: if the other strand executes a sleep instruction,
10303914Spm145316 		 * then the sleep ends immediately with a minimum time of
10313914Spm145316 		 * 42 clocks.  We check gethrtime to insure we have
10323914Spm145316 		 * waited long enough.  And we include both a short
10333914Spm145316 		 * spin loop and a sleep for any final delay time.
10343914Spm145316 		 */
10353914Spm145316 
10363914Spm145316 		while ((gethrtime() - delay_start) < cnt * OPL_BOFF_TM) {
10373914Spm145316 			cpu_smt_pause();
10383914Spm145316 			for (ctr = OPL_BOFF_SPIN; ctr; ctr--) {
10393914Spm145316 				if (flag) (void) nulldev();
10403914Spm145316 			}
10413914Spm145316 		}
10423914Spm145316 	}
10433914Spm145316 
10443914Spm145316 	/*
10453914Spm145316 	 * We adjust the backoff in three linear stages
10463914Spm145316 	 * The initial stage has small increases as this phase is
10473914Spm145316 	 * usually handle locks with light contention.  We don't want
10483914Spm145316 	 * to have a long backoff on a lock that is available.
10493914Spm145316 	 *
10503914Spm145316 	 * In the second stage, we are in transition, unsure whether
10513914Spm145316 	 * the lock is under heavy contention.  As the failures to
10523914Spm145316 	 * obtain the lock increase, we back off further.
10533914Spm145316 	 *
10543914Spm145316 	 * For the final stage, we are in a heavily contended or
10553914Spm145316 	 * long held long so we want to reduce the number of tries.
10563914Spm145316 	 */
10573914Spm145316 	if (*backoff < OPL_BOFF_CAP1) {
10583914Spm145316 		*backoff += 1;
10593914Spm145316 	} else {
10603914Spm145316 		if (*backoff < OPL_BOFF_CAP2) {
10613914Spm145316 			*backoff += OPL_BOFF_SLEEP;
10623914Spm145316 		} else {
10633914Spm145316 			*backoff += 2 * OPL_BOFF_SLEEP;
10643914Spm145316 		}
10653914Spm145316 		if (*backoff > OPL_BOFF_MAX) {
10663914Spm145316 			*backoff = OPL_BOFF_MAX;
10673914Spm145316 		}
10683914Spm145316 	}
10693914Spm145316 }
1070*5347Sjfrank 
1071*5347Sjfrank /*
1072*5347Sjfrank  * The following code implements asynchronous call to XSCF to setup the
1073*5347Sjfrank  * domain node name.
1074*5347Sjfrank  */
1075*5347Sjfrank 
1076*5347Sjfrank #define	FREE_MSG(m)		kmem_free((m), NM_LEN((m)->len))
1077*5347Sjfrank 
1078*5347Sjfrank /*
1079*5347Sjfrank  * The following three macros define the all operations on the request
1080*5347Sjfrank  * list we are using here, and hide the details of the list
1081*5347Sjfrank  * implementation from the code.
1082*5347Sjfrank  */
1083*5347Sjfrank #define	PUSH(m) \
1084*5347Sjfrank 	{ \
1085*5347Sjfrank 		(m)->next = ctl_msg.head; \
1086*5347Sjfrank 		(m)->prev = NULL; \
1087*5347Sjfrank 		if ((m)->next != NULL) \
1088*5347Sjfrank 			(m)->next->prev = (m); \
1089*5347Sjfrank 		ctl_msg.head = (m); \
1090*5347Sjfrank 	}
1091*5347Sjfrank 
1092*5347Sjfrank #define	REMOVE(m) \
1093*5347Sjfrank 	{ \
1094*5347Sjfrank 		if ((m)->prev != NULL) \
1095*5347Sjfrank 			(m)->prev->next = (m)->next; \
1096*5347Sjfrank 		else \
1097*5347Sjfrank 			ctl_msg.head = (m)->next; \
1098*5347Sjfrank 		if ((m)->next != NULL) \
1099*5347Sjfrank 			(m)->next->prev = (m)->prev; \
1100*5347Sjfrank 	}
1101*5347Sjfrank 
1102*5347Sjfrank #define	FREE_THE_TAIL(head) \
1103*5347Sjfrank 	{ \
1104*5347Sjfrank 		nm_msg_t *n_msg, *m; \
1105*5347Sjfrank 		m = (head)->next; \
1106*5347Sjfrank 		(head)->next = NULL; \
1107*5347Sjfrank 		while (m != NULL) { \
1108*5347Sjfrank 			n_msg = m->next; \
1109*5347Sjfrank 			FREE_MSG(m); \
1110*5347Sjfrank 			m = n_msg; \
1111*5347Sjfrank 		} \
1112*5347Sjfrank 	}
1113*5347Sjfrank 
1114*5347Sjfrank #define	SCF_PUTINFO(f, s, p) \
1115*5347Sjfrank 	f(KEY_ESCF, 0x01, 0, s, p)
1116*5347Sjfrank 
1117*5347Sjfrank #define	PASS2XSCF(m, r)	((r = SCF_PUTINFO(ctl_msg.scf_service_function, \
1118*5347Sjfrank 					    (m)->len, (m)->data)) == 0)
1119*5347Sjfrank 
1120*5347Sjfrank /*
1121*5347Sjfrank  * The value of the following macro loosely depends on the
1122*5347Sjfrank  * value of the "device busy" timeout used in the SCF driver.
1123*5347Sjfrank  * (See pass2xscf_thread()).
1124*5347Sjfrank  */
1125*5347Sjfrank #define	SCF_DEVBUSY_DELAY	10
1126*5347Sjfrank 
1127*5347Sjfrank /*
1128*5347Sjfrank  * The default number of attempts to contact the scf driver
1129*5347Sjfrank  * if we cannot fetch any information about the timeout value
1130*5347Sjfrank  * it uses.
1131*5347Sjfrank  */
1132*5347Sjfrank 
1133*5347Sjfrank #define	REPEATS		4
1134*5347Sjfrank 
1135*5347Sjfrank typedef struct nm_msg {
1136*5347Sjfrank 	struct nm_msg *next;
1137*5347Sjfrank 	struct nm_msg *prev;
1138*5347Sjfrank 	int len;
1139*5347Sjfrank 	char data[1];
1140*5347Sjfrank } nm_msg_t;
1141*5347Sjfrank 
1142*5347Sjfrank #define	NM_LEN(len)		(sizeof (nm_msg_t) + (len) - 1)
1143*5347Sjfrank 
1144*5347Sjfrank static struct ctlmsg {
1145*5347Sjfrank 	nm_msg_t	*head;
1146*5347Sjfrank 	nm_msg_t	*now_serving;
1147*5347Sjfrank 	kmutex_t	nm_lock;
1148*5347Sjfrank 	kthread_t	*nmt;
1149*5347Sjfrank 	int		cnt;
1150*5347Sjfrank 	int (*scf_service_function)(uint32_t, uint8_t,
1151*5347Sjfrank 				    uint32_t, uint32_t, void *);
1152*5347Sjfrank } ctl_msg;
1153*5347Sjfrank 
1154*5347Sjfrank static void
1155*5347Sjfrank post_xscf_msg(char *dp, int len)
1156*5347Sjfrank {
1157*5347Sjfrank 	nm_msg_t *msg;
1158*5347Sjfrank 
1159*5347Sjfrank 	msg = (nm_msg_t *)kmem_zalloc(NM_LEN(len), KM_SLEEP);
1160*5347Sjfrank 
1161*5347Sjfrank 	bcopy(dp, msg->data, len);
1162*5347Sjfrank 	msg->len = len;
1163*5347Sjfrank 
1164*5347Sjfrank 	mutex_enter(&ctl_msg.nm_lock);
1165*5347Sjfrank 	if (ctl_msg.nmt == NULL) {
1166*5347Sjfrank 		ctl_msg.nmt =  thread_create(NULL, 0, pass2xscf_thread,
1167*5347Sjfrank 		    NULL, 0, &p0, TS_RUN, minclsyspri);
1168*5347Sjfrank 	}
1169*5347Sjfrank 
1170*5347Sjfrank 	PUSH(msg);
1171*5347Sjfrank 	ctl_msg.cnt++;
1172*5347Sjfrank 	mutex_exit(&ctl_msg.nm_lock);
1173*5347Sjfrank }
1174*5347Sjfrank 
1175*5347Sjfrank static void
1176*5347Sjfrank pass2xscf_thread()
1177*5347Sjfrank {
1178*5347Sjfrank 	nm_msg_t *msg;
1179*5347Sjfrank 	int ret;
1180*5347Sjfrank 	uint_t i, msg_sent, xscf_driver_delay;
1181*5347Sjfrank 	static uint_t repeat_cnt;
1182*5347Sjfrank 	uint_t *scf_wait_cnt;
1183*5347Sjfrank 
1184*5347Sjfrank 	mutex_enter(&ctl_msg.nm_lock);
1185*5347Sjfrank 
1186*5347Sjfrank 	/*
1187*5347Sjfrank 	 * Find the address of the SCF put routine if it's not done yet.
1188*5347Sjfrank 	 */
1189*5347Sjfrank 	if (ctl_msg.scf_service_function == NULL) {
1190*5347Sjfrank 		if ((ctl_msg.scf_service_function =
1191*5347Sjfrank 		    (int (*)(uint32_t, uint8_t, uint32_t, uint32_t, void *))
1192*5347Sjfrank 		    modgetsymvalue("scf_service_putinfo", 0)) == NULL) {
1193*5347Sjfrank 			cmn_err(CE_NOTE, "pass2xscf_thread: "
1194*5347Sjfrank 			    "scf_service_putinfo not found\n");
1195*5347Sjfrank 			ctl_msg.nmt = NULL;
1196*5347Sjfrank 			mutex_exit(&ctl_msg.nm_lock);
1197*5347Sjfrank 			return;
1198*5347Sjfrank 		}
1199*5347Sjfrank 	}
1200*5347Sjfrank 
1201*5347Sjfrank 	/*
1202*5347Sjfrank 	 * Calculate the number of attempts to connect XSCF based on the
1203*5347Sjfrank 	 * scf driver delay (which is
1204*5347Sjfrank 	 * SCF_DEVBUSY_DELAY*scf_online_wait_rcnt seconds) and the value
1205*5347Sjfrank 	 * of xscf_connect_delay (the total number of seconds to wait
1206*5347Sjfrank 	 * till xscf get ready.)
1207*5347Sjfrank 	 */
1208*5347Sjfrank 	if (repeat_cnt == 0) {
1209*5347Sjfrank 		if ((scf_wait_cnt =
1210*5347Sjfrank 		    (uint_t *)
1211*5347Sjfrank 		    modgetsymvalue("scf_online_wait_rcnt", 0)) == NULL) {
1212*5347Sjfrank 			repeat_cnt = REPEATS;
1213*5347Sjfrank 		} else {
1214*5347Sjfrank 
1215*5347Sjfrank 			xscf_driver_delay = *scf_wait_cnt *
1216*5347Sjfrank 			    SCF_DEVBUSY_DELAY;
1217*5347Sjfrank 			repeat_cnt = (xscf_connect_delay/xscf_driver_delay) + 1;
1218*5347Sjfrank 		}
1219*5347Sjfrank 	}
1220*5347Sjfrank 
1221*5347Sjfrank 	while (ctl_msg.cnt != 0) {
1222*5347Sjfrank 
1223*5347Sjfrank 		/*
1224*5347Sjfrank 		 * Take the very last request from the queue,
1225*5347Sjfrank 		 */
1226*5347Sjfrank 		ctl_msg.now_serving = ctl_msg.head;
1227*5347Sjfrank 		ASSERT(ctl_msg.now_serving != NULL);
1228*5347Sjfrank 
1229*5347Sjfrank 		/*
1230*5347Sjfrank 		 * and discard all the others if any.
1231*5347Sjfrank 		 */
1232*5347Sjfrank 		FREE_THE_TAIL(ctl_msg.now_serving);
1233*5347Sjfrank 		ctl_msg.cnt = 1;
1234*5347Sjfrank 		mutex_exit(&ctl_msg.nm_lock);
1235*5347Sjfrank 
1236*5347Sjfrank 		/*
1237*5347Sjfrank 		 * Pass the name to XSCF. Note please, we do not hold the
1238*5347Sjfrank 		 * mutex while we are doing this.
1239*5347Sjfrank 		 */
1240*5347Sjfrank 		msg_sent = 0;
1241*5347Sjfrank 		for (i = 0; i < repeat_cnt; i++) {
1242*5347Sjfrank 			if (PASS2XSCF(ctl_msg.now_serving, ret)) {
1243*5347Sjfrank 				msg_sent = 1;
1244*5347Sjfrank 				break;
1245*5347Sjfrank 			} else {
1246*5347Sjfrank 				if (ret != EBUSY) {
1247*5347Sjfrank 					cmn_err(CE_NOTE, "pass2xscf_thread:"
1248*5347Sjfrank 					    " unexpected return code"
1249*5347Sjfrank 					    " from scf_service_putinfo():"
1250*5347Sjfrank 					    " %d\n", ret);
1251*5347Sjfrank 				}
1252*5347Sjfrank 			}
1253*5347Sjfrank 		}
1254*5347Sjfrank 
1255*5347Sjfrank 		if (msg_sent) {
1256*5347Sjfrank 
1257*5347Sjfrank 			/*
1258*5347Sjfrank 			 * Remove the request from the list
1259*5347Sjfrank 			 */
1260*5347Sjfrank 			mutex_enter(&ctl_msg.nm_lock);
1261*5347Sjfrank 			msg = ctl_msg.now_serving;
1262*5347Sjfrank 			ctl_msg.now_serving = NULL;
1263*5347Sjfrank 			REMOVE(msg);
1264*5347Sjfrank 			ctl_msg.cnt--;
1265*5347Sjfrank 			mutex_exit(&ctl_msg.nm_lock);
1266*5347Sjfrank 			FREE_MSG(msg);
1267*5347Sjfrank 		} else {
1268*5347Sjfrank 
1269*5347Sjfrank 			/*
1270*5347Sjfrank 			 * If while we have tried to communicate with
1271*5347Sjfrank 			 * XSCF there were any other requests we are
1272*5347Sjfrank 			 * going to drop this one and take the latest
1273*5347Sjfrank 			 * one.  Otherwise we will try to pass this one
1274*5347Sjfrank 			 * again.
1275*5347Sjfrank 			 */
1276*5347Sjfrank 			cmn_err(CE_NOTE,
1277*5347Sjfrank 			    "pass2xscf_thread: "
1278*5347Sjfrank 			    "scf_service_putinfo "
1279*5347Sjfrank 			    "not responding\n");
1280*5347Sjfrank 		}
1281*5347Sjfrank 		mutex_enter(&ctl_msg.nm_lock);
1282*5347Sjfrank 	}
1283*5347Sjfrank 
1284*5347Sjfrank 	/*
1285*5347Sjfrank 	 * The request queue is empty, exit.
1286*5347Sjfrank 	 */
1287*5347Sjfrank 	ctl_msg.nmt = NULL;
1288*5347Sjfrank 	mutex_exit(&ctl_msg.nm_lock);
1289*5347Sjfrank }
1290