Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi Move the ACPI_ACTIVATE_DEV block to one place. ...
details: https://anonhg.NetBSD.org/src/rev/4382ab308b12
branches: trunk
changeset: 752891:4382ab308b12
user: jruoho <jruoho%NetBSD.org@localhost>
date: Wed Mar 10 09:42:46 2010 +0000
description:
Move the ACPI_ACTIVATE_DEV block to one place. While there, provide missing
prototype for a function, try to make the code more simple, guard against a
potential NULL pointer dereference, and improve printing.
No functional change intended.
diffstat:
sys/dev/acpi/acpi.c | 122 ++++++++++++++++++++++++++++--------------------
sys/dev/acpi/acpivar.h | 3 +-
2 files changed, 73 insertions(+), 52 deletions(-)
diffs (209 lines):
diff -r 2762fe20710a -r 4382ab308b12 sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c Wed Mar 10 08:12:44 2010 +0000
+++ b/sys/dev/acpi/acpi.c Wed Mar 10 09:42:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi.c,v 1.158 2010/03/10 08:12:44 jruoho Exp $ */
+/* $NetBSD: acpi.c,v 1.159 2010/03/10 09:42:46 jruoho Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.158 2010/03/10 08:12:44 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.159 2010/03/10 09:42:46 jruoho Exp $");
#include "opt_acpi.h"
#include "opt_pcifixup.h"
@@ -204,6 +204,11 @@
static bool acpi_suspend(device_t, const pmf_qual_t *);
static bool acpi_resume(device_t, const pmf_qual_t *);
+#ifdef ACPI_ACTIVATE_DEV
+static void acpi_activate_device(ACPI_HANDLE, ACPI_DEVICE_INFO **);
+static ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE);
+#endif
+
/*
* acpi_probe:
*
@@ -785,38 +790,6 @@
}
}
-#ifdef ACPI_ACTIVATE_DEV
-static void
-acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
-{
- ACPI_STATUS rv;
- ACPI_DEVICE_INFO *newdi;
-
-#ifdef ACPI_DEBUG
- aprint_normal("%s: %s, old status=%x\n", __func__,
- (*di)->HardwareId.String, (*di)->CurrentStatus);
-#endif
-
- rv = acpi_allocate_resources(handle);
- if (ACPI_FAILURE(rv)) {
- aprint_error("acpi: activate failed for %s\n",
- (*di)->HardwareId.String);
- } else {
- aprint_verbose("acpi: activated %s\n",
- (*di)->HardwareId.String);
- }
-
- (void)AcpiGetObjectInfo(handle, &newdi);
- ACPI_FREE(*di);
- *di = newdi;
-
-#ifdef ACPI_DEBUG
- aprint_normal("%s: %s, new status=%x\n", __func__,
- (*di)->HardwareId.String, (*di)->CurrentStatus);
-#endif
-}
-#endif /* ACPI_ACTIVATE_DEV */
-
/*
* acpi_make_devnode:
*
@@ -852,14 +825,7 @@
case ACPI_TYPE_DEVICE:
#ifdef ACPI_ACTIVATE_DEV
- if ((devinfo->Valid & (ACPI_VALID_STA | ACPI_VALID_HID)) ==
- (ACPI_VALID_STA | ACPI_VALID_HID) &&
- (devinfo->CurrentStatus &
- (ACPI_STA_DEV_PRESENT | ACPI_STA_DEV_ENABLED)) ==
- ACPI_STA_DEV_PRESENT)
- acpi_activate_device(handle, &devinfo);
-
- /* FALLTHROUGH */
+ acpi_activate_device(handle, &devinfo);
#endif
case ACPI_TYPE_PROCESSOR:
@@ -1545,8 +1511,57 @@
return ret;
}
-#if defined(ACPI_ACTIVATE_DEV)
-/* XXX This very incomplete */
+#ifdef ACPI_ACTIVATE_DEV
+
+#define ACPI_DEV_VALID (ACPI_VALID_STA | ACPI_VALID_HID)
+#define ACPI_DEV_STATUS (ACPI_STA_DEV_PRESENT | ACPI_STA_DEV_ENABLED)
+
+static void
+acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
+{
+ ACPI_DEVICE_INFO *newdi;
+ ACPI_STATUS rv;
+ uint32_t old;
+
+ /*
+ * If the device is valid and present,
+ * but not enabled, try to activate it.
+ */
+ if (((*di)->Valid & ACPI_DEV_VALID) != ACPI_DEV_VALID)
+ return;
+
+ old = (*di)->CurrentStatus;
+
+ if ((old & ACPI_DEV_STATUS) != ACPI_STA_DEV_PRESENT)
+ return;
+
+ rv = acpi_allocate_resources(handle);
+
+ if (ACPI_FAILURE(rv))
+ goto fail;
+
+ rv = AcpiGetObjectInfo(handle, &newdi);
+
+ if (ACPI_FAILURE(rv))
+ goto fail;
+
+ ACPI_FREE(*di);
+ *di = newdi;
+
+ aprint_verbose_dev(acpi_softc->sc_dev,
+ "%s activated, STA 0x%08X -> STA 0x%08X\n",
+ (*di)->HardwareId.String, old, (*di)->CurrentStatus);
+
+ return;
+
+fail:
+ aprint_error_dev(acpi_softc->sc_dev, "failed to "
+ "activate %s\n", (*di)->HardwareId.String);
+}
+
+/*
+ * XXX: This very incomplete.
+ */
ACPI_STATUS
acpi_allocate_resources(ACPI_HANDLE handle)
{
@@ -1610,7 +1625,8 @@
resn->Length = resp->Length;
break;
default:
- printf("acpi_allocate_resources: res=%u\n", resc->Type);
+ aprint_error_dev(acpi_softc->sc_dev,
+ "%s: invalid type %u\n", __func__, resc->Type);
rv = AE_BAD_DATA;
goto out2;
}
@@ -1626,18 +1642,20 @@
resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta);
}
}
+
if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) {
- printf("acpi_allocate_resources: resc not exhausted\n");
+ aprint_error_dev(acpi_softc->sc_dev,
+ "%s: resc not exhausted\n", __func__);
rv = AE_BAD_DATA;
goto out3;
}
resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
rv = AcpiSetCurrentResources(handle, &bufn);
- if (ACPI_FAILURE(rv)) {
- printf("acpi_allocate_resources: AcpiSetCurrentResources %s\n",
- AcpiFormatException(rv));
- }
+
+ if (ACPI_FAILURE(rv))
+ aprint_error_dev(acpi_softc->sc_dev, "%s: failed to set "
+ "resources: %s\n", __func__, AcpiFormatException(rv));
out3:
free(bufn.Pointer, M_ACPI);
@@ -1648,6 +1666,10 @@
out:
return rv;
}
+
+#undef ACPI_DEV_VALID
+#undef ACPI_DEV_STATUS
+
#endif /* ACPI_ACTIVATE_DEV */
SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
diff -r 2762fe20710a -r 4382ab308b12 sys/dev/acpi/acpivar.h
--- a/sys/dev/acpi/acpivar.h Wed Mar 10 08:12:44 2010 +0000
+++ b/sys/dev/acpi/acpivar.h Wed Mar 10 09:42:46 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpivar.h,v 1.42 2010/03/09 18:15:22 jruoho Exp $ */
+/* $NetBSD: acpivar.h,v 1.43 2010/03/10 09:42:46 jruoho Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -270,7 +270,6 @@
void *, const struct acpi_resource_parse_ops *);
void acpi_resource_print(device_t, struct acpi_resources *);
void acpi_resource_cleanup(struct acpi_resources *);
-ACPI_STATUS acpi_allocate_resources(ACPI_HANDLE);
ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE, int);
Home |
Main Index |
Thread Index |
Old Index