📄 istallion.c
字号:
if (tty != cooktty) tty = cooktty; if (cooksize == 0) return; portp = tty->driver_data; if (portp == NULL) return; if (portp->brdnr >= stli_nrbrds) return; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return; spin_lock_irqsave(&brd_lock, flags); EBRDENABLE(brdp); ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); head = (unsigned int) readw(&ap->txq.head); tail = (unsigned int) readw(&ap->txq.tail); if (tail != ((unsigned int) readw(&ap->txq.tail))) tail = (unsigned int) readw(&ap->txq.tail); size = portp->txsize; if (head >= tail) { len = size - (head - tail) - 1; stlen = size - head; } else { len = tail - head - 1; stlen = len; } len = min(len, cooksize); count = 0; shbuf = EBRDGETMEMPTR(brdp, portp->txoffset); buf = stli_txcookbuf; while (len > 0) { stlen = min(len, stlen); memcpy_toio(shbuf + head, buf, stlen); buf += stlen; len -= stlen; count += stlen; head += stlen; if (head >= size) { head = 0; stlen = tail; } } ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr); writew(head, &ap->txq.head); if (test_bit(ST_TXBUSY, &portp->state)) { if (readl(&ap->changed.data) & DT_TXEMPTY) writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data); } hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset + portp->portidx; writeb(readb(bits) | portp->portbit, bits); set_bit(ST_TXBUSY, &portp->state); EBRDDISABLE(brdp); spin_unlock_irqrestore(&brd_lock, flags);}/*****************************************************************************/static int stli_writeroom(struct tty_struct *tty){ cdkasyrq_t __iomem *rp; struct stliport *portp; struct stlibrd *brdp; unsigned int head, tail, len; unsigned long flags; if (tty == stli_txcooktty) { if (stli_txcookrealsize != 0) { len = stli_txcookrealsize - stli_txcooksize; return len; } } portp = tty->driver_data; if (portp == NULL) return 0; if (portp->brdnr >= stli_nrbrds) return 0; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return 0; spin_lock_irqsave(&brd_lock, flags); EBRDENABLE(brdp); rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq; head = (unsigned int) readw(&rp->head); tail = (unsigned int) readw(&rp->tail); if (tail != ((unsigned int) readw(&rp->tail))) tail = (unsigned int) readw(&rp->tail); len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head); len--; EBRDDISABLE(brdp); spin_unlock_irqrestore(&brd_lock, flags); if (tty == stli_txcooktty) { stli_txcookrealsize = len; len -= stli_txcooksize; } return len;}/*****************************************************************************//* * Return the number of characters in the transmit buffer. Normally we * will return the number of chars in the shared memory ring queue. * We need to kludge around the case where the shared memory buffer is * empty but not all characters have drained yet, for this case just * return that there is 1 character in the buffer! */static int stli_charsinbuffer(struct tty_struct *tty){ cdkasyrq_t __iomem *rp; struct stliport *portp; struct stlibrd *brdp; unsigned int head, tail, len; unsigned long flags; if (tty == stli_txcooktty) stli_flushchars(tty); portp = tty->driver_data; if (portp == NULL) return 0; if (portp->brdnr >= stli_nrbrds) return 0; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return 0; spin_lock_irqsave(&brd_lock, flags); EBRDENABLE(brdp); rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq; head = (unsigned int) readw(&rp->head); tail = (unsigned int) readw(&rp->tail); if (tail != ((unsigned int) readw(&rp->tail))) tail = (unsigned int) readw(&rp->tail); len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head)); if ((len == 0) && test_bit(ST_TXBUSY, &portp->state)) len = 1; EBRDDISABLE(brdp); spin_unlock_irqrestore(&brd_lock, flags); return len;}/*****************************************************************************//* * Generate the serial struct info. */static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp){ struct serial_struct sio; struct stlibrd *brdp; memset(&sio, 0, sizeof(struct serial_struct)); sio.type = PORT_UNKNOWN; sio.line = portp->portnr; sio.irq = 0; sio.flags = portp->flags; sio.baud_base = portp->baud_base; sio.close_delay = portp->close_delay; sio.closing_wait = portp->closing_wait; sio.custom_divisor = portp->custom_divisor; sio.xmit_fifo_size = 0; sio.hub6 = 0; brdp = stli_brds[portp->brdnr]; if (brdp != NULL) sio.port = brdp->iobase; return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;}/*****************************************************************************//* * Set port according to the serial struct info. * At this point we do not do any auto-configure stuff, so we will * just quietly ignore any requests to change irq, etc. */static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp){ struct serial_struct sio; int rc; if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) return -EFAULT; if (!capable(CAP_SYS_ADMIN)) { if ((sio.baud_base != portp->baud_base) || (sio.close_delay != portp->close_delay) || ((sio.flags & ~ASYNC_USR_MASK) != (portp->flags & ~ASYNC_USR_MASK))) return -EPERM; } portp->flags = (portp->flags & ~ASYNC_USR_MASK) | (sio.flags & ASYNC_USR_MASK); portp->baud_base = sio.baud_base; portp->close_delay = sio.close_delay; portp->closing_wait = sio.closing_wait; portp->custom_divisor = sio.custom_divisor; if ((rc = stli_setport(portp)) < 0) return rc; return 0;}/*****************************************************************************/static int stli_tiocmget(struct tty_struct *tty, struct file *file){ struct stliport *portp = tty->driver_data; struct stlibrd *brdp; int rc; if (portp == NULL) return -ENODEV; if (portp->brdnr >= stli_nrbrds) return 0; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return 0; if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, sizeof(asysigs_t), 1)) < 0) return rc; return stli_mktiocm(portp->asig.sigvalue);}static int stli_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear){ struct stliport *portp = tty->driver_data; struct stlibrd *brdp; int rts = -1, dtr = -1; if (portp == NULL) return -ENODEV; if (portp->brdnr >= stli_nrbrds) return 0; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return 0; if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; if (set & TIOCM_RTS) rts = 1; if (set & TIOCM_DTR) dtr = 1; if (clear & TIOCM_RTS) rts = 0; if (clear & TIOCM_DTR) dtr = 0; stli_mkasysigs(&portp->asig, dtr, rts); return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0);}static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg){ struct stliport *portp; struct stlibrd *brdp; unsigned int ival; int rc; void __user *argp = (void __user *)arg; portp = tty->driver_data; if (portp == NULL) return -ENODEV; if (portp->brdnr >= stli_nrbrds) return 0; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return 0; if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { if (tty->flags & (1 << TTY_IO_ERROR)) return -EIO; } rc = 0; switch (cmd) { case TIOCGSOFTCAR: rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), (unsigned __user *) arg); break; case TIOCSSOFTCAR: if ((rc = get_user(ival, (unsigned __user *) arg)) == 0) tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0); break; case TIOCGSERIAL: rc = stli_getserial(portp, argp); break; case TIOCSSERIAL: rc = stli_setserial(portp, argp); break; case STL_GETPFLAG: rc = put_user(portp->pflag, (unsigned __user *)argp); break; case STL_SETPFLAG: if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0) stli_setport(portp); break; case COM_GETPORTSTATS: rc = stli_getportstats(portp, argp); break; case COM_CLRPORTSTATS: rc = stli_clrportstats(portp, argp); break; case TIOCSERCONFIG: case TIOCSERGWILD: case TIOCSERSWILD: case TIOCSERGETLSR: case TIOCSERGSTRUCT: case TIOCSERGETMULTI: case TIOCSERSETMULTI: default: rc = -ENOIOCTLCMD; break; } return rc;}/*****************************************************************************//* * This routine assumes that we have user context and can sleep. * Looks like it is true for the current ttys implementation..!! */static void stli_settermios(struct tty_struct *tty, struct ktermios *old){ struct stliport *portp; struct stlibrd *brdp; struct ktermios *tiosp; asyport_t aport; if (tty == NULL) return; portp = tty->driver_data; if (portp == NULL) return; if (portp->brdnr >= stli_nrbrds) return; brdp = stli_brds[portp->brdnr]; if (brdp == NULL) return; tiosp = tty->termios; stli_mkasyport(portp, &aport, tiosp); stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0); stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1); stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, sizeof(asysigs_t), 0); if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) tty->hw_stopped = 0; if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL)) wake_up_interruptible(&portp->open_wait);}/*****************************************************************************//* * Attempt to flow control who ever is sending us data. We won't really * do any flow control action here. We can't directly, and even if we * wanted to we would have to send a command to the slave. The slave * knows how to flow control, and will do so when its buffers reach its * internal high water marks. So what we will do is set a local state * bit that will stop us sending any RX data up from the poll routine * (which is the place where RX data from the slave is handled). */static void stli_throttle(struct tty_struct *tty){ struct stliport *portp = tty->driver_data; if (portp == NULL) return; set_bit(ST_RXSTOP, &portp->state);}/*****************************************************************************//* * Unflow control the device sending us data... That means that all * we have to do is clear the RXSTOP state bit. The next poll call * will then be able to pass the RX data back up. */static void stli_unthrottle(struct tty_struct *tty){ struct stliport *portp = tty->driver_data; if (portp == NULL) return; clear_bit(ST_RXSTOP, &portp->state);}/*****************************************************************************//* * Stop the transmitter. */static void stli_stop(struct tty_struct *tty){}/*****************************************************************************//* * Start the transmitter again. */static void stli_start(struct tty_struct *tty){}/*****************************************************************************//* * Scheduler called hang up routine. This is called from the scheduler, * not direct from the driver "poll" routine. We can't call it there * since the real local hangup code will enable/disable the board and * other things that we can't do while handling the poll. Much easier * to deal with it some time later (don't really care when, hangups * aren't that time critical). */static void stli_dohangup(struct work_struct *ugly_api){ struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup); if (portp->tty != NULL) { tty_hangup(portp->tty); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -