📄 con3215.c
字号:
break; } return (i >= NR_3215) ? NULL : raw;}/* * Interrupt routine, called from Ingo's I/O layer */static void raw3215_irq(int irq, void *int_parm, struct pt_regs *regs){ raw3215_info *raw; raw3215_req *req; struct tty_struct *tty; devstat_t *stat; int cstat, dstat; int count, slen; stat = (devstat_t *) int_parm; req = (raw3215_req *) stat->intparm; cstat = stat->cstat; dstat = stat->dstat; if (cstat != 0) { raw = raw3215_find_info(irq); if (raw != NULL) { raw->message = KERN_WARNING "Got nonzero channel status in raw3215_irq " "(dev %i, dev sts 0x%2x, sch sts 0x%2x)"; raw->msg_dstat = dstat; raw->msg_cstat = cstat; raw3215_sched_bh(raw); } } if (dstat & 0x01) { /* we got a unit exception */ dstat &= ~0x01; /* we can ignore it */ } switch (dstat) { case 0x80: if (cstat != 0) break; /* Attention interrupt, someone hit the enter key */ if ((raw = raw3215_find_info(irq)) == NULL) return; /* That shouldn't happen ... */ /* Setup a read request */ req = raw3215_mk_read_req(raw); raw3215_mk_read_ccw(raw, req); raw->queued_read = req; if (MACHINE_IS_P390) memset(raw->inbuf, 0, RAW3215_INBUF_SIZE); raw3215_sched_bh(raw); break; case 0x08: case 0x0C: /* Channel end interrupt. */ raw = req->info; if (req->type == RAW3215_READ) { /* store residual count, then wait for device end */ req->residual = stat->rescnt; } if (dstat == 0x08) break; case 0x04: /* Device end interrupt. */ raw = req->info; if (req->type == RAW3215_READ && raw->tty != NULL) { tty = raw->tty; count = 160 - req->residual; if (MACHINE_IS_P390) { slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE); if (count > slen) count = slen; } else if (count >= TTY_FLIPBUF_SIZE - tty->flip.count) count = TTY_FLIPBUF_SIZE - tty->flip.count - 1; EBCASC(raw->inbuf, count); if (count == 2 && ( /* hat is 0xb0 in codepage 037 (US etc.) and thus */ /* converted to 0x5e in ascii ('^') */ strncmp(raw->inbuf, "^c", 2) == 0 || /* hat is 0xb0 in several other codepages (German,*/ /* UK, ...) and thus converted to ascii octal 252 */ strncmp(raw->inbuf, "\252c", 2) == 0) ) { /* emulate a control C = break */ tty->flip.count++; *tty->flip.flag_buf_ptr++ = TTY_NORMAL; *tty->flip.char_buf_ptr++ = INTR_CHAR(tty); tty_flip_buffer_push(raw->tty); } else if (count == 2 && ( strncmp(raw->inbuf, "^d", 2) == 0 || strncmp(raw->inbuf, "\252d", 2) == 0) ) { /* emulate a control D = end of file */ tty->flip.count++; *tty->flip.flag_buf_ptr++ = TTY_NORMAL; *tty->flip.char_buf_ptr++ = EOF_CHAR(tty); tty_flip_buffer_push(raw->tty); } else if (count == 2 && ( strncmp(raw->inbuf, "^z", 2) == 0 || strncmp(raw->inbuf, "\252z", 2) == 0) ) { /* emulate a control Z = suspend */ tty->flip.count++; *tty->flip.flag_buf_ptr++ = TTY_NORMAL; *tty->flip.char_buf_ptr++ = SUSP_CHAR(tty); tty_flip_buffer_push(raw->tty); } else { memcpy(tty->flip.char_buf_ptr, raw->inbuf, count); if (count < 2 || (strncmp(raw->inbuf+count-2, "^n", 2) || strncmp(raw->inbuf+count-2, "\252n", 2)) ) { /* don't add the auto \n */ tty->flip.char_buf_ptr[count] = '\n'; memset(tty->flip.flag_buf_ptr, TTY_NORMAL, count + 1); count++; } else count-=2; tty->flip.char_buf_ptr += count; tty->flip.flag_buf_ptr += count; tty->flip.count += count; tty_flip_buffer_push(raw->tty); } } else if (req->type == RAW3215_WRITE) { raw->count -= ((req->end - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1; } raw->flags &= ~RAW3215_WORKING; raw3215_free_req(req); /* check for empty wait */ if (waitqueue_active(&raw->empty_wait) && raw->queued_write == NULL && raw->queued_read == NULL) { wake_up_interruptible(&raw->empty_wait); } raw3215_sched_bh(raw); break; default: /* Strange interrupt, I'll do my best to clean up */ if ((raw = raw3215_find_info(irq)) == NULL) return; /* That shouldn't happen ... */ if (raw == NULL) break; if (req != NULL && req->type != RAW3215_FREE) { if (req->type == RAW3215_WRITE) raw->count -= ((req->end - req->start) & (RAW3215_BUFFER_SIZE-1))+1; raw->flags &= ~RAW3215_WORKING; raw3215_free_req(req); } raw->message = KERN_WARNING "Spurious interrupt in in raw3215_irq " "(dev %i, dev sts 0x%2x, sch sts 0x%2x)"; raw->msg_dstat = dstat; raw->msg_cstat = cstat; raw3215_sched_bh(raw); } return;}/* * String write routine for 3215 devices */static intraw3215_write(raw3215_info *raw, const char *str, int from_user, unsigned int length){ raw3215_req *req; unsigned long flags; int ret, c; int count; ret = 0; while (length > 0) { s390irq_spin_lock_irqsave(raw->irq, flags); count = (length > RAW3215_BUFFER_SIZE) ? RAW3215_BUFFER_SIZE : length; length -= count; while (RAW3215_BUFFER_SIZE - raw->count < count) { /* there might be a request pending */ raw3215_try_io(raw); if (wait_cons_dev(raw->irq) != 0) { /* that shouldn't happen */ raw->count = 0; } } req = raw3215_mk_write_req(raw); /* copy string to output buffer and convert it to EBCDIC */ if (from_user) { while (1) { c = MIN(count, MIN(RAW3215_BUFFER_SIZE - raw->count, RAW3215_BUFFER_SIZE - raw->head)); if (c <= 0) break; c -= copy_from_user(raw->buffer + raw->head, str, c); if (c == 0) { if (!ret) ret = -EFAULT; break; } ASCEBC(raw->buffer + raw->head, c); raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1); raw->count += c; str += c; count -= c; ret += c; } } else { while (1) { c = MIN(count, MIN(RAW3215_BUFFER_SIZE - raw->count, RAW3215_BUFFER_SIZE - raw->head)); if (c <= 0) break; memcpy(raw->buffer + raw->head, str, c); ASCEBC(raw->buffer + raw->head, c); raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1); raw->count += c; str += c; count -= c; ret += c; } } raw3215_mk_write_ccw(raw, req); raw->queued_write = req; /* start or queue request */ raw3215_try_io(raw); s390irq_spin_unlock_irqrestore(raw->irq, flags); } return ret;}/* * Put character routine for 3215 devices */static void raw3215_putchar(raw3215_info *raw, unsigned char ch){ raw3215_req *req; unsigned long flags; s390irq_spin_lock_irqsave(raw->irq, flags); while (RAW3215_BUFFER_SIZE - raw->count < 1) { /* there might be a request pending */ raw3215_try_io(raw); if (wait_cons_dev(raw->irq) != 0) { /* that shouldn't happen */ raw->count = 0; } } req = raw3215_mk_write_req(raw); raw->buffer[raw->head] = (char) _ascebc[(int) ch]; raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1); raw->count++; raw3215_mk_write_ccw(raw, req); raw->queued_write = req; /* start or queue request */ raw3215_try_io(raw); s390irq_spin_unlock_irqrestore(raw->irq, flags);}/* * Flush routine, it simply sets the flush flag and tries to start * pending IO. */static void raw3215_flush_buffer(raw3215_info *raw){ unsigned long flags; s390irq_spin_lock_irqsave(raw->irq, flags); if (raw->count > 0) { raw->flags |= RAW3215_FLUSHING; raw3215_try_io(raw); raw->flags &= ~RAW3215_FLUSHING; } s390irq_spin_unlock_irqrestore(raw->irq, flags);}/* * Fire up a 3215 device. */static int raw3215_startup(raw3215_info *raw){ unsigned long flags; if (raw->flags & RAW3215_ACTIVE) return 0; if (request_irq(raw->irq, raw3215_irq, SA_INTERRUPT, "3215 terminal driver", &raw->devstat) != 0) return -1; raw->flags |= RAW3215_ACTIVE; s390irq_spin_lock_irqsave(raw->irq, flags); raw3215_try_io(raw); s390irq_spin_unlock_irqrestore(raw->irq, flags); return 0; }/* * Shutdown a 3215 device. */static void raw3215_shutdown(raw3215_info *raw){ DECLARE_WAITQUEUE(wait, current); unsigned long flags; if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED)) return; /* Wait for outstanding requests, then free irq */ s390irq_spin_lock_irqsave(raw->irq, flags); if ((raw->flags & RAW3215_WORKING) || raw->queued_write != NULL || raw->queued_read != NULL) { raw->flags |= RAW3215_CLOSING; add_wait_queue(&raw->empty_wait, &wait); current->state = TASK_INTERRUPTIBLE; s390irq_spin_unlock_irqrestore(raw->irq, flags); schedule(); s390irq_spin_lock_irqsave(raw->irq, flags); remove_wait_queue(&raw->empty_wait, &wait); current->state = TASK_RUNNING; raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING); } free_irq(raw->irq, NULL); s390irq_spin_unlock_irqrestore(raw->irq, flags);}static intraw3215_find_dev(int number){ dev_info_t dinfo; int irq; int count; irq = get_irq_first(); count = 0; while (count <= number && irq != -ENODEV) { if (get_dev_info(irq, &dinfo) == -ENODEV) break; if (dinfo.devno == raw3215_condevice || dinfo.sid_data.cu_type == 0x3215) { count++; if (count > number) return irq; } irq = get_irq_next(irq); } return -1; /* console not found */}#ifdef CONFIG_3215_CONSOLE/* * Try to request the console IRQ. Called from init/main.c */int con3215_activate(void){ raw3215_info *raw; if (!MACHINE_IS_VM && !MACHINE_IS_P390) return 0; raw = raw3215[0]; /* 3215 console is the first one */ if (raw->irq == -1) /* now console device found in con3215_init */ return -1; return raw3215_startup(raw);}/* * Write a string to the 3215 console */static voidcon3215_write(struct console *co, const char *str, unsigned int count){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -