timer_cpulocal.hh revision 8512
18512Sgeoffrey.blake@arm.com/*
28512Sgeoffrey.blake@arm.com * Copyright (c) 2010-2011 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#ifndef __DEV_ARM_LOCALTIMER_HH__
428512Sgeoffrey.blake@arm.com#define __DEV_ARM_LOCALTIMER_HH__
438512Sgeoffrey.blake@arm.com
448512Sgeoffrey.blake@arm.com#include "base/range.hh"
458512Sgeoffrey.blake@arm.com#include "dev/io_device.hh"
468512Sgeoffrey.blake@arm.com#include "params/CpuLocalTimer.hh"
478512Sgeoffrey.blake@arm.com
488512Sgeoffrey.blake@arm.com/** @file
498512Sgeoffrey.blake@arm.com * This implements the cpu local timer from the Cortex-A9 MPCore
508512Sgeoffrey.blake@arm.com * Technical Reference Manual rev r2p2 (ARM DDI 0407F)
518512Sgeoffrey.blake@arm.com */
528512Sgeoffrey.blake@arm.com
538512Sgeoffrey.blake@arm.comclass Gic;
548512Sgeoffrey.blake@arm.com
558512Sgeoffrey.blake@arm.comclass CpuLocalTimer : public BasicPioDevice
568512Sgeoffrey.blake@arm.com{
578512Sgeoffrey.blake@arm.com  protected:
588512Sgeoffrey.blake@arm.com    class Timer
598512Sgeoffrey.blake@arm.com    {
608512Sgeoffrey.blake@arm.com
618512Sgeoffrey.blake@arm.com      public:
628512Sgeoffrey.blake@arm.com        enum {
638512Sgeoffrey.blake@arm.com            TimerLoadReg    	   = 0x00,
648512Sgeoffrey.blake@arm.com            TimerCounterReg 	   = 0x04,
658512Sgeoffrey.blake@arm.com            TimerControlReg 	   = 0x08,
668512Sgeoffrey.blake@arm.com            TimerIntStatusReg      = 0x0C,
678512Sgeoffrey.blake@arm.com            WatchdogLoadReg        = 0x20,
688512Sgeoffrey.blake@arm.com            WatchdogCounterReg     = 0x24,
698512Sgeoffrey.blake@arm.com            WatchdogControlReg     = 0x28,
708512Sgeoffrey.blake@arm.com            WatchdogIntStatusReg   = 0x2C,
718512Sgeoffrey.blake@arm.com            WatchdogResetStatusReg = 0x30,
728512Sgeoffrey.blake@arm.com            WatchdogDisableReg     = 0x34,
738512Sgeoffrey.blake@arm.com            Size                   = 0x38
748512Sgeoffrey.blake@arm.com        };
758512Sgeoffrey.blake@arm.com
768512Sgeoffrey.blake@arm.com        BitUnion32(TimerCtrl)
778512Sgeoffrey.blake@arm.com            Bitfield<0>   enable;
788512Sgeoffrey.blake@arm.com            Bitfield<1>   autoReload;
798512Sgeoffrey.blake@arm.com            Bitfield<2>   intEnable;
808512Sgeoffrey.blake@arm.com            Bitfield<3,7> reserved;
818512Sgeoffrey.blake@arm.com            Bitfield<8,15> prescalar;
828512Sgeoffrey.blake@arm.com        EndBitUnion(TimerCtrl)
838512Sgeoffrey.blake@arm.com
848512Sgeoffrey.blake@arm.com        BitUnion32(WatchdogCtrl)
858512Sgeoffrey.blake@arm.com            Bitfield<0>   enable;
868512Sgeoffrey.blake@arm.com            Bitfield<1>   autoReload;
878512Sgeoffrey.blake@arm.com            Bitfield<2>   intEnable;
888512Sgeoffrey.blake@arm.com            Bitfield<3>   watchdogMode;
898512Sgeoffrey.blake@arm.com            Bitfield<4,7> reserved;
908512Sgeoffrey.blake@arm.com            Bitfield<8,15> prescalar;
918512Sgeoffrey.blake@arm.com        EndBitUnion(WatchdogCtrl)
928512Sgeoffrey.blake@arm.com
938512Sgeoffrey.blake@arm.com      protected:
948512Sgeoffrey.blake@arm.com        std::string _name;
958512Sgeoffrey.blake@arm.com
968512Sgeoffrey.blake@arm.com        /** Pointer to parent class */
978512Sgeoffrey.blake@arm.com        CpuLocalTimer *parent;
988512Sgeoffrey.blake@arm.com
998512Sgeoffrey.blake@arm.com        /** Number of interrupt to cause/clear */
1008512Sgeoffrey.blake@arm.com        uint32_t intNumTimer;
1018512Sgeoffrey.blake@arm.com        uint32_t intNumWatchdog;
1028512Sgeoffrey.blake@arm.com
1038512Sgeoffrey.blake@arm.com        /** Cpu this timer is attached to */
1048512Sgeoffrey.blake@arm.com        uint32_t cpuNum;
1058512Sgeoffrey.blake@arm.com
1068512Sgeoffrey.blake@arm.com        /** Number of ticks in a clock input */
1078512Sgeoffrey.blake@arm.com        Tick clock;
1088512Sgeoffrey.blake@arm.com
1098512Sgeoffrey.blake@arm.com        /** Control register as specified above */
1108512Sgeoffrey.blake@arm.com        TimerCtrl timerControl;
1118512Sgeoffrey.blake@arm.com        WatchdogCtrl watchdogControl;
1128512Sgeoffrey.blake@arm.com
1138512Sgeoffrey.blake@arm.com        /** If timer has caused an interrupt. This is irrespective of
1148512Sgeoffrey.blake@arm.com         * interrupt enable */
1158512Sgeoffrey.blake@arm.com        bool rawIntTimer;
1168512Sgeoffrey.blake@arm.com        bool rawIntWatchdog;
1178512Sgeoffrey.blake@arm.com        bool rawResetWatchdog;
1188512Sgeoffrey.blake@arm.com        uint32_t watchdogDisableReg;
1198512Sgeoffrey.blake@arm.com
1208512Sgeoffrey.blake@arm.com        /** If an interrupt is currently pending. Logical and of Timer or
1218512Sgeoffrey.blake@arm.com          * Watchdog Ctrl.enable and rawIntTimer or rawIntWatchdog */
1228512Sgeoffrey.blake@arm.com        bool pendingIntTimer;
1238512Sgeoffrey.blake@arm.com        bool pendingIntWatchdog;
1248512Sgeoffrey.blake@arm.com
1258512Sgeoffrey.blake@arm.com        /** Value to load into counters when periodic mode reaches 0 */
1268512Sgeoffrey.blake@arm.com        uint32_t timerLoadValue;
1278512Sgeoffrey.blake@arm.com        uint32_t watchdogLoadValue;
1288512Sgeoffrey.blake@arm.com
1298512Sgeoffrey.blake@arm.com        /** Called when the counter reaches 0 */
1308512Sgeoffrey.blake@arm.com        void timerAtZero();
1318512Sgeoffrey.blake@arm.com        EventWrapper<Timer, &Timer::timerAtZero> timerZeroEvent;
1328512Sgeoffrey.blake@arm.com
1338512Sgeoffrey.blake@arm.com        void watchdogAtZero();
1348512Sgeoffrey.blake@arm.com        EventWrapper<Timer, &Timer::watchdogAtZero> watchdogZeroEvent;
1358512Sgeoffrey.blake@arm.com      public:
1368512Sgeoffrey.blake@arm.com        /** Restart the counter ticking at val
1378512Sgeoffrey.blake@arm.com         * @param val the value to start at */
1388512Sgeoffrey.blake@arm.com        void restartTimerCounter(uint32_t val);
1398512Sgeoffrey.blake@arm.com        void restartWatchdogCounter(uint32_t val);
1408512Sgeoffrey.blake@arm.com
1418512Sgeoffrey.blake@arm.com        Timer();
1428512Sgeoffrey.blake@arm.com
1438512Sgeoffrey.blake@arm.com        std::string name() const { return _name; }
1448512Sgeoffrey.blake@arm.com
1458512Sgeoffrey.blake@arm.com        /** Handle read for a single timer */
1468512Sgeoffrey.blake@arm.com        void read(PacketPtr pkt, Addr daddr);
1478512Sgeoffrey.blake@arm.com
1488512Sgeoffrey.blake@arm.com        /** Handle write for a single timer */
1498512Sgeoffrey.blake@arm.com        void write(PacketPtr pkt, Addr daddr);
1508512Sgeoffrey.blake@arm.com
1518512Sgeoffrey.blake@arm.com        void serialize(std::ostream &os);
1528512Sgeoffrey.blake@arm.com        void unserialize(Checkpoint *cp, const std::string &section);
1538512Sgeoffrey.blake@arm.com
1548512Sgeoffrey.blake@arm.com        friend class CpuLocalTimer;
1558512Sgeoffrey.blake@arm.com    };
1568512Sgeoffrey.blake@arm.com
1578512Sgeoffrey.blake@arm.com    static const int CPU_MAX = 8;
1588512Sgeoffrey.blake@arm.com
1598512Sgeoffrey.blake@arm.com    /** Pointer to the GIC for causing an interrupt */
1608512Sgeoffrey.blake@arm.com    Gic *gic;
1618512Sgeoffrey.blake@arm.com
1628512Sgeoffrey.blake@arm.com    /** Timers that do the actual work */
1638512Sgeoffrey.blake@arm.com    Timer localTimer[CPU_MAX];
1648512Sgeoffrey.blake@arm.com
1658512Sgeoffrey.blake@arm.com  public:
1668512Sgeoffrey.blake@arm.com    typedef CpuLocalTimerParams Params;
1678512Sgeoffrey.blake@arm.com    const Params *
1688512Sgeoffrey.blake@arm.com    params() const
1698512Sgeoffrey.blake@arm.com    {
1708512Sgeoffrey.blake@arm.com        return dynamic_cast<const Params *>(_params);
1718512Sgeoffrey.blake@arm.com    }
1728512Sgeoffrey.blake@arm.com    /**
1738512Sgeoffrey.blake@arm.com      * The constructor for RealView just registers itself with the MMU.
1748512Sgeoffrey.blake@arm.com      * @param p params structure
1758512Sgeoffrey.blake@arm.com      */
1768512Sgeoffrey.blake@arm.com    CpuLocalTimer(Params *p);
1778512Sgeoffrey.blake@arm.com
1788512Sgeoffrey.blake@arm.com    /**
1798512Sgeoffrey.blake@arm.com     * Handle a read to the device
1808512Sgeoffrey.blake@arm.com     * @param pkt The memory request.
1818512Sgeoffrey.blake@arm.com     * @return Returns latency of device read
1828512Sgeoffrey.blake@arm.com     */
1838512Sgeoffrey.blake@arm.com    virtual Tick read(PacketPtr pkt);
1848512Sgeoffrey.blake@arm.com
1858512Sgeoffrey.blake@arm.com    /**
1868512Sgeoffrey.blake@arm.com     * Handle a write to the device.
1878512Sgeoffrey.blake@arm.com     * @param pkt The memory request.
1888512Sgeoffrey.blake@arm.com     * @return Returns latency of device write
1898512Sgeoffrey.blake@arm.com     */
1908512Sgeoffrey.blake@arm.com    virtual Tick write(PacketPtr pkt);
1918512Sgeoffrey.blake@arm.com
1928512Sgeoffrey.blake@arm.com
1938512Sgeoffrey.blake@arm.com    virtual void serialize(std::ostream &os);
1948512Sgeoffrey.blake@arm.com    virtual void unserialize(Checkpoint *cp, const std::string &section);
1958512Sgeoffrey.blake@arm.com};
1968512Sgeoffrey.blake@arm.com
1978512Sgeoffrey.blake@arm.com
1988512Sgeoffrey.blake@arm.com#endif // __DEV_ARM_SP804_HH__
1998512Sgeoffrey.blake@arm.com
200