1 /*- 2 * Copyright (c) 2003 Matthew N. Dodd <winter@jurai.net> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/kernel.h> 32 33 #include <sys/module.h> 34 #include <sys/bus.h> 35 #include <sys/conf.h> 36 37 #include <machine/bus.h> 38 #include <machine/resource.h> 39 #include <sys/rman.h> 40 41 #include <machine/smapi.h> 42 #include <i386/smapi/smapi_var.h> 43 44 u_long smapi32_offset; 45 u_short smapi32_segment; 46 #define SMAPI32_SEGMENT 0x18 47 48 devclass_t smapi_devclass; 49 50 static d_open_t smapi_open; 51 static d_close_t smapi_close; 52 static d_ioctl_t smapi_ioctl; 53 54 #define CDEV_MAJOR 183 55 56 static struct cdevsw smapi_cdevsw = { 57 .d_open = smapi_open, 58 .d_close = smapi_close, 59 .d_ioctl = smapi_ioctl, 60 .d_name = "smapi", 61 .d_maj = CDEV_MAJOR, 62 .d_flags = D_MEM, 63 }; 64 65 static int 66 smapi_open (dev, oflags, devtype, td) 67 dev_t dev; 68 int oflags; 69 int devtype; 70 d_thread_t * td; 71 { 72 73 return (0); 74 } 75 76 static int 77 smapi_close (dev, fflag, devtype, td) 78 dev_t dev; 79 int fflag; 80 int devtype; 81 d_thread_t * td; 82 { 83 84 return (0); 85 } 86 87 static int 88 smapi_ioctl (dev, cmd, data, fflag, td) 89 dev_t dev; 90 u_long cmd; 91 caddr_t data; 92 int fflag; 93 d_thread_t * td; 94 { 95 struct smapi_softc *sc; 96 int error; 97 98 error = 0; 99 sc = devclass_get_softc(smapi_devclass, minor(dev)); 100 if (sc == NULL) { 101 error = ENXIO; 102 goto fail; 103 } 104 105 switch (cmd) { 106 case SMAPIOGHEADER: 107 bcopy((caddr_t)sc->header, data, 108 sizeof(struct smapi_bios_header)); 109 error = 0; 110 break; 111 case SMAPIOCGFUNCTION: 112 #if 1 113 smapi32_segment = SMAPI32_SEGMENT; 114 smapi32_offset = sc->smapi32_entry; 115 error = smapi32( 116 #else 117 error = smapi32_new(sc->smapi32_entry, SMAPI32_SEGMENT, 118 #endif 119 (struct smapi_bios_parameter *)data, 120 (struct smapi_bios_parameter *)data); 121 break; 122 default: 123 error = ENOTTY; 124 } 125 126 fail: 127 return (error); 128 } 129 130 int 131 smapi_attach (struct smapi_softc *sc) 132 { 133 134 sc->cdev = make_dev(&smapi_cdevsw, 135 device_get_unit(sc->dev), 136 UID_ROOT, GID_WHEEL, 0600, 137 "%s%d", 138 smapi_cdevsw.d_name, 139 device_get_unit(sc->dev)); 140 141 return (0); 142 } 143 144 int 145 smapi_detach (struct smapi_softc *sc) 146 { 147 148 destroy_dev(sc->cdev); 149 return (0); 150 } 151