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.
This commit is contained in:
parent
f26ee18df3
commit
2aba95133a
@ -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.
|
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
|
||||||
@ -70,7 +70,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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_acpi.h"
|
||||||
#include "opt_pcifixup.h"
|
#include "opt_pcifixup.h"
|
||||||
@ -204,6 +204,11 @@ static int is_available_state(struct acpi_softc *, int);
|
|||||||
static bool acpi_suspend(device_t, const pmf_qual_t *);
|
static bool acpi_suspend(device_t, const pmf_qual_t *);
|
||||||
static bool acpi_resume(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:
|
* acpi_probe:
|
||||||
*
|
*
|
||||||
@ -785,38 +790,6 @@ acpi_rescan_nodes(struct acpi_softc *sc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#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:
|
* acpi_make_devnode:
|
||||||
*
|
*
|
||||||
@ -852,14 +825,7 @@ acpi_make_devnode(ACPI_HANDLE handle, uint32_t level,
|
|||||||
case ACPI_TYPE_DEVICE:
|
case ACPI_TYPE_DEVICE:
|
||||||
|
|
||||||
#ifdef ACPI_ACTIVATE_DEV
|
#ifdef ACPI_ACTIVATE_DEV
|
||||||
if ((devinfo->Valid & (ACPI_VALID_STA | ACPI_VALID_HID)) ==
|
acpi_activate_device(handle, &devinfo);
|
||||||
(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 */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case ACPI_TYPE_PROCESSOR:
|
case ACPI_TYPE_PROCESSOR:
|
||||||
@ -1545,8 +1511,57 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(ACPI_ACTIVATE_DEV)
|
#ifdef ACPI_ACTIVATE_DEV
|
||||||
/* XXX This very incomplete */
|
|
||||||
|
#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_STATUS
|
||||||
acpi_allocate_resources(ACPI_HANDLE handle)
|
acpi_allocate_resources(ACPI_HANDLE handle)
|
||||||
{
|
{
|
||||||
@ -1610,7 +1625,8 @@ acpi_allocate_resources(ACPI_HANDLE handle)
|
|||||||
resn->Length = resp->Length;
|
resn->Length = resp->Length;
|
||||||
break;
|
break;
|
||||||
default:
|
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;
|
rv = AE_BAD_DATA;
|
||||||
goto out2;
|
goto out2;
|
||||||
}
|
}
|
||||||
@ -1626,18 +1642,20 @@ acpi_allocate_resources(ACPI_HANDLE handle)
|
|||||||
resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta);
|
resn = (ACPI_RESOURCE *)((UINT8 *)bufn.Pointer + delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resc->Type != ACPI_RESOURCE_TYPE_END_TAG) {
|
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;
|
rv = AE_BAD_DATA;
|
||||||
goto out3;
|
goto out3;
|
||||||
}
|
}
|
||||||
|
|
||||||
resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
|
resn->Type = ACPI_RESOURCE_TYPE_END_TAG;
|
||||||
rv = AcpiSetCurrentResources(handle, &bufn);
|
rv = AcpiSetCurrentResources(handle, &bufn);
|
||||||
if (ACPI_FAILURE(rv)) {
|
|
||||||
printf("acpi_allocate_resources: AcpiSetCurrentResources %s\n",
|
if (ACPI_FAILURE(rv))
|
||||||
AcpiFormatException(rv));
|
aprint_error_dev(acpi_softc->sc_dev, "%s: failed to set "
|
||||||
}
|
"resources: %s\n", __func__, AcpiFormatException(rv));
|
||||||
|
|
||||||
out3:
|
out3:
|
||||||
free(bufn.Pointer, M_ACPI);
|
free(bufn.Pointer, M_ACPI);
|
||||||
@ -1648,6 +1666,10 @@ out1:
|
|||||||
out:
|
out:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef ACPI_DEV_VALID
|
||||||
|
#undef ACPI_DEV_STATUS
|
||||||
|
|
||||||
#endif /* ACPI_ACTIVATE_DEV */
|
#endif /* ACPI_ACTIVATE_DEV */
|
||||||
|
|
||||||
SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
|
SYSCTL_SETUP(sysctl_acpi_setup, "sysctl hw.acpi subtree setup")
|
||||||
|
@ -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.
|
* Copyright 2001 Wasabi Systems, Inc.
|
||||||
@ -270,7 +270,6 @@ ACPI_STATUS acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
|
|||||||
void *, const struct acpi_resource_parse_ops *);
|
void *, const struct acpi_resource_parse_ops *);
|
||||||
void acpi_resource_print(device_t, struct acpi_resources *);
|
void acpi_resource_print(device_t, struct acpi_resources *);
|
||||||
void acpi_resource_cleanup(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);
|
ACPI_STATUS acpi_pwr_switch_consumer(ACPI_HANDLE, int);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user