malta_io.hh revision 5222
15222Sksewell@umich.edu/*
25222Sksewell@umich.edu * Copyright (c) 2004-2005 The Regents of The University of Michigan
35222Sksewell@umich.edu * All rights reserved.
45222Sksewell@umich.edu *
55222Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without
65222Sksewell@umich.edu * modification, are permitted provided that the following conditions are
75222Sksewell@umich.edu * met: redistributions of source code must retain the above copyright
85222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer;
95222Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright
105222Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the
115222Sksewell@umich.edu * documentation and/or other materials provided with the distribution;
125222Sksewell@umich.edu * neither the name of the copyright holders nor the names of its
135222Sksewell@umich.edu * contributors may be used to endorse or promote products derived from
145222Sksewell@umich.edu * this software without specific prior written permission.
155222Sksewell@umich.edu *
165222Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
175222Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
185222Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
195222Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
205222Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
215222Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
225222Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235222Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
245222Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
255222Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265222Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
275222Sksewell@umich.edu *
285222Sksewell@umich.edu * Authors: Ali Saidi
295222Sksewell@umich.edu *          Andrew Schultz
305222Sksewell@umich.edu *          Miguel Serrano
315222Sksewell@umich.edu */
325222Sksewell@umich.edu
335222Sksewell@umich.edu/** @file
345222Sksewell@umich.edu * Malta I/O Space mapping including RTC/timer interrupts
355222Sksewell@umich.edu */
365222Sksewell@umich.edu
375222Sksewell@umich.edu#ifndef __DEV_MALTA_IO_HH__
385222Sksewell@umich.edu#define __DEV_MALTA_IO_HH__
395222Sksewell@umich.edu
405222Sksewell@umich.edu#include "dev/io_device.hh"
415222Sksewell@umich.edu#include "base/range.hh"
425222Sksewell@umich.edu#include "dev/mips/malta.hh"
435222Sksewell@umich.edu#include "sim/eventq.hh"
445222Sksewell@umich.edu#include "params/MaltaIO.hh"
455222Sksewell@umich.edu
465222Sksewell@umich.edu/**
475222Sksewell@umich.edu * Malta I/O device is a catch all for all the south bridge stuff we care
485222Sksewell@umich.edu * to implement.
495222Sksewell@umich.edu */
505222Sksewell@umich.educlass MaltaIO : public BasicPioDevice
515222Sksewell@umich.edu{
525222Sksewell@umich.edu  private:
535222Sksewell@umich.edu    struct tm tm;
545222Sksewell@umich.edu  public:
555222Sksewell@umich.edu        /** Post an Interrupt to the CPU */
565222Sksewell@umich.edu    void postIntr(uint8_t interrupt);
575222Sksewell@umich.edu
585222Sksewell@umich.edu    /** Clear an Interrupt to the CPU */
595222Sksewell@umich.edu    void clearIntr(uint8_t interrupt);
605222Sksewell@umich.edu
615222Sksewell@umich.edu  protected:
625222Sksewell@umich.edu    /** Real-Time Clock (MC146818) */
635222Sksewell@umich.edu    class RTC
645222Sksewell@umich.edu    {
655222Sksewell@umich.edu      private:
665222Sksewell@umich.edu        /** Event for RTC periodic interrupt */
675222Sksewell@umich.edu        struct RTCEvent : public Event
685222Sksewell@umich.edu        {
695222Sksewell@umich.edu            /** A pointer back to malta to create interrupt the processor. */
705222Sksewell@umich.edu            Malta* malta;
715222Sksewell@umich.edu            Tick interval;
725222Sksewell@umich.edu
735222Sksewell@umich.edu            RTCEvent(Malta* t, Tick i);
745222Sksewell@umich.edu
755222Sksewell@umich.edu            /** Schedule the RTC periodic interrupt */
765222Sksewell@umich.edu            void scheduleIntr();
775222Sksewell@umich.edu
785222Sksewell@umich.edu            /** Event process to occur at interrupt*/
795222Sksewell@umich.edu            virtual void process();
805222Sksewell@umich.edu
815222Sksewell@umich.edu            /** Event description */
825222Sksewell@umich.edu            virtual const char *description();
835222Sksewell@umich.edu        };
845222Sksewell@umich.edu
855222Sksewell@umich.edu      private:
865222Sksewell@umich.edu        std::string _name;
875222Sksewell@umich.edu        const std::string &name() const { return _name; }
885222Sksewell@umich.edu
895222Sksewell@umich.edu        /** RTC periodic interrupt event */
905222Sksewell@umich.edu        RTCEvent event;
915222Sksewell@umich.edu
925222Sksewell@umich.edu        /** Current RTC register address/index */
935222Sksewell@umich.edu        int addr;
945222Sksewell@umich.edu
955222Sksewell@umich.edu        /** Data for real-time clock function */
965222Sksewell@umich.edu        union {
975222Sksewell@umich.edu            uint8_t clock_data[10];
985222Sksewell@umich.edu
995222Sksewell@umich.edu            struct {
1005222Sksewell@umich.edu                uint8_t sec;
1015222Sksewell@umich.edu                uint8_t sec_alrm;
1025222Sksewell@umich.edu                uint8_t min;
1035222Sksewell@umich.edu                uint8_t min_alrm;
1045222Sksewell@umich.edu                uint8_t hour;
1055222Sksewell@umich.edu                uint8_t hour_alrm;
1065222Sksewell@umich.edu                uint8_t wday;
1075222Sksewell@umich.edu                uint8_t mday;
1085222Sksewell@umich.edu                uint8_t mon;
1095222Sksewell@umich.edu                uint8_t year;
1105222Sksewell@umich.edu            };
1115222Sksewell@umich.edu        };
1125222Sksewell@umich.edu
1135222Sksewell@umich.edu        /** RTC status register A */
1145222Sksewell@umich.edu        uint8_t stat_regA;
1155222Sksewell@umich.edu
1165222Sksewell@umich.edu        /** RTC status register B */
1175222Sksewell@umich.edu        uint8_t stat_regB;
1185222Sksewell@umich.edu
1195222Sksewell@umich.edu      public:
1205222Sksewell@umich.edu        RTC(const std::string &name, Malta* t, Tick i);
1215222Sksewell@umich.edu
1225222Sksewell@umich.edu        /** Set the initial RTC time/date */
1235222Sksewell@umich.edu        void set_time(time_t t);
1245222Sksewell@umich.edu
1255222Sksewell@umich.edu        /** RTC address port: write address of RTC RAM data to access */
1265222Sksewell@umich.edu        void writeAddr(const uint8_t data);
1275222Sksewell@umich.edu
1285222Sksewell@umich.edu        /** RTC write data */
1295222Sksewell@umich.edu        void writeData(const uint8_t data);
1305222Sksewell@umich.edu
1315222Sksewell@umich.edu
1325222Sksewell@umich.edu
1335222Sksewell@umich.edu        /** RTC read data */
1345222Sksewell@umich.edu        uint8_t readData();
1355222Sksewell@umich.edu
1365222Sksewell@umich.edu        /**
1375222Sksewell@umich.edu          * Serialize this object to the given output stream.
1385222Sksewell@umich.edu          * @param base The base name of the counter object.
1395222Sksewell@umich.edu          * @param os The stream to serialize to.
1405222Sksewell@umich.edu          */
1415222Sksewell@umich.edu        void serialize(const std::string &base, std::ostream &os);
1425222Sksewell@umich.edu
1435222Sksewell@umich.edu        /**
1445222Sksewell@umich.edu         * Reconstruct the state of this object from a checkpoint.
1455222Sksewell@umich.edu          * @param base The base name of the counter object.
1465222Sksewell@umich.edu         * @param cp The checkpoint use.
1475222Sksewell@umich.edu         * @param section The section name of this object
1485222Sksewell@umich.edu         */
1495222Sksewell@umich.edu        void unserialize(const std::string &base, Checkpoint *cp,
1505222Sksewell@umich.edu                         const std::string &section);
1515222Sksewell@umich.edu    };
1525222Sksewell@umich.edu
1535222Sksewell@umich.edu    /** Programmable Interval Timer (Intel 8254) */
1545222Sksewell@umich.edu    class PITimer
1555222Sksewell@umich.edu    {
1565222Sksewell@umich.edu        /** Counter element for PIT */
1575222Sksewell@umich.edu        class Counter
1585222Sksewell@umich.edu        {
1595222Sksewell@umich.edu            /** Event for counter interrupt */
1605222Sksewell@umich.edu            class CounterEvent : public Event
1615222Sksewell@umich.edu            {
1625222Sksewell@umich.edu              private:
1635222Sksewell@umich.edu                /** Pointer back to Counter */
1645222Sksewell@umich.edu                Counter* counter;
1655222Sksewell@umich.edu                Tick interval;
1665222Sksewell@umich.edu
1675222Sksewell@umich.edu              public:
1685222Sksewell@umich.edu                CounterEvent(Counter*);
1695222Sksewell@umich.edu
1705222Sksewell@umich.edu                /** Event process */
1715222Sksewell@umich.edu                virtual void process();
1725222Sksewell@umich.edu
1735222Sksewell@umich.edu                /** Event description */
1745222Sksewell@umich.edu                virtual const char *description();
1755222Sksewell@umich.edu
1765222Sksewell@umich.edu                friend class Counter;
1775222Sksewell@umich.edu            };
1785222Sksewell@umich.edu
1795222Sksewell@umich.edu          private:
1805222Sksewell@umich.edu            std::string _name;
1815222Sksewell@umich.edu            const std::string &name() const { return _name; }
1825222Sksewell@umich.edu
1835222Sksewell@umich.edu            CounterEvent event;
1845222Sksewell@umich.edu
1855222Sksewell@umich.edu            /** Current count value */
1865222Sksewell@umich.edu            uint16_t count;
1875222Sksewell@umich.edu
1885222Sksewell@umich.edu            /** Latched count */
1895222Sksewell@umich.edu            uint16_t latched_count;
1905222Sksewell@umich.edu
1915222Sksewell@umich.edu            /** Interrupt period */
1925222Sksewell@umich.edu            uint16_t period;
1935222Sksewell@umich.edu
1945222Sksewell@umich.edu            /** Current mode of operation */
1955222Sksewell@umich.edu            uint8_t mode;
1965222Sksewell@umich.edu
1975222Sksewell@umich.edu            /** Output goes high when the counter reaches zero */
1985222Sksewell@umich.edu            bool output_high;
1995222Sksewell@umich.edu
2005222Sksewell@umich.edu            /** State of the count latch */
2015222Sksewell@umich.edu            bool latch_on;
2025222Sksewell@umich.edu
2035222Sksewell@umich.edu            /** Set of values for read_byte and write_byte */
2045222Sksewell@umich.edu            enum {LSB, MSB};
2055222Sksewell@umich.edu
2065222Sksewell@umich.edu            /** Determine which byte of a 16-bit count value to read/write */
2075222Sksewell@umich.edu            uint8_t read_byte, write_byte;
2085222Sksewell@umich.edu
2095222Sksewell@umich.edu          public:
2105222Sksewell@umich.edu            Counter(const std::string &name);
2115222Sksewell@umich.edu
2125222Sksewell@umich.edu            /** Latch the current count (if one is not already latched) */
2135222Sksewell@umich.edu            void latchCount();
2145222Sksewell@umich.edu
2155222Sksewell@umich.edu            /** Set the read/write mode */
2165222Sksewell@umich.edu            void setRW(int rw_val);
2175222Sksewell@umich.edu
2185222Sksewell@umich.edu            /** Set operational mode */
2195222Sksewell@umich.edu            void setMode(int mode_val);
2205222Sksewell@umich.edu
2215222Sksewell@umich.edu            /** Set count encoding */
2225222Sksewell@umich.edu            void setBCD(int bcd_val);
2235222Sksewell@umich.edu
2245222Sksewell@umich.edu            /** Read a count byte */
2255222Sksewell@umich.edu            uint8_t read();
2265222Sksewell@umich.edu
2275222Sksewell@umich.edu            /** Write a count byte */
2285222Sksewell@umich.edu            void write(const uint8_t data);
2295222Sksewell@umich.edu
2305222Sksewell@umich.edu            /** Is the output high? */
2315222Sksewell@umich.edu            bool outputHigh();
2325222Sksewell@umich.edu
2335222Sksewell@umich.edu            /**
2345222Sksewell@umich.edu             * Serialize this object to the given output stream.
2355222Sksewell@umich.edu             * @param base The base name of the counter object.
2365222Sksewell@umich.edu             * @param os   The stream to serialize to.
2375222Sksewell@umich.edu             */
2385222Sksewell@umich.edu            void serialize(const std::string &base, std::ostream &os);
2395222Sksewell@umich.edu
2405222Sksewell@umich.edu            /**
2415222Sksewell@umich.edu             * Reconstruct the state of this object from a checkpoint.
2425222Sksewell@umich.edu             * @param base The base name of the counter object.
2435222Sksewell@umich.edu             * @param cp The checkpoint use.
2445222Sksewell@umich.edu             * @param section The section name of this object
2455222Sksewell@umich.edu             */
2465222Sksewell@umich.edu            void unserialize(const std::string &base, Checkpoint *cp,
2475222Sksewell@umich.edu                             const std::string &section);
2485222Sksewell@umich.edu        };
2495222Sksewell@umich.edu
2505222Sksewell@umich.edu      private:
2515222Sksewell@umich.edu        std::string _name;
2525222Sksewell@umich.edu        const std::string &name() const { return _name; }
2535222Sksewell@umich.edu
2545222Sksewell@umich.edu        /** PIT has three seperate counters */
2555222Sksewell@umich.edu        Counter *counter[3];
2565222Sksewell@umich.edu
2575222Sksewell@umich.edu      public:
2585222Sksewell@umich.edu        /** Public way to access individual counters (avoid array accesses) */
2595222Sksewell@umich.edu        Counter counter0;
2605222Sksewell@umich.edu        Counter counter1;
2615222Sksewell@umich.edu        Counter counter2;
2625222Sksewell@umich.edu
2635222Sksewell@umich.edu        PITimer(const std::string &name);
2645222Sksewell@umich.edu
2655222Sksewell@umich.edu        /** Write control word */
2665222Sksewell@umich.edu        void writeControl(const uint8_t data);
2675222Sksewell@umich.edu
2685222Sksewell@umich.edu        /**
2695222Sksewell@umich.edu         * Serialize this object to the given output stream.
2705222Sksewell@umich.edu         * @param base The base name of the counter object.
2715222Sksewell@umich.edu         * @param os The stream to serialize to.
2725222Sksewell@umich.edu         */
2735222Sksewell@umich.edu        void serialize(const std::string &base, std::ostream &os);
2745222Sksewell@umich.edu
2755222Sksewell@umich.edu        /**
2765222Sksewell@umich.edu         * Reconstruct the state of this object from a checkpoint.
2775222Sksewell@umich.edu         * @param base The base name of the counter object.
2785222Sksewell@umich.edu         * @param cp The checkpoint use.
2795222Sksewell@umich.edu         * @param section The section name of this object
2805222Sksewell@umich.edu         */
2815222Sksewell@umich.edu        void unserialize(const std::string &base, Checkpoint *cp,
2825222Sksewell@umich.edu                         const std::string &section);
2835222Sksewell@umich.edu    };
2845222Sksewell@umich.edu
2855222Sksewell@umich.edu    /** Mask of the PIC1 */
2865222Sksewell@umich.edu    uint8_t mask1;
2875222Sksewell@umich.edu
2885222Sksewell@umich.edu    /** Mask of the PIC2 */
2895222Sksewell@umich.edu    uint8_t mask2;
2905222Sksewell@umich.edu
2915222Sksewell@umich.edu    /** Mode of PIC1. Not used for anything */
2925222Sksewell@umich.edu    uint8_t mode1;
2935222Sksewell@umich.edu
2945222Sksewell@umich.edu    /** Mode of PIC2. Not used for anything */
2955222Sksewell@umich.edu    uint8_t mode2;
2965222Sksewell@umich.edu
2975222Sksewell@umich.edu    /** Raw PIC interrupt register before masking */
2985222Sksewell@umich.edu    uint8_t picr; //Raw PIC interrput register
2995222Sksewell@umich.edu
3005222Sksewell@umich.edu    /** Is the pic interrupting right now or not. */
3015222Sksewell@umich.edu    bool picInterrupting;
3025222Sksewell@umich.edu
3035222Sksewell@umich.edu    /** A pointer to the Malta device which be belong to */
3045222Sksewell@umich.edu    Malta *malta;
3055222Sksewell@umich.edu
3065222Sksewell@umich.edu    /** Intel 8253 Periodic Interval Timer */
3075222Sksewell@umich.edu    PITimer pitimer;
3085222Sksewell@umich.edu
3095222Sksewell@umich.edu    RTC rtc;
3105222Sksewell@umich.edu
3115222Sksewell@umich.edu    /** The interval is set via two writes to the PIT.
3125222Sksewell@umich.edu     * This variable contains a flag as to how many writes have happened, and
3135222Sksewell@umich.edu     * the time so far.
3145222Sksewell@umich.edu     */
3155222Sksewell@umich.edu    uint16_t timerData;
3165222Sksewell@umich.edu
3175222Sksewell@umich.edu  public:
3185222Sksewell@umich.edu    /**
3195222Sksewell@umich.edu     * Return the freqency of the RTC
3205222Sksewell@umich.edu     * @return interrupt rate of the RTC
3215222Sksewell@umich.edu     */
3225222Sksewell@umich.edu    Tick frequency() const;
3235222Sksewell@umich.edu
3245222Sksewell@umich.edu    typedef MaltaIOParams Params;
3255222Sksewell@umich.edu
3265222Sksewell@umich.edu    const Params *
3275222Sksewell@umich.edu    params() const
3285222Sksewell@umich.edu    {
3295222Sksewell@umich.edu        return dynamic_cast<const Params *>(_params);
3305222Sksewell@umich.edu    }
3315222Sksewell@umich.edu
3325222Sksewell@umich.edu  public:
3335222Sksewell@umich.edu    /**
3345222Sksewell@umich.edu     * Initialize all the data for devices supported by Malta I/O.
3355222Sksewell@umich.edu     * @param p pointer to Params struct
3365222Sksewell@umich.edu     */
3375222Sksewell@umich.edu    MaltaIO(Params *p);
3385222Sksewell@umich.edu
3395222Sksewell@umich.edu    virtual Tick read(PacketPtr pkt);
3405222Sksewell@umich.edu    virtual Tick write(PacketPtr pkt);
3415222Sksewell@umich.edu
3425222Sksewell@umich.edu
3435222Sksewell@umich.edu
3445222Sksewell@umich.edu    /**
3455222Sksewell@umich.edu     * Serialize this object to the given output stream.
3465222Sksewell@umich.edu     * @param os The stream to serialize to.
3475222Sksewell@umich.edu     */
3485222Sksewell@umich.edu    virtual void serialize(std::ostream &os);
3495222Sksewell@umich.edu
3505222Sksewell@umich.edu    /**
3515222Sksewell@umich.edu     * Reconstruct the state of this object from a checkpoint.
3525222Sksewell@umich.edu     * @param cp The checkpoint use.
3535222Sksewell@umich.edu     * @param section The section name of this object
3545222Sksewell@umich.edu     */
3555222Sksewell@umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
3565222Sksewell@umich.edu
3575222Sksewell@umich.edu};
3585222Sksewell@umich.edu
3595222Sksewell@umich.edu#endif // __DEV_MALTA_IO_HH__
360