diff options
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/arc/arc/conf.c | 22 | ||||
-rw-r--r-- | sys/arch/arc/conf/ARCTIC | 10 | ||||
-rw-r--r-- | sys/arch/arc/conf/GENERIC | 16 | ||||
-rw-r--r-- | sys/arch/arc/conf/PICA | 10 | ||||
-rw-r--r-- | sys/arch/arc/conf/files.arc | 25 | ||||
-rw-r--r-- | sys/arch/arc/dev/ace.c | 1810 | ||||
-rw-r--r-- | sys/arch/arc/dev/lpr.c | 675 | ||||
-rw-r--r-- | sys/arch/arc/include/bus.h | 206 | ||||
-rw-r--r-- | sys/arch/arc/include/bus.old.h | 140 | ||||
-rw-r--r-- | sys/arch/arc/isa/isabus.c | 11 | ||||
-rw-r--r-- | sys/arch/arc/pica/lpt_pica.c | 180 |
11 files changed, 331 insertions, 2774 deletions
diff --git a/sys/arch/arc/arc/conf.c b/sys/arch/arc/arc/conf.c index 127275e2b09..b672b1ce664 100644 --- a/sys/arch/arc/arc/conf.c +++ b/sys/arch/arc/arc/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.10 1996/11/25 14:52:57 niklas Exp $ */ +/* $OpenBSD: conf.c,v 1.11 1996/11/28 23:35:38 niklas Exp $ */ /* * Copyright (c) 1992, 1993 @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * from: @(#)conf.c 8.2 (Berkeley) 11/14/93 - * $Id: conf.c,v 1.10 1996/11/25 14:52:57 niklas Exp $ + * $Id: conf.c,v 1.11 1996/11/28 23:35:38 niklas Exp $ */ #include <sys/param.h> @@ -101,7 +101,7 @@ int nblkdev = sizeof (bdevsw) / sizeof (bdevsw[0]); dev_init(c,n,tty), ttselect, dev_init(c,n,mmap), D_TTY } /* open, close, write, ioctl */ -#define cdev_lpr_init(c,n) { \ +#define cdev_lpt_init(c,n) { \ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ 0, seltrue, (dev_type_mmap((*))) enodev } @@ -136,10 +136,10 @@ bdev_decl(fd); cdev_decl(vnd); #include "bpfilter.h" cdev_decl(bpf); -#include "ace.h" -cdev_decl(ace); -#include "lpr.h" -cdev_decl(lpr); +#include "com.h" +cdev_decl(com); +#include "lpt.h" +cdev_decl(lpt); cdev_decl(sd); #include "pc.h" cdev_decl(pc); @@ -176,8 +176,8 @@ struct cdevsw cdevsw[] = cdev_disk_init(NFDC,fd), /* 13: Floppy disk */ cdev_pc_init(NPC,pc), /* 14: builtin pc style console dev */ cdev_mouse_init(1,pms), /* 15: builtin PS2 style mouse */ - cdev_lpr_init(NLPR,lpr), /* 16: lpr parallel printer interface */ - cdev_tty_init(NACE,ace), /* 17: ace 16C450 serial interface */ + cdev_lpt_init(NLPT,lpt), /* 16: Parallel printer interface */ + cdev_tty_init(NCOM,com), /* 17: 16C450 serial interface */ cdev_disk_init(NWDC,wd), /* 18: ST506/ESDI/IDE disk */ cdev_disk_init(NACD,acd), /* 19: ATAPI CD-ROM */ cdev_tty_init(NPTY,pts), /* 20: pseudo-tty slave */ @@ -346,14 +346,14 @@ blktochr(dev) #include <dev/cons.h> cons_decl(pc); -cons_decl(ace); +cons_decl(com); struct consdev constab[] = { #if NPC + NVT > 0 cons_init(pc), #endif #if NACE > 0 - cons_init(ace), + cons_init(com), #endif { 0 }, }; diff --git a/sys/arch/arc/conf/ARCTIC b/sys/arch/arc/conf/ARCTIC index a478e303171..3cf92e7a97f 100644 --- a/sys/arch/arc/conf/ARCTIC +++ b/sys/arch/arc/conf/ARCTIC @@ -1,4 +1,4 @@ -# $OpenBSD: ARCTIC,v 1.4 1996/11/12 08:44:08 niklas Exp $ +# $OpenBSD: ARCTIC,v 1.5 1996/11/28 23:35:39 niklas Exp $ # # Generic configuration file for MIPS R4x00 ARC Systems # @@ -82,10 +82,10 @@ isa* at isabr? clock0 at isa? port 0x70 irq 0 pc0 at isa? port 0x60 irq 1 # generic PC console device -ace0 at isa? port 0x3f8 irq 4 -ace1 at isa? port 0x2f8 irq 3 -ace2 at isa? port 0x3e8 irq 4 -ace3 at isa? port 0x2e8 irq 3 +com0 at isa? port 0x3f8 irq 4 +com1 at isa? port 0x2f8 irq 3 +com2 at isa? port 0x3e8 irq 4 +com3 at isa? port 0x2e8 irq 3 wdc0 at isa? port 0x1f0 irq 14 # ST506, ESDI, and IDE controllers wdc1 at isa? port 0x170 irq 15 diff --git a/sys/arch/arc/conf/GENERIC b/sys/arch/arc/conf/GENERIC index 19d770cda95..fe9b4f17d34 100644 --- a/sys/arch/arc/conf/GENERIC +++ b/sys/arch/arc/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.10 1996/10/01 21:26:03 pefo Exp $ +# $OpenBSD: GENERIC,v 1.11 1996/11/28 23:35:39 niklas Exp $ # # Generic configuration file for MIPS R4x00 ARC Systems # @@ -77,9 +77,9 @@ isabr* at mainbus0 clock0 at pica? pc0 at pica? pms0 at pica? -ace0 at pica? -ace1 at pica? -lpr0 at pica? +com0 at pica? +com1 at pica? +lpt0 at pica? sn0 at pica? fdc0 at pica? @@ -97,10 +97,10 @@ isa* at isabr? clock0 at isa? port 0x70 irq 0 pc0 at isa? port 0x60 irq 1 # generic PC console device -ace0 at isa? port 0x3f8 irq 4 -ace1 at isa? port 0x2f8 irq 3 -ace2 at isa? port 0x3e8 irq 4 -ace3 at isa? port 0x2e8 irq 3 +com0 at isa? port 0x3f8 irq 4 +com1 at isa? port 0x2f8 irq 3 +com2 at isa? port 0x3e8 irq 4 +com3 at isa? port 0x2e8 irq 3 wdc0 at isa? port 0x1f0 irq 14 # ST506, ESDI, and IDE controllers #wdc1 at isa? port 0x170 irq 15 diff --git a/sys/arch/arc/conf/PICA b/sys/arch/arc/conf/PICA index 600d6c92e4e..ecebd4bca9b 100644 --- a/sys/arch/arc/conf/PICA +++ b/sys/arch/arc/conf/PICA @@ -71,9 +71,9 @@ pica* at mainbus0 clock0 at pica? pc0 at pica? pms0 at pica? -ace0 at pica? -ace1 at pica? -lpr0 at pica? +com0 at pica? +com1 at pica? +lpt0 at pica? sn0 at pica? fdc0 at pica? @@ -96,8 +96,8 @@ isabr* at mainbus0 isa* at isabr? -ace2 at isa? port 0x3f8 irq 4 -ace3 at isa? port 0x2f8 irq 3 +com2 at isa? port 0x3f8 irq 4 +com3 at isa? port 0x2f8 irq 3 pseudo-device sl 2 # serial-line IP ports diff --git a/sys/arch/arc/conf/files.arc b/sys/arch/arc/conf/files.arc index 328e71ec28d..8eddba00822 100644 --- a/sys/arch/arc/conf/files.arc +++ b/sys/arch/arc/conf/files.arc @@ -1,4 +1,4 @@ -# $OpenBSD: files.arc,v 1.8 1996/09/24 21:30:00 niklas Exp $ +# $OpenBSD: files.arc,v 1.9 1996/11/28 23:35:40 niklas Exp $ # # maxpartitions must be first item in files.${ARCH} # @@ -56,7 +56,8 @@ file arch/arc/pica/picabus.c pica device isabr {} : isabus attach isabr at mainbus file arch/arc/isa/isabus.c isabr -file arch/arc/isa/isadma.c isadma needs-flag +#file arch/arc/isa/isadma.c isadma needs-flag +file dev/isa/isadma.c isadma needs-flag # Ethernet chip device sn @@ -105,24 +106,14 @@ device pms: tty attach pms at pica file arch/arc/dev/pccons.c pc & (pc_pica | pc_isa) needs-flag -# Serial driver for both ISA and LOCAL bus. -device ace: tty -attach ace at isa with ace_isa -attach ace at commulti with ace_commulti -attach ace at pica with ace_pica -file arch/arc/dev/ace.c ace & (ace_isa | ace_commulti | ace_pica) needs-flag - -# Parallel ports (XXX what chip?) -device lpr -attach lpr at isa with lpr_isa -attach lpr at pica with lpr_pica -file arch/arc/dev/lpr.c lpr & (lpr_isa | lpr_pica) needs-flag - # BusLogic BT-445C VLB SCSI Controller. Special on TYNE local bus. device btl: scsi attach btl at isa file arch/arc/dti/btl.c btl needs-count +# 8250/16[45]50-based "com" ports +attach com at pica with com_pica + # National Semiconductor DS8390/WD83C690-based boards # (WD/SMC 80x3 family, SMC Ultra [8216], 3Com 3C503, NE[12]000, and clones) # XXX conflicts with other ports; can't be in files.isa @@ -131,6 +122,10 @@ attach ed at isa with ed_isa attach ed at pcmcia with ed_pcmcia file dev/isa/if_ed.c ed & (ed_isa | ed_pcmcia) needs-flag +# PC parallel ports (XXX what chip?) +attach lpt at pica with lpt_pica +file arch/arc/pica/lpt_pica.c lpt_pica + # file dev/cons.c diff --git a/sys/arch/arc/dev/ace.c b/sys/arch/arc/dev/ace.c deleted file mode 100644 index f5e22feb9a9..00000000000 --- a/sys/arch/arc/dev/ace.c +++ /dev/null @@ -1,1810 +0,0 @@ -/* $OpenBSD: ace.c,v 1.7 1996/11/12 20:29:53 niklas Exp $ */ -/* $NetBSD: com.c,v 1.82.4.1 1996/06/02 09:08:00 mrg Exp $ */ - -/*- - * Copyright (c) 1993, 1994, 1995, 1996 - * Charles M. Hannum. All rights reserved. - * Copyright (c) 1991 The Regents of the University of California. - * 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 by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. - * - * @(#)com.c 7.5 (Berkeley) 5/16/91 - */ - -/* - * ACE driver, based on HP dca driver - * uses National Semiconductor NS16450/NS16550AF UART - */ -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/ioctl.h> -#include <sys/select.h> -#include <sys/tty.h> -#include <sys/proc.h> -#include <sys/user.h> -#include <sys/conf.h> -#include <sys/file.h> -#include <sys/uio.h> -#include <sys/kernel.h> -#include <sys/syslog.h> -#include <sys/types.h> -#include <sys/device.h> - -#include <arc/arc/arctype.h> -#include <machine/bus.old.h> -#include <machine/intr.h> - -#include <dev/isa/isavar.h> -#include <dev/isa/comreg.h> -#include <dev/isa/comvar.h> -#include <dev/ic/ns16550reg.h> -#ifdef COM_HAYESP -#include <dev/ic/hayespreg.h> -#endif -#define com_lcr com_cfcr - -#include "ace.h" - - -#define COM_IBUFSIZE (2 * 512) -#define COM_IHIGHWATER ((3 * COM_IBUFSIZE) / 4) - -struct com_softc { - struct device sc_dev; - void *sc_ih; - bus_chipset_tag_t sc_bc; - struct tty *sc_tty; - - int sc_overflows; - int sc_floods; - int sc_errors; - - int sc_halt; - - int sc_iobase; -#ifdef COM_HAYESP - int sc_hayespbase; -#endif - - bus_io_handle_t sc_ioh; - bus_io_handle_t sc_hayespioh; - - u_char sc_hwflags; -#define COM_HW_NOIEN 0x01 -#define COM_HW_FIFO 0x02 -#define COM_HW_HAYESP 0x04 -#define COM_HW_ABSENT_PENDING 0x08 /* reattached, awaiting close/reopen */ -#define COM_HW_ABSENT 0x10 /* configure actually failed, or removed */ -#define COM_HW_REATTACH 0x20 /* reattaching */ -#define COM_HW_CONSOLE 0x40 - u_char sc_swflags; -#define COM_SW_SOFTCAR 0x01 -#define COM_SW_CLOCAL 0x02 -#define COM_SW_CRTSCTS 0x04 -#define COM_SW_MDMBUF 0x08 - u_char sc_msr, sc_mcr, sc_lcr, sc_ier; - u_char sc_dtr; - - u_char sc_cua; - - u_char *sc_ibuf, *sc_ibufp, *sc_ibufhigh, *sc_ibufend; - u_char sc_ibufs[2][COM_IBUFSIZE]; -}; - -#ifdef COM_HAYESP -int comprobeHAYESP __P((bus_io_handle_t hayespioh, struct com_softc *sc)); -#endif -void comdiag __P((void *)); -int comspeed __P((long)); -int comparam __P((struct tty *, struct termios *)); -void comstart __P((struct tty *)); -void compoll __P((void *)); - -/* XXX: These belong elsewhere */ -cdev_decl(com); -bdev_decl(com); - -struct consdev; -void acecnprobe __P((struct consdev *)); -void acecninit __P((struct consdev *)); -int acecngetc __P((dev_t)); -void acecnputc __P((dev_t, int)); -void acecnpollc __P((dev_t, int)); - -static u_char tiocm_xxx2mcr __P((int)); - -/* - * XXX the following two cfattach structs should be different, and possibly - * XXX elsewhere. - */ -int comprobe __P((struct device *, void *, void *)); -void comattach __P((struct device *, struct device *, void *)); -void com_absent_notify __P((struct com_softc *sc)); -void comstart_pending __P((void *)); - -#if NACE_ISA -struct cfattach ace_isa_ca = { - sizeof(struct com_softc), comprobe, comattach -}; -#endif - -#if NACE_COMMULTI -struct cfattach ace_commulti_ca = { - sizeof(struct com_softc), comprobe, comattach -}; -#endif - -#if NACE_PICA -#undef CONADDR /* This is stupid but using devs before config .. */ -#define CONADDR 0xe0006000 - -struct cfattach ace_pica_ca = { - sizeof(struct com_softc), comprobe, comattach -}; -#endif - - -struct cfdriver ace_cd = { - NULL, "ace", DV_TTY -}; - -void cominit __P((bus_chipset_tag_t, bus_io_handle_t, int)); - -#ifndef CONSPEED -#define CONSPEED B9600 -#endif - -#ifdef COMCONSOLE -int comdefaultrate = CONSPEED; /* XXX why set default? */ -#else -int comdefaultrate = TTYDEF_SPEED; -#endif -int comconsaddr; -int comconsinit; -int comconsattached; -bus_chipset_tag_t comconsbc; -bus_io_handle_t comconsioh; -tcflag_t comconscflag = TTYDEF_CFLAG; - -int commajor; -int comsopen = 0; -int comevents = 0; - -#ifdef KGDB -#include <machine/remote-sl.h> -extern int kgdb_dev; -extern int kgdb_rate; -extern int kgdb_debug_init; -#endif - -#define DEVUNIT(x) (minor(x) & 0x7f) -#define DEVCUA(x) (minor(x) & 0x80) - -/* Macros to clear/set/test flags. */ -#define SET(t, f) (t) |= (f) -#define CLR(t, f) (t) &= ~(f) -#define ISSET(t, f) ((t) & (f)) - -#if NACE_PCMCIA -#include <dev/pcmcia/pcmciavar.h> - -int com_pcmcia_match __P((struct device *, void *, void *)); -void com_pcmcia_attach __P((struct device *, struct device *, void *)); -int com_pcmcia_detach __P((struct device *)); - -struct cfattach ace_pcmcia_ca = { - sizeof(struct com_softc), com_pcmcia_match, comattach, - com_pcmcia_detach -}; - -int com_pcmcia_mod __P((struct pcmcia_link *pc_link, struct device *self, - struct pcmcia_conf *pc_cf, struct cfdata *cf)); - -/* additional setup needed for pcmcia devices */ -/* modify config entry */ -int -com_pcmcia_mod(pc_link, self, pc_cf, cf) - struct pcmcia_link *pc_link; - struct device *self; - struct pcmcia_conf *pc_cf; - struct cfdata *cf; -{ - int err; - struct pcmciadevs *dev = pc_link->device; - struct ed_softc *sc = (void *)self; - if (!(err = PCMCIA_BUS_CONFIG(pc_link->adapter, pc_link, self, - pc_cf, cf))) { - pc_cf->memwin = 0; - if (pc_cf->cfgtype == 0) - pc_cf->cfgtype = CFGENTRYID; /* determine from ioaddr */ - } - return err; -} - -int com_pcmcia_isa_attach __P((struct device *, void *, void *, - struct pcmcia_link *)); -int com_pcmcia_remove __P((struct pcmcia_link *, struct device *)); - -static struct pcmcia_com { - struct pcmcia_device pcd; -} pcmcia_com = { - {"PCMCIA Modem card", com_pcmcia_mod, com_pcmcia_isa_attach, - NULL, com_pcmcia_remove} -}; - - -struct pcmciadevs pcmcia_com_devs[] = { - { "com", 0, - NULL, "*MODEM*", NULL, NULL, - NULL, (void *)&pcmcia_com - }, - { "com", 0, - NULL, NULL, "*MODEM*", NULL, - NULL, (void *)&pcmcia_com - }, - { "com", 0, - NULL, NULL, NULL, "*MODEM*", - NULL, (void *)&pcmcia_com - }, - {NULL} -}; -#define ncom_pcmcia_devs sizeof(pcmcia_com_devs)/sizeof(pcmcia_com_devs[0]) - -int -com_pcmcia_match(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - return pcmcia_slave_match(parent, match, aux, pcmcia_com_devs, - ncom_pcmcia_devs); -} - -int -com_pcmcia_isa_attach(parent, match, aux, pc_link) - struct device *parent; - void *match; - void *aux; - struct pcmcia_link *pc_link; -{ - struct isa_attach_args *ia = aux; - struct com_softc *sc = match; - - int rval; - if (rval = comprobe(parent, sc->sc_dev.dv_cfdata, ia)) { - if (ISSET(pc_link->flags, PCMCIA_REATTACH)) { -#ifdef COM_DEBUG - printf("comreattach, hwflags=%x\n", sc->sc_hwflags); -#endif - sc->sc_hwflags = COM_HW_REATTACH | - (sc->sc_hwflags & (COM_HW_ABSENT_PENDING|COM_HW_CONSOLE)); - } else - sc->sc_hwflags = 0; - } - return rval; -} - - -/* - * Called by config_detach attempts, shortly after com_pcmcia_remove - * was called. - */ -int -com_pcmcia_detach(self) - struct device *self; -{ - struct com_softc *sc = (void *)self; - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT_PENDING)) { - /* don't let it really be detached, it is still open */ - return EBUSY; - } - return 0; /* OK! */ -} - -/* - * called by pcmcia framework to accept/reject remove attempts. - * If we return 0, then the detach will proceed. - */ -int -com_pcmcia_remove(pc_link, self) - struct pcmcia_link *pc_link; - struct device *self; -{ - struct com_softc *sc = (void *)self; - struct tty *tp; - int s; - - if (!sc->sc_tty) - goto ok; - tp = sc->sc_tty; - - /* not in use ? if so, return "OK" */ - if (!ISSET(tp->t_state, TS_ISOPEN) && - !ISSET(tp->t_state, TS_WOPEN)) { - ttyfree(sc->sc_tty); - sc->sc_tty = NULL; - ok: - isa_intr_disestablish(sc->sc_bc, sc->sc_ih); - sc->sc_ih = NULL; - SET(sc->sc_hwflags, COM_HW_ABSENT); - return 0; /* OK! */ - } - /* - * Not easily removed. Put device into a dead state, clean state - * as best we can. notify all waiters. - */ - SET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING); -#ifdef COM_DEBUG - printf("pending detach flags %x\n", sc->sc_hwflags); -#endif - - s = spltty(); - com_absent_notify(sc); - splx(s); - - return 0; -} - -#if 0 -void -com_pcmcia_attach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct pcmcia_attach_args *paa = aux; - - printf("com_pcmcia_attach %p %p %p\n", parent, self, aux); - delay(2000000); - if (!pcmcia_configure(parent, self, paa->paa_link)) { - struct com_softc *sc = (void *)self; - sc->sc_hwflags |= COM_HW_ABSENT; - printf(": not attached\n"); - } -} -#endif -#endif - -/* - * must be called at spltty() or higher. - */ -void -com_absent_notify(sc) - struct com_softc *sc; -{ - struct tty *tp = sc->sc_tty; - - if (tp) { - CLR(tp->t_state, TS_CARR_ON|TS_BUSY); - ttyflush(tp, FREAD|FWRITE); - } -} - -int -comspeed(speed) - long speed; -{ -#define divrnd(n, q) (((n)*2/(q)+1)/2) /* divide and round off */ - - int x, err; - - if (speed == 0) - return 0; - if (speed < 0) - return -1; - x = divrnd((COM_FREQ / 16), speed); - if (x <= 0) - return -1; - err = divrnd((COM_FREQ / 16) * 1000, speed * x) - 1000; - if (err < 0) - err = -err; - if (err > COM_TOLERANCE) - return -1; - return x; - -#undef divrnd(n, q) -} - -int -comprobe1(bc, ioh, iobase) - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - int iobase; -{ - int i, k; - - /* force access to id reg */ - bus_io_write_1(bc, ioh, com_lcr, 0); - bus_io_write_1(bc, ioh, com_iir, 0); - for (i = 0; i < 32; i++) { - k = bus_io_read_1(bc, ioh, com_iir); - if (k & 0x38) { - bus_io_read_1(bc, ioh, com_data); /* cleanup */ - } else - break; - } - if (i >= 32) - return 0; - - return 1; -} - -#ifdef COM_HAYESP -int -comprobeHAYESP(hayespioh, sc) - bus_io_handle_t hayespioh; - struct com_softc *sc; -{ - char val, dips; - int combaselist[] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 }; - bus_chipset_tag_t bc = sc->sc_bc; - - /* - * Hayes ESP cards have two iobases. One is for compatibility with - * 16550 serial chips, and at the same ISA PC base addresses. The - * other is for ESP-specific enhanced features, and lies at a - * different addressing range entirely (0x140, 0x180, 0x280, or 0x300). - */ - - /* Test for ESP signature */ - if ((bus_io_read_1(bc, hayespioh, 0) & 0xf3) == 0) - return 0; - - /* - * ESP is present at ESP enhanced base address; unknown com port - */ - - /* Get the dip-switch configurations */ - bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_GETDIPS); - dips = bus_io_read_1(bc, hayespioh, HAYESP_STATUS1); - - /* Determine which com port this ESP card services: bits 0,1 of */ - /* dips is the port # (0-3); combaselist[val] is the com_iobase */ - if (sc->sc_iobase != combaselist[dips & 0x03]) - return 0; - - printf(": ESP"); - - /* Check ESP Self Test bits. */ - /* Check for ESP version 2.0: bits 4,5,6 == 010 */ - bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_GETTEST); - val = bus_io_read_1(bc, hayespioh, HAYESP_STATUS1); /* Clear reg 1 */ - val = bus_io_read_1(bc, hayespioh, HAYESP_STATUS2); - if ((val & 0x70) < 0x20) { - printf("-old (%o)", val & 0x70); - /* we do not support the necessary features */ - return 0; - } - - /* Check for ability to emulate 16550: bit 8 == 1 */ - if ((dips & 0x80) == 0) { - printf(" slave"); - /* XXX Does slave really mean no 16550 support?? */ - return 0; - } - - /* - * If we made it this far, we are a full-featured ESP v2.0 (or - * better), at the correct com port address. - */ - - SET(sc->sc_hwflags, COM_HW_HAYESP); - printf(", 1024 byte fifo\n"); - return 1; -} -#endif - -int -comprobe(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - int iobase, needioh; - int rv = 1; - -#if NACE_ISA || NACE_PCMCIA -#define IS_ISA(parent) \ - (!strcmp((parent)->dv_cfdata->cf_driver->cd_name, "isa") || \ - !strcmp((parent)->dv_cfdata->cf_driver->cd_name, "pcmcia")) -#elif NACE_ISA -#define IS_ISA(parent) \ - !strcmp((parent)->dv_cfdata->cf_driver->cd_name, "isa") -#endif -#if NACE_PICA -#define IS_PICA(parent) \ - !strcmp((parent)->dv_cfdata->cf_driver->cd_name, "pica") -#endif - /* - * XXX should be broken out into functions for isa probe and - * XXX for commulti probe, with a helper function that contains - * XXX most of the interesting stuff. - */ -#if NACE_ISA || NACE_PCMCIA - if (IS_ISA(parent)) { - struct isa_attach_args *ia = aux; - - bc = ia->ia_bc; - iobase = ia->ia_iobase; - needioh = 1; - } else -#endif -#if NACE_PICA - if(IS_PICA(parent)) { - struct confargs *ca = aux; - if(!BUS_MATCHNAME(ca, "com")) - return(0); - iobase = (long)BUS_CVTADDR(ca); - bc = 0; - needioh = 1; - } else -#endif -#if NACE_COMMULTI - if (1) { - struct cfdata *cf = match; - struct commulti_attach_args *ca = aux; - - if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != ca->ca_slave) - return (0); - - bc = ca->ca_bc; - iobase = ca->ca_iobase; - ioh = ca->ca_ioh; - needioh = 0; - } else -#endif - return(0); /* This cannot happen */ - - /* if it's in use as console, it's there. */ - if (iobase == comconsaddr && !comconsattached) - goto out; - - if (needioh && bus_io_map(bc, iobase, COM_NPORTS, &ioh)) { - rv = 0; - goto out; - } - rv = comprobe1(bc, ioh, iobase); - if (needioh) - bus_io_unmap(bc, ioh, COM_NPORTS); - -out: -#if NACE_ISA || NACE_PCMCIA - if (rv && IS_ISA(parent)) { - struct isa_attach_args *ia = aux; - - ia->ia_iosize = COM_NPORTS; - ia->ia_msize = 0; - } -#endif - return (rv); -} - -void -comattach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct com_softc *sc = (void *)self; - int iobase, irq; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; -#ifdef COM_HAYESP - int hayesp_ports[] = { 0x140, 0x180, 0x280, 0x300, 0 }; - int *hayespp; -#endif - - /* - * XXX should be broken out into functions for isa attach and - * XXX for commulti attach, with a helper function that contains - * XXX most of the interesting stuff. - */ - if (ISSET(sc->sc_hwflags, COM_HW_REATTACH)) { - int s; - s = spltty(); - com_absent_notify(sc); - splx(s); - } else - sc->sc_hwflags = 0; - sc->sc_swflags = 0; -#if NACE_ISA || NACE_PCMCIA - if (IS_ISA(parent)) { - struct isa_attach_args *ia = aux; - - /* - * We're living on an isa. - */ - iobase = ia->ia_iobase; - bc = ia->ia_bc; - if (iobase != comconsaddr) { - if (bus_io_map(bc, iobase, COM_NPORTS, &ioh)) - panic("comattach: io mapping failed"); - } else - ioh = comconsioh; - irq = ia->ia_irq; - } else -#endif -#if NACE_PICA - if(IS_PICA(parent)) { - struct confargs *ca = aux; - iobase = (long)BUS_CVTADDR(ca); - bc = 0; - irq = 0; - ioh = iobase; - } else -#endif -#if NACE_COMMULTI - if (1) { - struct commulti_attach_args *ca = aux; - - /* - * We're living on a commulti. - */ - iobase = ca->ca_iobase; - bc = ca->ca_bc; - ioh = ca->ca_ioh; - irq = IRQUNK; - - if (ca->ca_noien) - SET(sc->sc_hwflags, COM_HW_NOIEN); - } else -#endif - panic("comattach: impossible"); - - sc->sc_bc = bc; - sc->sc_ioh = ioh; - sc->sc_iobase = iobase; - - if (iobase == comconsaddr) { - comconsattached = 1; - - /* - * Need to reset baud rate, etc. of next print so reset - * comconsinit. Also make sure console is always "hardwired". - */ - delay(1000); /* wait for output to finish */ - comconsinit = 0; - SET(sc->sc_hwflags, COM_HW_CONSOLE); - SET(sc->sc_swflags, COM_SW_SOFTCAR); - } - -#ifdef COM_HAYESP - /* Look for a Hayes ESP board. */ - for (hayespp = hayesp_ports; *hayespp != 0; hayespp++) { - bus_io_handle_t hayespioh; - -#define HAYESP_NPORTS 8 /* XXX XXX XXX ??? ??? ??? */ - if (bus_io_map(bc, *hayespp, HAYESP_NPORTS, &hayespioh)) - continue; - if (comprobeHAYESP(hayespioh, sc)) { - sc->sc_hayespbase = *hayespp; - sc->sc_hayespioh = hayespioh; - break; - } - bus_io_unmap(bc, hayespioh, HAYESP_NPORTS); - } - /* No ESP; look for other things. */ - if (*hayespp == 0) { -#endif - - /* look for a NS 16550AF UART with FIFOs */ - bus_io_write_1(bc, ioh, com_fifo, - FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_14); - delay(100); - if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_FIFO_MASK) == - IIR_FIFO_MASK) - if (ISSET(bus_io_read_1(bc, ioh, com_fifo), FIFO_TRIGGER_14) == - FIFO_TRIGGER_14) { - SET(sc->sc_hwflags, COM_HW_FIFO); - printf(": ns16550a, working fifo\n"); - } else - printf(": ns16550, broken fifo\n"); - else - printf(": ns8250 or ns16450, no fifo\n"); - bus_io_write_1(bc, ioh, com_fifo, 0); -#ifdef COM_HAYESP - } -#endif - - /* disable interrupts */ - bus_io_write_1(bc, ioh, com_ier, 0); - bus_io_write_1(bc, ioh, com_mcr, 0); - - if (irq != IRQUNK) { -#if NACE_ISA || NACE_PCMCIA - if (IS_ISA(parent)) { - struct isa_attach_args *ia = aux; - - sc->sc_ih = isa_intr_establish(ia->ia_ic, irq, - IST_EDGE, IPL_TTY, comintr, sc, - sc->sc_dev.dv_xname); - } else -#endif -#if NACE_PICA - if (IS_PICA(parent)) { - struct confargs *ca = aux; - BUS_INTR_ESTABLISH(ca, comintr, (void *)(long)sc); - } else -#endif - panic("comattach: IRQ but can't have one"); - } - -#ifdef KGDB - if (kgdb_dev == makedev(commajor, unit)) { - if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) - kgdb_dev = -1; /* can't debug over console port */ - else { - cominit(bc, ioh, kgdb_rate); - if (kgdb_debug_init) { - /* - * Print prefix of device name, - * let kgdb_connect print the rest. - */ - printf("%s: ", sc->sc_dev.dv_xname); - kgdb_connect(1); - } else - printf("%s: kgdb enabled\n", - sc->sc_dev.dv_xname); - } - } -#endif - - /* XXX maybe move up some? */ - if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) - printf("%s: console\n", sc->sc_dev.dv_xname); -} - -int -aceopen(dev, flag, mode, p) - dev_t dev; - int flag, mode; - struct proc *p; -{ - int unit = DEVUNIT(dev); - struct com_softc *sc; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - struct tty *tp; - int s; - int error = 0; - - if (unit >= ace_cd.cd_ndevs) - return ENXIO; - sc = ace_cd.cd_devs[unit]; - if (!sc || ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) - return ENXIO; - - s = spltty(); - if (!sc->sc_tty) { - tp = sc->sc_tty = ttymalloc(); - tty_attach(tp); - } else - tp = sc->sc_tty; - splx(s); - - tp->t_oproc = comstart; - tp->t_param = comparam; - tp->t_dev = dev; - if (!ISSET(tp->t_state, TS_ISOPEN)) { - SET(tp->t_state, TS_WOPEN); - ttychars(tp); - tp->t_iflag = TTYDEF_IFLAG; - tp->t_oflag = TTYDEF_OFLAG; - if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) - tp->t_cflag = comconscflag; - else - tp->t_cflag = TTYDEF_CFLAG; - if (ISSET(sc->sc_swflags, COM_SW_CLOCAL)) - SET(tp->t_cflag, CLOCAL); - if (ISSET(sc->sc_swflags, COM_SW_CRTSCTS)) - SET(tp->t_cflag, CRTSCTS); - if (ISSET(sc->sc_swflags, COM_SW_MDMBUF)) - SET(tp->t_cflag, MDMBUF); - tp->t_lflag = TTYDEF_LFLAG; - tp->t_ispeed = tp->t_ospeed = comdefaultrate; - - s = spltty(); - - comparam(tp, &tp->t_termios); - ttsetwater(tp); - - if (comsopen++ == 0) - timeout(compoll, NULL, 1); - - sc->sc_ibufp = sc->sc_ibuf = sc->sc_ibufs[0]; - sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER; - sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE; - - bc = sc->sc_bc; - ioh = sc->sc_ioh; -#ifdef COM_HAYESP - /* Setup the ESP board */ - if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) { - bus_io_handle_t hayespioh = sc->sc_hayespioh; - - bus_io_write_1(bc, ioh, com_fifo, - FIFO_DMA_MODE|FIFO_ENABLE| - FIFO_RCV_RST|FIFO_XMT_RST|FIFO_TRIGGER_8); - - /* Set 16550 compatibility mode */ - bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETMODE); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, - HAYESP_MODE_FIFO|HAYESP_MODE_RTS| - HAYESP_MODE_SCALE); - - /* Set RTS/CTS flow control */ - bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETFLOWTYPE); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, HAYESP_FLOW_RTS); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, HAYESP_FLOW_CTS); - - /* Set flow control levels */ - bus_io_write_1(bc, hayespioh, HAYESP_CMD1, HAYESP_SETRXFLOW); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, - HAYESP_HIBYTE(HAYESP_RXHIWMARK)); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, - HAYESP_LOBYTE(HAYESP_RXHIWMARK)); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, - HAYESP_HIBYTE(HAYESP_RXLOWMARK)); - bus_io_write_1(bc, hayespioh, HAYESP_CMD2, - HAYESP_LOBYTE(HAYESP_RXLOWMARK)); - } else -#endif - if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) - /* Set the FIFO threshold based on the receive speed. */ - bus_io_write_1(bc, ioh, com_fifo, - FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | - (tp->t_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8)); - /* flush any pending I/O */ - while (ISSET(bus_io_read_1(bc, ioh, com_lsr), LSR_RXRDY)) - (void) bus_io_read_1(bc, ioh, com_data); - /* you turn me on, baby */ - sc->sc_mcr = MCR_DTR | MCR_RTS; - if (!ISSET(sc->sc_hwflags, COM_HW_NOIEN)) - SET(sc->sc_mcr, MCR_IENABLE); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - sc->sc_ier = IER_ERXRDY | IER_ERLS | IER_EMSC; - bus_io_write_1(bc, ioh, com_ier, sc->sc_ier); - - sc->sc_msr = bus_io_read_1(bc, ioh, com_msr); - if (ISSET(sc->sc_swflags, COM_SW_SOFTCAR) || DEVCUA(dev) || - ISSET(sc->sc_msr, MSR_DCD) || ISSET(tp->t_cflag, MDMBUF)) - SET(tp->t_state, TS_CARR_ON); - else - CLR(tp->t_state, TS_CARR_ON); - } else if (ISSET(tp->t_state, TS_XCLUDE) && p->p_ucred->cr_uid != 0) - return EBUSY; - else - s = spltty(); - - if (DEVCUA(dev)) { - if (ISSET(tp->t_state, TS_ISOPEN)) { - /* Ah, but someone already is dialed in... */ - splx(s); - return EBUSY; - } - sc->sc_cua = 1; /* We go into CUA mode */ - } - - /* wait for carrier if necessary */ - if (ISSET(flag, O_NONBLOCK)) { - if (!DEVCUA(dev) && sc->sc_cua) { - /* Opening TTY non-blocking... but the CUA is busy */ - splx(s); - return EBUSY; - } - } else { - while (!(DEVCUA(dev) && sc->sc_cua) && - !ISSET(tp->t_cflag, CLOCAL) && - !ISSET(tp->t_state, TS_CARR_ON)) { - SET(tp->t_state, TS_WOPEN); - error = ttysleep(tp, &tp->t_rawq, TTIPRI | PCATCH, - ttopen, 0); - if (error) { - /* XXX should turn off chip if we're the - only waiter */ - if (DEVCUA(dev)) - sc->sc_cua = 0; - splx(s); - return error; - } - } - } - splx(s); - - return (*linesw[tp->t_line].l_open)(dev, tp); -} - -int -aceclose(dev, flag, mode, p) - dev_t dev; - int flag, mode; - struct proc *p; -{ - int unit = DEVUNIT(dev); - struct com_softc *sc = ace_cd.cd_devs[unit]; - struct tty *tp = sc->sc_tty; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - int s; - - /* XXX This is for cons.c. */ - if (!ISSET(tp->t_state, TS_ISOPEN)) - return 0; - - (*linesw[tp->t_line].l_close)(tp, flag); - s = spltty(); - if (!ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - /* can't do any of this stuff .... */ - CLR(sc->sc_lcr, LCR_SBREAK); - bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr); - bus_io_write_1(bc, ioh, com_ier, 0); - if (ISSET(tp->t_cflag, HUPCL) && - !ISSET(sc->sc_swflags, COM_SW_SOFTCAR)) { - /* XXX perhaps only clear DTR */ - bus_io_write_1(bc, ioh, com_mcr, 0); - } - } - CLR(tp->t_state, TS_BUSY | TS_FLUSH); - if (--comsopen == 0) - untimeout(compoll, NULL); - sc->sc_cua = 0; - splx(s); - ttyclose(tp); -#ifdef COM_DEBUG - /* mark it ready for more use if reattached earlier */ - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT_PENDING)) { - printf("aceclose pending cleared\n"); - } -#endif - CLR(sc->sc_hwflags, COM_HW_ABSENT_PENDING); - -#ifdef notyet /* XXXX */ - if (ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) { - ttyfree(tp); - sc->sc_tty = 0; - } -#endif - return 0; -} - -int -aceread(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; -{ - struct com_softc *sc = ace_cd.cd_devs[DEVUNIT(dev)]; - struct tty *tp = sc->sc_tty; - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - int s = spltty(); - com_absent_notify(sc); - splx(s); - return EIO; - } - - return ((*linesw[tp->t_line].l_read)(tp, uio, flag)); -} - -int -acewrite(dev, uio, flag) - dev_t dev; - struct uio *uio; - int flag; -{ - struct com_softc *sc = ace_cd.cd_devs[DEVUNIT(dev)]; - struct tty *tp = sc->sc_tty; - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - int s = spltty(); - com_absent_notify(sc); - splx(s); - return EIO; - } - - return ((*linesw[tp->t_line].l_write)(tp, uio, flag)); -} - -struct tty * -acetty(dev) - dev_t dev; -{ - struct com_softc *sc = ace_cd.cd_devs[DEVUNIT(dev)]; - struct tty *tp = sc->sc_tty; - - return (tp); -} - -static u_char -tiocm_xxx2mcr(data) - int data; -{ - u_char m = 0; - - if (ISSET(data, TIOCM_DTR)) - SET(m, MCR_DTR); - if (ISSET(data, TIOCM_RTS)) - SET(m, MCR_RTS); - return m; -} - -int -aceioctl(dev, cmd, data, flag, p) - dev_t dev; - u_long cmd; - caddr_t data; - int flag; - struct proc *p; -{ - int unit = DEVUNIT(dev); - struct com_softc *sc = ace_cd.cd_devs[unit]; - struct tty *tp = sc->sc_tty; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - int error; - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - int s = spltty(); - com_absent_notify(sc); - splx(s); - return EIO; - } - - error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); - if (error >= 0) - return error; - error = ttioctl(tp, cmd, data, flag, p); - if (error >= 0) - return error; - - switch (cmd) { - case TIOCSBRK: - SET(sc->sc_lcr, LCR_SBREAK); - bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr); - break; - case TIOCCBRK: - CLR(sc->sc_lcr, LCR_SBREAK); - bus_io_write_1(bc, ioh, com_lcr, sc->sc_lcr); - break; - case TIOCSDTR: - SET(sc->sc_mcr, sc->sc_dtr); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - break; - case TIOCCDTR: - CLR(sc->sc_mcr, sc->sc_dtr); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - break; - case TIOCMSET: - CLR(sc->sc_mcr, MCR_DTR | MCR_RTS); - case TIOCMBIS: - SET(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data)); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - break; - case TIOCMBIC: - CLR(sc->sc_mcr, tiocm_xxx2mcr(*(int *)data)); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - break; - case TIOCMGET: { - u_char m; - int bits = 0; - - m = sc->sc_mcr; - if (ISSET(m, MCR_DTR)) - SET(bits, TIOCM_DTR); - if (ISSET(m, MCR_RTS)) - SET(bits, TIOCM_RTS); - m = sc->sc_msr; - if (ISSET(m, MSR_DCD)) - SET(bits, TIOCM_CD); - if (ISSET(m, MSR_CTS)) - SET(bits, TIOCM_CTS); - if (ISSET(m, MSR_DSR)) - SET(bits, TIOCM_DSR); - if (ISSET(m, MSR_RI | MSR_TERI)) - SET(bits, TIOCM_RI); - if (bus_io_read_1(bc, ioh, com_ier)) - SET(bits, TIOCM_LE); - *(int *)data = bits; - break; - } - case TIOCGFLAGS: { - int driverbits, userbits = 0; - - driverbits = sc->sc_swflags; - if (ISSET(driverbits, COM_SW_SOFTCAR)) - SET(userbits, TIOCFLAG_SOFTCAR); - if (ISSET(driverbits, COM_SW_CLOCAL)) - SET(userbits, TIOCFLAG_CLOCAL); - if (ISSET(driverbits, COM_SW_CRTSCTS)) - SET(userbits, TIOCFLAG_CRTSCTS); - if (ISSET(driverbits, COM_SW_MDMBUF)) - SET(userbits, TIOCFLAG_MDMBUF); - - *(int *)data = userbits; - break; - } - case TIOCSFLAGS: { - int userbits, driverbits = 0; - - error = suser(p->p_ucred, &p->p_acflag); - if (error != 0) - return(EPERM); - - userbits = *(int *)data; - if (ISSET(userbits, TIOCFLAG_SOFTCAR) || - ISSET(sc->sc_hwflags, COM_HW_CONSOLE)) - SET(driverbits, COM_SW_SOFTCAR); - if (ISSET(userbits, TIOCFLAG_CLOCAL)) - SET(driverbits, COM_SW_CLOCAL); - if (ISSET(userbits, TIOCFLAG_CRTSCTS)) - SET(driverbits, COM_SW_CRTSCTS); - if (ISSET(userbits, TIOCFLAG_MDMBUF)) - SET(driverbits, COM_SW_MDMBUF); - - sc->sc_swflags = driverbits; - break; - } - default: - return ENOTTY; - } - - return 0; -} - -int -comparam(tp, t) - struct tty *tp; - struct termios *t; -{ - struct com_softc *sc = ace_cd.cd_devs[DEVUNIT(tp->t_dev)]; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - int ospeed = comspeed(t->c_ospeed); - u_char lcr; - tcflag_t oldcflag; - int s; - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - int s = spltty(); - com_absent_notify(sc); - splx(s); - return EIO; - } - - /* check requested parameters */ - if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed)) - return EINVAL; - - lcr = ISSET(sc->sc_lcr, LCR_SBREAK); - - switch (ISSET(t->c_cflag, CSIZE)) { - case CS5: - SET(lcr, LCR_5BITS); - break; - case CS6: - SET(lcr, LCR_6BITS); - break; - case CS7: - SET(lcr, LCR_7BITS); - break; - case CS8: - SET(lcr, LCR_8BITS); - break; - } - if (ISSET(t->c_cflag, PARENB)) { - SET(lcr, LCR_PENAB); - if (!ISSET(t->c_cflag, PARODD)) - SET(lcr, LCR_PEVEN); - } - if (ISSET(t->c_cflag, CSTOPB)) - SET(lcr, LCR_STOPB); - - sc->sc_lcr = lcr; - - s = spltty(); - - if (ospeed == 0) { - CLR(sc->sc_mcr, MCR_DTR); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } - - /* - * Set the FIFO threshold based on the receive speed, if we are - * changing it. - */ -#if 0 /* XXX CHECK WHY SPEED IS NOT INIT CORRECTLY */ - if (tp->t_ispeed != t->c_ispeed) { -#else - if (1) { -#endif - if (ospeed != 0) { - /* - * Make sure the transmit FIFO is empty before - * proceeding. If we don't do this, some revisions - * of the UART will hang. Interestingly enough, - * even if we do this will the last character is - * still being pushed out, they don't hang. This - * seems good enough. - */ - while (ISSET(tp->t_state, TS_BUSY)) { - int error; - - ++sc->sc_halt; - error = ttysleep(tp, &tp->t_outq, - TTOPRI | PCATCH, "comprm", 0); - --sc->sc_halt; - if (error) { - splx(s); - comstart(tp); - return (error); - } - } - - bus_io_write_1(bc, ioh, com_lcr, lcr | LCR_DLAB); - bus_io_write_1(bc, ioh, com_dlbl, ospeed); - bus_io_write_1(bc, ioh, com_dlbh, ospeed >> 8); - bus_io_write_1(bc, ioh, com_lcr, lcr); - SET(sc->sc_mcr, MCR_DTR); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } else - bus_io_write_1(bc, ioh, com_lcr, lcr); - - if (!ISSET(sc->sc_hwflags, COM_HW_HAYESP) && - ISSET(sc->sc_hwflags, COM_HW_FIFO)) - bus_io_write_1(bc, ioh, com_fifo, - FIFO_ENABLE | - (t->c_ispeed <= 1200 ? FIFO_TRIGGER_1 : FIFO_TRIGGER_8)); - } else - bus_io_write_1(bc, ioh, com_lcr, lcr); - - /* When not using CRTSCTS, RTS follows DTR. */ - if (!ISSET(t->c_cflag, CRTSCTS)) { - if (ISSET(sc->sc_mcr, MCR_DTR)) { - if (!ISSET(sc->sc_mcr, MCR_RTS)) { - SET(sc->sc_mcr, MCR_RTS); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } - } else { - if (ISSET(sc->sc_mcr, MCR_RTS)) { - CLR(sc->sc_mcr, MCR_RTS); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } - } - sc->sc_dtr = MCR_DTR | MCR_RTS; - } else - sc->sc_dtr = MCR_DTR; - - /* and copy to tty */ - tp->t_ispeed = t->c_ispeed; - tp->t_ospeed = t->c_ospeed; - oldcflag = tp->t_cflag; - tp->t_cflag = t->c_cflag; - - /* - * If DCD is off and MDMBUF is changed, ask the tty layer if we should - * stop the device. - */ - if (!ISSET(sc->sc_msr, MSR_DCD) && - !ISSET(sc->sc_swflags, COM_SW_SOFTCAR) && - ISSET(oldcflag, MDMBUF) != ISSET(tp->t_cflag, MDMBUF) && - (*linesw[tp->t_line].l_modem)(tp, 0) == 0) { - CLR(sc->sc_mcr, sc->sc_dtr); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } - - /* Just to be sure... */ - splx(s); - comstart(tp); - return 0; -} - -void -comstart_pending(arg) - void *arg; -{ - struct com_softc *sc = arg; - int s; - - s = spltty(); - com_absent_notify(sc); - splx(s); -} - -void -comstart(tp) - struct tty *tp; -{ - struct com_softc *sc = ace_cd.cd_devs[DEVUNIT(tp->t_dev)]; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - int s; - - s = spltty(); - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT|COM_HW_ABSENT_PENDING)) { - /* - * not quite good enough: if caller is ttywait() it will - * go to sleep immediately, so hang out a bit and then - * prod caller again. - */ - com_absent_notify(sc); - timeout(comstart_pending, sc, 1); - goto out; - } - if (ISSET(tp->t_state, TS_BUSY)) - goto out; - if (ISSET(tp->t_state, TS_TIMEOUT | TS_TTSTOP) || - sc->sc_halt > 0) - goto stopped; - if (ISSET(tp->t_cflag, CRTSCTS) && !ISSET(sc->sc_msr, MSR_CTS)) - goto stopped; - if (tp->t_outq.c_cc <= tp->t_lowat) { - if (ISSET(tp->t_state, TS_ASLEEP)) { - CLR(tp->t_state, TS_ASLEEP); - wakeup(&tp->t_outq); - } - if (tp->t_outq.c_cc == 0) - goto stopped; - selwakeup(&tp->t_wsel); - } - SET(tp->t_state, TS_BUSY); - - if (!ISSET(sc->sc_ier, IER_ETXRDY)) { - SET(sc->sc_ier, IER_ETXRDY); - bus_io_write_1(bc, ioh, com_ier, sc->sc_ier); - } -#ifdef COM_HAYESP - if (ISSET(sc->sc_hwflags, COM_HW_HAYESP)) { - u_char buffer[1024], *cp = buffer; - int n = q_to_b(&tp->t_outq, cp, sizeof buffer); - do - bus_io_write_1(bc, ioh, com_data, *cp++); - while (--n); - } - else -#endif - if (ISSET(sc->sc_hwflags, COM_HW_FIFO)) { - u_char buffer[16], *cp = buffer; - int n = q_to_b(&tp->t_outq, cp, sizeof buffer); - do { - bus_io_write_1(bc, ioh, com_data, *cp++); - } while (--n); - } else - bus_io_write_1(bc, ioh, com_data, getc(&tp->t_outq)); -out: - splx(s); - return; -stopped: - if (ISSET(sc->sc_ier, IER_ETXRDY)) { - CLR(sc->sc_ier, IER_ETXRDY); - bus_io_write_1(bc, ioh, com_ier, sc->sc_ier); - } - splx(s); -} - -/* - * Stop output on a line. - */ -int -acestop(tp, flag) - struct tty *tp; - int flag; -{ - int s; - - s = spltty(); - if (ISSET(tp->t_state, TS_BUSY)) - if (!ISSET(tp->t_state, TS_TTSTOP)) - SET(tp->t_state, TS_FLUSH); - splx(s); - return 0; -} - -void -comdiag(arg) - void *arg; -{ - struct com_softc *sc = arg; - int overflows, floods; - int s; - - s = spltty(); - sc->sc_errors = 0; - overflows = sc->sc_overflows; - sc->sc_overflows = 0; - floods = sc->sc_floods; - sc->sc_floods = 0; - splx(s); - - log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf overflow%s\n", - sc->sc_dev.dv_xname, - overflows, overflows == 1 ? "" : "s", - floods, floods == 1 ? "" : "s"); -} - -void -compoll(arg) - void *arg; -{ - int unit; - struct com_softc *sc; - struct tty *tp; - register u_char *ibufp; - u_char *ibufend; - register int c; - int s; - static int lsrmap[8] = { - 0, TTY_PE, - TTY_FE, TTY_PE|TTY_FE, - TTY_FE, TTY_PE|TTY_FE, - TTY_FE, TTY_PE|TTY_FE - }; - - s = spltty(); - if (comevents == 0) { - splx(s); - goto out; - } - comevents = 0; - splx(s); - - for (unit = 0; unit < ace_cd.cd_ndevs; unit++) { - sc = ace_cd.cd_devs[unit]; - if (sc == 0 || sc->sc_ibufp == sc->sc_ibuf) - continue; - - tp = sc->sc_tty; - - s = spltty(); - - ibufp = sc->sc_ibuf; - ibufend = sc->sc_ibufp; - - if (ibufp == ibufend) { - splx(s); - continue; - } - - sc->sc_ibufp = sc->sc_ibuf = (ibufp == sc->sc_ibufs[0]) ? - sc->sc_ibufs[1] : sc->sc_ibufs[0]; - sc->sc_ibufhigh = sc->sc_ibuf + COM_IHIGHWATER; - sc->sc_ibufend = sc->sc_ibuf + COM_IBUFSIZE; - - if (tp == 0 || !ISSET(tp->t_state, TS_ISOPEN)) { - splx(s); - continue; - } - - if (ISSET(tp->t_cflag, CRTSCTS) && - !ISSET(sc->sc_mcr, MCR_RTS)) { - /* XXX */ - SET(sc->sc_mcr, MCR_RTS); - bus_io_write_1(sc->sc_bc, sc->sc_ioh, com_mcr, - sc->sc_mcr); - } - - splx(s); - - while (ibufp < ibufend) { - c = *ibufp++; - if (*ibufp & LSR_OE) { - sc->sc_overflows++; - if (sc->sc_errors++ == 0) - timeout(comdiag, sc, 60 * hz); - } - /* This is ugly, but fast. */ - c |= lsrmap[(*ibufp++ & (LSR_BI|LSR_FE|LSR_PE)) >> 2]; - (*linesw[tp->t_line].l_rint)(c, tp); - } - } - -out: - timeout(compoll, NULL, 1); -} - -int -comintr(arg) - void *arg; -{ - struct com_softc *sc = arg; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - struct tty *tp; - u_char lsr, data, msr, delta; -#ifdef COM_DEBUG - int n; - struct { - u_char iir, lsr, msr; - } iter[32]; -#endif - - if (ISSET(sc->sc_hwflags, COM_HW_ABSENT) || !sc->sc_tty) - return 0; /* can't do squat. */ - -#ifdef COM_DEBUG - n = 0; - if (ISSET(iter[n].iir = bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND)) - return (0); -#else - if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND)) - return (0); -#endif - - tp = sc->sc_tty; - - for (;;) { -#ifdef COM_DEBUG - iter[n].lsr = -#endif - lsr = bus_io_read_1(bc, ioh, com_lsr); - - if (ISSET(lsr, LSR_RXRDY)) { - register u_char *p = sc->sc_ibufp; - - comevents = 1; - do { - data = bus_io_read_1(bc, ioh, com_data); - if (ISSET(lsr, LSR_BI)) { -#ifdef notdef - printf("break %02x %02x %02x %02x\n", - sc->sc_msr, sc->sc_mcr, sc->sc_lcr, - sc->sc_dtr); -#endif -#ifdef DDB - if (ISSET(sc->sc_hwflags, - COM_HW_CONSOLE)) { - Debugger(); - goto next; - } -#endif - } - if (p >= sc->sc_ibufend) { - sc->sc_floods++; - if (sc->sc_errors++ == 0) - timeout(comdiag, sc, 60 * hz); - } else { - *p++ = data; - *p++ = lsr; - if (p == sc->sc_ibufhigh && - ISSET(tp->t_cflag, CRTSCTS)) { - /* XXX */ - CLR(sc->sc_mcr, MCR_RTS); - bus_io_write_1(bc, ioh, com_mcr, - sc->sc_mcr); - } - } - next: -#ifdef COM_DEBUG - if (++n >= 32) - goto ohfudge; - iter[n].lsr = -#endif - lsr = bus_io_read_1(bc, ioh, com_lsr); - } while (ISSET(lsr, LSR_RXRDY)); - - sc->sc_ibufp = p; - } -#ifdef COM_DEBUG - else if (ISSET(lsr, LSR_BI|LSR_FE|LSR_PE|LSR_OE)) - printf("weird lsr %02x\n", lsr); -#endif - -#ifdef COM_DEBUG - iter[n].msr = -#endif - msr = bus_io_read_1(bc, ioh, com_msr); - - if (msr != sc->sc_msr) { - delta = msr ^ sc->sc_msr; - sc->sc_msr = msr; - if (ISSET(delta, MSR_DCD) && - !ISSET(sc->sc_swflags, COM_SW_SOFTCAR) && - (*linesw[tp->t_line].l_modem)(tp, ISSET(msr, MSR_DCD)) == 0) { - CLR(sc->sc_mcr, sc->sc_dtr); - bus_io_write_1(bc, ioh, com_mcr, sc->sc_mcr); - } - if (ISSET(delta & msr, MSR_CTS) && - ISSET(tp->t_cflag, CRTSCTS)) { - /* the line is up and we want to do rts/cts flow control */ - (*linesw[tp->t_line].l_start)(tp); - } - } - - if (ISSET(lsr, LSR_TXRDY) && ISSET(tp->t_state, TS_BUSY)) { - CLR(tp->t_state, TS_BUSY | TS_FLUSH); - if (sc->sc_halt > 0) - wakeup(&tp->t_outq); - (*linesw[tp->t_line].l_start)(tp); - } - -#ifdef COM_DEBUG - if (++n >= 32) - goto ohfudge; - if (ISSET(iter[n].iir = bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND)) - return (1); -#else - if (ISSET(bus_io_read_1(bc, ioh, com_iir), IIR_NOPEND)) - return (1); -#endif - } -#ifdef COM_DEBUG -ohfudge: - printf("comintr: too many iterations"); - for (n = 0; n < 32; n++) { - if ((n % 4) == 0) - printf("\ncomintr: iter[%02d]", n); - printf(" %02x %02x %02x", iter[n].iir, iter[n].lsr, iter[n].msr); - } - printf("\n"); - printf("comintr: msr %02x mcr %02x lcr %02x ier %02x\n", - sc->sc_msr, sc->sc_mcr, sc->sc_lcr, sc->sc_ier); - printf("comintr: state %08x cc %d\n", sc->sc_tty->t_state, - sc->sc_tty->t_outq.c_cc); -#endif -} - -/* - * Following are all routines needed for COM to act as console - */ -#include <dev/cons.h> - -void -acecnprobe(cp) - struct consdev *cp; -{ - /* XXX NEEDS TO BE FIXED XXX */ - extern int cputype; - bus_chipset_tag_t bc = 0; - bus_io_handle_t ioh; - int found; - - cp->cn_pri = CN_DEAD; - - if(cputype != ACER_PICA_61) - return; - - if (bus_io_map(bc, CONADDR, COM_NPORTS, &ioh)) { - cp->cn_pri = CN_DEAD; - return; - } - ioh = CONADDR; - found = comprobe1(bc, ioh, CONADDR); - if (!found) { - return; - } - - /* locate the major number */ - for (commajor = 0; commajor < nchrdev; commajor++) - if (cdevsw[commajor].d_open == aceopen) - break; - - /* initialize required fields */ - cp->cn_dev = makedev(commajor, CONUNIT); -#ifdef COMCONSOLE - cp->cn_pri = CN_REMOTE; /* Force a serial port console */ -#else - cp->cn_pri = CN_NORMAL; -#endif -} - -void -acecninit(cp) - struct consdev *cp; -{ - -#if 0 - XXX NEEDS TO BE FIXED XXX - comconsbc = ???; -#endif - if (bus_io_map(comconsbc, CONADDR, COM_NPORTS, &comconsioh)) - panic("acecninit: mapping failed"); - - cominit(comconsbc, comconsioh, comdefaultrate); - comconsaddr = CONADDR; - comconsinit = 0; -} - -void -cominit(bc, ioh, rate) - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - int rate; -{ - int s = splhigh(); - u_char stat; - - bus_io_write_1(bc, ioh, com_lcr, LCR_DLAB); - rate = comspeed(comdefaultrate); - bus_io_write_1(bc, ioh, com_dlbl, rate); - bus_io_write_1(bc, ioh, com_dlbh, rate >> 8); - bus_io_write_1(bc, ioh, com_lcr, LCR_8BITS); - bus_io_write_1(bc, ioh, com_ier, IER_ERXRDY | IER_ETXRDY); - bus_io_write_1(bc, ioh, com_fifo, FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_4); - stat = bus_io_read_1(bc, ioh, com_iir); - splx(s); -} - -int -acecngetc(dev) - dev_t dev; -{ - int s = splhigh(); - bus_chipset_tag_t bc = comconsbc; - bus_io_handle_t ioh = comconsioh; - u_char stat, c; - - while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_RXRDY)) - ; - c = bus_io_read_1(bc, ioh, com_data); - stat = bus_io_read_1(bc, ioh, com_iir); - splx(s); - return c; -} - -/* - * Console kernel output character routine. - */ -void -acecnputc(dev, c) - dev_t dev; - int c; -{ - int s = splhigh(); - bus_chipset_tag_t bc = comconsbc; - bus_io_handle_t ioh = comconsioh; - u_char stat; - register int timo; - -#ifdef KGDB - if (dev != kgdb_dev) -#endif - if (comconsinit == 0) { - cominit(bc, ioh, comdefaultrate); - comconsinit = 1; - } - /* wait for any pending transmission to finish */ - timo = 50000; - while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_TXRDY) && --timo) - ; - bus_io_write_1(bc, ioh, com_data, c); - /* wait for this transmission to complete */ - timo = 1500000; - while (!ISSET(stat = bus_io_read_1(bc, ioh, com_lsr), LSR_TXRDY) && --timo) - ; - /* clear any interrupts generated by this transmission */ - stat = bus_io_read_1(bc, ioh, com_iir); - splx(s); -} - -void -acecnpollc(dev, on) - dev_t dev; - int on; -{ - -} diff --git a/sys/arch/arc/dev/lpr.c b/sys/arch/arc/dev/lpr.c deleted file mode 100644 index 6c5e6d61d7c..00000000000 --- a/sys/arch/arc/dev/lpr.c +++ /dev/null @@ -1,675 +0,0 @@ -/* $OpenBSD: lpr.c,v 1.3 1996/11/12 20:29:54 niklas Exp $ */ - -/* - * Copyright (c) 1993, 1994 Charles Hannum. - * 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: - * This software is a component of "386BSD" developed by - * 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. - * - * 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 - * NOT MAKE USE OF THIS WORK. - * - * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED - * 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 - * 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. - */ - -/* - * Device Driver for AT parallel printer port - */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/proc.h> -#include <sys/user.h> -#include <sys/buf.h> -#include <sys/kernel.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <sys/device.h> -#include <sys/conf.h> -#include <sys/syslog.h> - -#include <machine/bus.old.h> -#include <machine/intr.h> - -#include <dev/isa/isavar.h> -#include <dev/isa/lptreg.h> - -#include <lpr.h> - -#define TIMEOUT hz*16 /* wait up to 16 seconds for a ready */ -#define STEP hz/4 - -#define LPTPRI (PZERO+8) -#define LPT_BSIZE 1024 - -#if !defined(DEBUG) || !defined(notdef) -#define LPRINTF(a) -#else -#define LPRINTF if (lprdebug) printf a -int lprdebug = 1; -#endif - -struct lpr_softc { - struct device sc_dev; - void *sc_ih; - - size_t sc_count; - struct buf *sc_inbuf; - u_char *sc_cp; - int sc_spinmax; - int sc_iobase; - bus_chipset_tag_t sc_bc; - bus_io_handle_t sc_ioh; - int sc_irq; - u_char sc_state; -#define LPT_OPEN 0x01 /* device is open */ -#define LPT_OBUSY 0x02 /* printer is busy doing output */ -#define LPT_INIT 0x04 /* waiting to initialize for open */ - u_char sc_flags; -#define LPT_AUTOLF 0x20 /* automatic LF on CR */ -#define LPT_NOPRIME 0x40 /* don't prime on open */ -#define LPT_NOINTR 0x80 /* do not use interrupt */ - u_char sc_control; - u_char sc_laststatus; -}; - -/* XXX does not belong here */ -cdev_decl(lpr); - -int lprintr __P((void *)); - -#if NLPR_ISA -int lpr_isa_probe __P((struct device *, void *, void *)); -void lpr_isa_attach __P((struct device *, struct device *, void *)); -struct cfattach lpr_isa_ca = { - sizeof(struct lpr_softc), lpr_isa_probe, lpr_isa_attach -}; -#endif - -#if NLPR_PICA -int lpr_pica_probe __P((struct device *, void *, void *)); -void lpr_pica_attach __P((struct device *, struct device *, void *)); -struct cfattach lpr_pica_ca = { - sizeof(struct lpr_softc), lpr_pica_probe, lpr_pica_attach -}; -#endif - -struct cfdriver lpr_cd = { - NULL, "lpr", DV_TTY -}; - -#define LPTUNIT(s) (minor(s) & 0x1f) -#define LPTFLAGS(s) (minor(s) & 0xe0) - -#define LPS_INVERT (LPS_SELECT|LPS_NERR|LPS_NBSY|LPS_NACK) -#define LPS_MASK (LPS_SELECT|LPS_NERR|LPS_NBSY|LPS_NACK|LPS_NOPAPER) -#define NOT_READY() ((bus_io_read_1(bc, ioh, lpt_status) ^ LPS_INVERT) & LPS_MASK) -#define NOT_READY_ERR() not_ready(bus_io_read_1(bc, ioh, lpt_status), sc) -static int not_ready __P((u_char, struct lpr_softc *)); - -static void lprwakeup __P((void *arg)); -static int pushbytes __P((struct lpr_softc *)); - -int lpr_port_test __P((bus_chipset_tag_t, bus_io_handle_t, bus_io_addr_t, - bus_io_size_t, u_char, u_char)); - -/* - * Internal routine to lprprobe to do port tests of one byte value. - */ -int -lpr_port_test(bc, ioh, base, off, data, mask) - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - bus_io_addr_t base; - bus_io_size_t off; - u_char data, mask; -{ - int timeout; - u_char temp; - - data &= mask; - bus_io_write_1(bc, ioh, off, data); - timeout = 1000; - do { - delay(10); - temp = bus_io_read_1(bc, ioh, off) & mask; - } while (temp != data && --timeout); - LPRINTF(("lpr: port=0x%x out=0x%x in=0x%x timeout=%d\n", base + off, - data, temp, timeout)); - return (temp == data); -} - -/* - * 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. - * - * 3) Set the data and control ports to a value of 0 - */ -#if NLPR_ISA -int -lpr_isa_probe(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - struct isa_attach_args *ia = aux; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - u_long base; - u_char mask, data; - int i, rv; - -#ifdef DEBUG -#define ABORT do {printf("lprprobe: mask %x data %x failed\n", mask, data); \ - goto out;} while (0) -#else -#define ABORT goto out -#endif - - bc = ia->ia_bc; - base = ia->ia_iobase; - if (bus_io_map(bc, base, LPT_NPORTS, &ioh)) - return 0; - - rv = 0; - mask = 0xff; - - data = 0x55; /* Alternating zeros */ - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - - data = 0xaa; /* Alternating ones */ - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - - for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */ - data = ~(1 << i); - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - } - - for (i = 0; i < CHAR_BIT; i++) { /* Walking one */ - data = (1 << i); - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - } - - bus_io_write_1(bc, ioh, lpt_data, 0); - bus_io_write_1(bc, ioh, lpt_control, 0); - - ia->ia_iosize = LPT_NPORTS; - ia->ia_msize = 0; - - rv = 1; - -out: - bus_io_unmap(bc, ioh, LPT_NPORTS); - return rv; -} -#endif - -#if NLPR_PICA -int -lpr_pica_probe(parent, match, aux) - struct device *parent; - void *match, *aux; -{ - struct confargs *ca = aux; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - u_long base; - u_char mask, data; - int i; - -#ifdef DEBUG -#define ABORT do {printf("lprprobe: mask %x data %x failed\n", mask, data); \ - return 0;} while (0) -#else -#define ABORT return 0 -#endif - - if(!BUS_MATCHNAME(ca, "lpr")) - return(0); - - bc = 0; - base = (int)BUS_CVTADDR(ca); - ioh = base; - - mask = 0xff; - - data = 0x55; /* Alternating zeros */ - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - - data = 0xaa; /* Alternating ones */ - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - - for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */ - data = ~(1 << i); - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - } - - for (i = 0; i < CHAR_BIT; i++) { /* Walking one */ - data = (1 << i); - if (!lpr_port_test(bc, ioh, base, lpt_data, data, mask)) - ABORT; - } - - bus_io_write_1(bc, ioh, lpt_data, 0); - bus_io_write_1(bc, ioh, lpt_control, 0); - - return 1; -} -#endif - -#if NLPR_ISA -void -lpr_isa_attach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct lpr_softc *sc = (void *)self; - struct isa_attach_args *ia = aux; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - - if (ia->ia_irq != IRQUNK) - printf("\n"); - else - printf(": polled\n"); - - sc->sc_iobase = ia->ia_iobase; - sc->sc_irq = ia->ia_irq; - sc->sc_state = 0; - - bc = sc->sc_bc = ia->ia_bc; - if (bus_io_map(bc, sc->sc_iobase, LPT_NPORTS, &ioh)) - panic("lprattach: couldn't map I/O ports"); - sc->sc_ioh = ioh; - - bus_io_write_1(bc, ioh, lpt_control, LPC_NINIT); - - if (ia->ia_irq != IRQUNK) - sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE, - IPL_TTY, lprintr, sc, sc->sc_dev.dv_xname); -} -#endif - -#if NLPR_PICA -void -lpr_pica_attach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct lpr_softc *sc = (void *)self; - struct confargs *ca = aux; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - - printf("\n"); - - sc->sc_iobase = (int)BUS_CVTADDR(ca); - sc->sc_irq = 0; - sc->sc_state = 0; - - bc = sc->sc_bc = 0; - sc->sc_ioh = sc->sc_iobase; - - bus_io_write_1(bc, ioh, lpt_control, LPC_NINIT); - - BUS_INTR_ESTABLISH(ca, lprintr, sc); -} -#endif - -/* - * Reset the printer, then wait until it's selected and not busy. - */ -int -lpropen(dev, flag, mode, p) - dev_t dev; - int flag; - int mode; - struct proc *p; -{ - int unit = LPTUNIT(dev); - u_char flags = LPTFLAGS(dev); - struct lpr_softc *sc; - bus_chipset_tag_t bc; - bus_io_handle_t ioh; - u_char control; - int error; - int spin; - - if (unit >= lpr_cd.cd_ndevs) - return ENXIO; - sc = lpr_cd.cd_devs[unit]; - if (!sc) - return ENXIO; - - if (sc->sc_irq == IRQUNK && (flags & LPT_NOINTR) == 0) - return ENXIO; - -#ifdef DIAGNOSTIC - if (sc->sc_state) - printf("%s: stat=0x%x not zero\n", sc->sc_dev.dv_xname, - sc->sc_state); -#endif - - if (sc->sc_state) - return EBUSY; - - sc->sc_state = LPT_INIT; - sc->sc_flags = flags; - LPRINTF(("%s: open: flags=0x%x\n", sc->sc_dev.dv_xname, flags)); - bc = sc->sc_bc; - ioh = sc->sc_ioh; - - if ((flags & LPT_NOPRIME) == 0) { - /* assert INIT for 100 usec to start up printer */ - bus_io_write_1(bc, ioh, lpt_control, LPC_SELECT); - delay(100); - } - - control = LPC_SELECT | LPC_NINIT; - bus_io_write_1(bc, ioh, lpt_control, control); - - /* wait till ready (printer running diagnostics) */ - for (spin = 0; NOT_READY_ERR(); spin += STEP) { - if (spin >= TIMEOUT) { - sc->sc_state = 0; - return EBUSY; - } - - /* wait 1/4 second, give up if we get a signal */ - error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "lpropen", STEP); - if (error != EWOULDBLOCK) { - sc->sc_state = 0; - return error; - } - } - - if ((flags & LPT_NOINTR) == 0) - control |= LPC_IENABLE; - if (flags & LPT_AUTOLF) - control |= LPC_AUTOLF; - sc->sc_control = control; - bus_io_write_1(bc, ioh, lpt_control, control); - - sc->sc_inbuf = geteblk(LPT_BSIZE); - sc->sc_count = 0; - sc->sc_state = LPT_OPEN; - - if ((sc->sc_flags & LPT_NOINTR) == 0) - lprwakeup(sc); - - LPRINTF(("%s: opened\n", sc->sc_dev.dv_xname)); - return 0; -} - -int -not_ready(status, sc) - u_char status; - struct lpr_softc *sc; -{ - u_char new; - - status = (status ^ LPS_INVERT) & LPS_MASK; - new = status & ~sc->sc_laststatus; - sc->sc_laststatus = status; - - if (new & LPS_SELECT) - log(LOG_NOTICE, "%s: offline\n", sc->sc_dev.dv_xname); - else if (new & LPS_NOPAPER) - log(LOG_NOTICE, "%s: out of paper\n", sc->sc_dev.dv_xname); - else if (new & LPS_NERR) - log(LOG_NOTICE, "%s: output error\n", sc->sc_dev.dv_xname); - - return status; -} - -void -lprwakeup(arg) - void *arg; -{ - struct lpr_softc *sc = arg; - int s; - - s = spltty(); - lprintr(sc); - splx(s); - - timeout(lprwakeup, sc, STEP); -} - -/* - * Close the device, and free the local line buffer. - */ -int -lprclose(dev, flag, mode, p) - dev_t dev; - int flag; - int mode; - struct proc *p; -{ - int unit = LPTUNIT(dev); - struct lpr_softc *sc = lpr_cd.cd_devs[unit]; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - - if (sc->sc_count) - (void) pushbytes(sc); - - if ((sc->sc_flags & LPT_NOINTR) == 0) - untimeout(lprwakeup, sc); - - bus_io_write_1(bc, ioh, lpt_control, LPC_NINIT); - sc->sc_state = 0; - bus_io_write_1(bc, ioh, lpt_control, LPC_NINIT); - brelse(sc->sc_inbuf); - - LPRINTF(("%s: closed\n", sc->sc_dev.dv_xname)); - return 0; -} - -int -pushbytes(sc) - struct lpr_softc *sc; -{ - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - int error; - - if (sc->sc_flags & LPT_NOINTR) { - int spin, tic; - u_char control = sc->sc_control; - - while (sc->sc_count > 0) { - spin = 0; - while (NOT_READY()) { - if (++spin < sc->sc_spinmax) - continue; - tic = 0; - /* adapt busy-wait algorithm */ - sc->sc_spinmax++; - while (NOT_READY_ERR()) { - /* exponential backoff */ - tic = tic + tic + 1; - if (tic > TIMEOUT) - tic = TIMEOUT; - error = tsleep((caddr_t)sc, - LPTPRI | PCATCH, "lprpsh", tic); - if (error != EWOULDBLOCK) - return error; - } - break; - } - - bus_io_write_1(bc, ioh, lpt_data, *sc->sc_cp++); - bus_io_write_1(bc, ioh, lpt_control, control | LPC_STROBE); - sc->sc_count--; - bus_io_write_1(bc, ioh, lpt_control, control); - - /* adapt busy-wait algorithm */ - if (spin*2 + 16 < sc->sc_spinmax) - sc->sc_spinmax--; - } - } else { - int s; - - while (sc->sc_count > 0) { - /* if the printer is ready for a char, give it one */ - if ((sc->sc_state & LPT_OBUSY) == 0) { - LPRINTF(("%s: write %d\n", sc->sc_dev.dv_xname, - sc->sc_count)); - s = spltty(); - (void) lprintr(sc); - splx(s); - } - error = tsleep((caddr_t)sc, LPTPRI | PCATCH, - "lprwrite2", 0); - if (error) - return error; - } - } - return 0; -} - -/* - * Copy a line from user space to a local buffer, then call putc to get the - * chars moved to the output queue. - */ -int -lprwrite(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - struct lpr_softc *sc = lpr_cd.cd_devs[LPTUNIT(dev)]; - size_t n; - int error = 0; - - while ((n = min(LPT_BSIZE, uio->uio_resid)) != 0) { - uiomove(sc->sc_cp = sc->sc_inbuf->b_data, n, uio); - sc->sc_count = n; - error = pushbytes(sc); - if (error) { - /* - * Return accurate residual if interrupted or timed - * out. - */ - uio->uio_resid += sc->sc_count; - sc->sc_count = 0; - return error; - } - } - return 0; -} - -/* - * Handle printer interrupts which occur when the printer is ready to accept - * another char. - */ -int -lprintr(arg) - void *arg; -{ - struct lpr_softc *sc = arg; - bus_chipset_tag_t bc = sc->sc_bc; - bus_io_handle_t ioh = sc->sc_ioh; - - if (((sc->sc_state & LPT_OPEN) == 0 && sc->sc_count == 0) || (sc->sc_flags & LPT_NOINTR)) - return 0; - - /* is printer online and ready for output */ - if (NOT_READY() && NOT_READY_ERR()) - return -1; - - if (sc->sc_count) { - u_char control = sc->sc_control; - /* send char */ - bus_io_write_1(bc, ioh, lpt_data, *sc->sc_cp++); - bus_io_write_1(bc, ioh, lpt_control, control | LPC_STROBE); - sc->sc_count--; - bus_io_write_1(bc, ioh, lpt_control, control); - sc->sc_state |= LPT_OBUSY; - } else - sc->sc_state &= ~LPT_OBUSY; - - if (sc->sc_count == 0) { - /* none, wake up the top half to get more */ - wakeup((caddr_t)sc); - } - - return 1; -} - -int -lprioctl(dev, cmd, data, flag, p) - dev_t dev; - u_long cmd; - caddr_t data; - int flag; - struct proc *p; -{ - int error = 0; - - switch (cmd) { - default: - error = ENODEV; - } - - return error; -} diff --git a/sys/arch/arc/include/bus.h b/sys/arch/arc/include/bus.h index d261d565555..7b121c8c018 100644 --- a/sys/arch/arc/include/bus.h +++ b/sys/arch/arc/include/bus.h @@ -1,7 +1,7 @@ -/* $OpenBSD: bus.h,v 1.7 1996/10/17 18:58:58 niklas Exp $ */ +/* $OpenBSD: bus.h,v 1.8 1996/11/28 23:35:42 niklas Exp $ */ /* - * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. + * Copyright (c) 1996 Niklas Hallqvist. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,108 +33,116 @@ #ifndef _ARC_BUS_H_ #define _ARC_BUS_H_ -#include <machine/autoconf.h> -#include <machine/pio.h> - -/* - * I/O addresses (in bus space) - */ -typedef u_long bus_io_addr_t; -typedef u_long bus_io_size_t; -typedef u_long bus_io_handle_t; +#ifdef __STDC__ +#define CAT(a,b) a##b +#define CAT3(a,b,c) a##b##c +#else +#define CAT(a,b) a/**/b +#define CAT3(a,b,c) a/**/b/**/c +#endif /* - * Memory addresses (in bus space) + * Bus access types. */ -typedef u_long bus_mem_addr_t; -typedef u_long bus_mem_size_t; -typedef caddr_t bus_mem_handle_t; +typedef u_int32_t bus_addr_t; +typedef u_int32_t bus_size_t; +typedef u_int32_t bus_space_handle_t; +typedef u_int32_t bus_space_tag_t; /* - * Access methods for bus resources, I/O space, and memory space. + * Access methods for bus resources */ -typedef -struct arc_isa_busmap { - void *isa_io_base; - void *isa_mem_base; -} *bus_chipset_tag_t; - - -#define bus_io_map(t, port, size, iohp) \ - (*iohp = (t == NULL ? port : port + (ulong)(t->isa_io_base)), 0) -#define bus_io_unmap(t, ioh, size) - -#define bus_io_read_1(t, h, o) inb((h) + (o)) -#define bus_io_read_2(t, h, o) inw((h) + (o)) -#define bus_io_read_4(t, h, o) inl((h) + (o)) -#if 0 /* Cause a link error for bus_io_read_8 */ -#define bus_io_read_8(t, h, o) !!! bus_io_read_8 unimplemented !!! -#endif - -#define bus_io_read_multi_1(t, h, o, a, c) \ - insb((h) + (o), (a), (c)) -#define bus_io_read_multi_2(t, h, o, a, c) \ - insw((h) + (o), (a), (c)) -#define bus_io_read_multi_4(t, h, o, a, c) \ - insl((h) + (o), (a), (c)) -#if 0 /* Cause a link error for bus_io_read_multi_8 */ -#define bus_io_read_multi_8(t, h, o, a, c) \ - !!! bus_io_read_multi_8 unimplemented !!! -#endif - -#define bus_io_write_1(t, h, o, v) outb((h) + (o), (v)) -#define bus_io_write_2(t, h, o, v) outw((h) + (o), (v)) -#define bus_io_write_4(t, h, o, v) outl((h) + (o), (v)) -#if 0 /* Cause a link error for bus_io_write_8 */ -#define bus_io_write_8(t, h, o, v) !!! bus_io_write_8 unimplemented !!! -#endif - -#define bus_io_write_multi_1(t, h, o, a, c) \ - outsb((h) + (o), (a), (c)) -#define bus_io_write_multi_2(t, h, o, a, c) \ - outsw((h) + (o), (a), (c)) -#define bus_io_write_multi_4(t, h, o, a, c) \ - outsl((h) + (o), (a), (c)) -#if 0 /* Cause a link error for bus_io_write_multi_8 */ -#define bus_io_write_multi_8(t, h, o, a, c) \ - !!! bus_io_write_multi_8 unimplimented !!! -#endif - -#define bus_mem_map(t, addr, size, cacheable, mhp) \ - (*mhp = (bus_mem_handle_t)(t == NULL ? addr : addr + (ulong)(t->isa_mem_base)), 0) -#define bus_mem_unmap(t, ioh, size) - -#define bus_mem_read_1(t, h, o) (*(volatile u_int8_t *)((h) + (o))) -#define bus_mem_read_2(t, h, o) (*(volatile u_int16_t *)((h) + (o))) -#define bus_mem_read_4(t, h, o) (*(volatile u_int32_t *)((h) + (o))) -#define bus_mem_read_8(t, h, o) (*(volatile u_int64_t *)((h) + (o))) - -#define bus_mem_write_1(t, h, o, v) \ - ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))) -#define bus_mem_write_2(t, h, o, v) \ - ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))) -#define bus_mem_write_4(t, h, o, v) \ - ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))) -#define bus_mem_write_8(t, h, o, v) \ - ((void)(*(volatile u_int64_t *)((h) + (o)) = (v))) - -/* These are extensions to the general NetBSD bus interface. */ -#define bus_io_read_raw_multi_2(t, h, o, a, c) \ - insw((h) + (o), (a), ((c) >> 1)) -#define bus_io_read_raw_multi_4(t, h, o, a, c) \ - insl((h) + (o), (a), ((c) >> 2)) -#if 0 /* Cause a link error for bus_io_read_raw_multi_8 */ -#define bus_io_read_raw_multi_8(t, h, o, a, c) \ - !!! bus_io_read_raw_multi_8 unimplemented !!! -#endif - -#define bus_io_write_raw_multi_2(t, h, o, a, c) \ - outsw((h) + (o), (a), ((c) >> 1)) -#define bus_io_write_raw_multi_4(t, h, o, a, c) \ - outsl((h) + (o), (a), ((c) >> 2)) -#if 0 /* Cause a link error for bus_io_write_raw_multi_8 */ -#define bus_io_write_raw_multi_8(t, h, o, a, c) \ - !!! bus_io_write_raw_multi_8 unimplimented !!! -#endif +#define bus_space_map(t, addr, size, cacheable, bshp) \ + ((*(bshp) = (t) + (addr)), 0) +#define bus_space_unmap(t, bsh, size) + +#define bus_space_read(n,m) \ +static __inline CAT3(u_int,m,_t) \ +CAT(bus_space_read_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba) \ +{ \ + return *(volatile CAT3(u_int,m,_t) *)(bsh + ba); \ +} + +bus_space_read(1,8) +bus_space_read(2,16) +bus_space_read(4,32) + +#define bus_space_read_8 !!! bus_space_read_8 unimplemented !!! + +#define bus_space_read_multi(n, m) \ +static __inline void \ +CAT(bus_space_read_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + *buf++ = CAT(bus_space_read_,n)(bst, bsh, ba); \ +} + +bus_space_read_multi(1,8) +bus_space_read_multi(2,16) +bus_space_read_multi(4,32) + +#define bus_space_read_multi_8 !!! bus_space_read_multi_8 not implemented !!! + +#define bus_space_write(n,m) \ +static __inline void \ +CAT(bus_space_write_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, CAT3(u_int,m,_t) x) \ +{ \ + *(volatile CAT3(u_int,m,_t) *)(bsh + ba) = x; \ +} + +bus_space_write(1,8) +bus_space_write(2,16) +bus_space_write(4,32) + +#define bus_space_write_8 !!! bus_space_write_8 unimplemented !!! + +#define bus_space_write_multi(n, m) \ +static __inline void \ +CAT(bus_space_write_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, const CAT3(u_int,m,_t) *buf, bus_size_t cnt) \ +{ \ + while (cnt--) \ + CAT(bus_space_write_,n)(bst, bsh, ba, *buf++); \ +} + +bus_space_write_multi(1,8) +bus_space_write_multi(2,16) +bus_space_write_multi(4,32) + +#define bus_space_write_multi_8 !!! bus_space_write_multi_8 not implemented !!! + +/* These are OpenBSD extensions to the general NetBSD bus interface. */ +#define bus_space_read_raw_multi(n,m,l) \ +static __inline void \ +CAT(bus_space_read_raw_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh, \ + bus_addr_t ba, u_int8_t *buf, bus_size_t cnt) \ +{ \ + CAT(bus_space_read_multi_,n)(bst, bsh, ba, (CAT3(u_int,m,_t) *)buf, \ + cnt >> l); \ +} + +bus_space_read_raw_multi(2,16,1) +bus_space_read_raw_multi(4,32,2) + +#define bus_space_read_raw_multi_8 \ + !!! bus_space_read_raw_multi_8 not implemented !!! + +#define bus_space_write_raw_multi(n,m,l) \ +static __inline void \ +CAT(bus_space_write_raw_multi_,n)(bus_space_tag_t bst, bus_space_handle_t bsh,\ + bus_addr_t ba, const u_int8_t *buf, bus_size_t cnt) \ +{ \ + CAT(bus_space_write_multi_,n)(bst, bsh, ba, \ + (const CAT3(u_int,m,_t) *)buf, cnt >> l); \ +} + +bus_space_write_raw_multi(2,16,1) +bus_space_write_raw_multi(4,32,2) + +#define bus_space_write_raw_multi_8 \ + !!! bus_space_write_raw_multi_8 not implemented !!! #endif /* _ARC_BUS_H_ */ diff --git a/sys/arch/arc/include/bus.old.h b/sys/arch/arc/include/bus.old.h deleted file mode 100644 index fbf8f293bab..00000000000 --- a/sys/arch/arc/include/bus.old.h +++ /dev/null @@ -1,140 +0,0 @@ -/* $OpenBSD: bus.old.h,v 1.1 1996/11/12 20:29:56 niklas Exp $ */ - -/* - * Copyright (c) 1996 Christopher G. Demetriou. 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 by Christopher G. Demetriou - * for the NetBSD Project. - * 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. - */ - -#ifndef _ARC_BUS_H_ -#define _ARC_BUS_H_ - -#include <machine/autoconf.h> -#include <machine/pio.h> - -/* - * I/O addresses (in bus space) - */ -typedef u_long bus_io_addr_t; -typedef u_long bus_io_size_t; -typedef u_long bus_io_handle_t; - -/* - * Memory addresses (in bus space) - */ -typedef u_long bus_mem_addr_t; -typedef u_long bus_mem_size_t; -typedef caddr_t bus_mem_handle_t; - -/* - * Access methods for bus resources, I/O space, and memory space. - */ -typedef -struct arc_isa_busmap { - void *isa_io_base; - void *isa_mem_base; -} *bus_chipset_tag_t; - - -#define bus_io_map(t, port, size, iohp) \ - (*iohp = (t == NULL ? port : port + (ulong)(t->isa_io_base)), 0) -#define bus_io_unmap(t, ioh, size) - -#define bus_io_read_1(t, h, o) inb((h) + (o)) -#define bus_io_read_2(t, h, o) inw((h) + (o)) -#define bus_io_read_4(t, h, o) inl((h) + (o)) -#if 0 /* Cause a link error for bus_io_read_8 */ -#define bus_io_read_8(t, h, o) !!! bus_io_read_8 unimplemented !!! -#endif - -#define bus_io_read_multi_1(t, h, o, a, c) \ - insb((h) + (o), (a), (c)) -#define bus_io_read_multi_2(t, h, o, a, c) \ - insw((h) + (o), (a), (c)) -#define bus_io_read_multi_4(t, h, o, a, c) \ - insl((h) + (o), (a), (c)) -#if 0 /* Cause a link error for bus_io_read_multi_8 */ -#define bus_io_read_multi_8(t, h, o, a, c) \ - !!! bus_io_read_multi_8 unimplemented !!! -#endif - -#define bus_io_write_1(t, h, o, v) outb((h) + (o), (v)) -#define bus_io_write_2(t, h, o, v) outw((h) + (o), (v)) -#define bus_io_write_4(t, h, o, v) outl((h) + (o), (v)) -#if 0 /* Cause a link error for bus_io_write_8 */ -#define bus_io_write_8(t, h, o, v) !!! bus_io_write_8 unimplemented !!! -#endif - -#define bus_io_write_multi_1(t, h, o, a, c) \ - outsb((h) + (o), (a), (c)) -#define bus_io_write_multi_2(t, h, o, a, c) \ - outsw((h) + (o), (a), (c)) -#define bus_io_write_multi_4(t, h, o, a, c) \ - outsl((h) + (o), (a), (c)) -#if 0 /* Cause a link error for bus_io_write_multi_8 */ -#define bus_io_write_multi_8(t, h, o, a, c) \ - !!! bus_io_write_multi_8 unimplimented !!! -#endif - -#define bus_mem_map(t, addr, size, cacheable, mhp) \ - (*mhp = (bus_mem_handle_t)(t == NULL ? addr : addr + (ulong)(t->isa_mem_base)), 0) -#define bus_mem_unmap(t, ioh, size) - -#define bus_mem_read_1(t, h, o) (*(volatile u_int8_t *)((h) + (o))) -#define bus_mem_read_2(t, h, o) (*(volatile u_int16_t *)((h) + (o))) -#define bus_mem_read_4(t, h, o) (*(volatile u_int32_t *)((h) + (o))) -#define bus_mem_read_8(t, h, o) (*(volatile u_int64_t *)((h) + (o))) - -#define bus_mem_write_1(t, h, o, v) \ - ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))) -#define bus_mem_write_2(t, h, o, v) \ - ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))) -#define bus_mem_write_4(t, h, o, v) \ - ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))) -#define bus_mem_write_8(t, h, o, v) \ - ((void)(*(volatile u_int64_t *)((h) + (o)) = (v))) - -/* These are extensions to the general NetBSD bus interface. */ -#define bus_io_read_raw_multi_2(t, h, o, a, c) \ - insw((h) + (o), (a), ((c) >> 1)) -#define bus_io_read_raw_multi_4(t, h, o, a, c) \ - insl((h) + (o), (a), ((c) >> 2)) -#if 0 /* Cause a link error for bus_io_read_raw_multi_8 */ -#define bus_io_read_raw_multi_8(t, h, o, a, c) \ - !!! bus_io_read_raw_multi_8 unimplemented !!! -#endif - -#define bus_io_write_raw_multi_2(t, h, o, a, c) \ - outsw((h) + (o), (a), ((c) >> 1)) -#define bus_io_write_raw_multi_4(t, h, o, a, c) \ - outsl((h) + (o), (a), ((c) >> 2)) -#if 0 /* Cause a link error for bus_io_write_raw_multi_8 */ -#define bus_io_write_raw_multi_8(t, h, o, a, c) \ - !!! bus_io_write_raw_multi_8 unimplimented !!! -#endif - -#endif /* _ARC_BUS_H_ */ diff --git a/sys/arch/arc/isa/isabus.c b/sys/arch/arc/isa/isabus.c index de0634cd7e3..2d21710a5ae 100644 --- a/sys/arch/arc/isa/isabus.c +++ b/sys/arch/arc/isa/isabus.c @@ -1,4 +1,4 @@ -/* $OpenBSD: isabus.c,v 1.6 1996/11/23 21:45:33 kstailey Exp $ */ +/* $OpenBSD: isabus.c,v 1.7 1996/11/28 23:35:44 niklas Exp $ */ /* $NetBSD: isa.c,v 1.33 1995/06/28 04:30:51 cgd Exp $ */ /*- @@ -116,7 +116,6 @@ static int beeping; struct isabr_softc { struct device sc_dv; struct arc_isa_bus arc_isa_cs; - struct arc_isa_busmap arc_isa_map; struct abus sc_bus; }; @@ -192,11 +191,10 @@ isabrattach(parent, self, aux) sc->arc_isa_cs.ic_intr_establish = isabr_intr_establish; sc->arc_isa_cs.ic_intr_disestablish = isabr_intr_disestablish; - sc->arc_isa_map.isa_io_base = (void *)isa_io_base; - sc->arc_isa_map.isa_mem_base = (void *)isa_mem_base; iba.iba_busname = "isa"; - iba.iba_bc = &sc->arc_isa_map; + iba.iba_iot = (bus_space_tag_t)isa_io_base; + iba.iba_memt = (bus_space_tag_t)isa_mem_base; iba.iba_ic = &sc->arc_isa_cs; config_found(self, &iba, isabrprint); } @@ -210,7 +208,8 @@ isabrprint(aux, pnp) if (pnp) printf("%s at %s", ca->ca_name, pnp); - printf(" isa_io_base 0x%lx isa_mem_base 0x%lx", isa_io_base, isa_mem_base); + printf(" isa_io_base 0x%lx isa_mem_base 0x%lx", isa_io_base, + isa_mem_base); return (UNCONF); } diff --git a/sys/arch/arc/pica/lpt_pica.c b/sys/arch/arc/pica/lpt_pica.c new file mode 100644 index 00000000000..9b30ed23c4d --- /dev/null +++ b/sys/arch/arc/pica/lpt_pica.c @@ -0,0 +1,180 @@ +/* $OpenBSD: lpt_pica.c,v 1.1 1996/11/28 23:35:44 niklas Exp $ */ + +/* + * Copyright (c) 1993, 1994 Charles Hannum. + * 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: + * This software is a component of "386BSD" developed by + * 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. + * + * 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 + * NOT MAKE USE OF THIS WORK. + * + * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED + * 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 + * 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. + */ + +/* + * Device Driver for AT parallel printer port + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/device.h> + +#include <machine/autoconf.h> +#include <machine/bus.h> +#include <machine/intr.h> + +#include <dev/isa/lptreg.h> + +/* XXX create ic/lptvar.h with this structure and prototypes in it. */ +struct lpt_softc { + struct device sc_dev; + void *sc_ih; + + size_t sc_count; + struct buf *sc_inbuf; + u_char *sc_cp; + int sc_spinmax; + int sc_iobase; + bus_space_tag_t sc_iot; + bus_space_handle_t sc_ioh; + int sc_irq; + u_char sc_state; +#define LPT_OPEN 0x01 /* device is open */ +#define LPT_OBUSY 0x02 /* printer is busy doing output */ +#define LPT_INIT 0x04 /* waiting to initialize for open */ + u_char sc_flags; +#define LPT_AUTOLF 0x20 /* automatic LF on CR */ +#define LPT_NOPRIME 0x40 /* don't prime on open */ +#define LPT_NOINTR 0x80 /* do not use interrupt */ + u_char sc_control; + u_char sc_laststatus; +}; + +int lptintr __P((void *)); + +int lpt_pica_probe __P((struct device *, void *, void *)); +void lpt_pica_attach __P((struct device *, struct device *, void *)); + +struct cfattach lpt_pica_ca = { + sizeof(struct lpt_softc), lpt_pica_probe, lpt_pica_attach +}; + +int +lpt_pica_probe(parent, match, aux) + struct device *parent; + void *match, *aux; +{ + struct confargs *ca = aux; + bus_space_tag_t iot; + bus_space_handle_t ioh; + u_long base; + u_char mask, data; + int i; + +#ifdef DEBUG +#define ABORT \ + do { \ + printf("lpt_pica_probe: mask %x data %x failed\n", mask, \ + data); \ + return 0; \ + } while (0) +#else +#define ABORT return 0 +#endif + + if(!BUS_MATCHNAME(ca, "lpt")) + return(0); + + iot = 0; + base = (int)BUS_CVTADDR(ca); + ioh = base; + + mask = 0xff; + + data = 0x55; /* Alternating zeros */ + if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask)) + ABORT; + + data = 0xaa; /* Alternating ones */ + if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask)) + ABORT; + + for (i = 0; i < CHAR_BIT; i++) { /* Walking zero */ + data = ~(1 << i); + if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask)) + ABORT; + } + + for (i = 0; i < CHAR_BIT; i++) { /* Walking one */ + data = (1 << i); + if (!lpt_port_test(iot, ioh, base, lpt_data, data, mask)) + ABORT; + } + + bus_space_write_1(iot, ioh, lpt_data, 0); + bus_space_write_1(iot, ioh, lpt_control, 0); + + return 1; +} + +void +lpt_pica_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct lpt_softc *sc = (void *)self; + struct confargs *ca = aux; + bus_space_tag_t iot; + bus_space_handle_t ioh; + + printf("\n"); + + sc->sc_iobase = (int)BUS_CVTADDR(ca); + sc->sc_irq = 0; + sc->sc_state = 0; + + iot = sc->sc_iot = 0; + sc->sc_ioh = sc->sc_iobase; + + bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT); + + BUS_INTR_ESTABLISH(ca, lptintr, sc); +} |