home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / sys / lkm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  8.3 KB  |  367 lines  |  [TEXT/R*ch]

  1. /*
  2.  * lkm.h
  3.  *
  4.  * Header file used by loadable kernel modules and loadable kernel module
  5.  * utilities.
  6.  *
  7.  * 23 Jan 93    Terry Lambert        Original
  8.  *
  9.  * Copyright (c) 1992 Terrence R. Lambert.
  10.  * All rights reserved.
  11.  *
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  * 3. All advertising materials mentioning features or use of this software
  21.  *    must display the following acknowledgement:
  22.  *      This product includes software developed by Terrence R. Lambert.
  23.  * 4. The name Terrence R. Lambert may not be used to endorse or promote
  24.  *    products derived from this software without specific prior written
  25.  *    permission.
  26.  *
  27.  * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY
  28.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE
  31.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  36.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37.  * SUCH DAMAGE.
  38.  *
  39.  *    $Id: lkm.h,v 1.1 1993/06/07 19:52:51 cgd Exp $
  40.  */
  41. #ifndef _SYS_LKM_H_
  42. #define _SYS_LKM_H_
  43.  
  44.  
  45. /*
  46.  * Supported module types
  47.  */
  48. typedef enum loadmod {
  49.     LM_SYSCALL,
  50.     LM_VFS,
  51.     LM_DEV,
  52.     LM_STRMOD,
  53.     LM_EXEC,
  54.     LM_MISC
  55. } MODTYPE;
  56.  
  57.  
  58. #define    LKM_VERSION    1        /* version of module loader*/
  59. /****************************************************************************/
  60.  
  61. /*
  62.  * Loadable system call
  63.  */
  64. struct lkm_syscall {
  65.     MODTYPE        lkm_type;
  66.     int        lkm_ver;
  67.     char        *lkm_name;
  68.     int        lkm_offset;        /* save/assign area*/
  69.     struct sysent    *lkm_sysent;
  70.     struct sysent    lkm_oldent;        /* save area for unload*/
  71. };
  72.  
  73. /*
  74.  * Loadable file system
  75.  */
  76. struct lkm_vfs {
  77.     MODTYPE        lkm_type;
  78.     int        lkm_ver;
  79.     char        *lkm_name;
  80.     int        lkm_offset;
  81.     unsigned long    lkm_flags;
  82.     struct vfsops    *lkm_vfsops;
  83. };
  84.  
  85. /*
  86.  * Supported device module types
  87.  */
  88. typedef enum devtype {
  89.     LM_DT_BLOCK,
  90.     LM_DT_CHAR
  91. } DEVTYPE;
  92.  
  93. /*
  94.  * Loadable device driver
  95.  */
  96. struct lkm_dev {
  97.     MODTYPE        lkm_type;
  98.     int        lkm_ver;
  99.     char        *lkm_name;
  100.     int        lkm_offset;
  101.     DEVTYPE        lkm_devtype;
  102.     union {
  103.         void        *anon;
  104.         struct bdevsw    *bdev;
  105.         struct cdevsw    *cdev;
  106.     } lkm_dev;
  107.     union {
  108.         struct bdevsw    bdev;
  109.         struct cdevsw    cdev;
  110.     } lkm_olddev;
  111. };
  112.  
  113. /*
  114.  * Loadable streams module
  115.  */
  116. struct lkm_strmod {
  117.     MODTYPE        lkm_type;
  118.     int        lkm_ver;
  119.     char        *lkm_name;
  120.     int        lkm_offset;
  121.     /*
  122.      * Removed: future release
  123.      */
  124. };
  125.  
  126. /*
  127.  * Exec loader
  128.  */
  129. struct lkm_exec {
  130.     MODTYPE        lkm_type;
  131.     int        lkm_ver;
  132.     char        *lkm_name;
  133.     int        lkm_offset;
  134.     struct execsw    *lkm_exec;
  135.     struct execsw    lkm_oldexec;
  136. };
  137.  
  138. /*
  139.  * Miscellaneous module (complex load/unload, potentially complex stat
  140.  */
  141. struct lkm_misc {
  142.     MODTYPE        lkm_type;
  143.     int        lkm_ver;
  144.     char        *lkm_name;
  145.     int        lkm_offset;
  146. };
  147.  
  148.  
  149. /*
  150.  * Any module (to get type and name info without knowing type)
  151.  */
  152. struct lkm_any {
  153.     MODTYPE        lkm_type;
  154.     int        lkm_ver;
  155.     char        *lkm_name;
  156.     int        lkm_offset;
  157. };
  158.  
  159.  
  160.  
  161. /*
  162.  * Generic reference ala XEvent to allow single entry point in the xxxinit()
  163.  * routine.
  164.  */
  165. union lkm_generic {
  166.     struct lkm_any        *lkm_any;
  167.     struct lkm_syscall    *lkm_syscall;
  168.     struct lkm_vfs        *lkm_vfs;
  169.     struct lkm_dev        *lkm_dev;
  170.     struct lkm_strmod    *lkm_strmod;
  171.     struct lkm_exec        *lkm_exec;
  172.     struct lkm_misc        *lkm_misc;
  173. };
  174.  
  175. union lkm_all {
  176.     struct lkm_any        lkm_any;
  177.     struct lkm_syscall    lkm_syscall;
  178.     struct lkm_vfs        lkm_vfs;
  179.     struct lkm_dev        lkm_dev;
  180.     struct lkm_strmod    lkm_strmod;
  181.     struct lkm_exec        lkm_exec;
  182.     struct lkm_misc        lkm_misc;
  183. };
  184.  
  185. /*
  186.  * Per module information structure
  187.  */
  188. #define    MAXLKMNAME    32
  189. struct lkm_table {
  190.     int        type;
  191.     unsigned int    size;
  192.     unsigned int    offset;
  193.     char        *area;
  194.     char        used;
  195.  
  196.     int            ver;        /* version (INIT)*/
  197.     int            refcnt;        /* reference count (INIT)*/
  198.     int            depcnt;        /* dependency count (INIT)*/
  199.     int            id;        /* identifier (INIT)*/
  200.  
  201.     int            (*entry)();    /* entry function*/
  202.     union lkm_generic    private;    /* module private data*/
  203. };
  204.  
  205.  
  206. #define    LKM_E_LOAD    1
  207. #define    LKM_E_UNLOAD    2
  208. #define    LKM_E_STAT    3
  209.  
  210.  
  211. #define    MOD_SYSCALL(name,callslot,sysentp)    \
  212.     static struct lkm_syscall _module = {    \
  213.         LM_SYSCALL,            \
  214.         LKM_VERSION,            \
  215.         name,                \
  216.         callslot,            \
  217.         sysentp                \
  218.     };
  219.  
  220. #define    MOD_VFS(name,vfsslot,flags,vfsopsp)        \
  221.     static struct lkm_vfs _module = {    \
  222.         LM_VFS,                \
  223.         LKM_VERSION,            \
  224.         name,                \
  225.         vfsslot,            \
  226.         flags,                \
  227.         vfsopsp                \
  228.     };
  229.  
  230. #define    MOD_DEV(name,devtype,devslot,devp)    \
  231.     static struct lkm_dev _module = {    \
  232.         LM_DEV,                \
  233.         LKM_VERSION,            \
  234.         name,                \
  235.         devslot,            \
  236.         devtype,            \
  237.         (void *)devp            \
  238.     };
  239.  
  240. #define    MOD_EXEC(name,execslot,execsw)        \
  241.     static struct lkm_exec _module = {    \
  242.         LM_EXEC,            \
  243.         LKM_VERSION,            \
  244.         name,                \
  245.         execslot,            \
  246.         execsw                \
  247.     };
  248.  
  249. #define    MOD_MISC(name)                \
  250.     static struct lkm_misc _module = {    \
  251.         LM_MISC,            \
  252.         LKM_VERSION,            \
  253.         name                \
  254.     };
  255.  
  256.  
  257. extern int    nosys();
  258.  
  259. /*
  260.  * DISPATCH -- body function for use in module entry point function;
  261.  * generally, the function body will consist entirely of a single
  262.  * DISPATCH line.
  263.  *
  264.  * If load/unload/stat are not "nosys", then they are called on each
  265.  * corresponding entry instance.  "cmd" is passed to each function so
  266.  * that a single function can be used if desired.
  267.  */
  268. #define    DISPATCH(lkmtp,cmd,ver,load,unload,stat)            \
  269.     if( ver != LKM_VERSION)                        \
  270.         return( EINVAL);    /* version mismatch*/        \
  271.     switch( cmd) {                            \
  272.     int    _err;                            \
  273.     case LKM_E_LOAD:                        \
  274.         lkmtp->private.lkm_any = (struct lkm_any *)&_module;    \
  275.         if( load != nosys && (_err = load( lkmtp, cmd)))    \
  276.             return( _err);                    \
  277.         break;                            \
  278.     case LKM_E_UNLOAD:                        \
  279.         if( unload != nosys && (_err = unload( lkmtp, cmd)))    \
  280.             return( _err);                    \
  281.         break;                            \
  282.     case LKM_E_STAT:                        \
  283.         if( stat != nosys && (_err = stat( lkmtp, cmd)))    \
  284.             return( _err);                    \
  285.         break;                            \
  286.     }                                \
  287.     return( lkmdispatch( lkmtp, cmd));
  288.  
  289.  
  290. /****************************************************************************/
  291.  
  292.  
  293. /*
  294.  * IOCTL's recognized by /dev/lkm
  295.  */
  296. #define    LMRESERV    _IOWR( 'K', 0, struct lmc_resrv)
  297. #define    LMLOADBUF    _IOW( 'K', 1, struct lmc_loadbuf)
  298. #define    LMUNRESRV    _IO( 'K', 2)
  299. #define    LMREADY        _IOW( 'K', 3, int)
  300.  
  301. #define    LMLOAD        _IOW( 'K', 9, struct lmc_load)
  302. #define    LMUNLOAD    _IOWR( 'K', 10, struct lmc_unload)
  303. #define    LMSTAT        _IOWR( 'K', 11, struct lmc_stat)
  304.  
  305. #define    MODIOBUF    512        /* # of bytes at a time to loadbuf*/
  306.  
  307. /*
  308.  * IOCTL arguments
  309.  */
  310.  
  311.  
  312. /*
  313.  * Reserve a page-aligned block of kernel memory for the module
  314.  */
  315. struct lmc_resrv {
  316.     unsigned long    size;        /* IN: size of module to reserve*/
  317.     char        *name;        /* IN: name (must be provided*/
  318.     int        slot;        /* OUT: allocated slot (module ID)*/
  319.     unsigned long    addr;        /* OUT: Link-to address*/
  320. };
  321.  
  322.  
  323. /*
  324.  * Copy a buffer at a time into the allocated area in the kernel; writes
  325.  * are assumed to occur contiguously.
  326.  */
  327. struct lmc_loadbuf {
  328.     int        cnt;        /* IN: # of chars pointed to by data*/
  329.     char        *data;        /* IN: pointer to data buffer*/
  330. };
  331.  
  332.  
  333. /*
  334.  * Load a module (assumes it's been mmapped to address before call)
  335.  */
  336. struct lmc_load {
  337.     caddr_t        address;    /* IN: user space mmap address*/
  338.     int        status;        /* OUT: status of operation*/
  339.     int        id;        /* OUT: module ID if loaded*/
  340. };
  341.  
  342. /*
  343.  * Unload a module (by name/id)
  344.  */
  345. struct lmc_unload {
  346.     int        id;        /* IN: module ID to unload*/
  347.     char        *name;        /* IN: module name to unload if id -1*/
  348.     int        status;        /* OUT: status of operation*/
  349. };
  350.  
  351.  
  352. /*
  353.  * Get module information for a given id (or name if id == -1).
  354.  */
  355. struct lmc_stat {
  356.     int        id;            /* IN: module ID to unload*/
  357.     char        name[ MAXLKMNAME];    /* IN/OUT: name of module*/
  358.     int        offset;            /* OUT: target table offset*/
  359.     MODTYPE        type;            /* OUT: type of module*/
  360.     char        *area;            /* OUT: kernel load addr*/
  361.     int        size;            /* OUT: module size (pages)*/
  362.     unsigned long    private;        /* OUT: module private data*/
  363.     int        ver;            /* OUT: lkm compile version*/
  364. };
  365.  
  366. #endif    /* !_SYS_LKM_H_ */
  367.