Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/macppc apm emulation, from openbsd



details:   https://anonhg.NetBSD.org/src/rev/a893c7d15d5c
branches:  trunk
changeset: 532942:a893c7d15d5c
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Jun 18 05:22:50 2002 +0000

description:
apm emulation, from openbsd

diffstat:

 sys/arch/macppc/conf/GENERIC      |    5 +-
 sys/arch/macppc/conf/files.macppc |    6 +-
 sys/arch/macppc/dev/adb.c         |   12 +-
 sys/arch/macppc/dev/apm.c         |  476 ++++++++++++++++++++++++++++++++++++++
 sys/arch/macppc/dev/pm_direct.c   |   45 +++-
 sys/arch/macppc/dev/pm_direct.h   |   56 ++++-
 sys/arch/macppc/include/Makefile  |    4 +-
 sys/arch/macppc/include/adbsys.h  |    4 +-
 sys/arch/macppc/include/apmvar.h  |  142 +++++++++++
 sys/arch/macppc/macppc/conf.c     |    6 +-
 10 files changed, 746 insertions(+), 10 deletions(-)

diffs (truncated from 898 to 300 lines):

diff -r 2eec4959c23b -r a893c7d15d5c sys/arch/macppc/conf/GENERIC
--- a/sys/arch/macppc/conf/GENERIC      Tue Jun 18 05:01:55 2002 +0000
+++ b/sys/arch/macppc/conf/GENERIC      Tue Jun 18 05:22:50 2002 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.131 2002/06/17 05:14:15 lukem Exp $
+# $NetBSD: GENERIC,v 1.132 2002/06/18 05:22:50 itojun Exp $
 #
 # GENERIC machine description file
 # 
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident                 "GENERIC-$Revision: 1.131 $"
+#ident                 "GENERIC-$Revision: 1.132 $"
 
 maxusers       32
 
@@ -207,6 +207,7 @@
 mesh*  at obio? flags 0xffff           # MESH SCSI
 nvram* at obio?                        # nvram
 adb*   at obio?                        # Apple Desktop Bus
+apm0   at adb?                         # APM emulation
 aed*   at adb?                         # ADB Event Device
 akbd*  at adb?                         # ADB keyboard
 ams*   at adb?                         # ADB mouse
diff -r 2eec4959c23b -r a893c7d15d5c sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Tue Jun 18 05:01:55 2002 +0000
+++ b/sys/arch/macppc/conf/files.macppc Tue Jun 18 05:22:50 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.macppc,v 1.50 2002/04/22 09:41:20 augustss Exp $
+#      $NetBSD: files.macppc,v 1.51 2002/06/18 05:22:50 itojun Exp $
 #
 # macppc-specific configuration info
 
@@ -156,6 +156,10 @@
 file arch/macppc/dev/adb_direct.c              adb
 file arch/macppc/dev/pm_direct.c               adb
 
+device apm
+attach apm at adb
+file arch/macppc/dev/apm.c                     apm needs-count
+
 device aed
 attach aed at adb
 file arch/macppc/dev/aed.c                     aed needs-flag
diff -r 2eec4959c23b -r a893c7d15d5c sys/arch/macppc/dev/adb.c
--- a/sys/arch/macppc/dev/adb.c Tue Jun 18 05:01:55 2002 +0000
+++ b/sys/arch/macppc/dev/adb.c Tue Jun 18 05:22:50 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: adb.c,v 1.10 2002/06/18 04:33:36 itojun Exp $  */
+/*     $NetBSD: adb.c,v 1.11 2002/06/18 05:22:51 itojun Exp $  */
 
 /*-
  * Copyright (C) 1994  Bradley A. Grantham
@@ -48,6 +48,7 @@
 #include <dev/ofw/openfirm.h>
 
 #include "aed.h"
+#include "apm.h"
 
 /*
  * Function declarations.
@@ -160,6 +161,15 @@
                (void)config_found(self, &aa_args, adbprint);
        }
 
+#if NAPM > 0
+       /* Magic for signalling the apm driver to match. */
+       aa_args.origaddr = ADBADDR_APM;
+       aa_args.adbaddr = ADBADDR_APM;
+       aa_args.handler_id = ADBADDR_APM;
+
+       (void)config_found(self, &aa_args, NULL);
+#endif
+
        if (adbHardware == ADB_HW_CUDA)
                adb_cuda_autopoll();
        adb_polling = 0;
diff -r 2eec4959c23b -r a893c7d15d5c sys/arch/macppc/dev/apm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/dev/apm.c Tue Jun 18 05:22:50 2002 +0000
@@ -0,0 +1,476 @@
+/*     $NetBSD: apm.c,v 1.1 2002/06/18 05:22:51 itojun Exp $   */
+/*     $OpenBSD: apm.c,v 1.5 2002/06/07 07:13:59 miod Exp $    */
+
+/*-
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
+ *
+ */
+
+#include "apm.h"
+
+#if NAPM > 1
+#error only one APM emulation device may be configured
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/device.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#ifdef __OpenBSD__
+#include <sys/event.h>
+#endif
+#ifdef __NetBSD__
+#include <sys/select.h>
+#include <sys/poll.h>
+#include <sys/conf.h>
+#endif
+
+#ifdef __OpenBSD__
+#include <machine/conf.h>
+#endif
+#include <machine/cpu.h>
+#include <machine/apmvar.h>
+
+#include <macppc/dev/adbvar.h>
+#include <macppc/dev/adb_direct.h>
+#include <macppc/dev/pm_direct.h>
+
+#if defined(APMDEBUG)
+#define DPRINTF(x)     printf x
+#else
+#define        DPRINTF(x)      /**/
+#endif
+
+#define APM_NEVENTS 16
+
+struct apm_softc {
+       struct device sc_dev;
+       struct selinfo sc_rsel;
+#ifdef __OpenBSD__
+       struct klist sc_note;
+#endif
+       int    sc_flags;
+       int     event_count;
+       int     event_ptr;
+       struct lock 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.
+ */
+#ifdef __NetBSD__
+#define        APM_LOCK(apmsc)                                                 \
+       (void) lockmgr(&(apmsc)->sc_lock, LK_EXCLUSIVE, NULL)
+#define        APM_UNLOCK(apmsc)                                               \
+       (void) lockmgr(&(apmsc)->sc_lock, LK_RELEASE, NULL)
+#else
+#define APM_LOCK(apmsc)
+#define APM_UNLOCK(apmsc)
+#endif
+
+int apmmatch(struct device *, struct cfdata *, void *);
+void apmattach(struct device *, struct device *, void *);
+
+#ifdef __NetBSD__
+#if 0
+static int     apm_record_event __P((struct apm_softc *, u_int));
+#endif
+#endif
+
+#ifdef __NetBSD__
+cdev_decl(apm);
+#endif
+
+struct cfattach apm_ca = {
+       sizeof(struct apm_softc), apmmatch, apmattach
+};
+
+#ifdef __OpenBSD__
+struct cfdriver apm_cd = {
+       NULL, "apm", DV_DULL
+};
+#else
+extern struct cfdriver apm_cd;
+#endif
+
+int    apm_evindex;
+
+#define        APMUNIT(dev)    (minor(dev)&0xf0)
+#define        APMDEV(dev)     (minor(dev)&0x0f)
+#define APMDEV_NORMAL  0
+#define APMDEV_CTL     8
+
+#ifdef __OpenBSD__
+void filt_apmrdetach(struct knote *kn);
+int filt_apmread(struct knote *kn, long hint);
+int apmkqfilter(dev_t dev, struct knote *kn);
+
+struct filterops apmread_filtops =
+       { 1, NULL, filt_apmrdetach, filt_apmread};
+#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.
+ */
+
+#define SCFLAG_NOPRINT 0x0008000
+#define SCFLAG_PCTPRINT        0x0004000
+#define SCFLAG_PRINT   (SCFLAG_NOPRINT|SCFLAG_PCTPRINT)
+
+#define        SCFLAG_OREAD    (1 << 0)
+#define        SCFLAG_OWRITE   (1 << 1)
+#define        SCFLAG_OPEN     (SCFLAG_OREAD|SCFLAG_OWRITE)
+
+
+int
+apmmatch(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct adb_attach_args *aa = (void *)aux;               
+       if (aa->origaddr != ADBADDR_APM ||
+           aa->handler_id != ADBADDR_APM ||
+           aa->adbaddr != ADBADDR_APM)
+               return 0;
+
+       if (adbHardware != ADB_HW_PB)
+               return 0;
+
+       return 1;
+}
+
+void
+apmattach(parent, self, aux)
+       struct device *parent, *self;
+       void *aux;
+{
+       struct pmu_battery_info info;
+
+       pm_battery_info(0, &info);
+
+       printf(": battery flags 0x%X, ", info.flags);
+       printf("%d%% charged\n", ((info.cur_charge * 100) / info.max_charge));
+}
+
+int
+apmopen(dev, flag, mode, p)
+       dev_t dev;
+       int flag, mode;
+       struct proc *p;
+{
+       struct apm_softc *sc;
+       int error = 0;
+
+       /* apm0 only */
+       if (!apm_cd.cd_ndevs || APMUNIT(dev) != 0 ||
+           !(sc = apm_cd.cd_devs[APMUNIT(dev)]))
+               return ENXIO;
+
+       DPRINTF(("apmopen: dev %d pid %d flag %x mode %x\n",
+           APMDEV(dev), p->p_pid, flag, mode));
+
+       APM_LOCK(sc);
+       switch (APMDEV(dev)) {



Home | Main Index | Thread Index | Old Index