diff options
| author | cube <cube@NetBSD.org> | 2008-03-07 21:45:07 +0000 |
|---|---|---|
| committer | cube <cube@NetBSD.org> | 2008-03-07 21:45:07 +0000 |
| commit | 3c5e53b4e205a4d4623da25edbf2df40bbbbb931 (patch) | |
| tree | f08a7234f4ee76861869f0e7128c1e2b6f6690eb /sys | |
| parent | 4f831ae35acb2902da1b69556547d25e2a2aa40f (diff) | |
Split device_t/softc for i386's apm(4), and other related cosmetic changes.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/i386/i386/apmbios.c | 92 | ||||
| -rw-r--r-- | sys/dev/acpi/acpi_apm.c | 20 | ||||
| -rw-r--r-- | sys/dev/apm/apm.c | 47 | ||||
| -rw-r--r-- | sys/dev/apm/apmvar.h | 4 |
4 files changed, 79 insertions, 84 deletions
diff --git a/sys/arch/i386/i386/apmbios.c b/sys/arch/i386/i386/apmbios.c index 15320cf1353..f6d2506d054 100644 --- a/sys/arch/i386/i386/apmbios.c +++ b/sys/arch/i386/i386/apmbios.c @@ -1,4 +1,4 @@ -/* $NetBSD: apmbios.c,v 1.8 2008/01/04 18:25:43 ad Exp $ */ +/* $NetBSD: apmbios.c,v 1.9 2008/03/07 21:45:07 cube Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: apmbios.c,v 1.8 2008/01/04 18:25:43 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: apmbios.c,v 1.9 2008/03/07 21:45:07 cube Exp $"); #include "opt_apm.h" #include "opt_compat_mach.h" /* Needed to get the right segment def */ @@ -136,7 +136,7 @@ static void apm_powmgt_enable(int); static void apm_powmgt_engage(int, u_int); static int apm_get_ver(struct apm_softc *); -CFATTACH_DECL(apmbios, sizeof(struct apm_softc), +CFATTACH_DECL_NEW(apmbios, sizeof(struct apm_softc), apmbiosmatch, apmbiosattach, NULL, NULL); #ifdef APMDEBUG @@ -470,7 +470,7 @@ static void apmbiosattach(struct device *parent, struct device *self, void *aux) { - struct apm_softc *apmsc = (void *)self; + struct apm_softc *apmsc = device_private(self); struct bioscallregs regs; int apm_data_seg_ok; u_int okbases[] = { 0, biosbasemem*1024 }; @@ -487,21 +487,23 @@ apmbiosattach(struct device *parent, struct device *self, aprint_naive(": Power management\n"); aprint_normal(": Advanced Power Management BIOS"); + apmsc->sc_dev = self; + memset(®s, 0, sizeof(struct bioscallregs)); regs.AX = APM_BIOS_FN(APM_INSTALLATION_CHECK); regs.BX = APM_DEV_APM_BIOS; #ifdef APM_USE_KVM86 res = kvm86_bioscall_simple(APM_SYSTEM_BIOS, ®s); if (res) { - aprint_error("%s: kvm86 error (APM_INSTALLATION_CHECK)\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, + "%s: kvm86 error (APM_INSTALLATION_CHECK)\n"); goto bail_disconnected; } #else bioscall(APM_SYSTEM_BIOS, ®s); #endif DPRINTF_BIOSRETURN(regs, bits); - DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", apmsc->sc_dev.dv_xname)); + DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", device_xname(self))); apminfo.apm_detail = (u_int)regs.AX | ((u_int)regs.CX << 16); @@ -515,19 +517,17 @@ apmbiosattach(struct device *parent, struct device *self, #ifdef APM_USE_KVM86 res = kvm86_bioscall_simple(APM_SYSTEM_BIOS, ®s); if (res) { - aprint_error("%s: kvm86 error (APM_DISCONNECT)\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, "%s: kvm86 error (APM_DISCONNECT)\n"); goto bail_disconnected; } #else bioscall(APM_SYSTEM_BIOS, ®s); #endif DPRINTF_BIOSRETURN(regs, bits); - DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", apmsc->sc_dev.dv_xname)); + DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", device_xname(self))); if ((apminfo.apm_detail & APM_32BIT_SUPPORTED) == 0) { - aprint_error("%s: no 32-bit APM support\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, "no 32-bit APM support\n"); goto bail_disconnected; } @@ -540,15 +540,15 @@ apmbiosattach(struct device *parent, struct device *self, #ifdef APM_USE_KVM86 res = kvm86_bioscall_simple(APM_SYSTEM_BIOS, ®s); if (res) { - aprint_error("%s: kvm86 error (APM_32BIT_CONNECT)\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, + "%s: kvm86 error (APM_32BIT_CONNECT)\n"); goto bail_disconnected; } #else bioscall(APM_SYSTEM_BIOS, ®s); #endif DPRINTF_BIOSRETURN(regs, bits); - DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", apmsc->sc_dev.dv_xname)); + DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", device_xname(self))); apminfo.apm_code32_seg_base = regs.AX << 4; apminfo.apm_entrypt = regs.BX; /* spec says EBX, can't map >=64k */ @@ -590,7 +590,7 @@ apmbiosattach(struct device *parent, struct device *self, ("lame v%d.%d bios gave zero len code32, pegged to 64k\n%s: ", APM_MAJOR_VERS(apminfo.apm_detail), APM_MINOR_VERS(apminfo.apm_detail), - apmsc->sc_dev.dv_xname)); + device_xname(self))); } if (apminfo.apm_code16_seg_len == 0) { /* @@ -603,7 +603,7 @@ apmbiosattach(struct device *parent, struct device *self, ("lame v%d.%d bios gave zero len code16, pegged to 64k\n%s: ", APM_MAJOR_VERS(apminfo.apm_detail), APM_MINOR_VERS(apminfo.apm_detail), - apmsc->sc_dev.dv_xname)); + device_xname(self))); } if (apminfo.apm_data_seg_len == 0) { /* @@ -621,7 +621,7 @@ apmbiosattach(struct device *parent, struct device *self, ("lame v%d.%d bios gave zero len data, tentative 64k\n%s: ", APM_MAJOR_VERS(apminfo.apm_detail), APM_MINOR_VERS(apminfo.apm_detail), - apmsc->sc_dev.dv_xname)); + device_xname(self))); } break; } @@ -631,15 +631,15 @@ apmbiosattach(struct device *parent, struct device *self, ("nonsensical BIOS code length %d ignored (entry point offset is %d)\n%s: ", apminfo.apm_code32_seg_len, apminfo.apm_entrypt, - apmsc->sc_dev.dv_xname)); + device_xname(self))); apminfo.apm_code32_seg_len = 65536; } if (apminfo.apm_code32_seg_base < IOM_BEGIN || apminfo.apm_code32_seg_base >= IOM_END) { DPRINTF(APMDEBUG_ATTACH, ("code32 segment starts outside ISA hole [%x]\n%s: ", - apminfo.apm_code32_seg_base, apmsc->sc_dev.dv_xname)); - aprint_error("%s: bogus 32-bit code segment start\n", - apmsc->sc_dev.dv_xname); + apminfo.apm_code32_seg_base, device_xname(self))); + aprint_error_dev(self, + "bogus 32-bit code segment start\n"); goto bail; } if (apminfo.apm_code32_seg_base + @@ -647,10 +647,9 @@ apmbiosattach(struct device *parent, struct device *self, DPRINTF(APMDEBUG_ATTACH, ("code32 segment oversized: [%x,%x)\n%s: ", apminfo.apm_code32_seg_base, apminfo.apm_code32_seg_base + apminfo.apm_code32_seg_len - 1, - apmsc->sc_dev.dv_xname)); + device_xname(self))); #if 0 - aprint_error("%s: bogus 32-bit code segment size\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, "bogus 32-bit code segment size\n"); goto bail; #else apminfo.apm_code32_seg_len = @@ -660,9 +659,9 @@ apmbiosattach(struct device *parent, struct device *self, if (apminfo.apm_code16_seg_base < IOM_BEGIN || apminfo.apm_code16_seg_base >= IOM_END) { DPRINTF(APMDEBUG_ATTACH, ("code16 segment starts outside ISA hole [%x]\n%s: ", - apminfo.apm_code16_seg_base, apmsc->sc_dev.dv_xname)); - aprint_error("%s: bogus 16-bit code segment start\n", - apmsc->sc_dev.dv_xname); + apminfo.apm_code16_seg_base, device_xname(self))); + aprint_error_dev(self, + "bogus 16-bit code segment start\n"); goto bail; } if (apminfo.apm_code16_seg_base + @@ -671,13 +670,12 @@ apmbiosattach(struct device *parent, struct device *self, ("code16 segment oversized: [%x,%x), giving up\n%s: ", apminfo.apm_code16_seg_base, apminfo.apm_code16_seg_base + apminfo.apm_code16_seg_len - 1, - apmsc->sc_dev.dv_xname)); + device_xname(self))); /* * give up since we may have to trash the * 32bit segment length otherwise. */ - aprint_error("%s: bogus 16-bit code segment size\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, "bogus 16-bit code segment size\n"); goto bail; } /* @@ -705,13 +703,13 @@ apmbiosattach(struct device *parent, struct device *self, ("; resized to [%x,%x)\n%s: ", apminfo.apm_data_seg_base, apminfo.apm_data_seg_base + apminfo.apm_data_seg_len, - apmsc->sc_dev.dv_xname)); + device_xname(self))); } else { DPRINTF(APMDEBUG_ATTACH, ("data segment fine: [%x,%x)\n%s: ", apminfo.apm_data_seg_base, apminfo.apm_data_seg_base + apminfo.apm_data_seg_len, - apmsc->sc_dev.dv_xname)); + device_xname(self))); } apm_data_seg_ok = 1; break; @@ -721,11 +719,11 @@ apmbiosattach(struct device *parent, struct device *self, if (apm_allow_bogus_segments) { DPRINTF(APMDEBUG_ATTACH, ("bogus bios data seg location, continuing\n%s: ", - apmsc->sc_dev.dv_xname)); + device_xname(self))); } else { DPRINTF(APMDEBUG_ATTACH, ("bogus bios data seg location, ignoring\n%s: ", - apmsc->sc_dev.dv_xname)); + device_xname(self))); apminfo.apm_data_seg_base = 0; apminfo.apm_data_seg_len = 0; } @@ -736,9 +734,8 @@ apmbiosattach(struct device *parent, struct device *self, ("data segment [%x,%x) not in an available location\n%s: ", apminfo.apm_data_seg_base, apminfo.apm_data_seg_base + apminfo.apm_data_seg_len, - apmsc->sc_dev.dv_xname)); - aprint_error("%s: data segment unavailable\n", - apmsc->sc_dev.dv_xname); + device_xname(self))); + aprint_error_dev(self, "data segment unavailable\n"); goto bail; } @@ -758,7 +755,7 @@ apmbiosattach(struct device *parent, struct device *self, DPRINTF(APMDEBUG_ATTACH, ("code32len=%x, datalen=%x\n%s: ", apminfo.apm_code32_seg_len, apminfo.apm_data_seg_len, - apmsc->sc_dev.dv_xname)); + device_xname(self))); setgdt(GAPM32CODE_SEL, ISA_HOLE_VADDR(apminfo.apm_code32_seg_base), apminfo.apm_code32_seg_len - 1, SDT_MEMERA, SEL_KPL, 1, 0); @@ -789,14 +786,14 @@ apmbiosattach(struct device *parent, struct device *self, if (_x86_memio_map(X86_BUS_SPACE_MEM, apminfo.apm_data_seg_base, apminfo.apm_data_seg_len, 0, &memh)) { - aprint_error("%s: couldn't map data segment\n", - apmsc->sc_dev.dv_xname); + aprint_error_dev(self, + "couldn't map data segment\n"); goto bail; } DPRINTF(APMDEBUG_ATTACH, ("mapping bios data area %x @ 0x%lx\n%s: ", apminfo.apm_data_seg_base, memh, - apmsc->sc_dev.dv_xname)); + device_xname(self))); setgdt(GAPMDATA_SEL, (void *)memh, apminfo.apm_data_seg_len - 1, SDT_MEMRWA, SEL_KPL, 1, 0); @@ -822,7 +819,7 @@ apmbiosattach(struct device *parent, struct device *self, apminfo.apm_entrypt + (char *)ISA_HOLE_VADDR(apminfo.apm_code32_seg_base), &apminfo.apm_segsel, - apmsc->sc_dev.dv_xname)); + device_xname(self))); apmsc->sc_ops = &apm_accessops; apmsc->sc_cookie = apmsc; @@ -839,8 +836,7 @@ bail: */ apm_disconnect(apmsc); bail_disconnected: - aprint_normal("%s: kernel APM support disabled\n", - apmsc->sc_dev.dv_xname); + aprint_normal_dev(self, "kernel APM support disabled\n"); } static void @@ -882,10 +878,10 @@ apm_disconnect(void *arg) #endif if (sc == NULL) return; - DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", sc->sc_dev.dv_xname)); + DPRINTF(APMDEBUG_ATTACH, ("\n%s: ", device_xname(sc->sc_dev))); DPRINTF_BIOSRETURN(regs, bits); - printf("%s: unable to create thread, kernel APM support disabled\n", - sc->sc_dev.dv_xname); + aprint_error_dev(sc->sc_dev, + "unable to create thread, kernel APM support disabled\n"); } static int diff --git a/sys/dev/acpi/acpi_apm.c b/sys/dev/acpi/acpi_apm.c index e69b2772356..b2ea96ac34c 100644 --- a/sys/dev/acpi/acpi_apm.c +++ b/sys/dev/acpi/acpi_apm.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_apm.c,v 1.12 2007/12/09 20:27:52 jmcneill Exp $ */ +/* $NetBSD: acpi_apm.c,v 1.13 2008/03/07 21:45:08 cube Exp $ */ /*- * Copyright (c) 2006 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_apm.c,v 1.12 2007/12/09 20:27:52 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_apm.c,v 1.13 2008/03/07 21:45:08 cube Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -105,27 +105,27 @@ static int acpiapm_node = CTL_EOL, standby_node = CTL_EOL; struct acpi_softc; extern ACPI_STATUS acpi_enter_sleep_state(struct acpi_softc *, int); -static int acpiapm_match(struct device *, struct cfdata *, void *); -static void acpiapm_attach(struct device *, struct device *, void *); +static int acpiapm_match(device_t, cfdata_t , void *); +static void acpiapm_attach(device_t, device_t, void *); static int sysctl_state(SYSCTLFN_PROTO); -CFATTACH_DECL(acpiapm, sizeof(struct apm_softc), +CFATTACH_DECL_NEW(acpiapm, sizeof(struct apm_softc), acpiapm_match, acpiapm_attach, NULL, NULL); static int /*ARGSUSED*/ -acpiapm_match(struct device *parent, - struct cfdata *match, void *aux) +acpiapm_match(device_t parent, cfdata_t match, void *aux) { return apm_match(); } static void /*ARGSUSED*/ -acpiapm_attach(struct device *parent, struct device *self, void *aux) +acpiapm_attach(device_t parent, device_t self, void *aux) { - struct apm_softc *sc = (struct apm_softc *)self; + struct apm_softc *sc = device_private(self); + sc->sc_dev = self; sc->sc_ops = &acpiapm_accessops; sc->sc_cookie = parent; sc->sc_vers = 0x0102; @@ -239,7 +239,7 @@ acpiapm_enable(void *opaque, int onoff) static int acpiapm_set_powstate(void *opaque, u_int devid, u_int powstat) { - struct acpi_softc *sc = opaque; + struct acpi_softc *sc = device_private((device_t)opaque); if (devid != APM_DEV_ALLDEVS) return APM_ERR_UNRECOG_DEV; diff --git a/sys/dev/apm/apm.c b/sys/dev/apm/apm.c index 4ce4b1afeb4..be6ee1de858 100644 --- a/sys/dev/apm/apm.c +++ b/sys/dev/apm/apm.c @@ -1,4 +1,4 @@ -/* $NetBSD: apm.c,v 1.18 2008/03/01 14:16:50 rmind Exp $ */ +/* $NetBSD: apm.c,v 1.19 2008/03/07 21:45:08 cube Exp $ */ /*- * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.18 2008/03/01 14:16:50 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: apm.c,v 1.19 2008/03/07 21:45:08 cube Exp $"); #include "opt_apm.h" @@ -234,10 +234,11 @@ apm_power_print(struct apm_softc *sc, struct apm_power_info *pi) { if (pi->battery_life != APM_BATT_LIFE_UNKNOWN) { - printf("%s: battery life expectancy: %d%%\n", - sc->sc_dev.dv_xname, pi->battery_life); + aprint_normal_dev(sc->sc_dev, + "battery life expectancy: %d%%\n", + pi->battery_life); } - printf("%s: A/C state: ", sc->sc_dev.dv_xname); + aprint_normal_dev(sc->sc_dev, "A/C state: "); switch (pi->ac_state) { case APM_AC_OFF: printf("off\n"); @@ -253,7 +254,7 @@ apm_power_print(struct apm_softc *sc, struct apm_power_info *pi) printf("unknown\n"); break; } - printf("%s: battery charge state:", sc->sc_dev.dv_xname); + aprint_normal_dev(sc->sc_dev, "battery charge state:"); if (apm_minver == 0) switch (pi->battery_state) { case APM_BATT_HIGH: @@ -290,7 +291,7 @@ apm_power_print(struct apm_softc *sc, struct apm_power_info *pi) } printf("\n"); if (pi->minutes_valid) { - printf("%s: estimated ", sc->sc_dev.dv_xname); + aprint_normal_dev(sc->sc_dev, "estimated "); if (pi->minutes_left / 60) printf("%dh ", pi->minutes_left / 60); printf("%dm\n", pi->minutes_left % 60); @@ -307,8 +308,8 @@ apm_suspend(struct apm_softc *sc) if (sc->sc_power_state == PWR_SUSPEND) { #ifdef APMDEBUG - printf("%s: apm_suspend: already suspended?\n", - sc->sc_dev.dv_xname); + aprint_debug_dev(sc->sc_dev, + "apm_suspend: already suspended?\n"); #endif return; } @@ -333,8 +334,8 @@ apm_standby(struct apm_softc *sc) if (sc->sc_power_state == PWR_STANDBY) { #ifdef APMDEBUG - printf("%s: apm_standby: already standing by?\n", - sc->sc_dev.dv_xname); + aprint_debug_dev(sc->sc_dev, + "apm_standby: already standing by?\n"); #endif return; } @@ -356,8 +357,7 @@ apm_resume(struct apm_softc *sc, u_int event_type, u_int event_info) if (sc->sc_power_state == PWR_RESUME) { #ifdef APMDEBUG - printf("%s: apm_resume: already running?\n", - sc->sc_dev.dv_xname); + aprint_debug_dev(sc->sc_dev, "apm_resume: already running?\n"); #endif return; } @@ -676,19 +676,18 @@ apm_attach(struct apm_softc *sc) * and notify other subsystems when they occur. */ if (kthread_create(PRI_NONE, 0, NULL, apm_thread, sc, - &sc->sc_thread, "%s", sc->sc_dev.dv_xname) != 0) { + &sc->sc_thread, "%s", device_xname(sc->sc_dev)) != 0) { /* * We were unable to create the APM thread; bail out. */ if (sc->sc_ops->aa_disconnect) (*sc->sc_ops->aa_disconnect)(sc->sc_cookie); - printf("%s: unable to create thread, " - "kernel APM support disabled\n", - sc->sc_dev.dv_xname); + aprint_error_dev(sc->sc_dev, "unable to create thread, " + "kernel APM support disabled\n"); } - if (!pmf_device_register(&sc->sc_dev, NULL, NULL)) - aprint_error_dev(&sc->sc_dev, "couldn't establish power handler\n"); + if (!pmf_device_register(sc->sc_dev, NULL, NULL)) + aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n"); } void @@ -717,7 +716,7 @@ apmopen(dev_t dev, int flag, int mode, struct lwp *l) if (unit >= apm_cd.cd_ndevs) return ENXIO; - sc = apm_cd.cd_devs[unit]; + sc = device_private(apm_cd.cd_devs[unit]); if (!sc) return ENXIO; @@ -760,7 +759,7 @@ int apmclose(dev_t dev, int flag, int mode, struct lwp *l) { - struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct apm_softc *sc = device_private(apm_cd.cd_devs[APMUNIT(dev)]); int ctl = APM(dev); DPRINTF(APMDEBUG_DEVICE, @@ -787,7 +786,7 @@ int apmioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) { - struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct apm_softc *sc = device_private(apm_cd.cd_devs[APMUNIT(dev)]); struct apm_power_info *powerp; struct apm_event_info *evp; #if 0 @@ -886,7 +885,7 @@ apmioctl(dev_t dev, u_long cmd, void *data, int flag, int apmpoll(dev_t dev, int events, struct lwp *l) { - struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct apm_softc *sc = device_private(apm_cd.cd_devs[APMUNIT(dev)]); int revents = 0; APM_LOCK(sc); @@ -926,7 +925,7 @@ static const struct filterops apmread_filtops = int apmkqfilter(dev_t dev, struct knote *kn) { - struct apm_softc *sc = apm_cd.cd_devs[APMUNIT(dev)]; + struct apm_softc *sc = device_private(apm_cd.cd_devs[APMUNIT(dev)]); struct klist *klist; switch (kn->kn_filter) { diff --git a/sys/dev/apm/apmvar.h b/sys/dev/apm/apmvar.h index b27bcb07d4a..744ce99d072 100644 --- a/sys/dev/apm/apmvar.h +++ b/sys/dev/apm/apmvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: apmvar.h,v 1.5 2007/12/05 07:58:29 ad Exp $ */ +/* $NetBSD: apmvar.h,v 1.6 2008/03/07 21:45:08 cube Exp $ */ /*- * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. * All rights reserved. @@ -54,7 +54,7 @@ struct apm_accessops { #define APM_NEVENTS 16 struct apm_softc { - struct device sc_dev; + device_t sc_dev; struct selinfo sc_rsel; struct selinfo sc_xsel; int sc_flags; |
