static void detach(sPAPRDRConnector *drc, DeviceState *d,

                   spapr_drc_detach_cb *detach_cb,

                   void *detach_cb_opaque, Error **errp)

{

    trace_spapr_drc_detach(get_index(drc));



    drc->detach_cb = detach_cb;

    drc->detach_cb_opaque = detach_cb_opaque;



    /* if we've signalled device presence to the guest, or if the guest

     * has gone ahead and configured the device (via manually-executed

     * device add via drmgr in guest, namely), we need to wait

     * for the guest to quiesce the device before completing detach.

     * Otherwise, we can assume the guest hasn't seen it and complete the

     * detach immediately. Note that there is a small race window

     * just before, or during, configuration, which is this context

     * refers mainly to fetching the device tree via RTAS.

     * During this window the device access will be arbitrated by

     * associated DRC, which will simply fail the RTAS calls as invalid.

     * This is recoverable within guest and current implementations of

     * drmgr should be able to cope.

     */

    if (!drc->signalled && !drc->configured) {

        /* if the guest hasn't seen the device we can't rely on it to

         * set it back to an isolated state via RTAS, so do it here manually

         */

        drc->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED;

    }



    if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {

        trace_spapr_drc_awaiting_isolated(get_index(drc));

        drc->awaiting_release = true;

        return;

    }



    if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&

        drc->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {

        trace_spapr_drc_awaiting_unusable(get_index(drc));

        drc->awaiting_release = true;

        return;

    }



    if (drc->awaiting_allocation) {

        if (!drc->awaiting_allocation_skippable) {

            drc->awaiting_release = true;

            trace_spapr_drc_awaiting_allocation(get_index(drc));

            return;

        }

    }



    drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;



    if (drc->detach_cb) {

        drc->detach_cb(drc->dev, drc->detach_cb_opaque);

    }



    drc->awaiting_release = false;

    drc->awaiting_allocation_skippable = false;

    g_free(drc->fdt);

    drc->fdt = NULL;

    drc->fdt_start_offset = 0;

    object_property_del(OBJECT(drc), "device", NULL);

    drc->dev = NULL;

    drc->detach_cb = NULL;

    drc->detach_cb_opaque = NULL;

}

static void detach(sPAPRDRConnector *drc, DeviceState *d,

                   spapr_drc_detach_cb *detach_cb,

                   void *detach_cb_opaque, Error **errp)

{

    trace_spapr_drc_detach(get_index(drc));



    drc->detach_cb = detach_cb;

    drc->detach_cb_opaque = detach_cb_opaque;



    

























    if (!drc->signalled && !drc->configured) {

        





        drc->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED;

    }



    if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {

        trace_spapr_drc_awaiting_isolated(get_index(drc));

        drc->awaiting_release = true;

        return;

    }



    if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&

        drc->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {

        trace_spapr_drc_awaiting_unusable(get_index(drc));

        drc->awaiting_release = true;

        return;

    }



    if (drc->awaiting_allocation) {

        if (!drc->awaiting_allocation_skippable) {

            drc->awaiting_release = true;

            trace_spapr_drc_awaiting_allocation(get_index(drc));

            return;

        }

    }



    drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;



    if (drc->detach_cb) {

        drc->detach_cb(drc->dev, drc->detach_cb_opaque);

    }



    drc->awaiting_release = false;

    drc->awaiting_allocation_skippable = false;

    g_free(drc->fdt);

    drc->fdt = NULL;

    drc->fdt_start_offset = 0;

    object_property_del(OBJECT(drc), "device", NULL);

    drc->dev = NULL;

    drc->detach_cb = NULL;

    drc->detach_cb_opaque = NULL;

}

static void FUNC_0(sPAPRDRConnector *VAR_0, DeviceState *VAR_1,

                   spapr_drc_detach_cb *VAR_2,

                   void *VAR_3, Error **VAR_4)

{

    trace_spapr_drc_detach(get_index(VAR_0));



    VAR_0->VAR_2 = VAR_2;

    VAR_0->VAR_3 = VAR_3;



    

























    if (!VAR_0->signalled && !VAR_0->configured) {

        





        VAR_0->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED;

    }



    if (VAR_0->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {

        trace_spapr_drc_awaiting_isolated(get_index(VAR_0));

        VAR_0->awaiting_release = true;

        return;

    }



    if (VAR_0->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&

        VAR_0->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {

        trace_spapr_drc_awaiting_unusable(get_index(VAR_0));

        VAR_0->awaiting_release = true;

        return;

    }



    if (VAR_0->awaiting_allocation) {

        if (!VAR_0->awaiting_allocation_skippable) {

            VAR_0->awaiting_release = true;

            trace_spapr_drc_awaiting_allocation(get_index(VAR_0));

            return;

        }

    }



    VAR_0->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;



    if (VAR_0->VAR_2) {

        VAR_0->VAR_2(VAR_0->dev, VAR_0->VAR_3);

    }



    VAR_0->awaiting_release = false;

    VAR_0->awaiting_allocation_skippable = false;

    g_free(VAR_0->fdt);

    VAR_0->fdt = NULL;

    VAR_0->fdt_start_offset = 0;

    object_property_del(OBJECT(VAR_0), "device", NULL);

    VAR_0->dev = NULL;

    VAR_0->VAR_2 = NULL;

    VAR_0->VAR_3 = NULL;

}

static void FUNC_0(sPAPRDRConnector *VAR_0, DeviceState *VAR_1,
spapr_drc_detach_cb *VAR_2,
void *VAR_3, Error **VAR_4)
{ trace_spapr_drc_detach(get_index(VAR_0)); VAR_0->VAR_2 = VAR_2; VAR_0->VAR_3 = VAR_3; if (!VAR_0->signalled && !VAR_0->configured) { VAR_0->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED; } if (VAR_0->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) { trace_spapr_drc_awaiting_isolated(get_index(VAR_0)); VAR_0->awaiting_release = true; return; } if (VAR_0->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&
VAR_0->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) { trace_spapr_drc_awaiting_unusable(get_index(VAR_0)); VAR_0->awaiting_release = true; return; } if (VAR_0->awaiting_allocation) { if (!VAR_0->awaiting_allocation_skippable) { VAR_0->awaiting_release = true; trace_spapr_drc_awaiting_allocation(get_index(VAR_0)); return; } } VAR_0->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE; if (VAR_0->VAR_2) { VAR_0->VAR_2(VAR_0->dev, VAR_0->VAR_3); } VAR_0->awaiting_release = false; VAR_0->awaiting_allocation_skippable = false; g_free(VAR_0->fdt); VAR_0->fdt = NULL; VAR_0->fdt_start_offset = 0; object_property_del(OBJECT(VAR_0), "device", NULL); VAR_0->dev = NULL; VAR_0->VAR_2 = NULL; VAR_0->VAR_3 = NULL; }