Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/sys/arch/hpcmips/dev Pull up revision 1.1 (new, request...



details:   https://anonhg.NetBSD.org/src/rev/656ddfabd075
branches:  netbsd-1-5
changeset: 488893:656ddfabd075
user:      takemura <takemura%NetBSD.org@localhost>
date:      Sun Aug 06 03:56:41 2000 +0000

description:
Pull up revision 1.1 (new, requested by takemura)

New power management function and MQ200 video power management driver.

diffstat:

 sys/arch/hpcmips/dev/apm/apmdev.c  |  915 +++++++++++++++++++++++++++++++++++++
 sys/arch/hpcmips/dev/apm/apmvar.h  |  339 +++++++++++++
 sys/arch/hpcmips/dev/apm/files.apm |   12 +
 sys/arch/hpcmips/dev/mq200.c       |  440 +++++++++++++++++
 sys/arch/hpcmips/dev/mq200reg.h    |  566 ++++++++++++++++++++++
 sys/arch/hpcmips/dev/mq200var.h    |   54 ++
 6 files changed, 2326 insertions(+), 0 deletions(-)

diffs (truncated from 2350 to 300 lines):

diff -r 3ee58ee5d86b -r 656ddfabd075 sys/arch/hpcmips/dev/apm/apmdev.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/hpcmips/dev/apm/apmdev.c Sun Aug 06 03:56:41 2000 +0000
@@ -0,0 +1,915 @@
+/*     $NetBSD: apmdev.c,v 1.1.2.2 2000/08/06 03:56:42 takemura Exp $ */
+
+/*-
+ * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by John Kohl and Christopher G. Demetriou.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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 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.
+ */
+/*
+ * from: sys/arch/i386/i386/apm.c,v 1.49 2000/05/08
+ */
+
+#include "opt_apmdev.h"
+
+#ifdef APM_NOIDLE
+#error APM_NOIDLE option deprecated; use APM_NO_IDLE instead
+#endif
+
+#if defined(DEBUG) && !defined(APMDEBUG)
+#define        APMDEBUG
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/signalvar.h>
+#include <sys/kernel.h>
+#include <sys/map.h>
+#include <sys/proc.h>
+#include <sys/kthread.h>
+#include <sys/lock.h>
+#include <sys/user.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+#include <sys/poll.h>
+#include <sys/conf.h>
+
+#include <arch/hpcmips/dev/apm/apmvar.h>
+
+#include <machine/stdarg.h>
+
+#define        APMDEBUG
+#if defined(APMDEBUG)
+#define        DPRINTF(f, x)           do { if (apmdebug & (f)) printf x; } while (0)
+
+#define        APMDEBUG_INFO           0x01
+#define        APMDEBUG_APMCALLS       0x02
+#define        APMDEBUG_EVENTS         0x04
+#define        APMDEBUG_PROBE          0x10
+#define        APMDEBUG_ATTACH         0x40
+#define        APMDEBUG_DEVICE         0x20
+#define        APMDEBUG_ANOM           0x40
+
+#ifdef APMDEBUG_VALUE
+int    apmdebug = APMDEBUG_VALUE;
+#else
+int    apmdebug = 0;
+#endif
+#else
+#define        DPRINTF(f, x)           /**/
+#endif
+
+#define APM_NEVENTS 16
+
+struct apm_softc {
+       struct device sc_dev;
+       struct selinfo sc_rsel;
+       struct selinfo sc_xsel;
+       int     sc_flags;
+       int     event_count;
+       int     event_ptr;
+       int     sc_power_state;
+       struct proc *sc_thread;
+       struct lock sc_lock;
+       struct apm_event_info event_list[APM_NEVENTS];
+       struct apm_accessops *ops;
+       void *cookie;
+};
+#define        SCFLAG_OREAD    0x0000001
+#define        SCFLAG_OWRITE   0x0000002
+#define        SCFLAG_OPEN     (SCFLAG_OREAD|SCFLAG_OWRITE)
+
+#define        APMUNIT(dev)    (minor(dev)&0xf0)
+#define        APMDEV(dev)     (minor(dev)&0x0f)
+#define APMDEV_NORMAL  0
+#define APMDEV_CTL     8
+
+/*
+ * 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)                                                 \
+       (void) lockmgr(&(apmsc)->sc_lock, LK_EXCLUSIVE, NULL)
+#define        APM_UNLOCK(apmsc)                                               \
+       (void) lockmgr(&(apmsc)->sc_lock, LK_RELEASE, NULL)
+
+static void    apmattach __P((struct device *, struct device *, void *));
+static int     apmmatch __P((struct device *, struct cfdata *, void *));
+
+static void    apm_event_handle __P((struct apm_softc *, u_int, u_int));
+static void    apm_periodic_check __P((struct apm_softc *));
+static void    apm_create_thread __P((void *));
+static void    apm_thread __P((void *));
+static void    apm_perror __P((const char *, int, ...))
+                   __kprintf_attribute__((__format__(__printf__,1,3)));
+#ifdef APM_POWER_PRINT
+static void    apm_power_print __P((struct apm_softc *, struct apm_power_info *));
+#endif
+static int     apm_record_event __P((struct apm_softc *, u_int));
+static void    apm_set_ver __P((struct apm_softc *, u_long));
+static void    apm_standby __P((struct apm_softc *));
+static const char *apm_strerror __P((int));
+static void    apm_suspend __P((struct apm_softc *));
+static void    apm_resume __P((struct apm_softc *, u_int, u_int));
+
+cdev_decl(apmdev);
+
+struct cfattach apmdev_ca = {
+       sizeof(struct apm_softc), apmmatch, apmattach
+};
+
+extern struct cfdriver apmdev_cd;
+
+/* configurable variables */
+int    apm_bogus_bios = 0;
+#ifdef APM_DISABLE
+int    apm_enabled = 0;
+#else
+int    apm_enabled = 1;
+#endif
+#ifdef APM_NO_IDLE
+int    apm_do_idle = 0;
+#else
+int    apm_do_idle = 1;
+#endif
+#ifdef APM_NO_STANDBY
+int    apm_do_standby = 0;
+#else
+int    apm_do_standby = 1;
+#endif
+#ifdef APM_V10_ONLY
+int    apm_v11_enabled = 0;
+#else
+int    apm_v11_enabled = 1;
+#endif
+#ifdef APM_NO_V12
+int    apm_v12_enabled = 0;
+#else
+int    apm_v12_enabled = 1;
+#endif
+
+/* variables used during operation (XXX cgd) */
+u_char apm_majver, apm_minver;
+int    apm_inited;
+int    apm_standbys, apm_userstandbys, apm_suspends, apm_battlow;
+int    apm_damn_fool_bios, apm_op_inprog;
+int    apm_evindex;
+
+static const char *
+apm_strerror(code)
+       int code;
+{
+       switch (code) {
+       case APM_ERR_PM_DISABLED:
+               return ("power management disabled");
+       case APM_ERR_REALALREADY:
+               return ("real mode interface already connected");
+       case APM_ERR_NOTCONN:
+               return ("interface not connected");
+       case APM_ERR_16ALREADY:
+               return ("16-bit interface already connected");
+       case APM_ERR_16NOTSUPP:
+               return ("16-bit interface not supported");
+       case APM_ERR_32ALREADY:
+               return ("32-bit interface already connected");
+       case APM_ERR_32NOTSUPP:
+               return ("32-bit interface not supported");
+       case APM_ERR_UNRECOG_DEV:
+               return ("unrecognized device ID");
+       case APM_ERR_ERANGE:
+               return ("parameter out of range");
+       case APM_ERR_NOTENGAGED:
+               return ("interface not engaged");
+       case APM_ERR_UNABLE:
+               return ("unable to enter requested state");
+       case APM_ERR_NOEVENTS:
+               return ("no pending events");
+       case APM_ERR_NOT_PRESENT:
+               return ("no APM present");
+       default:
+               return ("unknown error code");
+       }
+}
+
+static void
+apm_perror(const char *str, int errinfo, ...) /* XXX cgd */
+{
+       va_list ap;
+
+       printf("APM ");
+
+       va_start(ap, errinfo);
+       vprintf(str, ap);                       /* XXX cgd */
+       va_end(ap);
+
+       printf(": %s\n", apm_strerror(errinfo));
+}
+
+#ifdef APM_POWER_PRINT
+static void
+apm_power_print(sc, pi)
+       struct apm_softc *sc;
+       struct apm_power_info *pi;
+{
+
+       if (APM_BATT_LIFE(regs) != APM_BATT_LIFE_UNKNOWN) {
+               printf("%s: battery life expectancy: %d%%\n",
+                   sc->sc_dev.dv_xname, APM_BATT_LIFE(regs));
+       }
+       printf("%s: A/C state: ", sc->sc_dev.dv_xname);
+       switch (pi->ac_state) {
+       case APM_AC_OFF:
+               printf("off\n");
+               break;
+       case APM_AC_ON:
+               printf("on\n");
+               break;
+       case APM_AC_BACKUP:
+               printf("backup power\n");
+               break;
+       default:
+       case APM_AC_UNKNOWN:
+               printf("unknown\n");
+               break;
+       }
+       printf("%s: battery charge state:", sc->sc_dev.dv_xname);
+       switch (pi->battery_state) {
+       case APM_BATT_HIGH:
+               printf("high\n");
+               break;
+       case APM_BATT_LOW:
+               printf("low\n");
+               break;
+       case APM_BATT_CRITICAL:
+               printf("critical\n");
+               break;
+       case APM_BATT_CHARGING:
+               printf("charging\n");
+               break;
+       case APM_BATT_UNKNOWN:
+               printf("unknown\n");
+               break;
+       default:
+               printf("undecoded state %x\n", pi->battery_state);
+               break;
+       }
+       if (pi->minutes_left != 0) {
+               printf("%s: estimated ", sc->sc_dev.dv_xname);
+               printf("%dh ", pi->minutes_left / 60);
+       }
+       return;
+}
+#endif



Home | Main Index | Thread Index | Old Index