ia64/xen-unstable

view xen/include/xen/serial.h @ 17864:d4dcd4d39952

Bring back console_start_log_everything() as a milder alternative to
console_start_sync(). Revert keyhandler logic to use it. The
difference now is that serial logic is updated to not drop characters
if inb a log_everything region. Still this is milder than a sync
region since the async buffer must be filled before we start to
busy-wait on each character.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jun 13 14:15:00 2008 +0100 (2008-06-13)
parents 7eab5d8788a6
children
line source
1 /******************************************************************************
2 * serial.h
3 *
4 * Framework for serial device drivers.
5 *
6 * Copyright (c) 2003-2008, 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
21 /* Number of characters we buffer for an interrupt-driven transmitter. */
22 extern unsigned int serial_txbufsz;
24 struct uart_driver;
26 struct serial_port {
27 /* Uart-driver parameters. */
28 struct uart_driver *driver;
29 void *uart;
30 /* Number of characters the port can hold for transmit. */
31 int tx_fifo_size;
32 /* Transmit data buffer (interrupt-driven uart). */
33 char *txbuf;
34 unsigned int txbufp, txbufc;
35 bool_t tx_quench;
36 int tx_log_everything;
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 rx_lock, tx_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 /* Get IRQ number for this port's serial line: returns -1 if none. */
61 int (*irq)(struct serial_port *);
62 };
64 /* 'Serial handles' are composed from the following fields. */
65 #define SERHND_IDX (1<<0) /* COM1 or COM2? */
66 #define SERHND_HI (1<<1) /* Mux/demux each transferred char by MSB. */
67 #define SERHND_LO (1<<2) /* Ditto, except that the MSB is cleared. */
68 #define SERHND_COOKED (1<<3) /* Newline/carriage-return translation? */
70 /* Two-stage initialisation (before/after IRQ-subsystem initialisation). */
71 void serial_init_preirq(void);
72 void serial_init_postirq(void);
74 /* Clean-up hook before domain 0 runs. */
75 void serial_endboot(void);
77 /* Takes a config string and creates a numeric handle on the COM port. */
78 int serial_parse_handle(char *conf);
80 /* Transmit a single character via the specified COM port. */
81 void serial_putc(int handle, char c);
83 /* Transmit a NULL-terminated string via the specified COM port. */
84 void serial_puts(int handle, const char *s);
86 /*
87 * An alternative to registering a character-receive hook. This function
88 * will not return until a character is available. It can safely be
89 * called with interrupts disabled.
90 */
91 char serial_getc(int handle);
93 /* Forcibly prevent serial lockup when the system is in a bad way. */
94 /* (NB. This also forces an implicit serial_start_sync()). */
95 void serial_force_unlock(int handle);
97 /* Start/end a synchronous region (temporarily disable interrupt-driven tx). */
98 void serial_start_sync(int handle);
99 void serial_end_sync(int handle);
101 /* Start/end a region where we will wait rather than drop characters. */
102 void serial_start_log_everything(int handle);
103 void serial_end_log_everything(int handle);
105 /* Return number of bytes headroom in transmit buffer. */
106 int serial_tx_space(int handle);
108 /* Return irq number for specified serial port (identified by index). */
109 int serial_irq(int idx);
111 /* Serial suspend/resume. */
112 void serial_suspend(void);
113 void serial_resume(void);
115 /*
116 * Initialisation and helper functions for uart drivers.
117 */
118 /* Register a uart on serial port @idx (e.g., @idx==0 is COM1). */
119 void serial_register_uart(int idx, struct uart_driver *driver, void *uart);
120 /* Place the serial port into asynchronous transmit mode. */
121 void serial_async_transmit(struct serial_port *port);
122 /* Process work in interrupt context. */
123 void serial_rx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
124 void serial_tx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
126 /*
127 * Initialisers for individual uart drivers.
128 */
129 /* NB. Any default value can be 0 if it is unknown and must be specified. */
130 struct ns16550_defaults {
131 int baud; /* default baud rate; BAUD_AUTO == pre-configured */
132 int data_bits; /* default data bits (5, 6, 7 or 8) */
133 int parity; /* default parity (n, o, e, m or s) */
134 int stop_bits; /* default stop bits (1 or 2) */
135 int irq; /* default irq */
136 unsigned long io_base; /* default io_base address */
137 };
138 void ns16550_init(int index, struct ns16550_defaults *defaults);
140 /* Baud rate was pre-configured before invoking the UART driver. */
141 #define BAUD_AUTO (-1)
143 #endif /* __XEN_SERIAL_H__ */
145 /*
146 * Local variables:
147 * mode: C
148 * c-set-style: "BSD"
149 * c-basic-offset: 4
150 * tab-width: 4
151 * indent-tabs-mode: nil
152 * End:
153 */