static int ehci_state_waitlisthead(EHCIState *ehci,  int async)

{

    EHCIqh qh;

    int i = 0;

    int again = 0;

    uint32_t entry = ehci->asynclistaddr;



    /* set reclamation flag at start event (4.8.6) */

    if (async) {

        ehci_set_usbsts(ehci, USBSTS_REC);

    }



    ehci_queues_rip_unused(ehci, async, 0);



    /*  Find the head of the list (4.9.1.1) */

    for(i = 0; i < MAX_QH; i++) {

        get_dwords(ehci, NLPTR_GET(entry), (uint32_t *) &qh,

                   sizeof(EHCIqh) >> 2);

        ehci_trace_qh(NULL, NLPTR_GET(entry), &qh);



        if (qh.epchar & QH_EPCHAR_H) {

            if (async) {

                entry |= (NLPTR_TYPE_QH << 1);

            }



            ehci_set_fetch_addr(ehci, async, entry);

            ehci_set_state(ehci, async, EST_FETCHENTRY);

            again = 1;

            goto out;

        }



        entry = qh.next;

        if (entry == ehci->asynclistaddr) {

            break;

        }

    }



    /* no head found for list. */



    ehci_set_state(ehci, async, EST_ACTIVE);



out:

    return again;

}

static int ehci_state_waitlisthead(EHCIState *ehci,  int async)

{

    EHCIqh qh;

    int i = 0;

    int again = 0;

    uint32_t entry = ehci->asynclistaddr;



    

    if (async) {

        ehci_set_usbsts(ehci, USBSTS_REC);

    }



    ehci_queues_rip_unused(ehci, async, 0);



    

    for(i = 0; i < MAX_QH; i++) {

        get_dwords(ehci, NLPTR_GET(entry), (uint32_t *) &qh,

                   sizeof(EHCIqh) >> 2);

        ehci_trace_qh(NULL, NLPTR_GET(entry), &qh);



        if (qh.epchar & QH_EPCHAR_H) {

            if (async) {

                entry |= (NLPTR_TYPE_QH << 1);

            }



            ehci_set_fetch_addr(ehci, async, entry);

            ehci_set_state(ehci, async, EST_FETCHENTRY);

            again = 1;

            goto out;

        }



        entry = qh.next;

        if (entry == ehci->asynclistaddr) {

            break;

        }

    }



    



    ehci_set_state(ehci, async, EST_ACTIVE);



out:

    return again;

}

static int FUNC_0(EHCIState *VAR_0,  int VAR_1)

{

    EHCIqh qh;

    int VAR_2 = 0;

    int VAR_3 = 0;

    uint32_t entry = VAR_0->asynclistaddr;



    

    if (VAR_1) {

        ehci_set_usbsts(VAR_0, USBSTS_REC);

    }



    ehci_queues_rip_unused(VAR_0, VAR_1, 0);



    

    for(VAR_2 = 0; VAR_2 < MAX_QH; VAR_2++) {

        get_dwords(VAR_0, NLPTR_GET(entry), (uint32_t *) &qh,

                   sizeof(EHCIqh) >> 2);

        ehci_trace_qh(NULL, NLPTR_GET(entry), &qh);



        if (qh.epchar & QH_EPCHAR_H) {

            if (VAR_1) {

                entry |= (NLPTR_TYPE_QH << 1);

            }



            ehci_set_fetch_addr(VAR_0, VAR_1, entry);

            ehci_set_state(VAR_0, VAR_1, EST_FETCHENTRY);

            VAR_3 = 1;

            goto out;

        }



        entry = qh.next;

        if (entry == VAR_0->asynclistaddr) {

            break;

        }

    }



    



    ehci_set_state(VAR_0, VAR_1, EST_ACTIVE);



out:

    return VAR_3;

}

static int FUNC_0(EHCIState *VAR_0,  int VAR_1)
{ EHCIqh qh; int VAR_2 = 0; int VAR_3 = 0; uint32_t entry = VAR_0->asynclistaddr; if (VAR_1) { ehci_set_usbsts(VAR_0, USBSTS_REC); } ehci_queues_rip_unused(VAR_0, VAR_1, 0); for(VAR_2 = 0; VAR_2 < MAX_QH; VAR_2++) { get_dwords(VAR_0, NLPTR_GET(entry), (uint32_t *) &qh,
sizeof(EHCIqh) >> 2); ehci_trace_qh(NULL, NLPTR_GET(entry), &qh); if (qh.epchar & QH_EPCHAR_H) { if (VAR_1) { entry |= (NLPTR_TYPE_QH << 1); } ehci_set_fetch_addr(VAR_0, VAR_1, entry); ehci_set_state(VAR_0, VAR_1, EST_FETCHENTRY); VAR_3 = 1; goto out; } entry = qh.next; if (entry == VAR_0->asynclistaddr) { break; } } ehci_set_state(VAR_0, VAR_1, EST_ACTIVE); out:
return VAR_3; }