diff options
| author | kochi <kochi@NetBSD.org> | 2006-03-23 13:43:05 +0000 |
|---|---|---|
| committer | kochi <kochi@NetBSD.org> | 2006-03-23 13:43:05 +0000 |
| commit | f0c5abbdc87fdd5073f43b9ebe6ff18b22f29017 (patch) | |
| tree | c7e28598c3d5cbb688864ccc9a9c2bffaeeed1a5 /sys/dev/acpi | |
| parent | f4afd64ab08c4eed9151586af5d12958d6a39b41 (diff) | |
Move to sys/dev/acpi/acpica.
Diffstat (limited to 'sys/dev/acpi')
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdEnvironment.c | 107 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdHardware.c | 344 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdInterrupt.c | 162 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdMemory.c | 141 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdMisc.c | 208 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdSchedule.c | 226 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdStream.c | 86 | ||||
| -rw-r--r-- | sys/dev/acpi/acpica/Osd/OsdSynch.c | 337 |
8 files changed, 0 insertions, 1611 deletions
diff --git a/sys/dev/acpi/acpica/Osd/OsdEnvironment.c b/sys/dev/acpi/acpica/Osd/OsdEnvironment.c deleted file mode 100644 index bc431c2a447..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdEnvironment.c +++ /dev/null @@ -1,107 +0,0 @@ -/* $NetBSD: OsdEnvironment.c,v 1.6 2005/12/12 15:04:50 cube Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.1: Environmental support. - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdEnvironment.c,v 1.6 2005/12/12 15:04:50 cube Exp $"); - -#include <sys/types.h> - -#include <dev/acpi/acpica.h> -#include <dev/acpi/acpivar.h> -#include <dev/acpi/acpi_osd.h> - -#include <machine/acpi_machdep.h> - -#define _COMPONENT ACPI_OS_SERVICES -ACPI_MODULE_NAME("ENVIRONMENT"); - -/* - * AcpiOsInitialize: - * - * Initialize the OSL subsystem. - */ -ACPI_STATUS -AcpiOsInitialize(void) -{ - ACPI_STATUS rv; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - /* Initialize the Osd Scheduler. */ - acpi_osd_sched_init(); - - rv = acpi_md_OsInitialize(); - - return_ACPI_STATUS(rv); -} - -/* - * AcpiOsTerminate: - * - * Terminate the OSL subsystem. - */ -ACPI_STATUS -AcpiOsTerminate(void) -{ - ACPI_STATUS rv; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - /* Tear down the Osd Scheduler. */ - acpi_osd_sched_fini(); - - rv = acpi_md_OsTerminate(); - - return_ACPI_STATUS(rv); -} - -/* - * AcpiOsGetRootPointer: - * - * Obtain the Root ACPI talbe pointer (RSDP) - */ -ACPI_STATUS -AcpiOsGetRootPointer(UINT32 Flags, ACPI_POINTER *PhysicalAddress) -{ - return acpi_OsGetRootPointer(Flags, PhysicalAddress); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdHardware.c b/sys/dev/acpi/acpica/Osd/OsdHardware.c deleted file mode 100644 index e267086eb32..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdHardware.c +++ /dev/null @@ -1,344 +0,0 @@ -/* $NetBSD: OsdHardware.c,v 1.11 2005/12/24 20:27:29 perry Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.7: Address Space Access: Port Input/Output - * 6.8: Address Space Access: Memory and Memory Mapped I/O - * 6.9: Address Space Access: PCI Configuration Space - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdHardware.c,v 1.11 2005/12/24 20:27:29 perry Exp $"); - -#include <sys/param.h> -#include <sys/device.h> - -#include <dev/acpi/acpica.h> -#include <dev/acpi/acpivar.h> - -#include <machine/acpi_machdep.h> - -/* - * ACPICA doesn't provide much in the way of letting us know which - * hardware resources it wants to use. We therefore have to resort - * to calling machinde-dependent code to do the access for us. - */ - -/* - * AcpiOsReadPort: - * - * Read a value from an input port. - */ -ACPI_STATUS -AcpiOsReadPort(ACPI_IO_ADDRESS Address, UINT32 *Value, UINT32 Width) -{ - - switch (Width) { - case 8: - *Value = acpi_md_OsIn8(Address); - break; - - case 16: - *Value = acpi_md_OsIn16(Address); - break; - - case 32: - *Value = acpi_md_OsIn32(Address); - break; - - default: - return AE_BAD_PARAMETER; - } - - return AE_OK; -} - -/* - * AcpiOsWritePort: - * - * Write a value to an output port. - */ -ACPI_STATUS -AcpiOsWritePort(ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width) -{ - - switch (Width) { - case 8: - acpi_md_OsOut8(Address, Value); - break; - - case 16: - acpi_md_OsOut16(Address, Value); - break; - - case 32: - acpi_md_OsOut32(Address, Value); - break; - - default: - return AE_BAD_PARAMETER; - } - - return AE_OK; -} - -/* - * AcpiOsReadMemory: - * - * Read a value from a memory location. - */ -ACPI_STATUS -AcpiOsReadMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 *Value, UINT32 Width) -{ - void *LogicalAddress; - ACPI_STATUS rv; - - rv = AcpiOsMapMemory(Address, Width / 8, &LogicalAddress); - if (rv != AE_OK) - return rv; - - switch (Width) { - case 8: - *Value = *(volatile uint8_t *) LogicalAddress; - break; - - case 16: - *Value = *(volatile uint16_t *) LogicalAddress; - break; - - case 32: - *Value = *(volatile uint32_t *) LogicalAddress; - break; - - default: - rv = AE_BAD_PARAMETER; - } - - AcpiOsUnmapMemory(LogicalAddress, Width / 8); - - return rv; -} - -/* - * AcpiOsWriteMemory: - * - * Write a value to a memory location. - */ -ACPI_STATUS -AcpiOsWriteMemory(ACPI_PHYSICAL_ADDRESS Address, UINT32 Value, UINT32 Width) -{ - void *LogicalAddress; - ACPI_STATUS rv; - - rv = AcpiOsMapMemory(Address, Width / 8, &LogicalAddress); - if (rv != AE_OK) - return rv; - - switch (Width) { - case 8: - *(volatile uint8_t *) LogicalAddress = Value; - break; - - case 16: - *(volatile uint16_t *) LogicalAddress = Value; - break; - - case 32: - *(volatile uint32_t *) LogicalAddress = Value; - break; - - default: - rv = AE_BAD_PARAMETER; - } - - AcpiOsUnmapMemory(LogicalAddress, Width / 8); - - return rv; -} - -/* - * AcpiOsReadPciConfiguration: - * - * Read a value from a PCI configuration register. - */ -ACPI_STATUS -AcpiOsReadPciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, void *Value, - UINT32 Width) -{ - pcitag_t tag; - pcireg_t tmp; - - /* XXX Need to deal with "segment" ("hose" in Alpha terminology). */ - - tag = pci_make_tag(acpi_softc->sc_pc, PciId->Bus, PciId->Device, - PciId->Function); - tmp = pci_conf_read(acpi_softc->sc_pc, tag, Register & ~3); - - switch (Width) { - case 8: - *(uint8_t *) Value = (tmp >> ((Register & 3) * 8)) & 0xff; - break; - - case 16: - *(uint16_t *) Value = (tmp >> ((Register & 3) * 8)) & 0xffff; - break; - - case 32: - *(uint32_t *) Value = tmp; - break; - - default: - return AE_BAD_PARAMETER; - } - - return AE_OK; -} - -/* - * AcpiOsWritePciConfiguration: - * - * Write a value to a PCI configuration register. - */ -ACPI_STATUS -AcpiOsWritePciConfiguration(ACPI_PCI_ID *PciId, UINT32 Register, - ACPI_INTEGER Value, UINT32 Width) -{ - pcitag_t tag; - pcireg_t tmp; - - /* XXX Need to deal with "segment" ("hose" in Alpha terminology). */ - - tag = pci_make_tag(acpi_softc->sc_pc, PciId->Bus, PciId->Device, - PciId->Function); - - switch (Width) { - case 8: - tmp = pci_conf_read(acpi_softc->sc_pc, tag, Register & ~3); - tmp &= ~(0xff << ((Register & 3) * 8)); - tmp |= (Value << ((Register & 3) * 8)); - break; - - case 16: - tmp = pci_conf_read(acpi_softc->sc_pc, tag, Register & ~3); - tmp &= ~(0xffff << ((Register & 3) * 8)); - tmp |= (Value << ((Register & 3) * 8)); - break; - - case 32: - tmp = Value; - break; - - default: - return AE_BAD_PARAMETER; - } - - pci_conf_write(acpi_softc->sc_pc, tag, Register & ~3, tmp); - - return AE_OK; -} - -/* get PCI bus# from root bridge recursively */ -static int -get_bus_number( - ACPI_HANDLE rhandle, - ACPI_HANDLE chandle, - ACPI_PCI_ID **PciId) -{ - ACPI_HANDLE handle; - ACPI_STATUS rv; - ACPI_OBJECT_TYPE type; - ACPI_PCI_ID *id; - ACPI_INTEGER v; - int bus; - - id = *PciId; - - rv = AcpiGetParent(chandle, &handle); - if (ACPI_FAILURE(rv)) - return 0; - - /* - * When handle == rhandle, we have valid PciId->Bus - * which was obtained from _BBN in evrgnini.c - * so we don't have to reevaluate _BBN. - */ - if (handle != rhandle) { - bus = get_bus_number(rhandle, handle, PciId); - - rv = AcpiGetType(handle, &type); - if (ACPI_FAILURE(rv) || type != ACPI_TYPE_DEVICE) - return bus; - - rv = acpi_eval_integer(handle, METHOD_NAME__ADR, &v); - - if (ACPI_FAILURE(rv)) - return bus; - - id->Bus = bus; - id->Device = ACPI_HIWORD((ACPI_INTEGER)v); - id->Function = ACPI_LOWORD((ACPI_INTEGER)v); - - /* read HDR_TYPE register */ - rv = AcpiOsReadPciConfiguration(id, 0x0e, &v, 8); - if (ACPI_SUCCESS(rv) && - /* mask multifunction bit & check bridge type */ - ((v & 0x7f) == 1 || (v & 0x7f) == 2)) { - /* read SECONDARY_BUS register */ - rv = AcpiOsReadPciConfiguration(id, 0x19, &v, 8); - if (ACPI_SUCCESS(rv)) - id->Bus = v; - } - } - - return id->Bus; -} - -/* - * AcpiOsDerivePciId: - * - * Derive correct PCI bus# by traversing bridges - */ -void -AcpiOsDerivePciId( - ACPI_HANDLE rhandle, - ACPI_HANDLE chandle, - ACPI_PCI_ID **PciId) -{ - (*PciId)->Bus = get_bus_number(rhandle, chandle, PciId); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdInterrupt.c b/sys/dev/acpi/acpica/Osd/OsdInterrupt.c deleted file mode 100644 index d7681c00815..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdInterrupt.c +++ /dev/null @@ -1,162 +0,0 @@ -/* $NetBSD: OsdInterrupt.c,v 1.7 2005/12/11 12:21:02 christos Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.5: Interrupt Handling - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdInterrupt.c,v 1.7 2005/12/11 12:21:02 christos Exp $"); - -#include <sys/param.h> -#include <sys/malloc.h> -#include <sys/lock.h> -#include <sys/queue.h> - -#include <dev/acpi/acpica.h> - -#include <machine/acpi_machdep.h> - -#define _COMPONENT ACPI_OS_SERVICES -ACPI_MODULE_NAME("INTERRUPT") - -MALLOC_DEFINE(M_ACPI, "acpi", "Advanced Configuration and Power Interface"); - -/* - * We're lucky -- ACPI uses the same convention for interrupt service - * routine return values at NetBSD does -- so we can just ask MD code - * to hook it up directly (ACPI interrupts are always level triggered - * and shareable, and return 0 for "not handled" and 1 for "handled"). - */ - -struct acpi_interrupt_handler { - LIST_ENTRY(acpi_interrupt_handler) aih_list; - UINT32 aih_intrnum; - ACPI_OSD_HANDLER aih_func; - void *aih_ih; -}; - -static LIST_HEAD(, acpi_interrupt_handler) acpi_interrupt_list = - LIST_HEAD_INITIALIZER(&acpi_interrupt_list); -static struct simplelock acpi_interrupt_list_slock = SIMPLELOCK_INITIALIZER; - -#define ACPI_INTERRUPT_LIST_LOCK(s) \ -do { \ - (s) = splhigh(); \ - simple_lock(&acpi_interrupt_list_slock); \ -} while (/*CONSTCOND*/0) - -#define ACPI_INTERRUPT_LIST_UNLOCK(s) \ -do { \ - simple_unlock(&acpi_interrupt_list_slock); \ - splx((s)); \ -} while (/*CONSTCOND*/0) - -/* - * AcpiOsInstallInterruptHandler: - * - * Install a handler for a hardware interrupt level. - */ -ACPI_STATUS -AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, - ACPI_OSD_HANDLER ServiceRoutine, void *Context) -{ - struct acpi_interrupt_handler *aih; - ACPI_STATUS rv; - int s; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (InterruptNumber < 0 || InterruptNumber > 255) - return_ACPI_STATUS(AE_BAD_PARAMETER); - if (ServiceRoutine == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - aih = malloc(sizeof(*aih), M_ACPI, M_NOWAIT); - if (aih == NULL) - return_ACPI_STATUS(AE_NO_MEMORY); - - aih->aih_intrnum = InterruptNumber; - aih->aih_func = ServiceRoutine; - - rv = acpi_md_OsInstallInterruptHandler(InterruptNumber, - ServiceRoutine, Context, &aih->aih_ih); - if (rv == AE_OK) { - ACPI_INTERRUPT_LIST_LOCK(s); - LIST_INSERT_HEAD(&acpi_interrupt_list, aih, aih_list); - ACPI_INTERRUPT_LIST_UNLOCK(s); - } else - free(aih, M_ACPI); - - return_ACPI_STATUS(rv); -} - -/* - * AcpiOsRemoveInterruptHandler: - * - * Remove an interrupt handler. - */ -ACPI_STATUS -AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, - ACPI_OSD_HANDLER ServiceRoutine) -{ - struct acpi_interrupt_handler *aih; - int s; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (InterruptNumber < 0 || InterruptNumber > 255) - return_ACPI_STATUS(AE_BAD_PARAMETER); - if (ServiceRoutine == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - ACPI_INTERRUPT_LIST_LOCK(s); - LIST_FOREACH(aih, &acpi_interrupt_list, aih_list) { - if (aih->aih_intrnum == InterruptNumber && - aih->aih_func == ServiceRoutine) { - LIST_REMOVE(aih, aih_list); - ACPI_INTERRUPT_LIST_UNLOCK(s); - acpi_md_OsRemoveInterruptHandler(aih->aih_ih); - free(aih, M_ACPI); - return_ACPI_STATUS(AE_OK); - } - } - ACPI_INTERRUPT_LIST_UNLOCK(s); - return_ACPI_STATUS(AE_NOT_EXIST); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdMemory.c b/sys/dev/acpi/acpica/Osd/OsdMemory.c deleted file mode 100644 index 35bc3b9a6fd..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdMemory.c +++ /dev/null @@ -1,141 +0,0 @@ -/* $NetBSD: OsdMemory.c,v 1.8 2005/12/11 12:21:02 christos Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.2: Memory management. - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdMemory.c,v 1.8 2005/12/11 12:21:02 christos Exp $"); - -#include <sys/param.h> -#include <sys/malloc.h> - -#include <dev/acpi/acpica.h> - -#include <machine/acpi_machdep.h> - -MALLOC_DECLARE(M_ACPI); - -/* - * AcpiOsMapMemory: - * - * Map physical memory into the caller's address space. - */ -ACPI_STATUS -AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length, - void **LogicalAddress) -{ - - return acpi_md_OsMapMemory(PhysicalAddress, Length, LogicalAddress); -} - -/* - * AcpiOsUnmapMemory: - * - * Remove a physical to logical memory mapping. - */ -void -AcpiOsUnmapMemory(void *LogicalAddress, ACPI_SIZE Length) -{ - - acpi_md_OsUnmapMemory(LogicalAddress, Length); -} - -/* - * AcpiOsGetPhysicalAddress: - * - * Translate a logical address to a physical address. - */ -ACPI_STATUS -AcpiOsGetPhysicalAddress(void *LogicalAddress, - ACPI_PHYSICAL_ADDRESS *PhysicalAddress) -{ - - return acpi_md_OsGetPhysicalAddress(LogicalAddress, PhysicalAddress); -} - -/* - * AcpiOsAllocate: - * - * Allocate memory from the dynamic memory pool. - */ -void * -AcpiOsAllocate(ACPI_SIZE Size) -{ - - return malloc(Size, M_ACPI, M_NOWAIT); -} - -/* - * AcpiOsFree: - * - * Free previously allocated memory. - */ -void -AcpiOsFree(void *Memory) -{ - - free(Memory, M_ACPI); -} - - -/* - * AcpiOsReadable: - * - * Check if a memory region is readable. - */ -BOOLEAN -AcpiOsReadable(void *Pointer, ACPI_SIZE Length) -{ - - return acpi_md_OsReadable(Pointer, Length); -} - -/* - * AcpiOsWritable: - * - * Check if a memory region is writable (and readable). - */ -BOOLEAN -AcpiOsWritable(void *Pointer, ACPI_SIZE Length) -{ - - return acpi_md_OsWritable(Pointer, Length); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdMisc.c b/sys/dev/acpi/acpica/Osd/OsdMisc.c deleted file mode 100644 index a087caaf021..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdMisc.c +++ /dev/null @@ -1,208 +0,0 @@ -/* $NetBSD: OsdMisc.c,v 1.14 2006/01/05 17:13:20 rpaulo Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.10: Miscellaneous - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdMisc.c,v 1.14 2006/01/05 17:13:20 rpaulo Exp $"); - -#include "opt_acpi.h" -#include "opt_ddb.h" - -#include <sys/param.h> -#include <sys/systm.h> - -#include <machine/db_machdep.h> - -#include <ddb/db_extern.h> -#include <ddb/db_output.h> - -#include <dev/acpi/acpica.h> -#include <dev/acpi/acpi_osd.h> - -#include <dev/acpi/acpica/Subsystem/acdebug.h> -/* - * for debugging DSDT (try this at your own risk!): - * - * 1. dump your raw DSDT (with acpidump(*1) etc.) - * 2. disassemble with iasl -d (*2) - * 3. modify the ASL file - * 4. compile it with iasl -tc - * 5. copy *.hex to src/sys/dev/acpi/acpica/Osd/dsdt.hex - * -or- - * options ACPI_DSDT_FILE="\"yourdsdt.hex\"" in - * your config file and yourdsdt.hex in the build directory - * 6. options ACPI_DSDT_OVERRIDE in your kernel config file - * and rebuild the kernel - * - * (*1) /usr/pkgsrc/sysutils/acpidump - * (*2) /usr/pkgsrc/sysutils/acpi-iasl - */ - -#ifdef ACPI_DSDT_OVERRIDE -#ifndef ACPI_DSDT_FILE -#define ACPI_DSDT_FILE "dsdt.hex" -#endif -#include ACPI_DSDT_FILE -#endif - -int acpi_indebugger; - -/* - * AcpiOsSignal: - * - * Break to the debugger or display a breakpoint message. - */ -ACPI_STATUS -AcpiOsSignal(UINT32 Function, const void *Info) -{ - - switch (Function) { - case ACPI_SIGNAL_FATAL: - { - const ACPI_SIGNAL_FATAL_INFO *info = Info; - - panic("ACPI fatal signal: " - "Type 0x%08x, Code 0x%08x, Argument 0x%08x", - info->Type, info->Code, info->Argument); - /* NOTREACHED */ - break; - } - - case ACPI_SIGNAL_BREAKPOINT: - { - const char *info = Info; - - printf("%s\n", info); -#if defined(DDB) - Debugger(); -#else - printf("ACPI: WARNING: DDB not configured into kernel.\n"); - return AE_NOT_EXIST; -#endif - break; - } - - default: - return AE_BAD_PARAMETER; - } - - return AE_OK; -} - -ACPI_STATUS -AcpiOsGetLine(char *Buffer) -{ -#if defined(DDB) - char *cp; - - db_readline(Buffer, 80); - for (cp = Buffer; *cp != 0; cp++) - if (*cp == '\n' || *cp == '\r') - *cp = 0; - db_output_line = 0; - return AE_OK; -#else - printf("ACPI: WARNING: DDB not configured into kernel.\n"); - return AE_NOT_EXIST; -#endif -} - -ACPI_STATUS -AcpiOsTableOverride(ACPI_TABLE_HEADER *ExistingTable, - ACPI_TABLE_HEADER **NewTable) -{ -#ifndef ACPI_DSDT_OVERRIDE - *NewTable = NULL; -#else - if (strncmp(ExistingTable->Signature, "DSDT", 4) == 0) - *NewTable = (ACPI_TABLE_HEADER *)AmlCode; - else - *NewTable = NULL; -#endif - return AE_OK; -} - -ACPI_STATUS -AcpiOsPredefinedOverride(const ACPI_PREDEFINED_NAMES *InitVal, - ACPI_STRING *NewVal) -{ - if (!InitVal || !NewVal) - return AE_BAD_PARAMETER; - - *NewVal = NULL; - return AE_OK; -} - -/* - * acpi_osd_debugger: - * - * Enter the ACPICA debugger. - */ -void -acpi_osd_debugger(void) -{ -#ifdef ACPI_DEBUGGER - static int beenhere; - ACPI_PARSE_OBJECT obj; - label_t acpi_jmpbuf; - label_t *savejmp; - - if (beenhere == 0) { - printf("Initializing ACPICA debugger...\n"); - AcpiDbInitialize(); - beenhere = 1; - } - - printf("Entering ACPICA debugger...\n"); - savejmp = db_recover; - setjmp(&acpi_jmpbuf); - db_recover = &acpi_jmpbuf; - - acpi_indebugger = 1; - AcpiDbUserCommands('A', &obj); - acpi_indebugger = 0; - - db_recover = savejmp; -#else - printf("ACPI: WARNING: ACPICA debugger not present.\n"); -#endif -} diff --git a/sys/dev/acpi/acpica/Osd/OsdSchedule.c b/sys/dev/acpi/acpica/Osd/OsdSchedule.c deleted file mode 100644 index f858b5df46e..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdSchedule.c +++ /dev/null @@ -1,226 +0,0 @@ -/* $NetBSD: OsdSchedule.c,v 1.12 2005/12/11 12:21:02 christos Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.3: Scheduling services - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.12 2005/12/11 12:21:02 christos Exp $"); - -#include <sys/param.h> -#include <sys/malloc.h> -#include <sys/proc.h> -#include <sys/systm.h> -#include <sys/kernel.h> - -#include <dev/acpi/acpica.h> - -#include <dev/acpi/acpi_osd.h> - -#include <dev/sysmon/sysmon_taskq.h> - -#define _COMPONENT ACPI_OS_SERVICES -ACPI_MODULE_NAME("SCHEDULE") - -/* - * acpi_osd_sched_init: - * - * Initialize the APCICA Osd scheduler. Called from AcpiOsInitialize(). - */ -void -acpi_osd_sched_init(void) -{ - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - sysmon_task_queue_init(); - - return_VOID; -} - -/* - * acpi_osd_sched_fini: - * - * Clean up the ACPICA Osd scheduler. Called from AcpiOsdTerminate(). - */ -void -acpi_osd_sched_fini(void) -{ - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - sysmon_task_queue_fini(); - - return_VOID; -} - -/* - * AcpiOsGetThreadId: - * - * Obtain the ID of the currently executing thread. - */ -UINT32 -AcpiOsGetThreadId(void) -{ - - /* XXX ACPI CA can call this function in interrupt context */ - if (curlwp == NULL) - return 1; - - /* XXX Bleh, we're not allowed to return 0 (how stupid!) */ - return (curlwp->l_proc->p_pid + 1); -} - -/* - * AcpiOsQueueForExecution: - * - * Schedule a procedure for deferred execution. - */ -ACPI_STATUS -AcpiOsQueueForExecution(UINT32 Priority, ACPI_OSD_EXEC_CALLBACK Function, - void *Context) -{ - int pri; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - switch (Priority) { - case OSD_PRIORITY_GPE: - pri = 3; - break; - - case OSD_PRIORITY_HIGH: - pri = 2; - break; - - case OSD_PRIORITY_MED: - pri = 1; - break; - - case OSD_PRIORITY_LO: - pri = 0; - break; - - default: - return_ACPI_STATUS(AE_BAD_PARAMETER); - } - - switch (sysmon_task_queue_sched(pri, Function, Context)) { - case 0: - return_ACPI_STATUS(AE_OK); - - case ENOMEM: - return_ACPI_STATUS(AE_NO_MEMORY); - - default: - return_ACPI_STATUS(AE_BAD_PARAMETER); - } -} - -/* - * AcpiOsSleep: - * - * Suspend the running task (coarse granularity). - */ -void -AcpiOsSleep(ACPI_INTEGER Milliseconds) -{ - int timo; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - timo = Milliseconds * hz / 1000; - if (timo == 0) - timo = 1; - - (void) tsleep(&timo, PVM, "acpislp", timo); - - return_VOID; -} - -/* - * AcpiOsStall: - * - * Suspend the running task (fine granularity). - */ -void -AcpiOsStall(UINT32 Microseconds) -{ - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - /* - * sleep(9) isn't safe because AcpiOsStall may be called - * with interrupt-disabled. (eg. by AcpiEnterSleepState) - * we should watch out for long stall requests. - */ -#ifdef ACPI_DEBUG - if (Microseconds > 1000) - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "long stall: %uus\n", - Microseconds)); -#endif - - delay(Microseconds); - - return_VOID; - -} - -/* - * AcpiOsStall: - * - * Get the current system time in 100 nanosecond units - */ -UINT64 -AcpiOsGetTimer(void) -{ - struct timeval tv; - UINT64 t; - - /* XXX During early boot there is no (decent) timer available yet. */ - if (cold) - panic("acpi: timer op not yet supported during boot"); - - microtime(&tv); - t = (UINT64)10 * tv.tv_usec; - t += (UINT64)10000000 * tv.tv_sec; - - return (t); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdStream.c b/sys/dev/acpi/acpica/Osd/OsdStream.c deleted file mode 100644 index 74463938ffa..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdStream.c +++ /dev/null @@ -1,86 +0,0 @@ -/* $NetBSD: OsdStream.c,v 1.5 2003/02/13 14:16:14 kanaoka Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.6: Stream I/O - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdStream.c,v 1.5 2003/02/13 14:16:14 kanaoka Exp $"); - -#include "opt_ddb.h" - -#include <sys/types.h> -#include <sys/systm.h> - -#include <dev/acpi/acpica.h> - -#ifdef DDB -#include <ddb/db_output.h> -#endif - -extern int acpi_indebugger; - -/* - * AcpiOsPrintf: - * - * Formatted stream output. - */ -void ACPI_INTERNAL_VAR_XFACE -AcpiOsPrintf(const char *Format, ...) -{ - - va_list ap; - - va_start(ap, Format); - AcpiOsVprintf(Format, ap); - va_end(ap); -} - -void -AcpiOsVprintf(const char *Format, va_list Args) -{ - -#ifdef DDB - if (acpi_indebugger) - db_vprintf(Format, Args); - else -#endif - vprintf(Format, Args); -} diff --git a/sys/dev/acpi/acpica/Osd/OsdSynch.c b/sys/dev/acpi/acpica/Osd/OsdSynch.c deleted file mode 100644 index c3938024299..00000000000 --- a/sys/dev/acpi/acpica/Osd/OsdSynch.c +++ /dev/null @@ -1,337 +0,0 @@ -/* $NetBSD: OsdSynch.c,v 1.9 2006/01/29 03:11:26 kochi Exp $ */ - -/* - * Copyright 2001 Wasabi Systems, Inc. - * All rights reserved. - * - * Written by Jason R. Thorpe for Wasabi Systems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project by - * Wasabi Systems, Inc. - * 4. The name of Wasabi Systems, Inc. may not be used to endorse - * or promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/*- - * Copyright (c) 2000 Michael Smith - * Copyright (c) 2000 BSDi - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * OS Services Layer - * - * 6.4: Mutual Exclusion and Synchronization - */ - -#include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: OsdSynch.c,v 1.9 2006/01/29 03:11:26 kochi Exp $"); - -#include <sys/param.h> -#include <sys/malloc.h> -#include <sys/lock.h> -#include <sys/kernel.h> -#include <sys/proc.h> - -#include <dev/acpi/acpica.h> - -MALLOC_DECLARE(M_ACPI); - -#define _COMPONENT ACPI_OS_SERVICES -ACPI_MODULE_NAME("SYNCH") - -/* - * Simple counting semaphore implemented using a mutex. This is - * subsequently used in the OSI code to implement a mutex. Go figure. - */ -struct acpi_semaphore { - struct simplelock as_slock; - UINT32 as_units; - UINT32 as_maxunits; -}; - -struct acpi_lock { - struct simplelock al_slock; -}; - -/* - * AcpiOsCreateSemaphore: - * - * Create a semaphore. - */ -ACPI_STATUS -AcpiOsCreateSemaphore(UINT32 MaxUnits, UINT32 InitialUnits, - ACPI_HANDLE *OutHandle) -{ - struct acpi_semaphore *as; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (OutHandle == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - if (InitialUnits > MaxUnits) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - as = malloc(sizeof(*as), M_ACPI, M_NOWAIT); - if (as == NULL) - return_ACPI_STATUS(AE_NO_MEMORY); - - simple_lock_init(&as->as_slock); - as->as_units = InitialUnits; - as->as_maxunits = MaxUnits; - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, - "created semaphore %p max %u initial %u\n", - as, as->as_maxunits, as->as_units)); - - *OutHandle = (ACPI_HANDLE) as; - return_ACPI_STATUS(AE_OK); -} - -/* - * AcpiOsDeleteSemaphore: - * - * Delete a semaphore. - */ -ACPI_STATUS -AcpiOsDeleteSemaphore(ACPI_HANDLE Handle) -{ - struct acpi_semaphore *as = (void *) Handle; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (as == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - free(as, M_ACPI); - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "destroyed semaphore %p\n", as)); - - return_ACPI_STATUS(AE_OK); -} - -/* - * AcpiOsWaitSemaphore: - * - * Wait for units from a semaphore. - */ -ACPI_STATUS -AcpiOsWaitSemaphore(ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout) -{ - struct acpi_semaphore *as = (void *) Handle; - ACPI_STATUS rv; - int timo, error; - - /* - * This implementation has a bug: It has to stall for the entire - * timeout before it will return AE_TIME. A better implementation - * would adjust the amount of time left after being awakened. - */ - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (as == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - /* A timeout of 0xFFFF means "forever". */ - if (Timeout == 0xFFFF) - timo = 0; - else { - /* Compute the timeout using uSec per tick. */ - timo = (Timeout * 1000) / (1000000 / hz); - if (timo <= 0) - timo = 1; - } - - simple_lock(&as->as_slock); - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, - "get %d units from semaphore %p (has %d) timeout %d\n", - Units, as, as->as_units, Timeout)); - - for (;;) { - if (as->as_units >= Units) { - as->as_units -= Units; - rv = AE_OK; - break; - } - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, - "semaphore blocked, sleeping %d ticks\n", timo)); - - error = ltsleep(as, PVM, "acpisem", timo, &as->as_slock); - if (error == EWOULDBLOCK) { - rv = AE_TIME; - break; - } - } - - simple_unlock(&as->as_slock); - - return_ACPI_STATUS(rv); -} - -/* - * AcpiOsSignalSemaphore: - * - * Send units to a semaphore. - */ -ACPI_STATUS -AcpiOsSignalSemaphore(ACPI_HANDLE Handle, UINT32 Units) -{ - struct acpi_semaphore *as = (void *) Handle; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (as == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - simple_lock(&as->as_slock); - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, - "return %d units to semaphore %p (has %d)\n", - Units, as, as->as_units)); - - as->as_units += Units; - if (as->as_units > as->as_maxunits) - as->as_units = as->as_maxunits; - wakeup(as); - - simple_unlock(&as->as_slock); - - return_ACPI_STATUS(AE_OK); -} - -/* - * AcpiOsCreateLock: - * - * Create a lock. - */ -ACPI_STATUS -AcpiOsCreateLock(ACPI_HANDLE *OutHandle) -{ - struct acpi_lock *al; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (OutHandle == NULL) - return_ACPI_STATUS(AE_BAD_PARAMETER); - - al = malloc(sizeof(*al), M_ACPI, M_NOWAIT); - if (al == NULL) - return_ACPI_STATUS(AE_NO_MEMORY); - - simple_lock_init(&al->al_slock); - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, - "created lock %p\n", al)); - - *OutHandle = (ACPI_HANDLE) al; - return_ACPI_STATUS(AE_OK); -} - -/* - * AcpiOsDeleteLock: - * - * Delete a lock. - */ -void -AcpiOsDeleteLock(ACPI_HANDLE Handle) -{ - struct acpi_lock *al = (void *) Handle; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (al == NULL) - return; - - free(al, M_ACPI); - - ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "destroyed lock %p\n", al)); - - return; -} - -/* - * AcpiOsAcquireLock: - * - * Acquire a lock. - */ -ACPI_NATIVE_UINT -AcpiOsAcquireLock(ACPI_HANDLE Handle) -{ - struct acpi_lock *al = (void *) Handle; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (al == NULL) - return 0; - - simple_lock(&al->al_slock); - - return 0; -} - -/* - * AcpiOsReleaseLock: - * - * Release a lock. - */ -void -AcpiOsReleaseLock(ACPI_HANDLE Handle, ACPI_NATIVE_UINT Flags) -{ - struct acpi_lock *al = (void *) Handle; - - ACPI_FUNCTION_TRACE(__FUNCTION__); - - if (al == NULL) - return; - - simple_unlock(&al->al_slock); - - return; -} |
