timer_cpulocal.hh revision 9235:5aa4896ed55a
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright (c) 2010-2011 ARM Limited
312027Sjungma@eit.uni-kl.de * All rights reserved
412027Sjungma@eit.uni-kl.de *
512027Sjungma@eit.uni-kl.de * The license below extends only to copyright in the software and shall
612027Sjungma@eit.uni-kl.de * not be construed as granting a license to any other intellectual
712027Sjungma@eit.uni-kl.de * property including but not limited to intellectual property relating
812027Sjungma@eit.uni-kl.de * to a hardware implementation of the functionality of the software
912027Sjungma@eit.uni-kl.de * licensed hereunder.  You may use the software subject to the license
1012027Sjungma@eit.uni-kl.de * terms below provided that you ensure that this notice is replicated
1112027Sjungma@eit.uni-kl.de * unmodified and in its entirety in all distributions of the software,
1212027Sjungma@eit.uni-kl.de * modified or unmodified, in source code or in binary form.
1312027Sjungma@eit.uni-kl.de *
1412027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
1512027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
1612027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
1712027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
1812027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
1912027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
2012027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
2112027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
2212027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
2312027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
2412027Sjungma@eit.uni-kl.de *
2512027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2612027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2712027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2812027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2912027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3012027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3112027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3212027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3312027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3412027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3512027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3612027Sjungma@eit.uni-kl.de *
3712027Sjungma@eit.uni-kl.de * Authors: Ali Saidi
3812027Sjungma@eit.uni-kl.de *          Geoffrey Blake
3912027Sjungma@eit.uni-kl.de */
4012027Sjungma@eit.uni-kl.de
4112027Sjungma@eit.uni-kl.de#ifndef __DEV_ARM_LOCALTIMER_HH__
4212027Sjungma@eit.uni-kl.de#define __DEV_ARM_LOCALTIMER_HH__
4312027Sjungma@eit.uni-kl.de
4412027Sjungma@eit.uni-kl.de#include "dev/io_device.hh"
4512027Sjungma@eit.uni-kl.de#include "params/CpuLocalTimer.hh"
4612027Sjungma@eit.uni-kl.de
4712027Sjungma@eit.uni-kl.de/** @file
4812027Sjungma@eit.uni-kl.de * This implements the cpu local timer from the Cortex-A9 MPCore
4912027Sjungma@eit.uni-kl.de * Technical Reference Manual rev r2p2 (ARM DDI 0407F)
5012027Sjungma@eit.uni-kl.de */
5112027Sjungma@eit.uni-kl.de
5212027Sjungma@eit.uni-kl.declass Gic;
5312027Sjungma@eit.uni-kl.de
5412027Sjungma@eit.uni-kl.declass CpuLocalTimer : public BasicPioDevice
5512027Sjungma@eit.uni-kl.de{
5612027Sjungma@eit.uni-kl.de  protected:
5712027Sjungma@eit.uni-kl.de    class Timer
5812027Sjungma@eit.uni-kl.de    {
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.de      public:
6112027Sjungma@eit.uni-kl.de        enum {
6212027Sjungma@eit.uni-kl.de            TimerLoadReg    	   = 0x00,
6312027Sjungma@eit.uni-kl.de            TimerCounterReg 	   = 0x04,
6412027Sjungma@eit.uni-kl.de            TimerControlReg 	   = 0x08,
6512027Sjungma@eit.uni-kl.de            TimerIntStatusReg      = 0x0C,
6612027Sjungma@eit.uni-kl.de            WatchdogLoadReg        = 0x20,
6712027Sjungma@eit.uni-kl.de            WatchdogCounterReg     = 0x24,
6812027Sjungma@eit.uni-kl.de            WatchdogControlReg     = 0x28,
6912027Sjungma@eit.uni-kl.de            WatchdogIntStatusReg   = 0x2C,
7012027Sjungma@eit.uni-kl.de            WatchdogResetStatusReg = 0x30,
7112027Sjungma@eit.uni-kl.de            WatchdogDisableReg     = 0x34,
7212027Sjungma@eit.uni-kl.de            Size                   = 0x38
7312027Sjungma@eit.uni-kl.de        };
7412027Sjungma@eit.uni-kl.de
7512027Sjungma@eit.uni-kl.de        BitUnion32(TimerCtrl)
7612027Sjungma@eit.uni-kl.de            Bitfield<0>   enable;
7712027Sjungma@eit.uni-kl.de            Bitfield<1>   autoReload;
7812027Sjungma@eit.uni-kl.de            Bitfield<2>   intEnable;
7912027Sjungma@eit.uni-kl.de            Bitfield<7,3> reserved;
8012027Sjungma@eit.uni-kl.de            Bitfield<15,8> prescalar;
8112027Sjungma@eit.uni-kl.de        EndBitUnion(TimerCtrl)
8212027Sjungma@eit.uni-kl.de
8312027Sjungma@eit.uni-kl.de        BitUnion32(WatchdogCtrl)
8412027Sjungma@eit.uni-kl.de            Bitfield<0>   enable;
8512027Sjungma@eit.uni-kl.de            Bitfield<1>   autoReload;
8612027Sjungma@eit.uni-kl.de            Bitfield<2>   intEnable;
8712027Sjungma@eit.uni-kl.de            Bitfield<3>   watchdogMode;
8812027Sjungma@eit.uni-kl.de            Bitfield<7,4> reserved;
8912027Sjungma@eit.uni-kl.de            Bitfield<15,8> prescalar;
9012027Sjungma@eit.uni-kl.de        EndBitUnion(WatchdogCtrl)
9112027Sjungma@eit.uni-kl.de
9212027Sjungma@eit.uni-kl.de      protected:
9312027Sjungma@eit.uni-kl.de        std::string _name;
9412027Sjungma@eit.uni-kl.de
9512027Sjungma@eit.uni-kl.de        /** Pointer to parent class */
9612027Sjungma@eit.uni-kl.de        CpuLocalTimer *parent;
9712027Sjungma@eit.uni-kl.de
9812027Sjungma@eit.uni-kl.de        /** Number of interrupt to cause/clear */
9912027Sjungma@eit.uni-kl.de        uint32_t intNumTimer;
10012027Sjungma@eit.uni-kl.de        uint32_t intNumWatchdog;
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de        /** Cpu this timer is attached to */
10312027Sjungma@eit.uni-kl.de        uint32_t cpuNum;
10412027Sjungma@eit.uni-kl.de
10512027Sjungma@eit.uni-kl.de        /** Number of ticks in a clock input */
10612027Sjungma@eit.uni-kl.de        Tick clock;
10712027Sjungma@eit.uni-kl.de
10812027Sjungma@eit.uni-kl.de        /** Control register as specified above */
10912027Sjungma@eit.uni-kl.de        TimerCtrl timerControl;
11012027Sjungma@eit.uni-kl.de        WatchdogCtrl watchdogControl;
11112027Sjungma@eit.uni-kl.de
11212027Sjungma@eit.uni-kl.de        /** If timer has caused an interrupt. This is irrespective of
11312027Sjungma@eit.uni-kl.de         * interrupt enable */
11412027Sjungma@eit.uni-kl.de        bool rawIntTimer;
11512027Sjungma@eit.uni-kl.de        bool rawIntWatchdog;
11612027Sjungma@eit.uni-kl.de        bool rawResetWatchdog;
11712027Sjungma@eit.uni-kl.de        uint32_t watchdogDisableReg;
11812027Sjungma@eit.uni-kl.de
11912027Sjungma@eit.uni-kl.de        /** If an interrupt is currently pending. Logical and of Timer or
12012027Sjungma@eit.uni-kl.de          * Watchdog Ctrl.enable and rawIntTimer or rawIntWatchdog */
12112027Sjungma@eit.uni-kl.de        bool pendingIntTimer;
12212027Sjungma@eit.uni-kl.de        bool pendingIntWatchdog;
12312027Sjungma@eit.uni-kl.de
12412027Sjungma@eit.uni-kl.de        /** Value to load into counters when periodic mode reaches 0 */
12512027Sjungma@eit.uni-kl.de        uint32_t timerLoadValue;
12612027Sjungma@eit.uni-kl.de        uint32_t watchdogLoadValue;
12712027Sjungma@eit.uni-kl.de
12812027Sjungma@eit.uni-kl.de        /** Called when the counter reaches 0 */
12912027Sjungma@eit.uni-kl.de        void timerAtZero();
13012027Sjungma@eit.uni-kl.de        EventWrapper<Timer, &Timer::timerAtZero> timerZeroEvent;
13112027Sjungma@eit.uni-kl.de
13212027Sjungma@eit.uni-kl.de        void watchdogAtZero();
13312027Sjungma@eit.uni-kl.de        EventWrapper<Timer, &Timer::watchdogAtZero> watchdogZeroEvent;
13412027Sjungma@eit.uni-kl.de      public:
13512027Sjungma@eit.uni-kl.de        /** Restart the counter ticking at val
13612027Sjungma@eit.uni-kl.de         * @param val the value to start at */
13712027Sjungma@eit.uni-kl.de        void restartTimerCounter(uint32_t val);
13812027Sjungma@eit.uni-kl.de        void restartWatchdogCounter(uint32_t val);
13912027Sjungma@eit.uni-kl.de
14012027Sjungma@eit.uni-kl.de        Timer();
14112027Sjungma@eit.uni-kl.de
14212027Sjungma@eit.uni-kl.de        std::string name() const { return _name; }
14312027Sjungma@eit.uni-kl.de
14412027Sjungma@eit.uni-kl.de        /** Handle read for a single timer */
14512027Sjungma@eit.uni-kl.de        void read(PacketPtr pkt, Addr daddr);
14612027Sjungma@eit.uni-kl.de
14712027Sjungma@eit.uni-kl.de        /** Handle write for a single timer */
14812027Sjungma@eit.uni-kl.de        void write(PacketPtr pkt, Addr daddr);
14912027Sjungma@eit.uni-kl.de
15012027Sjungma@eit.uni-kl.de        void serialize(std::ostream &os);
15112027Sjungma@eit.uni-kl.de        void unserialize(Checkpoint *cp, const std::string &section);
15212027Sjungma@eit.uni-kl.de
15312027Sjungma@eit.uni-kl.de        friend class CpuLocalTimer;
15412027Sjungma@eit.uni-kl.de    };
15512027Sjungma@eit.uni-kl.de
15612027Sjungma@eit.uni-kl.de    static const int CPU_MAX = 8;
15712027Sjungma@eit.uni-kl.de
15812027Sjungma@eit.uni-kl.de    /** Pointer to the GIC for causing an interrupt */
15912027Sjungma@eit.uni-kl.de    Gic *gic;
16012027Sjungma@eit.uni-kl.de
16112027Sjungma@eit.uni-kl.de    /** Timers that do the actual work */
16212027Sjungma@eit.uni-kl.de    Timer localTimer[CPU_MAX];
16312027Sjungma@eit.uni-kl.de
16412027Sjungma@eit.uni-kl.de  public:
16512027Sjungma@eit.uni-kl.de    typedef CpuLocalTimerParams Params;
16612027Sjungma@eit.uni-kl.de    const Params *
16712027Sjungma@eit.uni-kl.de    params() const
16812027Sjungma@eit.uni-kl.de    {
16912027Sjungma@eit.uni-kl.de        return dynamic_cast<const Params *>(_params);
17012027Sjungma@eit.uni-kl.de    }
17112027Sjungma@eit.uni-kl.de    /**
17212027Sjungma@eit.uni-kl.de      * The constructor for RealView just registers itself with the MMU.
17312027Sjungma@eit.uni-kl.de      * @param p params structure
17412027Sjungma@eit.uni-kl.de      */
17512027Sjungma@eit.uni-kl.de    CpuLocalTimer(Params *p);
17612027Sjungma@eit.uni-kl.de
17712027Sjungma@eit.uni-kl.de    /**
17812027Sjungma@eit.uni-kl.de     * Handle a read to the device
17912027Sjungma@eit.uni-kl.de     * @param pkt The memory request.
18012027Sjungma@eit.uni-kl.de     * @return Returns latency of device read
18112027Sjungma@eit.uni-kl.de     */
18212027Sjungma@eit.uni-kl.de    virtual Tick read(PacketPtr pkt);
18312027Sjungma@eit.uni-kl.de
18412027Sjungma@eit.uni-kl.de    /**
18512027Sjungma@eit.uni-kl.de     * Handle a write to the device.
18612027Sjungma@eit.uni-kl.de     * @param pkt The memory request.
18712027Sjungma@eit.uni-kl.de     * @return Returns latency of device write
18812027Sjungma@eit.uni-kl.de     */
18912027Sjungma@eit.uni-kl.de    virtual Tick write(PacketPtr pkt);
19012027Sjungma@eit.uni-kl.de
19112027Sjungma@eit.uni-kl.de
19212027Sjungma@eit.uni-kl.de    virtual void serialize(std::ostream &os);
19312027Sjungma@eit.uni-kl.de    virtual void unserialize(Checkpoint *cp, const std::string &section);
19412027Sjungma@eit.uni-kl.de};
19512027Sjungma@eit.uni-kl.de
19612027Sjungma@eit.uni-kl.de
19712027Sjungma@eit.uni-kl.de#endif // __DEV_ARM_SP804_HH__
19812027Sjungma@eit.uni-kl.de
19912027Sjungma@eit.uni-kl.de