/* Structures and data needed to register tty driver */ staticstruct tty_driver *sclp_vt220_driver;
staticstruct tty_port sclp_vt220_port;
/* Lock to protect internal data from concurrent access */ static DEFINE_SPINLOCK(sclp_vt220_lock);
/* List of empty pages to be used as write request buffers */ static LIST_HEAD(sclp_vt220_empty);
/* List of pending requests */ static LIST_HEAD(sclp_vt220_outqueue);
/* Flag that output queue is currently running */ staticint sclp_vt220_queue_running;
/* Timer used for delaying write requests to merge subsequent messages into
* a single buffer */ staticstruct timer_list sclp_vt220_timer;
/* Pointer to current request buffer which has been partially filled but not
* yet sent */ staticstruct sclp_vt220_request *sclp_vt220_current_request;
/* Number of characters in current request buffer */ staticint sclp_vt220_buffered_chars;
/* Flag indicating that sclp_vt220_current_request should really * have been already queued but wasn't because the SCLP was processing
* another buffer */ staticint sclp_vt220_flush_later;
/* * Put provided request buffer back into queue and check emit pending * buffers if necessary.
*/ staticvoid
sclp_vt220_process_queue(struct sclp_vt220_request *request)
{ unsignedlong flags; void *page;
do { /* Put buffer back to list of empty buffers */
page = request->sclp_req.sccb;
spin_lock_irqsave(&sclp_vt220_lock, flags); /* Move request from outqueue to empty queue */
list_del(&request->list);
list_add_tail((struct list_head *) page, &sclp_vt220_empty); /* Check if there is a pending buffer on the out queue. */
request = NULL; if (!list_empty(&sclp_vt220_outqueue))
request = list_entry(sclp_vt220_outqueue.next, struct sclp_vt220_request, list); if (!request) {
sclp_vt220_queue_running = 0;
spin_unlock_irqrestore(&sclp_vt220_lock, flags); break;
}
spin_unlock_irqrestore(&sclp_vt220_lock, flags);
} while (__sclp_vt220_emit(request)); if (request == NULL && sclp_vt220_flush_later)
sclp_vt220_emit_current();
tty_port_tty_wakeup(&sclp_vt220_port);
}
#define SCLP_BUFFER_MAX_RETRY 1
/* * Callback through which the result of a write request is reported by the * SCLP.
*/ staticvoid
sclp_vt220_callback(struct sclp_req *request, void *data)
{ struct sclp_vt220_request *vt220_request; struct sclp_vt220_sccb *sccb;
/* * Add msg to buffer associated with request. Return the number of characters * added.
*/ staticint
sclp_vt220_add_msg(struct sclp_vt220_request *request, constunsignedchar *msg, int count, int convertlf)
{ struct sclp_vt220_sccb *sccb; void *buffer; unsignedchar c; int from; int to;
if (count > sclp_vt220_space_left(request))
count = sclp_vt220_space_left(request); if (count <= 0) return 0;
/* * Emit buffer after having waited long enough for more data to arrive.
*/ staticvoid
sclp_vt220_timeout(struct timer_list *unused)
{
sclp_vt220_emit_current();
}
#define BUFFER_MAX_DELAY HZ/20
/* * Drop oldest console buffer if sclp_con_drop is set
*/ staticint
sclp_vt220_drop_buffer(void)
{ struct list_head *list; struct sclp_vt220_request *request; void *page;
if (!sclp_console_drop) return 0;
list = sclp_vt220_outqueue.next; if (sclp_vt220_queue_running) /* The first element is in I/O */
list = list->next; if (list == &sclp_vt220_outqueue) return 0;
list_del(list);
request = list_entry(list, struct sclp_vt220_request, list);
page = request->sclp_req.sccb;
list_add_tail((struct list_head *) page, &sclp_vt220_empty); return 1;
}
/* * Internal implementation of the write function. Write COUNT bytes of data * from memory at BUF * to the SCLP interface. In case that the data does not fit into the current * write buffer, emit the current one and allocate a new one. If there are no * more empty buffers available, wait until one gets emptied. If DO_SCHEDULE * is non-zero, the buffer will be scheduled for emitting after a timeout - * otherwise the user has to explicitly call the flush function. * A non-zero CONVERTLF parameter indicates that 0x0a characters in the message * buffer should be converted to 0x0a 0x0d. After completion, return the number * of bytes written.
*/ staticint
__sclp_vt220_write(constunsignedchar *buf, int count, int do_schedule, int convertlf, int may_fail)
{ unsignedlong flags; void *page; int written; int overall_written;
if (count <= 0) return 0;
overall_written = 0;
spin_lock_irqsave(&sclp_vt220_lock, flags); do { /* Create an sclp output buffer if none exists yet */ if (sclp_vt220_current_request == NULL) { if (list_empty(&sclp_vt220_empty))
sclp_console_full++; while (list_empty(&sclp_vt220_empty)) { if (may_fail) goto out; if (sclp_vt220_drop_buffer()) break;
spin_unlock_irqrestore(&sclp_vt220_lock, flags);
sclp_sync_wait();
spin_lock_irqsave(&sclp_vt220_lock, flags);
}
page = (void *) sclp_vt220_empty.next;
list_del((struct list_head *) page);
sclp_vt220_current_request =
sclp_vt220_initialize_page(page);
} /* Try to write the string to the current request buffer */
written = sclp_vt220_add_msg(sclp_vt220_current_request,
buf, count, convertlf);
overall_written += written; if (written == count) break; /* * Not all characters could be written to the current * output buffer. Emit the buffer, create a new buffer * and then output the rest of the string.
*/
spin_unlock_irqrestore(&sclp_vt220_lock, flags);
sclp_vt220_emit_current();
spin_lock_irqsave(&sclp_vt220_lock, flags);
buf += written;
count -= written;
} while (count > 0); /* Setup timer to output current console buffer after some time */ if (sclp_vt220_current_request != NULL &&
!timer_pending(&sclp_vt220_timer) && do_schedule) {
sclp_vt220_timer.expires = jiffies + BUFFER_MAX_DELAY;
add_timer(&sclp_vt220_timer);
}
out:
spin_unlock_irqrestore(&sclp_vt220_lock, flags); return overall_written;
}
/* * This routine is called by the kernel to write a series of * characters to the tty device. The characters may come from * user space or kernel space. This routine will return the * number of characters actually accepted for writing.
*/ static ssize_t
sclp_vt220_write(struct tty_struct *tty, const u8 *buf, size_t count)
{ return __sclp_vt220_write(buf, count, 1, 0, 1);
}
switch (*buffer) { case SCLP_VT220_SESSION_ENDED: case SCLP_VT220_SESSION_STARTED:
sclp_vt220_reset_session(); break; case SCLP_VT220_SESSION_DATA: /* Send input to line discipline */
buffer++;
count--;
sclp_vt220_handle_input(buffer, count);
tty_flip_buffer_push(&sclp_vt220_port); break;
}
}
/* * This routine is called when a particular tty device is opened.
*/ staticint
sclp_vt220_open(struct tty_struct *tty, struct file *filp)
{ if (tty->count == 1) {
tty_port_tty_set(&sclp_vt220_port, tty); if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
tty->winsize.ws_row = 24;
tty->winsize.ws_col = 80;
}
} return 0;
}
/* * This routine is called when a particular tty device is closed.
*/ staticvoid
sclp_vt220_close(struct tty_struct *tty, struct file *filp)
{ if (tty->count == 1)
tty_port_tty_set(&sclp_vt220_port, NULL);
}
/* * This routine is called by the kernel to write a single * character to the tty device. If the kernel uses this routine, * it must call the flush_chars() routine (if defined) when it is * done stuffing characters into the driver.
*/ staticint
sclp_vt220_put_char(struct tty_struct *tty, u8 ch)
{ return __sclp_vt220_write(&ch, 1, 0, 0, 1);
}
/* * This routine is called by the kernel after it has written a * series of characters to the tty device using put_char().
*/ staticvoid
sclp_vt220_flush_chars(struct tty_struct *tty)
{ if (!sclp_vt220_queue_running)
sclp_vt220_emit_current(); else
sclp_vt220_flush_later = 1;
}
/* * This routine returns the numbers of characters the tty driver * will accept for queuing to be written. This number is subject * to change as output buffers get emptied, or if the output flow * control is acted.
*/ staticunsignedint
sclp_vt220_write_room(struct tty_struct *tty)
{ unsignedlong flags; struct list_head *l; unsignedint count;
/* * Pass on all buffers to the hardware. Return only when there are no more * buffers pending.
*/ staticvoid
sclp_vt220_flush_buffer(struct tty_struct *tty)
{
sclp_vt220_emit_current();
}
/* Release memory and unregister from sclp core. Controlled by init counting -
* only the last invoker will actually perform these actions. */ staticvoid __init __sclp_vt220_cleanup(void)
{
sclp_vt220_init_count--; if (sclp_vt220_init_count != 0) return;
sclp_unregister(&sclp_vt220_register);
__sclp_vt220_free_pages();
tty_port_destroy(&sclp_vt220_port);
}
/* Allocate buffer pages and register with sclp core. Controlled by init
* counting - only the first invoker will actually perform these actions. */ staticint __init __sclp_vt220_init(int num_pages)
{ void *page; int i; int rc;
/* * Register driver with SCLP and Linux and initialize internal tty structures.
*/ staticint __init sclp_vt220_tty_init(void)
{ struct tty_driver *driver; int rc;
/* Note: we're not testing for CONSOLE_IS_SCLP here to preserve
* symmetry between VM and LPAR systems regarding ttyS1. */
driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW); if (IS_ERR(driver)) return PTR_ERR(driver);
rc = __sclp_vt220_init(MAX_KMEM_PAGES); if (rc) goto out_driver;
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.