2 * Copyright (c) 2003 Nate Lawson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/kernel.h>
35 #include <machine/bus.h>
36 #include <machine/resource.h>
39 #include <contrib/dev/acpica/include/acpi.h>
41 #include <dev/acpica/acpivar.h>
44 * Package manipulation convenience functions
48 acpi_PkgInt(ACPI_OBJECT *res, int idx, UINT64 *dst)
52 obj = &res->Package.Elements[idx];
53 if (obj->Type != ACPI_TYPE_INTEGER)
55 *dst = obj->Integer.Value;
61 acpi_PkgInt32(ACPI_OBJECT *res, int idx, uint32_t *dst)
66 error = acpi_PkgInt(res, idx, &tmp);
74 acpi_PkgInt16(ACPI_OBJECT *res, int idx, uint16_t *dst)
79 error = acpi_PkgInt(res, idx, &tmp);
87 acpi_PkgStr(ACPI_OBJECT *res, int idx, void *dst, size_t size)
93 obj = &res->Package.Elements[idx];
98 case ACPI_TYPE_STRING:
99 ptr = obj->String.Pointer;
100 length = obj->String.Length;
102 case ACPI_TYPE_BUFFER:
103 ptr = obj->Buffer.Pointer;
104 length = obj->Buffer.Length;
110 /* Make sure string will fit, including terminating NUL */
114 strlcpy(dst, ptr, length);
119 acpi_PkgGas(device_t dev, ACPI_OBJECT *res, int idx, int *type, int *rid,
120 struct resource **dst, u_int flags)
122 ACPI_GENERIC_ADDRESS gas;
125 obj = &res->Package.Elements[idx];
126 if (obj == NULL || obj->Type != ACPI_TYPE_BUFFER ||
127 obj->Buffer.Length < sizeof(ACPI_GENERIC_ADDRESS) + 3)
130 memcpy(&gas, obj->Buffer.Pointer + 3, sizeof(gas));
132 return (acpi_bus_alloc_gas(dev, type, rid, &gas, dst, flags));
136 acpi_PkgFFH_IntelCpu(ACPI_OBJECT *res, int idx, int *vendor, int *class,
137 uint64_t *address, int *accsize)
139 ACPI_GENERIC_ADDRESS gas;
142 obj = &res->Package.Elements[idx];
143 if (obj == NULL || obj->Type != ACPI_TYPE_BUFFER ||
144 obj->Buffer.Length < sizeof(ACPI_GENERIC_ADDRESS) + 3)
147 memcpy(&gas, obj->Buffer.Pointer + 3, sizeof(gas));
148 if (gas.SpaceId != ACPI_ADR_SPACE_FIXED_HARDWARE)
150 *vendor = gas.BitWidth;
151 *class = gas.BitOffset;
152 *address = gas.Address;
153 *accsize = gas.AccessWidth;
158 acpi_GetReference(ACPI_HANDLE scope, ACPI_OBJECT *obj)
166 case ACPI_TYPE_LOCAL_REFERENCE:
168 h = obj->Reference.Handle;
170 case ACPI_TYPE_STRING:
172 * The String object usually contains a fully-qualified path, so
175 * XXX This may not always be the case.
177 if (ACPI_FAILURE(AcpiGetHandle(scope, obj->String.Pointer, &h)))