diff options
| author | dyoung <dyoung@NetBSD.org> | 2008-03-10 20:58:38 +0000 |
|---|---|---|
| committer | dyoung <dyoung@NetBSD.org> | 2008-03-10 20:58:38 +0000 |
| commit | 73e95caf73ca12f17e6a0485f9d684580ef119d7 (patch) | |
| tree | eaa22367e2b7d79eefbd5127ae1f727970387cf0 /sys/dev | |
| parent | 4bcfb62209a84b446588192135783ef0833dcb00 (diff) | |
Use device_t and accessors. Use aprint_*_dev().
Add a method for detaching children. XXX acpi(4) may leak some
resources for each child detached. Needs attention from someone
who understands acpi(4).
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/acpi/acpi.c | 125 |
1 files changed, 75 insertions, 50 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c index 7efe7c0cdb5..dff318cf764 100644 --- a/sys/dev/acpi/acpi.c +++ b/sys/dev/acpi/acpi.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi.c,v 1.110 2008/03/09 19:09:00 jmcneill Exp $ */ +/* $NetBSD: acpi.c,v 1.111 2008/03/10 20:58:38 dyoung Exp $ */ /*- * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.110 2008/03/09 19:09:00 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.111 2008/03/10 20:58:38 dyoung Exp $"); #include "opt_acpi.h" #include "opt_pcifixup.h" @@ -124,8 +124,9 @@ static int acpi_dbgr = 0x00; static ACPI_TABLE_DESC acpi_initial_tables[128]; -static int acpi_match(struct device *, struct cfdata *, void *); -static void acpi_attach(struct device *, struct device *, void *); +static int acpi_match(device_t, struct cfdata *, void *); +static void acpi_attach(device_t, device_t, void *); +static void acpi_childdet(device_t, device_t); static int acpi_print(void *aux, const char *); @@ -133,8 +134,8 @@ static int sysctl_hw_acpi_sleepstate(SYSCTLFN_ARGS); extern struct cfdriver acpi_cd; -CFATTACH_DECL(acpi, sizeof(struct acpi_softc), - acpi_match, acpi_attach, NULL, NULL); +CFATTACH_DECL2(acpi, sizeof(struct acpi_softc), + acpi_match, acpi_attach, NULL, NULL, NULL, acpi_childdet); /* * This is a flag we set when the ACPI subsystem is active. Machine @@ -347,8 +348,7 @@ acpi_OsGetRootPointer(void) * Autoconfiguration `match' routine. */ static int -acpi_match(struct device *parent, struct cfdata *match, - void *aux) +acpi_match(device_t parent, struct cfdata *match, void *aux) { /* * XXX Check other locators? Hard to know -- machine @@ -359,6 +359,25 @@ acpi_match(struct device *parent, struct cfdata *match, return 1; } +/* Remove references to child devices. + * + * XXX Need to reclaim any resources? + */ +static void +acpi_childdet(device_t self, device_t child) +{ + struct acpi_softc *sc = device_private(self); + struct acpi_scope *as; + struct acpi_devnode *ad; + + TAILQ_FOREACH(as, &sc->sc_scopes, as_list) { + TAILQ_FOREACH(ad, &as->as_devnodes, ad_list) { + if (ad->ad_device == child) + ad->ad_device = NULL; + } + } +} + /* * acpi_attach: * @@ -368,9 +387,9 @@ acpi_match(struct device *parent, struct cfdata *match, * and enable the ACPI subsystem. */ static void -acpi_attach(struct device *parent, struct device *self, void *aux) +acpi_attach(device_t parent, device_t self, void *aux) { - struct acpi_softc *sc = (void *) self; + struct acpi_softc *sc = device_private(self); struct acpibus_attach_args *aa = aux; ACPI_STATUS rv; ACPI_TABLE_HEADER *rsdt; @@ -383,18 +402,19 @@ acpi_attach(struct device *parent, struct device *self, void *aux) sysmon_power_settype("acpi"); - aprint_verbose("%s: using Intel ACPI CA subsystem version %08x\n", - sc->sc_dev.dv_xname, ACPI_CA_VERSION); + aprint_verbose_dev(&sc->sc_dev, + "using Intel ACPI CA subsystem version %08x\n", ACPI_CA_VERSION); rsdt = acpi_map_rsdt(); if (rsdt) { - aprint_verbose("%s: X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n", - sc->sc_dev.dv_xname, + aprint_verbose_dev( + &sc->sc_dev, + "X/RSDT: OemId <%6.6s,%8.8s,%08x>, AslId <%4.4s,%08x>\n", rsdt->OemId, rsdt->OemTableId, rsdt->OemRevision, rsdt->AslCompilerId, rsdt->AslCompilerRevision); } else - aprint_error("%s: X/RSDT: Not found\n", sc->sc_dev.dv_xname); + aprint_error_dev(&sc->sc_dev, "X/RSDT: Not found\n"); acpi_unmap_rsdt(rsdt); sc->sc_quirks = acpi_find_quirks(); @@ -429,8 +449,8 @@ acpi_attach(struct device *parent, struct device *self, void *aux) rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE1); if (ACPI_FAILURE(rv)) { - aprint_error("%s: unable to enable ACPI: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); + aprint_error_dev(&sc->sc_dev, "unable to enable ACPI: %s\n", + AcpiFormatException(rv)); return; } @@ -438,8 +458,8 @@ acpi_attach(struct device *parent, struct device *self, void *aux) rv = AcpiEnableSubsystem(ACPI_ENABLE_PHASE2); if (ACPI_FAILURE(rv)) { - aprint_error("%s: unable to enable ACPI: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); + aprint_error_dev(&sc->sc_dev, "unable to enable ACPI: %s\n", + AcpiFormatException(rv)); return; } @@ -448,8 +468,9 @@ acpi_attach(struct device *parent, struct device *self, void *aux) rv = AcpiInitializeObjects(ACPI_FULL_INITIALIZATION); if (ACPI_FAILURE(rv)) { - aprint_error("%s: unable to initialize ACPI objects: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); + aprint_error_dev(&sc->sc_dev, + "unable to initialize ACPI objects: %s\n", + AcpiFormatException(rv)); return; } acpi_active = 1; @@ -458,8 +479,8 @@ acpi_attach(struct device *parent, struct device *self, void *aux) sc->sc_sleepstate = ACPI_STATE_S0; /* Show SCI interrupt. */ - aprint_verbose("%s: SCI interrupting at int %d\n", - sc->sc_dev.dv_xname, AcpiGbl_FADT.SciInterrupt); + aprint_verbose_dev(&sc->sc_dev, "SCI interrupting at int %d\n", + AcpiGbl_FADT.SciInterrupt); /* * Check for fixed-hardware features. @@ -674,8 +695,9 @@ acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context, rv = AcpiGetObjectInfo(handle, &buf); if (ACPI_FAILURE(rv)) { #ifdef ACPI_DEBUG - aprint_normal("%s: AcpiGetObjectInfo failed: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); + aprint_normal_dev(&sc->sc_dev, + "AcpiGetObjectInfo failed: %s\n", + AcpiFormatException(rv)); #endif goto out; /* XXX why return OK */ } @@ -728,8 +750,8 @@ acpi_make_devnode(ACPI_HANDLE handle, UINT32 level, void *context, goto out; #ifdef ACPI_EXTRA_DEBUG - aprint_normal("%s: HID %s found in scope %s level %d\n", - sc->sc_dev.dv_xname, + aprint_normal_dev(&sc->sc_dev, + "HID %s found in scope %s level %d\n", ad->ad_devinfo->HardwareId.Value, as->as_name, ad->ad_level); if (ad->ad_devinfo->Valid & ACPI_VALID_UID) @@ -842,42 +864,44 @@ acpi_enable_fixed_events(struct acpi_softc *sc) */ if ((AcpiGbl_FADT.Flags & ACPI_FADT_POWER_BUTTON) == 0) { - aprint_verbose("%s: fixed-feature power button present\n", - sc->sc_dev.dv_xname); - sc->sc_smpsw_power.smpsw_name = sc->sc_dev.dv_xname; + aprint_verbose_dev(&sc->sc_dev, + "fixed-feature power button present\n"); + sc->sc_smpsw_power.smpsw_name = device_xname(&sc->sc_dev); sc->sc_smpsw_power.smpsw_type = PSWITCH_TYPE_POWER; if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { - aprint_error("%s: unable to register fixed power " - "button with sysmon\n", sc->sc_dev.dv_xname); + aprint_error_dev(&sc->sc_dev, + "unable to register fixed power " + "button with sysmon\n"); } else { rv = AcpiInstallFixedEventHandler( ACPI_EVENT_POWER_BUTTON, acpi_fixed_button_handler, &sc->sc_smpsw_power); if (ACPI_FAILURE(rv)) { - aprint_error("%s: unable to install handler " + aprint_error_dev(&sc->sc_dev, + "unable to install handler " "for fixed power button: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); } } } if ((AcpiGbl_FADT.Flags & ACPI_FADT_SLEEP_BUTTON) == 0) { - aprint_verbose("%s: fixed-feature sleep button present\n", - sc->sc_dev.dv_xname); - sc->sc_smpsw_sleep.smpsw_name = sc->sc_dev.dv_xname; + aprint_verbose_dev(&sc->sc_dev, + "fixed-feature sleep button present\n"); + sc->sc_smpsw_sleep.smpsw_name = device_xname(&sc->sc_dev); sc->sc_smpsw_sleep.smpsw_type = PSWITCH_TYPE_SLEEP; if (sysmon_pswitch_register(&sc->sc_smpsw_power) != 0) { - aprint_error("%s: unable to register fixed sleep " - "button with sysmon\n", sc->sc_dev.dv_xname); + aprint_error_dev(&sc->sc_dev, + "unable to register fixed sleep " + "button with sysmon\n"); } else { rv = AcpiInstallFixedEventHandler( ACPI_EVENT_SLEEP_BUTTON, acpi_fixed_button_handler, &sc->sc_smpsw_sleep); if (ACPI_FAILURE(rv)) { - aprint_error("%s: unable to install handler " + aprint_error_dev(&sc->sc_dev, + "unable to install handler " "for fixed sleep button: %s\n", - sc->sc_dev.dv_xname, AcpiFormatException(rv)); } } @@ -1159,7 +1183,7 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state) if (state == acpi_sleepstate) return AE_OK; - aprint_normal("%s: entering state %d\n", sc->sc_dev.dv_xname, state); + aprint_normal_dev(&sc->sc_dev, "entering state %d\n", state); switch (state) { case ACPI_STATE_S0: @@ -1169,8 +1193,8 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state) case ACPI_STATE_S3: case ACPI_STATE_S4: if (!is_available_state(sc, state)) { - aprint_error("%s: cannot enter the sleep state (%d)\n", - sc->sc_dev.dv_xname, state); + aprint_error_dev(&sc->sc_dev, + "cannot enter the sleep state (%d)\n", state); break; } @@ -1181,8 +1205,9 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state) ret = AcpiEnterSleepStatePrep(state); if (ACPI_FAILURE(ret)) { - aprint_error("%s: failed preparing to sleep (%s)\n", - sc->sc_dev.dv_xname, AcpiFormatException(ret)); + aprint_error_dev(&sc->sc_dev, + "failed preparing to sleep (%s)\n", + AcpiFormatException(ret)); break; } @@ -1205,16 +1230,16 @@ acpi_enter_sleep_state(struct acpi_softc *sc, int state) case ACPI_STATE_S5: ret = AcpiEnterSleepStatePrep(ACPI_STATE_S5); if (ACPI_FAILURE(ret)) { - aprint_error("%s: failed preparing to sleep (%s)\n", - sc->sc_dev.dv_xname, AcpiFormatException(ret)); + aprint_error_dev(&sc->sc_dev, + "failed preparing to sleep (%s)\n", + AcpiFormatException(ret)); break; } DELAY(1000000); acpi_sleepstate = state; acpi_md_OsDisableInterrupt(); AcpiEnterSleepState(ACPI_STATE_S5); - aprint_error("%s: WARNING powerdown failed!\n", - sc->sc_dev.dv_xname); + aprint_error_dev(&sc->sc_dev, "WARNING powerdown failed!\n"); break; } |
