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/bus.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 /*-
    2  * Copyright (c) 1997,1998 Doug Rabson
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  *
   26  * $FreeBSD$
   27  */
   28 
   29 #ifndef _SYS_BUS_H_
   30 #define _SYS_BUS_H_
   31 
   32 #ifdef KERNEL
   33 
   34 /*
   35  * Forward declarations
   36  */
   37 typedef struct device           *device_t;
   38 typedef struct driver           driver_t;
   39 typedef struct device_method    device_method_t;
   40 typedef struct devclass         *devclass_t;
   41 typedef struct device_ops       *device_ops_t;
   42 typedef struct device_op_desc   *device_op_desc_t;
   43 
   44 typedef void driver_intr_t(void*);
   45 
   46 /*
   47  * We define this in terms of bits because some devices may belong
   48  * to multiple classes (and therefore need to be included in
   49  * multiple interrupt masks, which is what this really serves to
   50  * indicate.  Buses which do interrupt remapping will want to
   51  * change their type to reflect what sort of devices are underneath.
   52  */
   53 typedef enum driver_type {
   54     DRIVER_TYPE_TTY = 1,
   55     DRIVER_TYPE_BIO = 2,
   56     DRIVER_TYPE_NET = 4,
   57     DRIVER_TYPE_CAM = 8,
   58     DRIVER_TYPE_MISC = 16,
   59     DRIVER_TYPE_FAST = 128
   60 } driver_type_t;
   61 
   62 typedef int (*devop_t)(void);
   63 
   64 struct device_method {
   65     device_op_desc_t    desc;
   66     devop_t             func;
   67 };
   68 
   69 struct driver {
   70     const char          *name;          /* driver name */
   71     device_method_t     *methods;       /* method table */
   72     driver_type_t       type;
   73     size_t              softc;          /* size of device softc struct */
   74     void                *priv;          /* driver private data */
   75     TAILQ_ENTRY(driver) link;           /* list of devices on bus */
   76     device_ops_t        ops;            /* compiled method table */
   77 };
   78 
   79 typedef enum device_state device_state_t;
   80 enum device_state {
   81     DS_NOTPRESENT,                      /* not probed or probe failed */
   82     DS_ALIVE,                           /* probe succeeded */
   83     DS_ATTACHED,                        /* attach method called */
   84     DS_BUSY                             /* device is open */
   85 };
   86 
   87 /*
   88  * The root bus, to which all top-level busses are attached.
   89  */
   90 extern device_t root_bus;
   91 extern devclass_t root_devclass;
   92 void    root_bus_configure(void);
   93 
   94 /*
   95  * Useful functions for implementing busses.
   96  */
   97 struct  resource;
   98 
   99 int     bus_generic_activate_resource(device_t dev, device_t child, int type,
  100                                       int rid, struct resource *r);
  101 struct resource *bus_generic_alloc_resource(device_t bus, device_t child,
  102                                             int type, int *rid,
  103                                             u_long start, u_long end,
  104                                             u_long count, u_int flags);
  105 int     bus_generic_attach(device_t dev);
  106 int     bus_generic_deactivate_resource(device_t dev, device_t child, int type,
  107                                         int rid, struct resource *r);
  108 int     bus_generic_detach(device_t dev);
  109 void    bus_generic_print_child(device_t dev, device_t child);
  110 int     bus_generic_read_ivar(device_t dev, device_t child, int which,
  111                               uintptr_t *result);
  112 int     bus_generic_release_resource(device_t bus, device_t child,
  113                                      int type, int rid, struct resource *r);
  114 int     bus_generic_resume(device_t dev);
  115 int     bus_generic_setup_intr(device_t dev, device_t child,
  116                                struct resource *irq,
  117                                driver_intr_t *intr, void *arg, void **cookiep);
  118 int     bus_generic_shutdown(device_t dev);
  119 int     bus_generic_suspend(device_t dev);
  120 int     bus_generic_teardown_intr(device_t dev, device_t child,
  121                                   struct resource *irq, void *cookie);
  122 int     bus_generic_write_ivar(device_t dev, device_t child, int which,
  123                                uintptr_t value);
  124 
  125 /*
  126  * Wrapper functions for the BUS_*_RESOURCE methods to make client code
  127  * a little simpler.
  128  */
  129 struct  resource *bus_alloc_resource(device_t dev, int type, int *rid,
  130                                      u_long start, u_long end, u_long count,
  131                                      u_int flags);
  132 int     bus_activate_resource(device_t dev, int type, int rid, 
  133                               struct resource *r);
  134 int     bus_deactivate_resource(device_t dev, int type, int rid,
  135                                 struct resource *r);
  136 int     bus_release_resource(device_t dev, int type, int rid, 
  137                              struct resource *r);
  138 
  139 /*
  140  * Access functions for device.
  141  */
  142 device_t        device_add_child(device_t dev, const char *name, int unit,
  143                                  void *ivp);
  144 device_t        device_add_child_after(device_t dev, device_t place,
  145                                        const char *name, int unit, void *ivp);
  146 void    device_busy(device_t dev);
  147 int     device_delete_child(device_t dev, device_t child);
  148 int     device_detach(device_t dev);
  149 void    device_disable(device_t dev);
  150 void    device_enable(device_t dev);
  151 device_t        device_find_child(device_t dev, const char *classname,
  152                                   int unit);
  153 const char      *device_get_desc(device_t dev);
  154 devclass_t      device_get_devclass(device_t dev);
  155 driver_t        *device_get_driver(device_t dev);
  156 device_t        device_get_parent(device_t dev);
  157 int     device_get_children(device_t dev, device_t **listp, int *countp);
  158 void    *device_get_ivars(device_t dev);
  159 const   char *device_get_name(device_t dev);
  160 void    *device_get_softc(device_t dev);
  161 device_state_t  device_get_state(device_t dev);
  162 int     device_get_unit(device_t dev);
  163 int     device_is_enabled(device_t dev);
  164 int     device_is_alive(device_t dev); /* did probe succeed? */
  165 void    device_print_prettyname(device_t dev);
  166 void    device_printf(device_t dev, const char *, ...) __printflike(2, 3);
  167 int     device_probe_and_attach(device_t dev);
  168 void    device_set_desc(device_t dev, const char* desc);
  169 int     device_set_devclass(device_t dev, const char *classname);
  170 int     device_set_driver(device_t dev, driver_t *driver);
  171 int     device_shutdown(device_t dev);
  172 void    device_unbusy(device_t dev);
  173 
  174 /*
  175  * Access functions for devclass.
  176  */
  177 int     devclass_add_driver(devclass_t dc, driver_t *driver);
  178 int     devclass_delete_driver(devclass_t dc, driver_t *driver);
  179 devclass_t      devclass_find(const char *classname);
  180 driver_t        *devclass_find_driver(devclass_t dc, const char *classname);
  181 const char      *devclass_get_name(devclass_t dc);
  182 device_t        devclass_get_device(devclass_t dc, int unit);
  183 void    *devclass_get_softc(devclass_t dc, int unit);
  184 int     devclass_get_devices(devclass_t dc, device_t **listp, int *countp);
  185 int     devclass_get_maxunit(devclass_t dc);
  186 
  187 /*
  188  * Access functions for device resources.
  189  */
  190 int     resource_int_value(const char *name, int unit, char *resname,
  191                            int *result);
  192 int     resource_long_value(const char *name, int unit, char *resname,
  193                             long *result);
  194 int     resource_string_value(const char *name, int unit, char *resname,
  195                               char **result);
  196 int     resource_query_string(int i, char *resname, char *value);
  197 char    *resource_query_name(int i);
  198 int     resource_query_unit(int i);
  199 
  200 /*
  201  * Shorthand for constructing method tables.
  202  */
  203 #define DEVMETHOD(NAME, FUNC) { &NAME##_desc, (devop_t) FUNC }
  204 
  205 /*
  206  * Some common device interfaces.
  207  */
  208 #include "device_if.h"
  209 #include "bus_if.h"
  210 
  211 struct  module;
  212 
  213 int     driver_module_handler(struct module *, int, void *);
  214 
  215 /*
  216  * Module support for automatically adding drivers to busses.
  217  */
  218 struct driver_module_data {
  219         int             (*dmd_chainevh)(struct module *, int, void *);
  220         void            *dmd_chainarg;
  221         const char      *dmd_busname;
  222         driver_t        **dmd_drivers;
  223         int             dmd_ndrivers;
  224         devclass_t      *dmd_devclass;
  225 };
  226 
  227 #define DRIVER_MODULE(name, busname, driver, devclass, evh, arg)        \
  228                                                                         \
  229 static driver_t *name##_##busname##_driver_list[] = { &driver };        \
  230 static struct driver_module_data name##_##busname##_driver_mod = {      \
  231         evh, arg,                                                       \
  232         #busname,                                                       \
  233         name##_##busname##_driver_list,                                 \
  234         (sizeof name##_##busname##_driver_list) /                       \
  235                 (sizeof name##_##busname##_driver_list[0]),             \
  236         &devclass                                                       \
  237 };                                                                      \
  238                                                                         \
  239 static moduledata_t name##_##busname##_mod = {                          \
  240         #busname "/" #name,                                             \
  241         driver_module_handler,                                          \
  242         &name##_##busname##_driver_mod                                  \
  243 };                                                                      \
  244 DECLARE_MODULE(name##_##busname, name##_##busname##_mod,                \
  245                SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
  246 
  247 #define MULTI_DRIVER_MODULE(name, busname, drivers, devclass, evh, arg) \
  248                                                                         \
  249 static driver_t name##_##busname##_driver_list[] = drivers;             \
  250 static struct driver_module_data name##_##busname##_driver_mod = {      \
  251         evh, arg,                                                       \
  252         #busname,                                                       \
  253         name##_##busname##_driver_list,                                 \
  254         (sizeof name##_##busname##_driver_list) /                       \
  255                 (sizeof name##_##busname##_driver_list[0]),             \
  256         &devclass                                                       \
  257 };                                                                      \
  258                                                                         \
  259 static moduledata_t name##_##busname##_mod = {                          \
  260         #busname "/" #name,                                             \
  261         driver_module_handler,                                          \
  262         &name##_##busname##_driver_mod                                  \
  263 };                                                                      \
  264 DECLARE_MODULE(name##_##busname, name##_##busname##_mod,                \
  265                SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
  266 
  267 #define CDEV_DRIVER_MODULE(name, busname, driver, devclass,             \
  268                            major, devsw, evh, arg)                      \
  269                                                                         \
  270 static struct cdevsw_module_data name##_##busname##_cdevsw_mod = {      \
  271     evh, arg, makedev(major, 0), &devsw                                 \
  272 };                                                                      \
  273                                                                         \
  274 DRIVER_MODULE(name, busname, driver, devclass,                          \
  275               cdevsw_module_handler, &name##_##busname##_cdevsw_mod)
  276 
  277 #define BDEV_DRIVER_MODULE(name, busname, driver, devclass,             \
  278                            bmajor, cmajor, devsw, evh, arg)             \
  279                                                                         \
  280 static struct bdevsw_module_data name##_##busname##_bdevsw_mod = {      \
  281     evh, arg, makedev(bmajor, 0), makedev(cmajor, 0), &devsw            \
  282 };                                                                      \
  283                                                                         \
  284 DRIVER_MODULE(name, busname, driver, devclass,                          \
  285               bdevsw_module_handler, &name##_##busname##_bdevsw_mod)
  286 
  287 #endif /* KERNEL */
  288 
  289 #endif /* !_SYS_BUS_H_ */

Cache object: c79ad4d9409f6d5f170b05b68cd8c40e


[ 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.