1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990 William F. Jolitz, TeleMuse
|
|
|
|
* 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:
|
1995-05-30 08:16:23 +00:00
|
|
|
* This software is a component of "386BSD" developed by
|
1993-06-12 14:58:17 +00:00
|
|
|
* William F. Jolitz, TeleMuse.
|
|
|
|
* 4. Neither the name of the developer nor the name "386BSD"
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
1995-05-30 08:16:23 +00:00
|
|
|
* THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
|
|
|
|
* AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
|
|
|
|
* SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
|
|
|
|
* THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
|
1993-06-12 14:58:17 +00:00
|
|
|
* NOT MAKE USE OF THIS WORK.
|
|
|
|
*
|
|
|
|
* FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
|
1995-05-30 08:16:23 +00:00
|
|
|
* BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
|
|
|
|
* REFERENCES SUCH AS THE "PORTING UNIX TO THE 386" SERIES
|
|
|
|
* (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
|
|
|
|
* JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
|
|
|
|
* LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
|
|
|
|
* ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
|
1993-06-12 14:58:17 +00:00
|
|
|
* OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``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 DEVELOPER 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.
|
|
|
|
*
|
1993-10-16 13:48:52 +00:00
|
|
|
* from: unknown origin, 386BSD 0.1
|
1998-12-10 01:42:32 +00:00
|
|
|
* $Id: lpt.c,v 1.71 1998/10/22 05:58:39 bde Exp $
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device Driver for AT parallel printer port
|
|
|
|
* Written by William Jolitz 12/18/90
|
|
|
|
*/
|
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
/*
|
|
|
|
* Parallel port TCP/IP interfaces added. I looked at the driver from
|
|
|
|
* MACH but this is a complete rewrite, and btw. incompatible, and it
|
|
|
|
* should perform better too. I have never run the MACH driver though.
|
|
|
|
*
|
|
|
|
* This driver sends two bytes (0x08, 0x00) in front of each packet,
|
|
|
|
* to allow us to distinguish another format later.
|
|
|
|
*
|
1995-12-02 20:33:40 +00:00
|
|
|
* Now added an Linux/Crynwr compatibility mode which is enabled using
|
|
|
|
* IF_LINK0 - Tim Wilkinson.
|
|
|
|
*
|
1994-08-13 00:37:03 +00:00
|
|
|
* TODO:
|
|
|
|
* Make HDLC/PPP mode, use IF_LLC1 to enable.
|
|
|
|
*
|
|
|
|
* Connect the two computers using a Laplink parallel cable to use this
|
|
|
|
* feature:
|
|
|
|
*
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |A-name A-End B-End Descr. Port/Bit |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |DATA0 2 15 Data 0/0x01 |
|
|
|
|
* |-ERROR 15 2 1/0x08 |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |DATA1 3 13 Data 0/0x02 |
|
|
|
|
* |+SLCT 13 3 1/0x10 |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |DATA2 4 12 Data 0/0x04 |
|
|
|
|
* |+PE 12 4 1/0x20 |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |DATA3 5 10 Strobe 0/0x08 |
|
|
|
|
* |-ACK 10 5 1/0x40 |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |DATA4 6 11 Data 0/0x10 |
|
|
|
|
* |BUSY 11 6 1/~0x80 |
|
|
|
|
* +----------------------------------------+
|
|
|
|
* |GND 18-25 18-25 GND - |
|
|
|
|
* +----------------------------------------+
|
|
|
|
*
|
|
|
|
* Expect transfer-rates up to 75 kbyte/sec.
|
|
|
|
*
|
|
|
|
* If GCC could correctly grok
|
1995-05-30 08:16:23 +00:00
|
|
|
* register int port asm("edx")
|
1994-08-13 00:37:03 +00:00
|
|
|
* the code would be cleaner
|
|
|
|
*
|
1995-12-02 20:33:40 +00:00
|
|
|
* Poul-Henning Kamp <phk@freebsd.org>
|
1994-08-13 00:37:03 +00:00
|
|
|
*/
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#include "lpt.h"
|
1998-01-24 02:54:56 +00:00
|
|
|
#include "opt_devfs.h"
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_inet.h"
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1995-11-16 09:56:02 +00:00
|
|
|
#include <sys/conf.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/syslog.h>
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
|
|
|
#include <sys/devfsext.h>
|
|
|
|
#endif /*DEVFS*/
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-03-16 18:17:34 +00:00
|
|
|
#include <machine/clock.h>
|
1995-02-26 05:14:53 +00:00
|
|
|
#include <machine/lpt.h>
|
|
|
|
|
1995-12-06 23:52:35 +00:00
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
1995-12-06 23:52:35 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <i386/isa/isa.h>
|
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#include <i386/isa/lptreg.h>
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
1995-09-25 16:57:54 +00:00
|
|
|
#include "bpfilter.h"
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
1994-08-13 00:37:03 +00:00
|
|
|
#endif /* INET */
|
|
|
|
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
#define LPINITRDY 4 /* wait up to 4 seconds for a ready */
|
1996-04-04 12:28:36 +00:00
|
|
|
#define LPTOUTINITIAL 10 /* initial timeout to wait for ready 1/10 s */
|
|
|
|
#define LPTOUTMAX 1 /* maximal timeout 1 s */
|
1993-06-12 14:58:17 +00:00
|
|
|
#define LPPRI (PZERO+8)
|
|
|
|
#define BUFSIZE 1024
|
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
|
|
|
#ifndef LPMTU /* MTU for the lp# interfaces */
|
|
|
|
#define LPMTU 1500
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LPMAXSPIN1 /* DELAY factor for the lp# interfaces */
|
1994-08-14 01:46:28 +00:00
|
|
|
#define LPMAXSPIN1 8000 /* Spinning for remote intr to happen */
|
1994-08-13 00:37:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LPMAXSPIN2 /* DELAY factor for the lp# interfaces */
|
1994-08-14 01:46:28 +00:00
|
|
|
#define LPMAXSPIN2 500 /* Spinning for remote handshake to happen */
|
1994-08-13 00:37:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef LPMAXERRS /* Max errors before !RUNNING */
|
|
|
|
#define LPMAXERRS 100
|
|
|
|
#endif
|
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
#define CLPIPHDRLEN 14 /* We send dummy ethernet addresses (two) + packet type in front of packet */
|
|
|
|
#define CLPIP_SHAKE 0x80 /* This bit toggles between nibble reception */
|
|
|
|
#define MLPIPHDRLEN CLPIPHDRLEN
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
#define LPIPHDRLEN 2 /* We send 0x08, 0x00 in front of packet */
|
|
|
|
#define LPIP_SHAKE 0x40 /* This bit toggles between nibble reception */
|
1995-12-02 20:33:40 +00:00
|
|
|
#if !defined(MLPIPHDRLEN) || LPIPHDRLEN > MLPIPHDRLEN
|
|
|
|
#define MLPIPHDRLEN LPIPHDRLEN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LPIPTBLSIZE 256 /* Size of octet translation table */
|
1994-09-18 06:12:45 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#endif /* INET */
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
/* BIOS printer list - used by BIOS probe*/
|
|
|
|
#define BIOS_LPT_PORTS 0x408
|
|
|
|
#define BIOS_PORTS (short *)(KERNBASE+BIOS_LPT_PORTS)
|
|
|
|
#define BIOS_MAX_LPT 4
|
|
|
|
|
|
|
|
|
1998-02-20 04:19:39 +00:00
|
|
|
#ifndef DEBUG
|
1998-12-10 01:42:32 +00:00
|
|
|
#define lprintf(args)
|
1993-06-12 14:58:17 +00:00
|
|
|
#else
|
1998-12-10 01:42:32 +00:00
|
|
|
#define lprintf(args) do { \
|
|
|
|
if (lptflag) \
|
|
|
|
printf args; \
|
|
|
|
} while (0)
|
1996-07-12 07:41:34 +00:00
|
|
|
static int volatile lptflag = 1;
|
1993-06-12 14:58:17 +00:00
|
|
|
#endif
|
|
|
|
|
1994-02-06 22:06:58 +00:00
|
|
|
#define LPTUNIT(s) ((s)&0x03)
|
|
|
|
#define LPTFLAGS(s) ((s)&0xfc)
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static struct lpt_softc {
|
1996-11-11 16:32:43 +00:00
|
|
|
int sc_port;
|
1993-06-12 14:58:17 +00:00
|
|
|
short sc_state;
|
|
|
|
/* default case: negative prime, negative ack, handshake strobe,
|
|
|
|
prime once */
|
|
|
|
u_char sc_control;
|
1994-02-17 10:20:18 +00:00
|
|
|
char sc_flags;
|
1994-02-06 22:06:58 +00:00
|
|
|
#define LP_POS_INIT 0x04 /* if we are a postive init signal */
|
|
|
|
#define LP_POS_ACK 0x08 /* if we are a positive going ack */
|
|
|
|
#define LP_NO_PRIME 0x10 /* don't prime the printer at all */
|
|
|
|
#define LP_PRIMEOPEN 0x20 /* prime on every open */
|
|
|
|
#define LP_AUTOLF 0x40 /* tell printer to do an automatic lf */
|
|
|
|
#define LP_BYPASS 0x80 /* bypass printer ready checks */
|
1993-06-12 14:58:17 +00:00
|
|
|
struct buf *sc_inbuf;
|
|
|
|
short sc_xfercnt ;
|
|
|
|
char sc_primed;
|
|
|
|
char *sc_cp ;
|
1994-02-17 10:20:18 +00:00
|
|
|
u_char sc_irq ; /* IRQ status of port */
|
|
|
|
#define LP_HAS_IRQ 0x01 /* we have an irq available */
|
|
|
|
#define LP_USE_IRQ 0x02 /* we are using our irq */
|
1994-04-06 16:42:33 +00:00
|
|
|
#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */
|
1996-04-04 12:28:36 +00:00
|
|
|
u_char sc_backoff ; /* time to call lptout() again */
|
1994-04-06 16:42:33 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct ifnet sc_if;
|
1994-09-18 06:12:45 +00:00
|
|
|
u_char *sc_ifbuf;
|
1994-08-13 00:37:03 +00:00
|
|
|
int sc_iferrs;
|
1996-03-29 11:54:56 +00:00
|
|
|
#endif
|
|
|
|
#ifdef DEVFS
|
1995-12-08 11:19:42 +00:00
|
|
|
void *devfs_token;
|
1996-03-29 11:54:56 +00:00
|
|
|
void *devfs_token_ctl;
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1993-06-12 14:58:17 +00:00
|
|
|
} lpt_sc[NLPT] ;
|
|
|
|
|
|
|
|
/* bits for state */
|
|
|
|
#define OPEN (1<<0) /* device is open */
|
|
|
|
#define ASLP (1<<1) /* awaiting draining of printer */
|
|
|
|
#define ERROR (1<<2) /* error was received from printer */
|
|
|
|
#define OBUSY (1<<3) /* printer is busy doing output */
|
1994-02-17 10:20:18 +00:00
|
|
|
#define LPTOUT (1<<4) /* timeout while not selected */
|
|
|
|
#define TOUT (1<<5) /* timeout while not selected */
|
1993-06-12 14:58:17 +00:00
|
|
|
#define INIT (1<<6) /* waiting to initialize for open */
|
1994-02-17 10:20:18 +00:00
|
|
|
#define INTERRUPTED (1<<7) /* write call was interrupted */
|
|
|
|
|
|
|
|
|
|
|
|
/* status masks to interrogate printer status */
|
|
|
|
#define RDY_MASK (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR) /* ready ? */
|
|
|
|
#define LP_READY (LPS_SEL|LPS_NBSY|LPS_NERR)
|
|
|
|
|
|
|
|
/* Printer Ready condition - from lpa.c */
|
|
|
|
/* Only used in polling code */
|
|
|
|
#define LPS_INVERT (LPS_NBSY | LPS_NACK | LPS_SEL | LPS_NERR)
|
|
|
|
#define LPS_MASK (LPS_NBSY | LPS_NACK | LPS_OUT | LPS_SEL | LPS_NERR)
|
|
|
|
#define NOT_READY(x) ((inb(x)^LPS_INVERT)&LPS_MASK)
|
|
|
|
|
|
|
|
#define MAX_SLEEP (hz*5) /* Timeout while waiting for device ready */
|
|
|
|
#define MAX_SPIN 20 /* Max delay for device ready in usecs */
|
|
|
|
|
1997-04-20 15:36:12 +00:00
|
|
|
static timeout_t lptout;
|
1995-11-14 09:58:47 +00:00
|
|
|
static int lptprobe (struct isa_device *dvp);
|
|
|
|
static int lptattach (struct isa_device *isdp);
|
1998-10-22 05:58:45 +00:00
|
|
|
static ointhand2_t lptintr;
|
1994-04-06 16:42:33 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
/* Tables for the lp# interface */
|
1994-09-18 06:12:45 +00:00
|
|
|
static u_char *txmith;
|
1995-05-09 01:33:16 +00:00
|
|
|
#define txmitl (txmith+(1*LPIPTBLSIZE))
|
|
|
|
#define trecvh (txmith+(2*LPIPTBLSIZE))
|
|
|
|
#define trecvl (txmith+(3*LPIPTBLSIZE))
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
static u_char *ctxmith;
|
|
|
|
#define ctxmitl (ctxmith+(1*LPIPTBLSIZE))
|
|
|
|
#define ctrecvh (ctxmith+(2*LPIPTBLSIZE))
|
|
|
|
#define ctrecvl (ctxmith+(3*LPIPTBLSIZE))
|
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
/* Functions for the lp# interface */
|
|
|
|
static void lpattach(struct lpt_softc *,int);
|
1995-11-29 10:17:03 +00:00
|
|
|
static int lpinittables(void);
|
1998-06-07 17:13:14 +00:00
|
|
|
static int lpioctl(struct ifnet *, u_long, caddr_t);
|
1994-08-13 00:37:03 +00:00
|
|
|
static int lpoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
|
|
|
|
struct rtentry *);
|
|
|
|
static void lpintr(int);
|
|
|
|
#endif /* INET */
|
|
|
|
|
1994-04-06 16:42:33 +00:00
|
|
|
struct isa_driver lptdriver = {
|
|
|
|
lptprobe, lptattach, "lpt"
|
|
|
|
};
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t lptopen;
|
|
|
|
static d_close_t lptclose;
|
|
|
|
static d_write_t lptwrite;
|
|
|
|
static d_ioctl_t lptioctl;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 16
|
1995-12-08 23:23:00 +00:00
|
|
|
static struct cdevsw lpt_cdevsw =
|
1995-12-08 11:19:42 +00:00
|
|
|
{ lptopen, lptclose, noread, lptwrite, /*16*/
|
|
|
|
lptioctl, nullstop, nullreset, nodevtotty,/* lpt */
|
|
|
|
seltrue, nommap, nostrat, "lpt", NULL, -1 };
|
|
|
|
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/*
|
|
|
|
* Internal routine to lptprobe to do port tests of one byte value
|
|
|
|
*/
|
1994-04-06 16:42:33 +00:00
|
|
|
static int
|
1996-11-11 16:32:43 +00:00
|
|
|
lpt_port_test (int port, u_char data, u_char mask)
|
1994-02-06 22:06:58 +00:00
|
|
|
{
|
1993-06-12 14:58:17 +00:00
|
|
|
int temp, timeout;
|
|
|
|
|
|
|
|
data = data & mask;
|
|
|
|
outb(port, data);
|
1994-02-17 10:20:18 +00:00
|
|
|
timeout = 10000;
|
|
|
|
do {
|
|
|
|
DELAY(10);
|
1993-06-12 14:58:17 +00:00
|
|
|
temp = inb(port) & mask;
|
1994-02-17 10:20:18 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
while (temp != data && --timeout);
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("Port 0x%x\tout=%x\tin=%x\ttout=%d\n",
|
|
|
|
port, data, temp, timeout));
|
1993-06-12 14:58:17 +00:00
|
|
|
return (temp == data);
|
1994-02-06 22:06:58 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/*
|
1994-02-17 10:20:18 +00:00
|
|
|
* New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
|
|
|
|
* Based partially on Rod Grimes' printer probe
|
|
|
|
*
|
|
|
|
* Logic:
|
|
|
|
* 1) If no port address was given, use the bios detected ports
|
|
|
|
* and autodetect what ports the printers are on.
|
|
|
|
* 2) Otherwise, probe the data port at the address given,
|
|
|
|
* using the method in Rod Grimes' port probe.
|
|
|
|
* (Much code ripped off directly from Rod's probe.)
|
1993-06-12 14:58:17 +00:00
|
|
|
*
|
1994-02-17 10:20:18 +00:00
|
|
|
* Comments from Rod's probe:
|
1993-06-12 14:58:17 +00:00
|
|
|
* Logic:
|
|
|
|
* 1) You should be able to write to and read back the same value
|
|
|
|
* to the data port. Do an alternating zeros, alternating ones,
|
|
|
|
* walking zero, and walking one test to check for stuck bits.
|
|
|
|
*
|
|
|
|
* 2) You should be able to write to and read back the same value
|
|
|
|
* to the control port lower 5 bits, the upper 3 bits are reserved
|
|
|
|
* per the IBM PC technical reference manauls and different boards
|
|
|
|
* do different things with them. Do an alternating zeros, alternating
|
|
|
|
* ones, walking zero, and walking one test to check for stuck bits.
|
|
|
|
*
|
|
|
|
* Some printers drag the strobe line down when the are powered off
|
|
|
|
* so this bit has been masked out of the control port test.
|
|
|
|
*
|
|
|
|
* XXX Some printers may not like a fast pulse on init or strobe, I
|
|
|
|
* don't know at this point, if that becomes a problem these bits
|
|
|
|
* should be turned off in the mask byte for the control port test.
|
|
|
|
*
|
1994-02-17 10:20:18 +00:00
|
|
|
* We are finally left with a mask of 0x14, due to some printers
|
|
|
|
* being adamant about holding other bits high ........
|
|
|
|
*
|
|
|
|
* Before probing the control port, we write a 0 to the data port -
|
|
|
|
* If not, some printers chuck out garbage when the strobe line
|
|
|
|
* gets toggled.
|
|
|
|
*
|
1993-06-12 14:58:17 +00:00
|
|
|
* 3) Set the data and control ports to a value of 0
|
1994-02-17 10:20:18 +00:00
|
|
|
*
|
|
|
|
* This probe routine has been tested on Epson Lx-800, HP LJ3P,
|
|
|
|
* Epson FX-1170 and C.Itoh 8510RM
|
|
|
|
* printers.
|
|
|
|
* Quick exit on fail added.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
int
|
1994-02-22 09:05:13 +00:00
|
|
|
lptprobe(struct isa_device *dvp)
|
1993-07-13 18:52:49 +00:00
|
|
|
{
|
1996-11-11 16:32:43 +00:00
|
|
|
int port;
|
1994-02-17 10:20:18 +00:00
|
|
|
static short next_bios_lpt = 0;
|
|
|
|
int status;
|
1998-02-20 02:44:48 +00:00
|
|
|
static u_char testbyte[18] = {
|
|
|
|
0x55, /* alternating zeros */
|
|
|
|
0xaa, /* alternating ones */
|
|
|
|
0xfe, 0xfd, 0xfb, 0xf7,
|
|
|
|
0xef, 0xdf, 0xbf, 0x7f, /* walking zero */
|
|
|
|
0x01, 0x02, 0x04, 0x08,
|
|
|
|
0x10, 0x20, 0x40, 0x80 /* walking one */
|
|
|
|
};
|
1994-02-17 10:20:18 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure there is some way for lptopen to see that
|
|
|
|
* the port is not configured
|
|
|
|
* This 0 will remain if the port isn't attached
|
|
|
|
*/
|
|
|
|
(lpt_sc + dvp->id_unit)->sc_port = 0;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
status = IO_LPTSIZE;
|
1994-02-17 10:20:18 +00:00
|
|
|
/* If port not specified, use bios list */
|
|
|
|
if(dvp->id_iobase < 0) { /* port? */
|
|
|
|
if((next_bios_lpt < BIOS_MAX_LPT) &&
|
|
|
|
(*(BIOS_PORTS+next_bios_lpt) != 0) ) {
|
|
|
|
dvp->id_iobase = *(BIOS_PORTS+next_bios_lpt++);
|
|
|
|
goto end_probe;
|
1995-05-30 08:16:23 +00:00
|
|
|
} else
|
1994-02-17 10:20:18 +00:00
|
|
|
return (0);
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
/* Port was explicitly specified */
|
|
|
|
/* This allows probing of ports unknown to the BIOS */
|
1993-06-12 14:58:17 +00:00
|
|
|
port = dvp->id_iobase + lpt_data;
|
1998-02-20 02:44:48 +00:00
|
|
|
for (i = 0; i < 18; i++) {
|
|
|
|
if (!lpt_port_test(port, testbyte[i], 0xff)) {
|
|
|
|
status = 0;
|
|
|
|
goto end_probe;
|
|
|
|
}
|
1994-02-17 10:20:18 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
end_probe:
|
|
|
|
/* write 0's to control and data ports */
|
1993-06-12 14:58:17 +00:00
|
|
|
outb(dvp->id_iobase+lpt_data, 0);
|
|
|
|
outb(dvp->id_iobase+lpt_control, 0);
|
1994-02-17 10:20:18 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
return (status);
|
1994-02-06 22:06:58 +00:00
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
/* XXX Todo - try and detect if interrupt is working */
|
1993-07-13 18:52:49 +00:00
|
|
|
int
|
1994-04-06 16:42:33 +00:00
|
|
|
lptattach(struct isa_device *isdp)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct lpt_softc *sc;
|
1995-12-08 11:19:42 +00:00
|
|
|
int unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
isdp->id_ointr = lptintr;
|
1995-12-08 11:19:42 +00:00
|
|
|
unit = isdp->id_unit;
|
|
|
|
sc = lpt_sc + unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
sc->sc_port = isdp->id_iobase;
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_primed = 0; /* not primed yet */
|
1993-06-12 14:58:17 +00:00
|
|
|
outb(sc->sc_port+lpt_control, LPC_NINIT);
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
/* check if we can use interrupt */
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("oldirq %x\n", sc->sc_irq));
|
1995-05-09 01:33:16 +00:00
|
|
|
if (isdp->id_irq) {
|
1994-04-06 16:42:33 +00:00
|
|
|
sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ;
|
1995-12-08 11:19:42 +00:00
|
|
|
printf("lpt%d: Interrupt-driven port\n", unit);
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
1995-12-08 11:19:42 +00:00
|
|
|
lpattach(sc, unit);
|
1994-08-13 00:37:03 +00:00
|
|
|
#endif
|
1994-02-17 10:20:18 +00:00
|
|
|
} else {
|
|
|
|
sc->sc_irq = 0;
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("lpt%d: Polled port\n", unit));
|
1994-02-17 10:20:18 +00:00
|
|
|
}
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("irq %x\n", sc->sc_irq));
|
1994-02-17 10:20:18 +00:00
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
#ifdef DEVFS
|
1996-03-29 11:54:56 +00:00
|
|
|
/* XXX what to do about the flags in the minor number? */
|
|
|
|
sc->devfs_token = devfs_add_devswf(&lpt_cdevsw,
|
|
|
|
unit, DV_CHR,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "lpt%d", unit);
|
|
|
|
sc->devfs_token_ctl = devfs_add_devswf(&lpt_cdevsw,
|
|
|
|
unit | LP_BYPASS, DV_CHR,
|
|
|
|
UID_ROOT, GID_WHEEL, 0600, "lpctl%d", unit);
|
1995-12-08 11:19:42 +00:00
|
|
|
#endif
|
1993-06-12 14:58:17 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lptopen -- reset the printer, then wait until it's selected and not busy.
|
1994-09-03 22:47:08 +00:00
|
|
|
* If LP_BYPASS flag is selected, then we do not try to select the
|
|
|
|
* printer -- this is just used for passing ioctls.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
lptopen (dev_t dev, int flags, int fmt, struct proc *p)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1993-07-13 18:52:49 +00:00
|
|
|
struct lpt_softc *sc;
|
1993-06-12 14:58:17 +00:00
|
|
|
int s;
|
|
|
|
int trys, port;
|
1993-07-13 18:52:49 +00:00
|
|
|
u_int unit = LPTUNIT(minor(dev));
|
1994-02-17 10:20:18 +00:00
|
|
|
|
1993-07-13 18:52:49 +00:00
|
|
|
sc = lpt_sc + unit;
|
1994-02-17 10:20:18 +00:00
|
|
|
if ((unit >= NLPT) || (sc->sc_port == 0))
|
|
|
|
return (ENXIO);
|
|
|
|
|
1994-08-23 07:52:29 +00:00
|
|
|
#ifdef INET
|
1995-05-30 08:16:23 +00:00
|
|
|
if (sc->sc_if.if_flags & IFF_UP)
|
1994-08-13 00:37:03 +00:00
|
|
|
return(EBUSY);
|
1994-08-23 07:52:29 +00:00
|
|
|
#endif
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
if (sc->sc_state) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("lp: still open %x\n", sc->sc_state));
|
1993-06-12 14:58:17 +00:00
|
|
|
return(EBUSY);
|
1995-05-09 01:33:16 +00:00
|
|
|
} else
|
|
|
|
sc->sc_state |= INIT;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
sc->sc_flags = LPTFLAGS(minor(dev));
|
1994-09-03 22:47:08 +00:00
|
|
|
|
|
|
|
/* Check for open with BYPASS flag set. */
|
1995-05-09 01:33:16 +00:00
|
|
|
if (sc->sc_flags & LP_BYPASS) {
|
1994-09-03 22:47:08 +00:00
|
|
|
sc->sc_state = OPEN;
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = spltty();
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("lp flags 0x%x\n", sc->sc_flags));
|
1993-06-12 14:58:17 +00:00
|
|
|
port = sc->sc_port;
|
|
|
|
|
1994-04-06 16:42:33 +00:00
|
|
|
/* set IRQ status according to ENABLE_IRQ flag */
|
1995-05-09 01:33:16 +00:00
|
|
|
if (sc->sc_irq & LP_ENABLE_IRQ)
|
1994-04-06 16:42:33 +00:00
|
|
|
sc->sc_irq |= LP_USE_IRQ;
|
|
|
|
else
|
|
|
|
sc->sc_irq &= ~LP_USE_IRQ;
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/* init printer */
|
1995-05-09 01:33:16 +00:00
|
|
|
if ((sc->sc_flags & LP_NO_PRIME) == 0) {
|
1993-06-12 14:58:17 +00:00
|
|
|
if((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) {
|
|
|
|
outb(port+lpt_control, 0);
|
|
|
|
sc->sc_primed++;
|
|
|
|
DELAY(500);
|
|
|
|
}
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
outb (port+lpt_control, LPC_SEL|LPC_NINIT);
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
/* wait till ready (printer running diagnostics) */
|
|
|
|
trys = 0;
|
|
|
|
do {
|
|
|
|
/* ran out of waiting for the printer */
|
|
|
|
if (trys++ >= LPINITRDY*4) {
|
|
|
|
splx(s);
|
|
|
|
sc->sc_state = 0;
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("status %x\n", inb(port+lpt_status)));
|
1993-06-12 14:58:17 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait 1/4 second, give up if we get a signal */
|
1995-05-09 01:33:16 +00:00
|
|
|
if (tsleep ((caddr_t)sc, LPPRI|PCATCH, "lptinit", hz/4) !=
|
|
|
|
EWOULDBLOCK) {
|
1993-06-12 14:58:17 +00:00
|
|
|
sc->sc_state = 0;
|
|
|
|
splx(s);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
/* is printer online and ready for output */
|
|
|
|
} while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
|
1995-05-09 01:33:16 +00:00
|
|
|
(LPS_SEL|LPS_NBSY|LPS_NERR));
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_control = LPC_SEL|LPC_NINIT;
|
1995-05-09 01:33:16 +00:00
|
|
|
if (sc->sc_flags & LP_AUTOLF)
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_control |= LPC_AUTOL;
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
/* enable interrupt if interrupt-driven */
|
1995-05-09 01:33:16 +00:00
|
|
|
if (sc->sc_irq & LP_USE_IRQ)
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_control |= LPC_ENA;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
outb(port+lpt_control, sc->sc_control);
|
|
|
|
|
|
|
|
sc->sc_state = OPEN;
|
1993-06-12 14:58:17 +00:00
|
|
|
sc->sc_inbuf = geteblk(BUFSIZE);
|
|
|
|
sc->sc_xfercnt = 0;
|
|
|
|
splx(s);
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
/* only use timeout if using interrupt */
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("irq %x\n", sc->sc_irq));
|
1995-05-09 01:33:16 +00:00
|
|
|
if (sc->sc_irq & LP_USE_IRQ) {
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_state |= TOUT;
|
1997-04-20 15:36:12 +00:00
|
|
|
timeout (lptout, (caddr_t)sc,
|
1996-04-04 12:28:36 +00:00
|
|
|
(sc->sc_backoff = hz/LPTOUTINITIAL));
|
1994-02-17 10:20:18 +00:00
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("opened.\n"));
|
1993-06-12 14:58:17 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1994-04-06 16:42:33 +00:00
|
|
|
static void
|
1997-04-20 15:36:12 +00:00
|
|
|
lptout (void *arg)
|
|
|
|
{
|
|
|
|
struct lpt_softc *sc = arg;
|
|
|
|
int pl;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("T %x ", inb(sc->sc_port+lpt_status)));
|
1996-04-04 12:28:36 +00:00
|
|
|
if (sc->sc_state & OPEN) {
|
|
|
|
sc->sc_backoff++;
|
|
|
|
if (sc->sc_backoff > hz/LPTOUTMAX)
|
|
|
|
sc->sc_backoff = sc->sc_backoff > hz/LPTOUTMAX;
|
1997-04-20 15:36:12 +00:00
|
|
|
timeout (lptout, (caddr_t)sc, sc->sc_backoff);
|
1996-04-04 12:28:36 +00:00
|
|
|
} else
|
1995-05-09 01:33:16 +00:00
|
|
|
sc->sc_state &= ~TOUT;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
if (sc->sc_state & ERROR)
|
|
|
|
sc->sc_state &= ~ERROR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Avoid possible hangs do to missed interrupts
|
|
|
|
*/
|
|
|
|
if (sc->sc_xfercnt) {
|
|
|
|
pl = spltty();
|
|
|
|
lptintr(sc - lpt_sc);
|
|
|
|
splx(pl);
|
|
|
|
} else {
|
|
|
|
sc->sc_state &= ~OBUSY;
|
|
|
|
wakeup((caddr_t)sc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lptclose -- close the device, free the local line buffer.
|
1994-02-17 10:20:18 +00:00
|
|
|
*
|
|
|
|
* Check for interrupted write call added.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
lptclose(dev_t dev, int flags, int fmt, struct proc *p)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct lpt_softc *sc = lpt_sc + LPTUNIT(minor(dev));
|
|
|
|
int port = sc->sc_port;
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
if(sc->sc_flags & LP_BYPASS)
|
1994-09-03 22:47:08 +00:00
|
|
|
goto end_close;
|
|
|
|
|
1993-06-12 14:58:17 +00:00
|
|
|
sc->sc_state &= ~OPEN;
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
/* if the last write was interrupted, don't complete it */
|
|
|
|
if((!(sc->sc_state & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ))
|
|
|
|
while ((inb(port+lpt_status) & (LPS_SEL|LPS_OUT|LPS_NBSY|LPS_NERR)) !=
|
1993-06-12 14:58:17 +00:00
|
|
|
(LPS_SEL|LPS_NBSY|LPS_NERR) || sc->sc_xfercnt)
|
1994-02-17 10:20:18 +00:00
|
|
|
/* wait 1/4 second, give up if we get a signal */
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tsleep ((caddr_t)sc, LPPRI|PCATCH,
|
1994-02-17 10:20:18 +00:00
|
|
|
"lpclose", hz) != EWOULDBLOCK)
|
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
outb(sc->sc_port+lpt_control, LPC_NINIT);
|
|
|
|
brelse(sc->sc_inbuf);
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-09-03 22:47:08 +00:00
|
|
|
end_close:
|
|
|
|
sc->sc_state = 0;
|
|
|
|
sc->sc_xfercnt = 0;
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("closed.\n"));
|
1994-02-17 10:20:18 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pushbytes()
|
|
|
|
* Workhorse for actually spinning and writing bytes to printer
|
|
|
|
* Derived from lpa.c
|
|
|
|
* Originally by ?
|
|
|
|
*
|
|
|
|
* This code is only used when we are polling the port
|
|
|
|
*/
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
|
|
|
pushbytes(struct lpt_softc * sc)
|
1994-02-17 10:20:18 +00:00
|
|
|
{
|
|
|
|
int spin, err, tic;
|
|
|
|
char ch;
|
|
|
|
int port = sc->sc_port;
|
|
|
|
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("p"));
|
1994-02-17 10:20:18 +00:00
|
|
|
/* loop for every character .. */
|
|
|
|
while (sc->sc_xfercnt > 0) {
|
|
|
|
/* printer data */
|
|
|
|
ch = *(sc->sc_cp);
|
|
|
|
sc->sc_cp++;
|
|
|
|
sc->sc_xfercnt--;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for printer ready.
|
|
|
|
* Loop 20 usecs testing BUSY bit, then sleep
|
|
|
|
* for exponentially increasing timeout. (vak)
|
|
|
|
*/
|
|
|
|
for (spin=0; NOT_READY(port+lpt_status) && spin<MAX_SPIN; ++spin)
|
|
|
|
DELAY(1); /* XXX delay is NOT this accurate! */
|
|
|
|
if (spin >= MAX_SPIN) {
|
|
|
|
tic = 0;
|
|
|
|
while (NOT_READY(port+lpt_status)) {
|
|
|
|
/*
|
|
|
|
* Now sleep, every cycle a
|
|
|
|
* little longer ..
|
|
|
|
*/
|
|
|
|
tic = tic + tic + 1;
|
|
|
|
/*
|
|
|
|
* But no more than 10 seconds. (vak)
|
|
|
|
*/
|
|
|
|
if (tic > MAX_SLEEP)
|
|
|
|
tic = MAX_SLEEP;
|
|
|
|
err = tsleep((caddr_t)sc, LPPRI,
|
|
|
|
"lptpoll", tic);
|
|
|
|
if (err != EWOULDBLOCK) {
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* output data */
|
|
|
|
outb(port+lpt_data, ch);
|
|
|
|
/* strobe */
|
|
|
|
outb(port+lpt_control, sc->sc_control|LPC_STB);
|
|
|
|
outb(port+lpt_control, sc->sc_control);
|
|
|
|
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
|
|
|
* lptwrite --copy a line from user space to a local buffer, then call
|
1993-06-12 14:58:17 +00:00
|
|
|
* putc to get the chars moved to the output queue.
|
1994-02-17 10:20:18 +00:00
|
|
|
*
|
|
|
|
* Flagging of interrupted write added.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
lptwrite(dev_t dev, struct uio * uio, int ioflag)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
register unsigned n;
|
|
|
|
int pl, err;
|
|
|
|
struct lpt_softc *sc = lpt_sc + LPTUNIT(minor(dev));
|
|
|
|
|
1994-09-03 22:47:08 +00:00
|
|
|
if(sc->sc_flags & LP_BYPASS) {
|
|
|
|
/* we can't do writes in bypass mode */
|
|
|
|
return(EPERM);
|
|
|
|
}
|
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_state &= ~INTERRUPTED;
|
1994-10-10 01:12:27 +00:00
|
|
|
while ((n = min(BUFSIZE, uio->uio_resid)) != 0) {
|
1997-12-02 21:07:20 +00:00
|
|
|
sc->sc_cp = sc->sc_inbuf->b_data ;
|
1993-06-12 14:58:17 +00:00
|
|
|
uiomove(sc->sc_cp, n, uio);
|
|
|
|
sc->sc_xfercnt = n ;
|
1994-04-06 16:42:33 +00:00
|
|
|
while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("i"));
|
1994-04-06 16:42:33 +00:00
|
|
|
/* if the printer is ready for a char, */
|
|
|
|
/* give it one */
|
|
|
|
if ((sc->sc_state & OBUSY) == 0){
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("\nC %d. ", sc->sc_xfercnt));
|
1994-04-06 16:42:33 +00:00
|
|
|
pl = spltty();
|
|
|
|
lptintr(sc - lpt_sc);
|
|
|
|
(void) splx(pl);
|
1994-02-06 22:06:58 +00:00
|
|
|
}
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("W "));
|
1994-04-06 16:42:33 +00:00
|
|
|
if (sc->sc_state & OBUSY)
|
1995-05-30 08:16:23 +00:00
|
|
|
if ((err = tsleep ((caddr_t)sc,
|
1994-08-13 00:37:03 +00:00
|
|
|
LPPRI|PCATCH, "lpwrite", 0))) {
|
1994-04-06 16:42:33 +00:00
|
|
|
sc->sc_state |= INTERRUPTED;
|
|
|
|
return(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* check to see if we must do a polled write */
|
1995-05-30 08:16:23 +00:00
|
|
|
if(!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("p"));
|
1994-02-17 10:20:18 +00:00
|
|
|
if((err = pushbytes(sc)))
|
|
|
|
return(err);
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lptintr -- handle printer interrupts which occur when the printer is
|
|
|
|
* ready to accept another char.
|
1994-02-17 10:20:18 +00:00
|
|
|
*
|
|
|
|
* do checking for interrupted write call.
|
1993-06-12 14:58:17 +00:00
|
|
|
*/
|
|
|
|
|
1998-10-22 05:58:45 +00:00
|
|
|
static void
|
1994-04-06 16:42:33 +00:00
|
|
|
lptintr(int unit)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
|
|
|
struct lpt_softc *sc = lpt_sc + unit;
|
1994-02-17 10:20:18 +00:00
|
|
|
int port = sc->sc_port, sts;
|
1996-04-04 12:28:36 +00:00
|
|
|
int i;
|
1994-02-17 10:20:18 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
|
|
|
if(sc->sc_if.if_flags & IFF_UP) {
|
|
|
|
lpintr(unit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
|
1996-04-04 12:28:36 +00:00
|
|
|
/*
|
|
|
|
* Is printer online and ready for output?
|
|
|
|
*
|
|
|
|
* Avoid falling back to lptout() too quickly. First spin-loop
|
|
|
|
* to see if the printer will become ready ``really soon now''.
|
|
|
|
*/
|
|
|
|
for (i = 0;
|
|
|
|
i < 100 &&
|
|
|
|
((sts=inb(port+lpt_status)) & RDY_MASK) != LP_READY;
|
|
|
|
i++) ;
|
|
|
|
if ((sts & RDY_MASK) == LP_READY) {
|
1994-02-17 10:20:18 +00:00
|
|
|
sc->sc_state = (sc->sc_state | OBUSY) & ~ERROR;
|
1996-04-04 12:28:36 +00:00
|
|
|
sc->sc_backoff = hz/LPTOUTINITIAL;
|
1994-02-17 10:20:18 +00:00
|
|
|
|
|
|
|
if (sc->sc_xfercnt) {
|
|
|
|
/* send char */
|
1998-12-10 01:42:32 +00:00
|
|
|
/*lprintf(("%x ", *sc->sc_cp)); */
|
1995-05-30 08:16:23 +00:00
|
|
|
outb(port+lpt_data, *sc->sc_cp++) ;
|
1994-02-17 10:20:18 +00:00
|
|
|
outb(port+lpt_control, sc->sc_control|LPC_STB);
|
|
|
|
/* DELAY(X) */
|
|
|
|
outb(port+lpt_control, sc->sc_control);
|
|
|
|
|
|
|
|
/* any more data for printer */
|
|
|
|
if(--(sc->sc_xfercnt) > 0) return;
|
|
|
|
}
|
1993-06-12 14:58:17 +00:00
|
|
|
|
1994-02-17 10:20:18 +00:00
|
|
|
/*
|
|
|
|
* No more data waiting for printer.
|
|
|
|
* Wakeup is not done if write call was interrupted.
|
|
|
|
*/
|
1993-06-12 14:58:17 +00:00
|
|
|
sc->sc_state &= ~OBUSY;
|
1994-02-17 10:20:18 +00:00
|
|
|
if(!(sc->sc_state & INTERRUPTED))
|
|
|
|
wakeup((caddr_t)sc);
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("w "));
|
1994-02-17 10:20:18 +00:00
|
|
|
return;
|
|
|
|
} else { /* check for error */
|
|
|
|
if(((sts & (LPS_NERR | LPS_OUT) ) != LPS_NERR) &&
|
|
|
|
(sc->sc_state & OPEN))
|
|
|
|
sc->sc_state |= ERROR;
|
1996-04-04 12:28:36 +00:00
|
|
|
/* lptout() will jump in and try to restart. */
|
1994-02-06 22:06:58 +00:00
|
|
|
}
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("sts %x ", sts));
|
1993-06-12 14:58:17 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
lptioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
|
1993-06-12 14:58:17 +00:00
|
|
|
{
|
1994-04-06 16:42:33 +00:00
|
|
|
int error = 0;
|
|
|
|
struct lpt_softc *sc;
|
|
|
|
u_int unit = LPTUNIT(minor(dev));
|
1994-04-08 22:13:49 +00:00
|
|
|
u_char old_sc_irq; /* old printer IRQ status */
|
1994-04-06 16:42:33 +00:00
|
|
|
|
|
|
|
sc = lpt_sc + unit;
|
1993-06-12 14:58:17 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
1994-04-06 16:42:33 +00:00
|
|
|
case LPT_IRQ :
|
|
|
|
if(sc->sc_irq & LP_HAS_IRQ) {
|
1995-05-30 08:16:23 +00:00
|
|
|
/*
|
|
|
|
* NOTE:
|
1994-04-06 16:42:33 +00:00
|
|
|
* If the IRQ status is changed,
|
|
|
|
* this will only be visible on the
|
|
|
|
* next open.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-04-08 22:13:49 +00:00
|
|
|
* If interrupt status changes,
|
|
|
|
* this gets syslog'd.
|
1994-04-06 16:42:33 +00:00
|
|
|
*/
|
1994-04-08 22:13:49 +00:00
|
|
|
old_sc_irq = sc->sc_irq;
|
1994-04-06 16:42:33 +00:00
|
|
|
if(*(int*)data == 0)
|
|
|
|
sc->sc_irq &= (~LP_ENABLE_IRQ);
|
|
|
|
else
|
|
|
|
sc->sc_irq |= LP_ENABLE_IRQ;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (old_sc_irq != sc->sc_irq )
|
1994-04-08 22:13:49 +00:00
|
|
|
log(LOG_NOTICE, "lpt%c switched to %s mode\n",
|
1995-05-30 08:16:23 +00:00
|
|
|
(char)unit+'0',
|
1994-04-08 22:13:49 +00:00
|
|
|
(sc->sc_irq & LP_ENABLE_IRQ)?
|
|
|
|
"interrupt-driven":"polled");
|
1994-04-06 16:42:33 +00:00
|
|
|
} else /* polled port */
|
|
|
|
error = EOPNOTSUPP;
|
1995-05-30 08:16:23 +00:00
|
|
|
break;
|
1993-06-12 14:58:17 +00:00
|
|
|
default:
|
|
|
|
error = ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
#ifdef INET
|
|
|
|
|
|
|
|
static void
|
1995-05-09 01:33:16 +00:00
|
|
|
lpattach (struct lpt_softc *sc, int unit)
|
1994-08-13 00:37:03 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
|
1996-02-06 18:51:28 +00:00
|
|
|
ifp->if_softc = sc;
|
1994-08-13 00:37:03 +00:00
|
|
|
ifp->if_name = "lp";
|
|
|
|
ifp->if_unit = unit;
|
|
|
|
ifp->if_mtu = LPMTU;
|
1995-09-25 16:57:54 +00:00
|
|
|
ifp->if_flags = IFF_SIMPLEX | IFF_POINTOPOINT | IFF_MULTICAST;
|
1994-08-13 00:37:03 +00:00
|
|
|
ifp->if_ioctl = lpioctl;
|
|
|
|
ifp->if_output = lpoutput;
|
1995-06-21 10:23:23 +00:00
|
|
|
ifp->if_type = IFT_PARA;
|
1994-08-13 00:37:03 +00:00
|
|
|
ifp->if_hdrlen = 0;
|
|
|
|
ifp->if_addrlen = 0;
|
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
|
|
|
if_attach(ifp);
|
1995-05-09 01:33:16 +00:00
|
|
|
printf("lp%d: TCP/IP capable interface\n", unit);
|
1995-09-25 16:57:54 +00:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
1996-02-06 18:51:28 +00:00
|
|
|
bpfattach(ifp, DLT_NULL, LPIPHDRLEN);
|
1995-09-25 16:57:54 +00:00
|
|
|
#endif
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
|
|
|
/*
|
1995-05-09 01:33:16 +00:00
|
|
|
* Build the translation tables for the LPIP (BSD unix) protocol.
|
1995-05-30 08:16:23 +00:00
|
|
|
* We don't want to calculate these nasties in our tight loop, so we
|
1994-08-13 00:37:03 +00:00
|
|
|
* precalculate them when we initialize.
|
|
|
|
*/
|
1994-09-18 06:12:45 +00:00
|
|
|
static int
|
1995-05-09 01:33:16 +00:00
|
|
|
lpinittables (void)
|
1994-08-13 00:37:03 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
if (!txmith)
|
|
|
|
txmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (!txmith)
|
1994-09-18 06:12:45 +00:00
|
|
|
return 1;
|
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
if (!ctxmith)
|
|
|
|
ctxmith = malloc(4*LPIPTBLSIZE, M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (!ctxmith)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
for (i=0; i < LPIPTBLSIZE; i++) {
|
|
|
|
ctxmith[i] = (i & 0xF0) >> 4;
|
|
|
|
ctxmitl[i] = 0x10 | (i & 0x0F);
|
|
|
|
ctrecvh[i] = (i & 0x78) << 1;
|
|
|
|
ctrecvl[i] = (i & 0x78) >> 3;
|
|
|
|
}
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
for (i=0; i < LPIPTBLSIZE; i++) {
|
1994-08-13 00:37:03 +00:00
|
|
|
txmith[i] = ((i & 0x80) >> 3) | ((i & 0x70) >> 4) | 0x08;
|
|
|
|
txmitl[i] = ((i & 0x08) << 1) | (i & 0x07);
|
|
|
|
trecvh[i] = ((~i) & 0x80) | ((i & 0x38) << 1);
|
|
|
|
trecvl[i] = (((~i) & 0x80) >> 4) | ((i & 0x38) >> 3);
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-09-18 06:12:45 +00:00
|
|
|
return 0;
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
lpioctl (struct ifnet *ifp, u_long cmd, caddr_t data)
|
1994-08-13 00:37:03 +00:00
|
|
|
{
|
1994-09-18 06:12:45 +00:00
|
|
|
struct lpt_softc *sc = lpt_sc + ifp->if_unit;
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
1995-05-30 08:16:23 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
1994-09-18 06:12:45 +00:00
|
|
|
u_char *ptr;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
case SIOCAIFADDR:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
return EAFNOSUPPORT;
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if ((!(ifp->if_flags & IFF_UP)) && (ifp->if_flags & IFF_RUNNING)) {
|
1995-05-09 01:33:16 +00:00
|
|
|
outb(sc->sc_port + lpt_control, 0x00);
|
1994-09-18 06:12:45 +00:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (((ifp->if_flags & IFF_UP)) && (!(ifp->if_flags & IFF_RUNNING))) {
|
1995-05-09 01:33:16 +00:00
|
|
|
if (lpinittables())
|
1994-09-18 06:12:45 +00:00
|
|
|
return ENOBUFS;
|
1995-12-02 20:33:40 +00:00
|
|
|
sc->sc_ifbuf = malloc(sc->sc_if.if_mtu + MLPIPHDRLEN,
|
1995-05-09 01:33:16 +00:00
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
if (!sc->sc_ifbuf)
|
1994-09-18 06:12:45 +00:00
|
|
|
return ENOBUFS;
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
outb(sc->sc_port + lpt_control, LPC_ENA);
|
1994-09-18 06:12:45 +00:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
ptr = sc->sc_ifbuf;
|
1995-12-02 20:33:40 +00:00
|
|
|
sc->sc_ifbuf = malloc(ifr->ifr_mtu+MLPIPHDRLEN, M_DEVBUF, M_NOWAIT);
|
1995-05-09 01:33:16 +00:00
|
|
|
if (!sc->sc_ifbuf) {
|
1994-09-18 06:12:45 +00:00
|
|
|
sc->sc_ifbuf = ptr;
|
|
|
|
return ENOBUFS;
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1994-11-16 06:09:29 +00:00
|
|
|
if (ptr)
|
1995-05-09 01:33:16 +00:00
|
|
|
free(ptr,M_DEVBUF);
|
1995-06-22 07:03:20 +00:00
|
|
|
sc->sc_if.if_mtu = ifr->ifr_mtu;
|
1994-09-18 06:12:45 +00:00
|
|
|
break;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1994-09-18 06:12:45 +00:00
|
|
|
case SIOCGIFMTU:
|
1995-06-22 07:03:20 +00:00
|
|
|
ifr->ifr_mtu = sc->sc_if.if_mtu;
|
1994-09-18 06:12:45 +00:00
|
|
|
break;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-09-25 16:57:54 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
if (ifr == 0) {
|
|
|
|
return EAFNOSUPPORT; /* XXX */
|
|
|
|
}
|
|
|
|
switch (ifr->ifr_addr.sa_family) {
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EAFNOSUPPORT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1994-09-18 06:12:45 +00:00
|
|
|
default:
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("LP:ioctl(0x%lx)\n", cmd));
|
1994-09-18 06:12:45 +00:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
|
|
|
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline int
|
1995-12-02 20:33:40 +00:00
|
|
|
clpoutbyte (u_char byte, int spin, int data_port, int status_port)
|
|
|
|
{
|
|
|
|
outb(data_port, ctxmitl[byte]);
|
|
|
|
while (inb(status_port) & CLPIP_SHAKE)
|
|
|
|
if (--spin == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
outb(data_port, ctxmith[byte]);
|
|
|
|
while (!(inb(status_port) & CLPIP_SHAKE))
|
|
|
|
if (--spin == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline int
|
1995-12-02 20:33:40 +00:00
|
|
|
clpinbyte (int spin, int data_port, int status_port)
|
|
|
|
{
|
|
|
|
int c, cl;
|
|
|
|
|
|
|
|
while((inb(status_port) & CLPIP_SHAKE))
|
|
|
|
if(!--spin) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cl = inb(status_port);
|
|
|
|
outb(data_port, 0x10);
|
|
|
|
|
|
|
|
while(!(inb(status_port) & CLPIP_SHAKE))
|
|
|
|
if(!--spin) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
c = inb(status_port);
|
|
|
|
outb(data_port, 0x00);
|
|
|
|
|
|
|
|
return (ctrecvl[cl] | ctrecvh[c]);
|
|
|
|
}
|
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
static void
|
1995-05-09 01:33:16 +00:00
|
|
|
lpintr (int unit)
|
1994-08-13 00:37:03 +00:00
|
|
|
{
|
1995-05-09 01:33:16 +00:00
|
|
|
struct lpt_softc *sc = lpt_sc + unit;
|
|
|
|
register int lpt_data_port = sc->sc_port + lpt_data;
|
|
|
|
register int lpt_stat_port = sc->sc_port + lpt_status;
|
|
|
|
int lpt_ctrl_port = sc->sc_port + lpt_control;
|
|
|
|
int len, s, j;
|
1994-09-18 06:12:45 +00:00
|
|
|
u_char *bp;
|
1995-05-09 01:33:16 +00:00
|
|
|
u_char c, cl;
|
1994-10-27 05:08:28 +00:00
|
|
|
struct mbuf *top;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-02-26 21:41:41 +00:00
|
|
|
s = splhigh();
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
if (sc->sc_if.if_flags & IFF_LINK0) {
|
|
|
|
|
|
|
|
/* Ack. the request */
|
|
|
|
outb(lpt_data_port, 0x01);
|
|
|
|
|
|
|
|
/* Get the packet length */
|
|
|
|
j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
|
|
|
|
if (j == -1)
|
|
|
|
goto err;
|
|
|
|
len = j;
|
|
|
|
j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
|
|
|
|
if (j == -1)
|
|
|
|
goto err;
|
|
|
|
len = len + (j << 8);
|
1996-03-04 15:58:25 +00:00
|
|
|
if (len > sc->sc_if.if_mtu + MLPIPHDRLEN)
|
|
|
|
goto err;
|
1995-12-02 20:33:40 +00:00
|
|
|
|
|
|
|
bp = sc->sc_ifbuf;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
|
|
|
|
if (j == -1) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
*bp++ = j;
|
|
|
|
}
|
|
|
|
/* Get and ignore checksum */
|
|
|
|
j = clpinbyte(LPMAXSPIN2, lpt_data_port, lpt_stat_port);
|
|
|
|
if (j == -1) {
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = bp - sc->sc_ifbuf;
|
|
|
|
if (len <= CLPIPHDRLEN)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
sc->sc_iferrs = 0;
|
|
|
|
|
|
|
|
if (IF_QFULL(&ipintrq)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("DROP"));
|
1995-12-02 20:33:40 +00:00
|
|
|
IF_DROP(&ipintrq);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
len -= CLPIPHDRLEN;
|
|
|
|
sc->sc_if.if_ipackets++;
|
|
|
|
sc->sc_if.if_ibytes += len;
|
|
|
|
top = m_devget(sc->sc_ifbuf + CLPIPHDRLEN, len, 0, &sc->sc_if, 0);
|
|
|
|
if (top) {
|
|
|
|
IF_ENQUEUE(&ipintrq, top);
|
|
|
|
schednetisr(NETISR_IP);
|
|
|
|
}
|
|
|
|
goto done;
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
while ((inb(lpt_stat_port) & LPIP_SHAKE)) {
|
|
|
|
len = sc->sc_if.if_mtu + LPIPHDRLEN;
|
|
|
|
bp = sc->sc_ifbuf;
|
|
|
|
while (len--) {
|
|
|
|
|
|
|
|
cl = inb(lpt_stat_port);
|
|
|
|
outb(lpt_data_port, 8);
|
|
|
|
|
1994-10-27 05:08:28 +00:00
|
|
|
j = LPMAXSPIN2;
|
1995-05-09 01:33:16 +00:00
|
|
|
while((inb(lpt_stat_port) & LPIP_SHAKE))
|
1994-08-13 00:37:03 +00:00
|
|
|
if(!--j) goto err;
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
c = inb(lpt_stat_port);
|
|
|
|
outb(lpt_data_port, 0);
|
|
|
|
|
1994-09-18 06:12:45 +00:00
|
|
|
*bp++= trecvh[cl] | trecvl[c];
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-10-27 05:08:28 +00:00
|
|
|
j = LPMAXSPIN2;
|
1995-05-09 01:33:16 +00:00
|
|
|
while (!((cl=inb(lpt_stat_port)) & LPIP_SHAKE)) {
|
|
|
|
if (cl != c &&
|
|
|
|
(((cl = inb(lpt_stat_port)) ^ 0xb8) & 0xf8) ==
|
|
|
|
(c & 0xf8))
|
1994-08-13 00:37:03 +00:00
|
|
|
goto end;
|
1995-05-09 01:33:16 +00:00
|
|
|
if (!--j) goto err;
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
end:
|
1994-09-18 06:12:45 +00:00
|
|
|
len = bp - sc->sc_ifbuf;
|
1995-05-09 01:33:16 +00:00
|
|
|
if (len <= LPIPHDRLEN)
|
1994-08-13 00:37:03 +00:00
|
|
|
goto err;
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
sc->sc_iferrs = 0;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
if (IF_QFULL(&ipintrq)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("DROP"));
|
1994-08-13 00:37:03 +00:00
|
|
|
IF_DROP(&ipintrq);
|
|
|
|
goto done;
|
|
|
|
}
|
1995-09-25 16:57:54 +00:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (sc->sc_if.if_bpf) {
|
1996-02-06 18:51:28 +00:00
|
|
|
bpf_tap(&sc->sc_if, sc->sc_ifbuf, len);
|
1995-09-25 16:57:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
1995-05-09 01:33:16 +00:00
|
|
|
len -= LPIPHDRLEN;
|
1994-08-13 00:37:03 +00:00
|
|
|
sc->sc_if.if_ipackets++;
|
|
|
|
sc->sc_if.if_ibytes += len;
|
1995-05-09 01:33:16 +00:00
|
|
|
top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, &sc->sc_if, 0);
|
|
|
|
if (top) {
|
1994-10-27 05:08:28 +00:00
|
|
|
IF_ENQUEUE(&ipintrq, top);
|
|
|
|
schednetisr(NETISR_IP);
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
1994-10-27 05:08:28 +00:00
|
|
|
}
|
1994-08-13 00:37:03 +00:00
|
|
|
goto done;
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
err:
|
1995-05-09 01:33:16 +00:00
|
|
|
outb(lpt_data_port, 0);
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("R"));
|
1994-08-13 00:37:03 +00:00
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
sc->sc_iferrs++;
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We are not able to send receive anything for now,
|
|
|
|
* so stop wasting our time
|
|
|
|
*/
|
|
|
|
if (sc->sc_iferrs > LPMAXERRS) {
|
1994-08-13 00:37:03 +00:00
|
|
|
printf("lp%d: Too many errors, Going off-line.\n", unit);
|
1995-05-09 01:33:16 +00:00
|
|
|
outb(lpt_ctrl_port, 0x00);
|
1994-08-13 00:37:03 +00:00
|
|
|
sc->sc_if.if_flags &= ~IFF_RUNNING;
|
|
|
|
sc->sc_iferrs=0;
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
done:
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline int
|
1995-05-09 01:33:16 +00:00
|
|
|
lpoutbyte (u_char byte, int spin, int data_port, int status_port)
|
|
|
|
{
|
1995-12-02 20:33:40 +00:00
|
|
|
outb(data_port, txmith[byte]);
|
|
|
|
while (!(inb(status_port) & LPIP_SHAKE))
|
|
|
|
if (--spin == 0)
|
|
|
|
return 1;
|
|
|
|
outb(data_port, txmitl[byte]);
|
|
|
|
while (inb(status_port) & LPIP_SHAKE)
|
|
|
|
if (--spin == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
1995-05-09 01:33:16 +00:00
|
|
|
}
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
static int
|
|
|
|
lpoutput (struct ifnet *ifp, struct mbuf *m,
|
1995-05-09 01:33:16 +00:00
|
|
|
struct sockaddr *dst, struct rtentry *rt)
|
1994-08-13 00:37:03 +00:00
|
|
|
{
|
1995-05-09 01:33:16 +00:00
|
|
|
register int lpt_data_port = lpt_sc[ifp->if_unit].sc_port + lpt_data;
|
|
|
|
register int lpt_stat_port = lpt_sc[ifp->if_unit].sc_port + lpt_status;
|
|
|
|
int lpt_ctrl_port = lpt_sc[ifp->if_unit].sc_port + lpt_control;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
int s, err;
|
|
|
|
struct mbuf *mm;
|
|
|
|
u_char *cp = "\0\0";
|
1995-12-02 20:33:40 +00:00
|
|
|
u_char chksum = 0;
|
|
|
|
int count = 0;
|
|
|
|
int i;
|
|
|
|
int spin;
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
/* We need a sensible value if we abort */
|
1994-09-15 02:37:11 +00:00
|
|
|
cp++;
|
1995-05-09 01:33:16 +00:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
|
|
|
|
err = 1; /* assume we're aborting because of an error */
|
|
|
|
|
|
|
|
s = splhigh();
|
1994-09-15 02:37:11 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
/* Suspend (on laptops) or receive-errors might have taken us offline */
|
1995-05-09 01:33:16 +00:00
|
|
|
outb(lpt_ctrl_port, LPC_ENA);
|
1994-08-13 00:37:03 +00:00
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
if (ifp->if_flags & IFF_LINK0) {
|
|
|
|
|
|
|
|
if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("&"));
|
1995-12-02 20:33:40 +00:00
|
|
|
lptintr(ifp->if_unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alert other end to pending packet */
|
|
|
|
spin = LPMAXSPIN1;
|
|
|
|
outb(lpt_data_port, 0x08);
|
|
|
|
while ((inb(lpt_stat_port) & 0x08) == 0)
|
|
|
|
if (--spin == 0) {
|
|
|
|
goto nend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate length of packet, then send that */
|
|
|
|
|
|
|
|
count += 14; /* Ethernet header len */
|
|
|
|
|
|
|
|
mm = m;
|
|
|
|
for (mm = m; mm; mm = mm->m_next) {
|
|
|
|
count += mm->m_len;
|
|
|
|
}
|
|
|
|
if (clpoutbyte(count & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
if (clpoutbyte((count >> 8) & 0xFF, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
|
|
|
|
/* Send dummy ethernet header */
|
|
|
|
for (i = 0; i < 12; i++) {
|
|
|
|
if (clpoutbyte(i, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
chksum += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
if (clpoutbyte(0x00, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
chksum += 0x08 + 0x00; /* Add into checksum */
|
|
|
|
|
|
|
|
mm = m;
|
|
|
|
do {
|
|
|
|
cp = mtod(mm, u_char *);
|
|
|
|
while (mm->m_len--) {
|
|
|
|
chksum += *cp;
|
|
|
|
if (clpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
}
|
|
|
|
} while ((mm = mm->m_next));
|
|
|
|
|
|
|
|
/* Send checksum */
|
|
|
|
if (clpoutbyte(chksum, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
|
|
|
|
goto nend;
|
|
|
|
|
|
|
|
/* Go quiescent */
|
|
|
|
outb(lpt_data_port, 0);
|
|
|
|
|
|
|
|
err = 0; /* No errors */
|
|
|
|
|
|
|
|
nend:
|
|
|
|
if (err) { /* if we didn't timeout... */
|
|
|
|
ifp->if_oerrors++;
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("X"));
|
1995-12-02 20:33:40 +00:00
|
|
|
} else {
|
|
|
|
ifp->if_opackets++;
|
|
|
|
ifp->if_obytes += m->m_pkthdr.len;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_freem(m);
|
|
|
|
|
|
|
|
if (!(inb(lpt_stat_port) & CLPIP_SHAKE)) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("^"));
|
1995-12-02 20:33:40 +00:00
|
|
|
lptintr(ifp->if_unit);
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
if (inb(lpt_stat_port) & LPIP_SHAKE) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("&"));
|
1995-12-02 20:33:40 +00:00
|
|
|
lptintr(ifp->if_unit);
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
|
|
|
|
1995-05-09 01:33:16 +00:00
|
|
|
if (lpoutbyte(0x08, LPMAXSPIN1, lpt_data_port, lpt_stat_port))
|
1995-12-02 20:33:40 +00:00
|
|
|
goto end;
|
1995-05-09 01:33:16 +00:00
|
|
|
if (lpoutbyte(0x00, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
|
1995-12-02 20:33:40 +00:00
|
|
|
goto end;
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
mm = m;
|
1994-08-13 00:37:03 +00:00
|
|
|
do {
|
1995-12-02 20:33:40 +00:00
|
|
|
cp = mtod(mm,u_char *);
|
|
|
|
while (mm->m_len--)
|
1995-05-09 01:33:16 +00:00
|
|
|
if (lpoutbyte(*cp++, LPMAXSPIN2, lpt_data_port, lpt_stat_port))
|
1995-12-02 20:33:40 +00:00
|
|
|
goto end;
|
1994-08-13 00:37:03 +00:00
|
|
|
} while ((mm = mm->m_next));
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
err = 0; /* no errors were encountered */
|
|
|
|
|
1995-12-02 20:33:40 +00:00
|
|
|
end:
|
1995-05-09 01:33:16 +00:00
|
|
|
--cp;
|
|
|
|
outb(lpt_data_port, txmitl[*cp] ^ 0x17);
|
|
|
|
|
|
|
|
if (err) { /* if we didn't timeout... */
|
1994-08-13 00:37:03 +00:00
|
|
|
ifp->if_oerrors++;
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("X"));
|
1995-05-09 01:33:16 +00:00
|
|
|
} else {
|
|
|
|
ifp->if_opackets++;
|
|
|
|
ifp->if_obytes += m->m_pkthdr.len;
|
1995-09-25 16:57:54 +00:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (ifp->if_bpf) {
|
|
|
|
/*
|
|
|
|
* We need to prepend the packet type as
|
|
|
|
* a two byte field. Cons up a dummy header
|
|
|
|
* to pacify bpf. This is safe because bpf
|
|
|
|
* will only read from the mbuf (i.e., it won't
|
|
|
|
* try to free it or keep a pointer to it).
|
|
|
|
*/
|
|
|
|
struct mbuf m0;
|
|
|
|
u_short hdr = 0x800;
|
|
|
|
|
|
|
|
m0.m_next = m;
|
|
|
|
m0.m_len = 2;
|
|
|
|
m0.m_data = (char *)&hdr;
|
|
|
|
|
1996-02-06 18:51:28 +00:00
|
|
|
bpf_mtap(ifp, &m0);
|
1995-09-25 16:57:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
1994-08-13 00:37:03 +00:00
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
1994-08-13 00:37:03 +00:00
|
|
|
m_freem(m);
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
if (inb(lpt_stat_port) & LPIP_SHAKE) {
|
1998-12-10 01:42:32 +00:00
|
|
|
lprintf(("^"));
|
1994-08-13 00:37:03 +00:00
|
|
|
lptintr(ifp->if_unit);
|
|
|
|
}
|
1995-05-09 01:33:16 +00:00
|
|
|
|
|
|
|
(void) splx(s);
|
1994-08-13 00:37:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* INET */
|
|
|
|
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
static lpt_devsw_installed = 0;
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
static void lpt_drvinit(void *unused)
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
{
|
1995-11-29 10:49:16 +00:00
|
|
|
dev_t dev;
|
|
|
|
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
if( ! lpt_devsw_installed ) {
|
1995-12-08 11:19:42 +00:00
|
|
|
dev = makedev(CDEV_MAJOR, 0);
|
|
|
|
cdevsw_add(&dev,&lpt_cdevsw, NULL);
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
lpt_devsw_installed = 1;
|
1995-11-29 14:41:20 +00:00
|
|
|
}
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
}
|
1995-11-29 10:49:16 +00:00
|
|
|
|
|
|
|
SYSINIT(lptdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,lpt_drvinit,NULL)
|
|
|
|
|