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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_AUTOCONF_H 287c478bd9Sstevel@tonic-gate #define _SYS_AUTOCONF_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* Derived from autoconf.h, SunOS 4.1.1 1.15 */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #ifdef __cplusplus 357c478bd9Sstevel@tonic-gate extern "C" { 367c478bd9Sstevel@tonic-gate #endif 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * This defines a parallel structure to the devops list. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 437c478bd9Sstevel@tonic-gate #include <sys/devops.h> 447c478bd9Sstevel@tonic-gate #include <sys/mutex.h> 457c478bd9Sstevel@tonic-gate #include <sys/thread.h> 467c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h> 477c478bd9Sstevel@tonic-gate #include <sys/systm.h> 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate struct devnames { 507c478bd9Sstevel@tonic-gate char *dn_name; /* Name of this driver */ 517c478bd9Sstevel@tonic-gate int dn_flags; /* per-driver flags, see below */ 527c478bd9Sstevel@tonic-gate struct par_list *dn_pl; /* parent list, for making devinfos */ 537c478bd9Sstevel@tonic-gate kmutex_t dn_lock; /* Per driver lock (see below) */ 547c478bd9Sstevel@tonic-gate dev_info_t *dn_head; /* Head of instance list */ 557c478bd9Sstevel@tonic-gate int dn_instance; /* Next instance no. to assign */ 567c478bd9Sstevel@tonic-gate void *dn_inlist; /* instance # nodes for this driver */ 577c478bd9Sstevel@tonic-gate ddi_prop_list_t *dn_global_prop_ptr; /* per-driver global properties */ 587c478bd9Sstevel@tonic-gate kcondvar_t dn_wait; /* for ddi_hold_installed_driver */ 597c478bd9Sstevel@tonic-gate kthread_id_t dn_busy_thread; /* for debugging only */ 607c478bd9Sstevel@tonic-gate struct mperm *dn_mperm; /* minor permissions */ 617c478bd9Sstevel@tonic-gate struct mperm *dn_mperm_wild; /* default minor permission */ 627c478bd9Sstevel@tonic-gate struct mperm *dn_mperm_clone; /* minor permission, clone use */ 637c478bd9Sstevel@tonic-gate }; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate /* 667c478bd9Sstevel@tonic-gate * dn_lock is used to protect the driver initialization/loading 677c478bd9Sstevel@tonic-gate * from fini/unloading. It also protects each drivers devops 687c478bd9Sstevel@tonic-gate * reference count, the dn_flags, and the dn_head linked list of 697c478bd9Sstevel@tonic-gate * driver instances. The busy_changing bit is used to avoid 707c478bd9Sstevel@tonic-gate * recursive calls to ddi_hold_installed_driver to hold the 717c478bd9Sstevel@tonic-gate * same driver. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * Defines for dn_flags. 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate #define DN_CONF_PARSED 0x0001 787c478bd9Sstevel@tonic-gate #define DN_DRIVER_BUSY 0x0002 /* for ddi_hold_installed_driver */ 797c478bd9Sstevel@tonic-gate #define DN_DRIVER_HELD 0x0020 /* held via ddi_hold_installed_driver */ 807c478bd9Sstevel@tonic-gate #define DN_TAKEN_GETUDEV 0x0040 /* getudev() used this entry */ 817c478bd9Sstevel@tonic-gate #define DN_DRIVER_REMOVED 0x0080 /* driver entry removed */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate #define DN_FORCE_ATTACH 0x0100 /* ddi-forceattach prop */ 847c478bd9Sstevel@tonic-gate #define DN_LEAF_DRIVER 0x0200 /* this is a leaf driver */ 857c478bd9Sstevel@tonic-gate #define DN_NETWORK_DRIVER 0x0400 /* network interface driver */ 867c478bd9Sstevel@tonic-gate #define DN_NO_AUTODETACH 0x0800 /* no autodetach */ 877c478bd9Sstevel@tonic-gate #define DN_GLDV3_DRIVER 0x1000 /* gldv3 (Nemo) driver */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #ifdef _KERNEL 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * Debugging flags and macros 937c478bd9Sstevel@tonic-gate */ 947c478bd9Sstevel@tonic-gate #define DDI_AUDIT 0x0001 957c478bd9Sstevel@tonic-gate #define DDI_DEBUG 0x0002 967c478bd9Sstevel@tonic-gate #define DDI_MTCONFIG 0x0004 977c478bd9Sstevel@tonic-gate #define DDI_DEBUG_BOOTMOD 0x0008 /* module loading to mount root */ 987c478bd9Sstevel@tonic-gate #define DDI_DEBUG_COMPAT 0x0010 /* ddi_hold_install_driver */ 997c478bd9Sstevel@tonic-gate #define LDI_DBG_OPENCLOSE 0x0020 /* ldi open/close info */ 1007c478bd9Sstevel@tonic-gate #define LDI_DBG_ALLOCFREE 0x0040 /* ldi ident alloc/free info */ 1017c478bd9Sstevel@tonic-gate #define LDI_DBG_STREAMS 0x0080 /* ldi streams link/unlink */ 1027c478bd9Sstevel@tonic-gate #define LDI_DBG_EVENTCB 0x0100 /* ldi event callback info */ 1037c478bd9Sstevel@tonic-gate #define DDI_INTR_API 0x0200 /* interrupt interface messages */ 1047c478bd9Sstevel@tonic-gate #define DDI_INTR_IMPL 0x0400 /* interrupt implementation msgs */ 1057c478bd9Sstevel@tonic-gate #define DDI_INTR_NEXUS 0x0800 /* interrupt messages from nexuses */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate extern int ddidebug; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #ifdef DEBUG 1107c478bd9Sstevel@tonic-gate #define NDI_CONFIG_DEBUG(args) if (ddidebug & DDI_DEBUG) cmn_err args 1117c478bd9Sstevel@tonic-gate #define BMDPRINTF(args) if (ddidebug & DDI_DEBUG_BOOTMOD) printf args 1127c478bd9Sstevel@tonic-gate #define DCOMPATPRINTF(args) if (ddidebug & DDI_DEBUG_COMPAT) cmn_err args 1137c478bd9Sstevel@tonic-gate #define LDI_OPENCLOSE(args) if (ddidebug & LDI_DBG_OPENCLOSE) cmn_err args 1147c478bd9Sstevel@tonic-gate #define LDI_ALLOCFREE(args) if (ddidebug & LDI_DBG_ALLOCFREE) cmn_err args 1157c478bd9Sstevel@tonic-gate #define LDI_STREAMS_LNK(args) if (ddidebug & LDI_DBG_STREAMS) cmn_err args 1167c478bd9Sstevel@tonic-gate #define LDI_EVENTCB(args) if (ddidebug & LDI_DBG_EVENTCB) cmn_err args 1177c478bd9Sstevel@tonic-gate #define DDI_INTR_APIDBG(args) if (ddidebug & DDI_INTR_API) cmn_err args 1187c478bd9Sstevel@tonic-gate #define DDI_INTR_IMPLDBG(args) if (ddidebug & DDI_INTR_IMPL) cmn_err args 1197c478bd9Sstevel@tonic-gate #define DDI_INTR_NEXDBG(args) if (ddidebug & DDI_INTR_NEXUS) cmn_err args 1207c478bd9Sstevel@tonic-gate #else 1217c478bd9Sstevel@tonic-gate #define NDI_CONFIG_DEBUG(args) 1227c478bd9Sstevel@tonic-gate #define BMDPRINTF(args) 1237c478bd9Sstevel@tonic-gate #define DCOMPATPRINTF(args) 1247c478bd9Sstevel@tonic-gate #define LDI_OPENCLOSE(args) 1257c478bd9Sstevel@tonic-gate #define LDI_ALLOCFREE(args) 1267c478bd9Sstevel@tonic-gate #define LDI_STREAMS_LNK(args) 1277c478bd9Sstevel@tonic-gate #define LDI_EVENTCB(args) 1287c478bd9Sstevel@tonic-gate #define DDI_INTR_APIDBG(args) 1297c478bd9Sstevel@tonic-gate #define DDI_INTR_IMPLDBG(args) 1307c478bd9Sstevel@tonic-gate #define DDI_INTR_NEXDBG(args) 1317c478bd9Sstevel@tonic-gate #endif 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate /* 1357c478bd9Sstevel@tonic-gate * DDI configuration logs 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate #define DDI_STACK_DEPTH 14 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate typedef struct devinfo_audit { 1407c478bd9Sstevel@tonic-gate dev_info_t *da_devinfo; /* address of devinfo node */ 1417c478bd9Sstevel@tonic-gate hrtime_t da_timestamp; /* audit time */ 1427c478bd9Sstevel@tonic-gate kthread_id_t da_thread; /* thread of transaction */ 1437c478bd9Sstevel@tonic-gate struct devinfo_audit *da_lastlog; /* last log of state change */ 1447c478bd9Sstevel@tonic-gate ddi_node_state_t da_node_state; /* devinfo state at log time */ 1457c478bd9Sstevel@tonic-gate int da_device_state; /* device state */ 1467c478bd9Sstevel@tonic-gate int da_depth; 1477c478bd9Sstevel@tonic-gate pc_t da_stack[DDI_STACK_DEPTH]; 1487c478bd9Sstevel@tonic-gate } devinfo_audit_t; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate typedef struct { 1517c478bd9Sstevel@tonic-gate kmutex_t dh_lock; 1527c478bd9Sstevel@tonic-gate int dh_max; 1537c478bd9Sstevel@tonic-gate int dh_curr; 1547c478bd9Sstevel@tonic-gate int dh_hits; 1557c478bd9Sstevel@tonic-gate devinfo_audit_t dh_entry[1]; 1567c478bd9Sstevel@tonic-gate } devinfo_log_header_t; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate struct di_cache { 1597c478bd9Sstevel@tonic-gate uint32_t cache_valid; /* no lock needed - field atomic updt */ 1607c478bd9Sstevel@tonic-gate kmutex_t cache_lock; /* protects fields below */ 1617c478bd9Sstevel@tonic-gate void *cache_data; 1627c478bd9Sstevel@tonic-gate size_t cache_size; 1637c478bd9Sstevel@tonic-gate }; 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate extern struct di_cache di_cache; 1667c478bd9Sstevel@tonic-gate extern int di_cache_debug; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate /* 1697c478bd9Sstevel@tonic-gate * Special dev_info nodes 1707c478bd9Sstevel@tonic-gate */ 1717c478bd9Sstevel@tonic-gate #define PSEUDO_PATH "/"DEVI_PSEUDO_NEXNAME 1727c478bd9Sstevel@tonic-gate #define CLONE_PATH PSEUDO_PATH"/clone@0" 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate #define DI_CACHE_FILE "/etc/devices/snapshot_cache" 1757c478bd9Sstevel@tonic-gate #define DI_CACHE_TEMP DI_CACHE_FILE".tmp" 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate extern dev_info_t *options_dip; 1787c478bd9Sstevel@tonic-gate extern dev_info_t *pseudo_dip; 1797c478bd9Sstevel@tonic-gate extern dev_info_t *clone_dip; 1807c478bd9Sstevel@tonic-gate extern major_t clone_major; 1817c478bd9Sstevel@tonic-gate extern major_t mm_major; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate extern struct devnames *devnamesp; 1847c478bd9Sstevel@tonic-gate extern struct devnames orphanlist; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate extern struct dev_ops nodev_ops, mod_nodev_ops; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* 1897c478bd9Sstevel@tonic-gate * Obsolete interface, no longer used, to be removed. 1907c478bd9Sstevel@tonic-gate * Retained only for driver compatibility. 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate extern krwlock_t devinfo_tree_lock; /* obsolete */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate * Acquires dn_lock, as above. 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate #define LOCK_DEV_OPS(lp) mutex_enter((lp)) 1987c478bd9Sstevel@tonic-gate #define UNLOCK_DEV_OPS(lp) mutex_exit((lp)) 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * Not to be used without obtaining the per-driver lock. 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate #define INCR_DEV_OPS_REF(opsp) (opsp)->devo_refcnt++ 2047c478bd9Sstevel@tonic-gate #define DECR_DEV_OPS_REF(opsp) (opsp)->devo_refcnt-- 2057c478bd9Sstevel@tonic-gate #define CB_DRV_INSTALLED(opsp) ((opsp) != &nodev_ops && \ 2067c478bd9Sstevel@tonic-gate (opsp) != &mod_nodev_ops) 2077c478bd9Sstevel@tonic-gate #define DRV_UNLOADABLE(opsp) ((opsp)->devo_refcnt == 0) 2087c478bd9Sstevel@tonic-gate #define DEV_OPS_HELD(opsp) ((opsp)->devo_refcnt > 0) 2097c478bd9Sstevel@tonic-gate #define NEXUS_DRV(opsp) ((opsp)->devo_bus_ops != NULL) 2107c478bd9Sstevel@tonic-gate #define NETWORK_DRV(major) (devnamesp[major].dn_flags & DN_NETWORK_DRIVER) 2117c478bd9Sstevel@tonic-gate #define GLDV3_DRV(major) (devnamesp[major].dn_flags & DN_GLDV3_DRIVER) 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate extern void impl_rem_dev_props(dev_info_t *); 2147c478bd9Sstevel@tonic-gate extern void add_class(char *, char *); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate struct bind; 2177c478bd9Sstevel@tonic-gate extern int make_mbind(char *, int, char *, struct bind **); 2187c478bd9Sstevel@tonic-gate extern void delete_mbind(char *, struct bind **); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate extern void configure(void); 2217c478bd9Sstevel@tonic-gate #if defined(__sparc) 2227c478bd9Sstevel@tonic-gate extern void setcputype(void); 2237c478bd9Sstevel@tonic-gate #endif 2247c478bd9Sstevel@tonic-gate extern void devtree_freeze(void); 2257c478bd9Sstevel@tonic-gate extern void reset_leaves(void); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate extern void setup_ddi(void); 2287c478bd9Sstevel@tonic-gate extern void setup_ddi_poststartup(void); 2297c478bd9Sstevel@tonic-gate extern void impl_ddi_callback_init(void); 2307c478bd9Sstevel@tonic-gate extern void impl_fix_props(dev_info_t *, dev_info_t *, char *, int, caddr_t); 2317c478bd9Sstevel@tonic-gate extern int impl_check_cpu(dev_info_t *); 2327c478bd9Sstevel@tonic-gate extern int check_status(int, char *, dev_info_t *); 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate extern int exclude_settrap(int); 2357c478bd9Sstevel@tonic-gate extern int exclude_level(int); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate extern major_t path_to_major(char *); 2387c478bd9Sstevel@tonic-gate extern void i_ddi_node_cache_init(void); 239*fa9e4066Sahrens extern dev_info_t *i_ddi_alloc_node(dev_info_t *, char *, pnode_t, int, 2407c478bd9Sstevel@tonic-gate ddi_prop_t *, int); 2417c478bd9Sstevel@tonic-gate extern void i_ddi_forceattach_drivers(void); 2427c478bd9Sstevel@tonic-gate extern int i_ddi_io_initialized(void); 2437c478bd9Sstevel@tonic-gate extern dev_info_t *i_ddi_create_branch(dev_info_t *, int); 2447c478bd9Sstevel@tonic-gate extern void i_ddi_add_devimap(dev_info_t *dip); 2457c478bd9Sstevel@tonic-gate extern void i_ddi_di_cache_invalidate(int kmflag); 2467c478bd9Sstevel@tonic-gate extern void i_ddi_di_cache_free(struct di_cache *cache); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate #endif 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate #endif /* _SYS_AUTOCONF_H */ 255