Revision 1f590cf9

b/hmp-commands.hx
837 837
@item nmi @var{cpu}
838 838
@findex nmi
839 839
Inject an NMI on the given CPU (x86 only).
840

  
841
ETEXI
842

  
843
    {
844
        .name       = "memchar_write",
845
        .args_type  = "device:s,data:s",
846
        .params     = "device data",
847
        .help       = "Provide writing interface for CirMemCharDriver. Write"
848
                      "'data' to it.",
849
        .mhandler.cmd = hmp_memchar_write,
850
    },
851

  
852
STEXI
853
@item memchar_write @var{device} @var{data}
854
@findex memchar_write
855
Provide writing interface for CirMemCharDriver. Write @var{data}
856
to char device 'memory'.
857

  
840 858
ETEXI
841 859

  
842 860
    {
b/hmp.c
662 662
    hmp_handle_error(mon, &errp);
663 663
}
664 664

  
665
void hmp_memchar_write(Monitor *mon, const QDict *qdict)
666
{
667
    uint32_t size;
668
    const char *chardev = qdict_get_str(qdict, "device");
669
    const char *data = qdict_get_str(qdict, "data");
670
    Error *errp = NULL;
671

  
672
    size = strlen(data);
673
    qmp_memchar_write(chardev, size, data, false, 0, &errp);
674

  
675
    hmp_handle_error(mon, &errp);
676
}
677

  
665 678
static void hmp_cont_cb(void *opaque, int err)
666 679
{
667 680
    if (!err) {
b/hmp.h
43 43
void hmp_cpu(Monitor *mon, const QDict *qdict);
44 44
void hmp_memsave(Monitor *mon, const QDict *qdict);
45 45
void hmp_pmemsave(Monitor *mon, const QDict *qdict);
46
void hmp_memchar_write(Monitor *mon, const QDict *qdict);
46 47
void hmp_cont(Monitor *mon, const QDict *qdict);
47 48
void hmp_system_wakeup(Monitor *mon, const QDict *qdict);
48 49
void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
b/qapi-schema.json
325 325
{ 'command': 'query-chardev', 'returns': ['ChardevInfo'] }
326 326

  
327 327
##
328
# @DataFormat:
329
#
330
# An enumeration of data format.
331
#
332
# @utf8: The data format is 'utf8'.
333
#
334
# @base64: The data format is 'base64'.
335
#
336
# Since: 1.4
337
##
338
{ 'enum': 'DataFormat'
339
  'data': [ 'utf8', 'base64' ] }
340

  
341
##
342
# @memchar-write:
343
#
344
# Provide writing interface for memchardev. Write data to char
345
# device 'memory'.
346
#
347
# @device: the name of the memory char device.
348
#
349
# @size: the size to write in bytes.
350
#
351
# @data: the source data write to memchar.
352
#
353
# @format: #optional the format of the data write to chardev 'memory',
354
#          by default is 'utf8'.
355
#
356
# Returns: Nothing on success
357
#          If @device is not a valid char device, DeviceNotFound
358
#
359
# Since: 1.4
360
##
361
{ 'command': 'memchar-write',
362
  'data': {'device': 'str', 'size': 'int', 'data': 'str',
363
           '*format': 'DataFormat'} }
364

  
365
##
328 366
# @CommandInfo:
329 367
#
330 368
# Information about a QMP command
b/qemu-char.c
2748 2748
    return NULL;
2749 2749
}
2750 2750

  
2751
static bool qemu_is_chr(const CharDriverState *chr, const char *filename)
2752
{
2753
    return strcmp(chr->filename, filename);
2754
}
2755

  
2756
void qmp_memchar_write(const char *device, int64_t size,
2757
                       const char *data, bool has_format,
2758
                       enum DataFormat format,
2759
                       Error **errp)
2760
{
2761
    CharDriverState *chr;
2762
    guchar *write_data;
2763
    int ret;
2764
    gsize write_count;
2765

  
2766
    chr = qemu_chr_find(device);
2767
    if (!chr) {
2768
        error_set(errp, QERR_DEVICE_NOT_FOUND, device);
2769
        return;
2770
    }
2771

  
2772
    if (qemu_is_chr(chr, "memory")) {
2773
        error_setg(errp,"%s is not memory char device", device);
2774
        return;
2775
    }
2776

  
2777
    write_count = (gsize)size;
2778

  
2779
    if (has_format && (format == DATA_FORMAT_BASE64)) {
2780
        write_data = g_base64_decode(data, &write_count);
2781
    } else {
2782
        write_data = (uint8_t *)data;
2783
    }
2784

  
2785
    ret = cirmem_chr_write(chr, write_data, write_count);
2786

  
2787
    if (ret < 0) {
2788
        error_setg(errp, "Failed to write to device %s", device);
2789
        return;
2790
    }
2791
}
2792

  
2751 2793
QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename)
2752 2794
{
2753 2795
    char host[65], port[33], width[8], height[8];
b/qmp-commands.hx
466 466
EQMP
467 467

  
468 468
    {
469
        .name       = "memchar-write",
470
        .args_type  = "device:s,size:i,data:s,format:s?",
471
        .mhandler.cmd_new = qmp_marshal_input_memchar_write,
472
    },
473

  
474
SQMP
475
memchar-write
476
-------------
477

  
478
Provide writing interface for CirMemCharDriver. Write data to memory
479
char device.
480

  
481
Arguments:
482

  
483
- "device": the name of the char device, must be unique (json-string)
484
- "size": the memory size, in bytes, should be power of 2 (json-int)
485
- "data": the source data write to memory (json-string)
486
- "format": the data format write to memory, default is
487
            utf8. (json-string, optional)
488
          - Possible values: "utf8", "base64"
489

  
490
Example:
491

  
492
-> { "execute": "memchar-write",
493
                "arguments": { "device": foo,
494
                               "size": 8,
495
                               "data": "abcdefgh",
496
                               "format": "utf8" } }
497
<- { "return": {} }
498

  
499
EQMP
500

  
501
    {
469 502
        .name       = "xen-save-devices-state",
470 503
        .args_type  = "filename:F",
471 504
    .mhandler.cmd_new = qmp_marshal_input_xen_save_devices_state,

Also available in: Unified diff