1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/* $OpenBSD: pcex.c,v 1.1 2014/12/19 13:17:35 aoyama Exp $ */
/*
* Copyright (c) 2014 Kenji Aoyama.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* PC-9801 extension board slot direct access driver for LUNA-88K2.
*/
#include <sys/param.h>
#include <sys/systm.h> /* tsleep()/wakeup() */
#include <sys/device.h>
#include <sys/ioctl.h>
#include <machine/autoconf.h>
#include <machine/board.h> /* PC_BASE */
#include <machine/conf.h>
#include <machine/pcex.h>
#include <luna88k/cbus/cbusvar.h>
extern int hz;
#if 0
#define PCEX_DEBUG
#endif
#define PCEXMEM_BASE PC_BASE
#define PCEXIO_BASE (PC_BASE + 0x1000000)
/* autoconf stuff */
int pcex_match(struct device *, void *, void *);
void pcex_attach(struct device *, struct device *, void *);
struct pcex_softc {
struct device sc_dev;
int intr_use[NCBUSISR];
};
const struct cfattach pcex_ca = {
sizeof(struct pcex_softc), pcex_match, pcex_attach
};
struct cfdriver pcex_cd = {
NULL, "pcex", DV_DULL
};
/* prototypes */
int pcex_intr(void *);
int pcex_set_int(struct pcex_softc *, u_int);
int pcex_reset_int(struct pcex_softc *, u_int);
int pcex_wait_int(struct pcex_softc *, u_int);
int
pcex_match(struct device *parent, void *cf, void *aux)
{
return 1; /* XXX: always matched */
}
void
pcex_attach(struct device *parent, struct device *self, void *args)
{
struct pcex_softc *sc = (struct pcex_softc *)self;
int i;
for (i = 0; i < NCBUSISR; i++)
sc->intr_use[i] = 0;
printf("\n");
return;
}
int
pcexopen(dev_t dev, int flag, int mode, struct proc *p)
{
switch (minor(dev)) {
case 0: /* memory area */
case 1: /* I/O port area */
return 0;
default:
return ENXIO;
}
}
int
pcexclose(dev_t dev, int flag, int mode, struct proc *p)
{
return (0);
}
paddr_t
pcexmmap(dev_t dev, off_t offset, int prot)
{
paddr_t cookie = -1;
switch (minor(dev)) {
case 0: /* memory area */
if (offset >= 0 && offset < 0x1000000)
cookie = (paddr_t)(PCEXMEM_BASE + offset);
break;
case 1: /* I/O port area */
if (offset >= 0 && offset < 0x10000)
cookie = (paddr_t)(PCEXIO_BASE + offset);
break;
default:
break;
}
return cookie;
}
int
pcexioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
{
struct pcex_softc *sc = NULL;
u_int level;
if (pcex_cd.cd_ndevs != 0)
sc = pcex_cd.cd_devs[0];
if (sc == NULL)
return ENXIO;
level = *(u_int *)data;
switch(cmd) {
case PCEXSETLEVEL:
return pcex_set_int(sc, level);
case PCEXRESETLEVEL:
return pcex_reset_int(sc, level);
case PCEXWAITINT:
return pcex_wait_int(sc, level);
default:
return ENOTTY;
}
}
int
pcex_set_int(struct pcex_softc *sc, u_int level)
{
if (level > 6)
return EINVAL;
if (sc->intr_use[level] != 0)
return EINVAL; /* Duplicate */
sc->intr_use[level] = 1;
cbus_isrlink(pcex_intr, &(sc->intr_use[level]), level,
sc->sc_dev.dv_xname);
return 0;
}
int
pcex_reset_int(struct pcex_softc *sc, u_int level)
{
if (level > 6)
return EINVAL;
if (sc->intr_use[level] == 0)
return EINVAL; /* Not registered */
sc->intr_use[level] = 0;
cbus_isrunlink(pcex_intr, level);
return 0;
}
int
pcex_wait_int(struct pcex_softc *sc, u_int level)
{
int ret;
if (level > 6)
return EINVAL;
if (sc->intr_use[level] == 0)
return EINVAL; /* Not registered */
ret = tsleep(&(sc->intr_use[level]), PWAIT | PCATCH, "pcex",
hz /* XXX: 1 sec. */);
#ifdef PCEX_DEBUG
if (ret == EWOULDBLOCK)
printf("pcex_wait_int: timeout in tsleep\n");
#endif
return ret;
}
int
pcex_intr(void *arg)
{
#ifdef PCEX_DEBUG
printf("pcex_intr: called, arg=%p\n", arg);
#endif
/* Just wakeup(9) for now */
wakeup(arg);
return 1;
}
|