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