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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
|
/* $OpenBSD: pcdisplay.c,v 1.6 2002/03/14 03:16:05 millert Exp $ */
/* $NetBSD: pcdisplay.c,v 1.9.4.1 2000/06/30 16:27:48 simonb Exp $ */
/*
* Copyright (c) 1998
* Matthias Drochner. 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project
* by Matthias Drochner.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <machine/bus.h>
#include <dev/isa/isavar.h>
#include <dev/isa/isareg.h>
#include <dev/ic/mc6845reg.h>
#include <dev/ic/pcdisplayvar.h>
#include <dev/isa/pcdisplayvar.h>
#include <dev/ic/pcdisplay.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
struct pcdisplay_config {
struct pcdisplayscreen pcs;
struct pcdisplay_handle dc_ph;
int mono;
};
struct pcdisplay_softc {
struct device sc_dev;
struct pcdisplay_config *sc_dc;
int nscreens;
};
static int pcdisplayconsole, pcdisplay_console_attached;
static struct pcdisplay_config pcdisplay_console_dc;
int pcdisplay_match(struct device *, void *, void *);
void pcdisplay_attach(struct device *, struct device *, void *);
static int pcdisplay_is_console(bus_space_tag_t);
static int pcdisplay_probe_col(bus_space_tag_t, bus_space_tag_t);
static int pcdisplay_probe_mono(bus_space_tag_t, bus_space_tag_t);
static void pcdisplay_init(struct pcdisplay_config *,
bus_space_tag_t, bus_space_tag_t,
int);
static int pcdisplay_alloc_attr(void *, int, int, int, long *);
struct cfattach pcdisplay_ca = {
sizeof(struct pcdisplay_softc), pcdisplay_match, pcdisplay_attach,
};
const struct wsdisplay_emulops pcdisplay_emulops = {
pcdisplay_cursor,
pcdisplay_mapchar,
pcdisplay_putchar,
pcdisplay_copycols,
pcdisplay_erasecols,
pcdisplay_copyrows,
pcdisplay_eraserows,
pcdisplay_alloc_attr
};
const struct wsscreen_descr pcdisplay_scr = {
"80x25", 80, 25,
&pcdisplay_emulops,
0, 0, /* no font support */
WSSCREEN_REVERSE /* that's minimal... */
};
const struct wsscreen_descr *_pcdisplay_scrlist[] = {
&pcdisplay_scr,
};
const struct wsscreen_list pcdisplay_screenlist = {
sizeof(_pcdisplay_scrlist) / sizeof(struct wsscreen_descr *),
_pcdisplay_scrlist
};
static int pcdisplay_ioctl(void *, u_long, caddr_t, int, struct proc *);
static paddr_t pcdisplay_mmap(void *, off_t, int);
static int pcdisplay_alloc_screen(void *, const struct wsscreen_descr *,
void **, int *, int *, long *);
static void pcdisplay_free_screen(void *, void *);
static int pcdisplay_show_screen(void *, void *, int,
void (*) (void *, int, int), void *);
const struct wsdisplay_accessops pcdisplay_accessops = {
pcdisplay_ioctl,
pcdisplay_mmap,
pcdisplay_alloc_screen,
pcdisplay_free_screen,
pcdisplay_show_screen,
0 /* load_font */
};
static int
pcdisplay_probe_col(iot, memt)
bus_space_tag_t iot, memt;
{
bus_space_handle_t memh, ioh_6845;
u_int16_t oldval, val;
if (bus_space_map(memt, 0xb8000, 0x8000, 0, &memh))
return (0);
oldval = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, 0xa55a);
val = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, oldval);
bus_space_unmap(memt, memh, 0x8000);
if (val != 0xa55a)
return (0);
if (bus_space_map(iot, 0x3d0, 0x10, 0, &ioh_6845))
return (0);
bus_space_unmap(iot, ioh_6845, 0x10);
return (1);
}
static int
pcdisplay_probe_mono(iot, memt)
bus_space_tag_t iot, memt;
{
bus_space_handle_t memh, ioh_6845;
u_int16_t oldval, val;
if (bus_space_map(memt, 0xb0000, 0x8000, 0, &memh))
return (0);
oldval = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, 0xa55a);
val = bus_space_read_2(memt, memh, 0);
bus_space_write_2(memt, memh, 0, oldval);
bus_space_unmap(memt, memh, 0x8000);
if (val != 0xa55a)
return (0);
if (bus_space_map(iot, 0x3b0, 0x10, 0, &ioh_6845))
return (0);
bus_space_unmap(iot, ioh_6845, 0x10);
return (1);
}
static void
pcdisplay_init(dc, iot, memt, mono)
struct pcdisplay_config *dc;
bus_space_tag_t iot, memt;
int mono;
{
struct pcdisplay_handle *ph = &dc->dc_ph;
int cpos;
ph->ph_iot = iot;
ph->ph_memt = memt;
dc->mono = mono;
if (bus_space_map(memt, mono ? 0xb0000 : 0xb8000, 0x8000,
0, &ph->ph_memh))
panic("pcdisplay_init: cannot map memory");
if (bus_space_map(iot, mono ? 0x3b0 : 0x3d0, 0x10,
0, &ph->ph_ioh_6845))
panic("pcdisplay_init: cannot map io");
/*
* initialize the only screen
*/
dc->pcs.hdl = ph;
dc->pcs.type = &pcdisplay_scr;
dc->pcs.active = 1;
dc->pcs.mem = NULL;
cpos = pcdisplay_6845_read(ph, cursorh) << 8;
cpos |= pcdisplay_6845_read(ph, cursorl);
/* make sure we have a valid cursor position */
if (cpos < 0 || cpos >= pcdisplay_scr.nrows * pcdisplay_scr.ncols)
cpos = 0;
dc->pcs.dispoffset = 0;
dc->pcs.visibleoffset = 0;
dc->pcs.vc_crow = cpos / pcdisplay_scr.ncols;
dc->pcs.vc_ccol = cpos % pcdisplay_scr.ncols;
pcdisplay_cursor_init(&dc->pcs, 1);
}
int
pcdisplay_match(parent, match, aux)
struct device *parent;
void *match;
void *aux;
{
struct isa_attach_args *ia = aux;
int mono;
/* If values are hardwired to something that they can't be, punt. */
if ((ia->ia_iobase != IOBASEUNK &&
ia->ia_iobase != 0x3d0 &&
ia->ia_iobase != 0x3b0) ||
/* ia->ia_iosize != 0 || XXX isa.c */
(ia->ia_maddr != MADDRUNK &&
ia->ia_maddr != 0xb8000 &&
ia->ia_maddr != 0xb0000) ||
(ia->ia_msize != 0 && ia->ia_msize != 0x8000) ||
ia->ia_irq != IRQUNK || ia->ia_drq != DRQUNK)
return (0);
if (pcdisplay_is_console(ia->ia_iot))
mono = pcdisplay_console_dc.mono;
else if (ia->ia_iobase != 0x3b0 && ia->ia_maddr != 0xb0000 &&
pcdisplay_probe_col(ia->ia_iot, ia->ia_memt))
mono = 0;
else if (ia->ia_iobase != 0x3d0 && ia->ia_maddr != 0xb8000 &&
pcdisplay_probe_mono(ia->ia_iot, ia->ia_memt))
mono = 1;
else
return (0);
ia->ia_iobase = mono ? 0x3b0 : 0x3d0;
ia->ia_iosize = 0x10;
ia->ia_maddr = mono ? 0xb0000 : 0xb8000;
ia->ia_msize = 0x8000;
return (1);
}
void
pcdisplay_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct isa_attach_args *ia = aux;
struct pcdisplay_softc *sc = (struct pcdisplay_softc *)self;
int console;
struct pcdisplay_config *dc;
struct wsemuldisplaydev_attach_args aa;
printf("\n");
console = pcdisplay_is_console(ia->ia_iot);
if (console) {
dc = &pcdisplay_console_dc;
sc->nscreens = 1;
pcdisplay_console_attached = 1;
} else {
dc = malloc(sizeof(struct pcdisplay_config),
M_DEVBUF, M_WAITOK);
if (ia->ia_iobase != 0x3b0 && ia->ia_maddr != 0xb0000 &&
pcdisplay_probe_col(ia->ia_iot, ia->ia_memt))
pcdisplay_init(dc, ia->ia_iot, ia->ia_memt, 0);
else if (ia->ia_iobase != 0x3d0 && ia->ia_maddr != 0xb8000 &&
pcdisplay_probe_mono(ia->ia_iot, ia->ia_memt))
pcdisplay_init(dc, ia->ia_iot, ia->ia_memt, 1);
else
panic("pcdisplay_attach: display disappeared");
}
sc->sc_dc = dc;
aa.console = console;
aa.scrdata = &pcdisplay_screenlist;
aa.accessops = &pcdisplay_accessops;
aa.accesscookie = sc;
config_found(self, &aa, wsemuldisplaydevprint);
}
int
pcdisplay_cnattach(iot, memt)
bus_space_tag_t iot, memt;
{
int mono;
if (pcdisplay_probe_col(iot, memt))
mono = 0;
else if (pcdisplay_probe_mono(iot, memt))
mono = 1;
else
return (ENXIO);
pcdisplay_init(&pcdisplay_console_dc, iot, memt, mono);
wsdisplay_cnattach(&pcdisplay_scr, &pcdisplay_console_dc,
pcdisplay_console_dc.pcs.vc_ccol,
pcdisplay_console_dc.pcs.vc_crow,
FG_LIGHTGREY | BG_BLACK);
pcdisplayconsole = 1;
return (0);
}
static int
pcdisplay_is_console(iot)
bus_space_tag_t iot;
{
if (pcdisplayconsole &&
!pcdisplay_console_attached &&
iot == pcdisplay_console_dc.dc_ph.ph_iot)
return (1);
return (0);
}
static int
pcdisplay_ioctl(v, cmd, data, flag, p)
void *v;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
/*
* XXX "do something!"
*/
return (-1);
}
static paddr_t
pcdisplay_mmap(v, offset, prot)
void *v;
off_t offset;
int prot;
{
return (-1);
}
static int
pcdisplay_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
void *v;
const struct wsscreen_descr *type;
void **cookiep;
int *curxp, *curyp;
long *defattrp;
{
struct pcdisplay_softc *sc = v;
if (sc->nscreens > 0)
return (ENOMEM);
*cookiep = sc->sc_dc;
*curxp = 0;
*curyp = 0;
*defattrp = FG_LIGHTGREY | BG_BLACK;
sc->nscreens++;
return (0);
}
static void
pcdisplay_free_screen(v, cookie)
void *v;
void *cookie;
{
struct pcdisplay_softc *sc = v;
if (sc->sc_dc == &pcdisplay_console_dc)
panic("pcdisplay_free_screen: console");
sc->nscreens--;
}
static int
pcdisplay_show_screen(v, cookie, waitok, cb, cbarg)
void *v;
void *cookie;
int waitok;
void (*cb)(void *, int, int);
void *cbarg;
{
#ifdef DIAGNOSTIC
struct pcdisplay_softc *sc = v;
if (cookie != sc->sc_dc)
panic("pcdisplay_show_screen: bad screen");
#endif
return (0);
}
static int
pcdisplay_alloc_attr(id, fg, bg, flags, attrp)
void *id;
int fg, bg;
int flags;
long *attrp;
{
if (flags & WSATTR_REVERSE)
*attrp = FG_BLACK | BG_LIGHTGREY;
else
*attrp = FG_LIGHTGREY | BG_BLACK;
return (0);
}
struct cfdriver pcdisplay_cd = {
NULL, "pcdisplay", DV_DULL
};
|