ia64/xen-unstable

view xen/include/xen/serial.h @ 6552:a9873d384da4

Merge.
author adsharma@los-vmm.sc.intel.com
date Thu Aug 25 12:24:48 2005 -0700 (2005-08-25)
parents 112d44270733 fa0754a9f64f
children dfaf788ab18c
line source
1 /******************************************************************************
2 * serial.h
3 *
4 * Framework for serial device drivers.
5 *
6 * Copyright (c) 2003-2005, K A Fraser
7 */
9 #ifndef __XEN_SERIAL_H__
10 #define __XEN_SERIAL_H__
12 struct cpu_user_regs;
14 /* Register a character-receive hook on the specified COM port. */
15 typedef void (*serial_rx_fn)(char, struct cpu_user_regs *);
16 void serial_set_rx_handler(int handle, serial_rx_fn fn);
18 /* Number of characters we buffer for a polling receiver. */
19 #define SERIAL_RXBUFSZ 32
20 #define MASK_SERIAL_RXBUF_IDX(_i) ((_i)&(SERIAL_RXBUFSZ-1))
22 /* Number of characters we buffer for an interrupt-driven transmitter. */
23 #define SERIAL_TXBUFSZ 16384
24 #define MASK_SERIAL_TXBUF_IDX(_i) ((_i)&(SERIAL_TXBUFSZ-1))
26 struct uart_driver;
28 struct serial_port {
29 /* Uart-driver parameters. */
30 struct uart_driver *driver;
31 void *uart;
32 /* Number of characters the port can hold for transmit. */
33 int tx_fifo_size;
34 /* Transmit data buffer (interrupt-driven uart). */
35 char *txbuf;
36 unsigned int txbufp, txbufc;
37 /* Force synchronous transmit. */
38 int sync;
39 /* Receiver callback functions (asynchronous receivers). */
40 serial_rx_fn rx_lo, rx_hi, rx;
41 /* Receive data buffer (polling receivers). */
42 char rxbuf[SERIAL_RXBUFSZ];
43 unsigned int rxbufp, rxbufc;
44 /* Serial I/O is concurrency-safe. */
45 spinlock_t lock;
46 };
48 struct uart_driver {
49 /* Driver initialisation (pre- and post-IRQ subsystem setup). */
50 void (*init_preirq)(struct serial_port *);
51 void (*init_postirq)(struct serial_port *);
52 /* Hook to clean up after Xen bootstrap (before domain 0 runs). */
53 void (*endboot)(struct serial_port *);
54 /* Transmit FIFO ready to receive up to @tx_fifo_size characters? */
55 int (*tx_empty)(struct serial_port *);
56 /* Put a character onto the serial line. */
57 void (*putc)(struct serial_port *, char);
58 /* Get a character from the serial line: returns 0 if none available. */
59 int (*getc)(struct serial_port *, char *);
60 };
62 /* 'Serial handles' are composed from the following fields. */
63 #define SERHND_IDX (1<<0) /* COM1 or COM2? */
64 #define SERHND_HI (1<<1) /* Mux/demux each transferred char by MSB. */
65 #define SERHND_LO (1<<2) /* Ditto, except that the MSB is cleared. */
66 #define SERHND_COOKED (1<<3) /* Newline/carriage-return translation? */
68 /* Two-stage initialisation (before/after IRQ-subsystem initialisation). */
69 void serial_init_preirq(void);
70 void serial_init_postirq(void);
72 /* Clean-up hook before domain 0 runs. */
73 void serial_endboot(void);
75 /* Takes a config string and creates a numeric handle on the COM port. */
76 int serial_parse_handle(char *conf);
78 /* Transmit a single character via the specified COM port. */
79 void serial_putc(int handle, char c);
81 /* Transmit a NULL-terminated string via the specified COM port. */
82 void serial_puts(int handle, const char *s);
84 /*
85 * An alternative to registering a character-receive hook. This function
86 * will not return until a character is available. It can safely be
87 * called with interrupts disabled.
88 */
89 char serial_getc(int handle);
91 /* Forcibly prevent serial lockup when the system is in a bad way. */
92 /* (NB. This also forces an implicit serial_start_sync()). */
93 void serial_force_unlock(int handle);
95 /* Start/end a synchronous region (temporarily disable interrupt-driven tx). */
96 void serial_start_sync(int handle);
97 void serial_end_sync(int handle);
99 /* Return number of bytes headroom in transmit buffer. */
100 int serial_tx_space(int handle);
102 /*
103 * Initialisation and helper functions for uart drivers.
104 */
105 /* Register a uart on serial port @idx (e.g., @idx==0 is COM1). */
106 void serial_register_uart(int idx, struct uart_driver *driver, void *uart);
107 /* Place the serial port into asynchronous transmit mode. */
108 void serial_async_transmit(struct serial_port *port);
109 /* Process work in interrupt context. */
110 void serial_rx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
111 void serial_tx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
113 /*
114 * Initialisers for individual uart drivers.
115 */
116 /* NB. Any default value can be 0 if it is unknown and must be specified. */
117 struct ns16550_defaults {
118 int baud; /* default baud rate; BAUD_AUTO == pre-configured */
119 int data_bits; /* default data bits (5, 6, 7 or 8) */
120 int parity; /* default parity (n, o, e, m or s) */
121 int stop_bits; /* default stop bits (1 or 2) */
122 int irq; /* default irq */
123 unsigned long io_base; /* default io_base address */
124 };
125 void ns16550_init(int index, struct ns16550_defaults *defaults);
127 /* Baud rate was pre-configured before invoking the UART driver. */
128 #define BAUD_AUTO (-1)
130 #endif /* __XEN_SERIAL_H__ */
132 /*
133 * Local variables:
134 * mode: C
135 * c-set-style: "BSD"
136 * c-basic-offset: 4
137 * tab-width: 4
138 * indent-tabs-mode: nil
139 * End:
140 */