17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * sun4v root nexus driver 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate #include <sys/conf.h> 337c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 347c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 357c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 367c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 377c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 387c478bd9Sstevel@tonic-gate #include <sys/async.h> 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* Useful debugging Stuff */ 417c478bd9Sstevel@tonic-gate #include <sys/nexusdebug.h> 427c478bd9Sstevel@tonic-gate #define ROOTNEX_MAP_DEBUG 0x1 437c478bd9Sstevel@tonic-gate #define ROOTNEX_INTR_DEBUG 0x2 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate extern uint_t root_phys_addr_lo_mask; 467c478bd9Sstevel@tonic-gate extern int rootnex_name_child(dev_info_t *child, char *name, int namelen); 477c478bd9Sstevel@tonic-gate extern int rootnex_ctl_uninitchild(dev_info_t *dip); 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate uint_t root_phys_addr_hi_mask = 0xfffffff; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define BUS_ADDRTYPE_CONFIG 0xc 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #define BUSTYPE_TO_ADDRTYPE(bustype) ((bustype >> 28) & 0xf) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static char *bus_addrtype[16] = { 567c478bd9Sstevel@tonic-gate "m", NULL, NULL, NULL, NULL, NULL, NULL, NULL, 577c478bd9Sstevel@tonic-gate "i", NULL, NULL, NULL, "", NULL, NULL, NULL 587c478bd9Sstevel@tonic-gate }; 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * config information 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate int 647c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 657c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate int 687c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 697c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 707c478bd9Sstevel@tonic-gate 71*a195726fSgovinda int 727c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip, 737c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t rootnex_err_ibc; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * rootnex_add_intr_impl: 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 817c478bd9Sstevel@tonic-gate int 827c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 837c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 847c478bd9Sstevel@tonic-gate { 857c478bd9Sstevel@tonic-gate return (i_ddi_add_ivintr(hdlp)); 867c478bd9Sstevel@tonic-gate } 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * rootnex_remove_intr_impl: 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 927c478bd9Sstevel@tonic-gate int 937c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 947c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 957c478bd9Sstevel@tonic-gate { 967c478bd9Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 1027c478bd9Sstevel@tonic-gate * rootnex_get_intr_pri: 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 105*a195726fSgovinda int 1067c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip, 1077c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp) 1087c478bd9Sstevel@tonic-gate { 109*a195726fSgovinda return (hdlp->ih_pri); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate int 1137c478bd9Sstevel@tonic-gate rootnex_ctl_reportdev_impl(dev_info_t *dev) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate struct regspec *rp; 1167c478bd9Sstevel@tonic-gate char buf[80]; 1177c478bd9Sstevel@tonic-gate char *p = buf; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate (void) sprintf(p, "%s%d at root", ddi_driver_name(dev), 1207c478bd9Sstevel@tonic-gate ddi_get_instance(dev)); 1217c478bd9Sstevel@tonic-gate p += strlen(p); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate if (sparc_pd_getnreg(dev) > 0) { 1247c478bd9Sstevel@tonic-gate rp = sparc_pd_getreg(dev, 0); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate (void) strcpy(p, ": "); 1277c478bd9Sstevel@tonic-gate p += strlen(p); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate (void) snprintf(p, sizeof (buf) - (buf - p), 1307c478bd9Sstevel@tonic-gate "0x%x 0x%x", rp->regspec_bustype & root_phys_addr_hi_mask, 1317c478bd9Sstevel@tonic-gate rp->regspec_addr & root_phys_addr_lo_mask); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate p += strlen(p); 1347c478bd9Sstevel@tonic-gate } 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * This is where we need to print out the interrupt specifications 1387c478bd9Sstevel@tonic-gate * for the FFB device and any UPA add-on devices. Not sure how to 1397c478bd9Sstevel@tonic-gate * do this yet? 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?%s\n", buf); 1427c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate int 1467c478bd9Sstevel@tonic-gate rootnex_name_child_impl(dev_info_t *child, char *name, int namelen) 1477c478bd9Sstevel@tonic-gate { 1487c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 1497c478bd9Sstevel@tonic-gate uint_t addrtype; 1507c478bd9Sstevel@tonic-gate uint_t addrlow; 1517c478bd9Sstevel@tonic-gate struct regspec *rp; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate extern uint_t root_phys_addr_lo_mask; 1547c478bd9Sstevel@tonic-gate extern void make_ddi_ppd( 1557c478bd9Sstevel@tonic-gate dev_info_t *, struct ddi_parent_private_data **); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * Fill in parent-private data and this function returns to us 1597c478bd9Sstevel@tonic-gate * an indication if it used "registers" to fill in the data. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 1627c478bd9Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 1637c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * No reg property, return null string as address (e.g. pseudo) 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate name[0] = '\0'; 1707c478bd9Sstevel@tonic-gate if (sparc_pd_getnreg(child) == 0) { 1717c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate rp = sparc_pd_getreg(child, 0); 1747c478bd9Sstevel@tonic-gate ASSERT(rp != NULL); 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * Name node on behalf of child nexus. 1787c478bd9Sstevel@tonic-gate */ 1797c478bd9Sstevel@tonic-gate if (ddi_get_parent(child) != ddi_root_node()) { 1807c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 1817c478bd9Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr); 1827c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * On sun4v, the 'name' of a root node device depends upon 1877c478bd9Sstevel@tonic-gate * the first reg property, which contains two 32-bit address 1887c478bd9Sstevel@tonic-gate * cells as follows: 1897c478bd9Sstevel@tonic-gate * 1907c478bd9Sstevel@tonic-gate * bit# 63-32: ssss.hhhh.hhhh.hhhh.hhhh.hhhh.hhhh.hhhh 1917c478bd9Sstevel@tonic-gate * bit# 31-00: llll.llll.llll.llll.llll.llll.llll.llll 1927c478bd9Sstevel@tonic-gate * 1937c478bd9Sstevel@tonic-gate * where 'ssss' defines the address type and naming convention 1947c478bd9Sstevel@tonic-gate * as follows: 1957c478bd9Sstevel@tonic-gate * 1967c478bd9Sstevel@tonic-gate * 0000 -> cacheable address space 1977c478bd9Sstevel@tonic-gate * foo@m<high-addr>[,<low-addr>] 1987c478bd9Sstevel@tonic-gate * 1000 -> non-cacheable IO address space 1997c478bd9Sstevel@tonic-gate * foo@i<high-addr>[,<low-addr>] 2007c478bd9Sstevel@tonic-gate * 1100 -> non-cacheable configuration address space 2017c478bd9Sstevel@tonic-gate * foo@<high-addr> 2027c478bd9Sstevel@tonic-gate * 2037c478bd9Sstevel@tonic-gate * where <hish-addr> is hex-ASCII reprensation of the hh...hh 2047c478bd9Sstevel@tonic-gate * bits and <low-addr> is hex-ASCII represenation of the 2057c478bd9Sstevel@tonic-gate * ll...ll bits. 2067c478bd9Sstevel@tonic-gate * 2077c478bd9Sstevel@tonic-gate * Note that the leading zeros are omitted here. Also, if the 2087c478bd9Sstevel@tonic-gate * <low-addr> bits are zero, then the trailing component is 2097c478bd9Sstevel@tonic-gate * omitted as well. 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate addrtype = BUSTYPE_TO_ADDRTYPE(rp->regspec_bustype); 2127c478bd9Sstevel@tonic-gate addrlow = rp->regspec_addr & root_phys_addr_lo_mask; 2137c478bd9Sstevel@tonic-gate if (bus_addrtype[addrtype] == NULL) 2147c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "rootnex: wrong bustype: %x child: %s\n", 2157c478bd9Sstevel@tonic-gate rp->regspec_bustype, ddi_node_name(child)); 2167c478bd9Sstevel@tonic-gate else if (addrtype == BUS_ADDRTYPE_CONFIG || addrlow == 0) 2177c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%s%x", 2187c478bd9Sstevel@tonic-gate bus_addrtype[addrtype], 2197c478bd9Sstevel@tonic-gate rp->regspec_bustype & root_phys_addr_hi_mask); 2207c478bd9Sstevel@tonic-gate else 2217c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%s%x,%x", 2227c478bd9Sstevel@tonic-gate bus_addrtype[addrtype], 2237c478bd9Sstevel@tonic-gate rp->regspec_bustype & root_phys_addr_hi_mask, addrlow); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate int 2307c478bd9Sstevel@tonic-gate rootnex_ctl_initchild_impl(dev_info_t *dip) 2317c478bd9Sstevel@tonic-gate { 2327c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pd; 2337c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate extern struct ddi_parent_private_data *init_regspec_64(dev_info_t *dip); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* Name the child */ 2387c478bd9Sstevel@tonic-gate (void) rootnex_name_child(dip, name, MAXNAMELEN); 2397c478bd9Sstevel@tonic-gate ddi_set_name_addr(dip, name); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * Try to merge .conf node. If merge is successful, return 2437c478bd9Sstevel@tonic-gate * DDI_FAILURE to allow caller to remove this node. 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip) == 0 && 2467c478bd9Sstevel@tonic-gate (ndi_merge_node(dip, rootnex_name_child) == DDI_SUCCESS)) { 2477c478bd9Sstevel@tonic-gate (void) rootnex_ctl_uninitchild(dip); 2487c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2497c478bd9Sstevel@tonic-gate } 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * If there are no "reg"s in the child node, return. 2537c478bd9Sstevel@tonic-gate */ 2547c478bd9Sstevel@tonic-gate pd = init_regspec_64(dip); 2557c478bd9Sstevel@tonic-gate if ((pd == NULL) || (pd->par_nreg == 0)) 2567c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2627c478bd9Sstevel@tonic-gate void 2637c478bd9Sstevel@tonic-gate rootnex_ctl_uninitchild_impl(dev_info_t *dip) 2647c478bd9Sstevel@tonic-gate { 2657c478bd9Sstevel@tonic-gate } 266