From 7534ac7ab77288e2ea1532970bb8264e43dd3631 Mon Sep 17 00:00:00 2001 From: "Matthew N. Dodd" Date: Fri, 17 Jan 2003 08:10:18 +0000 Subject: A driver for the System Management Application Program Interface (SMAPI) BIOS, which is present on some IBM Thinkpad models (560, 600, 770 to name a few.) The SMAPI BIOS provides access to System Information, System Configuration, and Power Management. --- sys/i386/bios/smapi.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 sys/i386/bios/smapi.c (limited to 'sys/i386/bios/smapi.c') diff --git a/sys/i386/bios/smapi.c b/sys/i386/bios/smapi.c new file mode 100644 index 000000000000..e2e96adf4f11 --- /dev/null +++ b/sys/i386/bios/smapi.c @@ -0,0 +1,167 @@ +/*- + * Copyright (c) 2003 Matthew N. Dodd + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +u_long smapi32_offset; +u_short smapi32_segment; +#define SMAPI32_SEGMENT 0x18 + +devclass_t smapi_devclass; + +static d_open_t smapi_open; +static d_close_t smapi_close; +static d_ioctl_t smapi_ioctl; + +#define CDEV_MAJOR 183 + +static struct cdevsw smapi_cdevsw = { + /* open */ smapi_open, + /* close */ smapi_close, + /* read */ noread, + /* write */ nowrite, + /* ioctl */ smapi_ioctl, + /* poll */ nopoll, + /* mmap */ nommap, + /* strategy */ nostrategy, + /* name */ "smapi", + /* maj */ CDEV_MAJOR, + /* dump */ nodump, + /* psize */ nopsize, + /* flags */ D_MEM, + /* kqfilter */ NULL, +}; + +static int +smapi_open (dev, oflags, devtype, td) + dev_t dev; + int oflags; + int devtype; + d_thread_t * td; +{ + + return (0); +} + +static int +smapi_close (dev, fflag, devtype, td) + dev_t dev; + int fflag; + int devtype; + d_thread_t * td; +{ + + return (0); +} + +static int +smapi_ioctl (dev, cmd, data, fflag, td) + dev_t dev; + u_long cmd; + caddr_t data; + int fflag; + d_thread_t * td; +{ + struct smapi_softc *sc; + int error; + + error = 0; + sc = devclass_get_softc(smapi_devclass, minor(dev)); + if (sc == NULL) { + error = ENXIO; + goto fail; + } + + switch (cmd) { + case SMAPIOGHEADER: + bcopy((caddr_t)sc->header, data, + sizeof(struct smapi_bios_header)); + error = 0; + break; + case SMAPIOCGFUNCTION: + smapi32_segment = SMAPI32_SEGMENT; + smapi32_offset = sc->smapi32_entry; + error = smapi32((struct smapi_bios_parameter *)data, + (struct smapi_bios_parameter *)data); + break; + default: + error = ENOTTY; + } + +fail: + return (error); +} + +int +smapi_attach (struct smapi_softc *sc) +{ + struct smapi_bios_parameter input_param; + struct smapi_bios_parameter output_param; + int retval; + + sc->cdev = make_dev(&smapi_cdevsw, + device_get_unit(sc->dev), + UID_ROOT, GID_WHEEL, 0600, + "%s%d", + smapi_cdevsw.d_name, + device_get_unit(sc->dev)); + + bzero(&input_param, sizeof(struct smapi_bios_parameter)); + bzero(&output_param, sizeof(struct smapi_bios_parameter)); + smapi32_segment = SMAPI32_SEGMENT; + smapi32_offset = sc->smapi32_entry; + retval = smapi32(&output_param, &output_param); + +#if 0 + retval = smapi32_new(sc->smapi32_entry, SMAPI32_SEGMENT, + &output_param, &output_param); +#endif + + return (0); +} + +int +smapi_detach (struct smapi_softc *sc) +{ + + destroy_dev(sc->cdev); + return (0); +} -- cgit v1.2.3