Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Add code to parse ACPI bus resources.



details:   https://anonhg.NetBSD.org/src/rev/453b22bb01c2
branches:  trunk
changeset: 515586:453b22bb01c2
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Sep 29 05:34:00 2001 +0000

description:
Add code to parse ACPI bus resources.

diffstat:

 sys/dev/acpi/acpi.c          |   32 ++-
 sys/dev/acpi/acpi_resource.c |  662 +++++++++++++++++++++++++++++++++++++++++++
 sys/dev/acpi/acpivar.h       |  123 +++++++-
 3 files changed, 815 insertions(+), 2 deletions(-)

diffs (truncated from 863 to 300 lines):

diff -r 4dba00189c15 -r 453b22bb01c2 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Sat Sep 29 05:33:00 2001 +0000
+++ b/sys/dev/acpi/acpi.c       Sat Sep 29 05:34:00 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.1 2001/09/28 02:09:22 thorpej Exp $ */
+/*     $NetBSD: acpi.c,v 1.2 2001/09/29 05:34:00 thorpej Exp $ */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -592,6 +592,11 @@
  * ACPI utility routines.
  *****************************************************************************/
 
+/*
+ * acpi_eval_integer:
+ *
+ *     Evaluate an integer object.
+ */
 ACPI_STATUS
 acpi_eval_integer(ACPI_HANDLE handle, char *path, int *valp)
 {
@@ -615,3 +620,28 @@
 
        return (rv);
 }
