static int apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) { int error; struct apm_clone_data *clone; struct acpi_softc *acpi_sc; struct apm_info info; struct apm_event_info *ev_info; apm_info_old_t aiop; error = 0; clone = dev->si_drv1; acpi_sc = clone->acpi_sc; switch (cmd) { case APMIO_SUSPEND: if ((flag & FWRITE) == 0) return (EPERM); if (acpi_sc->acpi_next_sstate == 0) { if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) { error = acpi_ReqSleepState(acpi_sc, acpi_sc->acpi_suspend_sx); } else { printf( "power off via apm suspend not supported\n"); error = ENXIO; } } else error = acpi_AckSleepState(clone, 0); break; case APMIO_STANDBY: if ((flag & FWRITE) == 0) return (EPERM); if (acpi_sc->acpi_next_sstate == 0) { if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) { error = acpi_ReqSleepState(acpi_sc, acpi_sc->acpi_standby_sx); } else { printf( "power off via apm standby not supported\n"); error = ENXIO; } } else error = acpi_AckSleepState(clone, 0); break; case APMIO_NEXTEVENT: printf("apm nextevent start\n"); ACPI_LOCK(acpi); if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status == APM_EV_NONE) { ev_info = (struct apm_event_info *)addr; if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3) ev_info->type = PMEV_STANDBYREQ; else ev_info->type = PMEV_SUSPENDREQ; ev_info->index = 0; clone->notify_status = APM_EV_NOTIFIED; printf("apm event returning %d\n", ev_info->type); } else error = EAGAIN; ACPI_UNLOCK(acpi); break; case APMIO_GETINFO_OLD: if (acpi_capm_get_info(&info)) error = ENXIO; aiop = (apm_info_old_t)addr; aiop->ai_major = info.ai_major; aiop->ai_minor = info.ai_minor; aiop->ai_acline = info.ai_acline; aiop->ai_batt_stat = info.ai_batt_stat; aiop->ai_batt_life = info.ai_batt_life; aiop->ai_status = info.ai_status; break; case APMIO_GETINFO: if (acpi_capm_get_info((apm_info_t)addr)) error = ENXIO; break; case APMIO_GETPWSTATUS: if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr)) error = ENXIO; break; case APMIO_ENABLE: if ((flag & FWRITE) == 0) return (EPERM); apm_active = 1; break; case APMIO_DISABLE: if ((flag & FWRITE) == 0) return (EPERM); apm_active = 0; break; case APMIO_HALTCPU: break; case APMIO_NOTHALTCPU: break; case APMIO_DISPLAY: if ((flag & FWRITE) == 0) return (EPERM); break; case APMIO_BIOS: if ((flag & FWRITE) == 0) return (EPERM); bzero(addr, sizeof(struct apm_bios_arg)); break; default: error = EINVAL; break; } return (error); }
static int apmioctl(struct dev_ioctl_args *ap) { int error = 0; struct acpi_softc *acpi_sc; struct apm_info info; apm_info_old_t aiop; acpi_sc = device_get_softc(acpi_dev); switch (ap->a_cmd) { case APMIO_SUSPEND: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); if (apm_softc.active) acpi_SetSleepState(acpi_sc, acpi_sc->acpi_suspend_sx); else error = EINVAL; break; case APMIO_STANDBY: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); if (apm_softc.active) acpi_SetSleepState(acpi_sc, acpi_sc->acpi_standby_sx); else error = EINVAL; break; case APMIO_GETINFO_OLD: if (acpi_capm_get_info(&info)) error = ENXIO; aiop = (apm_info_old_t)ap->a_data; aiop->ai_major = info.ai_major; aiop->ai_minor = info.ai_minor; aiop->ai_acline = info.ai_acline; aiop->ai_batt_stat = info.ai_batt_stat; aiop->ai_batt_life = info.ai_batt_life; aiop->ai_status = info.ai_status; break; case APMIO_GETINFO: if (acpi_capm_get_info((apm_info_t)ap->a_data)) error = ENXIO; break; case APMIO_GETPWSTATUS: if (acpi_capm_get_pwstatus((apm_pwstatus_t)ap->a_data)) error = ENXIO; break; case APMIO_ENABLE: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); apm_softc.active = 1; break; case APMIO_DISABLE: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); apm_softc.active = 0; break; case APMIO_HALTCPU: break; case APMIO_NOTHALTCPU: break; case APMIO_DISPLAY: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); break; case APMIO_BIOS: if ((ap->a_fflag & FWRITE) == 0) return (EPERM); bzero(ap->a_data, sizeof(struct apm_bios_arg)); break; default: error = EINVAL; break; } return (error); }
static int apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td) { int error = 0; struct acpi_softc *acpi_sc; struct apm_info info; apm_info_old_t aiop; if ((acpi_sc = device_get_softc(acpi_dev)) == NULL) { return (ENXIO); } switch (cmd) { case APMIO_SUSPEND: if (!(flag & FWRITE)) return (EPERM); if (apm_softc.active) acpi_SetSleepState(acpi_sc, acpi_sc->acpi_suspend_sx); else error = EINVAL; break; case APMIO_STANDBY: if (!(flag & FWRITE)) return (EPERM); if (apm_softc.active) acpi_SetSleepState(acpi_sc, acpi_sc->acpi_standby_sx); else error = EINVAL; break; case APMIO_GETINFO_OLD: if (acpi_capm_get_info(&info)) error = ENXIO; aiop = (apm_info_old_t)addr; aiop->ai_major = info.ai_major; aiop->ai_minor = info.ai_minor; aiop->ai_acline = info.ai_acline; aiop->ai_batt_stat = info.ai_batt_stat; aiop->ai_batt_life = info.ai_batt_life; aiop->ai_status = info.ai_status; break; case APMIO_GETINFO: if (acpi_capm_get_info((apm_info_t)addr)) error = ENXIO; break; case APMIO_GETPWSTATUS: if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr)) error = ENXIO; break; case APMIO_ENABLE: if (!(flag & FWRITE)) return (EPERM); apm_softc.active = 1; break; case APMIO_DISABLE: if (!(flag & FWRITE)) return (EPERM); apm_softc.active = 0; break; case APMIO_HALTCPU: break; case APMIO_NOTHALTCPU: break; case APMIO_DISPLAY: if (!(flag & FWRITE)) return (EPERM); break; case APMIO_BIOS: if (!(flag & FWRITE)) return (EPERM); bzero(addr, sizeof(struct apm_bios_arg)); break; default: error = EINVAL; break; } return (error); }