xref: /titanic_54/usr/src/uts/common/sys/instance.h (revision 0a653502ce7060b491de569a1991825128724441)
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
5*0a653502Swroche  * Common Development and Distribution License (the "License").
6*0a653502Swroche  * 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*0a653502Swroche  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_INSTANCE_H
277c478bd9Sstevel@tonic-gate #define	_SYS_INSTANCE_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Instance number assignment data structures
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/param.h>
377c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	INSTANCE_FILE	"/etc/path_to_inst"
447c478bd9Sstevel@tonic-gate #define	INSTANCE_FILE_SUFFIX	".old"
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #if	defined(_KERNEL) || defined(_KMEMUSER)
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * The form of a node;  These form a tree that is parallel to the
507c478bd9Sstevel@tonic-gate  * dev_info tree, but always fully populated.  The tree is rooted in
517c478bd9Sstevel@tonic-gate  * the in_softstate struct (e_ddi_inst_state.ins_root).
527c478bd9Sstevel@tonic-gate  *
537c478bd9Sstevel@tonic-gate  * Each node has one or more in_drv entries hanging from it.
547c478bd9Sstevel@tonic-gate  * (It will have more than one if it has been driven by more than one driver
557c478bd9Sstevel@tonic-gate  * over its lifetime.  This can happen due to a generic name
567c478bd9Sstevel@tonic-gate  * or to a "compatible" name giving a more specific driver).
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct in_node {
607c478bd9Sstevel@tonic-gate 	char		*in_node_name;	/* devi_node_name of this node	*/
617c478bd9Sstevel@tonic-gate 	char		*in_unit_addr;	/* address part of name		*/
627c478bd9Sstevel@tonic-gate 	struct in_node	*in_child;	/* children of this node	*/
637c478bd9Sstevel@tonic-gate 	struct in_node	*in_sibling;	/* "peers" of this node	*/
647c478bd9Sstevel@tonic-gate 	struct in_drv	*in_drivers;	/* drivers bound to this node	*/
657c478bd9Sstevel@tonic-gate 	struct in_node	*in_parent;	/* parent of this node		*/
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 */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * special value for dn_instance
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	IN_SEARCHME (-1)
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
967c478bd9Sstevel@tonic-gate void e_ddi_instance_init(void);
977c478bd9Sstevel@tonic-gate uint_t e_ddi_assign_instance(dev_info_t *dip);
987c478bd9Sstevel@tonic-gate void e_ddi_keep_instance(dev_info_t *dip);
997c478bd9Sstevel@tonic-gate void e_ddi_free_instance(dev_info_t *dip, char *addr);
1007c478bd9Sstevel@tonic-gate int e_ddi_instance_majorinstance_to_path(major_t major,
1017c478bd9Sstevel@tonic-gate 	uint_t instance, char *path);
1027c478bd9Sstevel@tonic-gate void e_ddi_unorphan_instance_nos(void);
1037c478bd9Sstevel@tonic-gate void e_ddi_enter_instance(void);
1047c478bd9Sstevel@tonic-gate void e_ddi_exit_instance(void);
1057c478bd9Sstevel@tonic-gate in_node_t *e_ddi_instance_root(void);
1067c478bd9Sstevel@tonic-gate int e_ddi_instance_is_clean(void);
1077c478bd9Sstevel@tonic-gate void e_ddi_instance_set_clean(void);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /* Platform instance override functions */
1107c478bd9Sstevel@tonic-gate uint_t impl_assign_instance(dev_info_t *dip);
1117c478bd9Sstevel@tonic-gate int impl_keep_instance(dev_info_t *dip);
1127c478bd9Sstevel@tonic-gate int impl_free_instance(dev_info_t *dip);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /* walk the instance tree */
1157c478bd9Sstevel@tonic-gate int e_ddi_walk_instances(int (*)(const char *,
1167c478bd9Sstevel@tonic-gate 	in_node_t *, in_drv_t *, void *), void *);
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /* return values from e_ddi_walk_instances callback */
1197c478bd9Sstevel@tonic-gate #define	INST_WALK_CONTINUE	0
1207c478bd9Sstevel@tonic-gate #define	INST_WALK_TERMINATE	1
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
1247c478bd9Sstevel@tonic-gate #ifdef __STDC__
1257c478bd9Sstevel@tonic-gate extern int inst_sync(char *pathname, int flags);
1267c478bd9Sstevel@tonic-gate #else
1277c478bd9Sstevel@tonic-gate extern int inst_sync();
1287c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
1297c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1307c478bd9Sstevel@tonic-gate 
131*0a653502Swroche #define	INST_SYNC_IF_REQUIRED	0
132*0a653502Swroche #define	INST_SYNC_ALWAYS	1
133*0a653502Swroche 
1347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate #endif
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #endif	/* _SYS_INSTANCE_H */
139