Deleted Added
full compact
smapi.c (109463) smapi.c (111815)
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 *
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 $
26 * $FreeBSD: head/sys/i386/bios/smapi.c 111815 2003-03-03 12:15:54Z phk $
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 = {
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,
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,
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}
63};
64
65static int
66smapi_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
76static int
77smapi_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
87static int
88smapi_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
126fail:
127 return (error);
128}
129
130int
131smapi_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
144int
145smapi_detach (struct smapi_softc *sc)
146{
147
148 destroy_dev(sc->cdev);
149 return (0);
150}