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