10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52621Sllai1 * Common Development and Distribution License (the "License"). 62621Sllai1 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*12588SJerry.Gilliam@Sun.COM * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate */ 240Sstevel@tonic-gate 250Sstevel@tonic-gate #ifndef _SYS_MODCTL_H 260Sstevel@tonic-gate #define _SYS_MODCTL_H 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * loadable module support. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/ioccom.h> 340Sstevel@tonic-gate #include <sys/nexusdefs.h> 350Sstevel@tonic-gate #include <sys/thread.h> 360Sstevel@tonic-gate #include <sys/t_lock.h> 370Sstevel@tonic-gate #include <sys/dditypes.h> 380Sstevel@tonic-gate #include <sys/hwconf.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * The following structure defines the operations used by modctl 460Sstevel@tonic-gate * to load and unload modules. Each supported loadable module type 470Sstevel@tonic-gate * requires a set of mod_ops. 480Sstevel@tonic-gate */ 490Sstevel@tonic-gate struct mod_ops { 500Sstevel@tonic-gate int (*modm_install)(); /* install module in kernel */ 510Sstevel@tonic-gate int (*modm_remove)(); /* remove from kernel */ 520Sstevel@tonic-gate int (*modm_info)(); /* module info */ 530Sstevel@tonic-gate }; 540Sstevel@tonic-gate 550Sstevel@tonic-gate #ifdef _KERNEL 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* 580Sstevel@tonic-gate * The defined set of mod_ops structures for each loadable module type 590Sstevel@tonic-gate * Defined in modctl.c 600Sstevel@tonic-gate */ 612712Snn35248 extern struct mod_ops mod_brandops; 621414Scindi #if defined(__i386) || defined(__amd64) 631414Scindi extern struct mod_ops mod_cpuops; 641414Scindi #endif 650Sstevel@tonic-gate extern struct mod_ops mod_cryptoops; 660Sstevel@tonic-gate extern struct mod_ops mod_driverops; 670Sstevel@tonic-gate extern struct mod_ops mod_execops; 680Sstevel@tonic-gate extern struct mod_ops mod_fsops; 690Sstevel@tonic-gate extern struct mod_ops mod_miscops; 700Sstevel@tonic-gate extern struct mod_ops mod_schedops; 710Sstevel@tonic-gate extern struct mod_ops mod_strmodops; 720Sstevel@tonic-gate extern struct mod_ops mod_syscallops; 738348SEric.Yu@Sun.COM extern struct mod_ops mod_sockmodops; 740Sstevel@tonic-gate #ifdef _SYSCALL32_IMPL 750Sstevel@tonic-gate extern struct mod_ops mod_syscallops32; 760Sstevel@tonic-gate #endif 770Sstevel@tonic-gate extern struct mod_ops mod_dacfops; 780Sstevel@tonic-gate extern struct mod_ops mod_ippops; 790Sstevel@tonic-gate extern struct mod_ops mod_pcbeops; 805206Sis extern struct mod_ops mod_kiconvops; 810Sstevel@tonic-gate 820Sstevel@tonic-gate #endif /* _KERNEL */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* 850Sstevel@tonic-gate * Definitions for the module specific linkage structures. 860Sstevel@tonic-gate * The first two fields are the same in all of the structures. 870Sstevel@tonic-gate * The linkinfo is for informational purposes only and is returned by 880Sstevel@tonic-gate * modctl with the MODINFO cmd. 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* For drivers */ 920Sstevel@tonic-gate struct modldrv { 930Sstevel@tonic-gate struct mod_ops *drv_modops; 940Sstevel@tonic-gate char *drv_linkinfo; 950Sstevel@tonic-gate struct dev_ops *drv_dev_ops; 960Sstevel@tonic-gate }; 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* For system calls */ 990Sstevel@tonic-gate struct modlsys { 1000Sstevel@tonic-gate struct mod_ops *sys_modops; 1010Sstevel@tonic-gate char *sys_linkinfo; 1020Sstevel@tonic-gate struct sysent *sys_sysent; 1030Sstevel@tonic-gate }; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* For filesystems */ 1060Sstevel@tonic-gate struct modlfs { 1070Sstevel@tonic-gate struct mod_ops *fs_modops; 1080Sstevel@tonic-gate char *fs_linkinfo; 1096264Srm15945 struct vfsdef_v5 *fs_vfsdef; /* version may actually vary */ 1100Sstevel@tonic-gate }; 1110Sstevel@tonic-gate 1121414Scindi #if defined(__i386) || defined(__amd64) 1131414Scindi struct cmi_ops; 1141414Scindi 1151414Scindi /* For CPU modules */ 1161414Scindi struct modlcpu { 1171414Scindi struct mod_ops *cpu_modops; 1181414Scindi char *cpu_linkinfo; 1191414Scindi struct cmi_ops *cpu_cmiops; 1201414Scindi }; 1211414Scindi #endif 1221414Scindi 1230Sstevel@tonic-gate /* For cryptographic providers */ 1240Sstevel@tonic-gate struct modlcrypto { 1250Sstevel@tonic-gate struct mod_ops *crypto_modops; 1260Sstevel@tonic-gate char *crypto_linkinfo; 1270Sstevel@tonic-gate }; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* For misc */ 1300Sstevel@tonic-gate struct modlmisc { 1310Sstevel@tonic-gate struct mod_ops *misc_modops; 1320Sstevel@tonic-gate char *misc_linkinfo; 1330Sstevel@tonic-gate }; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* For IP Modules */ 1360Sstevel@tonic-gate struct modlipp { 1370Sstevel@tonic-gate struct mod_ops *ipp_modops; 1380Sstevel@tonic-gate char *ipp_linkinfo; 1390Sstevel@tonic-gate struct ipp_ops *ipp_ops; 1400Sstevel@tonic-gate }; 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate /* For Streams Modules. */ 1430Sstevel@tonic-gate struct modlstrmod { 1440Sstevel@tonic-gate struct mod_ops *strmod_modops; 1450Sstevel@tonic-gate char *strmod_linkinfo; 1460Sstevel@tonic-gate struct fmodsw *strmod_fmodsw; 1470Sstevel@tonic-gate }; 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* For Scheduling classes */ 1500Sstevel@tonic-gate struct modlsched { 1510Sstevel@tonic-gate struct mod_ops *sched_modops; 1520Sstevel@tonic-gate char *sched_linkinfo; 1530Sstevel@tonic-gate struct sclass *sched_class; 1540Sstevel@tonic-gate }; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* For Exec file type (like ELF, ...) */ 1570Sstevel@tonic-gate struct modlexec { 1580Sstevel@tonic-gate struct mod_ops *exec_modops; 1590Sstevel@tonic-gate char *exec_linkinfo; 1600Sstevel@tonic-gate struct execsw *exec_execsw; 1610Sstevel@tonic-gate }; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* For dacf modules */ 1640Sstevel@tonic-gate struct modldacf { 1650Sstevel@tonic-gate struct mod_ops *dacf_modops; 1660Sstevel@tonic-gate char *dacf_linkinfo; 1670Sstevel@tonic-gate struct dacfsw *dacf_dacfsw; 1680Sstevel@tonic-gate }; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* For PCBE modules */ 1710Sstevel@tonic-gate struct modlpcbe { 1720Sstevel@tonic-gate struct mod_ops *pcbe_modops; 1730Sstevel@tonic-gate char *pcbe_linkinfo; 1740Sstevel@tonic-gate struct __pcbe_ops *pcbe_ops; 1750Sstevel@tonic-gate }; 1760Sstevel@tonic-gate 1772712Snn35248 /* For Brand modules */ 1782712Snn35248 struct modlbrand { 1792712Snn35248 struct mod_ops *brand_modops; 1802712Snn35248 char *brand_linkinfo; 1812712Snn35248 struct brand *brand_branddef; 1822712Snn35248 }; 1832712Snn35248 1848348SEric.Yu@Sun.COM /* For socket Modules. */ 1858348SEric.Yu@Sun.COM struct modlsockmod { 1868348SEric.Yu@Sun.COM struct mod_ops *sockmod_modops; 1878348SEric.Yu@Sun.COM char *sockmod_linkinfo; 1888348SEric.Yu@Sun.COM struct smod_reg_s *sockmod_reg_info; 1898348SEric.Yu@Sun.COM }; 1908348SEric.Yu@Sun.COM 1915206Sis /* For kiconv modules */ 1925206Sis struct modlkiconv { 1935206Sis struct mod_ops *kiconv_modops; 1945206Sis char *kiconv_linkinfo; 1955206Sis struct kiconv_mod_info *kiconv_moddef; 1965206Sis }; 1975206Sis 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * Revision number of loadable modules support. This is the value 2000Sstevel@tonic-gate * that must be used in the modlinkage structure. 2010Sstevel@tonic-gate */ 2020Sstevel@tonic-gate #define MODREV_1 1 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * The modlinkage structure is the structure that the module writer 2060Sstevel@tonic-gate * provides to the routines to install, remove, and stat a module. 2070Sstevel@tonic-gate * The ml_linkage element is an array of pointers to linkage structures. 2080Sstevel@tonic-gate * For most modules there is only one linkage structure. We allocate 2090Sstevel@tonic-gate * enough space for 3 linkage structures which happens to be the most 2100Sstevel@tonic-gate * we have in any sun supplied module. For those modules with more 2110Sstevel@tonic-gate * than 3 linkage structures (which is very unlikely), a modlinkage 2120Sstevel@tonic-gate * structure must be kmem_alloc'd in the module wrapper to be big enough 2130Sstevel@tonic-gate * for all of the linkage structures. 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate struct modlinkage { 2160Sstevel@tonic-gate int ml_rev; /* rev of loadable modules system */ 2170Sstevel@tonic-gate #ifdef _LP64 2180Sstevel@tonic-gate void *ml_linkage[7]; /* more space in 64-bit OS */ 2190Sstevel@tonic-gate #else 2200Sstevel@tonic-gate void *ml_linkage[4]; /* NULL terminated list of */ 2210Sstevel@tonic-gate /* linkage structures */ 2220Sstevel@tonic-gate #endif 2230Sstevel@tonic-gate }; 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* 2260Sstevel@tonic-gate * commands. These are the commands supported by the modctl system call. 2270Sstevel@tonic-gate */ 2280Sstevel@tonic-gate #define MODLOAD 0 2290Sstevel@tonic-gate #define MODUNLOAD 1 2300Sstevel@tonic-gate #define MODINFO 2 2310Sstevel@tonic-gate #define MODRESERVED 3 2320Sstevel@tonic-gate #define MODSETMINIROOT 4 2330Sstevel@tonic-gate #define MODADDMAJBIND 5 2340Sstevel@tonic-gate #define MODGETPATH 6 2350Sstevel@tonic-gate #define MODREADSYSBIND 7 2360Sstevel@tonic-gate #define MODGETMAJBIND 8 2370Sstevel@tonic-gate #define MODGETNAME 9 2380Sstevel@tonic-gate #define MODSIZEOF_DEVID 10 2390Sstevel@tonic-gate #define MODGETDEVID 11 2400Sstevel@tonic-gate #define MODSIZEOF_MINORNAME 12 2410Sstevel@tonic-gate #define MODGETMINORNAME 13 2420Sstevel@tonic-gate #define MODGETPATHLEN 14 2430Sstevel@tonic-gate #define MODEVENTS 15 2440Sstevel@tonic-gate #define MODGETFBNAME 16 2450Sstevel@tonic-gate #define MODREREADDACF 17 2460Sstevel@tonic-gate #define MODLOADDRVCONF 18 2470Sstevel@tonic-gate #define MODUNLOADDRVCONF 19 2480Sstevel@tonic-gate #define MODREMMAJBIND 20 2490Sstevel@tonic-gate #define MODDEVT2INSTANCE 21 2500Sstevel@tonic-gate #define MODGETDEVFSPATH_LEN 22 2510Sstevel@tonic-gate #define MODGETDEVFSPATH 23 2520Sstevel@tonic-gate #define MODDEVID2PATHS 24 2530Sstevel@tonic-gate #define MODSETDEVPOLICY 26 2540Sstevel@tonic-gate #define MODGETDEVPOLICY 27 2550Sstevel@tonic-gate #define MODALLOCPRIV 28 2560Sstevel@tonic-gate #define MODGETDEVPOLICYBYNAME 29 2570Sstevel@tonic-gate #define MODLOADMINORPERM 31 2580Sstevel@tonic-gate #define MODADDMINORPERM 32 2590Sstevel@tonic-gate #define MODREMMINORPERM 33 2600Sstevel@tonic-gate #define MODREMDRVCLEANUP 34 2612621Sllai1 #define MODDEVEXISTS 35 2622621Sllai1 #define MODDEVREADDIR 36 2632621Sllai1 #define MODDEVNAME 37 2642723Scth #define MODGETDEVFSPATH_MI_LEN 38 2652723Scth #define MODGETDEVFSPATH_MI 39 2664845Svikram #define MODRETIRE 40 2674845Svikram #define MODUNRETIRE 41 2684845Svikram #define MODISRETIRED 42 2696065Scth #define MODDEVEMPTYDIR 43 2708831SJerry.Gilliam@Sun.COM #define MODREMDRVALIAS 44 27110923SEvan.Yan@Sun.COM #define MODHPOPS 45 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * sub cmds for MODEVENTS 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate #define MODEVENTS_FLUSH 0 2770Sstevel@tonic-gate #define MODEVENTS_FLUSH_DUMP 1 2780Sstevel@tonic-gate #define MODEVENTS_SET_DOOR_UPCALL_FILENAME 2 2790Sstevel@tonic-gate #define MODEVENTS_GETDATA 3 2800Sstevel@tonic-gate #define MODEVENTS_FREEDATA 4 2810Sstevel@tonic-gate #define MODEVENTS_POST_EVENT 5 2820Sstevel@tonic-gate #define MODEVENTS_REGISTER_EVENT 6 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* 2852621Sllai1 * devname subcmds for MODDEVNAME 2862621Sllai1 */ 2872621Sllai1 #define MODDEVNAME_LOOKUPDOOR 0 2882621Sllai1 #define MODDEVNAME_PROFILE 3 2892621Sllai1 #define MODDEVNAME_RECONFIG 4 2902621Sllai1 #define MODDEVNAME_SYSAVAIL 5 2912621Sllai1 29210923SEvan.Yan@Sun.COM /* 29310923SEvan.Yan@Sun.COM * subcmds for MODHPOPS 29410923SEvan.Yan@Sun.COM */ 29510923SEvan.Yan@Sun.COM #define MODHPOPS_CHANGE_STATE 0 29610923SEvan.Yan@Sun.COM #define MODHPOPS_CREATE_PORT 1 29710923SEvan.Yan@Sun.COM #define MODHPOPS_REMOVE_PORT 2 29810923SEvan.Yan@Sun.COM #define MODHPOPS_BUS_GET 3 29910923SEvan.Yan@Sun.COM #define MODHPOPS_BUS_SET 4 30010923SEvan.Yan@Sun.COM 3012621Sllai1 3022621Sllai1 /* 3030Sstevel@tonic-gate * Data structure passed to modconfig command in kernel to build devfs tree 3040Sstevel@tonic-gate */ 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate struct aliases { 3070Sstevel@tonic-gate struct aliases *a_next; 3080Sstevel@tonic-gate char *a_name; 3090Sstevel@tonic-gate int a_len; 3100Sstevel@tonic-gate }; 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate #define MAXMODCONFNAME 256 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate struct modconfig { 3150Sstevel@tonic-gate char drvname[MAXMODCONFNAME]; 3160Sstevel@tonic-gate char drvclass[MAXMODCONFNAME]; 3170Sstevel@tonic-gate int major; 3188831SJerry.Gilliam@Sun.COM int flags; 3190Sstevel@tonic-gate int num_aliases; 3200Sstevel@tonic-gate struct aliases *ap; 3210Sstevel@tonic-gate }; 3220Sstevel@tonic-gate 3230Sstevel@tonic-gate #if defined(_SYSCALL32) 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate struct aliases32 { 3260Sstevel@tonic-gate caddr32_t a_next; 3270Sstevel@tonic-gate caddr32_t a_name; 3280Sstevel@tonic-gate int32_t a_len; 3290Sstevel@tonic-gate }; 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate struct modconfig32 { 3320Sstevel@tonic-gate char drvname[MAXMODCONFNAME]; 3330Sstevel@tonic-gate char drvclass[MAXMODCONFNAME]; 3340Sstevel@tonic-gate int32_t major; 3358831SJerry.Gilliam@Sun.COM int32_t flags; 3360Sstevel@tonic-gate int32_t num_aliases; 3370Sstevel@tonic-gate caddr32_t ap; 3380Sstevel@tonic-gate }; 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate #endif /* _SYSCALL32 */ 3410Sstevel@tonic-gate 3428831SJerry.Gilliam@Sun.COM /* flags for modconfig */ 3438831SJerry.Gilliam@Sun.COM #define MOD_UNBIND_OVERRIDE 0x01 /* fail unbind if in use */ 34410842SJerry.Gilliam@Sun.COM #define MOD_ADDMAJBIND_UPDATE 0x02 /* update only, do not load */ 34510842SJerry.Gilliam@Sun.COM 34610842SJerry.Gilliam@Sun.COM /* flags for MODLOADDRVCONF - modctl_load_drvconf() */ 34710842SJerry.Gilliam@Sun.COM #define MOD_LOADDRVCONF_RECONF 0x01 /* complete configuration */ 34810842SJerry.Gilliam@Sun.COM /* after update-only */ 3498831SJerry.Gilliam@Sun.COM 3500Sstevel@tonic-gate /* 3510Sstevel@tonic-gate * Max module path length 3520Sstevel@tonic-gate */ 3530Sstevel@tonic-gate #define MOD_MAXPATH 256 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* 3560Sstevel@tonic-gate * Default search path for modules ADDITIONAL to the directory 3570Sstevel@tonic-gate * where the kernel components we booted from are. 3580Sstevel@tonic-gate * 3590Sstevel@tonic-gate * Most often, this will be "/platform/{platform}/kernel /kernel /usr/kernel", 3600Sstevel@tonic-gate * but we don't wire it down here. 3610Sstevel@tonic-gate */ 3620Sstevel@tonic-gate #define MOD_DEFPATH "/kernel /usr/kernel" 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate /* 3650Sstevel@tonic-gate * Default file name extension for autoloading modules. 3660Sstevel@tonic-gate */ 3670Sstevel@tonic-gate #define MOD_DEFEXT "" 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate /* 3700Sstevel@tonic-gate * Parameters for modinfo 3710Sstevel@tonic-gate */ 3720Sstevel@tonic-gate #define MODMAXNAMELEN 32 /* max module name length */ 3730Sstevel@tonic-gate #define MODMAXLINKINFOLEN 32 /* max link info length */ 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate /* 3760Sstevel@tonic-gate * Module specific information. 3770Sstevel@tonic-gate */ 3780Sstevel@tonic-gate struct modspecific_info { 3790Sstevel@tonic-gate char msi_linkinfo[MODMAXLINKINFOLEN]; /* name in linkage struct */ 3800Sstevel@tonic-gate int msi_p0; /* module specific information */ 3810Sstevel@tonic-gate }; 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Structure returned by modctl with MODINFO command. 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate #define MODMAXLINK 10 /* max linkages modinfo can handle */ 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate struct modinfo { 3890Sstevel@tonic-gate int mi_info; /* Flags for info wanted */ 3900Sstevel@tonic-gate int mi_state; /* Flags for module state */ 3910Sstevel@tonic-gate int mi_id; /* id of this loaded module */ 3920Sstevel@tonic-gate int mi_nextid; /* id of next module or -1 */ 3930Sstevel@tonic-gate caddr_t mi_base; /* virtual addr of text */ 3940Sstevel@tonic-gate size_t mi_size; /* size of module in bytes */ 3950Sstevel@tonic-gate int mi_rev; /* loadable modules rev */ 3960Sstevel@tonic-gate int mi_loadcnt; /* # of times loaded */ 3970Sstevel@tonic-gate char mi_name[MODMAXNAMELEN]; /* name of module */ 3980Sstevel@tonic-gate struct modspecific_info mi_msinfo[MODMAXLINK]; 3990Sstevel@tonic-gate /* mod specific info */ 4000Sstevel@tonic-gate }; 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate #if defined(_SYSCALL32) 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate #define MODMAXNAMELEN32 32 /* max module name length */ 4060Sstevel@tonic-gate #define MODMAXLINKINFOLEN32 32 /* max link info length */ 4070Sstevel@tonic-gate #define MODMAXLINK32 10 /* max linkages modinfo can handle */ 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate struct modspecific_info32 { 4100Sstevel@tonic-gate char msi_linkinfo[MODMAXLINKINFOLEN32]; /* name in linkage struct */ 4110Sstevel@tonic-gate int32_t msi_p0; /* module specific information */ 4120Sstevel@tonic-gate }; 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate struct modinfo32 { 4150Sstevel@tonic-gate int32_t mi_info; /* Flags for info wanted */ 4160Sstevel@tonic-gate int32_t mi_state; /* Flags for module state */ 4170Sstevel@tonic-gate int32_t mi_id; /* id of this loaded module */ 4180Sstevel@tonic-gate int32_t mi_nextid; /* id of next module or -1 */ 4190Sstevel@tonic-gate caddr32_t mi_base; /* virtual addr of text */ 4200Sstevel@tonic-gate uint32_t mi_size; /* size of module in bytes */ 4210Sstevel@tonic-gate int32_t mi_rev; /* loadable modules rev */ 4220Sstevel@tonic-gate int32_t mi_loadcnt; /* # of times loaded */ 4230Sstevel@tonic-gate char mi_name[MODMAXNAMELEN32]; /* name of module */ 4240Sstevel@tonic-gate struct modspecific_info32 mi_msinfo[MODMAXLINK32]; 4250Sstevel@tonic-gate /* mod specific info */ 4260Sstevel@tonic-gate }; 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate #endif /* _SYSCALL32 */ 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* Values for mi_info flags */ 4310Sstevel@tonic-gate #define MI_INFO_ONE 1 4320Sstevel@tonic-gate #define MI_INFO_ALL 2 4330Sstevel@tonic-gate #define MI_INFO_CNT 4 4340Sstevel@tonic-gate #ifdef _KERNEL 4350Sstevel@tonic-gate #define MI_INFO_LINKAGE 8 /* used internally to extract modlinkage */ 4360Sstevel@tonic-gate #endif 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * MI_INFO_NOBASE indicates caller does not need mi_base. Failure to use this 4390Sstevel@tonic-gate * flag may lead 32-bit apps to receive an EOVERFLOW error from modctl(MODINFO) 4400Sstevel@tonic-gate * when used with a 64-bit kernel. 4410Sstevel@tonic-gate */ 4420Sstevel@tonic-gate #define MI_INFO_NOBASE 16 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* Values for mi_state */ 4450Sstevel@tonic-gate #define MI_LOADED 1 4460Sstevel@tonic-gate #define MI_INSTALLED 2 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate /* 4490Sstevel@tonic-gate * Macros to vector to the appropriate module specific routine. 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate #define MODL_INSTALL(MODL, MODLP) \ 4520Sstevel@tonic-gate (*(MODL)->misc_modops->modm_install)(MODL, MODLP) 4530Sstevel@tonic-gate #define MODL_REMOVE(MODL, MODLP) \ 4540Sstevel@tonic-gate (*(MODL)->misc_modops->modm_remove)(MODL, MODLP) 4550Sstevel@tonic-gate #define MODL_INFO(MODL, MODLP, P0) \ 4560Sstevel@tonic-gate (*(MODL)->misc_modops->modm_info)(MODL, MODLP, P0) 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* 4590Sstevel@tonic-gate * Definitions for stubs 4600Sstevel@tonic-gate */ 4610Sstevel@tonic-gate struct mod_stub_info { 4620Sstevel@tonic-gate uintptr_t mods_func_adr; 4630Sstevel@tonic-gate struct mod_modinfo *mods_modinfo; 4640Sstevel@tonic-gate uintptr_t mods_stub_adr; 4650Sstevel@tonic-gate int (*mods_errfcn)(); 4660Sstevel@tonic-gate int mods_flag; /* flags defined below */ 4670Sstevel@tonic-gate }; 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate /* 4700Sstevel@tonic-gate * Definitions for mods_flag. 4710Sstevel@tonic-gate */ 4720Sstevel@tonic-gate #define MODS_WEAK 0x01 /* weak stub (not loaded if called) */ 4730Sstevel@tonic-gate #define MODS_NOUNLOAD 0x02 /* module not unloadable (no _fini()) */ 4740Sstevel@tonic-gate #define MODS_INSTALLED 0x10 /* module installed */ 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate struct mod_modinfo { 4770Sstevel@tonic-gate char *modm_module_name; 4780Sstevel@tonic-gate struct modctl *mp; 4790Sstevel@tonic-gate struct mod_stub_info modm_stubs[1]; 4800Sstevel@tonic-gate }; 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate struct modctl_list { 4830Sstevel@tonic-gate struct modctl_list *modl_next; 4840Sstevel@tonic-gate struct modctl *modl_modp; 4850Sstevel@tonic-gate }; 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* 4880Sstevel@tonic-gate * Structure to manage a loadable module. 4890Sstevel@tonic-gate * Note: the module (mod_mp) structure's "text" and "text_size" information 4900Sstevel@tonic-gate * are replicated in the modctl structure so that mod_containing_pc() 4910Sstevel@tonic-gate * doesn't have to grab any locks (modctls are persistent; modules are not.) 4920Sstevel@tonic-gate */ 4931414Scindi typedef struct modctl { 4940Sstevel@tonic-gate struct modctl *mod_next; /* &modules based list */ 4950Sstevel@tonic-gate struct modctl *mod_prev; 4960Sstevel@tonic-gate int mod_id; 4970Sstevel@tonic-gate void *mod_mp; 4980Sstevel@tonic-gate kthread_t *mod_inprogress_thread; 4990Sstevel@tonic-gate struct mod_modinfo *mod_modinfo; 5000Sstevel@tonic-gate struct modlinkage *mod_linkage; 5010Sstevel@tonic-gate char *mod_filename; 5020Sstevel@tonic-gate char *mod_modname; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate char mod_busy; /* inprogress_thread has locked */ 5050Sstevel@tonic-gate char mod_want; /* someone waiting for unlock */ 5060Sstevel@tonic-gate char mod_prim; /* primary module */ 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate int mod_ref; /* ref count - from dependent or stub */ 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate char mod_loaded; /* module in memory */ 5110Sstevel@tonic-gate char mod_installed; /* post _init pre _fini */ 5120Sstevel@tonic-gate char mod_loadflags; 5130Sstevel@tonic-gate char mod_delay_unload; /* deferred unload */ 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate struct modctl_list *mod_requisites; /* mods this one depends on. */ 5160Sstevel@tonic-gate void *__unused; /* NOTE: reuse (same size) is OK, */ 5170Sstevel@tonic-gate /* deletion causes mdb.vs.core issues */ 5180Sstevel@tonic-gate int mod_loadcnt; /* number of times mod was loaded */ 5190Sstevel@tonic-gate int mod_nenabled; /* # of enabled DTrace probes in mod */ 5200Sstevel@tonic-gate char *mod_text; 5210Sstevel@tonic-gate size_t mod_text_size; 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate int mod_gencount; /* # times loaded/unloaded */ 5240Sstevel@tonic-gate struct modctl *mod_requisite_loading; /* mod circular dependency */ 5251414Scindi } modctl_t; 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * mod_loadflags 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate #define MOD_NOAUTOUNLOAD 0x1 /* Auto mod-unloader skips this mod */ 5320Sstevel@tonic-gate #define MOD_NONOTIFY 0x2 /* No krtld notifications on (un)load */ 5330Sstevel@tonic-gate #define MOD_NOUNLOAD 0x4 /* Assume EBUSY for all _fini's */ 5340Sstevel@tonic-gate 5352621Sllai1 5360Sstevel@tonic-gate #ifdef _KERNEL 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate #define MOD_BIND_HASHSIZE 64 5390Sstevel@tonic-gate #define MOD_BIND_HASHMASK (MOD_BIND_HASHSIZE-1) 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate typedef int modid_t; 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * global function and data declarations 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate extern kmutex_t mod_lock; 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate extern char *systemfile; 5490Sstevel@tonic-gate extern char **syscallnames; 5500Sstevel@tonic-gate extern int moddebug; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* 5530Sstevel@tonic-gate * this is the head of a doubly linked list. Only the next and prev 5540Sstevel@tonic-gate * pointers are used 5550Sstevel@tonic-gate */ 5561414Scindi extern modctl_t modules; 5571414Scindi 5581414Scindi extern int modload_qualified(const char *, 5595254Sgavinm const char *, const char *, const char *, uint_t[], int, int *); 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate extern void mod_setup(void); 5626855Sjohnlev extern int modload(const char *, const char *); 5636855Sjohnlev extern int modloadonly(const char *, const char *); 5640Sstevel@tonic-gate extern int modunload(int); 5650Sstevel@tonic-gate extern int mod_hold_stub(struct mod_stub_info *); 5660Sstevel@tonic-gate extern void modunload_disable(void); 5670Sstevel@tonic-gate extern void modunload_enable(void); 5681218Scth extern void modunload_begin(void); 5691218Scth extern void modunload_end(void); 5700Sstevel@tonic-gate extern int mod_remove_by_name(char *); 5710Sstevel@tonic-gate extern int mod_sysvar(const char *, const char *, u_longlong_t *); 5720Sstevel@tonic-gate extern int mod_sysctl(int, void *); 5730Sstevel@tonic-gate struct sysparam; 5741414Scindi extern int mod_hold_by_modctl(modctl_t *, int); 5750Sstevel@tonic-gate #define MOD_WAIT_ONCE 0x01 5760Sstevel@tonic-gate #define MOD_WAIT_FOREVER 0x02 5770Sstevel@tonic-gate #define MOD_LOCK_HELD 0x04 5780Sstevel@tonic-gate #define MOD_LOCK_NOT_HELD 0x08 5790Sstevel@tonic-gate extern int mod_sysctl_type(int, int (*)(struct sysparam *, void *), 5800Sstevel@tonic-gate void *); 5810Sstevel@tonic-gate extern void mod_read_system_file(int); 5820Sstevel@tonic-gate extern void mod_release_stub(struct mod_stub_info *); 5830Sstevel@tonic-gate extern void mod_askparams(void); 5840Sstevel@tonic-gate extern void mod_uninstall_daemon(void); 5850Sstevel@tonic-gate extern void modreap(void); 5861414Scindi extern modctl_t *mod_hold_by_id(modid_t); 5871414Scindi extern modctl_t *mod_hold_by_name(const char *); 5881414Scindi extern void mod_release_mod(modctl_t *); 5891414Scindi extern uintptr_t modlookup(const char *, const char *); 5901414Scindi extern uintptr_t modlookup_by_modctl(modctl_t *, const char *); 5910Sstevel@tonic-gate extern char *modgetsymname(uintptr_t, unsigned long *); 5921414Scindi extern void mod_release_requisites(modctl_t *); 5931414Scindi extern modctl_t *mod_load_requisite(modctl_t *, char *); 5941414Scindi extern modctl_t *mod_find_by_filename(char *, char *); 5950Sstevel@tonic-gate extern uintptr_t modgetsymvalue(char *, int); 5960Sstevel@tonic-gate 597*12588SJerry.Gilliam@Sun.COM extern int major_valid(major_t); 59810842SJerry.Gilliam@Sun.COM extern int driver_installed(major_t); 599*12588SJerry.Gilliam@Sun.COM extern int driver_active(major_t); 600*12588SJerry.Gilliam@Sun.COM 6010Sstevel@tonic-gate extern void mod_rele_dev_by_major(major_t); 6020Sstevel@tonic-gate extern struct dev_ops *mod_hold_dev_by_major(major_t); 6030Sstevel@tonic-gate extern struct dev_ops *mod_hold_dev_by_devi(dev_info_t *); 6040Sstevel@tonic-gate extern void mod_rele_dev_by_devi(dev_info_t *); 6050Sstevel@tonic-gate 60610842SJerry.Gilliam@Sun.COM extern int make_devname(char *, major_t, int); 6072621Sllai1 extern int gmatch(const char *, const char *); 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate extern void make_aliases(struct bind **); 6100Sstevel@tonic-gate extern int read_binding_file(char *, struct bind **, 6110Sstevel@tonic-gate int (*line_parser)(char *, int, char *, struct bind **)); 6120Sstevel@tonic-gate extern void clear_binding_hash(struct bind **); 6130Sstevel@tonic-gate 6140Sstevel@tonic-gate extern void read_class_file(void); 6150Sstevel@tonic-gate extern void setbootpath(char *); 6160Sstevel@tonic-gate extern void setbootfstype(char *); 6170Sstevel@tonic-gate 6181414Scindi extern int install_stubs_by_name(modctl_t *, char *); 6191414Scindi extern void install_stubs(modctl_t *); 6201414Scindi extern void uninstall_stubs(modctl_t *); 6211414Scindi extern void reset_stubs(modctl_t *); 6221414Scindi extern modctl_t *mod_getctl(struct modlinkage *); 6230Sstevel@tonic-gate extern major_t mod_name_to_major(char *); 6240Sstevel@tonic-gate extern modid_t mod_name_to_modid(char *); 6250Sstevel@tonic-gate extern char *mod_major_to_name(major_t); 6260Sstevel@tonic-gate extern void init_devnamesp(int); 6270Sstevel@tonic-gate extern void init_syscallnames(int); 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate extern char *mod_getsysname(int); 6300Sstevel@tonic-gate extern int mod_getsysnum(char *); 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate extern char *mod_containing_pc(caddr_t); 6330Sstevel@tonic-gate extern int mod_in_autounload(void); 6347009Scth extern const char *mod_modname(struct modlinkage *); 6350Sstevel@tonic-gate 6361414Scindi extern int dev_minorperm(dev_info_t *, char *, mperm_t *); 6374870Sjg extern void dev_devices_cleanup(void); 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate /* 6400Sstevel@tonic-gate * Declarations used for dynamic linking support routines. Interfaces 6410Sstevel@tonic-gate * are marked with the pragma "unknown_control_flow" to prevent tail call 6420Sstevel@tonic-gate * optimization, so that implementations can reliably use caller() to 6430Sstevel@tonic-gate * determine initiating module. 6440Sstevel@tonic-gate */ 6450Sstevel@tonic-gate #define KRTLD_MODE_FIRST 0x0001 6460Sstevel@tonic-gate typedef struct __ddi_modhandle *ddi_modhandle_t; 6470Sstevel@tonic-gate extern ddi_modhandle_t ddi_modopen(const char *, 6480Sstevel@tonic-gate int, int *); 6490Sstevel@tonic-gate extern void *ddi_modsym(ddi_modhandle_t, 6500Sstevel@tonic-gate const char *, int *); 6510Sstevel@tonic-gate extern int ddi_modclose(ddi_modhandle_t); 6520Sstevel@tonic-gate #pragma unknown_control_flow(ddi_modopen, ddi_modsym, ddi_modclose) 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate /* 6550Sstevel@tonic-gate * Only the following are part of the DDI/DKI 6560Sstevel@tonic-gate */ 6570Sstevel@tonic-gate extern int _init(void); 6580Sstevel@tonic-gate extern int _fini(void); 6590Sstevel@tonic-gate extern int _info(struct modinfo *); 6600Sstevel@tonic-gate extern int mod_install(struct modlinkage *); 6610Sstevel@tonic-gate extern int mod_remove(struct modlinkage *); 6620Sstevel@tonic-gate extern int mod_info(struct modlinkage *, struct modinfo *); 6630Sstevel@tonic-gate 6640Sstevel@tonic-gate #else /* _KERNEL */ 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate extern int modctl(int, ...); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate #endif /* _KERNEL */ 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate /* 6710Sstevel@tonic-gate * bit definitions for moddebug. 6720Sstevel@tonic-gate */ 6730Sstevel@tonic-gate #define MODDEBUG_LOADMSG 0x80000000 /* print "[un]loading..." msg */ 6740Sstevel@tonic-gate #define MODDEBUG_ERRMSG 0x40000000 /* print detailed error msgs */ 6750Sstevel@tonic-gate #define MODDEBUG_LOADMSG2 0x20000000 /* print 2nd level msgs */ 6764845Svikram #define MODDEBUG_RETIRE 0x10000000 /* print retire msgs */ 6778831SJerry.Gilliam@Sun.COM #define MODDEBUG_BINDING 0x00040000 /* driver/alias binding */ 6780Sstevel@tonic-gate #define MODDEBUG_FINI_EBUSY 0x00020000 /* pretend fini returns EBUSY */ 6790Sstevel@tonic-gate #define MODDEBUG_NOAUL_IPP 0x00010000 /* no Autounloading ipp mods */ 6800Sstevel@tonic-gate #define MODDEBUG_NOAUL_DACF 0x00008000 /* no Autounloading dacf mods */ 6810Sstevel@tonic-gate #define MODDEBUG_KEEPTEXT 0x00004000 /* keep text after unloading */ 6820Sstevel@tonic-gate #define MODDEBUG_NOAUL_DRV 0x00001000 /* no Autounloading Drivers */ 6830Sstevel@tonic-gate #define MODDEBUG_NOAUL_EXEC 0x00000800 /* no Autounloading Execs */ 6840Sstevel@tonic-gate #define MODDEBUG_NOAUL_FS 0x00000400 /* no Autounloading File sys */ 6850Sstevel@tonic-gate #define MODDEBUG_NOAUL_MISC 0x00000200 /* no Autounloading misc */ 6860Sstevel@tonic-gate #define MODDEBUG_NOAUL_SCHED 0x00000100 /* no Autounloading scheds */ 6870Sstevel@tonic-gate #define MODDEBUG_NOAUL_STR 0x00000080 /* no Autounloading streams */ 6880Sstevel@tonic-gate #define MODDEBUG_NOAUL_SYS 0x00000040 /* no Autounloading syscalls */ 6890Sstevel@tonic-gate #define MODDEBUG_NOCTF 0x00000020 /* do not load CTF debug data */ 6900Sstevel@tonic-gate #define MODDEBUG_NOAUTOUNLOAD 0x00000010 /* no autounloading at all */ 6910Sstevel@tonic-gate #define MODDEBUG_DDI_MOD 0x00000008 /* ddi_mod{open,sym,close} */ 6920Sstevel@tonic-gate #define MODDEBUG_MP_MATCH 0x00000004 /* dev_minorperm */ 6930Sstevel@tonic-gate #define MODDEBUG_MINORPERM 0x00000002 /* minor perm modctls */ 6940Sstevel@tonic-gate #define MODDEBUG_USERDEBUG 0x00000001 /* bpt after init_module() */ 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate #ifdef __cplusplus 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate #endif 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate #endif /* _SYS_MODCTL_H */ 701