📄 serialio.h
字号:
/* * Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Further, this software is distributed without any warranty that it is * free of the rightful claim of any third person regarding infringement * or the like. Any license provided herein, whether implied or * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. * * You should have received a copy of the GNU General Public * License along with this program; if not, write the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. * * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA 94043, or: * * http://www.sgi.com * */#ifndef _ASM_IA64_SN_SERIALIO_H#define _ASM_IA64_SN_SERIALIO_H/* * Definitions for the modular serial i/o driver. * * The modular serial i/o driver is a driver which has the hardware * dependent and hardware independent parts separated into separate * modules. The upper half is responsible for all hardware independent * operations, specifically the interface to the kernel. An upper half * may implement a streams interface, character interface, or whatever * interface it wishes to the kernel. The same upper half may access any * physical hardware through a set of standardized entry points into the * lower level, which deals directly with the hardware. Whereas a * separate upper layer exists for each kernel interface type (streams, * character, polling etc), a separate lower level exists for each * hardware type supported. Any upper and lower layer pair may be * connected to form a complete driver. This file defines the interface * between the two *//* Definitions needed per port by both layers. Each lower layer * declares a set of per-port private data areas describing each * physical port, and by definition the first member of that private * data is the following structure. Thus a pointer to the lower * layer's private data is interchangeable with a pointer to the * common private data, and the upper layer does not allocate anything * so it does need to know anything about the physical configuration * of the machine. This structure may also contain any hardware * independent info that must be persistent across device closes. */typedef struct sioport { /* calling vectors */ struct serial_calldown *sio_calldown; struct serial_callup *sio_callup; void *sio_upper; /* upper layer's private data area */ vertex_hdl_t sio_vhdl; /* vertex handle of the hardware independent * portion of this port (e.g. tty/1 without * the d,m,f, etc) */ spinlock_t sio_lock;} sioport_t;/* bits for sio_flags */#define SIO_HWGRAPH_INITED 0x1#define SIO_SPINLOCK_HELD 0x2#define SIO_MUTEX_HELD 0x4#define SIO_LOCKS_MASK (SIO_SPINLOCK_HELD | SIO_MUTEX_HELD)#if DEBUG/* bits for sio_lockcalls, one per downcall except du_write which is * not called by an upper layer. */#define L_OPEN 0x0001#define L_CONFIG 0x0002#define L_ENABLE_HFC 0x0004#define L_SET_EXTCLK 0x0008#define L_WRITE 0x0010#define L_BREAK 0x0020#define L_READ 0x0040#define L_NOTIFICATION 0x0080#define L_RX_TIMEOUT 0x0100#define L_SET_DTR 0x0200#define L_SET_RTS 0x0400#define L_QUERY_DCD 0x0800#define L_QUERY_CTS 0x1000#define L_SET_PROTOCOL 0x2000#define L_ENABLE_TX 0x4000#define L_LOCK_ALL (~0)/* debug lock assertion: each lower layer entry point does an * assertion with the following macro, passing in the port passed to * the entry point and the bit corresponding to which entry point it * is. If the upper layer has turned on the bit for that entry point, * sio_port_islocked is called, thus an upper layer may specify that * it is ok for a particular downcall to be made without the port lock * held. */#define L_LOCKED(port, flag) (((port)->sio_lockcalls & (flag)) == 0 || \ sio_port_islocked(port))#endif/* flags for next_char_state */#define NCS_BREAK 1#define NCS_PARITY 2#define NCS_FRAMING 4#define NCS_OVERRUN 8/* protocol types for DOWN_SET_PROTOCOL */enum sio_proto { PROTO_RS232, PROTO_RS422};/* calldown vector. This is a set of entry points into a lower layer * module, providing black-box access to the hardware by the upper * layer */struct serial_calldown { /* hardware configuration */ int (*down_open) (sioport_t *port); int (*down_config) (sioport_t *port, int baud, int byte_size, int stop_bits, int parenb, int parodd); int (*down_enable_hfc) (sioport_t *port, int enable); int (*down_set_extclk) (sioport_t *port, int clock_factor); /* data transmission */ int (*down_write) (sioport_t *port, char *buf, int len); int (*down_du_write) (sioport_t *port, char *buf, int len); void (*down_du_flush) (sioport_t *port); int (*down_break) (sioport_t *port, int brk); int (*down_enable_tx) (sioport_t *port, int enb); /* data reception */ int (*down_read) (sioport_t *port, char *buf, int len); /* event notification */ int (*down_notification) (sioport_t *port, int mask, int on); int (*down_rx_timeout) (sioport_t *port, int timeout); /* modem control */ int (*down_set_DTR) (sioport_t *port, int dtr); int (*down_set_RTS) (sioport_t *port, int rts); int (*down_query_DCD) (sioport_t *port); int (*down_query_CTS) (sioport_t *port); /* transmission protocol */ int (*down_set_protocol) (sioport_t *port, enum sio_proto protocol); /* memory mapped user driver support */ int (*down_mapid) (sioport_t *port, void *arg); int (*down_map) (sioport_t *port, uint64_t *vt, off_t off); void (*down_unmap) (sioport_t *port); int (*down_set_sscr) (sioport_t *port, int arg, int flag);};/* * Macros used by the upper layer to access the lower layer. Unless * otherwise noted, all integer functions should return 0 on success * or 1 if the hardware does not support the requested operation. In * the case of non-support, the upper layer may work around the problem * where appropriate or just notify the user. * For hardware which supports detaching, these functions should * return -1 if the hardware is no longer present. *//* open a device. Do whatever initialization/resetting necessary */#define DOWN_OPEN(p) \ ((p)->sio_calldown->down_open(p))/* configure the hardware with the given baud rate, number of stop * bits, byte size and parity */#define DOWN_CONFIG(p, a, b, c, d, e) \ ((p)->sio_calldown->down_config(p, a, b, c, d, e))/* Enable hardware flow control. If the hardware does not support * this, the upper layer will emulate HFC by manipulating RTS and CTS */#define DOWN_ENABLE_HFC(p, enb) \ ((p)->sio_calldown->down_enable_hfc(p, enb))/* Set external clock to the given clock factor. If cf is zero, * internal clock is used. If cf is non-zero external clock is used * and the clock is cf times the baud. */#define DOWN_SET_EXTCLK(p, cf) \ ((p)->sio_calldown->down_set_extclk(p, cf))/* Write bytes to the device. The number of bytes actually written is * returned. The upper layer will continue to call this function until * it has no more data to send or until 0 is returned, indicating that * no more bytes may be sent until some have drained. */#define DOWN_WRITE(p, buf, len) \ ((p)->sio_calldown->down_write(p, buf, len))/* Same as DOWN_WRITE, but called only from synchronous du output * routines. Allows lower layer the option of implementing kernel * printfs differently than ordinary console output. */#define DOWN_DU_WRITE(p, buf, len) \ ((p)->sio_calldown->down_du_write(p, buf, len))/* Flushes previous down_du_write() calls. Needed on serial controllers * that can heavily buffer output like IOC3 for conbuf_flush(). */#define DOWN_DU_FLUSH(p) \ ((p)->sio_calldown->down_du_flush(p))/* Set the output break condition high or low */#define DOWN_BREAK(p, brk) \ ((p)->sio_calldown->down_break(p, brk))/* Enable/disable TX for soft flow control */#define DOWN_ENABLE_TX(p) \ ((p)->sio_calldown->down_enable_tx(p, 1))#define DOWN_DISABLE_TX(p) \ ((p)->sio_calldown->down_enable_tx(p, 0))/* Read bytes from the device. The number of bytes actually read is * returned. All bytes returned by a single call have the same error * status. Thus if the device has 10 bytes queued for input and byte 5 * has a parity error, the first call to DOWN_READ will return bytes 0-4 * only. A subsequent call to DOWN_READ will first cause a call to * UP_PARITY_ERROR to notify the upper layer that the next byte has an
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -