The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/device.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: device.h,v 1.92 2006/08/28 01:46:10 christos Exp $ */
    2 
    3 /*
    4  * Copyright (c) 1996, 2000 Christopher G. Demetriou
    5  * All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *          This product includes software developed for the
   18  *          NetBSD Project.  See http://www.NetBSD.org/ for
   19  *          information about NetBSD.
   20  * 4. The name of the author may not be used to endorse or promote products
   21  *    derived from this software without specific prior written permission.
   22  *
   23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   33  *
   34  * --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
   35  */
   36 
   37 /*
   38  * Copyright (c) 1992, 1993
   39  *      The Regents of the University of California.  All rights reserved.
   40  *
   41  * This software was developed by the Computer Systems Engineering group
   42  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
   43  * contributed to Berkeley.
   44  *
   45  * All advertising materials mentioning features or use of this software
   46  * must display the following acknowledgement:
   47  *      This product includes software developed by the University of
   48  *      California, Lawrence Berkeley Laboratories.
   49  *
   50  * Redistribution and use in source and binary forms, with or without
   51  * modification, are permitted provided that the following conditions
   52  * are met:
   53  * 1. Redistributions of source code must retain the above copyright
   54  *    notice, this list of conditions and the following disclaimer.
   55  * 2. Redistributions in binary form must reproduce the above copyright
   56  *    notice, this list of conditions and the following disclaimer in the
   57  *    documentation and/or other materials provided with the distribution.
   58  * 3. Neither the name of the University nor the names of its contributors
   59  *    may be used to endorse or promote products derived from this software
   60  *    without specific prior written permission.
   61  *
   62  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   63  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   65  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   66  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   67  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   68  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   70  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   71  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   72  * SUCH DAMAGE.
   73  *
   74  *      @(#)device.h    8.2 (Berkeley) 2/17/94
   75  */
   76 
   77 #ifndef _SYS_DEVICE_H_
   78 #define _SYS_DEVICE_H_
   79 
   80 #include <sys/evcnt.h>
   81 #include <sys/queue.h>
   82 
   83 #include <prop/proplib.h>
   84 
   85 /*
   86  * Minimal device structures.
   87  * Note that all ``system'' device types are listed here.
   88  */
   89 typedef enum devclass {
   90         DV_DULL,                /* generic, no special info */
   91         DV_CPU,                 /* CPU (carries resource utilization) */
   92         DV_DISK,                /* disk drive (label, etc) */
   93         DV_IFNET,               /* network interface */
   94         DV_TAPE,                /* tape device */
   95         DV_TTY                  /* serial line interface (?) */
   96 } devclass_t;
   97 
   98 /*
   99  * Actions for ca_activate.
  100  */
  101 typedef enum devact {
  102         DVACT_ACTIVATE,         /* activate the device */
  103         DVACT_DEACTIVATE        /* deactivate the device */
  104 } devact_t;
  105 
  106 typedef struct cfdata *cfdata_t;
  107 typedef struct cfdriver *cfdriver_t;
  108 typedef struct cfattach *cfattach_t;
  109 typedef struct device *device_t;
  110 
  111 struct device {
  112         devclass_t      dv_class;       /* this device's classification */
  113         TAILQ_ENTRY(device) dv_list;    /* entry on list of all devices */
  114         cfdata_t        dv_cfdata;      /* config data that found us
  115                                            (NULL if pseudo-device) */
  116         cfdriver_t      dv_cfdriver;    /* our cfdriver */
  117         cfattach_t      dv_cfattach;    /* our cfattach */
  118         int             dv_unit;        /* device unit number */
  119         char            dv_xname[16];   /* external name (name + unit) */
  120         device_t        dv_parent;      /* pointer to parent device
  121                                            (NULL if pesudo- or root node) */
  122         int             dv_flags;       /* misc. flags; see below */
  123         int             *dv_locators;   /* our actual locators (optional) */
  124         prop_dictionary_t dv_properties;/* properties dictionary */
  125 };
  126 
  127 /* dv_flags */
  128 #define DVF_ACTIVE      0x0001          /* device is activated */
  129 
  130 TAILQ_HEAD(devicelist, device);
  131 
  132 /*
  133  * Description of a locator, as part of interface attribute definitions.
  134  */
  135 struct cflocdesc {
  136         const char *cld_name;
  137         const char *cld_defaultstr; /* NULL if no default */
  138         int cld_default;
  139 };
  140 
  141 /*
  142  * Description of an interface attribute, provided by potential
  143  * parent device drivers, referred to by child device configuration data.
  144  */
  145 struct cfiattrdata {
  146         const char *ci_name;
  147         int ci_loclen;
  148         const struct cflocdesc ci_locdesc[
  149 #if defined(__GNUC__) && __GNUC__ <= 2
  150                 0
  151 #endif
  152         ];
  153 };
  154 
  155 /*
  156  * Description of a configuration parent.  Each device attachment attaches
  157  * to an "interface attribute", which is given in this structure.  The parent
  158  * *must* carry this attribute.  Optionally, an individual device instance
  159  * may also specify a specific parent device instance.
  160  */
  161 struct cfparent {
  162         const char *cfp_iattr;          /* interface attribute */
  163         const char *cfp_parent;         /* optional specific parent */
  164         int cfp_unit;                   /* optional specific unit
  165                                            (-1 to wildcard) */
  166 };
  167 
  168 /*
  169  * Configuration data (i.e., data placed in ioconf.c).
  170  */
  171 struct cfdata {
  172         const char *cf_name;            /* driver name */
  173         const char *cf_atname;          /* attachment name */
  174         short   cf_unit;                /* unit number */
  175         short   cf_fstate;              /* finding state (below) */
  176         int     *cf_loc;                /* locators (machine dependent) */
  177         int     cf_flags;               /* flags from config */
  178         const struct cfparent *cf_pspec;/* parent specification */
  179 };
  180 #define FSTATE_NOTFOUND         0       /* has not been found */
  181 #define FSTATE_FOUND            1       /* has been found */
  182 #define FSTATE_STAR             2       /* duplicable */
  183 #define FSTATE_DSTAR            3       /* has not been found, and disabled */
  184 #define FSTATE_DNOTFOUND        4       /* duplicate, and disabled */
  185 
  186 /*
  187  * Multiple configuration data tables may be maintained.  This structure
  188  * provides the linkage.
  189  */
  190 struct cftable {
  191         cfdata_t        ct_cfdata;      /* pointer to cfdata table */
  192         TAILQ_ENTRY(cftable) ct_list;   /* list linkage */
  193 };
  194 TAILQ_HEAD(cftablelist, cftable);
  195 
  196 typedef int (*cfsubmatch_t)(device_t, cfdata_t, const int *, void *);
  197 
  198 /*
  199  * `configuration' attachment and driver (what the machine-independent
  200  * autoconf uses).  As devices are found, they are applied against all
  201  * the potential matches.  The one with the best match is taken, and a
  202  * device structure (plus any other data desired) is allocated.  Pointers
  203  * to these are placed into an array of pointers.  The array itself must
  204  * be dynamic since devices can be found long after the machine is up
  205  * and running.
  206  *
  207  * Devices can have multiple configuration attachments if they attach
  208  * to different attributes (busses, or whatever), to allow specification
  209  * of multiple match and attach functions.  There is only one configuration
  210  * driver per driver, so that things like unit numbers and the device
  211  * structure array will be shared.
  212  */
  213 struct cfattach {
  214         const char *ca_name;            /* name of attachment */
  215         LIST_ENTRY(cfattach) ca_list;   /* link on cfdriver's list */
  216         size_t    ca_devsize;           /* size of dev data (for malloc) */
  217         int     (*ca_match)(device_t, cfdata_t, void *);
  218         void    (*ca_attach)(device_t, device_t, void *);
  219         int     (*ca_detach)(device_t, int);
  220         int     (*ca_activate)(device_t, devact_t);
  221         /* technically, the next 2 belong into "struct cfdriver" */
  222         int     (*ca_rescan)(device_t, const char *,
  223                              const int *); /* scan for new children */
  224         void    (*ca_childdetached)(device_t, device_t);
  225 };
  226 LIST_HEAD(cfattachlist, cfattach);
  227 
  228 #define CFATTACH_DECL(name, ddsize, matfn, attfn, detfn, actfn)         \
  229 struct cfattach __CONCAT(name,_ca) = {                                  \
  230     ___STRING(name), { NULL, NULL }, ddsize, matfn, attfn, detfn, actfn, 0, 0 \
  231 }
  232 
  233 #define CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, \
  234         rescanfn, chdetfn) \
  235 struct cfattach __CONCAT(name,_ca) = {                                  \
  236     ___STRING(name), { NULL, NULL }, ddsize, matfn, attfn, detfn, actfn, \
  237                 rescanfn, chdetfn \
  238 }
  239 
  240 /* Flags given to config_detach(), and the ca_detach function. */
  241 #define DETACH_FORCE    0x01            /* force detachment; hardware gone */
  242 #define DETACH_QUIET    0x02            /* don't print a notice */
  243 
  244 struct cfdriver {
  245         LIST_ENTRY(cfdriver) cd_list;   /* link on allcfdrivers */
  246         struct cfattachlist cd_attach;  /* list of all attachments */
  247         void    **cd_devs;              /* devices found */
  248         const char *cd_name;            /* device name */
  249         enum    devclass cd_class;      /* device classification */
  250         int     cd_ndevs;               /* size of cd_devs array */
  251         const struct cfiattrdata * const *cd_attrs; /* attributes provided */
  252 };
  253 LIST_HEAD(cfdriverlist, cfdriver);
  254 
  255 #define CFDRIVER_DECL(name, class, attrs)                               \
  256 struct cfdriver __CONCAT(name,_cd) = {                                  \
  257     { NULL, NULL }, { NULL }, NULL, ___STRING(name), class, 0, attrs    \
  258 }
  259 
  260 /*
  261  * The cfattachinit is a data structure used to associate a list of
  262  * cfattach's with cfdrivers as found in the static kernel configuration.
  263  */
  264 struct cfattachinit {
  265         const char *cfai_name;           /* driver name */
  266         struct cfattach * const *cfai_list;/* list of attachments */
  267 };
  268 /*
  269  * the same, but with a non-constant list so it can be modified
  270  * for LKM bookkeeping
  271  */
  272 struct cfattachlkminit {
  273         const char *cfai_name;          /* driver name */
  274         struct cfattach **cfai_list;    /* list of attachments */
  275 };
  276 
  277 /*
  278  * Configuration printing functions, and their return codes.  The second
  279  * argument is NULL if the device was configured; otherwise it is the name
  280  * of the parent device.  The return value is ignored if the device was
  281  * configured, so most functions can return UNCONF unconditionally.
  282  */
  283 typedef int (*cfprint_t)(void *, const char *);         /* XXX const char * */
  284 #define QUIET   0               /* print nothing */
  285 #define UNCONF  1               /* print " not configured\n" */
  286 #define UNSUPP  2               /* print " not supported\n" */
  287 
  288 /*
  289  * Pseudo-device attach information (function + number of pseudo-devs).
  290  */
  291 struct pdevinit {
  292         void    (*pdev_attach)(int);
  293         int     pdev_count;
  294 };
  295 
  296 /* This allows us to wildcard a device unit. */
  297 #define DVUNIT_ANY      -1
  298 
  299 #ifdef _KERNEL
  300 
  301 extern struct cfdriverlist allcfdrivers;/* list of all cfdrivers */
  302 extern struct devicelist alldevs;       /* list of all devices */
  303 extern struct cftablelist allcftables;  /* list of all cfdata tables */
  304 extern device_t booted_device;          /* the device we booted from */
  305 extern device_t booted_wedge;           /* the wedge on that device */
  306 extern int booted_partition;            /* or the partition on that device */
  307 
  308 extern volatile int config_pending;     /* semaphore for mountroot */
  309 
  310 void    config_init(void);
  311 void    configure(void);
  312 
  313 int     config_cfdriver_attach(struct cfdriver *);
  314 int     config_cfdriver_detach(struct cfdriver *);
  315 
  316 int     config_cfattach_attach(const char *, struct cfattach *);
  317 int     config_cfattach_detach(const char *, struct cfattach *);
  318 
  319 int     config_cfdata_attach(cfdata_t, int);
  320 int     config_cfdata_detach(cfdata_t);
  321 
  322 struct cfdriver *config_cfdriver_lookup(const char *);
  323 struct cfattach *config_cfattach_lookup(const char *, const char *);
  324 const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *);
  325 
  326 int     config_stdsubmatch(device_t, cfdata_t, const int *, void *);
  327 cfdata_t config_search_loc(cfsubmatch_t, device_t,
  328                                  const char *, const int *, void *);
  329 cfdata_t config_search_ia(cfsubmatch_t, device_t,
  330                                  const char *, void *);
  331 cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *);
  332 device_t config_found_sm_loc(device_t, const char *, const int *,
  333                              void *, cfprint_t, cfsubmatch_t);
  334 device_t config_found_ia(device_t, const char *, void *, cfprint_t);
  335 device_t config_found(device_t, void *, cfprint_t);
  336 device_t config_rootfound(const char *, void *);
  337 device_t config_attach_loc(device_t, cfdata_t, const int *, void *, cfprint_t);
  338 device_t config_attach(device_t, cfdata_t, void *, cfprint_t);
  339 int     config_match(device_t, cfdata_t, void *);
  340 
  341 device_t config_attach_pseudo(cfdata_t);
  342 
  343 void    config_makeroom(int n, struct cfdriver *cd);
  344 int     config_detach(device_t, int);
  345 int     config_activate(device_t);
  346 int     config_deactivate(device_t);
  347 void    config_defer(device_t, void (*)(device_t));
  348 void    config_interrupts(device_t, void (*)(device_t));
  349 void    config_pending_incr(void);
  350 void    config_pending_decr(void);
  351 
  352 int     config_finalize_register(device_t, int (*)(device_t));
  353 void    config_finalize(void);
  354 
  355 void            *device_lookup(cfdriver_t, int);
  356 #ifdef __HAVE_DEVICE_REGISTER
  357 void            device_register(device_t, void *);
  358 #endif
  359 
  360 devclass_t      device_class(device_t);
  361 cfdata_t        device_cfdata(device_t);
  362 cfdriver_t      device_cfdriver(device_t);
  363 cfattach_t      device_cfattach(device_t);
  364 int             device_unit(device_t);
  365 const char      *device_xname(device_t);
  366 device_t        device_parent(device_t);
  367 boolean_t       device_is_active(device_t);
  368 int             device_locator(device_t, u_int);
  369 void            *device_private(device_t);
  370 prop_dictionary_t device_properties(device_t);
  371 
  372 boolean_t       device_is_a(device_t, const char *);
  373 
  374 #endif /* _KERNEL */
  375 
  376 #endif /* !_SYS_DEVICE_H_ */

Cache object: 1000b09037d7561dd63f1396d0266206


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.