+
+/*
+ * acpi_get:
+ *
+ *     Fetch data info the specified (empty) ACPI buffer.
+ */
+ACPI_STATUS
+acpi_get(ACPI_HANDLE handle, ACPI_BUFFER *buf,
+    ACPI_STATUS (*getit)(ACPI_HANDLE, ACPI_BUFFER *))
+{
+       ACPI_STATUS rv;
+
+       buf->Pointer = NULL;
+       buf->Length = 0;
+
+       rv = (*getit)(handle, buf);
+       if (rv != AE_BUFFER_OVERFLOW)
+               return (rv);
+
+       buf->Pointer = AcpiOsCallocate(buf->Length);
+       if (buf->Pointer == NULL)
+               return (AE_NO_MEMORY);
+
+       return ((*getit)(handle, buf));
+}
diff -r 4dba00189c15 -r 453b22bb01c2 sys/dev/acpi/acpi_resource.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/acpi/acpi_resource.c      Sat Sep 29 05:34:00 2001 +0000
@@ -0,0 +1,662 @@
+/*     $NetBSD: acpi_resource.c,v 1.1 2001/09/29 05:34:00 thorpej 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.         
+ */
+
+/*
+ * ACPI resource parsing.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/malloc.h> 
+
+#include <dev/acpi/acpica.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#define        _COMPONENT      ACPI_BUS
+MODULE_NAME("RESOURCE")
+
+/*
+ * acpi_resource_parse:
+ *
+ *     Parse a device node's resources and fill them in for the
+ *     client.
+ *
+ *     Note that it might be nice to also locate ACPI-specific resource
+ *     items, such as GPE bits.
+ */
+ACPI_STATUS
+acpi_resource_parse(struct device *dev, struct acpi_devnode *ad,
+    void *arg, const struct acpi_resource_parse_ops *ops)
+{
+       ACPI_BUFFER buf;
+       ACPI_RESOURCE *res;
+       char *cur, *last;
+       ACPI_STATUS status;
+       void *context;
+       int i;
+
+       FUNCTION_TRACE(__FUNCTION__);
+
+       /*
+        * XXX Note, this means we only get devices that are currently
+        * decoding their address space.  This might not be what we
+        * want, in the long term.
+        */
+
+       status = acpi_get(ad->ad_handle, &buf, AcpiGetCurrentResources);
+       if (status != AE_OK) {
+               printf("%s: ACPI: unable to get Current Resources: %d\n",
+                   dev->dv_xname, status);
+               return_ACPI_STATUS(status);
+       }
+
+       ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "got %d bytes of _CRS\n",
+           buf.Length));
+
+       (*ops->init)(dev, arg, &context);
+
+       cur = buf.Pointer;
+       last = cur + buf.Length;
+       while (cur < last) {
+               res = (ACPI_RESOURCE *) cur;
+               cur += res->Length;
+
+               switch (res->Id) {
+               case ACPI_RSTYPE_END_TAG:
+                       ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, "EndTag\n"));
+                       cur = last;
+                       break;
+
+               case ACPI_RSTYPE_FIXED_IO:
+                       ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                           "FixedIo 0x%x/%d\n",
+                           res->Data.FixedIo.BaseAddress,
+                           res->Data.FixedIo.RangeLength));
+                       (*ops->ioport)(dev, context,
+                           res->Data.FixedIo.BaseAddress,
+                           res->Data.FixedIo.RangeLength);
+                       break;
+
+               case ACPI_RSTYPE_IO:
+                       if (res->Data.Io.MinBaseAddress ==
+                           res->Data.Io.MaxBaseAddress) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "Io 0x%x/%d\n",
+                                   res->Data.Io.MinBaseAddress,
+                                   res->Data.Io.RangeLength));
+                               (*ops->ioport)(dev, context,
+                                   res->Data.Io.MinBaseAddress,
+                                   res->Data.Io.RangeLength);
+                       } else {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "Io 0x%x-0x%x/%d\n",
+                                   res->Data.Io.MinBaseAddress,
+                                   res->Data.Io.MaxBaseAddress,
+                                   res->Data.Io.RangeLength));
+                               (*ops->iorange)(dev, context,
+                                   res->Data.Io.MinBaseAddress,
+                                   res->Data.Io.MaxBaseAddress,
+                                   res->Data.Io.RangeLength,
+                                   res->Data.Io.Alignment);
+                       }
+                       break;
+
+               case ACPI_RSTYPE_FIXED_MEM32:
+                       ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                           "FixedMemory32 0x%x/%d\n",
+                           res->Data.FixedMemory32.RangeBaseAddress,
+                           res->Data.FixedMemory32.RangeLength));
+                       (*ops->memory)(dev, context,
+                           res->Data.FixedMemory32.RangeBaseAddress,
+                           res->Data.FixedMemory32.RangeLength);
+                       break;
+
+               case ACPI_RSTYPE_MEM32:
+                       if (res->Data.Memory32.MinBaseAddress ==
+                           res->Data.Memory32.MaxBaseAddress) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, 
+                                   "Memory32 0x%x/%d\n",
+                                   res->Data.Memory32.MinBaseAddress,
+                                   res->Data.Memory32.RangeLength));
+                               (*ops->memory)(dev, context,
+                                   res->Data.Memory32.MinBaseAddress,
+                                   res->Data.Memory32.RangeLength);
+                       } else {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "Memory32 0x%x-0x%x/%d\n",
+                                   res->Data.Memory32.MinBaseAddress,
+                                   res->Data.Memory32.MaxBaseAddress,
+                                   res->Data.Memory32.RangeLength));
+                               (*ops->memrange)(dev, context,
+                                   res->Data.Memory32.MinBaseAddress,
+                                   res->Data.Memory32.MaxBaseAddress,
+                                   res->Data.Memory32.RangeLength,
+                                   res->Data.Memory32.Alignment);
+                       }
+                       break;
+
+               case ACPI_RSTYPE_MEM24:
+                       if (res->Data.Memory24.MinBaseAddress ==
+                           res->Data.Memory24.MaxBaseAddress) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES, 
+                                   "Memory24 0x%x/%d\n",
+                                   res->Data.Memory24.MinBaseAddress,
+                                   res->Data.Memory24.RangeLength));
+                               (*ops->memory)(dev, context,
+                                   res->Data.Memory24.MinBaseAddress,
+                                   res->Data.Memory24.RangeLength);
+                       } else {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "Memory24 0x%x-0x%x/%d\n",
+                                   res->Data.Memory24.MinBaseAddress,
+                                   res->Data.Memory24.MaxBaseAddress,
+                                   res->Data.Memory24.RangeLength));
+                               (*ops->memrange)(dev, context,
+                                   res->Data.Memory24.MinBaseAddress,
+                                   res->Data.Memory24.MaxBaseAddress,
+                                   res->Data.Memory24.RangeLength,
+                                   res->Data.Memory24.Alignment);
+                       }
+                       break;
+
+               case ACPI_RSTYPE_IRQ:
+                       for (i = 0; i < res->Data.Irq.NumberOfInterrupts; i++) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "IRQ %d\n", res->Data.Irq.Interrupts[i]));
+                               (*ops->irq)(dev, context,
+                                   res->Data.Irq.Interrupts[i]);
+                       }
+                       break;
+
+               case ACPI_RSTYPE_DMA:
+                       for (i = 0; i < res->Data.Dma.NumberOfChannels; i++) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                                   "DRQ %d\n", res->Data.Dma.Channels[i]));
+                               (*ops->drq)(dev, context,
+                                   res->Data.Dma.Channels[i]);
+                       }
+                       break;
+
+               case ACPI_RSTYPE_START_DPF:
+                       ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+                           "Start dependant functions: %d\n",
+                            res->Data.StartDpf.CompatibilityPriority));



Home | Main Index | Thread Index | Old Index