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
5*1c0f05faSjasonwu * Common Development and Distribution License (the "License").
6*1c0f05faSjasonwu * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*1c0f05faSjasonwu * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * sun4u root nexus driver
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate #include <sys/conf.h>
327c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysiosbus.h>
347c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
357c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
367c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
377c478bd9Sstevel@tonic-gate #include <sys/async.h>
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /* Useful debugging Stuff */
407c478bd9Sstevel@tonic-gate #include <sys/nexusdebug.h>
417c478bd9Sstevel@tonic-gate #define ROOTNEX_MAP_DEBUG 0x1
427c478bd9Sstevel@tonic-gate #define ROOTNEX_INTR_DEBUG 0x2
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate * Extern declarations
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate extern uint_t root_phys_addr_lo_mask;
487c478bd9Sstevel@tonic-gate extern int rootnex_name_child(dev_info_t *child, char *name, int namelen);
497c478bd9Sstevel@tonic-gate extern int rootnex_ctl_uninitchild(dev_info_t *dip);
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate uint_t root_phys_addr_hi_mask = 0xffffffff;
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate * config information
557c478bd9Sstevel@tonic-gate */
567c478bd9Sstevel@tonic-gate int
577c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
587c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp);
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate int
617c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
627c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp);
637c478bd9Sstevel@tonic-gate
64a195726fSgovinda int
657c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
667c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t rootnex_err_ibc;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * rootnex_add_intr_impl:
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate /*ARGSUSED*/
747c478bd9Sstevel@tonic-gate int
rootnex_add_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)757c478bd9Sstevel@tonic-gate rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip,
767c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp)
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate volatile uint64_t *intr_mapping_reg;
797c478bd9Sstevel@tonic-gate volatile uint64_t mondo_vector;
807c478bd9Sstevel@tonic-gate int32_t r_upaid = -1;
817c478bd9Sstevel@tonic-gate int32_t slave = 0;
82*1c0f05faSjasonwu int32_t portid;
837c478bd9Sstevel@tonic-gate int len, ret;
847c478bd9Sstevel@tonic-gate
85*1c0f05faSjasonwu if (((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
86*1c0f05faSjasonwu DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) ||
87*1c0f05faSjasonwu ((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
88*1c0f05faSjasonwu DDI_PROP_DONTPASS, "portid", -1)) != -1)) {
897c478bd9Sstevel@tonic-gate if (ddi_getprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
907c478bd9Sstevel@tonic-gate "upa-interrupt-slave", 0) != 0) {
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate /* Give slave devices pri of 5. e.g. fb's */
93a195726fSgovinda hdlp->ih_pri = 5;
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate * Translate the interrupt property by stuffing in the
98*1c0f05faSjasonwu * portid for those devices which have a portid.
997c478bd9Sstevel@tonic-gate */
100*1c0f05faSjasonwu hdlp->ih_vector |= (UPAID_TO_IGN(portid) << 6);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate /*
1047c478bd9Sstevel@tonic-gate * Hack to support the UPA slave devices before the 1275
1057c478bd9Sstevel@tonic-gate * support for imap was introduced.
1067c478bd9Sstevel@tonic-gate */
1077c478bd9Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, NULL, "interrupt-map",
1087c478bd9Sstevel@tonic-gate &len) != DDI_PROP_SUCCESS && ddi_getprop(DDI_DEV_T_ANY,
1097c478bd9Sstevel@tonic-gate rdip, DDI_PROP_DONTPASS, "upa-interrupt-slave", 0) != 0 &&
1107c478bd9Sstevel@tonic-gate ddi_get_parent(rdip) == dip) {
1117c478bd9Sstevel@tonic-gate slave = 1;
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate if ((r_upaid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1147c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) {
1157c478bd9Sstevel@tonic-gate extern uint64_t *get_intr_mapping_reg(int, int);
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate if ((intr_mapping_reg = get_intr_mapping_reg(
1187c478bd9Sstevel@tonic-gate r_upaid, 1)) == NULL)
1197c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1207c478bd9Sstevel@tonic-gate } else
1217c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate if ((ret = i_ddi_add_ivintr(hdlp)) != DDI_SUCCESS)
1257c478bd9Sstevel@tonic-gate return (ret);
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate /*
1287c478bd9Sstevel@tonic-gate * Hack to support the UPA slave devices before the 1275
1297c478bd9Sstevel@tonic-gate * support for imap was introduced.
1307c478bd9Sstevel@tonic-gate */
1317c478bd9Sstevel@tonic-gate if (slave) {
1327c478bd9Sstevel@tonic-gate /*
1337c478bd9Sstevel@tonic-gate * Program the interrupt mapping register.
1347c478bd9Sstevel@tonic-gate * Interrupts from the slave UPA devices are
1357c478bd9Sstevel@tonic-gate * directed at the boot CPU until it is known
1367c478bd9Sstevel@tonic-gate * that they can be safely redirected while
1377c478bd9Sstevel@tonic-gate * running under load.
1387c478bd9Sstevel@tonic-gate */
1397c478bd9Sstevel@tonic-gate mondo_vector = cpu0.cpu_id << IMR_TID_SHIFT;
140a195726fSgovinda mondo_vector |= (IMR_VALID | (uint64_t)hdlp->ih_vector);
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate /* Set the mapping register */
1437c478bd9Sstevel@tonic-gate *intr_mapping_reg = mondo_vector;
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate /* Flush write buffers */
1467c478bd9Sstevel@tonic-gate mondo_vector = *intr_mapping_reg;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate return (ret);
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate /*
1537c478bd9Sstevel@tonic-gate * rootnex_remove_intr_impl:
1547c478bd9Sstevel@tonic-gate */
1557c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1567c478bd9Sstevel@tonic-gate int
rootnex_remove_intr_impl(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)1577c478bd9Sstevel@tonic-gate rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip,
1587c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp)
1597c478bd9Sstevel@tonic-gate {
160*1c0f05faSjasonwu int32_t portid;
1617c478bd9Sstevel@tonic-gate int len;
1627c478bd9Sstevel@tonic-gate
163*1c0f05faSjasonwu if (((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
164*1c0f05faSjasonwu DDI_PROP_DONTPASS, "upa-portid", -1)) != -1) ||
165*1c0f05faSjasonwu ((portid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
166*1c0f05faSjasonwu DDI_PROP_DONTPASS, "portid", -1)) != -1)) {
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * Translate the interrupt property by stuffing in the
169*1c0f05faSjasonwu * portid for those devices which have a portid.
1707c478bd9Sstevel@tonic-gate */
171*1c0f05faSjasonwu hdlp->ih_vector |= (UPAID_TO_IGN(portid) << 6);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate * Hack to support the UPA slave devices before the 1275
1767c478bd9Sstevel@tonic-gate * support for imap was introduced.
1777c478bd9Sstevel@tonic-gate */
1787c478bd9Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, NULL, "interrupt-map",
1797c478bd9Sstevel@tonic-gate &len) != DDI_PROP_SUCCESS && ddi_getprop(DDI_DEV_T_ANY,
1807c478bd9Sstevel@tonic-gate rdip, DDI_PROP_DONTPASS, "upa-interrupt-slave", 0) != 0) {
1817c478bd9Sstevel@tonic-gate int32_t r_upaid = -1;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate if ((r_upaid = ddi_prop_get_int(DDI_DEV_T_ANY, rdip,
1847c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1)) != -1 &&
1857c478bd9Sstevel@tonic-gate ddi_get_parent(rdip) == dip) {
1867c478bd9Sstevel@tonic-gate volatile uint64_t *intr_mapping_reg;
1877c478bd9Sstevel@tonic-gate volatile uint64_t flush_data;
1887c478bd9Sstevel@tonic-gate extern uint64_t *get_intr_mapping_reg(int, int);
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate if ((intr_mapping_reg = get_intr_mapping_reg(
1917c478bd9Sstevel@tonic-gate r_upaid, 1)) == NULL)
1927c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate /* Clear the mapping register */
1957c478bd9Sstevel@tonic-gate *intr_mapping_reg = 0x0ull;
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate /* Flush write buffers */
1987c478bd9Sstevel@tonic-gate flush_data = *intr_mapping_reg;
1997c478bd9Sstevel@tonic-gate #ifdef lint
2007c478bd9Sstevel@tonic-gate flush_data = flush_data;
2017c478bd9Sstevel@tonic-gate #endif /* lint */
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate }
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate i_ddi_rem_ivintr(hdlp);
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate * rootnex_get_intr_pri:
2127c478bd9Sstevel@tonic-gate */
2137c478bd9Sstevel@tonic-gate /*ARGSUSED*/
214a195726fSgovinda int
rootnex_get_intr_pri(dev_info_t * dip,dev_info_t * rdip,ddi_intr_handle_impl_t * hdlp)2157c478bd9Sstevel@tonic-gate rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip,
2167c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp)
2177c478bd9Sstevel@tonic-gate {
218a195726fSgovinda int pri = hdlp->ih_pri;
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
2217c478bd9Sstevel@tonic-gate "upa-portid", -1) != -1) {
2227c478bd9Sstevel@tonic-gate if (ddi_getprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
2237c478bd9Sstevel@tonic-gate "upa-interrupt-slave", 0) != 0) {
2247c478bd9Sstevel@tonic-gate
2257c478bd9Sstevel@tonic-gate /* Give slave devices pri of 5. e.g. fb's */
226a195726fSgovinda pri = 5;
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate }
229a195726fSgovinda
230a195726fSgovinda return (pri);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
2337c478bd9Sstevel@tonic-gate int
rootnex_ctl_reportdev_impl(dev_info_t * dev)2347c478bd9Sstevel@tonic-gate rootnex_ctl_reportdev_impl(dev_info_t *dev)
2357c478bd9Sstevel@tonic-gate {
2367c478bd9Sstevel@tonic-gate struct regspec *rp;
2377c478bd9Sstevel@tonic-gate char buf[80];
2387c478bd9Sstevel@tonic-gate char *p = buf;
2397c478bd9Sstevel@tonic-gate register int n;
2407c478bd9Sstevel@tonic-gate int portid;
2417c478bd9Sstevel@tonic-gate int nodeid;
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate (void) sprintf(p, "%s%d at root", ddi_driver_name(dev),
2447c478bd9Sstevel@tonic-gate ddi_get_instance(dev));
2457c478bd9Sstevel@tonic-gate p += strlen(p);
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if ((n = sparc_pd_getnreg(dev)) > 0) {
2487c478bd9Sstevel@tonic-gate rp = sparc_pd_getreg(dev, 0);
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate (void) strcpy(p, ": ");
2517c478bd9Sstevel@tonic-gate p += strlen(p);
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate /*
2547c478bd9Sstevel@tonic-gate * This stuff needs to be fixed correctly for the FFB
2557c478bd9Sstevel@tonic-gate * devices and the UPA add-on devices.
2567c478bd9Sstevel@tonic-gate */
2577c478bd9Sstevel@tonic-gate portid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2587c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1);
2597c478bd9Sstevel@tonic-gate if (portid != -1)
2607c478bd9Sstevel@tonic-gate (void) sprintf(p, "UPA 0x%x 0x%x%s",
2617c478bd9Sstevel@tonic-gate portid,
2627c478bd9Sstevel@tonic-gate rp->regspec_addr, (n > 1 ? "" : " ..."));
2637c478bd9Sstevel@tonic-gate else {
2647c478bd9Sstevel@tonic-gate portid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2657c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "portid", -1);
2667c478bd9Sstevel@tonic-gate nodeid = ddi_prop_get_int(DDI_DEV_T_ANY, dev,
2677c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "nodeid", -1);
2687c478bd9Sstevel@tonic-gate if (portid == -1 && nodeid == -1)
2697c478bd9Sstevel@tonic-gate printf("could not find portid "
2707c478bd9Sstevel@tonic-gate "or nodeid property in %s\n",
2717c478bd9Sstevel@tonic-gate DEVI(dev)->devi_node_name);
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate if (portid != -1)
2747c478bd9Sstevel@tonic-gate (void) sprintf(p, "SAFARI 0x%x 0x%x%s",
2757c478bd9Sstevel@tonic-gate portid,
2767c478bd9Sstevel@tonic-gate rp->regspec_addr &
2777c478bd9Sstevel@tonic-gate root_phys_addr_lo_mask,
2787c478bd9Sstevel@tonic-gate (n > 1 ? "" : " ..."));
2797c478bd9Sstevel@tonic-gate if (nodeid != -1)
2807c478bd9Sstevel@tonic-gate (void) sprintf(p, "SSM Node %d", nodeid);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate p += strlen(p);
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate * This is where we need to print out the interrupt specifications
2877c478bd9Sstevel@tonic-gate * for the FFB device and any UPA add-on devices. Not sure how to
2887c478bd9Sstevel@tonic-gate * do this yet?
2897c478bd9Sstevel@tonic-gate */
2907c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?%s\n", buf);
2917c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate int
rootnex_name_child_impl(dev_info_t * child,char * name,int namelen)2957c478bd9Sstevel@tonic-gate rootnex_name_child_impl(dev_info_t *child, char *name, int namelen)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pdptr;
2987c478bd9Sstevel@tonic-gate int portid, nodeid;
2997c478bd9Sstevel@tonic-gate char *node_name;
3007c478bd9Sstevel@tonic-gate struct regspec *rp;
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate extern uint_t root_phys_addr_lo_mask;
3037c478bd9Sstevel@tonic-gate extern void make_ddi_ppd(
3047c478bd9Sstevel@tonic-gate dev_info_t *, struct ddi_parent_private_data **);
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate * Fill in parent-private data and this function returns to us
3087c478bd9Sstevel@tonic-gate * an indication if it used "registers" to fill in the data.
3097c478bd9Sstevel@tonic-gate */
3107c478bd9Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) {
3117c478bd9Sstevel@tonic-gate make_ddi_ppd(child, &pdptr);
3127c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, pdptr);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate * No reg property, return null string as address (e.g. pseudo)
3177c478bd9Sstevel@tonic-gate */
3187c478bd9Sstevel@tonic-gate name[0] = '\0';
3197c478bd9Sstevel@tonic-gate if (sparc_pd_getnreg(child) == 0) {
3207c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
3217c478bd9Sstevel@tonic-gate }
3227c478bd9Sstevel@tonic-gate rp = sparc_pd_getreg(child, 0);
3237c478bd9Sstevel@tonic-gate ASSERT(rp != NULL);
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate /*
3267c478bd9Sstevel@tonic-gate * Create portid property for fhc node under root(/fhc).
3277c478bd9Sstevel@tonic-gate */
3287c478bd9Sstevel@tonic-gate node_name = ddi_node_name(child);
3297c478bd9Sstevel@tonic-gate if ((strcmp(node_name, "fhc") == 0) ||
3307c478bd9Sstevel@tonic-gate (strcmp(node_name, "mem-unit") == 0) ||
3317c478bd9Sstevel@tonic-gate (strcmp(node_name, "central") == 0)) {
3327c478bd9Sstevel@tonic-gate #ifdef _STARFIRE
3337c478bd9Sstevel@tonic-gate portid = ((((rp->regspec_bustype) & 0x6) >> 1) |
3347c478bd9Sstevel@tonic-gate (((rp->regspec_bustype) & 0xF0) >> 2) |
3357c478bd9Sstevel@tonic-gate (((rp->regspec_bustype) & 0x8) << 3));
3367c478bd9Sstevel@tonic-gate #else
3377c478bd9Sstevel@tonic-gate portid = (rp->regspec_bustype >> 1) & 0x1f;
3387c478bd9Sstevel@tonic-gate #endif
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate * The port-id must go on the hardware property list,
3427c478bd9Sstevel@tonic-gate * otherwise, initchild may fail.
3437c478bd9Sstevel@tonic-gate */
3447c478bd9Sstevel@tonic-gate if (ndi_prop_update_int(DDI_DEV_T_NONE, child, "upa-portid",
3457c478bd9Sstevel@tonic-gate portid) != DDI_SUCCESS)
3467c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
3477c478bd9Sstevel@tonic-gate "Error in creating upa-portid property for fhc.\n");
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate * Name node on behalf of child nexus.
3527c478bd9Sstevel@tonic-gate */
3537c478bd9Sstevel@tonic-gate if (ddi_get_parent(child) != ddi_root_node()) {
3547c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x",
3557c478bd9Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr);
3567c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate * On sun4u, the 'name' of children of the root node
3617c478bd9Sstevel@tonic-gate * is foo@<upa-mid>,<offset>, which is derived from,
3627c478bd9Sstevel@tonic-gate * but not identical to the physical address.
3637c478bd9Sstevel@tonic-gate */
3647c478bd9Sstevel@tonic-gate portid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3657c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "upa-portid", -1);
3667c478bd9Sstevel@tonic-gate if (portid == -1)
3677c478bd9Sstevel@tonic-gate portid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3687c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "portid", -1);
3697c478bd9Sstevel@tonic-gate nodeid = ddi_prop_get_int(DDI_DEV_T_ANY, child,
3707c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "nodeid", -1);
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate /*
3737c478bd9Sstevel@tonic-gate * Do not log message, to handle cases where OBP version
3747c478bd9Sstevel@tonic-gate * does not have "portid" property for the root i2c node.
3757c478bd9Sstevel@tonic-gate *
3767c478bd9Sstevel@tonic-gate * Platforms supporting root i2c node (potentially without
3777c478bd9Sstevel@tonic-gate * "portid" property) are :
3787c478bd9Sstevel@tonic-gate * SunBlade 1500, SunBlade 2500, V240, V250
3797c478bd9Sstevel@tonic-gate */
3807c478bd9Sstevel@tonic-gate if (portid == -1 && nodeid == -1 &&
3817c478bd9Sstevel@tonic-gate strncmp(node_name, "i2c", strlen("i2c")) != 0)
3827c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
3837c478bd9Sstevel@tonic-gate "could not find portid or nodeid property in %s\n",
3847c478bd9Sstevel@tonic-gate DEVI(child)->devi_node_name);
3857c478bd9Sstevel@tonic-gate if (nodeid != -1)
3867c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,0", nodeid);
3877c478bd9Sstevel@tonic-gate else
3887c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", portid,
3897c478bd9Sstevel@tonic-gate rp->regspec_addr & root_phys_addr_lo_mask);
3907c478bd9Sstevel@tonic-gate
3917c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate int
rootnex_ctl_initchild_impl(dev_info_t * dip)3957c478bd9Sstevel@tonic-gate rootnex_ctl_initchild_impl(dev_info_t *dip)
3967c478bd9Sstevel@tonic-gate {
3977c478bd9Sstevel@tonic-gate struct regspec *rp;
3987c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pd;
3997c478bd9Sstevel@tonic-gate char name[MAXNAMELEN];
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate extern struct ddi_parent_private_data *init_regspec_64(dev_info_t *dip);
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate /* Name the child */
4047c478bd9Sstevel@tonic-gate (void) rootnex_name_child(dip, name, MAXNAMELEN);
4057c478bd9Sstevel@tonic-gate ddi_set_name_addr(dip, name);
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate * Try to merge .conf node. If merge is successful, return
4097c478bd9Sstevel@tonic-gate * DDI_FAILURE to allow caller to remove this node.
4107c478bd9Sstevel@tonic-gate */
4117c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(dip) == 0 &&
4127c478bd9Sstevel@tonic-gate (ndi_merge_node(dip, rootnex_name_child) == DDI_SUCCESS)) {
4137c478bd9Sstevel@tonic-gate (void) rootnex_ctl_uninitchild(dip);
4147c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate * If there are no "reg"s in the child node, return.
4197c478bd9Sstevel@tonic-gate */
4207c478bd9Sstevel@tonic-gate pd = init_regspec_64(dip);
4217c478bd9Sstevel@tonic-gate if ((pd == NULL) || (pd->par_nreg == 0))
4227c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate /*
4257c478bd9Sstevel@tonic-gate * If this is a slave device sitting on the UPA, we assume that
4267c478bd9Sstevel@tonic-gate * This device can accept DMA accesses from other devices. We need
4277c478bd9Sstevel@tonic-gate * to register this fact with the system by using the highest
4287c478bd9Sstevel@tonic-gate * and lowest physical pfns of the devices register space. This
4297c478bd9Sstevel@tonic-gate * will then represent a physical block of addresses that are valid
4307c478bd9Sstevel@tonic-gate * for DMA accesses.
4317c478bd9Sstevel@tonic-gate */
4327c478bd9Sstevel@tonic-gate if ((ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "upa-portid",
4337c478bd9Sstevel@tonic-gate -1) != -1) && ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
4347c478bd9Sstevel@tonic-gate "upa-interrupt-slave", 0)) {
4357c478bd9Sstevel@tonic-gate pfn_t lopfn = (pfn_t)-1;
4367c478bd9Sstevel@tonic-gate pfn_t hipfn = 0;
4377c478bd9Sstevel@tonic-gate int i;
4387c478bd9Sstevel@tonic-gate extern void pf_set_dmacapable(pfn_t, pfn_t);
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate /* Scan the devices highest and lowest physical pfns */
4417c478bd9Sstevel@tonic-gate for (i = 0, rp = pd->par_reg; i < pd->par_nreg; i++, rp++) {
4427c478bd9Sstevel@tonic-gate uint64_t addr;
4437c478bd9Sstevel@tonic-gate pfn_t tmphipfn, tmplopfn;
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate addr = (unsigned long long)((unsigned long long)
4467c478bd9Sstevel@tonic-gate rp->regspec_bustype << 32);
4477c478bd9Sstevel@tonic-gate addr |= (uint64_t)rp->regspec_addr;
4487c478bd9Sstevel@tonic-gate tmplopfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4497c478bd9Sstevel@tonic-gate addr += (uint64_t)(rp->regspec_size - 1);
4507c478bd9Sstevel@tonic-gate tmphipfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate hipfn = (tmphipfn > hipfn) ? tmphipfn : hipfn;
4537c478bd9Sstevel@tonic-gate lopfn = (tmplopfn < lopfn) ? tmplopfn : lopfn;
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate pf_set_dmacapable(hipfn, lopfn);
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate
4587c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate void
rootnex_ctl_uninitchild_impl(dev_info_t * dip)4627c478bd9Sstevel@tonic-gate rootnex_ctl_uninitchild_impl(dev_info_t *dip)
4637c478bd9Sstevel@tonic-gate {
4647c478bd9Sstevel@tonic-gate if ((ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "upa-portid",
4657c478bd9Sstevel@tonic-gate -1) != -1) && (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
4667c478bd9Sstevel@tonic-gate "upa-interrupt-slave", 0))) {
4677c478bd9Sstevel@tonic-gate struct regspec *rp;
4687c478bd9Sstevel@tonic-gate extern void pf_unset_dmacapable(pfn_t);
4697c478bd9Sstevel@tonic-gate unsigned long long addr;
4707c478bd9Sstevel@tonic-gate pfn_t pfn;
4717c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pd;
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate pd = ddi_get_parent_data(dip);
4747c478bd9Sstevel@tonic-gate ASSERT(pd != NULL);
4757c478bd9Sstevel@tonic-gate rp = pd->par_reg;
4767c478bd9Sstevel@tonic-gate addr = (unsigned long long) ((unsigned long long)
4777c478bd9Sstevel@tonic-gate rp->regspec_bustype << 32);
4787c478bd9Sstevel@tonic-gate addr |= (unsigned long long) rp->regspec_addr;
4797c478bd9Sstevel@tonic-gate pfn = (pfn_t)(addr >> MMU_PAGESHIFT);
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate pf_unset_dmacapable(pfn);
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate }
484