1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Permission is hereby granted, free of charge, to any person obtaining a 5*4882a593Smuzhiyun * copy of this software and associated documentation files (the "Software"), 6*4882a593Smuzhiyun * to deal in the Software without restriction, including without limitation 7*4882a593Smuzhiyun * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*4882a593Smuzhiyun * and/or sell copies of the Software, and to permit persons to whom the 9*4882a593Smuzhiyun * Software is furnished to do so, subject to the following conditions: 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun * The above copyright notice and this permission notice shall be included in 12*4882a593Smuzhiyun * all copies or substantial portions of the Software. 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*4882a593Smuzhiyun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17*4882a593Smuzhiyun * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18*4882a593Smuzhiyun * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19*4882a593Smuzhiyun * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20*4882a593Smuzhiyun * OTHER DEALINGS IN THE SOFTWARE. 21*4882a593Smuzhiyun * 22*4882a593Smuzhiyun * Except as contained in this notice, the name of the copyright holder(s) 23*4882a593Smuzhiyun * and author(s) shall not be used in advertising or otherwise to promote 24*4882a593Smuzhiyun * the sale, use or other dealings in this Software without prior written 25*4882a593Smuzhiyun * authorization from the copyright holder(s) and author(s). 26*4882a593Smuzhiyun */ 27*4882a593Smuzhiyun 28*4882a593Smuzhiyun /* 29*4882a593Smuzhiyun * This file contains the parts of the loader interface that are visible 30*4882a593Smuzhiyun * to modules. This is the only loader-related header that modules should 31*4882a593Smuzhiyun * include. 32*4882a593Smuzhiyun * 33*4882a593Smuzhiyun * It should include a bare minimum of other headers. 34*4882a593Smuzhiyun * 35*4882a593Smuzhiyun * Longer term, the module/loader code should probably live directly under 36*4882a593Smuzhiyun * Xserver/. 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * XXX This file arguably belongs in xfree86/loader/. 39*4882a593Smuzhiyun */ 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun #ifndef _XF86MODULE_H 42*4882a593Smuzhiyun #define _XF86MODULE_H 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun #include <X11/Xfuncproto.h> 45*4882a593Smuzhiyun #include <X11/Xdefs.h> 46*4882a593Smuzhiyun #include <X11/Xmd.h> 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun #ifndef NULL 49*4882a593Smuzhiyun #define NULL ((void *)0) 50*4882a593Smuzhiyun #endif 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun #define DEFAULT_LIST ((char *)-1) 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun /* Built-in ABI classes. These definitions must not be changed. */ 55*4882a593Smuzhiyun #define ABI_CLASS_NONE NULL 56*4882a593Smuzhiyun #define ABI_CLASS_ANSIC "X.Org ANSI C Emulation" 57*4882a593Smuzhiyun #define ABI_CLASS_VIDEODRV "X.Org Video Driver" 58*4882a593Smuzhiyun #define ABI_CLASS_XINPUT "X.Org XInput driver" 59*4882a593Smuzhiyun #define ABI_CLASS_EXTENSION "X.Org Server Extension" 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun #define ABI_MINOR_MASK 0x0000FFFF 62*4882a593Smuzhiyun #define ABI_MAJOR_MASK 0xFFFF0000 63*4882a593Smuzhiyun #define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK) 64*4882a593Smuzhiyun #define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16) 65*4882a593Smuzhiyun #define SET_ABI_VERSION(maj, min) \ 66*4882a593Smuzhiyun ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun /* 69*4882a593Smuzhiyun * ABI versions. Each version has a major and minor revision. Modules 70*4882a593Smuzhiyun * using lower minor revisions must work with servers of a higher minor 71*4882a593Smuzhiyun * revision. There is no compatibility between different major revisions. 72*4882a593Smuzhiyun * Whenever the ABI_ANSIC_VERSION is changed, the others must also be 73*4882a593Smuzhiyun * changed. The minor revision mask is 0x0000FFFF and the major revision 74*4882a593Smuzhiyun * mask is 0xFFFF0000. 75*4882a593Smuzhiyun */ 76*4882a593Smuzhiyun #define ABI_ANSIC_VERSION SET_ABI_VERSION(0, 4) 77*4882a593Smuzhiyun #define ABI_VIDEODRV_VERSION SET_ABI_VERSION(24, 1) 78*4882a593Smuzhiyun #define ABI_XINPUT_VERSION SET_ABI_VERSION(24, 1) 79*4882a593Smuzhiyun #define ABI_EXTENSION_VERSION SET_ABI_VERSION(10, 0) 80*4882a593Smuzhiyun 81*4882a593Smuzhiyun #define MODINFOSTRING1 0xef23fdc5 82*4882a593Smuzhiyun #define MODINFOSTRING2 0x10dc023a 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun #ifndef MODULEVENDORSTRING 85*4882a593Smuzhiyun #define MODULEVENDORSTRING "X.Org Foundation" 86*4882a593Smuzhiyun #endif 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun /* Error return codes for errmaj */ 89*4882a593Smuzhiyun typedef enum { 90*4882a593Smuzhiyun LDR_NOERROR = 0, 91*4882a593Smuzhiyun LDR_NOMEM, /* memory allocation failed */ 92*4882a593Smuzhiyun LDR_NOENT, /* Module file does not exist */ 93*4882a593Smuzhiyun LDR_NOLOAD, /* type specific loader failed */ 94*4882a593Smuzhiyun LDR_ONCEONLY, /* Module should only be loaded once (not an error) */ 95*4882a593Smuzhiyun LDR_MISMATCH, /* the module didn't match the spec'd requirments */ 96*4882a593Smuzhiyun LDR_BADUSAGE, /* LoadModule is called with bad arguments */ 97*4882a593Smuzhiyun LDR_INVALID, /* The module doesn't have a valid ModuleData object */ 98*4882a593Smuzhiyun LDR_BADOS, /* The module doesn't support the OS */ 99*4882a593Smuzhiyun LDR_MODSPECIFIC /* A module-specific error in the SetupProc */ 100*4882a593Smuzhiyun } LoaderErrorCode; 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun /* 103*4882a593Smuzhiyun * Some common module classes. The moduleclass can be used to identify 104*4882a593Smuzhiyun * that modules loaded are of the correct type. This is a finer 105*4882a593Smuzhiyun * classification than the ABI classes even though the default set of 106*4882a593Smuzhiyun * classes have the same names. For example, not all modules that require 107*4882a593Smuzhiyun * the video driver ABI are themselves video drivers. 108*4882a593Smuzhiyun */ 109*4882a593Smuzhiyun #define MOD_CLASS_NONE NULL 110*4882a593Smuzhiyun #define MOD_CLASS_VIDEODRV "X.Org Video Driver" 111*4882a593Smuzhiyun #define MOD_CLASS_XINPUT "X.Org XInput Driver" 112*4882a593Smuzhiyun #define MOD_CLASS_EXTENSION "X.Org Server Extension" 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun /* This structure is expected to be returned by the initfunc */ 115*4882a593Smuzhiyun typedef struct { 116*4882a593Smuzhiyun const char *modname; /* name of module, e.g. "foo" */ 117*4882a593Smuzhiyun const char *vendor; /* vendor specific string */ 118*4882a593Smuzhiyun CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ 119*4882a593Smuzhiyun CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */ 120*4882a593Smuzhiyun CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ 121*4882a593Smuzhiyun CARD8 majorversion; /* module-specific major version */ 122*4882a593Smuzhiyun CARD8 minorversion; /* module-specific minor version */ 123*4882a593Smuzhiyun CARD16 patchlevel; /* module-specific patch level */ 124*4882a593Smuzhiyun const char *abiclass; /* ABI class that the module uses */ 125*4882a593Smuzhiyun CARD32 abiversion; /* ABI version */ 126*4882a593Smuzhiyun const char *moduleclass; /* module class description */ 127*4882a593Smuzhiyun CARD32 checksum[4]; /* contains a digital signature of the */ 128*4882a593Smuzhiyun /* version info structure */ 129*4882a593Smuzhiyun } XF86ModuleVersionInfo; 130*4882a593Smuzhiyun 131*4882a593Smuzhiyun /* 132*4882a593Smuzhiyun * This structure can be used to callers of LoadModule and LoadSubModule to 133*4882a593Smuzhiyun * specify version and/or ABI requirements. 134*4882a593Smuzhiyun */ 135*4882a593Smuzhiyun typedef struct { 136*4882a593Smuzhiyun CARD8 majorversion; /* module-specific major version */ 137*4882a593Smuzhiyun CARD8 minorversion; /* moudle-specific minor version */ 138*4882a593Smuzhiyun CARD16 patchlevel; /* module-specific patch level */ 139*4882a593Smuzhiyun const char *abiclass; /* ABI class that the module uses */ 140*4882a593Smuzhiyun CARD32 abiversion; /* ABI version */ 141*4882a593Smuzhiyun const char *moduleclass; /* module class */ 142*4882a593Smuzhiyun } XF86ModReqInfo; 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun #define MODULE_VERSION_NUMERIC(maj, min, patch) \ 145*4882a593Smuzhiyun ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) 146*4882a593Smuzhiyun #define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) 147*4882a593Smuzhiyun #define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) 148*4882a593Smuzhiyun #define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun #define INITARGS void 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun /* Prototypes for Loader functions that are exported to modules */ 153*4882a593Smuzhiyun extern _X_EXPORT void *LoadSubModule(void *, const char *, const char **, 154*4882a593Smuzhiyun const char **, void *, 155*4882a593Smuzhiyun const XF86ModReqInfo *, int *, int *); 156*4882a593Smuzhiyun extern _X_EXPORT void UnloadSubModule(void *); 157*4882a593Smuzhiyun extern _X_EXPORT void UnloadModule(void *); 158*4882a593Smuzhiyun extern _X_EXPORT void *LoaderSymbol(const char *); 159*4882a593Smuzhiyun extern _X_EXPORT void LoaderErrorMsg(const char *, const char *, int, int); 160*4882a593Smuzhiyun extern _X_EXPORT Bool LoaderShouldIgnoreABI(void); 161*4882a593Smuzhiyun extern _X_EXPORT int LoaderGetABIVersion(const char *abiclass); 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun typedef void *(*ModuleSetupProc) (void *, void *, int *, int *); 164*4882a593Smuzhiyun typedef void (*ModuleTearDownProc) (void *); 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun #define MODULESETUPPROTO(func) void *func(void *, void *, int*, int*) 167*4882a593Smuzhiyun #define MODULETEARDOWNPROTO(func) void func(void *) 168*4882a593Smuzhiyun 169*4882a593Smuzhiyun typedef struct { 170*4882a593Smuzhiyun XF86ModuleVersionInfo *vers; 171*4882a593Smuzhiyun ModuleSetupProc setup; 172*4882a593Smuzhiyun ModuleTearDownProc teardown; 173*4882a593Smuzhiyun } XF86ModuleData; 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun #endif /* _XF86STR_H */ 176