Coverage Report

Created: 2017-10-25 09:10

/root/src/xen/xen/include/xen/serial.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 * serial.h
3
 * 
4
 * Framework for serial device drivers.
5
 * 
6
 * Copyright (c) 2003-2008, K A Fraser
7
 */
8
9
#ifndef __XEN_SERIAL_H__
10
#define __XEN_SERIAL_H__
11
12
#include <xen/init.h>
13
#include <xen/spinlock.h>
14
15
struct cpu_user_regs;
16
17
/* Register a character-receive hook on the specified COM port. */
18
typedef void (*serial_rx_fn)(char, struct cpu_user_regs *);
19
void serial_set_rx_handler(int handle, serial_rx_fn fn);
20
21
/* Number of characters we buffer for a polling receiver. */
22
0
#define serial_rxbufsz 32
23
24
/* Number of characters we buffer for an interrupt-driven transmitter. */
25
extern unsigned int serial_txbufsz;
26
27
struct uart_driver;
28
29
enum serial_port_state {
30
    serial_unused,
31
    serial_parsed,
32
    serial_initialized
33
};
34
35
struct vuart_info {
36
    paddr_t base_addr;          /* Base address of the UART */
37
    unsigned long size;         /* Size of the memory region */
38
    unsigned long data_off;     /* Data register offset */
39
    unsigned long status_off;   /* Status register offset */
40
    unsigned long status;       /* Ready status value */
41
};
42
43
struct serial_port {
44
    /* Uart-driver parameters. */
45
    struct uart_driver *driver;
46
    void               *uart;
47
    enum serial_port_state state;
48
    /* Transmit data buffer (interrupt-driven uart). */
49
    char               *txbuf;
50
    unsigned int        txbufp, txbufc;
51
    bool_t              tx_quench;
52
    int                 tx_log_everything;
53
    /* Force synchronous transmit. */
54
    int                 sync;
55
    /* Receiver callback functions (asynchronous receivers). */
56
    serial_rx_fn        rx_lo, rx_hi, rx;
57
    /* Receive data buffer (polling receivers). */
58
    char                rxbuf[serial_rxbufsz];
59
    unsigned int        rxbufp, rxbufc;
60
    /* Serial I/O is concurrency-safe. */
61
    spinlock_t          rx_lock, tx_lock;
62
};
63
64
struct uart_driver {
65
    /* Driver initialisation (pre- and post-IRQ subsystem setup). */
66
    void (*init_preirq)(struct serial_port *);
67
    void (*init_postirq)(struct serial_port *);
68
    /* Hook to clean up after Xen bootstrap (before domain 0 runs). */
69
    void (*endboot)(struct serial_port *);
70
    /* Driver suspend/resume. */
71
    void (*suspend)(struct serial_port *);
72
    void (*resume)(struct serial_port *);
73
    /* Return number of characters the port can hold for transmit,
74
     * or -EIO if port is inaccesible */
75
    int (*tx_ready)(struct serial_port *);
76
    /* Put a character onto the serial line. */
77
    void (*putc)(struct serial_port *, char);
78
    /* Flush accumulated characters. */
79
    void (*flush)(struct serial_port *);
80
    /* Get a character from the serial line: returns 0 if none available. */
81
    int  (*getc)(struct serial_port *, char *);
82
    /* Get IRQ number for this port's serial line: returns -1 if none. */
83
    int  (*irq)(struct serial_port *);
84
    /* Unmask TX interrupt */
85
    void  (*start_tx)(struct serial_port *);
86
    /* Mask TX interrupt */
87
    void  (*stop_tx)(struct serial_port *);
88
    /* Get serial information */
89
    const struct vuart_info *(*vuart_info)(struct serial_port *);
90
};
91
92
/* 'Serial handles' are composed from the following fields. */
93
119k
#define SERHND_IDX      (3<<0) /* COM1, COM2, DBGP, DTUART?               */
94
1
# define SERHND_COM1    (0<<0)
95
0
# define SERHND_COM2    (1<<0)
96
0
# define SERHND_DBGP    (2<<0)
97
0
# define SERHND_DTUART  (0<<0) /* Steal SERHND_COM1 value */
98
141k
#define SERHND_HI       (1<<2) /* Mux/demux each transferred char by MSB. */
99
138k
#define SERHND_LO       (1<<3) /* Ditto, except that the MSB is cleared.  */
100
2.84k
#define SERHND_COOKED   (1<<4) /* Newline/carriage-return translation?    */
101
102
/* Two-stage initialisation (before/after IRQ-subsystem initialisation). */
103
void serial_init_preirq(void);
104
void serial_init_postirq(void);
105
106
/* Clean-up hook before domain 0 runs. */
107
void serial_endboot(void);
108
109
/* Takes a config string and creates a numeric handle on the COM port. */
110
int serial_parse_handle(char *conf);
111
112
/* Transmit a single character via the specified COM port. */
113
void serial_putc(int handle, char c);
114
115
/* Transmit a NULL-terminated string via the specified COM port. */
116
void serial_puts(int handle, const char *s);
117
118
/*
119
 * An alternative to registering a character-receive hook. This function
120
 * will not return until a character is available. It can safely be
121
 * called with interrupts disabled.
122
 */
