xref: /onnv-gate/usr/src/lib/libprtdiag/inc/pdevinfo.h (revision 1708:ea74d8598a3a)
1*1708Sstevel /*
2*1708Sstevel  * CDDL HEADER START
3*1708Sstevel  *
4*1708Sstevel  * The contents of this file are subject to the terms of the
5*1708Sstevel  * Common Development and Distribution License, Version 1.0 only
6*1708Sstevel  * (the "License").  You may not use this file except in compliance
7*1708Sstevel  * with the License.
8*1708Sstevel  *
9*1708Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*1708Sstevel  * or http://www.opensolaris.org/os/licensing.
11*1708Sstevel  * See the License for the specific language governing permissions
12*1708Sstevel  * and limitations under the License.
13*1708Sstevel  *
14*1708Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
15*1708Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*1708Sstevel  * If applicable, add the following below this CDDL HEADER, with the
17*1708Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
18*1708Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
19*1708Sstevel  *
20*1708Sstevel  * CDDL HEADER END
21*1708Sstevel  */
22*1708Sstevel /*
23*1708Sstevel  * Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
24*1708Sstevel  * Use is subject to license terms.
25*1708Sstevel  */
26*1708Sstevel 
27*1708Sstevel #ifndef	_PDEVINFO_H
28*1708Sstevel #define	_PDEVINFO_H
29*1708Sstevel 
30*1708Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*1708Sstevel 
32*1708Sstevel #ifdef	__cplusplus
33*1708Sstevel extern "C" {
34*1708Sstevel #endif
35*1708Sstevel 
36*1708Sstevel /* structures necessary to hold Openprom data */
37*1708Sstevel 
38*1708Sstevel /*
39*1708Sstevel  * 128 is the size of the largest (currently) property name
40*1708Sstevel  * 4096 - MAXPROPSIZE - sizeof (int) is the size of the largest
41*1708Sstevel  * (currently) property value that is allowed.
42*1708Sstevel  * the sizeof (u_int) is from struct openpromio
43*1708Sstevel  */
44*1708Sstevel #define	MAXPROPSIZE	128
45*1708Sstevel #define	MAXVALSIZE	(4096 - MAXPROPSIZE - sizeof (uint_t))
46*1708Sstevel #define	BUFSIZE		(MAXPROPSIZE + MAXVALSIZE + sizeof (uint_t))
47*1708Sstevel typedef union {
48*1708Sstevel 	char buf[BUFSIZE];
49*1708Sstevel 	struct openpromio opp;
50*1708Sstevel 	void	*val_ptr;
51*1708Sstevel } Oppbuf;
52*1708Sstevel 
53*1708Sstevel /*
54*1708Sstevel  * The prop structures associated with a Prom_node were formerly statically
55*1708Sstevel  * sized - via the buf element of the Oppbuf union. This was highly memory
56*1708Sstevel  * inefficient, so dynamic sizing capabilities have been introduced.
57*1708Sstevel  *
58*1708Sstevel  * This has been achieved via the creation of dynopenpromio and dynOppbuf
59*1708Sstevel  * structs, and altering the prop structure. The prop structure's name and value
60*1708Sstevel  * elements are now typed as dynOppbuf instead of Oppbuf.
61*1708Sstevel  *
62*1708Sstevel  * For legacy purposes, static_prop has been created. It is essentially the same
63*1708Sstevel  * as the former prop structure, but the *next element now points to a
64*1708Sstevel  * static_prop structure instead of a prop structure.
65*1708Sstevel  */
66*1708Sstevel typedef struct static_prop StaticProp;
67*1708Sstevel struct static_prop {
68*1708Sstevel 	StaticProp *next;
69*1708Sstevel 	Oppbuf name;
70*1708Sstevel 	Oppbuf value;
71*1708Sstevel 	int size;	/* size of data in bytes */
72*1708Sstevel };
73*1708Sstevel 
74*1708Sstevel /*
75*1708Sstevel  * dynopenpromio structs are similar to openpromio structs, but with 2 major
76*1708Sstevel  * differences. The first is that the opio_u.b element is char * instead of
77*1708Sstevel  * char [], which allows for dynamic sizing.
78*1708Sstevel  *
79*1708Sstevel  * The second regards opio_u.i, which was an int, but is now int []. In almost
80*1708Sstevel  * all cases, only opio_u.i (opio_u.i[0]) will be referenced. However, certain
81*1708Sstevel  * platforms rely on the fact that Prop structures formerly contained Oppbuf
82*1708Sstevel  * unions, the buf element of which was statically sized at 4k. In theory, this
83*1708Sstevel  * enabled those platforms to validly reference any part of the union up to 4k
84*1708Sstevel  * from the start. In reality, no element greater than opio_u.i[4] is currently
85*1708Sstevel  * referenced, hence OPROM_NODE_SIZE (named because opio_u.i is usually
86*1708Sstevel  * referenced as oprom_node) being set to 5.
87*1708Sstevel  *
88*1708Sstevel  * A minor difference is that the holds_array element has been added, which
89*1708Sstevel  * affords an easy way to determine whether opio_u contains char * or int.
90*1708Sstevel  */
91*1708Sstevel #define	OPROM_NODE_SIZE		5
92*1708Sstevel struct dynopenpromio {
93*1708Sstevel 	uint_t oprom_size;
94*1708Sstevel 	union {
95*1708Sstevel 		char *b;
96*1708Sstevel 		int i[OPROM_NODE_SIZE];
97*1708Sstevel 	} opio_u;
98*1708Sstevel 	uint_t holds_array;
99*1708Sstevel };
100*1708Sstevel 
101*1708Sstevel /*
102*1708Sstevel  * dynOppbuf structs are a dynamic alternative to Oppbuf unions. The statically
103*1708Sstevel  * sized Oppbuf.buf element has been removed, and the opp element common to both
104*1708Sstevel  * is of type struct dynopenpromio instead of struct openpromio. This allows us
105*1708Sstevel  * to take advantage of dynopenpromio's dynamic sizing capabilities.
106*1708Sstevel  */
107*1708Sstevel typedef struct dynoppbuf dynOppbuf;
108*1708Sstevel struct dynoppbuf {
109*1708Sstevel 	struct dynopenpromio opp;
110*1708Sstevel 	char *val_ptr;
111*1708Sstevel };
112*1708Sstevel 
113*1708Sstevel typedef struct prop Prop;
114*1708Sstevel struct prop {
115*1708Sstevel 	Prop *next;
116*1708Sstevel 	dynOppbuf name;
117*1708Sstevel 	dynOppbuf value;
118*1708Sstevel 	int size;	/* size of data in bytes */
119*1708Sstevel };
120*1708Sstevel 
121*1708Sstevel typedef struct prom_node Prom_node;
122*1708Sstevel struct prom_node {
123*1708Sstevel 	Prom_node *parent;	/* points to parent node */
124*1708Sstevel 	Prom_node *child;	/* points to child PROM node */
125*1708Sstevel 	Prom_node *sibling;	/* point to next sibling */
126*1708Sstevel 	Prop *props;		/* points to list of properties */
127*1708Sstevel };
128*1708Sstevel 
129*1708Sstevel /*
130*1708Sstevel  * Defines for board types.
131*1708Sstevel  */
132*1708Sstevel 
133*1708Sstevel typedef struct board_node Board_node;
134*1708Sstevel struct board_node {
135*1708Sstevel 	int node_id;
136*1708Sstevel 	int board_num;
137*1708Sstevel 	int board_type;
138*1708Sstevel 	Prom_node *nodes;
139*1708Sstevel 	Board_node *next;  /* link for list */
140*1708Sstevel };
141*1708Sstevel 
142*1708Sstevel typedef struct system_tree Sys_tree;
143*1708Sstevel struct system_tree {
144*1708Sstevel 	Prom_node *sys_mem;	/* System memory node */
145*1708Sstevel 	Prom_node *boards;	/* boards node holds bif info if present */
146*1708Sstevel 	Board_node *bd_list;	/* node holds list of boards */
147*1708Sstevel 	int board_cnt;		/* number of boards in the system */
148*1708Sstevel };
149*1708Sstevel 
150*1708Sstevel int do_prominfo(int, char *, int, int);
151*1708Sstevel int is_openprom(void);
152*1708Sstevel void promclose(void);
153*1708Sstevel int promopen(int);
154*1708Sstevel extern char *badarchmsg;
155*1708Sstevel int _error(char *fmt, ...);
156*1708Sstevel 
157*1708Sstevel /* Functions for building the user copy of the device tree. */
158*1708Sstevel Board_node *find_board(Sys_tree *, int);
159*1708Sstevel Board_node *insert_board(Sys_tree *, int);
160*1708Sstevel 
161*1708Sstevel /* functions for searching for Prom nodes */
162*1708Sstevel char *get_node_name(Prom_node *);
163*1708Sstevel char *get_node_type(Prom_node *);
164*1708Sstevel Prom_node *dev_find_node(Prom_node *, char *);
165*1708Sstevel Prom_node *dev_next_node(Prom_node *, char *);
166*1708Sstevel Prom_node *dev_find_node_by_type(Prom_node *root, char *type, char *property);
167*1708Sstevel Prom_node *dev_next_node_by_type(Prom_node *root, char *type, char *property);
168*1708Sstevel Prom_node *dev_find_type(Prom_node *, char *);
169*1708Sstevel Prom_node *dev_next_type(Prom_node *, char *);
170*1708Sstevel Prom_node *sys_find_node(Sys_tree *, int, char *);
171*1708Sstevel Prom_node *find_failed_node(Prom_node *);
172*1708Sstevel Prom_node *next_failed_node(Prom_node *);
173*1708Sstevel Prom_node *dev_find_node_by_compatible(Prom_node *root, char *compat);
174*1708Sstevel Prom_node *dev_next_node_by_compatible(Prom_node *root, char *compat);
175*1708Sstevel int node_failed(Prom_node *);
176*1708Sstevel int node_status(Prom_node *node, char *status);
177*1708Sstevel void dump_node(Prom_node *);
178*1708Sstevel int next(int);
179*1708Sstevel int has_board_num(Prom_node *);
180*1708Sstevel int get_board_num(Prom_node *);
181*1708Sstevel int child(int);
182*1708Sstevel 
183*1708Sstevel /* functions for searching for properties, extracting data from them */
184*1708Sstevel void *get_prop_val(Prop *);
185*1708Sstevel void getpropval(struct openpromio *);
186*1708Sstevel Prop *find_prop(Prom_node *, char *);
187*1708Sstevel 
188*1708Sstevel #ifdef	__cplusplus
189*1708Sstevel }
190*1708Sstevel #endif
191*1708Sstevel 
192*1708Sstevel #endif	/* _PDEVINFO_H */
193