static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,

                                      unsigned int size)

{

    MemHotplugState *mem_st = opaque;

    MemStatus *mdev;

    ACPIOSTInfo *info;

    DeviceState *dev = NULL;

    HotplugHandler *hotplug_ctrl = NULL;

    Error *local_err = NULL;



    if (!mem_st->dev_count) {

        return;

    }



    if (addr) {

        if (mem_st->selector >= mem_st->dev_count) {

            trace_mhp_acpi_invalid_slot_selected(mem_st->selector);

            return;

        }

    }



    switch (addr) {

    case 0x0: /* DIMM slot selector */

        mem_st->selector = data;

        trace_mhp_acpi_write_slot(mem_st->selector);

        break;

    case 0x4: /* _OST event  */

        mdev = &mem_st->devs[mem_st->selector];

        if (data == 1) {

            /* TODO: handle device insert OST event */

        } else if (data == 3) {

            /* TODO: handle device remove OST event */

        }

        mdev->ost_event = data;

        trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event);

        break;

    case 0x8: /* _OST status */

        mdev = &mem_st->devs[mem_st->selector];

        mdev->ost_status = data;

        trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status);

        /* TODO: implement memory removal on guest signal */



        info = acpi_memory_device_status(mem_st->selector, mdev);

        qapi_event_send_acpi_device_ost(info, &error_abort);

        qapi_free_ACPIOSTInfo(info);

        break;

    case 0x14: /* set is_* fields  */

        mdev = &mem_st->devs[mem_st->selector];

        if (data & 2) { /* clear insert event */

            mdev->is_inserting  = false;

            trace_mhp_acpi_clear_insert_evt(mem_st->selector);

        } else if (data & 4) {

            mdev->is_removing = false;

            trace_mhp_acpi_clear_remove_evt(mem_st->selector);

        } else if (data & 8) {

            if (!mdev->is_enabled) {

                trace_mhp_acpi_ejecting_invalid_slot(mem_st->selector);

                break;

            }



            dev = DEVICE(mdev->dimm);

            hotplug_ctrl = qdev_get_hotplug_handler(dev);

            /* call pc-dimm unplug cb */

            hotplug_handler_unplug(hotplug_ctrl, dev, &local_err);

            if (local_err) {

                trace_mhp_acpi_pc_dimm_delete_failed(mem_st->selector);

                qapi_event_send_mem_unplug_error(dev->id,

                                                 error_get_pretty(local_err),

                                                 &error_abort);


                break;

            }

            trace_mhp_acpi_pc_dimm_deleted(mem_st->selector);

        }

        break;

    default:

        break;

    }



}
static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data,

                                      unsigned int size)

{

    MemHotplugState *mem_st = opaque;

    MemStatus *mdev;

    ACPIOSTInfo *info;

    DeviceState *dev = NULL;

    HotplugHandler *hotplug_ctrl = NULL;

    Error *local_err = NULL;



    if (!mem_st->dev_count) {

        return;

    }



    if (addr) {

        if (mem_st->selector >= mem_st->dev_count) {

            trace_mhp_acpi_invalid_slot_selected(mem_st->selector);

            return;

        }

    }



    switch (addr) {

    case 0x0: 

        mem_st->selector = data;

        trace_mhp_acpi_write_slot(mem_st->selector);

        break;

    case 0x4: 

        mdev = &mem_st->devs[mem_st->selector];

        if (data == 1) {

            

        } else if (data == 3) {

            

        }

        mdev->ost_event = data;

        trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event);

        break;

    case 0x8: 

        mdev = &mem_st->devs[mem_st->selector];

        mdev->ost_status = data;

        trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status);

        



        info = acpi_memory_device_status(mem_st->selector, mdev);

        qapi_event_send_acpi_device_ost(info, &error_abort);

        qapi_free_ACPIOSTInfo(info);

        break;

    case 0x14: 

        mdev = &mem_st->devs[mem_st->selector];

        if (data & 2) { 

            mdev->is_inserting  = false;

            trace_mhp_acpi_clear_insert_evt(mem_st->selector);

        } else if (data & 4) {

            mdev->is_removing = false;

            trace_mhp_acpi_clear_remove_evt(mem_st->selector);

        } else if (data & 8) {

            if (!mdev->is_enabled) {

                trace_mhp_acpi_ejecting_invalid_slot(mem_st->selector);

                break;

            }



            dev = DEVICE(mdev->dimm);

            hotplug_ctrl = qdev_get_hotplug_handler(dev);

            

            hotplug_handler_unplug(hotplug_ctrl, dev, &local_err);

            if (local_err) {

                trace_mhp_acpi_pc_dimm_delete_failed(mem_st->selector);

                qapi_event_send_mem_unplug_error(dev->id,

                                                 error_get_pretty(local_err),

                                                 &error_abort);


                break;

            }

            trace_mhp_acpi_pc_dimm_deleted(mem_st->selector);

        }

        break;

    default:

        break;

    }



}
static void FUNC_0(void *VAR_0, hwaddr VAR_1, uint64_t VAR_2,

                                      unsigned int VAR_3)

