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
52659Ssusans * Common Development and Distribution License (the "License").
62659Ssusans * 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 */
21*11311SSurya.Prakki@Sun.COM
220Sstevel@tonic-gate /*
23*11311SSurya.Prakki@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/param.h>
280Sstevel@tonic-gate #include <sys/systm.h>
290Sstevel@tonic-gate #include <sys/sunddi.h>
300Sstevel@tonic-gate #include <sys/esunddi.h>
310Sstevel@tonic-gate #include <sys/sunndi.h>
320Sstevel@tonic-gate #include <sys/ddi.h>
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/sysmacros.h>
350Sstevel@tonic-gate #include <sys/note.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate #include <sys/platform_module.h>
380Sstevel@tonic-gate #include <sys/errno.h>
390Sstevel@tonic-gate #include <sys/i2c/clients/i2c_client.h>
400Sstevel@tonic-gate #include <sys/cherrystone.h>
410Sstevel@tonic-gate #include <sys/machsystm.h>
420Sstevel@tonic-gate #include <sys/promif.h>
430Sstevel@tonic-gate #include <vm/page.h>
440Sstevel@tonic-gate #include <sys/memnode.h>
450Sstevel@tonic-gate #include <vm/vm_dep.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate /* Cherrystone Keyswitch Information */
480Sstevel@tonic-gate #define CHERRY_KEY_POLL_PORT 3
490Sstevel@tonic-gate #define CHERRY_KEY_POLL_BIT 2
500Sstevel@tonic-gate #define CHERRY_KEY_POLL_INTVL 10
510Sstevel@tonic-gate
520Sstevel@tonic-gate #define SHARED_PCF8584_PATH "/pci@9,700000/ebus@1/i2c@1,2e/nvram@4,a4"
530Sstevel@tonic-gate static dev_info_t *shared_pcf8584_dip;
540Sstevel@tonic-gate static kmutex_t cherry_pcf8584_mutex;
550Sstevel@tonic-gate
560Sstevel@tonic-gate static boolean_t key_locked_bit;
570Sstevel@tonic-gate static clock_t keypoll_timeout_hz;
580Sstevel@tonic-gate
590Sstevel@tonic-gate /*
60605Slm66018 * Table that maps memory slices to a specific memnode.
61605Slm66018 */
62605Slm66018 int slice_to_memnode[CHERRYSTONE_MAX_SLICE];
63605Slm66018
64605Slm66018 /*
650Sstevel@tonic-gate * For software memory interleaving support.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate static void update_mem_bounds(int, int, int, uint64_t, uint64_t);
680Sstevel@tonic-gate
690Sstevel@tonic-gate static uint64_t
700Sstevel@tonic-gate slice_table[CHERRYSTONE_SBD_SLOTS][CHERRYSTONE_CPUS_PER_BOARD]
710Sstevel@tonic-gate [CHERRYSTONE_BANKS_PER_MC][2];
720Sstevel@tonic-gate
730Sstevel@tonic-gate #define SLICE_PA 0
740Sstevel@tonic-gate #define SLICE_SPAN 1
750Sstevel@tonic-gate
760Sstevel@tonic-gate /* Function prototypes */
770Sstevel@tonic-gate int (*p2get_mem_unum)(int, uint64_t, char *, int, int *);
780Sstevel@tonic-gate
790Sstevel@tonic-gate int (*cherry_ssc050_get_port_bit) (dev_info_t *, int, int, uint8_t *, int);
800Sstevel@tonic-gate extern void (*abort_seq_handler)();
810Sstevel@tonic-gate
820Sstevel@tonic-gate static int cherry_dev_search(dev_info_t *, void *);
830Sstevel@tonic-gate static void keyswitch_poll(void *);
840Sstevel@tonic-gate static void cherry_abort_seq_handler(char *msg);
850Sstevel@tonic-gate
860Sstevel@tonic-gate /* Function definitions from this point forward. */
870Sstevel@tonic-gate
880Sstevel@tonic-gate int
set_platform_tsb_spares()890Sstevel@tonic-gate set_platform_tsb_spares()
900Sstevel@tonic-gate {
910Sstevel@tonic-gate return (0);
920Sstevel@tonic-gate }
930Sstevel@tonic-gate
940Sstevel@tonic-gate void
startup_platform(void)950Sstevel@tonic-gate startup_platform(void)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate * Disable an active h/w watchdog timer
990Sstevel@tonic-gate * upon exit to OBP.
1000Sstevel@tonic-gate */
1010Sstevel@tonic-gate extern int disable_watchdog_on_exit;
1020Sstevel@tonic-gate disable_watchdog_on_exit = 1;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate mutex_init(&cherry_pcf8584_mutex, NULL, NULL, NULL);
1050Sstevel@tonic-gate }
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate #pragma weak mmu_init_large_pages
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate void
set_platform_defaults(void)1100Sstevel@tonic-gate set_platform_defaults(void)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate extern void mmu_init_large_pages(size_t);
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate if ((mmu_page_sizes == max_mmu_page_sizes) &&
1152659Ssusans (mmu_ism_pagesize != DEFAULT_ISM_PAGESIZE)) {
1160Sstevel@tonic-gate if (&mmu_init_large_pages)
1170Sstevel@tonic-gate mmu_init_large_pages(mmu_ism_pagesize);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate }
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate void
load_platform_modules(void)1220Sstevel@tonic-gate load_platform_modules(void)
1230Sstevel@tonic-gate {
1240Sstevel@tonic-gate if (modload("drv", "pmc") < 0) {
1250Sstevel@tonic-gate cmn_err(CE_NOTE, "pmc driver failed to load");
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate void
load_platform_drivers(void)1300Sstevel@tonic-gate load_platform_drivers(void)
1310Sstevel@tonic-gate {
1320Sstevel@tonic-gate char **drv;
1330Sstevel@tonic-gate dev_info_t *i2cnexus_dip;
1340Sstevel@tonic-gate dev_info_t *keysw_dip = NULL;
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate static char *boot_time_drivers[] = {
1370Sstevel@tonic-gate "todds1287",
1380Sstevel@tonic-gate "mc-us3",
1390Sstevel@tonic-gate "ssc050",
1400Sstevel@tonic-gate NULL
1410Sstevel@tonic-gate };
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate for (drv = boot_time_drivers; *drv; drv++) {
1440Sstevel@tonic-gate if (i_ddi_attach_hw_nodes(*drv) != DDI_SUCCESS)
1450Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to install \"%s\" driver.",
1465648Ssetje *drv);
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate * mc-us3 and ssc050 must stay loaded for plat_get_mem_unum()
1510Sstevel@tonic-gate * and keyswitch_poll()
1520Sstevel@tonic-gate */
1530Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("mc-us3"));
1540Sstevel@tonic-gate (void) ddi_hold_driver(ddi_name_to_major("ssc050"));
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /* Gain access into the ssc050_get_port function */
1570Sstevel@tonic-gate cherry_ssc050_get_port_bit = (int (*) (dev_info_t *, int, int,
1585648Ssetje uint8_t *, int)) modgetsymvalue("ssc050_get_port_bit", 0);
1590Sstevel@tonic-gate if (cherry_ssc050_get_port_bit == NULL) {
1600Sstevel@tonic-gate cmn_err(CE_WARN, "cannot find ssc050_get_port_bit");
1610Sstevel@tonic-gate return;
1620Sstevel@tonic-gate }
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate e_ddi_walk_driver("i2c-ssc050", cherry_dev_search, (void *)&keysw_dip);
1650Sstevel@tonic-gate ASSERT(keysw_dip != NULL);
1660Sstevel@tonic-gate
1673402Smb158278 /*
1683402Smb158278 * prevent detach of i2c-ssc050
1693402Smb158278 */
1703402Smb158278 e_ddi_hold_devi(keysw_dip);
1713402Smb158278
1720Sstevel@tonic-gate keypoll_timeout_hz = drv_usectohz(10 * MICROSEC);
1730Sstevel@tonic-gate keyswitch_poll(keysw_dip);
1740Sstevel@tonic-gate abort_seq_handler = cherry_abort_seq_handler;
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate /*
1770Sstevel@tonic-gate * Figure out which pcf8584_dip is shared with OBP for the nvram
1780Sstevel@tonic-gate * device, so the lock can be acquired.
1790Sstevel@tonic-gate */
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate i2cnexus_dip = e_ddi_hold_devi_by_path(SHARED_PCF8584_PATH, 0);
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate ASSERT(i2cnexus_dip != NULL);
1840Sstevel@tonic-gate shared_pcf8584_dip = ddi_get_parent(i2cnexus_dip);
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate ndi_hold_devi(shared_pcf8584_dip);
1870Sstevel@tonic-gate ndi_rele_devi(i2cnexus_dip);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate static int
cherry_dev_search(dev_info_t * dip,void * arg)1910Sstevel@tonic-gate cherry_dev_search(dev_info_t *dip, void *arg)
1920Sstevel@tonic-gate {
1930Sstevel@tonic-gate int *dev_regs; /* Info about where the device is. */
1940Sstevel@tonic-gate uint_t len;
1950Sstevel@tonic-gate int err;
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate if (strcmp(ddi_binding_name(dip), "i2c-ssc050") != 0)
1980Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate err = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
2015648Ssetje DDI_PROP_DONTPASS, "reg", &dev_regs, &len);
2020Sstevel@tonic-gate if (err != DDI_PROP_SUCCESS) {
2030Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
2040Sstevel@tonic-gate }
2050Sstevel@tonic-gate /*
2060Sstevel@tonic-gate * regs[0] contains the bus number and regs[1]
2070Sstevel@tonic-gate * contains the device address of the i2c device.
2080Sstevel@tonic-gate * 0x82 is the device address of the i2c device
2090Sstevel@tonic-gate * from which the key switch position is read.
2100Sstevel@tonic-gate */
2110Sstevel@tonic-gate if (dev_regs[0] == 0 && dev_regs[1] == 0x82) {
2120Sstevel@tonic-gate *((dev_info_t **)arg) = dip;
2130Sstevel@tonic-gate ddi_prop_free(dev_regs);
2140Sstevel@tonic-gate return (DDI_WALK_TERMINATE);
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate ddi_prop_free(dev_regs);
2170Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
2180Sstevel@tonic-gate }
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate static void
keyswitch_poll(void * arg)2210Sstevel@tonic-gate keyswitch_poll(void *arg)
2220Sstevel@tonic-gate {
2230Sstevel@tonic-gate dev_info_t *dip = arg;
2240Sstevel@tonic-gate uchar_t port_byte;
2250Sstevel@tonic-gate int port = CHERRY_KEY_POLL_PORT;
2260Sstevel@tonic-gate int bit = CHERRY_KEY_POLL_BIT;
2270Sstevel@tonic-gate int err;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate err = cherry_ssc050_get_port_bit(dip, port, bit,
2305648Ssetje &port_byte, I2C_NOSLEEP);
2310Sstevel@tonic-gate if (err != 0) {
2323402Smb158278 cmn_err(CE_WARN, "keyswitch polling disabled: "
2335648Ssetje "errno=%d while reading ssc050", err);
2340Sstevel@tonic-gate return;
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate key_locked_bit = (boolean_t)((port_byte & 0x1));
238*11311SSurya.Prakki@Sun.COM (void) timeout(keyswitch_poll, (caddr_t)dip, keypoll_timeout_hz);
2390Sstevel@tonic-gate }
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate static void
cherry_abort_seq_handler(char * msg)2420Sstevel@tonic-gate cherry_abort_seq_handler(char *msg)
2430Sstevel@tonic-gate {
2440Sstevel@tonic-gate if (key_locked_bit == 0)
2450Sstevel@tonic-gate cmn_err(CE_CONT, "KEY in LOCKED position, "
2465648Ssetje "ignoring debug enter sequence");
2470Sstevel@tonic-gate else {
2480Sstevel@tonic-gate debug_enter(msg);
2490Sstevel@tonic-gate }
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate /*ARGSUSED*/
2540Sstevel@tonic-gate int
plat_cpu_poweron(struct cpu * cp)2550Sstevel@tonic-gate plat_cpu_poweron(struct cpu *cp)
2560Sstevel@tonic-gate {
2570Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
2580Sstevel@tonic-gate }
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate /*ARGSUSED*/
2610Sstevel@tonic-gate int
plat_cpu_poweroff(struct cpu * cp)2620Sstevel@tonic-gate plat_cpu_poweroff(struct cpu *cp)
2630Sstevel@tonic-gate {
2640Sstevel@tonic-gate return (ENOTSUP); /* not supported on this platform */
2650Sstevel@tonic-gate }
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate * Given a pfn, return the board and beginning/end of the page's
2690Sstevel@tonic-gate * memory controller's address range.
2700Sstevel@tonic-gate */
2710Sstevel@tonic-gate static int
plat_discover_slice(pfn_t pfn,pfn_t * first,pfn_t * last)2720Sstevel@tonic-gate plat_discover_slice(pfn_t pfn, pfn_t *first, pfn_t *last)
2730Sstevel@tonic-gate {
2740Sstevel@tonic-gate int bd, cpu, bank;
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate for (bd = 0; bd < CHERRYSTONE_SBD_SLOTS; bd++) {
2770Sstevel@tonic-gate for (cpu = 0; cpu < CHERRYSTONE_CPUS_PER_BOARD; cpu++) {
2780Sstevel@tonic-gate for (bank = 0; bank < CHERRYSTONE_BANKS_PER_MC;
2795648Ssetje bank++) {
2800Sstevel@tonic-gate uint64_t *slice = slice_table[bd][cpu][bank];
2810Sstevel@tonic-gate uint64_t base = btop(slice[SLICE_PA]);
2820Sstevel@tonic-gate uint64_t len = btop(slice[SLICE_SPAN]);
2830Sstevel@tonic-gate if (len && pfn >= base && pfn < (base + len)) {
2840Sstevel@tonic-gate *first = base;
2850Sstevel@tonic-gate *last = base + len - 1;
2860Sstevel@tonic-gate return (bd);
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate }
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate panic("plat_discover_slice: no slice for pfn 0x%lx\n", pfn);
2920Sstevel@tonic-gate /* NOTREACHED */
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate
295605Slm66018 /*ARGSUSED*/
2960Sstevel@tonic-gate void
plat_freelist_process(int mnode)2970Sstevel@tonic-gate plat_freelist_process(int mnode)
298605Slm66018 {}
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate /*
3010Sstevel@tonic-gate * Called for each board/cpu/PA range detected in plat_fill_mc().
3020Sstevel@tonic-gate */
3030Sstevel@tonic-gate static void
update_mem_bounds(int boardid,int cpuid,int bankid,uint64_t base,uint64_t size)3040Sstevel@tonic-gate update_mem_bounds(int boardid, int cpuid, int bankid,
3050Sstevel@tonic-gate uint64_t base, uint64_t size)
3060Sstevel@tonic-gate {
307605Slm66018 uint64_t end;
308605Slm66018 int mnode;
309605Slm66018
3100Sstevel@tonic-gate slice_table[boardid][cpuid][bankid][SLICE_PA] = base;
3110Sstevel@tonic-gate slice_table[boardid][cpuid][bankid][SLICE_SPAN] = size;
312605Slm66018
313605Slm66018 end = base + size - 1;
314605Slm66018
315605Slm66018 /*
316605Slm66018 * First see if this board already has a memnode associated
317605Slm66018 * with it. If not, see if this slice has a memnode. This
318605Slm66018 * covers the cases where a single slice covers multiple
319605Slm66018 * boards (cross-board interleaving) and where a single
320605Slm66018 * board has multiple slices (1+GB DIMMs).
321605Slm66018 */
322605Slm66018 if ((mnode = plat_lgrphand_to_mem_node(boardid)) == -1) {
323605Slm66018 if ((mnode = slice_to_memnode[PA_2_SLICE(base)]) == -1)
324605Slm66018 mnode = mem_node_alloc();
325605Slm66018
326605Slm66018 ASSERT(mnode >= 0);
327605Slm66018 ASSERT(mnode < MAX_MEM_NODES);
328605Slm66018 plat_assign_lgrphand_to_mem_node(boardid, mnode);
329605Slm66018 }
330605Slm66018
331605Slm66018 base = P2ALIGN(base, (1ul << PA_SLICE_SHIFT));
332605Slm66018
333605Slm66018 while (base < end) {
334605Slm66018 slice_to_memnode[PA_2_SLICE(base)] = mnode;
335605Slm66018 base += (1ul << PA_SLICE_SHIFT);
336605Slm66018 }
3370Sstevel@tonic-gate }
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate * Dynamically detect memory slices in the system by decoding
3410Sstevel@tonic-gate * the cpu memory decoder registers at boot time.
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate void
plat_fill_mc(pnode_t nodeid)344789Sahrens plat_fill_mc(pnode_t nodeid)
3450Sstevel@tonic-gate {
3460Sstevel@tonic-gate uint64_t mc_addr, saf_addr;
3470Sstevel@tonic-gate uint64_t mc_decode[CHERRYSTONE_BANKS_PER_MC];
3480Sstevel@tonic-gate uint64_t base, size;
3490Sstevel@tonic-gate uint64_t saf_mask;
3500Sstevel@tonic-gate uint64_t offset;
3510Sstevel@tonic-gate uint32_t regs[4];
3520Sstevel@tonic-gate int len;
3530Sstevel@tonic-gate int local_mc;
3540Sstevel@tonic-gate int portid;
3550Sstevel@tonic-gate int boardid;
3560Sstevel@tonic-gate int cpuid;
3570Sstevel@tonic-gate int i;
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate if ((prom_getprop(nodeid, "portid", (caddr_t)&portid) < 0) ||
3600Sstevel@tonic-gate (portid == -1))
3610Sstevel@tonic-gate return;
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate /*
3640Sstevel@tonic-gate * Decode the board number from the MC portid. Assumes
3650Sstevel@tonic-gate * portid == safari agentid.
3660Sstevel@tonic-gate */
3670Sstevel@tonic-gate boardid = CHERRYSTONE_GETSLOT(portid);
3680Sstevel@tonic-gate cpuid = CHERRYSTONE_GETSID(portid);
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate /*
3710Sstevel@tonic-gate * The "reg" property returns 4 32-bit values. The first two are
3720Sstevel@tonic-gate * combined to form a 64-bit address. The second two are for a
3730Sstevel@tonic-gate * 64-bit size, but we don't actually need to look at that value.
3740Sstevel@tonic-gate */
3750Sstevel@tonic-gate len = prom_getproplen(nodeid, "reg");
3760Sstevel@tonic-gate if (len != (sizeof (uint32_t) * 4)) {
3770Sstevel@tonic-gate prom_printf("Warning: malformed 'reg' property\n");
3780Sstevel@tonic-gate return;
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate if (prom_getprop(nodeid, "reg", (caddr_t)regs) < 0)
3810Sstevel@tonic-gate return;
3820Sstevel@tonic-gate mc_addr = ((uint64_t)regs[0]) << 32;
3830Sstevel@tonic-gate mc_addr |= (uint64_t)regs[1];
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate /*
3860Sstevel@tonic-gate * Figure out whether the memory controller we are examining
3870Sstevel@tonic-gate * belongs to this CPU or a different one.
3880Sstevel@tonic-gate */
3890Sstevel@tonic-gate saf_addr = lddsafaddr(8);
3900Sstevel@tonic-gate saf_mask = (uint64_t)SAF_MASK;
3910Sstevel@tonic-gate if ((mc_addr & saf_mask) == saf_addr)
3920Sstevel@tonic-gate local_mc = 1;
3930Sstevel@tonic-gate else
3940Sstevel@tonic-gate local_mc = 0;
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate for (i = 0; i < CHERRYSTONE_BANKS_PER_MC; i++) {
3970Sstevel@tonic-gate /*
3980Sstevel@tonic-gate * Memory decode masks are at offsets 0x10 - 0x28.
3990Sstevel@tonic-gate */
4000Sstevel@tonic-gate offset = 0x10 + (i << 3);
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate /*
4030Sstevel@tonic-gate * If the memory controller is local to this CPU, we use
4040Sstevel@tonic-gate * the special ASI to read the decode registers.
4050Sstevel@tonic-gate * Otherwise, we load the values from a magic address in
4060Sstevel@tonic-gate * I/O space.
4070Sstevel@tonic-gate */
4080Sstevel@tonic-gate if (local_mc)
4090Sstevel@tonic-gate mc_decode[i] = lddmcdecode(offset);
4100Sstevel@tonic-gate else
4110Sstevel@tonic-gate mc_decode[i] = lddphysio(mc_addr | offset);
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate /*
4140Sstevel@tonic-gate * If the upper bit is set, we have a valid mask
4150Sstevel@tonic-gate */
4160Sstevel@tonic-gate if ((int64_t)mc_decode[i] < 0) {
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate * The memory decode register is a bitmask field,
4190Sstevel@tonic-gate * so we can decode that into both a base and
4200Sstevel@tonic-gate * a span.
4210Sstevel@tonic-gate */
4220Sstevel@tonic-gate base = MC_BASE(mc_decode[i]) << PHYS2UM_SHIFT;
4230Sstevel@tonic-gate size = MC_UK2SPAN(mc_decode[i]);
4240Sstevel@tonic-gate update_mem_bounds(boardid, cpuid, i, base, size);
4250Sstevel@tonic-gate }
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate /*
430605Slm66018 * This routine is run midway through the boot process. By the time we get
431605Slm66018 * here, we know about all the active CPU boards in the system, and we have
432605Slm66018 * extracted information about each board's memory from the memory
433605Slm66018 * controllers. We have also figured out which ranges of memory will be
434605Slm66018 * assigned to which memnodes, so we walk the slice table to build the table
435605Slm66018 * of memnodes.
436605Slm66018 */
437605Slm66018 /* ARGSUSED */
438605Slm66018 void
plat_build_mem_nodes(prom_memlist_t * list,size_t nelems)4395648Ssetje plat_build_mem_nodes(prom_memlist_t *list, size_t nelems)
440605Slm66018 {
441605Slm66018 int slice;
442605Slm66018 pfn_t basepfn;
443605Slm66018 pgcnt_t npgs;
444605Slm66018
445605Slm66018 mem_node_pfn_shift = PFN_SLICE_SHIFT;
446605Slm66018 mem_node_physalign = (1ull << PA_SLICE_SHIFT);
447605Slm66018 npgs = 1ull << PFN_SLICE_SHIFT;
448605Slm66018
449605Slm66018 for (slice = 0; slice < CHERRYSTONE_MAX_SLICE; slice++) {
450605Slm66018 if (slice_to_memnode[slice] == -1)
451605Slm66018 continue;
452605Slm66018 basepfn = (uint64_t)slice << PFN_SLICE_SHIFT;
453605Slm66018 mem_node_add_slice(basepfn, basepfn + npgs - 1);
454605Slm66018 }
455605Slm66018 }
456605Slm66018
457605Slm66018
458605Slm66018
459605Slm66018 /*
460605Slm66018 * Cherrystone support for lgroups.
461605Slm66018 *
462605Slm66018 * On Cherrystone, an lgroup platform handle == slot number.
463605Slm66018 *
464605Slm66018 * Mappings between lgroup handles and memnodes are managed
465605Slm66018 * in addition to mappings between memory slices and memnodes
466605Slm66018 * to support cross-board interleaving as well as multiple
467605Slm66018 * slices per board (e.g. >1GB DIMMs). The initial mapping
468605Slm66018 * of memnodes to lgroup handles is determined at boot time.
469605Slm66018 */
470605Slm66018
471605Slm66018 int
plat_pfn_to_mem_node(pfn_t pfn)472605Slm66018 plat_pfn_to_mem_node(pfn_t pfn)
473605Slm66018 {
474605Slm66018 return (slice_to_memnode[PFN_2_SLICE(pfn)]);
475605Slm66018 }
476605Slm66018
477605Slm66018 /*
478605Slm66018 * Return the platform handle for the lgroup containing the given CPU
479605Slm66018 *
480605Slm66018 * For Cherrystone, lgroup platform handle == slot/board number
481605Slm66018 */
482605Slm66018 lgrp_handle_t
plat_lgrp_cpu_to_hand(processorid_t id)483605Slm66018 plat_lgrp_cpu_to_hand(processorid_t id)
484605Slm66018 {
485605Slm66018 return (CHERRYSTONE_GETSLOT(id));
486605Slm66018 }
487605Slm66018
488605Slm66018 /*
489605Slm66018 * Platform specific lgroup initialization
490605Slm66018 */
491605Slm66018 void
plat_lgrp_init(void)492605Slm66018 plat_lgrp_init(void)
493605Slm66018 {
494605Slm66018 int i;
495605Slm66018
496605Slm66018 /*
497605Slm66018 * Initialize lookup tables to invalid values so we catch
498605Slm66018 * any illegal use of them.
499605Slm66018 */
500605Slm66018 for (i = 0; i < CHERRYSTONE_MAX_SLICE; i++) {
501605Slm66018 slice_to_memnode[i] = -1;
502605Slm66018 }
503605Slm66018 }
504605Slm66018
505605Slm66018 /*
506605Slm66018 * Return latency between "from" and "to" lgroups
507605Slm66018 *
508605Slm66018 * This latency number can only be used for relative comparison
509605Slm66018 * between lgroups on the running system, cannot be used across platforms,
510605Slm66018 * and may not reflect the actual latency. It is platform and implementation
511605Slm66018 * specific, so platform gets to decide its value. It would be nice if the
512605Slm66018 * number was at least proportional to make comparisons more meaningful though.
513605Slm66018 * NOTE: The numbers below are supposed to be load latencies for uncached
514605Slm66018 * memory divided by 10.
515605Slm66018 */
516605Slm66018 int
plat_lgrp_latency(lgrp_handle_t from,lgrp_handle_t to)517605Slm66018 plat_lgrp_latency(lgrp_handle_t from, lgrp_handle_t to)
518605Slm66018 {
519605Slm66018 /*
520605Slm66018 * Return min remote latency when there are more than two lgroups
521605Slm66018 * (root and child) and getting latency between two different lgroups
522605Slm66018 * or root is involved
523605Slm66018 */
524605Slm66018 if (lgrp_optimizations() && (from != to ||
525605Slm66018 from == LGRP_DEFAULT_HANDLE || to == LGRP_DEFAULT_HANDLE))
526605Slm66018 return (21);
527605Slm66018 else
528605Slm66018 return (19);
529605Slm66018 }
530605Slm66018
531605Slm66018 /*
5320Sstevel@tonic-gate * No platform drivers on this platform
5330Sstevel@tonic-gate */
5340Sstevel@tonic-gate char *platform_module_list[] = {
5350Sstevel@tonic-gate (char *)0
5360Sstevel@tonic-gate };
5370Sstevel@tonic-gate
5380Sstevel@tonic-gate /*ARGSUSED*/
5390Sstevel@tonic-gate void
plat_tod_fault(enum tod_fault_type tod_bad)5400Sstevel@tonic-gate plat_tod_fault(enum tod_fault_type tod_bad)
5410Sstevel@tonic-gate {
5420Sstevel@tonic-gate }
5430Sstevel@tonic-gate
5440Sstevel@tonic-gate /*ARGSUSED*/
5450Sstevel@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)5460Sstevel@tonic-gate plat_get_mem_unum(int synd_code, uint64_t flt_addr, int flt_bus_id,
5470Sstevel@tonic-gate int flt_in_memory, ushort_t flt_status, char *buf, int buflen, int *lenp)
5480Sstevel@tonic-gate {
5490Sstevel@tonic-gate if (flt_in_memory && (p2get_mem_unum != NULL))
5500Sstevel@tonic-gate return (p2get_mem_unum(synd_code, P2ALIGN(flt_addr, 8),
5515648Ssetje buf, buflen, lenp));
5520Sstevel@tonic-gate else
5530Sstevel@tonic-gate return (ENOTSUP);
5540Sstevel@tonic-gate }
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate /*
5570Sstevel@tonic-gate * This platform hook gets called from mc_add_mem_unum_label() in the mc-us3
5580Sstevel@tonic-gate * driver giving each platform the opportunity to add platform
5590Sstevel@tonic-gate * specific label information to the unum for ECC error logging purposes.
5600Sstevel@tonic-gate */
5610Sstevel@tonic-gate void
plat_add_mem_unum_label(char * unum,int mcid,int bank,int dimm)5620Sstevel@tonic-gate plat_add_mem_unum_label(char *unum, int mcid, int bank, int dimm)
5630Sstevel@tonic-gate {
5640Sstevel@tonic-gate _NOTE(ARGUNUSED(bank, dimm))
5650Sstevel@tonic-gate
5660Sstevel@tonic-gate char board = CHERRYSTONE_GETSLOT_LABEL(mcid);
5670Sstevel@tonic-gate char old_unum[UNUM_NAMLEN];
5680Sstevel@tonic-gate
569*11311SSurya.Prakki@Sun.COM (void) strcpy(old_unum, unum);
570*11311SSurya.Prakki@Sun.COM (void) snprintf(unum, UNUM_NAMLEN, "Slot %c: %s", board, old_unum);
5710Sstevel@tonic-gate }
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate int
plat_get_cpu_unum(int cpuid,char * buf,int buflen,int * lenp)5740Sstevel@tonic-gate plat_get_cpu_unum(int cpuid, char *buf, int buflen, int *lenp)
5750Sstevel@tonic-gate {
5760Sstevel@tonic-gate char board = CHERRYSTONE_GETSLOT_LABEL(cpuid);
5770Sstevel@tonic-gate
5780Sstevel@tonic-gate if (snprintf(buf, buflen, "Slot %c", board) >= buflen) {
5790Sstevel@tonic-gate return (ENOSPC);
5800Sstevel@tonic-gate } else {
5810Sstevel@tonic-gate *lenp = strlen(buf);
5820Sstevel@tonic-gate return (0);
5830Sstevel@tonic-gate }
5840Sstevel@tonic-gate }
5850Sstevel@tonic-gate
5860Sstevel@tonic-gate /*
5870Sstevel@tonic-gate * Cherrystone's BBC pcf8584 controller is used by both OBP and the OS's i2c
5880Sstevel@tonic-gate * drivers. The 'eeprom' command executes OBP code to handle property requests.
5890Sstevel@tonic-gate * If eeprom didn't do this, or if the controllers were partitioned so that all
5900Sstevel@tonic-gate * devices on a given controller were driven by either OBP or the OS, this
5910Sstevel@tonic-gate * wouldn't be necessary.
5920Sstevel@tonic-gate *
5930Sstevel@tonic-gate * Note that getprop doesn't have the same issue as it reads from cached
5940Sstevel@tonic-gate * memory in OBP.
5950Sstevel@tonic-gate */
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate /*
5980Sstevel@tonic-gate * Common locking enter code
5990Sstevel@tonic-gate */
6000Sstevel@tonic-gate void
plat_setprop_enter(void)6010Sstevel@tonic-gate plat_setprop_enter(void)
6020Sstevel@tonic-gate {
6030Sstevel@tonic-gate mutex_enter(&cherry_pcf8584_mutex);
6040Sstevel@tonic-gate }
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate /*
6070Sstevel@tonic-gate * Common locking exit code
6080Sstevel@tonic-gate */
6090Sstevel@tonic-gate void
plat_setprop_exit(void)6100Sstevel@tonic-gate plat_setprop_exit(void)
6110Sstevel@tonic-gate {
6120Sstevel@tonic-gate mutex_exit(&cherry_pcf8584_mutex);
6130Sstevel@tonic-gate }
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate /*
6160Sstevel@tonic-gate * Called by pcf8584 driver
6170Sstevel@tonic-gate */
6180Sstevel@tonic-gate void
plat_shared_i2c_enter(dev_info_t * i2cnexus_dip)6190Sstevel@tonic-gate plat_shared_i2c_enter(dev_info_t *i2cnexus_dip)
6200Sstevel@tonic-gate {
6210Sstevel@tonic-gate if (i2cnexus_dip == shared_pcf8584_dip) {
6220Sstevel@tonic-gate plat_setprop_enter();
6230Sstevel@tonic-gate }
6240Sstevel@tonic-gate }
6250Sstevel@tonic-gate
6260Sstevel@tonic-gate /*
6270Sstevel@tonic-gate * Called by pcf8584 driver
6280Sstevel@tonic-gate */
6290Sstevel@tonic-gate void
plat_shared_i2c_exit(dev_info_t * i2cnexus_dip)6300Sstevel@tonic-gate plat_shared_i2c_exit(dev_info_t *i2cnexus_dip)
6310Sstevel@tonic-gate {
6320Sstevel@tonic-gate if (i2cnexus_dip == shared_pcf8584_dip) {
6330Sstevel@tonic-gate plat_setprop_exit();
6340Sstevel@tonic-gate }
6350Sstevel@tonic-gate }
636