This diff creates a common aml_dereference function, please test on as many 
systems as possible and send dmesg

Index: acpiprt.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpiprt.c,v
retrieving revision 1.43
diff -u -p -b -r1.43 acpiprt.c
--- acpiprt.c   3 Aug 2010 22:54:12 -0000       1.43
+++ acpiprt.c   22 Apr 2011 18:28:57 -0000
@@ -237,25 +237,10 @@ acpiprt_prt_add(struct acpiprt_softc *sc
                return;
        }
 
-       pp = v->v_package[2];
-       if (pp->type == AML_OBJTYPE_STRING) {
-               node = aml_searchrel(sc->sc_devnode, pp->v_string);
-               if (node == NULL) {
+       pp = aml_dereference(sc->sc_devnode, v->v_package[2]);
+       if (pp == NULL) {
                        printf("Invalid device\n");
                        return;
-               }
-               pp = node->value;
-       }
-       if (pp->type == AML_OBJTYPE_NAMEREF) {
-               node = aml_searchrel(sc->sc_devnode, pp->v_nameref);
-               if (node == NULL) {
-                       printf("Invalid device\n");
-                       return;
-               }
-               pp = node->value;
-       }
-       if (pp->type == AML_OBJTYPE_OBJREF) {
-               pp = pp->v_objref.ref;
        }
        if (pp->type == AML_OBJTYPE_DEVICE) {
                node = pp->node;
Index: acpitz.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpitz.c,v
retrieving revision 1.42
diff -u -p -b -r1.42 acpitz.c
--- acpitz.c    7 Apr 2011 20:16:19 -0000       1.42
+++ acpitz.c    22 Apr 2011 18:28:57 -0000
@@ -239,7 +239,6 @@ acpitz_attach(struct device *parent, str
 int
 acpitz_setfan(struct acpitz_softc *sc, int i, char *method)
 {
-       struct aml_node         *node;
        struct aml_value        res1, *ref;
        char                    name[8];
        int                     rv = 1, x, y;
@@ -267,20 +266,12 @@ acpitz_setfan(struct acpitz_softc *sc, i
                        continue;
                }
                for (y = 0; y < res1.length; y++) {
-                       ref = res1.v_package[y];
-                       if (ref->type == AML_OBJTYPE_STRING) {
-                               node = aml_searchrel(sc->sc_devnode,
-                                   ref->v_string);
-                               if (node == NULL) {
+                       ref = aml_dereference(sc->sc_devnode, 
res1.v_package[y]);
+                       if (ref == NULL) {
                                        printf("%s: %s[%d.%d] _PRO"
                                            " not a valid device\n",
                                            DEVNAME(sc), name, x, y);
                                        continue;
-                               }
-                               ref = node->value;
-                       }
-                       if (ref->type == AML_OBJTYPE_OBJREF) {
-                               ref = ref->v_objref.ref;
                        }
                        if (ref->type != AML_OBJTYPE_DEVICE &&
                            ref->type != AML_OBJTYPE_POWERRSRC) {
Index: dsdt.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.185
diff -u -p -b -r1.185 dsdt.c
--- dsdt.c      22 Apr 2011 18:22:01 -0000      1.185
+++ dsdt.c      22 Apr 2011 18:28:59 -0000
@@ -1810,6 +1810,27 @@ aml_findscope(struct aml_scope *scope, i
 }
 
 struct aml_value *
+aml_dereference(struct aml_node *node, struct aml_value *val)
+{
+       printf("deref: %s %x\n", aml_nodename(node), val->type);
+       if (val->type == AML_OBJTYPE_STRING) {
+               node = aml_searchrel(node, val->v_string);
+               if (node == NULL)
+                       return NULL;
+               val = node->value;
+       }
+       if (val->type == AML_OBJTYPE_NAMEREF) {
+               node = aml_searchrel(node, val->v_string);
+               if (node == NULL)
+                       return NULL;
+               val = node->value;
+       }
+       while (val->type == AML_OBJTYPE_OBJREF)
+               val = val->v_objref.ref;
+       return val;
+}
+
+struct aml_value *
 aml_getstack(struct aml_scope *scope, int opcode)
 {
        struct aml_value *sp;
Index: dsdt.h
===================================================================
RCS file: /cvs/src/sys/dev/acpi/dsdt.h,v
retrieving revision 1.58
diff -u -p -b -r1.58 dsdt.h
--- dsdt.h      18 Apr 2011 00:40:26 -0000      1.58
+++ dsdt.h      22 Apr 2011 18:28:59 -0000
@@ -46,6 +46,7 @@ int64_t                       aml_val2int(struct aml_value *
 struct aml_node                *aml_searchname(struct aml_node *, const void 
*);
 struct aml_node                *aml_searchrel(struct aml_node *, const void *);
 
+struct aml_value       *aml_dereference(struct aml_node *, struct aml_value *);
 struct aml_value       *aml_getstack(struct aml_scope *, int);
 struct aml_value       *aml_allocvalue(int, int64_t, const void *);
 void                   aml_freevalue(struct aml_value *);

Reply via email to