static void grlib_gptimer_write(void *opaque, target_phys_addr_t addr,

                                uint64_t value, unsigned size)

{

    GPTimerUnit        *unit = opaque;

    target_phys_addr_t  timer_addr;

    int                 id;



    addr &= 0xff;



    /* Unit registers */

    switch (addr) {

    case SCALER_OFFSET:

        value &= 0xFFFF; /* clean up the value */

        unit->scaler = value;

        trace_grlib_gptimer_writel(-1, addr, unit->scaler);

        return;



    case SCALER_RELOAD_OFFSET:

        value &= 0xFFFF; /* clean up the value */

        unit->reload = value;

        trace_grlib_gptimer_writel(-1, addr, unit->reload);

        grlib_gptimer_set_scaler(unit, value);

        return;



    case CONFIG_OFFSET:

        /* Read Only (disable timer freeze not supported) */

        trace_grlib_gptimer_writel(-1, addr, 0);

        return;



    default:

        break;

    }



    timer_addr = (addr % TIMER_BASE);

    id         = (addr - TIMER_BASE) / TIMER_BASE;



    if (id >= 0 && id < unit->nr_timers) {



        /* GPTimer registers */

        switch (timer_addr) {

        case COUNTER_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);

            unit->timers[id].counter = value;

            grlib_gptimer_enable(&unit->timers[id]);

            return;



        case COUNTER_RELOAD_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);

            unit->timers[id].reload = value;

            return;



        case CONFIG_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);



            if (value & GPTIMER_INT_PENDING) {

                /* clear pending bit */

                value &= ~GPTIMER_INT_PENDING;

            } else {

                /* keep pending bit */

                value |= unit->timers[id].config & GPTIMER_INT_PENDING;

            }



            unit->timers[id].config = value;



            /* gptimer_restart calls gptimer_enable, so if "enable" and "load"

               bits are present, we just have to call restart. */



            if (value & GPTIMER_LOAD) {

                grlib_gptimer_restart(&unit->timers[id]);

            } else if (value & GPTIMER_ENABLE) {

                grlib_gptimer_enable(&unit->timers[id]);

            }



            /* These fields must always be read as 0 */

            value &= ~(GPTIMER_LOAD & GPTIMER_DEBUG_HALT);



            unit->timers[id].config = value;

            return;



        default:

            break;

        }



    }



    trace_grlib_gptimer_writel(-1, addr, value);

}

static void grlib_gptimer_write(void *opaque, target_phys_addr_t addr,

                                uint64_t value, unsigned size)

{

    GPTimerUnit        *unit = opaque;

    target_phys_addr_t  timer_addr;

    int                 id;



    addr &= 0xff;



    

    switch (addr) {

    case SCALER_OFFSET:

        value &= 0xFFFF; 

        unit->scaler = value;

        trace_grlib_gptimer_writel(-1, addr, unit->scaler);

        return;



    case SCALER_RELOAD_OFFSET:

        value &= 0xFFFF; 

        unit->reload = value;

        trace_grlib_gptimer_writel(-1, addr, unit->reload);

        grlib_gptimer_set_scaler(unit, value);

        return;



    case CONFIG_OFFSET:

        

        trace_grlib_gptimer_writel(-1, addr, 0);

        return;



    default:

        break;

    }



    timer_addr = (addr % TIMER_BASE);

    id         = (addr - TIMER_BASE) / TIMER_BASE;



    if (id >= 0 && id < unit->nr_timers) {



        

        switch (timer_addr) {

        case COUNTER_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);

            unit->timers[id].counter = value;

            grlib_gptimer_enable(&unit->timers[id]);

            return;



        case COUNTER_RELOAD_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);

            unit->timers[id].reload = value;

            return;



        case CONFIG_OFFSET:

            trace_grlib_gptimer_writel(id, addr, value);



            if (value & GPTIMER_INT_PENDING) {

                

                value &= ~GPTIMER_INT_PENDING;

            } else {

                

                value |= unit->timers[id].config & GPTIMER_INT_PENDING;

            }



            unit->timers[id].config = value;



            





            if (value & GPTIMER_LOAD) {

                grlib_gptimer_restart(&unit->timers[id]);

            } else if (value & GPTIMER_ENABLE) {

                grlib_gptimer_enable(&unit->timers[id]);

            }



            

            value &= ~(GPTIMER_LOAD & GPTIMER_DEBUG_HALT);



            unit->timers[id].config = value;

            return;



        default:

            break;

        }



    }



    trace_grlib_gptimer_writel(-1, addr, value);

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,

                                uint64_t VAR_2, unsigned VAR_3)

