Statistics
| Branch: | Revision:

root / hw / virtio-serial.h @ f146ec9a

History | View | Annotate | Download (4.7 kB)

1 98b19252 Amit Shah
/*
2 98b19252 Amit Shah
 * Virtio Serial / Console Support
3 98b19252 Amit Shah
 *
4 98b19252 Amit Shah
 * Copyright IBM, Corp. 2008
5 98b19252 Amit Shah
 * Copyright Red Hat, Inc. 2009
6 98b19252 Amit Shah
 *
7 98b19252 Amit Shah
 * Authors:
8 98b19252 Amit Shah
 *  Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
9 98b19252 Amit Shah
 *  Amit Shah <amit.shah@redhat.com>
10 98b19252 Amit Shah
 *
11 98b19252 Amit Shah
 * This work is licensed under the terms of the GNU GPL, version 2.  See
12 98b19252 Amit Shah
 * the COPYING file in the top-level directory.
13 98b19252 Amit Shah
 *
14 98b19252 Amit Shah
 */
15 98b19252 Amit Shah
#ifndef _QEMU_VIRTIO_SERIAL_H
16 98b19252 Amit Shah
#define _QEMU_VIRTIO_SERIAL_H
17 98b19252 Amit Shah
18 98b19252 Amit Shah
#include <stdbool.h>
19 98b19252 Amit Shah
#include "qdev.h"
20 98b19252 Amit Shah
#include "virtio.h"
21 98b19252 Amit Shah
22 98b19252 Amit Shah
/* == Interface shared between the guest kernel and qemu == */
23 98b19252 Amit Shah
24 98b19252 Amit Shah
/* The Virtio ID for virtio console / serial ports */
25 98b19252 Amit Shah
#define VIRTIO_ID_CONSOLE                3
26 98b19252 Amit Shah
27 98b19252 Amit Shah
/* Features supported */
28 98b19252 Amit Shah
#define VIRTIO_CONSOLE_F_MULTIPORT        1
29 98b19252 Amit Shah
30 98b19252 Amit Shah
struct virtio_console_config {
31 98b19252 Amit Shah
    /*
32 98b19252 Amit Shah
     * These two fields are used by VIRTIO_CONSOLE_F_SIZE which
33 98b19252 Amit Shah
     * isn't implemented here yet
34 98b19252 Amit Shah
     */
35 98b19252 Amit Shah
    uint16_t cols;
36 98b19252 Amit Shah
    uint16_t rows;
37 98b19252 Amit Shah
38 98b19252 Amit Shah
    uint32_t max_nr_ports;
39 98b19252 Amit Shah
    uint32_t nr_ports;
40 98b19252 Amit Shah
} __attribute__((packed));
41 98b19252 Amit Shah
42 98b19252 Amit Shah
struct virtio_console_control {
43 98b19252 Amit Shah
    uint32_t id;                /* Port number */
44 98b19252 Amit Shah
    uint16_t event;                /* The kind of control event (see below) */
45 98b19252 Amit Shah
    uint16_t value;                /* Extra information for the key */
46 98b19252 Amit Shah
};
47 98b19252 Amit Shah
48 98b19252 Amit Shah
/* Some events for the internal messages (control packets) */
49 98b19252 Amit Shah
#define VIRTIO_CONSOLE_PORT_READY        0
50 98b19252 Amit Shah
#define VIRTIO_CONSOLE_CONSOLE_PORT        1
51 98b19252 Amit Shah
#define VIRTIO_CONSOLE_RESIZE                2
52 6663a195 Amit Shah
#define VIRTIO_CONSOLE_PORT_OPEN        3
53 160600fd Amit Shah
#define VIRTIO_CONSOLE_PORT_NAME        4
54 f146ec9a Amit Shah
#define VIRTIO_CONSOLE_PORT_REMOVE        5
55 98b19252 Amit Shah
56 98b19252 Amit Shah
/* == In-qemu interface == */
57 98b19252 Amit Shah
58 98b19252 Amit Shah
typedef struct VirtIOSerial VirtIOSerial;
59 98b19252 Amit Shah
typedef struct VirtIOSerialBus VirtIOSerialBus;
60 98b19252 Amit Shah
typedef struct VirtIOSerialPort VirtIOSerialPort;
61 98b19252 Amit Shah
typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
62 98b19252 Amit Shah
63 98b19252 Amit Shah
typedef struct VirtIOSerialDevice {
64 98b19252 Amit Shah
    DeviceState qdev;
65 98b19252 Amit Shah
    VirtIOSerialPortInfo *info;
66 98b19252 Amit Shah
} VirtIOSerialDevice;
67 98b19252 Amit Shah
68 98b19252 Amit Shah
/*
69 98b19252 Amit Shah
 * This is the state that's shared between all the ports.  Some of the
70 98b19252 Amit Shah
 * state is configurable via command-line options. Some of it can be
71 98b19252 Amit Shah
 * set by individual devices in their initfn routines. Some of the
72 98b19252 Amit Shah
 * state is set by the generic qdev device init routine.
73 98b19252 Amit Shah
 */
74 98b19252 Amit Shah
struct VirtIOSerialPort {
75 98b19252 Amit Shah
    DeviceState dev;
76 98b19252 Amit Shah
    VirtIOSerialPortInfo *info;
77 98b19252 Amit Shah
78 98b19252 Amit Shah
    QTAILQ_ENTRY(VirtIOSerialPort) next;
79 98b19252 Amit Shah
80 98b19252 Amit Shah
    /*
81 98b19252 Amit Shah
     * This field gives us the virtio device as well as the qdev bus
82 98b19252 Amit Shah
     * that we are associated with
83 98b19252 Amit Shah
     */
84 98b19252 Amit Shah
    VirtIOSerial *vser;
85 98b19252 Amit Shah
86 98b19252 Amit Shah
    VirtQueue *ivq, *ovq;
87 98b19252 Amit Shah
88 98b19252 Amit Shah
    /*
89 160600fd Amit Shah
     * This name is sent to the guest and exported via sysfs.
90 160600fd Amit Shah
     * The guest could create symlinks based on this information.
91 160600fd Amit Shah
     * The name is in the reverse fqdn format, like org.qemu.console.0
92 160600fd Amit Shah
     */
93 160600fd Amit Shah
    char *name;
94 160600fd Amit Shah
95 160600fd Amit Shah
    /*
96 98b19252 Amit Shah
     * This id helps identify ports between the guest and the host.
97 98b19252 Amit Shah
     * The guest sends a "header" with this id with each data packet
98 98b19252 Amit Shah
     * that it sends and the host can then find out which associated
99 98b19252 Amit Shah
     * device to send out this data to
100 98b19252 Amit Shah
     */
101 98b19252 Amit Shah
    uint32_t id;
102 98b19252 Amit Shah
103 98b19252 Amit Shah
    /* Identify if this is a port that binds with hvc in the guest */
104 98b19252 Amit Shah
    uint8_t is_console;
105 6663a195 Amit Shah
106 6663a195 Amit Shah
    /* Is the corresponding guest device open? */
107 6663a195 Amit Shah
    bool guest_connected;
108 6663a195 Amit Shah
    /* Is this device open for IO on the host? */
109 6663a195 Amit Shah
    bool host_connected;
110 98b19252 Amit Shah
};
111 98b19252 Amit Shah
112 98b19252 Amit Shah
struct VirtIOSerialPortInfo {
113 98b19252 Amit Shah
    DeviceInfo qdev;
114 98b19252 Amit Shah
    /*
115 98b19252 Amit Shah
     * The per-port (or per-app) init function that's called when a
116 98b19252 Amit Shah
     * new device is found on the bus.
117 98b19252 Amit Shah
     */
118 98b19252 Amit Shah
    int (*init)(VirtIOSerialDevice *dev);
119 98b19252 Amit Shah
    /*
120 98b19252 Amit Shah
     * Per-port exit function that's called when a port gets
121 98b19252 Amit Shah
     * hot-unplugged or removed.
122 98b19252 Amit Shah
     */
123 98b19252 Amit Shah
    int (*exit)(VirtIOSerialDevice *dev);
124 98b19252 Amit Shah
125 98b19252 Amit Shah
    /* Callbacks for guest events */
126 98b19252 Amit Shah
        /* Guest opened device. */
127 98b19252 Amit Shah
    void (*guest_open)(VirtIOSerialPort *port);
128 98b19252 Amit Shah
        /* Guest closed device. */
129 98b19252 Amit Shah
    void (*guest_close)(VirtIOSerialPort *port);
130 98b19252 Amit Shah
131 98b19252 Amit Shah
        /* Guest is now ready to accept data (virtqueues set up). */
132 98b19252 Amit Shah
    void (*guest_ready)(VirtIOSerialPort *port);
133 98b19252 Amit Shah
134 98b19252 Amit Shah
    /*
135 98b19252 Amit Shah
     * Guest wrote some data to the port. This data is handed over to
136 98b19252 Amit Shah
     * the app via this callback. The app should return the number of
137 98b19252 Amit Shah
     * bytes it successfully consumed.
138 98b19252 Amit Shah
     */
139 98b19252 Amit Shah
    size_t (*have_data)(VirtIOSerialPort *port, const uint8_t *buf, size_t len);
140 98b19252 Amit Shah
};
141 98b19252 Amit Shah
142 98b19252 Amit Shah
/* Interface to the virtio-serial bus */
143 98b19252 Amit Shah
144 98b19252 Amit Shah
/*
145 98b19252 Amit Shah
 * Individual ports/apps should call this function to register the port
146 98b19252 Amit Shah
 * with the virtio-serial bus
147 98b19252 Amit Shah
 */
148 98b19252 Amit Shah
void virtio_serial_port_qdev_register(VirtIOSerialPortInfo *info);
149 98b19252 Amit Shah
150 98b19252 Amit Shah
/*
151 98b19252 Amit Shah
 * Open a connection to the port
152 98b19252 Amit Shah
 *   Returns 0 on success (always).
153 98b19252 Amit Shah
 */
154 98b19252 Amit Shah
int virtio_serial_open(VirtIOSerialPort *port);
155 98b19252 Amit Shah
156 98b19252 Amit Shah
/*
157 98b19252 Amit Shah
 * Close the connection to the port
158 98b19252 Amit Shah
 *   Returns 0 on success (always).
159 98b19252 Amit Shah
 */
160 98b19252 Amit Shah
int virtio_serial_close(VirtIOSerialPort *port);
161 98b19252 Amit Shah
162 98b19252 Amit Shah
/*
163 98b19252 Amit Shah
 * Send data to Guest
164 98b19252 Amit Shah
 */
165 98b19252 Amit Shah
ssize_t virtio_serial_write(VirtIOSerialPort *port, const uint8_t *buf,
166 98b19252 Amit Shah
                            size_t size);
167 98b19252 Amit Shah
168 98b19252 Amit Shah
/*
169 98b19252 Amit Shah
 * Query whether a guest is ready to receive data.
170 98b19252 Amit Shah
 */
171 98b19252 Amit Shah
size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
172 98b19252 Amit Shah
173 98b19252 Amit Shah
#endif