10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56548Swroche * Common Development and Distribution License (the "License"). 66548Swroche * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12116SVikram.Hegde@Sun.COM * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_INSTANCE_H 260Sstevel@tonic-gate #define _SYS_INSTANCE_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Instance number assignment data structures 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/param.h> 340Sstevel@tonic-gate #include <sys/dditypes.h> 35*12116SVikram.Hegde@Sun.COM #include <sys/list.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate #define INSTANCE_FILE "/etc/path_to_inst" 420Sstevel@tonic-gate #define INSTANCE_FILE_SUFFIX ".old" 430Sstevel@tonic-gate 44*12116SVikram.Hegde@Sun.COM 450Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * The form of a node; These form a tree that is parallel to the 490Sstevel@tonic-gate * dev_info tree, but always fully populated. The tree is rooted in 500Sstevel@tonic-gate * the in_softstate struct (e_ddi_inst_state.ins_root). 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * Each node has one or more in_drv entries hanging from it. 530Sstevel@tonic-gate * (It will have more than one if it has been driven by more than one driver 540Sstevel@tonic-gate * over its lifetime. This can happen due to a generic name 550Sstevel@tonic-gate * or to a "compatible" name giving a more specific driver). 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate 580Sstevel@tonic-gate typedef struct in_node { 590Sstevel@tonic-gate char *in_node_name; /* devi_node_name of this node */ 600Sstevel@tonic-gate char *in_unit_addr; /* address part of name */ 610Sstevel@tonic-gate struct in_node *in_child; /* children of this node */ 62*12116SVikram.Hegde@Sun.COM struct in_node *in_sibling; /* "peers" of this node */ 630Sstevel@tonic-gate struct in_drv *in_drivers; /* drivers bound to this node */ 640Sstevel@tonic-gate struct in_node *in_parent; /* parent of this node */ 65*12116SVikram.Hegde@Sun.COM dev_info_t *in_devi; /* corresponding devinfo */ 660Sstevel@tonic-gate } in_node_t; 670Sstevel@tonic-gate 680Sstevel@tonic-gate typedef struct in_drv { 690Sstevel@tonic-gate char *ind_driver_name; /* canonical name of driver */ 700Sstevel@tonic-gate int ind_instance; /* current instance number */ 710Sstevel@tonic-gate int ind_state; /* see below */ 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * The following field is used to link instance numbers for the 740Sstevel@tonic-gate * same driver off of devnamesp or in_no_major or in_no_instance 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate struct in_drv *ind_next; /* next for this driver */ 770Sstevel@tonic-gate struct in_drv *ind_next_drv; /* next driver this node */ 780Sstevel@tonic-gate struct in_node *ind_node; /* node that these hang on */ 790Sstevel@tonic-gate } in_drv_t; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * Values for in_state 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate #define IN_PROVISIONAL 0x1 /* provisional instance number assigned */ 850Sstevel@tonic-gate #define IN_PERMANENT 0x2 /* instance number has been confirmed */ 860Sstevel@tonic-gate #define IN_UNKNOWN 0x3 /* instance number not yet assigned */ 87*12116SVikram.Hegde@Sun.COM #define IN_BORROWED 0x4 /* instance number from alias */ 88*12116SVikram.Hegde@Sun.COM 89*12116SVikram.Hegde@Sun.COM 90*12116SVikram.Hegde@Sun.COM /* 91*12116SVikram.Hegde@Sun.COM * Guard for path to instance file 92*12116SVikram.Hegde@Sun.COM */ 93*12116SVikram.Hegde@Sun.COM #define PTI_GUARD "#\n#\tCaution! This file contains critical kernel state\n#\n" 94*12116SVikram.Hegde@Sun.COM 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * special value for dn_instance 980Sstevel@tonic-gate */ 990Sstevel@tonic-gate #define IN_SEARCHME (-1) 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate #ifdef _KERNEL 1040Sstevel@tonic-gate void e_ddi_instance_init(void); 1050Sstevel@tonic-gate uint_t e_ddi_assign_instance(dev_info_t *dip); 1060Sstevel@tonic-gate void e_ddi_keep_instance(dev_info_t *dip); 1070Sstevel@tonic-gate void e_ddi_free_instance(dev_info_t *dip, char *addr); 1080Sstevel@tonic-gate int e_ddi_instance_majorinstance_to_path(major_t major, 1090Sstevel@tonic-gate uint_t instance, char *path); 1100Sstevel@tonic-gate void e_ddi_unorphan_instance_nos(void); 1110Sstevel@tonic-gate void e_ddi_enter_instance(void); 1120Sstevel@tonic-gate void e_ddi_exit_instance(void); 1130Sstevel@tonic-gate in_node_t *e_ddi_instance_root(void); 1140Sstevel@tonic-gate int e_ddi_instance_is_clean(void); 1150Sstevel@tonic-gate void e_ddi_instance_set_clean(void); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* Platform instance override functions */ 1180Sstevel@tonic-gate uint_t impl_assign_instance(dev_info_t *dip); 1190Sstevel@tonic-gate int impl_keep_instance(dev_info_t *dip); 1200Sstevel@tonic-gate int impl_free_instance(dev_info_t *dip); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* walk the instance tree */ 1230Sstevel@tonic-gate int e_ddi_walk_instances(int (*)(const char *, 124*12116SVikram.Hegde@Sun.COM in_node_t *, in_drv_t *, void *), void *); 125*12116SVikram.Hegde@Sun.COM 126*12116SVikram.Hegde@Sun.COM /* for DDI-MP */ 127*12116SVikram.Hegde@Sun.COM in_node_t *e_ddi_path_to_instance(char *path); 128*12116SVikram.Hegde@Sun.COM void e_ddi_borrow_instance(dev_info_t *cdip, in_node_t *cnp); 129*12116SVikram.Hegde@Sun.COM void e_ddi_return_instance(dev_info_t *cdip, char *addr, in_node_t *cnp); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* return values from e_ddi_walk_instances callback */ 1320Sstevel@tonic-gate #define INST_WALK_CONTINUE 0 1330Sstevel@tonic-gate #define INST_WALK_TERMINATE 1 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate #else /* _KERNEL */ 1370Sstevel@tonic-gate #ifdef __STDC__ 1380Sstevel@tonic-gate extern int inst_sync(char *pathname, int flags); 1390Sstevel@tonic-gate #else 1400Sstevel@tonic-gate extern int inst_sync(); 1410Sstevel@tonic-gate #endif /* __STDC__ */ 1420Sstevel@tonic-gate #endif /* _KERNEL */ 1430Sstevel@tonic-gate 1446548Swroche #define INST_SYNC_IF_REQUIRED 0 1456548Swroche #define INST_SYNC_ALWAYS 1 1466548Swroche 1470Sstevel@tonic-gate #ifdef __cplusplus 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate #endif 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate #endif /* _SYS_INSTANCE_H */ 152