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