📄 cyclades.c
字号:
* Revision 1.34 1994/12/10 12:37:12 steffen * This is the corrected version as suggested by Marcio Saito * * Revision 1.33 1994/12/01 22:41:18 bentson * add hooks to support more high speeds directly; add tytso * patch regarding CLOCAL wakeups * * Revision 1.32 1994/11/23 19:50:04 bentson * allow direct kernel control of higher signalling rates; * look for cards at additional locations * * Revision 1.31 1994/11/16 04:33:28 bentson * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com-- * a problem in chars_in_buffer has been resolved by some * small changes; this should yield smoother output * * Revision 1.30 1994/11/16 04:28:05 bentson * Fix from Corey Minyard, Internet: minyard@metronet.com, * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to * cy_hangup that appears to clear up much (all?) of the * DTR glitches; also he's added/cleaned-up diagnostic messages * * Revision 1.29 1994/11/16 04:16:07 bentson * add change proposed by Ralph Sims, ralphs@halcyon.com, to * operate higher speeds in same way as other serial ports; * add more serial ports (for up to two 16-port muxes). * * Revision 1.28 1994/11/04 00:13:16 root * turn off diagnostic messages * * Revision 1.27 1994/11/03 23:46:37 root * bunch of changes to bring driver into greater conformance * with the serial.c driver (looking for missed fixes) * * Revision 1.26 1994/11/03 22:40:36 root * automatic interrupt probing fixed. * * Revision 1.25 1994/11/03 20:17:02 root * start to implement auto-irq * * Revision 1.24 1994/11/03 18:01:55 root * still working on modem signals--trying not to drop DTR * during the getty/login processes * * Revision 1.23 1994/11/03 17:51:36 root * extend baud rate support; set receive threshold as function * of baud rate; fix some problems with RTS/CTS; * * Revision 1.22 1994/11/02 18:05:35 root * changed arguments to udelay to type long to get * delays to be of correct duration * * Revision 1.21 1994/11/02 17:37:30 root * employ udelay (after calibrating loops_per_second earlier * in init/main.c) instead of using home-grown delay routines * * Revision 1.20 1994/11/02 03:11:38 root * cy_chars_in_buffer forces a return value of 0 to let * login work (don't know why it does); some functions * that were returning EFAULT, now executes the code; * more work on deciding when to disable xmit interrupts; * * Revision 1.19 1994/11/01 20:10:14 root * define routine to start transmission interrupts (by enabling * transmit interrupts); directly enable/disable modem interrupts; * * Revision 1.18 1994/11/01 18:40:45 bentson * Don't always enable transmit interrupts in startup; interrupt on * TxMpty instead of TxRdy to help characters get out before shutdown; * restructure xmit interrupt to check for chars first and quit if * none are ready to go; modem status (MXVRx) is upright, _not_ inverted * (to my view); * * Revision 1.17 1994/10/30 04:39:45 bentson * rename serial_driver and callout_driver to cy_serial_driver and * cy_callout_driver to avoid linkage interference; initialize * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port * from cyclades_port structure; add paranoia check to cy_close; * * Revision 1.16 1994/10/30 01:14:33 bentson * change major numbers; add some _early_ return statements; * * Revision 1.15 1994/10/29 06:43:15 bentson * final tidying up for clean compile; enable some error reporting * * Revision 1.14 1994/10/28 20:30:22 Bentson * lots of changes to drag the driver towards the new tty_io * structures and operation. not expected to work, but may * compile cleanly. * * Revision 1.13 1994/07/21 23:08:57 Bentson * add some diagnostic cruft; support 24 lines (for testing * both -8Y and -16Y cards; be more thorough in servicing all * chips during interrupt; add "volatile" a few places to * circumvent compiler optimizations; fix base & offset * computations in block_til_ready (was causing chip 0 to * stop operation) * * Revision 1.12 1994/07/19 16:42:11 Bentson * add some hackery for kernel version 1.1.8; expand * error messages; refine timing for delay loops and * declare loop params volatile * * Revision 1.11 1994/06/11 21:53:10 bentson * get use of save_car right in transmit interrupt service * * Revision 1.10.1.1 1994/06/11 21:31:18 bentson * add some diagnostic printing; try to fix save_car stuff * * Revision 1.10 1994/06/11 20:36:08 bentson * clean up compiler warnings * * Revision 1.9 1994/06/11 19:42:46 bentson * added a bunch of code to support modem signalling * * Revision 1.8 1994/06/11 17:57:07 bentson * recognize break & parity error * * Revision 1.7 1994/06/05 05:51:34 bentson * Reorder baud table to be monotonic; add cli to CP; discard * incoming characters and status if the line isn't open; start to * fold code into cy_throttle; start to port get_serial_info, * set_serial_info, get_modem_info, set_modem_info, and send_break * from serial.c; expand cy_ioctl; relocate and expand config_setup; * get flow control characters from tty struct; invalidate ports w/o * hardware; * * Revision 1.6 1994/05/31 18:42:21 bentson * add a loop-breaker in the interrupt service routine; * note when port is initialized so that it can be shut * down under the right conditions; receive works without * any obvious errors * * Revision 1.5 1994/05/30 00:55:02 bentson * transmit works without obvious errors * * Revision 1.4 1994/05/27 18:46:27 bentson * incorporated more code from lib_y.c; can now print short * strings under interrupt control to port zero; seems to * select ports/channels/lines correctly * * Revision 1.3 1994/05/25 22:12:44 bentson * shifting from multi-port on a card to proper multiplexor * data structures; added skeletons of most routines * * Revision 1.2 1994/05/19 13:21:43 bentson * start to crib from other sources * *//* If you need to install more boards than NR_CARDS, change the constant in the definition below. No other change is necessary to support up to eight boards. Beyond that you'll have to extend cy_isa_addresses. */#define NR_CARDS 4/* If the total number of ports is larger than NR_PORTS, change this constant in the definition below. No other change is necessary to support more boards/ports. */#define NR_PORTS 128#define ZE_V1_NPORTS 64#define ZO_V1 0#define ZO_V2 1#define ZE_V1 2#define SERIAL_PARANOIA_CHECK#undef CY_DEBUG_OPEN#undef CY_DEBUG_THROTTLE#undef CY_DEBUG_OTHER#undef CY_DEBUG_IO#undef CY_DEBUG_COUNT#undef CY_DEBUG_DTR#undef CY_DEBUG_WAIT_UNTIL_SENT#undef CY_DEBUG_INTERRUPTS#undef CY_16Y_HACK#undef CY_ENABLE_MONITORING#undef CY_PCI_DEBUG#define CY_PROC#if 0#define PAUSE __asm__("nop");#else#define PAUSE ;#endif#define cy_min(a,b) (((a)<(b))?(a):(b))#if 0/******** * For the next two macros, it is assumed that the buffer size is a * power of 2 ********/#define CHARS_IN_BUF(buf_ctrl) \ ((cy_readl(&buf_ctrl->rx_put) - \ cy_readl(&buf_ctrl->rx_get) + \ cy_readl(&buf_ctrl->rx_bufsize)) & \ (cy_readl(&buf_ctrl->rx_bufsize) - 1))#define SPACE_IN_BUF(buf_ctrl) \ ((cy_readl(&buf_ctrl->tx_get) - \ cy_readl(&buf_ctrl->tx_put) + \ cy_readl(&buf_ctrl->tx_bufsize) - 1) & \ (cy_readl(&buf_ctrl->tx_bufsize) - 1))#endif/* * Include section */#include <linux/config.h>#include <linux/module.h>#include <linux/errno.h>#include <linux/signal.h>#include <linux/sched.h>#include <linux/timer.h>#include <linux/interrupt.h>#include <linux/tty.h>#include <linux/serial.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/ptrace.h>#include <linux/cyclades.h>#include <linux/mm.h>#include <linux/init.h>#include <linux/delay.h>#include <asm/system.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/pci.h>#include <linux/version.h>#include <linux/stat.h>#include <linux/proc_fs.h>#define cy_put_user put_userstatic unsigned long cy_get_user(unsigned long *addr){ unsigned long result = 0; int error = get_user (result, addr); if (error) printk ("cyclades: cy_get_user: error == %d\n", error); return result;}#ifndef MIN#define MIN(a,b) ((a) < (b) ? (a) : (b))#endif#define IS_CYC_Z(card) ((card).num_chips == -1)#define Z_FPGA_CHECK(card) \ ((cy_readl(&((struct RUNTIME_9060 *) \ ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 *) \ ((card).ctl_addr))->mail_box_0)) || \ Z_FPGA_CHECK(card)) && \ (ZFIRM_ID==cy_readl(&((struct FIRM_ID *) \ ((card).base_addr+ID_ADDRESS))->signature)))#define WAKEUP_CHARS (SERIAL_XMIT_SIZE-256)#define STD_COM_FLAGS (0)#define JIFFIES_DIFF(n, j) ((j) - (n))static DECLARE_TASK_QUEUE(tq_cyclades);static struct tty_driver cy_serial_driver, cy_callout_driver;static int serial_refcount;static volatile int cy_irq_triggered;static volatile int cy_triggered;static int cy_wild_int_mask;static volatile ucchar *intr_base_addr;/* This is the address lookup table. The driver will probe for Cyclom-Y/ISA boards at all addresses in here. If you want the driver to probe addresses at a different address, add it to this table. If the driver is probing some other board and causing problems, remove the offending address from this table. The cy_setup function extracts additional addresses from the boot options line. The form is "cyclades=address,address..."*/static unsigned char *cy_isa_addresses[] = { (unsigned char *) 0xD0000, (unsigned char *) 0xD2000, (unsigned char *) 0xD4000, (unsigned char *) 0xD6000, (unsigned char *) 0xD8000, (unsigned char *) 0xDA000, (unsigned char *) 0xDC000, (unsigned char *) 0xDE000, 0,0,0,0,0,0,0,0};#define NR_ISA_ADDRS (sizeof(cy_isa_addresses)/sizeof(unsigned char*))/* This is the per-card data structure containing address, irq, number of channels, etc. This driver supports a maximum of NR_CARDS cards.*/static struct cyclades_card cy_card[NR_CARDS];/* This is the per-channel data structure containing pointers, flags and variables for the port. This driver supports a maximum of NR_PORTS.*/static struct cyclades_port cy_port[NR_PORTS];static int cy_next_channel = 0; /* next minor available */static struct tty_struct *serial_table[NR_PORTS];static struct termios *serial_termios[NR_PORTS];static struct termios *serial_termios_locked[NR_PORTS];/* This is the per-irq data structure, it maps an irq to the corresponding card */static struct cyclades_card *IRQ_cards[NR_IRQS];/* * tmp_buf is used as a temporary buffer by serial_write. We need to * lock it in case the copy_from_user blocks while swapping in a page, * and some other program tries to do a serial write at the same time. * Since the lock will only come under contention when the system is * swapping and available memory is low, it makes sense to share one * buffer across all the serial ports, since it significantly saves * memory if large numbers of serial ports are open. This buffer is * allocated when the first cy_open occurs. */static unsigned char *tmp_buf;static struct semaphore tmp_buf_sem = MUTEX;/* * This is used to look up the divisor speeds and the timeouts * We're normally limited to 15 distinct baud rates. The extra * are accessed via settings in info->flags. * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, * HI VHI * 20 */static int baud_table[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 230400, 0};static char baud_co_25[] = { /* 25 MHz clock option table */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -