xref: /titanic_50/usr/src/uts/common/sys/autoconf.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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_AUTOCONF_H
28*7c478bd9Sstevel@tonic-gate #define	_SYS_AUTOCONF_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /* Derived from autoconf.h, SunOS 4.1.1 1.15 */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
35*7c478bd9Sstevel@tonic-gate extern "C" {
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * This defines a parallel structure to the devops list.
40*7c478bd9Sstevel@tonic-gate  */
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/devops.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/thread.h>
46*7c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h>
47*7c478bd9Sstevel@tonic-gate #include <sys/systm.h>
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate struct devnames {
50*7c478bd9Sstevel@tonic-gate 	char		*dn_name;	/* Name of this driver */
51*7c478bd9Sstevel@tonic-gate 	int		dn_flags;	/* per-driver flags, see below */
52*7c478bd9Sstevel@tonic-gate 	struct par_list	*dn_pl;		/* parent list, for making devinfos */
53*7c478bd9Sstevel@tonic-gate 	kmutex_t	dn_lock;	/* Per driver lock (see below) */
54*7c478bd9Sstevel@tonic-gate 	dev_info_t	*dn_head;	/* Head of instance list */
55*7c478bd9Sstevel@tonic-gate 	int		dn_instance;	/* Next instance no. to assign */
56*7c478bd9Sstevel@tonic-gate 	void		*dn_inlist;	/* instance # nodes for this driver */
57*7c478bd9Sstevel@tonic-gate 	ddi_prop_list_t	*dn_global_prop_ptr; /* per-driver global properties */
58*7c478bd9Sstevel@tonic-gate 	kcondvar_t	dn_wait;	/* for ddi_hold_installed_driver */
59*7c478bd9Sstevel@tonic-gate 	kthread_id_t	dn_busy_thread;	/* for debugging only */
60*7c478bd9Sstevel@tonic-gate 	struct mperm	*dn_mperm;	/* minor permissions */
61*7c478bd9Sstevel@tonic-gate 	struct mperm	*dn_mperm_wild;	/* default minor permission */
62*7c478bd9Sstevel@tonic-gate 	struct mperm	*dn_mperm_clone; /* minor permission, clone use */
63*7c478bd9Sstevel@tonic-gate };
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  * dn_lock is used to protect the driver initialization/loading
67*7c478bd9Sstevel@tonic-gate  * from fini/unloading. It also protects each drivers devops
68*7c478bd9Sstevel@tonic-gate  * reference count, the dn_flags, and the dn_head linked list of
69*7c478bd9Sstevel@tonic-gate  * driver instances. The busy_changing bit is used to avoid
70*7c478bd9Sstevel@tonic-gate  * recursive calls to ddi_hold_installed_driver to hold the
71*7c478bd9Sstevel@tonic-gate  * same driver.
72*7c478bd9Sstevel@tonic-gate  */
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate  * Defines for dn_flags.
76*7c478bd9Sstevel@tonic-gate  */
77*7c478bd9Sstevel@tonic-gate #define	DN_CONF_PARSED		0x0001
78*7c478bd9Sstevel@tonic-gate #define	DN_DRIVER_BUSY		0x0002	/* for ddi_hold_installed_driver */
79*7c478bd9Sstevel@tonic-gate #define	DN_DRIVER_HELD		0x0020	/* held via ddi_hold_installed_driver */
80*7c478bd9Sstevel@tonic-gate #define	DN_TAKEN_GETUDEV	0x0040	/* getudev() used this entry */
81*7c478bd9Sstevel@tonic-gate #define	DN_DRIVER_REMOVED	0x0080	/* driver entry removed */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate #define	DN_FORCE_ATTACH		0x0100	/* ddi-forceattach prop */
84*7c478bd9Sstevel@tonic-gate #define	DN_LEAF_DRIVER		0x0200	/* this is a leaf driver */
85*7c478bd9Sstevel@tonic-gate #define	DN_NETWORK_DRIVER	0x0400	/* network interface driver */
86*7c478bd9Sstevel@tonic-gate #define	DN_NO_AUTODETACH	0x0800	/* no autodetach */
87*7c478bd9Sstevel@tonic-gate #define	DN_GLDV3_DRIVER		0x1000	/* gldv3 (Nemo) driver */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /*
92*7c478bd9Sstevel@tonic-gate  * Debugging flags and macros
93*7c478bd9Sstevel@tonic-gate  */
94*7c478bd9Sstevel@tonic-gate #define	DDI_AUDIT		0x0001
95*7c478bd9Sstevel@tonic-gate #define	DDI_DEBUG		0x0002
96*7c478bd9Sstevel@tonic-gate #define	DDI_MTCONFIG		0x0004
97*7c478bd9Sstevel@tonic-gate #define	DDI_DEBUG_BOOTMOD	0x0008	/* module loading to mount root */
98*7c478bd9Sstevel@tonic-gate #define	DDI_DEBUG_COMPAT	0x0010	/* ddi_hold_install_driver */
99*7c478bd9Sstevel@tonic-gate #define	LDI_DBG_OPENCLOSE	0x0020	/* ldi open/close info */
100*7c478bd9Sstevel@tonic-gate #define	LDI_DBG_ALLOCFREE	0x0040	/* ldi ident alloc/free info */
101*7c478bd9Sstevel@tonic-gate #define	LDI_DBG_STREAMS		0x0080	/* ldi streams link/unlink */
102*7c478bd9Sstevel@tonic-gate #define	LDI_DBG_EVENTCB		0x0100	/* ldi event callback info */
103*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_API		0x0200	/* interrupt interface messages  */
104*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_IMPL		0x0400	/* interrupt implementation msgs */
105*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_NEXUS		0x0800	/* interrupt messages from nexuses */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate extern int ddidebug;
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
110*7c478bd9Sstevel@tonic-gate #define	NDI_CONFIG_DEBUG(args)	if (ddidebug & DDI_DEBUG) cmn_err args
111*7c478bd9Sstevel@tonic-gate #define	BMDPRINTF(args)		if (ddidebug & DDI_DEBUG_BOOTMOD) printf args
112*7c478bd9Sstevel@tonic-gate #define	DCOMPATPRINTF(args)	if (ddidebug & DDI_DEBUG_COMPAT) cmn_err args
113*7c478bd9Sstevel@tonic-gate #define	LDI_OPENCLOSE(args)	if (ddidebug & LDI_DBG_OPENCLOSE) cmn_err args
114*7c478bd9Sstevel@tonic-gate #define	LDI_ALLOCFREE(args)	if (ddidebug & LDI_DBG_ALLOCFREE) cmn_err args
115*7c478bd9Sstevel@tonic-gate #define	LDI_STREAMS_LNK(args)	if (ddidebug & LDI_DBG_STREAMS) cmn_err args
116*7c478bd9Sstevel@tonic-gate #define	LDI_EVENTCB(args)	if (ddidebug & LDI_DBG_EVENTCB) cmn_err args
117*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_APIDBG(args)	if (ddidebug & DDI_INTR_API) cmn_err args
118*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_IMPLDBG(args)	if (ddidebug & DDI_INTR_IMPL) cmn_err args
119*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_NEXDBG(args)	if (ddidebug & DDI_INTR_NEXUS) cmn_err args
120*7c478bd9Sstevel@tonic-gate #else
121*7c478bd9Sstevel@tonic-gate #define	NDI_CONFIG_DEBUG(args)
122*7c478bd9Sstevel@tonic-gate #define	BMDPRINTF(args)
123*7c478bd9Sstevel@tonic-gate #define	DCOMPATPRINTF(args)
124*7c478bd9Sstevel@tonic-gate #define	LDI_OPENCLOSE(args)
125*7c478bd9Sstevel@tonic-gate #define	LDI_ALLOCFREE(args)
126*7c478bd9Sstevel@tonic-gate #define	LDI_STREAMS_LNK(args)
127*7c478bd9Sstevel@tonic-gate #define	LDI_EVENTCB(args)
128*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_APIDBG(args)
129*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_IMPLDBG(args)
130*7c478bd9Sstevel@tonic-gate #define	DDI_INTR_NEXDBG(args)
131*7c478bd9Sstevel@tonic-gate #endif
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*
135*7c478bd9Sstevel@tonic-gate  * DDI configuration logs
136*7c478bd9Sstevel@tonic-gate  */
137*7c478bd9Sstevel@tonic-gate #define	DDI_STACK_DEPTH		14
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate typedef struct devinfo_audit {
140*7c478bd9Sstevel@tonic-gate 	dev_info_t		*da_devinfo;	/* address of devinfo node */
141*7c478bd9Sstevel@tonic-gate 	hrtime_t		da_timestamp;	/* audit time */
142*7c478bd9Sstevel@tonic-gate 	kthread_id_t		da_thread;	/* thread of transaction */
143*7c478bd9Sstevel@tonic-gate 	struct devinfo_audit	*da_lastlog;	/* last log of state change */
144*7c478bd9Sstevel@tonic-gate 	ddi_node_state_t	da_node_state;	/* devinfo state at log time */
145*7c478bd9Sstevel@tonic-gate 	int			da_device_state;	/* device state */
146*7c478bd9Sstevel@tonic-gate 	int			da_depth;
147*7c478bd9Sstevel@tonic-gate 	pc_t			da_stack[DDI_STACK_DEPTH];
148*7c478bd9Sstevel@tonic-gate } devinfo_audit_t;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate typedef struct {
151*7c478bd9Sstevel@tonic-gate 	kmutex_t	dh_lock;
152*7c478bd9Sstevel@tonic-gate 	int		dh_max;
153*7c478bd9Sstevel@tonic-gate 	int		dh_curr;
154*7c478bd9Sstevel@tonic-gate 	int		dh_hits;
155*7c478bd9Sstevel@tonic-gate 	devinfo_audit_t	dh_entry[1];
156*7c478bd9Sstevel@tonic-gate } devinfo_log_header_t;
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate struct di_cache {
159*7c478bd9Sstevel@tonic-gate 	uint32_t	cache_valid;	/* no lock needed - field atomic updt */
160*7c478bd9Sstevel@tonic-gate 	kmutex_t	cache_lock;	/* protects fields below */
161*7c478bd9Sstevel@tonic-gate 	void		*cache_data;
162*7c478bd9Sstevel@tonic-gate 	size_t		cache_size;
163*7c478bd9Sstevel@tonic-gate };
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate extern struct di_cache di_cache;
166*7c478bd9Sstevel@tonic-gate extern int di_cache_debug;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /*
169*7c478bd9Sstevel@tonic-gate  * Special dev_info nodes
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate #define	PSEUDO_PATH	"/"DEVI_PSEUDO_NEXNAME
172*7c478bd9Sstevel@tonic-gate #define	CLONE_PATH	PSEUDO_PATH"/clone@0"
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate #define	DI_CACHE_FILE	"/etc/devices/snapshot_cache"
175*7c478bd9Sstevel@tonic-gate #define	DI_CACHE_TEMP	DI_CACHE_FILE".tmp"
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate extern dev_info_t *options_dip;
178*7c478bd9Sstevel@tonic-gate extern dev_info_t *pseudo_dip;
179*7c478bd9Sstevel@tonic-gate extern dev_info_t *clone_dip;
180*7c478bd9Sstevel@tonic-gate extern major_t clone_major;
181*7c478bd9Sstevel@tonic-gate extern major_t mm_major;
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate extern struct devnames *devnamesp;
184*7c478bd9Sstevel@tonic-gate extern struct devnames orphanlist;
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate extern struct dev_ops nodev_ops, mod_nodev_ops;
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate /*
189*7c478bd9Sstevel@tonic-gate  * Obsolete interface, no longer used, to be removed.
190*7c478bd9Sstevel@tonic-gate  * Retained only for driver compatibility.
191*7c478bd9Sstevel@tonic-gate  */
192*7c478bd9Sstevel@tonic-gate extern krwlock_t devinfo_tree_lock;		/* obsolete */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate /*
195*7c478bd9Sstevel@tonic-gate  * Acquires dn_lock, as above.
196*7c478bd9Sstevel@tonic-gate  */
197*7c478bd9Sstevel@tonic-gate #define	LOCK_DEV_OPS(lp)	mutex_enter((lp))
198*7c478bd9Sstevel@tonic-gate #define	UNLOCK_DEV_OPS(lp)	mutex_exit((lp))
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /*
201*7c478bd9Sstevel@tonic-gate  * Not to be used without obtaining the per-driver lock.
202*7c478bd9Sstevel@tonic-gate  */
203*7c478bd9Sstevel@tonic-gate #define	INCR_DEV_OPS_REF(opsp)	(opsp)->devo_refcnt++
204*7c478bd9Sstevel@tonic-gate #define	DECR_DEV_OPS_REF(opsp)	(opsp)->devo_refcnt--
205*7c478bd9Sstevel@tonic-gate #define	CB_DRV_INSTALLED(opsp)	((opsp) != &nodev_ops && \
206*7c478bd9Sstevel@tonic-gate 				(opsp) != &mod_nodev_ops)
207*7c478bd9Sstevel@tonic-gate #define	DRV_UNLOADABLE(opsp)	((opsp)->devo_refcnt == 0)
208*7c478bd9Sstevel@tonic-gate #define	DEV_OPS_HELD(opsp)	((opsp)->devo_refcnt > 0)
209*7c478bd9Sstevel@tonic-gate #define	NEXUS_DRV(opsp)		((opsp)->devo_bus_ops != NULL)
210*7c478bd9Sstevel@tonic-gate #define	NETWORK_DRV(major)	(devnamesp[major].dn_flags & DN_NETWORK_DRIVER)
211*7c478bd9Sstevel@tonic-gate #define	GLDV3_DRV(major)	(devnamesp[major].dn_flags & DN_GLDV3_DRIVER)
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate extern void impl_rem_dev_props(dev_info_t *);
214*7c478bd9Sstevel@tonic-gate extern void add_class(char *, char *);
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate struct bind;
217*7c478bd9Sstevel@tonic-gate extern int make_mbind(char *, int, char *, struct bind **);
218*7c478bd9Sstevel@tonic-gate extern void delete_mbind(char *, struct bind **);
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate extern void configure(void);
221*7c478bd9Sstevel@tonic-gate #if defined(__sparc)
222*7c478bd9Sstevel@tonic-gate extern void setcputype(void);
223*7c478bd9Sstevel@tonic-gate #endif
224*7c478bd9Sstevel@tonic-gate extern void devtree_freeze(void);
225*7c478bd9Sstevel@tonic-gate extern void reset_leaves(void);
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate extern void setup_ddi(void);
228*7c478bd9Sstevel@tonic-gate extern void setup_ddi_poststartup(void);
229*7c478bd9Sstevel@tonic-gate extern void impl_ddi_callback_init(void);
230*7c478bd9Sstevel@tonic-gate extern void impl_fix_props(dev_info_t *, dev_info_t *, char *, int, caddr_t);
231*7c478bd9Sstevel@tonic-gate extern int impl_check_cpu(dev_info_t *);
232*7c478bd9Sstevel@tonic-gate extern int check_status(int, char *, dev_info_t *);
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate extern int exclude_settrap(int);
235*7c478bd9Sstevel@tonic-gate extern int exclude_level(int);
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate extern major_t path_to_major(char *);
238*7c478bd9Sstevel@tonic-gate extern void i_ddi_node_cache_init(void);
239*7c478bd9Sstevel@tonic-gate extern dev_info_t *i_ddi_alloc_node(dev_info_t *, char *, dnode_t, int,
240*7c478bd9Sstevel@tonic-gate     ddi_prop_t *, int);
241*7c478bd9Sstevel@tonic-gate extern void i_ddi_forceattach_drivers(void);
242*7c478bd9Sstevel@tonic-gate extern int i_ddi_io_initialized(void);
243*7c478bd9Sstevel@tonic-gate extern dev_info_t *i_ddi_create_branch(dev_info_t *, int);
244*7c478bd9Sstevel@tonic-gate extern void i_ddi_add_devimap(dev_info_t *dip);
245*7c478bd9Sstevel@tonic-gate extern void i_ddi_di_cache_invalidate(int kmflag);
246*7c478bd9Sstevel@tonic-gate extern void i_ddi_di_cache_free(struct di_cache *cache);
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate #endif
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate #endif /* _SYS_AUTOCONF_H */
255