[BACK]Return to device.h CVS log [TXT][DIR] Up to [local] / sys / sys

Annotation of sys/sys/device.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: device.h,v 1.36 2007/05/15 01:56:47 deraadt Exp $     */
                      2: /*     $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd Exp $  */
                      3:
                      4: /*
                      5:  * Copyright (c) 1992, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * This software was developed by the Computer Systems Engineering group
                      9:  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
                     10:  * contributed to Berkeley.
                     11:  *
                     12:  * All advertising materials mentioning features or use of this software
                     13:  * must display the following acknowledgement:
                     14:  *     This product includes software developed by the University of
                     15:  *     California, Lawrence Berkeley Laboratory.
                     16:  *
                     17:  * Redistribution and use in source and binary forms, with or without
                     18:  * modification, are permitted provided that the following conditions
                     19:  * are met:
                     20:  * 1. Redistributions of source code must retain the above copyright
                     21:  *    notice, this list of conditions and the following disclaimer.
                     22:  * 2. Redistributions in binary form must reproduce the above copyright
                     23:  *    notice, this list of conditions and the following disclaimer in the
                     24:  *    documentation and/or other materials provided with the distribution.
                     25:  * 3. Neither the name of the University nor the names of its contributors
                     26:  *    may be used to endorse or promote products derived from this software
                     27:  *    without specific prior written permission.
                     28:  *
                     29:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     30:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     31:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     32:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     33:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     34:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     35:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     36:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     37:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     38:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     39:  * SUCH DAMAGE.
                     40:  *
                     41:  *     @(#)device.h    8.2 (Berkeley) 2/17/94
                     42:  */
                     43:
                     44: #ifndef _SYS_DEVICE_H_
                     45: #define        _SYS_DEVICE_H_
                     46:
                     47: #include <sys/queue.h>
                     48:
                     49: /*
                     50:  * Minimal device structures.
                     51:  * Note that all ``system'' device types are listed here.
                     52:  */
                     53: enum devclass {
                     54:        DV_DULL,                /* generic, no special info */
                     55:        DV_CPU,                 /* CPU (carries resource utilization) */
                     56:        DV_DISK,                /* disk drive (label, etc) */
                     57:        DV_IFNET,               /* network interface */
                     58:        DV_TAPE,                /* tape device */
                     59:        DV_TTY                  /* serial line interface (???) */
                     60: };
                     61:
                     62: /*
                     63:  * Actions for ca_activate.
                     64:  */
                     65: enum devact {
                     66:        DVACT_ACTIVATE,         /* activate the device */
                     67:        DVACT_DEACTIVATE        /* deactivate the device */
                     68: };
                     69:
                     70: #include <sys/lock.h>
                     71:
                     72: struct device {
                     73:        enum    devclass dv_class;      /* this device's classification */
                     74:        TAILQ_ENTRY(device) dv_list;    /* entry on list of all devices */
                     75:        struct  cfdata *dv_cfdata;      /* config data that found us */
                     76:        int     dv_unit;                /* device unit number */
                     77:        char    dv_xname[16];           /* external name (name + unit) */
                     78:        struct  device *dv_parent;      /* pointer to parent device */
                     79:        int     dv_flags;               /* misc. flags; see below */
                     80:        int     dv_ref;                 /* ref count */
                     81: };
                     82:
                     83: /* dv_flags */
                     84: #define        DVF_ACTIVE      0x0001          /* device is activated */
                     85:
                     86: TAILQ_HEAD(devicelist, device);
                     87:
                     88: /*
                     89:  * Configuration data (i.e., data placed in ioconf.c).
                     90:  */
                     91: struct cfdata {
                     92:        struct  cfattach *cf_attach;    /* config attachment */
                     93:        struct  cfdriver *cf_driver;    /* config driver */
                     94:        short   cf_unit;                /* unit number */
                     95:        short   cf_fstate;              /* finding state (below) */
                     96:        int     *cf_loc;                /* locators (machine dependent) */
                     97:        int     cf_flags;               /* flags from config */
                     98:        short   *cf_parents;            /* potential parents */
                     99:        int     cf_locnames;            /* start of names */
                    100:        void    (**cf_ivstubs)(void);   /* config-generated vectors, if any */
                    101:        short   cf_starunit1;           /* 1st usable unit number by STAR */
                    102: };
                    103: extern struct cfdata cfdata[];
                    104: #define FSTATE_NOTFOUND        0       /* has not been found */
                    105: #define        FSTATE_FOUND    1       /* has been found */
                    106: #define        FSTATE_STAR     2       /* duplicable */
                    107: #define FSTATE_DNOTFOUND 3     /* has not been found, and is disabled */
                    108: #define FSTATE_DSTAR   4       /* duplicable, and is disabled */
                    109:
                    110: typedef int (*cfmatch_t)(struct device *, void *, void *);
                    111: typedef void (*cfscan_t)(struct device *, void *);
                    112:
                    113: /*
                    114:  * `configuration' attachment and driver (what the machine-independent
                    115:  * autoconf uses).  As devices are found, they are applied against all
                    116:  * the potential matches.  The one with the best match is taken, and a
                    117:  * device structure (plus any other data desired) is allocated.  Pointers
                    118:  * to these are placed into an array of pointers.  The array itself must
                    119:  * be dynamic since devices can be found long after the machine is up
                    120:  * and running.
                    121:  *
                    122:  * Devices can have multiple configuration attachments if they attach
                    123:  * to different attributes (busses, or whatever), to allow specification
                    124:  * of multiple match and attach functions.  There is only one configuration
                    125:  * driver per driver, so that things like unit numbers and the device
                    126:  * structure array will be shared.
                    127:  */
                    128: struct cfattach {
                    129:        size_t    ca_devsize;           /* size of dev data (for malloc) */
                    130:        cfmatch_t ca_match;             /* returns a match level */
                    131:        void    (*ca_attach)(struct device *, struct device *, void *);
                    132:        int     (*ca_detach)(struct device *, int);
                    133:        int     (*ca_activate)(struct device *, enum devact);
                    134: };
                    135:
                    136: /* Flags given to config_detach(), and the ca_detach function. */
                    137: #define        DETACH_FORCE    0x01            /* force detachment; hardware gone */
                    138: #define        DETACH_QUIET    0x02            /* don't print a notice */
                    139:
                    140: struct cfdriver {
                    141:        void    **cd_devs;              /* devices found */
                    142:        char    *cd_name;               /* device name */
                    143:        enum    devclass cd_class;      /* device classification */
                    144:        int     cd_indirect;            /* indirectly configure subdevices */
                    145:        int     cd_ndevs;               /* size of cd_devs array */
                    146: };
                    147:
                    148: /*
                    149:  * Configuration printing functions, and their return codes.  The second
                    150:  * argument is NULL if the device was configured; otherwise it is the name
                    151:  * of the parent device.  The return value is ignored if the device was
                    152:  * configured, so most functions can return UNCONF unconditionally.
                    153:  */
                    154: typedef int (*cfprint_t)(void *, const char *);
                    155: #define        QUIET   0               /* print nothing */
                    156: #define        UNCONF  1               /* print " not configured\n" */
                    157: #define        UNSUPP  2               /* print " not supported\n" */
                    158:
                    159: /*
                    160:  * Pseudo-device attach information (function + number of pseudo-devs).
                    161:  */
                    162: struct pdevinit {
                    163:        void    (*pdev_attach)(int);
                    164:        int     pdev_count;
                    165: };
                    166:
                    167: #ifdef _KERNEL
                    168: struct cftable {
                    169:        struct cfdata *tab;
                    170:        TAILQ_ENTRY(cftable) list;
                    171: };
                    172: TAILQ_HEAD(cftable_head, cftable);
                    173:
                    174: extern struct devicelist alldevs;      /* list of all devices */
                    175:
                    176: extern int autoconf_verbose;
                    177: extern __volatile int config_pending;  /* semaphore for mountroot */
                    178:
                    179: void config_init(void);
                    180: void *config_search(cfmatch_t, struct device *, void *);
                    181: void *config_rootsearch(cfmatch_t, char *, void *);
                    182: struct device *config_found_sm(struct device *, void *, cfprint_t,
                    183:     cfmatch_t);
                    184: struct device *config_rootfound(char *, void *);
                    185: void config_scan(cfscan_t, struct device *);
                    186: struct device *config_attach(struct device *, void *, void *, cfprint_t);
                    187: int config_detach(struct device *, int);
                    188: int config_detach_children(struct device *, int);
                    189: int config_activate(struct device *);
                    190: int config_deactivate(struct device *);
                    191: int config_activate_children(struct device *, enum devact);
                    192: struct device *config_make_softc(struct device *parent,
                    193:     struct cfdata *cf);
                    194: void config_defer(struct device *, void (*)(struct device *));
                    195: void config_pending_incr(void);
                    196: void config_pending_decr(void);
                    197:
                    198: struct device *device_lookup(struct cfdriver *, int unit);
                    199: void device_ref(struct device *);
                    200: void device_unref(struct device *);
                    201:
                    202: struct nam2blk {
                    203:        char    *name;
                    204:        int     maj;
                    205: };
                    206:
                    207: int    findblkmajor(struct device *dv);
                    208: char   *findblkname(int);
                    209: void   setroot(struct device *, int, int);
                    210: struct device *getdisk(char *str, int len, int defpart, dev_t *devp);
                    211: struct device *parsedisk(char *str, int len, int defpart, dev_t *devp);
                    212: void   device_register(struct device *, void *);
                    213:
                    214: int loadfirmware(const char *name, u_char **bufp, size_t *buflen);
                    215: #define FIRMWARE_MAX   5*1024*1024
                    216:
                    217: /* compatibility definitions */
                    218: #define config_found(d, a, p)  config_found_sm((d), (a), (p), NULL)
                    219:
                    220: #endif /* _KERNEL */
                    221:
                    222: #endif /* !_SYS_DEVICE_H_ */

CVSweb