Home | History | Annotate | Line # | Download | only in sun
kbdvar.h revision 1.7.6.1
      1  1.7.6.1     fvdl /*	$NetBSD: kbdvar.h,v 1.7.6.1 2001/10/11 00:02:27 fvdl Exp $	*/
      2      1.1      mrg 
      3      1.1      mrg /*
      4      1.1      mrg  * Copyright (c) 1992, 1993
      5      1.1      mrg  *	The Regents of the University of California.  All rights reserved.
      6      1.1      mrg  *
      7      1.1      mrg  * This software was developed by the Computer Systems Engineering group
      8      1.1      mrg  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9      1.1      mrg  * contributed to Berkeley.
     10      1.1      mrg  *
     11      1.1      mrg  * All advertising materials mentioning features or use of this software
     12      1.1      mrg  * must display the following acknowledgement:
     13      1.1      mrg  *	This product includes software developed by the University of
     14      1.1      mrg  *	California, Lawrence Berkeley Laboratory.
     15      1.1      mrg  *
     16      1.1      mrg  * Redistribution and use in source and binary forms, with or without
     17      1.1      mrg  * modification, are permitted provided that the following conditions
     18      1.1      mrg  * are met:
     19      1.1      mrg  * 1. Redistributions of source code must retain the above copyright
     20      1.1      mrg  *    notice, this list of conditions and the following disclaimer.
     21      1.1      mrg  * 2. Redistributions in binary form must reproduce the above copyright
     22      1.1      mrg  *    notice, this list of conditions and the following disclaimer in the
     23      1.1      mrg  *    documentation and/or other materials provided with the distribution.
     24      1.1      mrg  * 3. All advertising materials mentioning features or use of this software
     25      1.1      mrg  *    must display the following acknowledgement:
     26      1.1      mrg  *	This product includes software developed by the University of
     27      1.1      mrg  *	California, Berkeley and its contributors.
     28      1.1      mrg  * 4. Neither the name of the University nor the names of its contributors
     29      1.1      mrg  *    may be used to endorse or promote products derived from this software
     30      1.1      mrg  *    without specific prior written permission.
     31      1.1      mrg  *
     32      1.1      mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33      1.1      mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34      1.1      mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35      1.1      mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36      1.1      mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37      1.1      mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38      1.1      mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39      1.1      mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40      1.1      mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41      1.1      mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42      1.1      mrg  * SUCH DAMAGE.
     43      1.1      mrg  *
     44      1.1      mrg  *	@(#)kbd.c	8.2 (Berkeley) 10/30/93
     45      1.1      mrg  */
     46      1.1      mrg 
     47      1.4  thorpej #include <sys/callout.h>
     48      1.4  thorpej 
     49      1.1      mrg /*
     50      1.1      mrg  * How many input characters we can buffer.
     51      1.1      mrg  * The port-specific var.h may override this.
     52      1.1      mrg  * Note: must be a power of two!
     53      1.1      mrg  */
     54      1.1      mrg #define	KBD_RX_RING_SIZE	256
     55      1.1      mrg #define KBD_RX_RING_MASK (KBD_RX_RING_SIZE-1)
     56      1.1      mrg /*
     57      1.1      mrg  * Output buffer.  Only need a few chars.
     58      1.1      mrg  */
     59      1.1      mrg #define	KBD_TX_RING_SIZE	16
     60      1.1      mrg #define KBD_TX_RING_MASK (KBD_TX_RING_SIZE-1)
     61      1.1      mrg /*
     62      1.1      mrg  * Keyboard serial line speed is fixed at 1200 bps.
     63      1.1      mrg  */
     64      1.1      mrg #define KBD_BPS 1200
     65      1.1      mrg #define KBD_RESET_TIMO 1000 /* mS. */
     66      1.1      mrg 
     67      1.1      mrg /*
     68      1.1      mrg  * XXX - Historical comment - no longer quite right...
     69      1.1      mrg  * Keyboard driver state.  The ascii and kbd links go up and down and
     70      1.1      mrg  * we just sit in the middle doing translation.  Note that it is possible
     71      1.1      mrg  * to get just one of the two links, in which case /dev/kbd is unavailable.
     72      1.1      mrg  * The downlink supplies us with `internal' open and close routines which
     73      1.1      mrg  * will enable dataflow across the downlink.  We promise to call open when
     74      1.1      mrg  * we are willing to take keystrokes, and to call close when we are not.
     75      1.1      mrg  * If /dev/kbd is not the console tty input source, we do this whenever
     76      1.1      mrg  * /dev/kbd is in use; otherwise we just leave it open forever.
     77      1.1      mrg  */
     78      1.1      mrg struct zs_chanstate;
     79      1.1      mrg struct ucom_softc;
     80  1.7.6.1     fvdl struct vnode;
     81      1.1      mrg 
     82      1.1      mrg struct kbd_softc {
     83      1.1      mrg 	struct	device k_dev;		/* required first: base device */
     84      1.1      mrg 
     85      1.1      mrg 	/* Stuff our parent setup */
     86      1.1      mrg 	union {
     87      1.7      eeh 		struct zs_chanstate *ku_cs;
     88      1.7      eeh 		struct ucom_softc *ku_usc;
     89      1.7      eeh 		void *ku_priv;
     90      1.7      eeh 	} k_u;
     91      1.7      eeh #define	k_cs k_u.ku_cs
     92      1.7      eeh #define	k_usc k_u.ku_usc
     93      1.7      eeh #define k_priv k_u.ku_priv
     94      1.7      eeh 
     95      1.7      eeh 	/*
     96      1.7      eeh 	 * The deviopen and deviclose routines are provided
     97      1.7      eeh 	 * by the lower level driver and used as a back door
     98      1.7      eeh 	 * when opening and closing the internal device.
     99      1.7      eeh 	 */
    100  1.7.6.1     fvdl 	int	(*k_deviopen)	__P((struct device *, int, struct vnode *));
    101  1.7.6.1     fvdl 	int	(*k_deviclose)	__P((struct device *, int, struct vnode *));
    102      1.1      mrg 	void	(*k_write_data) __P((struct kbd_softc *, int));
    103      1.1      mrg 
    104  1.7.6.1     fvdl 	dev_t	k_rdev;
    105  1.7.6.1     fvdl 	struct vnode *k_devvp;
    106  1.7.6.1     fvdl 
    107      1.1      mrg 	/* Flags to communicate with kbd_softint() */
    108      1.1      mrg 	volatile int k_intr_flags;
    109      1.1      mrg #define	INTR_RX_OVERRUN 1
    110      1.1      mrg #define INTR_TX_EMPTY   2
    111      1.1      mrg #define INTR_ST_CHECK   4
    112      1.1      mrg 
    113      1.1      mrg 	/* Transmit state */
    114      1.1      mrg 	volatile int k_txflags;
    115      1.1      mrg #define	K_TXBUSY 1
    116      1.1      mrg #define K_TXWANT 2
    117      1.1      mrg 
    118      1.1      mrg 	/*
    119      1.1      mrg 	 * State of upper interface.
    120      1.1      mrg 	 */
    121      1.1      mrg 	int	k_isopen;		/* set if open has been done */
    122      1.1      mrg 	int	k_evmode;		/* set if we should produce events */
    123      1.1      mrg 	struct	evvar k_events;		/* event queue state */
    124      1.1      mrg 
    125      1.1      mrg 	/*
    126      1.1      mrg 	 * ACSI translation state
    127      1.1      mrg 	 */
    128      1.1      mrg 	int k_repeat_start; 	/* initial delay */
    129      1.1      mrg 	int k_repeat_step;  	/* inter-char delay */
    130      1.1      mrg 	int	k_repeatsym;		/* repeating symbol */
    131      1.1      mrg 	int	k_repeating;		/* we've called timeout() */
    132      1.1      mrg 	struct	kbd_state k_state;	/* ASCII translation state */
    133      1.1      mrg 
    134      1.4  thorpej 	struct callout k_repeat_ch;
    135      1.4  thorpej 
    136      1.2       pk 	/* Console hooks */
    137      1.2       pk 	char k_isconsole;
    138      1.2       pk 	struct cons_channel *k_cc;
    139      1.2       pk 
    140      1.1      mrg 	/*
    141      1.1      mrg 	 * Magic sequence stuff (L1-A)
    142      1.1      mrg 	 */
    143      1.1      mrg 	char k_magic1_down;
    144      1.1      mrg 	u_char k_magic1;	/* L1 */
    145      1.1      mrg 	u_char k_magic2;	/* A */
    146      1.2       pk 
    147      1.1      mrg 	/*
    148      1.1      mrg 	 * The transmit ring buffer.
    149      1.1      mrg 	 */
    150      1.1      mrg 	volatile u_int	k_tbget;	/* transmit buffer `get' index */
    151      1.1      mrg 	volatile u_int	k_tbput;	/* transmit buffer `put' index */
    152      1.1      mrg 	u_char	k_tbuf[KBD_TX_RING_SIZE]; /* data */
    153      1.1      mrg 
    154      1.1      mrg 	/*
    155      1.1      mrg 	 * The receive ring buffer.
    156      1.1      mrg 	 */
    157      1.1      mrg 	u_int	k_rbget;	/* ring buffer `get' index */
    158      1.1      mrg 	volatile u_int	k_rbput;	/* ring buffer `put' index */
    159      1.1      mrg 	u_short	k_rbuf[KBD_RX_RING_SIZE]; /* rr1, data pairs */
    160      1.1      mrg 
    161      1.1      mrg };
    162      1.1      mrg 
    163      1.1      mrg /* functions used between backend/frontend keyboard drivers */
    164      1.1      mrg void	kbd_input_raw __P((struct kbd_softc *k, int));
    165      1.1      mrg void	kbd_output(struct kbd_softc *k, int c);
    166      1.1      mrg void	kbd_start_tx(struct kbd_softc *k);
    167  1.7.6.1     fvdl int	kbd_cc_open __P((struct cons_channel *, struct vnode *));
    168  1.7.6.1     fvdl int	kbd_cc_close __P((struct cons_channel *, struct vnode *));
    169      1.2       pk 
    170      1.2       pk /*
    171      1.2       pk  * kbd console input channel interface.
    172      1.2       pk  * XXX - does not belong in this header; but for now, kbd is the only user..
    173      1.2       pk  */
    174      1.2       pk struct cons_channel {
    175      1.2       pk 	/* Provided by lower driver */
    176      1.2       pk 	void	*cc_dev;			/* Lower device private data */
    177      1.5  hannken 	struct callout	cc_callout;
    178      1.2       pk 	int	(*cc_iopen)			/* Open lower device */
    179  1.7.6.1     fvdl 			__P((struct cons_channel *, struct vnode *));
    180      1.2       pk 	int	(*cc_iclose)			/* Close lower device */
    181  1.7.6.1     fvdl 			__P((struct cons_channel *, struct vnode *));
    182      1.2       pk 
    183      1.2       pk 	/* Provided by upper driver */
    184      1.2       pk 	void	(*cc_upstream)__P((int));	/* Send a character upstream */
    185      1.2       pk };
    186      1.2       pk 
    187      1.2       pk /* Special hook to attach the keyboard driver to the console */
    188      1.6      eeh void	cons_attach_input __P((struct cons_channel *, struct consdev *));
    189