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/kern_intr.c

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, Stefan Esser <se@freebsd.org>
    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 unmodified, this list of conditions, and the following
   10  *    disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   25  *
   26  * $FreeBSD$
   27  *
   28  */
   29 
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/malloc.h>
   34 #include <sys/kernel.h>
   35 #include <sys/sysctl.h>
   36 
   37 #include <machine/ipl.h>
   38 
   39 #include <sys/interrupt.h>
   40 
   41 struct swilist {
   42         swihand_t       *sl_handler;
   43         struct swilist  *sl_next;
   44 };
   45 
   46 static struct swilist swilists[NSWI];
   47 
   48 void
   49 register_swi(intr, handler)
   50         int intr;
   51         swihand_t *handler;
   52 {
   53         struct swilist *slp, *slq;
   54         int s;
   55 
   56         if (intr < NHWI || intr >= NHWI + NSWI)
   57                 panic("register_swi: bad intr %d", intr);
   58         if (handler == swi_generic || handler == swi_null)
   59                 panic("register_swi: bad handler %p", (void *)handler);
   60         slp = &swilists[intr - NHWI];
   61         s = splhigh();
   62         if (ihandlers[intr] == swi_null)
   63                 ihandlers[intr] = handler;
   64         else {
   65                 if (slp->sl_next == NULL) {
   66                         slp->sl_handler = ihandlers[intr];
   67                         ihandlers[intr] = swi_generic;
   68                 }
   69                 slq = malloc(sizeof(*slq), M_DEVBUF, M_NOWAIT);
   70                 if (slq == NULL)
   71                         panic("register_swi: malloc failed");
   72                 slq->sl_handler = handler;
   73                 slq->sl_next = NULL;
   74                 while (slp->sl_next != NULL)
   75                         slp = slp->sl_next;
   76                 slp->sl_next = slq;
   77         }
   78         splx(s);
   79 }
   80 
   81 void
   82 swi_dispatcher(intr)
   83         int intr;
   84 {
   85         struct swilist *slp;
   86 
   87         slp = &swilists[intr - NHWI];
   88         do {
   89                 (*slp->sl_handler)();
   90                 slp = slp->sl_next;
   91         } while (slp != NULL);
   92 }
   93 
   94 void
   95 unregister_swi(intr, handler)
   96         int intr;
   97         swihand_t *handler;
   98 {
   99         struct swilist *slfoundpred, *slp, *slq;
  100         int s;
  101 
  102         if (intr < NHWI || intr >= NHWI + NSWI)
  103                 panic("unregister_swi: bad intr %d", intr);
  104         if (handler == swi_generic || handler == swi_null)
  105                 panic("unregister_swi: bad handler %p", (void *)handler);
  106         slp = &swilists[intr - NHWI];
  107         s = splhigh();
  108         if (ihandlers[intr] == handler)
  109                 ihandlers[intr] = swi_null;
  110         else if (slp->sl_next != NULL) {
  111                 slfoundpred = NULL;
  112                 for (slq = slp->sl_next; slq != NULL;
  113                     slp = slq, slq = slp->sl_next)
  114                         if (slq->sl_handler == handler)
  115                                 slfoundpred = slp;
  116                 slp = &swilists[intr - NHWI];
  117                 if (slfoundpred != NULL) {
  118                         slq = slfoundpred->sl_next;
  119                         slfoundpred->sl_next = slq->sl_next;
  120                         free(slq, M_DEVBUF);
  121                 } else if (slp->sl_handler == handler) {
  122                         slq = slp->sl_next;
  123                         slp->sl_next = slq->sl_next;
  124                         slp->sl_handler = slq->sl_handler;
  125                         free(slq, M_DEVBUF);
  126                 }
  127                 if (slp->sl_next == NULL)
  128                         ihandlers[intr] = slp->sl_handler;
  129         }
  130         splx(s);
  131 }
  132 
  133 /* 
  134  * Sysctls used by systat and others: hw.intrnames and hw.intrcnt.
  135  * The data for this machine dependent, and the declarations are in machine
  136  * dependent code.  The layout of intrnames and intrcnt however is machine
  137  * independent.
  138  *
  139  * We do not know the length of intrcnt and intrnames at compile time, so
  140  * calculate things at run time.
  141  */
  142 static int
  143 sysctl_intrnames(SYSCTL_HANDLER_ARGS)
  144 {
  145         return (sysctl_handle_opaque(oidp, intrnames, eintrnames - intrnames, 
  146             req));
  147 }
  148 
  149 SYSCTL_PROC(_hw, OID_AUTO, intrnames, CTLTYPE_OPAQUE | CTLFLAG_RD,
  150         NULL, 0, sysctl_intrnames, "", "Interrupt Names");
  151 
  152 static int
  153 sysctl_intrcnt(SYSCTL_HANDLER_ARGS)
  154 {
  155         return (sysctl_handle_opaque(oidp, intrcnt, 
  156             (char *)eintrcnt - (char *)intrcnt, req));
  157 }
  158 
  159 SYSCTL_PROC(_hw, OID_AUTO, intrcnt, CTLTYPE_OPAQUE | CTLFLAG_RD,
  160         NULL, 0, sysctl_intrcnt, "", "Interrupt Counts");

Cache object: f9938204553d7f05725d76907311a589


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