timer_cpulocal.cc revision 11005
18512Sgeoffrey.blake@arm.com/*
29545Sandreas.hansson@arm.com * Copyright (c) 2010-2013 ARM Limited
38512Sgeoffrey.blake@arm.com * All rights reserved
48512Sgeoffrey.blake@arm.com *
58512Sgeoffrey.blake@arm.com * The license below extends only to copyright in the software and shall
68512Sgeoffrey.blake@arm.com * not be construed as granting a license to any other intellectual
78512Sgeoffrey.blake@arm.com * property including but not limited to intellectual property relating
88512Sgeoffrey.blake@arm.com * to a hardware implementation of the functionality of the software
98512Sgeoffrey.blake@arm.com * licensed hereunder.  You may use the software subject to the license
108512Sgeoffrey.blake@arm.com * terms below provided that you ensure that this notice is replicated
118512Sgeoffrey.blake@arm.com * unmodified and in its entirety in all distributions of the software,
128512Sgeoffrey.blake@arm.com * modified or unmodified, in source code or in binary form.
138512Sgeoffrey.blake@arm.com *
148512Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without
158512Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are
168512Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright
178512Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer;
188512Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright
198512Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the
208512Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution;
218512Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its
228512Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from
238512Sgeoffrey.blake@arm.com * this software without specific prior written permission.
248512Sgeoffrey.blake@arm.com *
258512Sgeoffrey.blake@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
268512Sgeoffrey.blake@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
278512Sgeoffrey.blake@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
288512Sgeoffrey.blake@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
298512Sgeoffrey.blake@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
308512Sgeoffrey.blake@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
318512Sgeoffrey.blake@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
328512Sgeoffrey.blake@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
338512Sgeoffrey.blake@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
348512Sgeoffrey.blake@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
358512Sgeoffrey.blake@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
368512Sgeoffrey.blake@arm.com *
378512Sgeoffrey.blake@arm.com * Authors: Ali Saidi
388512Sgeoffrey.blake@arm.com *          Geoffrey Blake
398512Sgeoffrey.blake@arm.com */
408512Sgeoffrey.blake@arm.com
418512Sgeoffrey.blake@arm.com#include "base/intmath.hh"
428512Sgeoffrey.blake@arm.com#include "base/trace.hh"
438512Sgeoffrey.blake@arm.com#include "debug/Checkpoint.hh"
448512Sgeoffrey.blake@arm.com#include "debug/Timer.hh"
459525SAndreas.Sandberg@ARM.com#include "dev/arm/base_gic.hh"
468512Sgeoffrey.blake@arm.com#include "dev/arm/timer_cpulocal.hh"
478512Sgeoffrey.blake@arm.com#include "mem/packet.hh"
488512Sgeoffrey.blake@arm.com#include "mem/packet_access.hh"
498512Sgeoffrey.blake@arm.com
508512Sgeoffrey.blake@arm.comCpuLocalTimer::CpuLocalTimer(Params *p)
519808Sstever@gmail.com    : BasicPioDevice(p, 0x38), gic(p->gic)
528512Sgeoffrey.blake@arm.com{
538512Sgeoffrey.blake@arm.com   // Initialize the timer registers for each per cpu timer
548512Sgeoffrey.blake@arm.com   for (int i = 0; i < CPU_MAX; i++) {
558512Sgeoffrey.blake@arm.com        std::stringstream oss;
568512Sgeoffrey.blake@arm.com        oss << name() << ".timer" << i;
578512Sgeoffrey.blake@arm.com        localTimer[i]._name = oss.str();
588512Sgeoffrey.blake@arm.com        localTimer[i].parent = this;
598512Sgeoffrey.blake@arm.com        localTimer[i].intNumTimer = p->int_num_timer;
608512Sgeoffrey.blake@arm.com        localTimer[i].intNumWatchdog = p->int_num_watchdog;
618512Sgeoffrey.blake@arm.com        localTimer[i].cpuNum = i;
628512Sgeoffrey.blake@arm.com    }
638512Sgeoffrey.blake@arm.com}
648512Sgeoffrey.blake@arm.com
658512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::Timer()
668512Sgeoffrey.blake@arm.com    : timerControl(0x0), watchdogControl(0x0), rawIntTimer(false), rawIntWatchdog(false),
678512Sgeoffrey.blake@arm.com      rawResetWatchdog(false), watchdogDisableReg(0x0), pendingIntTimer(false), pendingIntWatchdog(false),
688512Sgeoffrey.blake@arm.com      timerLoadValue(0x0), watchdogLoadValue(0x0), timerZeroEvent(this), watchdogZeroEvent(this)
698512Sgeoffrey.blake@arm.com{
708512Sgeoffrey.blake@arm.com}
718512Sgeoffrey.blake@arm.com
728512Sgeoffrey.blake@arm.comTick
738512Sgeoffrey.blake@arm.comCpuLocalTimer::read(PacketPtr pkt)
748512Sgeoffrey.blake@arm.com{
758512Sgeoffrey.blake@arm.com    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
768512Sgeoffrey.blake@arm.com    assert(pkt->getSize() == 4);
778512Sgeoffrey.blake@arm.com    Addr daddr = pkt->getAddr() - pioAddr;
7811005Sandreas.sandberg@arm.com    ContextID cpu_id = pkt->req->contextId();
798512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Reading from CpuLocalTimer at offset: %#x\n", daddr);
808512Sgeoffrey.blake@arm.com    assert(cpu_id >= 0);
818512Sgeoffrey.blake@arm.com    assert(cpu_id < CPU_MAX);
828512Sgeoffrey.blake@arm.com
838512Sgeoffrey.blake@arm.com    if (daddr < Timer::Size)
848512Sgeoffrey.blake@arm.com        localTimer[cpu_id].read(pkt, daddr);
858512Sgeoffrey.blake@arm.com    else
868512Sgeoffrey.blake@arm.com        panic("Tried to read CpuLocalTimer at offset %#x that doesn't exist\n", daddr);
878512Sgeoffrey.blake@arm.com    pkt->makeAtomicResponse();
888512Sgeoffrey.blake@arm.com    return pioDelay;
898512Sgeoffrey.blake@arm.com}
908512Sgeoffrey.blake@arm.com
918512Sgeoffrey.blake@arm.com
928512Sgeoffrey.blake@arm.comvoid
938512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::read(PacketPtr pkt, Addr daddr)
948512Sgeoffrey.blake@arm.com{
958512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Reading from CpuLocalTimer at offset: %#x\n", daddr);
968512Sgeoffrey.blake@arm.com    Tick time;
978512Sgeoffrey.blake@arm.com
988512Sgeoffrey.blake@arm.com    switch(daddr) {
998512Sgeoffrey.blake@arm.com      case TimerLoadReg:
1008512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(timerLoadValue);
1018512Sgeoffrey.blake@arm.com        break;
1028512Sgeoffrey.blake@arm.com      case TimerCounterReg:
1038512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "Event schedule for timer %d, clock=%d, prescale=%d\n",
1049545Sandreas.hansson@arm.com                timerZeroEvent.when(), parent->clockPeriod(),
1059545Sandreas.hansson@arm.com                timerControl.prescalar);
1068512Sgeoffrey.blake@arm.com        time = timerZeroEvent.when() - curTick();
1079545Sandreas.hansson@arm.com        time = time / parent->clockPeriod() /
1089545Sandreas.hansson@arm.com            power(16, timerControl.prescalar);
1098512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- returning counter at %d\n", time);
1108512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(time);
1118512Sgeoffrey.blake@arm.com        break;
1128512Sgeoffrey.blake@arm.com      case TimerControlReg:
1138512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(timerControl);
1148512Sgeoffrey.blake@arm.com        break;
1158512Sgeoffrey.blake@arm.com      case TimerIntStatusReg:
1168512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(rawIntTimer);
1178512Sgeoffrey.blake@arm.com        break;
1188512Sgeoffrey.blake@arm.com      case WatchdogLoadReg:
1198512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(watchdogLoadValue);
1208512Sgeoffrey.blake@arm.com        break;
1218512Sgeoffrey.blake@arm.com      case WatchdogCounterReg:
1229545Sandreas.hansson@arm.com        DPRINTF(Timer,
1239545Sandreas.hansson@arm.com                "Event schedule for watchdog %d, clock=%d, prescale=%d\n",
1249545Sandreas.hansson@arm.com                watchdogZeroEvent.when(), parent->clockPeriod(),
1259545Sandreas.hansson@arm.com                watchdogControl.prescalar);
1268512Sgeoffrey.blake@arm.com        time = watchdogZeroEvent.when() - curTick();
1279545Sandreas.hansson@arm.com        time = time / parent->clockPeriod() /
1289545Sandreas.hansson@arm.com            power(16, watchdogControl.prescalar);
1298512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- returning counter at %d\n", time);
1308512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(time);
1318512Sgeoffrey.blake@arm.com        break;
1328512Sgeoffrey.blake@arm.com      case WatchdogControlReg:
1338512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(watchdogControl);
1348512Sgeoffrey.blake@arm.com        break;
1358512Sgeoffrey.blake@arm.com      case WatchdogIntStatusReg:
1368512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(rawIntWatchdog);
1378512Sgeoffrey.blake@arm.com        break;
1388512Sgeoffrey.blake@arm.com      case WatchdogResetStatusReg:
1398512Sgeoffrey.blake@arm.com        pkt->set<uint32_t>(rawResetWatchdog);
1408512Sgeoffrey.blake@arm.com        break;
1418512Sgeoffrey.blake@arm.com      case WatchdogDisableReg:
1428512Sgeoffrey.blake@arm.com        panic("Tried to read from WatchdogDisableRegister\n");
1438512Sgeoffrey.blake@arm.com        break;
1448512Sgeoffrey.blake@arm.com      default:
1458512Sgeoffrey.blake@arm.com        panic("Tried to read CpuLocalTimer at offset %#x\n", daddr);
1468512Sgeoffrey.blake@arm.com        break;
1478512Sgeoffrey.blake@arm.com    }
1488512Sgeoffrey.blake@arm.com}
1498512Sgeoffrey.blake@arm.com
1508512Sgeoffrey.blake@arm.comTick
1518512Sgeoffrey.blake@arm.comCpuLocalTimer::write(PacketPtr pkt)
1528512Sgeoffrey.blake@arm.com{
1538512Sgeoffrey.blake@arm.com    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
1548512Sgeoffrey.blake@arm.com    assert(pkt->getSize() == 4);
1558512Sgeoffrey.blake@arm.com    Addr daddr = pkt->getAddr() - pioAddr;
15611005Sandreas.sandberg@arm.com    ContextID cpu_id = pkt->req->contextId();
1578512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Writing to CpuLocalTimer at offset: %#x\n", daddr);
1588512Sgeoffrey.blake@arm.com    assert(cpu_id >= 0);
1598512Sgeoffrey.blake@arm.com    assert(cpu_id < CPU_MAX);
1608512Sgeoffrey.blake@arm.com
1618512Sgeoffrey.blake@arm.com    if (daddr < Timer::Size)
1628512Sgeoffrey.blake@arm.com        localTimer[cpu_id].write(pkt, daddr);
1638512Sgeoffrey.blake@arm.com    else
1648512Sgeoffrey.blake@arm.com        panic("Tried to write CpuLocalTimer at offset %#x that doesn't exist\n", daddr);
1658512Sgeoffrey.blake@arm.com    pkt->makeAtomicResponse();
1668512Sgeoffrey.blake@arm.com    return pioDelay;
1678512Sgeoffrey.blake@arm.com}
1688512Sgeoffrey.blake@arm.com
1698512Sgeoffrey.blake@arm.comvoid
1708512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::write(PacketPtr pkt, Addr daddr)
1718512Sgeoffrey.blake@arm.com{
1728512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Writing to CpuLocalTimer at offset: %#x\n", daddr);
1738512Sgeoffrey.blake@arm.com    bool old_enable;
1748512Sgeoffrey.blake@arm.com    bool old_wd_mode;
1758512Sgeoffrey.blake@arm.com    uint32_t old_val;
1768512Sgeoffrey.blake@arm.com
1778512Sgeoffrey.blake@arm.com    switch (daddr) {
1788512Sgeoffrey.blake@arm.com      case TimerLoadReg:
1798512Sgeoffrey.blake@arm.com        // Writing to this register also resets the counter register and
1808512Sgeoffrey.blake@arm.com        // starts decrementing if the counter is enabled.
1818512Sgeoffrey.blake@arm.com        timerLoadValue = pkt->get<uint32_t>();
1828512Sgeoffrey.blake@arm.com        restartTimerCounter(timerLoadValue);
1838512Sgeoffrey.blake@arm.com        break;
1848512Sgeoffrey.blake@arm.com      case TimerCounterReg:
1858512Sgeoffrey.blake@arm.com        // Can be written, doesn't start counting unless the timer is enabled
1868512Sgeoffrey.blake@arm.com        restartTimerCounter(pkt->get<uint32_t>());
1878512Sgeoffrey.blake@arm.com        break;
1888512Sgeoffrey.blake@arm.com      case TimerControlReg:
1898512Sgeoffrey.blake@arm.com        old_enable = timerControl.enable;
1908512Sgeoffrey.blake@arm.com        timerControl = pkt->get<uint32_t>();
1918512Sgeoffrey.blake@arm.com        if ((old_enable == 0) && timerControl.enable)
1928512Sgeoffrey.blake@arm.com            restartTimerCounter(timerLoadValue);
1938512Sgeoffrey.blake@arm.com        break;
1948512Sgeoffrey.blake@arm.com      case TimerIntStatusReg:
1958512Sgeoffrey.blake@arm.com        rawIntTimer = false;
1968512Sgeoffrey.blake@arm.com        if (pendingIntTimer) {
1978512Sgeoffrey.blake@arm.com            pendingIntTimer = false;
1988512Sgeoffrey.blake@arm.com            DPRINTF(Timer, "Clearing interrupt\n");
1998512Sgeoffrey.blake@arm.com        }
2008512Sgeoffrey.blake@arm.com        break;
2018512Sgeoffrey.blake@arm.com      case WatchdogLoadReg:
2028512Sgeoffrey.blake@arm.com        watchdogLoadValue = pkt->get<uint32_t>();
2038512Sgeoffrey.blake@arm.com        restartWatchdogCounter(watchdogLoadValue);
2048512Sgeoffrey.blake@arm.com        break;
2058512Sgeoffrey.blake@arm.com      case WatchdogCounterReg:
2068512Sgeoffrey.blake@arm.com        // Can't be written when in watchdog mode, but can in timer mode
2078512Sgeoffrey.blake@arm.com        if (!watchdogControl.watchdogMode) {
2088512Sgeoffrey.blake@arm.com            restartWatchdogCounter(pkt->get<uint32_t>());
2098512Sgeoffrey.blake@arm.com        }
2108512Sgeoffrey.blake@arm.com        break;
2118512Sgeoffrey.blake@arm.com      case WatchdogControlReg:
2128512Sgeoffrey.blake@arm.com        old_enable = watchdogControl.enable;
2138512Sgeoffrey.blake@arm.com        old_wd_mode = watchdogControl.watchdogMode;
2148512Sgeoffrey.blake@arm.com        watchdogControl = pkt->get<uint32_t>();
2158512Sgeoffrey.blake@arm.com        if ((old_enable == 0) && watchdogControl.enable)
2168512Sgeoffrey.blake@arm.com            restartWatchdogCounter(watchdogLoadValue);
2178512Sgeoffrey.blake@arm.com        // cannot disable watchdog using control register
2188512Sgeoffrey.blake@arm.com        if ((old_wd_mode == 1) && watchdogControl.watchdogMode == 0)
2198512Sgeoffrey.blake@arm.com            watchdogControl.watchdogMode = 1;
2208512Sgeoffrey.blake@arm.com        break;
2218512Sgeoffrey.blake@arm.com      case WatchdogIntStatusReg:
2228512Sgeoffrey.blake@arm.com        rawIntWatchdog = false;
2238512Sgeoffrey.blake@arm.com        if (pendingIntWatchdog) {
2248512Sgeoffrey.blake@arm.com            pendingIntWatchdog = false;
2258512Sgeoffrey.blake@arm.com            DPRINTF(Timer, "Clearing watchdog interrupt\n");
2268512Sgeoffrey.blake@arm.com        }
2278512Sgeoffrey.blake@arm.com        break;
2288512Sgeoffrey.blake@arm.com      case WatchdogResetStatusReg:
2298512Sgeoffrey.blake@arm.com        rawResetWatchdog = false;
2308512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "Clearing watchdog reset flag\n");
2318512Sgeoffrey.blake@arm.com        break;
2328512Sgeoffrey.blake@arm.com      case WatchdogDisableReg:
2338512Sgeoffrey.blake@arm.com        old_val = watchdogDisableReg;
2348512Sgeoffrey.blake@arm.com        watchdogDisableReg = pkt->get<uint32_t>();
2358512Sgeoffrey.blake@arm.com        // if this sequence is observed, turn off watchdog mode
2368512Sgeoffrey.blake@arm.com        if (old_val == 0x12345678 && watchdogDisableReg == 0x87654321)
2378512Sgeoffrey.blake@arm.com            watchdogControl.watchdogMode = 0;
2388512Sgeoffrey.blake@arm.com        break;
2398512Sgeoffrey.blake@arm.com      default:
2408512Sgeoffrey.blake@arm.com        panic("Tried to write CpuLocalTimer timer at offset %#x\n", daddr);
2418512Sgeoffrey.blake@arm.com        break;
2428512Sgeoffrey.blake@arm.com    }
2438512Sgeoffrey.blake@arm.com}
2448512Sgeoffrey.blake@arm.com
2458512Sgeoffrey.blake@arm.com//XXX: Two functions are needed because the control registers are different types
2468512Sgeoffrey.blake@arm.comvoid
2478512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::restartTimerCounter(uint32_t val)
2488512Sgeoffrey.blake@arm.com{
2498512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Resetting timer counter with value %#x\n", val);
2508512Sgeoffrey.blake@arm.com    if (!timerControl.enable)
2518512Sgeoffrey.blake@arm.com        return;
2528512Sgeoffrey.blake@arm.com
2539545Sandreas.hansson@arm.com    Tick time = parent->clockPeriod() * power(16, timerControl.prescalar);
2548512Sgeoffrey.blake@arm.com    time *= val;
2558512Sgeoffrey.blake@arm.com
2568512Sgeoffrey.blake@arm.com    if (timerZeroEvent.scheduled()) {
2578512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- Event was already schedule, de-scheduling\n");
2588512Sgeoffrey.blake@arm.com        parent->deschedule(timerZeroEvent);
2598512Sgeoffrey.blake@arm.com    }
2608512Sgeoffrey.blake@arm.com    parent->schedule(timerZeroEvent, curTick() + time);
2618512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "-- Scheduling new event for: %d\n", curTick() + time);
2628512Sgeoffrey.blake@arm.com}
2638512Sgeoffrey.blake@arm.com
2648512Sgeoffrey.blake@arm.comvoid
2658512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::restartWatchdogCounter(uint32_t val)
2668512Sgeoffrey.blake@arm.com{
2678512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Resetting watchdog counter with value %#x\n", val);
2688512Sgeoffrey.blake@arm.com    if (!watchdogControl.enable)
2698512Sgeoffrey.blake@arm.com        return;
2708512Sgeoffrey.blake@arm.com
2719545Sandreas.hansson@arm.com    Tick time = parent->clockPeriod() * power(16, watchdogControl.prescalar);
2728512Sgeoffrey.blake@arm.com    time *= val;
2738512Sgeoffrey.blake@arm.com
2748512Sgeoffrey.blake@arm.com    if (watchdogZeroEvent.scheduled()) {
2758512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- Event was already schedule, de-scheduling\n");
2768512Sgeoffrey.blake@arm.com        parent->deschedule(watchdogZeroEvent);
2778512Sgeoffrey.blake@arm.com    }
2788512Sgeoffrey.blake@arm.com    parent->schedule(watchdogZeroEvent, curTick() + time);
2798512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "-- Scheduling new event for: %d\n", curTick() + time);
2808512Sgeoffrey.blake@arm.com}
2818512Sgeoffrey.blake@arm.com//////
2828512Sgeoffrey.blake@arm.com
2838512Sgeoffrey.blake@arm.comvoid
2848512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::timerAtZero()
2858512Sgeoffrey.blake@arm.com{
2868512Sgeoffrey.blake@arm.com    if (!timerControl.enable)
2878512Sgeoffrey.blake@arm.com        return;
2888512Sgeoffrey.blake@arm.com
2898512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Timer Counter reached zero\n");
2908512Sgeoffrey.blake@arm.com
2918512Sgeoffrey.blake@arm.com    rawIntTimer = true;
2928512Sgeoffrey.blake@arm.com    bool old_pending = pendingIntTimer;
2938512Sgeoffrey.blake@arm.com    if (timerControl.intEnable)
2948512Sgeoffrey.blake@arm.com        pendingIntTimer = true;
2958993SAli.Saidi@ARM.com    if (pendingIntTimer && !old_pending) {
2968512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- Causing interrupt\n");
2978512Sgeoffrey.blake@arm.com        parent->gic->sendPPInt(intNumTimer, cpuNum);
2988512Sgeoffrey.blake@arm.com    }
2998512Sgeoffrey.blake@arm.com
3008512Sgeoffrey.blake@arm.com    if (!timerControl.autoReload)
3018512Sgeoffrey.blake@arm.com        return;
3028512Sgeoffrey.blake@arm.com    else
3038512Sgeoffrey.blake@arm.com        restartTimerCounter(timerLoadValue);
3048512Sgeoffrey.blake@arm.com}
3058512Sgeoffrey.blake@arm.com
3068512Sgeoffrey.blake@arm.comvoid
3078512Sgeoffrey.blake@arm.comCpuLocalTimer::Timer::watchdogAtZero()
3088512Sgeoffrey.blake@arm.com{
3098512Sgeoffrey.blake@arm.com    if (!watchdogControl.enable)
3108512Sgeoffrey.blake@arm.com        return;
3118512Sgeoffrey.blake@arm.com
3128512Sgeoffrey.blake@arm.com    DPRINTF(Timer, "Watchdog Counter reached zero\n");
3138512Sgeoffrey.blake@arm.com
3148512Sgeoffrey.blake@arm.com    rawIntWatchdog = true;
3158512Sgeoffrey.blake@arm.com    bool old_pending = pendingIntWatchdog;
3168512Sgeoffrey.blake@arm.com    // generates an interrupt only if the watchdog is in timer
3178512Sgeoffrey.blake@arm.com    // mode.
3188512Sgeoffrey.blake@arm.com    if (watchdogControl.intEnable && !watchdogControl.watchdogMode)
3198512Sgeoffrey.blake@arm.com        pendingIntWatchdog = true;
3208512Sgeoffrey.blake@arm.com    else if (watchdogControl.watchdogMode) {
3218512Sgeoffrey.blake@arm.com        rawResetWatchdog = true;
3228512Sgeoffrey.blake@arm.com        fatal("gem5 ARM Model does not support true watchdog operation!\n");
3238512Sgeoffrey.blake@arm.com        //XXX: Should we ever support a true watchdog reset?
3248512Sgeoffrey.blake@arm.com    }
3258512Sgeoffrey.blake@arm.com
3268993SAli.Saidi@ARM.com    if (pendingIntWatchdog && !old_pending) {
3278512Sgeoffrey.blake@arm.com        DPRINTF(Timer, "-- Causing interrupt\n");
3288512Sgeoffrey.blake@arm.com        parent->gic->sendPPInt(intNumWatchdog, cpuNum);
3298512Sgeoffrey.blake@arm.com    }
3308512Sgeoffrey.blake@arm.com
3318512Sgeoffrey.blake@arm.com    if (watchdogControl.watchdogMode)
3328512Sgeoffrey.blake@arm.com        return;
3338512Sgeoffrey.blake@arm.com    else if (watchdogControl.autoReload)
3348512Sgeoffrey.blake@arm.com        restartWatchdogCounter(watchdogLoadValue);
3358512Sgeoffrey.blake@arm.com}
3368512Sgeoffrey.blake@arm.com
3378512Sgeoffrey.blake@arm.comvoid
33810905Sandreas.sandberg@arm.comCpuLocalTimer::Timer::serialize(CheckpointOut &cp) const
3398512Sgeoffrey.blake@arm.com{
3408512Sgeoffrey.blake@arm.com    DPRINTF(Checkpoint, "Serializing Arm CpuLocalTimer\n");
3418512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(intNumTimer);
3428512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(intNumWatchdog);
3438512Sgeoffrey.blake@arm.com
3448512Sgeoffrey.blake@arm.com    uint32_t timer_control_serial = timerControl;
3458512Sgeoffrey.blake@arm.com    uint32_t watchdog_control_serial = watchdogControl;
3468512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(timer_control_serial);
3478512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(watchdog_control_serial);
3488512Sgeoffrey.blake@arm.com
3498512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(rawIntTimer);
3508512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(rawIntWatchdog);
3518512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(rawResetWatchdog);
3528512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(watchdogDisableReg);
3538512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(pendingIntTimer);
3548512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(pendingIntWatchdog);
3558512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(timerLoadValue);
3568512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(watchdogLoadValue);
3578512Sgeoffrey.blake@arm.com
3588512Sgeoffrey.blake@arm.com    bool timer_is_in_event = timerZeroEvent.scheduled();
3598512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(timer_is_in_event);
3608512Sgeoffrey.blake@arm.com    bool watchdog_is_in_event = watchdogZeroEvent.scheduled();
3618512Sgeoffrey.blake@arm.com    SERIALIZE_SCALAR(watchdog_is_in_event);
3628512Sgeoffrey.blake@arm.com
3638512Sgeoffrey.blake@arm.com    Tick timer_event_time;
3648512Sgeoffrey.blake@arm.com    if (timer_is_in_event){
3658512Sgeoffrey.blake@arm.com        timer_event_time = timerZeroEvent.when();
3668512Sgeoffrey.blake@arm.com        SERIALIZE_SCALAR(timer_event_time);
3678512Sgeoffrey.blake@arm.com    }
3688512Sgeoffrey.blake@arm.com    Tick watchdog_event_time;
3698512Sgeoffrey.blake@arm.com    if (watchdog_is_in_event){
3708512Sgeoffrey.blake@arm.com        watchdog_event_time = watchdogZeroEvent.when();
3718512Sgeoffrey.blake@arm.com        SERIALIZE_SCALAR(watchdog_event_time);
3728512Sgeoffrey.blake@arm.com    }
3738512Sgeoffrey.blake@arm.com}
3748512Sgeoffrey.blake@arm.com
3758512Sgeoffrey.blake@arm.comvoid
37610905Sandreas.sandberg@arm.comCpuLocalTimer::Timer::unserialize(CheckpointIn &cp)
3778512Sgeoffrey.blake@arm.com{
3788512Sgeoffrey.blake@arm.com    DPRINTF(Checkpoint, "Unserializing Arm CpuLocalTimer\n");
3798512Sgeoffrey.blake@arm.com
3808512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(intNumTimer);
3818512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(intNumWatchdog);
3828512Sgeoffrey.blake@arm.com
3838512Sgeoffrey.blake@arm.com    uint32_t timer_control_serial;
3848512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(timer_control_serial);
3858512Sgeoffrey.blake@arm.com    timerControl = timer_control_serial;
3868512Sgeoffrey.blake@arm.com    uint32_t watchdog_control_serial;
3878512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(watchdog_control_serial);
3888512Sgeoffrey.blake@arm.com    watchdogControl = watchdog_control_serial;
3898512Sgeoffrey.blake@arm.com
3908512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(rawIntTimer);
3918512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(rawIntWatchdog);
3928512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(rawResetWatchdog);
3938512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(watchdogDisableReg);
3948512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(pendingIntTimer);
3958512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(pendingIntWatchdog);
3968512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(timerLoadValue);
3978512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(watchdogLoadValue);
3988512Sgeoffrey.blake@arm.com
3998512Sgeoffrey.blake@arm.com    bool timer_is_in_event;
4008512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(timer_is_in_event);
4018512Sgeoffrey.blake@arm.com    bool watchdog_is_in_event;
4028512Sgeoffrey.blake@arm.com    UNSERIALIZE_SCALAR(watchdog_is_in_event);
4038512Sgeoffrey.blake@arm.com
4048512Sgeoffrey.blake@arm.com    Tick timer_event_time;
4058512Sgeoffrey.blake@arm.com    if (timer_is_in_event){
4068512Sgeoffrey.blake@arm.com        UNSERIALIZE_SCALAR(timer_event_time);
4078512Sgeoffrey.blake@arm.com        parent->schedule(timerZeroEvent, timer_event_time);
4088512Sgeoffrey.blake@arm.com    }
4098512Sgeoffrey.blake@arm.com    Tick watchdog_event_time;
4108512Sgeoffrey.blake@arm.com    if (watchdog_is_in_event) {
4118512Sgeoffrey.blake@arm.com        UNSERIALIZE_SCALAR(watchdog_event_time);
4128512Sgeoffrey.blake@arm.com        parent->schedule(watchdogZeroEvent, watchdog_event_time);
4138512Sgeoffrey.blake@arm.com    }
4148512Sgeoffrey.blake@arm.com}
4158512Sgeoffrey.blake@arm.com
4168512Sgeoffrey.blake@arm.com
4178512Sgeoffrey.blake@arm.com
4188512Sgeoffrey.blake@arm.comvoid
41910905Sandreas.sandberg@arm.comCpuLocalTimer::serialize(CheckpointOut &cp) const
4208512Sgeoffrey.blake@arm.com{
42110905Sandreas.sandberg@arm.com    for (int i = 0; i < CPU_MAX; i++)
42210905Sandreas.sandberg@arm.com        localTimer[i].serializeSection(cp, csprintf("timer%d", i));
4238512Sgeoffrey.blake@arm.com}
4248512Sgeoffrey.blake@arm.com
4258512Sgeoffrey.blake@arm.comvoid
42610905Sandreas.sandberg@arm.comCpuLocalTimer::unserialize(CheckpointIn &cp)
4278512Sgeoffrey.blake@arm.com{
42810905Sandreas.sandberg@arm.com    for (int i = 0; i < CPU_MAX; i++)
42910905Sandreas.sandberg@arm.com        localTimer[i].unserializeSection(cp, csprintf("timer%d", i));
4308512Sgeoffrey.blake@arm.com}
4318512Sgeoffrey.blake@arm.com
4328512Sgeoffrey.blake@arm.comCpuLocalTimer *
4338512Sgeoffrey.blake@arm.comCpuLocalTimerParams::create()
4348512Sgeoffrey.blake@arm.com{
4358512Sgeoffrey.blake@arm.com    return new CpuLocalTimer(this);
4368512Sgeoffrey.blake@arm.com}
437