/*
* drivers/s390/char/con3215.c
* 3215 line mode terminal driver.
*
* S390 version
* Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
*
* Updated:
* Aug-2000: Added tab support
* Dan Morrison, IBM Corporation (dmorriso@cse.buffalo.edu)
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kdev_t.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#include <linux/vt_kern.h>
#include <linux/init.h>
#include <linux/console.h>
#include <linux/interrupt.h>
#include <linux/err.h>
#include <linux/reboot.h>
#include <linux/slab.h>
#include <linux/bootmem.h>
#include <asm/ccwdev.h>
#include <asm/cio.h>
#include <asm/io.h>
#include <asm/ebcdic.h>
#include <asm/uaccess.h>
#include <asm/delay.h>
#include <asm/cpcmd.h>
#include <asm/setup.h>
#include "ctrlchar.h"
#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_ACTIVE 2 /* set if the device is in use */
#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_CLOSING 32 /* set while in close process */
#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 ccw_device *cdev; /* device for tty driver */
spinlock_t *lock; /* pointer to irq lock */
int flags; /* state flags */
char *buffer; /* pointer to output buffer */
char *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 tty_struct *tty; /* pointer to tty structure if present */
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) */
char ubuffer[80]; /* copy_from_user buffer */
};
/* array of 3215 devices structures */
static struct raw3215_info *raw3215[NR_3215];
/* spinlock to protect the raw3215 array */
static DEFINE_SPINLOCK(raw3215_device_lock);
/* list of free request structures */
static struct raw3215_req *raw3215_freelist;
/* spinlock to protect free list */
static spinlock_t raw3215_freelist_lock;
static struct tty_driver *tty3215_driver;
/*
* Get a request structure from the free list
*/
static inline struct raw3215_req *
raw3215_alloc_req(void) {
struct raw3215_req *req;
unsigned long flags;
spin_lock_irqsave(&raw3215_freelist_lock, flags);
req = raw3215_freelist;
raw3215_freelist = req->next;
spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
return req;
}
/*
* Put a request structure back to the free list
*/
static inline void
raw3215_free_req(struct raw3215_req *req) {
unsigned long flags;
if (req->type == RAW3215_FREE)
return; /* don't free a free request */
req->type = RAW3215_FREE;
spin_lock_irqsave(&raw3215_freelist_lock, flags);
req->next = raw3215_freelist;
raw3215_freelist = req