/* AUTOMATICALLY GENERATED by qapi-gen.py DO NOT MODIFY */

/*
 * Schema-defined QAPI/QMP commands
 *
 * Copyright IBM, Corp. 2011
 * Copyright (C) 2014-2018 Red Hat, Inc.
 *
 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
 * See the COPYING.LIB file in the top-level directory.
 */

#include "qemu/osdep.h"
#include "qapi/compat-policy.h"
#include "qapi/visitor.h"
#include "qobject/qdict.h"
#include "qapi/dealloc-visitor.h"
#include "qapi/error.h"
#include "qapi-visit-cxl.h"
#include "qapi-commands-cxl.h"
#include "qobject/qjson.h"
#include "trace/trace-qapi_commands_cxl_trace_events.h"

void qmp_marshal_cxl_inject_general_media_event(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_general_media_event_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_general_media_event_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_GENERAL_MEDIA_EVENT)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_general_media_event(req_json->str);
    }

    qmp_cxl_inject_general_media_event(arg.path, arg.log, arg.flags, arg.dpa, arg.descriptor, arg.type, arg.transaction_type, arg.has_channel, arg.channel, arg.has_rank, arg.rank, arg.has_device, arg.device, arg.component_id, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_general_media_event(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_general_media_event("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_general_media_event_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_inject_dram_event(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_dram_event_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_dram_event_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_DRAM_EVENT)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_dram_event(req_json->str);
    }

    qmp_cxl_inject_dram_event(arg.path, arg.log, arg.flags, arg.dpa, arg.descriptor, arg.type, arg.transaction_type, arg.has_channel, arg.channel, arg.has_rank, arg.rank, arg.has_nibble_mask, arg.nibble_mask, arg.has_bank_group, arg.bank_group, arg.has_bank, arg.bank, arg.has_row, arg.row, arg.has_column, arg.column, arg.has_correction_mask, arg.correction_mask, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_dram_event(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_dram_event("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_dram_event_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_inject_memory_module_event(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_memory_module_event_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_memory_module_event_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_MEMORY_MODULE_EVENT)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_memory_module_event(req_json->str);
    }

    qmp_cxl_inject_memory_module_event(arg.path, arg.log, arg.flags, arg.type, arg.health_status, arg.media_status, arg.additional_status, arg.life_used, arg.temperature, arg.dirty_shutdown_count, arg.corrected_volatile_error_count, arg.corrected_persistent_error_count, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_memory_module_event(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_memory_module_event("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_memory_module_event_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_inject_poison(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_poison_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_poison_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_POISON)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_poison(req_json->str);
    }

    qmp_cxl_inject_poison(arg.path, arg.start, arg.length, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_poison(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_poison("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_poison_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_inject_uncorrectable_errors(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_uncorrectable_errors_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_uncorrectable_errors_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_UNCORRECTABLE_ERRORS)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_uncorrectable_errors(req_json->str);
    }

    qmp_cxl_inject_uncorrectable_errors(arg.path, arg.errors, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_uncorrectable_errors(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_uncorrectable_errors("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_uncorrectable_errors_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_inject_correctable_error(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_inject_correctable_error_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_inject_correctable_error_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_INJECT_CORRECTABLE_ERROR)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_inject_correctable_error(req_json->str);
    }

    qmp_cxl_inject_correctable_error(arg.path, arg.type, &err);
    if (err) {
        trace_qmp_exit_cxl_inject_correctable_error(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_inject_correctable_error("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_inject_correctable_error_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_add_dynamic_capacity(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_add_dynamic_capacity_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_add_dynamic_capacity_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_ADD_DYNAMIC_CAPACITY)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_add_dynamic_capacity(req_json->str);
    }

    qmp_cxl_add_dynamic_capacity(arg.path, arg.host_id, arg.selection_policy, arg.region, arg.tag, arg.extents, &err);
    if (err) {
        trace_qmp_exit_cxl_add_dynamic_capacity(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_add_dynamic_capacity("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_add_dynamic_capacity_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

void qmp_marshal_cxl_release_dynamic_capacity(QDict *args, QObject **ret, Error **errp)
{
    Error *err = NULL;
    bool ok = false;
    Visitor *v;
    q_obj_cxl_release_dynamic_capacity_arg arg = {0};

    v = qobject_input_visitor_new_qmp(QOBJECT(args));
    if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
        goto out;
    }
    if (visit_type_q_obj_cxl_release_dynamic_capacity_arg_members(v, &arg, errp)) {
        ok = visit_check_struct(v, errp);
    }
    visit_end_struct(v, NULL);
    if (!ok) {
        goto out;
    }

    if (trace_event_get_state_backends(TRACE_QMP_ENTER_CXL_RELEASE_DYNAMIC_CAPACITY)) {
        g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));

        trace_qmp_enter_cxl_release_dynamic_capacity(req_json->str);
    }

    qmp_cxl_release_dynamic_capacity(arg.path, arg.host_id, arg.removal_policy, arg.has_forced_removal, arg.forced_removal, arg.has_sanitize_on_release, arg.sanitize_on_release, arg.region, arg.tag, arg.extents, &err);
    if (err) {
        trace_qmp_exit_cxl_release_dynamic_capacity(error_get_pretty(err), false);
        error_propagate(errp, err);
        goto out;
    }

    trace_qmp_exit_cxl_release_dynamic_capacity("{}", true);

out:
    visit_free(v);
    v = qapi_dealloc_visitor_new();
    visit_start_struct(v, NULL, NULL, 0, NULL);
    visit_type_q_obj_cxl_release_dynamic_capacity_arg_members(v, &arg, NULL);
    visit_end_struct(v, NULL);
    visit_free(v);
}

/* Dummy declaration to prevent empty .o file */
char qapi_dummy_qapi_commands_cxl_c;
