1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_INSTANCE_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_INSTANCE_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * Instance number assignment data structures 34*7c478bd9Sstevel@tonic-gate */ 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 41*7c478bd9Sstevel@tonic-gate extern "C" { 42*7c478bd9Sstevel@tonic-gate #endif 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #define INSTANCE_FILE "/etc/path_to_inst" 45*7c478bd9Sstevel@tonic-gate #define INSTANCE_FILE_SUFFIX ".old" 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* 50*7c478bd9Sstevel@tonic-gate * The form of a node; These form a tree that is parallel to the 51*7c478bd9Sstevel@tonic-gate * dev_info tree, but always fully populated. The tree is rooted in 52*7c478bd9Sstevel@tonic-gate * the in_softstate struct (e_ddi_inst_state.ins_root). 53*7c478bd9Sstevel@tonic-gate * 54*7c478bd9Sstevel@tonic-gate * Each node has one or more in_drv entries hanging from it. 55*7c478bd9Sstevel@tonic-gate * (It will have more than one if it has been driven by more than one driver 56*7c478bd9Sstevel@tonic-gate * over its lifetime. This can happen due to a generic name 57*7c478bd9Sstevel@tonic-gate * or to a "compatible" name giving a more specific driver). 58*7c478bd9Sstevel@tonic-gate */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate typedef struct in_node { 61*7c478bd9Sstevel@tonic-gate char *in_node_name; /* devi_node_name of this node */ 62*7c478bd9Sstevel@tonic-gate char *in_unit_addr; /* address part of name */ 63*7c478bd9Sstevel@tonic-gate struct in_node *in_child; /* children of this node */ 64*7c478bd9Sstevel@tonic-gate struct in_node *in_sibling; /* "peers" of this node */ 65*7c478bd9Sstevel@tonic-gate struct in_drv *in_drivers; /* drivers bound to this node */ 66*7c478bd9Sstevel@tonic-gate struct in_node *in_parent; /* parent of this node */ 67*7c478bd9Sstevel@tonic-gate } in_node_t; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate typedef struct in_drv { 70*7c478bd9Sstevel@tonic-gate char *ind_driver_name; /* canonical name of driver */ 71*7c478bd9Sstevel@tonic-gate int ind_instance; /* current instance number */ 72*7c478bd9Sstevel@tonic-gate int ind_state; /* see below */ 73*7c478bd9Sstevel@tonic-gate /* 74*7c478bd9Sstevel@tonic-gate * The following field is used to link instance numbers for the 75*7c478bd9Sstevel@tonic-gate * same driver off of devnamesp or in_no_major or in_no_instance 76*7c478bd9Sstevel@tonic-gate */ 77*7c478bd9Sstevel@tonic-gate struct in_drv *ind_next; /* next for this driver */ 78*7c478bd9Sstevel@tonic-gate struct in_drv *ind_next_drv; /* next driver this node */ 79*7c478bd9Sstevel@tonic-gate struct in_node *ind_node; /* node that these hang on */ 80*7c478bd9Sstevel@tonic-gate } in_drv_t; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate /* 83*7c478bd9Sstevel@tonic-gate * Values for in_state 84*7c478bd9Sstevel@tonic-gate */ 85*7c478bd9Sstevel@tonic-gate #define IN_PROVISIONAL 0x1 /* provisional instance number assigned */ 86*7c478bd9Sstevel@tonic-gate #define IN_PERMANENT 0x2 /* instance number has been confirmed */ 87*7c478bd9Sstevel@tonic-gate #define IN_UNKNOWN 0x3 /* instance number not yet assigned */ 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* 90*7c478bd9Sstevel@tonic-gate * special value for dn_instance 91*7c478bd9Sstevel@tonic-gate */ 92*7c478bd9Sstevel@tonic-gate #define IN_SEARCHME (-1) 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 97*7c478bd9Sstevel@tonic-gate void e_ddi_instance_init(void); 98*7c478bd9Sstevel@tonic-gate uint_t e_ddi_assign_instance(dev_info_t *dip); 99*7c478bd9Sstevel@tonic-gate void e_ddi_keep_instance(dev_info_t *dip); 100*7c478bd9Sstevel@tonic-gate void e_ddi_free_instance(dev_info_t *dip, char *addr); 101*7c478bd9Sstevel@tonic-gate int e_ddi_instance_majorinstance_to_path(major_t major, 102*7c478bd9Sstevel@tonic-gate uint_t instance, char *path); 103*7c478bd9Sstevel@tonic-gate void e_ddi_unorphan_instance_nos(void); 104*7c478bd9Sstevel@tonic-gate void e_ddi_enter_instance(void); 105*7c478bd9Sstevel@tonic-gate void e_ddi_exit_instance(void); 106*7c478bd9Sstevel@tonic-gate in_node_t *e_ddi_instance_root(void); 107*7c478bd9Sstevel@tonic-gate int e_ddi_instance_is_clean(void); 108*7c478bd9Sstevel@tonic-gate void e_ddi_instance_set_clean(void); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* Platform instance override functions */ 111*7c478bd9Sstevel@tonic-gate uint_t impl_assign_instance(dev_info_t *dip); 112*7c478bd9Sstevel@tonic-gate int impl_keep_instance(dev_info_t *dip); 113*7c478bd9Sstevel@tonic-gate int impl_free_instance(dev_info_t *dip); 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate /* walk the instance tree */ 116*7c478bd9Sstevel@tonic-gate int e_ddi_walk_instances(int (*)(const char *, 117*7c478bd9Sstevel@tonic-gate in_node_t *, in_drv_t *, void *), void *); 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate /* return values from e_ddi_walk_instances callback */ 120*7c478bd9Sstevel@tonic-gate #define INST_WALK_CONTINUE 0 121*7c478bd9Sstevel@tonic-gate #define INST_WALK_TERMINATE 1 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate #else /* _KERNEL */ 125*7c478bd9Sstevel@tonic-gate #ifdef __STDC__ 126*7c478bd9Sstevel@tonic-gate extern int inst_sync(char *pathname, int flags); 127*7c478bd9Sstevel@tonic-gate #else 128*7c478bd9Sstevel@tonic-gate extern int inst_sync(); 129*7c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 130*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate #endif 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate #endif /* _SYS_INSTANCE_H */ 137