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
|
/*
* Mach Operating System
* Copyright (c) 1993-1990 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* Parallel port printer driver v1.0
* All rights reserved.
*/
#include <lpr.h>
#if NLPR > 0
#include <par.h>
#ifdef MACH_KERNEL
#include <mach/std_types.h>
#include <sys/types.h>
#include <sys/time.h>
#include <device/conf.h>
#include <device/errno.h>
#include <device/tty.h>
#include <device/io_req.h>
#else MACH_KERNEL
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/systm.h>
#include <sys/uio.h>
#include <sys/file.h>
#endif MACH_KERNEL
#include <i386/ipl.h>
#include <i386/pio.h>
#include <chips/busses.h>
#include <i386at/lprreg.h>
#if NPAR > 0
extern int parattach();
#endif
extern void splx();
extern spl_t spltty();
extern void timeout();
extern void ttrstrt();
/*
* Driver information for auto-configuration stuff.
*/
int lprprobe(), lprintr(), lprstart(), lprstop();
void lprattach(struct bus_device *);
#ifdef MACH_KERNEL
int lprstop(), lprgetstat(), lprsetstat();
#endif MACH_KERNEL
struct bus_device *lprinfo[NLPR]; /* ??? */
static vm_offset_t lpr_std[NLPR] = { 0 };
static struct bus_device *lpr_info[NLPR];
struct bus_driver lprdriver = {
lprprobe, 0, lprattach, 0, lpr_std, "lpr", lpr_info, 0, 0, 0};
struct tty lpr_tty[NLPR];
int lpr_alive[NLPR];
lprprobe(port, dev)
struct bus_device *dev;
{
u_short addr = (u_short) dev->address;
int unit = dev->unit;
int ret;
if ((unit < 0) || (unit > NLPR)) {
printf("com %d out of range\n", unit);
return(0);
}
outb(INTR_ENAB(addr),0x07);
outb(DATA(addr),0xaa);
ret = inb(DATA(addr)) == 0xaa;
if (ret) {
if (lpr_alive[unit]) {
printf("lpr: Multiple alive entries for unit %d.\n", unit);
printf("lpr: Ignoring entry with address = %x .\n", addr);
ret = 0;
} else
lpr_alive[unit]++;
}
return(ret);
}
void lprattach(struct bus_device *dev)
{
u_char unit = dev->unit;
u_short addr = (u_short) dev->address;
struct tty *tp = &lpr_tty[unit];
take_dev_irq(dev);
printf(", port = %x, spl = %d, pic = %d.",
dev->address, dev->sysdep, dev->sysdep1);
lprinfo[unit] = dev;
outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
#if NPAR > 0
parattach(dev);
#endif
return;
}
lpropen(dev, flag, ior)
int dev;
int flag;
#ifdef MACH_KERNEL
io_req_t ior;
#endif MACH_KERNEL
{
int unit = minor(dev);
struct bus_device *isai;
struct tty *tp;
u_short addr;
if (unit >= NLPR || (isai = lprinfo[unit]) == 0 || isai->alive == 0)
return(ENXIO);
tp = &lpr_tty[unit];
#ifndef MACH_KERNEL
if (tp->t_state & TS_XCLUDE && u.u_uid != 0)
return(EBUSY);
#endif MACH_KERNEL
addr = (u_short) isai->address;
tp->t_dev = dev;
tp->t_addr = *(caddr_t *)&addr;
tp->t_oproc = lprstart;
tp->t_state |= TS_WOPEN;
#ifdef MACH_KERNEL
tp->t_stop = lprstop;
tp->t_getstat = lprgetstat;
tp->t_setstat = lprsetstat;
#endif MACH_KERNEL
if ((tp->t_state & TS_ISOPEN) == 0)
ttychars(tp);
outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) | 0x10);
tp->t_state |= TS_CARR_ON;
return (char_open(dev, tp, flag, ior));
}
lprclose(dev, flag)
int dev;
int flag;
{
int unit = minor(dev);
struct tty *tp = &lpr_tty[unit];
u_short addr = (u_short) lprinfo[unit]->address;
#ifndef MACH_KERNEL
(*linesw[tp->t_line].l_close)(tp);
#endif MACH_KERNEL
ttyclose(tp);
if (tp->t_state&TS_HUPCLS || (tp->t_state&TS_ISOPEN)==0) {
outb(INTR_ENAB(addr), inb(INTR_ENAB(addr)) & 0x0f);
tp->t_state &= ~TS_BUSY;
}
}
#ifdef MACH_KERNEL
lprread(dev, ior)
int dev;
io_req_t ior;
{
return char_read(&lpr_tty[minor(dev)], ior);
}
lprwrite(dev, ior)
int dev;
io_req_t ior;
{
return char_write(&lpr_tty[minor(dev)], ior);
}
lprportdeath(dev, port)
dev_t dev;
mach_port_t port;
{
return (tty_portdeath(&lpr_tty[minor(dev)], port));
}
io_return_t
lprgetstat(dev, flavor, data, count)
dev_t dev;
int flavor;
int *data; /* pointer to OUT array */
unsigned int *count; /* out */
{
io_return_t result = D_SUCCESS;
int unit = minor(dev);
switch (flavor) {
default:
result = tty_get_status(&lpr_tty[unit], flavor, data, count);
break;
}
return (result);
}
io_return_t
lprsetstat(dev, flavor, data, count)
dev_t dev;
int flavor;
int * data;
unsigned int count;
{
io_return_t result = D_SUCCESS;
int unit = minor(dev);
u_short dev_addr = (u_short) lprinfo[unit]->address;
int s;
switch (flavor) {
default:
result = tty_set_status(&lpr_tty[unit], flavor, data, count);
/* if (result == D_SUCCESS && flavor == TTY_STATUS)
lprparam(unit);
*/ return (result);
}
return (D_SUCCESS);
}
#else MACH_KERNEL
int lprwrite(dev, uio)
int dev;
struct uio *uio;
{
struct tty *tp= &lpr_tty[minor(dev)];
return ((*linesw[tp->t_line].l_write)(tp, uio));
}
int lprioctl(dev, cmd, addr, mode)
int dev;
int cmd;
caddr_t addr;
int mode;
{
int error;
spl_t s;
int unit = minor(dev);
struct tty *tp = &lpr_tty[unit];
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr,mode);
if (error >= 0)
return(error);
error = ttioctl(tp, cmd, addr,mode);
if (error >= 0)
return (error);
s = spltty();
switch (cmd) {
default:
splx(s);
return(ENOTTY);
}
splx(s);
return(0);
}
#endif MACH_KERNEL
int lprintr(unit)
int unit;
{
register struct tty *tp = &lpr_tty[unit];
if ((tp->t_state & TS_ISOPEN) == 0)
return;
tp->t_state &= ~TS_BUSY;
if (tp->t_state&TS_FLUSH)
tp->t_state &=~TS_FLUSH;
tt_write_wakeup(tp);
lprstart(tp);
}
int lprstart(tp)
struct tty *tp;
{
spl_t s = spltty();
u_short addr = (natural_t) tp->t_addr;
int status = inb(STATUS(addr));
char nch;
if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP|TS_BUSY)) {
splx(s);
return(0);
}
if (status & 0x20) {
printf("Printer out of paper!\n");
splx(s);
return(0);
}
if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
#ifdef MACH_KERNEL
tt_write_wakeup(tp);
#else MACH_KERNEL
if (tp->t_state & TS_ASLEEP) {
tp->t_state &= ~TS_ASLEEP;
wakeup ((caddr_t)&tp->t_outq);
}
if (tp->t_wsel) {
selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
tp->t_wsel = 0;
tp->t_state &= ~TS_WCOLL;
}
#endif MACH_KERNEL
}
if (tp->t_outq.c_cc == 0) {
splx(s);
return(0);
}
#ifdef MACH_KERNEL
nch = getc(&tp->t_outq);
if ((tp->t_flags & LITOUT) == 0 && (nch & 0200)) {
timeout(ttrstrt, (char *)tp, (nch & 0x7f) + 6);
tp->t_state |= TS_TIMEOUT;
return;
}
outb(DATA(addr), nch);
outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) | 0x01);
outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) & 0x1e);
tp->t_state |= TS_BUSY;
#else MACH_KERNEL
if (tp->t_flags & (RAW|LITOUT))
nch = ndqb(&tp->t_outq,0);
else {
nch = ndqb(&tp->t_outq, 0200);
if (nch == 0) {
nch = getc(&tp->t_outq);
timeout(ttrstrt,(caddr_t)tp,(nch&0x7f)+6);
tp->t_state |= TS_TIMEOUT;
splx(s);
return(0);
}
}
if (nch) {
nch=getc(&tp->t_outq);
outb(DATA(addr), nch);
outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) | 0x01);
outb(INTR_ENAB(addr),inb(INTR_ENAB(addr)) & 0x1e);
tp->t_state |= TS_BUSY;
}
#endif MACH_KERNEL
splx(s);
return(0);
}
#ifdef MACH_KERNEL
lprstop(tp, flags)
register struct tty *tp;
int flags;
{
if ((tp->t_state & TS_BUSY) && (tp->t_state & TS_TTSTOP) == 0)
tp->t_state |= TS_FLUSH;
}
#else MACH_KERNEL
int lprstop(tp, flag)
struct tty *tp;
{
int s = spltty();
if ((tp->t_state&TS_BUSY) && (!(tp->t_state&TS_TTSTOP)))
tp->t_state |= TS_FLUSH;
splx(s);
}
#endif MACH_KERNEL
lprpr(unit)
{
lprpr_addr(lprinfo[unit]->address);
return 0;
}
lprpr_addr(addr)
{
printf("DATA(%x) %x, STATUS(%x) %x, INTR_ENAB(%x) %x\n",
DATA(addr), inb(DATA(addr)),
STATUS(addr), inb(STATUS(addr)),
INTR_ENAB(addr), inb(INTR_ENAB(addr)));
}
#endif NLPR
|