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
390Sstevel@tonic-gate int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
400Sstevel@tonic-gate
410Sstevel@tonic-gate void
startup_platform(void)420Sstevel@tonic-gate startup_platform(void)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate }
450Sstevel@tonic-gate
460Sstevel@tonic-gate int
set_platform_tsb_spares()470Sstevel@tonic-gate set_platform_tsb_spares()
480Sstevel@tonic-gate {
490Sstevel@tonic-gate return (0);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate
520Sstevel@tonic-gate void
set_platform_defaults(void)530Sstevel@tonic-gate set_platform_defaults(void)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * Definitions for accessing the pci config space of the isa node
590Sstevel@tonic-gate * of Southbridge.
600Sstevel@tonic-gate */
610Sstevel@tonic-gate #define ENCHILADA_ISA_PATHNAME "/pci@1e,600000/isa@7"
620Sstevel@tonic-gate static ddi_acc_handle_t isa_handle; /* handle for isa pci space */
630Sstevel@tonic-gate
640Sstevel@tonic-gate
650Sstevel@tonic-gate void
load_platform_drivers(void)660Sstevel@tonic-gate load_platform_drivers(void)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate dev_info_t *dip; /* dip of the isa driver */
690Sstevel@tonic-gate
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate * Install power driver which handles the power button.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("power") != DDI_SUCCESS)
740Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"power\" driver.");
750Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("power"));
760Sstevel@tonic-gate
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate * It is OK to return error because 'us' driver is not available
790Sstevel@tonic-gate * in all clusters (e.g. missing in Core cluster).
800Sstevel@tonic-gate */
810Sstevel@tonic-gate (void) i_ddi_attach_hw_nodes("us");
820Sstevel@tonic-gate
830Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("grbeep") != DDI_SUCCESS)
840Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"beep\" driver.");
850Sstevel@tonic-gate
860Sstevel@tonic-gate
870Sstevel@tonic-gate /*
880Sstevel@tonic-gate * mc-us3i must stay loaded for plat_get_mem_unum()
890Sstevel@tonic-gate */
900Sstevel@tonic-gate if (i_ddi_attach_hw_nodes("mc-us3i") != DDI_SUCCESS)
910Sstevel@tonic-gate cmn_err(CE_WARN, "mc-us3i driver failed to install");
920Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("mc-us3i"));
930Sstevel@tonic-gate
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate * Install Isa driver. This is required for the southbridge IDE
960Sstevel@tonic-gate * workaround - to reset the IDE channel during IDE bus reset.
970Sstevel@tonic-gate * Panic the system in case ISA driver could not be loaded or
980Sstevel@tonic-gate * any problem in accessing its pci config space. Since the register
990Sstevel@tonic-gate * to reset the channel for IDE is in ISA config space!.
1000Sstevel@tonic-gate */
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate dip = e_ddi_hold_devi_by_path(ENCHILADA_ISA_PATHNAME, 0);
1030Sstevel@tonic-gate if (dip == NULL) {
1040Sstevel@tonic-gate cmn_err(CE_PANIC, "Could not install the isa driver\n");
1050Sstevel@tonic-gate return;
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate if (pci_config_setup(dip, &isa_handle) != DDI_SUCCESS) {
1090Sstevel@tonic-gate cmn_err(CE_PANIC, "Could not get the config space of isa\n");
1100Sstevel@tonic-gate return;
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate * This routine provides a workaround for a bug in the SB chip which
1160Sstevel@tonic-gate * can cause data corruption. Will be invoked from the IDE HBA driver for
1170Sstevel@tonic-gate * Acer SouthBridge at the time of IDE bus reset.
1180Sstevel@tonic-gate */
1190Sstevel@tonic-gate /*ARGSUSED*/
1200Sstevel@tonic-gate int
plat_ide_chipreset(dev_info_t * dip,int chno)1210Sstevel@tonic-gate plat_ide_chipreset(dev_info_t *dip, int chno)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate uint8_t val;
1240Sstevel@tonic-gate int ret = DDI_SUCCESS;
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate if (isa_handle == NULL) {
1270Sstevel@tonic-gate return (DDI_FAILURE);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate val = pci_config_get8(isa_handle, 0x58);
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate * The dip passed as the argument is not used here.
1330Sstevel@tonic-gate * This will be needed for platforms which have multiple on-board SB,
1340Sstevel@tonic-gate * The dip passed will be used to match the corresponding ISA node.
1350Sstevel@tonic-gate */
1360Sstevel@tonic-gate switch (chno) {
1370Sstevel@tonic-gate case 0:
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate * First disable the primary channel then re-enable it.
1400Sstevel@tonic-gate * As per ALI no wait should be required in between have
1410Sstevel@tonic-gate * given 1ms delay in between to be on safer side.
1420Sstevel@tonic-gate * bit 2 of register 0x58 when 0 disable the channel 0.
1430Sstevel@tonic-gate * bit 2 of register 0x58 when 1 enables the channel 0.
1440Sstevel@tonic-gate */
1450Sstevel@tonic-gate pci_config_put8(isa_handle, 0x58, val & 0xFB);
1460Sstevel@tonic-gate drv_usecwait(1000);
1470Sstevel@tonic-gate pci_config_put8(isa_handle, 0x58, val);
1480Sstevel@tonic-gate break;
1490Sstevel@tonic-gate case 1:
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate * bit 3 of register 0x58 when 0 disable the channel 1.
1520Sstevel@tonic-gate * bit 3 of register 0x58 when 1 enables the channel 1.
1530Sstevel@tonic-gate */
1540Sstevel@tonic-gate pci_config_put8(isa_handle, 0x58, val & 0xF7);
1550Sstevel@tonic-gate drv_usecwait(1000);
1560Sstevel@tonic-gate pci_config_put8(isa_handle, 0x58, val);
1570Sstevel@tonic-gate break;
1580Sstevel@tonic-gate default:
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate * Unknown channel number passed. Return failure.
1610Sstevel@tonic-gate */
1620Sstevel@tonic-gate ret = DDI_FAILURE;
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate return (ret);
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate /*ARGSUSED*/
1700Sstevel@tonic-gate int
plat_cpu_poweron(struct cpu * cp)1710Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate /*ARGSUSED*/
1770Sstevel@tonic-gate int
plat_cpu_poweroff(struct cpu * cp)1780Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
1790Sstevel@tonic-gate {
1800Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate /*ARGSUSED*/
1840Sstevel@tonic-gate void
plat_freelist_process(int mnode)1850Sstevel@tonic-gate plat_freelist_process(int mnode)
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate char *platform_module_list[] = {
1900Sstevel@tonic-gate "m1535ppm",
1910Sstevel@tonic-gate "jbusppm",
1920Sstevel@tonic-gate "ics951601",
1930Sstevel@tonic-gate "pca9556",
1940Sstevel@tonic-gate "ppm",
1950Sstevel@tonic-gate (char *)0
1960Sstevel@tonic-gate };
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate /*ARGSUSED*/
1990Sstevel@tonic-gate void
plat_tod_fault(enum tod_fault_type tod_bad)2000Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate /*ARGSUSED*/
2050Sstevel@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)2060Sstevel@tonic-gate plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
2070Sstevel@tonic-gate int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate if (flt_in_memory && (p2get_mem_unum != NULL))
2100Sstevel@tonic-gate return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
2110Sstevel@tonic-gate buf, buflen, lenp));
2120Sstevel@tonic-gate else
2130Sstevel@tonic-gate return (ENOTSUP);
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate /*ARGSUSED*/
2170Sstevel@tonic-gate int
plat_get_cpu_unum(int cpuid,char * buf,int buflen,int * lenp)2180Sstevel@tonic-gate plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate if (snprintf(buf, buflen, "MB") >= buflen) {
2210Sstevel@tonic-gate return (ENOSPC);
2220Sstevel@tonic-gate } else {
2230Sstevel@tonic-gate *lenp = strlen(buf);
2240Sstevel@tonic-gate return (0);
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate /*
2290Sstevel@tonic-gate * Fiesta support for lgroups.
2300Sstevel@tonic-gate *
2310Sstevel@tonic-gate * On fiesta platform, an lgroup platform handle == CPU id
2320Sstevel@tonic-gate */
2330Sstevel@tonic-gate
2340Sstevel@tonic-gate /*
2350Sstevel@tonic-gate * Macro for extracting the CPU number from the CPU id
2360Sstevel@tonic-gate */
2370Sstevel@tonic-gate #define CPUID_TO_LGRP(id) ((id) & 0x7)
2380Sstevel@tonic-gate #define ENCHILADA_MC_SHIFT 36
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate * Return the platform handle for the lgroup containing the given CPU
2420Sstevel@tonic-gate */
2430Sstevel@tonic-gate lgrp_handle_t
plat_lgrp_cpu_to_hand(processorid_t id)2440Sstevel@tonic-gate plat_lgrp_cpu_to_hand(processorid_t id)
2450Sstevel@tonic-gate {
2460Sstevel@tonic-gate return (CPUID_TO_LGRP(id));
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate /*
2500Sstevel@tonic-gate * Platform specific lgroup initialization
2510Sstevel@tonic-gate */
2520Sstevel@tonic-gate void
plat_lgrp_init(void)2530Sstevel@tonic-gate plat_lgrp_init(void)
2540Sstevel@tonic-gate {
255789Sahrens pnode_t curnode;
2560Sstevel@tonic-gate char tmp_name[MAXSYSNAME];
2570Sstevel@tonic-gate int portid;
2580Sstevel@tonic-gate int cpucnt = 0;
2590Sstevel@tonic-gate int max_portid = -1;
2600Sstevel@tonic-gate extern uint32_t lgrp_expand_proc_thresh;
2610Sstevel@tonic-gate extern uint32_t lgrp_expand_proc_diff;
2620Sstevel@tonic-gate extern pgcnt_t lgrp_mem_free_thresh;
2630Sstevel@tonic-gate extern uint32_t lgrp_loadavg_tolerance;
2640Sstevel@tonic-gate extern uint32_t lgrp_loadavg_max_effect;
2650Sstevel@tonic-gate extern uint32_t lgrp_load_thresh;
2660Sstevel@tonic-gate extern lgrp_mem_policy_t lgrp_mem_policy_root;
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate /*
2690Sstevel@tonic-gate * Count the number of CPUs installed to determine if
2700Sstevel@tonic-gate * NUMA optimization should be enabled or not.
2710Sstevel@tonic-gate *
2720Sstevel@tonic-gate * All CPU nodes reside in the root node and have a
2730Sstevel@tonic-gate * device type "cpu".
2740Sstevel@tonic-gate */
2750Sstevel@tonic-gate curnode = prom_rootnode();
2760Sstevel@tonic-gate for (curnode = prom_childnode(curnode); curnode;
2770Sstevel@tonic-gate curnode = prom_nextnode(curnode)) {
2780Sstevel@tonic-gate bzero(tmp_name, MAXSYSNAME);
2790Sstevel@tonic-gate if (prom_getprop(curnode, OBP_NAME, (caddr_t)tmp_name) == -1 ||
2800Sstevel@tonic-gate prom_getprop(curnode, OBP_DEVICETYPE, tmp_name) == -1 ||
2810Sstevel@tonic-gate strcmp(tmp_name, "cpu") != 0)
2820Sstevel@tonic-gate continue;
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate cpucnt++;
2850Sstevel@tonic-gate if (prom_getprop(curnode, "portid", (caddr_t)&portid) != -1 &&
2860Sstevel@tonic-gate portid > max_portid)
2870Sstevel@tonic-gate max_portid = portid;
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate if (cpucnt <= 1)
2900Sstevel@tonic-gate max_mem_nodes = 1;
2910Sstevel@tonic-gate else if (max_portid >= 0 && max_portid < MAX_MEM_NODES)
2920Sstevel@tonic-gate max_mem_nodes = max_portid + 1;
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate /*
2950Sstevel@tonic-gate * Set tuneables for fiesta architecture
2960Sstevel@tonic-gate *
2970Sstevel@tonic-gate * lgrp_expand_proc_thresh is the minimum load on the lgroups
2980Sstevel@tonic-gate * this process is currently running on before considering
2990Sstevel@tonic-gate * expanding threads to another lgroup.
3000Sstevel@tonic-gate *
3010Sstevel@tonic-gate * lgrp_expand_proc_diff determines how much less the remote lgroup
3020Sstevel@tonic-gate * must be loaded before expanding to it.
3030Sstevel@tonic-gate *
3040Sstevel@tonic-gate * Optimize for memory bandwidth by spreading multi-threaded
3050Sstevel@tonic-gate * program to different lgroups.
3060Sstevel@tonic-gate */
3070Sstevel@tonic-gate lgrp_expand_proc_thresh = lgrp_loadavg_max_effect - 1;
3080Sstevel@tonic-gate lgrp_expand_proc_diff = lgrp_loadavg_max_effect / 2;
3090Sstevel@tonic-gate lgrp_loadavg_tolerance = lgrp_loadavg_max_effect / 2;
3100Sstevel@tonic-gate lgrp_mem_free_thresh = 1; /* home lgrp must have some memory */
3110Sstevel@tonic-gate lgrp_expand_proc_thresh = lgrp_loadavg_max_effect - 1;
3120Sstevel@tonic-gate lgrp_mem_policy_root = LGRP_MEM_POLICY_NEXT;
3130Sstevel@tonic-gate lgrp_load_thresh = 0;
3140Sstevel@tonic-gate
3150Sstevel@tonic-gate mem_node_pfn_shift = ENCHILADA_MC_SHIFT - MMU_PAGESHIFT;
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate * Return latency between "from" and "to" lgroups
3200Sstevel@tonic-gate *
3210Sstevel@tonic-gate * This latency number can only be used for relative comparison
3220Sstevel@tonic-gate * between lgroups on the running system, cannot be used across platforms,
3230Sstevel@tonic-gate * and may not reflect the actual latency. It is platform and implementation
3240Sstevel@tonic-gate * specific, so platform gets to decide its value. It would be nice if the
3250Sstevel@tonic-gate * number was at least proportional to make comparisons more meaningful though.
3260Sstevel@tonic-gate * NOTE: The numbers below are supposed to be load latencies for uncached
3270Sstevel@tonic-gate * memory divided by 10.
3280Sstevel@tonic-gate */
3290Sstevel@tonic-gate int
plat_lgrp_latency(lgrp_handle_t from,lgrp_handle_t to)3300Sstevel@tonic-gate plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate /*
3330Sstevel@tonic-gate * Return remote latency when there are more than two lgroups
3340Sstevel@tonic-gate * (root and child) and getting latency between two different
3350Sstevel@tonic-gate * lgroups or root is involved
3360Sstevel@tonic-gate */
3370Sstevel@tonic-gate if (lgrp_optimizations() && (from != to ||
3380Sstevel@tonic-gate from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
3390Sstevel@tonic-gate return (17);
3400Sstevel@tonic-gate else
3410Sstevel@tonic-gate return (12);
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate int
plat_pfn_to_mem_node(pfn_t pfn)3450Sstevel@tonic-gate plat_pfn_to_mem_node(pfn_t pfn)
3460Sstevel@tonic-gate {
3470Sstevel@tonic-gate ASSERT(max_mem_nodes > 1);
3480Sstevel@tonic-gate return (pfn >> mem_node_pfn_shift);
3490Sstevel@tonic-gate }
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate /*
3520Sstevel@tonic-gate * Assign memnode to lgroups
3530Sstevel@tonic-gate */
3540Sstevel@tonic-gate void
plat_fill_mc(pnode_t nodeid)355789Sahrens plat_fill_mc(pnode_t nodeid)
3560Sstevel@tonic-gate {
3570Sstevel@tonic-gate int portid;
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate /*
3600Sstevel@tonic-gate * Enchilada memory controller portid == global CPU id
3610Sstevel@tonic-gate */
3620Sstevel@tonic-gate if ((prom_getprop(nodeid, "portid", (caddr_t)&portid) == -1) ||
3630Sstevel@tonic-gate (portid < 0))
3640Sstevel@tonic-gate return;
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate if (portid < max_mem_nodes)
3670Sstevel@tonic-gate plat_assign_lgrphand_to_mem_node(portid, portid);
3680Sstevel@tonic-gate }
369