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