123
char serial_getc(int handle);
124
125
/* Forcibly prevent serial lockup when the system is in a bad way. */
126
/* (NB. This also forces an implicit serial_start_sync()). */
127
void serial_force_unlock(int handle);
128
129
/* Start/end a synchronous region (temporarily disable interrupt-driven tx). */
130
void serial_start_sync(int handle);
131
void serial_end_sync(int handle);
132
133
/* Start/end a region where we will wait rather than drop characters. */
134
void serial_start_log_everything(int handle);
135
void serial_end_log_everything(int handle);
136
137
/* Return irq number for specified serial port (identified by index). */
138
int serial_irq(int idx);
139
140
/* Retrieve basic UART information to emulate it (base address, size...) */
141
const struct vuart_info* serial_vuart_info(int idx);
142
143
/* Serial suspend/resume. */
144
void serial_suspend(void);
145
void serial_resume(void);
146
147
/*
148
 * Initialisation and helper functions for uart drivers.
149
 */
150
/* Register a uart on serial port @idx (e.g., @idx==0 is COM1). */
151
void serial_register_uart(int idx, struct uart_driver *driver, void *uart);
152
/* Place the serial port into asynchronous transmit mode. */
153
void serial_async_transmit(struct serial_port *port);
154
/* Process work in interrupt context. */
155
void serial_rx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
156
void serial_tx_interrupt(struct serial_port *port, struct cpu_user_regs *regs);
157
158
/*
159
 * Initialisers for individual uart drivers.
160
 */
161
/* NB. Any default value can be 0 if it is unknown and must be specified. */
162
struct ns16550_defaults {
163
    int baud;      /* default baud rate; BAUD_AUTO == pre-configured */
164
    int data_bits; /* default data bits (5, 6, 7 or 8) */
165
    int parity;    /* default parity (n, o, e, m or s) */
166
    int stop_bits; /* default stop bits (1 or 2) */
167
    int irq;       /* default irq */
168
    unsigned long io_base; /* default io_base address */
169
};
170
void ns16550_init(int index, struct ns16550_defaults *defaults);
171
void ehci_dbgp_init(void);
172
173
void arm_uart_init(void);
174
175
struct physdev_dbgp_op;
176
int dbgp_op(const struct physdev_dbgp_op *);
177
178
/* Baud rate was pre-configured before invoking the UART driver. */
179
3
#define BAUD_AUTO (-1)
180
181
#endif /* __XEN_SERIAL_H__ */
182
183
/*
184
 * Local variables:
185
 * mode: C
186
 * c-file-style: "BSD"
187
 * c-basic-offset: 4
188
 * tab-width: 4
189
 * indent-tabs-mode: nil
190
 * End:
191
 */