/*-
* Copyright (c) 2001 Alexander Guy. All rights reserved.
* Copyright (c) 1998-2001 Michael Shalayeff. All rights reserved.
* Copyright (c) 1995 John T. Kohl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the authors nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
struct apm_softc {
struct selinfo sc_rsel;
int sc_flags;
int event_count;
int event_ptr;
kmutex_t sc_lock;
struct apm_event_info event_list[APM_NEVENTS];
};
/*
* A brief note on the locking protocol: it's very simple; we
* assert an exclusive lock any time thread context enters the
* APM module. This is both the APM thread itself, as well as
* user context.
*/
#define APM_LOCK(apmsc) mutex_enter(&(apmsc)->sc_lock)
#define APM_UNLOCK(apmsc) mutex_exit(&(apmsc)->sc_lock)
int apmmatch(device_t, cfdata_t, void *);
void apmattach(device_t, device_t, void *);
#if 0
static int apm_record_event(struct apm_softc *, u_int);
#endif
/*
* Flags to control kernel display
* SCFLAG_NOPRINT: do not output APM power messages due to
* a power change event.
*
* SCFLAG_PCTPRINT: do not output APM power messages due to
* to a power change event unless the battery
* percentage changes.
*/
#if 0
/*
* return 0 if the user will notice and handle the event,
* return 1 if the kernel driver should do so.
*/
static int
apm_record_event(struct apm_softc *sc, u_int event_type)
{
struct apm_event_info *evp;
if ((sc->sc_flags & SCFLAG_OPEN) == 0)
return 1; /* no user waiting */
if (sc->event_count == APM_NEVENTS) {
DPRINTF(("apm_record_event: queue full!\n"));
return 1; /* overflow */
}
evp = &sc->event_list[sc->event_ptr];
sc->event_count++;
sc->event_ptr++;
sc->event_ptr %= APM_NEVENTS;
evp->type = event_type;
evp->index = ++apm_evindex;
selnotify(&sc->sc_rsel, 0, 0);
return (sc->sc_flags & SCFLAG_OWRITE) ? 0 : 1; /* user may handle */
}
#endif
int
apmpoll(dev_t dev, int events, struct lwp *l)
{
struct apm_softc *sc = device_lookup_private(&apm_cd,APMUNIT(dev));
int revents = 0;