Lines Matching refs:r
48 static void sifive_e_aon_wdt_update_wdogcount(SiFiveEAONState *r) in sifive_e_aon_wdt_update_wdogcount() argument
51 if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS) == 0 && in sifive_e_aon_wdt_update_wdogcount()
52 FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE) == 0) { in sifive_e_aon_wdt_update_wdogcount()
57 r->wdogcount += muldiv64(now - r->wdog_restart_time, in sifive_e_aon_wdt_update_wdogcount()
58 r->wdogclk_freq, NANOSECONDS_PER_SECOND); in sifive_e_aon_wdt_update_wdogcount()
61 r->wdogcount &= R_AON_WDT_WDOGCOUNT_VALUE_MASK; in sifive_e_aon_wdt_update_wdogcount()
62 r->wdog_restart_time = now; in sifive_e_aon_wdt_update_wdogcount()
65 static void sifive_e_aon_wdt_update_state(SiFiveEAONState *r) in sifive_e_aon_wdt_update_state() argument
69 sifive_e_aon_wdt_update_wdogcount(r); in sifive_e_aon_wdt_update_state()
70 wdogs = (uint16_t)(r->wdogcount >> in sifive_e_aon_wdt_update_state()
71 FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, SCALE)); in sifive_e_aon_wdt_update_state()
73 if (wdogs >= r->wdogcmp0) { in sifive_e_aon_wdt_update_state()
75 if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, ZEROCMP) == 1) { in sifive_e_aon_wdt_update_state()
76 r->wdogcount = 0; in sifive_e_aon_wdt_update_state()
82 if (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, RSTEN) == 1) { in sifive_e_aon_wdt_update_state()
85 r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, IP0, 1); in sifive_e_aon_wdt_update_state()
88 qemu_set_irq(r->wdog_irq, FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, IP0)); in sifive_e_aon_wdt_update_state()
90 if (wdogs < r->wdogcmp0 && in sifive_e_aon_wdt_update_state()
91 (FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS) == 1 || in sifive_e_aon_wdt_update_state()
92 FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE) == 1)) { in sifive_e_aon_wdt_update_state()
94 next += muldiv64((r->wdogcmp0 - wdogs) << in sifive_e_aon_wdt_update_state()
95 FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, SCALE), in sifive_e_aon_wdt_update_state()
96 NANOSECONDS_PER_SECOND, r->wdogclk_freq); in sifive_e_aon_wdt_update_state()
97 timer_mod(r->wdog_timer, next); in sifive_e_aon_wdt_update_state()
99 timer_mod(r->wdog_timer, INT64_MAX); in sifive_e_aon_wdt_update_state()
108 SiFiveEAONState *r = SIFIVE_E_AON(opaque); in sifive_e_aon_wdt_expired_cb() local
109 sifive_e_aon_wdt_update_state(r); in sifive_e_aon_wdt_expired_cb()
115 SiFiveEAONState *r = SIFIVE_E_AON(opaque); in sifive_e_aon_wdt_read() local
119 return r->wdogcfg; in sifive_e_aon_wdt_read()
121 sifive_e_aon_wdt_update_wdogcount(r); in sifive_e_aon_wdt_read()
122 return r->wdogcount; in sifive_e_aon_wdt_read()
124 sifive_e_aon_wdt_update_wdogcount(r); in sifive_e_aon_wdt_read()
125 return r->wdogcount >> in sifive_e_aon_wdt_read()
126 FIELD_EX32(r->wdogcfg, in sifive_e_aon_wdt_read()
132 return r->wdogunlock; in sifive_e_aon_wdt_read()
134 return r->wdogcmp0; in sifive_e_aon_wdt_read()
147 SiFiveEAONState *r = SIFIVE_E_AON(opaque); in sifive_e_aon_wdt_write() local
156 if (r->wdogunlock == 0) { in sifive_e_aon_wdt_write()
162 old_en_always = FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS); in sifive_e_aon_wdt_write()
163 old_en_core_awake = FIELD_EX32(r->wdogcfg, AON_WDT_WDOGCFG, in sifive_e_aon_wdt_write()
170 sifive_e_aon_wdt_update_wdogcount(r); in sifive_e_aon_wdt_write()
175 r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in sifive_e_aon_wdt_write()
177 r->wdogcfg = value; in sifive_e_aon_wdt_write()
178 r->wdogunlock = 0; in sifive_e_aon_wdt_write()
182 if (r->wdogunlock == 0) { in sifive_e_aon_wdt_write()
185 r->wdogcount = value & R_AON_WDT_WDOGCOUNT_VALUE_MASK; in sifive_e_aon_wdt_write()
186 r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in sifive_e_aon_wdt_write()
187 r->wdogunlock = 0; in sifive_e_aon_wdt_write()
192 if (r->wdogunlock == 0) { in sifive_e_aon_wdt_write()
196 r->wdogcount = 0; in sifive_e_aon_wdt_write()
197 r->wdog_restart_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); in sifive_e_aon_wdt_write()
199 r->wdogunlock = 0; in sifive_e_aon_wdt_write()
203 r->wdogunlock = 1; in sifive_e_aon_wdt_write()
207 if (r->wdogunlock == 0) { in sifive_e_aon_wdt_write()
210 r->wdogcmp0 = (uint16_t) value; in sifive_e_aon_wdt_write()
211 r->wdogunlock = 0; in sifive_e_aon_wdt_write()
217 sifive_e_aon_wdt_update_state(r); in sifive_e_aon_wdt_write()
266 SiFiveEAONState *r = SIFIVE_E_AON(dev); in sifive_e_aon_reset() local
268 r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, RSTEN, 0); in sifive_e_aon_reset()
269 r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, EN_ALWAYS, 0); in sifive_e_aon_reset()
270 r->wdogcfg = FIELD_DP32(r->wdogcfg, AON_WDT_WDOGCFG, EN_CORE_AWAKE, 0); in sifive_e_aon_reset()
271 r->wdogcmp0 = 0xbeef; in sifive_e_aon_reset()
273 sifive_e_aon_wdt_update_state(r); in sifive_e_aon_reset()
279 SiFiveEAONState *r = SIFIVE_E_AON(obj); in sifive_e_aon_init() local
281 memory_region_init_io(&r->mmio, OBJECT(r), &sifive_e_aon_ops, r, in sifive_e_aon_init()
283 sysbus_init_mmio(sbd, &r->mmio); in sifive_e_aon_init()
286 r->wdog_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, in sifive_e_aon_init()
287 sifive_e_aon_wdt_expired_cb, r); in sifive_e_aon_init()
288 r->wdogclk_freq = SIFIVE_E_LFCLK_DEFAULT_FREQ; in sifive_e_aon_init()
289 sysbus_init_irq(sbd, &r->wdog_irq); in sifive_e_aon_init()