smapi.c revision 109463
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: head/sys/i386/bios/smapi.c 109463 2003-01-18 04:36:12Z mdodd $
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
44u_long smapi32_offset;
45u_short smapi32_segment;
46#define	SMAPI32_SEGMENT	0x18
47
48devclass_t smapi_devclass;
49
50static d_open_t smapi_open;
51static d_close_t smapi_close;
52static d_ioctl_t smapi_ioctl;
53
54#define CDEV_MAJOR	183
55
56static struct cdevsw smapi_cdevsw = {
57	/* open */	smapi_open,
58	/* close */	smapi_close,
59	/* read */	noread,
60	/* write */	nowrite,
61	/* ioctl */	smapi_ioctl,
62	/* poll */	nopoll,
63	/* mmap */	nommap,
64	/* strategy */	nostrategy,
65	/* name */	"smapi",
66	/* maj */	CDEV_MAJOR,
67	/* dump */	nodump,
68	/* psize */	nopsize,
69	/* flags */	D_MEM,
70	/* kqfilter */	NULL,
71};
72
73static int
74smapi_open (dev, oflags, devtype, td)
75	dev_t		dev;
76	int		oflags;
77	int		devtype;
78	d_thread_t *	td;
79{
80
81	return (0);
82}
83
84static int
85smapi_close (dev, fflag, devtype, td)
86	dev_t		dev;
87	int		fflag;
88	int		devtype;
89	d_thread_t *	td;
90{
91
92	return (0);
93}
94
95static int
96smapi_ioctl (dev, cmd, data, fflag, td)
97	dev_t		dev;
98	u_long		cmd;
99	caddr_t		data;
100	int		fflag;
101	d_thread_t *	td;
102{
103	struct smapi_softc *sc;
104	int error;
105
106	error = 0;
107	sc = devclass_get_softc(smapi_devclass, minor(dev));
108        if (sc == NULL) {
109                error = ENXIO;
110                goto fail;
111        }
112
113	switch (cmd) {
114	case SMAPIOGHEADER:
115		bcopy((caddr_t)sc->header, data,
116				sizeof(struct smapi_bios_header));
117		error = 0;
118		break;
119	case SMAPIOCGFUNCTION:
120#if 1
121		smapi32_segment = SMAPI32_SEGMENT;
122		smapi32_offset = sc->smapi32_entry;
123		error = smapi32(
124#else
125		error = smapi32_new(sc->smapi32_entry, SMAPI32_SEGMENT,
126#endif
127				(struct smapi_bios_parameter *)data,
128				(struct smapi_bios_parameter *)data);
129		break;
130	default:
131		error = ENOTTY;
132	}
133
134fail:
135	return (error);
136}
137
138int
139smapi_attach (struct smapi_softc *sc)
140{
141
142	sc->cdev = make_dev(&smapi_cdevsw,
143			device_get_unit(sc->dev),
144			UID_ROOT, GID_WHEEL, 0600,
145			"%s%d",
146			smapi_cdevsw.d_name,
147			device_get_unit(sc->dev));
148
149	return (0);
150}
151
152int
153smapi_detach (struct smapi_softc *sc)
154{
155
156	destroy_dev(sc->cdev);
157	return (0);
158}
159