xref: /titanic_52/usr/src/cmd/prtconf/prt_xxx.c (revision 524b24f94a6680415290a5258702097dbedb7ecd)
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
5f6c0ee12Sgovinda  * Common Development and Distribution License (the "License").
6f6c0ee12Sgovinda  * 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*524b24f9SJudy Chen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <stddef.h>
287c478bd9Sstevel@tonic-gate #include <fcntl.h>
297c478bd9Sstevel@tonic-gate #include <string.h>
307c478bd9Sstevel@tonic-gate #include <libdevinfo.h>
317c478bd9Sstevel@tonic-gate #include <sys/pctypes.h>
327c478bd9Sstevel@tonic-gate #include <sys/pcmcia.h>
337c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
347c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include "prtconf.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate struct priv_data {
397c478bd9Sstevel@tonic-gate 	char *drv_name;		/* parent name */
407c478bd9Sstevel@tonic-gate 	void (*pd_print)(uintptr_t, int);	/* print function */
417c478bd9Sstevel@tonic-gate };
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate extern void indent_to_level();
447c478bd9Sstevel@tonic-gate static void obio_printregs(struct regspec *, int);
457c478bd9Sstevel@tonic-gate static void obio_printranges(struct rangespec *, int);
467c478bd9Sstevel@tonic-gate static void obio_printintr(struct intrspec *, int);
477c478bd9Sstevel@tonic-gate static void obio_print(uintptr_t, int);
487c478bd9Sstevel@tonic-gate static void pcmcia_printregs(struct pcm_regs *, int);
497c478bd9Sstevel@tonic-gate static void pcmcia_printintr(struct intrspec *, int);
507c478bd9Sstevel@tonic-gate static void pcmcia_print(uintptr_t, int);
517c478bd9Sstevel@tonic-gate static void sbus_print(uintptr_t, int);
527c478bd9Sstevel@tonic-gate static struct priv_data *match_priv_data(di_node_t);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate  * This is a hardcoded list of drivers we print parent private
567c478bd9Sstevel@tonic-gate  * data as of Solaris 7.
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate static struct di_priv_format ppd_format[] = {
597c478bd9Sstevel@tonic-gate 	{
607c478bd9Sstevel@tonic-gate 		/*
617c478bd9Sstevel@tonic-gate 		 * obio format: applies the following list
627c478bd9Sstevel@tonic-gate 		 * of nexus drivers. Note that obio driver
637c478bd9Sstevel@tonic-gate 		 * went away with sun4m.
647c478bd9Sstevel@tonic-gate 		 */
65f6c0ee12Sgovinda #ifdef	__sparc
66f6c0ee12Sgovinda 		"central dma ebus fhc isa pci rootnex",
67f6c0ee12Sgovinda #else
681ac69ea6Scth 		"central dma ebus fhc isa pci pci_pci rootnex",
69f6c0ee12Sgovinda #endif	/* __sparc */
707c478bd9Sstevel@tonic-gate 		sizeof (struct ddi_parent_private_data),
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 		sizeof (struct regspec),		/* first pointer */
737c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_reg),
747c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nreg),
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 		sizeof (struct intrspec),		/* second pointer */
777c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_intr),
787c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nintr),
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 		sizeof (struct rangespec),		/* third pointer */
817c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_rng),
827c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nrng),
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 		0, 0, 0,	/* no more pointers */
857c478bd9Sstevel@tonic-gate 		0, 0, 0
867c478bd9Sstevel@tonic-gate 	},
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	{	/* pcmcia format */
897c478bd9Sstevel@tonic-gate 		"pcic stp4020",
907c478bd9Sstevel@tonic-gate 		sizeof (struct pcmcia_parent_private),
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 		sizeof (struct pcm_regs),		/* first pointer */
937c478bd9Sstevel@tonic-gate 		offsetof(struct pcmcia_parent_private, ppd_reg),
947c478bd9Sstevel@tonic-gate 		offsetof(struct pcmcia_parent_private, ppd_nreg),
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 		sizeof (struct intrspec),		/* second pointer */
977c478bd9Sstevel@tonic-gate 		offsetof(struct pcmcia_parent_private, ppd_intrspec),
987c478bd9Sstevel@tonic-gate 		offsetof(struct pcmcia_parent_private, ppd_intr),
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		0, 0, 0,	/* no more pointers */
1017c478bd9Sstevel@tonic-gate 		0, 0, 0,
1027c478bd9Sstevel@tonic-gate 		0, 0, 0
1037c478bd9Sstevel@tonic-gate 	},
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	{	/* sbus format--it's different on sun4u!! */
1067c478bd9Sstevel@tonic-gate 		"sbus",
1077c478bd9Sstevel@tonic-gate 		sizeof (struct ddi_parent_private_data),
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 		sizeof (struct regspec),		/* first pointer */
1107c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_reg),
1117c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nreg),
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 		sizeof (struct intrspec),		/* second pointer */
1147c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_intr),
1157c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nintr),
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 		sizeof (struct rangespec),		/* third pointer */
1187c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_rng),
1197c478bd9Sstevel@tonic-gate 		offsetof(struct ddi_parent_private_data, par_nrng),
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 		0, 0, 0,	/* no more pointers */
1227c478bd9Sstevel@tonic-gate 		0, 0, 0
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate static struct priv_data prt_priv_data[] = {
1277c478bd9Sstevel@tonic-gate 	{ ppd_format[0].drv_name, obio_print},
1287c478bd9Sstevel@tonic-gate 	{ ppd_format[1].drv_name, pcmcia_print},
1297c478bd9Sstevel@tonic-gate 	{ ppd_format[2].drv_name, sbus_print}
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate static int nprt_priv_data = sizeof (prt_priv_data)/sizeof (struct priv_data);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate void
1357c478bd9Sstevel@tonic-gate init_priv_data(struct di_priv_data *fetch)
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate 	/* no driver private data */
1387c478bd9Sstevel@tonic-gate 	fetch->version = DI_PRIVDATA_VERSION_0;
1397c478bd9Sstevel@tonic-gate 	fetch->n_driver = 0;
1407c478bd9Sstevel@tonic-gate 	fetch->driver = NULL;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	fetch->n_parent = nprt_priv_data;
1437c478bd9Sstevel@tonic-gate 	fetch->parent = ppd_format;
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate static void
1477c478bd9Sstevel@tonic-gate obio_printregs(struct regspec *rp, int ilev)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate 	indent_to_level(ilev);
1507c478bd9Sstevel@tonic-gate 	(void) printf("    Bus Type=0x%x, Address=0x%x, Size=0x%x\n",
1517c478bd9Sstevel@tonic-gate 	    rp->regspec_bustype, rp->regspec_addr, rp->regspec_size);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate static void
1557c478bd9Sstevel@tonic-gate obio_printranges(struct rangespec *rp, int ilev)
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate 	indent_to_level(ilev);
1587c478bd9Sstevel@tonic-gate 	(void) printf("    Ch: %.2x,%.8x Pa: %.2x,%.8x, Sz: %x\n",
1597c478bd9Sstevel@tonic-gate 	    rp->rng_cbustype, rp->rng_coffset,
1607c478bd9Sstevel@tonic-gate 	    rp->rng_bustype, rp->rng_offset,
1617c478bd9Sstevel@tonic-gate 	    rp->rng_size);
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate static void
1657c478bd9Sstevel@tonic-gate obio_printintr(struct intrspec *ip, int ilev)
1667c478bd9Sstevel@tonic-gate {
1677c478bd9Sstevel@tonic-gate 	indent_to_level(ilev);
1687c478bd9Sstevel@tonic-gate 	(void) printf("    Interrupt Priority=0x%x (ipl %d)",
1697c478bd9Sstevel@tonic-gate 	    ip->intrspec_pri, INT_IPL(ip->intrspec_pri));
1707c478bd9Sstevel@tonic-gate 	if (ip->intrspec_vec)
1717c478bd9Sstevel@tonic-gate 		(void) printf(", vector=0x%x (%d)",
1727c478bd9Sstevel@tonic-gate 		    ip->intrspec_vec, ip->intrspec_vec);
1737c478bd9Sstevel@tonic-gate 	(void) printf("\n");
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate static void
1777c478bd9Sstevel@tonic-gate obio_print(uintptr_t data, int ilev)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate 	int i, nreg, nrng, nintr;
1807c478bd9Sstevel@tonic-gate 	struct ddi_parent_private_data *dp;
1817c478bd9Sstevel@tonic-gate 	struct regspec *reg;
1827c478bd9Sstevel@tonic-gate 	struct intrspec *intr;
1837c478bd9Sstevel@tonic-gate 	struct rangespec *rng;
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	dp = (struct ddi_parent_private_data *)data;
1867c478bd9Sstevel@tonic-gate #ifdef DEBUG
1877c478bd9Sstevel@tonic-gate 	dprintf("obio parent private data: nreg = 0x%x offset = 0x%x"
1887c478bd9Sstevel@tonic-gate 	    " nintr = 0x%x offset = 0x%x nrng = 0x%x offset = %x\n",
1897c478bd9Sstevel@tonic-gate 	    dp->par_nreg, *((di_off_t *)(&dp->par_reg)),
1907c478bd9Sstevel@tonic-gate 	    dp->par_nintr, *((di_off_t *)(&dp->par_intr)),
1917c478bd9Sstevel@tonic-gate 	    dp->par_nrng, *((di_off_t *)(&dp->par_rng)));
1927c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1937c478bd9Sstevel@tonic-gate 	nreg = dp->par_nreg;
1947c478bd9Sstevel@tonic-gate 	nintr = dp->par_nintr;
1957c478bd9Sstevel@tonic-gate 	nrng = dp->par_nrng;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/*
1987c478bd9Sstevel@tonic-gate 	 * All pointers are translated to di_off_t by the devinfo driver.
1997c478bd9Sstevel@tonic-gate 	 * This is a private agreement between libdevinfo and prtconf.
2007c478bd9Sstevel@tonic-gate 	 */
2017c478bd9Sstevel@tonic-gate 	if (nreg != 0) {
2027c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
2037c478bd9Sstevel@tonic-gate 		(void) printf("Register Specifications:\n");
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 		reg = (struct regspec *)(data + *(di_off_t *)(&dp->par_reg));
2067c478bd9Sstevel@tonic-gate 		for (i = 0; i < nreg; ++i)
2077c478bd9Sstevel@tonic-gate 			obio_printregs(reg + i, ilev);
2087c478bd9Sstevel@tonic-gate 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	if (nrng != 0) {
2117c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
2127c478bd9Sstevel@tonic-gate 		(void) printf("Range Specifications:\n");
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 		rng = (struct rangespec *)(data + *(di_off_t *)(&dp->par_rng));
2157c478bd9Sstevel@tonic-gate 		for (i = 0; i < nrng; ++i)
2167c478bd9Sstevel@tonic-gate 			obio_printranges(rng + i, ilev);
2177c478bd9Sstevel@tonic-gate 	}
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	if (nintr != 0) {
2207c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
2217c478bd9Sstevel@tonic-gate 		(void) printf("Interrupt Specifications:\n");
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 		intr = (struct intrspec *)(data + *(di_off_t *)(&dp->par_intr));
2247c478bd9Sstevel@tonic-gate 		for (i = 0; i < nintr; ++i)
2257c478bd9Sstevel@tonic-gate 			obio_printintr(intr + i, ilev);
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate static void
2307c478bd9Sstevel@tonic-gate pcmcia_printregs(struct pcm_regs *rp, int ilev)
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	indent_to_level(ilev);
2337c478bd9Sstevel@tonic-gate 	(void) printf("    Phys hi=0x%x, Phys lo=0x%x, Phys len=%x\n",
2347c478bd9Sstevel@tonic-gate 	    rp->phys_hi, rp->phys_lo, rp->phys_len);
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate static void
2387c478bd9Sstevel@tonic-gate pcmcia_printintr(struct intrspec *ip, int ilev)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate 	obio_printintr(ip, ilev);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate static void
2447c478bd9Sstevel@tonic-gate pcmcia_print(uintptr_t data, int ilev)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate 	int i, nreg, nintr;
2477c478bd9Sstevel@tonic-gate 	struct pcmcia_parent_private *dp;
2487c478bd9Sstevel@tonic-gate 	struct pcm_regs *reg;
2497c478bd9Sstevel@tonic-gate 	struct intrspec *intr;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	dp = (struct pcmcia_parent_private *)data;
2527c478bd9Sstevel@tonic-gate #ifdef DEBUG
2537c478bd9Sstevel@tonic-gate 	dprintf("pcmcia parent private data: nreg = 0x%x offset = 0x%x"
2547c478bd9Sstevel@tonic-gate 	    " intr = 0x%x offset = %x\n",
2557c478bd9Sstevel@tonic-gate 	    dp->ppd_nreg, *(di_off_t *)(&dp->ppd_reg),
2567c478bd9Sstevel@tonic-gate 	    dp->ppd_intr, *(di_off_t *)(&dp->ppd_intrspec));
2577c478bd9Sstevel@tonic-gate #endif /* DEBUG */
2587c478bd9Sstevel@tonic-gate 	nreg = dp->ppd_nreg;
2597c478bd9Sstevel@tonic-gate 	nintr = dp->ppd_intr;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/*
2627c478bd9Sstevel@tonic-gate 	 * All pointers are translated to di_off_t by the devinfo driver.
2637c478bd9Sstevel@tonic-gate 	 * This is a private agreement between libdevinfo and prtconf.
2647c478bd9Sstevel@tonic-gate 	 */
2657c478bd9Sstevel@tonic-gate 	if (nreg != 0)  {
2667c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
2677c478bd9Sstevel@tonic-gate 		(void) printf("Register Specifications:\n");
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 		reg = (struct pcm_regs *)(data + *(di_off_t *)(&dp->ppd_reg));
2707c478bd9Sstevel@tonic-gate 		for (i = 0; i < nreg; ++i)
2717c478bd9Sstevel@tonic-gate 			pcmcia_printregs(reg + i, ilev);
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	if (nintr != 0)  {
2757c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
2767c478bd9Sstevel@tonic-gate 		(void) printf("Interrupt Specifications:\n");
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 		intr = (struct intrspec *)
2797c478bd9Sstevel@tonic-gate 		    (data + *(di_off_t *)(&dp->ppd_intrspec));
2807c478bd9Sstevel@tonic-gate 		for (i = 0; i < nintr; ++i)
2817c478bd9Sstevel@tonic-gate 			pcmcia_printintr(intr + i, ilev);
2827c478bd9Sstevel@tonic-gate 	}
2837c478bd9Sstevel@tonic-gate }
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate static void
2867c478bd9Sstevel@tonic-gate sbus_print(uintptr_t data, int ilev)
2877c478bd9Sstevel@tonic-gate {
2887c478bd9Sstevel@tonic-gate 	int i, nreg, nrng, nintr;
2897c478bd9Sstevel@tonic-gate 	struct ddi_parent_private_data *dp;
2907c478bd9Sstevel@tonic-gate 	struct regspec *reg;
2917c478bd9Sstevel@tonic-gate 	struct intrspec *intr;
2927c478bd9Sstevel@tonic-gate 	struct rangespec *rng;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	dp = (struct ddi_parent_private_data *)data;
2957c478bd9Sstevel@tonic-gate #ifdef DEBUG
2967c478bd9Sstevel@tonic-gate 	dprintf("sbus parent private data: nreg = 0x%x offset = 0x%x"
2977c478bd9Sstevel@tonic-gate 	    " nintr = 0x%x offset = 0x%x nrng = 0x%x offset = %x\n",
2987c478bd9Sstevel@tonic-gate 	    dp->par_nreg, *((di_off_t *)(&dp->par_reg)),
2997c478bd9Sstevel@tonic-gate 	    dp->par_nintr, *((di_off_t *)(&dp->par_intr)),
3007c478bd9Sstevel@tonic-gate 	    dp->par_nrng, *((di_off_t *)(&dp->par_rng)));
3017c478bd9Sstevel@tonic-gate #endif /* DEBUG */
3027c478bd9Sstevel@tonic-gate 	nreg = dp->par_nreg;
3037c478bd9Sstevel@tonic-gate 	nintr = dp->par_nintr;
3047c478bd9Sstevel@tonic-gate 	nrng = dp->par_nrng;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	/*
3077c478bd9Sstevel@tonic-gate 	 * All pointers are translated to di_off_t by the devinfo driver.
3087c478bd9Sstevel@tonic-gate 	 * This is a private agreement between libdevinfo and prtconf.
3097c478bd9Sstevel@tonic-gate 	 */
3107c478bd9Sstevel@tonic-gate 	if (nreg != 0) {
3117c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
3127c478bd9Sstevel@tonic-gate 		(void) printf("Register Specifications:\n");
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 		reg = (struct regspec *)(data + *(di_off_t *)(&dp->par_reg));
3157c478bd9Sstevel@tonic-gate 		for (i = 0; i < nreg; ++i)
3167c478bd9Sstevel@tonic-gate 			obio_printregs(reg + i, ilev);
3177c478bd9Sstevel@tonic-gate 	}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	if (nrng != 0) {
3217c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
3227c478bd9Sstevel@tonic-gate 		(void) printf("Range Specifications:\n");
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 		rng = (struct rangespec *)(data + *(di_off_t *)(&dp->par_rng));
3257c478bd9Sstevel@tonic-gate 		for (i = 0; i < nrng; ++i)
3267c478bd9Sstevel@tonic-gate 			obio_printranges(rng + i, ilev);
3277c478bd9Sstevel@tonic-gate 	}
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	/*
3307c478bd9Sstevel@tonic-gate 	 * To print interrupt property for children of sbus on sun4u requires
3317c478bd9Sstevel@tonic-gate 	 * definitions in sysiosbus.h.
3327c478bd9Sstevel@tonic-gate 	 *
3337c478bd9Sstevel@tonic-gate 	 * We can't #include <sys/sysiosbus.h> to have the build work on
3347c478bd9Sstevel@tonic-gate 	 * non sun4u machines. It's not right either to
3357c478bd9Sstevel@tonic-gate 	 *	#include "../../uts/sun4u/sys/sysiosbus.h"
3367c478bd9Sstevel@tonic-gate 	 * As a result, we will not print the information.
3377c478bd9Sstevel@tonic-gate 	 */
3387c478bd9Sstevel@tonic-gate 	if ((nintr != 0) && (strcmp(opts.o_uts.machine, "sun4u") != 0)) {
3397c478bd9Sstevel@tonic-gate 		indent_to_level(ilev);
3407c478bd9Sstevel@tonic-gate 		(void) printf("Interrupt Specifications:\n");
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 		for (i = 0; i < nintr; ++i) {
3437c478bd9Sstevel@tonic-gate 			intr = (struct intrspec *)
3447c478bd9Sstevel@tonic-gate 			    (data + *(di_off_t *)(&dp->par_intr));
3457c478bd9Sstevel@tonic-gate 			obio_printintr(intr + i, ilev);
3467c478bd9Sstevel@tonic-gate 		}
3477c478bd9Sstevel@tonic-gate 	}
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate static struct priv_data *
3517c478bd9Sstevel@tonic-gate match_priv_data(di_node_t node)
3527c478bd9Sstevel@tonic-gate {
3537c478bd9Sstevel@tonic-gate 	int i;
3547c478bd9Sstevel@tonic-gate 	size_t len;
3557c478bd9Sstevel@tonic-gate 	char *drv_name, *tmp;
3567c478bd9Sstevel@tonic-gate 	di_node_t parent;
3577c478bd9Sstevel@tonic-gate 	struct priv_data *pdp;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	if ((parent = di_parent_node(node)) == DI_NODE_NIL)
3607c478bd9Sstevel@tonic-gate 		return (NULL);
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 	if ((drv_name = di_driver_name(parent)) == NULL)
3637c478bd9Sstevel@tonic-gate 		return (NULL);
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	pdp = prt_priv_data;
3667c478bd9Sstevel@tonic-gate 	len = strlen(drv_name);
3677c478bd9Sstevel@tonic-gate 	for (i = 0; i < nprt_priv_data; ++i, ++pdp) {
3687c478bd9Sstevel@tonic-gate 		tmp = pdp->drv_name;
3697c478bd9Sstevel@tonic-gate 		while (tmp && (*tmp != '\0')) {
3707c478bd9Sstevel@tonic-gate 			if (strncmp(tmp, drv_name, len) == 0) {
3717c478bd9Sstevel@tonic-gate #ifdef	DEBUG
3727c478bd9Sstevel@tonic-gate 				dprintf("matched parent private data"
3737c478bd9Sstevel@tonic-gate 				    " at Node <%s> parent driver <%s>\n",
3747c478bd9Sstevel@tonic-gate 				    di_node_name(node), drv_name);
3757c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
3767c478bd9Sstevel@tonic-gate 				return (pdp);
3777c478bd9Sstevel@tonic-gate 			}
3787c478bd9Sstevel@tonic-gate 			/*
3797c478bd9Sstevel@tonic-gate 			 * skip a white space
3807c478bd9Sstevel@tonic-gate 			 */
3817c478bd9Sstevel@tonic-gate 			if (tmp = strchr(tmp, ' '))
3827c478bd9Sstevel@tonic-gate 				tmp++;
3837c478bd9Sstevel@tonic-gate 		}
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	return (NULL);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate void
3907c478bd9Sstevel@tonic-gate dump_priv_data(int ilev, di_node_t node)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	uintptr_t priv;
3937c478bd9Sstevel@tonic-gate 	struct priv_data *pdp;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	if ((priv = (uintptr_t)di_parent_private_data(node)) == NULL)
3967c478bd9Sstevel@tonic-gate 		return;
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	if ((pdp = match_priv_data(node)) == NULL) {
3997c478bd9Sstevel@tonic-gate #ifdef DEBUG
4007c478bd9Sstevel@tonic-gate 		dprintf("Error: parent private data format unknown\n");
4017c478bd9Sstevel@tonic-gate #endif /* DEBUG */
4027c478bd9Sstevel@tonic-gate 		return;
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	pdp->pd_print(priv, ilev);
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	/* ignore driver private data for now */
4087c478bd9Sstevel@tonic-gate }
409*524b24f9SJudy Chen 
410*524b24f9SJudy Chen #define	LOOKUP_PROP(proptype, ph, nodetype, dev, node, name, data)	\
411*524b24f9SJudy Chen 	((nodetype == DI_PROM_NODEID) ?					\
412*524b24f9SJudy Chen 	di_prom_prop_lookup_##proptype(ph, node, name, data) :		\
413*524b24f9SJudy Chen 	di_prop_lookup_##proptype(dev, node, name, data))
414*524b24f9SJudy Chen #define	ISPCI(s)						\
415*524b24f9SJudy Chen 	(((s) != NULL) && ((strcmp((s), "pci") == 0) ||		\
416*524b24f9SJudy Chen 	(strcmp((s), "pciex") == 0)))
417*524b24f9SJudy Chen /*
418*524b24f9SJudy Chen  * Print vendor ID and device ID for PCI devices
419*524b24f9SJudy Chen  */
420*524b24f9SJudy Chen int
421*524b24f9SJudy Chen print_pciid(di_node_t node, di_prom_handle_t ph)
422*524b24f9SJudy Chen {
423*524b24f9SJudy Chen 	di_node_t pnode = di_parent_node(node);
424*524b24f9SJudy Chen 	char *s = NULL;
425*524b24f9SJudy Chen 	int *i, type = di_nodeid(node);
426*524b24f9SJudy Chen 
427*524b24f9SJudy Chen 	if (LOOKUP_PROP(strings, ph, type, DDI_DEV_T_ANY, pnode,
428*524b24f9SJudy Chen 	    "device_type", &s) <= 0)
429*524b24f9SJudy Chen 		return (0);
430*524b24f9SJudy Chen 
431*524b24f9SJudy Chen 	if (!ISPCI(s))
432*524b24f9SJudy Chen 		return (0);	/* not a pci device */
433*524b24f9SJudy Chen 
434*524b24f9SJudy Chen 	(void) printf(" (%s", s);
435*524b24f9SJudy Chen 	if (LOOKUP_PROP(ints, ph, type, DDI_DEV_T_ANY, node,
436*524b24f9SJudy Chen 	    "vendor-id", &i) > 0)
437*524b24f9SJudy Chen 		(void) printf("%x", i[0]);
438*524b24f9SJudy Chen 
439*524b24f9SJudy Chen 	if (LOOKUP_PROP(ints, ph, type, DDI_DEV_T_ANY, node,
440*524b24f9SJudy Chen 	    "device-id", &i) > 0)
441*524b24f9SJudy Chen 		(void) printf(",%x", i[0]);
442*524b24f9SJudy Chen 	(void) printf(")");
443*524b24f9SJudy Chen 
444*524b24f9SJudy Chen 	return (1);
445*524b24f9SJudy Chen }
446