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/kern/subr_autoconf.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1992, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * This software was developed by the Computer Systems Engineering group
    6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
    7  * contributed to Berkeley.
    8  *
    9  * Redistribution and use in source and binary forms, with or without
   10  * modification, are permitted provided that the following conditions
   11  * are met:
   12  * 1. Redistributions of source code must retain the above copyright
   13  *    notice, this list of conditions and the following disclaimer.
   14  * 2. Redistributions in binary form must reproduce the above copyright
   15  *    notice, this list of conditions and the following disclaimer in the
   16  *    documentation and/or other materials provided with the distribution.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  *      @(#)subr_autoconf.c     8.1 (Berkeley) 6/10/93
   34  *
   35  */
   36 
   37 #include <sys/cdefs.h>
   38 __FBSDID("$FreeBSD: stable/7/sys/kern/subr_autoconf.c 218277 2011-02-04 14:44:59Z jhb $");
   39 
   40 #include "opt_ddb.h"
   41 
   42 #include <sys/param.h>
   43 #include <sys/kernel.h>
   44 #include <sys/linker.h>
   45 #include <sys/lock.h>
   46 #include <sys/mutex.h>
   47 #include <sys/systm.h>
   48 
   49 /*
   50  * Autoconfiguration subroutines.
   51  */
   52 
   53 /*
   54  * "Interrupt driven config" functions.
   55  */
   56 static TAILQ_HEAD(, intr_config_hook) intr_config_hook_list =
   57         TAILQ_HEAD_INITIALIZER(intr_config_hook_list);
   58 static struct mtx intr_config_hook_lock;
   59 MTX_SYSINIT(intr_config_hook, &intr_config_hook_lock, "intr config", MTX_DEF);
   60 
   61 /* ARGSUSED */
   62 static void run_interrupt_driven_config_hooks(void *dummy);
   63 
   64 /*
   65  * If we wait too long for an interrupt-driven config hook to return, print
   66  * a diagnostic.
   67  */
   68 #define WARNING_INTERVAL_SECS   60
   69 static void
   70 run_interrupt_driven_config_hooks_warning(int warned)
   71 {
   72         struct intr_config_hook *hook_entry;
   73         char namebuf[64];
   74         long offset;
   75 
   76         if (warned < 6) {
   77                 printf("run_interrupt_driven_hooks: still waiting after %d "
   78                     "seconds for", warned * WARNING_INTERVAL_SECS);
   79                 TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
   80                         if (linker_search_symbol_name(
   81                             (caddr_t)hook_entry->ich_func, namebuf,
   82                             sizeof(namebuf), &offset) == 0)
   83                                 printf(" %s", namebuf);
   84                         else
   85                                 printf(" %p", hook_entry->ich_func);
   86                 }
   87                 printf("\n");
   88         }
   89         KASSERT(warned < 6,
   90             ("run_interrupt_driven_config_hooks: waited too long"));
   91 }
   92 
   93 static void
   94 run_interrupt_driven_config_hooks(dummy)
   95         void *dummy;
   96 {
   97         struct intr_config_hook *hook_entry, *next_entry;
   98         int warned;
   99 
  100         mtx_lock(&intr_config_hook_lock);
  101         TAILQ_FOREACH_SAFE(hook_entry, &intr_config_hook_list, ich_links,
  102             next_entry) {
  103                 mtx_unlock(&intr_config_hook_lock);
  104                 (*hook_entry->ich_func)(hook_entry->ich_arg);
  105                 mtx_lock(&intr_config_hook_lock);
  106         }
  107 
  108         warned = 0;
  109         while (!TAILQ_EMPTY(&intr_config_hook_list)) {
  110                 if (msleep(&intr_config_hook_list, &intr_config_hook_lock,
  111                     0, "conifhk", WARNING_INTERVAL_SECS * hz) ==
  112                     EWOULDBLOCK) {
  113                         mtx_unlock(&intr_config_hook_lock);
  114                         warned++;
  115                         run_interrupt_driven_config_hooks_warning(warned);
  116                         mtx_lock(&intr_config_hook_lock);
  117                 }
  118         }
  119         mtx_unlock(&intr_config_hook_lock);
  120 }
  121 SYSINIT(intr_config_hooks, SI_SUB_INT_CONFIG_HOOKS, SI_ORDER_FIRST,
  122         run_interrupt_driven_config_hooks, NULL);
  123 
  124 /*
  125  * Register a hook that will be called after "cold"
  126  * autoconfiguration is complete and interrupts can
  127  * be used to complete initialization.
  128  */
  129 int
  130 config_intrhook_establish(hook)
  131         struct intr_config_hook *hook;
  132 {
  133         struct intr_config_hook *hook_entry;
  134 
  135         mtx_lock(&intr_config_hook_lock);
  136         TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links)
  137                 if (hook_entry == hook)
  138                         break;
  139         if (hook_entry != NULL) {
  140                 mtx_unlock(&intr_config_hook_lock);
  141                 printf("config_intrhook_establish: establishing an "
  142                        "already established hook.\n");
  143                 return (1);
  144         }
  145         TAILQ_INSERT_TAIL(&intr_config_hook_list, hook, ich_links);
  146         mtx_unlock(&intr_config_hook_lock);
  147         if (cold == 0)
  148                 /* XXX Sufficient for modules loaded after initial config??? */
  149                 run_interrupt_driven_config_hooks(NULL);        
  150         return (0);
  151 }
  152 
  153 void
  154 config_intrhook_disestablish(hook)
  155         struct intr_config_hook *hook;
  156 {
  157         struct intr_config_hook *hook_entry;
  158 
  159         mtx_lock(&intr_config_hook_lock);
  160         TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links)
  161                 if (hook_entry == hook)
  162                         break;
  163         if (hook_entry == NULL)
  164                 panic("config_intrhook_disestablish: disestablishing an "
  165                       "unestablished hook");
  166 
  167         TAILQ_REMOVE(&intr_config_hook_list, hook, ich_links);
  168 
  169         /* Wakeup anyone watching the list */
  170         wakeup(&intr_config_hook_list);
  171         mtx_unlock(&intr_config_hook_lock);
  172 }
  173 
  174 #ifdef DDB
  175 #include <ddb/ddb.h>
  176 
  177 DB_SHOW_COMMAND(conifhk, db_show_conifhk)
  178 {
  179         struct intr_config_hook *hook_entry;
  180         char namebuf[64];
  181         long offset;
  182 
  183         TAILQ_FOREACH(hook_entry, &intr_config_hook_list, ich_links) {
  184                 if (linker_ddb_search_symbol_name(
  185                     (caddr_t)hook_entry->ich_func, namebuf, sizeof(namebuf),
  186                     &offset) == 0) {
  187                         db_printf("hook: %p at %s+%#lx arg: %p\n",
  188                             hook_entry->ich_func, namebuf, offset,
  189                             hook_entry->ich_arg);
  190                 } else {
  191                         db_printf("hook: %p at ??+?? arg %p\n",
  192                             hook_entry->ich_func, hook_entry->ich_arg);
  193                 }
  194         }
  195 }
  196 #endif /* DDB */

Cache object: 4a3bb5601a44ac0e6466058f0a949956


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