1768SN/A/*
21762SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
3768SN/A * All rights reserved.
4768SN/A *
5768SN/A * Redistribution and use in source and binary forms, with or without
6768SN/A * modification, are permitted provided that the following conditions are
7768SN/A * met: redistributions of source code must retain the above copyright
8768SN/A * notice, this list of conditions and the following disclaimer;
9768SN/A * redistributions in binary form must reproduce the above copyright
10768SN/A * notice, this list of conditions and the following disclaimer in the
11768SN/A * documentation and/or other materials provided with the distribution;
12768SN/A * neither the name of the copyright holders nor the names of its
13768SN/A * contributors may be used to endorse or promote products derived from
14768SN/A * this software without specific prior written permission.
15768SN/A *
16768SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17768SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18768SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19768SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20768SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21768SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22768SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23768SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24768SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25768SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26768SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665SN/A *
282665SN/A * Authors: Ali Saidi
292665SN/A *          Andrew Schultz
302665SN/A *          Miguel Serrano
31768SN/A */
32768SN/A
331722SN/A/** @file
341722SN/A * Tsunami I/O Space mapping including RTC/timer interrupts
35768SN/A */
36768SN/A
371401SN/A#ifndef __DEV_TSUNAMI_IO_HH__
381401SN/A#define __DEV_TSUNAMI_IO_HH__
39768SN/A
403540Sgblack@eecs.umich.edu#include "dev/alpha/tsunami.hh"
419338SAndreas.Sandberg@arm.com#include "dev/alpha/tsunami_cchip.hh"
425443Sgblack@eecs.umich.edu#include "dev/intel_8254_timer.hh"
438229Snate@binkert.org#include "dev/io_device.hh"
445392Sgblack@eecs.umich.edu#include "dev/mc146818.hh"
454762Snate@binkert.org#include "params/TsunamiIO.hh"
46932SN/A#include "sim/eventq.hh"
47768SN/A
481722SN/A/**
49885SN/A * Tsunami I/O device is a catch all for all the south bridge stuff we care
50885SN/A * to implement.
51768SN/A */
522542SN/Aclass TsunamiIO : public BasicPioDevice
53768SN/A{
54773SN/A
55768SN/A  protected:
565392Sgblack@eecs.umich.edu
575606Snate@binkert.org    class RTC : public MC146818
581854SN/A    {
595392Sgblack@eecs.umich.edu      public:
605606Snate@binkert.org        Tsunami *tsunami;
615606Snate@binkert.org        RTC(const std::string &n, const TsunamiIOParams *p);
625392Sgblack@eecs.umich.edu
635392Sgblack@eecs.umich.edu      protected:
645392Sgblack@eecs.umich.edu        void handleEvent()
651854SN/A        {
665392Sgblack@eecs.umich.edu            //Actually interrupt the processor here
675392Sgblack@eecs.umich.edu            tsunami->cchip->postRTC();
685392Sgblack@eecs.umich.edu        }
691817SN/A    };
70771SN/A
71885SN/A    /** Mask of the PIC1 */
72803SN/A    uint8_t mask1;
73885SN/A
74885SN/A    /** Mask of the PIC2 */
75803SN/A    uint8_t mask2;
76885SN/A
77885SN/A    /** Mode of PIC1. Not used for anything */
78803SN/A    uint8_t mode1;
79885SN/A
80885SN/A    /** Mode of PIC2. Not used for anything */
81803SN/A    uint8_t mode2;
82769SN/A
83885SN/A    /** Raw PIC interrupt register before masking */
84885SN/A    uint8_t picr; //Raw PIC interrput register
85885SN/A
86885SN/A    /** Is the pic interrupting right now or not. */
87777SN/A    bool picInterrupting;
88777SN/A
89885SN/A    /** A pointer to the Tsunami device which be belong to */
90775SN/A    Tsunami *tsunami;
91775SN/A
921817SN/A    /** Intel 8253 Periodic Interval Timer */
935443Sgblack@eecs.umich.edu    Intel8254Timer pitimer;
94773SN/A
955606Snate@binkert.org    RTC rtc;
965392Sgblack@eecs.umich.edu
975392Sgblack@eecs.umich.edu    uint8_t rtcAddr;
98773SN/A
99885SN/A    /** The interval is set via two writes to the PIT.
100885SN/A     * This variable contains a flag as to how many writes have happened, and
101885SN/A     * the time so far.
102885SN/A     */
1031817SN/A    uint16_t timerData;
104771SN/A
105768SN/A  public:
106891SN/A    /**
107891SN/A     * Return the freqency of the RTC
108891SN/A     * @return interrupt rate of the RTC
109891SN/A     */
1101634SN/A    Tick frequency() const;
111775SN/A
1122539SN/A  public:
1134762Snate@binkert.org    typedef TsunamiIOParams Params;
114885SN/A    /**
115885SN/A     * Initialize all the data for devices supported by Tsunami I/O.
1162539SN/A     * @param p pointer to Params struct
117885SN/A     */
1184762Snate@binkert.org    TsunamiIO(const Params *p);
1194762Snate@binkert.org
1204762Snate@binkert.org    const Params *
1214762Snate@binkert.org    params() const
1224762Snate@binkert.org    {
1234762Snate@binkert.org        return dynamic_cast<const Params *>(_params);
1244762Snate@binkert.org    }
125768SN/A
12611169Sandreas.hansson@arm.com    Tick read(PacketPtr pkt) override;
12711169Sandreas.hansson@arm.com    Tick write(PacketPtr pkt) override;
128768SN/A
129885SN/A    /**
130885SN/A     * Post an PIC interrupt to the CPU via the CChip
131885SN/A     * @param bitvector interrupt to post.
132885SN/A     */
133777SN/A    void postPIC(uint8_t bitvector);
134885SN/A
135885SN/A    /**
136885SN/A     * Clear a posted interrupt
137885SN/A     * @param bitvector interrupt to clear
138885SN/A     */
139777SN/A    void clearPIC(uint8_t bitvector);
140777SN/A
14111168Sandreas.hansson@arm.com    void serialize(CheckpointOut &cp) const override;
14211168Sandreas.hansson@arm.com    void unserialize(CheckpointIn &cp) override;
143909SN/A
14410631Scdirik@micron.com    /**
14510631Scdirik@micron.com     * Start running.
14610631Scdirik@micron.com     */
14711169Sandreas.hansson@arm.com    void startup() override;
14810631Scdirik@micron.com
149768SN/A};
150768SN/A
1511401SN/A#endif // __DEV_TSUNAMI_IO_HH__
152