10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*5648Ssetje * Common Development and Distribution License (the "License").
6*5648Ssetje * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*5648Ssetje * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/param.h>
290Sstevel@tonic-gate #include <sys/systm.h>
300Sstevel@tonic-gate #include <sys/sysmacros.h>
310Sstevel@tonic-gate #include <sys/sunddi.h>
320Sstevel@tonic-gate #include <sys/esunddi.h>
330Sstevel@tonic-gate #include <sys/platform_module.h>
340Sstevel@tonic-gate #include <sys/errno.h>
350Sstevel@tonic-gate #include <sys/lgrp.h>
360Sstevel@tonic-gate #include <sys/memnode.h>
370Sstevel@tonic-gate #include <sys/promif.h>
380Sstevel@tonic-gate
39511Sminht #define EBUS_NAME "ebus"
40511Sminht #define RTC_NAME "rtc"
410Sstevel@tonic-gate #define SHARED_MI2CV_PATH "/i2c@1f,520000"
420Sstevel@tonic-gate static dev_info_t *shared_mi2cv_dip;
430Sstevel@tonic-gate static kmutex_t chicago_mi2cv_mutex;
440Sstevel@tonic-gate
45511Sminht /*
46511Sminht * External variables
47511Sminht */
48511Sminht extern volatile uint8_t *v_rtc_addr_reg;
49511Sminht
500Sstevel@tonic-gate int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
51511Sminht static void get_ebus_rtc_vaddr(void);
520Sstevel@tonic-gate
530Sstevel@tonic-gate void
startup_platform(void)540Sstevel@tonic-gate startup_platform(void)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate mutex_init(&chicago_mi2cv_mutex, NULL, NULL, NULL);
570Sstevel@tonic-gate }
580Sstevel@tonic-gate
590Sstevel@tonic-gate int
set_platform_tsb_spares()600Sstevel@tonic-gate set_platform_tsb_spares()
610Sstevel@tonic-gate {
620Sstevel@tonic-gate return (0);
630Sstevel@tonic-gate }
640Sstevel@tonic-gate
650Sstevel@tonic-gate void
set_platform_defaults(void)660Sstevel@tonic-gate set_platform_defaults(void)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate extern char *tod_module_name;
69511Sminht
70511Sminht /*
71511Sminht * We need to set tod_module_name explicitly because there is a
72511Sminht * well known South bridge RTC node on chicago and tod_module_name
73511Sminht * gets set to that.
74511Sminht */
75511Sminht tod_module_name = "todbq4802";
76511Sminht
77511Sminht /* Work-around for Chicago platform */
78511Sminht get_ebus_rtc_vaddr();
79511Sminht
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * Definitions for accessing the pci config space of the isa node
840Sstevel@tonic-gate * of Southbridge.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate static ddi_acc_handle_t isa_handle = NULL; /* handle for isa pci space */
870Sstevel@tonic-gate
880Sstevel@tonic-gate
890Sstevel@tonic-gate void
load_platform_drivers(void)900Sstevel@tonic-gate load_platform_drivers(void)
910Sstevel@tonic-gate {
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate * Install power driver which handles the power button.
940Sstevel@tonic-gate */
950Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("power") != DDI_SUCCESS)
960Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"power\" driver.");
970Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("power"));
980Sstevel@tonic-gate
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate * It is OK to return error because 'us' driver is not available
1010Sstevel@tonic-gate * in all clusters (e.g. missing in Core cluster).
1020Sstevel@tonic-gate */
1030Sstevel@tonic-gate (void) i_ddi_attach_hw_nodes("us");
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("grbeep") != DDI_SUCCESS)
1060Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"beep\" driver.");
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate /*
1100Sstevel@tonic-gate * mc-us3i must stay loaded for plat_get_mem_unum()
1110Sstevel@tonic-gate */
1120Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("mc-us3i") != DDI_SUCCESS)
1130Sstevel@tonic-gate cmn_err(CE_WARN, "mc-us3i driver failed to install");
1140Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("mc-us3i"));
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate /*
1170Sstevel@tonic-gate * Figure out which mi2cv dip is shared with OBP for the nvram
1180Sstevel@tonic-gate * device, so the lock can be acquired.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate shared_mi2cv_dip = e_ddi_hold_devi_by_path(SHARED_MI2CV_PATH, 0);
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate /*ARGSUSED*/
1240Sstevel@tonic-gate int
plat_cpu_poweron(struct cpu * cp)1250Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
1260Sstevel@tonic-gate {
1270Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*ARGSUSED*/
1310Sstevel@tonic-gate int
plat_cpu_poweroff(struct cpu * cp)1320Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
1330Sstevel@tonic-gate {
1340Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate /*ARGSUSED*/
1380Sstevel@tonic-gate void
plat_freelist_process(int mnode)1390Sstevel@tonic-gate plat_freelist_process(int mnode)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate char *platform_module_list[] = {
1440Sstevel@tonic-gate "mi2cv",
1450Sstevel@tonic-gate "jbusppm",
1460Sstevel@tonic-gate "pca9556",
1470Sstevel@tonic-gate "ppm",
1480Sstevel@tonic-gate (char *)0
1490Sstevel@tonic-gate };
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate /*ARGSUSED*/
1520Sstevel@tonic-gate void
plat_tod_fault(enum tod_fault_type tod_bad)1530Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
1540Sstevel@tonic-gate {
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate /*ARGSUSED*/
1580Sstevel@tonic-gate int
plat_get_mem_unum(int synd_code,uint64_t flt_addr,int flt_bus_id,int flt_in_memory,ushort_t flt_status,char * buf,int buflen,int * lenp)1590Sstevel@tonic-gate plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
1600Sstevel@tonic-gate int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
1610Sstevel@tonic-gate {
1620Sstevel@tonic-gate if (flt_in_memory && (p2get_mem_unum != NULL))
1630Sstevel@tonic-gate return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
1640Sstevel@tonic-gate buf, buflen, lenp));
1650Sstevel@tonic-gate else
1660Sstevel@tonic-gate return (ENOTSUP);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate /*ARGSUSED*/
1700Sstevel@tonic-gate int
plat_get_cpu_unum(int cpuid,char * buf,int buflen,int * lenp)1710Sstevel@tonic-gate plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate if (snprintf(buf, buflen, "MB") >= buflen) {
1740Sstevel@tonic-gate return (ENOSPC);
1750Sstevel@tonic-gate } else {
1760Sstevel@tonic-gate *lenp = strlen(buf);
1770Sstevel@tonic-gate return (0);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate /*
1820Sstevel@tonic-gate * Fiesta support for lgroups.
1830Sstevel@tonic-gate *
1840Sstevel@tonic-gate * On fiesta platform, an lgroup platform handle == CPU id
1850Sstevel@tonic-gate */
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate /*
1880Sstevel@tonic-gate * Macro for extracting the CPU number from the CPU id
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate #define CPUID_TO_LGRP(id) ((id) & 0x7)
1910Sstevel@tonic-gate #define CHICAGO_MC_SHIFT 36
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate /*
1940Sstevel@tonic-gate * Return the platform handle for the lgroup containing the given CPU
1950Sstevel@tonic-gate */
1960Sstevel@tonic-gate void *
plat_lgrp_cpu_to_hand(processorid_t id)1970Sstevel@tonic-gate plat_lgrp_cpu_to_hand(processorid_t id)
1980Sstevel@tonic-gate {
199588Sminht return ((void *)(uintptr_t)CPUID_TO_LGRP(id));
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate * Platform specific lgroup initialization
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate void
plat_lgrp_init(void)2060Sstevel@tonic-gate plat_lgrp_init(void)
2070Sstevel@tonic-gate {
208789Sahrens pnode_t curnode;
2091306Sess char tmp_name[sizeof (OBP_CPU)];
2100Sstevel@tonic-gate int portid;
2110Sstevel@tonic-gate int cpucnt = 0;
2120Sstevel@tonic-gate int max_portid = -1;
2130Sstevel@tonic-gate extern uint32_t lgrp_expand_proc_thresh;
2140Sstevel@tonic-gate extern uint32_t lgrp_expand_proc_diff;
2150Sstevel@tonic-gate extern pgcnt_t lgrp_mem_free_thresh;
2160Sstevel@tonic-gate extern uint32_t lgrp_loadavg_tolerance;
2170Sstevel@tonic-gate extern uint32_t lgrp_loadavg_max_effect;
2180Sstevel@tonic-gate extern uint32_t lgrp_load_thresh;
2190Sstevel@tonic-gate extern lgrp_mem_policy_t lgrp_mem_policy_root;
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate /*
2220Sstevel@tonic-gate * Count the number of CPUs installed to determine if
2230Sstevel@tonic-gate * NUMA optimization should be enabled or not.
2240Sstevel@tonic-gate *
2250Sstevel@tonic-gate * All CPU nodes reside in the root node and have a
2260Sstevel@tonic-gate * device type "cpu".
2270Sstevel@tonic-gate */
2280Sstevel@tonic-gate curnode = prom_rootnode();
2290Sstevel@tonic-gate for (curnode = prom_childnode(curnode); curnode;
2300Sstevel@tonic-gate curnode = prom_nextnode(curnode)) {
2311306Sess bzero(tmp_name, sizeof (tmp_name));
2321306Sess if (prom_bounded_getprop(curnode, OBP_DEVICETYPE, tmp_name,
2331306Sess sizeof (tmp_name)) == -1 || strcmp(tmp_name, OBP_CPU) != 0)
2340Sstevel@tonic-gate continue;
2350Sstevel@tonic-gate
2361306Sess cpucnt++;
2371306Sess if (prom_getprop(curnode, "portid", (caddr_t)&portid) !=
2381306Sess -1 && portid > max_portid)
2391306Sess max_portid = portid;
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate if (cpucnt <= 1)
2420Sstevel@tonic-gate max_mem_nodes = 1;
2430Sstevel@tonic-gate else if (max_portid >= 0 && max_portid < MAX_MEM_NODES)
2440Sstevel@tonic-gate max_mem_nodes = max_portid + 1;
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate /*
2470Sstevel@tonic-gate * Set tuneables for fiesta architecture
2480Sstevel@tonic-gate *
2490Sstevel@tonic-gate * lgrp_expand_proc_thresh is the minimum load on the lgroups
2500Sstevel@tonic-gate * this process is currently running on before considering
2510Sstevel@tonic-gate * expanding threads to another lgroup.
2520Sstevel@tonic-gate *
2530Sstevel@tonic-gate * lgrp_expand_proc_diff determines how much less the remote lgroup
2540Sstevel@tonic-gate * must be loaded before expanding to it.
2550Sstevel@tonic-gate *
2560Sstevel@tonic-gate * Optimize for memory bandwidth by spreading multi-threaded
2570Sstevel@tonic-gate * program to different lgroups.
2580Sstevel@tonic-gate */
2590Sstevel@tonic-gate lgrp_expand_proc_thresh = lgrp_loadavg_max_effect - 1;
2600Sstevel@tonic-gate lgrp_expand_proc_diff = lgrp_loadavg_max_effect / 2;
2610Sstevel@tonic-gate lgrp_loadavg_tolerance = lgrp_loadavg_max_effect / 2;
2620Sstevel@tonic-gate lgrp_mem_free_thresh = 1; /* home lgrp must have some memory */
2630Sstevel@tonic-gate lgrp_expand_proc_thresh = lgrp_loadavg_max_effect - 1;
2640Sstevel@tonic-gate lgrp_mem_policy_root = LGRP_MEM_POLICY_NEXT;
2650Sstevel@tonic-gate lgrp_load_thresh = 0;
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate mem_node_pfn_shift = CHICAGO_MC_SHIFT - MMU_PAGESHIFT;
2680Sstevel@tonic-gate }
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate /*
2710Sstevel@tonic-gate * Return latency between "from" and "to" lgroups
2720Sstevel@tonic-gate *
2730Sstevel@tonic-gate * This latency number can only be used for relative comparison
2740Sstevel@tonic-gate * between lgroups on the running system, cannot be used across platforms,
2750Sstevel@tonic-gate * and may not reflect the actual latency. It is platform and implementation
2760Sstevel@tonic-gate * specific, so platform gets to decide its value. It would be nice if the
2770Sstevel@tonic-gate * number was at least proportional to make comparisons more meaningful though.
2780Sstevel@tonic-gate * NOTE: The numbers below are supposed to be load latencies for uncached
2790Sstevel@tonic-gate * memory divided by 10.
2800Sstevel@tonic-gate */
2810Sstevel@tonic-gate int
plat_lgrp_latency(lgrp_handle_t from,lgrp_handle_t to)2820Sstevel@tonic-gate plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
2830Sstevel@tonic-gate {
2840Sstevel@tonic-gate /*
2850Sstevel@tonic-gate * Return remote latency when there are more than two lgroups
2860Sstevel@tonic-gate * (root and child) and getting latency between two different
2870Sstevel@tonic-gate * lgroups or root is involved
2880Sstevel@tonic-gate */
2890Sstevel@tonic-gate if (lgrp_optimizations() && (from != to ||
2900Sstevel@tonic-gate from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
2910Sstevel@tonic-gate return (17);
2920Sstevel@tonic-gate else
2930Sstevel@tonic-gate return (12);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate int
plat_pfn_to_mem_node(pfn_t pfn)2970Sstevel@tonic-gate plat_pfn_to_mem_node(pfn_t pfn)
2980Sstevel@tonic-gate {
2990Sstevel@tonic-gate ASSERT(max_mem_nodes > 1);
3000Sstevel@tonic-gate return (pfn >> mem_node_pfn_shift);
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate /*
3040Sstevel@tonic-gate * Assign memnode to lgroups
3050Sstevel@tonic-gate */
3060Sstevel@tonic-gate void
plat_fill_mc(pnode_t nodeid)307789Sahrens plat_fill_mc(pnode_t nodeid)
3080Sstevel@tonic-gate {
3090Sstevel@tonic-gate int portid;
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate /*
3120Sstevel@tonic-gate * Chicago memory controller portid == global CPU id
3130Sstevel@tonic-gate */
3140Sstevel@tonic-gate if ((prom_getprop(nodeid, "portid", (caddr_t)&portid) == -1) ||
3150Sstevel@tonic-gate (portid < 0))
3160Sstevel@tonic-gate return;
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate if (portid < max_mem_nodes)
3190Sstevel@tonic-gate plat_assign_lgrphand_to_mem_node((lgrp_handle_t)portid, portid);
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate /*
3230Sstevel@tonic-gate * Common locking enter code
3240Sstevel@tonic-gate */
3250Sstevel@tonic-gate void
plat_setprop_enter(void)3260Sstevel@tonic-gate plat_setprop_enter(void)
3270Sstevel@tonic-gate {
3280Sstevel@tonic-gate mutex_enter(&chicago_mi2cv_mutex);
3290Sstevel@tonic-gate }
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate /*
3320Sstevel@tonic-gate * Common locking exit code
3330Sstevel@tonic-gate */
3340Sstevel@tonic-gate void
plat_setprop_exit(void)3350Sstevel@tonic-gate plat_setprop_exit(void)
3360Sstevel@tonic-gate {
3370Sstevel@tonic-gate mutex_exit(&chicago_mi2cv_mutex);
3380Sstevel@tonic-gate }
3390Sstevel@tonic-gate
3400Sstevel@tonic-gate /*
3410Sstevel@tonic-gate * Called by mi2cv driver
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate void
plat_shared_i2c_enter(dev_info_t * i2cnexus_dip)3440Sstevel@tonic-gate plat_shared_i2c_enter(dev_info_t *i2cnexus_dip)
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate if (i2cnexus_dip == shared_mi2cv_dip) {
3470Sstevel@tonic-gate plat_setprop_enter();
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate /*
3520Sstevel@tonic-gate * Called by mi2cv driver
3530Sstevel@tonic-gate */
3540Sstevel@tonic-gate void
plat_shared_i2c_exit(dev_info_t * i2cnexus_dip)3550Sstevel@tonic-gate plat_shared_i2c_exit(dev_info_t *i2cnexus_dip)
3560Sstevel@tonic-gate {
3570Sstevel@tonic-gate if (i2cnexus_dip == shared_mi2cv_dip) {
3580Sstevel@tonic-gate plat_setprop_exit();
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate }
361511Sminht
362511Sminht /*
363511Sminht * Work-around for the Chicago platform.
364511Sminht * There are two RTCs in the Chicago platform, one on the Southbridge
365511Sminht * and one on the EBUS.
366511Sminht * In the current Solaris implementation, have_rtc in sun4u/os/fillsysinfo.c
367511Sminht * returns address of the first rtc it sees. In this case, it's the SB RTC.
368511Sminht *
369511Sminht * get_ebus_rtc_vaddr() looks for the EBUS RTC and setup the right address.
370511Sminht * If there is no EBUS RTC node or the RTC node does not have the valid
371511Sminht * address property, get_ebus_rtc_vaddr() will fail.
372511Sminht */
373511Sminht static void
get_ebus_rtc_vaddr()374511Sminht get_ebus_rtc_vaddr()
375511Sminht {
376789Sahrens pnode_t node;
377511Sminht int size;
378511Sminht uint32_t eaddr;
379511Sminht
380511Sminht /* Find ebus RTC node */
381511Sminht if ((node = prom_findnode_byname(prom_rootnode(),
382511Sminht EBUS_NAME)) == OBP_NONODE)
383511Sminht cmn_err(CE_PANIC, "ebus node not present\n");
384511Sminht if ((node = prom_findnode_byname(node, RTC_NAME)) == OBP_NONODE)
385511Sminht cmn_err(CE_PANIC, "ebus RTC node not found\n");
386511Sminht
387511Sminht /* Make sure the ebus RTC address property is valid */
388511Sminht if ((size = prom_getproplen(node, "address")) == -1)
389511Sminht cmn_err(CE_PANIC, "ebus RTC addr prop. length not found\n");
390511Sminht if (size != sizeof (eaddr))
391511Sminht cmn_err(CE_PANIC, "ebus RTC addr length not OK."
392588Sminht " expected = %lu found =%d\n", sizeof (eaddr), size);
393511Sminht if (prom_getprop(node, "address", (caddr_t)&eaddr) == -1)
394511Sminht cmn_err(CE_PANIC, "ebus RTC addr propery not found\n");
395588Sminht v_rtc_addr_reg = (volatile unsigned char *)(uintptr_t)eaddr;
396511Sminht
397511Sminht /*
398511Sminht * Does this rtc have watchdog support?
399511Sminht */
400511Sminht if (prom_getproplen(node, "watchdog-enable") != -1)
401511Sminht watchdog_available = 1;
402511Sminht }
403