acpi.c (78689) | acpi.c (78915) |
---|---|
1/*- 2 * Copyright (c) 2000 Takanori Watanabe <takawata@jp.freebsd.org> 3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 4 * Copyright (c) 2000 Michael Smith 5 * Copyright (c) 2000 BSDi 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2000 Takanori Watanabe <takawata@jp.freebsd.org> 3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 4 * Copyright (c) 2000 Michael Smith 5 * Copyright (c) 2000 BSDi 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/dev/acpica/acpi.c 78689 2001-06-24 02:37:38Z iwasaki $ | 29 * $FreeBSD: head/sys/dev/acpica/acpi.c 78915 2001-06-28 06:17:16Z msmith $ |
30 */ 31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/proc.h> 36#include <sys/lock.h> 37#include <sys/malloc.h> --- 664 unchanged lines hidden (view full) --- 702 device_printf(sc->acpi_dev, MSGFORMAT, "sleep"); 703 } 704 } 705 706 first_time = 0; 707} 708 709/* | 30 */ 31 32#include "opt_acpi.h" 33#include <sys/param.h> 34#include <sys/kernel.h> 35#include <sys/proc.h> 36#include <sys/lock.h> 37#include <sys/malloc.h> --- 664 unchanged lines hidden (view full) --- 702 device_printf(sc->acpi_dev, MSGFORMAT, "sleep"); 703 } 704 } 705 706 first_time = 0; 707} 708 709/* |
710 * Returns true if the device is actually present and should 711 * be attached to. This requires the present, enabled, UI-visible 712 * and diagnostics-passed bits to be set. 713 */ 714BOOLEAN 715acpi_DeviceIsPresent(device_t dev) 716{ 717 ACPI_HANDLE h; 718 ACPI_DEVICE_INFO devinfo; 719 ACPI_STATUS error; 720 721 if ((h = acpi_get_handle(dev)) == NULL) 722 return(FALSE); 723 if ((error = AcpiGetObjectInfo(h, &devinfo)) != AE_OK) 724 return(FALSE); 725 if ((devinfo.Valid & ACPI_VALID_HID) && (devinfo.CurrentStatus & 0xf)) 726 return(TRUE); 727 return(FALSE); 728} 729 730/* |
|
710 * Match a HID string against a device 711 */ 712BOOLEAN 713acpi_MatchHid(device_t dev, char *hid) 714{ 715 ACPI_HANDLE h; 716 ACPI_DEVICE_INFO devinfo; 717 ACPI_STATUS error; --- 5 unchanged lines hidden (view full) --- 723 if ((error = AcpiGetObjectInfo(h, &devinfo)) != AE_OK) 724 return(FALSE); 725 if ((devinfo.Valid & ACPI_VALID_HID) && !strcmp(hid, devinfo.HardwareId)) 726 return(TRUE); 727 return(FALSE); 728} 729 730/* | 731 * Match a HID string against a device 732 */ 733BOOLEAN 734acpi_MatchHid(device_t dev, char *hid) 735{ 736 ACPI_HANDLE h; 737 ACPI_DEVICE_INFO devinfo; 738 ACPI_STATUS error; --- 5 unchanged lines hidden (view full) --- 744 if ((error = AcpiGetObjectInfo(h, &devinfo)) != AE_OK) 745 return(FALSE); 746 if ((devinfo.Valid & ACPI_VALID_HID) && !strcmp(hid, devinfo.HardwareId)) 747 return(TRUE); 748 return(FALSE); 749} 750 751/* |
752 * Return the handle of a named object within our scope, ie. that of (parent) 753 * or one if its parents. 754 */ 755ACPI_STATUS 756acpi_GetHandleInScope(ACPI_HANDLE parent, char *path, ACPI_HANDLE *result) 757{ 758 ACPI_HANDLE r; 759 ACPI_STATUS status; 760 761 /* walk back up the tree to the root */ 762 for (;;) { 763 status = AcpiGetHandle(parent, path, &r); 764 if (status == AE_OK) { 765 *result = r; 766 return(AE_OK); 767 } 768 if (status != AE_NOT_FOUND) 769 return(AE_OK); 770 if (AcpiGetParent(parent, &r) != AE_OK) 771 return(AE_NOT_FOUND); 772 parent = r; 773 } 774} 775 776/* 777 * Allocate a buffer with a preset data size. 778 */ 779ACPI_BUFFER * 780acpi_AllocBuffer(int size) 781{ 782 ACPI_BUFFER *buf; 783 784 if ((buf = malloc(size + sizeof(*buf), M_ACPIDEV, M_NOWAIT)) == NULL) 785 return(NULL); 786 buf->Length = size; 787 buf->Pointer = (void *)(buf + 1); 788 return(buf); 789} 790 791/* |
|
731 * Perform the tedious double-get procedure required for fetching something into 732 * an ACPI_BUFFER that has not been initialised. 733 */ 734ACPI_STATUS 735acpi_GetIntoBuffer(ACPI_HANDLE handle, ACPI_STATUS (*func)(ACPI_HANDLE, ACPI_BUFFER *), ACPI_BUFFER *buf) 736{ 737 ACPI_STATUS status; 738 739 buf->Length = 0; 740 buf->Pointer = NULL; 741 742 if ((status = func(handle, buf)) != AE_BUFFER_OVERFLOW) 743 return(status); 744 if ((buf->Pointer = AcpiOsCallocate(buf->Length)) == NULL) 745 return(AE_NO_MEMORY); 746 return(func(handle, buf)); 747} 748 749/* | 792 * Perform the tedious double-get procedure required for fetching something into 793 * an ACPI_BUFFER that has not been initialised. 794 */ 795ACPI_STATUS 796acpi_GetIntoBuffer(ACPI_HANDLE handle, ACPI_STATUS (*func)(ACPI_HANDLE, ACPI_BUFFER *), ACPI_BUFFER *buf) 797{ 798 ACPI_STATUS status; 799 800 buf->Length = 0; 801 buf->Pointer = NULL; 802 803 if ((status = func(handle, buf)) != AE_BUFFER_OVERFLOW) 804 return(status); 805 if ((buf->Pointer = AcpiOsCallocate(buf->Length)) == NULL) 806 return(AE_NO_MEMORY); 807 return(func(handle, buf)); 808} 809 810/* |
750 * Allocate a buffer with a preset data size. | 811 * Perform the tedious double-evaluate procedure for evaluating something into 812 * an ACPI_BUFFER that has not been initialised. Note that this evaluates 813 * twice, so avoid applying this to things that may have side-effects. 814 * 815 * This is like AcpiEvaluateObject with automatic buffer allocation. |
751 */ | 816 */ |
752ACPI_BUFFER * 753acpi_AllocBuffer(int size) | 817ACPI_STATUS 818acpi_EvaluateIntoBuffer(ACPI_HANDLE object, ACPI_STRING pathname, ACPI_OBJECT_LIST *params, 819 ACPI_BUFFER *buf) |
754{ | 820{ |
755 ACPI_BUFFER *buf; | 821 ACPI_STATUS status; 822 823 buf->Length = 0; 824 buf->Pointer = NULL; |
756 | 825 |
757 if ((buf = malloc(size + sizeof(*buf), M_ACPIDEV, M_NOWAIT)) == NULL) 758 return(NULL); 759 buf->Length = size; 760 buf->Pointer = (void *)(buf + 1); 761 return(buf); | 826 if ((status = AcpiEvaluateObject(object, pathname, params, buf)) != AE_BUFFER_OVERFLOW) 827 return(status); 828 if ((buf->Pointer = AcpiOsCallocate(buf->Length)) == NULL) 829 return(AE_NO_MEMORY); 830 return(AcpiEvaluateObject(object, pathname, params, buf)); |
762} 763 | 831} 832 |
833/* 834 * Evaluate a path that should return an integer. 835 */ 836ACPI_STATUS 837acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number) 838{ 839 ACPI_STATUS error; 840 ACPI_BUFFER buf; 841 ACPI_OBJECT param; 842 843 if (handle == NULL) 844 handle = ACPI_ROOT_OBJECT; 845 buf.Pointer = ¶m; 846 buf.Length = sizeof(param); 847 if ((error = AcpiEvaluateObject(handle, path, NULL, &buf)) == AE_OK) { 848 if (param.Type == ACPI_TYPE_INTEGER) { 849 *number = param.Integer.Value; 850 } else { 851 error = AE_TYPE; 852 } 853 } 854 return(error); 855} 856 857/* 858 * Iterate over the elements of an a package object, calling the supplied 859 * function for each element. 860 * 861 * XXX possible enhancement might be to abort traversal on error. 862 */ 863ACPI_STATUS 864acpi_ForeachPackageObject(ACPI_OBJECT *pkg, void (* func)(ACPI_OBJECT *comp, void *arg), void *arg) 865{ 866 ACPI_OBJECT *comp; 867 int i; 868 869 if ((pkg == NULL) || (pkg->Type != ACPI_TYPE_PACKAGE)) 870 return(AE_BAD_PARAMETER); 871 872 /* iterate over components */ 873 for (i = 0, comp = pkg->Package.Elements; i < pkg->Package.Count; i++, comp++) 874 func(comp, arg); 875 876 return(AE_OK); 877} 878 879 |
|
764static ACPI_STATUS __inline 765acpi_wakeup(UINT8 state) 766{ 767 UINT16 Count; 768 ACPI_STATUS Status; 769 ACPI_OBJECT_LIST Arg_list; 770 ACPI_OBJECT Arg; 771 ACPI_OBJECT Objects[3]; /* package plus 2 number objects */ --- 176 unchanged lines hidden (view full) --- 948 status = AE_OK; 949 } 950 if (status == AE_OK) 951 sc->acpi_enabled = 0; 952 return_ACPI_STATUS(status); 953} 954 955/* | 880static ACPI_STATUS __inline 881acpi_wakeup(UINT8 state) 882{ 883 UINT16 Count; 884 ACPI_STATUS Status; 885 ACPI_OBJECT_LIST Arg_list; 886 ACPI_OBJECT Arg; 887 ACPI_OBJECT Objects[3]; /* package plus 2 number objects */ --- 176 unchanged lines hidden (view full) --- 1064 status = AE_OK; 1065 } 1066 if (status == AE_OK) 1067 sc->acpi_enabled = 0; 1068 return_ACPI_STATUS(status); 1069} 1070 1071/* |
956 * Returns true if the device is actually present and should 957 * be attached to. This requires the present, enabled, UI-visible 958 * and diagnostics-passed bits to be set. 959 */ 960BOOLEAN 961acpi_DeviceIsPresent(device_t dev) 962{ 963 ACPI_HANDLE h; 964 ACPI_DEVICE_INFO devinfo; 965 ACPI_STATUS error; 966 967 if ((h = acpi_get_handle(dev)) == NULL) 968 return(FALSE); 969 if ((error = AcpiGetObjectInfo(h, &devinfo)) != AE_OK) 970 return(FALSE); 971 if ((devinfo.Valid & ACPI_VALID_HID) && (devinfo.CurrentStatus & 0xf)) 972 return(TRUE); 973 return(FALSE); 974} 975 976/* 977 * Evaluate a path that should return an integer. 978 */ 979ACPI_STATUS 980acpi_EvaluateInteger(ACPI_HANDLE handle, char *path, int *number) 981{ 982 ACPI_STATUS error; 983 ACPI_BUFFER buf; 984 ACPI_OBJECT param; 985 986 if (handle == NULL) 987 handle = ACPI_ROOT_OBJECT; 988 buf.Pointer = ¶m; 989 buf.Length = sizeof(param); 990 if ((error = AcpiEvaluateObject(handle, path, NULL, &buf)) == AE_OK) { 991 if (param.Type == ACPI_TYPE_INTEGER) { 992 *number = param.Integer.Value; 993 } else { 994 error = AE_TYPE; 995 } 996 } 997 return(error); 998} 999 1000/* | |
1001 * ACPI Event Handlers 1002 */ 1003 1004/* System Event Handlers (registered by EVENTHANDLER_REGISTER) */ 1005 1006static void 1007acpi_system_eventhandler_sleep(void *arg, int state) 1008{ --- 333 unchanged lines hidden (view full) --- 1342 */ 1343struct debugtag 1344{ 1345 char *name; 1346 UINT32 value; 1347}; 1348 1349static struct debugtag dbg_layer[] = { | 1072 * ACPI Event Handlers 1073 */ 1074 1075/* System Event Handlers (registered by EVENTHANDLER_REGISTER) */ 1076 1077static void 1078acpi_system_eventhandler_sleep(void *arg, int state) 1079{ --- 333 unchanged lines hidden (view full) --- 1413 */ 1414struct debugtag 1415{ 1416 char *name; 1417 UINT32 value; 1418}; 1419 1420static struct debugtag dbg_layer[] = { |
1350 {"GLOBAL", 0x00000001}, 1351 {"COMMON", 0x00000002}, 1352 {"PARSER", 0x00000004}, 1353 {"DISPATCHER", 0x00000008}, 1354 {"INTERPRETER", 0x00000010}, 1355 {"NAMESPACE", 0x00000020}, 1356 {"RESOURCE_MANAGER", 0x00000040}, 1357 {"TABLE_MANAGER", 0x00000080}, 1358 {"EVENT_HANDLING", 0x00000100}, 1359 {"HARDWARE", 0x00000200}, 1360 {"MISCELLANEOUS", 0x00000400}, 1361 {"OS_DEPENDENT", 0x00000800}, 1362 {"BUS_MANAGER", 0x00001000}, 1363 {"PROCESSOR_CONTROL", 0x00002000}, 1364 {"SYSTEM_CONTROL", 0x00004000}, 1365 {"THERMAL_CONTROL", 0x00008000}, 1366 {"POWER_CONTROL", 0x00010000}, 1367 {"EMBEDDED_CONTROLLER", 0x00020000}, 1368 {"BATTERY", 0x00040000}, 1369 {"DEBUGGER", 0x00100000}, 1370 {"ALL_COMPONENTS", 0x001FFFFF}, | 1421 {"ACPI_UTILITIES", ACPI_UTILITIES}, 1422 {"ACPI_HARDWARE", ACPI_HARDWARE}, 1423 {"ACPI_EVENTS", ACPI_EVENTS}, 1424 {"ACPI_TABLES", ACPI_TABLES}, 1425 {"ACPI_NAMESPACE", ACPI_NAMESPACE}, 1426 {"ACPI_PARSER", ACPI_PARSER}, 1427 {"ACPI_DISPATCHER", ACPI_DISPATCHER}, 1428 {"ACPI_EXECUTER", ACPI_EXECUTER}, 1429 {"ACPI_RESOURCES", ACPI_RESOURCES}, 1430 {"ACPI_DEVICES", ACPI_DEVICES}, 1431 {"ACPI_POWER", ACPI_POWER}, 1432 {"ACPI_BUS_MANAGER", ACPI_BUS_MANAGER}, 1433 {"ACPI_POWER_CONTROL", ACPI_POWER_CONTROL}, 1434 {"ACPI_EMBEDDED_CONTROLLER", ACPI_EMBEDDED_CONTROLLER}, 1435 {"ACPI_PROCESSOR_CONTROL", ACPI_PROCESSOR_CONTROL}, 1436 {"ACPI_AC_ADAPTER", ACPI_AC_ADAPTER}, 1437 {"ACPI_BATTERY", ACPI_BATTERY}, 1438 {"ACPI_BUTTON", ACPI_BUTTON}, 1439 {"ACPI_SYSTEM", ACPI_SYSTEM}, 1440 {"ACPI_THERMAL_ZONE", ACPI_THERMAL_ZONE}, 1441 {"ACPI_DEBUGGER", ACPI_DEBUGGER}, 1442 {"ACPI_OS_SERVICES", ACPI_OS_SERVICES}, 1443 {"ACPI_ALL_COMPONENTS", ACPI_ALL_COMPONENTS}, |
1371 {NULL, 0} 1372}; 1373 1374static struct debugtag dbg_level[] = { | 1444 {NULL, 0} 1445}; 1446 1447static struct debugtag dbg_level[] = { |
1375 {"ACPI_OK", 0x00000001}, 1376 {"ACPI_INFO", 0x00000002}, 1377 {"ACPI_WARN", 0x00000004}, 1378 {"ACPI_ERROR", 0x00000008}, 1379 {"ACPI_FATAL", 0x00000010}, 1380 {"ACPI_DEBUG_OBJECT", 0x00000020}, 1381 {"ACPI_ALL", 0x0000003F}, 1382 {"TRACE_PARSE", 0x00000100}, 1383 {"TRACE_DISPATCH", 0x00000200}, 1384 {"TRACE_LOAD", 0x00000400}, 1385 {"TRACE_EXEC", 0x00000800}, 1386 {"TRACE_NAMES", 0x00001000}, 1387 {"TRACE_OPREGION", 0x00002000}, 1388 {"TRACE_BFIELD", 0x00004000}, 1389 {"TRACE_TRASH", 0x00008000}, 1390 {"TRACE_TABLES", 0x00010000}, 1391 {"TRACE_FUNCTIONS", 0x00020000}, 1392 {"TRACE_VALUES", 0x00040000}, 1393 {"TRACE_OBJECTS", 0x00080000}, 1394 {"TRACE_ALLOCATIONS", 0x00100000}, 1395 {"TRACE_RESOURCES", 0x00200000}, 1396 {"TRACE_IO", 0x00400000}, 1397 {"TRACE_INTERRUPTS", 0x00800000}, 1398 {"TRACE_USER_REQUESTS", 0x01000000}, 1399 {"TRACE_PACKAGE", 0x02000000}, 1400 {"TRACE_MUTEX", 0x04000000}, 1401 {"TRACE_ALL", 0x0FFFFF00}, 1402 {"VERBOSE_AML_DISASSEMBLE", 0x10000000}, 1403 {"VERBOSE_INFO", 0x20000000}, 1404 {"VERBOSE_TABLES", 0x40000000}, 1405 {"VERBOSE_EVENTS", 0x80000000}, 1406 {"VERBOSE_ALL", 0xF0000000}, | 1448 {"ACPI_OK", ACPI_OK}, 1449 {"ACPI_INFO", ACPI_INFO}, 1450 {"ACPI_WARN", ACPI_WARN}, 1451 {"ACPI_ERROR", ACPI_ERROR}, 1452 {"ACPI_FATAL", ACPI_FATAL}, 1453 {"ACPI_DEBUG_OBJECT", ACPI_DEBUG_OBJECT}, 1454 {"ACPI_ALL", ACPI_ALL}, 1455 {"TRACE_THREADS", TRACE_THREADS}, 1456 {"TRACE_PARSE", TRACE_PARSE}, 1457 {"TRACE_DISPATCH", TRACE_DISPATCH}, 1458 {"TRACE_LOAD", TRACE_LOAD}, 1459 {"TRACE_EXEC", TRACE_EXEC}, 1460 {"TRACE_NAMES", TRACE_NAMES}, 1461 {"TRACE_OPREGION", TRACE_OPREGION}, 1462 {"TRACE_BFIELD", TRACE_BFIELD}, 1463 {"TRACE_TRASH", TRACE_TRASH}, 1464 {"TRACE_TABLES", TRACE_TABLES}, 1465 {"TRACE_FUNCTIONS", TRACE_FUNCTIONS}, 1466 {"TRACE_VALUES", TRACE_VALUES}, 1467 {"TRACE_OBJECTS", TRACE_OBJECTS}, 1468 {"TRACE_ALLOCATIONS", TRACE_ALLOCATIONS}, 1469 {"TRACE_RESOURCES", TRACE_RESOURCES}, 1470 {"TRACE_IO", TRACE_IO}, 1471 {"TRACE_INTERRUPTS", TRACE_INTERRUPTS}, 1472 {"TRACE_USER_REQUESTS", TRACE_USER_REQUESTS}, 1473 {"TRACE_PACKAGE", TRACE_PACKAGE}, 1474 {"TRACE_MUTEX", TRACE_MUTEX}, 1475 {"TRACE_INIT", TRACE_INIT}, 1476 {"TRACE_ALL", TRACE_ALL}, 1477 {"VERBOSE_AML_DISASSEMBLE", VERBOSE_AML_DISASSEMBLE}, 1478 {"VERBOSE_INFO", VERBOSE_INFO}, 1479 {"VERBOSE_TABLES", VERBOSE_TABLES}, 1480 {"VERBOSE_EVENTS", VERBOSE_EVENTS}, 1481 {"VERBOSE_ALL", VERBOSE_ALL}, |
1407 {NULL, 0} 1408}; 1409 1410static void 1411acpi_parse_debug(char *cp, struct debugtag *tag, UINT32 *flag) 1412{ 1413 char *ep; 1414 int i, l; --- 248 unchanged lines hidden --- | 1482 {NULL, 0} 1483}; 1484 1485static void 1486acpi_parse_debug(char *cp, struct debugtag *tag, UINT32 *flag) 1487{ 1488 char *ep; 1489 int i, l; --- 248 unchanged lines hidden --- |