{

    MemHotplugState *mem_st = VAR_0;

    MemStatus *mdev;

    ACPIOSTInfo *info;

    DeviceState *dev = NULL;

    HotplugHandler *hotplug_ctrl = NULL;

    Error *local_err = NULL;



    if (!mem_st->dev_count) {

        return;

    }



    if (VAR_1) {

        if (mem_st->selector >= mem_st->dev_count) {

            trace_mhp_acpi_invalid_slot_selected(mem_st->selector);

            return;

        }

    }



    switch (VAR_1) {

    case 0x0: 

        mem_st->selector = VAR_2;

        trace_mhp_acpi_write_slot(mem_st->selector);

        break;

    case 0x4: 

        mdev = &mem_st->devs[mem_st->selector];

        if (VAR_2 == 1) {

            

        } else if (VAR_2 == 3) {

            

        }

        mdev->ost_event = VAR_2;

        trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event);

        break;

    case 0x8: 

        mdev = &mem_st->devs[mem_st->selector];

        mdev->ost_status = VAR_2;

        trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status);

        



        info = acpi_memory_device_status(mem_st->selector, mdev);

        qapi_event_send_acpi_device_ost(info, &error_abort);

        qapi_free_ACPIOSTInfo(info);

        break;

    case 0x14: 

        mdev = &mem_st->devs[mem_st->selector];

        if (VAR_2 & 2) { 

            mdev->is_inserting  = false;

            trace_mhp_acpi_clear_insert_evt(mem_st->selector);

        } else if (VAR_2 & 4) {

            mdev->is_removing = false;

            trace_mhp_acpi_clear_remove_evt(mem_st->selector);

        } else if (VAR_2 & 8) {

            if (!mdev->is_enabled) {

                trace_mhp_acpi_ejecting_invalid_slot(mem_st->selector);

                break;

            }



            dev = DEVICE(mdev->dimm);

            hotplug_ctrl = qdev_get_hotplug_handler(dev);

            

            hotplug_handler_unplug(hotplug_ctrl, dev, &local_err);

            if (local_err) {

                trace_mhp_acpi_pc_dimm_delete_failed(mem_st->selector);

                qapi_event_send_mem_unplug_error(dev->id,

                                                 error_get_pretty(local_err),

                                                 &error_abort);


                break;

            }

            trace_mhp_acpi_pc_dimm_deleted(mem_st->selector);

        }

        break;

    default:

        break;

    }



}
static void FUNC_0(void *VAR_0, hwaddr VAR_1, uint64_t VAR_2,
unsigned int VAR_3)
{ MemHotplugState *mem_st = VAR_0; MemStatus *mdev; ACPIOSTInfo *info; DeviceState *dev = NULL; HotplugHandler *hotplug_ctrl = NULL; Error *local_err = NULL; if (!mem_st->dev_count) { return; } if (VAR_1) { if (mem_st->selector >= mem_st->dev_count) { trace_mhp_acpi_invalid_slot_selected(mem_st->selector); return; } } switch (VAR_1) { case 0x0:
mem_st->selector = VAR_2; trace_mhp_acpi_write_slot(mem_st->selector); break; case 0x4:
mdev = &mem_st->devs[mem_st->selector]; if (VAR_2 == 1) { } else if (VAR_2 == 3) { } mdev->ost_event = VAR_2; trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event); break; case 0x8:
mdev = &mem_st->devs[mem_st->selector]; mdev->ost_status = VAR_2; trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status); info = acpi_memory_device_status(mem_st->selector, mdev); qapi_event_send_acpi_device_ost(info, &error_abort); qapi_free_ACPIOSTInfo(info); break; case 0x14:
mdev = &mem_st->devs[mem_st->selector]; if (VAR_2 & 2) { mdev->is_inserting  = false; trace_mhp_acpi_clear_insert_evt(mem_st->selector); } else if (VAR_2 & 4) { mdev->is_removing = false; trace_mhp_acpi_clear_remove_evt(mem_st->selector); } else if (VAR_2 & 8) { if (!mdev->is_enabled) { trace_mhp_acpi_ejecting_invalid_slot(mem_st->selector); break; } dev = DEVICE(mdev->dimm); hotplug_ctrl = qdev_get_hotplug_handler(dev); hotplug_handler_unplug(hotplug_ctrl, dev, &local_err); if (local_err) { trace_mhp_acpi_pc_dimm_delete_failed(mem_st->selector); qapi_event_send_mem_unplug_error(dev->id,
error_get_pretty(local_err),
&error_abort); break; } trace_mhp_acpi_pc_dimm_deleted(mem_st->selector); } break; default:
break; } }