Index: sys/dev/acpica/acpi_ec.c =================================================================== --- sys/dev/acpica/acpi_ec.c +++ sys/dev/acpica/acpi_ec.c @@ -279,6 +279,7 @@ device_t child; ACPI_HANDLE h; struct acpi_ec_params *params; + char desc[64]; ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); @@ -326,9 +327,18 @@ acpi_GetInteger(h, "_GLK", ¶ms->glk); acpi_set_private(child, params); + snprintf(desc, sizeof(desc), "Embedded Controller: GPE %#x%s%s", + params->gpe_bit, (params->glk) ? ", GLK" : "", + ecdt ? ", ECDT" : ""); + device_set_desc_copy(child, desc); + /* Finish the attach process. */ - if (device_probe_and_attach(child) != 0) + device_set_driver(child, &acpi_ec_driver); + device_set_devclass_fixed(child, "acpi_ec"); + if (device_attach(child) != 0) { device_delete_child(parent, child); + free(params, M_TEMP); + } } static int @@ -346,7 +356,8 @@ static char *ec_ids[] = { "PNP0C09", NULL }; /* Check that this is a device and that EC is not disabled. */ - if (acpi_get_type(dev) != ACPI_TYPE_DEVICE || acpi_disabled("ec")) + if (acpi_get_type(dev) != ACPI_TYPE_DEVICE || acpi_disabled("ec") || + !ACPI_ID_PROBE(device_get_parent(dev), dev, ec_ids)) return (ENXIO); /* @@ -358,75 +369,70 @@ ecdt = 0; buf.Pointer = NULL; buf.Length = ACPI_ALLOCATE_BUFFER; - params = acpi_get_private(dev); - if (params != NULL) { - ecdt = 1; - ret = 0; - } else if (ACPI_ID_PROBE(device_get_parent(dev), dev, ec_ids)) { - params = malloc(sizeof(struct acpi_ec_params), M_TEMP, - M_WAITOK | M_ZERO); - h = acpi_get_handle(dev); - /* - * Read the unit ID to check for duplicate attach and the - * global lock value to see if we should acquire it when - * accessing the EC. - */ - status = acpi_GetInteger(h, "_UID", ¶ms->uid); - if (ACPI_FAILURE(status)) - params->uid = 0; - status = acpi_GetInteger(h, "_GLK", ¶ms->glk); - if (ACPI_FAILURE(status)) - params->glk = 0; + params = malloc(sizeof(struct acpi_ec_params), M_TEMP, + M_WAITOK | M_ZERO); + h = acpi_get_handle(dev); - /* - * Evaluate the _GPE method to find the GPE bit used by the EC to - * signal status (SCI). If it's a package, it contains a reference - * and GPE bit, similar to _PRW. - */ - status = AcpiEvaluateObject(h, "_GPE", NULL, &buf); - if (ACPI_FAILURE(status)) { - device_printf(dev, "can't evaluate _GPE - %s\n", - AcpiFormatException(status)); - goto out; - } - obj = (ACPI_OBJECT *)buf.Pointer; - if (obj == NULL) - goto out; + /* + * Read the unit ID to check for duplicate attach and the + * global lock value to see if we should acquire it when + * accessing the EC. + */ + status = acpi_GetInteger(h, "_UID", ¶ms->uid); + if (ACPI_FAILURE(status)) + params->uid = 0; + status = acpi_GetInteger(h, "_GLK", ¶ms->glk); + if (ACPI_FAILURE(status)) + params->glk = 0; - switch (obj->Type) { - case ACPI_TYPE_INTEGER: - params->gpe_handle = NULL; - params->gpe_bit = obj->Integer.Value; - break; - case ACPI_TYPE_PACKAGE: - if (!ACPI_PKG_VALID(obj, 2)) - goto out; - params->gpe_handle = - acpi_GetReference(NULL, &obj->Package.Elements[0]); - if (params->gpe_handle == NULL || - acpi_PkgInt32(obj, 1, ¶ms->gpe_bit) != 0) - goto out; - break; - default: - device_printf(dev, "_GPE has invalid type %d\n", obj->Type); + /* + * Evaluate the _GPE method to find the GPE bit used by the EC to + * signal status (SCI). If it's a package, it contains a reference + * and GPE bit, similar to _PRW. + */ + status = AcpiEvaluateObject(h, "_GPE", NULL, &buf); + if (ACPI_FAILURE(status)) { + device_printf(dev, "can't evaluate _GPE - %s\n", + AcpiFormatException(status)); + goto out; + } + obj = (ACPI_OBJECT *)buf.Pointer; + if (obj == NULL) + goto out; + + switch (obj->Type) { + case ACPI_TYPE_INTEGER: + params->gpe_handle = NULL; + params->gpe_bit = obj->Integer.Value; + break; + case ACPI_TYPE_PACKAGE: + if (!ACPI_PKG_VALID(obj, 2)) goto out; - } + params->gpe_handle = + acpi_GetReference(NULL, &obj->Package.Elements[0]); + if (params->gpe_handle == NULL || + acpi_PkgInt32(obj, 1, ¶ms->gpe_bit) != 0) + goto out; + break; + default: + device_printf(dev, "_GPE has invalid type %d\n", obj->Type); + goto out; + } - /* Store the values we got from the namespace for attach. */ - acpi_set_private(dev, params); + /* Store the values we got from the namespace for attach. */ + acpi_set_private(dev, params); - /* - * Check for a duplicate probe. This can happen when a probe - * via ECDT succeeded already. If this is a duplicate, disable - * this device. - */ - peer = devclass_get_device(acpi_ec_devclass, params->uid); - if (peer == NULL || !device_is_alive(peer)) - ret = 0; - else - device_disable(dev); - } + /* + * Check for a duplicate probe. This can happen when a probe + * via ECDT succeeded already. If this is a duplicate, disable + * this device. + */ + peer = devclass_get_device(acpi_ec_devclass, params->uid); + if (peer == NULL || !device_is_alive(peer)) + ret = 0; + else + device_disable(dev); out: if (ret == 0) {