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