#define NR_3215 1 #define NR_3215_REQ (4*NR_3215) #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */ #define RAW3215_INBUF_SIZE 256 /* input buffer size */ #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */ #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */ #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */ #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */ #define RAW3215_NR_CCWS 3 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
#define RAW3215_FIXED 1 /* 3215 console device is not be freed */ #define RAW3215_WORKING 4 /* set if a request is being worked on */ #define RAW3215_THROTTLED 8 /* set if reading is disabled */ #define RAW3215_STOPPED 16 /* set if writing is disabled */ #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */ #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
#define TAB_STOP_SIZE 8 /* tab stop size */
/* * Request types for a 3215 device
*/ enum raw3215_type {
RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
};
/* * Request structure for a 3215 device
*/ struct raw3215_req { enum raw3215_type type; /* type of the request */ int start, len; /* start index & len in output buffer */ int delayable; /* indication to wait for more data */ int residual; /* residual count for read request */ struct ccw1 ccws[RAW3215_NR_CCWS]; /* space for the channel program */ struct raw3215_info *info; /* pointer to main structure */ struct raw3215_req *next; /* pointer to next request */
} __attribute__ ((aligned(8)));
struct raw3215_info { struct tty_port port; struct ccw_device *cdev; /* device for tty driver */
spinlock_t *lock; /* pointer to irq lock */ int flags; /* state flags */
u8 *buffer; /* pointer to output buffer */
u8 *inbuf; /* pointer to input buffer */ int head; /* first free byte in output buffer */ int count; /* number of bytes in output buffer */ int written; /* number of bytes in write requests */ struct raw3215_req *queued_read; /* pointer to queued read requests */ struct raw3215_req *queued_write;/* pointer to queued write requests */
wait_queue_head_t empty_wait; /* wait queue for flushing */ struct timer_list timer; /* timer for delayed output */ int line_pos; /* position on the line (for tabs) */
};
/* array of 3215 devices structures */ staticstruct raw3215_info *raw3215[NR_3215]; /* spinlock to protect the raw3215 array */ static DEFINE_SPINLOCK(raw3215_device_lock); /* list of free request structures */ staticstruct raw3215_req *raw3215_freelist; /* spinlock to protect free list */ static DEFINE_SPINLOCK(raw3215_freelist_lock);
/* * Get a request structure from the free list
*/ staticinlinestruct raw3215_req *raw3215_alloc_req(void)
{ struct raw3215_req *req; unsignedlong flags;
/* * Set up a read request that reads up to 160 byte from the 3215 device. * If there is a queued read request it is used, but that shouldn't happen * because a 3215 terminal won't accept a new read before the old one is * completed.
*/ staticvoid raw3215_mk_read_req(struct raw3215_info *raw)
{ struct raw3215_req *req; struct ccw1 *ccw;
/* there can only be ONE read request at a time */
req = raw->queued_read; if (req == NULL) { /* no queued read request, use new req structure */
req = raw3215_alloc_req();
req->type = RAW3215_READ;
req->info = raw;
raw->queued_read = req;
}
/* * Set up a write request with the information from the main structure. * A ccw chain is created that writes as much as possible from the output * buffer to the 3215 device. If a queued write exists it is replaced by * the new, probably lengthened request.
*/ staticvoid raw3215_mk_write_req(struct raw3215_info *raw)
{ struct raw3215_req *req; struct ccw1 *ccw; int len, count, ix, lines;
if (raw->count <= raw->written) return; /* check if there is a queued write request */
req = raw->queued_write; if (req == NULL) { /* no queued write request, use new req structure */
req = raw3215_alloc_req();
req->type = RAW3215_WRITE;
req->info = raw;
raw->queued_write = req;
} else {
raw->written -= req->len;
}
ccw = req->ccws;
req->start = (raw->head - raw->count + raw->written) &
(RAW3215_BUFFER_SIZE - 1); /* * now we have to count newlines. We can at max accept * RAW3215_MAX_NEWLINE newlines in a single ssch due to * a restriction in VM
*/
lines = 0;
ix = req->start; while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) { if (raw->buffer[ix] == 0x15)
lines++;
ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
}
len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1; if (len > RAW3215_MAX_BYTES)
len = RAW3215_MAX_BYTES;
req->len = len;
raw->written += len;
/* set the indication if we should try to enlarge this request */
req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
ix = req->start; while (len > 0) { if (ccw > req->ccws)
ccw[-1].flags |= 0x40; /* use command chaining */
ccw->cmd_code = 0x01; /* write, auto carrier return */
ccw->flags = 0x20; /* ignore incorrect length ind. */
ccw->cda = virt_to_dma32(raw->buffer + ix);
count = len; if (ix + count > RAW3215_BUFFER_SIZE)
count = RAW3215_BUFFER_SIZE - ix;
ccw->count = count;
len -= count;
ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
ccw++;
} /* * Add a NOP to the channel program. 3215 devices are purely * emulated and its much better to avoid the channel end * interrupt in this case.
*/ if (ccw > req->ccws)
ccw[-1].flags |= 0x40; /* use command chaining */
ccw->cmd_code = 0x03; /* NOP */
ccw->flags = 0;
ccw->cda = 0;
ccw->count = 1;
}
/* * Start a read or a write request
*/ staticvoid raw3215_start_io(struct raw3215_info *raw)
{ struct raw3215_req *req; int res;
req = raw->queued_read; if (req != NULL &&
!(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) { /* dequeue request */
raw->queued_read = NULL;
res = ccw_device_start(raw->cdev, req->ccws,
(unsignedlong) req, 0, 0); if (res != 0) { /* do_IO failed, put request back to queue */
raw->queued_read = req;
} else {
raw->flags |= RAW3215_WORKING;
}
}
req = raw->queued_write; if (req != NULL &&
!(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) { /* dequeue request */
raw->queued_write = NULL;
res = ccw_device_start(raw->cdev, req->ccws,
(unsignedlong) req, 0, 0); if (res != 0) { /* do_IO failed, put request back to queue */
raw->queued_write = req;
} else {
raw->flags |= RAW3215_WORKING;
}
}
}
/* * Function to start a delayed output after RAW3215_TIMEOUT seconds
*/ staticvoid raw3215_timeout(struct timer_list *t)
{ struct raw3215_info *raw = timer_container_of(raw, t, timer); unsignedlong flags;
/* * Function to conditionally start an IO. A read is started immediately, * a write is only started immediately if the flush flag is on or the * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
*/ staticinlinevoid raw3215_try_io(struct raw3215_info *raw)
{ if (!tty_port_initialized(&raw->port)) return; if (raw->queued_read != NULL)
raw3215_start_io(raw); elseif (raw->queued_write != NULL) { if ((raw->queued_write->delayable == 0) ||
(raw->flags & RAW3215_FLUSHING)) { /* execute write requests bigger than minimum size */
raw3215_start_io(raw);
}
} if ((raw->queued_read || raw->queued_write) &&
!(raw->flags & RAW3215_WORKING) &&
!(raw->flags & RAW3215_TIMER_RUNS)) {
raw->timer.expires = RAW3215_TIMEOUT + jiffies;
add_timer(&raw->timer);
raw->flags |= RAW3215_TIMER_RUNS;
}
}
/* * Try to start the next IO and wake up processes waiting on the tty.
*/ staticvoid raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty)
{
raw3215_mk_write_req(raw);
raw3215_try_io(raw); if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE)
tty_wakeup(tty);
}
/* * Interrupt routine, called from common io layer
*/ staticvoid raw3215_irq(struct ccw_device *cdev, unsignedlong intparm, struct irb *irb)
{ struct raw3215_info *raw; struct raw3215_req *req; struct tty_struct *tty; int cstat, dstat; int count;
raw = dev_get_drvdata(&cdev->dev);
req = (struct raw3215_req *) intparm;
tty = tty_port_tty_get(&raw->port);
cstat = irb->scsw.cmd.cstat;
dstat = irb->scsw.cmd.dstat; if (cstat != 0)
raw3215_next_io(raw, tty); 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 */
raw3215_mk_read_req(raw);
raw3215_next_io(raw, tty); break; case 0x08: case 0x0C: /* Channel end interrupt. */ if ((raw = req->info) == NULL) goto put_tty; /* That shouldn't happen ... */ if (req->type == RAW3215_READ) { /* store residual count, then wait for device end */
req->residual = irb->scsw.cmd.count;
} if (dstat == 0x08) break;
fallthrough; case 0x04: /* Device end interrupt. */ if ((raw = req->info) == NULL) goto put_tty; /* That shouldn't happen ... */ if (req->type == RAW3215_READ && tty != NULL) { unsignedint cchar;
case CTRLCHAR_CTRL:
tty_insert_flip_char(&raw->port, cchar,
TTY_NORMAL);
tty_flip_buffer_push(&raw->port); break;
case CTRLCHAR_NONE: if (count < 2 ||
(strncmp(raw->inbuf+count-2, "\252n", 2) &&
strncmp(raw->inbuf+count-2, "^n", 2)) ) { /* add the auto \n */
raw->inbuf[count] = '\n';
count++;
} else
count -= 2;
tty_insert_flip_string(&raw->port, raw->inbuf,
count);
tty_flip_buffer_push(&raw->port); break;
}
} elseif (req->type == RAW3215_WRITE) {
raw->count -= req->len;
raw->written -= req->len;
}
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_next_io(raw, tty); break; default: /* Strange interrupt, I'll do my best to clean up */ if (req != NULL && req->type != RAW3215_FREE) { if (req->type == RAW3215_WRITE) {
raw->count -= req->len;
raw->written -= req->len;
}
raw->flags &= ~RAW3215_WORKING;
raw3215_free_req(req);
}
raw3215_next_io(raw, tty);
}
put_tty:
tty_kref_put(tty);
}
/* * Need to drop data to avoid blocking. Drop as much data as possible. * This is unqueued part in the buffer and the queued part in the request. * Also adjust the head position to append new data and set count * accordingly. * * Return number of bytes available in buffer.
*/ staticunsignedint raw3215_drop(struct raw3215_info *raw)
{ struct raw3215_req *req;
req = raw->queued_write; if (req) { /* Drop queued data and delete request */
raw->written -= req->len;
raw3215_free_req(req);
raw->queued_write = NULL;
}
raw->head = (raw->head - raw->count + raw->written) &
(RAW3215_BUFFER_SIZE - 1);
raw->count = raw->written;
return RAW3215_BUFFER_SIZE - raw->count;
}
/* * Wait until length bytes are available int the output buffer. * If drop mode is active and wait condition holds true, start dropping * data. * Has to be called with the s390irq lock held. Can be called * disabled.
*/ staticunsignedint raw3215_make_room(struct raw3215_info *raw, unsignedint length, bool drop)
{ while (RAW3215_BUFFER_SIZE - raw->count < length) { if (drop) return raw3215_drop(raw);
/* there might be a request pending */
raw->flags |= RAW3215_FLUSHING;
raw3215_mk_write_req(raw);
raw3215_try_io(raw);
raw->flags &= ~RAW3215_FLUSHING; #ifdef CONFIG_TN3215_CONSOLE
ccw_device_wait_idle(raw->cdev); #endif /* Enough room freed up ? */ if (RAW3215_BUFFER_SIZE - raw->count >= length) break; /* there might be another cpu waiting for the lock */
spin_unlock(get_ccwdev_lock(raw->cdev));
udelay(100);
spin_lock(get_ccwdev_lock(raw->cdev));
} return length;
}
#define RAW3215_COUNT 1 #define RAW3215_STORE 2
/* * Add text to console buffer. Find tabs in input and calculate size * including tab replacement. * This function operates in 2 different modes, depending on parameter * opmode: * RAW3215_COUNT: Get the size needed for the input string with * proper tab replacement calculation. * Return value is the number of bytes required to store the * input. However no data is actually stored. * The parameter todrop is not used. * RAW3215_STORE: Add data to the console buffer. The parameter todrop is * valid and contains the number of bytes to be dropped from head of * string without blocking. * Return value is the number of bytes copied.
*/ staticunsignedint raw3215_addtext(const u8 *str, size_t length, struct raw3215_info *raw, int opmode, unsignedint todrop)
{ unsignedint i, blanks, expanded_size = 0; unsignedint column = raw->line_pos;
size_t c;
u8 ch;
if (opmode == RAW3215_COUNT)
todrop = 0;
for (c = 0; c < length; ++c) {
blanks = 1;
ch = str[c];
/* * Put character routine for 3215 devices
*/ staticvoid raw3215_putchar(struct raw3215_info *raw, u8 ch)
{
raw3215_write(raw, &ch, 1);
}
/* * Flush routine, it simply sets the flush flag and tries to start * pending IO.
*/ staticvoid raw3215_flush_buffer(struct raw3215_info *raw)
{ unsignedlong flags;
/* * The below function is called as a panic/reboot notifier before the * system enters a disabled, endless loop. * * Notice we must use the spin_trylock() alternative, to prevent lockups * in atomic context (panic routine runs with secondary CPUs, local IRQs * and preemption disabled).
*/ staticint con3215_notify(struct notifier_block *self, unsignedlong event, void *data)
{ struct raw3215_info *raw; unsignedlong flags;
raw = raw3215[0]; /* console 3215 is the first one */ if (!spin_trylock_irqsave(get_ccwdev_lock(raw->cdev), flags)) return NOTIFY_DONE;
raw3215_make_room(raw, RAW3215_BUFFER_SIZE, false);
spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
return NOTIFY_DONE;
}
staticstruct notifier_block on_panic_nb = {
.notifier_call = con3215_notify,
.priority = INT_MIN + 1, /* run the callback late */
};
staticstruct notifier_block on_reboot_nb = {
.notifier_call = con3215_notify,
.priority = INT_MIN + 1, /* run the callback late */
};
/* * The console structure for the 3215 console
*/ staticstruct console con3215 = {
.name = "ttyS",
.write = con3215_write,
.device = con3215_device,
.flags = CON_PRINTBUFFER,
};
/* * 3215 console initialization code called from console_init().
*/ staticint __init con3215_init(void)
{ struct ccw_device *cdev; struct raw3215_info *raw; struct raw3215_req *req; int i;
/* Check if 3215 is to be the console */ if (!CONSOLE_IS_3215) return -ENODEV;
/* Set the console mode for VM */ if (machine_is_vm()) {
cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
}
/* allocate 3215 request structures */
raw3215_freelist = NULL; for (i = 0; i < NR_3215_REQ; i++) {
req = kzalloc(sizeof(struct raw3215_req), GFP_KERNEL | GFP_DMA); if (!req) return -ENOMEM;
req->next = raw3215_freelist;
raw3215_freelist = req;
}
cdev = ccw_device_create_console(&raw3215_ccw_driver); if (IS_ERR(cdev)) return -ENODEV;
/* * tty3215_open * * This routine is called whenever a 3215 tty is opened.
*/ staticint tty3215_open(struct tty_struct *tty, struct file * filp)
{ struct raw3215_info *raw = tty->driver_data;
tty_port_tty_set(&raw->port, tty);
/* * Start up 3215 device
*/ return raw3215_startup(raw);
}
/* * tty3215_close() * * This routine is called when the 3215 tty is closed. We wait * for the remaining request to be completed. Then we clean up.
*/ staticvoid tty3215_close(struct tty_struct *tty, struct file * filp)
{ struct raw3215_info *raw = tty->driver_data;
/* * Returns the amount of free space in the output buffer.
*/ staticunsignedint tty3215_write_room(struct tty_struct *tty)
{ struct raw3215_info *raw = tty->driver_data;
/* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */ if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0) return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE; else return 0;
}
/* * Returns the number of characters in the output buffer
*/ staticunsignedint tty3215_chars_in_buffer(struct tty_struct *tty)
{ struct raw3215_info *raw = tty->driver_data;
/* * 3215 tty registration code called from tty_init(). * Most kernel services (incl. kmalloc) are available at this poimt.
*/ staticint __init tty3215_init(void)
{ struct tty_driver *driver; int ret;
if (!CONSOLE_IS_3215) return 0;
driver = tty_alloc_driver(NR_3215, TTY_DRIVER_REAL_RAW); if (IS_ERR(driver)) return PTR_ERR(driver);
ret = ccw_driver_register(&raw3215_ccw_driver); if (ret) {
tty_driver_kref_put(driver); return ret;
} /* * Initialize the tty_driver structure * Entries in tty3215_driver that are NOT initialized: * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.