1994-10-01 03:23:33 +00:00
|
|
|
/*
|
1998-02-20 07:17:48 +00:00
|
|
|
* Copyright (C) 1994 by Tatsumi Hosokawa <hosokawa@jp.FreeBSD.org>
|
1994-10-01 03:23:33 +00:00
|
|
|
*
|
|
|
|
* This software may be used, modified, copied, distributed, and sold,
|
|
|
|
* in both source and binary form provided that the above copyright and
|
1995-05-30 03:57:47 +00:00
|
|
|
* these terms are retained. Under no circumstances is the author
|
|
|
|
* responsible for the proper functioning of this software, nor does
|
|
|
|
* the author assume any responsibility for damages incurred with its
|
1994-10-01 03:23:33 +00:00
|
|
|
* use.
|
|
|
|
*
|
|
|
|
* Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD)
|
|
|
|
*/
|
|
|
|
|
1997-09-02 06:37:48 +00:00
|
|
|
#ifndef lint
|
|
|
|
static const char rcsid[] =
|
1998-02-20 07:17:48 +00:00
|
|
|
"$Id: apmconf.c,v 1.7 1997/09/02 06:37:48 charnier Exp $";
|
1997-09-02 06:37:48 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <err.h>
|
1994-10-01 03:23:33 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1997-09-02 06:37:48 +00:00
|
|
|
#include <unistd.h>
|
1994-10-01 03:23:33 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <machine/apm_bios.h>
|
|
|
|
|
1996-03-18 20:35:17 +00:00
|
|
|
#define APMDEV "/dev/apm"
|
1994-10-01 03:23:33 +00:00
|
|
|
|
|
|
|
static int enable = 0, disable = 0;
|
|
|
|
static int haltcpu = 0, nothaltcpu = 0;
|
|
|
|
static int main_argc;
|
|
|
|
static char **main_argv;
|
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
static void
|
1994-10-01 03:23:33 +00:00
|
|
|
parse_option(void)
|
|
|
|
{
|
|
|
|
int i, option;
|
1994-11-01 22:46:40 +00:00
|
|
|
enum {OPT_NONE, OPT_ENABLE, OPT_DISABLE, OPT_HALTCPU, OPT_NOTHALTCPU} mode;
|
1994-10-01 03:23:33 +00:00
|
|
|
|
|
|
|
for (i = 1; i < main_argc; i++) {
|
|
|
|
option = 0;
|
|
|
|
mode = OPT_NONE;
|
|
|
|
if (main_argv[i][0] == '-') {
|
|
|
|
switch (main_argv[i][1]) {
|
|
|
|
case 'e':
|
|
|
|
mode = OPT_ENABLE;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
mode = OPT_DISABLE;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
mode = OPT_HALTCPU;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
mode = OPT_NOTHALTCPU;
|
|
|
|
option = 0;
|
|
|
|
break;
|
|
|
|
default:
|
1997-09-02 06:37:48 +00:00
|
|
|
errx(1, "unknown option '%s'", main_argv[i]);
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (option) {
|
1997-09-02 06:37:48 +00:00
|
|
|
if (i == main_argc - 1)
|
|
|
|
errx(1, "option '%s' needs arguments", main_argv[i]);
|
1994-10-01 03:23:33 +00:00
|
|
|
optarg = main_argv[++i];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case OPT_ENABLE:
|
|
|
|
enable = 1;
|
|
|
|
break;
|
|
|
|
case OPT_DISABLE:
|
|
|
|
disable = 1;
|
|
|
|
break;
|
|
|
|
case OPT_HALTCPU:
|
|
|
|
haltcpu = 1;
|
|
|
|
break;
|
|
|
|
case OPT_NOTHALTCPU:
|
|
|
|
nothaltcpu = 1;
|
|
|
|
break;
|
1997-09-02 06:37:48 +00:00
|
|
|
case OPT_NONE:
|
|
|
|
break;
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enable_apm(int dh)
|
|
|
|
{
|
1997-09-02 06:37:48 +00:00
|
|
|
if (ioctl(dh, APMIO_ENABLE, NULL) == -1)
|
|
|
|
errx(1, "can't ioctl APMIO_ENABLE");
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
disable_apm(int dh)
|
|
|
|
{
|
1997-09-02 06:37:48 +00:00
|
|
|
if (ioctl(dh, APMIO_DISABLE, NULL) == -1)
|
|
|
|
errx(1, "can't ioctl APMIO_DISABLE");
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
haltcpu_apm(int dh)
|
|
|
|
{
|
1997-09-02 06:37:48 +00:00
|
|
|
if (ioctl(dh, APMIO_HALTCPU, NULL) == -1)
|
|
|
|
errx(1, "can't ioctl APMIO_HALTCPU");
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nothaltcpu_apm(int dh)
|
|
|
|
{
|
1997-09-02 06:37:48 +00:00
|
|
|
if (ioctl(dh, APMIO_NOTHALTCPU, NULL) == -1)
|
|
|
|
errx(1, "can't ioctl APMIO_NOTHALTCPU");
|
1994-10-01 03:23:33 +00:00
|
|
|
}
|
1997-09-02 06:37:48 +00:00
|
|
|
|
1995-05-30 03:57:47 +00:00
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
1994-10-01 03:23:33 +00:00
|
|
|
{
|
1997-09-02 06:37:48 +00:00
|
|
|
int dh;
|
1994-10-01 03:23:33 +00:00
|
|
|
|
|
|
|
main_argc = argc;
|
|
|
|
main_argv = argv;
|
1997-09-02 06:37:48 +00:00
|
|
|
if ((dh = open(APMDEV, O_RDWR)) == -1)
|
|
|
|
errx(1, "can't open '%s'", APMDEV);
|
1994-10-01 03:23:33 +00:00
|
|
|
parse_option();
|
|
|
|
|
|
|
|
/* disable operation is executed first */
|
|
|
|
if (disable) {
|
|
|
|
disable_apm(dh);
|
|
|
|
}
|
|
|
|
if (haltcpu) {
|
|
|
|
haltcpu_apm(dh);
|
|
|
|
}
|
|
|
|
if (nothaltcpu) {
|
|
|
|
nothaltcpu_apm(dh);
|
|
|
|
}
|
|
|
|
/* enable operation is executed last */
|
|
|
|
if (enable) {
|
|
|
|
enable_apm(dh);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|