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 51966Sarutz * Common Development and Distribution License (the "License"). 61966Sarutz * 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 /* 226803Spothier * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/conf.h> 290Sstevel@tonic-gate #include <sys/ddi.h> 300Sstevel@tonic-gate #include <sys/stat.h> 310Sstevel@tonic-gate #include <sys/sunddi.h> 320Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 330Sstevel@tonic-gate #include <sys/obpdefs.h> 340Sstevel@tonic-gate #include <sys/cmn_err.h> 350Sstevel@tonic-gate #include <sys/errno.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/open.h> 380Sstevel@tonic-gate #include <sys/thread.h> 390Sstevel@tonic-gate #include <sys/cpuvar.h> 400Sstevel@tonic-gate #include <sys/x_call.h> 410Sstevel@tonic-gate #include <sys/debug.h> 420Sstevel@tonic-gate #include <sys/sysmacros.h> 430Sstevel@tonic-gate #include <sys/ivintr.h> 440Sstevel@tonic-gate #include <sys/intr.h> 450Sstevel@tonic-gate #include <sys/intreg.h> 460Sstevel@tonic-gate #include <sys/autoconf.h> 470Sstevel@tonic-gate #include <sys/modctl.h> 480Sstevel@tonic-gate #include <sys/spl.h> 490Sstevel@tonic-gate #include <sys/async.h> 500Sstevel@tonic-gate #include <sys/mc.h> 510Sstevel@tonic-gate #include <sys/mc-us3i.h> 520Sstevel@tonic-gate #include <sys/note.h> 530Sstevel@tonic-gate #include <sys/cpu_module.h> 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * pm-hardware-state value 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate #define NO_SUSPEND_RESUME "no-suspend-resume" 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * Function prototypes 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate 640Sstevel@tonic-gate static int mc_open(dev_t *, int, int, cred_t *); 650Sstevel@tonic-gate static int mc_close(dev_t, int, int, cred_t *); 660Sstevel@tonic-gate static int mc_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 670Sstevel@tonic-gate static int mc_attach(dev_info_t *, ddi_attach_cmd_t); 680Sstevel@tonic-gate static int mc_detach(dev_info_t *, ddi_detach_cmd_t); 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* 710Sstevel@tonic-gate * Configuration data structures 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate static struct cb_ops mc_cb_ops = { 740Sstevel@tonic-gate mc_open, /* open */ 750Sstevel@tonic-gate mc_close, /* close */ 760Sstevel@tonic-gate nulldev, /* strategy */ 770Sstevel@tonic-gate nulldev, /* print */ 780Sstevel@tonic-gate nodev, /* dump */ 790Sstevel@tonic-gate nulldev, /* read */ 800Sstevel@tonic-gate nulldev, /* write */ 810Sstevel@tonic-gate mc_ioctl, /* ioctl */ 820Sstevel@tonic-gate nodev, /* devmap */ 830Sstevel@tonic-gate nodev, /* mmap */ 840Sstevel@tonic-gate nodev, /* segmap */ 850Sstevel@tonic-gate nochpoll, /* poll */ 860Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 870Sstevel@tonic-gate 0, /* streamtab */ 880Sstevel@tonic-gate D_MP | D_NEW | D_HOTPLUG, /* Driver compatibility flag */ 890Sstevel@tonic-gate CB_REV, /* rev */ 900Sstevel@tonic-gate nodev, /* cb_aread */ 910Sstevel@tonic-gate nodev /* cb_awrite */ 920Sstevel@tonic-gate }; 930Sstevel@tonic-gate 940Sstevel@tonic-gate static struct dev_ops mc_ops = { 950Sstevel@tonic-gate DEVO_REV, /* rev */ 960Sstevel@tonic-gate 0, /* refcnt */ 970Sstevel@tonic-gate ddi_no_info, /* getinfo */ 980Sstevel@tonic-gate nulldev, /* identify */ 990Sstevel@tonic-gate nulldev, /* probe */ 1000Sstevel@tonic-gate mc_attach, /* attach */ 1010Sstevel@tonic-gate mc_detach, /* detach */ 1020Sstevel@tonic-gate nulldev, /* reset */ 1030Sstevel@tonic-gate &mc_cb_ops, /* cb_ops */ 1040Sstevel@tonic-gate (struct bus_ops *)0, /* bus_ops */ 105*7656SSherry.Moore@Sun.COM nulldev, /* power */ 106*7656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */ 1070Sstevel@tonic-gate }; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Driver globals 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate static void *mcp; 1130Sstevel@tonic-gate static int nmcs = 0; 1140Sstevel@tonic-gate static int seg_id; 1150Sstevel@tonic-gate static int nsegments; 1160Sstevel@tonic-gate static uint64_t memsize; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate static uint_t mc_debug = 0; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate static int getreg; 1210Sstevel@tonic-gate static int nregs; 1220Sstevel@tonic-gate struct memory_reg_info *reg_info; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate static mc_dlist_t *seg_head, *seg_tail, *bank_head, *bank_tail; 1250Sstevel@tonic-gate static mc_dlist_t *mctrl_head, *mctrl_tail, *dgrp_head, *dgrp_tail; 1260Sstevel@tonic-gate static mc_dlist_t *device_head, *device_tail; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate static kmutex_t mcmutex; 1290Sstevel@tonic-gate static kmutex_t mcdatamutex; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate extern struct mod_ops mod_driverops; 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate static struct modldrv modldrv = { 1340Sstevel@tonic-gate &mod_driverops, /* module type, this one is a driver */ 135*7656SSherry.Moore@Sun.COM "Memory-controller: 1.14", /* module name */ 1360Sstevel@tonic-gate &mc_ops, /* driver ops */ 1370Sstevel@tonic-gate }; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate static struct modlinkage modlinkage = { 1400Sstevel@tonic-gate MODREV_1, /* rev */ 1410Sstevel@tonic-gate (void *)&modldrv, 1420Sstevel@tonic-gate NULL 1430Sstevel@tonic-gate }; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate static int mc_get_memory_reg_info(struct mc_soft_state *softsp); 1460Sstevel@tonic-gate static void mc_construct(struct mc_soft_state *softsp); 1470Sstevel@tonic-gate static void mc_delete(int mc_id); 1480Sstevel@tonic-gate static void mc_node_add(mc_dlist_t *node, mc_dlist_t **head, mc_dlist_t **tail); 1490Sstevel@tonic-gate static void mc_node_del(mc_dlist_t *node, mc_dlist_t **head, mc_dlist_t **tail); 1500Sstevel@tonic-gate static void *mc_node_get(int id, mc_dlist_t *head); 1510Sstevel@tonic-gate static void mc_add_mem_unum_label(char *unum, int mcid, int bank, int dimm); 1520Sstevel@tonic-gate static int mc_get_mem_unum(int synd_code, uint64_t paddr, char *buf, 1530Sstevel@tonic-gate int buflen, int *lenp); 1540Sstevel@tonic-gate static int mc_get_mem_info(int synd_code, uint64_t paddr, 1550Sstevel@tonic-gate uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep, 1560Sstevel@tonic-gate int *segsp, int *banksp, int *mcidp); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate #pragma weak p2get_mem_unum 1590Sstevel@tonic-gate #pragma weak p2get_mem_info 1600Sstevel@tonic-gate #pragma weak plat_add_mem_unum_label 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* For testing only */ 1630Sstevel@tonic-gate struct test_unum { 1640Sstevel@tonic-gate int synd_code; 1650Sstevel@tonic-gate uint64_t paddr; 1660Sstevel@tonic-gate char unum[UNUM_NAMLEN]; 1670Sstevel@tonic-gate int len; 1680Sstevel@tonic-gate }; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * These are the module initialization routines. 1720Sstevel@tonic-gate */ 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate int 1750Sstevel@tonic-gate _init(void) 1760Sstevel@tonic-gate { 1770Sstevel@tonic-gate int error; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate if ((error = ddi_soft_state_init(&mcp, 1800Sstevel@tonic-gate sizeof (struct mc_soft_state), 1)) != 0) 1810Sstevel@tonic-gate return (error); 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate error = mod_install(&modlinkage); 1840Sstevel@tonic-gate if (error == 0) { 1850Sstevel@tonic-gate mutex_init(&mcmutex, NULL, MUTEX_DRIVER, NULL); 1860Sstevel@tonic-gate mutex_init(&mcdatamutex, NULL, MUTEX_DRIVER, NULL); 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate return (error); 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate int 1930Sstevel@tonic-gate _fini(void) 1940Sstevel@tonic-gate { 1950Sstevel@tonic-gate int error; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) != 0) 1980Sstevel@tonic-gate return (error); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate ddi_soft_state_fini(&mcp); 2010Sstevel@tonic-gate mutex_destroy(&mcmutex); 2020Sstevel@tonic-gate mutex_destroy(&mcdatamutex); 2030Sstevel@tonic-gate return (0); 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate int 2070Sstevel@tonic-gate _info(struct modinfo *modinfop) 2080Sstevel@tonic-gate { 2090Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2100Sstevel@tonic-gate } 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate static int 2130Sstevel@tonic-gate mc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 2140Sstevel@tonic-gate { 2150Sstevel@tonic-gate struct mc_soft_state *softsp; 2160Sstevel@tonic-gate struct dimm_info *dimminfop; 2170Sstevel@tonic-gate int instance, len, err; 2180Sstevel@tonic-gate int mcreg1_len; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate switch (cmd) { 2210Sstevel@tonic-gate case DDI_ATTACH: 2220Sstevel@tonic-gate break; 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate case DDI_RESUME: 2250Sstevel@tonic-gate return (DDI_SUCCESS); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate default: 2280Sstevel@tonic-gate return (DDI_FAILURE); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate instance = ddi_get_instance(devi); 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate if (ddi_soft_state_zalloc(mcp, instance) != DDI_SUCCESS) 2340Sstevel@tonic-gate return (DDI_FAILURE); 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate softsp = ddi_get_soft_state(mcp, instance); 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate /* Set the dip in the soft state */ 2390Sstevel@tonic-gate softsp->dip = devi; 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate if ((softsp->portid = (int)ddi_getprop(DDI_DEV_T_ANY, softsp->dip, 2420Sstevel@tonic-gate DDI_PROP_DONTPASS, "portid", -1)) == -1) { 2430Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, ("mc%d: unable to get %s property\n", 2440Sstevel@tonic-gate instance, "portid")); 2450Sstevel@tonic-gate goto bad; 2460Sstevel@tonic-gate } 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, ("mc_attach: mc %d portid %d, cpuid %d\n", 2490Sstevel@tonic-gate instance, softsp->portid, CPU->cpu_id)); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate /* Get the content of Memory Control Register I from obp */ 2520Sstevel@tonic-gate mcreg1_len = sizeof (uint64_t); 2530Sstevel@tonic-gate if ((ddi_getlongprop_buf(DDI_DEV_T_ANY, softsp->dip, DDI_PROP_DONTPASS, 2540Sstevel@tonic-gate "memory-control-register-1", (caddr_t)&(softsp->mcreg1), 2550Sstevel@tonic-gate &mcreg1_len) == DDI_PROP_SUCCESS) && 2560Sstevel@tonic-gate (mcreg1_len == sizeof (uint64_t))) { 2570Sstevel@tonic-gate softsp->mcr_read_ok = 1; 2580Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, ("mc%d from obp: Reg1: 0x%lx\n", 2596803Spothier instance, softsp->mcreg1)); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* attach fails if mcreg1 cannot be accessed */ 2630Sstevel@tonic-gate if (!softsp->mcr_read_ok) { 2640Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, ("mc%d: unable to get mcreg1\n", 2650Sstevel@tonic-gate instance)); 2660Sstevel@tonic-gate goto bad; 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate /* nothing to suspend/resume here */ 2700Sstevel@tonic-gate (void) ddi_prop_create(DDI_DEV_T_NONE, devi, DDI_PROP_CANSLEEP, 2710Sstevel@tonic-gate "pm-hardware-state", NO_SUSPEND_RESUME, 2720Sstevel@tonic-gate sizeof (NO_SUSPEND_RESUME)); 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate /* 2750Sstevel@tonic-gate * Get the label of dimms and pin routing information from the 2760Sstevel@tonic-gate * memory-layout property of the memory controller. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate err = ddi_getlongprop(DDI_DEV_T_ANY, softsp->dip, DDI_PROP_DONTPASS, 2790Sstevel@tonic-gate "memory-layout", (caddr_t)&dimminfop, &len); 2800Sstevel@tonic-gate if (err == DDI_PROP_SUCCESS && dimminfop->table_width == 1) { 2810Sstevel@tonic-gate /* Set the pointer and size of property in the soft state */ 2820Sstevel@tonic-gate softsp->memlayoutp = dimminfop; 2830Sstevel@tonic-gate softsp->memlayoutlen = len; 2840Sstevel@tonic-gate } else { 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * memory-layout property was not found or some other 2870Sstevel@tonic-gate * error occured, plat_get_mem_unum() will not work 2880Sstevel@tonic-gate * for this mc. 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate softsp->memlayoutp = NULL; 2910Sstevel@tonic-gate softsp->memlayoutlen = 0; 2920Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, 2930Sstevel@tonic-gate ("mc %d: missing or unsupported memory-layout property\n", 2940Sstevel@tonic-gate instance)); 2950Sstevel@tonic-gate } 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate mutex_enter(&mcmutex); 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* Get the physical segments from memory/reg, just once for all MC */ 3000Sstevel@tonic-gate if (!getreg) { 3010Sstevel@tonic-gate if (mc_get_memory_reg_info(softsp) != 0) { 3020Sstevel@tonic-gate goto bad1; 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate getreg = 1; 3050Sstevel@tonic-gate } 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* Construct the physical and logical layout of the MC */ 3080Sstevel@tonic-gate mc_construct(softsp); 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate if (nmcs == 1) { 3110Sstevel@tonic-gate if (&p2get_mem_unum) 3120Sstevel@tonic-gate p2get_mem_unum = mc_get_mem_unum; 3130Sstevel@tonic-gate if (&p2get_mem_info) 3140Sstevel@tonic-gate p2get_mem_info = mc_get_mem_info; 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate if (ddi_create_minor_node(devi, "mc-us3i", S_IFCHR, instance, 3180Sstevel@tonic-gate "ddi_mem_ctrl", 0) != DDI_SUCCESS) { 3190Sstevel@tonic-gate DPRINTF(MC_ATTACH_DEBUG, ("mc_attach: create_minor_node" 3200Sstevel@tonic-gate " failed \n")); 3210Sstevel@tonic-gate goto bad1; 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate mutex_exit(&mcmutex); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate ddi_report_dev(devi); 3260Sstevel@tonic-gate return (DDI_SUCCESS); 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate bad1: 3290Sstevel@tonic-gate /* release all allocated data struture for this MC */ 3300Sstevel@tonic-gate mc_delete(softsp->portid); 3310Sstevel@tonic-gate mutex_exit(&mcmutex); 3320Sstevel@tonic-gate if (softsp->memlayoutp != NULL) 3330Sstevel@tonic-gate kmem_free(softsp->memlayoutp, softsp->memlayoutlen); 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate bad: 3360Sstevel@tonic-gate cmn_err(CE_WARN, "mc-us3i: attach failed for instance %d\n", instance); 3370Sstevel@tonic-gate ddi_soft_state_free(mcp, instance); 3380Sstevel@tonic-gate return (DDI_FAILURE); 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate /* ARGSUSED */ 3420Sstevel@tonic-gate static int 3430Sstevel@tonic-gate mc_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 3440Sstevel@tonic-gate { 3450Sstevel@tonic-gate int instance; 3460Sstevel@tonic-gate struct mc_soft_state *softsp; 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate /* get the instance of this devi */ 3490Sstevel@tonic-gate instance = ddi_get_instance(devi); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* get the soft state pointer for this device node */ 3520Sstevel@tonic-gate softsp = ddi_get_soft_state(mcp, instance); 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate switch (cmd) { 3550Sstevel@tonic-gate case DDI_SUSPEND: 3560Sstevel@tonic-gate return (DDI_SUCCESS); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate case DDI_DETACH: 3590Sstevel@tonic-gate break; 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate default: 3620Sstevel@tonic-gate return (DDI_FAILURE); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate DPRINTF(MC_DETACH_DEBUG, ("mc %d DETACH: portid %d\n", instance, 3660Sstevel@tonic-gate softsp->portid)); 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate mutex_enter(&mcmutex); 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate /* release all allocated data struture for this MC */ 3710Sstevel@tonic-gate mc_delete(softsp->portid); 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate if (softsp->memlayoutp != NULL) 3740Sstevel@tonic-gate kmem_free(softsp->memlayoutp, softsp->memlayoutlen); 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate if (nmcs == 0) { 3770Sstevel@tonic-gate if (&p2get_mem_unum) 3780Sstevel@tonic-gate p2get_mem_unum = NULL; 3790Sstevel@tonic-gate if (&p2get_mem_info) 3800Sstevel@tonic-gate p2get_mem_info = NULL; 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate mutex_exit(&mcmutex); 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 3860Sstevel@tonic-gate /* free up the soft state */ 3870Sstevel@tonic-gate ddi_soft_state_free(mcp, instance); 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate return (DDI_SUCCESS); 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate /* ARGSUSED */ 3930Sstevel@tonic-gate static int 3940Sstevel@tonic-gate mc_open(dev_t *devp, int flag, int otyp, cred_t *credp) 3950Sstevel@tonic-gate { 3960Sstevel@tonic-gate int status = 0; 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate /* verify that otyp is appropriate */ 3990Sstevel@tonic-gate if (otyp != OTYP_CHR) { 4000Sstevel@tonic-gate return (EINVAL); 4010Sstevel@tonic-gate } 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate mutex_enter(&mcmutex); 4040Sstevel@tonic-gate /* At least one attached? */ 4050Sstevel@tonic-gate if (nmcs == 0) { 4060Sstevel@tonic-gate status = ENXIO; 4070Sstevel@tonic-gate } 4083685Smb158278 mutex_exit(&mcmutex); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate return (status); 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate /* ARGSUSED */ 4140Sstevel@tonic-gate static int 4150Sstevel@tonic-gate mc_close(dev_t devp, int flag, int otyp, cred_t *credp) 4160Sstevel@tonic-gate { 4170Sstevel@tonic-gate return (0); 4180Sstevel@tonic-gate } 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate /* 4210Sstevel@tonic-gate * cmd includes MCIOC_MEMCONF, MCIOC_MEM, MCIOC_SEG, MCIOC_BANK, MCIOC_DEVGRP, 4220Sstevel@tonic-gate * MCIOC_CTRLCONF, MCIOC_CONTROL. 4230Sstevel@tonic-gate * 4240Sstevel@tonic-gate * MCIOC_MEM, MCIOC_SEG, MCIOC_CTRLCONF, and MCIOC_CONTROL are 4250Sstevel@tonic-gate * associated with various length struct. If given number is less than the 4260Sstevel@tonic-gate * number in kernel, update the number and return EINVAL so that user could 4270Sstevel@tonic-gate * allocate enough space for it. 4280Sstevel@tonic-gate * 4290Sstevel@tonic-gate */ 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate /* ARGSUSED */ 4320Sstevel@tonic-gate static int 4330Sstevel@tonic-gate mc_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cred_p, 4340Sstevel@tonic-gate int *rval_p) 4350Sstevel@tonic-gate { 4360Sstevel@tonic-gate size_t size; 4370Sstevel@tonic-gate struct mc_memconf mcmconf; 4380Sstevel@tonic-gate struct mc_memory *mcmem, mcmem_in; 4390Sstevel@tonic-gate struct mc_segment *mcseg, mcseg_in; 4400Sstevel@tonic-gate struct mc_bank mcbank; 4410Sstevel@tonic-gate struct mc_devgrp mcdevgrp; 4420Sstevel@tonic-gate struct mc_ctrlconf *mcctrlconf, mcctrlconf_in; 4430Sstevel@tonic-gate struct mc_control *mccontrol, mccontrol_in; 4440Sstevel@tonic-gate struct seg_info *seg = NULL; 4450Sstevel@tonic-gate struct bank_info *bank = NULL; 4460Sstevel@tonic-gate struct dgrp_info *dgrp = NULL; 4470Sstevel@tonic-gate struct mctrl_info *mcport; 4480Sstevel@tonic-gate mc_dlist_t *mctrl; 4490Sstevel@tonic-gate int i, status = 0; 4500Sstevel@tonic-gate cpu_t *cpu; 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate switch (cmd) { 4530Sstevel@tonic-gate case MCIOC_MEMCONF: 4540Sstevel@tonic-gate mutex_enter(&mcdatamutex); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate mcmconf.nmcs = nmcs; 4570Sstevel@tonic-gate mcmconf.nsegments = nsegments; 4580Sstevel@tonic-gate mcmconf.nbanks = NLOGBANKS_PER_SEG; 4590Sstevel@tonic-gate mcmconf.ndevgrps = NDGRPS_PER_MC; 4600Sstevel@tonic-gate mcmconf.ndevs = NDIMMS_PER_DGRP; 4610Sstevel@tonic-gate mcmconf.len_dev = MAX_DEVLEN; 4620Sstevel@tonic-gate mcmconf.xfer_size = TRANSFER_SIZE; 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate mutex_exit(&mcdatamutex); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate if (copyout(&mcmconf, (void *)arg, sizeof (mcmconf))) 4670Sstevel@tonic-gate return (EFAULT); 4680Sstevel@tonic-gate return (0); 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate /* 4710Sstevel@tonic-gate * input: nsegments and allocate space for various length of segmentids 4720Sstevel@tonic-gate * 4730Sstevel@tonic-gate * return 0: size, number of segments, and all segment ids, 4740Sstevel@tonic-gate * where glocal and local ids are identical. 4750Sstevel@tonic-gate * EINVAL: if the given nsegments is less than that in kernel and 4760Sstevel@tonic-gate * nsegments of struct will be updated. 4770Sstevel@tonic-gate * EFAULT: if other errors in kernel. 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate case MCIOC_MEM: 4800Sstevel@tonic-gate if (copyin((void *)arg, &mcmem_in, sizeof (mcmem_in)) != 0) 4810Sstevel@tonic-gate return (EFAULT); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate mutex_enter(&mcdatamutex); 4840Sstevel@tonic-gate if (mcmem_in.nsegments < nsegments) { 4850Sstevel@tonic-gate mcmem_in.nsegments = nsegments; 4860Sstevel@tonic-gate mutex_exit(&mcdatamutex); 4870Sstevel@tonic-gate if (copyout(&mcmem_in, (void *)arg, sizeof (mcmem_in))) 4880Sstevel@tonic-gate status = EFAULT; 4890Sstevel@tonic-gate else 4900Sstevel@tonic-gate status = EINVAL; 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate return (status); 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate 4950Sstevel@tonic-gate size = sizeof (*mcmem) + (nsegments - 1) * 4960Sstevel@tonic-gate sizeof (mcmem->segmentids[0]); 4970Sstevel@tonic-gate mcmem = kmem_zalloc(size, KM_SLEEP); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate mcmem->size = memsize; 5000Sstevel@tonic-gate mcmem->nsegments = nsegments; 5010Sstevel@tonic-gate seg = (struct seg_info *)seg_head; 5020Sstevel@tonic-gate for (i = 0; i < nsegments; i++) { 5030Sstevel@tonic-gate ASSERT(seg != NULL); 5040Sstevel@tonic-gate mcmem->segmentids[i].globalid = seg->seg_node.id; 5050Sstevel@tonic-gate mcmem->segmentids[i].localid = seg->seg_node.id; 5060Sstevel@tonic-gate seg = (struct seg_info *)seg->seg_node.next; 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate mutex_exit(&mcdatamutex); 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate if (copyout(mcmem, (void *)arg, size)) 5110Sstevel@tonic-gate status = EFAULT; 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate kmem_free(mcmem, size); 5140Sstevel@tonic-gate return (status); 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate /* 5170Sstevel@tonic-gate * input: id, nbanks and allocate space for various length of bankids 5180Sstevel@tonic-gate * 5190Sstevel@tonic-gate * return 0: base, size, number of banks, and all bank ids, 5200Sstevel@tonic-gate * where global id is unique of all banks and local id 5210Sstevel@tonic-gate * is only unique for mc. 5220Sstevel@tonic-gate * EINVAL: either id isn't found or if given nbanks is less than 5230Sstevel@tonic-gate * that in kernel and nbanks of struct will be updated. 5240Sstevel@tonic-gate * EFAULT: if other errors in kernel. 5250Sstevel@tonic-gate */ 5260Sstevel@tonic-gate case MCIOC_SEG: 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate if (copyin((void *)arg, &mcseg_in, sizeof (mcseg_in)) != 0) 5290Sstevel@tonic-gate return (EFAULT); 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate mutex_enter(&mcdatamutex); 5320Sstevel@tonic-gate if ((seg = mc_node_get(mcseg_in.id, seg_head)) == NULL) { 5330Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_SEG: seg not match, " 5340Sstevel@tonic-gate "id %d\n", mcseg_in.id)); 5350Sstevel@tonic-gate mutex_exit(&mcdatamutex); 5360Sstevel@tonic-gate return (EFAULT); 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate 5390Sstevel@tonic-gate if (mcseg_in.nbanks < seg->nbanks) { 5400Sstevel@tonic-gate mcseg_in.nbanks = seg->nbanks; 5410Sstevel@tonic-gate mutex_exit(&mcdatamutex); 5420Sstevel@tonic-gate if (copyout(&mcseg_in, (void *)arg, sizeof (mcseg_in))) 5430Sstevel@tonic-gate status = EFAULT; 5440Sstevel@tonic-gate else 5450Sstevel@tonic-gate status = EINVAL; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate return (status); 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate size = sizeof (*mcseg) + (seg->nbanks - 1) * 5510Sstevel@tonic-gate sizeof (mcseg->bankids[0]); 5520Sstevel@tonic-gate mcseg = kmem_zalloc(size, KM_SLEEP); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate mcseg->id = seg->seg_node.id; 5550Sstevel@tonic-gate mcseg->ifactor = seg->ifactor; 5560Sstevel@tonic-gate mcseg->base = seg->base; 5570Sstevel@tonic-gate mcseg->size = seg->size; 5580Sstevel@tonic-gate mcseg->nbanks = seg->nbanks; 5590Sstevel@tonic-gate 5600Sstevel@tonic-gate bank = seg->head; 5610Sstevel@tonic-gate 5620Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_SEG:nbanks %d seg %p bank %p\n", 5630Sstevel@tonic-gate seg->nbanks, (void *) seg, (void *) bank)); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate i = 0; 5660Sstevel@tonic-gate while (bank != NULL) { 5670Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_SEG:idx %d bank_id %d\n", 5680Sstevel@tonic-gate i, bank->bank_node.id)); 5690Sstevel@tonic-gate mcseg->bankids[i].globalid = bank->bank_node.id; 5700Sstevel@tonic-gate mcseg->bankids[i++].localid = bank->local_id; 5710Sstevel@tonic-gate bank = bank->next; 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate ASSERT(i == seg->nbanks); 5740Sstevel@tonic-gate mutex_exit(&mcdatamutex); 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate if (copyout(mcseg, (void *)arg, size)) 5770Sstevel@tonic-gate status = EFAULT; 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate kmem_free(mcseg, size); 5800Sstevel@tonic-gate return (status); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* 5830Sstevel@tonic-gate * input: id 5840Sstevel@tonic-gate * 5850Sstevel@tonic-gate * return 0: mask, match, size, and devgrpid, 5860Sstevel@tonic-gate * where global id is unique of all devgrps and local id 5870Sstevel@tonic-gate * is only unique for mc. 5880Sstevel@tonic-gate * EINVAL: if id isn't found 5890Sstevel@tonic-gate * EFAULT: if other errors in kernel. 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate case MCIOC_BANK: 5920Sstevel@tonic-gate if (copyin((void *)arg, &mcbank, sizeof (mcbank)) != 0) 5930Sstevel@tonic-gate return (EFAULT); 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_BANK: bank id %d\n", mcbank.id)); 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate mutex_enter(&mcdatamutex); 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate if ((bank = mc_node_get(mcbank.id, bank_head)) == NULL) { 6000Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6010Sstevel@tonic-gate return (EINVAL); 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate mcbank.mask = bank->mask; 6050Sstevel@tonic-gate mcbank.match = bank->match; 6060Sstevel@tonic-gate mcbank.size = bank->size; 6070Sstevel@tonic-gate mcbank.devgrpid.globalid = bank->devgrp_id; 6080Sstevel@tonic-gate mcbank.devgrpid.localid = 6090Sstevel@tonic-gate bank->bank_node.id % NLOGBANKS_PER_SEG; 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate if (copyout(&mcbank, (void *)arg, sizeof (mcbank))) 6140Sstevel@tonic-gate return (EFAULT); 6150Sstevel@tonic-gate return (0); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate /* 6180Sstevel@tonic-gate * input:id and allocate space for various length of deviceids 6190Sstevel@tonic-gate * 6200Sstevel@tonic-gate * return 0: size and number of devices. 6210Sstevel@tonic-gate * EINVAL: id isn't found 6220Sstevel@tonic-gate * EFAULT: if other errors in kernel. 6230Sstevel@tonic-gate */ 6240Sstevel@tonic-gate case MCIOC_DEVGRP: 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate if (copyin((void *)arg, &mcdevgrp, sizeof (mcdevgrp)) != 0) 6270Sstevel@tonic-gate return (EFAULT); 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate mutex_enter(&mcdatamutex); 6300Sstevel@tonic-gate if ((dgrp = mc_node_get(mcdevgrp.id, dgrp_head)) == NULL) { 6310Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_DEVGRP: not match, id " 6320Sstevel@tonic-gate "%d\n", mcdevgrp.id)); 6330Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6340Sstevel@tonic-gate return (EINVAL); 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate mcdevgrp.ndevices = dgrp->ndevices; 6380Sstevel@tonic-gate mcdevgrp.size = dgrp->size; 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate if (copyout(&mcdevgrp, (void *)arg, sizeof (mcdevgrp))) 6430Sstevel@tonic-gate status = EFAULT; 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate return (status); 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* 6480Sstevel@tonic-gate * input: nmcs and allocate space for various length of mcids 6490Sstevel@tonic-gate * 6500Sstevel@tonic-gate * return 0: number of mc, and all mcids, 6510Sstevel@tonic-gate * where glocal and local ids are identical. 6520Sstevel@tonic-gate * EINVAL: if the given nmcs is less than that in kernel and 6530Sstevel@tonic-gate * nmcs of struct will be updated. 6540Sstevel@tonic-gate * EFAULT: if other errors in kernel. 6550Sstevel@tonic-gate */ 6560Sstevel@tonic-gate case MCIOC_CTRLCONF: 6570Sstevel@tonic-gate if (copyin((void *)arg, &mcctrlconf_in, 6580Sstevel@tonic-gate sizeof (mcctrlconf_in)) != 0) 6590Sstevel@tonic-gate return (EFAULT); 6600Sstevel@tonic-gate 6610Sstevel@tonic-gate mutex_enter(&mcdatamutex); 6620Sstevel@tonic-gate if (mcctrlconf_in.nmcs < nmcs) { 6630Sstevel@tonic-gate mcctrlconf_in.nmcs = nmcs; 6640Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6650Sstevel@tonic-gate if (copyout(&mcctrlconf_in, (void *)arg, 6660Sstevel@tonic-gate sizeof (mcctrlconf_in))) 6670Sstevel@tonic-gate status = EFAULT; 6680Sstevel@tonic-gate else 6690Sstevel@tonic-gate status = EINVAL; 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate return (status); 6720Sstevel@tonic-gate } 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /* 6750Sstevel@tonic-gate * Cannot just use the size of the struct because of the various 6760Sstevel@tonic-gate * length struct 6770Sstevel@tonic-gate */ 6780Sstevel@tonic-gate size = sizeof (*mcctrlconf) + ((nmcs - 1) * 6790Sstevel@tonic-gate sizeof (mcctrlconf->mcids[0])); 6800Sstevel@tonic-gate mcctrlconf = kmem_zalloc(size, KM_SLEEP); 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate mcctrlconf->nmcs = nmcs; 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate /* Get all MC ids and add to mcctrlconf */ 6850Sstevel@tonic-gate mctrl = mctrl_head; 6860Sstevel@tonic-gate i = 0; 6870Sstevel@tonic-gate while (mctrl != NULL) { 6880Sstevel@tonic-gate mcctrlconf->mcids[i].globalid = mctrl->id; 6890Sstevel@tonic-gate mcctrlconf->mcids[i].localid = mctrl->id; 6900Sstevel@tonic-gate i++; 6910Sstevel@tonic-gate mctrl = mctrl->next; 6920Sstevel@tonic-gate } 6930Sstevel@tonic-gate ASSERT(i == nmcs); 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate mutex_exit(&mcdatamutex); 6960Sstevel@tonic-gate 6970Sstevel@tonic-gate if (copyout(mcctrlconf, (void *)arg, size)) 6980Sstevel@tonic-gate status = EFAULT; 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate kmem_free(mcctrlconf, size); 7010Sstevel@tonic-gate return (status); 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate /* 7040Sstevel@tonic-gate * input:id, ndevgrps and allocate space for various length of devgrpids 7050Sstevel@tonic-gate * 7060Sstevel@tonic-gate * return 0: number of devgrp, and all devgrpids, 7070Sstevel@tonic-gate * is unique of all devgrps and local id is only unique 7080Sstevel@tonic-gate * for mc. 7090Sstevel@tonic-gate * EINVAL: either if id isn't found or if the given ndevgrps is 7100Sstevel@tonic-gate * less than that in kernel and ndevgrps of struct will 7110Sstevel@tonic-gate * be updated. 7120Sstevel@tonic-gate * EFAULT: if other errors in kernel. 7130Sstevel@tonic-gate */ 7140Sstevel@tonic-gate case MCIOC_CONTROL: 7150Sstevel@tonic-gate if (copyin((void *)arg, &mccontrol_in, 7160Sstevel@tonic-gate sizeof (mccontrol_in)) != 0) 7170Sstevel@tonic-gate return (EFAULT); 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate mutex_enter(&mcdatamutex); 7200Sstevel@tonic-gate if ((mcport = mc_node_get(mccontrol_in.id, 7210Sstevel@tonic-gate mctrl_head)) == NULL) { 7220Sstevel@tonic-gate mutex_exit(&mcdatamutex); 7230Sstevel@tonic-gate return (EINVAL); 7240Sstevel@tonic-gate } 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate /* 7270Sstevel@tonic-gate * mcport->ndevgrps zero means Memory Controller is disable. 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate if ((mccontrol_in.ndevgrps < mcport->ndevgrps) || 7300Sstevel@tonic-gate (mcport->ndevgrps == 0)) { 7310Sstevel@tonic-gate mccontrol_in.ndevgrps = mcport->ndevgrps; 7320Sstevel@tonic-gate mutex_exit(&mcdatamutex); 7330Sstevel@tonic-gate if (copyout(&mccontrol_in, (void *)arg, 7340Sstevel@tonic-gate sizeof (mccontrol_in))) 7350Sstevel@tonic-gate status = EFAULT; 7360Sstevel@tonic-gate else if (mcport->ndevgrps != 0) 7370Sstevel@tonic-gate status = EINVAL; 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate return (status); 7400Sstevel@tonic-gate } 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate size = sizeof (*mccontrol) + (mcport->ndevgrps - 1) * 7430Sstevel@tonic-gate sizeof (mccontrol->devgrpids[0]); 7440Sstevel@tonic-gate mccontrol = kmem_zalloc(size, KM_SLEEP); 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate mccontrol->id = mcport->mctrl_node.id; 7470Sstevel@tonic-gate mccontrol->ndevgrps = mcport->ndevgrps; 7480Sstevel@tonic-gate for (i = 0; i < mcport->ndevgrps; i++) { 7490Sstevel@tonic-gate mccontrol->devgrpids[i].globalid = mcport->devgrpids[i]; 7500Sstevel@tonic-gate mccontrol->devgrpids[i].localid = 7510Sstevel@tonic-gate mcport->devgrpids[i] % NDGRPS_PER_MC; 7520Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("MCIOC_CONTROL: devgrp id %d\n", 7530Sstevel@tonic-gate i)); 7540Sstevel@tonic-gate } 7550Sstevel@tonic-gate mutex_exit(&mcdatamutex); 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate if (copyout(mccontrol, (void *)arg, size)) 7580Sstevel@tonic-gate status = EFAULT; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate kmem_free(mccontrol, size); 7610Sstevel@tonic-gate return (status); 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate /* 7640Sstevel@tonic-gate * input:id 7650Sstevel@tonic-gate * 7660Sstevel@tonic-gate * return 0: CPU flushed successfully. 7670Sstevel@tonic-gate * EINVAL: the id wasn't found 7680Sstevel@tonic-gate */ 7690Sstevel@tonic-gate case MCIOC_ECFLUSH: 7700Sstevel@tonic-gate mutex_enter(&cpu_lock); 7710Sstevel@tonic-gate cpu = cpu_get((processorid_t)arg); 7720Sstevel@tonic-gate mutex_exit(&cpu_lock); 7730Sstevel@tonic-gate if (cpu == NULL) 7740Sstevel@tonic-gate return (EINVAL); 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate xc_one(arg, (xcfunc_t *)cpu_flush_ecache, 0, 0); 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate return (0); 7790Sstevel@tonic-gate 7800Sstevel@tonic-gate default: 7810Sstevel@tonic-gate DPRINTF(MC_CMD_DEBUG, ("DEFAULT: cmd is wrong\n")); 7820Sstevel@tonic-gate return (EFAULT); 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate /* 7870Sstevel@tonic-gate * Gets the reg property from the memory node. This provides the various 7880Sstevel@tonic-gate * memory segments, at bank-boundries, dimm-pair boundries, in the form 7890Sstevel@tonic-gate * of [base, size] pairs. Continuous segments, spanning boundries are 7900Sstevel@tonic-gate * merged into one. 7910Sstevel@tonic-gate * Returns 0 for success and -1 for failure. 7920Sstevel@tonic-gate */ 7930Sstevel@tonic-gate static int 7940Sstevel@tonic-gate mc_get_memory_reg_info(struct mc_soft_state *softsp) 7950Sstevel@tonic-gate { 7960Sstevel@tonic-gate dev_info_t *devi; 7970Sstevel@tonic-gate int len; 7980Sstevel@tonic-gate int i; 7990Sstevel@tonic-gate struct memory_reg_info *mregi; 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate _NOTE(ARGUNUSED(softsp)) 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate if ((devi = ddi_find_devinfo("memory", -1, 0)) == NULL) { 8040Sstevel@tonic-gate DPRINTF(MC_REG_DEBUG, 8050Sstevel@tonic-gate ("mc-us3i: cannot find memory node under root\n")); 8060Sstevel@tonic-gate return (-1); 8070Sstevel@tonic-gate } 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 8100Sstevel@tonic-gate "reg", (caddr_t)®_info, &len) != DDI_PROP_SUCCESS) { 8110Sstevel@tonic-gate DPRINTF(MC_REG_DEBUG, 8120Sstevel@tonic-gate ("mc-us3i: reg undefined under memory\n")); 8130Sstevel@tonic-gate return (-1); 8140Sstevel@tonic-gate } 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate nregs = len/sizeof (*mregi); 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate DPRINTF(MC_REG_DEBUG, ("mc_get_memory_reg_info: nregs %d" 8190Sstevel@tonic-gate "reg_info %p\n", nregs, (void *) reg_info)); 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate mregi = reg_info; 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate /* debug printfs */ 8240Sstevel@tonic-gate for (i = 0; i < nregs; i++) { 8250Sstevel@tonic-gate DPRINTF(MC_REG_DEBUG, (" [0x%lx, 0x%lx] ", 8260Sstevel@tonic-gate mregi->base, mregi->size)); 8270Sstevel@tonic-gate mregi++; 8280Sstevel@tonic-gate } 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate return (0); 8310Sstevel@tonic-gate } 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate /* 8340Sstevel@tonic-gate * Initialize a logical bank 8350Sstevel@tonic-gate */ 8360Sstevel@tonic-gate static struct bank_info * 8370Sstevel@tonic-gate mc_add_bank(int bankid, uint64_t mask, uint64_t match, uint64_t size, 8380Sstevel@tonic-gate int dgrpid) 8390Sstevel@tonic-gate { 8400Sstevel@tonic-gate struct bank_info *banki; 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate if ((banki = mc_node_get(bankid, bank_head)) != NULL) { 8430Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_bank: bank %d exists\n", 8440Sstevel@tonic-gate bankid)); 8450Sstevel@tonic-gate return (banki); 8460Sstevel@tonic-gate } 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate banki = kmem_zalloc(sizeof (*banki), KM_SLEEP); 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate banki->bank_node.id = bankid; 8510Sstevel@tonic-gate banki->devgrp_id = dgrpid; 8520Sstevel@tonic-gate banki->mask = mask; 8530Sstevel@tonic-gate banki->match = match; 8540Sstevel@tonic-gate banki->base = match; 8550Sstevel@tonic-gate banki->size = size; 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate mc_node_add((mc_dlist_t *)banki, &bank_head, &bank_tail); 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_bank: id %d mask 0x%lx match 0x%lx" 8600Sstevel@tonic-gate " base 0x%lx size 0x%lx\n", bankid, mask, match, 8610Sstevel@tonic-gate banki->base, banki->size)); 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate return (banki); 8640Sstevel@tonic-gate } 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate /* 8670Sstevel@tonic-gate * Use the bank's base address to find out whether to initialize a new segment, 8680Sstevel@tonic-gate * or weave the bank into an existing segment. If the tail bank of a previous 8690Sstevel@tonic-gate * segment is not continuous with the new bank, the new bank goes into a new 8700Sstevel@tonic-gate * segment. 8710Sstevel@tonic-gate */ 8720Sstevel@tonic-gate static void 8730Sstevel@tonic-gate mc_add_segment(struct bank_info *banki) 8740Sstevel@tonic-gate { 8750Sstevel@tonic-gate struct seg_info *segi; 8760Sstevel@tonic-gate struct bank_info *tb; 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate /* does this bank start a new segment? */ 8790Sstevel@tonic-gate if ((segi = mc_node_get(seg_id, seg_head)) == NULL) { 8800Sstevel@tonic-gate /* this should happen for the first segment only */ 8810Sstevel@tonic-gate goto new_seg; 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate tb = segi->tail; 8850Sstevel@tonic-gate /* discontiguous banks go into a new segment, increment the seg_id */ 8860Sstevel@tonic-gate if (banki->base > (tb->base + tb->size)) { 8870Sstevel@tonic-gate seg_id++; 8880Sstevel@tonic-gate goto new_seg; 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate /* weave the bank into the segment */ 8920Sstevel@tonic-gate segi->nbanks++; 8930Sstevel@tonic-gate tb->next = banki; 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate banki->seg_id = segi->seg_node.id; 8960Sstevel@tonic-gate banki->local_id = tb->local_id + 1; 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate /* contiguous or interleaved? */ 8990Sstevel@tonic-gate if (banki->base != (tb->base + tb->size)) 9000Sstevel@tonic-gate segi->ifactor++; 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate segi->size += banki->size; 9030Sstevel@tonic-gate segi->tail = banki; 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate memsize += banki->size; 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_segment: id %d add bank: id %d" 9080Sstevel@tonic-gate "size 0x%lx\n", segi->seg_node.id, banki->bank_node.id, 9090Sstevel@tonic-gate banki->size)); 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate return; 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate new_seg: 9140Sstevel@tonic-gate segi = kmem_zalloc(sizeof (*segi), KM_SLEEP); 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate segi->seg_node.id = seg_id; 9170Sstevel@tonic-gate segi->nbanks = 1; 9180Sstevel@tonic-gate segi->ifactor = 1; 9190Sstevel@tonic-gate segi->base = banki->base; 9200Sstevel@tonic-gate segi->size = banki->size; 9210Sstevel@tonic-gate segi->head = banki; 9220Sstevel@tonic-gate segi->tail = banki; 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate banki->seg_id = segi->seg_node.id; 9250Sstevel@tonic-gate banki->local_id = 0; 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate mc_node_add((mc_dlist_t *)segi, &seg_head, &seg_tail); 9280Sstevel@tonic-gate nsegments++; 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate memsize += banki->size; 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_segment: id %d new bank: id %d" 9330Sstevel@tonic-gate "size 0x%lx\n", segi->seg_node.id, banki->bank_node.id, 9340Sstevel@tonic-gate banki->size)); 9350Sstevel@tonic-gate } 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate /* 9380Sstevel@tonic-gate * Returns the address bit number (row index) that controls the logical/external 9390Sstevel@tonic-gate * bank assignment in interleave of kind internal-external same dimm-pair, 9400Sstevel@tonic-gate * internal-external both dimm-pair. This is done by using the dimm-densities 9410Sstevel@tonic-gate * and part-type. 9420Sstevel@tonic-gate */ 9430Sstevel@tonic-gate static int 9440Sstevel@tonic-gate get_row_shift(int row_index, struct dgrp_info *dgrp) 9450Sstevel@tonic-gate { 9460Sstevel@tonic-gate int shift; 9470Sstevel@tonic-gate 9480Sstevel@tonic-gate switch (dgrp->base_device) { 9490Sstevel@tonic-gate case BASE_DEVICE_128Mb: 9500Sstevel@tonic-gate case BASE_DEVICE_256Mb: 9510Sstevel@tonic-gate /* 128Mb and 256Mb devices have same bank select mask */ 9520Sstevel@tonic-gate shift = ADDR_GEN_128Mb_X8_ROW_0; 9530Sstevel@tonic-gate break; 9540Sstevel@tonic-gate case BASE_DEVICE_512Mb: 9550Sstevel@tonic-gate case BASE_DEVICE_1Gb: 9560Sstevel@tonic-gate /* 512 and 1Gb devices have same bank select mask */ 9570Sstevel@tonic-gate shift = ADDR_GEN_512Mb_X8_ROW_0; 9580Sstevel@tonic-gate break; 9590Sstevel@tonic-gate } 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate if (dgrp->part_type == PART_TYPE_X4) 9620Sstevel@tonic-gate shift += 1; 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate shift += row_index; 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate return (shift); 9670Sstevel@tonic-gate } 9680Sstevel@tonic-gate 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate static void 9710Sstevel@tonic-gate get_device_select(int interleave, struct dgrp_info *dgrp, 9720Sstevel@tonic-gate int *ds_shift, int *bs_shift) 9730Sstevel@tonic-gate { 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate switch (interleave) { 9760Sstevel@tonic-gate case INTERLEAVE_DISABLE: 9770Sstevel@tonic-gate /* Fall Through */ 9780Sstevel@tonic-gate case INTERLEAVE_INTERNAL: 9790Sstevel@tonic-gate /* Bit 33 selects the dimm group/pair */ 9800Sstevel@tonic-gate *ds_shift = DIMM_PAIR_SELECT_SHIFT; 9810Sstevel@tonic-gate if (dgrp->nlogbanks == 2) { 9820Sstevel@tonic-gate /* Bit 32 selects the logical bank */ 9830Sstevel@tonic-gate *bs_shift = LOG_BANK_SELECT_SHIFT; 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate break; 9860Sstevel@tonic-gate case INTERLEAVE_INTEXT_SAME_DIMM_PAIR: 9870Sstevel@tonic-gate /* Bit 33 selects the dimm group/pair */ 9880Sstevel@tonic-gate *ds_shift = DIMM_PAIR_SELECT_SHIFT; 9890Sstevel@tonic-gate if (dgrp->nlogbanks == 2) { 9900Sstevel@tonic-gate /* Row[2] selects the logical bank */ 9910Sstevel@tonic-gate *bs_shift = get_row_shift(2, dgrp); 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate break; 9940Sstevel@tonic-gate case INTERLEAVE_INTEXT_BOTH_DIMM_PAIR: 9950Sstevel@tonic-gate if (dgrp->nlogbanks == 2) { 9960Sstevel@tonic-gate /* Row[3] selects the dimm group/pair */ 9970Sstevel@tonic-gate *ds_shift = get_row_shift(3, dgrp); 9980Sstevel@tonic-gate 9990Sstevel@tonic-gate /* Row[2] selects the logical bank */ 10000Sstevel@tonic-gate *bs_shift = get_row_shift(2, dgrp); 10010Sstevel@tonic-gate } else { 10020Sstevel@tonic-gate /* Row[2] selects the dimm group/pair */ 10030Sstevel@tonic-gate *ds_shift = get_row_shift(2, dgrp); 10040Sstevel@tonic-gate } 10050Sstevel@tonic-gate break; 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate static void 10100Sstevel@tonic-gate mc_add_xor_banks(struct mctrl_info *mctrl, 10110Sstevel@tonic-gate uint64_t mask, uint64_t match, int interleave) 10120Sstevel@tonic-gate { 10130Sstevel@tonic-gate int i, j, nbits, nbanks; 10140Sstevel@tonic-gate int bankid; 10150Sstevel@tonic-gate int dselect[4]; 10160Sstevel@tonic-gate int ds_shift = -1, bs_shift = -1; 10170Sstevel@tonic-gate uint64_t id, size, xmatch; 10180Sstevel@tonic-gate struct bank_info *banki; 10190Sstevel@tonic-gate struct dgrp_info *dgrp; 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate /* xor mode - assume 2 identical dimm-pairs */ 10220Sstevel@tonic-gate if ((dgrp = mc_node_get(mctrl->devgrpids[0], dgrp_head)) == NULL) { 10230Sstevel@tonic-gate return; 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate get_device_select(interleave, dgrp, &ds_shift, &bs_shift); 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate mask |= (ds_shift == -1 ? 0 : (1ULL << ds_shift)); 10290Sstevel@tonic-gate mask |= (bs_shift == -1 ? 0 : (1ULL << bs_shift)); 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate /* xor enable means, bit 21 is used for dimm-pair select */ 10320Sstevel@tonic-gate mask |= XOR_DEVICE_SELECT_MASK; 10330Sstevel@tonic-gate if (dgrp->nlogbanks == NLOGBANKS_PER_DGRP) { 10340Sstevel@tonic-gate /* bit 20 is used for logbank select */ 10350Sstevel@tonic-gate mask |= XOR_BANK_SELECT_MASK; 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate 10380Sstevel@tonic-gate /* find out the bits set to 1 in mask, nbits can be 2 or 4 */ 10390Sstevel@tonic-gate nbits = 0; 10400Sstevel@tonic-gate for (i = 0; i <= DIMM_PAIR_SELECT_SHIFT; i++) { 10410Sstevel@tonic-gate if ((((mask >> i) & 1) == 1) && (nbits < 4)) { 10420Sstevel@tonic-gate dselect[nbits] = i; 10430Sstevel@tonic-gate nbits++; 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate } 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate /* number or banks can be 4 or 16 */ 10480Sstevel@tonic-gate nbanks = 1 << nbits; 10490Sstevel@tonic-gate 10500Sstevel@tonic-gate size = (dgrp->size * 2)/nbanks; 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate bankid = mctrl->mctrl_node.id * NLOGBANKS_PER_MC; 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate /* each bit position of the mask decides the match & base for bank */ 10550Sstevel@tonic-gate for (i = 0; i < nbanks; i++) { 10560Sstevel@tonic-gate xmatch = 0; 10570Sstevel@tonic-gate for (j = 0; j < nbits; j++) { 10580Sstevel@tonic-gate xmatch |= (i & (1ULL << j)) << (dselect[j] - j); 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate /* xor ds bits to get the dimm-pair */ 10610Sstevel@tonic-gate id = ((xmatch & (1ULL << ds_shift)) >> ds_shift) ^ 10626803Spothier ((xmatch & (1ULL << XOR_DEVICE_SELECT_SHIFT)) >> 10636803Spothier XOR_DEVICE_SELECT_SHIFT); 10640Sstevel@tonic-gate banki = mc_add_bank(bankid, mask, match | xmatch, size, 10650Sstevel@tonic-gate mctrl->devgrpids[id]); 10660Sstevel@tonic-gate mc_add_segment(banki); 10670Sstevel@tonic-gate bankid++; 10680Sstevel@tonic-gate } 10690Sstevel@tonic-gate } 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate /* 10720Sstevel@tonic-gate * Based on interleave, dimm-densities, part-type determine the mask 10730Sstevel@tonic-gate * and match per bank, construct the logical layout by adding segments 10740Sstevel@tonic-gate * and banks 10750Sstevel@tonic-gate */ 10760Sstevel@tonic-gate static int 10770Sstevel@tonic-gate mc_add_dgrp_banks(uint64_t bankid, uint64_t dgrpid, 10780Sstevel@tonic-gate uint64_t mask, uint64_t match, int interleave) 10790Sstevel@tonic-gate { 10800Sstevel@tonic-gate int nbanks = 0; 10810Sstevel@tonic-gate struct bank_info *banki; 10820Sstevel@tonic-gate struct dgrp_info *dgrp; 10830Sstevel@tonic-gate int ds_shift = -1, bs_shift = -1; 10840Sstevel@tonic-gate uint64_t size; 10850Sstevel@tonic-gate uint64_t match_save; 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate if ((dgrp = mc_node_get(dgrpid, dgrp_head)) == NULL) { 10880Sstevel@tonic-gate return (0); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate get_device_select(interleave, dgrp, &ds_shift, &bs_shift); 10920Sstevel@tonic-gate 10930Sstevel@tonic-gate mask |= (ds_shift == -1 ? 0 : (1ULL << ds_shift)); 10940Sstevel@tonic-gate mask |= (bs_shift == -1 ? 0 : (1ULL << bs_shift)); 10950Sstevel@tonic-gate match |= (ds_shift == -1 ? 0 : ((dgrpid & 1) << ds_shift)); 10960Sstevel@tonic-gate match_save = match; 10970Sstevel@tonic-gate size = dgrp->size/dgrp->nlogbanks; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate /* for bankid 0, 2, 4 .. */ 11000Sstevel@tonic-gate match |= (bs_shift == -1 ? 0 : ((bankid & 1) << bs_shift)); 11010Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_segments: interleave %d" 11020Sstevel@tonic-gate " mask 0x%lx bs_shift %d match 0x%lx\n", 11030Sstevel@tonic-gate interleave, mask, bs_shift, match)); 11040Sstevel@tonic-gate banki = mc_add_bank(bankid, mask, match, size, dgrpid); 11050Sstevel@tonic-gate nbanks++; 11060Sstevel@tonic-gate mc_add_segment(banki); 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate if (dgrp->nlogbanks == 2) { 11090Sstevel@tonic-gate /* 11100Sstevel@tonic-gate * Set match value to original before adding second 11110Sstevel@tonic-gate * logical bank interleaving information. 11120Sstevel@tonic-gate */ 11130Sstevel@tonic-gate match = match_save; 11140Sstevel@tonic-gate bankid++; 11150Sstevel@tonic-gate match |= (bs_shift == -1 ? 0 : ((bankid & 1) << bs_shift)); 11160Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_segments: interleave %d" 11170Sstevel@tonic-gate " mask 0x%lx shift %d match 0x%lx\n", 11180Sstevel@tonic-gate interleave, mask, bs_shift, match)); 11190Sstevel@tonic-gate banki = mc_add_bank(bankid, mask, match, size, dgrpid); 11200Sstevel@tonic-gate nbanks++; 11210Sstevel@tonic-gate mc_add_segment(banki); 11220Sstevel@tonic-gate } 11230Sstevel@tonic-gate 11240Sstevel@tonic-gate return (nbanks); 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate /* 11280Sstevel@tonic-gate * Construct the logical layout 11290Sstevel@tonic-gate */ 11300Sstevel@tonic-gate static void 11310Sstevel@tonic-gate mc_logical_layout(struct mctrl_info *mctrl, struct mc_soft_state *softsp) 11320Sstevel@tonic-gate { 11330Sstevel@tonic-gate int i; 11340Sstevel@tonic-gate uint64_t mcid, bankid, interleave, mask, match; 11350Sstevel@tonic-gate 11360Sstevel@tonic-gate if (mctrl->ndevgrps == 0) 11370Sstevel@tonic-gate return; 11380Sstevel@tonic-gate 11390Sstevel@tonic-gate mcid = mctrl->mctrl_node.id; 11400Sstevel@tonic-gate mask = MC_SELECT_MASK; 11410Sstevel@tonic-gate match = mcid << MC_SELECT_SHIFT; 11420Sstevel@tonic-gate 11430Sstevel@tonic-gate interleave = (softsp->mcreg1 & MCREG1_INTERLEAVE_MASK) >> 11440Sstevel@tonic-gate MCREG1_INTERLEAVE_SHIFT; 11450Sstevel@tonic-gate 11460Sstevel@tonic-gate /* Two dimm pairs and xor bit set */ 11470Sstevel@tonic-gate if (mctrl->ndevgrps == NDGRPS_PER_MC && 11480Sstevel@tonic-gate (softsp->mcreg1 & MCREG1_XOR_ENABLE)) { 11490Sstevel@tonic-gate mc_add_xor_banks(mctrl, mask, match, interleave); 11500Sstevel@tonic-gate return; 11510Sstevel@tonic-gate } 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * For xor bit unset or only one dimm pair. 11550Sstevel@tonic-gate * In one dimm pair case, even if xor bit is set, xor 11560Sstevel@tonic-gate * interleaving is only taking place in dimm's internal 11570Sstevel@tonic-gate * banks. Dimm and external bank select bits are the 11580Sstevel@tonic-gate * same as those without xor bit set. 11590Sstevel@tonic-gate */ 11600Sstevel@tonic-gate bankid = mcid * NLOGBANKS_PER_MC; 11610Sstevel@tonic-gate for (i = 0; i < mctrl->ndevgrps; i++) { 11620Sstevel@tonic-gate bankid += mc_add_dgrp_banks(bankid, mctrl->devgrpids[i], 11636803Spothier mask, match, interleave); 11640Sstevel@tonic-gate } 11650Sstevel@tonic-gate } 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate /* 11680Sstevel@tonic-gate * Get the dimm-pair's size from the reg_info 11690Sstevel@tonic-gate */ 11700Sstevel@tonic-gate static uint64_t 11710Sstevel@tonic-gate get_devgrp_size(uint64_t start) 11720Sstevel@tonic-gate { 11730Sstevel@tonic-gate int i; 11740Sstevel@tonic-gate uint64_t size; 11750Sstevel@tonic-gate uint64_t end, reg_start, reg_end; 11760Sstevel@tonic-gate struct memory_reg_info *regi; 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate /* dgrp end address */ 11790Sstevel@tonic-gate end = start + DGRP_SIZE_MAX - 1; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate regi = reg_info; 11820Sstevel@tonic-gate size = 0; 11830Sstevel@tonic-gate for (i = 0; i < nregs; i++) { 11840Sstevel@tonic-gate reg_start = regi->base; 11850Sstevel@tonic-gate reg_end = regi->base + regi->size - 1; 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate /* completely outside */ 11880Sstevel@tonic-gate if ((reg_end < start) || (reg_start > end)) { 11890Sstevel@tonic-gate regi++; 11900Sstevel@tonic-gate continue; 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate /* completely inside */ 11940Sstevel@tonic-gate if ((reg_start <= start) && (reg_end >= end)) { 11950Sstevel@tonic-gate return (DGRP_SIZE_MAX); 11960Sstevel@tonic-gate } 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate /* start is inside, but not the end, get the remainder */ 11990Sstevel@tonic-gate if (reg_start < start) { 12000Sstevel@tonic-gate size = regi->size - (start - reg_start); 12010Sstevel@tonic-gate regi++; 12020Sstevel@tonic-gate continue; 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate /* add up size for all within range */ 12060Sstevel@tonic-gate size += regi->size; 12070Sstevel@tonic-gate regi++; 12080Sstevel@tonic-gate } 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate return (size); 12110Sstevel@tonic-gate } 12120Sstevel@tonic-gate 12130Sstevel@tonic-gate /* 12140Sstevel@tonic-gate * Each device group is a pair (dimm-pair) of identical single/dual dimms. 12150Sstevel@tonic-gate * Determine the dimm-pair's dimm-densities and part-type using the MCR-I. 12160Sstevel@tonic-gate */ 12170Sstevel@tonic-gate static void 12180Sstevel@tonic-gate mc_add_devgrp(int dgrpid, struct mc_soft_state *softsp) 12190Sstevel@tonic-gate { 12200Sstevel@tonic-gate int i, mcid, devid, dgrpoffset; 12210Sstevel@tonic-gate struct dgrp_info *dgrp; 12220Sstevel@tonic-gate struct device_info *dev; 12230Sstevel@tonic-gate struct dimm_info *dimmp = (struct dimm_info *)softsp->memlayoutp; 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate mcid = softsp->portid; 12260Sstevel@tonic-gate 12270Sstevel@tonic-gate /* add the entry on dgrp_info list */ 12280Sstevel@tonic-gate if ((dgrp = mc_node_get(dgrpid, dgrp_head)) != NULL) { 12290Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_devgrp: devgrp %d exists\n", 12300Sstevel@tonic-gate dgrpid)); 12310Sstevel@tonic-gate return; 12320Sstevel@tonic-gate } 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate dgrp = kmem_zalloc(sizeof (*dgrp), KM_SLEEP); 12350Sstevel@tonic-gate 12360Sstevel@tonic-gate dgrp->dgrp_node.id = dgrpid; 12370Sstevel@tonic-gate 12380Sstevel@tonic-gate /* a devgrp has identical (type & size) pair */ 12390Sstevel@tonic-gate if ((dgrpid & 1) == 0) { 12400Sstevel@tonic-gate /* dimm-pair 0, 2, 4, 6 */ 12410Sstevel@tonic-gate if (softsp->mcreg1 & MCREG1_DIMM1_BANK1) 12420Sstevel@tonic-gate dgrp->nlogbanks = 2; 12430Sstevel@tonic-gate else 12440Sstevel@tonic-gate dgrp->nlogbanks = 1; 12450Sstevel@tonic-gate dgrp->base_device = (softsp->mcreg1 & MCREG1_ADDRGEN1_MASK) >> 12460Sstevel@tonic-gate MCREG1_ADDRGEN1_SHIFT; 12470Sstevel@tonic-gate dgrp->part_type = (softsp->mcreg1 & MCREG1_X4DIMM1_MASK) >> 12480Sstevel@tonic-gate MCREG1_X4DIMM1_SHIFT; 12490Sstevel@tonic-gate } else { 12500Sstevel@tonic-gate /* dimm-pair 1, 3, 5, 7 */ 12510Sstevel@tonic-gate if (softsp->mcreg1 & MCREG1_DIMM2_BANK3) 12520Sstevel@tonic-gate dgrp->nlogbanks = 2; 12530Sstevel@tonic-gate else 12540Sstevel@tonic-gate dgrp->nlogbanks = 1; 12550Sstevel@tonic-gate dgrp->base_device = (softsp->mcreg1 & MCREG1_ADDRGEN2_MASK) >> 12560Sstevel@tonic-gate MCREG1_ADDRGEN2_SHIFT; 12570Sstevel@tonic-gate dgrp->part_type = (softsp->mcreg1 & MCREG1_X4DIMM2_MASK) >> 12580Sstevel@tonic-gate MCREG1_X4DIMM2_SHIFT; 12590Sstevel@tonic-gate } 12600Sstevel@tonic-gate 12610Sstevel@tonic-gate dgrp->base = MC_BASE(mcid) + DGRP_BASE(dgrpid); 12620Sstevel@tonic-gate dgrp->size = get_devgrp_size(dgrp->base); 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_devgrp: id %d size %ld logbanks %d" 12650Sstevel@tonic-gate " base_device %d part_type %d\n", dgrpid, dgrp->size, 12660Sstevel@tonic-gate dgrp->nlogbanks, dgrp->base_device, dgrp->part_type)); 12670Sstevel@tonic-gate 12680Sstevel@tonic-gate dgrpoffset = dgrpid % NDGRPS_PER_MC; 12690Sstevel@tonic-gate dgrp->ndevices = NDIMMS_PER_DGRP; 12700Sstevel@tonic-gate /* add the entry for the (identical) pair of dimms/device */ 12710Sstevel@tonic-gate for (i = 0; i < NDIMMS_PER_DGRP; i++) { 12720Sstevel@tonic-gate devid = dgrpid * NDIMMS_PER_DGRP + i; 12730Sstevel@tonic-gate dgrp->deviceids[i] = devid; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate if ((dev = mc_node_get(devid, device_head)) != NULL) { 12760Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_devgrp: device %d " 12770Sstevel@tonic-gate "exists\n", devid)); 12780Sstevel@tonic-gate continue; 12790Sstevel@tonic-gate } 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate dev = kmem_zalloc(sizeof (*dev), KM_SLEEP); 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate dev->dev_node.id = devid; 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate dev->size = dgrp->size/2; 12860Sstevel@tonic-gate 12870Sstevel@tonic-gate if (dimmp) { 12880Sstevel@tonic-gate (void) strncpy(dev->label, (char *)dimmp->label[ 12890Sstevel@tonic-gate i + NDIMMS_PER_DGRP * dgrpoffset], 12900Sstevel@tonic-gate MAX_DEVLEN); 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_add_devgrp: dimm %d %s\n", 12930Sstevel@tonic-gate dev->dev_node.id, dev->label)); 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate mc_node_add((mc_dlist_t *)dev, &device_head, &device_tail); 12970Sstevel@tonic-gate } 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate mc_node_add((mc_dlist_t *)dgrp, &dgrp_head, &dgrp_tail); 13000Sstevel@tonic-gate } 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate /* 13030Sstevel@tonic-gate * Construct the physical and logical layout 13040Sstevel@tonic-gate */ 13050Sstevel@tonic-gate static void 13060Sstevel@tonic-gate mc_construct(struct mc_soft_state *softsp) 13070Sstevel@tonic-gate { 13080Sstevel@tonic-gate int i, mcid, dgrpid; 13090Sstevel@tonic-gate struct mctrl_info *mctrl; 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate mcid = softsp->portid; 13120Sstevel@tonic-gate 13130Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_construct: mcid %d, mcreg1 0x%lx\n", 13140Sstevel@tonic-gate mcid, softsp->mcreg1)); 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate /* 13170Sstevel@tonic-gate * Construct the Physical & Logical Layout 13180Sstevel@tonic-gate */ 13190Sstevel@tonic-gate mutex_enter(&mcdatamutex); 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate /* allocate for mctrl_info */ 13220Sstevel@tonic-gate if ((mctrl = mc_node_get(mcid, mctrl_head)) != NULL) { 13230Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_construct: mctrl %d exists\n", 13240Sstevel@tonic-gate mcid)); 13250Sstevel@tonic-gate mutex_exit(&mcdatamutex); 13260Sstevel@tonic-gate return; 13270Sstevel@tonic-gate } 13280Sstevel@tonic-gate 13290Sstevel@tonic-gate mctrl = kmem_zalloc(sizeof (*mctrl), KM_SLEEP); 13300Sstevel@tonic-gate 13310Sstevel@tonic-gate mctrl->mctrl_node.id = mcid; 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate i = 0; 13340Sstevel@tonic-gate dgrpid = mcid * NDGRPS_PER_MC; 13350Sstevel@tonic-gate if (softsp->mcreg1 & MCREG1_DIMM1_BANK0) { 13360Sstevel@tonic-gate mc_add_devgrp(dgrpid, softsp); 13370Sstevel@tonic-gate mctrl->devgrpids[i] = dgrpid; 13380Sstevel@tonic-gate mctrl->ndevgrps++; 13390Sstevel@tonic-gate i++; 13400Sstevel@tonic-gate } 13410Sstevel@tonic-gate 13420Sstevel@tonic-gate if (softsp->mcreg1 & MCREG1_DIMM2_BANK2) { 13430Sstevel@tonic-gate dgrpid++; 13440Sstevel@tonic-gate mc_add_devgrp(dgrpid, softsp); 13450Sstevel@tonic-gate mctrl->devgrpids[i] = dgrpid; 13460Sstevel@tonic-gate mctrl->ndevgrps++; 13470Sstevel@tonic-gate } 13480Sstevel@tonic-gate 13490Sstevel@tonic-gate mc_logical_layout(mctrl, softsp); 13500Sstevel@tonic-gate 13510Sstevel@tonic-gate mctrl->dimminfop = (struct dimm_info *)softsp->memlayoutp; 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate nmcs++; 13540Sstevel@tonic-gate mc_node_add((mc_dlist_t *)mctrl, &mctrl_head, &mctrl_tail); 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate mutex_exit(&mcdatamutex); 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate DPRINTF(MC_CNSTRC_DEBUG, ("mc_construct: nmcs %d memsize %ld" 13590Sstevel@tonic-gate "nsegments %d\n", nmcs, memsize, nsegments)); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate /* 13630Sstevel@tonic-gate * Delete nodes related to the given MC on mc, device group, device, 13640Sstevel@tonic-gate * and bank lists. Moreover, delete corresponding segment if its connected 13650Sstevel@tonic-gate * banks are all removed. 13660Sstevel@tonic-gate */ 13670Sstevel@tonic-gate static void 13680Sstevel@tonic-gate mc_delete(int mc_id) 13690Sstevel@tonic-gate { 13700Sstevel@tonic-gate int i, j, dgrpid, devid, bankid; 13710Sstevel@tonic-gate struct mctrl_info *mctrl; 13720Sstevel@tonic-gate struct dgrp_info *dgrp; 13730Sstevel@tonic-gate struct device_info *devp; 13740Sstevel@tonic-gate struct seg_info *segi; 13750Sstevel@tonic-gate struct bank_info *banki; 13760Sstevel@tonic-gate 13770Sstevel@tonic-gate mutex_enter(&mcdatamutex); 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate /* delete mctrl_info */ 13800Sstevel@tonic-gate if ((mctrl = mc_node_get(mc_id, mctrl_head)) != NULL) { 13810Sstevel@tonic-gate mc_node_del((mc_dlist_t *)mctrl, &mctrl_head, &mctrl_tail); 13820Sstevel@tonic-gate kmem_free(mctrl, sizeof (*mctrl)); 13830Sstevel@tonic-gate nmcs--; 13840Sstevel@tonic-gate } else 13850Sstevel@tonic-gate DPRINTF(MC_DESTRC_DEBUG, ("mc_delete: mctrl is not found\n")); 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate /* delete device groups and devices of the detached MC */ 13880Sstevel@tonic-gate for (i = 0; i < NDGRPS_PER_MC; i++) { 13890Sstevel@tonic-gate dgrpid = mc_id * NDGRPS_PER_MC + i; 13900Sstevel@tonic-gate if (!(dgrp = mc_node_get(dgrpid, dgrp_head))) { 13910Sstevel@tonic-gate continue; 13920Sstevel@tonic-gate } 13930Sstevel@tonic-gate 13940Sstevel@tonic-gate for (j = 0; j < NDIMMS_PER_DGRP; j++) { 13950Sstevel@tonic-gate devid = dgrpid * NDIMMS_PER_DGRP + j; 13960Sstevel@tonic-gate if (devp = mc_node_get(devid, device_head)) { 13970Sstevel@tonic-gate mc_node_del((mc_dlist_t *)devp, 13980Sstevel@tonic-gate &device_head, &device_tail); 13990Sstevel@tonic-gate kmem_free(devp, sizeof (*devp)); 14000Sstevel@tonic-gate } else 14010Sstevel@tonic-gate DPRINTF(MC_DESTRC_DEBUG, 14020Sstevel@tonic-gate ("mc_delete: no dev %d\n", devid)); 14030Sstevel@tonic-gate } 14040Sstevel@tonic-gate 14050Sstevel@tonic-gate mc_node_del((mc_dlist_t *)dgrp, &dgrp_head, &dgrp_tail); 14060Sstevel@tonic-gate kmem_free(dgrp, sizeof (*dgrp)); 14070Sstevel@tonic-gate } 14080Sstevel@tonic-gate 14090Sstevel@tonic-gate /* delete all banks and associated segments */ 14100Sstevel@tonic-gate for (i = 0; i < NLOGBANKS_PER_MC; i++) { 14110Sstevel@tonic-gate bankid = mc_id * NLOGBANKS_PER_MC + i; 14120Sstevel@tonic-gate if (!(banki = mc_node_get(bankid, bank_head))) { 14130Sstevel@tonic-gate continue; 14140Sstevel@tonic-gate } 14150Sstevel@tonic-gate 14160Sstevel@tonic-gate /* bank and segments go together */ 14171966Sarutz if ((segi = mc_node_get(banki->seg_id, seg_head)) != NULL) { 14180Sstevel@tonic-gate mc_node_del((mc_dlist_t *)segi, &seg_head, &seg_tail); 14190Sstevel@tonic-gate kmem_free(segi, sizeof (*segi)); 14200Sstevel@tonic-gate nsegments--; 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate 14230Sstevel@tonic-gate mc_node_del((mc_dlist_t *)banki, &bank_head, &bank_tail); 14240Sstevel@tonic-gate kmem_free(banki, sizeof (*banki)); 14250Sstevel@tonic-gate } 14260Sstevel@tonic-gate 14270Sstevel@tonic-gate mutex_exit(&mcdatamutex); 14280Sstevel@tonic-gate } 14290Sstevel@tonic-gate 14300Sstevel@tonic-gate /* 14310Sstevel@tonic-gate * mc_dlist is a double linking list, including unique id, and pointers to 14320Sstevel@tonic-gate * next, and previous nodes. seg_info, bank_info, dgrp_info, device_info, 14330Sstevel@tonic-gate * and mctrl_info has it at the top to share the operations, add, del, and get. 14340Sstevel@tonic-gate * 14350Sstevel@tonic-gate * The new node is added at the tail and is not sorted. 14360Sstevel@tonic-gate * 14370Sstevel@tonic-gate * Input: The pointer of node to be added, head and tail of the list 14380Sstevel@tonic-gate */ 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate static void 14410Sstevel@tonic-gate mc_node_add(mc_dlist_t *node, mc_dlist_t **head, mc_dlist_t **tail) 14420Sstevel@tonic-gate { 14430Sstevel@tonic-gate DPRINTF(MC_LIST_DEBUG, ("mc_node_add: node->id %d head %p tail %p\n", 14440Sstevel@tonic-gate node->id, (void *) *head, (void *) *tail)); 14450Sstevel@tonic-gate 14460Sstevel@tonic-gate if (*head != NULL) { 14470Sstevel@tonic-gate node->prev = *tail; 14480Sstevel@tonic-gate node->next = (*tail)->next; 14490Sstevel@tonic-gate (*tail)->next = node; 14500Sstevel@tonic-gate *tail = node; 14510Sstevel@tonic-gate } else { 14520Sstevel@tonic-gate node->next = node->prev = NULL; 14530Sstevel@tonic-gate *head = *tail = node; 14540Sstevel@tonic-gate } 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate 14570Sstevel@tonic-gate /* 14580Sstevel@tonic-gate * Input: The pointer of node to be deleted, head and tail of the list 14590Sstevel@tonic-gate * 14600Sstevel@tonic-gate * Deleted node will be at the following positions 14610Sstevel@tonic-gate * 1. At the tail of the list 14620Sstevel@tonic-gate * 2. At the head of the list 14630Sstevel@tonic-gate * 3. At the head and tail of the list, i.e. only one left. 14640Sstevel@tonic-gate * 4. At the middle of the list 14650Sstevel@tonic-gate */ 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate static void 14680Sstevel@tonic-gate mc_node_del(mc_dlist_t *node, mc_dlist_t **head, mc_dlist_t **tail) 14690Sstevel@tonic-gate { 14700Sstevel@tonic-gate if (node->next == NULL) { 14710Sstevel@tonic-gate /* deleted node is at the tail of list */ 14720Sstevel@tonic-gate *tail = node->prev; 14730Sstevel@tonic-gate } else { 14740Sstevel@tonic-gate node->next->prev = node->prev; 14750Sstevel@tonic-gate } 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate if (node->prev == NULL) { 14780Sstevel@tonic-gate /* deleted node is at the head of list */ 14790Sstevel@tonic-gate *head = node->next; 14800Sstevel@tonic-gate } else { 14810Sstevel@tonic-gate node->prev->next = node->next; 14820Sstevel@tonic-gate } 14830Sstevel@tonic-gate } 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate /* 14860Sstevel@tonic-gate * Search the list from the head of the list to match the given id 14870Sstevel@tonic-gate * Input: id and the head of the list 14880Sstevel@tonic-gate * Return: pointer of found node 14890Sstevel@tonic-gate */ 14900Sstevel@tonic-gate static void * 14910Sstevel@tonic-gate mc_node_get(int id, mc_dlist_t *head) 14920Sstevel@tonic-gate { 14930Sstevel@tonic-gate mc_dlist_t *node; 14940Sstevel@tonic-gate 14950Sstevel@tonic-gate node = head; 14960Sstevel@tonic-gate while (node != NULL) { 14970Sstevel@tonic-gate DPRINTF(MC_LIST_DEBUG, ("mc_node_get: id %d, given id %d\n", 14980Sstevel@tonic-gate node->id, id)); 14990Sstevel@tonic-gate if (node->id == id) 15000Sstevel@tonic-gate break; 15010Sstevel@tonic-gate node = node->next; 15020Sstevel@tonic-gate } 15030Sstevel@tonic-gate return (node); 15040Sstevel@tonic-gate } 15050Sstevel@tonic-gate 15060Sstevel@tonic-gate /* 15070Sstevel@tonic-gate * Memory subsystem provides 144 bits (128 Data bits, 9 ECC bits and 7 15080Sstevel@tonic-gate * unused bits) interface via a pair of DIMMs. Mapping of Data/ECC bits 15090Sstevel@tonic-gate * to a specific DIMM pin is described by the memory-layout property 15100Sstevel@tonic-gate * via two tables: dimm table and pin table. 15110Sstevel@tonic-gate * 15120Sstevel@tonic-gate * Memory-layout property arranges data/ecc bits in the following order: 15130Sstevel@tonic-gate * 15140Sstevel@tonic-gate * Bit# 143 16 15 7 6 0 15150Sstevel@tonic-gate * | Data[127:0] | ECC[8:0] | Unused[6:0] | 15160Sstevel@tonic-gate * 15170Sstevel@tonic-gate * dimm table: 1 bit is used to store DIMM number (2 possible DIMMs) for 15180Sstevel@tonic-gate * each Data/ECC bit. Thus, it needs 18 bytes (144/8) to represent 15190Sstevel@tonic-gate * all Data/ECC bits in this table. Information is stored in big 15200Sstevel@tonic-gate * endian order, i.e. dimm_table[0] represents information for 15210Sstevel@tonic-gate * logical bit# 143 to 136. 15220Sstevel@tonic-gate * 15230Sstevel@tonic-gate * pin table: 1 byte is used to store pin position for each Data/ECC bit. 15240Sstevel@tonic-gate * Thus, this table is 144 bytes long. Information is stored in little 15250Sstevel@tonic-gate * endian order, i.e, pin_table[0] represents pin number of logical 15260Sstevel@tonic-gate * bit 0 and pin_table[143] contains pin number for logical bit 143 15270Sstevel@tonic-gate * (i.e. data bit# 127). 15280Sstevel@tonic-gate * 15290Sstevel@tonic-gate * qwordmap table below is used to map mc_get_mem_unum "synd_code" value into 15300Sstevel@tonic-gate * logical bit position assigned above by the memory-layout property. 15310Sstevel@tonic-gate */ 15320Sstevel@tonic-gate 15330Sstevel@tonic-gate #define QWORD_SIZE 144 15340Sstevel@tonic-gate static uint8_t qwordmap[QWORD_SIZE] = 15350Sstevel@tonic-gate { 15360Sstevel@tonic-gate 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 15370Sstevel@tonic-gate 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 15380Sstevel@tonic-gate 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 15390Sstevel@tonic-gate 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 15400Sstevel@tonic-gate 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 15410Sstevel@tonic-gate 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 15420Sstevel@tonic-gate 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 15430Sstevel@tonic-gate 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 15440Sstevel@tonic-gate 7, 8, 9, 10, 11, 12, 13, 14, 15, 4, 5, 6, 0, 1, 2, 3 15450Sstevel@tonic-gate }; 15460Sstevel@tonic-gate 15470Sstevel@tonic-gate 15480Sstevel@tonic-gate /* ARGSUSED */ 15490Sstevel@tonic-gate static int 15500Sstevel@tonic-gate mc_get_mem_unum(int synd_code, uint64_t paddr, char *buf, int buflen, int *lenp) 15510Sstevel@tonic-gate { 15520Sstevel@tonic-gate int i; 15530Sstevel@tonic-gate int pos_cacheline, position, index, idx4dimm; 15540Sstevel@tonic-gate int qwlayout = synd_code; 15550Sstevel@tonic-gate short offset, data; 15560Sstevel@tonic-gate char unum[UNUM_NAMLEN]; 15570Sstevel@tonic-gate struct dimm_info *dimmp; 15580Sstevel@tonic-gate struct pin_info *pinp; 15590Sstevel@tonic-gate struct bank_info *bank; 15600Sstevel@tonic-gate struct mctrl_info *mctrl; 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate /* 15630Sstevel@tonic-gate * Enforce old Openboot requirement for synd code, either a single-bit 15640Sstevel@tonic-gate * code from 0..QWORD_SIZE-1 or -1 (multi-bit error). 15650Sstevel@tonic-gate */ 15660Sstevel@tonic-gate if (qwlayout < -1 || qwlayout >= QWORD_SIZE) 15670Sstevel@tonic-gate return (EINVAL); 15680Sstevel@tonic-gate 15690Sstevel@tonic-gate unum[0] = '\0'; 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate DPRINTF(MC_GUNUM_DEBUG, ("mc_get_mem_unum:qwlayout %d phyaddr 0x%lx\n", 15720Sstevel@tonic-gate qwlayout, paddr)); 15730Sstevel@tonic-gate 15740Sstevel@tonic-gate /* 15750Sstevel@tonic-gate * Scan all logical banks to get one responding to the physical 15760Sstevel@tonic-gate * address. Then compute the index to look up dimm and pin tables 15770Sstevel@tonic-gate * to generate the unmuber. 15780Sstevel@tonic-gate */ 15790Sstevel@tonic-gate mutex_enter(&mcdatamutex); 15800Sstevel@tonic-gate bank = (struct bank_info *)bank_head; 15810Sstevel@tonic-gate while (bank != NULL) { 15820Sstevel@tonic-gate int mcid, mcdgrpid, dimmoffset; 15830Sstevel@tonic-gate 15840Sstevel@tonic-gate /* 15850Sstevel@tonic-gate * Physical Address is in a bank if (Addr & Mask) == Match 15860Sstevel@tonic-gate */ 15870Sstevel@tonic-gate if ((paddr & bank->mask) != bank->match) { 15880Sstevel@tonic-gate bank = (struct bank_info *)bank->bank_node.next; 15890Sstevel@tonic-gate continue; 15900Sstevel@tonic-gate } 15910Sstevel@tonic-gate 15920Sstevel@tonic-gate mcid = bank->bank_node.id / NLOGBANKS_PER_MC; 15930Sstevel@tonic-gate mctrl = mc_node_get(mcid, mctrl_head); 15940Sstevel@tonic-gate ASSERT(mctrl != NULL); 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate DPRINTF(MC_GUNUM_DEBUG, ("mc_get_mem_unum:mc %d bank %d " 15970Sstevel@tonic-gate "dgrp %d\n", mcid, bank->bank_node.id, bank->devgrp_id)); 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate mcdgrpid = bank->devgrp_id % NDGRPS_PER_MC; 16000Sstevel@tonic-gate dimmoffset = mcdgrpid * NDIMMS_PER_DGRP; 16010Sstevel@tonic-gate 16020Sstevel@tonic-gate dimmp = (struct dimm_info *)mctrl->dimminfop; 16030Sstevel@tonic-gate if (dimmp == NULL) { 16040Sstevel@tonic-gate mutex_exit(&mcdatamutex); 16050Sstevel@tonic-gate return (ENXIO); 16060Sstevel@tonic-gate } 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate if ((qwlayout >= 0) && (qwlayout < QWORD_SIZE)) { 16090Sstevel@tonic-gate /* 16100Sstevel@tonic-gate * single-bit error handling, we can identify specific 16110Sstevel@tonic-gate * DIMM. 16120Sstevel@tonic-gate */ 16130Sstevel@tonic-gate 16140Sstevel@tonic-gate pinp = (struct pin_info *)&dimmp->data[0]; 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate pos_cacheline = qwordmap[qwlayout]; 16170Sstevel@tonic-gate position = 143 - pos_cacheline; 16180Sstevel@tonic-gate index = position / 8; 16190Sstevel@tonic-gate offset = 7 - (position % 8); 16200Sstevel@tonic-gate 16210Sstevel@tonic-gate DPRINTF(MC_GUNUM_DEBUG, ("mc_get_mem_unum:position " 16220Sstevel@tonic-gate "%d\n", position)); 16230Sstevel@tonic-gate /* 16240Sstevel@tonic-gate * Trade-off: We cound't add pin number to 16250Sstevel@tonic-gate * unumber string because statistic number 16260Sstevel@tonic-gate * pumps up at the corresponding dimm not pin. 16270Sstevel@tonic-gate * (void) sprintf(unum, "Pin %1u ", (uint_t) 16280Sstevel@tonic-gate * pinp->pintable[pos_cacheline]); 16290Sstevel@tonic-gate */ 16300Sstevel@tonic-gate DPRINTF(MC_GUNUM_DEBUG, ("mc_get_mem_unum:pin number " 16310Sstevel@tonic-gate "%1u\n", (uint_t)pinp->pintable[pos_cacheline])); 16320Sstevel@tonic-gate data = pinp->dimmtable[index]; 16330Sstevel@tonic-gate idx4dimm = (data >> offset) & 1; 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate (void) strncpy(unum, 16360Sstevel@tonic-gate (char *)dimmp->label[dimmoffset + idx4dimm], 16370Sstevel@tonic-gate UNUM_NAMLEN); 16380Sstevel@tonic-gate 16390Sstevel@tonic-gate DPRINTF(MC_GUNUM_DEBUG, 16406803Spothier ("mc_get_mem_unum:unum %s\n", unum)); 16410Sstevel@tonic-gate 16420Sstevel@tonic-gate /* 16430Sstevel@tonic-gate * platform hook for adding label information to unum. 16440Sstevel@tonic-gate */ 16450Sstevel@tonic-gate mc_add_mem_unum_label(unum, mcid, mcdgrpid, idx4dimm); 16460Sstevel@tonic-gate } else { 16470Sstevel@tonic-gate char *p = unum; 16480Sstevel@tonic-gate size_t res = UNUM_NAMLEN; 16490Sstevel@tonic-gate 16500Sstevel@tonic-gate /* 16510Sstevel@tonic-gate * multi-bit error handling, we can only identify 16520Sstevel@tonic-gate * bank of DIMMs. 16530Sstevel@tonic-gate */ 16540Sstevel@tonic-gate 16550Sstevel@tonic-gate for (i = 0; (i < NDIMMS_PER_DGRP) && (res > 0); i++) { 16560Sstevel@tonic-gate (void) snprintf(p, res, "%s%s", 16570Sstevel@tonic-gate i == 0 ? "" : " ", 16580Sstevel@tonic-gate (char *)dimmp->label[dimmoffset + i]); 16590Sstevel@tonic-gate res -= strlen(p); 16600Sstevel@tonic-gate p += strlen(p); 16610Sstevel@tonic-gate } 16620Sstevel@tonic-gate 16630Sstevel@tonic-gate /* 16640Sstevel@tonic-gate * platform hook for adding label information 16650Sstevel@tonic-gate * to unum. 16660Sstevel@tonic-gate */ 16670Sstevel@tonic-gate mc_add_mem_unum_label(unum, mcid, mcdgrpid, -1); 16680Sstevel@tonic-gate } 16690Sstevel@tonic-gate mutex_exit(&mcdatamutex); 16700Sstevel@tonic-gate if ((strlen(unum) >= UNUM_NAMLEN) || 16710Sstevel@tonic-gate (strlen(unum) >= buflen)) { 16726803Spothier return (ENAMETOOLONG); 16730Sstevel@tonic-gate } else { 16740Sstevel@tonic-gate (void) strncpy(buf, unum, UNUM_NAMLEN); 16750Sstevel@tonic-gate *lenp = strlen(buf); 16760Sstevel@tonic-gate return (0); 16770Sstevel@tonic-gate } 16780Sstevel@tonic-gate } /* end of while loop for logic bank list */ 16790Sstevel@tonic-gate 16800Sstevel@tonic-gate mutex_exit(&mcdatamutex); 16810Sstevel@tonic-gate return (ENXIO); 16820Sstevel@tonic-gate } 16830Sstevel@tonic-gate 16840Sstevel@tonic-gate static int 16850Sstevel@tonic-gate mc_get_mem_info(int synd_code, uint64_t paddr, 16860Sstevel@tonic-gate uint64_t *mem_sizep, uint64_t *seg_sizep, uint64_t *bank_sizep, 16870Sstevel@tonic-gate int *segsp, int *banksp, int *mcidp) 16880Sstevel@tonic-gate { 16890Sstevel@tonic-gate struct bank_info *bankp; 16900Sstevel@tonic-gate 16910Sstevel@tonic-gate if (synd_code < -1 || synd_code >= QWORD_SIZE) 16920Sstevel@tonic-gate return (EINVAL); 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate /* 16950Sstevel@tonic-gate * Scan all logical banks to get one responding to the physical 16960Sstevel@tonic-gate * address. Then compute the index to look up dimm and pin tables 16970Sstevel@tonic-gate * to generate the unmuber. 16980Sstevel@tonic-gate */ 16990Sstevel@tonic-gate mutex_enter(&mcdatamutex); 17000Sstevel@tonic-gate bankp = (struct bank_info *)bank_head; 17010Sstevel@tonic-gate while (bankp != NULL) { 17020Sstevel@tonic-gate struct seg_info *segp; 17030Sstevel@tonic-gate int mcid; 17040Sstevel@tonic-gate 17050Sstevel@tonic-gate /* 17060Sstevel@tonic-gate * Physical Address is in a bank if (Addr & Mask) == Match 17070Sstevel@tonic-gate */ 17080Sstevel@tonic-gate if ((paddr & bankp->mask) != bankp->match) { 17090Sstevel@tonic-gate bankp = (struct bank_info *)bankp->bank_node.next; 17100Sstevel@tonic-gate continue; 17110Sstevel@tonic-gate } 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate mcid = bankp->bank_node.id / NLOGBANKS_PER_MC; 17140Sstevel@tonic-gate 17150Sstevel@tonic-gate /* 17160Sstevel@tonic-gate * Get the corresponding segment. 17170Sstevel@tonic-gate */ 17180Sstevel@tonic-gate if ((segp = (struct seg_info *)mc_node_get(bankp->seg_id, 17190Sstevel@tonic-gate seg_head)) == NULL) { 17200Sstevel@tonic-gate mutex_exit(&mcdatamutex); 17210Sstevel@tonic-gate return (EFAULT); 17220Sstevel@tonic-gate } 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate *mem_sizep = memsize; 17250Sstevel@tonic-gate *seg_sizep = segp->size; 17260Sstevel@tonic-gate *bank_sizep = bankp->size; 17270Sstevel@tonic-gate *segsp = nsegments; 17280Sstevel@tonic-gate *banksp = segp->nbanks; 17290Sstevel@tonic-gate *mcidp = mcid; 17300Sstevel@tonic-gate 17310Sstevel@tonic-gate mutex_exit(&mcdatamutex); 17320Sstevel@tonic-gate return (0); 17330Sstevel@tonic-gate 17340Sstevel@tonic-gate } /* end of while loop for logic bank list */ 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate mutex_exit(&mcdatamutex); 17370Sstevel@tonic-gate return (ENXIO); 17380Sstevel@tonic-gate } 17390Sstevel@tonic-gate /* 17400Sstevel@tonic-gate * mc-us3i driver allows a platform to add extra label 17410Sstevel@tonic-gate * information to the unum string. If a platform implements a 17420Sstevel@tonic-gate * kernel function called plat_add_mem_unum_label() it will be 17430Sstevel@tonic-gate * executed. This would typically be implemented in the platmod. 17440Sstevel@tonic-gate */ 17450Sstevel@tonic-gate static void 17460Sstevel@tonic-gate mc_add_mem_unum_label(char *unum, int mcid, int bank, int dimm) 17470Sstevel@tonic-gate { 17480Sstevel@tonic-gate if (&plat_add_mem_unum_label) 17490Sstevel@tonic-gate plat_add_mem_unum_label(unum, mcid, bank, dimm); 17500Sstevel@tonic-gate } 1751