OsdInterrupt.c revision 67760
167760Smsmith/*- 267760Smsmith * Copyright (c) 2000 Michael Smith 367760Smsmith * Copyright (c) 2000 BSDi 467760Smsmith * All rights reserved. 567760Smsmith * 667760Smsmith * Redistribution and use in source and binary forms, with or without 767760Smsmith * modification, are permitted provided that the following conditions 867760Smsmith * are met: 967760Smsmith * 1. Redistributions of source code must retain the above copyright 1067760Smsmith * notice, this list of conditions and the following disclaimer. 1167760Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1267760Smsmith * notice, this list of conditions and the following disclaimer in the 1367760Smsmith * documentation and/or other materials provided with the distribution. 1467760Smsmith * 1567760Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1667760Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1767760Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1867760Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1967760Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2067760Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2167760Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2267760Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2367760Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2467760Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2567760Smsmith * SUCH DAMAGE. 2667760Smsmith * 2767760Smsmith * $FreeBSD: head/sys/dev/acpica/Osd/OsdInterrupt.c 67760 2000-10-28 06:56:15Z msmith $ 2867760Smsmith */ 2967760Smsmith 3067760Smsmith/* 3167760Smsmith * 6.5 : Interrupt handling 3267760Smsmith */ 3367760Smsmith 3467760Smsmith#include "acpi.h" 3567760Smsmith 3667760Smsmith#include <sys/bus.h> 3767760Smsmith#include <machine/resource.h> 3867760Smsmith#include <machine/bus.h> 3967760Smsmith#include <sys/rman.h> 4067760Smsmith 4167760Smsmith#include <dev/acpica/acpivar.h> 4267760Smsmith 4367760Smsmith/* 4467760Smsmith * XXX this does not correctly free resources in the case of partically successful 4567760Smsmith * attachment. 4667760Smsmith */ 4767760SmsmithACPI_STATUS 4867760SmsmithAcpiOsInstallInterruptHandler(UINT32 InterruptNumber, OSD_HANDLER ServiceRoutine, void *Context) 4967760Smsmith{ 5067760Smsmith struct acpi_softc *sc; 5167760Smsmith 5267760Smsmith if ((InterruptNumber < 0) || (InterruptNumber > 255)) 5367760Smsmith return(AE_BAD_PARAMETER); 5467760Smsmith if (ServiceRoutine == NULL) 5567760Smsmith return(AE_BAD_PARAMETER); 5667760Smsmith 5767760Smsmith if ((sc = devclass_get_softc(acpi_devclass, 0)) == NULL) 5867760Smsmith panic("can't find ACPI device to register interrupt"); 5967760Smsmith if (sc->acpi_dev == NULL) 6067760Smsmith panic("acpi softc has invalid device"); 6167760Smsmith 6267760Smsmith /* 6367760Smsmith * This isn't strictly true, as we ought to be able to handle > 1 interrupt. The ACPI 6467760Smsmith * spec doesn't call for this though. 6567760Smsmith */ 6667760Smsmith if (sc->acpi_irq != NULL) { 6767760Smsmith device_printf(sc->acpi_dev, "attempt to register more than one interrupt handler\n"); 6867760Smsmith return(AE_EXIST); 6967760Smsmith } 7067760Smsmith sc->acpi_irq_rid = 0; 7167760Smsmith bus_set_resource(sc->acpi_dev, SYS_RES_IRQ, 0, InterruptNumber, 1); 7267760Smsmith if ((sc->acpi_irq = bus_alloc_resource(sc->acpi_dev, SYS_RES_IRQ, &sc->acpi_irq_rid, 0, ~0, 1, 7367760Smsmith RF_SHAREABLE | RF_ACTIVE)) == NULL) { 7467760Smsmith device_printf(sc->acpi_dev, "could not allocate SCI interrupt\n"); 7567760Smsmith return(AE_EXIST); 7667760Smsmith } 7767760Smsmith if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, INTR_TYPE_MISC, (driver_intr_t *)ServiceRoutine, Context, 7867760Smsmith &sc->acpi_irq_handle)) { 7967760Smsmith device_printf(sc->acpi_dev, "could not set up SCI interrupt\n"); 8067760Smsmith return(AE_EXIST); 8167760Smsmith } 8267760Smsmith 8367760Smsmith return(AE_OK); 8467760Smsmith} 8567760Smsmith 8667760SmsmithACPI_STATUS 8767760SmsmithAcpiOsRemoveInterruptHandler (UINT32 InterruptNumber, OSD_HANDLER ServiceRoutine) 8867760Smsmith{ 8967760Smsmith struct acpi_softc *sc; 9067760Smsmith 9167760Smsmith if ((InterruptNumber < 0) || (InterruptNumber > 255)) 9267760Smsmith return(AE_BAD_PARAMETER); 9367760Smsmith if (ServiceRoutine == NULL) 9467760Smsmith return(AE_BAD_PARAMETER); 9567760Smsmith 9667760Smsmith if ((sc = devclass_get_softc(acpi_devclass, 0)) == NULL) 9767760Smsmith panic("can't find ACPI device to deregister interrupt"); 9867760Smsmith 9967760Smsmith if (sc->acpi_irq == NULL) 10067760Smsmith return(AE_NOT_EXIST); 10167760Smsmith 10267760Smsmith bus_teardown_intr(sc->acpi_dev, sc->acpi_irq, sc->acpi_irq_handle); 10367760Smsmith bus_release_resource(sc->acpi_dev, SYS_RES_IRQ, 0, sc->acpi_irq); 10467760Smsmith bus_delete_resource(sc->acpi_dev, SYS_RES_IRQ, 0); 10567760Smsmith 10667760Smsmith sc->acpi_irq = NULL; 10767760Smsmith 10867760Smsmith return(AE_OK); 10967760Smsmith} 11067760Smsmith 111