{

    GPTimerUnit        *unit = VAR_0;

    target_phys_addr_t  timer_addr;

    int                 VAR_4;



    VAR_1 &= 0xff;



    

    switch (VAR_1) {

    case SCALER_OFFSET:

        VAR_2 &= 0xFFFF; 

        unit->scaler = VAR_2;

        trace_grlib_gptimer_writel(-1, VAR_1, unit->scaler);

        return;



    case SCALER_RELOAD_OFFSET:

        VAR_2 &= 0xFFFF; 

        unit->reload = VAR_2;

        trace_grlib_gptimer_writel(-1, VAR_1, unit->reload);

        grlib_gptimer_set_scaler(unit, VAR_2);

        return;



    case CONFIG_OFFSET:

        

        trace_grlib_gptimer_writel(-1, VAR_1, 0);

        return;



    default:

        break;

    }



    timer_addr = (VAR_1 % TIMER_BASE);

    VAR_4         = (VAR_1 - TIMER_BASE) / TIMER_BASE;



    if (VAR_4 >= 0 && VAR_4 < unit->nr_timers) {



        

        switch (timer_addr) {

        case COUNTER_OFFSET:

            trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2);

            unit->timers[VAR_4].counter = VAR_2;

            grlib_gptimer_enable(&unit->timers[VAR_4]);

            return;



        case COUNTER_RELOAD_OFFSET:

            trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2);

            unit->timers[VAR_4].reload = VAR_2;

            return;



        case CONFIG_OFFSET:

            trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2);



            if (VAR_2 & GPTIMER_INT_PENDING) {

                

                VAR_2 &= ~GPTIMER_INT_PENDING;

            } else {

                

                VAR_2 |= unit->timers[VAR_4].config & GPTIMER_INT_PENDING;

            }



            unit->timers[VAR_4].config = VAR_2;



            





            if (VAR_2 & GPTIMER_LOAD) {

                grlib_gptimer_restart(&unit->timers[VAR_4]);

            } else if (VAR_2 & GPTIMER_ENABLE) {

                grlib_gptimer_enable(&unit->timers[VAR_4]);

            }



            

            VAR_2 &= ~(GPTIMER_LOAD & GPTIMER_DEBUG_HALT);



            unit->timers[VAR_4].config = VAR_2;

            return;



        default:

            break;

        }



    }



    trace_grlib_gptimer_writel(-1, VAR_1, VAR_2);

}

static void FUNC_0(void *VAR_0, target_phys_addr_t VAR_1,
uint64_t VAR_2, unsigned VAR_3)
{ GPTimerUnit        *unit = VAR_0; target_phys_addr_t  timer_addr; int                 VAR_4; VAR_1 &= 0xff; switch (VAR_1) { case SCALER_OFFSET:
VAR_2 &= 0xFFFF; unit->scaler = VAR_2; trace_grlib_gptimer_writel(-1, VAR_1, unit->scaler); return; case SCALER_RELOAD_OFFSET:
VAR_2 &= 0xFFFF; unit->reload = VAR_2; trace_grlib_gptimer_writel(-1, VAR_1, unit->reload); grlib_gptimer_set_scaler(unit, VAR_2); return; case CONFIG_OFFSET:
trace_grlib_gptimer_writel(-1, VAR_1, 0); return; default:
break; } timer_addr = (VAR_1 % TIMER_BASE); VAR_4         = (VAR_1 - TIMER_BASE) / TIMER_BASE; if (VAR_4 >= 0 && VAR_4 < unit->nr_timers) { switch (timer_addr) { case COUNTER_OFFSET:
trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2); unit->timers[VAR_4].counter = VAR_2; grlib_gptimer_enable(&unit->timers[VAR_4]); return; case COUNTER_RELOAD_OFFSET:
trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2); unit->timers[VAR_4].reload = VAR_2; return; case CONFIG_OFFSET:
trace_grlib_gptimer_writel(VAR_4, VAR_1, VAR_2); if (VAR_2 & GPTIMER_INT_PENDING) { VAR_2 &= ~GPTIMER_INT_PENDING; } else { VAR_2 |= unit->timers[VAR_4].config & GPTIMER_INT_PENDING; } unit->timers[VAR_4].config = VAR_2; if (VAR_2 & GPTIMER_LOAD) { grlib_gptimer_restart(&unit->timers[VAR_4]); } else if (VAR_2 & GPTIMER_ENABLE) { grlib_gptimer_enable(&unit->timers[VAR_4]); } VAR_2 &= ~(GPTIMER_LOAD & GPTIMER_DEBUG_HALT); unit->timers[VAR_4].config = VAR_2; return; default:
break; } } trace_grlib_gptimer_writel(-1, VAR_1, VAR_2); }