17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50a653502Swroche * Common Development and Distribution License (the "License"). 60a653502Swroche * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*94c894bbSVikram Hegde * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #ifndef _SYS_INSTANCE_H 267c478bd9Sstevel@tonic-gate #define _SYS_INSTANCE_H 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Instance number assignment data structures 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/param.h> 347c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 35*94c894bbSVikram Hegde #include <sys/list.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef __cplusplus 387c478bd9Sstevel@tonic-gate extern "C" { 397c478bd9Sstevel@tonic-gate #endif 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #define INSTANCE_FILE "/etc/path_to_inst" 427c478bd9Sstevel@tonic-gate #define INSTANCE_FILE_SUFFIX ".old" 437c478bd9Sstevel@tonic-gate 44*94c894bbSVikram Hegde 457c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * The form of a node; These form a tree that is parallel to the 497c478bd9Sstevel@tonic-gate * dev_info tree, but always fully populated. The tree is rooted in 507c478bd9Sstevel@tonic-gate * the in_softstate struct (e_ddi_inst_state.ins_root). 517c478bd9Sstevel@tonic-gate * 527c478bd9Sstevel@tonic-gate * Each node has one or more in_drv entries hanging from it. 537c478bd9Sstevel@tonic-gate * (It will have more than one if it has been driven by more than one driver 547c478bd9Sstevel@tonic-gate * over its lifetime. This can happen due to a generic name 557c478bd9Sstevel@tonic-gate * or to a "compatible" name giving a more specific driver). 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate typedef struct in_node { 597c478bd9Sstevel@tonic-gate char *in_node_name; /* devi_node_name of this node */ 607c478bd9Sstevel@tonic-gate char *in_unit_addr; /* address part of name */ 617c478bd9Sstevel@tonic-gate struct in_node *in_child; /* children of this node */ 627c478bd9Sstevel@tonic-gate struct in_node *in_sibling; /* "peers" of this node */ 637c478bd9Sstevel@tonic-gate struct in_drv *in_drivers; /* drivers bound to this node */ 647c478bd9Sstevel@tonic-gate struct in_node *in_parent; /* parent of this node */ 65*94c894bbSVikram Hegde dev_info_t *in_devi; /* corresponding devinfo */ 667c478bd9Sstevel@tonic-gate } in_node_t; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate typedef struct in_drv { 697c478bd9Sstevel@tonic-gate char *ind_driver_name; /* canonical name of driver */ 707c478bd9Sstevel@tonic-gate int ind_instance; /* current instance number */ 717c478bd9Sstevel@tonic-gate int ind_state; /* see below */ 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * The following field is used to link instance numbers for the 747c478bd9Sstevel@tonic-gate * same driver off of devnamesp or in_no_major or in_no_instance 757c478bd9Sstevel@tonic-gate */ 767c478bd9Sstevel@tonic-gate struct in_drv *ind_next; /* next for this driver */ 777c478bd9Sstevel@tonic-gate struct in_drv *ind_next_drv; /* next driver this node */ 787c478bd9Sstevel@tonic-gate struct in_node *ind_node; /* node that these hang on */ 797c478bd9Sstevel@tonic-gate } in_drv_t; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * Values for in_state 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate #define IN_PROVISIONAL 0x1 /* provisional instance number assigned */ 857c478bd9Sstevel@tonic-gate #define IN_PERMANENT 0x2 /* instance number has been confirmed */ 867c478bd9Sstevel@tonic-gate #define IN_UNKNOWN 0x3 /* instance number not yet assigned */ 87*94c894bbSVikram Hegde #define IN_BORROWED 0x4 /* instance number from alias */ 88*94c894bbSVikram Hegde 89*94c894bbSVikram Hegde 90*94c894bbSVikram Hegde /* 91*94c894bbSVikram Hegde * Guard for path to instance file 92*94c894bbSVikram Hegde */ 93*94c894bbSVikram Hegde #define PTI_GUARD "#\n#\tCaution! This file contains critical kernel state\n#\n" 94*94c894bbSVikram Hegde 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* 977c478bd9Sstevel@tonic-gate * special value for dn_instance 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate #define IN_SEARCHME (-1) 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1047c478bd9Sstevel@tonic-gate void e_ddi_instance_init(void); 1057c478bd9Sstevel@tonic-gate uint_t e_ddi_assign_instance(dev_info_t *dip); 1067c478bd9Sstevel@tonic-gate void e_ddi_keep_instance(dev_info_t *dip); 1077c478bd9Sstevel@tonic-gate void e_ddi_free_instance(dev_info_t *dip, char *addr); 1087c478bd9Sstevel@tonic-gate int e_ddi_instance_majorinstance_to_path(major_t major, 1097c478bd9Sstevel@tonic-gate uint_t instance, char *path); 1107c478bd9Sstevel@tonic-gate void e_ddi_unorphan_instance_nos(void); 1117c478bd9Sstevel@tonic-gate void e_ddi_enter_instance(void); 1127c478bd9Sstevel@tonic-gate void e_ddi_exit_instance(void); 1137c478bd9Sstevel@tonic-gate in_node_t *e_ddi_instance_root(void); 1147c478bd9Sstevel@tonic-gate int e_ddi_instance_is_clean(void); 1157c478bd9Sstevel@tonic-gate void e_ddi_instance_set_clean(void); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* Platform instance override functions */ 1187c478bd9Sstevel@tonic-gate uint_t impl_assign_instance(dev_info_t *dip); 1197c478bd9Sstevel@tonic-gate int impl_keep_instance(dev_info_t *dip); 1207c478bd9Sstevel@tonic-gate int impl_free_instance(dev_info_t *dip); 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* walk the instance tree */ 1237c478bd9Sstevel@tonic-gate int e_ddi_walk_instances(int (*)(const char *, 1247c478bd9Sstevel@tonic-gate in_node_t *, in_drv_t *, void *), void *); 1257c478bd9Sstevel@tonic-gate 126*94c894bbSVikram Hegde /* for DDI-MP */ 127*94c894bbSVikram Hegde in_node_t *e_ddi_path_to_instance(char *path); 128*94c894bbSVikram Hegde void e_ddi_borrow_instance(dev_info_t *cdip, in_node_t *cnp); 129*94c894bbSVikram Hegde void e_ddi_return_instance(dev_info_t *cdip, char *addr, in_node_t *cnp); 130*94c894bbSVikram Hegde 1317c478bd9Sstevel@tonic-gate /* return values from e_ddi_walk_instances callback */ 1327c478bd9Sstevel@tonic-gate #define INST_WALK_CONTINUE 0 1337c478bd9Sstevel@tonic-gate #define INST_WALK_TERMINATE 1 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #else /* _KERNEL */ 1377c478bd9Sstevel@tonic-gate #ifdef __STDC__ 1387c478bd9Sstevel@tonic-gate extern int inst_sync(char *pathname, int flags); 1397c478bd9Sstevel@tonic-gate #else 1407c478bd9Sstevel@tonic-gate extern int inst_sync(); 1417c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 1427c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1437c478bd9Sstevel@tonic-gate 1440a653502Swroche #define INST_SYNC_IF_REQUIRED 0 1450a653502Swroche #define INST_SYNC_ALWAYS 1 1460a653502Swroche 1477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate #endif 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate #endif /* _SYS_INSTANCE_H */ 152