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/powerpc/powerpc/intr_machdep.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) 1991 The Regents of the University of California.
    3  * All rights reserved.
    4  *
    5  * This code is derived from software contributed to Berkeley by
    6  * William Jolitz.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 4. Neither the name of the University nor the names of its contributors
   17  *    may be used to endorse or promote products derived from this software
   18  *    without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   30  * SUCH DAMAGE.
   31  */
   32 /*-
   33  * Copyright (c) 2002 Benno Rice.
   34  * All rights reserved.
   35  *
   36  * Redistribution and use in source and binary forms, with or without
   37  * modification, are permitted provided that the following conditions
   38  * are met:
   39  * 1. Redistributions of source code must retain the above copyright
   40  *    notice, this list of conditions and the following disclaimer.
   41  * 2. Redistributions in binary form must reproduce the above copyright
   42  *    notice, this list of conditions and the following disclaimer in the
   43  *    documentation and/or other materials provided with the distribution.
   44  *
   45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   55  * SUCH DAMAGE.
   56  *
   57  *      from: @(#)isa.c 7.2 (Berkeley) 5/13/91
   58  *      form: src/sys/i386/isa/intr_machdep.c,v 1.57 2001/07/20
   59  *
   60  * $FreeBSD$
   61  */
   62 
   63 #include <sys/param.h>
   64 #include <sys/systm.h>
   65 #include <sys/kernel.h>
   66 #include <sys/queue.h>
   67 #include <sys/bus.h>
   68 #include <sys/interrupt.h>
   69 #include <sys/ktr.h>
   70 #include <sys/lock.h>
   71 #include <sys/malloc.h>
   72 #include <sys/mutex.h>
   73 #include <sys/pcpu.h>
   74 #include <sys/syslog.h>
   75 #include <sys/vmmeter.h>
   76 #include <sys/proc.h>
   77 
   78 #include <machine/frame.h>
   79 #include <machine/intr_machdep.h>
   80 #include <machine/md_var.h>
   81 #include <machine/trap.h>
   82 
   83 #include "pic_if.h"
   84 
   85 #define MAX_STRAY_LOG   5
   86 
   87 MALLOC_DEFINE(M_INTR, "intr", "interrupt handler data");
   88 
   89 struct powerpc_intr {
   90         struct intr_event *event;
   91         long    *cntp;
   92         u_int   irq;
   93 };
   94 
   95 static struct powerpc_intr *powerpc_intrs[INTR_VECTORS];
   96 static u_int nvectors;          /* Allocated vectors */
   97 static u_int stray_count;
   98 
   99 device_t pic;
  100 
  101 static void
  102 intrcnt_setname(const char *name, int index)
  103 {
  104         snprintf(intrnames + (MAXCOMLEN + 1) * index, MAXCOMLEN + 1, "%-*s",
  105             MAXCOMLEN, name);
  106 }
  107 
  108 #ifdef INTR_FILTER
  109 static void
  110 powerpc_intr_eoi(void *arg)
  111 {
  112         u_int irq = (uintptr_t)arg;
  113 
  114         PIC_EOI(pic, irq);
  115 }
  116 
  117 static void
  118 powerpc_intr_mask(void *arg)
  119 {
  120         u_int irq = (uintptr_t)arg;
  121 
  122         PIC_MASK(pic, irq);
  123 }
  124 #endif
  125 
  126 static void
  127 powerpc_intr_unmask(void *arg)
  128 {
  129         u_int irq = (uintptr_t)arg;
  130 
  131         PIC_UNMASK(pic, irq);
  132 }
  133 
  134 void
  135 powerpc_register_pic(device_t dev)
  136 {
  137 
  138         pic = dev;
  139 }
  140 
  141 int
  142 powerpc_enable_intr(void)
  143 {
  144         struct powerpc_intr *i;
  145         int vector;
  146 
  147         for (vector = 0; vector < nvectors; vector++) {
  148                 i = powerpc_intrs[vector];
  149                 if (i == NULL)
  150                         continue;
  151 
  152                 PIC_ENABLE(pic, i->irq, vector);
  153         }
  154 
  155         return (0);
  156 }
  157 
  158 int
  159 powerpc_setup_intr(const char *name, u_int irq, driver_filter_t filter, 
  160     driver_intr_t handler, void *arg, enum intr_type flags, void **cookiep)
  161 {
  162         struct powerpc_intr *i;
  163         u_int vector;
  164         int error;
  165 
  166         /* XXX lock */
  167 
  168         i = NULL;
  169         for (vector = 0; vector < nvectors; vector++) {
  170                 i = powerpc_intrs[vector];
  171                 if (i == NULL)
  172                         continue;
  173                 if (i->irq == irq)
  174                         break;
  175                 i = NULL;
  176         }
  177 
  178         if (i == NULL) {
  179                 if (nvectors >= INTR_VECTORS) {
  180                         /* XXX unlock */
  181                         return (ENOENT);
  182                 }
  183 
  184                 i = malloc(sizeof(*i), M_INTR, M_NOWAIT);
  185                 if (i == NULL) {
  186                         /* XXX unlock */
  187                         return (ENOMEM);
  188                 }
  189                 error = intr_event_create(&i->event, (void *)irq, 0,
  190                     powerpc_intr_unmask,
  191 #ifdef INTR_FILTER
  192                     powerpc_intr_eoi, powerpc_intr_mask,
  193 #endif
  194                     NULL, "irq%u:", irq);
  195                 if (error) {
  196                         /* XXX unlock */
  197                         free(i, M_INTR);
  198                         return (error);
  199                 }
  200 
  201                 vector = nvectors++;
  202                 powerpc_intrs[vector] = i;
  203 
  204                 i->irq = irq;
  205 
  206                 /* XXX unlock */
  207 
  208                 i->cntp = &intrcnt[vector];
  209                 intrcnt_setname(i->event->ie_fullname, vector);
  210 
  211                 if (!cold)
  212                         PIC_ENABLE(pic, i->irq, vector);
  213         } else {
  214                 /* XXX unlock */
  215         }
  216 
  217         error = intr_event_add_handler(i->event, name, filter, handler, arg,
  218             intr_priority(flags), flags, cookiep);
  219         if (!error)
  220                 intrcnt_setname(i->event->ie_fullname, vector);
  221         return (error);
  222 }
  223 
  224 int
  225 powerpc_teardown_intr(void *cookie)
  226 {
  227 
  228         return (intr_event_remove_handler(cookie));
  229 }
  230 
  231 void
  232 powerpc_dispatch_intr(u_int vector, struct trapframe *tf)
  233 {
  234         struct powerpc_intr *i;
  235         struct intr_event *ie;
  236 #ifndef INTR_FILTER
  237         struct intr_handler *ih;
  238         int error, sched, ret;
  239 #endif
  240 
  241         i = powerpc_intrs[vector];
  242         if (i == NULL)
  243                 goto stray;
  244 
  245         (*i->cntp)++;
  246 
  247         ie = i->event;
  248         KASSERT(ie != NULL, ("%s: interrupt without an event", __func__));
  249 
  250 #ifdef INTR_FILTER
  251         if (intr_event_handle(ie, tf) != 0) {
  252                 PIC_MASK(pic, i->irq);
  253                 log(LOG_ERR, "stray irq%u\n", i->irq);
  254         }
  255 #else
  256         if (TAILQ_EMPTY(&ie->ie_handlers))
  257                 goto stray;
  258 
  259         /*
  260          * Execute all fast interrupt handlers directly without Giant.  Note
  261          * that this means that any fast interrupt handler must be MP safe.
  262          */
  263         ret = 0;
  264         sched = 0;
  265         critical_enter();
  266         TAILQ_FOREACH(ih, &ie->ie_handlers, ih_next) {
  267                 if (ih->ih_filter == NULL) {
  268                         sched = 1;
  269                         continue;
  270                 }
  271                 CTR4(KTR_INTR, "%s: exec %p(%p) for %s", __func__,
  272                     ih->ih_filter, ih->ih_argument, ih->ih_name);
  273                 ret = ih->ih_filter(ih->ih_argument);
  274                 /*
  275                  * Wrapper handler special case: see
  276                  * i386/intr_machdep.c::intr_execute_handlers()
  277                  */
  278                 if (!sched) {
  279                         if (ret == FILTER_SCHEDULE_THREAD)
  280                                 sched = 1;
  281                 }
  282         }
  283 
  284         if (sched) {
  285                 PIC_MASK(pic, i->irq);
  286                 error = intr_event_schedule_thread(ie);
  287                 KASSERT(error == 0, ("%s: impossible stray interrupt",
  288                     __func__));
  289         } else
  290                 PIC_EOI(pic, i->irq);
  291         critical_exit();
  292 #endif
  293         return;
  294 
  295 stray:
  296         stray_count++;
  297         if (stray_count <= MAX_STRAY_LOG) {
  298                 printf("stray irq %d\n", i->irq);
  299                 if (stray_count >= MAX_STRAY_LOG) {
  300                         printf("got %d stray interrupts, not logging anymore\n",
  301                             MAX_STRAY_LOG);
  302                 }
  303         }
  304         if (i != NULL)
  305                 PIC_MASK(pic, i->irq);
  306 }

Cache object: 32d4388da5dc33de5731d778d858822a


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