timer_cpulocal.hh revision 9235:5aa4896ed55a
12379SN/A/*
210298Salexandru.dutu@amd.com * Copyright (c) 2010-2011 ARM Limited
32379SN/A * All rights reserved
42379SN/A *
52379SN/A * The license below extends only to copyright in the software and shall
62379SN/A * not be construed as granting a license to any other intellectual
72379SN/A * property including but not limited to intellectual property relating
82379SN/A * to a hardware implementation of the functionality of the software
92379SN/A * licensed hereunder.  You may use the software subject to the license
102379SN/A * terms below provided that you ensure that this notice is replicated
112379SN/A * unmodified and in its entirety in all distributions of the software,
122379SN/A * modified or unmodified, in source code or in binary form.
132379SN/A *
142379SN/A * Redistribution and use in source and binary forms, with or without
152379SN/A * modification, are permitted provided that the following conditions are
162379SN/A * met: redistributions of source code must retain the above copyright
172379SN/A * notice, this list of conditions and the following disclaimer;
182379SN/A * redistributions in binary form must reproduce the above copyright
192379SN/A * notice, this list of conditions and the following disclaimer in the
202379SN/A * documentation and/or other materials provided with the distribution;
212379SN/A * neither the name of the copyright holders nor the names of its
222379SN/A * contributors may be used to endorse or promote products derived from
232379SN/A * this software without specific prior written permission.
242379SN/A *
252379SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262379SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272379SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292665Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302665Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
313311Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322379SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332379SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342379SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352379SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3610298Salexandru.dutu@amd.com *
372379SN/A * Authors: Ali Saidi
3811793Sbrandon.potter@amd.com *          Geoffrey Blake
3911793Sbrandon.potter@amd.com */
402379SN/A
412379SN/A#ifndef __DEV_ARM_LOCALTIMER_HH__
4212536Sbrandon.potter@amd.com#define __DEV_ARM_LOCALTIMER_HH__
432379SN/A
448232Snate@binkert.org#include "dev/io_device.hh"
457678Sgblack@eecs.umich.edu#include "params/CpuLocalTimer.hh"
4611800Sbrandon.potter@amd.com
472379SN/A/** @file
482399SN/A * This implements the cpu local timer from the Cortex-A9 MPCore
4912448Sgabeblack@google.com * Technical Reference Manual rev r2p2 (ARM DDI 0407F)
502399SN/A */
5110558Salexandru.dutu@amd.com
522399SN/Aclass Gic;
532399SN/A
542399SN/Aclass CpuLocalTimer : public BasicPioDevice
5512448Sgabeblack@google.com{
563311Ssaidi@eecs.umich.edu  protected:
5712448Sgabeblack@google.com    class Timer
5812442Sgabeblack@google.com    {
5912442Sgabeblack@google.com
6012461Sgabeblack@google.com      public:
6112461Sgabeblack@google.com        enum {
6212461Sgabeblack@google.com            TimerLoadReg    	   = 0x00,
6312461Sgabeblack@google.com            TimerCounterReg 	   = 0x04,
6412461Sgabeblack@google.com            TimerControlReg 	   = 0x08,
6512442Sgabeblack@google.com            TimerIntStatusReg      = 0x0C,
6612461Sgabeblack@google.com            WatchdogLoadReg        = 0x20,
672399SN/A            WatchdogCounterReg     = 0x24,
682399SN/A            WatchdogControlReg     = 0x28,
6912448Sgabeblack@google.com            WatchdogIntStatusReg   = 0x2C,
7012448Sgabeblack@google.com            WatchdogResetStatusReg = 0x30,
7112448Sgabeblack@google.com            WatchdogDisableReg     = 0x34,
722399SN/A            Size                   = 0x38
732399SN/A        };
742399SN/A
755877Shsul@eecs.umich.edu        BitUnion32(TimerCtrl)
7612448Sgabeblack@google.com            Bitfield<0>   enable;
775877Shsul@eecs.umich.edu            Bitfield<1>   autoReload;
785877Shsul@eecs.umich.edu            Bitfield<2>   intEnable;
795877Shsul@eecs.umich.edu            Bitfield<7,3> reserved;
805877Shsul@eecs.umich.edu            Bitfield<15,8> prescalar;
815877Shsul@eecs.umich.edu        EndBitUnion(TimerCtrl)
825877Shsul@eecs.umich.edu
835877Shsul@eecs.umich.edu        BitUnion32(WatchdogCtrl)
8412448Sgabeblack@google.com            Bitfield<0>   enable;
8512536Sbrandon.potter@amd.com            Bitfield<1>   autoReload;
8612442Sgabeblack@google.com            Bitfield<2>   intEnable;
8712442Sgabeblack@google.com            Bitfield<3>   watchdogMode;
885877Shsul@eecs.umich.edu            Bitfield<7,4> reserved;
8912519Srico.amslinger@informatik.uni-augsburg.de            Bitfield<15,8> prescalar;
9012442Sgabeblack@google.com        EndBitUnion(WatchdogCtrl)
9112448Sgabeblack@google.com
9212448Sgabeblack@google.com      protected:
9312448Sgabeblack@google.com        std::string _name;
945877Shsul@eecs.umich.edu
955877Shsul@eecs.umich.edu        /** Pointer to parent class */
965877Shsul@eecs.umich.edu        CpuLocalTimer *parent;
975877Shsul@eecs.umich.edu
9812448Sgabeblack@google.com        /** Number of interrupt to cause/clear */
9911886Sbrandon.potter@amd.com        uint32_t intNumTimer;
10011886Sbrandon.potter@amd.com        uint32_t intNumWatchdog;
10112637Sodanrc@yahoo.com.br
10211886Sbrandon.potter@amd.com        /** Cpu this timer is attached to */
10311886Sbrandon.potter@amd.com        uint32_t cpuNum;
10411886Sbrandon.potter@amd.com
10512448Sgabeblack@google.com        /** Number of ticks in a clock input */
1065877Shsul@eecs.umich.edu        Tick clock;
1075877Shsul@eecs.umich.edu
1085877Shsul@eecs.umich.edu        /** Control register as specified above */
10912461Sgabeblack@google.com        TimerCtrl timerControl;
1105877Shsul@eecs.umich.edu        WatchdogCtrl watchdogControl;
11112448Sgabeblack@google.com
11212442Sgabeblack@google.com        /** If timer has caused an interrupt. This is irrespective of
11312442Sgabeblack@google.com         * interrupt enable */
11412442Sgabeblack@google.com        bool rawIntTimer;
11512448Sgabeblack@google.com        bool rawIntWatchdog;
11612448Sgabeblack@google.com        bool rawResetWatchdog;
1175877Shsul@eecs.umich.edu        uint32_t watchdogDisableReg;
1185877Shsul@eecs.umich.edu
1195877Shsul@eecs.umich.edu        /** If an interrupt is currently pending. Logical and of Timer or
1202399SN/A          * Watchdog Ctrl.enable and rawIntTimer or rawIntWatchdog */
12112448Sgabeblack@google.com        bool pendingIntTimer;
1228600Ssteve.reinhardt@amd.com        bool pendingIntWatchdog;
1238600Ssteve.reinhardt@amd.com
1248600Ssteve.reinhardt@amd.com        /** Value to load into counters when periodic mode reaches 0 */
1258600Ssteve.reinhardt@amd.com        uint32_t timerLoadValue;
12612448Sgabeblack@google.com        uint32_t watchdogLoadValue;
12712448Sgabeblack@google.com
1288600Ssteve.reinhardt@amd.com        /** Called when the counter reaches 0 */
1298600Ssteve.reinhardt@amd.com        void timerAtZero();
1308600Ssteve.reinhardt@amd.com        EventWrapper<Timer, &Timer::timerAtZero> timerZeroEvent;
1318600Ssteve.reinhardt@amd.com
1328600Ssteve.reinhardt@amd.com        void watchdogAtZero();
13312461Sgabeblack@google.com        EventWrapper<Timer, &Timer::watchdogAtZero> watchdogZeroEvent;
13412455Sgabeblack@google.com      public:
1352399SN/A        /** Restart the counter ticking at val
1362399SN/A         * @param val the value to start at */
1375004Sgblack@eecs.umich.edu        void restartTimerCounter(uint32_t val);
13812448Sgabeblack@google.com        void restartWatchdogCounter(uint32_t val);
13912455Sgabeblack@google.com
14012461Sgabeblack@google.com        Timer();
1412399SN/A
1422399SN/A        std::string name() const { return _name; }
1435004Sgblack@eecs.umich.edu
14412448Sgabeblack@google.com        /** Handle read for a single timer */
1455004Sgblack@eecs.umich.edu        void read(PacketPtr pkt, Addr daddr);
14612461Sgabeblack@google.com
14712455Sgabeblack@google.com        /** Handle write for a single timer */
1485183Ssaidi@eecs.umich.edu        void write(PacketPtr pkt, Addr daddr);
1495004Sgblack@eecs.umich.edu
1505183Ssaidi@eecs.umich.edu        void serialize(std::ostream &os);
15112461Sgabeblack@google.com        void unserialize(Checkpoint *cp, const std::string &section);
1525183Ssaidi@eecs.umich.edu
1535004Sgblack@eecs.umich.edu        friend class CpuLocalTimer;
1545004Sgblack@eecs.umich.edu    };
1552399SN/A
1562394SN/A    static const int CPU_MAX = 8;
15712749Sgiacomo.travaglini@arm.com
1582394SN/A    /** Pointer to the GIC for causing an interrupt */
1592532SN/A    Gic *gic;
16012448Sgabeblack@google.com
16112448Sgabeblack@google.com    /** Timers that do the actual work */
16212448Sgabeblack@google.com    Timer localTimer[CPU_MAX];
1635004Sgblack@eecs.umich.edu
1642532SN/A  public:
1655004Sgblack@eecs.umich.edu    typedef CpuLocalTimerParams Params;
1665004Sgblack@eecs.umich.edu    const Params *
1675004Sgblack@eecs.umich.edu    params() const
1685004Sgblack@eecs.umich.edu    {
1695004Sgblack@eecs.umich.edu        return dynamic_cast<const Params *>(_params);
1702394SN/A    }
1713311Ssaidi@eecs.umich.edu    /**
1723311Ssaidi@eecs.umich.edu      * The constructor for RealView just registers itself with the MMU.
17312448Sgabeblack@google.com      * @param p params structure
1743311Ssaidi@eecs.umich.edu      */
17510905Sandreas.sandberg@arm.com    CpuLocalTimer(Params *p);
1763320Shsul@eecs.umich.edu
1776227Snate@binkert.org    /**
17810905Sandreas.sandberg@arm.com     * Handle a read to the device
17910905Sandreas.sandberg@arm.com     * @param pkt The memory request.
1803311Ssaidi@eecs.umich.edu     * @return Returns latency of device read
18110905Sandreas.sandberg@arm.com     */
18212461Sgabeblack@google.com    virtual Tick read(PacketPtr pkt);
18312461Sgabeblack@google.com
1843311Ssaidi@eecs.umich.edu    /**
1853311Ssaidi@eecs.umich.edu     * Handle a write to the device.
1863311Ssaidi@eecs.umich.edu     * @param pkt The memory request.
1873311Ssaidi@eecs.umich.edu     * @return Returns latency of device write
1883311Ssaidi@eecs.umich.edu     */
18912448Sgabeblack@google.com    virtual Tick write(PacketPtr pkt);
1903311Ssaidi@eecs.umich.edu
19110905Sandreas.sandberg@arm.com
19210905Sandreas.sandberg@arm.com    virtual void serialize(std::ostream &os);
1933311Ssaidi@eecs.umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
19410905Sandreas.sandberg@arm.com};
19510905Sandreas.sandberg@arm.com
1963311Ssaidi@eecs.umich.edu
19712461Sgabeblack@google.com#endif // __DEV_ARM_SP804_HH__
19812461Sgabeblack@google.com
19912461Sgabeblack@google.com