static void ehci_frame_timer(void *opaque)

{

    EHCIState *ehci = opaque;

    int schedules = 0;

    int64_t expire_time, t_now;

    uint64_t ns_elapsed;

    int frames;

    int i;

    int skipped_frames = 0;



    t_now = qemu_get_clock_ns(vm_clock);

    ns_elapsed = t_now - ehci->last_run_ns;

    frames = ns_elapsed / FRAME_TIMER_NS;



    if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) {

        schedules++;

        expire_time = t_now + (get_ticks_per_sec() / FRAME_TIMER_FREQ);



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

            ehci_update_frindex(ehci, 1);



            if (frames - i > ehci->maxframes) {

                skipped_frames++;

            } else {

                ehci_advance_periodic_state(ehci);

            }



            ehci->last_run_ns += FRAME_TIMER_NS;

        }

    } else {

        if (ehci->async_stepdown < ehci->maxframes / 2) {

            ehci->async_stepdown++;

        }

        expire_time = t_now + (get_ticks_per_sec()

                               * ehci->async_stepdown / FRAME_TIMER_FREQ);

        ehci_update_frindex(ehci, frames);

        ehci->last_run_ns += FRAME_TIMER_NS * frames;

    }



#if 0

    if (skipped_frames) {

        DPRINTF("WARNING - EHCI skipped %d frames\n", skipped_frames);

    }

#endif



    /*  Async is not inside loop since it executes everything it can once

     *  called

     */

    if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) {

        schedules++;

        qemu_bh_schedule(ehci->async_bh);

    }



    if (schedules) {

        qemu_mod_timer(ehci->frame_timer, expire_time);

    }

}

static void ehci_frame_timer(void *opaque)

{

    EHCIState *ehci = opaque;

    int schedules = 0;

    int64_t expire_time, t_now;

    uint64_t ns_elapsed;

    int frames;

    int i;

    int skipped_frames = 0;



    t_now = qemu_get_clock_ns(vm_clock);

    ns_elapsed = t_now - ehci->last_run_ns;

    frames = ns_elapsed / FRAME_TIMER_NS;



    if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) {

        schedules++;

        expire_time = t_now + (get_ticks_per_sec() / FRAME_TIMER_FREQ);



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

            ehci_update_frindex(ehci, 1);



            if (frames - i > ehci->maxframes) {

                skipped_frames++;

            } else {

                ehci_advance_periodic_state(ehci);

            }



            ehci->last_run_ns += FRAME_TIMER_NS;

        }

    } else {

        if (ehci->async_stepdown < ehci->maxframes / 2) {

            ehci->async_stepdown++;

        }

        expire_time = t_now + (get_ticks_per_sec()

                               * ehci->async_stepdown / FRAME_TIMER_FREQ);

        ehci_update_frindex(ehci, frames);

        ehci->last_run_ns += FRAME_TIMER_NS * frames;

    }



#if 0

    if (skipped_frames) {

        DPRINTF("WARNING - EHCI skipped %d frames\n", skipped_frames);

    }

#endif



    





    if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) {

        schedules++;

        qemu_bh_schedule(ehci->async_bh);

    }



    if (schedules) {

        qemu_mod_timer(ehci->frame_timer, expire_time);

    }

}

static void FUNC_0(void *VAR_0)

{

    EHCIState *ehci = VAR_0;

    int VAR_1 = 0;

    int64_t expire_time, t_now;

    uint64_t ns_elapsed;

    int VAR_2;

    int VAR_3;

    int VAR_4 = 0;



    t_now = qemu_get_clock_ns(vm_clock);

    ns_elapsed = t_now - ehci->last_run_ns;

    VAR_2 = ns_elapsed / FRAME_TIMER_NS;



    if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) {

        VAR_1++;

        expire_time = t_now + (get_ticks_per_sec() / FRAME_TIMER_FREQ);



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

            ehci_update_frindex(ehci, 1);



            if (VAR_2 - VAR_3 > ehci->maxframes) {

                VAR_4++;

            } else {

                ehci_advance_periodic_state(ehci);

            }



            ehci->last_run_ns += FRAME_TIMER_NS;

        }

    } else {

        if (ehci->async_stepdown < ehci->maxframes / 2) {

            ehci->async_stepdown++;

        }

        expire_time = t_now + (get_ticks_per_sec()

                               * ehci->async_stepdown / FRAME_TIMER_FREQ);

        ehci_update_frindex(ehci, VAR_2);

        ehci->last_run_ns += FRAME_TIMER_NS * VAR_2;

    }



#if 0

    if (VAR_4) {

        DPRINTF("WARNING - EHCI skipped %d VAR_2\n", VAR_4);

    }

#endif



    





    if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) {

        VAR_1++;

        qemu_bh_schedule(ehci->async_bh);

    }



    if (VAR_1) {

        qemu_mod_timer(ehci->frame_timer, expire_time);

    }

}

static void FUNC_0(void *VAR_0)
{ EHCIState *ehci = VAR_0; int VAR_1 = 0; int64_t expire_time, t_now; uint64_t ns_elapsed; int VAR_2; int VAR_3; int VAR_4 = 0; t_now = qemu_get_clock_ns(vm_clock); ns_elapsed = t_now - ehci->last_run_ns; VAR_2 = ns_elapsed / FRAME_TIMER_NS; if (ehci_periodic_enabled(ehci) || ehci->pstate != EST_INACTIVE) { VAR_1++; expire_time = t_now + (get_ticks_per_sec() / FRAME_TIMER_FREQ); for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { ehci_update_frindex(ehci, 1); if (VAR_2 - VAR_3 > ehci->maxframes) { VAR_4++; } else { ehci_advance_periodic_state(ehci); } ehci->last_run_ns += FRAME_TIMER_NS; } } else { if (ehci->async_stepdown < ehci->maxframes / 2) { ehci->async_stepdown++; } expire_time = t_now + (get_ticks_per_sec()
* ehci->async_stepdown / FRAME_TIMER_FREQ); ehci_update_frindex(ehci, VAR_2); ehci->last_run_ns += FRAME_TIMER_NS * VAR_2; } #if 0
if (VAR_4) { DPRINTF("WARNING - EHCI skipped %d VAR_2\n", VAR_4); } #endif
if (ehci_async_enabled(ehci) || ehci->astate != EST_INACTIVE) { VAR_1++; qemu_bh_schedule(ehci->async_bh); } if (VAR_1) { qemu_mod_timer(ehci->frame_timer, expire_time); } }