⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zs.c

📁 自己根据lkd和情境分析
💻 C
📖 第 1 页 / 共 5 页
字号:
	restore_flags(flags);}void mouse_put_char(char ch){	struct sun_zschannel *chan = zs_mousechan;	unsigned long flags;	if(!chan)		return;	save_flags(flags); cli();	zs_put_char(chan, ch);	restore_flags(flags);}/* These are for receiving and sending characters under the kgdb * source level kernel debugger. */void putDebugChar(char kgdb_char){	struct sun_zschannel *chan = zs_kgdbchan;	while((sbus_readb(&chan->control) & Tx_BUF_EMP)==0)		udelay(5);	sbus_writeb(kgdb_char, &chan->data);	ZS_WSYNC(chan);	ZSLOG(REGDATA, kgdb_char, 1);}char getDebugChar(void){	struct sun_zschannel *chan = zs_kgdbchan;	u8 val;	do {		val = sbus_readb(&chan->control);		ZSLOG(REGCTRL, val, 0);		udelay(5);	} while ((val & Rx_CH_AV) == 0);	val = sbus_readb(&chan->data);	ZSLOG(REGDATA, val, 0);	return val;}static void zs_flush_chars(struct tty_struct *tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	unsigned long flags;	if (serial_paranoia_check(info, tty->device, "zs_flush_chars"))		return;	save_flags(flags); cli();	if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||	    !info->xmit_buf)		goto out;	/* Enable transmitter */	info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;	write_zsreg(info->zs_channel, 1, info->curregs[1]);	info->curregs[5] |= TxENAB;	write_zsreg(info->zs_channel, 5, info->curregs[5]);	/*	 * Send a first (bootstrapping) character. A best solution is	 * to call transmit_chars() here which handles output in a	 * generic way. Current transmit_chars() not only transmits,	 * but resets interrupts also what we do not desire here.	 * XXX Discuss with David.	 */	zs_put_char(info->zs_channel, info->xmit_buf[info->xmit_tail++]);	info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);	info->xmit_cnt--;out:	restore_flags(flags);}static int zs_write(struct tty_struct * tty, int from_user,		    const unsigned char *buf, int count){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	unsigned long flags;	int c, total = 0;	if (serial_paranoia_check(info, tty->device, "zs_write"))		return 0;	if (!info || !info->xmit_buf || !tmp_buf)		return 0;	save_flags(flags);	if (from_user) {		down(&tmp_buf_sem);		while (1) {			c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,					   SERIAL_XMIT_SIZE - info->xmit_head));			if (c <= 0)				break;			c -= copy_from_user(tmp_buf, buf, c);			if (!c) {				if (!total)					total = -EFAULT;				break;			}			cli();			c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,				       SERIAL_XMIT_SIZE - info->xmit_head));			memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);			info->xmit_head = ((info->xmit_head + c) &					   (SERIAL_XMIT_SIZE - 1));			info->xmit_cnt += c;			restore_flags(flags);			buf += c;			count -= c;			total += c;		}		up(&tmp_buf_sem);	} else {		while (1) {			cli();					c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,					   SERIAL_XMIT_SIZE - info->xmit_head));			if (c <= 0) {				restore_flags(flags);				break;			}			memcpy(info->xmit_buf + info->xmit_head, buf, c);			info->xmit_head = ((info->xmit_head + c) &					   (SERIAL_XMIT_SIZE - 1));			info->xmit_cnt += c;			restore_flags(flags);			buf += c;			count -= c;			total += c;		}	}	cli();			if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {		/* Enable transmitter */		info->curregs[1] |= TxINT_ENAB|EXT_INT_ENAB;		write_zsreg(info->zs_channel, 1, info->curregs[1]);		info->curregs[5] |= TxENAB;		write_zsreg(info->zs_channel, 5, info->curregs[5]);#if 1		zs_put_char(info->zs_channel,			    info->xmit_buf[info->xmit_tail++]);		info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);		info->xmit_cnt--;#endif	}	restore_flags(flags);	return total;}static int zs_write_room(struct tty_struct *tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	int ret;	if (serial_paranoia_check(info, tty->device, "zs_write_room"))		return 0;	ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;	if (ret < 0)		ret = 0;	return ret;}static int zs_chars_in_buffer(struct tty_struct *tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	if (serial_paranoia_check(info, tty->device, "zs_chars_in_buffer"))		return 0;	return info->xmit_cnt;}static void zs_flush_buffer(struct tty_struct *tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	if (serial_paranoia_check(info, tty->device, "zs_flush_buffer"))		return;	cli();	info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;	sti();	wake_up_interruptible(&tty->write_wait);	if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&	    tty->ldisc.write_wakeup)		(tty->ldisc.write_wakeup)(tty);}/* * ------------------------------------------------------------ * zs_throttle() *  * This routine is called by the upper-layer tty layer to signal that * incoming characters should be throttled. * ------------------------------------------------------------ */static void zs_throttle(struct tty_struct * tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;#ifdef SERIAL_DEBUG_THROTTLE	char	buf[64];		printk("throttle %s: %d....\n", _tty_name(tty, buf),	       tty->ldisc.chars_in_buffer(tty));#endif	if (serial_paranoia_check(info, tty->device, "zs_throttle"))		return;		if (I_IXOFF(tty))		info->x_char = STOP_CHAR(tty);	/* Turn off RTS line */	cli();	info->curregs[5] &= ~RTS;	write_zsreg(info->zs_channel, 5, info->curregs[5]);	sti();}static void zs_unthrottle(struct tty_struct * tty){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;#ifdef SERIAL_DEBUG_THROTTLE	char	buf[64];		printk("unthrottle %s: %d....\n", _tty_name(tty, buf),	       tty->ldisc.chars_in_buffer(tty));#endif	if (serial_paranoia_check(info, tty->device, "zs_unthrottle"))		return;		if (I_IXOFF(tty)) {		if (info->x_char)			info->x_char = 0;		else			info->x_char = START_CHAR(tty);	}	/* Assert RTS line */	cli();	info->curregs[5] |= RTS;	write_zsreg(info->zs_channel, 5, info->curregs[5]);	sti();}/* * ------------------------------------------------------------ * zs_ioctl() and friends * ------------------------------------------------------------ */static int get_serial_info(struct sun_serial * info,			   struct serial_struct * retinfo){	struct serial_struct tmp;  	if (!retinfo)		return -EFAULT;	memset(&tmp, 0, sizeof(tmp));	tmp.type = info->type;	tmp.line = info->line;	tmp.port = info->port;	tmp.irq = info->irq;	tmp.flags = info->flags;	tmp.baud_base = info->baud_base;	tmp.close_delay = info->close_delay;	tmp.closing_wait = info->closing_wait;	tmp.custom_divisor = info->custom_divisor;	if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))		return -EFAULT;	return 0;}static int set_serial_info(struct sun_serial * info,			   struct serial_struct * new_info){	struct serial_struct new_serial;	struct sun_serial old_info;	int retval = 0;	if (!new_info || copy_from_user(&new_serial,new_info,sizeof(new_serial)))		return -EFAULT;	old_info = *info;	if (!capable(CAP_SYS_ADMIN)) {		if ((new_serial.baud_base != info->baud_base) ||		    (new_serial.type != info->type) ||		    (new_serial.close_delay != info->close_delay) ||		    ((new_serial.flags & ~ZILOG_USR_MASK) !=		     (info->flags & ~ZILOG_USR_MASK)))			return -EPERM;		info->flags = ((info->flags & ~ZILOG_USR_MASK) |			       (new_serial.flags & ZILOG_USR_MASK));		info->custom_divisor = new_serial.custom_divisor;		goto check_and_exit;	}	if(new_serial.baud_base < 9600)		return -EINVAL;	if (info->count > 1)		return -EBUSY;	/*	 * OK, past this point, all the error checking has been done.	 * At this point, we start making changes.....	 */	info->baud_base = new_serial.baud_base;	info->flags = ((info->flags & ~ZILOG_FLAGS) |			(new_serial.flags & ZILOG_FLAGS));	info->custom_divisor = new_serial.custom_divisor;	info->type = new_serial.type;	info->close_delay = new_serial.close_delay;	info->closing_wait = new_serial.closing_wait;check_and_exit:	retval = startup(info);	return retval;}/* * get_lsr_info - get line status register info * * Purpose: Let user call ioctl() to get info when the UART physically * 	    is emptied.  On bus types like RS485, the transmitter must * 	    release the bus after transmitting. This must be done when * 	    the transmit shift register is empty, not be done when the * 	    transmit holding register is empty.  This functionality * 	    allows an RS485 driver to be written in user space.  */static int get_lsr_info(struct sun_serial * info, unsigned int *value){	unsigned char status;	cli();	status = sbus_readb(&info->zs_channel->control);	ZSDELAY();	ZSLOG(REGCTRL, status, 0);	sti();	if (put_user(status, value))		return -EFAULT;	return 0;}static int get_modem_info(struct sun_serial * info, unsigned int *value){	unsigned char status;	unsigned int result;	cli();	status = sbus_readb(&info->zs_channel->control);	ZSDELAY();	ZSLOG(REGCTRL, status, 0);	sti();	result =  ((info->curregs[5] & RTS) ? TIOCM_RTS : 0)		| ((info->curregs[5] & DTR) ? TIOCM_DTR : 0)		| ((status  & DCD) ? TIOCM_CAR : 0)		| ((status  & SYNC) ? TIOCM_DSR : 0)		| ((status  & CTS) ? TIOCM_CTS : 0);	if (put_user(result, value))		return -EFAULT;	return 0;}static int set_modem_info(struct sun_serial * info, unsigned int cmd,			  unsigned int *value){	unsigned int arg;	if (get_user(arg, value))		return -EFAULT;	switch (cmd) {	case TIOCMBIS: 		if (arg & TIOCM_RTS)			info->curregs[5] |= RTS;		if (arg & TIOCM_DTR)			info->curregs[5] |= DTR;		break;	case TIOCMBIC:		if (arg & TIOCM_RTS)			info->curregs[5] &= ~RTS;		if (arg & TIOCM_DTR)			info->curregs[5] &= ~DTR;		break;	case TIOCMSET:		info->curregs[5] = ((info->curregs[5] & ~(RTS | DTR))			     | ((arg & TIOCM_RTS) ? RTS : 0)			     | ((arg & TIOCM_DTR) ? DTR : 0));		break;	default:		return -EINVAL;	}	cli();	write_zsreg(info->zs_channel, 5, info->curregs[5]);	sti();	return 0;}/* * This routine sends a break character out the serial port. */static void send_break(	struct sun_serial * info, int duration){	if (!info->port)		return;	current->state = TASK_INTERRUPTIBLE;	cli();	write_zsreg(info->zs_channel, 5, (info->curregs[5] | SND_BRK));	schedule_timeout(duration);	write_zsreg(info->zs_channel, 5, info->curregs[5]);	sti();}static int zs_ioctl(struct tty_struct *tty, struct file * file,		    unsigned int cmd, unsigned long arg){	struct sun_serial * info = (struct sun_serial *) tty->driver_data;	int retval;	if (serial_paranoia_check(info, tty->device, "zs_ioctl"))		return -ENODEV;	if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&	    (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD)  &&	    (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {		if (tty->flags & (1 << TTY_IO_ERROR))		    return -EIO;	}		switch (cmd) {		case TCSBRK:	/* SVID version: non-zero arg --> no break */			retval = tty_check_change(tty);			if (retval)				return retval;			tty_wait_until_sent(tty, 0);			if (!arg)				send_break(info, HZ/4);	/* 1/4 second */			return 0;		case TCSBRKP:	/* support for POSIX tcsendbreak() */			retval = tty_check_change(tty);			if (retval)				return retval;			tty_wait_until_sent(tty, 0);			send_break(info, arg ? arg*(HZ/10) : HZ/4);			return 0;		case TIOCGSOFTCAR:			if (put_user(C_CLOCAL(tty) ? 1 : 0,				     (unsigned long *) arg))				return -EFAULT;			return 0;		case TIOCSSOFTCAR:			if (get_user(arg, (unsigned long *) arg))				return -EFAULT;			tty->termios->c_cflag =				((tty->termios->c_cflag & ~CLOCAL) |				 (arg ? CLOCAL : 0));			return 0;		case TIOCMGET:			return get_modem_info(info, (unsigned int *) arg);		case TIOCMBIS:		case TIOCMBIC:		case TIOCMSET:			return set_modem_info(info, cmd, (unsigned int *) arg);		case TIOCGSERIAL:			return get_serial_info(info,					       (struct serial_struct *) arg);		case TIOCSSERIAL:			return set_serial_info(info,					       (struct serial_struct *) arg);		case TIOCSERGETLSR: /* Get line status register */			return get_lsr_info(info, (unsigned int *) arg);		case TIOCSERGSTRUCT:			if (copy_to_user((struct sun_serial *) arg,				    info, sizeof(struct sun_serial)))				return -EFAULT;			return 0;					default:			return -ENOIOCTLCMD;		}	return 0;}static void zs_set_termios(struct tty_struct *tty, struct termios *old_termios){	struct sun_serial *info = (struct sun_serial *) tty->driver_data;	if (tty->termios->c_cflag == old_termios->c_cflag)		return;	change_speed(info);	if ((old_termios->c_cflag & CRTSCTS) &&	    !(tty->termios->c_cflag & CRTSCTS)) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -