qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

char: move CharBackend handling in char-fe unit

Move all the frontend struct and methods to a seperate unit. This avoids
accidentally mixing backend and frontend calls, and helps with readabilty.

Make qemu_chr_replay() a macro shared by both char and char-fe.

Export qemu_chr_write(), and use a macro for qemu_chr_write_all()

(nb: yes, CharBackend is for char frontend :)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

+664 -623
+1 -1
backends/rng-egd.c
··· 12 12 13 13 #include "qemu/osdep.h" 14 14 #include "sysemu/rng.h" 15 - #include "chardev/char.h" 15 + #include "chardev/char-fe.h" 16 16 #include "qapi/error.h" 17 17 #include "qapi/qmp/qerror.h" 18 18
+1
chardev/Makefile.objs
··· 1 1 chardev-obj-y += char.o 2 2 chardev-obj-$(CONFIG_WIN32) += char-console.o 3 3 chardev-obj-$(CONFIG_POSIX) += char-fd.o 4 + chardev-obj-y += char-fe.o 4 5 chardev-obj-y += char-file.o 5 6 chardev-obj-y += char-io.o 6 7 chardev-obj-y += char-mux.o
+358
chardev/char-fe.c
··· 1 + /* 2 + * QEMU System Emulator 3 + * 4 + * Copyright (c) 2003-2008 Fabrice Bellard 5 + * 6 + * Permission is hereby granted, free of charge, to any person obtaining a copy 7 + * of this software and associated documentation files (the "Software"), to deal 8 + * in the Software without restriction, including without limitation the rights 9 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 + * copies of the Software, and to permit persons to whom the Software is 11 + * furnished to do so, subject to the following conditions: 12 + * 13 + * The above copyright notice and this permission notice shall be included in 14 + * all copies or substantial portions of the Software. 15 + * 16 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 + * THE SOFTWARE. 23 + */ 24 + #include "qemu/osdep.h" 25 + #include "qemu/error-report.h" 26 + #include "qapi/error.h" 27 + #include "qapi-visit.h" 28 + #include "sysemu/replay.h" 29 + 30 + #include "chardev/char-fe.h" 31 + #include "chardev/char-io.h" 32 + #include "chardev/char-mux.h" 33 + 34 + int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len) 35 + { 36 + Chardev *s = be->chr; 37 + 38 + if (!s) { 39 + return 0; 40 + } 41 + 42 + return qemu_chr_write(s, buf, len, false); 43 + } 44 + 45 + int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len) 46 + { 47 + Chardev *s = be->chr; 48 + 49 + if (!s) { 50 + return 0; 51 + } 52 + 53 + return qemu_chr_write(s, buf, len, true); 54 + } 55 + 56 + int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) 57 + { 58 + Chardev *s = be->chr; 59 + int offset = 0, counter = 10; 60 + int res; 61 + 62 + if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) { 63 + return 0; 64 + } 65 + 66 + if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) { 67 + return replay_char_read_all_load(buf); 68 + } 69 + 70 + while (offset < len) { 71 + retry: 72 + res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset, 73 + len - offset); 74 + if (res == -1 && errno == EAGAIN) { 75 + g_usleep(100); 76 + goto retry; 77 + } 78 + 79 + if (res == 0) { 80 + break; 81 + } 82 + 83 + if (res < 0) { 84 + if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { 85 + replay_char_read_all_save_error(res); 86 + } 87 + return res; 88 + } 89 + 90 + offset += res; 91 + 92 + if (!counter--) { 93 + break; 94 + } 95 + } 96 + 97 + if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { 98 + replay_char_read_all_save_buf(buf, offset); 99 + } 100 + return offset; 101 + } 102 + 103 + int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg) 104 + { 105 + Chardev *s = be->chr; 106 + int res; 107 + 108 + if (!s || !CHARDEV_GET_CLASS(s)->chr_ioctl || qemu_chr_replay(s)) { 109 + res = -ENOTSUP; 110 + } else { 111 + res = CHARDEV_GET_CLASS(s)->chr_ioctl(s, cmd, arg); 112 + } 113 + 114 + return res; 115 + } 116 + 117 + int qemu_chr_fe_get_msgfd(CharBackend *be) 118 + { 119 + Chardev *s = be->chr; 120 + int fd; 121 + int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1; 122 + if (s && qemu_chr_replay(s)) { 123 + error_report("Replay: get msgfd is not supported " 124 + "for serial devices yet"); 125 + exit(1); 126 + } 127 + return res; 128 + } 129 + 130 + int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len) 131 + { 132 + Chardev *s = be->chr; 133 + 134 + if (!s) { 135 + return -1; 136 + } 137 + 138 + return CHARDEV_GET_CLASS(s)->get_msgfds ? 139 + CHARDEV_GET_CLASS(s)->get_msgfds(s, fds, len) : -1; 140 + } 141 + 142 + int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num) 143 + { 144 + Chardev *s = be->chr; 145 + 146 + if (!s) { 147 + return -1; 148 + } 149 + 150 + return CHARDEV_GET_CLASS(s)->set_msgfds ? 151 + CHARDEV_GET_CLASS(s)->set_msgfds(s, fds, num) : -1; 152 + } 153 + 154 + void qemu_chr_fe_accept_input(CharBackend *be) 155 + { 156 + Chardev *s = be->chr; 157 + 158 + if (!s) { 159 + return; 160 + } 161 + 162 + if (CHARDEV_GET_CLASS(s)->chr_accept_input) { 163 + CHARDEV_GET_CLASS(s)->chr_accept_input(s); 164 + } 165 + qemu_notify_event(); 166 + } 167 + 168 + void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) 169 + { 170 + char buf[CHR_READ_BUF_LEN]; 171 + va_list ap; 172 + va_start(ap, fmt); 173 + vsnprintf(buf, sizeof(buf), fmt, ap); 174 + /* XXX this blocks entire thread. Rewrite to use 175 + * qemu_chr_fe_write and background I/O callbacks */ 176 + qemu_chr_fe_write_all(be, (uint8_t *)buf, strlen(buf)); 177 + va_end(ap); 178 + } 179 + 180 + Chardev *qemu_chr_fe_get_driver(CharBackend *be) 181 + { 182 + return be->chr; 183 + } 184 + 185 + bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) 186 + { 187 + int tag = 0; 188 + 189 + if (CHARDEV_IS_MUX(s)) { 190 + MuxChardev *d = MUX_CHARDEV(s); 191 + 192 + if (d->mux_cnt >= MAX_MUX) { 193 + goto unavailable; 194 + } 195 + 196 + d->backends[d->mux_cnt] = b; 197 + tag = d->mux_cnt++; 198 + } else if (s->be) { 199 + goto unavailable; 200 + } else { 201 + s->be = b; 202 + } 203 + 204 + b->fe_open = false; 205 + b->tag = tag; 206 + b->chr = s; 207 + return true; 208 + 209 + unavailable: 210 + error_setg(errp, QERR_DEVICE_IN_USE, s->label); 211 + return false; 212 + } 213 + 214 + void qemu_chr_fe_deinit(CharBackend *b) 215 + { 216 + assert(b); 217 + 218 + if (b->chr) { 219 + qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true); 220 + if (b->chr->be == b) { 221 + b->chr->be = NULL; 222 + } 223 + if (CHARDEV_IS_MUX(b->chr)) { 224 + MuxChardev *d = MUX_CHARDEV(b->chr); 225 + d->backends[b->tag] = NULL; 226 + } 227 + b->chr = NULL; 228 + } 229 + } 230 + 231 + void qemu_chr_fe_set_handlers(CharBackend *b, 232 + IOCanReadHandler *fd_can_read, 233 + IOReadHandler *fd_read, 234 + IOEventHandler *fd_event, 235 + void *opaque, 236 + GMainContext *context, 237 + bool set_open) 238 + { 239 + Chardev *s; 240 + ChardevClass *cc; 241 + int fe_open; 242 + 243 + s = b->chr; 244 + if (!s) { 245 + return; 246 + } 247 + 248 + cc = CHARDEV_GET_CLASS(s); 249 + if (!opaque && !fd_can_read && !fd_read && !fd_event) { 250 + fe_open = 0; 251 + remove_fd_in_watch(s); 252 + } else { 253 + fe_open = 1; 254 + } 255 + b->chr_can_read = fd_can_read; 256 + b->chr_read = fd_read; 257 + b->chr_event = fd_event; 258 + b->opaque = opaque; 259 + if (cc->chr_update_read_handler) { 260 + cc->chr_update_read_handler(s, context); 261 + } 262 + 263 + if (set_open) { 264 + qemu_chr_fe_set_open(b, fe_open); 265 + } 266 + 267 + if (fe_open) { 268 + qemu_chr_fe_take_focus(b); 269 + /* We're connecting to an already opened device, so let's make sure we 270 + also get the open event */ 271 + if (s->be_open) { 272 + qemu_chr_be_event(s, CHR_EVENT_OPENED); 273 + } 274 + } 275 + 276 + if (CHARDEV_IS_MUX(s)) { 277 + mux_chr_set_handlers(s, context); 278 + } 279 + } 280 + 281 + void qemu_chr_fe_take_focus(CharBackend *b) 282 + { 283 + if (!b->chr) { 284 + return; 285 + } 286 + 287 + if (CHARDEV_IS_MUX(b->chr)) { 288 + mux_set_focus(b->chr, b->tag); 289 + } 290 + } 291 + 292 + int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp) 293 + { 294 + if (!be->chr) { 295 + error_setg(errp, "missing associated backend"); 296 + return -1; 297 + } 298 + 299 + return qemu_chr_wait_connected(be->chr, errp); 300 + } 301 + 302 + void qemu_chr_fe_set_echo(CharBackend *be, bool echo) 303 + { 304 + Chardev *chr = be->chr; 305 + 306 + if (chr && CHARDEV_GET_CLASS(chr)->chr_set_echo) { 307 + CHARDEV_GET_CLASS(chr)->chr_set_echo(chr, echo); 308 + } 309 + } 310 + 311 + void qemu_chr_fe_set_open(CharBackend *be, int fe_open) 312 + { 313 + Chardev *chr = be->chr; 314 + 315 + if (!chr) { 316 + return; 317 + } 318 + 319 + if (be->fe_open == fe_open) { 320 + return; 321 + } 322 + be->fe_open = fe_open; 323 + if (CHARDEV_GET_CLASS(chr)->chr_set_fe_open) { 324 + CHARDEV_GET_CLASS(chr)->chr_set_fe_open(chr, fe_open); 325 + } 326 + } 327 + 328 + guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, 329 + GIOFunc func, void *user_data) 330 + { 331 + Chardev *s = be->chr; 332 + GSource *src; 333 + guint tag; 334 + 335 + if (!s || CHARDEV_GET_CLASS(s)->chr_add_watch == NULL) { 336 + return 0; 337 + } 338 + 339 + src = CHARDEV_GET_CLASS(s)->chr_add_watch(s, cond); 340 + if (!src) { 341 + return 0; 342 + } 343 + 344 + g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); 345 + tag = g_source_attach(src, NULL); 346 + g_source_unref(src); 347 + 348 + return tag; 349 + } 350 + 351 + void qemu_chr_fe_disconnect(CharBackend *be) 352 + { 353 + Chardev *chr = be->chr; 354 + 355 + if (chr && CHARDEV_GET_CLASS(chr)->chr_disconnect) { 356 + CHARDEV_GET_CLASS(chr)->chr_disconnect(chr); 357 + } 358 + }
+1 -342
chardev/char.c
··· 22 22 * THE SOFTWARE. 23 23 */ 24 24 #include "qemu/osdep.h" 25 - #include "qemu-common.h" 26 25 #include "qemu/cutils.h" 27 26 #include "monitor/monitor.h" 28 27 #include "sysemu/sysemu.h" ··· 35 34 #include "qemu/help_option.h" 36 35 37 36 #include "chardev/char-mux.h" 38 - #include "chardev/char-io.h" 39 - #include "chardev/char-parallel.h" 40 - #include "chardev/char-serial.h" 41 37 42 38 /***********************************************************/ 43 39 /* character device */ ··· 129 125 return res; 130 126 } 131 127 132 - static bool qemu_chr_replay(Chardev *chr) 133 - { 134 - return qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY); 135 - } 136 - 137 - static int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, 138 - bool write_all) 128 + int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all) 139 129 { 140 130 int offset = 0; 141 131 int res; ··· 159 149 return offset; 160 150 } 161 151 162 - int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len) 163 - { 164 - return qemu_chr_write(s, buf, len, true); 165 - } 166 - 167 - int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len) 168 - { 169 - Chardev *s = be->chr; 170 - 171 - if (!s) { 172 - return 0; 173 - } 174 - 175 - return qemu_chr_write(s, buf, len, false); 176 - } 177 - 178 - int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len) 179 - { 180 - Chardev *s = be->chr; 181 - 182 - if (!s) { 183 - return 0; 184 - } 185 - 186 - return qemu_chr_write(s, buf, len, true); 187 - } 188 - 189 - int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) 190 - { 191 - Chardev *s = be->chr; 192 - int offset = 0, counter = 10; 193 - int res; 194 - 195 - if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) { 196 - return 0; 197 - } 198 - 199 - if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_PLAY) { 200 - return replay_char_read_all_load(buf); 201 - } 202 - 203 - while (offset < len) { 204 - retry: 205 - res = CHARDEV_GET_CLASS(s)->chr_sync_read(s, buf + offset, 206 - len - offset); 207 - if (res == -1 && errno == EAGAIN) { 208 - g_usleep(100); 209 - goto retry; 210 - } 211 - 212 - if (res == 0) { 213 - break; 214 - } 215 - 216 - if (res < 0) { 217 - if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { 218 - replay_char_read_all_save_error(res); 219 - } 220 - return res; 221 - } 222 - 223 - offset += res; 224 - 225 - if (!counter--) { 226 - break; 227 - } 228 - } 229 - 230 - if (qemu_chr_replay(s) && replay_mode == REPLAY_MODE_RECORD) { 231 - replay_char_read_all_save_buf(buf, offset); 232 - } 233 - return offset; 234 - } 235 - 236 - int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg) 237 - { 238 - Chardev *s = be->chr; 239 - int res; 240 - 241 - if (!s || !CHARDEV_GET_CLASS(s)->chr_ioctl || qemu_chr_replay(s)) { 242 - res = -ENOTSUP; 243 - } else { 244 - res = CHARDEV_GET_CLASS(s)->chr_ioctl(s, cmd, arg); 245 - } 246 - 247 - return res; 248 - } 249 - 250 152 int qemu_chr_be_can_write(Chardev *s) 251 153 { 252 154 CharBackend *be = s->be; ··· 279 181 } 280 182 } 281 183 282 - int qemu_chr_fe_get_msgfd(CharBackend *be) 283 - { 284 - Chardev *s = be->chr; 285 - int fd; 286 - int res = (qemu_chr_fe_get_msgfds(be, &fd, 1) == 1) ? fd : -1; 287 - if (s && qemu_chr_replay(s)) { 288 - error_report("Replay: get msgfd is not supported " 289 - "for serial devices yet"); 290 - exit(1); 291 - } 292 - return res; 293 - } 294 - 295 - int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int len) 296 - { 297 - Chardev *s = be->chr; 298 - 299 - if (!s) { 300 - return -1; 301 - } 302 - 303 - return CHARDEV_GET_CLASS(s)->get_msgfds ? 304 - CHARDEV_GET_CLASS(s)->get_msgfds(s, fds, len) : -1; 305 - } 306 - 307 - int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num) 308 - { 309 - Chardev *s = be->chr; 310 - 311 - if (!s) { 312 - return -1; 313 - } 314 - 315 - return CHARDEV_GET_CLASS(s)->set_msgfds ? 316 - CHARDEV_GET_CLASS(s)->set_msgfds(s, fds, num) : -1; 317 - } 318 - 319 184 int qemu_chr_add_client(Chardev *s, int fd) 320 185 { 321 186 return CHARDEV_GET_CLASS(s)->chr_add_client ? 322 187 CHARDEV_GET_CLASS(s)->chr_add_client(s, fd) : -1; 323 - } 324 - 325 - void qemu_chr_fe_accept_input(CharBackend *be) 326 - { 327 - Chardev *s = be->chr; 328 - 329 - if (!s) { 330 - return; 331 - } 332 - 333 - if (CHARDEV_GET_CLASS(s)->chr_accept_input) { 334 - CHARDEV_GET_CLASS(s)->chr_accept_input(s); 335 - } 336 - qemu_notify_event(); 337 - } 338 - 339 - void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) 340 - { 341 - char buf[CHR_READ_BUF_LEN]; 342 - va_list ap; 343 - va_start(ap, fmt); 344 - vsnprintf(buf, sizeof(buf), fmt, ap); 345 - /* XXX this blocks entire thread. Rewrite to use 346 - * qemu_chr_fe_write and background I/O callbacks */ 347 - qemu_chr_fe_write_all(be, (uint8_t *)buf, strlen(buf)); 348 - va_end(ap); 349 188 } 350 189 351 190 static void qemu_char_open(Chardev *chr, ChardevBackend *backend, ··· 459 298 .notify = muxes_realize_done, 460 299 }; 461 300 462 - Chardev *qemu_chr_fe_get_driver(CharBackend *be) 463 - { 464 - return be->chr; 465 - } 466 - 467 - bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp) 468 - { 469 - int tag = 0; 470 - 471 - if (CHARDEV_IS_MUX(s)) { 472 - MuxChardev *d = MUX_CHARDEV(s); 473 - 474 - if (d->mux_cnt >= MAX_MUX) { 475 - goto unavailable; 476 - } 477 - 478 - d->backends[d->mux_cnt] = b; 479 - tag = d->mux_cnt++; 480 - } else if (s->be) { 481 - goto unavailable; 482 - } else { 483 - s->be = b; 484 - } 485 - 486 - b->fe_open = false; 487 - b->tag = tag; 488 - b->chr = s; 489 - return true; 490 - 491 - unavailable: 492 - error_setg(errp, QERR_DEVICE_IN_USE, s->label); 493 - return false; 494 - } 495 - 496 301 static bool qemu_chr_is_busy(Chardev *s) 497 302 { 498 303 if (CHARDEV_IS_MUX(s)) { ··· 503 308 } 504 309 } 505 310 506 - void qemu_chr_fe_deinit(CharBackend *b) 507 - { 508 - assert(b); 509 - 510 - if (b->chr) { 511 - qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true); 512 - if (b->chr->be == b) { 513 - b->chr->be = NULL; 514 - } 515 - if (CHARDEV_IS_MUX(b->chr)) { 516 - MuxChardev *d = MUX_CHARDEV(b->chr); 517 - d->backends[b->tag] = NULL; 518 - } 519 - b->chr = NULL; 520 - } 521 - } 522 - 523 - void qemu_chr_fe_set_handlers(CharBackend *b, 524 - IOCanReadHandler *fd_can_read, 525 - IOReadHandler *fd_read, 526 - IOEventHandler *fd_event, 527 - void *opaque, 528 - GMainContext *context, 529 - bool set_open) 530 - { 531 - Chardev *s; 532 - ChardevClass *cc; 533 - int fe_open; 534 - 535 - s = b->chr; 536 - if (!s) { 537 - return; 538 - } 539 - 540 - cc = CHARDEV_GET_CLASS(s); 541 - if (!opaque && !fd_can_read && !fd_read && !fd_event) { 542 - fe_open = 0; 543 - remove_fd_in_watch(s); 544 - } else { 545 - fe_open = 1; 546 - } 547 - b->chr_can_read = fd_can_read; 548 - b->chr_read = fd_read; 549 - b->chr_event = fd_event; 550 - b->opaque = opaque; 551 - if (cc->chr_update_read_handler) { 552 - cc->chr_update_read_handler(s, context); 553 - } 554 - 555 - if (set_open) { 556 - qemu_chr_fe_set_open(b, fe_open); 557 - } 558 - 559 - if (fe_open) { 560 - qemu_chr_fe_take_focus(b); 561 - /* We're connecting to an already opened device, so let's make sure we 562 - also get the open event */ 563 - if (s->be_open) { 564 - qemu_chr_be_event(s, CHR_EVENT_OPENED); 565 - } 566 - } 567 - 568 - if (CHARDEV_IS_MUX(s)) { 569 - mux_chr_set_handlers(s, context); 570 - } 571 - } 572 - 573 - void qemu_chr_fe_take_focus(CharBackend *b) 574 - { 575 - if (!b->chr) { 576 - return; 577 - } 578 - 579 - if (CHARDEV_IS_MUX(b->chr)) { 580 - mux_set_focus(b->chr, b->tag); 581 - } 582 - } 583 - 584 311 int qemu_chr_wait_connected(Chardev *chr, Error **errp) 585 312 { 586 313 ChardevClass *cc = CHARDEV_GET_CLASS(chr); ··· 590 317 } 591 318 592 319 return 0; 593 - } 594 - 595 - int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp) 596 - { 597 - if (!be->chr) { 598 - error_setg(errp, "missing associated backend"); 599 - return -1; 600 - } 601 - 602 - return qemu_chr_wait_connected(be->chr, errp); 603 320 } 604 321 605 322 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) ··· 976 693 replay_register_char_driver(chr); 977 694 } 978 695 return chr; 979 - } 980 - 981 - void qemu_chr_fe_set_echo(CharBackend *be, bool echo) 982 - { 983 - Chardev *chr = be->chr; 984 - 985 - if (chr && CHARDEV_GET_CLASS(chr)->chr_set_echo) { 986 - CHARDEV_GET_CLASS(chr)->chr_set_echo(chr, echo); 987 - } 988 - } 989 - 990 - void qemu_chr_fe_set_open(CharBackend *be, int fe_open) 991 - { 992 - Chardev *chr = be->chr; 993 - 994 - if (!chr) { 995 - return; 996 - } 997 - 998 - if (be->fe_open == fe_open) { 999 - return; 1000 - } 1001 - be->fe_open = fe_open; 1002 - if (CHARDEV_GET_CLASS(chr)->chr_set_fe_open) { 1003 - CHARDEV_GET_CLASS(chr)->chr_set_fe_open(chr, fe_open); 1004 - } 1005 - } 1006 - 1007 - guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, 1008 - GIOFunc func, void *user_data) 1009 - { 1010 - Chardev *s = be->chr; 1011 - GSource *src; 1012 - guint tag; 1013 - 1014 - if (!s || CHARDEV_GET_CLASS(s)->chr_add_watch == NULL) { 1015 - return 0; 1016 - } 1017 - 1018 - src = CHARDEV_GET_CLASS(s)->chr_add_watch(s, cond); 1019 - if (!src) { 1020 - return 0; 1021 - } 1022 - 1023 - g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); 1024 - tag = g_source_attach(src, NULL); 1025 - g_source_unref(src); 1026 - 1027 - return tag; 1028 - } 1029 - 1030 - void qemu_chr_fe_disconnect(CharBackend *be) 1031 - { 1032 - Chardev *chr = be->chr; 1033 - 1034 - if (chr && CHARDEV_GET_CLASS(chr)->chr_disconnect) { 1035 - CHARDEV_GET_CLASS(chr)->chr_disconnect(chr); 1036 - } 1037 696 } 1038 697 1039 698 static int qmp_query_chardev_foreach(Object *obj, void *data)
+1
gdbstub.c
··· 26 26 #else 27 27 #include "monitor/monitor.h" 28 28 #include "chardev/char.h" 29 + #include "chardev/char-fe.h" 29 30 #include "sysemu/sysemu.h" 30 31 #include "exec/gdbstub.h" 31 32 #endif
+1 -1
hw/arm/omap2.c
··· 30 30 #include "hw/arm/omap.h" 31 31 #include "sysemu/sysemu.h" 32 32 #include "qemu/timer.h" 33 - #include "chardev/char.h" 33 + #include "chardev/char-fe.h" 34 34 #include "hw/block/flash.h" 35 35 #include "hw/arm/soc_dma.h" 36 36 #include "hw/sysbus.h"
+1 -1
hw/arm/pxa2xx.c
··· 17 17 #include "hw/char/serial.h" 18 18 #include "hw/i2c/i2c.h" 19 19 #include "hw/ssi/ssi.h" 20 - #include "chardev/char.h" 20 + #include "chardev/char-fe.h" 21 21 #include "sysemu/block-backend.h" 22 22 #include "sysemu/blockdev.h" 23 23 #include "qemu/cutils.h"
+1
hw/arm/strongarm.c
··· 34 34 #include "strongarm.h" 35 35 #include "qemu/error-report.h" 36 36 #include "hw/arm/arm.h" 37 + #include "chardev/char-fe.h" 37 38 #include "chardev/char-serial.h" 38 39 #include "sysemu/sysemu.h" 39 40 #include "hw/ssi/ssi.h"
+1
hw/char/cadence_uart.c
··· 23 23 24 24 #include "qemu/osdep.h" 25 25 #include "hw/sysbus.h" 26 + #include "chardev/char-fe.h" 26 27 #include "chardev/char-serial.h" 27 28 #include "qemu/timer.h" 28 29 #include "qemu/log.h"
+1 -1
hw/char/debugcon.c
··· 27 27 #include "qemu/osdep.h" 28 28 #include "qapi/error.h" 29 29 #include "hw/hw.h" 30 - #include "chardev/char.h" 30 + #include "chardev/char-fe.h" 31 31 #include "hw/isa/isa.h" 32 32 #include "hw/i386/pc.h" 33 33
+1 -1
hw/char/digic-uart.c
··· 29 29 #include "qemu/osdep.h" 30 30 #include "hw/hw.h" 31 31 #include "hw/sysbus.h" 32 - #include "chardev/char.h" 32 + #include "chardev/char-fe.h" 33 33 #include "qemu/log.h" 34 34 35 35 #include "hw/char/digic-uart.h"
+1
hw/char/escc.c
··· 26 26 #include "hw/hw.h" 27 27 #include "hw/sysbus.h" 28 28 #include "hw/char/escc.h" 29 + #include "chardev/char-fe.h" 29 30 #include "chardev/char-serial.h" 30 31 #include "ui/console.h" 31 32 #include "ui/input.h"
+1 -1
hw/char/etraxfs_ser.c
··· 24 24 25 25 #include "qemu/osdep.h" 26 26 #include "hw/sysbus.h" 27 - #include "chardev/char.h" 27 + #include "chardev/char-fe.h" 28 28 #include "qemu/log.h" 29 29 30 30 #define D(x)
+1
hw/char/exynos4210_uart.c
··· 23 23 #include "hw/sysbus.h" 24 24 #include "qemu/error-report.h" 25 25 #include "sysemu/sysemu.h" 26 + #include "chardev/char-fe.h" 26 27 #include "chardev/char-serial.h" 27 28 28 29 #include "hw/arm/exynos4210.h"
+1 -1
hw/char/grlib_apbuart.c
··· 24 24 25 25 #include "qemu/osdep.h" 26 26 #include "hw/sysbus.h" 27 - #include "chardev/char.h" 27 + #include "chardev/char-fe.h" 28 28 29 29 #include "trace.h" 30 30
+1 -1
hw/char/ipoctal232.c
··· 11 11 #include "qemu/osdep.h" 12 12 #include "hw/ipack/ipack.h" 13 13 #include "qemu/bitops.h" 14 - #include "chardev/char.h" 14 + #include "chardev/char-fe.h" 15 15 16 16 /* #define DEBUG_IPOCTAL */ 17 17
+1 -1
hw/char/lm32_juart.c
··· 21 21 #include "hw/hw.h" 22 22 #include "hw/sysbus.h" 23 23 #include "trace.h" 24 - #include "chardev/char.h" 24 + #include "chardev/char-fe.h" 25 25 26 26 #include "hw/char/lm32_juart.h" 27 27
+1 -1
hw/char/lm32_uart.c
··· 26 26 #include "hw/hw.h" 27 27 #include "hw/sysbus.h" 28 28 #include "trace.h" 29 - #include "chardev/char.h" 29 + #include "chardev/char-fe.h" 30 30 #include "qemu/error-report.h" 31 31 32 32 enum {
+1 -1
hw/char/mcf_uart.c
··· 9 9 #include "hw/hw.h" 10 10 #include "hw/sysbus.h" 11 11 #include "hw/m68k/mcf.h" 12 - #include "chardev/char.h" 12 + #include "chardev/char-fe.h" 13 13 #include "exec/address-spaces.h" 14 14 #include "qapi/error.h" 15 15
+1 -1
hw/char/milkymist-uart.c
··· 25 25 #include "hw/hw.h" 26 26 #include "hw/sysbus.h" 27 27 #include "trace.h" 28 - #include "chardev/char.h" 28 + #include "chardev/char-fe.h" 29 29 #include "qemu/error-report.h" 30 30 31 31 enum {
+1
hw/char/parallel.c
··· 26 26 #include "qapi/error.h" 27 27 #include "hw/hw.h" 28 28 #include "chardev/char-parallel.h" 29 + #include "chardev/char-fe.h" 29 30 #include "hw/isa/isa.h" 30 31 #include "hw/i386/pc.h" 31 32 #include "sysemu/sysemu.h"
+1 -1
hw/char/pl011.c
··· 9 9 10 10 #include "qemu/osdep.h" 11 11 #include "hw/sysbus.h" 12 - #include "chardev/char.h" 12 + #include "chardev/char-fe.h" 13 13 #include "qemu/log.h" 14 14 #include "trace.h" 15 15
+1 -1
hw/char/sclpconsole-lm.c
··· 17 17 #include "hw/qdev.h" 18 18 #include "qemu/thread.h" 19 19 #include "qemu/error-report.h" 20 - #include "chardev/char.h" 20 + #include "chardev/char-fe.h" 21 21 22 22 #include "hw/s390x/sclp.h" 23 23 #include "hw/s390x/event-facility.h"
+1 -1
hw/char/sclpconsole.c
··· 19 19 20 20 #include "hw/s390x/sclp.h" 21 21 #include "hw/s390x/event-facility.h" 22 - #include "chardev/char.h" 22 + #include "chardev/char-fe.h" 23 23 24 24 typedef struct ASCIIConsoleData { 25 25 EventBufferHeader ebh;
+1 -1
hw/char/sh_serial.c
··· 27 27 #include "qemu/osdep.h" 28 28 #include "hw/hw.h" 29 29 #include "hw/sh4/sh.h" 30 - #include "chardev/char.h" 30 + #include "chardev/char-fe.h" 31 31 #include "exec/address-spaces.h" 32 32 #include "qapi/error.h" 33 33
+1 -1
hw/char/spapr_vty.c
··· 4 4 #include "qemu-common.h" 5 5 #include "cpu.h" 6 6 #include "hw/qdev.h" 7 - #include "chardev/char.h" 7 + #include "chardev/char-fe.h" 8 8 #include "hw/ppc/spapr.h" 9 9 #include "hw/ppc/spapr_vio.h" 10 10
+1 -1
hw/char/terminal3270.c
··· 13 13 14 14 #include "qemu/osdep.h" 15 15 #include "qapi/error.h" 16 - #include "chardev/char.h" 16 + #include "chardev/char-fe.h" 17 17 #include "hw/s390x/3270-ccw.h" 18 18 19 19 /* Enough spaces for different window sizes. */
+1 -1
hw/char/virtio-console.c
··· 11 11 */ 12 12 13 13 #include "qemu/osdep.h" 14 - #include "chardev/char.h" 14 + #include "chardev/char-fe.h" 15 15 #include "qemu/error-report.h" 16 16 #include "trace.h" 17 17 #include "hw/virtio/virtio-serial.h"
+1 -1
hw/char/xen_console.c
··· 25 25 26 26 #include "qapi/error.h" 27 27 #include "hw/hw.h" 28 - #include "chardev/char.h" 28 + #include "chardev/char-fe.h" 29 29 #include "hw/xen/xen_backend.h" 30 30 #include "qapi/error.h" 31 31
+1 -1
hw/char/xilinx_uartlite.c
··· 24 24 25 25 #include "qemu/osdep.h" 26 26 #include "hw/sysbus.h" 27 - #include "chardev/char.h" 27 + #include "chardev/char-fe.h" 28 28 29 29 #define DUART(x) 30 30
+1 -1
hw/core/qdev-properties-system.c
··· 20 20 #include "hw/block/block.h" 21 21 #include "net/hub.h" 22 22 #include "qapi/visitor.h" 23 - #include "chardev/char.h" 23 + #include "chardev/char-fe.h" 24 24 #include "sysemu/iothread.h" 25 25 26 26 static void get_pointer(Object *obj, Visitor *v, Property *prop,
+1 -1
hw/ipmi/ipmi_bmc_extern.c
··· 30 30 #include "qemu/osdep.h" 31 31 #include "qapi/error.h" 32 32 #include "qemu/timer.h" 33 - #include "chardev/char.h" 33 + #include "chardev/char-fe.h" 34 34 #include "sysemu/sysemu.h" 35 35 #include "hw/ipmi/ipmi.h" 36 36
+1 -1
hw/misc/ivshmem.c
··· 29 29 #include "qemu/error-report.h" 30 30 #include "qemu/event_notifier.h" 31 31 #include "qom/object_interfaces.h" 32 - #include "chardev/char.h" 32 + #include "chardev/char-fe.h" 33 33 #include "sysemu/hostmem.h" 34 34 #include "sysemu/qtest.h" 35 35 #include "qapi/visitor.h"
+1 -1
hw/usb/ccid-card-passthru.c
··· 9 9 */ 10 10 11 11 #include "qemu/osdep.h" 12 - #include "chardev/char.h" 12 + #include "chardev/char-fe.h" 13 13 #include "qemu/error-report.h" 14 14 #include "qemu/sockets.h" 15 15 #include "ccid.h"
+1
hw/usb/dev-serial.c
··· 16 16 #include "hw/usb.h" 17 17 #include "hw/usb/desc.h" 18 18 #include "chardev/char-serial.h" 19 + #include "chardev/char-fe.h" 19 20 20 21 //#define DEBUG_Serial 21 22
+1 -1
hw/usb/redirect.c
··· 33 33 #include "qapi/qmp/qerror.h" 34 34 #include "qemu/error-report.h" 35 35 #include "qemu/iov.h" 36 - #include "chardev/char.h" 36 + #include "chardev/char-fe.h" 37 37 38 38 #include <usbredirparser.h> 39 39 #include <usbredirfilter.h>
+1 -1
hw/virtio/vhost-user.c
··· 13 13 #include "hw/virtio/vhost.h" 14 14 #include "hw/virtio/vhost-backend.h" 15 15 #include "hw/virtio/virtio-net.h" 16 - #include "chardev/char.h" 16 + #include "chardev/char-fe.h" 17 17 #include "sysemu/kvm.h" 18 18 #include "qemu/error-report.h" 19 19 #include "qemu/sockets.h"
+249
include/chardev/char-fe.h
··· 1 + #ifndef QEMU_CHAR_FE_H 2 + #define QEMU_CHAR_FE_H 3 + 4 + #include "chardev/char.h" 5 + 6 + typedef void IOEventHandler(void *opaque, int event); 7 + 8 + /* This is the backend as seen by frontend, the actual backend is 9 + * Chardev */ 10 + struct CharBackend { 11 + Chardev *chr; 12 + IOEventHandler *chr_event; 13 + IOCanReadHandler *chr_can_read; 14 + IOReadHandler *chr_read; 15 + void *opaque; 16 + int tag; 17 + int fe_open; 18 + }; 19 + 20 + /** 21 + * @qemu_chr_fe_init: 22 + * 23 + * Initializes a front end for the given CharBackend and 24 + * Chardev. Call qemu_chr_fe_deinit() to remove the association and 25 + * release the driver. 26 + * 27 + * Returns: false on error. 28 + */ 29 + bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp); 30 + 31 + /** 32 + * @qemu_chr_fe_deinit: 33 + * 34 + * Dissociate the CharBackend from the Chardev. 35 + * 36 + * Safe to call without associated Chardev. 37 + */ 38 + void qemu_chr_fe_deinit(CharBackend *b); 39 + 40 + /** 41 + * @qemu_chr_fe_get_driver: 42 + * 43 + * Returns the driver associated with a CharBackend or NULL if no 44 + * associated Chardev. 45 + */ 46 + Chardev *qemu_chr_fe_get_driver(CharBackend *be); 47 + 48 + /** 49 + * @qemu_chr_fe_set_handlers: 50 + * @b: a CharBackend 51 + * @fd_can_read: callback to get the amount of data the frontend may 52 + * receive 53 + * @fd_read: callback to receive data from char 54 + * @fd_event: event callback 55 + * @opaque: an opaque pointer for the callbacks 56 + * @context: a main loop context or NULL for the default 57 + * @set_open: whether to call qemu_chr_fe_set_open() implicitely when 58 + * any of the handler is non-NULL 59 + * 60 + * Set the front end char handlers. The front end takes the focus if 61 + * any of the handler is non-NULL. 62 + * 63 + * Without associated Chardev, nothing is changed. 64 + */ 65 + void qemu_chr_fe_set_handlers(CharBackend *b, 66 + IOCanReadHandler *fd_can_read, 67 + IOReadHandler *fd_read, 68 + IOEventHandler *fd_event, 69 + void *opaque, 70 + GMainContext *context, 71 + bool set_open); 72 + 73 + /** 74 + * @qemu_chr_fe_take_focus: 75 + * 76 + * Take the focus (if the front end is muxed). 77 + * 78 + * Without associated Chardev, nothing is changed. 79 + */ 80 + void qemu_chr_fe_take_focus(CharBackend *b); 81 + 82 + /** 83 + * @qemu_chr_fe_accept_input: 84 + * 85 + * Notify that the frontend is ready to receive data 86 + */ 87 + void qemu_chr_fe_accept_input(CharBackend *be); 88 + 89 + /** 90 + * @qemu_chr_fe_disconnect: 91 + * 92 + * Close a fd accpeted by character backend. 93 + * Without associated Chardev, do nothing. 94 + */ 95 + void qemu_chr_fe_disconnect(CharBackend *be); 96 + 97 + /** 98 + * @qemu_chr_fe_wait_connected: 99 + * 100 + * Wait for characted backend to be connected, return < 0 on error or 101 + * if no assicated Chardev. 102 + */ 103 + int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp); 104 + 105 + /** 106 + * @qemu_chr_fe_set_echo: 107 + * 108 + * Ask the backend to override its normal echo setting. This only really 109 + * applies to the stdio backend and is used by the QMP server such that you 110 + * can see what you type if you try to type QMP commands. 111 + * Without associated Chardev, do nothing. 112 + * 113 + * @echo true to enable echo, false to disable echo 114 + */ 115 + void qemu_chr_fe_set_echo(CharBackend *be, bool echo); 116 + 117 + /** 118 + * @qemu_chr_fe_set_open: 119 + * 120 + * Set character frontend open status. This is an indication that the 121 + * front end is ready (or not) to begin doing I/O. 122 + * Without associated Chardev, do nothing. 123 + */ 124 + void qemu_chr_fe_set_open(CharBackend *be, int fe_open); 125 + 126 + /** 127 + * @qemu_chr_fe_printf: 128 + * 129 + * Write to a character backend using a printf style interface. This 130 + * function is thread-safe. It does nothing without associated 131 + * Chardev. 132 + * 133 + * @fmt see #printf 134 + */ 135 + void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) 136 + GCC_FMT_ATTR(2, 3); 137 + 138 + /** 139 + * @qemu_chr_fe_add_watch: 140 + * 141 + * If the backend is connected, create and add a #GSource that fires 142 + * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP) 143 + * is active; return the #GSource's tag. If it is disconnected, 144 + * or without associated Chardev, return 0. 145 + * 146 + * @cond the condition to poll for 147 + * @func the function to call when the condition happens 148 + * @user_data the opaque pointer to pass to @func 149 + * 150 + * Returns: the source tag 151 + */ 152 + guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, 153 + GIOFunc func, void *user_data); 154 + 155 + /** 156 + * @qemu_chr_fe_write: 157 + * 158 + * Write data to a character backend from the front end. This function 159 + * will send data from the front end to the back end. This function 160 + * is thread-safe. 161 + * 162 + * @buf the data 163 + * @len the number of bytes to send 164 + * 165 + * Returns: the number of bytes consumed (0 if no assicated Chardev) 166 + */ 167 + int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len); 168 + 169 + /** 170 + * @qemu_chr_fe_write_all: 171 + * 172 + * Write data to a character backend from the front end. This function will 173 + * send data from the front end to the back end. Unlike @qemu_chr_fe_write, 174 + * this function will block if the back end cannot consume all of the data 175 + * attempted to be written. This function is thread-safe. 176 + * 177 + * @buf the data 178 + * @len the number of bytes to send 179 + * 180 + * Returns: the number of bytes consumed (0 if no assicated Chardev) 181 + */ 182 + int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); 183 + 184 + /** 185 + * @qemu_chr_fe_read_all: 186 + * 187 + * Read data to a buffer from the back end. 188 + * 189 + * @buf the data buffer 190 + * @len the number of bytes to read 191 + * 192 + * Returns: the number of bytes read (0 if no assicated Chardev) 193 + */ 194 + int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len); 195 + 196 + /** 197 + * @qemu_chr_fe_ioctl: 198 + * 199 + * Issue a device specific ioctl to a backend. This function is thread-safe. 200 + * 201 + * @cmd see CHR_IOCTL_* 202 + * @arg the data associated with @cmd 203 + * 204 + * Returns: if @cmd is not supported by the backend or there is no 205 + * associated Chardev, -ENOTSUP, otherwise the return 206 + * value depends on the semantics of @cmd 207 + */ 208 + int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg); 209 + 210 + /** 211 + * @qemu_chr_fe_get_msgfd: 212 + * 213 + * For backends capable of fd passing, return the latest file descriptor passed 214 + * by a client. 215 + * 216 + * Returns: -1 if fd passing isn't supported or there is no pending file 217 + * descriptor. If a file descriptor is returned, subsequent calls to 218 + * this function will return -1 until a client sends a new file 219 + * descriptor. 220 + */ 221 + int qemu_chr_fe_get_msgfd(CharBackend *be); 222 + 223 + /** 224 + * @qemu_chr_fe_get_msgfds: 225 + * 226 + * For backends capable of fd passing, return the number of file received 227 + * descriptors and fills the fds array up to num elements 228 + * 229 + * Returns: -1 if fd passing isn't supported or there are no pending file 230 + * descriptors. If file descriptors are returned, subsequent calls to 231 + * this function will return -1 until a client sends a new set of file 232 + * descriptors. 233 + */ 234 + int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num); 235 + 236 + /** 237 + * @qemu_chr_fe_set_msgfds: 238 + * 239 + * For backends capable of fd passing, set an array of fds to be passed with 240 + * the next send operation. 241 + * A subsequent call to this function before calling a write function will 242 + * result in overwriting the fd array with the new value without being send. 243 + * Upon writing the message the fd array is freed. 244 + * 245 + * Returns: -1 if fd passing isn't supported or no associated Chardev. 246 + */ 247 + int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num); 248 + 249 + #endif /* QEMU_CHAR_FE_H */
+1
include/chardev/char-mux.h
··· 25 25 #define CHAR_MUX_H 26 26 27 27 #include "chardev/char.h" 28 + #include "chardev/char-fe.h" 28 29 29 30 extern bool muxes_realized; 30 31
+4 -238
include/chardev/char.h
··· 16 16 #define IAC 255 17 17 18 18 /* character device */ 19 + typedef struct CharBackend CharBackend; 19 20 20 21 typedef enum { 21 22 CHR_EVENT_BREAK, /* serial break char */ ··· 26 27 } QEMUChrEvent; 27 28 28 29 #define CHR_READ_BUF_LEN 4096 29 - 30 - typedef void IOEventHandler(void *opaque, int event); 31 30 32 31 typedef enum { 33 32 /* Whether the chardev peer is able to close and ··· 44 43 QEMU_CHAR_FEATURE_LAST, 45 44 } ChardevFeature; 46 45 47 - /* This is the backend as seen by frontend, the actual backend is 48 - * Chardev */ 49 - typedef struct CharBackend { 50 - Chardev *chr; 51 - IOEventHandler *chr_event; 52 - IOCanReadHandler *chr_can_read; 53 - IOReadHandler *chr_read; 54 - void *opaque; 55 - int tag; 56 - int fe_open; 57 - } CharBackend; 46 + #define qemu_chr_replay(chr) qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_REPLAY) 58 47 59 48 struct Chardev { 60 49 Object parent_obj; ··· 102 91 * Returns: a new character backend 103 92 */ 104 93 Chardev *qemu_chr_new(const char *label, const char *filename); 105 - 106 - 107 - /** 108 - * @qemu_chr_fe_disconnect: 109 - * 110 - * Close a fd accpeted by character backend. 111 - * Without associated Chardev, do nothing. 112 - */ 113 - void qemu_chr_fe_disconnect(CharBackend *be); 114 94 115 95 /** 116 96 * @qemu_chr_cleanup: ··· 120 100 void qemu_chr_cleanup(void); 121 101 122 102 /** 123 - * @qemu_chr_fe_wait_connected: 124 - * 125 - * Wait for characted backend to be connected, return < 0 on error or 126 - * if no assicated Chardev. 127 - */ 128 - int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp); 129 - 130 - /** 131 103 * @qemu_chr_new_noreplay: 132 104 * 133 105 * Create a new character backend from a URI. ··· 142 114 Chardev *qemu_chr_new_noreplay(const char *label, const char *filename); 143 115 144 116 /** 145 - * @qemu_chr_fe_set_echo: 146 - * 147 - * Ask the backend to override its normal echo setting. This only really 148 - * applies to the stdio backend and is used by the QMP server such that you 149 - * can see what you type if you try to type QMP commands. 150 - * Without associated Chardev, do nothing. 151 - * 152 - * @echo true to enable echo, false to disable echo 153 - */ 154 - void qemu_chr_fe_set_echo(CharBackend *be, bool echo); 155 - 156 - /** 157 - * @qemu_chr_fe_set_open: 158 - * 159 - * Set character frontend open status. This is an indication that the 160 - * front end is ready (or not) to begin doing I/O. 161 - * Without associated Chardev, do nothing. 162 - */ 163 - void qemu_chr_fe_set_open(CharBackend *be, int fe_open); 164 - 165 - /** 166 - * @qemu_chr_fe_printf: 167 - * 168 - * Write to a character backend using a printf style interface. This 169 - * function is thread-safe. It does nothing without associated 170 - * Chardev. 171 - * 172 - * @fmt see #printf 173 - */ 174 - void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) 175 - GCC_FMT_ATTR(2, 3); 176 - 177 - /** 178 - * @qemu_chr_fe_add_watch: 179 - * 180 - * If the backend is connected, create and add a #GSource that fires 181 - * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP) 182 - * is active; return the #GSource's tag. If it is disconnected, 183 - * or without associated Chardev, return 0. 184 - * 185 - * @cond the condition to poll for 186 - * @func the function to call when the condition happens 187 - * @user_data the opaque pointer to pass to @func 188 - * 189 - * Returns: the source tag 190 - */ 191 - guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, 192 - GIOFunc func, void *user_data); 193 - 194 - /** 195 - * @qemu_chr_fe_write: 196 - * 197 - * Write data to a character backend from the front end. This function 198 - * will send data from the front end to the back end. This function 199 - * is thread-safe. 200 - * 201 - * @buf the data 202 - * @len the number of bytes to send 203 - * 204 - * Returns: the number of bytes consumed (0 if no assicated Chardev) 205 - */ 206 - int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len); 207 - 208 - /** 209 - * @qemu_chr_fe_write_all: 210 - * 211 - * Write data to a character backend from the front end. This function will 212 - * send data from the front end to the back end. Unlike @qemu_chr_fe_write, 213 - * this function will block if the back end cannot consume all of the data 214 - * attempted to be written. This function is thread-safe. 215 - * 216 - * @buf the data 217 - * @len the number of bytes to send 218 - * 219 - * Returns: the number of bytes consumed (0 if no assicated Chardev) 220 - */ 221 - int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); 222 - 223 - /** 224 - * @qemu_chr_fe_read_all: 225 - * 226 - * Read data to a buffer from the back end. 227 - * 228 - * @buf the data buffer 229 - * @len the number of bytes to read 230 - * 231 - * Returns: the number of bytes read (0 if no assicated Chardev) 232 - */ 233 - int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len); 234 - 235 - /** 236 - * @qemu_chr_fe_ioctl: 237 - * 238 - * Issue a device specific ioctl to a backend. This function is thread-safe. 239 - * 240 - * @cmd see CHR_IOCTL_* 241 - * @arg the data associated with @cmd 242 - * 243 - * Returns: if @cmd is not supported by the backend or there is no 244 - * associated Chardev, -ENOTSUP, otherwise the return 245 - * value depends on the semantics of @cmd 246 - */ 247 - int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg); 248 - 249 - /** 250 - * @qemu_chr_fe_get_msgfd: 251 - * 252 - * For backends capable of fd passing, return the latest file descriptor passed 253 - * by a client. 254 - * 255 - * Returns: -1 if fd passing isn't supported or there is no pending file 256 - * descriptor. If a file descriptor is returned, subsequent calls to 257 - * this function will return -1 until a client sends a new file 258 - * descriptor. 259 - */ 260 - int qemu_chr_fe_get_msgfd(CharBackend *be); 261 - 262 - /** 263 - * @qemu_chr_fe_get_msgfds: 264 - * 265 - * For backends capable of fd passing, return the number of file received 266 - * descriptors and fills the fds array up to num elements 267 - * 268 - * Returns: -1 if fd passing isn't supported or there are no pending file 269 - * descriptors. If file descriptors are returned, subsequent calls to 270 - * this function will return -1 until a client sends a new set of file 271 - * descriptors. 272 - */ 273 - int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num); 274 - 275 - /** 276 - * @qemu_chr_fe_set_msgfds: 277 - * 278 - * For backends capable of fd passing, set an array of fds to be passed with 279 - * the next send operation. 280 - * A subsequent call to this function before calling a write function will 281 - * result in overwriting the fd array with the new value without being send. 282 - * Upon writing the message the fd array is freed. 283 - * 284 - * Returns: -1 if fd passing isn't supported or no associated Chardev. 285 - */ 286 - int qemu_chr_fe_set_msgfds(CharBackend *be, int *fds, int num); 287 - 288 - /** 289 117 * @qemu_chr_be_can_write: 290 118 * 291 119 * Determine how much data the front end can currently accept. This function ··· 328 156 */ 329 157 void qemu_chr_be_event(Chardev *s, int event); 330 158 331 - /** 332 - * @qemu_chr_fe_init: 333 - * 334 - * Initializes a front end for the given CharBackend and 335 - * Chardev. Call qemu_chr_fe_deinit() to remove the association and 336 - * release the driver. 337 - * 338 - * Returns: false on error. 339 - */ 340 - bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp); 341 - 342 - /** 343 - * @qemu_chr_fe_get_driver: 344 - * 345 - * Returns the driver associated with a CharBackend or NULL if no 346 - * associated Chardev. 347 - */ 348 - Chardev *qemu_chr_fe_get_driver(CharBackend *be); 349 - 350 - /** 351 - * @qemu_chr_fe_deinit: 352 - * 353 - * Dissociate the CharBackend from the Chardev. 354 - * 355 - * Safe to call without associated Chardev. 356 - */ 357 - void qemu_chr_fe_deinit(CharBackend *b); 358 - 359 - /** 360 - * @qemu_chr_fe_set_handlers: 361 - * @b: a CharBackend 362 - * @fd_can_read: callback to get the amount of data the frontend may 363 - * receive 364 - * @fd_read: callback to receive data from char 365 - * @fd_event: event callback 366 - * @opaque: an opaque pointer for the callbacks 367 - * @context: a main loop context or NULL for the default 368 - * @set_open: whether to call qemu_chr_fe_set_open() implicitely when 369 - * any of the handler is non-NULL 370 - * 371 - * Set the front end char handlers. The front end takes the focus if 372 - * any of the handler is non-NULL. 373 - * 374 - * Without associated Chardev, nothing is changed. 375 - */ 376 - void qemu_chr_fe_set_handlers(CharBackend *b, 377 - IOCanReadHandler *fd_can_read, 378 - IOReadHandler *fd_read, 379 - IOEventHandler *fd_event, 380 - void *opaque, 381 - GMainContext *context, 382 - bool set_open); 383 - 384 - /** 385 - * @qemu_chr_fe_take_focus: 386 - * 387 - * Take the focus (if the front end is muxed). 388 - * 389 - * Without associated Chardev, nothing is changed. 390 - */ 391 - void qemu_chr_fe_take_focus(CharBackend *b); 392 - 393 - void qemu_chr_fe_accept_input(CharBackend *be); 394 159 int qemu_chr_add_client(Chardev *s, int fd); 395 160 Chardev *qemu_chr_find(const char *name); 396 161 ··· 399 164 void qemu_chr_set_feature(Chardev *chr, 400 165 ChardevFeature feature); 401 166 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); 402 - int qemu_chr_write_all(Chardev *s, const uint8_t *buf, int len); 167 + int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all); 168 + #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true) 403 169 int qemu_chr_wait_connected(Chardev *chr, Error **errp); 404 170 405 171 #define TYPE_CHARDEV "chardev"
+1 -1
include/hw/char/bcm2835_aux.h
··· 9 9 #define BCM2835_AUX_H 10 10 11 11 #include "hw/sysbus.h" 12 - #include "chardev/char.h" 12 + #include "chardev/char-fe.h" 13 13 14 14 #define TYPE_BCM2835_AUX "bcm2835-aux" 15 15 #define BCM2835_AUX(obj) OBJECT_CHECK(BCM2835AuxState, (obj), TYPE_BCM2835_AUX)
+1 -1
include/hw/char/cadence_uart.h
··· 19 19 #ifndef CADENCE_UART_H 20 20 21 21 #include "hw/sysbus.h" 22 - #include "chardev/char.h" 22 + #include "chardev/char-fe.h" 23 23 #include "qemu/timer.h" 24 24 25 25 #define CADENCE_UART_RX_FIFO_SIZE 16
+1 -1
include/hw/char/digic-uart.h
··· 19 19 #define HW_CHAR_DIGIC_UART_H 20 20 21 21 #include "hw/sysbus.h" 22 - #include "chardev/char.h" 22 + #include "chardev/char-fe.h" 23 23 24 24 #define TYPE_DIGIC_UART "digic-uart" 25 25 #define DIGIC_UART(obj) \
+1 -1
include/hw/char/imx_serial.h
··· 19 19 #define IMX_SERIAL_H 20 20 21 21 #include "hw/sysbus.h" 22 - #include "chardev/char.h" 22 + #include "chardev/char-fe.h" 23 23 24 24 #define TYPE_IMX_SERIAL "imx.serial" 25 25 #define IMX_SERIAL(obj) OBJECT_CHECK(IMXSerialState, (obj), TYPE_IMX_SERIAL)
+1 -1
include/hw/char/serial.h
··· 28 28 29 29 #include "hw/hw.h" 30 30 #include "sysemu/sysemu.h" 31 - #include "chardev/char.h" 31 + #include "chardev/char-fe.h" 32 32 #include "exec/memory.h" 33 33 #include "qemu/fifo8.h" 34 34 #include "chardev/char.h"
+1 -1
include/hw/char/stm32f2xx_usart.h
··· 26 26 #define HW_STM32F2XX_USART_H 27 27 28 28 #include "hw/sysbus.h" 29 - #include "chardev/char.h" 29 + #include "chardev/char-fe.h" 30 30 #include "hw/hw.h" 31 31 32 32 #define USART_SR 0x00
+1 -1
monitor.c
··· 35 35 #include "exec/gdbstub.h" 36 36 #include "net/net.h" 37 37 #include "net/slirp.h" 38 - #include "chardev/char.h" 38 + #include "chardev/char-fe.h" 39 39 #include "ui/qemu-spice.h" 40 40 #include "sysemu/numa.h" 41 41 #include "monitor/monitor.h"
+1 -1
net/colo-compare.c
··· 25 25 #include "qom/object.h" 26 26 #include "qemu/typedefs.h" 27 27 #include "net/queue.h" 28 - #include "chardev/char.h" 28 + #include "chardev/char-fe.h" 29 29 #include "qemu/sockets.h" 30 30 #include "qapi-visit.h" 31 31 #include "net/colo.h"
+1 -1
net/filter-mirror.c
··· 20 20 #include "qemu/main-loop.h" 21 21 #include "qemu/error-report.h" 22 22 #include "trace.h" 23 - #include "chardev/char.h" 23 + #include "chardev/char-fe.h" 24 24 #include "qemu/iov.h" 25 25 #include "qemu/sockets.h" 26 26
+1 -1
net/slirp.c
··· 37 37 #include "qemu/sockets.h" 38 38 #include "slirp/libslirp.h" 39 39 #include "slirp/ip6.h" 40 - #include "chardev/char.h" 40 + #include "chardev/char-fe.h" 41 41 #include "sysemu/sysemu.h" 42 42 #include "qemu/cutils.h" 43 43 #include "qapi/error.h"
+1 -1
net/vhost-user.c
··· 12 12 #include "clients.h" 13 13 #include "net/vhost_net.h" 14 14 #include "net/vhost-user.h" 15 - #include "chardev/char.h" 15 + #include "chardev/char-fe.h" 16 16 #include "qemu/config-file.h" 17 17 #include "qemu/error-report.h" 18 18 #include "qmp-commands.h"
+1 -1
qtest.c
··· 17 17 #include "cpu.h" 18 18 #include "sysemu/qtest.h" 19 19 #include "hw/qdev.h" 20 - #include "chardev/char.h" 20 + #include "chardev/char-fe.h" 21 21 #include "exec/ioport.h" 22 22 #include "exec/memory.h" 23 23 #include "hw/irq.h"
+1 -1
slirp/slirp.c
··· 25 25 #include "qemu-common.h" 26 26 #include "qemu/timer.h" 27 27 #include "qemu/error-report.h" 28 - #include "chardev/char.h" 28 + #include "chardev/char-fe.h" 29 29 #include "slirp.h" 30 30 #include "hw/hw.h" 31 31 #include "qemu/cutils.h"
+1 -1
tests/test-char.c
··· 4 4 #include "qemu-common.h" 5 5 #include "qemu/config-file.h" 6 6 #include "qemu/sockets.h" 7 - #include "chardev/char.h" 7 + #include "chardev/char-fe.h" 8 8 #include "sysemu/sysemu.h" 9 9 #include "qapi/error.h" 10 10 #include "qom/qom-qobject.h"
+1 -1
tests/vhost-user-test.c
··· 16 16 #include "qemu/option.h" 17 17 #include "qemu/range.h" 18 18 #include "qemu/sockets.h" 19 - #include "chardev/char.h" 19 + #include "chardev/char-fe.h" 20 20 #include "sysemu/sysemu.h" 21 21 #include "libqos/libqos.h" 22 22 #include "libqos/pci-pc.h"
+1 -1
ui/console.c
··· 27 27 #include "hw/qdev-core.h" 28 28 #include "qemu/timer.h" 29 29 #include "qmp-commands.h" 30 - #include "chardev/char.h" 30 + #include "chardev/char-fe.h" 31 31 #include "trace.h" 32 32 #include "exec/memory.h" 33 33