1706f2543Smrg/* 2706f2543Smrg * Copyright (c) 1997-2003 by The XFree86 Project, Inc. 3706f2543Smrg * 4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5706f2543Smrg * copy of this software and associated documentation files (the "Software"), 6706f2543Smrg * to deal in the Software without restriction, including without limitation 7706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 9706f2543Smrg * Software is furnished to do so, subject to the following conditions: 10706f2543Smrg * 11706f2543Smrg * The above copyright notice and this permission notice shall be included in 12706f2543Smrg * all copies or substantial portions of the Software. 13706f2543Smrg * 14706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17706f2543Smrg * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18706f2543Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19706f2543Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20706f2543Smrg * OTHER DEALINGS IN THE SOFTWARE. 21706f2543Smrg * 22706f2543Smrg * Except as contained in this notice, the name of the copyright holder(s) 23706f2543Smrg * and author(s) shall not be used in advertising or otherwise to promote 24706f2543Smrg * the sale, use or other dealings in this Software without prior written 25706f2543Smrg * authorization from the copyright holder(s) and author(s). 26706f2543Smrg */ 27706f2543Smrg 28706f2543Smrg/* 29706f2543Smrg * This file contains the parts of the loader interface that are visible 30706f2543Smrg * to modules. This is the only loader-related header that modules should 31706f2543Smrg * include. 32706f2543Smrg * 33706f2543Smrg * It should include a bare minimum of other headers. 34706f2543Smrg * 35706f2543Smrg * Longer term, the module/loader code should probably live directly under 36706f2543Smrg * Xserver/. 37706f2543Smrg * 38706f2543Smrg * XXX This file arguably belongs in xfree86/loader/. 39706f2543Smrg */ 40706f2543Smrg 41706f2543Smrg#ifndef _XF86MODULE_H 42706f2543Smrg#define _XF86MODULE_H 43706f2543Smrg 44706f2543Smrg#include "misc.h" 45706f2543Smrg#ifndef NULL 46706f2543Smrg#define NULL ((void *)0) 47706f2543Smrg#endif 48706f2543Smrg 49706f2543Smrgtypedef enum { 50706f2543Smrg LD_RESOLV_IFDONE = 0, /* only check if no more 51706f2543Smrg delays pending */ 52706f2543Smrg LD_RESOLV_NOW = 1, /* finish one delay step */ 53706f2543Smrg LD_RESOLV_FORCE = 2 /* force checking... */ 54706f2543Smrg} LoaderResolveOptions; 55706f2543Smrg 56706f2543Smrg#define DEFAULT_LIST ((char *)-1) 57706f2543Smrg 58706f2543Smrg/* This indicates a special module that doesn't have the usual entry point */ 59706f2543Smrg#define EXTERN_MODULE ((pointer)-1) 60706f2543Smrg 61706f2543Smrg/* Built-in ABI classes. These definitions must not be changed. */ 62706f2543Smrg#define ABI_CLASS_NONE NULL 63706f2543Smrg#define ABI_CLASS_ANSIC "X.Org ANSI C Emulation" 64706f2543Smrg#define ABI_CLASS_VIDEODRV "X.Org Video Driver" 65706f2543Smrg#define ABI_CLASS_XINPUT "X.Org XInput driver" 66706f2543Smrg#define ABI_CLASS_EXTENSION "X.Org Server Extension" 67706f2543Smrg#define ABI_CLASS_FONT "X.Org Font Renderer" 68706f2543Smrg 69706f2543Smrg#define ABI_MINOR_MASK 0x0000FFFF 70706f2543Smrg#define ABI_MAJOR_MASK 0xFFFF0000 71706f2543Smrg#define GET_ABI_MINOR(v) ((v) & ABI_MINOR_MASK) 72706f2543Smrg#define GET_ABI_MAJOR(v) (((v) & ABI_MAJOR_MASK) >> 16) 73706f2543Smrg#define SET_ABI_VERSION(maj, min) \ 74706f2543Smrg ((((maj) << 16) & ABI_MAJOR_MASK) | ((min) & ABI_MINOR_MASK)) 75706f2543Smrg 76706f2543Smrg/* 77706f2543Smrg * ABI versions. Each version has a major and minor revision. Modules 78706f2543Smrg * using lower minor revisions must work with servers of a higher minor 79706f2543Smrg * revision. There is no compatibility between different major revisions. 80706f2543Smrg * Whenever the ABI_ANSIC_VERSION is changed, the others must also be 81706f2543Smrg * changed. The minor revision mask is 0x0000FFFF and the major revision 82706f2543Smrg * mask is 0xFFFF0000. 83706f2543Smrg */ 84706f2543Smrg#define ABI_ANSIC_VERSION SET_ABI_VERSION(0, 4) 85706f2543Smrg#define ABI_VIDEODRV_VERSION SET_ABI_VERSION(10, 0) 86706f2543Smrg#define ABI_XINPUT_VERSION SET_ABI_VERSION(12, 2) 87706f2543Smrg#define ABI_EXTENSION_VERSION SET_ABI_VERSION(5, 0) 88706f2543Smrg#define ABI_FONT_VERSION SET_ABI_VERSION(0, 6) 89706f2543Smrg 90706f2543Smrg#define MODINFOSTRING1 0xef23fdc5 91706f2543Smrg#define MODINFOSTRING2 0x10dc023a 92706f2543Smrg 93706f2543Smrg#ifndef MODULEVENDORSTRING 94706f2543Smrg#define MODULEVENDORSTRING "X.Org Foundation" 95706f2543Smrg#endif 96706f2543Smrg 97706f2543Smrg/* Error return codes for errmaj. New codes must only be added at the end. */ 98706f2543Smrgtypedef enum { 99706f2543Smrg LDR_NOERROR = 0, 100706f2543Smrg LDR_NOMEM, /* memory allocation failed */ 101706f2543Smrg LDR_NOENT, /* Module file does not exist */ 102706f2543Smrg LDR_NOSUBENT, /* pre-requsite file to be sub-loaded does not exist */ 103706f2543Smrg LDR_NOSPACE, /* internal module array full */ 104706f2543Smrg LDR_NOMODOPEN, /* module file could not be opened (check errmin) */ 105706f2543Smrg LDR_UNKTYPE, /* file is not a recognized module type */ 106706f2543Smrg LDR_NOLOAD, /* type specific loader failed */ 107706f2543Smrg LDR_ONCEONLY, /* Module should only be loaded once (not an error) */ 108706f2543Smrg LDR_NOPORTOPEN, /* could not open port (check errmin) */ 109706f2543Smrg LDR_NOHARDWARE, /* could not query/initialize the hardware device */ 110706f2543Smrg LDR_MISMATCH, /* the module didn't match the spec'd requirments */ 111706f2543Smrg LDR_BADUSAGE, /* LoadModule is called with bad arguments */ 112706f2543Smrg LDR_INVALID, /* The module doesn't have a valid ModuleData object */ 113706f2543Smrg LDR_BADOS, /* The module doesn't support the OS */ 114706f2543Smrg LDR_MODSPECIFIC /* A module-specific error in the SetupProc */ 115706f2543Smrg} LoaderErrorCode; 116706f2543Smrg 117706f2543Smrg/* 118706f2543Smrg * Some common module classes. The moduleclass can be used to identify 119706f2543Smrg * that modules loaded are of the correct type. This is a finer 120706f2543Smrg * classification than the ABI classes even though the default set of 121706f2543Smrg * classes have the same names. For example, not all modules that require 122706f2543Smrg * the video driver ABI are themselves video drivers. 123706f2543Smrg */ 124706f2543Smrg#define MOD_CLASS_NONE NULL 125706f2543Smrg#define MOD_CLASS_VIDEODRV "X.Org Video Driver" 126706f2543Smrg#define MOD_CLASS_XINPUT "X.Org XInput Driver" 127706f2543Smrg#define MOD_CLASS_FONT "X.Org Font Renderer" 128706f2543Smrg#define MOD_CLASS_EXTENSION "X.Org Server Extension" 129706f2543Smrg 130706f2543Smrg/* This structure is expected to be returned by the initfunc */ 131706f2543Smrgtypedef struct { 132706f2543Smrg const char * modname; /* name of module, e.g. "foo" */ 133706f2543Smrg const char * vendor; /* vendor specific string */ 134706f2543Smrg CARD32 _modinfo1_; /* constant MODINFOSTRING1/2 to find */ 135706f2543Smrg CARD32 _modinfo2_; /* infoarea with a binary editor or sign tool */ 136706f2543Smrg CARD32 xf86version; /* contains XF86_VERSION_CURRENT */ 137706f2543Smrg CARD8 majorversion; /* module-specific major version */ 138706f2543Smrg CARD8 minorversion; /* module-specific minor version */ 139706f2543Smrg CARD16 patchlevel; /* module-specific patch level */ 140706f2543Smrg const char * abiclass; /* ABI class that the module uses */ 141706f2543Smrg CARD32 abiversion; /* ABI version */ 142706f2543Smrg const char * moduleclass; /* module class description */ 143706f2543Smrg CARD32 checksum[4]; /* contains a digital signature of the */ 144706f2543Smrg /* version info structure */ 145706f2543Smrg} XF86ModuleVersionInfo; 146706f2543Smrg 147706f2543Smrg/* 148706f2543Smrg * This structure can be used to callers of LoadModule and LoadSubModule to 149706f2543Smrg * specify version and/or ABI requirements. 150706f2543Smrg */ 151706f2543Smrgtypedef struct { 152706f2543Smrg CARD8 majorversion; /* module-specific major version */ 153706f2543Smrg CARD8 minorversion; /* moudle-specific minor version */ 154706f2543Smrg CARD16 patchlevel; /* module-specific patch level */ 155706f2543Smrg const char * abiclass; /* ABI class that the module uses */ 156706f2543Smrg CARD32 abiversion; /* ABI version */ 157706f2543Smrg const char * moduleclass; /* module class */ 158706f2543Smrg} XF86ModReqInfo; 159706f2543Smrg 160706f2543Smrg/* values to indicate unspecified fields in XF86ModReqInfo. */ 161706f2543Smrg#define MAJOR_UNSPEC 0xFF 162706f2543Smrg#define MINOR_UNSPEC 0xFF 163706f2543Smrg#define PATCH_UNSPEC 0xFFFF 164706f2543Smrg#define ABI_VERS_UNSPEC 0xFFFFFFFF 165706f2543Smrg 166706f2543Smrg#define MODULE_VERSION_NUMERIC(maj, min, patch) \ 167706f2543Smrg ((((maj) & 0xFF) << 24) | (((min) & 0xFF) << 16) | (patch & 0xFFFF)) 168706f2543Smrg#define GET_MODULE_MAJOR_VERSION(vers) (((vers) >> 24) & 0xFF) 169706f2543Smrg#define GET_MODULE_MINOR_VERSION(vers) (((vers) >> 16) & 0xFF) 170706f2543Smrg#define GET_MODULE_PATCHLEVEL(vers) ((vers) & 0xFFFF) 171706f2543Smrg 172706f2543Smrg#define INITARGS void 173706f2543Smrg 174706f2543Smrgtypedef void (*InitExtension)(INITARGS); 175706f2543Smrg 176706f2543Smrgtypedef struct { 177706f2543Smrg InitExtension initFunc; 178706f2543Smrg const char * name; 179706f2543Smrg Bool *disablePtr; 180706f2543Smrg InitExtension setupFunc; 181706f2543Smrg const char ** initDependencies; 182706f2543Smrg} ExtensionModule; 183706f2543Smrg 184706f2543Smrgextern _X_EXPORT ExtensionModule *ExtensionModuleList; 185706f2543Smrg 186706f2543Smrg/* Prototypes for Loader functions that are exported to modules */ 187706f2543Smrgextern _X_EXPORT pointer LoadSubModule(pointer, const char *, const char **, 188706f2543Smrg const char **, pointer, const XF86ModReqInfo *, 189706f2543Smrg int *, int *); 190706f2543Smrgextern _X_EXPORT void UnloadSubModule(pointer); 191706f2543Smrgextern _X_EXPORT void UnloadModule (pointer); 192706f2543Smrgextern _X_EXPORT pointer LoaderSymbol(const char *); 193706f2543Smrgextern _X_EXPORT char **LoaderListDirs(const char **, const char **); 194706f2543Smrgextern _X_EXPORT void LoaderFreeDirList(char **); 195706f2543Smrgextern _X_EXPORT void LoaderErrorMsg(const char *, const char *, int, int); 196706f2543Smrgextern _X_EXPORT void LoadExtension(ExtensionModule *, Bool); 197706f2543Smrgextern _X_EXPORT void LoaderGetOS(const char **name, int *major, int *minor, int *teeny); 198706f2543Smrgextern _X_EXPORT Bool LoaderShouldIgnoreABI(void); 199706f2543Smrgextern _X_EXPORT int LoaderGetABIVersion(const char *abiclass); 200706f2543Smrg 201706f2543Smrgtypedef pointer (*ModuleSetupProc)(pointer, pointer, int *, int *); 202706f2543Smrgtypedef void (*ModuleTearDownProc)(pointer); 203706f2543Smrg#define MODULESETUPPROTO(func) pointer func(pointer, pointer, int*, int*) 204706f2543Smrg#define MODULETEARDOWNPROTO(func) void func(pointer) 205706f2543Smrg 206706f2543Smrgtypedef struct { 207706f2543Smrg XF86ModuleVersionInfo * vers; 208706f2543Smrg ModuleSetupProc setup; 209706f2543Smrg ModuleTearDownProc teardown; 210706f2543Smrg} XF86ModuleData; 211706f2543Smrg 212706f2543Smrg#endif /* _XF86STR_H */ 213