Home | History | Annotate | Line # | Download | only in dev
ite_compat.c revision 1.12
      1  1.12  dholland /*	$NetBSD: ite_compat.c,v 1.12 2014/07/25 08:10:33 dholland 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.7     lukem 
     38   1.7     lukem #include <sys/cdefs.h>
     39  1.12  dholland __KERNEL_RCSID(0, "$NetBSD: ite_compat.c,v 1.12 2014/07/25 08:10:33 dholland Exp $");
     40   1.2    scottr 
     41   1.2    scottr #include "ite.h"
     42   1.2    scottr #include "wsdisplay.h"
     43   1.2    scottr 
     44   1.2    scottr #include <sys/param.h>
     45   1.2    scottr #include <sys/systm.h>
     46   1.2    scottr #include <sys/conf.h>
     47   1.2    scottr #include <sys/device.h>
     48   1.2    scottr #include <sys/ioctl.h>
     49   1.3    scottr #include <sys/ttycom.h>
     50   1.2    scottr 
     51   1.2    scottr #include <dev/cons.h>
     52   1.2    scottr 
     53   1.2    scottr #include <machine/cpu.h>
     54   1.2    scottr #include <machine/iteioctl.h>
     55   1.2    scottr 
     56   1.5   gehenna dev_type_open(iteopen);
     57   1.5   gehenna dev_type_close(iteclose);
     58   1.5   gehenna dev_type_read(iteread);
     59   1.5   gehenna dev_type_write(itewrite);
     60   1.5   gehenna dev_type_ioctl(iteioctl);
     61   1.5   gehenna dev_type_tty(itetty);
     62   1.5   gehenna dev_type_poll(itepoll);
     63   1.6  jdolecek dev_type_kqfilter(itekqfilter);
     64   1.5   gehenna 
     65   1.5   gehenna const struct cdevsw ite_cdevsw = {
     66  1.11  dholland 	.d_open = iteopen,
     67  1.11  dholland 	.d_close = iteclose,
     68  1.11  dholland 	.d_read = iteread,
     69  1.11  dholland 	.d_write = itewrite,
     70  1.11  dholland 	.d_ioctl = iteioctl,
     71  1.11  dholland 	.d_stop = nostop,
     72  1.11  dholland 	.d_tty = itetty,
     73  1.11  dholland 	.d_poll = itepoll,
     74  1.11  dholland 	.d_mmap = nommap,
     75  1.11  dholland 	.d_kqfilter = itekqfilter,
     76  1.12  dholland 	.d_discard = nodiscard,
     77  1.11  dholland 	.d_flag = D_TTY
     78   1.5   gehenna };
     79   1.5   gehenna 
     80   1.5   gehenna #if NWSDISPLAY > 0
     81   1.5   gehenna extern const struct cdevsw wsdisplay_cdevsw;
     82   1.5   gehenna #endif
     83   1.5   gehenna 
     84   1.8       chs void		iteattach(int);
     85   1.2    scottr 
     86   1.2    scottr static int	ite_initted = 0;
     87   1.2    scottr static int	ite_bell_freq = 1880;
     88   1.2    scottr static int	ite_bell_length = 10;
     89   1.2    scottr static int	ite_bell_volume = 100;
     90   1.2    scottr 
     91   1.2    scottr 
     92   1.2    scottr /*ARGSUSED*/
     93   1.2    scottr void
     94   1.8       chs iteattach(int n)
     95   1.2    scottr {
     96   1.2    scottr #if NWSDISPLAY > 0
     97   1.2    scottr 	int maj;
     98   1.2    scottr 
     99   1.5   gehenna 	maj = cdevsw_lookup_major(&wsdisplay_cdevsw);
    100   1.5   gehenna 	KASSERT(maj != -1);
    101   1.2    scottr 
    102   1.2    scottr 	if (maj != major(cn_tab->cn_dev))
    103   1.2    scottr 		return;
    104   1.2    scottr 
    105   1.2    scottr 	ite_initted = 1;
    106   1.2    scottr #endif
    107   1.2    scottr }
    108   1.2    scottr 
    109   1.2    scottr /*
    110   1.2    scottr  * Tty handling functions
    111   1.2    scottr  */
    112   1.2    scottr 
    113   1.2    scottr /*ARGSUSED*/
    114   1.2    scottr int
    115   1.9  christos iteopen(dev_t dev, int mode, int devtype, struct lwp *l)
    116   1.2    scottr {
    117   1.3    scottr 	return ite_initted ? (0) : (ENXIO);
    118   1.2    scottr }
    119   1.2    scottr 
    120   1.2    scottr /*ARGSUSED*/
    121   1.2    scottr int
    122   1.9  christos iteclose(dev_t dev, int flag, int mode, struct lwp *l)
    123   1.2    scottr {
    124   1.3    scottr 	return ite_initted ? (0) : (ENXIO);
    125   1.2    scottr }
    126   1.2    scottr 
    127   1.2    scottr /*ARGSUSED*/
    128   1.2    scottr int
    129   1.8       chs iteread(dev_t dev, struct uio *uio, int flag)
    130   1.2    scottr {
    131   1.2    scottr 	return ite_initted ?
    132   1.5   gehenna 	    (*wsdisplay_cdevsw.d_read)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    133   1.2    scottr }
    134   1.2    scottr 
    135   1.2    scottr /*ARGSUSED*/
    136   1.2    scottr int
    137   1.8       chs itewrite(dev_t dev, struct uio *uio, int flag)
    138   1.2    scottr {
    139   1.2    scottr 	return ite_initted ?
    140   1.5   gehenna 	    (*wsdisplay_cdevsw.d_write)(cn_tab->cn_dev, uio, flag) : (ENXIO);
    141   1.2    scottr }
    142   1.2    scottr 
    143   1.2    scottr /*ARGSUSED*/
    144   1.2    scottr struct tty *
    145   1.8       chs itetty(dev_t dev)
    146   1.2    scottr {
    147   1.5   gehenna 	return ite_initted ? (*wsdisplay_cdevsw.d_tty)(cn_tab->cn_dev) : (NULL);
    148   1.2    scottr }
    149   1.2    scottr 
    150   1.2    scottr /*ARGSUSED*/
    151   1.2    scottr int
    152  1.10  christos iteioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
    153   1.2    scottr {
    154   1.2    scottr 	if (!ite_initted)
    155   1.2    scottr 		return (ENXIO);
    156   1.2    scottr 
    157   1.2    scottr 	switch (cmd) {
    158   1.2    scottr 	case ITEIOC_RINGBELL:
    159   1.2    scottr 		return mac68k_ring_bell(ite_bell_freq,
    160   1.2    scottr 		    ite_bell_length, ite_bell_volume);
    161   1.2    scottr 	case ITEIOC_SETBELL:
    162   1.2    scottr 		{
    163   1.2    scottr 			struct bellparams *bp = (void *)addr;
    164   1.2    scottr 
    165   1.2    scottr 			/* Do some sanity checks. */
    166   1.2    scottr 			if (bp->freq < 10 || bp->freq > 40000)
    167   1.2    scottr 				return (EINVAL);
    168   1.2    scottr 			if (bp->len < 0 || bp->len > 3600)
    169   1.2    scottr 				return (EINVAL);
    170   1.2    scottr 			if (bp->vol < 0 || bp->vol > 100)
    171   1.2    scottr 				return (EINVAL);
    172   1.2    scottr 
    173   1.2    scottr 			ite_bell_freq = bp->freq;
    174   1.2    scottr 			ite_bell_length = bp->len;
    175   1.2    scottr 			ite_bell_volume = bp->vol;
    176   1.2    scottr 			return (0);
    177   1.2    scottr 		}
    178   1.2    scottr 	case ITEIOC_GETBELL:
    179   1.2    scottr 		{
    180   1.2    scottr 			struct bellparams *bp = (void *)addr;
    181   1.2    scottr 
    182   1.2    scottr 			ite_bell_freq = bp->freq;
    183   1.2    scottr 			ite_bell_length = bp->len;
    184   1.2    scottr 			ite_bell_volume = bp->vol;
    185   1.2    scottr 			return (0);
    186   1.2    scottr 		}
    187   1.2    scottr 	default:
    188   1.5   gehenna 		return ((*wsdisplay_cdevsw.d_ioctl)(cn_tab->cn_dev, cmd,
    189   1.9  christos 						    addr, flag, l));
    190   1.2    scottr 	}
    191   1.2    scottr 
    192   1.2    scottr 	return (ENOTTY);
    193   1.4       scw }
    194   1.4       scw 
    195   1.4       scw /*ARGSUSED*/
    196   1.4       scw int
    197   1.9  christos itepoll(dev_t dev, int events, struct lwp *l)
    198   1.4       scw {
    199   1.4       scw 	return ite_initted ?
    200   1.9  christos 	    (*wsdisplay_cdevsw.d_poll)(cn_tab->cn_dev, events, l) : (ENXIO);
    201   1.6  jdolecek }
    202   1.6  jdolecek 
    203   1.6  jdolecek int
    204   1.8       chs itekqfilter(dev_t dev, struct knote *kn)
    205   1.6  jdolecek {
    206   1.6  jdolecek 	return ite_initted ?
    207   1.6  jdolecek 	    (*wsdisplay_cdevsw.d_kqfilter)(cn_tab->cn_dev, kn) : (ENXIO);
    208   1.2    scottr }
    209