Home | History | Annotate | Line # | Download | only in dev
ite_compat.c revision 1.6
      1  1.6  jdolecek /*	$NetBSD: ite_compat.c,v 1.6 2002/10/23 09:11:28 jdolecek Exp $	*/
      2  1.2    scottr 
      3  1.2    scottr /*
      4  1.2    scottr  * Copyright (C) 2000 Scott Reynolds
      5  1.2    scottr  * All rights reserved.
      6  1.2    scottr  *
      7  1.2    scottr  * Redistribution and use in source and binary forms, with or without
      8  1.2    scottr  * modification, are permitted provided that the following conditions
      9  1.2    scottr  * are met:
     10  1.2    scottr  * 1. Redistributions of source code must retain the above copyright
     11  1.2    scottr  *    notice, this list of conditions and the following disclaimer.
     12  1.2    scottr  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2    scottr  *    notice, this list of conditions and the following disclaimer in the
     14  1.2    scottr  *    documentation and/or other materials provided with the distribution.
     15  1.2    scottr  * 3. The name of the author may not be used to endorse or promote products
     16  1.2    scottr  *    derived from this software without specific prior written permission.
     17  1.2    scottr  *
     18  1.2    scottr  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.2    scottr  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.2    scottr  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.2    scottr  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.2    scottr  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.2    scottr  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.2    scottr  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.2    scottr  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.2    scottr  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.2    scottr  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.2    scottr  */
     29  1.2    scottr 
     30  1.2    scottr /*
     31  1.2    scottr  * The main thing to realize about this emulator is that the old console
     32  1.2    scottr  * emulator was largely compatible with the DEC VT-220.  Since the
     33  1.2    scottr  * wsdiplay driver has a more complete emulation of that terminal, it's
     34  1.2    scottr  * reasonable to pass virtually everything up to that driver without
     35  1.2    scottr  * modification.
     36  1.2    scottr  */
     37  1.2    scottr 
     38  1.2    scottr #include "ite.h"
     39  1.2    scottr #include "wsdisplay.h"
     40  1.2    scottr 
     41  1.2    scottr #include <sys/param.h>
     42  1.2    scottr #include <sys/systm.h>
     43  1.2    scottr #include <sys/conf.h>
     44  1.2    scottr #include <sys/device.h>
     45  1.2    scottr #include <sys/ioctl.h>
     46  1.3    scottr #include <sys/ttycom.h>
     47  1.2    scottr 
     48  1.2    scottr #include <dev/cons.h>
     49  1.2    scottr 
     50  1.2    scottr #include <machine/cpu.h>
     51  1.2    scottr #include <machine/iteioctl.h>
     52  1.2    scottr 
     53  1.5   gehenna dev_type_open(iteopen);
     54  1.5   gehenna dev_type_close(iteclose);
     55  1.5   gehenna dev_type_read(iteread);
     56  1.5   gehenna dev_type_write(itewrite);
     57  1.5   gehenna dev_type_ioctl(iteioctl);
     58  1.5   gehenna dev_type_tty(itetty);
     59  1.5   gehenna dev_type_poll(itepoll);
     60  1.6  jdolecek dev_type_kqfilter(itekqfilter);
     61  1.5   gehenna 
     62  1.5   gehenna const struct cdevsw ite_cdevsw = {
     63  1.5   gehenna 	iteopen, iteclose, iteread, itewrite, iteioctl,
     64  1.6  jdolecek 	nostop, itetty, itepoll, nommap, itekqfilter, D_TTY
     65  1.5   gehenna };
     66  1.5   gehenna 
     67  1.5   gehenna #if NWSDISPLAY > 0
     68  1.5   gehenna extern const struct cdevsw wsdisplay_cdevsw;
     69  1.5   gehenna #endif
     70  1.5   gehenna 
     71  1.2    scottr void		iteattach __P((int));
     72  1.2    scottr 
     73  1.2    scottr static int	ite_initted = 0;
     74  1.2    scottr static int	ite_bell_freq = 1880;
     75  1.2    scottr static int	ite_bell_length = 10;
     76  1.2    scottr static int	ite_bell_volume = 100;
     77  1.2    scottr 
     78  1.2    scottr 
     79  1.2    scottr /*ARGSUSED*/
     80  1.2    scottr void
     81  1.2    scottr iteattach(n)
     82  1.2    scottr 	int n;
     83  1.2    scottr {
     84  1.2    scottr #if NWSDISPLAY > 0
     85  1.2    scottr 	int maj;
     86  1.2    scottr 
     87  1.5   gehenna 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
     88  1.5   gehenna 	KASSERT(maj != -1);
     89  1.2    scottr 
     90  1.2    scottr 	if (maj != major(cn_tab->cn_dev))
     91  1.2    scottr 		return;
     92  1.2    scottr 
     93  1.2    scottr 	ite_initted = 1;
     94  1.2    scottr #endif
     95  1.2    scottr }
     96  1.2    scottr 
     97  1.2    scottr /*
     98  1.2    scottr  * Tty handling functions
     99  1.2    scottr  */
    100  1.2    scottr 
    101  1.2    scottr /*ARGSUSED*/
    102  1.2    scottr int
    103  1.2    scottr iteopen(dev, mode, devtype, p)
    104  1.2    scottr 	dev_t dev;
    105  1.2    scottr 	int mode;
    106  1.2    scottr 	int devtype;
    107  1.2    scottr 	struct proc *p;
    108  1.2    scottr {
    109  1.3    scottr 	return ite_initted ? (0) : (ENXIO);
    110  1.2    scottr }
    111  1.2    scottr 
    112  1.2    scottr /*ARGSUSED*/
    113  1.2    scottr int
    114  1.2    scottr iteclose(dev, flag, mode, p)
    115  1.2    scottr 	dev_t dev;
    116  1.2    scottr 	int flag;
    117  1.2    scottr 	int mode;
    118  1.2    scottr 	struct proc *p;
    119  1.2    scottr {
    120  1.3    scottr 	return ite_initted ? (0) : (ENXIO);
    121  1.2    scottr }
    122  1.2    scottr 
    123  1.2    scottr /*ARGSUSED*/
    124  1.2    scottr int
    125  1.2    scottr iteread(dev, uio, flag)
    126  1.2    scottr 	dev_t dev;
    127  1.2    scottr 	struct uio *uio;
    128  1.2    scottr 	int flag;
    129  1.2    scottr {
    130  1.2    scottr 	return ite_initted ?
    131  1.5   gehenna 	    (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    132  1.2    scottr }
    133  1.2    scottr 
    134  1.2    scottr /*ARGSUSED*/
    135  1.2    scottr int
    136  1.2    scottr itewrite(dev, uio, flag)
    137  1.2    scottr 	dev_t dev;
    138  1.2    scottr 	struct uio *uio;
    139  1.2    scottr 	int flag;
    140  1.2    scottr {
    141  1.2    scottr 	return ite_initted ?
    142  1.5   gehenna 	    (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    143  1.2    scottr }
    144  1.2    scottr 
    145  1.2    scottr /*ARGSUSED*/
    146  1.2    scottr struct tty *
    147  1.2    scottr itetty(dev)
    148  1.2    scottr 	dev_t dev;
    149  1.2    scottr {
    150  1.5   gehenna 	return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
    151  1.2    scottr }
    152  1.2    scottr 
    153  1.2    scottr /*ARGSUSED*/
    154  1.2    scottr int
    155  1.2    scottr iteioctl(dev, cmd, addr, flag, p)
    156  1.2    scottr 	dev_t dev;
    157  1.2    scottr 	u_long cmd;
    158  1.2    scottr 	caddr_t addr;
    159  1.2    scottr 	int flag;
    160  1.2    scottr 	struct proc *p;
    161  1.2    scottr {
    162  1.2    scottr 	if (!ite_initted)
    163  1.2    scottr 		return (ENXIO);
    164  1.2    scottr 
    165  1.2    scottr 	switch (cmd) {
    166  1.2    scottr 	case ITEIOC_RINGBELL:
    167  1.2    scottr 		return mac68k_ring_bell(ite_bell_freq,
    168  1.2    scottr 		    ite_bell_length, ite_bell_volume);
    169  1.2    scottr 	case ITEIOC_SETBELL:
    170  1.2    scottr 		{
    171  1.2    scottr 			struct bellparams *bp = (void *)addr;
    172  1.2    scottr 
    173  1.2    scottr 			/* Do some sanity checks. */
    174  1.2    scottr 			if (bp->freq < 10 || bp->freq > 40000)
    175  1.2    scottr 				return (EINVAL);
    176  1.2    scottr 			if (bp->len < 0 || bp->len > 3600)
    177  1.2    scottr 				return (EINVAL);
    178  1.2    scottr 			if (bp->vol < 0 || bp->vol > 100)
    179  1.2    scottr 				return (EINVAL);
    180  1.2    scottr 
    181  1.2    scottr 			ite_bell_freq = bp->freq;
    182  1.2    scottr 			ite_bell_length = bp->len;
    183  1.2    scottr 			ite_bell_volume = bp->vol;
    184  1.2    scottr 			return (0);
    185  1.2    scottr 		}
    186  1.2    scottr 	case ITEIOC_GETBELL:
    187  1.2    scottr 		{
    188  1.2    scottr 			struct bellparams *bp = (void *)addr;
    189  1.2    scottr 
    190  1.2    scottr 			ite_bell_freq = bp->freq;
    191  1.2    scottr 			ite_bell_length = bp->len;
    192  1.2    scottr 			ite_bell_volume = bp->vol;
    193  1.2    scottr 			return (0);
    194  1.2    scottr 		}
    195  1.2    scottr 	default:
    196  1.5   gehenna 		return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
    197  1.5   gehenna 						    addr, flag, p));
    198  1.2    scottr 	}
    199  1.2    scottr 
    200  1.2    scottr 	return (ENOTTY);
    201  1.4       scw }
    202  1.4       scw 
    203  1.4       scw /*ARGSUSED*/
    204  1.4       scw int
    205  1.4       scw itepoll(dev, events, p)
    206  1.4       scw 	dev_t dev;
    207  1.4       scw 	int events;
    208  1.4       scw 	struct proc *p;
    209  1.4       scw {
    210  1.4       scw 	return ite_initted ?
    211  1.5   gehenna 	    (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, p) : (ENXIO);
    212  1.6  jdolecek }
    213  1.6  jdolecek 
    214  1.6  jdolecek int
    215  1.6  jdolecek itekqfilter(dev, kn)
    216  1.6  jdolecek 	dev_t dev;
    217  1.6  jdolecek 	struct knote *kn;
    218  1.6  jdolecek {
    219  1.6  jdolecek 	return ite_initted ?
    220  1.6  jdolecek 	    (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
    221  1.2    scottr }
    222