📄 dtop.c
字号:
/*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Ralph Campbell and Rick Macklem. * * 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. * * @(#)dtop.c 8.2 (Berkeley) 11/30/93 *//* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* * Author: Alessandro Forin, Carnegie Mellon University * * Hardware-level operations for the Desktop serial line * bus (i2c aka ACCESS). *//************************************************************Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,and the Massachusetts Institute of Technology, Cambridge, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.********************************************************/#include <dtop.h>#if NDTOP > 0#include <sys/param.h>#include <sys/systm.h>#include <sys/ioctl.h>#include <sys/tty.h>#include <sys/proc.h>#include <sys/map.h>#include <sys/buf.h>#include <sys/conf.h>#include <sys/file.h>#include <sys/uio.h>#include <sys/kernel.h>#include <sys/syslog.h>#include <machine/pmioctl.h>#include <machine/machConst.h>#include <machine/dc7085cons.h>#include <pmax/pmax/pmaxtype.h>#include <pmax/pmax/maxine.h>#include <pmax/pmax/asic.h>#include <pmax/dev/device.h>#include <pmax/dev/dtopreg.h>#include <pmax/dev/fbreg.h>extern int pmax_boardtype;void dtop_keyboard_repeat __P((void *));int dtop_null_device_handler __P((dtop_device_t, dtop_message_t, int, int));int dtop_locator_handler __P((dtop_device_t, dtop_message_t, int, int));int dtop_keyboard_handler __P((dtop_device_t, dtop_message_t, int, int));int dtopparam __P((struct tty *, struct termios *));int dtopstop __P((struct tty *, int));void dtopstart __P((struct tty *));void dtopKBDPutc __P((dev_t, int));struct tty dtop_tty[NDTOP];void (*dtopDivertXInput)(); /* X windows keyboard input routine */void (*dtopMouseEvent)(); /* X windows mouse motion event routine */void (*dtopMouseButtons)(); /* X windows mouse buttons event routine */#define DTOP_MAX_POLL 0x7fff /* about half a sec */typedef volatile unsigned int *data_reg_t; /* uC */#define DTOP_GET_BYTE(data) (((*(data)) >> 8) & 0xff)#define DTOP_PUT_BYTE(data,c) { *(data) = (c) << 8; }typedef volatile unsigned int *poll_reg_t; /* SIR */#define DTOP_RX_AVAIL(poll) (*(poll) & 1)#define DTOP_TX_AVAIL(poll) (*(poll) & 2)#define GET_SHORT(b0,b1) (((b0)<<8)|(b1))/* * Driver status */struct dtop_softc { data_reg_t data; poll_reg_t poll; char polling_mode; char probed_once; short bad_pkts; struct dtop_ds { int (*handler)(); dtop_device status; } device[(DTOP_ADDR_DEFAULT - DTOP_ADDR_FIRST) >> 1];# define DTOP_DEVICE_NO(address) (((address)-DTOP_ADDR_FIRST)>>1)} dtop_softc[NDTOP];typedef struct dtop_softc *dtop_softc_t;struct tty dtop_tty[NDTOP];/* * lk201 keyboard divisions and up/down mode key bitmap. */#define NUMDIVS 14static u_char divbeg[NUMDIVS] = {0xbf, 0x91, 0xbc, 0xbd, 0xb0, 0xad, 0xa6, 0xa9, 0x88, 0x56, 0x63, 0x6f, 0x7b, 0x7e};static u_char divend[NUMDIVS] = {0xff, 0xa5, 0xbc, 0xbe, 0xb2, 0xaf, 0xa8, 0xac, 0x90, 0x62, 0x6e, 0x7a, 0x7d, 0x87};/* * Initial defaults, groups 5 and 6 are up/down */static u_long keymodes[8] = {0, 0, 0, 0, 0, 0x0003e000, 0, 0};/* * Definition of the driver for the auto-configuration program. */int dtopprobe();void dtopintr();struct driver dtopdriver = { "dtop", dtopprobe, 0, 0, dtopintr,};dtopprobe(cp) struct pmax_ctlr *cp;{ register struct tty *tp; register int cntr; int dtopunit = cp->pmax_unit, i, s; dtop_softc_t dtop; if (dtopunit >= NDTOP) return (0); if (badaddr(cp->pmax_addr, 2)) return (0); dtop = &dtop_softc[dtopunit]; dtop->poll = (poll_reg_t)MACH_PHYS_TO_UNCACHED(XINE_REG_INTR); dtop->data = (data_reg_t)cp->pmax_addr; for (i = 0; i < DTOP_MAX_DEVICES; i++) dtop->device[i].handler = dtop_null_device_handler; /* a lot more needed here, fornow: */ dtop->device[DTOP_DEVICE_NO(0x6a)].handler = dtop_locator_handler; dtop->device[DTOP_DEVICE_NO(0x6c)].handler = dtop_keyboard_handler; dtop->device[DTOP_DEVICE_NO(0x6c)].status.keyboard.k_ar_state = K_AR_IDLE; dtop->probed_once = 1; printf("dtop%d at nexus0 csr 0x%x priority %d\n", cp->pmax_unit, cp->pmax_addr, cp->pmax_pri); return (1);}dtopopen(dev, flag, mode, p) dev_t dev; int flag, mode; struct proc *p;{ register struct tty *tp; register int unit; int s, error = 0; unit = minor(dev); if (unit >= NDTOP) return (ENXIO); tp = &dtop_tty[unit]; tp->t_oproc = dtopstart; tp->t_param = dtopparam; tp->t_dev = dev; if ((tp->t_state & TS_ISOPEN) == 0) { tp->t_state |= TS_WOPEN; ttychars(tp); if (tp->t_ispeed == 0) { tp->t_iflag = TTYDEF_IFLAG; tp->t_oflag = TTYDEF_OFLAG; tp->t_cflag = TTYDEF_CFLAG; tp->t_lflag = TTYDEF_LFLAG; tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED; } (void) dtopparam(tp, &tp->t_termios); ttsetwater(tp); } else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0) return (EBUSY); s = spltty(); while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) && !(tp->t_state & TS_CARR_ON)) { tp->t_state |= TS_WOPEN; if (error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, ttopen, 0)) break; } splx(s); if (error) return (error); error = (*linesw[tp->t_line].l_open)(dev, tp); return (error);}/*ARGSUSED*/dtopclose(dev, flag, mode, p) dev_t dev; int flag, mode; struct proc *p;{ register struct tty *tp; register int unit; unit = minor(dev); tp = &dtop_tty[unit]; (*linesw[tp->t_line].l_close)(tp, flag); return (ttyclose(tp));}dtopread(dev, uio, flag) dev_t dev; struct uio *uio;{ register struct tty *tp; tp = &dtop_tty[minor(dev)]; return ((*linesw[tp->t_line].l_read)(tp, uio, flag));}dtopwrite(dev, uio, flag) dev_t dev; struct uio *uio;{ register struct tty *tp; tp = &dtop_tty[minor(dev)]; return ((*linesw[tp->t_line].l_write)(tp, uio, flag));}/*ARGSUSED*/dtopioctl(dev, cmd, data, flag, p) dev_t dev; int cmd; caddr_t data; int flag; struct proc *p;{ register struct tty *tp; register int unit = minor(dev); int error; tp = &dtop_tty[unit]; error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p); if (error >= 0) return (error); error = ttioctl(tp, cmd, data, flag); if (error >= 0) return (error); switch (cmd) { case TIOCSBRK: ttyoutput(0, tp); break; case TIOCCBRK: ttyoutput(0, tp); break; case TIOCMGET: *(int *)data = DML_DTR | DML_DSR | DML_CAR; break; default: return (ENOTTY); } return (0);}/* * Interrupt routine */voiddtopintr(unit) int unit;{ dtop_message msg; int devno; dtop_softc_t dtop; dtop = &dtop_softc[unit]; if (dtop_get_packet(dtop, &msg) < 0) {#ifdef DIAGNOSTIC printf("dtop: overrun (or stray)\n");#endif /* * Ugh! The most common occurrence of a data overrun is upon a * key press and the result is a software generated "stuck key". * All I can think to do is fake an "all keys up" whenever a * data overrun occurs. */ msg.src_address = 0x6c; msg.code.val.len = 1; msg.body[0] = DTOP_KBD_EMPTY; } /* * If not probed yet, just throw the data away. */ if (!dtop->probed_once) return; devno = DTOP_DEVICE_NO(msg.src_address); if (devno < 0 || devno > 15) return; (void) (*dtop->device[devno].handler) (&dtop->device[devno].status, &msg, DTOP_EVENT_RECEIVE_PACKET, 0);}voiddtopstart(tp) register struct tty *tp;{ register int cc; int s; s = spltty(); if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) goto out; if (tp->t_outq.c_cc <= tp->t_lowat) { if (tp->t_state & TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; wakeup((caddr_t)&tp->t_outq); } selwakeup(&tp->t_wsel); } if (tp->t_outq.c_cc == 0) goto out; /* handle console specially */ if (tp == dtop_tty) { while (tp->t_outq.c_cc > 0) { cc = getc(&tp->t_outq) & 0x7f; cnputc(cc); } /* * After we flush the output queue we may need to wake * up the process that made the output. */ if (tp->t_outq.c_cc <= tp->t_lowat) { if (tp->t_state & TS_ASLEEP) { tp->t_state &= ~TS_ASLEEP; wakeup((caddr_t)&tp->t_outq); } selwakeup(&tp->t_wsel); } }out: splx(s);}voiddtopKBDPutc(dev, c) dev_t dev;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -