xref: /titanic_51/usr/src/uts/common/sys/instance.h (revision ba3594ba9b5dd4c846c472a8d657edcb7c8109ac)
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*ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23*ba3594baSGarrett D'Amore  *
2494c894bbSVikram Hegde  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_SYS_INSTANCE_H
287c478bd9Sstevel@tonic-gate #define	_SYS_INSTANCE_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * Instance number assignment data structures
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
3794c894bbSVikram Hegde #include <sys/list.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 
4694c894bbSVikram Hegde 
477c478bd9Sstevel@tonic-gate #if	defined(_KERNEL) || defined(_KMEMUSER)
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * The form of a node;  These form a tree that is parallel to the
517c478bd9Sstevel@tonic-gate  * dev_info tree, but always fully populated.  The tree is rooted in
527c478bd9Sstevel@tonic-gate  * the in_softstate struct (e_ddi_inst_state.ins_root).
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * Each node has one or more in_drv entries hanging from it.
557c478bd9Sstevel@tonic-gate  * (It will have more than one if it has been driven by more than one driver
567c478bd9Sstevel@tonic-gate  * over its lifetime.  This can happen due to a generic name
577c478bd9Sstevel@tonic-gate  * or to a "compatible" name giving a more specific driver).
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef struct in_node {
617c478bd9Sstevel@tonic-gate 	char		*in_node_name;	/* devi_node_name of this node	*/
627c478bd9Sstevel@tonic-gate 	char		*in_unit_addr;	/* address part of name		*/
637c478bd9Sstevel@tonic-gate 	struct in_node	*in_child;	/* children of this node	*/
647c478bd9Sstevel@tonic-gate 	struct in_node	*in_sibling;	/* "peers" of this node		*/
657c478bd9Sstevel@tonic-gate 	struct in_drv	*in_drivers;	/* drivers bound to this node	*/
667c478bd9Sstevel@tonic-gate 	struct in_node	*in_parent;	/* parent of this node		*/
6794c894bbSVikram Hegde 	dev_info_t	*in_devi;	/* corresponding devinfo	*/
687c478bd9Sstevel@tonic-gate } in_node_t;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef struct in_drv {
717c478bd9Sstevel@tonic-gate 	char		*ind_driver_name; /* canonical name of driver	*/
727c478bd9Sstevel@tonic-gate 	int		ind_instance;	  /* current instance number	*/
737c478bd9Sstevel@tonic-gate 	int		ind_state;	  /* see below			*/
747c478bd9Sstevel@tonic-gate 	/*
757c478bd9Sstevel@tonic-gate 	 * The following field is used to link instance numbers for the
767c478bd9Sstevel@tonic-gate 	 * same driver off of devnamesp or in_no_major or in_no_instance
777c478bd9Sstevel@tonic-gate 	 */
787c478bd9Sstevel@tonic-gate 	struct in_drv	*ind_next;	  /* next for this driver	*/
797c478bd9Sstevel@tonic-gate 	struct in_drv	*ind_next_drv;	  /* next driver this node	*/
807c478bd9Sstevel@tonic-gate 	struct in_node	*ind_node;	  /* node that these hang on	*/
817c478bd9Sstevel@tonic-gate } in_drv_t;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * Values for in_state
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate #define	IN_PROVISIONAL	0x1	/* provisional instance number assigned */
877c478bd9Sstevel@tonic-gate #define	IN_PERMANENT	0x2	/* instance number has been confirmed */
887c478bd9Sstevel@tonic-gate #define	IN_UNKNOWN	0x3	/* instance number not yet assigned */
8994c894bbSVikram Hegde #define	IN_BORROWED	0x4	/* instance number from alias */
9094c894bbSVikram Hegde 
9194c894bbSVikram Hegde 
9294c894bbSVikram Hegde /*
9394c894bbSVikram Hegde  * Guard for path to instance file
9494c894bbSVikram Hegde  */
9594c894bbSVikram Hegde #define	PTI_GUARD "#\n#\tCaution! This file contains critical kernel state\n#\n"
9694c894bbSVikram Hegde 
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * special value for dn_instance
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate #define	IN_SEARCHME (-1)
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) || defined(_KMEMUSER) */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate #ifdef	_KERNEL
1067c478bd9Sstevel@tonic-gate void e_ddi_instance_init(void);
1077c478bd9Sstevel@tonic-gate uint_t e_ddi_assign_instance(dev_info_t *dip);
1087c478bd9Sstevel@tonic-gate void e_ddi_keep_instance(dev_info_t *dip);
1097c478bd9Sstevel@tonic-gate void e_ddi_free_instance(dev_info_t *dip, char *addr);
1107c478bd9Sstevel@tonic-gate int e_ddi_instance_majorinstance_to_path(major_t major,
1117c478bd9Sstevel@tonic-gate 	uint_t instance, char *path);
1127c478bd9Sstevel@tonic-gate void e_ddi_unorphan_instance_nos(void);
1137c478bd9Sstevel@tonic-gate void e_ddi_enter_instance(void);
1147c478bd9Sstevel@tonic-gate void e_ddi_exit_instance(void);
1157c478bd9Sstevel@tonic-gate in_node_t *e_ddi_instance_root(void);
1167c478bd9Sstevel@tonic-gate int e_ddi_instance_is_clean(void);
1177c478bd9Sstevel@tonic-gate void e_ddi_instance_set_clean(void);
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /* Platform instance override functions */
1207c478bd9Sstevel@tonic-gate uint_t impl_assign_instance(dev_info_t *dip);
1217c478bd9Sstevel@tonic-gate int impl_keep_instance(dev_info_t *dip);
1227c478bd9Sstevel@tonic-gate int impl_free_instance(dev_info_t *dip);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* walk the instance tree */
1257c478bd9Sstevel@tonic-gate int e_ddi_walk_instances(int (*)(const char *,
1267c478bd9Sstevel@tonic-gate     in_node_t *, in_drv_t *, void *), void *);
1277c478bd9Sstevel@tonic-gate 
12894c894bbSVikram Hegde /* for DDI-MP */
12994c894bbSVikram Hegde in_node_t *e_ddi_path_to_instance(char *path);
13094c894bbSVikram Hegde void e_ddi_borrow_instance(dev_info_t *cdip, in_node_t *cnp);
13194c894bbSVikram Hegde void e_ddi_return_instance(dev_info_t *cdip, char *addr, in_node_t *cnp);
13294c894bbSVikram Hegde 
1337c478bd9Sstevel@tonic-gate /* return values from e_ddi_walk_instances callback */
1347c478bd9Sstevel@tonic-gate #define	INST_WALK_CONTINUE	0
1357c478bd9Sstevel@tonic-gate #define	INST_WALK_TERMINATE	1
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
1397c478bd9Sstevel@tonic-gate extern int inst_sync(char *pathname, int flags);
1407c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1417c478bd9Sstevel@tonic-gate 
1420a653502Swroche #define	INST_SYNC_IF_REQUIRED	0
1430a653502Swroche #define	INST_SYNC_ALWAYS	1
1440a653502Swroche 
1457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #endif	/* _SYS_INSTANCE_H */
150