diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-04-14 20:42:27 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2020-04-14 20:42:27 +0000 |
commit | 8dbc81a23ecbf7e9754f044233b8a06b8ac0bd42 (patch) | |
tree | 07e703babc48c5eee7d7a7700612aca29eab2796 /sys/dev/acpi | |
parent | 4458ad7aaa1f8b15232d74929d404c8817ff0590 (diff) |
Implement acpi_getprop(), the ACPI equivalent of OF_getprop().
ok patrick@
Diffstat (limited to 'sys/dev/acpi')
-rw-r--r-- | sys/dev/acpi/acpi.c | 55 | ||||
-rw-r--r-- | sys/dev/acpi/acpivar.h | 3 |
2 files changed, 55 insertions, 3 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index ab5a2f09f1b..c3871e007a3 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi.c,v 1.381 2020/04/12 09:21:19 kettenis Exp $ */ +/* $OpenBSD: acpi.c,v 1.382 2020/04/14 20:42:26 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> @@ -2961,6 +2961,57 @@ acpi_foundsony(struct aml_node *node, void *arg) /* Support for _DSD Device Properties. */ +int +acpi_getprop(struct aml_node *node, const char *prop, void *buf, int buflen) +{ + struct aml_value dsd; + int i; + + /* daffd814-6eba-4d8c-8a91-bc9bbf4aa301 */ + static uint8_t prop_guid[] = { + 0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d, + 0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01, + }; + + if (aml_evalname(acpi_softc, node, "_DSD", 0, NULL, &dsd)) + return -1; + + if (dsd.type != AML_OBJTYPE_PACKAGE || dsd.length != 2 || + dsd.v_package[0]->type != AML_OBJTYPE_BUFFER || + dsd.v_package[1]->type != AML_OBJTYPE_PACKAGE) + return -1; + + /* Check UUID. */ + if (dsd.v_package[0]->length != sizeof(prop_guid) || + memcmp(dsd.v_package[0]->v_buffer, prop_guid, + sizeof(prop_guid)) != 0) + return -1; + + /* Check properties. */ + for (i = 0; i < dsd.v_package[1]->length; i++) { + struct aml_value *res = dsd.v_package[1]->v_package[i]; + int len; + + if (res->type != AML_OBJTYPE_PACKAGE || res->length != 2 || + res->v_package[0]->type != AML_OBJTYPE_STRING) + continue; + + len = res->v_package[1]->length; + switch (res->v_package[1]->type) { + case AML_OBJTYPE_BUFFER: + memcpy(buf, res->v_package[1]->v_buffer, + min(len, buflen)); + return len; + case AML_OBJTYPE_STRING: + memcpy(buf, res->v_package[1]->v_string, + min(len, buflen)); + return len; + } + } + + return -1; +} + uint32_t acpi_getpropint(struct aml_node *node, const char *prop, uint32_t defval) { @@ -2999,7 +3050,7 @@ acpi_getpropint(struct aml_node *node, const char *prop, uint32_t defval) if (strcmp(res->v_package[0]->v_string, prop) == 0) return res->v_package[1]->v_integer; } - + return defval; } diff --git a/sys/dev/acpi/acpivar.h b/sys/dev/acpi/acpivar.h index cfdc825bd23..b80105a50f5 100644 --- a/sys/dev/acpi/acpivar.h +++ b/sys/dev/acpi/acpivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: acpivar.h,v 1.106 2020/04/12 09:21:19 kettenis Exp $ */ +/* $OpenBSD: acpivar.h,v 1.107 2020/04/14 20:42:26 kettenis Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * @@ -372,6 +372,7 @@ int acpi_matchhids(struct acpi_attach_args *, const char *[], const char *); int acpi_parsehid(struct aml_node *, void *, char *, char *, size_t); int64_t acpi_getsta(struct acpi_softc *sc, struct aml_node *); +int acpi_getprop(struct aml_node *, const char *, void *, int); uint32_t acpi_getpropint(struct aml_node *, const char *, uint32_t); int acpi_record_event(struct acpi_softc *, u_int); |