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

📄 riscom8.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 4 页
字号:
		interruptible_sleep_on(&port->close_wait);		if (port->flags & ASYNC_HUP_NOTIFY)			return -EAGAIN;		else			return -ERESTARTSYS;	}	/*	 * If this is a callout device, then just make sure the normal	 * device isn't being used.	 */	if (tty->driver.subtype == RISCOM_TYPE_CALLOUT) {		if (port->flags & ASYNC_NORMAL_ACTIVE)			return -EBUSY;		if ((port->flags & ASYNC_CALLOUT_ACTIVE) &&		    (port->flags & ASYNC_SESSION_LOCKOUT) &&		    (port->session != current->session))		    return -EBUSY;		if ((port->flags & ASYNC_CALLOUT_ACTIVE) &&		    (port->flags & ASYNC_PGRP_LOCKOUT) &&		    (port->pgrp != current->pgrp))		    return -EBUSY;		port->flags |= ASYNC_CALLOUT_ACTIVE;		return 0;	}		/*	 * If non-blocking mode is set, or the port is not enabled,	 * then make the check up front and then exit.	 */	if ((filp->f_flags & O_NONBLOCK) ||	    (tty->flags & (1 << TTY_IO_ERROR))) {		if (port->flags & ASYNC_CALLOUT_ACTIVE)			return -EBUSY;		port->flags |= ASYNC_NORMAL_ACTIVE;		return 0;	}	if (port->flags & ASYNC_CALLOUT_ACTIVE) {		if (port->normal_termios.c_cflag & CLOCAL) 			do_clocal = 1;	} else {		if (C_CLOCAL(tty))  			do_clocal = 1;	}		/*	 * Block waiting for the carrier detect and the line to become	 * free (i.e., not in use by the callout).  While we are in	 * this loop, info->count is dropped by one, so that	 * rs_close() knows when to free things.  We restore it upon	 * exit, either normal or abnormal.	 */	retval = 0;	add_wait_queue(&port->open_wait, &wait);	cli();	if (!tty_hung_up_p(filp))		port->count--;	sti();	port->blocked_open++;	while (1) {		cli();		rc_out(bp, CD180_CAR, port_No(port));		CD = rc_in(bp, CD180_MSVR) & MSVR_CD;		if (!(port->flags & ASYNC_CALLOUT_ACTIVE))  {			rc_out(bp, CD180_MSVR, MSVR_RTS);			bp->DTR &= ~(1u << port_No(port));			rc_out(bp, RC_DTR, bp->DTR);		}		sti();		set_current_state(TASK_INTERRUPTIBLE);		if (tty_hung_up_p(filp) ||		    !(port->flags & ASYNC_INITIALIZED)) {			if (port->flags & ASYNC_HUP_NOTIFY)				retval = -EAGAIN;			else				retval = -ERESTARTSYS;				break;		}		if (!(port->flags & ASYNC_CALLOUT_ACTIVE) &&		    !(port->flags & ASYNC_CLOSING) &&		    (do_clocal || CD))			break;		if (signal_pending(current)) {			retval = -ERESTARTSYS;			break;		}		schedule();	}	current->state = TASK_RUNNING;	remove_wait_queue(&port->open_wait, &wait);	if (!tty_hung_up_p(filp))		port->count++;	port->blocked_open--;	if (retval)		return retval;		port->flags |= ASYNC_NORMAL_ACTIVE;	return 0;}	static int rc_open(struct tty_struct * tty, struct file * filp){	int board;	int error;	struct riscom_port * port;	struct riscom_board * bp;	unsigned long flags;		board = RC_BOARD(MINOR(tty->device));	if (board > RC_NBOARD || !(rc_board[board].flags & RC_BOARD_PRESENT))		return -ENODEV;		bp = &rc_board[board];	port = rc_port + board * RC_NPORT + RC_PORT(MINOR(tty->device));	if (rc_paranoia_check(port, tty->device, "rc_open"))		return -ENODEV;		if ((error = rc_setup_board(bp))) 		return error;			port->count++;	tty->driver_data = port;	port->tty = tty;		if ((error = rc_setup_port(bp, port))) 		return error;		if ((error = block_til_ready(tty, filp, port)))		return error;		if ((port->count == 1) && (port->flags & ASYNC_SPLIT_TERMIOS)) {		if (tty->driver.subtype == RISCOM_TYPE_NORMAL)			*tty->termios = port->normal_termios;		else			*tty->termios = port->callout_termios;		save_flags(flags); cli();		rc_change_speed(bp, port);		restore_flags(flags);	}	port->session = current->session;	port->pgrp = current->pgrp;		return 0;}static void rc_close(struct tty_struct * tty, struct file * filp){	struct riscom_port *port = (struct riscom_port *) tty->driver_data;	struct riscom_board *bp;	unsigned long flags;	unsigned long timeout;		if (!port || rc_paranoia_check(port, tty->device, "close"))		return;		save_flags(flags); cli();	if (tty_hung_up_p(filp))  {		restore_flags(flags);		return;	}		bp = port_Board(port);	if ((tty->count == 1) && (port->count != 1))  {		printk("rc%d: rc_close: bad port count;"		       " tty->count is 1, port count is %d\n",		       board_No(bp), port->count);		port->count = 1;	}	if (--port->count < 0)  {		printk("rc%d: rc_close: bad port count for tty%d: %d\n",		       board_No(bp), port_No(port), port->count);		port->count = 0;	}	if (port->count)  {		restore_flags(flags);		return;	}	port->flags |= ASYNC_CLOSING;	/*	 * Save the termios structure, since this port may have	 * separate termios for callout and dialin.	 */	if (port->flags & ASYNC_NORMAL_ACTIVE)		port->normal_termios = *tty->termios;	if (port->flags & ASYNC_CALLOUT_ACTIVE)		port->callout_termios = *tty->termios;	/*	 * Now we wait for the transmit buffer to clear; and we notify 	 * the line discipline to only process XON/XOFF characters.	 */	tty->closing = 1;	if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)		tty_wait_until_sent(tty, port->closing_wait);	/*	 * At this point we stop accepting input.  To do this, we	 * disable the receive line status interrupts, and tell the	 * interrupt driver to stop checking the data ready bit in the	 * line status register.	 */	port->IER &= ~IER_RXD;	if (port->flags & ASYNC_INITIALIZED) {		port->IER &= ~IER_TXRDY;		port->IER |= IER_TXEMPTY;		rc_out(bp, CD180_CAR, port_No(port));		rc_out(bp, CD180_IER, port->IER);		/*		 * Before we drop DTR, make sure the UART transmitter		 * has completely drained; this is especially		 * important if there is a transmit FIFO!		 */		timeout = jiffies+HZ;		while(port->IER & IER_TXEMPTY)  {			current->state = TASK_INTERRUPTIBLE; 			schedule_timeout(port->timeout);			if (time_after(jiffies, timeout))				break;		}	}	rc_shutdown_port(bp, port);	if (tty->driver.flush_buffer)		tty->driver.flush_buffer(tty);	if (tty->ldisc.flush_buffer)		tty->ldisc.flush_buffer(tty);	tty->closing = 0;	port->event = 0;	port->tty = 0;	if (port->blocked_open) {		if (port->close_delay) {			current->state = TASK_INTERRUPTIBLE;			schedule_timeout(port->close_delay);		}		wake_up_interruptible(&port->open_wait);	}	port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|			 ASYNC_CLOSING);	wake_up_interruptible(&port->close_wait);	restore_flags(flags);}static int rc_write(struct tty_struct * tty, int from_user, 		    const unsigned char *buf, int count){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;	struct riscom_board *bp;	int c, total = 0;	unsigned long flags;					if (rc_paranoia_check(port, tty->device, "rc_write"))		return 0;		bp = port_Board(port);	if (!tty || !port->xmit_buf || !tmp_buf)		return 0;	if (from_user)		down(&tmp_buf_sem);	save_flags(flags);	while (1) {		cli();				c = MIN(count, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,				   SERIAL_XMIT_SIZE - port->xmit_head));		if (c <= 0)			break;		if (from_user) {			copy_from_user(tmp_buf, buf, c);			c = MIN(c, MIN(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,				       SERIAL_XMIT_SIZE - port->xmit_head));			memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c);		} else			memcpy(port->xmit_buf + port->xmit_head, buf, c);		port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);		port->xmit_cnt += c;		restore_flags(flags);		buf += c;		count -= c;		total += c;	}	if (from_user)		up(&tmp_buf_sem);	if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped &&	    !(port->IER & IER_TXRDY)) {		port->IER |= IER_TXRDY;		rc_out(bp, CD180_CAR, port_No(port));		rc_out(bp, CD180_IER, port->IER);	}	restore_flags(flags);	return total;}static void rc_put_char(struct tty_struct * tty, unsigned char ch){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;	unsigned long flags;	if (rc_paranoia_check(port, tty->device, "rc_put_char"))		return;	if (!tty || !port->xmit_buf)		return;	save_flags(flags); cli();		if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {		restore_flags(flags);		return;	}	port->xmit_buf[port->xmit_head++] = ch;	port->xmit_head &= SERIAL_XMIT_SIZE - 1;	port->xmit_cnt++;	restore_flags(flags);}static void rc_flush_chars(struct tty_struct * tty){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;	unsigned long flags;					if (rc_paranoia_check(port, tty->device, "rc_flush_chars"))		return;		if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||	    !port->xmit_buf)		return;	save_flags(flags); cli();	port->IER |= IER_TXRDY;	rc_out(port_Board(port), CD180_CAR, port_No(port));	rc_out(port_Board(port), CD180_IER, port->IER);	restore_flags(flags);}static int rc_write_room(struct tty_struct * tty){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;	int	ret;					if (rc_paranoia_check(port, tty->device, "rc_write_room"))		return 0;	ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;	if (ret < 0)		ret = 0;	return ret;}static int rc_chars_in_buffer(struct tty_struct *tty){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;					if (rc_paranoia_check(port, tty->device, "rc_chars_in_buffer"))		return 0;		return port->xmit_cnt;}static void rc_flush_buffer(struct tty_struct *tty){	struct riscom_port *port = (struct riscom_port *)tty->driver_data;	unsigned long flags;					if (rc_paranoia_check(port, tty->device, "rc_flush_buffer"))		return;	save_flags(flags); cli();	port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;	restore_flags(flags);		wake_up_interruptible(&tty->write_wait);	if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&	    tty->ldisc.write_wakeup)		(tty->ldisc.write_wakeup)(tty);}static int rc_get_modem_info(struct riscom_port * port, unsigned int *value){	struct riscom_board * bp;	unsigned char status;	unsigned int result;	unsigned long flags;	bp = port_Board(port);	save_flags(flags); cli();	rc_out(bp, CD180_CAR, port_No(port));	status = rc_in(bp, CD180_MSVR);	result = rc_in(bp, RC_RI) & (1u << port_No(port)) ? 0 : TIOCM_RNG;	restore_flags(flags);	result |= ((status & MSVR_RTS) ? TIOCM_RTS : 0)		| ((status & MSVR_DTR) ? TIOCM_DTR : 0)		| ((status & MSVR_CD)  ? TIOCM_CAR : 0)		| ((status & MSVR_DSR) ? TIOCM_DSR : 0)		| ((status & MSVR_CTS) ? TIOCM_CTS : 0);	put_user(result, value);	return 0;}static int rc_set_modem_info(struct riscom_port * port, unsigned int cmd,			     unsigned int *value){	int error;	unsigned int arg;	unsigned long flags;	struct riscom_board *bp = port_Board(port);	error = get_user(arg, value);	if (error) 		return error;	switch (cmd) {	 case TIOCMBIS: 		if (arg & TIOCM_RTS) 			port->MSVR |= MSVR_RTS;		if (arg & TIOCM_DTR)			bp->DTR &= ~(1u << port_No(port));		break;	case TIOCMBIC:		if (arg & TIOCM_RTS)			port->MSVR &= ~MSVR_RTS;		if (arg & TIOCM_DTR)			bp->DTR |= (1u << port_No(port));		break;	case TIOCMSET:		port->MSVR = (arg & TIOCM_RTS) ? (port->MSVR | MSVR_RTS) : 					         (port->MSVR & ~MSVR_RTS);		bp->DTR = arg & TIOCM_DTR ? (bp->DTR &= ~(1u << port_No(port))) :					    (bp->DTR |=  (1u << port_No(port)));		break;	 default:		return -EINVAL;	}	save_flags(flags); cli();	rc_out(bp, CD180_CAR, port_No(port));	rc_out(bp, CD180_MSVR, port->MSVR);	rc_out(bp, RC_DTR, bp->DTR);	restore_flags(flags);	return 0;}static inline void rc_send_break(struct riscom_port * port, unsigned long length){	struct riscom_board *bp = port_Board(port);	unsigned long flags;		save_flags(flags); cli();	port->break_length = RISCOM_TPS / HZ * length;	port->COR2 |= COR2_ETC;	port->IER  |= IER_TXRDY;	rc_out(bp, CD180_CAR, port_No(port));	rc_out(bp, CD180_COR2, port->COR2);	rc_out(bp, CD180_IER, port->IER);	rc_wait_CCR(bp);	rc_out(bp, CD180_CCR, CCR_CORCHG2);	rc_wait_CCR(bp);	restore_flags(flags);}static inline int rc_set_serial_info(struct riscom_port * port,				     struct serial_struct * newinfo){	struct serial_struct tmp;	struct riscom_board *bp = port_Board(port);	int change_speed;	unsigned long flags;	int error;		error = verify_area(VERIFY_READ, (void *) newinfo, sizeof(tmp));	if (error)		return error;	copy_from_user(&tmp, newinfo, sizeof(tmp));	#if 0		if ((tmp.irq != bp->irq) ||	    (tmp.port != bp->base) ||	    (tmp.type != PORT_CIRRUS) ||	    (tmp.baud_base != (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC) ||	    (tmp.custom_divisor != 0) ||	    (tmp.xmit_fifo_size != CD180_NFIFO) ||

⌨️ 快捷键说明

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