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/dev/acpica/Osd/OsdInterrupt.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) 2000 Michael Smith
    3  * Copyright (c) 2000 BSDi
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following 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 AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  *
   27  * $FreeBSD: src/sys/dev/acpica/Osd/OsdInterrupt.c,v 1.17 2004/04/14 03:41:06 njl Exp $
   28  */
   29 
   30 /*
   31  * 6.5 : Interrupt handling
   32  */
   33 
   34 #include <sys/param.h>
   35 #include <sys/kernel.h>
   36 #include <sys/bus.h>
   37 #include <sys/rman.h>
   38 #include <sys/thread2.h>
   39 #include <sys/machintr.h>
   40  
   41 #include "acpi.h"
   42 #include "accommon.h"
   43 #include <dev/acpica/acpivar.h>
   44 #include <dev/acpica/acpi_sci_var.h>
   45 
   46 #define _COMPONENT      ACPI_OS_SERVICES
   47 ACPI_MODULE_NAME("INTERRUPT")
   48 
   49 static void             InterruptWrapper(void *arg);
   50 
   51 static ACPI_OSD_HANDLER InterruptHandler;
   52 
   53 ACPI_STATUS
   54 AcpiOsInstallInterruptHandler(UINT32 InterruptNumber,
   55     ACPI_OSD_HANDLER ServiceRoutine, void *Context)
   56 {
   57     struct acpi_softc   *sc;
   58     u_int flags;
   59 
   60     ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
   61 
   62     if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL)
   63         panic("can't find ACPI device to register interrupt");
   64     if (sc->acpi_dev == NULL)
   65         panic("acpi softc has invalid device");
   66 
   67     /*
   68      * Configure SCI mode
   69      */
   70     acpi_sci_config();
   71 
   72     /*
   73      * This could happen:
   74      * - SCI is disabled by user
   75      * - No suitable interrupt mode for SCI
   76      */
   77     if (!acpi_sci_enabled())
   78         return_ACPI_STATUS (AE_OK);
   79 
   80     if (InterruptNumber < 0 || InterruptNumber > 255)
   81         return_ACPI_STATUS (AE_BAD_PARAMETER);
   82     if (ServiceRoutine == NULL)
   83         return_ACPI_STATUS (AE_BAD_PARAMETER);
   84     if (InterruptHandler != NULL) {
   85         device_printf(sc->acpi_dev, "interrupt handler already installed\n");
   86         return_ACPI_STATUS (AE_ALREADY_EXISTS);
   87     }
   88     InterruptHandler = ServiceRoutine;
   89 
   90     flags = RF_ACTIVE;
   91     if (acpi_sci_pci_shareable())
   92         flags |= RF_SHAREABLE;
   93 
   94     /* Set up the interrupt resource. */
   95     sc->acpi_irq_rid = 0;
   96     bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1,
   97         machintr_legacy_intr_cpuid(InterruptNumber));
   98     sc->acpi_irq = bus_alloc_resource_any(sc->acpi_dev, SYS_RES_IRQ,
   99         &sc->acpi_irq_rid, flags);
  100     if (sc->acpi_irq == NULL) {
  101         device_printf(sc->acpi_dev, "could not allocate interrupt\n");
  102         goto error;
  103     }
  104     if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, 0,
  105                     InterruptWrapper, Context, &sc->acpi_irq_handle, NULL)) {
  106         device_printf(sc->acpi_dev, "could not set up interrupt\n");
  107         goto error;
  108     }
  109 
  110     return_ACPI_STATUS (AE_OK);
  111 
  112 error:
  113     if (sc->acpi_irq_handle)
  114         bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle);
  115     sc->acpi_irq_handle = NULL;
  116     if (sc->acpi_irq)
  117         bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq);
  118     sc->acpi_irq = NULL;
  119     bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0);
  120     InterruptHandler = NULL;
  121 
  122     return_ACPI_STATUS (AE_ALREADY_EXISTS);
  123 }
  124 
  125 ACPI_STATUS
  126 AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine)
  127 {
  128     struct acpi_softc   *sc;
  129 
  130     ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
  131 
  132     if (!acpi_sci_enabled())
  133         return_ACPI_STATUS (AE_OK);
  134 
  135     if (InterruptNumber < 0 || InterruptNumber > 255)
  136         return_ACPI_STATUS (AE_BAD_PARAMETER);
  137     if (ServiceRoutine == NULL)
  138         return_ACPI_STATUS (AE_BAD_PARAMETER);
  139 
  140     if ((sc = devclass_get_softc(devclass_find("acpi"), 0)) == NULL)
  141         panic("can't find ACPI device to deregister interrupt");
  142 
  143     if (sc->acpi_irq == NULL)
  144         return_ACPI_STATUS (AE_NOT_EXIST);
  145 
  146     bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle);
  147     bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq);
  148     bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0);
  149 
  150     sc->acpi_irq = NULL;
  151     InterruptHandler = NULL;
  152 
  153     return_ACPI_STATUS (AE_OK);
  154 }
  155 
  156 static void
  157 InterruptWrapper(void *arg)
  158 {
  159     crit_enter();
  160     InterruptHandler(arg);
  161     crit_exit();
  162 }

Cache object: 8d7b75ad3452fdfdad4d9cac90f19291


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